partia duużych zmian
[watermeloncms.git] / wtrmln / modules / admin / pages.php
blob006e4ec6354c33073071c24cce5b8b4cd87c880d
1 <?php
2 /********************************************************************
4 Watermelon CMS
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
26 * lista stron
29 function Index()
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');
42 return;
45 // skoro są, to je wyświetlamy
47 echo $this->load->view('pages_table', array('pagesList' => $pagesList));
51 * formularz nowej strony
54 function _new()
56 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('newpage', time() + 3600);
58 echo $this->load->view('pages_new', array('tkey' => $tempKey, 'tvalue' => $tempKeyValue));
62 * stworzenie strony
65 function Post()
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');
75 return;
78 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
80 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'newpage'))
82 echo $this->load->view('error');
83 return;
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
97 function edit()
99 $id = $this->url->segment(1);
101 $data = model('pages')->GetDataByID($id);
103 // sprawdzamy, czy w ogóle taka istnieje
105 if(!$data->exists())
107 echo $this->load->view('pages_nosuch');
108 return;
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');
133 return;
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
147 function delete()
149 $id = $this->url->segment(1);
151 $data = model('pages')->GetDataByID($id);
153 // sprawdzamy, czy w ogóle taka istnieje
155 if(!$data->exists())
157 echo $this->load->view('pages_nosuch');
158 return;
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));
169 * usuwanie strony
172 function delete_ok()
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');
183 return;
186 // skoro tak, to usuwamy
188 model('pages')->Delete($pageID);
190 redirect(site_url('msg:pages_deleted/pages'));