Updated copyright notices to show "2004"
[Packages/TYPO3.CMS.git] / typo3 / alt_shortcut.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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 * Appears in the bottom frame of the backend frameset.
30 * Provides links to registered shortcuts
31 * If the 'cms' extension is loaded you will also have a field for entering page id/alias which will be found/edited
32 *
33 * $Id$
34 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
35 * XHTML compliant output
36 *
37 * @author Kasper Skaarhoj <kasper@typo3.com>
38 */
39 /**
40 * [CLASS/FUNCTION INDEX of SCRIPT]
41 *
42 *
43 *
44 * 82: class SC_alt_shortcut
45 * 118: function preinit()
46 * 143: function preprocess()
47 * 202: function init()
48 * 237: function main()
49 * 336: function editLoadedFunc()
50 * 397: function editPageIdFunc()
51 * 440: function printContent()
52 *
53 * SECTION: OTHER FUNCTIONS:
54 * 468: function mIconFilename($Ifilename,$backPath)
55 * 481: function getIcon($modName)
56 * 505: function itemLabel($inlabel,$modName,$M_modName='')
57 *
58 * TOTAL FUNCTIONS: 10
59 * (This index is automatically created/updated by the extension "extdeveval")
60 *
61 */
62
63
64 require ('init.php');
65 require ('template.php');
66 include ('sysext/lang/locallang_misc.php');
67 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
68 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
69
70
71
72
73
74
75 /**
76 * Script Class for the shortcut frame, bottom frame of the backend frameset
77 *
78 * @author Kasper Skaarhoj <kasper@typo3.com>
79 * @package TYPO3
80 * @subpackage core
81 */
82 class SC_alt_shortcut {
83
84 // Internal, static: GPvar
85 var $modName;
86 var $M_modName;
87 var $URL;
88 var $editSC;
89 var $deleteCategory;
90 var $editPage;
91 var $editName;
92 var $editGroup;
93 var $whichItem;
94
95 // Internal, static:
96 var $loadModules; // Modules object
97 var $doc; // Document template object
98 var $nGroups; // Number of groups
99 var $nGlobals; // Number of globals
100
101 // Internal, dynamic:
102 var $content; // Accumulation of output HTML (string)
103 var $lines; // Accumulation of table cells (array)
104
105 var $editLoaded; // Flag for defining whether we are editing
106 var $editError; // Can contain edit error message
107 var $editSC_rec; // Holds the shortcut record when editing
108 var $theEditRec; // Page record to be edited
109 var $editPage; // Page alias or id to be edited
110 var $selOpt; // Select options.
111
112
113 /**
114 * Pre-initialization - setting input variables for storing shortcuts etc.
115 *
116 * @return void
117 */
118 function preinit() {
119 global $TBE_MODULES;
120
121 // Setting GPvars:
122 $this->modName = t3lib_div::GPvar('modName');
123 $this->M_modName = t3lib_div::GPvar('motherModName');
124 $this->URL = t3lib_div::GPvar('URL');
125 $this->editSC = t3lib_div::GPvar('editShortcut');
126
127 $this->deleteCategory = t3lib_div::GPvar('deleteCategory');
128 $this->editPage = t3lib_div::GPvar('editPage');
129 $this->editName = t3lib_div::GPvar('editName');
130 $this->editGroup = t3lib_div::GPvar('editGroup');
131 $this->whichItem = t3lib_div::GPvar('whichItem');
132
133 // Creating modules object
134 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
135 $this->loadModules->load($TBE_MODULES);
136 }
137
138 /**
139 * Adding shortcuts, editing shortcuts etc.
140 *
141 * @return void
142 */
143 function preprocess() {
144 global $BE_USER,$HTTP_POST_VARS;
145
146 // Adding a shortcut being set from another frame
147 if ($this->modName && $this->URL) {
148 $fields_values=array();
149 $fields_values['userid']=$BE_USER->user['uid'];
150 $fields_values['module_name']=$this->modName.'|'.$this->M_modName;
151 $fields_values['url']=$this->URL;
152 $fields_values['sorting']=time();
153 $query = t3lib_BEfunc::DBcompileInsert('sys_be_shortcuts',$fields_values);
154 $res = mysql(TYPO3_db,$query);
155 echo mysql_error();
156 }
157
158 // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
159 $addUSERWhere = (!$BE_USER->isAdmin()?' AND userid='.intval($BE_USER->user['uid']):'');
160
161 // Deleting shortcuts:
162 if (strcmp($this->deleteCategory,'')) {
163 if (t3lib_div::testInt($this->deleteCategory)) {
164 $q = 'DELETE FROM sys_be_shortcuts WHERE sc_group='.$this->deleteCategory.$addUSERWhere;
165 $res=mysql(TYPO3_db,$q);
166 }
167 }
168
169 // If other changes in post-vars:
170 if ($HTTP_POST_VARS) {
171 // Saving:
172 if (isset($HTTP_POST_VARS['_savedok_x']) || isset($HTTP_POST_VARS['_saveclosedok_x'])) {
173 $fields_values=array();
174 $fields_values['description']=$this->editName;
175 $fields_values['sc_group']=intval($this->editGroup);
176 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin()) {
177 $fields_values['sc_group']=0;
178 }
179
180 $q = t3lib_BEfunc::DBcompileUpdate('sys_be_shortcuts','uid='.intval($this->whichItem).$addUSERWhere,$fields_values);
181 $res=mysql(TYPO3_db,$q);
182 }
183 // If save without close, keep the session going...
184 if (isset($HTTP_POST_VARS['_savedok_x'])) {
185 $this->editSC=$this->whichItem;
186 }
187 // Deleting a single shortcut ?
188 if (isset($HTTP_POST_VARS['_deletedok_x'])) {
189 $q = 'DELETE FROM sys_be_shortcuts WHERE uid='.intval($this->whichItem).$addUSERWhere;
190 $res=mysql(TYPO3_db,$q);
191 if (!$this->editSC) $this->editSC=-1; // Just to have the checkbox set...
192 }
193 }
194
195 }
196
197 /**
198 * Initialize (page output)
199 *
200 * @return void
201 */
202 function init() {
203 global $BACK_PATH;
204
205 // If another page module was specified, replace the default Page module with the new one
206 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
207 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
208
209 $this->doc = t3lib_div::makeInstance('template');
210 $this->doc->backPath = $BACK_PATH;
211 $this->doc->form='<form action="alt_shortcut.php" name="shForm" method="post">';
212 $this->doc->docType='xhtml_trans';
213 $this->doc->divClass='typo3-shortcut';
214 $this->doc->JScode.=$this->doc->wrapScriptTags('
215 function jump(url,modName,mainModName) { //
216 // Clear information about which entry in nav. tree that might have been highlighted.
217 top.fsMod.navFrameHighlightedID = new Array();
218 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
219 top.content.nav_frame.refresh_nav();
220 }
221
222 top.nextLoadModuleUrl = url;
223 top.goToModule(modName);
224 }
225 function editSh(uid) { //
226 document.location="alt_shortcut.php?editShortcut="+uid;
227 }
228 function submitEditPage(id) { //
229 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
230 }
231 function loadEditId(id) { //
232 top.fsMod.recentIds["web"]=id;
233 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
234
235 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
236 top.content.nav_frame.refresh_nav();
237 }
238
239 top.goToModule("'.$pageModule.'");
240 }
241 ');
242 $this->content.=$this->doc->startPage('Shortcut frame');
243 }
244
245 /**
246 * Main function, creating content in the frame
247 *
248 * @return void
249 */
250 function main() {
251 global $BE_USER,$LANG;
252
253 // Setting groups and globals
254 $this->nGroups=4;
255 $this->nGlobals=5;
256
257 $globalGroups=array(-100);
258 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
259 for($a=1;$a<=$this->nGlobals;$a++) {
260 if ($BE_USER->isAdmin() || strcmp($shortCutGroups['properties'][$a],'')) {
261 $globalGroups[]=-$a;
262 }
263 }
264
265 // Fetching shortcuts to display for this user:
266 $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';
267 $res = mysql(TYPO3_db,$query);
268
269 // Init vars:
270 $this->lines=array();
271 $this->editSC_rec='';
272 $this->selOpt=array();
273 $formerGr='';
274
275 // Traverse shortcuts
276 while($row=mysql_fetch_assoc($res)) {
277 if ($this->editSC && $row['uid']==$this->editSC) {
278 $this->editSC_rec=$row;
279 }
280
281 if (strcmp($formerGr,$row['sc_group'])) {
282 if ($row['sc_group']!=-100) {
283 if ($row['sc_group']>=0) {
284 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
285 $this->lines[]='<td>&nbsp;</td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.abs($row['sc_group']).'</a></td>';
286 } else {
287 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.abs($row['sc_group']).'</td>';
288 }
289 }
290 }
291
292 $mParts = explode('|',$row['module_name']);
293 $row['module_name']=$mParts[0];
294 $row['M_module_name']=$mParts[1];
295 $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
296 $qParts = parse_url($row['url']);
297
298 $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
299 $titleA = $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']);
300
301 $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
302 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
303 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
304 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
305 if (trim($row['description'])) {
306 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
307 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd($row['description'],50)).'</option>';
308 }
309 $formerGr=$row['sc_group'];
310 }
311 ksort($this->selOpt);
312 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
313
314 $this->editLoadedFunc();
315 $this->editPageIdFunc();
316
317 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
318 $editIdCode = '<td nowrap="nowrap">'.$LANG->getLL('shortcut_editID',1).': <input type="text" value="'.($this->editError?htmlspecialchars($this->editPage):'').'" name="editPage"'.$this->doc->formWidth(5).' onchange="submitEditPage(this.value);" />'.
319 ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
320 (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,1).'\'</strong>':'').
321 '</td>';
322 } else $editIdCode='';
323
324 $this->content.='
325
326
327 <!--
328 Shortcut Display Table:
329 -->
330 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
331 <tr>
332 '.implode('
333 ',$this->lines).$editIdCode.'
334 </tr>
335 </table>
336
337 ';
338
339 if ($this->theEditRec['uid']) {
340 $this->content.=$this->doc->wrapScriptTags('loadEditId('.$this->theEditRec['uid'].');');
341 }
342 }
343
344 /**
345 * Creates lines for the editing form.
346 *
347 * @return void
348 */
349 function editLoadedFunc() {
350 global $BE_USER,$LANG;
351
352 $this->editLoaded=0;
353 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.
354 $this->editLoaded=1;
355
356 $opt=array();
357 $opt[]='<option value="0"></option>';
358 for($a=1;$a<=$this->nGroups;$a++) {
359 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_group',1).' '.$a.'</option>';
360 }
361 if ($BE_USER->isAdmin()) {
362 for($a=1;$a<=$this->nGlobals;$a++) {
363 $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$a.'</option>';
364 }
365 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$LANG->getLL('shortcut_ALL',1).'</option>';
366 }
367
368 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
369 $manageForm='
370
371
372 <!--
373 Shortcut Editing Form:
374 -->
375 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
376 <tr>
377 <td>&nbsp;&nbsp;</td>
378 <td><input type="image" class="c-inputButton" name="_savedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->getLL('shortcut_save',1).'" /></td>
379 <td><input type="image" class="c-inputButton" name="_saveclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->getLL('shortcut_saveClose',1).'" /></td>
380 <td><input type="image" class="c-inputButton" name="_closedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','').' title="'.$LANG->getLL('shortcut_close',1).'" /></td>
381 <td><input type="image" class="c-inputButton" name="_deletedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/deletedok.gif','').' title="'.$LANG->getLL('shortcut_delete',1).'" /></td>
382 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
383 <td><select name="editGroup">'.implode('',$opt).'</select></td>
384 </tr>
385 </table>
386 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
387
388 ';
389 } else $manageForm='';
390 //debug(count($opt));
391 if (!$this->editLoaded && count($this->selOpt)>1) {
392 $this->lines[]='<td>&nbsp;</td>';
393 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
394 }
395 if (count($this->lines)) {
396 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
397 $this->lines=array_merge(array('<td><input type="checkbox" name="editShortcut_check" value="1"'.($this->editSC?' checked="checked"':'').' />'.$LANG->getLL('shortcut_edit',1).'&nbsp;</td>'),$this->lines);
398 $this->lines[]='<td>'.$manageForm.'</td>';
399 }
400 $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
401 }
402 }
403
404 /**
405 * 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.
406 * Returns void
407 *
408 * @return void
409 */
410 function editPageIdFunc() {
411 global $BE_USER,$LANG;
412
413 if (!t3lib_extMgm::isLoaded('cms')) return;
414
415 // EDIT page:
416 $this->editPage = trim(strtolower($this->editPage));
417 $this->editError='';
418 $this->theEditRec='';
419 if ($this->editPage) {
420 $where=' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
421 if (t3lib_div::testInt($this->editPage)) {
422 $this->theEditRec = t3lib_BEfunc::getRecord ('pages',$this->editPage,'*',$where);
423 } else {
424 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
425 if (is_array($records)) {
426 reset($records);
427 $this->theEditRec = current($records);
428 }
429 }
430 if (!is_array($this->theEditRec) || !$BE_USER->isInWebMount($this->theEditRec['uid'])) {
431 unset($this->theEditRec);
432 $this->editError=$LANG->getLL('shortcut_notEditable');
433 } elseif(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
434 $expandedPages=unserialize($BE_USER->uc['browsePages']);
435 if (!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded')) $expandedPages=array();
436 $rL=t3lib_BEfunc::BEgetRootLine($this->theEditRec['pid']);
437 reset($rL);
438 while(list(,$rLDat)=each($rL)) {
439 $expandedPages[0][$rLDat['uid']]=1;
440 // debug($rLDat['uid']);
441 }
442 $BE_USER->uc['browsePages'] = serialize($expandedPages);
443 $BE_USER->writeUC();
444 }
445 }
446 }
447
448 /**
449 * Outputting the accumulated content to screen
450 *
451 * @return void
452 */
453 function printContent() {
454 $this->content.= $this->doc->endPage();
455 echo $this->content;
456 }
457
458
459
460
461
462
463
464
465
466
467
468 /***************************
469 *
470 * OTHER FUNCTIONS:
471 *
472 ***************************/
473
474 /**
475 * Returns relative filename for icon.
476 *
477 * @param string Absolute filename of the icon
478 * @param string Backpath string to prepend the icon after made relative
479 * @return void
480 */
481 function mIconFilename($Ifilename,$backPath) {
482 if (t3lib_div::isAbsPath($Ifilename)) {
483 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
484 }
485 return $backPath.$Ifilename;
486 }
487
488 /**
489 * Returns icon for shortcut display
490 *
491 * @param string Backend module name
492 * @return string Icon file name
493 */
494 function getIcon($modName) {
495 global $LANG;
496 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab']) {
497 $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
498 } elseif ($modName=='xMOD_alt_doc.php') {
499 $icon = 'gfx/edit2.gif';
500 } elseif ($modName=='xMOD_file_edit.php') {
501 $icon = 'gfx/edit_file.gif';
502 } elseif ($modName=='xMOD_wizard_rte.php') {
503 $icon = 'gfx/edit_rtewiz.gif';
504 } else {
505 $icon = 'gfx/dummy_module.gif';
506 }
507 return $icon;
508 }
509
510 /**
511 * Returns title-label for icon
512 *
513 * @param string In-label
514 * @param string Backend module name (key)
515 * @param string Backend module label (user defined?)
516 * @return string Label for the shortcut item
517 */
518 function itemLabel($inlabel,$modName,$M_modName='') {
519 global $LANG;
520 if (substr($modName,0,5)=='xMOD_') {
521 $label=substr($modName,5);
522 } else {
523 $split = explode('_',$modName);
524 $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
525 if (count($split)>1) {
526 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
527 }
528 }
529 if ($M_modName) $label.=' ('.$M_modName.')';
530 $label.=': '.$inlabel;
531 return $label;
532 }
533 }
534
535 // Include extension?
536 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']) {
537 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
538 }
539
540
541
542
543
544
545
546
547
548
549
550 // Make instance:
551 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
552 $SOBE->preinit();
553 $SOBE->preprocess();
554 $SOBE->init();
555 $SOBE->main();
556 $SOBE->printContent();
557 ?>