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

Revision 577, 22.7 KB checked in by niltonneto, 15 years ago (diff)

Resolve #348

  • 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                        $new_parent                     = (int)$_POST['new_parent'];
348                        $cat_parent                     = (int)$_POST['cat_parent'];
349                        $cat_name                       = $_POST['cat_name'];
350                        $cat_description                = $_POST['cat_description'];
351                        $cat_data                       = $_POST['cat_data'];
352                        $old_parent                     = (int)$_POST['old_parent'];
353                        $cat_group                      = $_POST['idgroup'];
354                       
355                        if ($new_parent)
356                        {
357                                $cat_parent = $new_parent;
358                        }
359
360                        $link_data = array
361                        (
362                                'menuaction'    => 'admin.uicategories.index',
363                                'appname'               => $this->appname
364                        );
365
366                        if (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0)
367                        {
368                                $GLOBALS['phpgw']->redirect_link('/index.php');
369                        }
370                        if ($_POST['cancel'] || $this->cat_id && !$this->acl_edit || $this->cat_id &&
371                                (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0))
372                        {
373                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
374                        }
375
376                       
377                        if ($_POST['save'])
378                        {
379                                $data = serialize($cat_data);
380
381                                $values = array
382                                (
383                                        'parent'                => $cat_parent,
384                                        'descr'                 => $cat_description,
385                                        'name'                  => $cat_name,
386                                        'group'                 => $cat_group,
387                                        'access'                => 'public',
388                                        'data'                  => $data
389                                );
390                                if ($this->cat_id)
391                                {
392                                        $values['id'] = $this->cat_id;
393                                        $values['old_parent'] = $old_parent;
394                                }
395                                $error = $this->bo->check_values($values);
396                                if (is_array($error))
397                                {
398                                        $this->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
399                                }
400                                else
401                                {
402                                        $this->cat_id = $this->bo->save_cat($values);
403                                        $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
404                                }
405                        }
406
407                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.($this->cat_id ? lang('Edit global category'):lang('Add global category'));
408
409                        $this->set_langs();
410                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
411                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
412                        $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];                                                   
413                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
414                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
415                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
416                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                               
417                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
418                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
419                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
420                                // Carrega todos scripts necessarios                           
421                                $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
422                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
423                                                        "<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";                         
424                                // Fim                                                         
425                                $this->template->set_var('scripts',$scripts);
426                                $this->template->set_var('template_set', $this->template_dir);
427                        }
428                }
429                // FIM if.
430
431                        $this->template->set_file(array('form' => 'category_form.tpl'));
432
433                        if ($this->cat_id)
434                        {
435                                list($cat) = $this->bo->cats->return_single($this->cat_id);
436                                $cat['data'] = unserialize($cat['data']);
437                        }
438                       
439                        else
440                        {
441                                $cat = array();
442                                $cat['parent'] = $_GET['cat_parent'];
443                        }
444
445                        // update the old calendar color format, color was added to the description
446                        if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches))
447                        {
448                                $cat['data']['color'] = $matches[1];
449                                $cat['description'] = str_replace($matches[1],'',$cat['description']);
450                        }
451
452                        $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n" .
453                                '<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">' . "\n".
454                                '<input type="hidden" id="idgroup" name="idgroup" value="' . $cat['id_group'] . '">' . "\n";
455
456                        $link_data['menuaction']        = 'admin.uicategories.edit';
457                        $link_data['cat_id']            = $this->cat_id;
458                        $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
459
460                        if ($this->acl_delete)
461                        {
462                                $link_data['menuaction'] = 'admin.uicategories.delete';
463
464                                $this->template->set_var('delete','<form method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
465                                        . '"><input type="submit" value="' . lang('Delete') .'"></form>');
466                        }
467                        else
468                        {
469                                $this->template->set_var('delete','&nbsp;');
470                        }
471                        $this->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cat['name']));
472                        $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description']));
473                        $this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id)));
474                        $this->template->set_var('category_namegroup',$GLOBALS['phpgw']->strip_html($cat['name_group']));
475                        $this->template->set_var('bt_rem_id_group_visibility',$cat['name_group'] ? "visible" : "hidden");
476                        if (!is_object($GLOBALS['phpgw']->html))
477                        {
478                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
479                        }
480                        $this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color')));
481                        $options = '';
482                        //$options = '<option value="aanone.gif"'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
483                        foreach ($this->icons as $icon)
484                        {
485                                if(!$cat['data']['icon']){
486                                        $cat['data']['icon'] = "aanone.gif";
487                                }
488                                $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'.
489                                        ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon == 'aanone.gif' ? lang('none') : $icon))."</option>\n";
490                        }
491                        $this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n");
492                        $this->template->set_var('icon',  '<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
493
494                        $already_done = array('icon','color');
495
496                        if ($extra)
497                        {
498                                foreach(explode(',',$extra) as $i => $name)
499                                {
500                                        $this->template->set_var('class',($i & 1) ? 'row_on' : 'row_off');
501                                        $this->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">');
502                                        $this->template->set_var('lang_data',lang($name));
503                                        $this->template->fp('row','data_row',True);
504                                        $already_done[] = $name;
505                                }
506                        }
507                        // preserv everything in the data array, not already shown via extra
508                        if (is_array($cat['data']))
509                        {
510                                foreach($cat['data'] as $name => $value)
511                                {
512                                        if (!in_array($name,$already_done))
513                                        {
514                                                $hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">';
515                                        }
516                                }
517                        }
518                        $this->template->set_var('hidden_vars',$hidden_vars);
519
520                        $GLOBALS['phpgw']->common->phpgw_header();
521                        echo parse_navbar();
522
523                        $this->template->pfp('out','form');
524                }
525
526                function delete()
527                {
528                        if (!$this->acl_delete)
529                        {
530                                $GLOBALS['phpgw']->redirect_link('/index.php');
531                        }
532                        $link_data = array
533                        (
534                                'menuaction'    => 'admin.uicategories.index',
535                                'appname'               => $this->appname
536                        );
537
538                        if (!$this->cat_id || $_POST['cancel'])
539                        {
540                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
541                        }
542
543                        if ($_POST['confirm'])
544                        {
545                                if ($_POST['subs'])
546                                {
547                                        $this->bo->delete($this->cat_id,True);
548                                }
549                                else
550                                {
551                                        $this->bo->delete($this->cat_id,False);
552                                }
553                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
554                        }
555                        $this->template->set_file(array('category_delete' => 'delete_cat.tpl'));
556
557                        if ($this->appname)
558                        {
559                                $type = 'noglobalapp';
560                        }
561                        else
562                        {
563                                $type = 'noglobal';
564                        }
565
566                        $apps_cats = $this->bo->exists(array
567                        (
568                                'type'     => $type,
569                                'cat_name' => '',
570                                'cat_id'   => $this->cat_id
571                        ));
572
573                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Delete category');
574                        if(!@is_object($GLOBALS['phpgw']->js))
575                        {
576                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
577                        }
578                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
579                        $GLOBALS['phpgw']->common->phpgw_header();
580                        echo parse_navbar();
581
582                        $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n";
583                        $this->template->set_var('hidden_vars',$hidden_vars);
584
585                        $cats = $this->bo->cats->return_single($this->cat_id);
586                        $this->template->set_var('cat_name',$cat['name']);
587                       
588                        if ($apps_cats)
589                        {
590                                $this->template->set_block('category_delete','delete','deletehandle');
591                                $this->template->set_var('messages',lang('This category is currently being used by applications as a parent category') . '<br>'
592                                        . lang('You will need to remove the subcategories before you can delete this category'));
593
594                                $this->template->set_var('lang_subs','');
595                                $this->template->set_var('subs','');
596                                $this->template->set_var('nolink',$nolink);
597                                $this->template->set_var('deletehandle','');
598                                $this->template->set_var('donehandle','');
599                                $this->template->set_var('lang_ok',lang('Ok'));
600                                $this->template->pfp('out','category_delete');
601                        }
602                        else
603                        {
604                                $this->template->set_block('category_delete','done','donehandle');
605                                $this->template->set_var('messages',lang('Are you sure you want to delete this category ?'));
606
607                                $exists = $this->bo->exists(array
608                                (
609                                        'type'     => 'subs',
610                                        'cat_name' => '',
611                                        'cat_id'   => $this->cat_id
612                                ));
613
614                                if ($exists)
615                                {
616                                        $this->template->set_var('lang_subs',lang('Do you also want to delete all global subcategories ?'));
617                                        $this->template->set_var('subs','<input type="checkbox" name="subs" value="True">');
618                                }
619                                else
620                                {
621                                        $this->template->set_var('lang_subs','');
622                                        $this->template->set_var('subs', '');
623                                }
624
625                                $link_data['menuaction'] = 'admin.uicategories.delete';
626                                $link_data['cat_id'] = $this->cat_id;
627                                $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
628                                $this->template->set_var('lang_yes',lang('Yes'));
629                                $this->template->set_var('lang_no',lang('No'));
630                                $this->template->pfp('out','category_delete');
631                        }
632                }
633        }
634?>
Note: See TracBrowser for help on using the repository browser.