source: sandbox/2.3-MailArchiver/admin/inc/class.uicategories.inc.php @ 6779

Revision 6779, 23.0 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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                        $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];
83                }
84
85                function _debug_sqsof()
86                {
87                        $data = array(
88                                'start'  => $this->start,
89                                'query'  => $this->query,
90                                'sort'   => $this->sort,
91                                'order'  => $this->order,
92                                'cat_id' => $this->cat_id
93                        );
94                        echo '<br>UI:<br>';
95                        _debug_array($data);
96                }
97
98                function save_sessiondata()
99                {
100                        $data = array
101                        (
102                                'start' => $this->start,
103                                'query' => $this->query,
104                                'sort'  => $this->sort,
105                                'order' => $this->order
106                        );
107
108                        if(isset($this->cat_id))
109                        {
110                                $data['cat_id'] = $this->cat_id;
111                        }
112                        $this->bo->save_sessiondata($data);
113                }
114
115                function set_langs()
116                {
117                        $this->template->set_var('lang_save',lang('Save'));
118                        $this->template->set_var('lang_search',lang('Search'));
119                        $this->template->set_var('lang_group_name',lang('group name'));
120                        $this->template->set_var('lang_cat_name',lang('category name'));
121                        $this->template->set_var('lang_sub',lang('Add sub'));
122                        $this->template->set_var('lang_icon',lang('icon'));
123                        $this->template->set_var('lang_edit',lang('Edit'));
124                        $this->template->set_var('lang_delete',lang('Delete'));
125                        $this->template->set_var('lang_parent',lang('Parent category'));
126                        $this->template->set_var('lang_none',lang('None'));
127                        $this->template->set_var('lang_name',lang('Name'));
128                        $this->template->set_var('lang_descr',lang('Description'));
129                        $this->template->set_var('lang_add',lang('Add'));
130                        $this->template->set_var('lang_reset',lang('Clear Form'));
131                        $this->template->set_var('lang_cancel',lang('Cancel'));
132                        $this->template->set_var('lang_done',lang('Done'));
133                        $this->template->set_var('lang_color',lang('Color'));
134                        $this->template->set_var('lang_icon',lang('Icon'));
135                        $this->template->set_var('lang_Loading',lang("Loading"));
136                        $this->template->set_var('lang_Searching', lang("search groups"));                             
137                        $this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));                                                                                                     
138                        $this->template->set_var('lang_Search_for', lang("Search Groups"));                                                                     
139                        $this->template->set_var('lang_cat_all', lang("All"));
140                        $this->template->set_var('lang_permission', lang("Permission"));
141                        $this->template->set_var('lang_Loading',lang("Loading"));
142                        $this->template->set_var('lang_Searching', lang("Search Groups"));
143                        $this->template->set_var('lang_Owner', lang("Owner (User/Group)"));
144                        $this->template->set_var('lang_Add', lang("Add"));
145                        $this->template->set_var('lang_Remove', lang("Remove"));                       
146                        $this->template->set_var('lang_Search_for', lang("Search Groups"));
147                        $this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));                             
148                }
149
150                function index()
151                {
152                        $link_data = array
153                        (
154                                'menuaction'    => 'admin.uicategories.edit',
155                                'appname'               => $this->appname
156                        );
157
158                        if ($_POST['add'])
159                        {
160                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
161                        }
162
163                        if ($_POST['done'])
164                        {
165                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
166                        }
167       
168                       
169                        $this->template->set_file(array('cat_list_t' => 'listcats.tpl'));
170                        $this->template->set_block('cat_list_t','cat_list','list');
171                        if (!$this->acl_add)
172                        {
173                                $this->template->set_block('cat_list_t','add','addhandle');
174                        }
175                        if (!$this->acl_search)
176                        {
177                                $this->template->set_block('cat_list_t','search','searchhandle');
178                        }
179
180                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Global categories');
181                        $GLOBALS['phpgw']->common->phpgw_header();
182                        echo parse_navbar();
183                        $this->set_langs();
184
185                        $this->template->set_var('query',$this->query);
186                       
187                        // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
188                        if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
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='calendar/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                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
429                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
430                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
431                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                               
432                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
433                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
434                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
435                                // Carrega todos scripts necessarios                           
436                                $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
437                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
438                                                        "<script src='calendar/js/search.js' type='text/javascript'></script>";                         
439                                // Fim                                                         
440                                $this->template->set_var('scripts',$scripts);
441                        }
442                }
443                // FIM if.
444                $this->template->set_var('template_set', $this->template_dir);
445
446                        $this->template->set_file(array('form' => 'category_form.tpl'));
447
448                        if ($this->cat_id)
449                        {
450                                list($cat) = $this->bo->cats->return_single($this->cat_id);
451                                $cat['data'] = unserialize($cat['data']);
452                        }
453                       
454                        else
455                        {
456                                $cat = array();
457                                $cat['parent'] = $_GET['cat_parent'];
458                        }
459
460                        // update the old calendar color format, color was added to the description
461                        if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches))
462                        {
463                                $cat['data']['color'] = $matches[1];
464                                $cat['description'] = str_replace($matches[1],'',$cat['description']);
465                        }
466                        if (strlen($cat['name_group']) == 0)
467                        {
468                                $cat['name_group'] = lang("All");
469                                $cat['id_group'] = 0;
470                        }
471                        $this->template->set_var('category_namegroup',$GLOBALS['phpgw']->strip_html($cat['name_group']));
472
473                        // Hidden vars
474                        $this->template->set_var('cat_id',$this->cat_id);
475                        $this->template->set_var('cat_parent',$cat['parent']);
476                        $this->template->set_var('cat_id_group',$cat['id_group']);
477
478                        $this->template->set_var('lang_add_multiple_categories',lang("add multiple categories?"));
479
480                        $link_data['menuaction']        = 'admin.uicategories.edit';
481                        $link_data['cat_id']            = $this->cat_id;
482                        $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
483
484                        if ($this->acl_delete)
485                        {
486                                $link_data['menuaction'] = 'admin.uicategories.delete';
487
488                                $this->template->set_var('delete','<form method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
489                                        . '"><input type="submit" value="' . lang('Delete') .'"></form>');
490                        }
491                        else
492                        {
493                                $this->template->set_var('delete','&nbsp;');
494                        }
495                        $this->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cat['name']));
496                        $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description']));
497                        $this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id)));
498                        $this->template->set_var('bt_rem_id_group_visibility',$cat['name_group'] ? "visible" : "hidden");
499                        if (!is_object($GLOBALS['phpgw']->html))
500                        {
501                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
502                        }
503                        $this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color')));
504                        $options = '';
505                        //$options = '<option value="aanone.gif"'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
506                        foreach ($this->icons as $icon)
507                        {
508                                if(!$cat['data']['icon']){
509                                        $cat['data']['icon'] = "aanone.gif";
510                                }
511                                $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'.
512                                        ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon == 'aanone.gif' ? lang('none') : $icon))."</option>\n";
513                        }
514                        $this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n");
515                        $this->template->set_var('icon',  '<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
516
517                        $already_done = array('icon','color');
518
519                        if ($extra)
520                        {
521                                foreach(explode(',',$extra) as $i => $name)
522                                {
523                                        $this->template->set_var('class',($i & 1) ? 'row_on' : 'row_off');
524                                        $this->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">');
525                                        $this->template->set_var('lang_data',lang($name));
526                                        $this->template->fp('row','data_row',True);
527                                        $already_done[] = $name;
528                                }
529                        }
530                        // preserv everything in the data array, not already shown via extra
531                        if (is_array($cat['data']))
532                        {
533                                foreach($cat['data'] as $name => $value)
534                                {
535                                        if (!in_array($name,$already_done))
536                                        {
537                                                $hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">';
538                                        }
539                                }
540                        }
541                        $this->template->set_var('hidden_vars',$hidden_vars);
542
543                        $GLOBALS['phpgw']->common->phpgw_header();
544                        echo parse_navbar();
545
546                        $this->template->pfp('out','form');
547                }
548
549                function delete()
550                {
551                        if (!$this->acl_delete)
552                        {
553                                $GLOBALS['phpgw']->redirect_link('/index.php');
554                        }
555                        $link_data = array
556                        (
557                                'menuaction'    => 'admin.uicategories.index',
558                                'appname'               => $this->appname
559                        );
560
561                        if (!$this->cat_id || $_POST['cancel'])
562                        {
563                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
564                        }
565
566                        if ($_POST['confirm'])
567                        {
568                                if ($_POST['subs'])
569                                {
570                                        $this->bo->delete($this->cat_id,True);
571                                }
572                                else
573                                {
574                                        $this->bo->delete($this->cat_id,False);
575                                }
576                                $GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
577                        }
578                        $this->template->set_file(array('category_delete' => 'delete_cat.tpl'));
579
580                        if ($this->appname)
581                        {
582                                $type = 'noglobalapp';
583                        }
584                        else
585                        {
586                                $type = 'noglobal';
587                        }
588
589                        $apps_cats = $this->bo->exists(array
590                        (
591                                'type'     => $type,
592                                'cat_name' => '',
593                                'cat_id'   => $this->cat_id
594                        ));
595
596                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Delete category');
597                        if(!@is_object($GLOBALS['phpgw']->js))
598                        {
599                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
600                        }
601                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
602                        $GLOBALS['phpgw']->common->phpgw_header();
603                        echo parse_navbar();
604
605                        $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n";
606                        $this->template->set_var('hidden_vars',$hidden_vars);
607
608                        $cats = $this->bo->cats->return_single($this->cat_id);
609                        $this->template->set_var('cat_name',$cat['name']);
610                       
611                        if ($apps_cats)
612                        {
613                                $this->template->set_block('category_delete','delete','deletehandle');
614                                $this->template->set_var('messages',lang('This category is currently being used by applications as a parent category') . '<br>'
615                                        . lang('You will need to remove the subcategories before you can delete this category'));
616
617                                $this->template->set_var('lang_subs','');
618                                $this->template->set_var('subs','');
619                                $this->template->set_var('nolink',$nolink);
620                                $this->template->set_var('deletehandle','');
621                                $this->template->set_var('donehandle','');
622                                $this->template->set_var('lang_ok',lang('Ok'));
623                                $this->template->pfp('out','category_delete');
624                        }
625                        else
626                        {
627                                $this->template->set_block('category_delete','done','donehandle');
628                                $this->template->set_var('messages',lang('Are you sure you want to delete this category ?'));
629
630                                $exists = $this->bo->exists(array
631                                (
632                                        'type'     => 'subs',
633                                        'cat_name' => '',
634                                        'cat_id'   => $this->cat_id
635                                ));
636
637                                if ($exists)
638                                {
639                                        $this->template->set_var('lang_subs',lang('Do you also want to delete all global subcategories ?'));
640                                        $this->template->set_var('subs','<input type="checkbox" name="subs" value="True">');
641                                }
642                                else
643                                {
644                                        $this->template->set_var('lang_subs','');
645                                        $this->template->set_var('subs', '');
646                                }
647
648                                $link_data['menuaction'] = 'admin.uicategories.delete';
649                                $link_data['cat_id'] = $this->cat_id;
650                                $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
651                                $this->template->set_var('lang_yes',lang('Yes'));
652                                $this->template->set_var('lang_no',lang('No'));
653                                $this->template->pfp('out','category_delete');
654                        }
655                }
656        }
657?>
Note: See TracBrowser for help on using the repository browser.