/** * Edit a record */ protected function editSingleRecord() { /** * Prepare URL */ $page_get = 'page_fd' . $this->id; $strUrl = preg_replace('/\\?.*$/', '', urldecode(\Environment::get('request'))); $strUrlParams = ''; $blnQuery = false; foreach (preg_split('/&(amp;)?/', $_SERVER['QUERY_STRING']) as $fragment) { if (strlen($fragment)) { if (strncasecmp($fragment, $this->strDetailKey, strlen($this->strDetailKey)) !== 0 && strncasecmp($fragment, 'act', 3) !== 0 && strncasecmp($fragment, 'order_by', 8) !== 0 && strncasecmp($fragment, 'sort', 4) !== 0 && strncasecmp($fragment, $page_get, strlen($page_get)) !== 0) { $strUrlParams .= (!$blnQuery ? '' : '&') . $fragment; $blnQuery = true; } } } // Check record if ($this->intRecordId === null || intval($this->intRecordId) < 1) { unset($_GET[$this->strDetailKey]); unset($_GET['act']); $strRed = preg_replace(array('/\\/' . $this->strDetailKey . '\\/' . \Input::get($this->strDetailKey) . '/i', '/' . $this->strDetailKey . '=' . \Input::get($this->strDetailKey) . '/i'), array('', ''), $strUrl) . (strlen($strUrlParams) ? '?' . $strUrlParams : ''); \Controller::redirect($strRed); } // Check Owner and Alias $objOwner = \Database::getInstance()->prepare("SELECT fd_member,alias FROM tl_formdata WHERE id=?")->execute($this->intRecordId); $varOwner = $objOwner->fetchAssoc(); // Check access if (!empty($this->efg_list_access) && $this->efg_list_access != 'public') { if (!in_array(intval($varOwner['fd_member']), $this->arrAllowedOwnerIds)) { $strRed = preg_replace(array('/\\/' . $this->strDetailKey . '\\/' . \Input::get($this->strDetailKey) . '/i', '/' . $this->strDetailKey . '=' . \Input::get($this->strDetailKey) . '/i', '/act=edit/i'), array('', '', ''), $strUrl) . (strlen($strUrlParams) ? '?' . $strUrlParams : ''); \Controller::redirect($strRed); } } // Check edit access $blnEditAllowed = false; if ($this->efg_fe_edit_access == 'none') { $blnEditAllowed = false; } elseif ($this->efg_fe_edit_access == 'public') { $blnEditAllowed = true; } elseif (!empty($this->efg_fe_edit_access)) { if (in_array(intval($varOwner['fd_member']), $this->arrAllowedEditOwnerIds)) { $blnEditAllowed = true; } } if ($blnEditAllowed == false) { $strRed = preg_replace(array('/\\/' . $this->strDetailKey . '\\/' . \Input::get($this->strDetailKey) . '/i', '/' . $this->strDetailKey . '=' . \Input::get($this->strDetailKey) . '/i', '/act=edit/i'), array('', '', ''), $strUrl) . (strlen($strUrlParams) ? '?' . $strUrlParams : ''); \Controller::redirect($strRed); } $intListingId = 0; if ($this->id) { $intListingId = intval($this->id); } $strForm = ''; $intFormId = 0; // Fallback template if (!strlen($this->list_edit_layout)) { $this->list_edit_layout = 'edit_fd_default'; } // Get the form $objCheckRecord = \Database::getInstance()->prepare("SELECT form FROM tl_formdata WHERE id=?")->limit(1)->execute($this->intRecordId); if ($objCheckRecord->numRows == 1) { $strForm = $objCheckRecord->form; } // Get the ContentElement holding the form if (strlen($strForm)) { $objForm = \FormModel::findOneBy('title', $strForm); if ($objForm !== null) { $objFormElement = \ContentModel::findOneBy('form', $objForm->id); } } if ($objFormElement === null) { $this->log("Could not find a ContentElement containing the form \"" . $strForm . "\"", __METHOD__, 'ERROR'); $strRed = preg_replace(array('/\\/' . $this->strDetailKey . '\\/' . \Input::get($this->strDetailKey) . '/i', '/' . $this->strDetailKey . '=' . \Input::get($this->strDetailKey) . '/i', '/act=edit/i'), array('', '', ''), $strUrl) . (strlen($strUrlParams) ? '?' . $strUrlParams : ''); \Controller::redirect($strRed); } $this->Template = new \FrontendTemplate($this->list_edit_layout); $arrRecordFields = array_merge($this->arrBaseFields, $this->arrDetailFields); $strQuery = "SELECT "; $strWhere = ''; $strSep = ''; foreach ($arrRecordFields as $field) { if (in_array($field, $this->arrBaseFields)) { $strQuery .= $strSep . $field; $strSep = ', '; } if (!empty($this->arrDetailFields) && in_array($field, $this->arrDetailFields)) { $strQuery .= $strSep . '(SELECT value FROM tl_formdata_details WHERE ff_name="' . $field . '" AND pid=f.id ) AS `' . $field . '`'; $strSep = ', '; } } $strQuery .= " FROM " . $this->list_table . " f"; $strWhere .= (strlen($strWhere) ? " AND " : " WHERE ") . "id=?"; $strQuery .= $strWhere; $objRecord = \Database::getInstance()->prepare($strQuery)->limit(1)->execute($this->intRecordId); if ($objRecord->numRows < 1) { return; } $_SESSION['EFP']['LISTING_MOD']['id'] = $intListingId; if ($objFormElement !== null) { $this->Template->editform = $this->generateEditForm($objFormElement, $objRecord); } }
/** * Find related elements of a start element. * * @param string|null $type Name of the type. If empty current type is used. * * @return \ContentModel|null */ public function findRelatedElement($type = null) { $model = $this->model; // invalid call if ($model->bootstrap_parentId == '' && !$this->isTypeOf(static::TYPE_START)) { return null; } $options = array('order' => 'sorting'); if ($type === null) { $column = 'bootstrap_parentId'; $values[] = $model->id; } else { $column = array('bootstrap_parentId=? ', 'type=?'); $values[] = $model->id; $values[] = $this->getTypeName($type); } return \ContentModel::findOneBy($column, $values, $options); }
/** * try to find previous element of same type or specified type * * @param Model $model * @param null $type * * @return \Model|null */ public static function findPreviousElement(Model $model, $type = null) { if ($type === null) { $type = $model->getType(); } $column = array('pid=?', 'ptable=?', 'type=?', 'sorting<?'); $values = array($model->pid, $model->ptable, $model->getTypeName($type), $model->sorting); return \ContentModel::findOneBy($column, $values); }