Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / typo3 / alt_shortcut.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Shortcut frame
29 *
30 * Appears in the bottom frame of the backend frameset.
31 * Provides links to registered shortcuts
32 * If the 'cms' extension is loaded you will also have a field for entering page id/alias which will be found/edited
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 * @package TYPO3
36 * @subpackage core
37 *
38 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
39 * XHTML compliant output
40 */
41
42
43 require ('init.php');
44 require ('template.php');
45 include ('sysext/lang/locallang_misc.php');
46 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
47 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
48
49
50
51 // ***************************
52 // Script Classes
53 // ***************************
54 class SC_alt_shortcut {
55 var $content;
56 var $loadModules;
57 var $modName;
58 var $M_modName;
59 var $URL;
60 var $editSC;
61 var $nGroups;
62 var $nGlobals;
63 var $lines;
64 var $editSC_rec;
65 var $editLoaded;
66 var $editError;
67 var $theEditRec;
68 var $editPage;
69 var $doc;
70 var $selOpt;
71
72 /**
73 * Pre-initialization - setting input variables for storing shortcuts etc.
74 */
75 function preinit() {
76 global $TBE_MODULES;
77
78 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
79 $this->loadModules->load($TBE_MODULES);
80
81 $this->modName = t3lib_div::GPvar('modName');
82 $this->M_modName = t3lib_div::GPvar('motherModName');
83 $this->URL = t3lib_div::GPvar('URL');
84 $this->editSC = t3lib_div::GPvar('editShortcut');
85 }
86
87 /**
88 * Adding shortcuts, editing shortcuts etc.
89 */
90 function preprocess() {
91 global $BE_USER,$HTTP_POST_VARS;
92
93 // Adding a shortcut being set from another frame
94 if ($this->modName && $this->URL) {
95 $fields_values=array();
96 $fields_values['userid']=$BE_USER->user['uid'];
97 $fields_values['module_name']=$this->modName.'|'.$this->M_modName;
98 $fields_values['url']=$this->URL;
99 $fields_values['sorting']=time();
100 $query = t3lib_BEfunc::DBcompileInsert('sys_be_shortcuts',$fields_values);
101 $res = mysql(TYPO3_db,$query);
102 echo mysql_error();
103 }
104
105 // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
106 $addUSERWhere = (!$BE_USER->isAdmin()?' AND userid='.intval($BE_USER->user['uid']):'');
107
108 // Deleting shortcuts:
109 if (strcmp(t3lib_div::GPvar('deleteCategory'),'')) {
110 $delCat = t3lib_div::GPvar('deleteCategory');
111 if (t3lib_div::testInt($delCat)) {
112 $q = 'DELETE FROM sys_be_shortcuts WHERE sc_group='.$delCat.$addUSERWhere;
113 $res=mysql(TYPO3_db,$q);
114 }
115 }
116
117 // If other changes in post-vars:
118 if ($HTTP_POST_VARS) {
119 // Saving:
120 if (isset($HTTP_POST_VARS['_savedok_x']) || isset($HTTP_POST_VARS['_saveclosedok_x'])) {
121 $fields_values=array();
122 $fields_values['description']=t3lib_div::GPvar('editName');
123 $fields_values['sc_group']=intval(t3lib_div::GPvar('editGroup'));
124 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin()) {
125 $fields_values['sc_group']=0;
126 }
127
128 $q = t3lib_BEfunc::DBcompileUpdate('sys_be_shortcuts','uid='.intval(t3lib_div::GPvar('whichItem')).$addUSERWhere,$fields_values);
129 $res=mysql(TYPO3_db,$q);
130 }
131 // If save without close, keep the session going...
132 if (isset($HTTP_POST_VARS['_savedok_x'])) {
133 $this->editSC=t3lib_div::GPvar('whichItem');
134 }
135 // Deleting a single shortcut ?
136 if (isset($HTTP_POST_VARS['_deletedok_x'])) {
137 $q = 'DELETE FROM sys_be_shortcuts WHERE uid='.intval(t3lib_div::GPvar('whichItem')).$addUSERWhere;
138 $res=mysql(TYPO3_db,$q);
139 if (!$this->editSC) $this->editSC=-1; // Just to have the checkbox set...
140 }
141 }
142
143 }
144
145 /**
146 * Initialize (page output)
147 */
148 function init() {
149 global $BACK_PATH;
150
151 $this->doc = t3lib_div::makeInstance('template');
152 $this->doc->backPath = $BACK_PATH;
153 $this->doc->form='<form name="shForm" action="alt_shortcut.php" method="post">';
154 $this->doc->docType='xhtml_trans';
155 $this->doc->divClass='typo3-shortcut';
156 $this->doc->JScode.='
157 <script type="text/javascript">
158 '.$this->doc->wrapInCData('
159 function jump(url,modName,mainModName) {
160 top.nextLoadModuleUrl = url;
161 top.goToModule(modName);
162 }
163 function editSh(uid) {
164 document.location="alt_shortcut.php?editShortcut="+uid;
165 }
166 function submitEditPage(id) {
167 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
168 }
169 function loadEditId(id) {
170 top.fsMod.recentIds["web"]=id;
171 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
172 top.content.nav_frame.refresh_nav();
173 }
174 top.goToModule("web_layout");
175 }
176 ').'
177 </script>
178 ';
179 $this->content.=$this->doc->startPage('Shortcut frame');
180 }
181
182 /**
183 * Main function, creating content in the frame
184 */
185 function main() {
186 global $BE_USER,$LANG;
187
188 // Setting groups and globals
189 $this->nGroups=4;
190 $this->nGlobals=5;
191
192 $globalGroups=array(-100);
193 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
194 for($a=1;$a<=$this->nGlobals;$a++) {
195 if ($BE_USER->isAdmin() || strcmp($shortCutGroups['properties'][$a],'')) {
196 $globalGroups[]=-$a;
197 }
198 }
199
200 // Fetching shortcuts to display for this user:
201 $query = 'SELECT * FROM sys_be_shortcuts WHERE ((userid='.$BE_USER->user['uid'].' AND sc_group>=0) OR sc_group IN ('.implode(',',$globalGroups).')) ORDER BY sc_group,sorting';
202 $res = mysql(TYPO3_db,$query);
203
204 // Init vars:
205 $this->lines=array();
206 $this->editSC_rec='';
207 $this->selOpt=array();
208 $formerGr='';
209
210 // Traverse shortcuts
211 while($row=mysql_fetch_assoc($res)) {
212 if ($this->editSC && $row['uid']==$this->editSC) {
213 $this->editSC_rec=$row;
214 }
215
216 if (strcmp($formerGr,$row['sc_group'])) {
217 if ($row['sc_group']!=-100) {
218 if ($row['sc_group']>=0) {
219 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
220 $this->lines[]='<td>&nbsp;</td><td bgcolor="'.$this->doc->bgColor5.'"><a href="#" onclick="'.htmlspecialchars($onC).'"'.t3lib_BEfunc::titleAttrib($LANG->getLL('shortcut_delAllInCat'),1).'>'.abs($row['sc_group']).'</a></td>';
221 } else {
222 $this->lines[]='<td>&nbsp;</td><td bgcolor="'.$this->doc->bgColor5.'">'.abs($row['sc_group']).'</td>';
223 }
224 }
225 }
226
227 $mParts = explode('|',$row['module_name']);
228 $row['module_name']=$mParts[0];
229 $row['M_module_name']=$mParts[1];
230 $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
231 $qParts = parse_url($row['url']);
232
233 $bgColor = $row['uid']==$this->editSC?' bgcolor="'.$this->doc->bgColor5.'"':($row['sc_group']<0?' bgcolor="'.$this->doc->bgColor6.'"':' bgcolor="'.$this->doc->bgColor4.'"');
234 $titleA = t3lib_BEfunc::titleAttrib($this->itemLabel($row['description']&&($row['uid']!=$this->editSC)?$row['description']:t3lib_div::fixed_lgd(rawurldecode($qParts['query']),150),$row['module_name'],$row['M_module_name']),1);
235
236 $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
237 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
238 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
239 $this->lines[]='<td'.$bgColor.'><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" border="0"'.$titleA.' alt="" /></a></td>';
240 if (trim($row['description'])) {
241 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
242 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd($row['description'],50)).'</option>';
243 }
244 $formerGr=$row['sc_group'];
245 }
246 ksort($this->selOpt);
247 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
248
249 $this->editLoadedFunc();
250 $this->editPageIdFunc();
251
252 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
253 $editIdCode = '<td nowrap>'.$LANG->getLL('shortcut_editID').': <input type="text" value="'.($this->editError?htmlspecialchars($this->editPage):'').'" name="editPage"'.$this->doc->formWidth(5).' onchange="submitEditPage(this.value);" />'.
254 ($this->editError?'&nbsp;<strong>'.$GLOBALS['TBE_TEMPLATE']->rfw($this->editError).'</strong>':'').
255 (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit').' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,1).'\'</strong>':'').
256 '</td>';
257 } else $editIdCode='';
258
259 $this->content.='<table border="0" cellpadding="0" cellspacing="2">
260 <tr>
261 '.implode('',$this->lines).$editIdCode.'
262 </tr>
263 </table>';
264
265 if ($this->theEditRec['uid']) {
266 $this->content.='<script type="text/javascript">loadEditId('.$this->theEditRec['uid'].');</script>';
267 }
268 }
269
270 /**
271 * Creates lines for the editing form.
272 */
273 function editLoadedFunc() {
274 global $BE_USER,$LANG;
275
276 $this->editLoaded=0;
277 if (is_array($this->editSC_rec) && ($this->editSC_rec['sc_group']>=0 || $BE_USER->isAdmin())) { // sc_group numbers below 0 requires admin to edit those. sc_group numbers above zero must always be owned by the user himself.
278 $this->editLoaded=1;
279
280 $opt=array();
281 $opt[]='<option value="0"></option>';
282 for($a=1;$a<=$this->nGroups;$a++) {
283 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_group').' '.$a.'</option>';
284 }
285 if ($BE_USER->isAdmin()) {
286 for($a=1;$a<=$this->nGlobals;$a++) {
287 $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL').': '.$a.'</option>';
288 }
289 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL').': '.$LANG->getLL('shortcut_ALL').'</option>';
290 }
291
292 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
293 $manageForm='<table border="0" cellpadding="0" cellspacing="0">
294 <tr>
295 <td>&nbsp;&nbsp;</td>
296 <td><input type="image" name="_savedok" src="gfx/savedok.gif" '.t3lib_BEfunc::titleAttrib($LANG->getLL('shortcut_save')).' /></td>
297 <td><input type="image" name="_saveclosedok" src="gfx/saveandclosedok.gif" '.t3lib_BEfunc::titleAttrib($LANG->getLL('shortcut_saveClose')).' /></td>
298 <td><input type="image" name="_closedok" src="gfx/closedok.gif" '.t3lib_BEfunc::titleAttrib($LANG->getLL('shortcut_close')).' /></td>
299 <td><input type="image" name="_deletedok" src="gfx/deletedok.gif" '.t3lib_BEfunc::titleAttrib($LANG->getLL('shortcut_delete')).' /></td>
300 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
301 <td><select name="editGroup">'.implode('',$opt).'</select></td>
302 </tr>
303 </table>
304 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />';
305 } else $manageForm='';
306 //debug(count($opt));
307 if (!$this->editLoaded && count($this->selOpt)>1) {
308 $this->lines[]='<td>&nbsp;</td>';
309 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
310 }
311 if (count($this->lines)) {
312 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
313 $this->lines=array_merge(array('<td><input type="checkbox" name="editShortcut_check" value="1"'.($this->editSC?' checked="checked"':'').' />'.$LANG->getLL('shortcut_edit').'&nbsp;</td>'),$this->lines);
314 $this->lines[]='<td>'.$manageForm.'</td>';
315 }
316 $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
317 }
318 }
319
320 /**
321 * If "editPage" value is sent to script and it points to an accessible page, the internal var $this->theEditRec is set to the page record which should be loaded.
322 * Returns void
323 */
324 function editPageIdFunc() {
325 global $BE_USER,$LANG;
326
327 if (!t3lib_extMgm::isLoaded('cms')) return;
328 // EDIT page:
329 $this->editPage = trim(strtolower(t3lib_div::GPvar('editPage')));
330 $this->editError='';
331 $this->theEditRec='';
332 if ($this->editPage) {
333 $where=' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
334 if (t3lib_div::testInt($this->editPage)) {
335 $this->theEditRec = t3lib_BEfunc::getRecord ('pages',$this->editPage,'*',$where);
336 } else {
337 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
338 if (is_array($records)) {
339 reset($records);
340 $this->theEditRec = current($records);
341 }
342 }
343 if (!is_array($this->theEditRec) || !$BE_USER->isInWebMount($this->theEditRec['uid'])) {
344 unset($this->theEditRec);
345 $this->editError=$LANG->getLL('shortcut_notEditable');
346 } elseif(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
347 $expandedPages=unserialize($BE_USER->uc['browsePages']);
348 if (!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded')) $expandedPages=array();
349 $rL=t3lib_BEfunc::BEgetRootLine($this->theEditRec['pid']);
350 reset($rL);
351 while(list(,$rLDat)=each($rL)) {
352 $expandedPages[0][$rLDat['uid']]=1;
353 // debug($rLDat['uid']);
354 }
355 $BE_USER->uc['browsePages'] = serialize($expandedPages);
356 $BE_USER->writeUC();
357 }
358 }
359 }
360
361 /**
362 * Output content
363 */
364 function printContent() {
365 $this->content.= $this->doc->endPage();
366 echo $this->content;
367 }
368
369
370 // ***************************
371 // OTHER FUNCTIONS:
372 // ***************************
373
374 /**
375 * Returns relative filename for icon.
376 */
377 function mIconFilename($Ifilename,$backPath) {
378 if (t3lib_div::isAbsPath($Ifilename)) {
379 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
380 }
381 return $backPath.$Ifilename;
382 }
383
384 /**
385 * Returns icon for shortcut display
386 */
387 function getIcon($modName) {
388 global $LANG;
389 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab']) {
390 $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
391 } elseif ($modName=='xMOD_alt_doc.php') {
392 $icon = 'gfx/edit2.gif';
393 } elseif ($modName=='xMOD_file_edit.php') {
394 $icon = 'gfx/edit_file.gif';
395 } elseif ($modName=='xMOD_wizard_rte.php') {
396 $icon = 'gfx/edit_rtewiz.gif';
397 } else {
398 $icon = 'gfx/dummy_module.gif';
399 }
400 return $icon;
401 }
402
403 /**
404 * Returns title-label for icon
405 */
406 function itemLabel($inlabel,$modName,$M_modName='') {
407 global $LANG;
408 if (substr($modName,0,5)=='xMOD_') {
409 $label=substr($modName,5);
410 } else {
411 $split = explode('_',$modName);
412 $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
413 if (count($split)>1) {
414 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
415 }
416 }
417 if ($M_modName) $label.=' ('.$M_modName.')';
418 $label.=': '.$inlabel;
419 return $label;
420 }
421 }
422
423 // Include extension?
424 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']) {
425 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
426 }
427
428
429
430
431
432
433
434
435
436
437
438 // Make instance:
439 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
440 $SOBE->preinit();
441 $SOBE->preprocess();
442 $SOBE->init();
443 $SOBE->main();
444 $SOBE->printContent();
445 ?>