2 /********************************************************************
6 Copyright 2009 Radosław Pietruszewski
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ********************************************************************/
23 class Pages
extends Controller
31 Watermelon
::$acceptMessages +
= array('pages_posted', 'pages_deleted', 'pages_edited');
33 // pobieramy listę stron
35 $pagesList = model('pages')->getPages();
37 // sprawdzamy, czy są jakieś strony
39 if(!$pagesList->exists())
41 echo $this->load
->view('pages_nopages');
45 // skoro są, to je wyświetlamy
47 echo $this->load
->view('pages_table', array('pagesList' => $pagesList));
51 * formularz nowej strony
56 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('newpage', time() +
3600);
58 echo $this->load
->view('pages_new', array('tkey' => $tempKey, 'tvalue' => $tempKeyValue));
67 $tempKey = $this->url
->segment(1);
68 $tempKeyValue = $this->url
->segment(2);
70 // sprawdzamy, czy zostały uzupełnione wszystkie pola.
72 if(empty($_POST['title']) OR empty($_POST['text']) OR empty($_POST['name']))
74 echo $this->load
->view('allfieldsneeded');
78 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
80 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'newpage'))
82 echo $this->load
->view('error');
86 // skoro tak, to wysyłamy
88 model('pages')->post(htmlspecialchars($_POST['title']), $_POST['name'], $_POST['text']);
90 redirect(site_url('msg:pages_posted/pages'));
94 * formularz edycji strony
99 $id = $this->url
->segment(1);
101 $data = model('pages')->GetDataByID($id);
103 // sprawdzamy, czy w ogóle taka istnieje
107 echo $this->load
->view('pages_nosuch');
111 // tworzymy klucz tymczasowy
113 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('edit:' . $id, time() +
3600);
115 echo $this->load
->view('pages_edit', array('data' => $data->to_obj(), 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
119 * submit: edycja strony
122 function editSubmit()
124 $tempKey = $this->url
->segment(1);
125 $tempKeyValue = $this->url
->segment(2);
126 $pageID = $this->url
->segment(3);
128 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
130 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'edit:' . $pageID))
132 echo $this->load
->view('error');
136 // skoro tak, to edytujemy
138 model('pages')->Edit($pageID, htmlspecialchars($_POST['title']), $_POST['name'], $_POST['text']);
140 redirect(site_url('msg:pages_edited/pages'));
144 * (samo potwierdznie) usunięcia strony
149 $id = $this->url
->segment(1);
151 $data = model('pages')->GetDataByID($id);
153 // sprawdzamy, czy w ogóle taka istnieje
157 echo $this->load
->view('pages_nosuch');
161 // tworzymy klucz tymczasowy
163 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('delete:' . $id);
165 echo $this->load
->view('pages_deletequestion', array('id' => $id, 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
174 $tempKey = $this->url
->segment(1);
175 $tempKeyValue = $this->url
->segment(2);
176 $pageID = $this->url
->segment(3);
178 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
180 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'delete:' . $pageID))
182 echo $this->load
->view('error');
186 // skoro tak, to usuwamy
188 model('pages')->Delete($pageID);
190 redirect(site_url('msg:pages_deleted/pages'));