panel admina
[watermeloncms.git] / wtrmln / modules / admin / news.php
blob5a7e7e73d0427d833c59732ad394149bef19631e
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 News extends Controller
26 * lista newsów
29 function index()
31 Watermelon::$acceptMessages += array('news_deleted', 'news_posted', 'news_edited');
33 // pobieramy listę newsów
35 $newsList = model('news')->getNews();
37 // sprawdzamy, czy są jakieś newsy
39 if(!$newsList->exists())
41 echo $this->load->view('news_nonews');
42 return;
45 // skoro są, to je wyświetlamy
47 echo $this->load->view('news_table', array('newsList' => $newsList));
51 * formularz nowego newsa
54 function _new()
56 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('newnews', time() + 3600);
58 echo $this->load->view('news_new', array('tkey' => $tempKey, 'tvalue' => $tempKeyValue));
62 * stworzenie newsa
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']))
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, 'newnews'))
82 echo $this->load->view('error');
83 return;
86 // skoro tak, to wysyłamy
88 model('news')->post(htmlspecialchars($_POST['title']), $_POST['text'], $_SESSION['WTRMLN_UID']);
90 siteredirect('msg:news_posted/news');
94 * formularz edycji newsa
97 function edit()
99 $id = $this->url->segment(1);
101 $data = model('news')->GetData($id);
103 // sprawdzamy, czy w ogóle taki istnieje
105 if(!$data->exists())
107 echo $this->load->view('news_nosuch');
108 return;
111 // tworzymy klucz tymczasowy
113 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey($id);
115 echo $this->load->view('news_edit', array('data' => $data->to_obj(), 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
119 * submit: edycja newsa
122 function editSubmit()
124 $tempKey = $this->url->segment(1);
125 $tempKeyValue = $this->url->segment(2);
126 $newsID = $this->url->segment(3);
128 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
130 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, $newsID))
132 echo $this->load->view('error');
133 return;
136 // skoro tak, to edytujemy
138 model('news')->Edit($newsID, htmlspecialchars($_POST['title']), $_POST['text']);
140 siteredirect('msg:news_edited/news');
144 * (samo potwierdznie) usunięcia newsa
147 function delete()
149 $id = $this->url->segment(1);
151 $data = model('news')->GetData($id);
153 // sprawdzamy, czy w ogóle taki istnieje
155 if(!$data->exists())
157 echo $this->load->view('news_nosuch');
158 return;
161 // tworzymy klucz tymczasowy
163 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey($id);
165 echo $this->load->view('news_deletequestion', array('id' => $id, 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
169 * usuwanie newsa
172 function delete_ok()
174 $tempKey = $this->url->segment(1);
175 $tempKeyValue = $this->url->segment(2);
176 $newsID = $this->url->segment(3);
178 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
180 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, $newsID))
182 echo $this->load->view('error');
183 return;
186 // skoro tak, to usuwamy
188 model('news')->Delete($newsID);
190 siteredirect('msg:news_deleted/news');