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 Download
extends Controller
31 Watermelon
::addmsgs('download_groupdeleted', 'download_groupposted', 'download_groupedited');
33 // pobieramy listę grup
35 $groups = model('download')->GetGroups();
37 // sprawdzamy, czy są jakieś grupy
39 if(!$groups->exists())
41 echo $this->load
->view('download_nogroups');
45 // skoro są, to je wyświetlamy
47 echo $this->load
->view('download_groupstable', array('groups' => $groups));
51 * formularz nowej grupy
56 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('newdownloadgroup', time() +
3600);
58 echo $this->load
->view('download_newgroup', 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['name']))
74 echo $this->load
->view('allfieldsneeded');
78 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
80 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'newdownloadgroup'))
82 echo $this->load
->view('error');
86 // skoro tak, to wysyłamy
88 model('download')->postgroup(htmlspecialchars($_POST['name']), $_POST['description']);
89 siteredirect('msg:download_groupposted/download');
93 * formularz edycji grupy
98 $id = $this->url
->segment(1);
100 $data = model('download')->GroupData($id);
102 // sprawdzamy, czy w ogóle taka istnieje
106 echo $this->load
->view('download_nosuchgroup');
110 // tworzymy klucz tymczasowy
112 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('editdownloadgroup:' . $id, time() +
3600);
114 echo $this->load
->view('download_editgroup', array('data' => $data->to_obj(), 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
118 * submit: edycja grupy
121 function editGroupSubmit()
123 $tempKey = $this->url
->segment(1);
124 $tempKeyValue = $this->url
->segment(2);
125 $ID = $this->url
->segment(3);
127 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
129 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'editdownloadgroup:' . $ID))
131 echo $this->load
->view('error');
135 // skoro tak, to edytujemy
137 model('download')->EditGroup($ID, htmlspecialchars($_POST['name']), $_POST['description']);
139 siteredirect('msg:download_groupedited/download');
143 * (samo potwierdznie) usunięcia grupy
146 function deletegroup()
148 $id = $this->url
->segment(1);
150 $data = model('download')->GroupData($id);
152 // sprawdzamy, czy w ogóle taka istnieje
156 echo $this->load
->view('download_nosuchgroup');
160 // tworzymy klucz tymczasowy
162 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('deletedownloadgroup:' . $id);
164 echo $this->load
->view('download_groupdeletequestion', array('id' => $id, 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
171 function groupdelete_ok()
173 $tempKey = $this->url
->segment(1);
174 $tempKeyValue = $this->url
->segment(2);
175 $ID = $this->url
->segment(3);
177 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
179 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'deletedownloadgroup:' . $ID))
181 echo $this->load
->view('error');
185 // skoro tak, to usuwamy
187 model('download')->DeleteGroup($ID);
189 siteredirect('msg:download_groupdeleted/download');
193 * lista plików w grupie
198 Watermelon
::addmsgs('download_filedeleted', 'download_fileposted', 'download_fileedited');
200 $group = $this->url
->segment(1);
202 $files = model('download')->GetFiles($group);
204 if(!$files->exists())
206 echo $this->load
->view('download_nofiles', array('gid' => $group));
210 echo $this->load
->view('download_filestable', array('files' => $files, 'gid' => $group));
214 * formularz nowego pliku
219 $id = $this->url
->segment(1);
221 $data = model('download')->GroupData($id);
223 // sprawdzamy, czy w ogóle taka istnieje
227 echo $this->load
->view('download_nosuchgroup');
231 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('newdownloadfile:' . $id, time() +
3600);
233 echo $this->load
->view('download_filenew', array('tkey' => $tempKey, 'tvalue' => $tempKeyValue, 'id' => $id));
242 $tempKey = $this->url
->segment(1);
243 $tempKeyValue = $this->url
->segment(2);
244 $id = $this->url
->segment(3);
246 // sprawdzamy, czy zostały uzupełnione wszystkie pola.
248 if(empty($_POST['file']) ||
empty($_POST['link']) ||
empty($_POST['description']) ||
empty($_POST['size']) ||
empty($_POST['unit']))
250 echo $this->load
->view('allfieldsneeded');
254 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
256 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'newdownloadfile:' . $id))
258 echo $this->load
->view('error');
262 // skoro tak, to wysyłamy
264 model('download')->postfile(htmlspecialchars($_POST['file']), $_POST['link'], $_POST['description'], floatval($_POST['size']) . ' ' . $_POST['unit'], $id);
265 siteredirect('msg:download_fileposted/download/group/' . $id);
269 * formularz edycji pliku
274 $id = $this->url
->segment(1);
276 $data = model('download')->FileData($id);
278 // sprawdzamy, czy w ogóle taki istnieje
282 echo $this->load
->view('download_nosuchfile');
286 // tworzymy klucz tymczasowy
288 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('editdownloadfile:' . $id, time() +
3600);
290 $data = $data->to_obj();
291 $data->size
= explode(' ', $data->size
);
292 $data->rsize
= $data->size
[0];
293 $data->unit
= $data->size
[1];
295 echo $this->load
->view('download_fileedit', array('data' => $data, 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
299 * submit: edycja pliku
302 function editfile_submit()
304 $tempKey = $this->url
->segment(1);
305 $tempKeyValue = $this->url
->segment(2);
306 $ID = $this->url
->segment(3);
308 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
310 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'editdownloadfile:' . $ID))
312 echo $this->load
->view('error');
316 // skoro tak, to edytujemy
318 $gid = model('download')->editfile(htmlspecialchars($_POST['file']), $_POST['link'], $_POST['description'], floatval($_POST['size']) . ' ' . $_POST['unit'], $ID);
320 siteredirect('msg:download_fileedited/download/group/' . $gid);
324 * (samo potwierdznie) usunięcia pliku
327 function deletefile()
329 $id = $this->url
->segment(1);
331 $data = model('download')->FileData($id);
333 // sprawdzamy, czy w ogóle taki istnieje
337 echo $this->load
->view('download_nosuchfile');
341 // tworzymy klucz tymczasowy
343 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('deletedownloadfile:' . $id);
345 echo $this->load
->view('download_filedeletequestion', array('id' => $id, 'tkey' => $tempKey, 'tvalue' => $tempKeyValue));
352 function filedelete_ok()
354 $tempKey = $this->url
->segment(1);
355 $tempKeyValue = $this->url
->segment(2);
356 $ID = $this->url
->segment(3);
358 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
360 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'deletedownloadfile:' . $ID))
362 echo $this->load
->view('error');
366 // skoro tak, to usuwamy
368 $gid = model('download')->DeleteFile($ID);
370 siteredirect('msg:download_filedeleted/download/group/' . $gid);