2011-06-17 13:52:00 +01:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
class Notes extends CI_Controller {
|
|
|
|
|
|
2019-10-05 19:35:55 +01: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'); }
|
2021-01-11 15:22:48 +00:00
|
|
|
|
|
|
|
|
// Load language files
|
|
|
|
|
$this->lang->load('notes');
|
2019-10-05 19:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-17 13:52:00 +01:00
|
|
|
/* Displays all notes in a list */
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2011-07-22 01:08:47 +01:00
|
|
|
$this->load->model('note');
|
2026-01-09 13:17:56 +00:00
|
|
|
$filters = array(
|
|
|
|
|
'search' => $this->input->get('q', TRUE),
|
2026-01-09 16:13:57 +00:00
|
|
|
'category' => $this->input->get('category', TRUE),
|
|
|
|
|
'date_from' => $this->input->get('date_from', TRUE),
|
|
|
|
|
'date_to' => $this->input->get('date_to', TRUE)
|
2026-01-09 13:17:56 +00:00
|
|
|
);
|
|
|
|
|
$data['filters'] = $filters;
|
|
|
|
|
$data['categories'] = $this->note->list_categories();
|
|
|
|
|
$data['notes'] = $this->note->list_all(null, $filters);
|
2011-11-04 17:32:03 +00:00
|
|
|
$data['page_title'] = "Notes";
|
2019-05-13 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2011-11-04 17:32:03 +00:00
|
|
|
$this->load->view('notes/main');
|
2019-05-13 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/footer');
|
2011-06-17 13:52:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Provides function for adding notes to the system. */
|
|
|
|
|
function add() {
|
|
|
|
|
|
2011-07-22 01:08:47 +01:00
|
|
|
$this->load->model('note');
|
2026-01-09 13:17:56 +00:00
|
|
|
$data['categories'] = $this->note->list_categories();
|
2011-07-22 01:08:47 +01:00
|
|
|
|
2011-06-17 13:52:00 +01:00
|
|
|
$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 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2011-06-17 13:52:00 +01:00
|
|
|
$this->load->view('notes/add');
|
2019-05-13 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/footer');
|
2011-06-17 13:52:00 +01:00
|
|
|
}
|
|
|
|
|
else
|
2011-07-22 01:08:47 +01:00
|
|
|
{
|
|
|
|
|
$this->note->add();
|
2011-06-17 13:52:00 +01:00
|
|
|
|
|
|
|
|
redirect('notes');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* View Notes */
|
|
|
|
|
function view($id) {
|
2011-07-22 01:08:47 +01:00
|
|
|
$this->load->model('note');
|
|
|
|
|
|
|
|
|
|
$data['note'] = $this->note->view($id);
|
2011-06-17 13:52:00 +01:00
|
|
|
|
|
|
|
|
// Display
|
2011-11-04 17:32:03 +00:00
|
|
|
$data['page_title'] = "Note";
|
2019-05-13 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2011-11-04 17:32:03 +00:00
|
|
|
$this->load->view('notes/view');
|
2019-05-13 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/footer');
|
2011-06-17 13:52:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Edit Notes */
|
|
|
|
|
function edit($id) {
|
2011-07-22 01:08:47 +01:00
|
|
|
$this->load->model('note');
|
2011-06-17 13:52:00 +01:00
|
|
|
$data['id'] = $id;
|
2011-07-22 01:08:47 +01:00
|
|
|
|
|
|
|
|
$data['note'] = $this->note->view($id);
|
2026-01-09 13:17:56 +00:00
|
|
|
$data['categories'] = $this->note->list_categories();
|
2011-06-17 13:52:00 +01:00
|
|
|
|
|
|
|
|
$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 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2011-11-04 17:32:03 +00:00
|
|
|
$this->load->view('notes/edit');
|
2019-05-13 18:28:16 +01:00
|
|
|
$this->load->view('interface_assets/footer');
|
2011-06-17 13:52:00 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-22 01:08:47 +01:00
|
|
|
$this->note->edit();
|
|
|
|
|
|
2011-06-17 13:52:00 +01:00
|
|
|
redirect('notes');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delete Note */
|
2026-01-09 13:17:56 +00:00
|
|
|
function delete() {
|
|
|
|
|
// Enforce POST for destructive action
|
|
|
|
|
if (strtolower($this->input->method()) !== 'post') {
|
|
|
|
|
$this->session->set_flashdata('notice', $this->lang->line('general_word_warning') . ': invalid request method.');
|
|
|
|
|
redirect('notes');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = $this->input->post('id', TRUE);
|
|
|
|
|
if (empty($id)) {
|
|
|
|
|
$this->session->set_flashdata('notice', $this->lang->line('general_word_warning') . ': missing note id.');
|
|
|
|
|
redirect('notes');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 01:08:47 +01:00
|
|
|
$this->load->model('note');
|
|
|
|
|
$this->note->delete($id);
|
2026-01-09 13:17:56 +00:00
|
|
|
$this->session->set_flashdata('notice', $this->lang->line('admin_delete') ?: 'Deleted');
|
|
|
|
|
redirect('notes');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delete/Merge Category */
|
|
|
|
|
function delete_category() {
|
|
|
|
|
if (strtolower($this->input->method()) !== 'post') {
|
|
|
|
|
$this->session->set_flashdata('notice', $this->lang->line('general_word_warning') . ': invalid request method.');
|
|
|
|
|
redirect('notes');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$source = trim($this->input->post('source_category', TRUE));
|
|
|
|
|
$target = trim($this->input->post('target_category', TRUE));
|
|
|
|
|
|
|
|
|
|
if ($source === '') {
|
|
|
|
|
$this->session->set_flashdata('notice', $this->lang->line('general_word_warning') . ': missing source category.');
|
|
|
|
|
redirect('notes');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($target === '') {
|
|
|
|
|
$target = 'General';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($source === $target) {
|
|
|
|
|
$this->session->set_flashdata('notice', $this->lang->line('general_word_warning') . ': choose a different target category.');
|
|
|
|
|
redirect('notes');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->load->model('note');
|
|
|
|
|
$affected = $this->note->replace_category($source, $target);
|
|
|
|
|
$this->session->set_flashdata('notice', sprintf('%s → %s (%d)', $source, $target, $affected));
|
2011-06-17 13:52:00 +01:00
|
|
|
redirect('notes');
|
|
|
|
|
}
|
|
|
|
|
}
|