public function writeMessage(DataContainer $dc) { //$banner->addBannerNewWindow($GLOBALS['TL_LANG']['CTE'][$module['type']][0], $GLOBALS['TL_LANG']['CTE'][$module['type']][1]); $banner = new ReadSpeaker\RS_Messages(); Message::reset(); $banner->addBannerReadSpeakerTop($GLOBALS['TL_LANG']['MOD']['readspeaker_settings'][0], $GLOBALS['TL_LANG']['MOD']['readspeaker_settings'][1]); $count_settings = ReadSpeaker\RsSettingsModel::countAll(); if (!Contao\Input::get('act')) { if ($count_settings == 0) { Message::addRaw($GLOBALS['TL_LANG']['tl_rs_settings']['info']['min_one_config']); } else { if ($count_settings > 0) { Message::addRaw($GLOBALS['TL_LANG']['tl_rs_settings']['info']['more_configs']); } } } }
public function writeMessage(DataContainer $dc) { Message::reset(); if (TL_MODE == 'BE' && Input::get('act') && Input::get('act') == 'edit') { $banner = new ReadSpeaker\RS_Messages(); $db = \Contao\Database::getInstance(); $module = $db->prepare("SELECT * FROM tl_content WHERE id = ?")->execute($dc->id)->row(); if ($module) { $rs_banner = false; $rs_doc_banner = false; $rs_ce_end_banner = false; switch ($module['type']) { case 'rs_content_ce': $rs_banner = true; $rs_ce_end_banner = true; break; case 'rs_content_end': $rs_banner = true; break; case 'rs_content_doc': $rs_banner = true; $rs_doc_banner = true; break; case 'rs_content_skip': $rs_banner = true; break; case 'rs_content_read': $rs_banner = true; break; default: break; } if ($rs_banner) { $banner->addBannerReadSpeakerTop($GLOBALS['TL_LANG']['CTE'][$module['type']][0], $GLOBALS['TL_LANG']['CTE'][$module['type']][1]); if ($rs_ce_end_banner) { $banner->addBannerNotForgetEndContentElement(); } if ($rs_doc_banner) { $banner->addBannerPossibleDocReaderFileTypes(); } } } } }
public function writeMessage($dc) { $banner = new ReadSpeaker\RS_Messages(); Message::reset(); $db = \Contao\Database::getInstance(); $module = $db->prepare("SELECT * FROM tl_module WHERE id = ?")->execute($dc->id)->row(); $rs_banner = false; switch ($module['type']) { case 'mod_rs': $rs_banner = true; break; case 'mod_rs_skip_from_here': $rs_banner = true; break; case 'mod_rs_read_from_here': $rs_banner = true; break; default: break; } if ($rs_banner) { $banner->addBannerReadSpeakerTop($GLOBALS['TL_LANG']['FMD'][$module['type']][0], $GLOBALS['TL_LANG']['FMD'][$module['type']][1]); } }
/** * Reset the message system * * @deprecated Use Message::reset() instead */ protected function resetMessages() { \Message::reset(); }
/** * Auto-generate a form to rename a file or folder * * @return string */ public function edit() { $return = ''; $this->noReload = false; $this->isValid($this->intId); if (!file_exists(TL_ROOT . '/' . $this->intId) || !$this->isMounted($this->intId)) { $this->log('File or folder "' . $this->intId . '" was not mounted or could not be found', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } $objModel = null; $objVersions = null; // Add the versioning routines if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->intId)) { if (stristr($this->intId, '__new__') === false) { $objModel = \FilesModel::findByPath($this->intId); if ($objModel === null) { $objModel = \Dbafs::addResource($this->intId); } $this->objActiveRecord = $objModel; } $this->blnCreateNewVersion = false; /** @var \FilesModel $objModel */ $objVersions = new \Versions($this->strTable, $objModel->id); if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) { // Compare versions if (\Input::get('versions')) { $objVersions->compare(); } // Restore a version if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') { $objVersions->restore(\Input::post('version')); $this->reload(); } } $objVersions->initialize(); } else { // Unset the database fields $GLOBALS['TL_DCA'][$this->strTable]['fields'] = array_intersect_key($GLOBALS['TL_DCA'][$this->strTable]['fields'], array('name' => true, 'protected' => true)); } // Build an array from boxes and rows (do not show excluded fields) $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); if (!empty($boxes)) { // Get fields foreach ($boxes as $k => $v) { $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (empty($boxes[$k])) { unset($boxes[$k]); } } // Render boxes $class = 'tl_tbox'; foreach ($boxes as $v) { $return .= ' <div class="' . $class . '">'; // Build rows of the current box foreach ($v as $vv) { $this->strField = $vv; $this->strInputName = $vv; // Load the current value if ($vv == 'name') { $objFile = is_dir(TL_ROOT . '/' . $this->intId) ? new \Folder($this->intId) : new \File($this->intId, true); $this->strPath = str_replace(TL_ROOT . '/', '', $objFile->dirname); $this->strExtension = $objFile->origext != '' ? '.' . $objFile->origext : ''; $this->varValue = $objFile->filename; // Fix Unix system files like .htaccess if (strncmp($this->varValue, '.', 1) === 0) { $this->strExtension = ''; } // Clear the current value if it is a new folder if (\Input::post('FORM_SUBMIT') != 'tl_files' && \Input::post('FORM_SUBMIT') != 'tl_templates' && $this->varValue == '__new__') { $this->varValue = ''; } } else { $this->varValue = $objModel !== null ? $objModel->{$vv} : null; } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback[0]}->{$callback[1]}($this->varValue, $this); } elseif (is_callable($callback)) { $this->varValue = $callback($this->varValue, $this); } } } // Build row $return .= $this->row(); } $class = 'tl_box'; $return .= ' <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '"> <div class="clear"></div> </div>'; } } // Versions overview if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu'] && $this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->intId)) { $version = $objVersions->renderDropdown(); } else { $version = ''; } // Submit buttons $arrButtons = array(); $arrButtons['save'] = '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">'; $arrButtons['saveNclose'] = '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">'; // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } // Add the buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </form>'; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . ' <div id="tl_buttons"> <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this); } elseif (is_callable($callback)) { $callback($this); } } } // Save the current version if ($this->blnCreateNewVersion && $objModel !== null) { $objVersions->create(); // Call the onversion_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'])) { @trigger_error('Using the onversion_callback has been deprecated and will no longer work in Contao 5.0. Use the oncreate_version_callback instead.', E_USER_DEPRECATED); foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->strTable, $objModel->id, $this); } elseif (is_callable($callback)) { $callback($this->strTable, $objModel->id, $this); } } } } // Set the current timestamp (-> DO NOT CHANGE THE ORDER version - timestamp) if ($this->blnIsDbAssisted && $objModel !== null) { $this->Database->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE id=?")->execute(time(), $objModel->id); } // Redirect if (\Input::post('saveNclose')) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $this->redirect($this->getReferer()); } // Reload if ($this->blnIsDbAssisted && $this->objActiveRecord !== null) { $this->redirect($this->addToUrl('id=' . $this->urlEncode($this->objActiveRecord->path))); } else { $this->redirect($this->addToUrl('id=' . $this->urlEncode($this->strPath . '/' . $this->varValue) . $this->strExtension)); } } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Auto-generate a form to edit the local configuration file * * @return string */ public function edit() { $return = ''; $ajaxId = null; if (\Environment::get('isAjaxRequest')) { $ajaxId = func_get_arg(1); } // Build an array from boxes and rows $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); $legends = array(); if (!empty($boxes)) { foreach ($boxes as $k => $v) { $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if (preg_match('/^\\[.*\\]$/', $vv)) { continue; } if (preg_match('/^\\{.*\\}$/', $vv)) { $legends[$k] = substr($vv, 1, -1); unset($boxes[$k][$kk]); } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (empty($boxes[$k])) { unset($boxes[$k]); } } // Render boxes $class = 'tl_tbox'; $fs = $this->Session->get('fieldset_states'); $blnIsFirst = true; foreach ($boxes as $k => $v) { $strAjax = ''; $blnAjax = false; $key = ''; $cls = ''; $legend = ''; if (isset($legends[$k])) { list($key, $cls) = explode(':', $legends[$k]); $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this, \'' . $key . '\', \'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>'; } if (isset($fs[$this->strTable][$key])) { $class .= $fs[$this->strTable][$key] ? '' : ' collapsed'; } else { $class .= $cls && $legend ? ' ' . $cls : ''; } $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend; // Build rows of the current box foreach ($v as $vv) { if ($vv == '[EOF]') { if ($blnAjax && \Environment::get('isAjaxRequest')) { return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">'; } $blnAjax = false; $return .= "\n " . '</div>'; continue; } if (preg_match('/^\\[.*\\]$/', $vv)) { $thisId = 'sub_' . substr($vv, 1, -1); $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false; $return .= "\n " . '<div id="' . $thisId . '">'; continue; } $this->strField = $vv; $this->strInputName = $vv; $this->varValue = \Config::get($this->strField); // Handle entities if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'textarea') { if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) { $this->varValue = deserialize($this->varValue); } if (!is_array($this->varValue)) { $this->varValue = htmlspecialchars($this->varValue); } else { foreach ($this->varValue as $k => $v) { $this->varValue[$k] = htmlspecialchars($v); } } } // Autofocus the first field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback[0]}->{$callback[1]}($this->varValue, $this); } elseif (is_callable($callback)) { $this->varValue = $callback($this->varValue, $this); } } } // Build row $blnAjax ? $strAjax .= $this->row() : ($return .= $this->row()); } $class = 'tl_box'; $return .= "\n" . '</fieldset>'; } } $this->import('Files'); // Check whether the target file is writeable if (!$this->Files->is_writeable('system/config/localconfig.php')) { \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['notWriteable'], 'system/config/localconfig.php')); } // Submit buttons $arrButtons = array(); $arrButtons['save'] = '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">'; $arrButtons['saveNclose'] = '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">'; // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } // Add the buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </form> <script> window.addEvent(\'domready\', function() { Theme.focusInput("' . $this->strTable . '"); }); </script>'; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = ' <div id="tl_buttons"> <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { // Call onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this); } elseif (is_callable($callback)) { $callback($this); } } } // Reload if (\Input::post('saveNclose')) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $this->redirect($this->getReferer()); } $this->reload(); } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Auto-generate a form to rename a file or folder * @return string */ public function edit() { $return = ''; $this->noReload = false; $this->isValid($this->intId); if (!file_exists(TL_ROOT . '/' . $this->intId) || !$this->isMounted($this->intId)) { $this->log('File or folder "' . $this->intId . '" was not mounted or could not be found', 'DC_Folder edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } // Get the DB entry if ($this->blnIsDbAssisted) { $objFile = \FilesModel::findByPath($this->intId); $this->objActiveRecord = $objFile; } $this->blnCreateNewVersion = false; // Change version if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'] && \Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') { $objData = $this->Database->prepare("SELECT * FROM tl_version WHERE fromTable=? AND pid=? AND version=?")->limit(1)->execute($this->strTable, $objFile->id, \Input::post('version')); if ($objData->numRows) { $data = deserialize($objData->data); if (is_array($data)) { $this->Database->prepare("UPDATE " . $objData->fromTable . " %s WHERE id=?")->set($data)->execute($objFile->id); $this->Database->prepare("UPDATE tl_version SET active='' WHERE pid=?")->execute($objFile->id); $this->Database->prepare("UPDATE tl_version SET active=1 WHERE pid=? AND version=?")->execute($objFile->id, \Input::post('version')); $this->log('Version ' . \Input::post('version') . ' of record "' . $this->strTable . '.id=' . $objFile->id . '" has been restored', 'DC_Table edit()', TL_GENERAL); // Trigger the onrestore_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objFile->id, $this->strTable, $data, \Input::post('version')); } } } } } $this->reload(); } // Build an array from boxes and rows (do not show excluded fields) $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); if (!empty($boxes)) { // Get fields foreach ($boxes as $k => $v) { $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (empty($boxes[$k])) { unset($boxes[$k]); } } // Render boxes $class = 'tl_tbox'; $blnIsFirst = true; foreach ($boxes as $v) { $return .= ' <div class="' . $class . '">'; // Build rows of the current box foreach ($v as $vv) { $this->strField = $vv; $this->strInputName = $vv; // Load the current value if ($vv == 'name') { $pathinfo = pathinfo($this->intId); $this->strPath = $pathinfo['dirname']; if (is_dir(TL_ROOT . '/' . $this->intId)) { $this->strExtension = ''; $this->varValue = basename($pathinfo['basename']); } else { $this->strExtension = $pathinfo['extension'] != '' ? '.' . $pathinfo['extension'] : ''; $this->varValue = basename($pathinfo['basename'], $this->strExtension); } // Fix Unix system files like .htaccess if (strncmp($this->varValue, '.', 1) === 0) { $this->strExtension = ''; } // Clear the current value if it is a new folder if (\Input::post('FORM_SUBMIT') != 'tl_files' && \Input::post('FORM_SUBMIT') != 'tl_templates' && $this->varValue == '__new__') { $this->varValue = ''; } } else { $this->varValue = $objFile->{$vv}; } // Autofocus the first field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback}[0]->{$callback}[1]($this->varValue, $this); } } } // Build row $return .= $this->row(); } $class = 'tl_box'; $return .= ' <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '"> </div>'; } } $version = ''; // Check versions if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning']) { $objVersion = $this->Database->prepare("SELECT tstamp, version, username, active FROM tl_version WHERE fromTable=? AND pid=? ORDER BY version DESC")->execute($this->strTable, $objFile->id); if ($objVersion->numRows > 1) { $versions = ''; while ($objVersion->next()) { $versions .= ' <option value="' . $objVersion->version . '"' . ($objVersion->active ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['version'] . ' ' . $objVersion->version . ' (' . $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objVersion->tstamp) . ') ' . $objVersion->username . '</option>'; } $version = ' <div class="tl_version_panel"> <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_version" class="tl_form" method="post"> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_version"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <select name="version" class="tl_select">' . $versions . ' </select> <input type="submit" name="showVersion" id="showVersion" class="tl_submit" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['restore']) . '"> <a href="contao/diff.php?table=' . $this->strTable . '&pid=' . $objFile->id . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']) . '" onclick="Backend.openModalIframe({\'width\':860,\'title\':\'' . specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']) . '\',\'url\':this.href});return false">' . $this->generateImage('diff.gif') . '</a> </div> </form> </div> '; } } // Add some buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> <input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '"> <input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '"> </div> </div> </form>'; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . ' <div id="tl_buttons"> <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> <h2 class="sub_headline">' . $GLOBALS['TL_LANG']['tl_files']['editFF'] . '</h2> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this); } } // Save the current version if ($this->blnCreateNewVersion && \Input::post('SUBMIT_TYPE') != 'auto') { $this->createNewVersion($this->strTable, $objFile->id); // Call the onversion_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this->strTable, $objFile->id, $this); } } $this->log('A new version of record "' . $this->strTable . '.id=' . $objFile->id . '" has been created', 'DC_Table edit()', TL_GENERAL); } // Set the current timestamp (-> DO NOT CHANGE THE ORDER version - timestamp) if ($this->blnIsDbAssisted) { $this->Database->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE id=?")->execute(time(), $objFile->id); } // Redirect if (\Input::post('saveNclose')) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); $this->redirect($this->getReferer()); } // Reload if ($this->blnIsDbAssisted) { $this->redirect($this->addToUrl('id=' . $this->urlEncode($this->objActiveRecord->path))); } else { $this->redirect($this->addToUrl('id=' . $this->urlEncode($this->strPath . '/' . $this->varValue) . $this->strExtension)); } } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Edit action * * Some parts of this function are adopted from * system/modules/core/drivers/DC_Table.php * * @return string back end HTML */ public function edit() { $this->isValid($this->intId); if (is_dir(TL_ROOT . '/' . $this->intId)) { $this->log('Folder "' . $this->intId . '" cannot be edited', 'DC_RockSolidThemeAssistant edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } elseif (!file_exists(TL_ROOT . '/' . $this->intId)) { $this->log('File "' . $this->intId . '" does not exist', 'DC_RockSolidThemeAssistant edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } elseif (substr($this->intId, -5) !== '.base') { $this->log('File "' . $this->intId . '" cannot be edited', 'DC_RockSolidThemeAssistant edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } $this->import('BackendUser', 'User'); // Check user permission if (!$this->User->isAdmin && !$this->User->hasAccess('f2', 'fop')) { $this->log('Not enough permissions to edit the file "' . $this->intId . '"', 'DC_RockSolidThemeAssistant edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } $objFile = new \File($this->intId); $this->objActiveRecord = new \stdClass(); $this->objActiveRecord->intId = $this->intId; $this->objActiveRecord->id = $this->intId; $return = ''; // Build an array from boxes and rows $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); $legends = array(); if (!empty($boxes)) { foreach ($boxes as $k => $v) { $eCount = 1; $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if (preg_match('/^\\[.*\\]$/', $vv)) { ++$eCount; continue; } if (preg_match('/^\\{.*\\}$/', $vv)) { $legends[$k] = substr($vv, 1, -1); unset($boxes[$k][$kk]); } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (count($boxes[$k]) < $eCount) { unset($boxes[$k]); } } $class = 'tl_tbox'; $fs = $this->Session->get('fieldset_states'); $blnIsFirst = true; // Render boxes foreach ($boxes as $k => $v) { $strAjax = ''; $blnAjax = false; $key = ''; $cls = ''; $legend = ''; if (isset($legends[$k])) { list($key, $cls) = explode(':', $legends[$k]); $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this,\'' . $key . '\',\'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>'; } if (isset($fs[$this->strTable][$key])) { $class .= $fs[$this->strTable][$key] ? '' : ' collapsed'; } else { $class .= $cls && $legend ? ' ' . $cls : ''; } $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend; // Build rows of the current box foreach ($v as $vv) { if ($vv == '[EOF]') { if ($blnAjax && \Environment::get('isAjaxRequest')) { return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">'; } $blnAjax = false; $return .= "\n" . '</div>'; continue; } if (preg_match('/^\\[.*\\]$/', $vv)) { $thisId = 'sub_' . substr($vv, 1, -1); $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false; $return .= "\n" . '<div id="' . $thisId . '">'; continue; } $this->strField = $vv; $this->strInputName = $vv; $this->varValue = ''; // Autofocus the first field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Convert CSV fields (see #2890) if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple'] && isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'])) { $this->varValue = trimsplit($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'], $this->varValue); } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback[0]}->{$callback[1]}($this->varValue, $this); } } } // Re-set the current value $this->objActiveRecord->{$this->strField} = $this->varValue; // Build the row and pass the current palette string (thanks to Tristan Lins) $blnAjax ? $strAjax .= $this->row($this->strPalette) : ($return .= $this->row($this->strPalette)); } $class = 'tl_box'; $return .= "\n" . '</fieldset>'; } } // Add some buttons and end the form $return .= '</div>' . '<div class="tl_formbody_submit">' . '<div class="tl_submit_container">' . '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">' . '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">' . '</div>' . '</div>' . '</form>' . '<script>' . ' window.addEvent(\'domready\', function() {' . ' (inp = $(\'' . $this->strTable . '\').getElement(\'input[class^="tl_text"]\')) && inp.focus();' . ' });' . '</script>'; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . '<div id="tl_buttons">' . '<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>' . '</div>' . '<h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['MSC']['editRecord'], $this->intId ? $this->intId : '') . '</h2>' . \Message::generate() . '<form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '>' . '<div class="tl_formbody_edit">' . '<input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '">' . '<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? '<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this); } } // Redirect if (isset($_POST['saveNclose'])) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); $this->redirect($this->getReferer()); } $this->reload(); } // Set the focus if there is an error if ($this->noReload) { $return .= '<script>' . 'window.addEvent(\'domready\', function() {' . ' Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20));' . '});' . '</script>'; } return $return; }
/** * Autogenerate a form to edit the current database record * @param integer * @param integer * @return string */ public function edit($intID = null, $ajaxId = null) { $table_alias = $this->strTable == 'tl_formdata' ? ' f' : ''; if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { $this->log('Table "' . $this->strTable . '" is not editable', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } if ($intID != '') { $this->intId = $intID; } $return = ''; $this->values[] = $this->intId; $this->procedure[] = 'id=?'; $this->blnCreateNewVersion = false; // Get current record $sqlQuery = "SELECT * " . (!empty($this->arrSqlDetails) ? ', ' . implode(',', array_values($this->arrSqlDetails)) : '') . " FROM " . $this->strTable . $table_alias; $sqlWhere = " WHERE id=?"; if ($sqlWhere != '') { $sqlQuery .= $sqlWhere; } $objRow = \Database::getInstance()->prepare($sqlQuery)->limit(1)->execute($this->intId); // Redirect if there is no record with the given ID if ($objRow->numRows < 1) { $this->log('Could not load record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } $this->objActiveRecord = $objRow; $this->checkForTinyMce(); // Build an array from boxes and rows $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); $legends = array(); if (!empty($boxes)) { foreach ($boxes as $k => $v) { $eCount = 1; $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if (preg_match('/^\\[.*\\]$/', $vv)) { ++$eCount; continue; } if (preg_match('/^\\{.*\\}$/', $vv)) { $legends[$k] = substr($vv, 1, -1); unset($boxes[$k][$kk]); } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (count($boxes[$k]) < $eCount) { unset($boxes[$k]); } } $class = 'tl_tbox'; $fs = $this->Session->get('fieldset_states'); $blnIsFirst = true; // Render boxes foreach ($boxes as $k => $v) { $strAjax = ''; $blnAjax = false; $key = ''; $cls = ''; $legend = ''; if (isset($legends[$k])) { list($key, $cls) = explode(':', $legends[$k]); $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this,\'' . $key . '\',\'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>'; } if (isset($fs[$this->strTable][$key])) { $class .= $fs[$this->strTable][$key] ? '' : ' collapsed'; } else { $class .= $cls && $legend ? ' ' . $cls : ''; } $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend; // Build rows of the current box foreach ($v as $kk => $vv) { if ($vv == '[EOF]') { if ($blnAjax && \Environment::get('isAjaxRequest')) { return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">'; } $blnAjax = false; $return .= "\n" . '</div>'; continue; } if (preg_match('/^\\[.*\\]$/', $vv)) { $thisId = 'sub_' . substr($vv, 1, -1); $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false; $return .= "\n" . '<div id="' . $thisId . '">'; continue; } $this->strField = $vv; $this->strInputName = $vv; $this->varValue = $objRow->{$vv}; // Autofocus the first text field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Call options_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options_callback'])) { $strClass = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options_callback'][0]; $strMethod = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options_callback'][1]; $this->import($strClass); $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'] = $this->{$strClass}->{$strMethod}($this); } // Convert CSV fields if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple'] && isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'])) { $this->varValue = trimsplit($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'], $this->varValue); } /* // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->$callback[0]->$callback[1]($this->varValue, $this); } elseif (is_callable($callback)) { $this->varValue = $callback($this->varValue, $this); } } $this->objActiveRecord->{$this->strField} = $this->varValue; } */ // prepare values of special fields like radio, select and checkbox $strInputType = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType']; // field types radio, select, multi checkbox if (in_array($strInputType, array('radio', 'select', 'conditionalselect', 'countryselect')) || $strInputType == 'checkbox' && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) { if (in_array($this->strField, $this->arrBaseFields) && in_array($this->strField, $this->arrOwnerFields)) { if ($this->strField == 'fd_user') { if ($this->User && $this->User->id) { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['default'] = $this->User->id; } } } else { // foreignKey fields if ($strInputType == 'select' && strlen($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['foreignKey'])) { // include blank Option $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['includeBlankOption'] = true; $arrKey = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['foreignKey']); $strForeignTable = $arrKey[0]; $strForeignField = $arrKey[1]; // WHERE condition for foreignKey $strForeignKeyCond = ''; if (strlen($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['foreignKeyWhere'])) { $strForeignKeyCond = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['foreignKeyWhere']; } // check if foreignKey table is a formdata table if (substr($strForeignTable, 0, 3) == 'fd_') { $strFormKey = substr($strForeignTable, 3); $strForeignDcaKey = $strForeignTable; $strForeignTable = 'tl_formdata'; // backup current dca and load dca for foreign formdata $BAK_DCA = $GLOBALS['TL_DCA'][$this->strTable]; $this->loadDataContainer($strForeignDcaKey); $strForeignField = $arrKey[1]; $strForeignSqlField = '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $strForeignField . '" AND pid=f.id ) AS `' . $strForeignField . '`'; $sqlForeignFd = "SELECT f.id," . $strForeignSqlField . " FROM tl_formdata f, tl_formdata_details fd "; $sqlForeignFd .= "WHERE (f.id=fd.pid) AND f." . $GLOBALS['TL_DCA'][$strForeignTable]['tl_formdata']['formFilterKey'] . "='" . $GLOBALS['TL_DCA'][$strForeignTable]['tl_formdata']['formFilterValue'] . "' AND fd.ff_name='" . $strForeignField . "'"; if (!empty($strForeignKeyCond)) { $arrForeignKeyCond = preg_split('/([\\s!=><]+)/', $strForeignKeyCond, -1, PREG_SPLIT_DELIM_CAPTURE); $strForeignCondField = $arrForeignKeyCond[0]; unset($arrForeignKeyCond[0]); if (in_array($strForeignCondField, $GLOBALS['TL_DCA'][$strForeignTable]['tl_formdata']['baseFields'])) { $sqlForeignFd .= ' AND f.' . $strForeignCondField . implode('', $arrForeignKeyCond); } if (in_array($strForeignCondField, $GLOBALS['TL_DCA'][$strForeignTable]['tl_formdata']['detailFields'])) { $sqlForeignFd .= ' AND (SELECT value FROM tl_formdata_details WHERE ff_name="' . $strForeignCondField . '" AND pid=f.id ) ' . implode('', $arrForeignKeyCond); } } $objForeignFd = \Database::getInstance()->prepare($sqlForeignFd)->execute(); // reset current dca $GLOBALS['TL_DCA'][$this->strTable] = $BAK_DCA; unset($BAK_DCA); if ($objForeignFd->numRows) { $arrForeignRecords = $objForeignFd->fetchAllAssoc(); if (!empty($arrForeignRecords)) { foreach ($arrForeignRecords as $arrForeignRecord) { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'][$arrForeignRecord['id']] = $arrForeignRecord[$strForeignField] . ' [~' . $arrForeignRecord['id'] . '~]'; } } unset($arrForeignRecords); } // unset dca 'foreignKey': prevents \Widget::getAttributesFromDca to read options from table instead handle as normal select unset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['foreignKey']); unset($objForeignFd); } elseif (\Database::getInstance()->fieldExists($strForeignField, $strForeignTable)) { $blnAlias = \Database::getInstance()->fieldExists('alias', $strForeignTable); $sqlForeign = "SELECT id," . ($blnAlias ? "alias," : "") . $strForeignField . " FROM " . $strForeignTable . (strlen($strForeignKeyCond) ? " WHERE " . $strForeignKeyCond : '') . " ORDER BY " . $strForeignField; $objForeign = \Database::getInstance()->prepare($sqlForeign)->execute(); if ($objForeign->numRows) { $arrForeignRecords = $objForeign->fetchAllAssoc(); if (!empty($arrForeignRecords)) { foreach ($arrForeignRecords as $arrForeignRecord) { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'][$arrForeignRecord['id']] = $arrForeignRecord[$strForeignField] . ' [~' . ($blnAlias && strlen($arrForeignRecord['alias']) ? $arrForeignRecord['alias'] : $arrForeignRecord['id']) . '~]'; } } unset($arrForeignRecords); } // unset dca 'foreignKey': prevents \Widget::getAttributesFromDca to read options from table instead handle as normal select unset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['foreignKey']); unset($objForeign); } // sort options on label asort($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options']); } if (!is_array($this->varValue)) { $strSep = isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'] : '|'; $arrValues = explode($strSep, $this->varValue); } else { $arrValues = $this->varValue; } if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['efgStoreValues']) { $this->varValue = $arrValues; } else { // prepare values $arrNewValues = array(); foreach ($arrValues as $kVal => $vVal) { $vVal = trim($vVal); $strK = false; if (strlen($vVal) && $strK == false) { // handle grouped options foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'] as $strOptsKey => $varOpts) { if (is_array($varOpts)) { $strK = array_search($vVal, $varOpts); } else { $strK = array_search($vVal, $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options']); } if ($strK !== false) { $arrNewValues[] = $strK; break; } } // add saved option to available options if it does not exist if ($strK === false) { $strK = preg_replace('/(.*?\\[)(.*?)(\\])/si', '$2', $vVal); $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'][$strK] = $vVal; $arrNewValues[] = $strK; } } } $this->varValue = $arrNewValues; } } } elseif ($strInputType == 'checkbox' && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) { // Modify options to handle Contao 3 new validation in Widget::isValidOption() if (in_array($this->strField, $this->arrDetailFields)) { if (!is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'])) { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'] = array('1' => $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['label'][0]); } $strFirstOpt = array_pop($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options']); $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'][1] = $strFirstOpt; if (!empty($this->varValue)) { $this->varValue = '1'; } } } elseif ($strInputType == 'efgLookupSelect') { $arrFieldOptions = $this->Formdata->prepareWidgetOptions($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]); $arrNewOptions = array(); // prepare options array and value if (is_array($arrFieldOptions)) { // prepare options array foreach ($arrFieldOptions as $k => $v) { $arrNewOptions[$v['value']] = $v['label']; } } $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'] = $arrNewOptions; // prepare varValue if (!empty($this->varValue)) { if (!is_array($this->varValue)) { $strSep = isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'] : '|'; $this->varValue = explode($strSep, $this->varValue); } foreach ($this->varValue as $k => $v) { $sNewVal = array_search($v, $arrNewOptions); if ($sNewVal) { $this->varValue[$v] = $sNewVal; } } } // render type efgLookupSelect as SelectMenu $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] = 'select'; } elseif ($strInputType == 'efgLookupCheckbox') { $arrFieldOptions = $this->Formdata->prepareWidgetOptions($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]); $arrNewOptions = array(); // prepare options array and value if (is_array($arrFieldOptions)) { // prepare options array foreach ($arrFieldOptions as $k => $v) { $arrNewOptions[$v['value']] = $v['label']; } } $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'] = $arrNewOptions; // prepare varValue if (!empty($this->varValue)) { if (!is_array($this->varValue)) { $strSep = isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'] : '|'; $this->varValue = explode($strSep, $this->varValue); } foreach ($this->varValue as $k => $v) { $sNewVal = array_search($v, $arrNewOptions); if ($sNewVal) { $this->varValue[$v] = $sNewVal; } } } // render type efgLookupCheckbox as CheckboxMenu $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] = 'checkbox'; } elseif ($strInputType == 'efgLookupRadio') { $arrFieldOptions = $this->Formdata->prepareWidgetOptions($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]); $arrNewOptions = array(); // prepare options array and value if (is_array($arrFieldOptions)) { // prepare options array foreach ($arrFieldOptions as $k => $v) { $arrNewOptions[$v['value']] = $v['label']; } } $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['options'] = $arrNewOptions; // prepare varValue if (!empty($this->varValue)) { if (!is_array($this->varValue)) { $strSep = isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'] : '|'; $this->varValue = explode($strSep, $this->varValue); } foreach ($this->varValue as $k => $v) { $sNewVal = array_search($v, $arrNewOptions); if ($sNewVal) { $this->varValue[$v] = $sNewVal; } } } // render type efgLookupRadio as RadioMenu $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] = 'radio'; } else { $this->varValue = $this->Formdata->prepareDatabaseValueForWidget($this->varValue, $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]); } $this->objActiveRecord->{$this->strField} = $this->varValue; // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback}[0]->{$callback}[1]($this->varValue, $this); } elseif (is_callable($callback)) { $this->varValue = $callback($this->varValue, $this); } } $this->objActiveRecord->{$this->strField} = $this->varValue; } // Build the row and pass the current palette string $blnAjax ? $strAjax .= $this->row($this->strPalette) : ($return .= $this->row($this->strPalette)); } $class = 'tl_box'; $return .= "\n" . '</fieldset>'; } } $version = ''; // Submit buttons $arrButtons = array(); $arrButtons['save'] = '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">'; if (!\Input::get('nb')) { $arrButtons['saveNclose'] = '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">'; } if (!\Input::get('popup') && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) { $arrButtons['saveNcreate'] = '<input type="submit" name="saveNcreate" id="saveNcreate" class="tl_submit" accesskey="n" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNcreate']) . '">'; } if (\Input::get('s2e')) { $arrButtons['saveNedit'] = '<input type="submit" name="saveNedit" id="saveNedit" class="tl_submit" accesskey="e" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNedit']) . '">'; } elseif (!\Input::get('popup') && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 || strlen($this->ptable) || $GLOBALS['TL_DCA'][$this->strTable]['config']['switchToEdit'])) { $arrButtons['saveNback'] = '<input type="submit" name="saveNback" id="saveNback" class="tl_submit" accesskey="g" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNback']) . '">'; } // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback}[0]->{$callback}[1]($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } // Add some buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </form> <script> window.addEvent(\'domready\', function() { Theme.focusInput("' . $this->strTable . '"); }); </script>'; // TODO: find a better solution to handle toggleSubpalette ... $return .= $this->getSubpaletteJavascript(); $return .= $this->getFilepickerJavascript('reloadEfgFiletree'); // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . ' <div id="tl_buttons">' . (\Input::get('nb') ? ' ' : ' <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>') . ' </div> <h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['MSC']['editRecord'], $this->intId ? 'ID ' . $this->intId : '') . '</h2> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { $arrValues = $this->values; array_unshift($arrValues, time()); // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this); } elseif (is_callable($callback)) { $callback($this); } } } // Set the current timestamp \Database::getInstance()->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE " . implode(' AND ', $this->procedure))->execute($arrValues); // Redirect if (isset($_POST['saveNclose'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); \Controller::redirect($this->getReferer()); } elseif (isset($_POST['saveNedit'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $strUrl = \Backend::addToUrl($GLOBALS['TL_DCA'][$this->strTable]['list']['operations']['edit']['href']); $strUrl = preg_replace('/(&)?s2e=[^&]*/i', '', $strUrl); $strUrl = preg_replace('/(&)?act=[^&]*/i', '', $strUrl); \Controller::redirect($strUrl); } elseif (isset($_POST['saveNback'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); \Controller::redirect(\Environment::get('script') . '?do=' . \Input::get('do')); } elseif (isset($_POST['saveNcreate'])) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); $strUrl = \Environment::get('script') . '?do=' . \Input::get('do'); if (isset($_GET['table'])) { $strUrl .= '&table=' . \Input::get('table'); } $strUrl .= strlen($GLOBALS['TL_DCA'][$this->strTable]['config']['ptable']) ? '&act=create&mode=2&pid=' . CURRENT_ID : '&act=create'; \Controller::redirect($strUrl . '&rt=' . REQUEST_TOKEN); } \Controller::reload(); } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Auto-generate a form to edit the current database record * @param integer * @param integer * @return string */ public function edit($intID = false, $ajaxId = false) { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { \System::log('Table ' . $this->strTable . ' is not editable', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } if ($intID) { $this->intId = $intID; } // Get the current record $objRow = \Database::getInstance()->prepare("SELECT * FROM {$this->strTable} WHERE id=?")->limit(1)->execute($this->intId); // Redirect if there is no record with the given ID if ($objRow->numRows < 1) { \System::log('Could not load record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } elseif ($objRow->language != '') { \System::log('Cannot edit language record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } $this->objActiveRecord = $objRow; $return = ''; $this->values[] = $this->intId; $this->procedure[] = 'id=?'; $this->blnCreateNewVersion = false; $objVersions = new \Versions($this->strTable, $this->intId); // Compare versions if (\Input::get('versions')) { $objVersions->compare(); } // Restore a version if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') { $objVersions->restore(\Input::post('version')); $this->reload(); } $objVersions->initialize(); // Load and/or change language $this->blnEditLanguage = false; if (!empty($this->arrTranslations)) { $blnLanguageUpdated = false; $session = $this->Session->getData(); if (\Input::post('FORM_SUBMIT') == 'tl_language') { if (in_array(\Input::post('language'), $this->arrTranslations)) { $session['language'][$this->strTable][$this->intId] = \Input::post('language'); } else { unset($session['language'][$this->strTable][$this->intId]); } $blnLanguageUpdated = true; } elseif (\Input::post('FORM_SUBMIT') == $this->strTable && isset($_POST['deleteLanguage'])) { $this->Database->prepare("DELETE FROM {$this->strTable} WHERE pid=? AND language=?")->execute($this->intId, $session['language'][$this->strTable][$this->intId]); unset($session['language'][$this->strTable][$this->intId]); $blnLanguageUpdated = true; } if ($blnLanguageUpdated) { $this->Session->setData($session); $_SESSION['TL_INFO'] = ''; \Controller::reload(); } if ($_SESSION['BE_DATA']['language'][$this->strTable][$this->intId] != '' && in_array($_SESSION['BE_DATA']['language'][$this->strTable][$this->intId], $this->arrTranslations)) { $objRow = $this->Database->prepare("SELECT * FROM {$this->strTable} WHERE pid=? AND language=?")->execute($this->intId, $_SESSION['BE_DATA']['language'][$this->strTable][$this->intId]); if (!$objRow->numRows) { $intId = $this->Database->prepare("INSERT INTO {$this->strTable} (pid,tstamp,language) VALUES (?,?,?)")->execute($this->intId, time(), $_SESSION['BE_DATA']['language'][$this->strTable][$this->intId])->insertId; $objRow = $this->Database->prepare("SELECT * FROM {$this->strTable} WHERE id=?")->execute($intId); } $this->objActiveRecord = $objRow; $this->values = array($this->intId, $_SESSION['BE_DATA']['language'][$this->strTable][$this->intId]); $this->procedure = array('pid=?', 'language=?'); $this->blnEditLanguage = true; } } // Build an array from boxes and rows $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); $legends = array(); if (!empty($boxes)) { foreach ($boxes as $k => $v) { $eCount = 1; $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if (preg_match('/^\\[.*\\]$/i', $vv)) { ++$eCount; continue; } if (preg_match('/^\\{.*\\}$/', $vv)) { $legends[$k] = substr($vv, 1, -1); unset($boxes[$k][$kk]); } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } elseif ($this->blnEditLanguage && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['attributes']['multilingual']) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (count($boxes[$k]) < $eCount) { unset($boxes[$k]); } } $class = 'tl_tbox'; $fs = $this->Session->get('fieldset_states'); $blnIsFirst = true; // Render boxes foreach ($boxes as $k => $v) { $strAjax = ''; $blnAjax = false; $key = ''; $cls = ''; $legend = ''; if (isset($legends[$k])) { list($key, $cls) = explode(':', $legends[$k]); $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this,\'' . $key . '\',\'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>'; } if (isset($fs[$this->strTable][$key])) { $class .= $fs[$this->strTable][$key] ? '' : ' collapsed'; } else { $class .= $cls && $legend ? ' ' . $cls : ''; } $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend; // Build rows of the current box foreach ($v as $vv) { if ($vv == '[EOF]') { if ($blnAjax && \Environment::get('isAjaxRequest')) { return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">'; } $blnAjax = false; $return .= "\n" . '</div>'; continue; } if (preg_match('/^\\[.*\\]$/', $vv)) { $thisId = 'sub_' . substr($vv, 1, -1); $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false; $return .= "\n" . '<div id="' . $thisId . '">'; continue; } $this->strField = $vv; $this->strInputName = $vv; $this->varValue = $this->objActiveRecord->{$vv}; // Autofocus the first field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Convert CSV fields (see #2890) if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple'] && isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'])) { $this->varValue = trimsplit($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'], $this->varValue); } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback}[0]->{$callback}[1]($this->varValue, $this); } elseif (is_callable($callback)) { $this->varValue = call_user_func($callback, $this->varValue, $this); } } } // Re-set the current value $this->objActiveRecord->{$this->strField} = $this->varValue; // Build the row and pass the current palette string (thanks to Tristan Lins) $blnAjax ? $strAjax .= $this->row($this->strPalette) : ($return .= $this->row($this->strPalette)); } $class = 'tl_box'; $return .= "\n" . '</fieldset>'; } } $version = ''; // Versions overview if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning']) { $version = $objVersions->renderDropdown(); } if ('' === $version) { $version = '<div class="tl_version_panel"></div>'; } // Check languages if (!empty($this->arrTranslations)) { $arrAvailableLanguages = $this->Database->prepare("SELECT language FROM {$this->strTable} WHERE pid=?")->execute($this->intId)->fetchEach('language'); $available = ''; $undefined = ''; foreach ($this->arrTranslations as $language) { if (in_array($language, $arrAvailableLanguages)) { if ($_SESSION['BE_DATA']['language'][$this->strTable][$this->intId] == $language) { $available .= '<option value="' . $language . '" selected="selected">' . $this->arrTranslationLabels[$language] . '</option>'; $_SESSION['TL_INFO'] = array($GLOBALS['TL_LANG']['MSC']['editingLanguage']); } else { $available .= '<option value="' . $language . '">' . $this->arrTranslationLabels[$language] . '</option>'; } } else { $undefined .= '<option value="' . $language . '">' . $this->arrTranslationLabels[$language] . ' (' . $GLOBALS['TL_LANG']['MSC']['undefinedLanguage'] . ')' . '</option>'; } } $version = str_replace('<div class="tl_version_panel">', '<div class="tl_version_panel tl_iso_products_panel"> <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_language" class="tl_form" method="post"> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_language"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <select name="language" class="tl_select' . (strlen($_SESSION['BE_DATA']['language'][$this->strTable][$this->intId]) ? ' active' : '') . '" onchange="document.id(this).getParent(\'form\').submit()"> <option value="">' . $GLOBALS['TL_LANG']['MSC']['defaultLanguage'] . '</option>' . $available . $undefined . ' </select> <noscript> <input type="submit" name="editLanguage" class="tl_submit" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['editLanguage']) . '"> </noscript> </div> </form>', $version); } // Submit buttons $arrButtons = array(); $arrButtons['save'] = '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">'; if (!\Input::get('nb')) { $arrButtons['saveNclose'] = '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">'; } if (!\Input::get('popup') && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) { $arrButtons['saveNcreate'] = '<input type="submit" name="saveNcreate" id="saveNcreate" class="tl_submit" accesskey="n" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNcreate']) . '">'; } if (\Input::get('s2e')) { $arrButtons['saveNedit'] = '<input type="submit" name="saveNedit" id="saveNedit" class="tl_submit" accesskey="e" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNedit']) . '">'; } elseif (!\Input::get('popup') && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 || strlen($this->ptable) || $GLOBALS['TL_DCA'][$this->strTable]['config']['switchToEdit'])) { $arrButtons['saveNback'] = '<input type="submit" name="saveNback" id="saveNback" class="tl_submit" accesskey="g" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNback']) . '">'; } if ($this->blnEditLanguage) { $arrButtons['deleteLanguage'] = '<input type="submit" name="deleteLanguage" class="tl_submit" style="float:right" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['deleteLanguage']) . '" onclick="return confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteLanguageConfirm'] . '\')">'; } // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback}[0]->{$callback}[1]($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } // Add the buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </form> <script> window.addEvent(\'domready\', function() { Theme.focusInput("' . $this->strTable . '"); }); </script>'; $copyFallback = $this->blnEditLanguage ? ' :: <a href="' . \Backend::addToUrl('act=copyFallback') . '" class="header_iso_copy" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['copyFallback']) . '" accesskey="d" onclick="Backend.getScrollOffset();">' . ($GLOBALS['TL_LANG']['MSC']['copyFallback'] ? $GLOBALS['TL_LANG']['MSC']['copyFallback'] : 'copyFallback') . '</a>' : ''; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . ' <div id="tl_buttons">' . (\Input::get('nb') ? ' ' : ' <a href="' . \System::getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>') . $copyFallback . ' </div> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { $arrValues = $this->values; array_unshift($arrValues, time()); // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this); } elseif (is_callable($callback)) { call_user_func($callback, $this); } } } // Save the current version if ($this->blnCreateNewVersion) { $objVersions->create(); // Call the onversion_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this->strTable, $this->objActiveRecord->id, $this); } elseif (is_callable($callback)) { call_user_func($callback, $this->strTable, $this->objActiveRecord->id, $this); } } } \System::log('A new version of record "' . $this->strTable . '.id=' . $this->intId . '" has been created' . $this->getParentEntries($this->strTable, $this->intId), __METHOD__, TL_GENERAL); } // Set the current timestamp (-> DO NOT CHANGE THE ORDER version - timestamp) if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']) { $this->Database->prepare("UPDATE " . $this->strTable . " SET ptable=?, tstamp=? WHERE id=?")->execute($this->ptable, time(), $this->intId); } else { $this->Database->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE id=?")->execute(time(), $this->intId); } // Redirect if (isset($_POST['saveNclose'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); \Controller::redirect(\System::getReferer()); } elseif (isset($_POST['saveNedit'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $strUrl = \Backend::addToUrl($GLOBALS['TL_DCA'][$this->strTable]['list']['operations']['edit']['href'], false); $strUrl = preg_replace('/(&)?(s2e|act)=[^&]*/i', '', $strUrl); \Controller::redirect($strUrl); } elseif (isset($_POST['saveNback'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); if ($this->ptable == '') { \Controller::redirect(TL_SCRIPT . '?do=' . \Input::get('do')); } elseif ($this->ptable == 'tl_theme' && $this->strTable == 'tl_style_sheet' || $this->ptable == 'tl_page' && $this->strTable == 'tl_article') { \Controller::redirect(\System::getReferer(false, $this->strTable)); } else { \Controller::redirect(\System::getReferer(false, $this->ptable)); } } elseif (isset($_POST['saveNcreate'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $strUrl = TL_SCRIPT . '?do=' . \Input::get('do'); if (isset($_GET['table'])) { $strUrl .= '&table=' . \Input::get('table'); } // Tree view if ($this->treeView) { $strUrl .= '&act=create&mode=1&pid=' . $this->intId; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 || $this->activeRecord->pid > 0) { $strUrl .= $this->Database->fieldExists('sorting', $this->strTable) ? '&act=create&mode=1&pid=' . $this->intId . '&id=' . $this->activeRecord->pid : '&act=create&mode=2&pid=' . $this->activeRecord->pid; } else { $strUrl .= $this->ptable != '' ? '&act=create&mode=2&pid=' . CURRENT_ID : '&act=create'; } \Controller::redirect($strUrl . '&rt=' . REQUEST_TOKEN); } \Controller::reload(); } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Validate the upload * @return string */ public function validateUpload() { \Message::reset(); $strTempName = $this->strName . '_fineuploader'; $objUploader = new \FileUpload(); $objUploader->setName($this->strName); $blnIsChunk = isset($_POST['qqpartindex']); // Convert the $_FILES array to Contao format if (!empty($_FILES[$strTempName])) { $arrFile = array('name' => array($_FILES[$strTempName]['name']), 'type' => array($_FILES[$strTempName]['type']), 'tmp_name' => array($_FILES[$strTempName]['tmp_name']), 'error' => array($_FILES[$strTempName]['error']), 'size' => array($_FILES[$strTempName]['size'])); // Set the UUID as the filename if ($blnIsChunk) { $arrFile['name'][0] = \Input::post('qquuid') . '.chunk'; } // Check if the file exists if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $arrFile['name'][0])) { $arrFile['name'][0] = $this->getFileName($arrFile['name'][0], $this->strTemporaryPath); } $_FILES[$this->strName] = $arrFile; unset($_FILES[$strTempName]); // Unset the temporary file } $varInput = ''; $extensions = null; $maxlength = null; // Add the "chunk" extension to upload types if ($blnIsChunk) { $extensions = $GLOBALS['TL_CONFIG']['uploadTypes']; $GLOBALS['TL_CONFIG']['uploadTypes'] .= ',chunk'; } // Override the default maxlength value if (isset($this->arrConfiguration['maxlength'])) { $maxlength = $GLOBALS['TL_CONFIG']['maxFileSize']; $GLOBALS['TL_CONFIG']['maxFileSize'] = $this->arrConfiguration['maxlength']; } try { $varInput = $objUploader->uploadTo($this->strTemporaryPath); if ($objUploader->hasError()) { foreach ($_SESSION['TL_ERROR'] as $strError) { $this->addError($strError); } } \Message::reset(); } catch (\Exception $e) { $this->addError($e->getMessage()); } // Restore the default maxlength value if ($maxlength !== null) { $GLOBALS['TL_CONFIG']['maxFileSize'] = $maxlength; } // Restore the default extensions value if ($extensions !== null) { $GLOBALS['TL_CONFIG']['uploadTypes'] = $extensions; } if (!is_array($varInput) || empty($varInput)) { $this->addError($GLOBALS['TL_LANG']['MSC']['fineuploader_error']); } $varInput = $varInput[0]; // Store the chunk in the session for further merge if ($blnIsChunk) { $_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')][] = $varInput; // This is the last chunking request, merge the chunks and create the final file if (\Input::post('qqpartindex') == \Input::post('qqtotalparts') - 1) { $strFileName = \Input::post('qqfilename'); // Get the new file name if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $strFileName)) { $strFileName = $this->getFileName($strFileName, $this->strTemporaryPath); } $objFile = new \File($this->strTemporaryPath . '/' . $strFileName); // Merge the chunks foreach ($_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')] as $strChunk) { $objFile->append(file_get_contents(TL_ROOT . '/' . $strChunk), ''); // Delete the file \Files::getInstance()->delete($strChunk); } $objFile->close(); $varInput = $objFile->path; } } return $varInput; }
/** * Pass an order to the document * @param DataContainer */ public function printDocument(\DataContainer $dc) { $strRedirectUrl = str_replace('&key=print_document', '', \Environment::get('request')); if (\Input::post('FORM_SUBMIT') == 'tl_iso_print_document') { if (($objOrder = Order::findByPk($dc->id)) === null) { \Message::addError('Could not find order id.'); \Controller::redirect($strRedirectUrl); } if (($objConfig = $objOrder->getRelated('config_id')) === null) { \Message::addError('Could not find config id.'); \Controller::redirect($strRedirectUrl); } // Set current config Isotope::setConfig($objConfig); /** @var \Isotope\Interfaces\IsotopeDocument $objDocument */ if (($objDocument = Document::findByPk(\Input::post('document'))) === null) { \Message::addError('Could not find document id.'); \Controller::redirect($strRedirectUrl); } $objDocument->outputToBrowser($objOrder); } $arrSelect = array('name' => 'document', 'label' => &$GLOBALS['TL_LANG']['tl_iso_product_collection']['document_choice'], 'inputType' => 'select', 'foreignKey' => 'tl_iso_document.name', 'eval' => array('mandatory' => true)); $objSelect = new \SelectMenu(\SelectMenu::getAttributesFromDca($arrSelect, $arrSelect['name'])); $strMessages = \Message::generate(); \Message::reset(); // Return form return ' <div id="tl_buttons"> <a href="' . ampersand($strRedirectUrl) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> <h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['tl_iso_product_collection']['print_document'][1], $dc->id) . '</h2>' . $strMessages . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_iso_product_import" class="tl_form" method="post"> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="tl_iso_print_document"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <div class="tl_tbox block"> ' . $objSelect->parse() . ' <p class="tl_help">' . $objSelect->description . '</p> </div> </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> <input type="submit" name="print" id="print" class="tl_submit" alt="" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_iso_product_collection']['print']) . '"> </div> </div> </form>'; }
/** * Validate the upload * @return string */ public function validateUpload() { \Message::reset(); $strTempName = $this->strName . '_upload'; $objUploader = new \FileUpload(); $objUploader->setName($this->strName); // Convert the $_FILES array to Contao format if (!empty($_FILES[$strTempName])) { $arrFile = array('name' => array($_FILES[$strTempName]['name']), 'type' => array($_FILES[$strTempName]['type']), 'tmp_name' => array($_FILES[$strTempName]['tmp_name']), 'error' => array($_FILES[$strTempName]['error']), 'size' => array($_FILES[$strTempName]['size'])); // Check if the file exists if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $arrFile['name'][0])) { $arrFile['name'][0] = $this->getFileName($arrFile['name'][0], $this->strTemporaryPath); } $_FILES[$this->strName] = $arrFile; unset($_FILES[$strTempName]); // Unset the temporary file } $varInput = ''; $maxlength = null; // Override the default maxlength value if (isset($this->arrConfiguration['maxlength'])) { $maxlength = $GLOBALS['TL_CONFIG']['maxFileSize']; $GLOBALS['TL_CONFIG']['maxFileSize'] = $this->getMaximumFileSize(); } try { $varInput = $objUploader->uploadTo($this->strTemporaryPath); if ($objUploader->hasError()) { foreach ($_SESSION['TL_ERROR'] as $strError) { $this->addError($strError); } } \Message::reset(); } catch (\Exception $e) { $this->addError($e->getMessage()); } // Restore the default maxlength value if ($maxlength !== null) { $GLOBALS['TL_CONFIG']['maxFileSize'] = $maxlength; } if (!is_array($varInput) || empty($varInput)) { $this->addError($GLOBALS['TL_LANG']['MSC']['avatar_error']); } $varInput = $varInput[0]; $strExtension = pathinfo($varInput, PATHINFO_EXTENSION); $arrAllowedTypes = trimsplit(',', strtolower($this->getAllowedExtensions())); // File type not allowed if (!in_array(strtolower($strExtension), $arrAllowedTypes)) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $strExtension)); } // Check image size if (($arrImageSize = @getimagesize(TL_ROOT . '/' . $varInput)) !== false) { // Image exceeds maximum image width if ($arrImageSize[0] > $GLOBALS['TL_CONFIG']['imageWidth']) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filewidth'], '', $GLOBALS['TL_CONFIG']['imageWidth'])); } // Image exceeds maximum image height if ($arrImageSize[1] > $GLOBALS['TL_CONFIG']['imageHeight']) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['fileheight'], '', $GLOBALS['TL_CONFIG']['imageHeight'])); } // Image exceeds minimum image width if ($arrImageSize[0] < $this->arrAvatarSize[0]) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['avatar_width'], $this->arrAvatarSize[0])); } // Image exceeds minimum image height if ($arrImageSize[1] < $this->arrAvatarSize[1]) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['avatar_height'], $this->arrAvatarSize[1])); } } return $varInput; }
/** * Auto-generate a form to edit the current database record * @param integer * @param integer * @return string */ public function edit($intID = null, $ajaxId = null) { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { $this->log('Table "' . $this->strTable . '" is not editable', 'DC_Table edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } if ($intID != '') { $this->intId = $intID; } $return = ''; $this->values[] = $this->intId; $this->procedure[] = 'id=?'; $this->blnCreateNewVersion = false; // Change version if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'] && \Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') { $objData = $this->Database->prepare("SELECT * FROM tl_version WHERE fromTable=? AND pid=? AND version=?")->limit(1)->execute($this->strTable, $this->intId, \Input::post('version')); if ($objData->numRows) { $data = deserialize($objData->data); if (is_array($data)) { $this->Database->prepare("UPDATE " . $objData->fromTable . " %s WHERE id=?")->set($data)->execute($this->intId); $this->Database->prepare("UPDATE tl_version SET active='' WHERE pid=?")->execute($this->intId); $this->Database->prepare("UPDATE tl_version SET active=1 WHERE pid=? AND version=?")->execute($this->intId, \Input::post('version')); $this->log('Version ' . \Input::post('version') . ' of record "' . $this->strTable . '.id=' . $this->intId . '" has been restored' . $this->getParentEntries($this->strTable, $this->intId), 'DC_Table edit()', TL_GENERAL); // Trigger the onrestore_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this->intId, $this->strTable, $data, \Input::post('version')); } } } } } $this->reload(); } // Get the current record $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->executeUncached($this->intId); // Redirect if there is no record with the given ID if ($objRow->numRows < 1) { $this->log('Could not load record "' . $this->strTable . '.id=' . $this->intId . '"', 'DC_Table edit()', TL_ERROR); $this->redirect('contao/main.php?act=error'); } $this->objActiveRecord = $objRow; $this->createInitialVersion($this->strTable, $this->intId); $this->checkForTinyMce(); // Build an array from boxes and rows $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); $legends = array(); if (!empty($boxes)) { foreach ($boxes as $k => $v) { $eCount = 1; $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if (preg_match('/^\\[.*\\]$/i', $vv)) { ++$eCount; continue; } if (preg_match('/^\\{.*\\}$/i', $vv)) { $legends[$k] = substr($vv, 1, -1); unset($boxes[$k][$kk]); } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (count($boxes[$k]) < $eCount) { unset($boxes[$k]); } } $class = 'tl_tbox'; $fs = $this->Session->get('fieldset_states'); $blnIsFirst = true; // Render boxes foreach ($boxes as $k => $v) { $strAjax = ''; $blnAjax = false; $key = ''; $cls = ''; $legend = ''; if (isset($legends[$k])) { list($key, $cls) = explode(':', $legends[$k]); $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this,\'' . $key . '\',\'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>'; } if (isset($fs[$this->strTable][$key])) { $class .= $fs[$this->strTable][$key] ? '' : ' collapsed'; } else { $class .= $cls && $legend ? ' ' . $cls : ''; } $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend; // Build rows of the current box foreach ($v as $vv) { if ($vv == '[EOF]') { if ($blnAjax && \Environment::get('isAjaxRequest')) { return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">'; } $blnAjax = false; $return .= "\n" . '</div>'; continue; } if (preg_match('/^\\[.*\\]$/i', $vv)) { $thisId = 'sub_' . substr($vv, 1, -1); $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false; $return .= "\n" . '<div id="' . $thisId . '">'; continue; } $this->strField = $vv; $this->strInputName = $vv; $this->varValue = $objRow->{$vv}; // Autofocus the first field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Convert CSV fields (see #2890) if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple'] && isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'])) { $this->varValue = trimsplit($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'], $this->varValue); } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback}[0]->{$callback}[1]($this->varValue, $this); } } $this->objActiveRecord->{$this->strField} = $this->varValue; } // Build the row and pass the current palette string (thanks to Tristan Lins) $blnAjax ? $strAjax .= $this->row($this->strPalette) : ($return .= $this->row($this->strPalette)); } $class = 'tl_box'; $return .= "\n" . '</fieldset>'; } } $version = ''; // Check versions if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning']) { $objVersion = $this->Database->prepare("SELECT tstamp, version, username, active FROM tl_version WHERE fromTable=? AND pid=? ORDER BY version DESC")->execute($this->strTable, $this->intId); if ($objVersion->numRows > 1) { $versions = ''; while ($objVersion->next()) { $versions .= ' <option value="' . $objVersion->version . '"' . ($objVersion->active ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['version'] . ' ' . $objVersion->version . ' (' . $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objVersion->tstamp) . ') ' . $objVersion->username . '</option>'; } $version = ' <div class="tl_version_panel"> <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_version" class="tl_form" method="post"> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_version"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <select name="version" class="tl_select">' . $versions . ' </select> <input type="submit" name="showVersion" id="showVersion" class="tl_submit" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['restore']) . '"> <a href="contao/diff.php?table=' . $this->strTable . '&pid=' . $this->intId . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']) . '" onclick="Backend.openModalIframe({\'width\':860,\'title\':\'' . specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']) . '\',\'url\':this.href});return false">' . $this->generateImage('diff.gif') . '</a> </div> </form> </div> '; } } // Add some buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> <input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '"> <input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '"> ' . (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] ? ' <input type="submit" name="saveNcreate" id="saveNcreate" class="tl_submit" accesskey="n" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNcreate']) . '"> ' : '') . (\Input::get('s2e') ? ' <input type="submit" name="saveNedit" id="saveNedit" class="tl_submit" accesskey="e" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNedit']) . '"> ' : ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 || strlen($this->ptable) || $GLOBALS['TL_DCA'][$this->strTable]['config']['switchToEdit'] ? ' <input type="submit" name="saveNback" id="saveNback" class="tl_submit" accesskey="g" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNback']) . '"> ' : '')) . ' </div> </div> </form>'; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . ' <div id="tl_buttons"> <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> <h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['MSC']['editRecord'], $this->intId ? 'ID ' . $this->intId : '') . '</h2> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { $arrValues = $this->values; array_unshift($arrValues, time()); // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this); } } // Save the current version if ($this->blnCreateNewVersion && \Input::post('SUBMIT_TYPE') != 'auto') { $this->createNewVersion($this->strTable, $this->intId); // Call the onversion_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this->strTable, $this->intId, $this); } } $this->log('A new version of record "' . $this->strTable . '.id=' . $this->intId . '" has been created' . $this->getParentEntries($this->strTable, $this->intId), 'DC_Table edit()', TL_GENERAL); } // Set the current timestamp (-> DO NOT CHANGE THE ORDER version - timestamp) $this->Database->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE id=?")->execute(time(), $this->intId); // Redirect if (isset($_POST['saveNclose'])) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); $this->redirect($this->getReferer()); } elseif (isset($_POST['saveNedit'])) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); $strUrl = $this->addToUrl($GLOBALS['TL_DCA'][$this->strTable]['list']['operations']['edit']['href']); $strUrl = preg_replace('/(&)?s2e=[^&]*/i', '', $strUrl); $strUrl = preg_replace('/(&)?act=[^&]*/i', '', $strUrl); $this->redirect($strUrl); } elseif (isset($_POST['saveNback'])) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); if ($this->ptable == '') { $this->redirect(\Environment::get('script') . '?do=' . \Input::get('do')); } elseif ($this->ptable == 'tl_theme' && $this->strTable == 'tl_style_sheet' || $this->ptable == 'tl_page' && $this->strTable == 'tl_article') { $this->redirect($this->getReferer(false, $this->strTable)); } else { $this->redirect($this->getReferer(false, $this->ptable)); } } elseif (isset($_POST['saveNcreate'])) { \Message::reset(); setcookie('BE_PAGE_OFFSET', 0, 0, '/'); $strUrl = \Environment::get('script') . '?do=' . \Input::get('do'); if (isset($_GET['table'])) { $strUrl .= '&table=' . \Input::get('table'); } // Tree view if ($this->treeView) { $strUrl .= '&act=create&mode=1&pid=' . $this->intId; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4) { $strUrl .= $this->Database->fieldExists('sorting', $this->strTable) ? '&act=create&mode=1&pid=' . $this->intId . '&id=' . $this->activeRecord->pid : '&act=create&mode=2&pid=' . $this->activeRecord->pid; } else { $strUrl .= $this->ptable != '' ? '&act=create&mode=2&pid=' . CURRENT_ID : '&act=create'; } $this->redirect($strUrl); } $this->reload(); } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Auto-generate a form to edit the current database record * * @param integer $intId * @param integer $ajaxId * * @return string */ public function edit($intId = null, $ajaxId = null) { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { $this->log('Table "' . $this->strTable . '" is not editable', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } if ($intId != '') { $this->intId = $intId; } // Get the current record $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->intId); // Redirect if there is no record with the given ID if ($objRow->numRows < 1) { $this->log('Could not load record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } $this->objActiveRecord = $objRow; $return = ''; $this->values[] = $this->intId; $this->procedure[] = 'id=?'; $this->blnCreateNewVersion = false; $objVersions = new \Versions($this->strTable, $this->intId); if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) { // Compare versions if (\Input::get('versions')) { $objVersions->compare(); } // Restore a version if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') { $objVersions->restore(\Input::post('version')); $this->reload(); } } $objVersions->initialize(); // Build an array from boxes and rows $this->strPalette = $this->getPalette(); $boxes = trimsplit(';', $this->strPalette); $legends = array(); if (!empty($boxes)) { foreach ($boxes as $k => $v) { $eCount = 1; $boxes[$k] = trimsplit(',', $v); foreach ($boxes[$k] as $kk => $vv) { if (preg_match('/^\\[.*\\]$/', $vv)) { ++$eCount; continue; } if (preg_match('/^\\{.*\\}$/', $vv)) { $legends[$k] = substr($vv, 1, -1); unset($boxes[$k][$kk]); } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) { unset($boxes[$k][$kk]); } } // Unset a box if it does not contain any fields if (count($boxes[$k]) < $eCount) { unset($boxes[$k]); } } $class = 'tl_tbox'; $fs = $this->Session->get('fieldset_states'); $blnIsFirst = true; // Render boxes foreach ($boxes as $k => $v) { $strAjax = ''; $blnAjax = false; $key = ''; $cls = ''; $legend = ''; if (isset($legends[$k])) { list($key, $cls) = explode(':', $legends[$k]); $legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this,\'' . $key . '\',\'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>'; } if (isset($fs[$this->strTable][$key])) { $class .= $fs[$this->strTable][$key] ? '' : ' collapsed'; } else { $class .= $cls && $legend ? ' ' . $cls : ''; } $return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend; // Build rows of the current box foreach ($v as $vv) { if ($vv == '[EOF]') { if ($blnAjax && \Environment::get('isAjaxRequest')) { return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">'; } $blnAjax = false; $return .= "\n" . '</div>'; continue; } if (preg_match('/^\\[.*\\]$/', $vv)) { $thisId = 'sub_' . substr($vv, 1, -1); $blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false; $return .= "\n" . '<div id="' . $thisId . '">'; continue; } $this->strField = $vv; $this->strInputName = $vv; $this->varValue = $objRow->{$vv}; // Autofocus the first field if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') { $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus'; $blnIsFirst = false; } // Convert CSV fields (see #2890) if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple'] && isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'])) { $this->varValue = trimsplit($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['csv'], $this->varValue); } // Call load_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->varValue = $this->{$callback[0]}->{$callback[1]}($this->varValue, $this); } elseif (is_callable($callback)) { $this->varValue = $callback($this->varValue, $this); } } } // Re-set the current value $this->objActiveRecord->{$this->strField} = $this->varValue; // Build the row and pass the current palette string (thanks to Tristan Lins) $blnAjax ? $strAjax .= $this->row($this->strPalette) : ($return .= $this->row($this->strPalette)); } $class = 'tl_box'; $return .= "\n" . '</fieldset>'; } } // Versions overview if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) { $version = $objVersions->renderDropdown(); } else { $version = ''; } // Submit buttons $arrButtons = array(); $arrButtons['save'] = '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">'; if (!\Input::get('nb')) { $arrButtons['saveNclose'] = '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">'; } if (!\Input::get('popup') && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) { $arrButtons['saveNcreate'] = '<input type="submit" name="saveNcreate" id="saveNcreate" class="tl_submit" accesskey="n" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNcreate']) . '">'; } if (\Input::get('s2e')) { $arrButtons['saveNedit'] = '<input type="submit" name="saveNedit" id="saveNedit" class="tl_submit" accesskey="e" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNedit']) . '">'; } elseif (!\Input::get('popup') && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 || strlen($this->ptable) || $GLOBALS['TL_DCA'][$this->strTable]['config']['switchToEdit'])) { $arrButtons['saveNback'] = '<input type="submit" name="saveNback" id="saveNback" class="tl_submit" accesskey="g" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNback']) . '">'; } // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } // Add the buttons and end the form $return .= ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </form> <script> window.addEvent(\'domready\', function() { Theme.focusInput("' . $this->strTable . '"); }); </script>'; // Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field) $return = $version . ' <div id="tl_buttons">' . (\Input::get('nb') ? ' ' : ' <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>') . ' </div> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="' . specialchars($this->strTable) . '"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? ' <p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return; // Reload the page to prevent _POST variables from being sent twice if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) { $arrValues = $this->values; array_unshift($arrValues, time()); // Trigger the onsubmit_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this); } elseif (is_callable($callback)) { $callback($this); } } } // Save the current version if ($this->blnCreateNewVersion) { $objVersions->create(); // Call the onversion_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'])) { @trigger_error('Using the onversion_callback has been deprecated and will no longer work in Contao 5.0. Use the oncreate_version_callback instead.', E_USER_DEPRECATED); foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->strTable, $this->intId, $this); } elseif (is_callable($callback)) { $callback($this->strTable, $this->intId, $this); } } } } // Set the current timestamp (-> DO NOT CHANGE THE ORDER version - timestamp) if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']) { $this->Database->prepare("UPDATE " . $this->strTable . " SET ptable=?, tstamp=? WHERE id=?")->execute($this->ptable, time(), $this->intId); } else { $this->Database->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE id=?")->execute(time(), $this->intId); } // Redirect if (isset($_POST['saveNclose'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $this->redirect($this->getReferer()); } elseif (isset($_POST['saveNedit'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $strUrl = $this->addToUrl($GLOBALS['TL_DCA'][$this->strTable]['list']['operations']['edit']['href'], false); $strUrl = preg_replace('/(&)?(s2e|act)=[^&]*/i', '', $strUrl); $this->redirect($strUrl); } elseif (isset($_POST['saveNback'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); if ($this->ptable == '') { $this->redirect(TL_SCRIPT . '?do=' . \Input::get('do')); } elseif ($this->ptable == 'tl_theme' && $this->strTable == 'tl_style_sheet' || $this->ptable == 'tl_page' && $this->strTable == 'tl_article') { $this->redirect($this->getReferer(false, $this->strTable)); } else { $this->redirect($this->getReferer(false, $this->ptable)); } } elseif (isset($_POST['saveNcreate'])) { \Message::reset(); \System::setCookie('BE_PAGE_OFFSET', 0, 0); $strUrl = TL_SCRIPT . '?do=' . \Input::get('do'); if (isset($_GET['table'])) { $strUrl .= '&table=' . \Input::get('table'); } // Tree view if ($this->treeView) { $strUrl .= '&act=create&mode=1&pid=' . $this->intId; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4) { $strUrl .= $this->Database->fieldExists('sorting', $this->strTable) ? '&act=create&mode=1&pid=' . $this->intId . '&id=' . $this->activeRecord->pid : '&act=create&mode=2&pid=' . $this->activeRecord->pid; } else { $strUrl .= $this->ptable != '' ? '&act=create&mode=2&pid=' . CURRENT_ID : '&act=create'; } $this->redirect($strUrl . '&rt=' . REQUEST_TOKEN); } $this->reload(); } // Set the focus if there is an error if ($this->noReload) { $return .= ' <script> window.addEvent(\'domready\', function() { Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20)); }); </script>'; } return $return; }
/** * Validate the upload * @return string */ public function validateUpload() { \Message::reset(); $objUploader = new \FileUpload(); $objUploader->setName($this->strName); $uploadFolder = $this->strTempFolder; // Convert the $_FILES array to Contao format if (!empty($_FILES[$this->strName])) { $pathinfo = pathinfo(strtolower($_FILES[$this->strName]['name'])); $strCacheName = standardize($pathinfo['filename']) . '.' . $pathinfo['extension']; $uploadFolder = $this->strTempFolder . '/' . substr($strCacheName, 0, 1); if (is_file(TL_ROOT . '/' . $uploadFolder . '/' . $strCacheName) && md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $_FILES[$this->strName]['name']) != md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $strCacheName)) { $strCacheName = standardize($pathinfo['filename']) . '-' . substr(md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $_FILES[$this->strName]['name']), 0, 8) . '.' . $pathinfo['extension']; $uploadFolder = $this->strTempFolder . '/' . substr($strCacheName, 0, 1); } \Haste\Haste::mkdirr($uploadFolder); $arrFallback = $this->getFallbackData(); // Check that image is not assigned in fallback language if (is_array($arrFallback) && in_array($strCacheName, $arrFallback)) { $this->addError($GLOBALS['TL_LANG']['ERR']['imageInFallback']); } $_FILES[$this->strName] = array('name' => array($strCacheName), 'type' => array($_FILES[$this->strName]['type']), 'tmp_name' => array($_FILES[$this->strName]['tmp_name']), 'error' => array($_FILES[$this->strName]['error']), 'size' => array($_FILES[$this->strName]['size'])); } $varInput = ''; try { $varInput = $objUploader->uploadTo($uploadFolder); } catch (\Exception $e) { $this->addError($e->getMessage()); } if ($objUploader->hasError()) { foreach ($_SESSION['TL_ERROR'] as $strError) { $this->addError($strError); } } \Message::reset(); if (!is_array($varInput) || empty($varInput)) { $this->addError($GLOBALS['TL_LANG']['MSC']['mmUnknownError']); } return $varInput[0]; }
/** * Validate the upload * @return string */ public function validateUpload() { \Message::reset(); $strTempName = $this->strName . '_fineuploader'; $objUploader = new \Haste\Util\FileUpload($this->strName); $blnIsChunk = isset($_POST['qqpartindex']); // Convert the $_FILES array to Contao format if (!empty($_FILES[$strTempName])) { $arrFile = array('name' => array($_FILES[$strTempName]['name']), 'type' => array($_FILES[$strTempName]['type']), 'tmp_name' => array($_FILES[$strTempName]['tmp_name']), 'error' => array($_FILES[$strTempName]['error']), 'size' => array($_FILES[$strTempName]['size'])); // Replace the comma character (#22) $arrFile['name'] = str_replace(',', '_', $arrFile['name']); // Set the UUID as the filename if ($blnIsChunk) { $arrFile['name'][0] = \Input::post('qquuid') . '.chunk'; } // Check if the file exists if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $arrFile['name'][0])) { $arrFile['name'][0] = $this->getFileName($arrFile['name'][0], $this->strTemporaryPath); } $_FILES[$this->strName] = $arrFile; unset($_FILES[$strTempName]); // Unset the temporary file } $varInput = ''; // Add the "chunk" extension to upload types if ($blnIsChunk) { $extensions = trimsplit(',', $GLOBALS['TL_CONFIG']['uploadTypes']); $extensions[] = 'chunk'; $objUploader->setExtensions($extensions); } // Validate the minlength if ($this->arrConfiguration['minlength'] > 0 && !$blnIsChunk) { $objUploader->setMinFileSize($this->arrConfiguration['minlength']); } // Validate the maxlength if ($this->arrConfiguration['maxlength'] > 0 || $blnIsChunk) { $objUploader->setMaxFileSize($blnIsChunk ? $this->arrConfiguration['chunkSize'] : $this->arrConfiguration['maxlength']); } try { $varInput = $objUploader->uploadTo($this->strTemporaryPath); if ($objUploader->hasError()) { foreach ($_SESSION['TL_ERROR'] as $strError) { $this->addError($strError); } } \Message::reset(); } catch (\Exception $e) { $this->addError($e->getMessage()); } if (!is_array($varInput) || empty($varInput)) { $this->addError($GLOBALS['TL_LANG']['MSC']['fineuploader_error']); } $varInput = $varInput[0]; // Store the chunk in the session for further merge if ($blnIsChunk) { $_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')][] = $varInput; // This is the last chunking request, merge the chunks and create the final file if (\Input::post('qqpartindex') == \Input::post('qqtotalparts') - 1) { $strFileName = \Input::post('qqfilename'); // Get the new file name if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $strFileName)) { $strFileName = $this->getFileName($strFileName, $this->strTemporaryPath); } $objFile = new \File($this->strTemporaryPath . '/' . $strFileName); // Merge the chunks foreach ($_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')] as $strChunk) { $objFile->append(file_get_contents(TL_ROOT . '/' . $strChunk), ''); // Delete the file \Files::getInstance()->delete($strChunk); } $objFile->close(); $varInput = $objFile->path; // Validate the minlength if ($this->arrConfiguration['minlength'] > 0 && $objFile->size < $this->arrConfiguration['minlength']) { $readableSize = \System::getReadableSize($this->arrConfiguration['minlength']); $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['minFileSize'], $readableSize)); \System::log('File "' . $objFile->name . '" is smaller than the minimum file size of ' . $readableSize, __METHOD__, TL_ERROR); } // Validate the maxlength if ($this->arrConfiguration['maxlength'] > 0 && $objFile->size > $this->arrConfiguration['maxlength']) { $readableSize = \System::getReadableSize($this->arrConfiguration['maxlength']); $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['maxFileSize'], $readableSize)); \System::log('File "' . $objFile->name . '" exceeds the maximum file size of ' . $readableSize, __METHOD__, TL_ERROR); } // Reset the chunk flag $blnIsChunk = false; // Unset the file session after merging the chunks unset($_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')]); } } // Validate and move the file immediately if ($this->arrConfiguration['directUpload'] && !$blnIsChunk) { $varInput = $this->validatorSingle($varInput, $this->getDestinationFolder()); } return $varInput; }