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

Revision 2802, 23.8 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Permitindo o envio de formulário por requisição background

  • 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( '/#' );
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/' );
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                        $this->template->set_var( 'add_button', $GLOBALS[ 'phpgw' ] -> link( '/index.php', $link_data ) );
207                        $this->template->set_var( 'done_button', $GLOBALS[ 'phpgw' ] -> link( '/admin/' ) );
208
209                        $link_data['menuaction'] = 'admin.uicategories.index';
210                        $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
211
212                        if(!$start)
213                        {
214                                $start = 0;
215                        }
216                        list($idgroup,$namegroup) = explode('.', @$_POST['group']);                     
217                        if($this-> query || $namegroup)
218                                $result_search = lang("result")." :: ".lang("about")." <b>'".($this-> query ? $this-> query : $namegroup)."'</b> :: ";
219                        else
220                                $this->template->set_var('type_search_'.($_POST['typesearch'] ? $_POST['typesearch'] : 'a').'_checked', "checked");                                             
221                        $cats = $this->bo->get_list($idgroup);
222
223                        if (!is_array($cats)) $cats = array();
224
225                        $left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,$link_data);
226                        $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,$link_data);
227                        $this->template->set_var('left',$left);
228                        $this->template->set_var('right',$right);
229
230                        $this->template->set_var('lang_showing',$result_search.$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));                     
231
232                        $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'));
233                        $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'));
234
235                        foreach($cats as $cat)
236                        {
237                                $data = unserialize($cat['data']);
238
239                                if ($data['color'])
240                                {
241                                        $this->template->set_var('tr_color',$data['color']);
242                                        $gray = (hexdec(substr($data['color'],1,2))+hexdec(substr($data['color'],3,2))+hexdec(substr($data['color'],5,2)))/3;
243                                }
244                                else
245                                {
246                                        $this->nextmatchs->template_alternate_row_color($this->template);
247                                        $gray = 255;
248                                }
249                                $this->template->set_var('color',$gray < 128 ? 'style="color: white;"' : '');
250
251                                $id = $cat['id'];
252                                $level = $cat['level'];
253                                $cat_name = $GLOBALS['phpgw']->strip_html($cat['name']);
254
255                                if ($level > 0)
256                                {
257                                        $space = '&nbsp;&nbsp;';
258                                        $spaceset = str_repeat($space,$level);
259                                        $cat_name = $spaceset . $cat_name;
260                                }
261
262                                $descr = $GLOBALS['phpgw']->strip_html($cat['description']);
263                                if (!$descr) { $descr = '&nbsp;'; }
264
265                                if ($level == 0)
266                                {
267                                        $cat_name = '<font color="FF0000"><b>' . $cat_name . '</b></font>';
268                                        $descr = '<font color="FF0000"><b>' . $descr . '</b></font>';
269                                }
270
271                                if ($this->appname && $cat['app_name'] == 'phpgw')
272                                {
273                                        $appendix = '&lt;' . lang('Global') . '&gt;';
274                                }
275                                else
276                                {
277                                        $appendix = '';
278                                }
279
280                                $this->template->set_var(array
281                                (
282                                        'name' => $cat_name . $appendix,
283                                        'descr' => $descr
284                                ));
285
286                                if ($this->acl_add_sub)
287                                {
288                                        $link_data['menuaction'] = 'admin.uicategories.edit';
289                                        $link_data['cat_parent'] = $id;
290                                        unset($link_data['cat_id']);
291                                        $this->template->set_var('add_sub','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'.
292                                                lang('Add sub').'</a>');
293                                }
294                                if ($this->appname && $cat['app_name'] == $this->appname)
295                                {
296                                        $show_edit_del = True;
297                                }
298                                elseif(!$this->appname && $cat['app_name'] == 'phpgw')
299                                {
300                                        $show_edit_del = True;
301                                }
302                                else
303                                {
304                                        $show_edit_del = False;
305                                }
306
307                                $link_data['cat_id'] = $id;
308                                unset($link_data['cat_parent']);
309                                if ($show_edit_del && $this->acl_edit)
310                                {
311                                        $link_data['menuaction'] = 'admin.uicategories.edit';
312                                        $this->template->set_var('edit','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'.
313                                                lang('Edit').'</a>');
314                                }
315                                else
316                                {                                       
317                                        $this->template->set_var('edit','');
318                                }
319                                if ($show_edit_del && $this->acl_delete)
320                                {
321                                        $link_data['menuaction'] = 'admin.uicategories.delete';
322                                        $this->template->set_var('delete','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'.
323                                                lang('Delete').'</a>');
324                                }
325                                else
326                                {
327                                        $this->template->set_var('delete','');
328                                }
329
330                                $data = unserialize($cat['data']);
331                                $icon = $data['icon'];                         
332                                $permission = ($cat['owner'] == '-1' ? lang("all"): $cat['owner']);
333                                $this->template->set_var('permission', $permission);
334                                $dir_img = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'phpgwapi' . SEP . 'images' . SEP;
335                                $this->template->set_var('icon', !$icon ? lang("None") : "<img src='". $dir_img . $icon  ."'>");
336
337                                $this->template->fp('list','cat_list',True);
338                        }
339                        $link_data['menuaction'] = 'admin.uicategories.edit';
340                        unset($link_data['cat_id']);
341                        unset($link_data['cat_parent']);
342                        $this->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
343
344                        $this->save_sessiondata();
345                        $this->template->pfp('out','cat_list_t',True);
346                }
347
348                function edit()
349                {
350                        $cat_group = split(",",$_POST['idgroup']);
351
352                        if (count($cat_group) == 0)     
353                                $cat_group = array('0'=>'0');
354
355                        $new_parent                     = (int)$_POST['new_parent'];
356                        $cat_parent                     = (int)$_POST['cat_parent'];
357                        $cat_name                       = $_POST['cat_name'];
358                        $cat_description                = $_POST['cat_description'];
359                        $cat_data                       = $_POST['cat_data'];
360                        $old_parent                     = (int)$_POST['old_parent'];
361
362                        if ($new_parent)
363                        {
364                                $cat_parent = $new_parent;
365                        }
366
367                        $link_data = array
368                        (
369                                'menuaction'    => 'admin.uicategories.index',
370                                'appname'               => $this->appname
371                        );
372
373                        if (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0)
374                        {
375                                $GLOBALS['phpgw']->redirect_link( '/#' );
376                        }
377                        if ($_POST['cancel'] || $this->cat_id && !$this->acl_edit || $this->cat_id &&
378                                (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0))
379                        {
380                                $GLOBALS['phpgw']->redirect_link('/#index.php',$link_data);
381                        }
382
383                       
384                        if ($_POST['save'])
385                        {
386                                $data = serialize($cat_data);
387                                $redirect_ = false;
388                                foreach($cat_group as $index_ => $catValue)
389                                {
390                                        $values = array
391                                                (
392                                                        'parent'                => $cat_parent,
393                                                        'descr'                 => $cat_description,
394                                                        'name'                  => $cat_name,
395                                                        'group'                 => $catValue,
396                                                        'access'                => 'public',
397                                                        'data'                  => $data
398                                                );
399                                        if ($this->cat_id)
400                                        {
401                                                if ($index_ == 0){
402                                                        $values['id'] = $this->cat_id;
403                                                        $values['old_parent'] = $old_parent;
404                                                }
405                                                else{
406                                                        $this->bo->save_cat($values);
407                                                }
408                                        }
409                                        $error = $this->bo->check_values($values);
410                                        if (is_array($error))
411                                        {
412                                                $this->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
413                                        }
414                                        else
415                                        {
416                                                $redirect_ = true;
417                                                $this->cat_id = $this->bo->save_cat($values);
418                                                unset($values);
419                                        }
420                                }
421                                if ($redirect_)
422                                {
423                                        $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ] .= "<script>ExpressoLivre.link( '{$GLOBALS[ 'phpgw' ] -> link('/index.php',$link_data)}' );</script>";
424                                        exit;
425                                }
426
427                        }
428
429                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.($this->cat_id ? lang('Edit global category'):lang('Add global category'));
430
431                        $this->set_langs();
432                        // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
433                        if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {
434                                $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];                                                   
435                                $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
436                                if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
437                                        $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
438                                        $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                               
439                                        $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
440                                        $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
441                                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
442                                        // Carrega todos scripts necessarios                           
443                                        $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
444                                                "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
445                                                "<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";                         
446                                        // Fim                                                         
447                                        $this->template->set_var('scripts',$scripts);
448                                        $this->template->set_var('template_set', $this->template_dir);
449                                }
450                        }
451                        // FIM if.
452
453                        $this->template->set_file(array('form' => 'category_form.tpl'));
454
455                        $this->template->set_var( 'cancel_button', $GLOBALS[ 'phpgw' ] -> link( '/index.php', $link_data ) );
456
457                        if ($this->cat_id)
458                        {
459                                list($cat) = $this->bo->cats->return_single($this->cat_id);
460                                $cat['data'] = unserialize($cat['data']);
461                        }
462                       
463                        else
464                        {
465                                $cat = array();
466                                $cat['parent'] = $_GET['cat_parent'];
467                        }
468
469                        // update the old calendar color format, color was added to the description
470                        if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches))
471                        {
472                                $cat['data']['color'] = $matches[1];
473                                $cat['description'] = str_replace($matches[1],'',$cat['description']);
474                        }
475                        if (strlen($cat['name_group']) == 0)
476                        {
477                                $cat['name_group'] = lang("All");
478                                $cat['id_group'] = 0;
479                        }
480                        $this->template->set_var('category_namegroup',$GLOBALS['phpgw']->strip_html($cat['name_group']));
481
482                        // Hidden vars
483                        $this->template->set_var('cat_id',$this->cat_id);
484                        $this->template->set_var('cat_parent',$cat['parent']);
485                        $this->template->set_var('cat_id_group',$cat['id_group']);
486
487                        $this->template->set_var('lang_add_multiple_categories',lang("add multiple categories?"));
488
489                        $link_data['menuaction']        = 'admin.uicategories.edit';
490                        $link_data['cat_id']            = $this->cat_id;
491                        $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
492
493                        if ($this->acl_delete)
494                        {
495                                $link_data['menuaction'] = 'admin.uicategories.delete';
496
497                                $this->template->set_var( 'lang_delete', lang('Delete') );
498                                $this->template->set_var( 'delete_button', $GLOBALS[ 'phpgw' ] -> link( '/index.php', $link_data ) );
499                        }
500                        else
501                        {
502                                $this->template->set_var('delete','&nbsp;');
503                        }
504                        $this->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cat['name']));
505                        $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description']));
506                        $this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id)));
507                        $this->template->set_var('bt_rem_id_group_visibility',$cat['name_group'] ? "visible" : "hidden");
508                        if (!is_object($GLOBALS['phpgw']->html))
509                        {
510                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
511                        }
512                        $this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color')));
513                        $options = '';
514                        //$options = '<option value="aanone.gif"'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n";
515                        foreach ($this->icons as $icon)
516                        {
517                                if(!$cat['data']['icon']){
518                                        $cat['data']['icon'] = "aanone.gif";
519                                }
520                                $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'.
521                                        ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon == 'aanone.gif' ? lang('none') : $icon))."</option>\n";
522                        }
523                        $this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n");
524                        $this->template->set_var('icon',  '<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">');
525
526                        $already_done = array('icon','color');
527
528                        if ($extra)
529                        {
530                                foreach(explode(',',$extra) as $i => $name)
531                                {
532                                        $this->template->set_var('class',($i & 1) ? 'row_on' : 'row_off');
533                                        $this->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">');
534                                        $this->template->set_var('lang_data',lang($name));
535                                        $this->template->fp('row','data_row',True);
536                                        $already_done[] = $name;
537                                }
538                        }
539                        // preserv everything in the data array, not already shown via extra
540                        if (is_array($cat['data']))
541                        {
542                                foreach($cat['data'] as $name => $value)
543                                {
544                                        if (!in_array($name,$already_done))
545                                        {
546                                                $hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">';
547                                        }
548                                }
549                        }
550                        $this->template->set_var('hidden_vars',$hidden_vars);
551
552                        //$GLOBALS['phpgw']->common->phpgw_header();
553                        //echo parse_navbar();
554
555                        $this->template->pfp('out','form');
556                }
557
558                function delete()
559                {
560                        if (!$this->acl_delete)
561                        {
562                                $GLOBALS['phpgw']->redirect_link('/#');
563                        }
564                        $link_data = array
565                        (
566                                'menuaction'    => 'admin.uicategories.index',
567                                'appname'               => $this->appname
568                        );
569
570                        if (!$this->cat_id || $_POST['cancel'])
571                        {
572                                $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ] .= "<script>ExpressoLivre.link( '{$GLOBALS[ 'phpgw' ] -> link('/index.php',$link_data)}' );</script>";
573                                exit;
574                        }
575
576                        if ($_POST['confirm'])
577                        {
578                                if ($_POST['subs'])
579                                {
580                                        $this->bo->delete($this->cat_id,True);
581                                }
582                                else
583                                {
584                                        $this->bo->delete($this->cat_id,False);
585                                }
586                                $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script' ] .= "<script>ExpressoLivre.link( '{$GLOBALS[ 'phpgw' ] -> link('/index.php',$link_data)}' );</script>";
587                                exit;
588                        }
589                        $this->template->set_file(array('category_delete' => 'delete_cat.tpl'));
590
591                        $this -> template -> set_var( 'no_button', $GLOBALS[ 'phpgw' ] -> link( '/index.php', $link_data ) );
592
593                        if ($this->appname)
594                        {
595                                $type = 'noglobalapp';
596                        }
597                        else
598                        {
599                                $type = 'noglobal';
600                        }
601
602                        $apps_cats = $this->bo->exists(array
603                        (
604                                'type'     => $type,
605                                'cat_name' => '',
606                                'cat_id'   => $this->cat_id
607                        ));
608
609                        $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Delete category');
610                        if(!@is_object($GLOBALS['phpgw']->js))
611                        {
612                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
613                        }
614                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
615                        //$GLOBALS['phpgw']->common->phpgw_header();
616                        //echo parse_navbar();
617
618                        $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n";
619                        $this->template->set_var('hidden_vars',$hidden_vars);
620
621                        $cats = $this->bo->cats->return_single($this->cat_id);
622                        $this->template->set_var('cat_name',$cat['name']);
623                       
624                        if ($apps_cats)
625                        {
626                                $this->template->set_block('category_delete','delete','deletehandle');
627                                $this->template->set_var('messages',lang('This category is currently being used by applications as a parent category') . '<br>'
628                                        . lang('You will need to remove the subcategories before you can delete this category'));
629
630                                $this->template->set_var('lang_subs','');
631                                $this->template->set_var('subs','');
632                                $this->template->set_var('nolink',$nolink);
633                                $this->template->set_var('deletehandle','');
634                                $this->template->set_var('donehandle','');
635                                $this->template->set_var('lang_ok',lang('Ok'));
636                                $this->template->pfp('out','category_delete');
637                        }
638                        else
639                        {
640                                $this->template->set_block('category_delete','done','donehandle');
641                                $this->template->set_var('messages',lang('Are you sure you want to delete this category ?'));
642
643                                $exists = $this->bo->exists(array
644                                (
645                                        'type'     => 'subs',
646                                        'cat_name' => '',
647                                        'cat_id'   => $this->cat_id
648                                ));
649
650                                if ($exists)
651                                {
652                                        $this->template->set_var('lang_subs',lang('Do you also want to delete all global subcategories ?'));
653                                        $this->template->set_var('subs','<input type="checkbox" name="subs" value="True">');
654                                }
655                                else
656                                {
657                                        $this->template->set_var('lang_subs','');
658                                        $this->template->set_var('subs', '');
659                                }
660
661                                $link_data['menuaction'] = 'admin.uicategories.delete';
662                                $link_data['cat_id'] = $this->cat_id;
663                                $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
664                                $this->template->set_var('lang_yes',lang('Yes'));
665                                $this->template->set_var('lang_no',lang('No'));
666                                $this->template->pfp('out','category_delete');
667                        }
668                }
669        }
670?>
Note: See TracBrowser for help on using the repository browser.