Cloudlog/application/controllers/Notes.php

99 wiersze
2.3 KiB
PHP
Czysty Zwykły widok Historia

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Notes extends CI_Controller {
2019-10-05 18:35:55 +00:00
function __construct()
{
parent::__construct();
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
/* Displays all notes in a list */
public function index()
{
2011-07-22 00:08:47 +00:00
$this->load->model('note');
$data['notes'] = $this->note->list_all();
2011-11-04 17:32:03 +00:00
$data['page_title'] = "Notes";
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/header', $data);
2011-11-04 17:32:03 +00:00
$this->load->view('notes/main');
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/footer');
}
/* Provides function for adding notes to the system. */
function add() {
2011-07-22 00:08:47 +00:00
$this->load->model('note');
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Note Title', 'required');
$this->form_validation->set_rules('content', 'Content', 'required');
if ($this->form_validation->run() == FALSE)
{
2011-11-04 17:32:03 +00:00
$data['page_title'] = "Add Notes";
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/header', $data);
$this->load->view('notes/add');
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/footer');
}
else
2011-07-22 00:08:47 +00:00
{
$this->note->add();
redirect('notes');
}
}
/* View Notes */
function view($id) {
2011-07-22 00:08:47 +00:00
$this->load->model('note');
$data['note'] = $this->note->view($id);
// Display
2011-11-04 17:32:03 +00:00
$data['page_title'] = "Note";
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/header', $data);
2011-11-04 17:32:03 +00:00
$this->load->view('notes/view');
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/footer');
}
/* Edit Notes */
function edit($id) {
2011-07-22 00:08:47 +00:00
$this->load->model('note');
$data['id'] = $id;
2011-07-22 00:08:47 +00:00
$data['note'] = $this->note->view($id);
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Note Title', 'required');
$this->form_validation->set_rules('content', 'Content', 'required');
if ($this->form_validation->run() == FALSE)
{
2011-11-04 17:32:03 +00:00
$data['page_title'] = "Edit Note";
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/header', $data);
2011-11-04 17:32:03 +00:00
$this->load->view('notes/edit');
2019-05-13 17:28:16 +00:00
$this->load->view('interface_assets/footer');
}
else
{
2011-07-22 00:08:47 +00:00
$this->note->edit();
redirect('notes');
}
}
/* Delete Note */
function delete($id) {
2011-07-22 00:08:47 +00:00
$this->load->model('note');
$this->note->delete($id);
redirect('notes');
}
}