source: trunk/admin/inc/class.uicategories.inc.php @ 662

Revision 662, 23.1 KB checked in by niltonneto, 15 years ago (diff)

Resolve #423

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare - Admin - Global categories                                   *
4        * http://www.egroupware.org                                                *
5        * Written by Bettina Gille [ceb@phpgroupware.org]                          *
6        * Simplified ;-) and icon & color added by RalfBecker@outdoor-training.de  *
7        * -----------------------------------------------                          *
8        * Copyright 2000 - 2003 Free Software Foundation, Inc                      *
9        *                                                                          *
10        * This program is free software; you can redistribute it and/or modify it  *
11        * under the terms of the GNU General Public License as published by the    *
12        * Free Software Foundation; either version 2 of the License, or (at your   *
13        * option) any later version.                                               *
14        \**************************************************************************/
15
16
17        class uicategories
18        {
19                var $bo;
20                var $template;
21
22                var $start;
23                var $query;
24                var $sort;
25                var $order;
26                var $cat_id;
27                var $debug = False;
28
29                var $public_functions = array
30                (
31                        'index'  => True,
32                        'edit'   => True,
33                        'delete' => True
34                );
35
36                function uicategories()
37                {
38                        if ($GLOBALS['phpgw']->acl->check('global_categories_access',1,'admin'))
39                        {
40                                $GLOBALS['phpgw']->redirect_link('/index.php');
41                        }
42
43                        $this->bo                       = CreateObject('admin.bocategories');
44                        $this->template         = $GLOBALS['phpgw']->template;
45                        $this->nextmatchs       = CreateObject('phpgwapi.nextmatchs');
46
47                        $this->acl_search = !$GLOBALS['phpgw']->acl->check('global_categories_access',2,'admin');
48                        $this->acl_add    = !$GLOBALS['phpgw']->acl->check('global_categories_access',4,'admin');
49                        $this->acl_view   = !$GLOBALS['phpgw']->acl->check('global_categories_access',8,'admin');
50                        $this->acl_edit   = !$GLOBALS['phpgw']->acl->check('global_categories_access',16,'admin');
51                        $this->acl_delete = !$GLOBALS['phpgw']->acl->check('global_categories_access',32,'admin');
52                        $this->acl_add_sub= !$GLOBALS['phpgw']->acl->check('global_categories_access',64,'admin');
53
54                        if(!@is_object($GLOBALS['phpgw']->js))
55                        {
56                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
57                        }
58                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
59
60                        $this->appname = get_var('appname',array('GET','POST'));
61                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps'][$this->appname ? $this->appname : 'admin']['title'];
62
63                        $this->start            = $this->bo->start;
64                        $this->query            = $this->bo->query;
65                        $this->sort             = $this->bo->sort;
66                        $this->order            = $this->bo->order;
67                        $this->cat_id           = $this->bo->cat_id;
68                        if($this->debug) { $this->_debug_sqsof(); }
69
70                        $dir = dir(PHPGW_SERVER_ROOT.'/phpgwapi/images');
71
72                        while($file = $dir->read())
73                        {
74                                if (preg_match('/\\.(png|gif|jpe?g)$/i',$file))
75                                {
76                                        $this->icons[] = $file;
77                                }
78                        }
79                        $dir->close();
80                        sort($this->icons);
81                        $this->img_url = $GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/images/';
82                }
83
84                function _debug_sqsof()
85                {
86                        $data = array(
87                                'start'  => $this->start,
88                                'query'  => $this->query,
89                                'sort'   => $this->sort,
90                                'order'  => $this->order,
91                                'cat_id' => $this->cat_id
92                        );
93                        echo '<br>UI:<br>';
94                        _debug_array($data);
95                }
96
97                function save_sessiondata()
98                {
99                        $data = array
100                        (
101                                'start' => $this->start,
102                                'query' => $this->query,
103                                'sort'  => $this->sort,
104                                'order' => $this->order
105                        );
106
107                        if(isset($this->cat_id))
108                        {
109                                $data['cat_id'] = $this->cat_id;
110                        }
111                        $this->bo->save_sessiondata($data);
112                }
113
114                function set_langs()
115                {
116                        $this->template->set_var('lang_save',lang('Save'));
117                        $this->template->set_var('lang_search',lang('Search'));
118                        $this->template->set_var('lang_group_name',lang('group name'));
119                        $this->template->set_var('lang_cat_name',lang('category name'));
120                        $this->template->set_var('lang_sub',lang('Add sub'));
121                        $this->template->set_var('lang_icon',lang('icon'));
122                        $this->template->set_var('lang_edit',lang('Edit'));
123                        $this->template->set_var('lang_delete',lang('Delete'));
124                        $this->template->set_var('lang_parent',lang('Parent category'));
125                        $this->template->set_var('lang_none',lang('None'));
126                        $this->template->set_var('lang_name',lang('Name'));
127                        $this->template->set_var('lang_descr',lang('Description'));
128                        $this->template->set_var('lang_add',lang('Add'));
129                        $this->template->set_var('lang_reset',lang('Clear Form'));
130                        $this->template->set_var('lang_cancel',lang('Cancel'));
131                        $this->template->set_var('lang_done',lang('Done'));
132                        $this->template->set_var('lang_color',lang('Color'));
133                        $this->template->set_var('lang_icon',lang('Icon'));
134                        $this->template->set_var('lang_Loading',lang("Loading"));
135                        $this->template->set_var('lang_Searching', lang("search groups"));                             
136                        $this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));                                                                                                     
137                        $this->template->set_var('lang_Search_for', lang("Search Groups"));                                                                     
138                        $this->template->set_var('lang_cat_all', lang("All"));
139                        $this->template->set_var('lang_permission', lang("Permission"));
140                        $this->template->set_var('lang_Loading',lang("Loading"));
141                        $this->template->set_var('lang_Searching', lang("Search Groups"));
142                        $this->template->set_var('lang_Owner', lang("Owner (User/Group)"));
143                        $this->template->set_var('lang_Add', lang("Add"));
144                        $this->template->set_var('lang_Remove', lang("Remove"));                       
145                        $this->template->set_var('lang_Search_for', lang("Search Groups"));
146                        $this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));                             
147                }
148
149                function index()
150                {
151                        $link_data = array
152                        (
153                                'menuaction'    => 'admin.uicategories.edit',
154                                'appname'               => $this->appname
155                        );
156
157                        if ($_POST['add'])
158                        {
159                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
160                        }
161
162                        if ($_POST['done'])
163                        {
164                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
165                        }
166       
167                       
168                        $this->template->set_file(array('cat_list_t' => 'listcats.tpl'));
169                        $this->template->set_block('cat_list_t','cat_list','list');
170                        if (!$this->acl_add)
171                        {
172                                $this->template->set_block('cat_list_t','add','addhandle');
173                        }
174                        if (!$this->acl_search)
175                        {
176                                $this->template->set_block('cat_list_t','search','searchhandle');
177                        }
178
179                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Global categories');
180                        $GLOBALS['phpgw']->common->phpgw_header();
181                        echo parse_navbar();
182                        $this->set_langs();
183
184                        $this->template->set_var('query',$this->query);
185                       
186                        // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
187                        if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
188                                $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];                                                   
189                                $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
190                                if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
191                                        $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
192                                        $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                               
193                                        $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
194                                        $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
195                                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
196                                        // Carrega todos scripts necessarios                           
197                                        $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
198                                                                "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
199                                                                "<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";
200                                        // Fim
201                                }
202                                $this->template->set_var('scripts',$scripts);                   
203                        }
204                        $this->template->set_var('template_set',$this->template_dir);
205
206                        $link_data['menuaction'] = 'admin.uicategories.index';
207                        $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
208
209                        if(!$start)
210                        {
211                                $start = 0;
212                        }
213                        list($idgroup,$namegroup) = explode('.', @$_POST['group']);                     
214                        if($this-> query || $namegroup)
215                                $result_search = lang("result")." :: ".lang("about")." <b>'".($this-> query ? $this-> query : $namegroup)."'</b> :: ";
216                        else
217                                $this->template->set_var('type_search_'.($_POST['typesearch'] ? $_POST['typesearch'] : 'a').'_checked', "checked");                                             
218                        $cats = $this->bo->get_list($idgroup);
219
220                        if (!is_array($cats)) $cats = array();
221
222                        $left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,$link_data);
223                        $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,$link_data);
224                        $this->template->set_var('left',$left);
225                        $this->template->set_var('right',$right);
226
227                        $this->template->set_var('lang_showing',$result_search.$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));                     
228
229                        $this->template->set_var('sort_name', !$_POST['typesearch'] ? $this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data) : lang('Name'));
230                        $this->template->set_var('sort_description', !$_POST['typesearch'] ? $this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data) : lang('Description'));
231
232                        foreach($cats as $cat)
233                        {
234                                $data = unserialize($cat['data']);
235
236                                if ($data['color'])
237                                {
238                                        $this->template->set_var('tr_color',$data['color']);
239                                        $gray = (hexdec(substr($data['color'],1,2))+hexdec(substr($data['color'],3,2))+hexdec(substr($data['color'],5,2)))/3;
240                                }
241                                else
242                                {
243                                        $this->nextmatchs->template_alternate_row_color($this->template);
244                                        $gray = 255;
245                                }
246                                $this->template->set_var('color',$gray < 128 ? 'style="color: white;"' : '');
247
248                                $id = $cat['id'];
249                                $level = $cat['level'];
250                                $cat_name = $GLOBALS['phpgw']->strip_html($cat['name']);
251
252                                if ($level > 0)
253                                {
254                                        $space = '&nbsp;&nbsp;';
255                                        $spaceset = str_repeat($space,$level);
256                                        $cat_name = $spaceset . $cat_name;
257                                }
258
259                                $descr = $GLOBALS['phpgw']->strip_html($cat['description']);
260                                if (!$descr) { $descr = '&nbsp;'; }
261
262                                if ($level == 0)
263                                {
264                                        $cat_name = '<font color="FF0000"><b>' . $cat_name . '</b></font>';
265                                        $descr = '<font color="FF0000"><b>' . $descr . '</b></font>';
266                                }
267
268                                if ($this->appname && $cat['app_name'] == 'phpgw')
269                                {
270                                        $appendix = '&lt;' . lang('Global') . '&gt;';
271                                }
272                                else
273                                {
274                                        $appendix = '';
275                                }
276
277                                $this->template->set_var(array
278                                (
279                                        'name' => $cat_name . $appendix,
280                                        'descr' => $descr
281                                ));
282
283                                if ($this->acl_add_sub)
284                                {
285                                        $link_data['menuaction'] = 'admin.uicategories.edit';
286                                        $link_data['cat_parent'] = $id;
287                                        unset($link_data['cat_id']);
288                                        $this->template->set_var('add_sub','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'.
289                                                lang('Add sub').'</a>');
290                                }
291                                if ($this->appname && $cat['app_name'] == $this->appname)
292                                {
293                                        $show_edit_del = True;
294                                }
295                                elseif(!$this->appname && $cat['app_name'] == 'phpgw')
296                                {
297                                        $show_edit_del = True;
298                                }
299                                else
300                                {
301                                        $show_edit_del = False;
302                                }
303
304                                $link_data['cat_id'] = $id;
305                                unset($link_data['cat_parent']);
306                                if ($show_edit_del && $this->acl_edit)
307                                {
308                                        $link_data['menuaction'] = 'admin.uicategories.edit';
309                                        $this->template->set_var('edit','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'.
310                                                lang('Edit').'</a>');
311                                }
312                                else
313                                {                                       
314                                        $this->template->set_var('edit','');
315                                }
316                                if ($show_edit_del && $this->acl_delete)
317                                {
318                                        $link_data['menuaction'] = 'admin.uicategories.delete';
319                                        $this->template->set_var('delete','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'.
320                                                lang('Delete').'</a>');
321                                }
322                                else
323                                {
324                                        $this->template->set_var('delete','');
325                                }
326
327                                $data = unserialize($cat['data']);
328                                $icon = $data['icon'];                         
329                                $permission = ($cat['owner'] == '-1' ? lang("all"): $cat['owner']);
330                                $this->template->set_var('permission', $permission);
331                                $dir_img = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'phpgwapi' . SEP . 'images' . SEP;
332                                $this->template->set_var('icon', !$icon ? lang("None") : "<img src='". $dir_img . $icon  ."'>");
333
334                                $this->template->fp('list','cat_list',True);
335                        }
336                        $link_data['menuaction'] = 'admin.uicategories.edit';
337                        unset($link_data['cat_id']);
338                        unset($link_data['cat_parent']);
339                        $this->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
340
341                        $this->save_sessiondata();
342                        $this->template->pfp('out','cat_list_t',True);
343                }
344
345                function edit()
346                {
347                        $cat_group = split(",",$_POST['idgroup']);
348
349                        if (count($cat_group) == 0)     
350                                $cat_group = array('0'=>'0');
351
352                        $new_parent                     = (int)$_POST['new_parent'];
353                        $cat_parent                     = (int)$_POST['cat_parent'];
354                        $cat_name                       = $_POST['cat_name'];
355                        $cat_description                = $_POST['cat_description'];
356                        $cat_data                       = $_POST['cat_data'];
357                        $old_parent                     = (int)$_POST['old_parent'];
358
359                        if ($new_parent)
360                        {
361                                $cat_parent = $new_parent;
362                        }
363
364                        $link_data = array
365                        (
366                                'menuaction'    => 'admin.uicategories.index',
367                                'appname'               => $this->appname
368                        );
369
370                        if (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0)
371                        {
372                                $GLOBALS['phpgw']->redirect_link('/index.php');
373                        }
374                        if ($_POST['cancel'] || $this->cat_id && !$this->acl_edit || $this->cat_id &&
375                                (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0))
376                        {
377                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
378                        }
379
380                       
381                        if ($_POST['save'])
382                        {
383                                $data = serialize($cat_data);
384                                $redirect_ = false;
385                                foreach($cat_group as $index_ => $catValue)
386                                {
387                                        $values = array
388                                                (
389                                                        'parent'                => $cat_parent,
390                                                        'descr'                 => $cat_description,
391                                                        'name'                  => $cat_name,
392                                                        'group'                 => $catValue,
393                                                        'access'                => 'public',
394                                                        'data'                  => $data
395                                                );
396                                        if ($this->cat_id)
397                                        {
398                                                if ($index_ == 0){
399                                                        $values['id'] = $this->cat_id;
400                                                        $values['old_parent'] = $old_parent;
401                                                }
402                                                else{
403                                                        $this->bo->save_cat($values);
404                                                }
405                                        }
406                                        $error = $this->bo->check_values($values);
407                                        if (is_array($error))
408                                        {
409                                                $this->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
410                                        }
411                                        else
412                                        {
413                                                $redirect_ = true;
414                                                $this->cat_id = $this->bo->save_cat($values);
415                                                unset($values);
416                                        }
417                                        }
418                                        if ($redirect_)
419                                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
420
421                        }
422
423                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.($this->cat_id ? lang('Edit global category'):lang('Add global category'));
424
425                        $this->set_langs();
426                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
427                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
428                        $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];                                                   
429                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
430                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
431                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
432                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                               
433                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
434                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
435                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
436                                // Carrega todos scripts necessarios                           
437                                $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
438                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
439                                                        "<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";                         
440                                // Fim                                                         
441                                $this->template->set_var('scripts',$scripts);
442                                $this->template->set_var('template_set', $this->template_dir);
443                        }
444                }
445                // FIM if.
446
447                        $this->template->set_file(array('form' => 'category_form.tpl'));
448
449                        if ($this->cat_id)
450                        {
451                                list($cat) = $this->bo->cats->return_single($this->cat_id);
452                                $cat['data'] = unserialize($cat['data']);
453                        }
454                       
455                        else
456                        {
457                                $cat = array();
458                                $cat['parent'] = $_GET['cat_parent'];
459                        }
460
461                        // update the old calendar color format, color was added to the description
462                        if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches))
463                        {
464                                $cat['data']['color'] = $matches[1];
465                                $cat['description'] = str_replace($matches[1],'',$cat['description']);
466                        }
467                        if (strlen($cat['name_group']) == 0)
468                        {
469                                $cat['name_group'] = lang("All");
470                                $cat['id_group'] = 0;
471                        }
472                        $this->template->set_var('category_namegroup',$GLOBALS['phpgw']->strip_html($cat['name_group']));
473
474                        // Hidden vars
475                        $this->template->set_var('cat_id',$this->cat_id);
476                        $this->template->set_var('cat_parent',$cat['parent']);
477                        $this->template->set_var('cat_id_group',$cat['id_group']);
478
479                        $this->template->set_var('lang_add_multiple_categories',lang("add multiple categories?"));
480
481                        $link_data['menuaction']        = 'admin.uicategories.edit';
482                        $link_data['cat_id']            = $this->cat_id;
483                        $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
484
485                        if ($this->acl_delete)
486                        {
487                                $link_data['menuaction'] = 'admin.uicategories.delete';
488
489                                $this->template->set_var('delete','<form method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
490                                        . '"><input type="submit" value="' . lang('Delete') .'"></form>');
491                        }
492                        else
493                        {
494                                $this->template->set_var('delete','&nbsp;');
495                        }
496                        $this->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cat['name']));
497                        $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description']));
498                        $this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id)));
499                        $this->template->set_var('bt_rem_id_group_visibility',$cat['name_group'] ? "visible" : "hidden");
500                        if (!is_object($GLOBALS['phpgw']->html))
501                        {
502                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
503                        }
504                        $this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color')));
505                        $options = '';
506                        //$options = '<option value="aanone.gif"'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
507                        foreach ($this->icons as $icon)
508                        {
509                                if(!$cat['data']['icon']){
510                                        $cat['data']['icon'] = "aanone.gif";
511                                }
512                                $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'.
513                                        ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon == 'aanone.gif' ? lang('none') : $icon))."</option>\n";
514                        }
515                        $this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n");
516                        $this->template->set_var('icon',  '<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
517
518                        $already_done = array('icon','color');
519
520                        if ($extra)
521                        {
522                                foreach(explode(',',$extra) as $i => $name)
523                                {
524                                        $this->template->set_var('class',($i & 1) ? 'row_on' : 'row_off');
525                                        $this->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">');
526                                        $this->template->set_var('lang_data',lang($name));
527                                        $this->template->fp('row','data_row',True);
528                                        $already_done[] = $name;
529                                }
530                        }
531                        // preserv everything in the data array, not already shown via extra
532                        if (is_array($cat['data']))
533                        {
534                                foreach($cat['data'] as $name => $value)
535                                {
536                                        if (!in_array($name,$already_done))
537                                        {
538                                                $hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">';
539                                        }
540                                }
541                        }
542                        $this->template->set_var('hidden_vars',$hidden_vars);
543
544                        $GLOBALS['phpgw']->common->phpgw_header();
545                        echo parse_navbar();
546
547                        $this->template->pfp('out','form');
548                }
549
550                function delete()
551                {
552                        if (!$this->acl_delete)
553                        {
554                                $GLOBALS['phpgw']->redirect_link('/index.php');
555                        }
556                        $link_data = array
557                        (
558                                'menuaction'    => 'admin.uicategories.index',
559                                'appname'               => $this->appname
560                        );
561
562                        if (!$this->cat_id || $_POST['cancel'])
563                        {
564                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
565                        }
566
567                        if ($_POST['confirm'])
568                        {
569                                if ($_POST['subs'])
570                                {
571                                        $this->bo->delete($this->cat_id,True);
572                                }
573                                else
574                                {
575                                        $this->bo->delete($this->cat_id,False);
576                                }
577                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
578                        }
579                        $this->template->set_file(array('category_delete' => 'delete_cat.tpl'));
580
581                        if ($this->appname)
582                        {
583                                $type = 'noglobalapp';
584                        }
585                        else
586                        {
587                                $type = 'noglobal';
588                        }
589
590                        $apps_cats = $this->bo->exists(array
591                        (
592                                'type'     => $type,
593                                'cat_name' => '',
594                                'cat_id'   => $this->cat_id
595                        ));
596
597                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Delete category');
598                        if(!@is_object($GLOBALS['phpgw']->js))
599                        {
600                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
601                        }
602                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
603                        $GLOBALS['phpgw']->common->phpgw_header();
604                        echo parse_navbar();
605
606                        $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n";
607                        $this->template->set_var('hidden_vars',$hidden_vars);
608
609                        $cats = $this->bo->cats->return_single($this->cat_id);
610                        $this->template->set_var('cat_name',$cat['name']);
611                       
612                        if ($apps_cats)
613                        {
614                                $this->template->set_block('category_delete','delete','deletehandle');
615                                $this->template->set_var('messages',lang('This category is currently being used by applications as a parent category') . '<br>'
616                                        . lang('You will need to remove the subcategories before you can delete this category'));
617
618                                $this->template->set_var('lang_subs','');
619                                $this->template->set_var('subs','');
620                                $this->template->set_var('nolink',$nolink);
621                                $this->template->set_var('deletehandle','');
622                                $this->template->set_var('donehandle','');
623                                $this->template->set_var('lang_ok',lang('Ok'));
624                                $this->template->pfp('out','category_delete');
625                        }
626                        else
627                        {
628                                $this->template->set_block('category_delete','done','donehandle');
629                                $this->template->set_var('messages',lang('Are you sure you want to delete this category ?'));
630
631                                $exists = $this->bo->exists(array
632                                (
633                                        'type'     => 'subs',
634                                        'cat_name' => '',
635                                        'cat_id'   => $this->cat_id
636                                ));
637
638                                if ($exists)
639                                {
640                                        $this->template->set_var('lang_subs',lang('Do you also want to delete all global subcategories ?'));
641                                        $this->template->set_var('subs','<input type="checkbox" name="subs" value="True">');
642                                }
643                                else
644                                {
645                                        $this->template->set_var('lang_subs','');
646                                        $this->template->set_var('subs', '');
647                                }
648
649                                $link_data['menuaction'] = 'admin.uicategories.delete';
650                                $link_data['cat_id'] = $this->cat_id;
651                                $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
652                                $this->template->set_var('lang_yes',lang('Yes'));
653                                $this->template->set_var('lang_no',lang('No'));
654                                $this->template->pfp('out','category_delete');
655                        }
656                }
657        }
658?>
Note: See TracBrowser for help on using the repository browser.