/**
  * Ajax handler for the "suggest" feature in TCEforms.
  *
  * @param array $params The parameters from the AJAX call
  * @param TYPO3AJAX $ajaxObj The AJAX object representing the AJAX call
  * @return void
  */
 public function processAjaxRequest($params, &$ajaxObj)
 {
     // get parameters from $_GET/$_POST
     $search = t3lib_div::_GP('value');
     $table = t3lib_div::_GP('table');
     $field = t3lib_div::_GP('field');
     $uid = t3lib_div::_GP('uid');
     $pageId = t3lib_div::_GP('pid');
     t3lib_div::loadTCA($table);
     // If the $uid is numeric, we have an already existing element, so get the
     // TSconfig of the page itself or the element container (for non-page elements)
     // otherwise it's a new element, so use given id of parent page (i.e., don't modify it here)
     if (is_numeric($uid)) {
         if ($table == 'pages') {
             $pageId = $uid;
         } else {
             $row = t3lib_BEfunc::getRecord($table, $uid);
             $pageId = $row['pid'];
         }
     }
     $TSconfig = t3lib_BEfunc::getPagesTSconfig($pageId);
     $queryTables = array();
     $foreign_table_where = '';
     $wizardConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config']['wizards']['suggest'];
     if (isset($GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed'])) {
         $queryTables = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed']);
     } elseif (isset($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table'])) {
         $queryTables = array($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table']);
         $foreign_table_where = $GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table_where'];
         // strip ORDER BY clause
         $foreign_table_where = trim(preg_replace('/ORDER[[:space:]]+BY.*/i', '', $foreign_table_where));
     }
     $resultRows = array();
     // fetch the records for each query table. A query table is a table from which records are allowed to
     // be added to the TCEForm selector, originally fetched from the "allowed" config option in the TCA
     foreach ($queryTables as $queryTable) {
         t3lib_div::loadTCA($queryTable);
         // if the table does not exist, skip it
         if (!is_array($GLOBALS['TCA'][$queryTable]) || !count($GLOBALS['TCA'][$queryTable])) {
             continue;
         }
         $config = (array) $wizardConfig['default'];
         if (is_array($wizardConfig[$queryTable])) {
             $config = t3lib_div::array_merge_recursive_overrule($config, $wizardConfig[$queryTable]);
         }
         // merge the configurations of different "levels" to get the working configuration for this table and
         // field (i.e., go from the most general to the most special configuration)
         if (is_array($TSconfig['TCEFORM.']['suggest.']['default.'])) {
             $config = t3lib_div::array_merge_recursive_overrule($config, $TSconfig['TCEFORM.']['suggest.']['default.']);
         }
         if (is_array($TSconfig['TCEFORM.']['suggest.'][$queryTable . '.'])) {
             $config = t3lib_div::array_merge_recursive_overrule($config, $TSconfig['TCEFORM.']['suggest.'][$queryTable . '.']);
         }
         // use $table instead of $queryTable here because we overlay a config
         // for the input-field here, not for the queried table
         if (is_array($TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.']['default.'])) {
             $config = t3lib_div::array_merge_recursive_overrule($config, $TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.']['default.']);
         }
         if (is_array($TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.'][$queryTable . '.'])) {
             $config = t3lib_div::array_merge_recursive_overrule($config, $TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.'][$queryTable . '.']);
         }
         //process addWhere
         if (!isset($config['addWhere']) && $foreign_table_where) {
             $config['addWhere'] = $foreign_table_where;
         }
         if (isset($config['addWhere'])) {
             $config['addWhere'] = strtr(' ' . $config['addWhere'], array('###THIS_UID###' => intval($uid), '###CURRENT_PID###' => intval($pageId)));
         }
         // instantiate the class that should fetch the records for this $queryTable
         $receiverClassName = $config['receiverClass'];
         if (!class_exists($receiverClassName)) {
             $receiverClassName = 't3lib_TCEforms_Suggest_DefaultReceiver';
         }
         $receiverObj = t3lib_div::makeInstance($receiverClassName, $queryTable, $config);
         $params = array('value' => $search);
         $rows = $receiverObj->queryTable($params);
         if (empty($rows)) {
             continue;
         }
         $resultRows = t3lib_div::array_merge($resultRows, $rows);
         unset($rows);
     }
     $listItems = array();
     if (count($resultRows) > 0) {
         // traverse all found records and sort them
         $rowsSort = array();
         foreach ($resultRows as $key => $row) {
             $rowsSort[$key] = $row['text'];
         }
         asort($rowsSort);
         $rowsSort = array_keys($rowsSort);
         // Limit the number of items in the result list
         $maxItems = $config['maxItemsInResultList'] ? $config['maxItemsInResultList'] : 10;
         $maxItems = min(count($resultRows), $maxItems);
         // put together the selector entry
         for ($i = 0; $i < $maxItems; $i++) {
             $row = $resultRows[$rowsSort[$i]];
             $rowId = $row['table'] . '-' . $row['uid'] . '-' . $table . '-' . $uid . '-' . $field;
             $listItems[] = '<li' . ($row['class'] != '' ? ' class="' . $row['class'] . '"' : '') . ' id="' . $rowId . '" style="' . $row['style'] . '">' . $row['text'] . '</li>';
         }
     }
     if (count($listItems) > 0) {
         $list = implode('', $listItems);
     } else {
         $list = '<li class="suggest-noresults"><i>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.noRecordFound') . '</i></li>';
     }
     $list = '<ul class="' . $this->cssClass . '-resultlist">' . $list . '</ul>';
     $ajaxObj->addContent(0, $list);
 }
 /**
  * General processor for AJAX requests.
  * (called by typo3/ajax.php)
  *
  * @param	array		$params: additional parameters (not used here)
  * @param	TYPO3AJAX	&$ajaxObj: the TYPO3AJAX object of this request
  * @return	void
  * @author	Oliver Hader <*****@*****.**>
  */
 public function processAjaxRequest($params, TYPO3AJAX &$ajaxObj)
 {
     $this->ajaxObj = $ajaxObj;
     // Load the TSref XML information:
     $this->loadFile(t3lib_extMgm::extPath('t3editor') . 'res/tsref/tsref.xml');
     $ajaxIdParts = explode('::', $ajaxObj->getAjaxID(), 2);
     $ajaxMethod = $ajaxIdParts[1];
     $response = array();
     // Process the AJAX requests:
     if ($ajaxMethod == 'getTypes') {
         $ajaxObj->setContent($this->getTypes());
         $ajaxObj->setContentFormat('jsonbody');
     } elseif ($ajaxMethod == 'getDescription') {
         $ajaxObj->addContent('', $this->getDescription(t3lib_div::_GP('typeId'), t3lib_div::_GP('parameterName')));
         $ajaxObj->setContentFormat('plain');
     }
 }
Пример #3
0
 /**
  * Used to broker incoming requests to other calls.
  * Called by typo3/ajax.php
  *
  * @param array $unused additional parameters (not used)
  * @param TYPO3AJAX $ajax the AJAX object for this request
  *
  * @return void
  */
 public function ajaxBroker(array $unused, TYPO3AJAX $ajax)
 {
     $state = (bool) t3lib_div::_POST('state');
     $checkbox = t3lib_div::_POST('checkbox');
     if (in_array($checkbox, $this->validCheckboxKeys, TRUE)) {
         $ajax->setContentFormat('json');
         $this->userSettingsService->set($checkbox, $state);
         $ajax->addContent('success', TRUE);
     } else {
         $ajax->setContentFormat('plain');
         $ajax->setError('Illegal input parameters.');
     }
 }
 /**
  * sets the workspace for the backend
  *
  * @param unknown_type $params
  * @param TYPO3AJAX $ajaxObj
  */
 public function setWorkspace($parameters = array(), TYPO3AJAX &$ajaxObj = null)
 {
     $workspaceId = (int) t3lib_div::_POST('workspaceId');
     $GLOBALS['BE_USER']->setWorkspace($workspaceId);
     $ajaxObj->addContent('setWorkspaceId', $workspaceId);
     $ajaxObj->setContentFormat('json');
 }
 /**
  * renders the menu so that it can be returned as response to an AJAX call
  *
  * @param	array		array of parameters from the AJAX interface, currently unused
  * @param	TYPO3AJAX	object of type TYPO3AJAX
  * @return	void
  */
 public function renderAjax($params = array(), TYPO3AJAX &$ajaxObj = null)
 {
     $menuContent = $this->renderMenu();
     $ajaxObj->addContent('opendocsMenu', $menuContent);
 }
 /**
  * gets called when a shortcut is changed, checks whether the user has
  * permissions to do so and saves the changes if everything is ok
  *
  * @param	array		array of parameters from the AJAX interface, currently unused
  * @param	TYPO3AJAX	object of type TYPO3AJAX
  * @return	void
  */
 public function setAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = null)
 {
     $shortcutId = (int) t3lib_div::_POST('shortcutId');
     $shortcutName = strip_tags(t3lib_div::_POST('value'));
     $shortcutGroupId = (int) t3lib_div::_POST('shortcut-group');
     if ($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) {
         // users can delete only their own shortcuts (except admins)
         $addUserWhere = !$GLOBALS['BE_USER']->isAdmin() ? ' AND userid=' . intval($GLOBALS['BE_USER']->user['uid']) : '';
         $fieldValues = array('description' => $shortcutName, 'sc_group' => $shortcutGroupId);
         if ($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) {
             $fieldValues['sc_group'] = 0;
         }
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid=' . $shortcutId . $addUserWhere, $fieldValues);
         $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
         if ($affectedRows == 1) {
             $ajaxObj->addContent('shortcut', $shortcutName);
         } else {
             $ajaxObj->addContent('shortcut', 'failed');
         }
     }
     $ajaxObj->setContentFormat('plain');
 }
 /**
  * Handles the actual process from within the ajaxExec function
  * therefore, it does exactly the same as the real typo3/tce_file.php
  * but without calling the "finish" method, thus makes it simpler to deal with the
  * actual return value
  *
  *
  * @param string $params 	always empty.
  * @param string $ajaxObj	The Ajax object used to return content and set content types
  * @return void
  */
 public function processAjaxRequest(array $params, TYPO3AJAX $ajaxObj)
 {
     $this->init();
     $this->main();
     $errors = $this->fileProcessor->getErrorMessages();
     if (count($errors)) {
         $ajaxObj->setError(implode(',', $errors));
     } else {
         $ajaxObj->addContent('result', $this->fileData);
         if ($this->redirect) {
             $ajaxObj->addContent('redirect', $this->redirect);
         }
         $ajaxObj->setContentFormat('json');
     }
 }
Пример #8
0
 /**
  * Generates new tokens for the ones found in the DOM.
  *
  * @param	array		$parameters: Parameters (not used)
  * @param	TYPO3AJAX	$parent: The calling parent AJAX object
  */
 public function refreshTokens(array $parameters, TYPO3AJAX $parent)
 {
     $accessToken = (string) t3lib_div::_GP('accessToken');
     $formprotection = t3lib_formprotection_Factory::get();
     if ($formprotection->validateToken($accessToken, 'refreshTokens')) {
         $oldTokens = json_decode((string) t3lib_div::_GP('tokens'));
         $regeneratedTokens = new stdClass();
         foreach ($oldTokens as $oldToken) {
             $newToken = $this->generateNewToken($oldToken);
             $regeneratedTokens->{$oldToken} = $newToken;
         }
     }
     $parent->addContent('newTokens', $regeneratedTokens);
     $parent->setContentFormat('json');
     $formprotection->persistTokens();
 }
 /**
  * The main dispatcher function. Collect data and prepare HTML output.
  *
  * @param	array		$params: array of parameters from the AJAX interface, currently unused
  * @param	TYPO3AJAX		$ajaxObj: object of type TYPO3AJAX
  * @return	Void
  */
 public function dispatch($params = array(), TYPO3AJAX &$ajaxObj = null)
 {
     $content = '';
     // Basic test for required value
     if ($this->conf['page'] > 0) {
         // Init TCE for execution of update
         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
         $tce->stripslashes_values = 1;
         // Determine the scripts to execute
         switch ($this->conf['action']) {
             // Return the select to change the owner (BE user) of the page
             case 'show_change_owner_selector':
                 $content = $this->renderUserSelector($this->conf['page'], $this->conf['ownerUid'], $this->conf['username']);
                 break;
                 // Change the owner and return the new owner HTML snippet
             // Change the owner and return the new owner HTML snippet
             case 'change_owner':
                 if (is_int($this->conf['new_owner_uid'])) {
                     // Prepare data to change
                     $data = array();
                     $data['pages'][$this->conf['page']]['perms_userid'] = $this->conf['new_owner_uid'];
                     // Execute TCE Update
                     $tce->start($data, array());
                     $tce->process_datamap();
                     $content = $this->renderOwnername($this->conf['page'], $this->conf['new_owner_uid'], $this->conf['new_owner_username']);
                 } else {
                     $ajaxObj->setError('An error occured: No page owner uid specified.');
                 }
                 break;
                 // Return the select to change the group (BE group) of the page
             // Return the select to change the group (BE group) of the page
             case 'show_change_group_selector':
                 $content = $this->renderGroupSelector($this->conf['page'], $this->conf['groupUid'], $this->conf['groupname']);
                 break;
                 // Change the group and return the new group HTML snippet
             // Change the group and return the new group HTML snippet
             case 'change_group':
                 if (is_int($this->conf['new_group_uid'])) {
                     // Prepare data to change
                     $data = array();
                     $data['pages'][$this->conf['page']]['perms_groupid'] = $this->conf['new_group_uid'];
                     // Execute TCE Update
                     $tce->start($data, array());
                     $tce->process_datamap();
                     $content = $this->renderGroupname($this->conf['page'], $this->conf['new_group_uid'], $this->conf['new_group_username']);
                 } else {
                     $ajaxObj->setError('An error occured: No page group uid specified.');
                 }
                 break;
                 // Change the group and return the new group HTML snippet
             // Change the group and return the new group HTML snippet
             case 'toggle_edit_lock':
                 // Prepare data to change
                 $data = array();
                 $data['pages'][$this->conf['page']]['editlock'] = $this->conf['editLockState'] === 1 ? 0 : 1;
                 // Execute TCE Update
                 $tce->start($data, array());
                 $tce->process_datamap();
                 $content = $this->renderToggleEditLock($this->conf['page'], $data['pages'][$this->conf['page']]['editlock']);
                 break;
                 // The script defaults to change permissions
             // The script defaults to change permissions
             default:
                 if ($this->conf['mode'] == 'delete') {
                     $this->conf['permissions'] = intval($this->conf['permissions'] - $this->conf['bits']);
                 } else {
                     $this->conf['permissions'] = intval($this->conf['permissions'] + $this->conf['bits']);
                 }
                 // Prepare data to change
                 $data = array();
                 $data['pages'][$this->conf['page']]['perms_' . $this->conf['who']] = $this->conf['permissions'];
                 // Execute TCE Update
                 $tce->start($data, array());
                 $tce->process_datamap();
                 $content = $this->renderPermissions($this->conf['permissions'], $this->conf['page'], $this->conf['who']);
         }
     } else {
         $ajaxObj->setError('This script cannot be called directly.');
     }
     $ajaxObj->addContent($this->conf['page'] . '_' . $this->conf['who'], $content);
 }
    /**
     * renders the backend menu as unordered list as an AJAX response without
     * the wrapping ul tags
     *
     * @param	array		array of parameters from the AJAX interface, currently unused
     * @param	TYPO3AJAX	object of type TYPO3AJAX
     * @return	void
     */
    public function renderAjax($params = array(), TYPO3AJAX &$ajaxObj = null)
    {
        $menu = $this->render(false);
        $menuSwitch = $this->getGotoModuleJavascript();
        // JS rocks: we can just overwrite a function with a new definition.
        // and yes, we actually do that =)
        $menuSwitchUpdate = '
		<script type="text/javascript">
			top.goToModule = ' . $menuSwitch . ';
		</script>';
        $ajaxObj->addContent('typo3-menu', $menu . $menuSwitchUpdate);
    }
 /**
  * Gets a MD5 challenge.
  *
  * @param	array		$parameters: Parameters (not used)
  * @param	TYPO3AJAX	$parent: The calling parent AJAX object
  * @return	void
  */
 public function getChallenge(array $parameters, TYPO3AJAX $parent)
 {
     session_start();
     $_SESSION['login_challenge'] = md5(uniqid('') . getmypid());
     session_commit();
     $parent->addContent('challenge', $_SESSION['login_challenge']);
     $parent->setContentFormat('json');
 }