PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

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