Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00070 // Initialize module: 00071 unset($MCONF); 00072 require('conf.php'); 00073 require($BACK_PATH.'init.php'); 00074 require($BACK_PATH.'template.php'); 00075 $BE_USER->modAccess($MCONF,1); 00076 00077 // Include libraries of various kinds used inside: 00078 $LANG->includeLLFile('EXT:lang/locallang_mod_user_ws.xml'); 00079 require_once(PATH_t3lib.'class.t3lib_scbase.php'); 00080 //require_once(PATH_typo3.'mod/user/ws/class.wslib.php'); 00081 require_once(PATH_t3lib.'class.t3lib_tcemain.php'); 00082 require_once(PATH_t3lib.'class.t3lib_tceforms.php'); 00083 require_once (PATH_t3lib.'class.t3lib_transferdata.php'); 00084 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php'); 00085 00093 class SC_mod_user_ws_workspaceForms extends t3lib_SCbase { 00094 00095 // Default variables for backend modules 00096 var $MCONF = array(); // Module configuration 00097 var $MOD_MENU = array(); // Module menu items 00098 var $MOD_SETTINGS = array(); // Module session settings 00099 var $doc; // Document Template Object 00100 var $content; // Accumulated content 00101 00102 // internal variables 00103 var $isEditAction = false; // true if about to edit workspace 00104 var $workspaceId; // ID of the workspace that we will edit. Set only if $isEditAction is true. 00105 var $tceforms; // An instance of t3lib_TCEForms 00106 00107 00108 00109 00110 00111 00112 /************************* 00113 * 00114 * PUBLIC MODULE METHODS 00115 * 00116 *************************/ 00117 00123 function init() { 00124 // Setting module configuration: 00125 $this->MCONF = $GLOBALS['MCONF']; 00126 00127 // Initialize Document Template object: 00128 $this->doc = t3lib_div::makeInstance('mediumDoc'); 00129 $this->doc->backPath = $GLOBALS['BACK_PATH']; 00130 $this->doc->docType = 'xhtml_trans'; 00131 $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);">'; 00132 00133 $CMparts = $this->doc->getContextMenuCode(); 00134 $this->doc->JScode.= $CMparts[0]; 00135 $this->doc->JScode.= $this->doc->getDynTabMenuJScode(); 00136 $this->doc->bodyTagAdditions = $CMparts[1]; 00137 $this->doc->postCode.= $CMparts[2]; 00138 00139 // Parent initialization: 00140 t3lib_SCbase::init(); 00141 } 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00158 function main() { 00159 global $LANG; 00160 00161 // see what we have to do and get parameters (call before processing data!!!) 00162 $this->getModuleParameters(); 00163 00164 $hasAccess = ( 00165 $GLOBALS['BE_USER']->isAdmin() || 00166 0 != ($GLOBALS['BE_USER']->groupData['workspace_perms'] & 4) || 00167 ($this->isEditAction && $this->checkWorkspaceAccess()) 00168 ); 00169 00170 if (!$hasAccess) { 00171 $title = $this->getTitle(); 00172 $this->content .= $this->doc->startPage($title); 00173 $this->content .= $this->doc->header($title); 00174 $this->content .= $this->doc->spacer(5); 00175 $this->content .= $LANG->getLL($this->isEditAction ? 'edit_workspace_no_permission' : 'create_workspace_no_permission'); 00176 $this->content .= $this->doc->spacer(5); 00177 $goBack = $GLOBALS['LANG']->getLL('edit_workspace_go_back'); 00178 $this->content .= '<img ' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/goback.gif', 'width="14" height="14"') . ' alt="' . $goBack . '" align="middle" hspace="2" />' . 00179 '<a href="javascript:history.back()">' . 00180 $goBack . 00181 '</a>'; 00182 $this->content .= $this->doc->endPage(); 00183 return; 00184 } 00185 00186 // process submission (this may override action and workspace ID!) 00187 if (t3lib_div::_GP('workspace_form_submited')) { 00188 $this->processData(); 00189 // if 'Save&Close' was pressed, redirect to main module script 00190 if (t3lib_div::_GP('_saveandclosedok_x')) { 00191 // `n` below is to prevent caching 00192 header('Location: ' . t3lib_div::locationHeaderUrl('index.php?n=' . uniqid(''))); 00193 exit(); 00194 } 00195 } 00196 00197 $this->initTCEForms(); 00198 00199 // 00200 // start page 00201 // 00202 $title = $this->getTitle(); 00203 $this->content .= $this->doc->startPage($title); 00204 $this->content .= $this->doc->header($title); 00205 $this->content .= $this->doc->spacer(5); 00206 00207 // 00208 // page content 00209 // 00210 $this->content .= $this->tceforms->printNeededJSFunctions_top(); 00211 $this->content .= $this->buildForm(); 00212 $this->content .= $this->tceforms->printNeededJSFunctions(); 00213 00214 // 00215 // end page 00216 // 00217 $this->content .= $this->doc->endPage(); 00218 } 00219 00220 00221 00222 00223 00224 00225 00226 00227 00233 function printContent() { 00234 echo $this->content; 00235 } 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 /************************* 00247 * 00248 * PRIVATE FUNCTIONS 00249 * 00250 *************************/ 00251 00257 function initTCEForms() { 00258 $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms'); 00259 $this->tceforms->initDefaultBEMode(); 00260 $this->tceforms->backPath = $GLOBALS['BACK_PATH']; 00261 $this->tceforms->doSaveFieldName = 'doSave'; 00262 $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : ''; // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat" 00263 $this->tceforms->returnUrl = $this->R_URI; 00264 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes']; 00265 $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE']; 00266 $this->tceforms->enableClickMenu = true; 00267 $this->tceforms->enableTabMenu = true; 00268 00269 // Setting external variables: 00270 if ($GLOBALS['BE_USER']->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions']) $this->tceforms->edit_showFieldHelp='text'; 00271 } 00272 00273 00274 00275 00276 00277 00278 00284 function getModuleParameters(){ 00285 $this->isEditAction = (t3lib_div::_GP('action') == 'edit'); 00286 if ($this->isEditAction) { 00287 $this->workspaceId = intval(t3lib_div::_GP('wkspId')); 00288 } 00289 } 00290 00291 00292 00293 00294 00295 00296 00302 function getTitle() { 00303 $label = ($this->isEditAction ? 'edit_workspace_title_edit' : 'edit_workspace_title_new'); 00304 return $GLOBALS['LANG']->getLL($label); 00305 } 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00321 function buildForm() { 00322 return $this->isEditAction ? $this->buildEditForm() : $this->buildNewForm(); 00323 } 00324 00330 function buildEditForm() { 00331 $content = ''; 00332 $table = 'sys_workspace'; 00333 $prevPageID = ''; 00334 $trData = t3lib_div::makeInstance('t3lib_transferData'); 00335 $trData->addRawData = TRUE; 00336 $trData->defVals = $this->defVals; 00337 $trData->lockRecords=1; 00338 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE']; 00339 $trData->prevPageID = $prevPageID; 00340 $trData->fetchRecord($table, $this->workspaceId, ''); 00341 reset($trData->regTableItems_data); 00342 $rec = current($trData->regTableItems_data); 00343 00344 // Setting variables in TCEforms object: 00345 $this->tceforms->hiddenFieldList = ''; 00346 // Register default language labels, if any: 00347 $this->tceforms->registerDefaultLanguageData($table,$rec); 00348 00349 $this->fixVariousTCAFields(); 00350 if (!$GLOBALS['BE_USER']->isAdmin()) { 00351 // Non-admins cannot select users from the root. We "fix" it for them. 00352 $this->fixTCAUserField('adminusers'); 00353 $this->fixTCAUserField('members'); 00354 $this->fixTCAUserField('reviewers'); 00355 } 00356 00357 // Create form for the record (either specific list of fields or the whole record): 00358 $form = ''; 00359 $form .= $this->tceforms->getMainFields($table,$rec); 00360 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />'; 00361 $form .= '<input type="hidden" name="workspace_form_submited" value="1" />'; 00362 $form .= '<input type="hidden" name="returnUrl" value="index.php" />'; 00363 $form .= '<input type="hidden" name="action" value="edit" />'; 00364 $form .= '<input type="hidden" name="closeDoc" value="0" />'; 00365 $form .= '<input type="hidden" name="doSave" value="0" />'; 00366 $form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />'; 00367 $form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />'; 00368 $form .= '<input type="hidden" name="wkspId" value="' . htmlspecialchars($this->workspaceId) . '" />'; 00369 $form = $this->tceforms->wrapTotal($form, $rec, $table); 00370 00371 $buttons = $this->createButtons() . $this->doc->spacer(5); 00372 00373 // Combine it all: 00374 $content .= $buttons . $form . $buttons; 00375 return $content; 00376 } 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00394 function buildNewForm() { 00395 $content = ''; 00396 $table = 'sys_workspace'; 00397 $prevPageID = ''; 00398 $trData = t3lib_div::makeInstance('t3lib_transferData'); 00399 $trData->addRawData = TRUE; 00400 $trData->defVals = $this->defVals; 00401 $trData->lockRecords=1; 00402 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE']; 00403 $trData->prevPageID = $prevPageID; 00404 $trData->fetchRecord($table, 0, 'new'); 00405 reset($trData->regTableItems_data); 00406 $rec = current($trData->regTableItems_data); 00407 $rec['uid'] = uniqid('NEW'); 00408 $rec['pid'] = 0; 00409 $rec['adminusers'] = $this->getOwnerUser($rec['uid']); 00410 00411 // Setting variables in TCEforms object: 00412 $this->tceforms->hiddenFieldList = ''; 00413 // Register default language labels, if any: 00414 $this->tceforms->registerDefaultLanguageData($table,$rec); 00415 00416 $this->fixVariousTCAFields(); 00417 if (!$GLOBALS['BE_USER']->isAdmin()) { 00418 // Non-admins cannot select users from the root. We "fix" it for them. 00419 $this->fixTCAUserField('adminusers'); 00420 $this->fixTCAUserField('members'); 00421 $this->fixTCAUserField('reviewers'); 00422 } 00423 00424 00425 // Create form for the record (either specific list of fields or the whole record): 00426 $form = ''; 00427 $form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec); 00428 $form .= $this->doc->spacer(5); 00429 $form .= $this->tceforms->getMainFields($table,$rec); 00430 00431 $form .= '<input type="hidden" name="workspace_form_submited" value="1" />'; 00432 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />'; 00433 $form .= '<input type="hidden" name="returnUrl" value="index.php" />'; 00434 $form .= '<input type="hidden" name="action" value="new" />'; 00435 $form .= '<input type="hidden" name="closeDoc" value="0" />'; 00436 $form .= '<input type="hidden" name="doSave" value="0" />'; 00437 $form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />'; 00438 $form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />'; 00439 $form = $this->tceforms->wrapTotal($form, $rec, $table); 00440 00441 $buttons = $this->createButtons() . $this->doc->spacer(5); 00442 00443 // Combine it all: 00444 $content .= $buttons . $form . $buttons; 00445 return $content; 00446 } 00447 00453 function createButtons() { 00454 global $LANG; 00455 00456 $content = ''; 00457 $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).'" value="_savedok" />'; 00458 $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).'" value="_saveandclosedok" />'; 00459 // `n` below is simply to prevent caching 00460 $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>'; 00461 return $content; 00462 } 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00479 function getOwnerUser($uid) { 00480 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup'); 00481 // Make sure that `sys_workspace` is in $TCA 00482 t3lib_div::loadTCA('sys_workspace'); 00483 // shortcut to `config` of `adminusers` field -- shorter code and better PHP performance 00484 $config = &$GLOBALS['TCA']['sys_workspace']['columns']['adminusers']['config']; 00485 // Notice: $config['MM'] is not set in the current version of $TCA but 00486 // we still pass it to ensure compatibility with feature versions! 00487 $loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid, 'sys_workspace', $config); 00488 $loadDB->getFromDB(); 00489 return $loadDB->readyForInterface(); 00490 } 00491 00492 00493 00494 00495 00496 00497 00498 00499 00505 function processData() { 00506 $tce = t3lib_div::makeInstance('t3lib_TCEmain'); 00507 $tce->stripslashes_values = 0; 00508 00509 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults'); 00510 if (is_array($TCAdefaultOverride)) { 00511 $tce->setDefaultsFromUserTS($TCAdefaultOverride); 00512 } 00513 $tce->stripslashes_values = 0; 00514 00515 // The following is a security precaution; It makes sure that the input data array can ONLY contain data for the sys_workspace table and ONLY one record. 00516 // If this is not present it could be mis-used for nasty XSS attacks which can escalate rights to admin for even non-admin users. 00517 $inputData_tmp = t3lib_div::_GP('data'); 00518 $inputData = array(); 00519 if (is_array($inputData_tmp['sys_workspace'])) { 00520 reset($inputData_tmp['sys_workspace']); 00521 $inputData['sys_workspace'][key($inputData_tmp['sys_workspace'])] = current($inputData_tmp['sys_workspace']); 00522 } 00523 00524 $tce->start($inputData, array(), $GLOBALS['BE_USER']); 00525 $tce->admin = 1; // Bypass table restrictions 00526 $tce->bypassWorkspaceRestrictions = true; 00527 $tce->process_datamap(); 00528 00529 // print error messages (if any) 00530 $script = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'); 00531 $tce->printLogErrorMessages($script . '?' . 00532 ($this->isEditAction ? 'action=edit&wkspId=' . $this->workspaceId : 'action=new')); 00533 00534 // If there was saved any new items, load them and update mode and workspace id 00535 if (count($tce->substNEWwithIDs_table)) { 00536 reset($tce->substNEWwithIDs_table); // not really necessary but better be safe... 00537 $this->workspaceId = current($tce->substNEWwithIDs); 00538 $this->isEditAction = true; 00539 } 00540 } 00541 00542 00543 00549 function fixVariousTCAFields() { 00550 // enable tabs 00551 $GLOBALS['TCA']['sys_workspace']['ctrl']['dividers2tabs'] = true; 00552 } 00553 00554 00561 function fixTCAUserField($fieldName) { 00562 // fix fields for non-admin 00563 if (!$GLOBALS['BE_USER']->isAdmin()) { 00564 // make a shortcut to field 00565 t3lib_div::loadTCA('sys_workspace'); 00566 $field = &$GLOBALS['TCA']['sys_workspace']['columns'][$fieldName]; 00567 $newField = array ( 00568 'label' => $field['label'], 00569 'config' => Array ( 00570 'type' => 'select', 00571 'itemsProcFunc' => 'user_SC_mod_user_ws_workspaceForms->processUserAndGroups', 00572 //'iconsInOptionTags' => true, 00573 'size' => 10, 00574 'maxitems' => $field['config']['maxitems'], 00575 'autoSizeMax' => $field['config']['autoSizeMax'], 00576 'mod_ws_allowed' => $field['config']['allowed'] // let us know what we can use in itemProcFunc 00577 ) 00578 ); 00579 $field = $newField; 00580 } 00581 } 00582 00588 function checkWorkspaceAccess() { 00589 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','uid=' . intval($this->workspaceId) . ' AND pid=0'.t3lib_BEfunc::deleteClause('sys_workspace')); 00590 if (is_array($workspaces) && count($workspaces) != 0 && false !== ($rec = $GLOBALS['BE_USER']->checkWorkspace($workspaces[0]))) { 00591 return ($rec['_ACCESS'] == 'owner' || $rec['_ACCESS'] == 'admin'); 00592 } 00593 return false; 00594 } 00595 } 00596 00601 class user_SC_mod_user_ws_workspaceForms { 00602 00610 function processUserAndGroups($conf, $tceforms) { 00611 // Get usernames and groupnames 00612 $be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid'); 00613 $groupArray = array_keys($be_group_Array); 00614 00615 $be_user_Array = t3lib_BEfunc::getUserNames(); 00616 $be_user_Array = t3lib_BEfunc::blindUserNames($be_user_Array,$groupArray,1); 00617 00618 // users 00619 $title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_users']['ctrl']['title']); 00620 foreach ($be_user_Array as $uid => $user) { 00621 $conf['items'][] = array( 00622 $user['username'] . ' (' . $title . ')', 00623 'be_users_' . $user['uid'], 00624 t3lib_iconWorks::getIcon('be_users', $user) 00625 ); 00626 } 00627 00628 // Process groups only if necessary -- save time! 00629 if (strstr($conf['config']['mod_ws_allowed'], 'be_groups')) { 00630 // groups 00631 00632 $be_group_Array = $be_group_Array_o = t3lib_BEfunc::getGroupNames(); 00633 $be_group_Array = t3lib_BEfunc::blindGroupNames($be_group_Array_o,$groupArray,1); 00634 00635 $title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_groups']['ctrl']['title']); 00636 foreach ($be_group_Array as $uid => $group) { 00637 $conf['items'][] = array( 00638 $group['title'] . ' (' . $title . ')', 00639 'be_groups_' . $group['uid'], 00640 t3lib_iconWorks::getIcon('be_groups', $user) 00641 ); 00642 } 00643 } 00644 } 00645 } 00646 00647 // Include extension? 00648 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/workspaceforms.php']) { 00649 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/workspaceforms.php']); 00650 } 00651 00652 // Make instance: 00653 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_workspaceForms'); 00654 $SOBE->init(); 00655 $SOBE->main(); 00656 $SOBE->printContent(); 00657 ?>