Tons of changes made to the CORE. All scripts has more a less been modified. Primaril...
[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 * 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 $this->doc = t3lib_div::makeInstance('template');
206 $this->doc->backPath = $BACK_PATH;
207 $this->doc->form='<form action="alt_shortcut.php" name="shForm" method="post">';
208 $this->doc->docType='xhtml_trans';
209 $this->doc->divClass='typo3-shortcut';
210 $this->doc->JScode.=$this->doc->wrapScriptTags('
211 function jump(url,modName,mainModName) { //
212 // Clear information about which entry in nav. tree that might have been highlighted.
213 top.fsMod.navFrameHighlightedID = new Array();
214 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
215 top.content.nav_frame.refresh_nav();
216 }
217
218 top.nextLoadModuleUrl = url;
219 top.goToModule(modName);
220 }
221 function editSh(uid) { //
222 document.location="alt_shortcut.php?editShortcut="+uid;
223 }
224 function submitEditPage(id) { //
225 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
226 }
227 function loadEditId(id) { //
228 top.fsMod.recentIds["web"]=id;
229 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
230
231 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
232 top.content.nav_frame.refresh_nav();
233 }
234
235 top.goToModule("web_layout");
236 }
237 ');
238 $this->content.=$this->doc->startPage('Shortcut frame');
239 }
240
241 /**
242 * Main function, creating content in the frame
243 *
244 * @return void
245 */
246 function main() {
247 global $BE_USER,$LANG;
248
249 // Setting groups and globals
250 $this->nGroups=4;
251 $this->nGlobals=5;
252
253 $globalGroups=array(-100);
254 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
255 for($a=1;$a<=$this->nGlobals;$a++) {
256 if ($BE_USER->isAdmin() || strcmp($shortCutGroups['properties'][$a],'')) {
257 $globalGroups[]=-$a;
258 }
259 }
260
261 // Fetching shortcuts to display for this user:
262 $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';
263 $res = mysql(TYPO3_db,$query);
264
265 // Init vars:
266 $this->lines=array();
267 $this->editSC_rec='';
268 $this->selOpt=array();
269 $formerGr='';
270
271 // Traverse shortcuts
272 while($row=mysql_fetch_assoc($res)) {
273 if ($this->editSC && $row['uid']==$this->editSC) {
274 $this->editSC_rec=$row;
275 }
276
277 if (strcmp($formerGr,$row['sc_group'])) {
278 if ($row['sc_group']!=-100) {
279 if ($row['sc_group']>=0) {
280 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
281 $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>';
282 } else {
283 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.abs($row['sc_group']).'</td>';
284 }
285 }
286 }
287
288 $mParts = explode('|',$row['module_name']);
289 $row['module_name']=$mParts[0];
290 $row['M_module_name']=$mParts[1];
291 $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
292 $qParts = parse_url($row['url']);
293
294 $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
295 $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']);
296
297 $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
298 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
299 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
300 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
301 if (trim($row['description'])) {
302 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
303 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd($row['description'],50)).'</option>';
304 }
305 $formerGr=$row['sc_group'];
306 }
307 ksort($this->selOpt);
308 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
309
310 $this->editLoadedFunc();
311 $this->editPageIdFunc();
312
313 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
314 $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);" />'.
315 ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
316 (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,1).'\'</strong>':'').
317 '</td>';
318 } else $editIdCode='';
319
320 $this->content.='
321
322
323 <!--
324 Shortcut Display Table:
325 -->
326 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
327 <tr>
328 '.implode('
329 ',$this->lines).$editIdCode.'
330 </tr>
331 </table>
332
333 ';
334
335 if ($this->theEditRec['uid']) {
336 $this->content.=$this->doc->wrapScriptTags('loadEditId('.$this->theEditRec['uid'].');');
337 }
338 }
339
340 /**
341 * Creates lines for the editing form.
342 *
343 * @return void
344 */
345 function editLoadedFunc() {
346 global $BE_USER,$LANG;
347
348 $this->editLoaded=0;
349 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.
350 $this->editLoaded=1;
351
352 $opt=array();
353 $opt[]='<option value="0"></option>';
354 for($a=1;$a<=$this->nGroups;$a++) {
355 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_group',1).' '.$a.'</option>';
356 }
357 if ($BE_USER->isAdmin()) {
358 for($a=1;$a<=$this->nGlobals;$a++) {
359 $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$a.'</option>';
360 }
361 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$LANG->getLL('shortcut_ALL',1).'</option>';
362 }
363
364 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
365 $manageForm='
366
367
368 <!--
369 Shortcut Editing Form:
370 -->
371 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
372 <tr>
373 <td>&nbsp;&nbsp;</td>
374 <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>
375 <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>
376 <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>
377 <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>
378 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
379 <td><select name="editGroup">'.implode('',$opt).'</select></td>
380 </tr>
381 </table>
382 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
383
384 ';
385 } else $manageForm='';
386 //debug(count($opt));
387 if (!$this->editLoaded && count($this->selOpt)>1) {
388 $this->lines[]='<td>&nbsp;</td>';
389 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
390 }
391 if (count($this->lines)) {
392 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
393 $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);
394 $this->lines[]='<td>'.$manageForm.'</td>';
395 }
396 $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
397 }
398 }
399
400 /**
401 * 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.
402 * Returns void
403 *
404 * @return void
405 */
406 function editPageIdFunc() {
407 global $BE_USER,$LANG;
408
409 if (!t3lib_extMgm::isLoaded('cms')) return;
410
411 // EDIT page:
412 $this->editPage = trim(strtolower($this->editPage));
413 $this->editError='';
414 $this->theEditRec='';
415 if ($this->editPage) {
416 $where=' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
417 if (t3lib_div::testInt($this->editPage)) {
418 $this->theEditRec = t3lib_BEfunc::getRecord ('pages',$this->editPage,'*',$where);
419 } else {
420 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
421 if (is_array($records)) {
422 reset($records);
423 $this->theEditRec = current($records);
424 }
425 }
426 if (!is_array($this->theEditRec) || !$BE_USER->isInWebMount($this->theEditRec['uid'])) {
427 unset($this->theEditRec);
428 $this->editError=$LANG->getLL('shortcut_notEditable');
429 } elseif(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
430 $expandedPages=unserialize($BE_USER->uc['browsePages']);
431 if (!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded')) $expandedPages=array();
432 $rL=t3lib_BEfunc::BEgetRootLine($this->theEditRec['pid']);
433 reset($rL);
434 while(list(,$rLDat)=each($rL)) {
435 $expandedPages[0][$rLDat['uid']]=1;
436 // debug($rLDat['uid']);
437 }
438 $BE_USER->uc['browsePages'] = serialize($expandedPages);
439 $BE_USER->writeUC();
440 }
441 }
442 }
443
444 /**
445 * Outputting the accumulated content to screen
446 *
447 * @return void
448 */
449 function printContent() {
450 $this->content.= $this->doc->endPage();
451 echo $this->content;
452 }
453
454
455
456
457
458
459
460
461
462
463
464 /***************************
465 *
466 * OTHER FUNCTIONS:
467 *
468 ***************************/
469
470 /**
471 * Returns relative filename for icon.
472 *
473 * @param string Absolute filename of the icon
474 * @param string Backpath string to prepend the icon after made relative
475 * @return void
476 */
477 function mIconFilename($Ifilename,$backPath) {
478 if (t3lib_div::isAbsPath($Ifilename)) {
479 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
480 }
481 return $backPath.$Ifilename;
482 }
483
484 /**
485 * Returns icon for shortcut display
486 *
487 * @param string Backend module name
488 * @return string Icon file name
489 */
490 function getIcon($modName) {
491 global $LANG;
492 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab']) {
493 $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
494 } elseif ($modName=='xMOD_alt_doc.php') {
495 $icon = 'gfx/edit2.gif';
496 } elseif ($modName=='xMOD_file_edit.php') {
497 $icon = 'gfx/edit_file.gif';
498 } elseif ($modName=='xMOD_wizard_rte.php') {
499 $icon = 'gfx/edit_rtewiz.gif';
500 } else {
501 $icon = 'gfx/dummy_module.gif';
502 }
503 return $icon;
504 }
505
506 /**
507 * Returns title-label for icon
508 *
509 * @param string In-label
510 * @param string Backend module name (key)
511 * @param string Backend module label (user defined?)
512 * @return string Label for the shortcut item
513 */
514 function itemLabel($inlabel,$modName,$M_modName='') {
515 global $LANG;
516 if (substr($modName,0,5)=='xMOD_') {
517 $label=substr($modName,5);
518 } else {
519 $split = explode('_',$modName);
520 $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
521 if (count($split)>1) {
522 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
523 }
524 }
525 if ($M_modName) $label.=' ('.$M_modName.')';
526 $label.=': '.$inlabel;
527 return $label;
528 }
529 }
530
531 // Include extension?
532 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']) {
533 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
534 }
535
536
537
538
539
540
541
542
543
544
545
546 // Make instance:
547 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
548 $SOBE->preinit();
549 $SOBE->preprocess();
550 $SOBE->init();
551 $SOBE->main();
552 $SOBE->printContent();
553 ?>