public function postPageEdit($params) { $this->cmsController->abortIfUserHasNotRights('MOD_PAGES_EDIT'); $pageID = null; $routeID = null; if (isset($params[0]) === true) { $pageID = (int) $params[0]; $routes = $this->routeModel->getRoutesByPageID($pageID); if (count($routes) > 0) { $routeData = array_shift($routes); $routeID = $routeData->ID; } } $coreModel = new CoreModel($this->cmsController->getDB()); $basePagesOpts = array(0 => '- no base page -'); foreach ($this->pageModel->getBasePagesForPage($pageID) as $p) { $basePagesOpts[$p->ID] = $p->language_codeFK . ', ' . $p->title; } $this->formHelper = new FormHelper(FormHelper::METHOD_POST); $this->formHelper->addField('title', null, FormHelper::TYPE_STRING, true, array('missingError' => 'Please insert a title for this page')); $this->formHelper->addField('language', null, FormHelper::TYPE_OPTION, true, array('missingError' => 'Please select a language this page', 'invalidError' => 'Please select a valid language for this page', 'options' => $coreModel->getLanguages())); $this->formHelper->addField('role', null, FormHelper::TYPE_OPTION, true, array('missingError' => 'Please select a role for this page', 'invalidError' => 'Please select a valid role for this page', 'options' => $this->getRoleOptions())); $this->formHelper->addField('base_page', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid base page for this page', 'options' => $basePagesOpts)); $this->formHelper->addField('description', null, FormHelper::TYPE_STRING, false); $this->formHelper->addField('inherit_rights', null, FormHelper::TYPE_CHECKBOX); if (!$this->formHelper->sent() || !$this->formHelper->validate()) { return $this->getPageEdit($params); } $pageRole = $this->formHelper->getFieldValue('role'); // Role specific form checks if ($pageRole === 'error') { $this->formHelper->addField('error_code', null, FormHelper::TYPE_OPTION, true, array('missingError' => 'Please select an error code for this page', 'invalidError' => 'Please select a valid error code for this page', 'options' => $this->getErrorCodeOptions())); } if (in_array($pageRole, array('page', 'module')) === true) { // Route $this->formHelper->addField('route', null, FormHelper::TYPE_STRING, true, array('missingError' => 'Please insert a title for this page')); $this->formHelper->addField('ssl', null, FormHelper::TYPE_OPTION, true, array('missingError' => 'Please choose an SSL option', 'invalidError' => 'Please choose a valid SSL option', 'options' => $this->getSSLOptions())); } if ($pageRole === 'module') { $this->formHelper->addField('module', null, FormHelper::TYPE_OPTION, true, array('missingError' => 'Please choose a module', 'invalidError' => 'Please choose a valid module', 'options' => $this->getModuleOptions())); } if (!$this->formHelper->validate()) { return $this->getPageEdit($params); } $stmntCheckErrorCode = $this->cmsController->getDB()->prepare("\n\t\t\tSELECT ID FROM page WHERE error_code = ?\n\t\t"); $errorCode = $this->formHelper->getFieldValue('error_code'); $resCheckErrorCode = $this->cmsController->getDB()->select($stmntCheckErrorCode, array($errorCode)); if (count($resCheckErrorCode) > 0 && $resCheckErrorCode[0]->ID != $pageID) { $this->formHelper->addError('error_code', 'There is already an error page (#' . $resCheckErrorCode[0]->ID . ') for error case ' . $errorCode); } if ($this->formHelper->hasErrors()) { return $this->getPageEdit($params); } // save settings $layoutIDFK = null; if ($this->formHelper->getFieldValue('base_page') !== null) { $stmntLayout = $this->cmsController->getDB()->prepare("SELECT layout_IDFK FROM page WHERE ID = ?"); $resLayout = $this->cmsController->getDB()->select($stmntLayout, array($this->formHelper->getFieldValue('base_page'))); if (count($resLayout) > 0) { $layoutIDFK = $resLayout[0]->layout_IDFK; } } try { $stmntUpdate = $this->cmsController->getDB()->prepare("\n\t\t\t\tINSERT INTO page SET\n\t\t\t\t\tID = ?, title = ?, language_codeFK = ?, description = ?, base_page_IDFK = ?, layout_IDFK = ?, inhert_rights = ?, creator_IDFK = ?, created = NOW(), role = ?, error_code = ?, uniqid = ?\n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\ttitle = ?, language_codeFK = ?, description = ?, base_page_IDFK = ?, layout_IDFK = ?, inhert_rights = ?, modifier_IDFK = ?, role = ?, error_code = ?, last_modified = NOW()\n\t\t\t"); $basePageParam = $this->formHelper->getFieldValue('base_page') != 0 ? $this->formHelper->getFieldValue('base_page') : null; $msgKey = 'updated'; $this->cmsController->getDB()->update($stmntUpdate, array($pageID, $this->formHelper->getFieldValue('title'), $this->formHelper->getFieldValue('language'), $this->formHelper->getFieldValue('description'), $basePageParam, $layoutIDFK, $this->formHelper->getFieldValue('inherit_rights'), $this->cmsController->getAuth()->getUserID(), $this->formHelper->getFieldValue('role'), $this->formHelper->getFieldValue('error_code'), uniqid(), $this->formHelper->getFieldValue('title'), $this->formHelper->getFieldValue('language'), $this->formHelper->getFieldValue('description'), $basePageParam, $layoutIDFK, $this->formHelper->getFieldValue('inherit_rights'), $this->cmsController->getAuth()->getUserID(), $this->formHelper->getFieldValue('role'), $this->formHelper->getFieldValue('error_code'))); if ($pageID === null) { $pageID = $this->cmsController->getDB()->lastInsertId(); $msgKey = 'created'; } // Route things $ssl = $this->formHelper->getFieldValue('ssl'); $sslRequired = 0; $sslForbidden = 0; if ($ssl === 'required') { $sslRequired = 1; } elseif ($ssl === 'forbidden') { $sslForbidden = 1; } $modID = null; if ($pageRole === CmsPage::ROLE_MODULE) { $modID = $this->formHelper->getFieldValue('module'); } if (in_array($pageRole, array(CmsPage::ROLE_STANDARD, CmsPage::ROLE_MODULE)) === true) { $formPattern = $this->formHelper->getFieldValue('route'); if (StringUtils::startsWith($formPattern, '/') === false) { $formPattern = '/' . $formPattern; } $stmntRouteUpdate = $this->cmsController->getDB()->prepare("\n\t\t\t\t\tINSERT INTO route SET\n\t\t\t\t\t\tID = ?, pattern = ?, page_IDFK = ?, ssl_required = ?, ssl_forbidden = ?, mod_IDFK = ?, regex = 0\n\t\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\t\tpattern = ?, page_IDFK = ?, ssl_required = ?, ssl_forbidden = ?, mod_IDFK = ?\n\t\t\t\t"); $this->cmsController->getDB()->update($stmntRouteUpdate, array($routeID, $formPattern, $pageID, $sslRequired, $sslForbidden, $modID, $formPattern, $pageID, $sslRequired, $sslForbidden, $modID)); } } catch (\Exception $e) { $this->formHelper->addError(null, $e->getMessage()); return $this->getPageEdit($params); } $this->setMessageKeyForNextPage($msgKey); RequestHandler::redirect($this->baseLink . '/page/' . $pageID); }
private function generateFormEditNavEntry() { $formHelper = new FormHelper(FormHelper::METHOD_POST); $routeModel = new RouteModel($this->cmsController->getDB()); $coreModel = new CoreModel($this->cmsController->getDB()); $optsRoute = array(); foreach ($routeModel->getAllRoutes() as $r) { $optsRoute[$r->ID] = $r->pattern; } $formHelper->addField('title', null, $formHelper::TYPE_STRING, true, array('missingError' => 'Please fill in an entry title')); $formHelper->addField('language', null, FormHelper::TYPE_OPTION, true, array('missingError' => 'Please choose a language', 'invalidError' => 'Please choose a valid language', 'options' => $coreModel->getLanguages())); $formHelper->addField('route', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please choose a valid route', 'options' => $optsRoute)); $formHelper->addField('external_link', null, $formHelper::TYPE_URL, false, array('invalidError' => 'Please fill in a valid URL')); return $formHelper; }