PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/typo3/sysext/setup/mod/index.php

https://github.com/andreaswolf/typo3-tceforms
PHP | 1035 lines | 602 code | 162 blank | 271 comment | 117 complexity | 9ccd872791bb4cc253f87b3eccd629b8 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2011 Kasper Skårhøj (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: User configuration
  29. *
  30. * This module lets users viev and change their individual settings
  31. *
  32. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  33. * Revised for TYPO3 3.7 6/2004 by Kasper Skårhøj
  34. * XHTML compatible.
  35. */
  36. /**
  37. * [CLASS/FUNCTION INDEX of SCRIPT]
  38. *
  39. *
  40. *
  41. * 86: class SC_mod_user_setup_index
  42. *
  43. * SECTION: Saving data
  44. * 114: function storeIncomingData()
  45. *
  46. * SECTION: Rendering module
  47. * 216: function init()
  48. * 248: function main()
  49. * 403: function printContent()
  50. *
  51. * SECTION: Helper functions
  52. * 432: function getRealScriptUserObj()
  53. * 442: function simulateUser()
  54. * 488: function setLabel($str,$key='')
  55. *
  56. * TOTAL FUNCTIONS: 7
  57. * (This index is automatically created/updated by the extension "extdeveval")
  58. *
  59. */
  60. unset($MCONF);
  61. require('conf.php');
  62. require($BACK_PATH.'init.php');
  63. /**
  64. * Script class for the Setup module
  65. *
  66. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  67. * @package TYPO3
  68. * @subpackage tx_setup
  69. */
  70. class SC_mod_user_setup_index {
  71. // Internal variables:
  72. var $MCONF = array();
  73. var $MOD_MENU = array();
  74. var $MOD_SETTINGS = array();
  75. /**
  76. * document template object
  77. *
  78. * @var mediumDoc
  79. */
  80. var $doc;
  81. var $content;
  82. var $overrideConf;
  83. /**
  84. * backend user object, set during simulate-user operation
  85. *
  86. * @var t3lib_beUserAuth
  87. */
  88. var $OLD_BE_USER;
  89. var $languageUpdate;
  90. protected $pagetreeNeedsRefresh = FALSE;
  91. protected $isAdmin;
  92. protected $dividers2tabs;
  93. protected $tsFieldConf;
  94. protected $saveData = FALSE;
  95. protected $passwordIsUpdated = FALSE;
  96. protected $passwordIsSubmitted = FALSE;
  97. protected $setupIsUpdated = FALSE;
  98. protected $tempDataIsCleared = FALSE;
  99. protected $settingsAreResetToDefault = FALSE;
  100. protected $installToolFileExists = FALSE;
  101. protected $installToolFileKeep = FALSE;
  102. /**
  103. * Form protection instance
  104. *
  105. * @var t3lib_formprotection_BackendFormProtection
  106. */
  107. protected $formProtection;
  108. /******************************
  109. *
  110. * Saving data
  111. *
  112. ******************************/
  113. /**
  114. * Instanciate the form protection before a simulated user is initialized.
  115. */
  116. public function __construct() {
  117. $this->formProtection = t3lib_formProtection_Factory::get();
  118. }
  119. /**
  120. * Getter for the form protection instance.
  121. */
  122. public function getFormProtection() {
  123. return $this->formProtection;
  124. }
  125. /**
  126. * If settings are submitted to _POST[DATA], store them
  127. * NOTICE: This method is called before the template.php is included. See
  128. * bottom of document.
  129. */
  130. public function storeIncomingData() {
  131. /* @var $BE_USER t3lib_beUserAuth */
  132. global $BE_USER;
  133. // First check if something is submittet in the data-array from POST vars
  134. $d = t3lib_div::_POST('data');
  135. $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
  136. $beUserId = $BE_USER->user['uid'];
  137. $storeRec = array();
  138. $fieldList = $this->getFieldsFromShowItem();
  139. if (is_array($d) && $this->formProtection->validateToken(
  140. (string) t3lib_div::_POST('formToken'),
  141. 'BE user setup', 'edit'
  142. )
  143. ) {
  144. // UC hashed before applying changes
  145. $save_before = md5(serialize($BE_USER->uc));
  146. // PUT SETTINGS into the ->uc array:
  147. // reload left frame when switching BE language
  148. if (isset($d['lang']) && ($d['lang'] != $BE_USER->uc['lang'])) {
  149. $this->languageUpdate = true;
  150. }
  151. // reload pagetree if the title length is changed
  152. if (isset($d['titleLen']) && ($d['titleLen'] !== $BE_USER->uc['titleLen'])) {
  153. $this->pagetreeNeedsRefresh = TRUE;
  154. }
  155. if ($d['setValuesToDefault']) {
  156. // If every value should be default
  157. $BE_USER->resetUC();
  158. $this->settingsAreResetToDefault = TRUE;
  159. } elseif ($d['clearSessionVars']) {
  160. foreach ($BE_USER->uc as $key => $value) {
  161. if (!isset($columns[$key])) {
  162. unset ($BE_USER->uc[$key]);
  163. }
  164. }
  165. $this->tempDataIsCleared = TRUE;
  166. } elseif ($d['save']) {
  167. // save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
  168. foreach($columns as $field => $config) {
  169. if (!in_array($field, $fieldList)) {
  170. continue;
  171. }
  172. if ($config['table']) {
  173. if ($config['table'] == 'be_users' && !in_array($field, array('password', 'password2', 'email', 'realName', 'admin'))) {
  174. if (!isset($config['access']) || $this->checkAccess($config) && $BE_USER->user[$field] !== $d['be_users'][$field]) {
  175. $storeRec['be_users'][$beUserId][$field] = $d['be_users'][$field];
  176. $BE_USER->user[$field] = $d['be_users'][$field];
  177. }
  178. }
  179. }
  180. if ($config['type'] == 'check') {
  181. $BE_USER->uc[$field] = isset($d[$field]) ? 1 : 0;
  182. } else {
  183. $BE_USER->uc[$field] = htmlspecialchars($d[$field]);
  184. }
  185. }
  186. // Personal data for the users be_user-record (email, name, password...)
  187. // If email and name is changed, set it in the users record:
  188. $be_user_data = $d['be_users'];
  189. $this->passwordIsSubmitted = (strlen($be_user_data['password']) > 0);
  190. $passwordIsConfirmed = ($this->passwordIsSubmitted && $be_user_data['password'] === $be_user_data['password2']);
  191. // Update the real name:
  192. if ($be_user_data['realName'] !== $BE_USER->user['realName']) {
  193. $BE_USER->user['realName'] = $storeRec['be_users'][$beUserId]['realName'] = substr($be_user_data['realName'], 0, 80);
  194. }
  195. // Update the email address:
  196. if ($be_user_data['email'] !== $BE_USER->user['email']) {
  197. $BE_USER->user['email'] = $storeRec['be_users'][$beUserId]['email'] = substr($be_user_data['email'], 0, 80);
  198. }
  199. // Update the password:
  200. if ($passwordIsConfirmed) {
  201. $storeRec['be_users'][$beUserId]['password'] = $be_user_data['password2'];
  202. $this->passwordIsUpdated = TRUE;
  203. }
  204. $this->saveData = TRUE;
  205. }
  206. $BE_USER->overrideUC(); // Inserts the overriding values.
  207. $save_after = md5(serialize($BE_USER->uc));
  208. if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
  209. $BE_USER->writeUC($BE_USER->uc);
  210. $BE_USER->writelog(254, 1, 0, 1, 'Personal settings changed', array());
  211. $this->setupIsUpdated = TRUE;
  212. }
  213. // If the temporary data has been cleared, lets make a log note about it
  214. if ($this->tempDataIsCleared) {
  215. $BE_USER->writelog(254, 1, 0, 1, $GLOBALS['LANG']->getLL('tempDataClearedLog'), array());
  216. }
  217. // Persist data if something has changed:
  218. if (count($storeRec) && $this->saveData) {
  219. // Make instance of TCE for storing the changes.
  220. $tce = t3lib_div::makeInstance('t3lib_TCEmain');
  221. $tce->stripslashes_values=0;
  222. $tce->start($storeRec,Array(),$BE_USER);
  223. $tce->admin = 1; // This is so the user can actually update his user record.
  224. $tce->bypassWorkspaceRestrictions = TRUE; // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
  225. $tce->process_datamap();
  226. unset($tce);
  227. if (!$this->passwordIsUpdated || count($storeRec['be_users'][$beUserId]) > 1) {
  228. $this->setupIsUpdated = TRUE;
  229. }
  230. }
  231. }
  232. }
  233. /******************************
  234. *
  235. * Rendering module
  236. *
  237. ******************************/
  238. /**
  239. * Initializes the module for display of the settings form.
  240. *
  241. * @return void
  242. */
  243. function init() {
  244. $this->MCONF = $GLOBALS['MCONF'];
  245. // check Install Tool enable file
  246. $this->setInstallToolFileExists();
  247. $this->setInstallToolFileKeep();
  248. // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
  249. $scriptUser = $this->getRealScriptUserObj();
  250. // ... and checking module access for the logged in user.
  251. $scriptUser->modAccess($this->MCONF, 1);
  252. $this->isAdmin = $scriptUser->isAdmin();
  253. // Getting the 'override' values as set might be set in User TSconfig
  254. $this->overrideConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.override');
  255. // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1)
  256. $this->tsFieldConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.fields');
  257. // Create instance of object for output of data
  258. $this->doc = t3lib_div::makeInstance('template');
  259. $this->doc->backPath = $GLOBALS['BACK_PATH'];
  260. $this->doc->setModuleTemplate('templates/setup.html');
  261. $this->doc->form = '<form action="index.php" method="post" name="usersetup" enctype="application/x-www-form-urlencoded">';
  262. $this->doc->tableLayout = array(
  263. 'defRow' => array(
  264. '0' => array('<td class="td-label">','</td>'),
  265. 'defCol' => array('<td valign="top">','</td>')
  266. )
  267. );
  268. $this->doc->table_TR = '<tr>';
  269. $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2" class="typo3-usersettings">';
  270. }
  271. /**
  272. * Generate the main settings formular:
  273. *
  274. * @return void
  275. */
  276. function main() {
  277. global $BE_USER,$LANG,$BACK_PATH,$TBE_MODULES;
  278. // file creation / delete
  279. if ($this->isAdmin) {
  280. if ($this->installToolFileKeep) {
  281. $flashMessage = t3lib_div::makeInstance(
  282. 't3lib_FlashMessage',
  283. $LANG->getLL('enableInstallTool.fileHasKeep'),
  284. $LANG->getLL('enableInstallTool.file'),
  285. t3lib_FlashMessage::WARNING
  286. );
  287. $this->content .= $flashMessage->render();
  288. }
  289. if (t3lib_div::_POST('deleteInstallToolEnableFile')) {
  290. unlink(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
  291. $this->setInstallToolFileExists();
  292. if ($this->getInstallToolFileExists()) {
  293. $flashMessage = t3lib_div::makeInstance(
  294. 't3lib_FlashMessage',
  295. $LANG->getLL('enableInstallTool.fileDelete_failed'),
  296. $LANG->getLL('enableInstallTool.file'),
  297. t3lib_FlashMessage::ERROR
  298. );
  299. } else {
  300. $flashMessage = t3lib_div::makeInstance(
  301. 't3lib_FlashMessage',
  302. $LANG->getLL('enableInstallTool.fileDelete_ok'),
  303. $LANG->getLL('enableInstallTool.file'),
  304. t3lib_FlashMessage::OK
  305. );
  306. }
  307. $this->content .= $flashMessage->render();
  308. }
  309. if (t3lib_div::_POST('createInstallToolEnableFile')) {
  310. touch(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
  311. t3lib_div::fixPermissions(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
  312. $this->setInstallToolFileExists();
  313. if ($this->getInstallToolFileExists()) {
  314. $flashMessage = t3lib_div::makeInstance(
  315. 't3lib_FlashMessage',
  316. $LANG->getLL('enableInstallTool.fileCreate_ok'),
  317. $LANG->getLL('enableInstallTool.file'),
  318. t3lib_FlashMessage::OK
  319. );
  320. } else {
  321. $flashMessage = t3lib_div::makeInstance(
  322. 't3lib_FlashMessage',
  323. $LANG->getLL('enableInstallTool.fileCreate_failed'),
  324. $LANG->getLL('enableInstallTool.file'),
  325. t3lib_FlashMessage::ERROR
  326. );
  327. }
  328. $this->content .= $flashMessage->render();
  329. }
  330. }
  331. if ($this->languageUpdate) {
  332. $this->doc->JScodeArray['languageUpdate'] .= '
  333. if (top.refreshMenu) {
  334. top.refreshMenu();
  335. } else {
  336. top.TYPO3ModuleMenu.refreshMenu();
  337. }
  338. ';
  339. }
  340. if ($this->pagetreeNeedsRefresh) {
  341. t3lib_BEfunc::setUpdateSignal('updatePageTree');
  342. }
  343. // Start page:
  344. $this->doc->loadJavascriptLib('md5.js');
  345. // use a wrapper div
  346. $this->content .= '<div id="user-setup-wrapper">';
  347. // Load available backend modules
  348. $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
  349. $this->loadModules->observeWorkspaces = true;
  350. $this->loadModules->load($TBE_MODULES);
  351. $this->content .= $this->doc->header($LANG->getLL('UserSettings').' - '.$BE_USER->user['realName'].' ['.$BE_USER->user['username'].']');
  352. // show if setup was saved
  353. if ($this->setupIsUpdated && !$this->tempDataIsCleared && !$this->settingsAreResetToDefault) {
  354. $flashMessage = t3lib_div::makeInstance(
  355. 't3lib_FlashMessage',
  356. $LANG->getLL('setupWasUpdated'),
  357. $LANG->getLL('UserSettings')
  358. );
  359. $this->content .= $flashMessage->render();
  360. }
  361. // Show if temporary data was cleared
  362. if ($this->tempDataIsCleared) {
  363. $flashMessage = t3lib_div::makeInstance(
  364. 't3lib_FlashMessage',
  365. $LANG->getLL('tempDataClearedFlashMessage'),
  366. $LANG->getLL('tempDataCleared')
  367. );
  368. $this->content .= $flashMessage->render();
  369. }
  370. // Show if temporary data was cleared
  371. if ($this->settingsAreResetToDefault) {
  372. $flashMessage = t3lib_div::makeInstance(
  373. 't3lib_FlashMessage',
  374. $LANG->getLL('settingsAreReset'),
  375. $LANG->getLL('resetConfiguration')
  376. );
  377. $this->content .= $flashMessage->render();
  378. }
  379. // If password is updated, output whether it failed or was OK.
  380. if ($this->passwordIsSubmitted) {
  381. if ($this->passwordIsUpdated) {
  382. $flashMessage = t3lib_div::makeInstance(
  383. 't3lib_FlashMessage',
  384. $LANG->getLL('newPassword_ok'),
  385. $LANG->getLL('newPassword')
  386. );
  387. } else {
  388. $flashMessage = t3lib_div::makeInstance(
  389. 't3lib_FlashMessage',
  390. $LANG->getLL('newPassword_failed'),
  391. $LANG->getLL('newPassword'),
  392. t3lib_FlashMessage::ERROR
  393. );
  394. }
  395. $this->content .= $flashMessage->render();
  396. }
  397. // render the menu items
  398. $menuItems = $this->renderUserSetup();
  399. $this->content .= $this->doc->spacer(20) . $this->doc->getDynTabMenu($menuItems, 'user-setup', FALSE, FALSE, 0, 1, FALSE, 1, $this->dividers2tabs);
  400. $formToken = $this->formProtection->generateToken('BE user setup', 'edit');
  401. // Submit and reset buttons
  402. $this->content .= $this->doc->spacer(20);
  403. $this->content .= $this->doc->section('',
  404. t3lib_BEfunc::cshItem('_MOD_user_setup', 'reset', $BACK_PATH) . '
  405. <input type="hidden" name="simUser" value="'.$this->simUser.'" />
  406. <input type="hidden" name="formToken" value="' . $formToken . '" />
  407. <input type="submit" name="data[save]" value="'.$LANG->getLL('save').'" />
  408. <input type="button" value="' . $LANG->getLL('resetConfiguration') .
  409. '" onclick="if(confirm(\''.$LANG->getLL('setToStandardQuestion').'\')) {document.getElementById(\'setValuesToDefault\').value=1;this.form.submit();}" />
  410. <input type="button" value="' . $LANG->getLL('clearSessionVars') .
  411. '" onclick="if(confirm(\'' . $LANG->getLL('clearSessionVarsQuestion') . '\')){document.getElementById(\'clearSessionVars\').value=1;this.form.submit();}" />
  412. <input type="hidden" name="data[setValuesToDefault]" value="0" id="setValuesToDefault" />
  413. <input type="hidden" name="data[clearSessionVars]" value="0" id="clearSessionVars" />'
  414. );
  415. // Notice
  416. $this->content .= $this->doc->spacer(30);
  417. $flashMessage = t3lib_div::makeInstance(
  418. 't3lib_FlashMessage',
  419. $LANG->getLL('activateChanges'),
  420. '',
  421. t3lib_FlashMessage::INFO
  422. );
  423. $this->content .= $flashMessage->render();
  424. // end of wrapper div
  425. $this->content .= '</div>';
  426. // Setting up the buttons and markers for docheader
  427. $docHeaderButtons = $this->getButtons();
  428. $markers['CSH'] = $docHeaderButtons['csh'];
  429. $markers['CONTENT'] = $this->content;
  430. // Build the <body> for the module
  431. $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
  432. // Renders the module page
  433. $this->content = $this->doc->render(
  434. $LANG->getLL('UserSettings'),
  435. $this->content
  436. );
  437. }
  438. /**
  439. * Sets existance of Install Tool file
  440. *
  441. * return void
  442. */
  443. public function setInstallToolFileExists() {
  444. $this->installToolFileExists = is_file(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
  445. }
  446. /**
  447. * Sets property if Install Tool file contains "KEEP_FILE"
  448. */
  449. public function setInstallToolFileKeep() {
  450. if ($this->installToolFileExists) {
  451. $this->installToolFileKeep = (trim(file_get_contents(PATH_typo3conf . 'ENABLE_INSTALL_TOOL')) === 'KEEP_FILE');
  452. }
  453. }
  454. /**
  455. * Gets property installToolFileExists
  456. *
  457. * @return boolean $this->installToolFileExists
  458. */
  459. public function getInstallToolFileExists() {
  460. return $this->installToolFileExists;
  461. }
  462. /**
  463. * Gets property installToolFileKeep
  464. *
  465. * @return boolean $this->installToolFileKeep
  466. */
  467. public function getInstallToolFileKeep() {
  468. return $this->installToolFileKeep;
  469. }
  470. /**
  471. * Prints the content / ends page
  472. *
  473. * @return void
  474. */
  475. function printContent() {
  476. echo $this->content;
  477. }
  478. /**
  479. * Create the panel of buttons for submitting the form or otherwise perform operations.
  480. *
  481. * @return array all available buttons as an assoc. array
  482. */
  483. protected function getButtons() {
  484. $buttons = array(
  485. 'csh' => '',
  486. 'save' => '',
  487. 'shortcut' => '',
  488. );
  489. $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'], '|', true);
  490. if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
  491. $buttons['shortcut'] = $this->doc->makeShortcutIcon('','',$this->MCONF['name']);
  492. }
  493. return $buttons;
  494. }
  495. /******************************
  496. *
  497. * Render module
  498. *
  499. ******************************/
  500. /**
  501. * renders the data for all tabs in the user setup and returns
  502. * everything that is needed with tabs and dyntab menu
  503. *
  504. * @return ready to use for the dyntabmenu itemarray
  505. */
  506. protected function renderUserSetup() {
  507. $result = array();
  508. $firstTabLabel = '';
  509. $code = array();
  510. $i = 0;
  511. $fieldArray = $this->getFieldsFromShowItem();
  512. $this->dividers2tabs = isset($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) ? intval($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) : 0;
  513. $tabLabel = '';
  514. foreach ($fieldArray as $fieldName) {
  515. $more = '';
  516. if (substr($fieldName, 0, 8) == '--div--;') {
  517. if ($firstTabLabel == '') {
  518. // first tab
  519. $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
  520. $firstTabLabel = $tabLabel;
  521. } else {
  522. if ($this->dividers2tabs) {
  523. $result[] = array(
  524. 'label' => $tabLabel,
  525. 'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
  526. );
  527. $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
  528. $i = 0;
  529. $code = array();
  530. }
  531. }
  532. continue;
  533. }
  534. $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
  535. // field my be disabled in setup.fields
  536. if (isset($this->tsFieldConf[$fieldName . '.']['disabled']) && $this->tsFieldConf[$fieldName . '.']['disabled'] == 1) {
  537. continue;
  538. }
  539. if (isset($config['access']) && !$this->checkAccess($config)) {
  540. continue;
  541. }
  542. $label = $this->getLabel($config['label'], $fieldName);
  543. $label = $this->getCSH($config['csh'] ? $config['csh'] : $fieldName, $label);
  544. $type = $config['type'];
  545. $eval = $config['eval'];
  546. $class = $config['class'];
  547. $style = $config['style'];
  548. if ($class) {
  549. $more .= ' class="' . $class . '"';
  550. }
  551. if ($style) {
  552. $more .= ' style="' . $style . '"';
  553. }
  554. if ($this->overrideConf[$fieldName]) {
  555. $more .= ' disabled="disabled"';
  556. }
  557. $value = $config['table'] == 'be_users' ? $GLOBALS['BE_USER']->user[$fieldName] : $GLOBALS['BE_USER']->uc[$fieldName];
  558. if (!$value && isset($config['default'])) {
  559. $value = $config['default'];
  560. }
  561. switch ($type) {
  562. case 'text':
  563. case 'password':
  564. $dataAdd = '';
  565. if ($config['table'] == 'be_users') {
  566. $dataAdd = '[be_users]';
  567. }
  568. if ($eval == 'md5') {
  569. $more .= ' onchange="this.value=this.value?MD5(this.value):\'\';"';
  570. }
  571. if ($type == 'password') {
  572. $value = '';
  573. }
  574. $noAutocomplete = ($type == 'password' ? 'autocomplete="off" ' : '');
  575. $html = '<input id="field_' . $fieldName . '"
  576. type="' . $type . '"
  577. name="data' . $dataAdd . '[' . $fieldName . ']" ' .
  578. $noAutocomplete .
  579. 'value="' . htmlspecialchars($value) . '" ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . $more . ' />';
  580. break;
  581. case 'check':
  582. if (!$class) {
  583. $more .= ' class="check"';
  584. }
  585. $html = '<input id="field_' . $fieldName . '"
  586. type="checkbox"
  587. name="data[' . $fieldName . ']"' .
  588. ($value ? ' checked="checked"' : '') . $more . ' />';
  589. break;
  590. case 'select':
  591. if (!$class) {
  592. $more .= ' class="select"';
  593. }
  594. if ($config['itemsProcFunc']) {
  595. $html = t3lib_div::callUserFunction($config['itemsProcFunc'], $config, $this, '');
  596. } else {
  597. $html = '<select id="field_' . $fieldName . '" name="data[' . $fieldName . ']"' . $more . '>' . LF;
  598. foreach ($config['items'] as $key => $optionLabel) {
  599. $html .= '<option value="' . $key . '"' .
  600. ($value == $key ? ' selected="selected"' : '') .
  601. '>' . $this->getLabel($optionLabel, '', false) . '</option>' . LF;
  602. }
  603. $html .= '</select>';
  604. }
  605. break;
  606. case 'user':
  607. $html = t3lib_div::callUserFunction($config['userFunc'], $config, $this, '');
  608. break;
  609. default:
  610. $html = '';
  611. }
  612. $code[$i][1] = $label;
  613. $code[$i++][2] = $html;
  614. }
  615. if ($this->dividers2tabs == 0) {
  616. $tabLabel = $firstTabLabel;
  617. }
  618. $result[] = array(
  619. 'label' => $tabLabel,
  620. 'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
  621. );
  622. return $result;
  623. }
  624. /******************************
  625. *
  626. * Helper functions
  627. *
  628. ******************************/
  629. /**
  630. * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
  631. * Anyway: The REAL user is returned - the one logged in.
  632. *
  633. * @return object The REAL user is returned - the one logged in.
  634. */
  635. protected function getRealScriptUserObj() {
  636. return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
  637. }
  638. /**
  639. * Return a select with available languages
  640. *
  641. * @return string complete select as HTML string or warning box if something went wrong.
  642. */
  643. public function renderLanguageSelect($params, $pObj) {
  644. // compile the languages dropdown
  645. $languageOptions = array(
  646. '000000000' => LF . '<option value="">' . $GLOBALS['LANG']->getLL('lang_default', 1) . '</option>'
  647. );
  648. // traverse the number of languages
  649. $theLanguages = t3lib_div::trimExplode('|', TYPO3_languages);
  650. foreach ($theLanguages as $language) {
  651. if ($language != 'default') {
  652. $languageValue = $GLOBALS['LOCAL_LANG']['default']['lang_' . $language];
  653. $localLabel = ' - ['.htmlspecialchars($languageValue) . ']';
  654. $unavailable = (is_dir(PATH_typo3conf . 'l10n/' . $language) ? false : true);
  655. if (!$unavailable) {
  656. $languageOptions[$languageValue . '--' . $language] = '
  657. <option value="'.$language.'"'.($GLOBALS['BE_USER']->uc['lang'] == $language ? ' selected="selected"' : '') . ($unavailable ? ' class="c-na"' : '').'>'.$GLOBALS['LANG']->getLL('lang_' . $language, 1) . $localLabel . '</option>';
  658. }
  659. }
  660. }
  661. ksort($languageOptions);
  662. $languageCode = '
  663. <select id="field_lang" name="data[lang]" class="select">' .
  664. implode('', $languageOptions) . '
  665. </select>';
  666. if ( $GLOBALS['BE_USER']->uc['lang'] && !@is_dir(PATH_typo3conf . 'l10n/' . $GLOBALS['BE_USER']->uc['lang'])) {
  667. $languageUnavailableWarning = 'The selected language "'
  668. . $GLOBALS['LANG']->getLL('lang_' . $GLOBALS['BE_USER']->uc['lang'], 1)
  669. . '" is not available before the language pack is installed.<br />'
  670. . ($GLOBALS['BE_USER']->isAdmin() ?
  671. 'You can use the Extension Manager to easily download and install new language packs.'
  672. : 'Please ask your system administrator to do this.');
  673. $languageUnavailableMessage = t3lib_div::makeInstance(
  674. 't3lib_FlashMessage',
  675. $languageUnavailableWarning,
  676. '',
  677. t3lib_FlashMessage::WARNING
  678. );
  679. $languageCode = $languageUnavailableMessage->render() . $languageCode;
  680. }
  681. return $languageCode;
  682. }
  683. /**
  684. * Returns a select with all modules for startup
  685. *
  686. * @return string complete select as HTML string
  687. */
  688. public function renderStartModuleSelect($params, $pObj) {
  689. // start module select
  690. if (empty($GLOBALS['BE_USER']->uc['startModule'])) {
  691. $GLOBALS['BE_USER']->uc['startModule'] = $GLOBALS['BE_USER']->uc_default['startModule'];
  692. }
  693. $startModuleSelect = '<option value=""></option>';
  694. foreach ($pObj->loadModules->modules as $mainMod => $modData) {
  695. if (isset($modData['sub']) && is_array($modData['sub'])) {
  696. $startModuleSelect .= '<option disabled="disabled">'.$GLOBALS['LANG']->moduleLabels['tabs'][$mainMod.'_tab'].'</option>';
  697. foreach ($modData['sub'] as $subKey => $subData) {
  698. $modName = $subData['name'];
  699. $startModuleSelect .= '<option value="' . $modName . '"' . ($GLOBALS['BE_USER']->uc['startModule'] == $modName ? ' selected="selected"' : '') . '>';
  700. $startModuleSelect .= ' - ' . $GLOBALS['LANG']->moduleLabels['tabs'][$modName.'_tab'] . '</option>';
  701. }
  702. }
  703. }
  704. return '<select id="field_startModule" name="data[startModule]" class="select">' . $startModuleSelect . '</select>';
  705. }
  706. /**
  707. *
  708. * @param array $params config of the field
  709. * @param SC_mod_user_setup_index $parent this class as reference
  710. * @return string html with description and button
  711. */
  712. public function renderInstallToolEnableFileButton(array $params, SC_mod_user_setup_index $parent) {
  713. // Install Tool access file
  714. $installToolEnableFile = PATH_typo3conf . 'ENABLE_INSTALL_TOOL';
  715. if ($parent->getInstallToolFileExists() && ($GLOBALS['EXEC_TIME'] - filemtime($installToolEnableFile) > 3600)) {
  716. if (!$parent->getInstallToolFileKeep()) {
  717. // Delete the file if it is older than 3600s (1 hour)
  718. unlink($installToolEnableFile);
  719. $parent->setInstallToolFileExists();
  720. }
  721. }
  722. if ($parent->getInstallToolFileExists()) {
  723. return '<input type="button" name="deleteInstallToolEnableFile"' .
  724. ($parent->getInstallToolFileKeep() ? ' disabled="disabled"' : '') .
  725. ' value="' . $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:enableInstallTool.deleteFile') . '" onclick="document.getElementById(\'deleteInstallToolEnableFile\').value=1;this.form.submit();" />
  726. <input type="hidden" name="deleteInstallToolEnableFile" value="0" id="deleteInstallToolEnableFile" />
  727. ';
  728. } else {
  729. return '<input type="button" name="createInstallToolEnableFile" value="' .
  730. $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:enableInstallTool.createFile') . '" onclick="document.getElementById(\'createInstallToolEnableFile\').value=1;this.form.submit();" />
  731. <input type="hidden" name="createInstallToolEnableFile" value="0" id="createInstallToolEnableFile" />';
  732. }
  733. }
  734. /**
  735. * Will make the simulate-user selector if the logged in user is administrator.
  736. * 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)
  737. *
  738. * @return void
  739. */
  740. public function simulateUser() {
  741. global $BE_USER,$LANG,$BACK_PATH;
  742. // *******************************************************************************
  743. // If admin, allow simulation of another user
  744. // *******************************************************************************
  745. $this->simUser = 0;
  746. $this->simulateSelector = '';
  747. unset($this->OLD_BE_USER);
  748. if ($BE_USER->isAdmin()) {
  749. $this->simUser = intval(t3lib_div::_GP('simUser'));
  750. // Make user-selector:
  751. $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName', t3lib_BEfunc::BEenableFields('be_users'));
  752. $opt = array();
  753. foreach ($users as $rr) {
  754. if ($rr['uid'] != $BE_USER->user['uid']) {
  755. $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser==$rr['uid']?' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
  756. }
  757. }
  758. if (count($opt)) {
  759. $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>';
  760. }
  761. }
  762. if ($this->simUser>0) { // This can only be set if the previous code was executed.
  763. $this->OLD_BE_USER = $BE_USER; // Save old user...
  764. unset($BE_USER); // Unset current
  765. $BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth'); // New backend user object
  766. $BE_USER->OS = TYPO3_OS;
  767. $BE_USER->setBeUserByUid($this->simUser);
  768. $BE_USER->fetchGroupData();
  769. $BE_USER->backendSetUC();
  770. $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
  771. }
  772. }
  773. /**
  774. * Returns a select with simulate users
  775. *
  776. * @return string complete select as HTML string
  777. */
  778. public function renderSimulateUserSelect($params, $pObj) {
  779. return $pObj->simulateSelector;
  780. }
  781. /**
  782. * Returns access check (currently only "admin" is supported)
  783. *
  784. * @param array $config: Configuration of the field, access mode is defined in key 'access'
  785. * @return boolean Whether it is allowed to modify the given field
  786. */
  787. protected function checkAccess(array $config) {
  788. $access = $config['access'];
  789. // check for hook
  790. if (strpos($access, 'tx_') === 0) {
  791. $accessObject = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access] . ':&' . $access);
  792. if (is_object($accessObject) && method_exists($accessObject, 'accessLevelCheck')) {
  793. // initialize vars. If method fails, $set will be set to false
  794. return $accessObject->accessLevelCheck($config);
  795. }
  796. } elseif ($access == 'admin') {
  797. return $this->isAdmin;
  798. }
  799. }
  800. /**
  801. * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
  802. *
  803. * @param string Locallang key
  804. * @param string Alternative override-config key
  805. * @param boolean Defines whether the string should be wrapped in a <label> tag.
  806. * @param string Alternative id for use in "for" attribute of <label> tag. By default the $str key is used prepended with "field_".
  807. * @return string HTML output.
  808. */
  809. protected function getLabel($str, $key='', $addLabelTag=true, $altLabelTagId='') {
  810. if (substr($str, 0, 4) == 'LLL:') {
  811. $out = $GLOBALS['LANG']->sL($str);
  812. } else {
  813. $out = htmlspecialchars($str);
  814. }
  815. if (isset($this->overrideConf[($key?$key:$str)])) {
  816. $out = '<span style="color:#999999">'.$out.'</span>';
  817. }
  818. if($addLabelTag) {
  819. $out = '<label for="' . ($altLabelTagId ? $altLabelTagId : 'field_' . $key) . '">' . $out . '</label>';
  820. }
  821. return $out;
  822. }
  823. /**
  824. * Returns the CSH Icon for given string
  825. *
  826. * @param string Locallang key
  827. * @param string The label to be used, that should be wrapped in help
  828. * @return string HTML output.
  829. */
  830. protected function getCSH($str, $label) {
  831. $context = '_MOD_user_setup';
  832. $field = $str;
  833. $strParts = explode(':', $str);
  834. if (count($strParts) > 1) {
  835. // Setting comes from another extension
  836. $context = $strParts[0];
  837. $field = $strParts[1];
  838. } else if (!t3lib_div::inList('language,simuser', $str)) {
  839. $field = 'option_' . $str;
  840. }
  841. return t3lib_BEfunc::wrapInHelp($context, $field, $label);
  842. }
  843. /**
  844. * Returns array with fields defined in $GLOBALS['TYPO3_USER_SETTINGS']['showitem']
  845. *
  846. * @param void
  847. * @return array array with fieldnames visible in form
  848. */
  849. protected function getFieldsFromShowItem() {
  850. $fieldList = $GLOBALS['TYPO3_USER_SETTINGS']['showitem'];
  851. // disable fields depended on settings
  852. if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
  853. $fieldList = t3lib_div::rmFromList('edit_RTE', $fieldList);
  854. }
  855. $fieldArray = t3lib_div::trimExplode(',', $fieldList, TRUE);
  856. return $fieldArray;
  857. }
  858. }
  859. if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php'])) {
  860. include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']);
  861. }
  862. // Make instance:
  863. $SOBE = t3lib_div::makeInstance('SC_mod_user_setup_index');
  864. $SOBE->simulateUser();
  865. $SOBE->storeIncomingData();
  866. // These includes MUST be afterwards the settings are saved...!
  867. require ($BACK_PATH.'template.php');
  868. $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
  869. $SOBE->init();
  870. $SOBE->main();
  871. $SOBE->printContent();
  872. $SOBE->getFormProtection()->persistTokens();
  873. ?>