TYPO3 API  SVNRelease
index.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (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 ***************************************************************/
00027 /**
00028  * Module: User configuration
00029  *
00030  * This module lets users viev and change their individual settings
00031  *
00032  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00033  * Revised for TYPO3 3.7 6/2004 by Kasper Skårhøj
00034  * XHTML compatible.
00035  */
00036 /**
00037  * [CLASS/FUNCTION INDEX of SCRIPT]
00038  *
00039  *
00040  *
00041  *   86: class SC_mod_user_setup_index
00042  *
00043  *              SECTION: Saving data
00044  *  114:     function storeIncomingData()
00045  *
00046  *              SECTION: Rendering module
00047  *  216:     function init()
00048  *  248:     function main()
00049  *  403:     function printContent()
00050  *
00051  *              SECTION: Helper functions
00052  *  432:     function getRealScriptUserObj()
00053  *  442:     function simulateUser()
00054  *  488:     function setLabel($str,$key='')
00055  *
00056  * TOTAL FUNCTIONS: 7
00057  * (This index is automatically created/updated by the extension "extdeveval")
00058  *
00059  */
00060 
00061 unset($MCONF);
00062 require('conf.php');
00063 require($BACK_PATH.'init.php');
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 /**
00079  * Script class for the Setup module
00080  *
00081  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00082  * @package TYPO3
00083  * @subpackage tx_setup
00084  */
00085 class SC_mod_user_setup_index {
00086 
00087         // Internal variables:
00088     var $MCONF = array();
00089     var $MOD_MENU = array();
00090     var $MOD_SETTINGS = array();
00091 
00092     /**
00093      * document template object
00094      *
00095      * @var mediumDoc
00096      */
00097     var $doc;
00098 
00099     var $content;
00100     var $overrideConf;
00101 
00102     /**
00103      * backend user object, set during simulate-user operation
00104      *
00105      * @var t3lib_beUserAuth
00106      */
00107     var $OLD_BE_USER;
00108     var $languageUpdate;
00109     protected $pagetreeNeedsRefresh = FALSE;
00110 
00111     protected $isAdmin;
00112     protected $dividers2tabs;
00113 
00114     protected $tsFieldConf;
00115 
00116     protected $saveData = FALSE;
00117     protected $passwordIsUpdated = FALSE;
00118     protected $passwordIsSubmitted = FALSE;
00119     protected $setupIsUpdated = FALSE;
00120     protected $tempDataIsCleared = FALSE;
00121     protected $settingsAreResetToDefault = FALSE;
00122     protected $installToolFileExists = FALSE;
00123     protected $installToolFileKeep = FALSE;
00124 
00125     /**
00126      * Form protection instance
00127      *
00128      * @var t3lib_formprotection_BackendFormProtection
00129      */
00130     protected $formProtection;
00131 
00132     /******************************
00133      *
00134      * Saving data
00135      *
00136      ******************************/
00137 
00138 
00139     /**
00140      * Instanciate the form protection before a simulated user is initialized.
00141      */
00142     public function __construct() {
00143         $this->formProtection = t3lib_formProtection_Factory::get();
00144     }
00145 
00146     /**
00147      * Getter for the form protection instance.
00148      */
00149     public function getFormProtection() {
00150         return $this->formProtection;
00151     }
00152 
00153     /**
00154      * If settings are submitted to _POST[DATA], store them
00155      * NOTICE: This method is called before the template.php is included. See
00156      * bottom of document.
00157      */
00158     public function storeIncomingData() {
00159         /* @var $BE_USER t3lib_beUserAuth */
00160         global $BE_USER;
00161 
00162             // First check if something is submittet in the data-array from POST vars
00163         $d = t3lib_div::_POST('data');
00164         $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
00165         $beUserId = $BE_USER->user['uid'];
00166         $storeRec = array();
00167         $fieldList = $this->getFieldsFromShowItem();
00168 
00169         if (is_array($d) && $this->formProtection->validateToken(
00170                 (string) t3lib_div::_POST('formToken'),
00171                 'BE user setup', 'edit'
00172             )
00173         ) {
00174                 // UC hashed before applying changes
00175             $save_before = md5(serialize($BE_USER->uc));
00176 
00177                 // PUT SETTINGS into the ->uc array:
00178 
00179                 // reload left frame when switching BE language
00180             if (isset($d['lang']) && ($d['lang'] != $BE_USER->uc['lang'])) {
00181                 $this->languageUpdate = true;
00182             }
00183 
00184                 // reload pagetree if the title length is changed
00185             if (isset($d['titleLen']) && ($d['titleLen'] !== $BE_USER->uc['titleLen'])) {
00186                 $this->pagetreeNeedsRefresh = TRUE;
00187             }
00188 
00189             if ($d['setValuesToDefault']) {
00190                     // If every value should be default
00191                 $BE_USER->resetUC();
00192                 $this->settingsAreResetToDefault = TRUE;
00193             } elseif ($d['clearSessionVars']) {
00194                 foreach ($BE_USER->uc as $key => $value) {
00195                     if (!isset($columns[$key])) {
00196                         unset ($BE_USER->uc[$key]);
00197                     }
00198                 }
00199                 $this->tempDataIsCleared = TRUE;
00200             } elseif ($d['save']) {
00201                     // save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
00202 
00203                 foreach($columns as $field => $config) {
00204                     if (!in_array($field, $fieldList)) {
00205                         continue;
00206                     }
00207                     if ($config['table']) {
00208                         if ($config['table'] == 'be_users' && !in_array($field, array('password', 'password2', 'email', 'realName', 'admin'))) {
00209                             if (!isset($config['access']) || $this->checkAccess($config) && $BE_USER->user[$field] !== $d['be_users'][$field]) {
00210                                 $storeRec['be_users'][$beUserId][$field] = $d['be_users'][$field];
00211                                 $BE_USER->user[$field] = $d['be_users'][$field];
00212                             }
00213                         }
00214                     }
00215                     if ($config['type'] == 'check') {
00216                         $BE_USER->uc[$field] = isset($d[$field]) ? 1 : 0;
00217                     } else {
00218                         $BE_USER->uc[$field] = htmlspecialchars($d[$field]);
00219                     }
00220                 }
00221 
00222                     // Personal data for the users be_user-record (email, name, password...)
00223                     // If email and name is changed, set it in the users record:
00224                 $be_user_data = $d['be_users'];
00225 
00226                 $this->passwordIsSubmitted = (strlen($be_user_data['password']) > 0);
00227                 $passwordIsConfirmed = ($this->passwordIsSubmitted && $be_user_data['password'] === $be_user_data['password2']);
00228 
00229                     // Update the real name:
00230                 if ($be_user_data['realName'] !== $BE_USER->user['realName']) {
00231                     $BE_USER->user['realName'] = $storeRec['be_users'][$beUserId]['realName'] = substr($be_user_data['realName'], 0, 80);
00232                 }
00233                     // Update the email address:
00234                 if ($be_user_data['email'] !== $BE_USER->user['email']) {
00235                     $BE_USER->user['email'] = $storeRec['be_users'][$beUserId]['email'] = substr($be_user_data['email'], 0, 80);
00236                 }
00237                     // Update the password:
00238                 if ($passwordIsConfirmed) {
00239                     $storeRec['be_users'][$beUserId]['password'] = $be_user_data['password2'];
00240                     $this->passwordIsUpdated = TRUE;
00241                 }
00242 
00243                 $this->saveData = TRUE;
00244             }
00245 
00246             $BE_USER->overrideUC(); // Inserts the overriding values.
00247 
00248             $save_after = md5(serialize($BE_USER->uc));
00249             if ($save_before!=$save_after)  {   // If something in the uc-array of the user has changed, we save the array...
00250                 $BE_USER->writeUC($BE_USER->uc);
00251                 $BE_USER->writelog(254, 1, 0, 1, 'Personal settings changed', array());
00252                 $this->setupIsUpdated = TRUE;
00253             }
00254                 // If the temporary data has been cleared, lets make a log note about it
00255             if ($this->tempDataIsCleared) {
00256                 $BE_USER->writelog(254, 1, 0, 1, $GLOBALS['LANG']->getLL('tempDataClearedLog'), array());
00257             }
00258 
00259                 // Persist data if something has changed:
00260             if (count($storeRec) && $this->saveData) {
00261                     // Make instance of TCE for storing the changes.
00262                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00263                 $tce->stripslashes_values=0;
00264                 $tce->start($storeRec,Array(),$BE_USER);
00265                 $tce->admin = 1;    // This is so the user can actually update his user record.
00266                 $tce->bypassWorkspaceRestrictions = TRUE;   // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
00267                 $tce->process_datamap();
00268                 unset($tce);
00269 
00270                 if (!$this->passwordIsUpdated || count($storeRec['be_users'][$beUserId]) > 1) {
00271                     $this->setupIsUpdated = TRUE;
00272                 }
00273             }
00274         }
00275     }
00276 
00277 
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288     /******************************
00289      *
00290      * Rendering module
00291      *
00292      ******************************/
00293 
00294     /**
00295      * Initializes the module for display of the settings form.
00296      *
00297      * @return  void
00298      */
00299     function init() {
00300         $this->MCONF = $GLOBALS['MCONF'];
00301 
00302             // check Install Tool enable file
00303         $this->setInstallToolFileExists();
00304         $this->setInstallToolFileKeep();
00305 
00306             // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
00307         $scriptUser = $this->getRealScriptUserObj();
00308             // ... and checking module access for the logged in user.
00309         $scriptUser->modAccess($this->MCONF, 1);
00310 
00311         $this->isAdmin = $scriptUser->isAdmin();
00312 
00313             // Getting the 'override' values as set might be set in User TSconfig
00314         $this->overrideConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.override');
00315             // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1)
00316         $this->tsFieldConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.fields');
00317 
00318             // Create instance of object for output of data
00319         $this->doc = t3lib_div::makeInstance('template');
00320         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00321         $this->doc->setModuleTemplate('templates/setup.html');
00322         $this->doc->form = '<form action="index.php" method="post" name="usersetup" enctype="application/x-www-form-urlencoded">';
00323         $this->doc->tableLayout = array(
00324             'defRow' => array(
00325                 '0' => array('<td class="td-label">','</td>'),
00326                 'defCol' => array('<td valign="top">','</td>')
00327             )
00328         );
00329         $this->doc->table_TR = '<tr>';
00330         $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2" class="typo3-usersettings">';
00331     }
00332 
00333     /**
00334      * Generate the main settings formular:
00335      *
00336      * @return  void
00337      */
00338     function main() {
00339         global $BE_USER,$LANG,$BACK_PATH,$TBE_MODULES;
00340 
00341             // file creation / delete
00342         if ($this->isAdmin) {
00343             if ($this->installToolFileKeep) {
00344                 $flashMessage = t3lib_div::makeInstance(
00345                     't3lib_FlashMessage',
00346                     $LANG->getLL('enableInstallTool.fileHasKeep'),
00347                     $LANG->getLL('enableInstallTool.file'),
00348                     t3lib_FlashMessage::WARNING
00349                 );
00350                 $this->content .= $flashMessage->render();
00351             }
00352 
00353             if (t3lib_div::_POST('deleteInstallToolEnableFile')) {
00354                 unlink(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
00355                 $this->setInstallToolFileExists();
00356                 if ($this->getInstallToolFileExists()) {
00357                     $flashMessage = t3lib_div::makeInstance(
00358                         't3lib_FlashMessage',
00359                         $LANG->getLL('enableInstallTool.fileDelete_failed'),
00360                         $LANG->getLL('enableInstallTool.file'),
00361                         t3lib_FlashMessage::ERROR
00362                     );
00363                 } else {
00364                     $flashMessage = t3lib_div::makeInstance(
00365                         't3lib_FlashMessage',
00366                         $LANG->getLL('enableInstallTool.fileDelete_ok'),
00367                         $LANG->getLL('enableInstallTool.file'),
00368                         t3lib_FlashMessage::OK
00369                     );
00370             }
00371                 $this->content .= $flashMessage->render();
00372             }
00373             if (t3lib_div::_POST('createInstallToolEnableFile')) {
00374                 touch(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
00375                 t3lib_div::fixPermissions(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
00376                 $this->setInstallToolFileExists();
00377                 if ($this->getInstallToolFileExists()) {
00378                     $flashMessage = t3lib_div::makeInstance(
00379                         't3lib_FlashMessage',
00380                         $LANG->getLL('enableInstallTool.fileCreate_ok'),
00381                         $LANG->getLL('enableInstallTool.file'),
00382                         t3lib_FlashMessage::OK
00383                     );
00384                 } else {
00385                     $flashMessage = t3lib_div::makeInstance(
00386                         't3lib_FlashMessage',
00387                         $LANG->getLL('enableInstallTool.fileCreate_failed'),
00388                         $LANG->getLL('enableInstallTool.file'),
00389                         t3lib_FlashMessage::ERROR
00390                     );
00391             }
00392                 $this->content .= $flashMessage->render();
00393         }
00394         }
00395 
00396         if ($this->languageUpdate) {
00397             $this->doc->JScodeArray['languageUpdate'] .=  '
00398                 if (top.refreshMenu) {
00399                     top.refreshMenu();
00400                 } else {
00401                     top.TYPO3ModuleMenu.refreshMenu();
00402                 }
00403             ';
00404         }
00405 
00406         if ($this->pagetreeNeedsRefresh) {
00407             t3lib_BEfunc::setUpdateSignal('updatePageTree');
00408         }
00409 
00410             // Start page:
00411         $this->doc->loadJavascriptLib('md5.js');
00412 
00413             // use a wrapper div
00414         $this->content .= '<div id="user-setup-wrapper">';
00415 
00416             // Load available backend modules
00417         $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00418         $this->loadModules->observeWorkspaces = true;
00419         $this->loadModules->load($TBE_MODULES);
00420 
00421         $this->content .= $this->doc->header($LANG->getLL('UserSettings').' - '.$BE_USER->user['realName'].' ['.$BE_USER->user['username'].']');
00422 
00423             // show if setup was saved
00424         if ($this->setupIsUpdated && !$this->tempDataIsCleared && !$this->settingsAreResetToDefault) {
00425             $flashMessage = t3lib_div::makeInstance(
00426                 't3lib_FlashMessage',
00427                 $LANG->getLL('setupWasUpdated'),
00428                 $LANG->getLL('UserSettings')
00429             );
00430             $this->content .= $flashMessage->render();
00431         }
00432             // Show if temporary data was cleared
00433         if ($this->tempDataIsCleared) {
00434             $flashMessage = t3lib_div::makeInstance(
00435                 't3lib_FlashMessage',
00436                 $LANG->getLL('tempDataClearedFlashMessage'),
00437                 $LANG->getLL('tempDataCleared')
00438             );
00439             $this->content .= $flashMessage->render();
00440         }
00441             // Show if temporary data was cleared
00442         if ($this->settingsAreResetToDefault) {
00443             $flashMessage = t3lib_div::makeInstance(
00444                 't3lib_FlashMessage',
00445                 $LANG->getLL('settingsAreReset'),
00446                 $LANG->getLL('resetConfiguration')
00447             );
00448             $this->content .= $flashMessage->render();
00449         }
00450             // If password is updated, output whether it failed or was OK.
00451         if ($this->passwordIsSubmitted) {
00452             if ($this->passwordIsUpdated) {
00453                 $flashMessage = t3lib_div::makeInstance(
00454                     't3lib_FlashMessage',
00455                     $LANG->getLL('newPassword_ok'),
00456                     $LANG->getLL('newPassword')
00457                 );
00458             } else {
00459                 $flashMessage = t3lib_div::makeInstance(
00460                     't3lib_FlashMessage',
00461                     $LANG->getLL('newPassword_failed'),
00462                     $LANG->getLL('newPassword'),
00463                     t3lib_FlashMessage::ERROR
00464                 );
00465             }
00466             $this->content .= $flashMessage->render();
00467         }
00468 
00469 
00470             // render the menu items
00471         $menuItems = $this->renderUserSetup();
00472 
00473         $this->content .= $this->doc->spacer(20) . $this->doc->getDynTabMenu($menuItems, 'user-setup', FALSE, FALSE, 0, 1, FALSE, 1, $this->dividers2tabs);
00474 
00475         $formToken = $this->formProtection->generateToken('BE user setup', 'edit');
00476 
00477             // Submit and reset buttons
00478         $this->content .= $this->doc->spacer(20);
00479         $this->content .= $this->doc->section('',
00480             t3lib_BEfunc::cshItem('_MOD_user_setup', 'reset', $BACK_PATH) . '
00481             <input type="hidden" name="simUser" value="'.$this->simUser.'" />
00482             <input type="hidden" name="formToken" value="' . $formToken . '" />
00483             <input type="submit" name="data[save]" value="'.$LANG->getLL('save').'" />
00484             <input type="button" value="' . $LANG->getLL('resetConfiguration') .
00485                     '" onclick="if(confirm(\''.$LANG->getLL('setToStandardQuestion').'\')) {document.getElementById(\'setValuesToDefault\').value=1;this.form.submit();}" />
00486             <input type="button" value="' . $LANG->getLL('clearSessionVars') .
00487                     '"  onclick="if(confirm(\'' . $LANG->getLL('clearSessionVarsQuestion') . '\')){document.getElementById(\'clearSessionVars\').value=1;this.form.submit();}" />
00488             <input type="hidden" name="data[setValuesToDefault]" value="0" id="setValuesToDefault" />
00489             <input type="hidden" name="data[clearSessionVars]" value="0" id="clearSessionVars" />'
00490         );
00491 
00492             // Notice
00493         $this->content .= $this->doc->spacer(30);
00494         $flashMessage = t3lib_div::makeInstance(
00495             't3lib_FlashMessage',
00496             $LANG->getLL('activateChanges'),
00497             '',
00498             t3lib_FlashMessage::INFO
00499         );
00500         $this->content .= $flashMessage->render();
00501             // end of wrapper div
00502         $this->content .= '</div>';
00503 
00504             // Setting up the buttons and markers for docheader
00505         $docHeaderButtons = $this->getButtons();
00506         $markers['CSH'] = $docHeaderButtons['csh'];
00507         $markers['CONTENT'] = $this->content;
00508 
00509             // Build the <body> for the module
00510         $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
00511             // Renders the module page
00512         $this->content = $this->doc->render(
00513             $LANG->getLL('UserSettings'),
00514             $this->content
00515         );
00516 
00517     }
00518 
00519     /**
00520      * Sets existance of Install Tool file
00521      *
00522      * return void
00523      */
00524     public function setInstallToolFileExists() {
00525         $this->installToolFileExists = is_file(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
00526     }
00527 
00528     /**
00529      * Sets property if Install Tool file contains "KEEP_FILE"
00530      */
00531     public function setInstallToolFileKeep() {
00532         if ($this->installToolFileExists) {
00533             $this->installToolFileKeep = (trim(file_get_contents(PATH_typo3conf . 'ENABLE_INSTALL_TOOL')) === 'KEEP_FILE');
00534         }
00535     }
00536 
00537     /**
00538      * Gets property installToolFileExists
00539      *
00540      * @return boolean $this->installToolFileExists
00541      */
00542     public function getInstallToolFileExists() {
00543         return $this->installToolFileExists;
00544     }
00545 
00546     /**
00547      * Gets property installToolFileKeep
00548      *
00549      * @return boolean $this->installToolFileKeep
00550      */
00551     public function getInstallToolFileKeep() {
00552         return $this->installToolFileKeep;
00553     }
00554 
00555     /**
00556      * Prints the content / ends page
00557      *
00558      * @return  void
00559      */
00560     function printContent() {
00561         echo $this->content;
00562     }
00563 
00564     /**
00565      * Create the panel of buttons for submitting the form or otherwise perform operations.
00566      *
00567      * @return  array   all available buttons as an assoc. array
00568      */
00569     protected function getButtons() {
00570         $buttons = array(
00571             'csh' => '',
00572             'save' => '',
00573             'shortcut' => '',
00574         );
00575 
00576         $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'], '|', true);
00577 
00578         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00579             $buttons['shortcut'] = $this->doc->makeShortcutIcon('','',$this->MCONF['name']);
00580         }
00581 
00582         return $buttons;
00583     }
00584 
00585 
00586 
00587 
00588     /******************************
00589      *
00590      * Render module
00591      *
00592      ******************************/
00593 
00594 
00595      /**
00596      * renders the data for all tabs in the user setup and returns
00597      * everything that is needed with tabs and dyntab menu
00598      *
00599      * @return  ready to use for the dyntabmenu itemarray
00600      */
00601     protected function renderUserSetup() {
00602         $result = array();
00603         $firstTabLabel = '';
00604         $code = array();
00605         $i = 0;
00606 
00607         $fieldArray = $this->getFieldsFromShowItem();
00608 
00609         $this->dividers2tabs = isset($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) ? intval($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) : 0;
00610         $tabLabel = '';
00611 
00612         foreach ($fieldArray as $fieldName) {
00613             $more = '';
00614 
00615             if (substr($fieldName, 0, 8) == '--div--;') {
00616                 if ($firstTabLabel == '') {
00617                     // first tab
00618                     $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
00619                     $firstTabLabel = $tabLabel;
00620                 } else {
00621                     if ($this->dividers2tabs) {
00622                         $result[] = array(
00623                             'label'   => $tabLabel,
00624                             'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
00625                         );
00626                         $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
00627                         $i = 0;
00628                         $code = array();
00629                     }
00630                 }
00631                 continue;
00632             }
00633 
00634             $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
00635 
00636                 // field my be disabled in setup.fields
00637             if (isset($this->tsFieldConf[$fieldName . '.']['disabled']) && $this->tsFieldConf[$fieldName . '.']['disabled'] == 1) {
00638                 continue;
00639             }
00640             if (isset($config['access']) && !$this->checkAccess($config)) {
00641                 continue;
00642             }
00643 
00644             $label = $this->getLabel($config['label'], $fieldName);
00645             $label = $this->getCSH($config['csh'] ? $config['csh'] : $fieldName, $label);
00646 
00647             $type = $config['type'];
00648             $eval = $config['eval'];
00649             $class = $config['class'];
00650             $style = $config['style'];
00651 
00652             if ($class) {
00653                 $more .= ' class="' . $class . '"';
00654             }
00655             if ($style) {
00656                 $more .= ' style="' . $style . '"';
00657             }
00658             if ($this->overrideConf[$fieldName]) {
00659                 $more .= ' disabled="disabled"';
00660             }
00661 
00662             $value = $config['table'] == 'be_users' ? $GLOBALS['BE_USER']->user[$fieldName] : $GLOBALS['BE_USER']->uc[$fieldName];
00663             if (!$value && isset($config['default'])) {
00664                 $value = $config['default'];
00665             }
00666 
00667             switch ($type) {
00668                 case 'text':
00669                 case 'password':
00670                     $dataAdd = '';
00671                     if ($config['table'] == 'be_users') {
00672                         $dataAdd = '[be_users]';
00673                     }
00674                     if ($eval == 'md5') {
00675                         $more .= ' onchange="this.value=this.value?MD5(this.value):\'\';"';
00676                     }
00677 
00678                     if ($type == 'password') {
00679                         $value = '';
00680                     }
00681 
00682                     $noAutocomplete = ($type == 'password' ? 'autocomplete="off" ' : '');
00683                     $html = '<input id="field_' . $fieldName . '"
00684                             type="' . $type . '"
00685                             name="data' . $dataAdd . '[' . $fieldName . ']" ' .
00686                             $noAutocomplete .
00687                             'value="' . htmlspecialchars($value) . '" ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . $more . ' />';
00688                 break;
00689                 case 'check':
00690                     if (!$class) {
00691                         $more .= ' class="check"';
00692                     }
00693                     $html = '<input id="field_' . $fieldName . '"
00694                                     type="checkbox"
00695                                     name="data[' . $fieldName . ']"' .
00696                                     ($value ? ' checked="checked"' : '') . $more . ' />';
00697                 break;
00698                 case 'select':
00699                     if (!$class) {
00700                         $more .= ' class="select"';
00701                     }
00702 
00703                     if ($config['itemsProcFunc']) {
00704                         $html = t3lib_div::callUserFunction($config['itemsProcFunc'], $config, $this, '');
00705                     } else {
00706                         $html = '<select id="field_' . $fieldName . '" name="data[' . $fieldName . ']"' . $more . '>' . LF;
00707                         foreach ($config['items'] as $key => $optionLabel) {
00708                             $html .= '<option value="' . $key . '"' .
00709                                 ($value == $key ? ' selected="selected"' : '') .
00710                                 '>' . $this->getLabel($optionLabel, '', false) . '</option>' . LF;
00711                         }
00712                         $html .= '</select>';
00713                     }
00714 
00715                 break;
00716                 case 'user':
00717                     $html = t3lib_div::callUserFunction($config['userFunc'], $config, $this, '');
00718                 break;
00719                 default:
00720                     $html = '';
00721             }
00722 
00723 
00724             $code[$i][1] = $label;
00725             $code[$i++][2] = $html;
00726 
00727 
00728 
00729         }
00730 
00731         if ($this->dividers2tabs == 0) {
00732             $tabLabel = $firstTabLabel;
00733         }
00734 
00735         $result[] = array(
00736             'label'   => $tabLabel,
00737             'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
00738         );
00739 
00740 
00741         return $result;
00742     }
00743 
00744 
00745 
00746 
00747 
00748 
00749     /******************************
00750      *
00751      * Helper functions
00752      *
00753      ******************************/
00754 
00755     /**
00756      * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
00757      * Anyway: The REAL user is returned - the one logged in.
00758      *
00759      * @return  object      The REAL user is returned - the one logged in.
00760      */
00761     protected function getRealScriptUserObj()   {
00762         return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
00763     }
00764 
00765 
00766     /**
00767     * Return a select with available languages
00768      *
00769     * @return   string      complete select as HTML string or warning box if something went wrong.
00770      */
00771     public function renderLanguageSelect($params, $pObj) {
00772 
00773             // compile the languages dropdown
00774         $languageOptions = array(
00775             '000000000' => LF . '<option value="">' . $GLOBALS['LANG']->getLL('lang_default', 1) . '</option>'
00776         );
00777             // traverse the number of languages
00778         $theLanguages = t3lib_div::trimExplode('|', TYPO3_languages);
00779         foreach ($theLanguages as $language) {
00780             if ($language != 'default') {
00781                 $languageValue = $GLOBALS['LOCAL_LANG']['default']['lang_' . $language];
00782                 $localLabel = '  -  ['.htmlspecialchars($languageValue) . ']';
00783                 $unavailable = (is_dir(PATH_typo3conf . 'l10n/' . $language) ? false : true);
00784                 if (!$unavailable) {
00785                     $languageOptions[$languageValue . '--' . $language] = '
00786                     <option value="'.$language.'"'.($GLOBALS['BE_USER']->uc['lang'] == $language ? ' selected="selected"' : '') . ($unavailable ? ' class="c-na"' : '').'>'.$GLOBALS['LANG']->getLL('lang_' . $language, 1) . $localLabel . '</option>';
00787                 }
00788             }
00789         }
00790         ksort($languageOptions);
00791         $languageCode = '
00792                 <select id="field_lang" name="data[lang]" class="select">' .
00793                     implode('', $languageOptions) . '
00794                 </select>';
00795         if ( $GLOBALS['BE_USER']->uc['lang'] && !@is_dir(PATH_typo3conf . 'l10n/' . $GLOBALS['BE_USER']->uc['lang'])) {
00796             $languageUnavailableWarning = 'The selected language "'
00797                 . $GLOBALS['LANG']->getLL('lang_' . $GLOBALS['BE_USER']->uc['lang'], 1)
00798                 . '" is not available before the language pack is installed.<br />'
00799                 . ($GLOBALS['BE_USER']->isAdmin() ?
00800                     'You can use the Extension Manager to easily download and install new language packs.'
00801                 :   'Please ask your system administrator to do this.');
00802 
00803 
00804             $languageUnavailableMessage = t3lib_div::makeInstance(
00805                 't3lib_FlashMessage',
00806                 $languageUnavailableWarning,
00807                 '',
00808                 t3lib_FlashMessage::WARNING
00809             );
00810 
00811             $languageCode = $languageUnavailableMessage->render() . $languageCode;
00812         }
00813 
00814         return $languageCode;
00815     }
00816 
00817     /**
00818     * Returns a select with all modules for startup
00819     *
00820     * @return   string      complete select as HTML string
00821     */
00822     public function renderStartModuleSelect($params, $pObj) {
00823             // start module select
00824         if (empty($GLOBALS['BE_USER']->uc['startModule']))  {
00825             $GLOBALS['BE_USER']->uc['startModule'] = $GLOBALS['BE_USER']->uc_default['startModule'];
00826         }
00827         $startModuleSelect = '<option value=""></option>';
00828         foreach ($pObj->loadModules->modules as $mainMod => $modData) {
00829             if (isset($modData['sub']) && is_array($modData['sub'])) {
00830                 $startModuleSelect .= '<option disabled="disabled">'.$GLOBALS['LANG']->moduleLabels['tabs'][$mainMod.'_tab'].'</option>';
00831                 foreach ($modData['sub'] as $subKey => $subData) {
00832                     $modName = $subData['name'];
00833                     $startModuleSelect .= '<option value="' . $modName . '"' . ($GLOBALS['BE_USER']->uc['startModule'] == $modName ? ' selected="selected"' : '') . '>';
00834                     $startModuleSelect .= ' - ' . $GLOBALS['LANG']->moduleLabels['tabs'][$modName.'_tab'] . '</option>';
00835                 }
00836             }
00837         }
00838 
00839 
00840         return '<select id="field_startModule" name="data[startModule]" class="select">' . $startModuleSelect . '</select>';
00841         }
00842 
00843     /**
00844      *
00845      * @param array $params                    config of the field
00846      * @param SC_mod_user_setup_index $parent  this class as reference
00847      * @return string                          html with description and button
00848      */
00849     public function renderInstallToolEnableFileButton(array $params, SC_mod_user_setup_index $parent) {
00850             // Install Tool access file
00851         $installToolEnableFile = PATH_typo3conf . 'ENABLE_INSTALL_TOOL';
00852         if ($parent->getInstallToolFileExists() && ($GLOBALS['EXEC_TIME'] - filemtime($installToolEnableFile) > 3600)) {
00853             if (!$parent->getInstallToolFileKeep()) {
00854                     // Delete the file if it is older than 3600s (1 hour)
00855                 unlink($installToolEnableFile);
00856                 $parent->setInstallToolFileExists();
00857             }
00858         }
00859 
00860         if ($parent->getInstallToolFileExists()) {
00861             return '<input type="button" name="deleteInstallToolEnableFile"' .
00862                     ($parent->getInstallToolFileKeep() ? ' disabled="disabled"' : '') .
00863                     ' value="' . $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:enableInstallTool.deleteFile') . '" onclick="document.getElementById(\'deleteInstallToolEnableFile\').value=1;this.form.submit();" />
00864                     <input type="hidden" name="deleteInstallToolEnableFile" value="0" id="deleteInstallToolEnableFile" />
00865                     ';
00866 
00867         } else {
00868             return '<input type="button" name="createInstallToolEnableFile" value="' .
00869                     $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:enableInstallTool.createFile') . '" onclick="document.getElementById(\'createInstallToolEnableFile\').value=1;this.form.submit();" />
00870                     <input type="hidden" name="createInstallToolEnableFile" value="0" id="createInstallToolEnableFile" />';
00871         }
00872     }
00873 
00874     /**
00875      * Will make the simulate-user selector if the logged in user is administrator.
00876      * It will also set the GLOBAL(!) BE_USER to the simulated user selected if any (and set $this->OLD_BE_USER to logged in user)
00877      *
00878      * @return  void
00879      */
00880     public function simulateUser()  {
00881         global $BE_USER,$LANG,$BACK_PATH;
00882 
00883         // *******************************************************************************
00884         // If admin, allow simulation of another user
00885         // *******************************************************************************
00886         $this->simUser = 0;
00887         $this->simulateSelector = '';
00888         unset($this->OLD_BE_USER);
00889         if ($BE_USER->isAdmin())    {
00890             $this->simUser = intval(t3lib_div::_GP('simUser'));
00891 
00892                 // Make user-selector:
00893             $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName', t3lib_BEfunc::BEenableFields('be_users'));
00894             $opt = array();
00895             foreach ($users as $rr) {
00896                 if ($rr['uid'] != $BE_USER->user['uid']) {
00897                     $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser==$rr['uid']?' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
00898                 }
00899             }
00900             if (count($opt)) {
00901                 $this->simulateSelector = '<select id="field_simulate" name="simulateUser" onchange="window.location.href=\'index.php?simUser=\'+this.options[this.selectedIndex].value;"><option></option>'.implode('',$opt).'</select>';
00902             }
00903         }
00904 
00905         if ($this->simUser>0)   {   // This can only be set if the previous code was executed.
00906             $this->OLD_BE_USER = $BE_USER;  // Save old user...
00907             unset($BE_USER);    // Unset current
00908 
00909             $BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth'); // New backend user object
00910             $BE_USER->OS = TYPO3_OS;
00911             $BE_USER->setBeUserByUid($this->simUser);
00912             $BE_USER->fetchGroupData();
00913             $BE_USER->backendSetUC();
00914             $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
00915         }
00916     }
00917 
00918     /**
00919     * Returns a select with simulate users
00920     *
00921     * @return   string      complete select as HTML string
00922     */
00923     public function renderSimulateUserSelect($params, $pObj) {
00924         return $pObj->simulateSelector;
00925     }
00926 
00927     /**
00928     * Returns access check (currently only "admin" is supported)
00929     *
00930     * @param    array       $config: Configuration of the field, access mode is defined in key 'access'
00931     * @return   boolean     Whether it is allowed to modify the given field
00932     */
00933     protected function checkAccess(array $config) {
00934         $access = $config['access'];
00935             // check for hook
00936         if (strpos($access, 'tx_') === 0) {
00937             $accessObject = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access] . ':&' . $access);
00938             if (is_object($accessObject) && method_exists($accessObject, 'accessLevelCheck'))   {
00939                     // initialize vars. If method fails, $set will be set to false
00940                 return $accessObject->accessLevelCheck($config);
00941             }
00942         } elseif ($access == 'admin') {
00943             return $this->isAdmin;
00944         }
00945     }
00946 
00947 
00948     /**
00949      * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
00950      *
00951      * @param   string      Locallang key
00952      * @param   string      Alternative override-config key
00953      * @param   boolean     Defines whether the string should be wrapped in a <label> tag.
00954      * @param   string      Alternative id for use in "for" attribute of <label> tag. By default the $str key is used prepended with "field_".
00955      * @return  string      HTML output.
00956      */
00957     protected function getLabel($str, $key='', $addLabelTag=true, $altLabelTagId='')    {
00958         if (substr($str, 0, 4) == 'LLL:') {
00959             $out = $GLOBALS['LANG']->sL($str);
00960         } else {
00961             $out = htmlspecialchars($str);
00962         }
00963 
00964 
00965         if (isset($this->overrideConf[($key?$key:$str)]))   {
00966             $out = '<span style="color:#999999">'.$out.'</span>';
00967         }
00968 
00969         if($addLabelTag) {
00970             $out = '<label for="' . ($altLabelTagId ? $altLabelTagId : 'field_' . $key) . '">' . $out . '</label>';
00971         }
00972         return $out;
00973     }
00974 
00975     /**
00976      * Returns the CSH Icon for given string
00977      *
00978      * @param   string      Locallang key
00979      * @param   string      The label to be used, that should be wrapped in help
00980      * @return  string      HTML output.
00981      */
00982     protected function getCSH($str, $label) {
00983         $context = '_MOD_user_setup';
00984         $field = $str;
00985         $strParts = explode(':', $str);
00986         if (count($strParts) > 1) {
00987                 // Setting comes from another extension
00988             $context = $strParts[0];
00989             $field = $strParts[1];
00990         } else if (!t3lib_div::inList('language,simuser', $str)) {
00991             $field = 'option_' . $str;
00992         }
00993         return t3lib_BEfunc::wrapInHelp($context, $field, $label);
00994     }
00995     /**
00996      * Returns array with fields defined in $GLOBALS['TYPO3_USER_SETTINGS']['showitem']
00997      *
00998      * @param   void
00999      * @return  array   array with fieldnames visible in form
01000      */
01001     protected function getFieldsFromShowItem() {
01002         $fieldList = $GLOBALS['TYPO3_USER_SETTINGS']['showitem'];
01003 
01004             // disable fields depended on settings
01005         if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
01006             $fieldList = t3lib_div::rmFromList('edit_RTE', $fieldList);
01007         }
01008 
01009         $fieldArray = t3lib_div::trimExplode(',', $fieldList, TRUE);
01010         return $fieldArray;
01011     }
01012 }
01013 
01014 
01015 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php'])) {
01016     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']);
01017 }
01018 
01019 
01020 
01021 // Make instance:
01022 $SOBE = t3lib_div::makeInstance('SC_mod_user_setup_index');
01023 $SOBE->simulateUser();
01024 $SOBE->storeIncomingData();
01025 
01026 // These includes MUST be afterwards the settings are saved...!
01027 require ($BACK_PATH.'template.php');
01028 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
01029 
01030 $SOBE->init();
01031 $SOBE->main();
01032 $SOBE->printContent();
01033 
01034 $SOBE->getFormProtection()->persistTokens();
01035 ?>