public function processRouteEdit() { $this->abortIfUserHasNotRights('CMS_ROUTES_EDIT'); //$coreModel = new CoreModel($this->db); $pageModel = new PageModel($this->db); $routeModel = new RouteModel($this->db); $moduleModel = new ModuleModel($this->db); $pageOptions = array(); foreach ($pageModel->getAllPages() as $p) { $pageOptions[$p->ID] = $p->language_codeFK . ', ' . $p->title; } $routeOptions = array(); foreach ($routeModel->getAllRoutes() as $r) { if ($r->ID == $this->route->getParam(0)) { continue; } $routeOptions[$r->ID] = $r->pattern; } $moduleOptions = array(); foreach ($moduleModel->getModulesWithFrontendController() as $m) { $routeOptions[$m->ID] = $m->ID; } $this->formHelper = new FormHelper(FormHelper::METHOD_POST); $this->formHelper->addField('pattern', null, FormHelper::TYPE_STRING, true, array('missingError' => 'Please insert a pattern for this route')); $this->formHelper->addField('page', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid page', 'options' => $pageOptions)); $this->formHelper->addField('robots', null, FormHelper::TYPE_STRING, false); $this->formHelper->addField('regexp', null, FormHelper::TYPE_CHECKBOX); $this->formHelper->addField('route_typ', null, FormHelper::TYPE_OPTION); $this->formHelper->addField('redirect', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid page', 'options' => $pageOptions)); $this->formHelper->addField('module', null, FormHelper::TYPE_OPTION, false, array('invalidError' => 'Please select a valid module', 'options' => $moduleOptions)); if (!$this->formHelper->sent() || !$this->formHelper->validate()) { return $this->getRouteEdit(); } $patternStr = $this->formHelper->getFieldValue('pattern'); if (StringUtils::startsWith($patternStr, '/')) { $this->formHelper->addError(null, 'The route can not start with a slash (/)'); return $this->getRouteEdit(); } if (preg_match('@^[A-Za-z0-9\\-\\._/?#\\@&+=]+$@', $patternStr) === 0) { $this->formHelper->addError(null, 'The route should only have alphanumeric characters and -._/?#@&+= in it'); return $this->getRouteEdit(); } if ($patternStr === 'backend' || StringUtils::startsWith($patternStr, 'backend/') === true) { $this->formHelper->addError(null, 'The route should not start with "backend/". This URI node is reserved by the CMS'); return $this->getRouteEdit(); } // save settings $routeTyp = $this->formHelper->getFieldValue('route_typ'); $stmntUpdate = $this->db->prepare("\n\t\t\tINSERT INTO route\n\t\t\t\tSET ID = ?, pattern = ?, regex = ?, page_IDFK = ?, mod_IDFK = ?, robots = ?, redirect_route_IDFK = ?\n\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\tpattern = ?, regex = ?, page_IDFK = ?, mod_IDFK = ?, robots = ?, redirect_route_IDFK = ?\n\n\t\t"); $resUpdate = $this->db->update($stmntUpdate, array($this->route->getParam(0), '/' . $patternStr, $this->formHelper->getFieldValue('regexp'), $routeTyp == 1 ? $this->formHelper->getFieldValue('page') : null, $this->formHelper->getFieldValue('module') == 0 ? null : $this->formHelper->getFieldValue('module'), $this->formHelper->getFieldValue('robots'), $routeTyp == 2 ? $this->formHelper->getFieldValue('redirect') : null, '/' . $patternStr, $this->formHelper->getFieldValue('regexp'), $routeTyp == 1 ? $this->formHelper->getFieldValue('page') : null, $this->formHelper->getFieldValue('module') == 0 ? null : $this->formHelper->getFieldValue('module'), $this->formHelper->getFieldValue('robots'), $routeTyp == 2 ? $this->formHelper->getFieldValue('redirect') : null)); RequestHandler::redirect('/backend/routes'); }
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; }