-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNotesController.php
More file actions
137 lines (103 loc) · 3.52 KB
/
NotesController.php
File metadata and controls
137 lines (103 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Notes plugin for Wolf CMS <http://project79.net/projects/notes>
* Available on Github <https://github.com/project79>
*
* Simple notes for admin area.
*
* @author Dejan Andjelkovic <dejan79@gmail.com>
* @package Wolf
* @subpackage plugin.notes
* @version 0.0.9
* @licence http://www.gnu.org/licenses/gpl.html
* @copyright http://project79.net, 2010-2012
*/
if (!defined('IN_CMS')) { exit(); }
class NotesController extends PluginController {
private static function _checkPermission() {
AuthUser::load();
if ( ! AuthUser::isLoggedIn()) {
redirect(get_url('login'));
}
}
public function __construct() {
self::_checkPermission();
define('NOTES_VIEWS_BASE', 'notes/views');
$this->setLayout('backend');
$this->assignToLayout('sidebar', new View('../../plugins/notes/views/sidebar'));
}
// Take me to all notes
public function index() {
$this->tasks();
}
// Documentation
public function documentation() {
$this->display(NOTES_VIEWS_BASE.'/documentation');
}
// Add new note
public function createnewnote(){
$this->display(NOTES_VIEWS_BASE.'/newnote');
}
// List all notes
public function tasks() {
$notes = Notes::findAllFrom('Notes','id=id ORDER BY id DESC');
$this->display(NOTES_VIEWS_BASE.'/tasks', array('notes' => $notes));
}
public function update($id){
$notes = Notes::findByIdFrom('Notes', $id);
$this->display(NOTES_VIEWS_BASE.'/update', array('notes' => $notes));
}
public function shownote($id){
$notes = Notes::findByIdFrom('Notes', $id);
$this->display(NOTES_VIEWS_BASE.'/shownote', array('notes' => $notes));
}
// Delete note
public function delete($id) {
$notes = Notes::findByIdFrom('Notes', $id);
$notes->delete();
Flash::set('success', __('Your note was successfully deleted'));
redirect(get_url('plugin/notes/tasks'));
}
/*
* Create new note
*/
public function newnote(){
//
if (!isset($_POST['save'])) {
Flash::set('error', __('Could not save this note!'));
}
else {
$data = $_POST['notes'];
$notes = new Notes();
$notes->title = $data['title'];
$notes->filter_id = $data['filter_id'];
$notes->content = $data['content'];
$notes->created_on = date('Y-m-d');
$notes->save();
Flash::set('success', __('All went well.'));
redirect(get_url('plugin/notes/tasks'));
}
}
/*
* Update note
*/
public function updatenote(){
if (!isset($_POST['save'])) {
Flash::set('error', __('Could not update this note!'));
}
else {
$data = $_POST['notes'];
use_helper('Kses');
$data['id'] = kses(trim($data['id']), array());
$notes = new Notes();
$notes->id = $data['id'];
$notes->title = $data['title'];
$notes->filter_id = $data['filter_id'];
$notes->content = $data['content'];
$notes->updated_on = date('Y-m-d');
$notes->save();
Flash::set('success', __('All went well.'));
redirect(get_url('plugin/notes/tasks'));
}
}
}