/** * Edit template/css form (use Ajax) * * @param string $what case (template|css) * @param string $theme Theme name * @param integer $id Template ID * @return void */ public function edit($what, $theme, $id) { // load dictionaries $this->dict->get_wordarray(array('form', 'template')); // get object $mod = new Template_model(); $item = $mod->get_by_id($id, 'templates', 'id_theme, name, css'); // path to file $file = $what == 'template' ? PATH . 'themes/' . $theme . '/templates/' . $item->name . '.php' : PATH . 'themes/' . $theme . '/css/' . $item->css . '.css'; // build the form $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_theme, 'name' => 'id_theme'); $fields[] = array('label' => _FILE, 'type' => 'textarea', 'value' => htmlentities($this->replace(1, file_get_contents($file))), 'name' => 'code', 'extra' => 'class="editfile"', 'rule' => 'required', 'extra' => 'class="large"'); // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editor'); if ($e) { $this->editing($_POST, $file); } else { $this->notice($fields); } die; } // contents $view = new X4View_core('editor'); $view->title = _EDIT . ' ' . $item->name; // form builder $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"'); $view->js = ' <script> window.addEvent("domready", function() { $("code").addClass("code"); }); </script>'; $view->render(TRUE); }