* Updated my email address from "kasper@typo3.com" (which is closed and will stay...
[Packages/TYPO3.CMS.git] / typo3 / alt_shortcut.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@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 <kasperYYYY@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 * 200: function init()
48 * 234: function main()
49 * 335: function editLoadedFunc()
50 * 396: function editPageIdFunc()
51 * 438: function printContent()
52 *
53 * SECTION: OTHER FUNCTIONS:
54 * 466: function mIconFilename($Ifilename,$backPath)
55 * 479: function getIcon($modName)
56 * 503: 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 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
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 <kasperYYYY@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 $editName;
91 var $editGroup;
92 var $whichItem;
93
94 // Internal, static:
95 var $loadModules; // Modules object
96 var $doc; // Document template object
97 var $nGroups; // Number of groups
98 var $nGlobals; // Number of globals
99
100 // Internal, dynamic:
101 var $content; // Accumulation of output HTML (string)
102 var $lines; // Accumulation of table cells (array)
103
104 var $editLoaded; // Flag for defining whether we are editing
105 var $editError; // Can contain edit error message
106 var $editPath; // Set to the record path of the record being edited.
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::_GP('modName');
123 $this->M_modName = t3lib_div::_GP('motherModName');
124 $this->URL = t3lib_div::_GP('URL');
125 $this->editSC = t3lib_div::_GP('editShortcut');
126
127 $this->deleteCategory = t3lib_div::_GP('deleteCategory');
128 $this->editPage = t3lib_div::_GP('editPage');
129 $this->editName = t3lib_div::_GP('editName');
130 $this->editGroup = t3lib_div::_GP('editGroup');
131 $this->whichItem = t3lib_div::_GP('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;
145
146 // Adding a shortcut being set from another frame
147 if ($this->modName && $this->URL) {
148 $fields_values = array(
149 'userid' => $BE_USER->user['uid'],
150 'module_name' => $this->modName.'|'.$this->M_modName,
151 'url' => $this->URL,
152 'sorting' => time()
153 );
154 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fields_values);
155 }
156
157 // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
158 $addUSERWhere = (!$BE_USER->isAdmin()?' AND userid='.intval($BE_USER->user['uid']):'');
159
160 // Deleting shortcuts:
161 if (strcmp($this->deleteCategory,'')) {
162 if (t3lib_div::testInt($this->deleteCategory)) {
163 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'sc_group='.intval($this->deleteCategory).$addUSERWhere);
164 }
165 }
166
167 // If other changes in post-vars:
168 if (is_array($_POST)) {
169 // Saving:
170 if (isset($_POST['_savedok_x']) || isset($_POST['_saveclosedok_x'])) {
171 $fields_values = array(
172 'description' => $this->editName,
173 'sc_group' => intval($this->editGroup)
174 );
175 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin()) {
176 $fields_values['sc_group']=0;
177 }
178
179 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere, $fields_values);
180 }
181 // If save without close, keep the session going...
182 if (isset($_POST['_savedok_x'])) {
183 $this->editSC=$this->whichItem;
184 }
185 // Deleting a single shortcut ?
186 if (isset($_POST['_deletedok_x'])) {
187 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere);
188
189 if (!$this->editSC) $this->editSC=-1; // Just to have the checkbox set...
190 }
191 }
192
193 }
194
195 /**
196 * Initialize (page output)
197 *
198 * @return void
199 */
200 function init() {
201 global $BACK_PATH;
202
203 $this->doc = t3lib_div::makeInstance('template');
204 $this->doc->backPath = $BACK_PATH;
205 $this->doc->form='<form action="alt_shortcut.php" name="shForm" method="post">';
206 $this->doc->docType='xhtml_trans';
207 $this->doc->divClass='typo3-shortcut';
208 $this->doc->JScode.=$this->doc->wrapScriptTags('
209 function jump(url,modName,mainModName) { //
210 // Clear information about which entry in nav. tree that might have been highlighted.
211 top.fsMod.navFrameHighlightedID = new Array();
212 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
213 top.content.nav_frame.refresh_nav();
214 }
215
216 top.nextLoadModuleUrl = url;
217 top.goToModule(modName);
218 }
219 function editSh(uid) { //
220 document.location="alt_shortcut.php?editShortcut="+uid;
221 }
222 function submitEditPage(id) { //
223 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
224 }
225 ');
226 $this->content.=$this->doc->startPage('Shortcut frame');
227 }
228
229 /**
230 * Main function, creating content in the frame
231 *
232 * @return void
233 */
234 function main() {
235 global $BE_USER,$LANG;
236
237 // Setting groups and globals
238 $this->nGroups=4;
239 $this->nGlobals=5;
240
241 $globalGroups=array(-100);
242 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
243 for($a=1;$a<=$this->nGlobals;$a++) {
244 if ($BE_USER->isAdmin() || strcmp($shortCutGroups['properties'][$a],'')) {
245 $globalGroups[]=-$a;
246 }
247 }
248
249 // Fetching shortcuts to display for this user:
250 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_be_shortcuts', '((userid='.$BE_USER->user['uid'].' AND sc_group>=0) OR sc_group IN ('.implode(',',$globalGroups).'))', '', 'sc_group,sorting');
251
252 // Init vars:
253 $this->lines=array();
254 $this->editSC_rec='';
255 $this->selOpt=array();
256 $formerGr='';
257
258 // Traverse shortcuts
259 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
260 if ($this->editSC && $row['uid']==$this->editSC) {
261 $this->editSC_rec=$row;
262 }
263
264 if (strcmp($formerGr,$row['sc_group'])) {
265 if ($row['sc_group']!=-100) {
266 if ($row['sc_group']>=0) {
267 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
268 $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>';
269 } else {
270 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.abs($row['sc_group']).'</td>';
271 }
272 }
273 }
274
275 $mParts = explode('|',$row['module_name']);
276 $row['module_name']=$mParts[0];
277 $row['M_module_name']=$mParts[1];
278 $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
279 $qParts = parse_url($row['url']);
280
281 $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
282 $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']);
283
284 $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
285 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
286 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
287 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
288 if (trim($row['description'])) {
289 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
290 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['description'],50)).'</option>';
291 }
292 $formerGr=$row['sc_group'];
293 }
294 ksort($this->selOpt);
295 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
296
297 $this->editLoadedFunc();
298 $this->editPageIdFunc();
299
300 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
301 $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);" />'.
302 ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
303 (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,1).'\'</strong> ('.htmlspecialchars($this->editPath).')':'').
304 '</td>';
305 } else $editIdCode = '';
306
307 // Adding CSH:
308 $editIdCode.= '<td>&nbsp;'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'shortcuts', $GLOBALS['BACK_PATH'],'',TRUE).'</td>';
309
310 $this->content.='
311
312
313 <!--
314 Shortcut Display Table:
315 -->
316 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
317 <tr>
318 '.implode('
319 ',$this->lines).$editIdCode.'
320 </tr>
321 </table>
322
323 ';
324
325 if ($this->theEditRec['uid']) {
326 $this->content.=$this->doc->wrapScriptTags('top.loadEditId('.$this->theEditRec['uid'].');');
327 }
328 }
329
330 /**
331 * Creates lines for the editing form.
332 *
333 * @return void
334 */
335 function editLoadedFunc() {
336 global $BE_USER,$LANG;
337
338 $this->editLoaded=0;
339 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.
340 $this->editLoaded=1;
341
342 $opt=array();
343 $opt[]='<option value="0"></option>';
344 for($a=1;$a<=$this->nGroups;$a++) {
345 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_group',1).' '.$a.'</option>';
346 }
347 if ($BE_USER->isAdmin()) {
348 for($a=1;$a<=$this->nGlobals;$a++) {
349 $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$a.'</option>';
350 }
351 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$LANG->getLL('shortcut_ALL',1).'</option>';
352 }
353
354 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
355 $manageForm='
356
357
358 <!--
359 Shortcut Editing Form:
360 -->
361 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
362 <tr>
363 <td>&nbsp;&nbsp;</td>
364 <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>
365 <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>
366 <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>
367 <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>
368 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
369 <td><select name="editGroup">'.implode('',$opt).'</select></td>
370 </tr>
371 </table>
372 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
373
374 ';
375 } else $manageForm='';
376 //debug(count($opt));
377 if (!$this->editLoaded && count($this->selOpt)>1) {
378 $this->lines[]='<td>&nbsp;</td>';
379 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
380 }
381 if (count($this->lines)) {
382 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
383 $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);
384 $this->lines[]='<td>'.$manageForm.'</td>';
385 }
386 $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
387 }
388 }
389
390 /**
391 * 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.
392 * Returns void
393 *
394 * @return void
395 */
396 function editPageIdFunc() {
397 global $BE_USER,$LANG;
398
399 if (!t3lib_extMgm::isLoaded('cms')) return;
400
401 // EDIT page:
402 $this->editPage = trim(strtolower($this->editPage));
403 $this->editError = '';
404 $this->theEditRec = '';
405 if ($this->editPage) {
406 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
407 if (t3lib_div::testInt($this->editPage)) {
408 $this->theEditRec = t3lib_BEfunc::getRecord ('pages',$this->editPage,'*',$where);
409 } else {
410 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
411 if (is_array($records)) {
412 reset($records);
413 $this->theEditRec = current($records);
414 }
415 }
416 if (!is_array($this->theEditRec) || !$BE_USER->isInWebMount($this->theEditRec['uid'])) {
417 unset($this->theEditRec);
418 $this->editError=$LANG->getLL('shortcut_notEditable');
419 } else {
420 // Visual path set:
421 $perms_clause = $BE_USER->getPagePermsClause(1);
422 $this->editPath = t3lib_BEfunc::getRecordPath($this->theEditRec['pid'], $perms_clause, 30);
423
424 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
425
426 // Expanding page tree:
427 t3lib_BEfunc::openPageTree($this->theEditRec['pid'],!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
428 }
429 }
430 }
431 }
432
433 /**
434 * Outputting the accumulated content to screen
435 *
436 * @return void
437 */
438 function printContent() {
439 $this->content.= $this->doc->endPage();
440 echo $this->content;
441 }
442
443
444
445
446
447
448
449
450
451
452
453 /***************************
454 *
455 * OTHER FUNCTIONS:
456 *
457 ***************************/
458
459 /**
460 * Returns relative filename for icon.
461 *
462 * @param string Absolute filename of the icon
463 * @param string Backpath string to prepend the icon after made relative
464 * @return void
465 */
466 function mIconFilename($Ifilename,$backPath) {
467 if (t3lib_div::isAbsPath($Ifilename)) {
468 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
469 }
470 return $backPath.$Ifilename;
471 }
472
473 /**
474 * Returns icon for shortcut display
475 *
476 * @param string Backend module name
477 * @return string Icon file name
478 */
479 function getIcon($modName) {
480 global $LANG;
481 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab']) {
482 $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
483 } elseif ($modName=='xMOD_alt_doc.php') {
484 $icon = 'gfx/edit2.gif';
485 } elseif ($modName=='xMOD_file_edit.php') {
486 $icon = 'gfx/edit_file.gif';
487 } elseif ($modName=='xMOD_wizard_rte.php') {
488 $icon = 'gfx/edit_rtewiz.gif';
489 } else {
490 $icon = 'gfx/dummy_module.gif';
491 }
492 return $icon;
493 }
494
495 /**
496 * Returns title-label for icon
497 *
498 * @param string In-label
499 * @param string Backend module name (key)
500 * @param string Backend module label (user defined?)
501 * @return string Label for the shortcut item
502 */
503 function itemLabel($inlabel,$modName,$M_modName='') {
504 global $LANG;
505 if (substr($modName,0,5)=='xMOD_') {
506 $label=substr($modName,5);
507 } else {
508 $split = explode('_',$modName);
509 $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
510 if (count($split)>1) {
511 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
512 }
513 }
514 if ($M_modName) $label.=' ('.$M_modName.')';
515 $label.=': '.$inlabel;
516 return $label;
517 }
518 }
519
520 // Include extension?
521 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']) {
522 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
523 }
524
525
526
527
528
529
530
531
532
533
534
535 // Make instance:
536 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
537 $SOBE->preinit();
538 $SOBE->preprocess();
539 $SOBE->init();
540 $SOBE->main();
541 $SOBE->printContent();
542 ?>