1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * phpGroupWare - Preferences - categories * |
---|
4 | * http://www.phpgroupware.org * |
---|
5 | * Written by Bettina Gille [ceb@phpgroupware.org] * |
---|
6 | * ----------------------------------------------- * |
---|
7 | * Copyright 2000 - 2003 Free Software Foundation, Inc * |
---|
8 | * * |
---|
9 | * This program is free software; you can redistribute it and/or modify it * |
---|
10 | * under the terms of the GNU General Public License as published by the * |
---|
11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
12 | * option) any later version. * |
---|
13 | \**************************************************************************/ |
---|
14 | |
---|
15 | class uicategories |
---|
16 | { |
---|
17 | var $bo; |
---|
18 | |
---|
19 | var $start; |
---|
20 | var $query; |
---|
21 | var $sort; |
---|
22 | var $order; |
---|
23 | var $cat_id; |
---|
24 | |
---|
25 | var $cats_app; |
---|
26 | |
---|
27 | var $public_functions = array |
---|
28 | ( |
---|
29 | 'index' => True, |
---|
30 | 'add' => True, |
---|
31 | 'edit' => True, |
---|
32 | 'delete' => True |
---|
33 | ); |
---|
34 | |
---|
35 | function uicategories() |
---|
36 | { |
---|
37 | $cats_app = get_var('cats_app',array('GET','POST')); |
---|
38 | |
---|
39 | $this->bo = CreateObject('preferences.bocategories',$cats_app); |
---|
40 | $this->nextmatchs = CreateObject('phpgwapi.nextmatchs'); |
---|
41 | $this->account = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
42 | $this->user = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
43 | |
---|
44 | $this->start = $this->bo->start; |
---|
45 | $this->query = $this->bo->query; |
---|
46 | $this->sort = $this->bo->sort; |
---|
47 | $this->order = $this->bo->order; |
---|
48 | } |
---|
49 | |
---|
50 | function save_sessiondata($cats_app) |
---|
51 | { |
---|
52 | $data = array |
---|
53 | ( |
---|
54 | 'start' => $this->start, |
---|
55 | 'query' => $this->query, |
---|
56 | 'sort' => $this->sort, |
---|
57 | 'order' => $this->order |
---|
58 | ); |
---|
59 | $this->bo->save_sessiondata($data,$cats_app); |
---|
60 | } |
---|
61 | |
---|
62 | function set_langs() |
---|
63 | { |
---|
64 | $GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']); |
---|
65 | $GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']); |
---|
66 | $GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']); |
---|
67 | $GLOBALS['phpgw']->template->set_var('lang_access',lang('Private')); |
---|
68 | $GLOBALS['phpgw']->template->set_var('lang_save',lang('Save')); |
---|
69 | $GLOBALS['phpgw']->template->set_var('user_name',$this->user); |
---|
70 | $GLOBALS['phpgw']->template->set_var('lang_search',lang('Search')); |
---|
71 | $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel')); |
---|
72 | $GLOBALS['phpgw']->template->set_var('lang_sub',lang('Add sub')); |
---|
73 | $GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit')); |
---|
74 | $GLOBALS['phpgw']->template->set_var('lang_delete',lang('Delete')); |
---|
75 | $GLOBALS['phpgw']->template->set_var('lang_parent',lang('Parent category')); |
---|
76 | $GLOBALS['phpgw']->template->set_var('lang_none',lang('None')); |
---|
77 | $GLOBALS['phpgw']->template->set_var('lang_name',lang('Name')); |
---|
78 | $GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description')); |
---|
79 | $GLOBALS['phpgw']->template->set_var('lang_add',lang('Add')); |
---|
80 | $GLOBALS['phpgw']->template->set_var('lang_reset',lang('Clear Form')); |
---|
81 | } |
---|
82 | |
---|
83 | function cat_data($edata,$data) |
---|
84 | { |
---|
85 | $edata_count = count($edata); |
---|
86 | for ($j=0;$j<$edata_count;++$j) |
---|
87 | { |
---|
88 | $td_data .= '<td>' . $data[$edata[$j]] . '</td>' . "\n"; |
---|
89 | } |
---|
90 | return $td_data; |
---|
91 | } |
---|
92 | |
---|
93 | function index() |
---|
94 | { |
---|
95 | $cats_app = get_var('cats_app',array('GET','POST')); |
---|
96 | $extra = get_var('extra',array('GET','POST')); |
---|
97 | $global_cats = get_var('global_cats',array('GET','POST')); |
---|
98 | $cats_level = get_var('cats_level',array('GET','POST')); |
---|
99 | |
---|
100 | $this->bo->query = get_var('query',array('GET','POST')); |
---|
101 | $this->bo->order = get_var('order',array('GET','POST')); |
---|
102 | $this->bo->start = get_var('start',array('GET','POST')); |
---|
103 | $this->bo->sort = get_var('sort',array('GET','POST')); |
---|
104 | $this->query = get_var('query',array('GET','POST')); |
---|
105 | $this->order = get_var('order',array('GET','POST')); |
---|
106 | $this->start = get_var('start',array('GET','POST')); |
---|
107 | $this->sort = get_var('sort',array('GET','POST')); |
---|
108 | $GLOBALS['query'] = get_var('query',array('GET','POST')); |
---|
109 | |
---|
110 | $link_data = array |
---|
111 | ( |
---|
112 | 'menuaction' => 'preferences.uicategories.index', |
---|
113 | 'cats_app' => $cats_app, |
---|
114 | 'extra' => $extra, |
---|
115 | 'global_cats' => $global_cats, |
---|
116 | 'cats_level' => $cats_level |
---|
117 | ); |
---|
118 | |
---|
119 | if($extra) |
---|
120 | { |
---|
121 | $edata = explode(',',$extra); |
---|
122 | } |
---|
123 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps'][$cats_app]['title']. |
---|
124 | ' '.lang('categories for').': '.$this->user; |
---|
125 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
126 | echo parse_navbar(); |
---|
127 | |
---|
128 | $GLOBALS['phpgw']->template->set_file(array( |
---|
129 | 'cat_list_t' => 'listcats.tpl', |
---|
130 | 'data_column' => 'listcats.tpl' |
---|
131 | )); |
---|
132 | $GLOBALS['phpgw']->template->set_block('cat_list_t','data_column','column'); |
---|
133 | $GLOBALS['phpgw']->template->set_block('cat_list_t','cat_list','list'); |
---|
134 | |
---|
135 | $this->set_langs(); |
---|
136 | |
---|
137 | $GLOBALS['phpgw']->template->set_var('title_categories',lang('categories for')); |
---|
138 | $GLOBALS['phpgw']->template->set_var('lang_app',lang($cats_app)); |
---|
139 | $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
140 | $GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/preferences/index.php')); |
---|
141 | |
---|
142 | if(!$this->start) |
---|
143 | { |
---|
144 | $this->start = 0; |
---|
145 | } |
---|
146 | |
---|
147 | if(!$global_cats) |
---|
148 | { |
---|
149 | $global_cats = False; |
---|
150 | } |
---|
151 | |
---|
152 | $cats = $this->bo->get_list($global_cats); |
---|
153 | |
---|
154 | //--------------------------------- nextmatch -------------------------------------------- |
---|
155 | |
---|
156 | $left = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,$link_data); |
---|
157 | $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,$link_data); |
---|
158 | $GLOBALS['phpgw']->template->set_var('left',$left); |
---|
159 | $GLOBALS['phpgw']->template->set_var('right',$right); |
---|
160 | |
---|
161 | $GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start)); |
---|
162 | |
---|
163 | // ------------------------------ end nextmatch ------------------------------------------ |
---|
164 | |
---|
165 | //------------------- list header variable template-declarations ------------------------- |
---|
166 | |
---|
167 | $GLOBALS['phpgw']->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data)); |
---|
168 | $GLOBALS['phpgw']->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data)); |
---|
169 | |
---|
170 | if (is_array($edata)) |
---|
171 | { |
---|
172 | $edata_count = count($edata); |
---|
173 | for($i=0;$i<$edata_count;++$i) |
---|
174 | { |
---|
175 | $GLOBALS['phpgw']->template->set_var('th_data','<td bgcolor="' . $GLOBALS['phpgw_info']['theme']['th_bg'] . '">' . lang($edata[$i]) . '</td>'); |
---|
176 | $GLOBALS['phpgw']->template->fp('column','data_column',True); |
---|
177 | } |
---|
178 | } |
---|
179 | else |
---|
180 | { |
---|
181 | $GLOBALS['phpgw']->template->set_var('th_data',''); |
---|
182 | } |
---|
183 | |
---|
184 | // -------------------------- end header declaration -------------------------------------- |
---|
185 | $cats_count = count($cats); |
---|
186 | for ($i=0;$i<$cats_count;++$i) |
---|
187 | { |
---|
188 | $this->nextmatchs->template_alternate_row_color($GLOBALS['phpgw']->template); |
---|
189 | |
---|
190 | if ($cats[$i]['app_name'] == 'phpgw') |
---|
191 | { |
---|
192 | $appendix = '<' . lang('Global') . '>'; |
---|
193 | } |
---|
194 | elseif ($cats[$i]['owner'] == '-1') |
---|
195 | { |
---|
196 | $appendix = '<' . lang('Global') . ' ' . $GLOBALS['phpgw_info']['apps'][$cats_app]['title'] . '>'; |
---|
197 | } |
---|
198 | else |
---|
199 | { |
---|
200 | $appendix = ''; |
---|
201 | } |
---|
202 | |
---|
203 | $level = $cats[$i]['level']; |
---|
204 | |
---|
205 | if ($level > 0) |
---|
206 | { |
---|
207 | $space = ' '; |
---|
208 | $spaceset = str_repeat($space,$level); |
---|
209 | $name = $spaceset . $GLOBALS['phpgw']->strip_html($cats[$i]['name']) . $appendix; |
---|
210 | } |
---|
211 | |
---|
212 | $descr = $GLOBALS['phpgw']->strip_html($cats[$i]['description']); |
---|
213 | if (!$descr) { $descr = ' '; } |
---|
214 | |
---|
215 | if (is_array($edata)) |
---|
216 | { |
---|
217 | $data = unserialize($cats[$i]['data']); |
---|
218 | if (! is_array($data)) |
---|
219 | { |
---|
220 | $holder = '<td> </td>' . "\n"; |
---|
221 | $placeholder = str_repeat($holder,count($edata)); |
---|
222 | $GLOBALS['phpgw']->template->set_var('td_data',$placeholder); |
---|
223 | } |
---|
224 | else |
---|
225 | { |
---|
226 | $GLOBALS['phpgw']->template->set_var('td_data',$this->cat_data($edata,$data)); |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | if ($level == 0) |
---|
231 | { |
---|
232 | $name = '<font color="FF0000"><b>' . $GLOBALS['phpgw']->strip_html($cats[$i]['name']) . '</b></font>' . $appendix; |
---|
233 | $descr = '<font color="FF0000"><b>' . $descr . '</b></font>'; |
---|
234 | } |
---|
235 | |
---|
236 | $GLOBALS['phpgw']->template->set_var(array( |
---|
237 | 'name' => $name, |
---|
238 | 'descr' => $descr |
---|
239 | )); |
---|
240 | |
---|
241 | $GLOBALS['phpgw']->template->set_var('app_url',$GLOBALS['phpgw']->link('/' . $cats_app . '/index.php','cat_id=' . $cats[$i]['id'])); |
---|
242 | |
---|
243 | if ($cats_level || ($level == 0)) |
---|
244 | { |
---|
245 | if ($cats[$i]['owner'] == $this->account || $cats[$i]['app_name'] == 'phpgw') |
---|
246 | { |
---|
247 | $link_data['menuaction'] = 'preferences.uicategories.add'; |
---|
248 | $link_data['cat_parent'] = $cats[$i]['id']; |
---|
249 | $GLOBALS['phpgw']->template->set_var('add_sub',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
250 | $GLOBALS['phpgw']->template->set_var('lang_sub_entry',lang('Add sub')); |
---|
251 | } |
---|
252 | } |
---|
253 | else |
---|
254 | { |
---|
255 | $GLOBALS['phpgw']->template->set_var('add_sub',''); |
---|
256 | $GLOBALS['phpgw']->template->set_var('lang_sub_entry',' '); |
---|
257 | } |
---|
258 | |
---|
259 | $link_data['cat_id'] = $cats[$i]['id']; |
---|
260 | |
---|
261 | if ($cats[$i]['owner'] == $GLOBALS['phpgw']->accounts->id2name($this->account) && $cats[$i]['app_name'] != 'phpgw') |
---|
262 | { |
---|
263 | $link_data['menuaction'] = 'preferences.uicategories.edit'; |
---|
264 | $GLOBALS['phpgw']->template->set_var('edit',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
265 | $GLOBALS['phpgw']->template->set_var('lang_edit_entry',lang('Edit')); |
---|
266 | |
---|
267 | $link_data['menuaction'] = 'preferences.uicategories.delete'; |
---|
268 | $GLOBALS['phpgw']->template->set_var('delete',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
269 | $GLOBALS['phpgw']->template->set_var('lang_delete_entry',lang('Delete')); |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | $GLOBALS['phpgw']->template->set_var('edit',''); |
---|
274 | $GLOBALS['phpgw']->template->set_var('lang_edit_entry',' '); |
---|
275 | |
---|
276 | $GLOBALS['phpgw']->template->set_var('delete',''); |
---|
277 | $GLOBALS['phpgw']->template->set_var('lang_delete_entry',' '); |
---|
278 | } |
---|
279 | $GLOBALS['phpgw']->template->fp('list','cat_list',True); |
---|
280 | } |
---|
281 | $link_data['menuaction'] = 'preferences.uicategories.add'; |
---|
282 | $GLOBALS['phpgw']->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
283 | $this->save_sessiondata($cats_app); |
---|
284 | |
---|
285 | $GLOBALS['phpgw']->template->pfp('out','cat_list_t',True); |
---|
286 | } |
---|
287 | |
---|
288 | function add() |
---|
289 | { |
---|
290 | $cats_app = get_var('cats_app',array('GET','POST')); |
---|
291 | $extra = get_var('extra',array('GET','POST')); |
---|
292 | $global_cats = get_var('global_cats',array('GET','POST')); |
---|
293 | $cats_level = get_var('cats_level',array('GET','POST')); |
---|
294 | |
---|
295 | $link_data = array |
---|
296 | ( |
---|
297 | 'menuaction' => 'preferences.uicategories.add', |
---|
298 | 'cats_app' => $cats_app, |
---|
299 | 'extra' => $extra, |
---|
300 | 'global_cats' => $global_cats, |
---|
301 | 'cats_level' => $cats_level |
---|
302 | ); |
---|
303 | |
---|
304 | $new_parent = $_POST['new_parent']; |
---|
305 | $cat_parent = get_var('cat_parent',array('POST','GET')); |
---|
306 | $cat_name = $_POST['cat_name']; |
---|
307 | $cat_description = $_POST['cat_description']; |
---|
308 | $cat_data = $_POST['cat_data']; |
---|
309 | $cat_access = $_POST['cat_access']; |
---|
310 | |
---|
311 | $GLOBALS['phpgw']->template->set_file(array('form' => 'category_form.tpl')); |
---|
312 | $GLOBALS['phpgw']->template->set_block('form','data_row','row'); |
---|
313 | $GLOBALS['phpgw']->template->set_block('form','add','addhandle'); |
---|
314 | $GLOBALS['phpgw']->template->set_block('form','edit','edithandle'); |
---|
315 | |
---|
316 | $this->set_langs(); |
---|
317 | |
---|
318 | if ($new_parent) |
---|
319 | { |
---|
320 | $cat_parent = $new_parent; |
---|
321 | } |
---|
322 | |
---|
323 | if (!$global_cats) |
---|
324 | { |
---|
325 | $global_cats = False; |
---|
326 | } |
---|
327 | |
---|
328 | if ($_POST['save']) |
---|
329 | { |
---|
330 | $data = serialize($cat_data); |
---|
331 | |
---|
332 | $values = array |
---|
333 | ( |
---|
334 | 'parent' => $cat_parent, |
---|
335 | 'descr' => $cat_description, |
---|
336 | 'name' => $cat_name, |
---|
337 | 'access' => $cat_access, |
---|
338 | 'data' => $data |
---|
339 | ); |
---|
340 | |
---|
341 | $error = $this->bo->check_values($values); |
---|
342 | if (is_array($error)) |
---|
343 | { |
---|
344 | $GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error)); |
---|
345 | } |
---|
346 | else |
---|
347 | { |
---|
348 | $this->bo->save_cat($values); |
---|
349 | return $this->index(); |
---|
350 | //$GLOBALS['phpgw']->template->set_var('message',lang('Category %1 has been added !', $cat_name)); |
---|
351 | } |
---|
352 | } |
---|
353 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Add %1 category for', |
---|
354 | $GLOBALS['phpgw_info']['apps'][$cats_app]['title']).': '.$this->user; |
---|
355 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
356 | echo parse_navbar(); |
---|
357 | |
---|
358 | $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
359 | |
---|
360 | if ($cats_level) |
---|
361 | { |
---|
362 | $type = 'all'; |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | $type = 'mains'; |
---|
367 | } |
---|
368 | |
---|
369 | $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->cats->formated_list('select',$type,$cat_parent,$global_cats)); |
---|
370 | $GLOBALS['phpgw']->template->set_var('cat_name',$cat_name); |
---|
371 | $GLOBALS['phpgw']->template->set_var('cat_description',$cat_description); |
---|
372 | |
---|
373 | $GLOBALS['phpgw']->template->set_var('access','<input type="checkbox" name="cat_access" value="True"' |
---|
374 | . ($cat_access == True ?' checked':'') . '>'); |
---|
375 | |
---|
376 | if ($extra) |
---|
377 | { |
---|
378 | $edata = explode(',',$extra); |
---|
379 | $edata_count = count($edata); |
---|
380 | for($i=0;$i<$edata_count;++$i) |
---|
381 | { |
---|
382 | $GLOBALS['phpgw']->template->set_var('tr_color',$GLOBALS['phpgw']->nextmatchs->alternate_row_color()); |
---|
383 | $GLOBALS['phpgw']->template->set_var('td_data','<input name="cat_data[' . $edata[$i] . ']" size="50" value="' . $cat_data[$edata[$i]] . '">'); |
---|
384 | $GLOBALS['phpgw']->template->set_var('lang_data',lang($edata[$i])); |
---|
385 | $GLOBALS['phpgw']->template->fp('row','data_row',True); |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | $link_data['menuaction'] = 'preferences.uicategories.index'; |
---|
390 | $GLOBALS['phpgw']->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
391 | $GLOBALS['phpgw']->template->set_var('edithandle',''); |
---|
392 | $GLOBALS['phpgw']->template->set_var('addhandle',''); |
---|
393 | $GLOBALS['phpgw']->template->pfp('out','form'); |
---|
394 | $GLOBALS['phpgw']->template->pfp('addhandle','add'); |
---|
395 | } |
---|
396 | |
---|
397 | function edit() |
---|
398 | { |
---|
399 | $cats_app = get_var('cats_app',array('GET','POST')); |
---|
400 | $extra = get_var('extra',array('GET','POST')); |
---|
401 | $global_cats = get_var('global_cats',array('GET','POST')); |
---|
402 | $cats_level = get_var('cats_level',array('GET','POST')); |
---|
403 | $cat_id = get_var('cat_id',array('GET','POST')); |
---|
404 | |
---|
405 | $link_data = array |
---|
406 | ( |
---|
407 | 'menuaction' => 'preferences.uicategories.index', |
---|
408 | 'cats_app' => $cats_app, |
---|
409 | 'extra' => $extra, |
---|
410 | 'global_cats' => $global_cats, |
---|
411 | 'cats_level' => $cats_level, |
---|
412 | 'cat_id' => $cat_id |
---|
413 | ); |
---|
414 | |
---|
415 | if (!$cat_id) |
---|
416 | { |
---|
417 | $GLOBALS['phpgw']->link_redirect('/index.php',$link_data); |
---|
418 | } |
---|
419 | |
---|
420 | $new_parent = $_POST['new_parent']; |
---|
421 | $cat_parent = $_POST['cat_parent']; |
---|
422 | $cat_name = $_POST['cat_name']; |
---|
423 | $cat_description = $_POST['cat_description']; |
---|
424 | $cat_data = $_POST['cat_data']; |
---|
425 | $cat_access = $_POST['cat_access']; |
---|
426 | $old_parent = $_POST['old_parent']; |
---|
427 | |
---|
428 | $GLOBALS['phpgw']->template->set_file(array('form' => 'category_form.tpl')); |
---|
429 | $GLOBALS['phpgw']->template->set_block('form','data_row','row'); |
---|
430 | $GLOBALS['phpgw']->template->set_block('form','add','addhandle'); |
---|
431 | $GLOBALS['phpgw']->template->set_block('form','edit','edithandle'); |
---|
432 | |
---|
433 | $this->set_langs(); |
---|
434 | $GLOBALS['phpgw']->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
435 | |
---|
436 | if ($new_parent) |
---|
437 | { |
---|
438 | $cat_parent = $new_parent; |
---|
439 | } |
---|
440 | |
---|
441 | if (!$global_cats) |
---|
442 | { |
---|
443 | $global_cats = False; |
---|
444 | } |
---|
445 | |
---|
446 | if ($_POST['save']) |
---|
447 | { |
---|
448 | $data = serialize($cat_data); |
---|
449 | |
---|
450 | $values = array |
---|
451 | ( |
---|
452 | 'id' => $cat_id, |
---|
453 | 'parent' => $cat_parent, |
---|
454 | 'descr' => $cat_description, |
---|
455 | 'name' => $cat_name, |
---|
456 | 'access' => $cat_access, |
---|
457 | 'data' => $data, |
---|
458 | 'old_parent' => $old_parent |
---|
459 | ); |
---|
460 | |
---|
461 | $error = $this->bo->check_values($values); |
---|
462 | if (is_array($error)) |
---|
463 | { |
---|
464 | $GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error)); |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | $cat_id = $this->bo->save_cat($values); |
---|
469 | return $this->index(); |
---|
470 | //$GLOBALS['phpgw']->template->set_var('message',lang('Category %1 has been updated !',$cat_name)); |
---|
471 | } |
---|
472 | } |
---|
473 | |
---|
474 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Edit %1 category for', |
---|
475 | $GLOBALS['phpgw_info']['apps'][$cats_app]['title']).': '.$this->user; |
---|
476 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
477 | echo parse_navbar(); |
---|
478 | |
---|
479 | $cats = $this->bo->cats->return_single($cat_id); |
---|
480 | |
---|
481 | $link_data['menuaction'] = 'preferences.uicategories.edit'; |
---|
482 | $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
483 | |
---|
484 | $GLOBALS['phpgw']->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cats[0]['name'])); |
---|
485 | $GLOBALS['phpgw']->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cats[0]['description'])); |
---|
486 | |
---|
487 | $GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="old_parent" value="' . $cats[0]['parent'] . '">'); |
---|
488 | |
---|
489 | if ($cats_level) |
---|
490 | { |
---|
491 | $type = 'all'; |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | $type = 'mains'; |
---|
496 | } |
---|
497 | |
---|
498 | $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->cats->formated_list(array( |
---|
499 | 'type' => $type,'selected' => $cats[0]['parent'], |
---|
500 | 'globals' => $global_cats, 'self' => $cat_id |
---|
501 | ))); |
---|
502 | |
---|
503 | $GLOBALS['phpgw']->template->set_var('access','<input type="checkbox" name="cat_access" value="True"' |
---|
504 | . ($cats[0]['access'] == 'private' ? ' checked' : '') . '>'); |
---|
505 | |
---|
506 | if ($extra) |
---|
507 | { |
---|
508 | $edata = explode(',',$extra); |
---|
509 | |
---|
510 | $data = unserialize($cats[0]['data']); |
---|
511 | $edata_count = count($edata); |
---|
512 | for($i=0;$i<$edata_count;++$i) |
---|
513 | { |
---|
514 | $GLOBALS['phpgw']->template->set_var('td_data','<input name="cat_data[' . $edata[$i] . ']" size="50" value="' . $data[$edata[$i]] . '">'); |
---|
515 | $GLOBALS['phpgw']->template->set_var('lang_data',lang($edata[$i])); |
---|
516 | $GLOBALS['phpgw']->template->fp('row','data_row',True); |
---|
517 | } |
---|
518 | } |
---|
519 | |
---|
520 | if ($cats[0]['owner'] == $this->account) |
---|
521 | { |
---|
522 | $link_data['menuaction'] = 'preferences.uicategories.delete'; |
---|
523 | $GLOBALS['phpgw']->template->set_var('delete','<form method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data) |
---|
524 | . '"><input type="submit" value="' . lang('Delete') .'"></form>'); |
---|
525 | } |
---|
526 | else |
---|
527 | { |
---|
528 | $GLOBALS['phpgw']->template->set_var('delete',' '); |
---|
529 | } |
---|
530 | |
---|
531 | $GLOBALS['phpgw']->template->set_var('edithandle',''); |
---|
532 | $GLOBALS['phpgw']->template->set_var('addhandle',''); |
---|
533 | $GLOBALS['phpgw']->template->pfp('out','form'); |
---|
534 | $GLOBALS['phpgw']->template->pfp('edithandle','edit'); |
---|
535 | } |
---|
536 | |
---|
537 | function delete() |
---|
538 | { |
---|
539 | $cats_app = get_var('cats_app',array('GET','POST')); |
---|
540 | $extra = get_var('extra',array('GET','POST')); |
---|
541 | $global_cats = get_var('global_cats',array('GET','POST')); |
---|
542 | $cats_level = get_var('cats_level',array('GET','POST')); |
---|
543 | $cat_id = get_var('cat_id',array('GET','POST')); |
---|
544 | |
---|
545 | $link_data = array |
---|
546 | ( |
---|
547 | 'menuaction' => 'preferences.uicategories.index', |
---|
548 | 'cats_app' => $cats_app, |
---|
549 | 'extra' => $extra, |
---|
550 | 'global_cats' => $global_cats, |
---|
551 | 'cats_level' => $cats_level, |
---|
552 | 'cat_id' => $cat_id |
---|
553 | ); |
---|
554 | |
---|
555 | if (!$cat_id || $_POST['cancel']) |
---|
556 | { |
---|
557 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
558 | } |
---|
559 | |
---|
560 | if ($_POST['confirm']) |
---|
561 | { |
---|
562 | if ($_POST['subs']) |
---|
563 | { |
---|
564 | $this->bo->delete($cat_id,True); |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | $this->bo->delete($cat_id,False); |
---|
569 | } |
---|
570 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
571 | } |
---|
572 | else |
---|
573 | { |
---|
574 | $GLOBALS['phpgw']->template->set_file(array('category_delete' => 'delete.tpl')); |
---|
575 | |
---|
576 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Delete Categories'); |
---|
577 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
578 | echo parse_navbar(); |
---|
579 | |
---|
580 | $GLOBALS['phpgw']->template->set_var('deleteheader',lang('Are you sure you want to delete this category ?')); |
---|
581 | |
---|
582 | $exists = $this->bo->exists(array |
---|
583 | ( |
---|
584 | 'type' => 'subs', |
---|
585 | 'cat_name' => '', |
---|
586 | 'cat_id' => $cat_id |
---|
587 | )); |
---|
588 | |
---|
589 | if ($exists) |
---|
590 | { |
---|
591 | $GLOBALS['phpgw']->template->set_var('lang_subs',lang('Do you also want to delete all subcategories ?')); |
---|
592 | $GLOBALS['phpgw']->template->set_var('subs','<input type="checkbox" name="subs" value="True">'); |
---|
593 | } |
---|
594 | else |
---|
595 | { |
---|
596 | $GLOBALS['phpgw']->template->set_var('lang_subs',''); |
---|
597 | $GLOBALS['phpgw']->template->set_var('subs', ''); |
---|
598 | } |
---|
599 | |
---|
600 | $GLOBALS['phpgw']->template->set_var('lang_no',lang('No')); |
---|
601 | $link_data['menuaction'] = 'preferences.uicategories.delete'; |
---|
602 | $GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
603 | $GLOBALS['phpgw']->template->set_var('lang_yes',lang('Yes')); |
---|
604 | $GLOBALS['phpgw']->template->pfp('out','category_delete'); |
---|
605 | } |
---|
606 | } |
---|
607 | } |
---|
608 | ?> |
---|