dokończenie modułu download
[watermeloncms.git] / wtrmln / modules / admin / download.php
blob6e3f44beb59f9ec5a010cfa5e83d5168aa438246
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 Download extends Controller
26 * lista grup
29 function Index()
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');
42 return;
45 // skoro są, to je wyświetlamy
47 echo $this->load->view('download_groupstable', array('groups' => $groups));
51 * formularz nowej grupy
54 function newgroup()
56 list($tempKey, $tempKeyValue) = model('tempkeys')->MakeKey('newdownloadgroup', time() + 3600);
58 echo $this->load->view('download_newgroup', array('tkey' => $tempKey, 'tvalue' => $tempKeyValue));
62 * stworzenie grupy
65 function postgroup()
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');
75 return;
78 // sprawdzamy, czy z kluczem tymczasowym wszystko w porządku
80 if(!model('TempKeys')->CheckKey($tempKey, $tempKeyValue, 'newdownloadgroup'))
82 echo $this->load->view('error');
83 return;
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
96 function editgroup()
98 $id = $this->url->segment(1);
100 $data = model('download')->GroupData($id);
102 // sprawdzamy, czy w ogóle taka istnieje
104 if(!$data->exists())
106 echo $this->load->view('download_nosuchgroup');
107 return;
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');
132 return;
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
154 if(!$data->exists())
156 echo $this->load->view('download_nosuchgroup');
157 return;
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));
168 * usuwanie grupy
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');
182 return;
185 // skoro tak, to usuwamy
187 model('download')->DeleteGroup($ID);
189 siteredirect('msg:download_groupdeleted/download');
193 * lista plików w grupie
196 function Group()
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));
207 return;
210 echo $this->load->view('download_filestable', array('files' => $files, 'gid' => $group));
214 * formularz nowego pliku
217 function newfile()
219 $id = $this->url->segment(1);
221 $data = model('download')->GroupData($id);
223 // sprawdzamy, czy w ogóle taka istnieje
225 if(!$data->exists())
227 echo $this->load->view('download_nosuchgroup');
228 return;
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));
237 * stworzenie pliku
240 function postfile()
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');
251 return;
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');
259 return;
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
272 function editfile()
274 $id = $this->url->segment(1);
276 $data = model('download')->FileData($id);
278 // sprawdzamy, czy w ogóle taki istnieje
280 if(!$data->exists())
282 echo $this->load->view('download_nosuchfile');
283 return;
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');
313 return;
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
335 if(!$data->exists())
337 echo $this->load->view('download_nosuchfile');
338 return;
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));
349 * usuwanie pliku
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');
363 return;
366 // skoro tak, to usuwamy
368 $gid = model('download')->DeleteFile($ID);
370 siteredirect('msg:download_filedeleted/download/group/' . $gid);