* Labels moved to locallang_user_mod_ws.xml
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / workspaceforms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 * Module: Workspace manager
29 *
30 * $Id$
31 *
32 * @author Dmitry Dulepov <typo3@fm-world.ru>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 86: class SC_mod_user_ws_workspaceForms extends t3lib_SCbase
40 *
41 * SECTION: PUBLIC MODULE METHODS
42 * 115: function init()
43 * 151: function main()
44 * 200: function printContent()
45 *
46 * SECTION: PRIVATE FUNCTIONS
47 * 224: function initTCEForms()
48 * 251: function getModuleParameters()
49 * 269: function getTitle()
50 * 288: function buildForm()
51 * 297: function buildEditForm()
52 * 349: function buildNewForm()
53 * 394: function createButtons()
54 * 421: function getOwnerUser($uid)
55 * 447: function processData()
56 *
57 * TOTAL FUNCTIONS: 12
58 * (This index is automatically created/updated by the extension "extdeveval")
59 *
60 */
61
62
63 // Initialize module:
64 unset($MCONF);
65 require('conf.php');
66 require($BACK_PATH.'init.php');
67 require($BACK_PATH.'template.php');
68 $BE_USER->modAccess($MCONF,1);
69
70 // Include libraries of various kinds used inside:
71 $LANG->includeLLFile('EXT:lang/locallang_mod_user_ws.xml');
72 require_once(PATH_t3lib.'class.t3lib_scbase.php');
73 //require_once(PATH_typo3.'mod/user/ws/class.wslib.php');
74 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
75 require_once(PATH_t3lib.'class.t3lib_tceforms.php');
76 require_once (PATH_t3lib.'class.t3lib_transferdata.php');
77 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
78
79 /**
80 * Module: Workspace forms for editing/creating workspaces.
81 *
82 * @author Dmitry Dulepov <typo3@fm-world.ru>
83 * @package TYPO3
84 * @subpackage core
85 */
86 class SC_mod_user_ws_workspaceForms extends t3lib_SCbase {
87 // Default variables for backend modules
88 var $MCONF = array(); // Module configuration
89 var $MOD_MENU = array(); // Module menu items
90 var $MOD_SETTINGS = array(); // Module session settings
91 var $doc; // Document Template Object
92 var $content; // Accumulated content
93
94 // internal variables
95 var $isEditAction = false; // true if about to edit workspace
96 var $workspaceId; // ID of the workspace that we will edit. Set only if $isEditAction is true.
97 var $tceforms; // An instance of t3lib_TCEForms
98
99
100
101
102
103
104 /*************************
105 *
106 * PUBLIC MODULE METHODS
107 *
108 *************************/
109
110 /**
111 * Initializes the module. See <code>t3lib_SCbase::init()</code> for more information.
112 *
113 * @return void
114 */
115 function init() {
116 // Setting module configuration:
117 $this->MCONF = $GLOBALS['MCONF'];
118
119 // Initialize Document Template object:
120 $this->doc = t3lib_div::makeInstance('mediumDoc');
121 $this->doc->backPath = $GLOBALS['BACK_PATH'];
122 $this->doc->docType = 'xhtml_trans';
123 $this->doc->form = '<form action="' . t3lib_div::getIndpEnv('SCRIPT_NAME').'" method="post" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'" name="editform" onsubmit="return TBE_EDITOR_checkSubmit(1);">';
124
125 $CMparts = $this->doc->getContextMenuCode();
126 $this->doc->JScode.= $CMparts[0];
127 $this->doc->JScode.= $this->doc->getDynTabMenuJScode();
128 $this->doc->bodyTagAdditions = $CMparts[1];
129 $this->doc->postCode.= $CMparts[2];
130
131 // Parent initialization:
132 t3lib_SCbase::init();
133 }
134
135
136
137
138
139
140
141
142
143
144
145 /**
146 * Creates module content.
147 *
148 * @return void
149 */
150 function main() {
151 global $LANG;
152
153 // see what we have to do and get parameters (call before processing data!!!)
154 $this->getModuleParameters();
155
156 $hasAccess = (
157 $GLOBALS['BE_USER']->isAdmin() ||
158 0 != ($GLOBALS['BE_USER']->groupData['workspace_perms'] & 4) ||
159 ($this->isEditAction && $this->checkWorkspaceAccess())
160 );
161
162 if (!$hasAccess) {
163 $title = $this->getTitle();
164 $this->content .= $this->doc->startPage($title);
165 $this->content .= $this->doc->header($title);
166 $this->content .= $this->doc->spacer(5);
167 $this->content .= $LANG->getLL($this->isEditAction ? 'edit_workspace_no_permission' : 'create_workspace_no_permission');
168 $this->content .= $this->doc->spacer(5);
169 $goBack = $GLOBALS['LANG']->getLL('edit_workspace_go_back');
170 $this->content .= '<img ' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/goback.gif', 'width="14" height="14"') . ' alt="' . $goBack . '" align="middle" hspace="2" />' .
171 '<a href="javascript:history.back()">' .
172 $goBack .
173 '</a>';
174 $this->content .= $this->doc->endPage();
175 return;
176 }
177
178 // process submission (this may override action and workspace ID!)
179 if (t3lib_div::_GP('submit_x') != '') {
180 $this->processData();
181 // if 'Save&Close' was pressed, redirect to main module script
182 if (t3lib_div::_GP('_saveandclosedok_x')) {
183 // `n` below is to prevent caching
184 header('Location: ' . t3lib_div::locationHeaderUrl('index.php?n=' . uniqid('')));
185 exit();
186 }
187 }
188
189 $this->initTCEForms();
190
191 //
192 // start page
193 //
194 $title = $this->getTitle();
195 $this->content .= $this->doc->startPage($title);
196 $this->content .= $this->doc->header($title);
197 $this->content .= $this->doc->spacer(5);
198
199 //
200 // page content
201 //
202 $this->content .= $this->tceforms->printNeededJSFunctions_top();
203 $this->content .= $this->buildForm();
204 $this->content .= $this->tceforms->printNeededJSFunctions();
205
206 //
207 // end page
208 //
209 $this->content .= $this->doc->endPage();
210 }
211
212
213
214
215
216
217
218
219
220 /**
221 * Outputs module content to the browser.
222 *
223 * @return void
224 */
225 function printContent() {
226 echo $this->content;
227 }
228
229
230
231
232
233
234
235
236
237
238 /*************************
239 *
240 * PRIVATE FUNCTIONS
241 *
242 *************************/
243
244 /**
245 * Initializes <code>t3lib_TCEform</code> class for use in this module.
246 *
247 * @return void
248 */
249 function initTCEForms() {
250 $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
251 $this->tceforms->initDefaultBEMode();
252 $this->tceforms->backPath = $GLOBALS['BACK_PATH'];
253 $this->tceforms->doSaveFieldName = 'doSave';
254 $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : ''; // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
255 $this->tceforms->returnUrl = $this->R_URI;
256 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
257 $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
258 $this->tceforms->enableClickMenu = true;
259 $this->tceforms->enableTabMenu = true;
260
261 // Setting external variables:
262 if ($GLOBALS['BE_USER']->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions']) $this->tceforms->edit_showFieldHelp='text';
263 }
264
265
266
267
268
269
270
271 /**
272 * Retrieves module parameters from the <code>t3lib_div::_GP</code>. The following arguments are retrieved: <ul><li>action</li><li>workspace id (if action == 'edit')</li></ul>
273 *
274 * @return void
275 */
276 function getModuleParameters(){
277 $this->isEditAction = (t3lib_div::_GP('action') == 'edit');
278 if ($this->isEditAction) {
279 $this->workspaceId = intval(t3lib_div::_GP('wkspId'));
280 }
281 }
282
283
284
285
286
287
288
289 /**
290 * Retrieves a title of the module according to action.
291 *
292 * @return string A title for the module
293 */
294 function getTitle() {
295 $label = ($this->isEditAction ? 'edit_workspace_title_edit' : 'edit_workspace_title_new');
296 return $GLOBALS['LANG']->getLL($label);
297 }
298
299
300
301
302
303
304
305
306
307
308 /**
309 * Creates form for workspace. This function is a wrapper around <code>buildEditForm()</code> and <code>buildNewForm()</code>.
310 *
311 * @return string Generated form
312 */
313 function buildForm() {
314 return $this->isEditAction ? $this->buildEditForm() : $this->buildNewForm();
315 }
316
317 /**
318 * Creates a form for editing workspace. Parts were adopted from <code>alt_doc.php</code>.
319 *
320 * @return string Generated form
321 */
322 function buildEditForm() {
323 $content = '';
324 $table = 'sys_workspace';
325 $prevPageID = '';
326 $trData = t3lib_div::makeInstance('t3lib_transferData');
327 $trData->addRawData = TRUE;
328 $trData->defVals = $this->defVals;
329 $trData->lockRecords=1;
330 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
331 $trData->prevPageID = $prevPageID;
332 $trData->fetchRecord($table, $this->workspaceId, '');
333 reset($trData->regTableItems_data);
334 $rec = current($trData->regTableItems_data);
335
336 // Setting variables in TCEforms object:
337 $this->tceforms->hiddenFieldList = '';
338 // Register default language labels, if any:
339 $this->tceforms->registerDefaultLanguageData($table,$rec);
340
341 $this->fixVariousTCAFields();
342 if (!$GLOBALS['BE_USER']->isAdmin()) {
343 // Non-admins cannot select users from the root. We "fix" it for them.
344 $this->fixTCAUserField('adminusers');
345 $this->fixTCAUserField('members');
346 $this->fixTCAUserField('reviewers');
347 }
348
349 // Create form for the record (either specific list of fields or the whole record):
350 $form = '';
351 // $form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec);
352 // $form .= $this->doc->spacer(5);
353 $form .= $this->tceforms->getMainFields($table,$rec);
354 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
355 $form .= '<input type="hidden" name="submit_x" value="1" />';
356 $form .= '<input type="hidden" name="returnUrl" value="index.php" />';
357 $form .= '<input type="hidden" name="action" value="edit" />';
358 $form .= '<input type="hidden" name="closeDoc" value="0" />';
359 $form .= '<input type="hidden" name="doSave" value="0" />';
360 $form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
361 $form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';
362 $form .= '<input type="hidden" name="workspaceId" value="' . $this->workspaceId . '" />';
363 $form = $this->tceforms->wrapTotal($form, $rec, $table);
364
365 $buttons = $this->createButtons() . $this->doc->spacer(5);
366
367 // Combine it all:
368 $content .= $buttons . $form . $buttons;
369 return $content;
370 }
371
372
373
374
375
376
377
378
379
380
381
382
383 /**
384 * Creates a form for new workspace. Parts are adopted from <code>alt_doc.php</code>.
385 *
386 * @return string Generated form
387 */
388 function buildNewForm() {
389 $content = '';
390 $table = 'sys_workspace';
391 $prevPageID = '';
392 $trData = t3lib_div::makeInstance('t3lib_transferData');
393 $trData->addRawData = TRUE;
394 $trData->defVals = $this->defVals;
395 $trData->lockRecords=1;
396 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
397 $trData->prevPageID = $prevPageID;
398 $trData->fetchRecord($table, 0, 'new');
399 reset($trData->regTableItems_data);
400 $rec = current($trData->regTableItems_data);
401 $rec['uid'] = uniqid('NEW');
402 $rec['pid'] = 0;
403 $rec['adminusers'] = $this->getOwnerUser($rec['uid']);
404
405 // Setting variables in TCEforms object:
406 $this->tceforms->hiddenFieldList = '';
407 // Register default language labels, if any:
408 $this->tceforms->registerDefaultLanguageData($table,$rec);
409
410 $this->fixVariousTCAFields();
411
412 // Create form for the record (either specific list of fields or the whole record):
413 $form = '';
414 // $fields = array_keys($GLOBALS['TCA'][$table]['columns']);
415 // unset($fields[array_search('freeze', $fields)]);
416 $form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec);
417 $form .= $this->doc->spacer(5);
418 $form .= $this->tceforms->getMainFields($table,$rec);
419 // $form .= $this->tceforms->getListedFields($table,$rec,implode(',', $fields));
420 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
421 $form .= '<input type="hidden" name="closeDoc" value="0" />';
422 $form .= '<input type="hidden" name="doSave" value="0" />';
423 $form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
424 $form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';
425 $form .= '<input type="hidden" name="submit" value="1" />';
426 $form = $this->tceforms->wrapTotal($form, $rec, $table);
427
428 $buttons = $this->createButtons() . $this->doc->spacer(5);
429
430 // Combine it all:
431 $content .= $buttons . $form . $buttons;
432 return $content;
433 }
434
435 /**
436 * Creates standard buttons for form. Adopted from <code>alt_doc.php</code>.
437 *
438 * @return string Generated buttons code
439 */
440 function createButtons() {
441 global $LANG;
442
443 $content = '';
444 $content .= '<input type="image" class="c-inputButton" name="_savedok"' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" />';
445 $content .= '<input type="image" class="c-inputButton" name="_saveandclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc',1).'" />';
446 // `n` below is simply to prevent caching
447 $content .= '<a href="index.php?n=' . uniqid('wksp') . '"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" /></a>';
448 return $content;
449 }
450
451
452
453
454
455
456
457
458
459
460 /**
461 * Returns owner user (i.e. current BE user) in the format suitable for TCE forms. This function uses <code>t3lib_loadDBGroup</code> to create value. Code is adopted from <code>t3lib_transferdata::renderRecord_groupProc()</code>.
462 *
463 * @param string $uid UID of the record (as <code>NEW...</code>)
464 * @return string User record formatted for TCEForms
465 */
466 function getOwnerUser($uid) {
467 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
468 // Make sure that `sys_workspace` is in $TCA
469 t3lib_div::loadTCA('sys_workspace');
470 // shortcut to `config` of `adminusers` field -- shorter code and better PHP performance
471 $config = &$GLOBALS['TCA']['sys_workspace']['columns']['adminusers']['config'];
472 // Notice: $config['MM'] is not set in the current version of $TCA but
473 // we still pass it to ensure compatibility with feature versions!
474 $loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid);
475 $loadDB->getFromDB();
476 return $loadDB->readyForInterface();
477 }
478
479
480
481
482
483
484
485
486
487 /**
488 * Processes submited data. This function uses <code>t3lib_TCEmain::process_datamap()</code> to create/update records in the <code>sys_workspace</code> table. It will print error messages just like any other Typo3 module with similar functionality. Function also changes workspace ID and module mode to 'edit' if new record was just created.
489 *
490 * @return void
491 */
492 function processData() {
493 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
494 $tce->stripslashes_values = 0;
495 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
496 if (is_array($TCAdefaultOverride)) {
497 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
498 }
499 $tce->stripslashes_values = 0;
500 $tce->start(t3lib_div::_GP('data'), array(), $GLOBALS['BE_USER']);
501 $tce->admin = 1; // Bypass table restrictions
502 $tce->bypassWorkspaceRestrictions = true;
503 $tce->process_datamap();
504
505 // print error messages (if any)
506 $script = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
507 $tce->printLogErrorMessages($script . '?' .
508 ($this->isEditAction ? 'action=edit&wkspId=' . $this->workspaceId : 'action=new'));
509
510 // If there was saved any new items, load them and update mode and workspace id
511 if (count($tce->substNEWwithIDs_table)) {
512 reset($tce->substNEWwithIDs_table); // not really necessary but better be safe...
513 $this->workspaceId = current($tce->substNEWwithIDs);
514 $this->isEditAction = true;
515 }
516 }
517
518
519
520 /**
521 * Fixes various <code>$TCA</code> fields for better visual representation of workspace editor.
522 *
523 * @return void
524 */
525 function fixVariousTCAFields() {
526 // enable tabs
527 $GLOBALS['TCA']['sys_workspace']['ctrl']['dividers2tabs'] = true;
528 }
529
530
531 /**
532 * "Fixes" <code>$TCA</code> to enable blinding for users/groups for non-admin users only.
533 *
534 * @param string $fieldName Name of the field to change
535 */
536 function fixTCAUserField($fieldName) {
537 // fix fields for non-admin
538 if (!$GLOBALS['BE_USER']->isAdmin()) {
539 // make a shortcut to field
540 $field = &$GLOBALS['TCA']['sys_workspace']['columns'][$fieldName];
541 $newField = array (
542 'label' => $field['label'],
543 'config' => Array (
544 'type' => 'select',
545 'itemsProcFunc' => 'user_SC_mod_user_ws_workspaceForms->processUserAndGroups',
546 //'iconsInOptionTags' => true,
547 'size' => $field['config']['size'],
548 'maxitems' => $field['config']['maxitems'],
549 'autoSizeMax' => $field['config']['autoSizeMax'],
550 'mod_ws_allowed' => $field['config']['allowed'] // let us know what we can use in itemProcFunc
551 )
552 );
553 $field = $newField;
554 }
555 }
556
557 /**
558 * Checks if use has editing access to the workspace.
559 *
560 * @return boolean Returns true if user can edit workspace
561 */
562 function checkWorkspaceAccess() {
563 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','uid=' . $this->workspaceId . ' AND pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'));
564 if (is_array($workspaces) && count($workspaces) != 0 && false !== ($rec = $GLOBALS['BE_USER']->checkWorkspace($workspaces[0]))) {
565 return ($rec['_ACCESS'] == 'owner' || $rec['_ACCESS'] == 'admin');
566 }
567 return false;
568 }
569 }
570
571 /**
572 * This class contains Typo3 callback functions. Class name must start from <code>user_</code> thus we use a separate class.
573 */
574 class user_SC_mod_user_ws_workspaceForms {
575
576 /**
577 * Callback function to blind user and group accounts. Used as <code>itemsProcFunc</code> in <code>$TCA</code>.
578 *
579 * @param array $conf Configuration array. The following elements are set:<ul><li>items - initial set of items (empty in our case)</li><li>config - field config from <code>$TCA</code></li><li>TSconfig - this function name</li><li>table - table name</li><li>row - record row (???)</li><li>field - field name</li></ul>
580 * @param object $tceforms <code>t3lib_div::TCEforms</code> object
581 * @return void
582 */
583 function processUserAndGroups($conf, $tceforms) {
584 // Get usernames and groupnames
585 $be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');
586 $groupArray = array_keys($be_group_Array);
587
588 $be_user_Array = t3lib_BEfunc::getUserNames();
589 $be_user_Array = t3lib_BEfunc::blindUserNames($be_user_Array,$groupArray,1);
590
591 // users
592 $title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_users']['ctrl']['title']);
593 foreach ($be_user_Array as $uid => $user) {
594 $conf['items'][] = array(
595 $user['username'] . ' (' . $title . ')',
596 'be_users_' . $user['uid'],
597 t3lib_iconWorks::getIcon('be_users', $user)
598 );
599 }
600
601 // Process groups only if necessary -- save time!
602 if (strstr($conf['config']['mod_ws_allowed'], 'be_groups')) {
603 // groups
604
605 $be_group_Array = $be_group_Array_o = t3lib_BEfunc::getGroupNames();
606 $be_group_Array = t3lib_BEfunc::blindGroupNames($be_group_Array_o,$groupArray,1);
607
608 $title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_groups']['ctrl']['title']);
609 foreach ($be_group_Array as $uid => $group) {
610 $conf['items'][] = array(
611 $group['title'] . ' (' . $title . ')',
612 'be_groups_' . $group['uid'],
613 t3lib_iconWorks::getIcon('be_groups', $user)
614 );
615 }
616 }
617 }
618 }
619
620 // Include extension?
621 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.mod_user_ws_workspaceForms.php']) {
622 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.mod_user_ws_workspaceForms.php']);
623 }
624
625 // Make instance:
626 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_workspaceForms');
627 $SOBE->init();
628 $SOBE->main();
629 $SOBE->printContent();
630 ?>