[2] | 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 | while($file = $dir->read()) |
---|
| 72 | { |
---|
| 73 | if (preg_match('/\\.(png|gif|jpe?g)$/i',$file)) |
---|
| 74 | { |
---|
| 75 | $this->icons[] = $file; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | $dir->close(); |
---|
| 79 | sort($this->icons); |
---|
| 80 | $this->img_url = $GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/images/'; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | function _debug_sqsof() |
---|
| 84 | { |
---|
| 85 | $data = array( |
---|
| 86 | 'start' => $this->start, |
---|
| 87 | 'query' => $this->query, |
---|
| 88 | 'sort' => $this->sort, |
---|
| 89 | 'order' => $this->order, |
---|
| 90 | 'cat_id' => $this->cat_id |
---|
| 91 | ); |
---|
| 92 | echo '<br>UI:<br>'; |
---|
| 93 | _debug_array($data); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | function save_sessiondata() |
---|
| 97 | { |
---|
| 98 | $data = array |
---|
| 99 | ( |
---|
| 100 | 'start' => $this->start, |
---|
| 101 | 'query' => $this->query, |
---|
| 102 | 'sort' => $this->sort, |
---|
| 103 | 'order' => $this->order |
---|
| 104 | ); |
---|
| 105 | |
---|
| 106 | if(isset($this->cat_id)) |
---|
| 107 | { |
---|
| 108 | $data['cat_id'] = $this->cat_id; |
---|
| 109 | } |
---|
| 110 | $this->bo->save_sessiondata($data); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | function set_langs() |
---|
| 114 | { |
---|
| 115 | $this->template->set_var('lang_save',lang('Save')); |
---|
| 116 | $this->template->set_var('lang_search',lang('Search')); |
---|
| 117 | $this->template->set_var('lang_sub',lang('Add sub')); |
---|
| 118 | $this->template->set_var('lang_icon',lang('icon')); |
---|
| 119 | $this->template->set_var('lang_edit',lang('Edit')); |
---|
| 120 | $this->template->set_var('lang_delete',lang('Delete')); |
---|
| 121 | $this->template->set_var('lang_parent',lang('Parent category')); |
---|
| 122 | $this->template->set_var('lang_none',lang('None')); |
---|
| 123 | $this->template->set_var('lang_name',lang('Name')); |
---|
| 124 | $this->template->set_var('lang_descr',lang('Description')); |
---|
| 125 | $this->template->set_var('lang_add',lang('Add')); |
---|
| 126 | $this->template->set_var('lang_reset',lang('Clear Form')); |
---|
| 127 | $this->template->set_var('lang_cancel',lang('Cancel')); |
---|
| 128 | $this->template->set_var('lang_done',lang('Done')); |
---|
| 129 | $this->template->set_var('lang_color',lang('Color')); |
---|
| 130 | $this->template->set_var('lang_icon',lang('Icon')); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function index() |
---|
| 134 | { |
---|
| 135 | $link_data = array |
---|
| 136 | ( |
---|
| 137 | 'menuaction' => 'admin.uicategories.edit', |
---|
| 138 | 'appname' => $this->appname |
---|
| 139 | ); |
---|
| 140 | |
---|
| 141 | if ($_POST['add']) |
---|
| 142 | { |
---|
| 143 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | if ($_POST['done']) |
---|
| 147 | { |
---|
| 148 | $GLOBALS['phpgw']->redirect_link('/admin/index.php'); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | $this->template->set_file(array('cat_list_t' => 'listcats.tpl')); |
---|
| 152 | $this->template->set_block('cat_list_t','cat_list','list'); |
---|
| 153 | if (!$this->acl_add) |
---|
| 154 | { |
---|
| 155 | $this->template->set_block('cat_list_t','add','addhandle'); |
---|
| 156 | } |
---|
| 157 | if (!$this->acl_search) |
---|
| 158 | { |
---|
| 159 | $this->template->set_block('cat_list_t','search','searchhandle'); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Global categories'); |
---|
| 163 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 164 | echo parse_navbar(); |
---|
| 165 | $this->set_langs(); |
---|
| 166 | $this->template->set_var('query',$this->query); |
---|
| 167 | |
---|
| 168 | $link_data['menuaction'] = 'admin.uicategories.index'; |
---|
| 169 | $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
| 170 | |
---|
| 171 | if(!$start) |
---|
| 172 | { |
---|
| 173 | $start = 0; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | $cats = $this->bo->get_list(); |
---|
| 177 | if (!is_array($cats)) $cats = array(); |
---|
| 178 | |
---|
| 179 | $left = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,$link_data); |
---|
| 180 | $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,$link_data); |
---|
| 181 | $this->template->set_var('left',$left); |
---|
| 182 | $this->template->set_var('right',$right); |
---|
| 183 | |
---|
| 184 | $this->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start)); |
---|
| 185 | |
---|
| 186 | $this->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data)); |
---|
| 187 | $this->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data)); |
---|
| 188 | |
---|
| 189 | foreach($cats as $cat) |
---|
| 190 | { |
---|
| 191 | $data = unserialize($cat['data']); |
---|
| 192 | |
---|
| 193 | if ($data['color']) |
---|
| 194 | { |
---|
| 195 | $this->template->set_var('tr_color',$data['color']); |
---|
| 196 | $gray = (hexdec(substr($data['color'],1,2))+hexdec(substr($data['color'],3,2))+hexdec(substr($data['color'],5,2)))/3; |
---|
| 197 | } |
---|
| 198 | else |
---|
| 199 | { |
---|
| 200 | $this->nextmatchs->template_alternate_row_color($this->template); |
---|
| 201 | $gray = 255; |
---|
| 202 | } |
---|
| 203 | $this->template->set_var('color',$gray < 128 ? 'style="color: white;"' : ''); |
---|
| 204 | |
---|
| 205 | $id = $cat['id']; |
---|
| 206 | $level = $cat['level']; |
---|
| 207 | $cat_name = $GLOBALS['phpgw']->strip_html($cat['name']); |
---|
| 208 | |
---|
| 209 | if ($level > 0) |
---|
| 210 | { |
---|
| 211 | $space = ' '; |
---|
| 212 | $spaceset = str_repeat($space,$level); |
---|
| 213 | $cat_name = $spaceset . $cat_name; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | $descr = $GLOBALS['phpgw']->strip_html($cat['description']); |
---|
| 217 | if (!$descr) { $descr = ' '; } |
---|
| 218 | |
---|
| 219 | if ($level == 0) |
---|
| 220 | { |
---|
| 221 | $cat_name = '<font color="FF0000"><b>' . $cat_name . '</b></font>'; |
---|
| 222 | $descr = '<font color="FF0000"><b>' . $descr . '</b></font>'; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | if ($this->appname && $cat['app_name'] == 'phpgw') |
---|
| 226 | { |
---|
| 227 | $appendix = '<' . lang('Global') . '>'; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
| 231 | $appendix = ''; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | $this->template->set_var(array |
---|
| 235 | ( |
---|
| 236 | 'name' => $cat_name . $appendix, |
---|
| 237 | 'descr' => $descr |
---|
| 238 | )); |
---|
| 239 | |
---|
| 240 | if ($this->acl_add_sub) |
---|
| 241 | { |
---|
| 242 | $link_data['menuaction'] = 'admin.uicategories.edit'; |
---|
| 243 | $link_data['cat_parent'] = $id; |
---|
| 244 | unset($link_data['cat_id']); |
---|
| 245 | $this->template->set_var('add_sub','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'. |
---|
| 246 | lang('Add sub').'</a>'); |
---|
| 247 | } |
---|
| 248 | if ($this->appname && $cat['app_name'] == $this->appname) |
---|
| 249 | { |
---|
| 250 | $show_edit_del = True; |
---|
| 251 | } |
---|
| 252 | elseif(!$this->appname && $cat['app_name'] == 'phpgw') |
---|
| 253 | { |
---|
| 254 | $show_edit_del = True; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | $show_edit_del = False; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | $link_data['cat_id'] = $id; |
---|
| 262 | unset($link_data['cat_parent']); |
---|
| 263 | if ($show_edit_del && $this->acl_edit) |
---|
| 264 | { |
---|
| 265 | $link_data['menuaction'] = 'admin.uicategories.edit'; |
---|
| 266 | $this->template->set_var('edit','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'. |
---|
| 267 | lang('Edit').'</a>'); |
---|
| 268 | } |
---|
| 269 | else |
---|
| 270 | { |
---|
| 271 | $this->template->set_var('edit',''); |
---|
| 272 | } |
---|
| 273 | if ($show_edit_del && $this->acl_delete) |
---|
| 274 | { |
---|
| 275 | $link_data['menuaction'] = 'admin.uicategories.delete'; |
---|
| 276 | $this->template->set_var('delete','<a href="'.$GLOBALS['phpgw']->link('/index.php',$link_data).'">'. |
---|
| 277 | lang('Delete').'</a>'); |
---|
| 278 | } |
---|
| 279 | else |
---|
| 280 | { |
---|
| 281 | $this->template->set_var('delete',''); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | $data = unserialize($cat['data']); |
---|
| 285 | $icon = $data['icon']; |
---|
| 286 | $dir_img = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'phpgwapi' . SEP . 'images' . SEP; |
---|
| 287 | $this->template->set_var('icon', "<img src='". $dir_img . $icon ."'>"); |
---|
| 288 | |
---|
| 289 | $this->template->fp('list','cat_list',True); |
---|
| 290 | } |
---|
| 291 | $link_data['menuaction'] = 'admin.uicategories.edit'; |
---|
| 292 | unset($link_data['cat_id']); |
---|
| 293 | unset($link_data['cat_parent']); |
---|
| 294 | $this->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
| 295 | |
---|
| 296 | $this->save_sessiondata(); |
---|
| 297 | $this->template->pfp('out','cat_list_t',True); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | function edit() |
---|
| 301 | { |
---|
| 302 | $new_parent = (int)$_POST['new_parent']; |
---|
| 303 | $cat_parent = (int)$_POST['cat_parent']; |
---|
| 304 | $cat_name = $_POST['cat_name']; |
---|
| 305 | $cat_description = $_POST['cat_description']; |
---|
| 306 | $cat_data = $_POST['cat_data']; |
---|
| 307 | $old_parent = (int)$_POST['old_parent']; |
---|
| 308 | |
---|
| 309 | if ($new_parent) |
---|
| 310 | { |
---|
| 311 | $cat_parent = $new_parent; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | $link_data = array |
---|
| 315 | ( |
---|
| 316 | 'menuaction' => 'admin.uicategories.index', |
---|
| 317 | 'appname' => $this->appname |
---|
| 318 | ); |
---|
| 319 | |
---|
| 320 | if (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0) |
---|
| 321 | { |
---|
| 322 | $GLOBALS['phpgw']->redirect_link('/index.php'); |
---|
| 323 | } |
---|
| 324 | if ($_POST['cancel'] || $this->cat_id && !$this->acl_edit || $this->cat_id && |
---|
| 325 | (!$this->acl_add && $cat_parent == 0 || !$this->acl_add_sub && $cat_parent != 0)) |
---|
| 326 | { |
---|
| 327 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | if ($_POST['save']) |
---|
| 331 | { |
---|
| 332 | $data = serialize($cat_data); |
---|
| 333 | |
---|
| 334 | $values = array |
---|
| 335 | ( |
---|
| 336 | 'parent' => $cat_parent, |
---|
| 337 | 'descr' => $cat_description, |
---|
| 338 | 'name' => $cat_name, |
---|
| 339 | 'access' => 'public', |
---|
| 340 | 'data' => $data |
---|
| 341 | ); |
---|
| 342 | if ($this->cat_id) |
---|
| 343 | { |
---|
| 344 | $values['id'] = $this->cat_id; |
---|
| 345 | $values['old_parent'] = $old_parent; |
---|
| 346 | } |
---|
| 347 | $error = $this->bo->check_values($values); |
---|
| 348 | if (is_array($error)) |
---|
| 349 | { |
---|
| 350 | $this->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error)); |
---|
| 351 | } |
---|
| 352 | else |
---|
| 353 | { |
---|
| 354 | $this->cat_id = $this->bo->save_cat($values); |
---|
| 355 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.($this->cat_id ? lang('Edit global category'):lang('Add global category')); |
---|
| 360 | |
---|
| 361 | $this->set_langs(); |
---|
| 362 | |
---|
| 363 | $this->template->set_file(array('form' => 'category_form.tpl')); |
---|
| 364 | |
---|
| 365 | if ($this->cat_id) |
---|
| 366 | { |
---|
| 367 | list($cat) = $this->bo->cats->return_single($this->cat_id); |
---|
| 368 | $cat['data'] = unserialize($cat['data']); |
---|
| 369 | } |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | $cat = array(); |
---|
| 373 | $cat['parent'] = $_GET['cat_parent']; |
---|
| 374 | } |
---|
| 375 | // update the old calendar color format, color was added to the description |
---|
| 376 | if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches)) |
---|
| 377 | { |
---|
| 378 | $cat['data']['color'] = $matches[1]; |
---|
| 379 | $cat['description'] = str_replace($matches[1],'',$cat['description']); |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n" . |
---|
| 383 | '<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">' . "\n"; |
---|
| 384 | |
---|
| 385 | $link_data['menuaction'] = 'admin.uicategories.edit'; |
---|
| 386 | $link_data['cat_id'] = $this->cat_id; |
---|
| 387 | $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
| 388 | |
---|
| 389 | if ($this->acl_delete) |
---|
| 390 | { |
---|
| 391 | $link_data['menuaction'] = 'admin.uicategories.delete'; |
---|
| 392 | |
---|
| 393 | $this->template->set_var('delete','<form method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data) |
---|
| 394 | . '"><input type="submit" value="' . lang('Delete') .'"></form>'); |
---|
| 395 | } |
---|
| 396 | else |
---|
| 397 | { |
---|
| 398 | $this->template->set_var('delete',' '); |
---|
| 399 | } |
---|
| 400 | $this->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cat['name'])); |
---|
| 401 | $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description'])); |
---|
| 402 | $this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id))); |
---|
| 403 | |
---|
| 404 | if (!is_object($GLOBALS['phpgw']->html)) |
---|
| 405 | { |
---|
| 406 | $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html'); |
---|
| 407 | } |
---|
| 408 | $this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color'))); |
---|
| 409 | |
---|
| 410 | $options = '<option value=""'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n"; |
---|
| 411 | foreach ($this->icons as $icon) |
---|
| 412 | { |
---|
| 413 | $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'. |
---|
| 414 | ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon))."</option>\n"; |
---|
| 415 | } |
---|
| 416 | $this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n"); |
---|
| 417 | $this->template->set_var('icon','<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">'); |
---|
| 418 | |
---|
| 419 | $already_done = array('icon','color'); |
---|
| 420 | |
---|
| 421 | if ($extra) |
---|
| 422 | { |
---|
| 423 | foreach(explode(',',$extra) as $i => $name) |
---|
| 424 | { |
---|
| 425 | $this->template->set_var('class',($i & 1) ? 'row_on' : 'row_off'); |
---|
| 426 | $this->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">'); |
---|
| 427 | $this->template->set_var('lang_data',lang($name)); |
---|
| 428 | $this->template->fp('row','data_row',True); |
---|
| 429 | $already_done[] = $name; |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | // preserv everything in the data array, not already shown via extra |
---|
| 433 | if (is_array($cat['data'])) |
---|
| 434 | { |
---|
| 435 | foreach($cat['data'] as $name => $value) |
---|
| 436 | { |
---|
| 437 | if (!in_array($name,$already_done)) |
---|
| 438 | { |
---|
| 439 | $hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">'; |
---|
| 440 | } |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | $this->template->set_var('hidden_vars',$hidden_vars); |
---|
| 444 | |
---|
| 445 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 446 | echo parse_navbar(); |
---|
| 447 | |
---|
| 448 | $this->template->pfp('out','form'); |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | function delete() |
---|
| 452 | { |
---|
| 453 | if (!$this->acl_delete) |
---|
| 454 | { |
---|
| 455 | $GLOBALS['phpgw']->redirect_link('/index.php'); |
---|
| 456 | } |
---|
| 457 | $link_data = array |
---|
| 458 | ( |
---|
| 459 | 'menuaction' => 'admin.uicategories.index', |
---|
| 460 | 'appname' => $this->appname |
---|
| 461 | ); |
---|
| 462 | |
---|
| 463 | if (!$this->cat_id || $_POST['cancel']) |
---|
| 464 | { |
---|
| 465 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | if ($_POST['confirm']) |
---|
| 469 | { |
---|
| 470 | if ($_POST['subs']) |
---|
| 471 | { |
---|
| 472 | $this->bo->delete($this->cat_id,True); |
---|
| 473 | } |
---|
| 474 | else |
---|
| 475 | { |
---|
| 476 | $this->bo->delete($this->cat_id,False); |
---|
| 477 | } |
---|
| 478 | $GLOBALS['phpgw']->redirect_link('/index.php',$link_data); |
---|
| 479 | } |
---|
| 480 | $this->template->set_file(array('category_delete' => 'delete_cat.tpl')); |
---|
| 481 | |
---|
| 482 | if ($this->appname) |
---|
| 483 | { |
---|
| 484 | $type = 'noglobalapp'; |
---|
| 485 | } |
---|
| 486 | else |
---|
| 487 | { |
---|
| 488 | $type = 'noglobal'; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | $apps_cats = $this->bo->exists(array |
---|
| 492 | ( |
---|
| 493 | 'type' => $type, |
---|
| 494 | 'cat_name' => '', |
---|
| 495 | 'cat_id' => $this->cat_id |
---|
| 496 | )); |
---|
| 497 | |
---|
| 498 | $GLOBALS['phpgw_info']['flags']['app_header'] .= ' - '.lang('Delete category'); |
---|
| 499 | if(!@is_object($GLOBALS['phpgw']->js)) |
---|
| 500 | { |
---|
| 501 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
| 502 | } |
---|
| 503 | $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin'); |
---|
| 504 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 505 | echo parse_navbar(); |
---|
| 506 | |
---|
| 507 | $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n"; |
---|
| 508 | $this->template->set_var('hidden_vars',$hidden_vars); |
---|
| 509 | |
---|
| 510 | $cats = $this->bo->cats->return_single($this->cat_id); |
---|
| 511 | $this->template->set_var('cat_name',$cat['name']); |
---|
| 512 | |
---|
| 513 | if ($apps_cats) |
---|
| 514 | { |
---|
| 515 | $this->template->set_block('category_delete','delete','deletehandle'); |
---|
| 516 | $this->template->set_var('messages',lang('This category is currently being used by applications as a parent category') . '<br>' |
---|
| 517 | . lang('You will need to remove the subcategories before you can delete this category')); |
---|
| 518 | |
---|
| 519 | $this->template->set_var('lang_subs',''); |
---|
| 520 | $this->template->set_var('subs',''); |
---|
| 521 | $this->template->set_var('nolink',$nolink); |
---|
| 522 | $this->template->set_var('deletehandle',''); |
---|
| 523 | $this->template->set_var('donehandle',''); |
---|
| 524 | $this->template->set_var('lang_ok',lang('Ok')); |
---|
| 525 | $this->template->pfp('out','category_delete'); |
---|
| 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
| 529 | $this->template->set_block('category_delete','done','donehandle'); |
---|
| 530 | $this->template->set_var('messages',lang('Are you sure you want to delete this category ?')); |
---|
| 531 | |
---|
| 532 | $exists = $this->bo->exists(array |
---|
| 533 | ( |
---|
| 534 | 'type' => 'subs', |
---|
| 535 | 'cat_name' => '', |
---|
| 536 | 'cat_id' => $this->cat_id |
---|
| 537 | )); |
---|
| 538 | |
---|
| 539 | if ($exists) |
---|
| 540 | { |
---|
| 541 | $this->template->set_var('lang_subs',lang('Do you also want to delete all global subcategories ?')); |
---|
| 542 | $this->template->set_var('subs','<input type="checkbox" name="subs" value="True">'); |
---|
| 543 | } |
---|
| 544 | else |
---|
| 545 | { |
---|
| 546 | $this->template->set_var('lang_subs',''); |
---|
| 547 | $this->template->set_var('subs', ''); |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | $link_data['menuaction'] = 'admin.uicategories.delete'; |
---|
| 551 | $link_data['cat_id'] = $this->cat_id; |
---|
| 552 | $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); |
---|
| 553 | $this->template->set_var('lang_yes',lang('Yes')); |
---|
| 554 | $this->template->set_var('lang_no',lang('No')); |
---|
| 555 | $this->template->pfp('out','category_delete'); |
---|
| 556 | } |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | ?> |
---|