/** * Action edit */ public function action_edit() { // Get id from param, if there is nothing then throw to 404 $id = $this->request->param('key'); if (!$id) { throw HTTP_Exception::factory(404); } // Get wrapper, if there is nothing then throw to 404 $wrapper = Tbl::factory('wrappers')->where('id', '=', $id)->read(1); if (!$wrapper) { throw HTTP_Exception::factory(404); } // Get content from file and direct set to wrppaer $wrapper->content = Tpl::get_file($wrapper->segment, $this->settings->front_tpl_dir . '/wrapper'); $wrapper->delete_url = URL::site("{$this->settings->backend_name}/wrappers/delete/{$wrapper->id}", 'http'); // Save present segment $oldfile = "wrapper/{$wrapper->segment}"; // If there are post if ($this->request->post()) { // Set post to wrapper $wrapper->segment = $this->request->post('segment'); $wrapper->name = $this->request->post('name'); $wrapper->content_type = $this->request->post('content_type'); $wrapper->content = $this->request->post('content'); // Database transaction start Database::instance()->begin(); // Try try { // Update Tbl::factory('wrappers')->get($wrapper->id)->update(array('segment' => $this->request->post('segment'), 'name' => $this->request->post('name'), 'content_type' => $this->request->post('content_type'))); // New file $newfile = "wrapper/{$wrapper->segment}"; // rename file Cms_Helper::rename_file($oldfile, $newfile, $this->settings->front_tpl_dir); // Update file Cms_Helper::set_file($newfile, $this->settings->front_tpl_dir, $this->request->post('content')); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR, $e->getMessage()); } } /** * View */ $content_file = Tpl::get_file('edit', $this->settings->back_tpl_dir . '/wrappers', $this->partials); $this->content = Tpl::factory($content_file)->set('wrapper', $wrapper); }
/** * Action edit */ public function action_edit() { // Get id from param, if there is nothing then throw to 404 $id = $this->request->param('key'); if (!$id) { throw HTTP_Exception::factory(404); } // Get division, if there is nothing then throw to 404 $division = Tbl::factory('divisions')->get($id); if (!$division) { throw HTTP_Exception::factory(404); } // Get wrapper $wrapper = Tbl::factory('wrappers')->where('id', '=', $division->wrapper_id)->read(1); // Direct set to division $division->wrapper_segment = $wrapper->segment; $division->wrapper_name = $wrapper->name; $division->wrapper_content_type = $wrapper->content_type; // Get content from file and direct set to division $division->content = Tpl::get_file($division->segment, $this->settings->front_tpl_dir . '/division'); $division->delete_url = URL::site("{$this->settings->backend_name}/divisions/delete/{$division->id}", 'http'); // Save old name $oldname = $division->segment; // Get wrappers $wrappers = Tbl::factory('wrappers')->read()->as_array(); // If there are post if ($this->request->post()) { // Set post to division $division->wrapper_id = $this->request->post('wrapper_id'); $division->segment = $this->request->post('segment'); $division->name = $this->request->post('name'); $division->content = $this->request->post('content'); // Database transaction start Database::instance()->begin(); // Try try { // Update Tbl::factory('divisions')->get($division->id)->update(array('wrapper_id' => $this->request->post('wrapper_id'), 'segment' => $this->request->post('segment'), 'name' => $this->request->post('name'))); // New name $newname = $division->segment; // Rename items/division/directory name Cms_Helper::rename_dir($oldname, $newname, $this->settings->item_dir); // Rename images/division/directory name Cms_Helper::rename_dir($oldname, $newname, $this->settings->image_dir . '/item'); // rename theme/.../division/division file Cms_Helper::rename_file($oldname, $newname, $this->settings->front_tpl_dir . '/division'); // Update file Cms_Helper::set_file($newname, $this->settings->front_tpl_dir . '/division', $this->request->post('content')); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success')); // Redirect $this->redirect(URL::site("{$this->settings->backend_name}/divisions/edit/{$division->id}", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR, $e->getMessage()); } } /** * View */ $content_file = Tpl::get_file('edit', $this->settings->back_tpl_dir . '/divisions', $this->partials); $this->content = Tpl::factory($content_file)->set('division', $division)->set('wrappers', $wrappers); }
/** * Action edit */ public function action_edit() { // Get id from param, if there is nothing then throw to 404 $id = $this->request->param('key'); if (!$id) { throw HTTP_Exception::factory(404); } // Get email, if there is nothing then throw to 404 $email = Tbl::factory('emails')->get($id); if (!$email) { throw HTTP_Exception::factory(404); } // Get content from file and direct set to email $email->content = Tpl::get_file($email->segment, $this->settings->front_tpl_dir . '/email'); $email->delete_url = URL::site("{$this->settings->backend_name}/emails/delete/{$email->id}", 'http'); // Save old name $oldname = $email->segment; // If there are post if ($this->request->post()) { // Set post to email $email->segment = $this->request->post('segment'); $email->name = $this->request->post('name'); $email->description = $this->request->post('description'); $email->admin_name = $this->request->post('admin_name'); $email->admin_address = $this->request->post('admin_address'); $email->receive_subject = $this->request->post('receive_subject'); $email->user_name_field = $this->request->post('user_name_field'); $email->user_address_field = $this->request->post('user_address_field'); $email->content = $this->request->post('content'); // Database transaction start Database::instance()->begin(); // Try try { // Update Tbl::factory('emails')->get($email->id)->update(array('segment' => $this->request->post('segment'), 'name' => $this->request->post('name'), 'description' => $this->request->post('description'), 'admin_name' => $this->request->post('admin_name'), 'admin_address' => $this->request->post('admin_address'), 'receive_subject' => $this->request->post('receive_subject'), 'user_name_field' => $this->request->post('user_name_field'), 'user_address_field' => $this->request->post('user_address_field'))); // New name $newname = $email->segment; // rename email file Cms_Helper::rename_file($oldname, $newname, $this->settings->front_tpl_dir . '/email'); Cms_Helper::rename_file($oldname, $newname, $this->settings->front_tpl_dir . '/email/confirm'); Cms_Helper::rename_file($oldname, $newname, $this->settings->front_tpl_dir . '/email/receive'); // Update file Cms_Helper::set_file($newname, $this->settings->front_tpl_dir . '/email', $this->request->post('content')); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success')); // Redirect $this->redirect(URL::site("{$this->settings->backend_name}/emails/edit/{$email->id}", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR, $e->getMessage()); } } /** * View */ $this->partials['local_menu'] = Tpl::get_file('local_menu', $this->settings->back_tpl_dir); $content_file = Tpl::get_file('edit', $this->settings->back_tpl_dir . '/emails', $this->partials); $this->content = Tpl::factory($content_file)->set('local_menus', $this->local_menus)->set('email', $email); }
/** * Action edit */ public function action_edit() { // Get id from param, if there is nothing then throw to 404 $segment = strtolower($this->request->param('key')); if (!$segment) { throw HTTP_Exception::factory(404); } // Make part and get content from file and direct set to part $part = new stdClass(); $part->segment = strtolower($segment); $part->content = Tpl::get_file($segment, $this->settings->front_tpl_dir . '/part'); // If there is nothing then throw to 404 if ($part->content === FALSE) { throw HTTP_Exception::factory(404); } // Set delete url $part->delete_url = URL::site("{$this->settings->backend_name}/parts/delete/{$part->segment}", 'http'); // Save present segment $oldname = $part->segment; // If there are post if ($this->request->post()) { // Try try { // Validation $validation = Validation::factory($this->request->post())->rule('segment', 'not_empty')->rule('segment', 'max_length', array(':value', '200'))->rule('segment', 'regex', array(':value', '/^[a-z0-9_]+$/'))->rule('segment', function (Validation $array, $field, $value, $present_segment) { $segments = array_keys((array) Cms_Helper::get_dirfiles('part', $this->settings->front_tpl_dir)); if (in_array($value, $segments)) { if ($value !== $present_segment) { $array->error($field, 'uniquely'); } } }, array(':validation', ':field', ':value', $part->segment))->label('segment', __('Segment')); // Check validation if (!$validation->check()) { throw new Validation_Exception($validation); } // new name $newname = $this->request->post('segment'); // Update file これが先じゃないとダメ Cms_Helper::set_file($oldname, "{$this->settings->front_tpl_dir}/part", $this->request->post('content')); // rename file Cms_Helper::rename_file($oldname, $newname, "{$this->settings->front_tpl_dir}/part"); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success')); // Redirect $this->redirect("{$this->settings->backend_name}/parts/edit/{$newname}"); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Add error notice Notice::add(Notice::ERROR); } } /** * View */ $content_file = Tpl::get_file('edit', $this->settings->back_tpl_dir . '/parts', $this->partials); $this->content = Tpl::factory($content_file)->set('part', $part); }
/** * Action content */ public function action_content() { /** * Get item etc */ // <editor-fold defaultstate="collapsed" desc="Get item etc"> // Get division $division = Tbl::factory('divisions')->where('id', '=', $this->item->division_id)->read(1); // Direct set to division $this->item->division_segment = $division->segment; $this->item->division_name = $division->name; // Get content from file and direct set to $this->item $this->item->content = Tpl::get_file($this->item->segment, $this->settings->item_dir . '/' . $division->segment); // Save present segment $oldfile = $this->item->segment; // Get divisions $divisions = Tbl::factory('divisions')->read()->as_array(); // Get shapes $shapes = Cms_Helper::get_dirfiles('shape', $this->settings->front_tpl_dir); // </editor-fold> /** * If update */ // <editor-fold defaultstate="collapsed" desc="If update"> if ($this->request->post('update')) { // Set post to division $this->item->shape_segment = $this->request->post('shape_segment'); $this->item->content = $this->request->post('content'); // Database transaction start Database::instance()->begin(); // Try try { // Update Tbl::factory('items')->get($this->item->id)->update(array('shape_segment' => $this->request->post('shape_segment') ?: NULL)); // New file $newfile = $this->item->segment; // rename file Cms_Helper::rename_file($oldfile, $newfile, $this->settings->item_dir . '/' . $division->segment); // Update file Cms_Helper::set_file($newfile, $this->settings->item_dir . '/' . $division->segment, $this->request->post('content')); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR, $e->getMessage()); } } // </editor-fold> /** * View */ // <editor-fold defaultstate="collapsed" desc="View"> $this->partials['local_menu'] = Tpl::get_file('local_menu', $this->settings->back_tpl_dir); $content_file = Tpl::get_file('content', $this->settings->back_tpl_dir . '/items', $this->partials); $this->content = Tpl::factory($content_file)->set('item', $this->item)->set('divisions', $divisions)->set('shapes', $shapes)->set('post', $this->request->post()); // </editor-fold> }