Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class pages extends Admin_Controller {
- public function __construct() {
- parent::__construct();
- $this->template->set_breadcrumb('Manage Pages', site_url('admin/pages'));
- $this->data['allEditors'] = $this->user_model->get_many_by('group', 2);
- }
- public function index() {
- switch ($this->input->post('submit')) {
- case 'New':
- redirect('admin/pages/add');
- break;
- case'Edit':
- if ($this->input->post('pageid')) {
- redirect('admin/pages/edit/' . $this->input->post('pageid'));
- }
- else {
- $this->session->set_flashdata('information', '<p class="red"><strong>Error - You must select a page to edit</strong></p>');
- redirect('admin/pages');
- }
- break;
- case'Delete':
- if ($this->input->post('pageid')) {
- redirect('admin/pages/delete/' . $this->input->post('pageid'));
- }
- else {
- $this->session->set_flashdata('information', '<p class="red"><strong>Error - You must select a page to delete</strong></p>');
- redirect('admin/pages');
- }
- default :
- $this->template->write_view('content', 'desktop/views/' . $this->data['viewbase'] . '/pages/index', $this->data);
- $this->template->render();
- break;
- }
- }
- /**
- * VIEW METHODS
- */
- public function add() {
- if (!isAdmin()) {
- $this->session->set_flashdata('information', '<p class="red">You do not have permission to perform this action</p>');
- redirect('/admin/pages');
- }
- $this->template->set_breadcrumb('Create Page', site_url('admin/pages/add'));
- $this->template->write_view('content', 'desktop/views/admin/pages/add', $this->data);
- $this->template->render();
- }
- public function edit() {
- $this->data['editPage'] = $this->page_model->get($this->uri->segment('4'));
- $this->template->set_breadcrumb('Edit Page: ' . $this->data['editPage']->title, site_url('admin/pages/edit/' . $this->data['editPage']->id));
- $this->template->write_view('content', 'desktop/views/' . $this->data['viewbase'] . '/pages/edit', $this->data);
- $this->template->render();
- }
- public function delete() {
- if (!isAdmin()) {
- $this->session->set_flashdata('information', '<p class="red">You do not have permission to perform this action</p>');
- redirect('/admin/pages');
- }
- $this->data['deletePage'] = $this->page_model->get($this->uri->segment('4'));
- $this->template->set_breadcrumb('Delete Page: ' . $this->data['deletePage']->title, site_url('admin/pages/delete'));
- $this->template->write_view('content', 'desktop/views/admin/pages/delete', $this->data);
- $this->template->render();
- }
- /**
- * ACTION METHODS
- */
- public function create() {
- if (!isAdmin()) {
- $this->session->set_flashdata('information', '<p class="red">You do not have permission to perform this action</p>');
- redirect('/admin/pages');
- }
- $rules = array(
- array('field' => 'title', 'label' => 'Page Title', 'rules' => 'trim|required|xss_clean|callback_title_check'),
- array('field' => 'content', 'label' => 'Page Content', 'rules' => 'trim|xss_clean'),
- );
- $this->form_validation->set_rules($rules);
- if ($this->form_validation->run()) {
- $newPage = array('title' => $this->input->post('title'), 'slug' => strtolower(url_title($this->input->post('title'), 'underscore')), 'content' => $this->input->post('content'), 'date' => date('Y-m-d H:i:s'), 'lastupdate' => date('Y-m-d H:i:s'), 'lastupdateby' => $this->session->userdata('id'));
- if ($this->input->post('index')) {
- foreach ($this->page_model->get_many_by(array('idx' => '1')) as $indexPage) {
- $this->page_model->update_by('id', $indexPage->id, array('idx' => 0));
- }
- $newPage['idx'] = 1;
- }
- if (sizeof($this->page_model->get_all()) == 0) {
- $newPage['idx'] = '1';
- }
- $newPageID = $this->page_model->insert($newPage);
- foreach ($this->input->post('editors') as $editor) {
- $newCrossReference = array('page' => $newPageID, 'user' => $editor);
- if (!$this->xref_model->insert($newCrossReference)) {
- exit(mysql_error());
- }
- }
- $this->session->set_flashdata('information', '<p class="green">The page was created successfully</p>');
- redirect(site_url('admin/pages'));
- }
- else {
- $this->message->set('error', explode("\n", trim(strip_tags(validation_errors()))));
- $this->template->write_view('content', 'desktop/views/admin/pages/add', $this->data);
- $this->template->render();
- }
- }
- public function update() {
- $rules = array(
- array('field' => 'title', 'label' => 'Page Title', 'rules' => 'trim|required|xss_clean|callback_update_title_check'),
- );
- $this->form_validation->set_rules($rules);
- if ($this->form_validation->run()) {
- if (isAdmin()) {
- $allEditors = array();
- foreach ($this->data['allEditors'] as $editor) {
- $allEditors[] = $editor->id;
- }
- $editorsPosted = $this->input->post('editors');
- $editorsNotPosted = array_diff($allEditors, $editorsPosted);
- if (sizeof($editorsNotPosted) > 0) {
- foreach ($editorsNotPosted as $editorNotPosted) {
- $this->xref_model->delete_by(array('user' => $editorNotPosted, 'page' => $this->input->post('pageid')));
- }
- }
- if (sizeof($editorsPosted) > 0) {
- foreach ($editorsPosted as $editorPosted) {
- $this->xref_model->insert(array('user' => $editorPosted, 'page' => $this->input->post('pageid')));
- }
- }
- }
- $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'));
- if (isAdmin()) {
- if ($this->input->post('index')) {
- foreach ($this->page_model->get_many_by(array('idx' => '1')) as $indexPage) {
- $this->page_model->update_by('id', $indexPage->id, array('idx' => 0));
- }
- $updatedPage['idx'] = 1;
- }
- }
- if (($this->input->post('published')) | ($this->page_model->get($this->input->post('pageid'))->idx == '1') | ($this->input->post('index'))) {
- $updatedPage['published'] = 1;
- }
- else {
- $updatedPage['published'] = 0;
- }
- $this->page_model->update_by('id', $this->input->post('pageid'), $updatedPage);
- $this->session->set_flashdata('information', '<p class="green">Your Changes To ' . $this->input->post('title') . ' were saved</p>');
- redirect(site_url('admin/pages'));
- }
- else {
- $this->data['editPage'] = $this->page_model->get($this->input->post('pageid'));
- $this->template->set_breadcrumb('Edit Page: ' . $this->data['editPage']->title, site_url('admin/pages/edit/' . $this->data['editPage']->id));
- $this->message->set('error', explode("\n", trim(strip_tags(validation_errors()))));
- $this->template->write_view('content', 'desktop/views/' . $this->data['viewbase'] . '/pages/edit', $this->data);
- $this->template->render();
- }
- }
- public function drop() {
- if (!isAdmin()) {
- $this->session->set_flashdata('information', '<p class="red">You do not have permission to perform this action</p>');
- redirect('/admin/pages');
- }
- if ($this->input->post('submit') == 'Yes') {
- $this->page_model->delete_by('id', $this->input->post('pageid'));
- $this->session->set_flashdata('information', '<p class="green">The page was successfully deleted</p>');
- }
- redirect('admin/pages');
- }
- public function title_check($title) {
- if ($this->page_model->get_by('title', $title)) {
- $this->form_validation->set_message('title_check', 'The page title "' . $title . '" is already in use.');
- return FALSE;
- }
- else {
- return TRUE;
- }
- }
- public function update_title_check($title) {
- if ((sizeof($this->page_model->get_many_by('title', $title)) - 1) >= 1) {
- $this->form_validation->set_message('update_title_check', 'The page title "' . $title . '" is already in use.');
- return FALSE;
- }
- else {
- return TRUE;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement