Initial version
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / class.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('noDoc');
121 $this->doc->backPath = $GLOBALS['BACK_PATH'];
122 $this->doc->docType = 'xhtml_trans';
123 $this->doc->form = '<form action="'.htmlspecialchars($this->R_URI).'" 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->bodyTagAdditions = $CMparts[1];
128 $this->doc->postCode.= $CMparts[2];
129
130 $this->initTCEForms();
131
132 // Parent initialization:
133 t3lib_SCbase::init();
134 }
135
136
137
138
139
140
141
142
143
144
145
146 /**
147 * Creates module content.
148 *
149 * @return void
150 */
151 function main() {
152 // see what we have to do and get parameters (call before processing data!!!)
153 $this->getModuleParameters();
154
155 // process submission (this may override action and workspace ID!)
156 if (t3lib_div::_GP('submit') != '') {
157 $this->processData();
158 // if 'Save&Close' was pressed, redirect to main module script
159 if (t3lib_div::_GP('_saveandclosedok_x')) {
160 // `n` below is to prevent caching
161 header('Location: ' . t3lib_div::locationHeaderUrl('index.php?n=' . uniqid('')));
162 exit();
163 }
164 }
165
166 //
167 // start page
168 //
169 $title = $this->getTitle();
170 $this->content .= $this->doc->startPage($title);
171 $this->content .= $this->doc->header($title);
172 $this->content .= $this->doc->spacer(5);
173
174 //
175 // page content
176 //
177 $this->content .= $this->tceforms->printNeededJSFunctions_top();
178 $this->content .= $this->buildForm();
179 $this->content .= $this->tceforms->printNeededJSFunctions();
180
181 //
182 // end page
183 //
184 $this->content .= $this->doc->endPage();
185 }
186
187
188
189
190
191
192
193
194
195 /**
196 * Outputs module content to the browser.
197 *
198 * @return void
199 */
200 function printContent() {
201 echo $this->content;
202 }
203
204
205
206
207
208
209
210
211
212
213 /*************************
214 *
215 * PRIVATE FUNCTIONS
216 *
217 *************************/
218
219 /**
220 * Initializes <code>t3lib_TCEform</code> class for use in this module.
221 *
222 * @return void
223 */
224 function initTCEForms() {
225 $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
226 $this->tceforms->initDefaultBEMode();
227 $this->tceforms->backPath = $GLOBALS['BACK_PATH'];
228 $this->tceforms->doSaveFieldName = 'doSave';
229 $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : ''; // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
230 $this->tceforms->returnUrl = $this->R_URI;
231 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
232 $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
233 $this->tceforms->enableClickMenu = true;
234 $this->tceforms->enableTabMenu = true;
235
236 // Setting external variables:
237 if ($GLOBALS['BE_USER']->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions']) $this->tceforms->edit_showFieldHelp='text';
238 }
239
240
241
242
243
244
245
246 /**
247 * 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>
248 *
249 * @return void
250 */
251 function getModuleParameters(){
252 $this->isEditAction = (t3lib_div::_GP('action') == 'edit');
253 if ($this->isEditAction) {
254 $this->workspaceId = intval(t3lib_div::_GP('wkspId'));
255 }
256 }
257
258
259
260
261
262
263
264 /**
265 * Retrieves a title of the module according to action.
266 *
267 * @return string A title for the module
268 */
269 function getTitle() {
270 if ($this->isEditAction) {
271 // TODO Localize this
272 return 'Edit workspace';
273 }
274 // TODO Localize this
275 return 'Create new workspace';
276 }
277
278
279
280
281
282
283 /**
284 * Creates form for workspace. This function is a wrapper around <code>buildEditForm()</code> and <code>buildNewForm()</code>.
285 *
286 * @return string Generated form
287 */
288 function buildForm() {
289 return $this->isEditAction ? $this->buildEditForm() : $this->buildNewForm();
290 }
291
292 /**
293 * Creates a form for editing workspace. Parts were adopted from <code>alt_doc.php</code>.
294 *
295 * @return string Generated form
296 */
297 function buildEditForm() {
298 $content = '';
299 $table = 'sys_workspace';
300 $prevPageID = '';
301 $trData = t3lib_div::makeInstance('t3lib_transferData');
302 $trData->addRawData = TRUE;
303 $trData->defVals = $this->defVals;
304 $trData->lockRecords=1;
305 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
306 $trData->prevPageID = $prevPageID;
307 $trData->fetchRecord($table, $this->workspaceId, '');
308 reset($trData->regTableItems_data);
309 $rec = current($trData->regTableItems_data);
310
311 // Setting variables in TCEforms object:
312 $this->tceforms->hiddenFieldList = '';
313 // Register default language labels, if any:
314 $this->tceforms->registerDefaultLanguageData($table,$rec);
315
316 // Create form for the record (either specific list of fields or the whole record):
317 $form = '';
318 $form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec);
319 $form .= $this->doc->spacer(5);
320 $form .= $this->tceforms->getMainFields($table,$rec);
321 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
322 $form .= '<input type="hidden" name="submit" value="1" />';
323 $form .= '<input type="hidden" name="action" value="edit" />';
324 $form .= '<input type="hidden" name="workspaceId" value="' . $this->workspaceId . '" />';
325 $form = $this->tceforms->wrapTotal($form, $rec, $table);
326
327 $buttons = $this->createButtons() . $this->doc->spacer(5);
328
329 // Combine it all:
330 $content .= $buttons . $form . $buttons;
331 return $content;
332 }
333
334
335
336
337
338
339
340
341
342
343
344 /**
345 * Creates a form for new workspace. Parts are adopted from <code>alt_doc.php</code>.
346 *
347 * @return string Generated form
348 */
349 function buildNewForm() {
350 $content = '';
351 $table = 'sys_workspace';
352 $prevPageID = '';
353 $trData = t3lib_div::makeInstance('t3lib_transferData');
354 $trData->addRawData = TRUE;
355 $trData->defVals = $this->defVals;
356 $trData->lockRecords=1;
357 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
358 $trData->prevPageID = $prevPageID;
359 $trData->fetchRecord($table, 0, 'new'/*1,''*/); // 'new'
360 reset($trData->regTableItems_data);
361 $rec = current($trData->regTableItems_data);
362 $rec['uid'] = uniqid('NEW');
363 $rec['pid'] = 0;
364 $rec['adminusers'] = $this->getOwnerUser($rec['uid']);
365
366 // Setting variables in TCEforms object:
367 $this->tceforms->hiddenFieldList = '';
368 // Register default language labels, if any:
369 $this->tceforms->registerDefaultLanguageData($table,$rec);
370
371 // Create form for the record (either specific list of fields or the whole record):
372 $form = '';
373 $fields = array_keys($GLOBALS['TCA'][$table]['columns']);
374 unset($fields[array_search('freeze', $fields)]);
375 $form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec);
376 $form .= $this->doc->spacer(5);
377 $form .= $this->tceforms->getListedFields($table,$rec,implode(',', $fields));
378 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
379 $form .= '<input type="hidden" name="submit" value="1" />';
380 $form = $this->tceforms->wrapTotal($form, $rec, $table);
381
382 $buttons = $this->createButtons() . $this->doc->spacer(5);
383
384 // Combine it all:
385 $content .= $buttons . $form . $buttons;
386 return $content;
387 }
388
389 /**
390 * Creates standard buttons for form. Adopted from <code>alt_doc.php</code>.
391 *
392 * @return string Generated buttons code
393 */
394 function createButtons() {
395 global $LANG;
396
397 $content = '';
398 $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).'" />';
399 $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).'" />';
400 // `n` below is simply to prevent caching
401 $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>';
402 return $content;
403 }
404
405
406
407
408
409
410
411
412
413
414
415 /**
416 * 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>.
417 *
418 * @param string $uid UID of the record (as <code>NEW...</code>)
419 * @return string User record formatted for TCEForms
420 */
421 function getOwnerUser($uid) {
422 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
423 // Make sure that `sys_workspace` is in $TCA
424 t3lib_div::loadTCA('sys_workspace');
425 // shortcut to `config` of `adminusers` field -- shorter code and better PHP performance
426 $config = &$GLOBALS['TCA']['sys_workspace']['columns']['adminusers']['config'];
427 // Notice: $config['MM'] is not set in the current version of $TCA but
428 // we still pass it to ensure compatibility with feature versions!
429 $loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid);
430 $loadDB->getFromDB();
431 return $loadDB->readyForInterface();
432 }
433
434
435
436
437
438
439
440
441
442 /**
443 * 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.
444 *
445 * @return void
446 */
447 function processData() {
448 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
449 $tce->stripslashes_values = 0;
450 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
451 if (is_array($TCAdefaultOverride)) {
452 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
453 }
454 $tce->stripslashes_values = 0;
455 $tce->start(t3lib_div::_GP('data'), array(), $GLOBALS['BE_USER']);
456 $tce->admin = 1; // Bypass table restrictions
457 $tce->bypassWorkspaceRestrictions = true;
458 $tce->process_datamap();
459
460 // print error messages (if any)
461 $script = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
462 $tce->printLogErrorMessages($script . '?' .
463 ($this->isEditAction ? 'action=edit&wkspId=' . $this->workspaceId : 'action=new'));
464
465 // If there was saved any new items, load them and update mode and workspace id
466 if (count($tce->substNEWwithIDs_table)) {
467 reset($tce->substNEWwithIDs_table); // not really necessary but better be safe...
468 $this->workspaceId = current($tce->substNEWwithIDs);
469 $this->isEditAction = true;
470 }
471 }
472 }
473
474 // Include extension?
475 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.mod_user_ws_workspaceForms.php']) {
476 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.mod_user_ws_workspaceForms.php']);
477 }
478
479 // Make instance:
480 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_workspaceForms');
481 $SOBE->init();
482 $SOBE->main();
483 $SOBE->printContent();
484 ?>