/src/typo3_src-4.2.0alpha1/typo3/mod/user/ws/workspaceforms.php

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 
00105         var $doc;
00106         var $content;                                           // Accumulated content
00107 
00108         // internal variables
00109         var     $isEditAction = false;                  // true if about to edit workspace
00110         var $workspaceId;                                       // ID of the workspace that we will edit. Set only if $isEditAction is true.
00111 
00117         var $tceforms;
00118 
00119 
00120 
00121 
00122 
00123 
00124         /*************************
00125          *
00126          * PUBLIC MODULE METHODS
00127          *
00128          *************************/
00129 
00135         function init() {
00136                 // Setting module configuration:
00137                 $this->MCONF = $GLOBALS['MCONF'];
00138 
00139                 // Initialize Document Template object:
00140                 $this->doc = t3lib_div::makeInstance('mediumDoc');
00141                 $this->doc->backPath = $GLOBALS['BACK_PATH'];
00142                 $this->doc->docType = 'xhtml_trans';
00143                 $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);">';
00144 
00145                 $CMparts = $this->doc->getContextMenuCode();
00146                 $this->doc->JScode.= $CMparts[0];
00147                 $this->doc->JScode.= $this->doc->getDynTabMenuJScode();
00148                 $this->doc->bodyTagAdditions = $CMparts[1];
00149                 $this->doc->postCode.= $CMparts[2];
00150 
00151                 // Parent initialization:
00152                 t3lib_SCbase::init();
00153         }
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00170         function main() {
00171                 global  $LANG;
00172 
00173                 // see what we have to do and get parameters (call before processing data!!!)
00174                 $this->getModuleParameters();
00175 
00176                 $hasAccess = (
00177                         $GLOBALS['BE_USER']->isAdmin() ||
00178                         0 != ($GLOBALS['BE_USER']->groupData['workspace_perms'] & 4) ||
00179                         ($this->isEditAction && $this->checkWorkspaceAccess())
00180                 );
00181 
00182                 if (!$hasAccess) {
00183                         $title = $this->getTitle();
00184                         $this->content .= $this->doc->startPage($title);
00185                         $this->content .= $this->doc->header($title);
00186                         $this->content .= $this->doc->spacer(5);
00187                         $this->content .= $LANG->getLL($this->isEditAction ? 'edit_workspace_no_permission' : 'create_workspace_no_permission');
00188                         $this->content .= $this->doc->spacer(5);
00189                         $goBack = $GLOBALS['LANG']->getLL('edit_workspace_go_back');
00190                         $this->content .= '<img ' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/goback.gif', 'width="14" height="14"') . ' alt="' . $goBack . '" align="middle" hspace="2" />' .
00191                                                 '<a href="javascript:history.back()">' .
00192                                                 $goBack .
00193                                                 '</a>';
00194                         $this->content .= $this->doc->endPage();
00195                         return;
00196                 }
00197 
00198                 // process submission (this may override action and workspace ID!)
00199                 if (t3lib_div::_GP('workspace_form_submited')) {
00200                         $this->processData();
00201                         // if 'Save&Close' was pressed, redirect to main module script
00202                         if (t3lib_div::_GP('_saveandclosedok_x')) {
00203                                 // `n` below is to prevent caching
00204                                 header('Location: ' . t3lib_div::locationHeaderUrl('index.php?n=' . uniqid('')));
00205                                 exit();
00206                         }
00207                 }
00208 
00209                 $this->initTCEForms();
00210 
00211                 //
00212                 // start page
00213                 //
00214                 $title = $this->getTitle();
00215                 $this->content .= $this->doc->startPage($title);
00216                 $this->content .= $this->doc->header($title);
00217                 $this->content .= $this->doc->spacer(5);
00218 
00219                 //
00220                 // page content
00221                 //
00222                 $this->content .= $this->tceforms->printNeededJSFunctions_top();
00223                 $this->content .= $this->buildForm();
00224                 $this->content .= $this->tceforms->printNeededJSFunctions();
00225 
00226                 //
00227                 // end page
00228                 //
00229                 $this->content .= $this->doc->endPage();
00230         }
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00245         function printContent() {
00246                 echo $this->content;
00247         }
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258         /*************************
00259          *
00260          * PRIVATE FUNCTIONS
00261          *
00262          *************************/
00263 
00269         function initTCEForms() {
00270                 $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
00271                 $this->tceforms->initDefaultBEMode();
00272                 $this->tceforms->backPath = $GLOBALS['BACK_PATH'];
00273                 $this->tceforms->doSaveFieldName = 'doSave';
00274                 $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : '';     // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
00275                 $this->tceforms->returnUrl = $this->R_URI;
00276                 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
00277                 $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
00278                 $this->tceforms->enableClickMenu = true;
00279                 $this->tceforms->enableTabMenu = true;
00280 
00281                         // Setting external variables:
00282                 if ($GLOBALS['BE_USER']->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions'])   $this->tceforms->edit_showFieldHelp='text';
00283         }
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00296         function getModuleParameters(){
00297                 $this->isEditAction = (t3lib_div::_GP('action') == 'edit');
00298                 if ($this->isEditAction) {
00299                         $this->workspaceId = intval(t3lib_div::_GP('wkspId'));
00300                 }
00301         }
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00314         function getTitle() {
00315                 $label = ($this->isEditAction ? 'edit_workspace_title_edit' : 'edit_workspace_title_new');
00316                 return $GLOBALS['LANG']->getLL($label);
00317         }
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327 
00333         function buildForm() {
00334                 return $this->isEditAction ? $this->buildEditForm() : $this->buildNewForm();
00335         }
00336 
00342         function buildEditForm() {
00343                 $content = '';
00344                 $table = 'sys_workspace';
00345                 $prevPageID = '';
00346                 $trData = t3lib_div::makeInstance('t3lib_transferData');
00347                 $trData->addRawData = TRUE;
00348                 $trData->defVals = $this->defVals;
00349                 $trData->lockRecords=1;
00350                 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
00351                 $trData->prevPageID = $prevPageID;
00352                 $trData->fetchRecord($table, $this->workspaceId, '');
00353                 reset($trData->regTableItems_data);
00354                 $rec = current($trData->regTableItems_data);
00355 
00356                 // Setting variables in TCEforms object:
00357                 $this->tceforms->hiddenFieldList = '';
00358                 // Register default language labels, if any:
00359                 $this->tceforms->registerDefaultLanguageData($table,$rec);
00360 
00361                 $this->fixVariousTCAFields();
00362                 if (!$GLOBALS['BE_USER']->isAdmin()) {
00363                         // Non-admins cannot select users from the root. We "fix" it for them.
00364                         $this->fixTCAUserField('adminusers');
00365                         $this->fixTCAUserField('members');
00366                         $this->fixTCAUserField('reviewers');
00367                 }
00368 
00369                 // Create form for the record (either specific list of fields or the whole record):
00370                 $form = '';
00371                 $form .= $this->tceforms->getMainFields($table,$rec);
00372                 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
00373                 $form .= '<input type="hidden" name="workspace_form_submited" value="1" />';
00374                 $form .= '<input type="hidden" name="returnUrl" value="index.php" />';
00375                 $form .= '<input type="hidden" name="action" value="edit" />';
00376                 $form .= '<input type="hidden" name="closeDoc" value="0" />';
00377                 $form .= '<input type="hidden" name="doSave" value="0" />';
00378                 $form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
00379                 $form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';
00380                 $form .= '<input type="hidden" name="wkspId" value="' . htmlspecialchars($this->workspaceId) . '" />';
00381                 $form = $this->tceforms->wrapTotal($form, $rec, $table);
00382 
00383                 $buttons = $this->createButtons() . $this->doc->spacer(5);
00384 
00385                 // Combine it all:
00386                 $content .= $buttons . $form . $buttons;
00387                 return $content;
00388         }
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00406         function buildNewForm() {
00407                 $content = '';
00408                 $table = 'sys_workspace';
00409                 $prevPageID = '';
00410                 $trData = t3lib_div::makeInstance('t3lib_transferData');
00411                 $trData->addRawData = TRUE;
00412                 $trData->defVals = $this->defVals;
00413                 $trData->lockRecords=1;
00414                 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
00415                 $trData->prevPageID = $prevPageID;
00416                 $trData->fetchRecord($table, 0, 'new');
00417                 reset($trData->regTableItems_data);
00418                 $rec = current($trData->regTableItems_data);
00419                 $rec['uid'] = uniqid('NEW');
00420                 $rec['pid'] = 0;
00421                 $rec['adminusers'] = $this->getOwnerUser($rec['uid']);
00422 
00423                 // Setting variables in TCEforms object:
00424                 $this->tceforms->hiddenFieldList = '';
00425                 // Register default language labels, if any:
00426                 $this->tceforms->registerDefaultLanguageData($table,$rec);
00427 
00428                 $this->fixVariousTCAFields();
00429                 if (!$GLOBALS['BE_USER']->isAdmin()) {
00430                         // Non-admins cannot select users from the root. We "fix" it for them.
00431                         $this->fixTCAUserField('adminusers');
00432                         $this->fixTCAUserField('members');
00433                         $this->fixTCAUserField('reviewers');
00434                 }
00435 
00436 
00437                 // Create form for the record (either specific list of fields or the whole record):
00438                 $form = '';
00439                 $form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec);
00440                 $form .= $this->doc->spacer(5);
00441                 $form .= $this->tceforms->getMainFields($table,$rec);
00442 
00443                 $form .= '<input type="hidden" name="workspace_form_submited" value="1" />';
00444                 $form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
00445                 $form .= '<input type="hidden" name="returnUrl" value="index.php" />';
00446                 $form .= '<input type="hidden" name="action" value="new" />';
00447                 $form .= '<input type="hidden" name="closeDoc" value="0" />';
00448                 $form .= '<input type="hidden" name="doSave" value="0" />';
00449                 $form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
00450                 $form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';
00451                 $form = $this->tceforms->wrapTotal($form, $rec, $table);
00452 
00453                 $buttons = $this->createButtons() . $this->doc->spacer(5);
00454 
00455                 // Combine it all:
00456                 $content .= $buttons . $form . $buttons;
00457                 return $content;
00458         }
00459 
00465         function createButtons() {
00466                 global  $LANG;
00467 
00468                 $content = '';
00469                 $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" />';
00470                 $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" />';
00471                 // `n` below is simply to prevent caching
00472                 $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>';
00473                 return $content;
00474         }
00475 
00476 
00477 
00478 
00479 
00480 
00481 
00482 
00483 
00484 
00491         function getOwnerUser($uid) {
00492                 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
00493                 // Make sure that `sys_workspace` is in $TCA
00494                 t3lib_div::loadTCA('sys_workspace');
00495                 // shortcut to `config` of `adminusers` field -- shorter code and better PHP performance
00496                 $config = &$GLOBALS['TCA']['sys_workspace']['columns']['adminusers']['config'];
00497                 // Notice: $config['MM'] is not set in the current version of $TCA but
00498                 // we still pass it to ensure compatibility with feature versions!
00499                 $loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid, 'sys_workspace', $config);
00500                 $loadDB->getFromDB();
00501                 return $loadDB->readyForInterface();
00502         }
00503 
00504 
00505 
00506 
00507 
00508 
00509 
00510 
00511 
00517         function processData() {
00518                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00519                 $tce->stripslashes_values = 0;
00520 
00521                 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
00522                 if (is_array($TCAdefaultOverride))      {
00523                         $tce->setDefaultsFromUserTS($TCAdefaultOverride);
00524                 }
00525                 $tce->stripslashes_values = 0;
00526 
00527                         // 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.
00528                         // 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.
00529                 $inputData_tmp = t3lib_div::_GP('data');
00530                 $inputData = array();
00531                 if (is_array($inputData_tmp['sys_workspace']))  {
00532                         reset($inputData_tmp['sys_workspace']);
00533                         $inputData['sys_workspace'][key($inputData_tmp['sys_workspace'])] = current($inputData_tmp['sys_workspace']);
00534                 }
00535 
00536                 $tce->start($inputData, array(), $GLOBALS['BE_USER']);
00537                 $tce->admin = 1;        // Bypass table restrictions
00538                 $tce->bypassWorkspaceRestrictions = true;
00539                 $tce->process_datamap();
00540 
00541                         // print error messages (if any)
00542                 $script = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
00543                 $tce->printLogErrorMessages($script . '?' .
00544                         ($this->isEditAction ? 'action=edit&wkspId=' . $this->workspaceId : 'action=new'));
00545 
00546                 // If there was saved any new items, load them and update mode and workspace id
00547                 if (count($tce->substNEWwithIDs_table)) {
00548                         reset($tce->substNEWwithIDs_table);     // not really necessary but better be safe...
00549                         $this->workspaceId = current($tce->substNEWwithIDs);
00550                         $this->isEditAction = true;
00551                 }
00552         }
00553 
00554 
00555 
00561         function fixVariousTCAFields() {
00562                 // enable tabs
00563                 $GLOBALS['TCA']['sys_workspace']['ctrl']['dividers2tabs'] = true;
00564         }
00565 
00566 
00573         function fixTCAUserField($fieldName) {
00574                 // fix fields for non-admin
00575                 if (!$GLOBALS['BE_USER']->isAdmin()) {
00576                         // make a shortcut to field
00577                         t3lib_div::loadTCA('sys_workspace');
00578                         $field = &$GLOBALS['TCA']['sys_workspace']['columns'][$fieldName];
00579                         $newField = array (
00580                                 'label' => $field['label'],
00581                                 'config' => Array (
00582                                         'type' => 'select',
00583                                         'itemsProcFunc' => 'user_SC_mod_user_ws_workspaceForms->processUserAndGroups',
00584                                         //'iconsInOptionTags' => true,
00585                                         'size' => 10,
00586                                         'maxitems' => $field['config']['maxitems'],
00587                                         'autoSizeMax' => $field['config']['autoSizeMax'],
00588                                         'mod_ws_allowed' => $field['config']['allowed'] // let us know what we can use in itemProcFunc
00589                                 )
00590                         );
00591                         $field = $newField;
00592                 }
00593         }
00594 
00600         function checkWorkspaceAccess() {
00601                 $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'));
00602                 if (is_array($workspaces) && count($workspaces) != 0 && false !== ($rec = $GLOBALS['BE_USER']->checkWorkspace($workspaces[0]))) {
00603                         return ($rec['_ACCESS'] == 'owner' || $rec['_ACCESS'] == 'admin');
00604                 }
00605                 return false;
00606         }
00607 }
00608 
00613 class user_SC_mod_user_ws_workspaceForms {
00614 
00622         function processUserAndGroups($conf, $tceforms) {
00623                         // Get usernames and groupnames
00624                 $be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');
00625                 $groupArray = array_keys($be_group_Array);
00626 
00627                 $be_user_Array = t3lib_BEfunc::getUserNames();
00628                 $be_user_Array = t3lib_BEfunc::blindUserNames($be_user_Array,$groupArray,1);
00629 
00630                 // users
00631                 $title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_users']['ctrl']['title']);
00632                 foreach ($be_user_Array as $uid => $user) {
00633                         $conf['items'][] = array(
00634                                 $user['username'] . ' (' . $title . ')',
00635                                 'be_users_' . $user['uid'],
00636                                 t3lib_iconWorks::getIcon('be_users', $user)
00637                         );
00638                 }
00639 
00640                 // Process groups only if necessary -- save time!
00641                 if (strstr($conf['config']['mod_ws_allowed'], 'be_groups')) {
00642                         // groups
00643 
00644                         $be_group_Array = $be_group_Array_o = t3lib_BEfunc::getGroupNames();
00645                         $be_group_Array = t3lib_BEfunc::blindGroupNames($be_group_Array_o,$groupArray,1);
00646 
00647                         $title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_groups']['ctrl']['title']);
00648                         foreach ($be_group_Array as $uid => $group) {
00649                                 $conf['items'][] = array(
00650                                         $group['title'] . ' (' . $title . ')',
00651                                         'be_groups_' . $group['uid'],
00652                                         t3lib_iconWorks::getIcon('be_groups', $user)
00653                                 );
00654                         }
00655                 }
00656         }
00657 }
00658 
00659 // Include extension?
00660 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/workspaceforms.php'])    {
00661         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/workspaceforms.php']);
00662 }
00663 
00664 // Make instance:
00665 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_workspaceForms');
00666 $SOBE->init();
00667 $SOBE->main();
00668 $SOBE->printContent();
00669 ?>

This documentation has been generated automatically from TYPO3 source code using Doxygen and is provided as is by Cast Iron Coding as a courtesy to other TYPO3 developers and users. Please consider Cast Iron Coding — a full-service web development agency in Portland, Oregon specializing in TYPO3 extension development — for all of your TYPO3 development and consulting needs!