Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1.   public function update() {
  2.         $rules = array(
  3.             array('field' => 'title', 'label' => 'Page Title', 'rules' => 'trim|required|xss_clean|callback_update_title_check'),
  4.         );
  5.  
  6.         $this->form_validation->set_rules($rules);
  7.  
  8.         if ($this->form_validation->run()) {
  9.             if (isAdmin()) {
  10.                 $allEditors = array();
  11.                 foreach ($this->data['allEditors'] as $editor) {
  12.                     $allEditors[] = $editor->id;
  13.                 }
  14.                 $editorsPosted = $this->input->post('editors');
  15.                 if (sizeof($editorsPosted) > 0) {
  16.                     $editorsNotPosted = array_diff($allEditors, $editorsPosted);
  17.                     if (sizeof($editorsNotPosted) > 0) {
  18.                         foreach ($editorsNotPosted as $editorNotPosted) {
  19.                             $this->xref_model->delete_by(array('user' => $editorNotPosted, 'page' => $this->input->post('pageid')));
  20.                         }
  21.                     }
  22.  
  23.                     if (sizeof($editorsPosted) > 0) {
  24.                         foreach ($editorsPosted as $editorPosted) {
  25.                             $this->xref_model->insert(array('user' => $editorPosted, 'page' => $this->input->post('pageid')));
  26.                         }
  27.                     }
  28.                 }
  29.                 else {
  30.                     foreach ($editorsNotPosted as $editorNotPosted) {
  31.                         $this->xref_model->delete_by(array('page' => $this->input->post('pageid')));
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             $updatedPage = array('title' => $this->input->post('title'), 'slug' => url_title(strtolower($this->input->post('title')), 'underscore'), 'content' => $this->input->post('content'), 'lastupdate' => date('Y-m-d H:i:s'), 'lastupdateby' => $this->session->userdata('id'));
  37.  
  38.             if (isAdmin()) {
  39.                 if ($this->input->post('index')) {
  40.                     foreach ($this->page_model->get_many_by(array('idx' => '1')) as $indexPage) {
  41.                         $this->page_model->update_by('id', $indexPage->id, array('idx' => 0));
  42.                     }
  43.                     $updatedPage['idx'] = 1;
  44.                 }
  45.             }
  46.  
  47.             if (($this->input->post('published')) | ($this->page_model->get($this->input->post('pageid'))->idx == '1') | ($this->input->post('index'))) {
  48.                 $updatedPage['published'] = 1;
  49.             }
  50.             else {
  51.                 $updatedPage['published'] = 0;
  52.             }
  53.  
  54.             $this->page_model->update_by('id', $this->input->post('pageid'), $updatedPage);
  55.             $this->session->set_flashdata('information', '<p class="green">Your Changes To ' . $this->input->post('title') . ' were saved</p>');
  56.             redirect(site_url('admin/pages'));
  57.         }
  58.         else {
  59.  
  60.             $this->data['editPage'] = $this->page_model->get($this->input->post('pageid'));
  61.             $this->template->set_breadcrumb('Edit Page: ' . $this->data['editPage']->title, site_url('admin/pages/edit/' . $this->data['editPage']->id));
  62.             $this->message->set('error', explode("\n", trim(strip_tags(validation_errors()))));
  63.             $this->template->write_view('content', 'desktop/views/' . $this->data['viewbase'] . '/pages/edit', $this->data);
  64.             $this->template->render();
  65.         }
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement