[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Preferences - 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 /* $Id: class.uicategories.inc.php 19703 2005-11-09 13:32:40Z ralfbecker $ */ 16 17 class uicategories 18 { 19 var $bo; 20 21 var $start; 22 var $query; 23 var $sort; 24 var $order; 25 var $cat_id; 26 var $referer; 27 28 var $cats_app; 29 30 var $public_functions = array 31 ( 32 'index' => True, 33 'edit' => True, 34 'delete' => True 35 ); 36 37 function uicategories() 38 { 39 $cats_app = get_var('cats_app',array('GET','POST')); 40 41 $this->bo =& CreateObject('preferences.bocategories',$cats_app); 42 $this->nextmatchs =& CreateObject('phpgwapi.nextmatchs'); 43 $this->account = $GLOBALS['egw_info']['user']['account_id']; 44 $this->user = $GLOBALS['egw_info']['user']['fullname']; 45 46 $this->start = $this->bo->start; 47 $this->query = $this->bo->query; 48 $this->sort = $this->bo->sort; 49 $this->order = $this->bo->order; 50 $this->referer = $this->bo->referer; 51 52 $dir = dir(EGW_SERVER_ROOT.'/phpgwapi/images'); 53 while($file = $dir->read()) 54 { 55 if (preg_match('/\\.(png|gif|jpe?g)$/i',$file)) 56 { 57 $this->icons[] = $file; 58 } 59 } 60 $dir->close(); 61 sort($this->icons); 62 $this->img_url = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/images/'; 63 } 64 65 function save_sessiondata($cats_app) 66 { 67 $data = array 68 ( 69 'start' => $this->start, 70 'query' => $this->query, 71 'sort' => $this->sort, 72 'order' => $this->order, 73 'referer' => $this->referer, 74 ); 75 $this->bo->save_sessiondata($data,$cats_app); 76 } 77 78 function set_langs() 79 { 80 $GLOBALS['egw']->template->set_var('lang_access',lang('Private')); 81 $GLOBALS['egw']->template->set_var('lang_save',lang('Save')); 82 $GLOBALS['egw']->template->set_var('user_name',$this->user); 83 $GLOBALS['egw']->template->set_var('lang_search',lang('Search')); 84 $GLOBALS['egw']->template->set_var('lang_cancel',lang('Cancel')); 85 $GLOBALS['egw']->template->set_var('lang_sub',lang('Add sub')); 86 $GLOBALS['egw']->template->set_var('lang_edit',lang('Edit')); 87 $GLOBALS['egw']->template->set_var('lang_delete',lang('Delete')); 88 $GLOBALS['egw']->template->set_var('lang_parent',lang('Parent category')); 89 $GLOBALS['egw']->template->set_var('lang_none',lang('None')); 90 $GLOBALS['egw']->template->set_var('lang_name',lang('Name')); 91 $GLOBALS['egw']->template->set_var('lang_descr',lang('Description')); 92 $GLOBALS['egw']->template->set_var('lang_add',lang('Add')); 93 $GLOBALS['egw']->template->set_var('lang_reset',lang('Clear Form')); 94 $GLOBALS['egw']->template->set_var('lang_color',lang('Color')); 95 $GLOBALS['egw']->template->set_var('lang_icon',lang('Icon')); 96 } 97 98 function cat_data($edata,$data) 99 { 100 foreach ($edata as $name) 101 { 102 $td_data .= '<td>' . ($name == 'icon' && $data['icon'] ? '<img src="'.$this->img_url.$data['icon'].'">' : $data[$name]) . '</td>' . "\n"; 103 } 104 return $td_data; 105 } 106 107 function index() 108 { 109 $cats_app = get_var('cats_app',array('GET','POST')); 110 $extra = get_var('extra',array('GET','POST')); 111 $global_cats = get_var('global_cats',array('GET','POST')); 112 $cats_level = get_var('cats_level',array('GET','POST')); 113 114 // make categories called via sidebox menu of an app, to behave like a part of that app 115 $referer = $GLOBALS['egw']->common->get_referer('/preferences/index.php'); 116 if (!strstr($referer,'menuaction=preferences.uicategories')) 117 { 118 $this->referer = $referer; 119 } 120 if ($this->referer != '/preferences/index.php') 121 { 122 $GLOBALS['egw_info']['flags']['currentapp'] = $cats_app; 123 } 124 125 $link_data = array 126 ( 127 'menuaction' => 'preferences.uicategories.index', 128 'cats_app' => $cats_app, 129 'extra' => $extra, 130 'global_cats' => $global_cats, 131 'cats_level' => $cats_level 132 ); 133 134 if($extra) 135 { 136 $edata = explode(',',$extra); 137 } 138 else 139 { 140 $edata = array('icon'); 141 } 142 $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$cats_app]['title']. 143 ' '.lang('categories for').': '.$this->user; 144 $GLOBALS['egw']->common->egw_header(); 145 echo parse_navbar(); 146 147 $GLOBALS['egw']->template->set_file(array( 148 'cat_list_t' => 'listcats.tpl', 149 )); 150 $GLOBALS['egw']->template->set_block('cat_list_t','cat_list','list'); 151 152 $this->set_langs(); 153 154 $GLOBALS['egw']->template->set_var('title_categories',lang('categories for')); 155 $GLOBALS['egw']->template->set_var('lang_app',lang($cats_app)); 156 $GLOBALS['egw']->template->set_var('actionurl',$GLOBALS['egw']->link('/index.php',$link_data)); 157 $GLOBALS['egw']->template->set_var('doneurl',$GLOBALS['egw']->link($this->referer)); 158 159 if(!$this->start) 160 { 161 $this->start = 0; 162 } 163 164 if(!$global_cats) 165 { 166 $global_cats = False; 167 } 168 169 $cats = $this->bo->get_list($global_cats); 170 if (!is_array($cats)) $cats = array(); 171 172 //--------------------------------- nextmatch -------------------------------------------- 173 174 $left = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,$link_data); 175 $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,$link_data); 176 $GLOBALS['egw']->template->set_var('left',$left); 177 $GLOBALS['egw']->template->set_var('right',$right); 178 179 $GLOBALS['egw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start)); 180 181 // ------------------------------ end nextmatch ------------------------------------------ 182 183 //------------------- list header variable template-declarations ------------------------- 184 185 $GLOBALS['egw']->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data)); 186 $GLOBALS['egw']->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data)); 187 188 if (is_array($edata)) 189 { 190 for($i=0;$i<count($edata);$i++) 191 { 192 $GLOBALS['egw']->template->set_var('sort_data','<td class="th">' . lang($edata[$i]) . '</td>'); 193 } 194 } 195 else 196 { 197 $GLOBALS['egw']->template->set_var('th_data',''); 198 } 199 200 // -------------------------- end header declaration -------------------------------------- 201 202 foreach($cats as $cat) 203 { 204 $data = unserialize($cat['data']); 205 206 if ($data['color']) 207 { 208 $GLOBALS['egw']->template->set_var('tr_color',$data['color']); 209 $gray = (hexdec(substr($data['color'],1,2))+hexdec(substr($data['color'],3,2))+hexdec(substr($data['color'],5,2)))/3; 210 } 211 else 212 { 213 $this->nextmatchs->template_alternate_row_color($GLOBALS['egw']->template); 214 $gray = 255; 215 } 216 $GLOBALS['egw']->template->set_var('color',$gray < 128 ? 'style="color: white;"' : ''); 217 218 if ($cat['app_name'] == 'phpgw') 219 { 220 $appendix = '<' . lang('Global') . '>'; 221 } 222 elseif ($cat['owner'] == '-1') 223 { 224 $appendix = '<' . lang('Global') . ' ' . $GLOBALS['egw_info']['apps'][$cats_app]['title'] . '>'; 225 } 226 else 227 { 228 $appendix = ''; 229 } 230 231 $level = $cat['level']; 232 233 if ($level > 0) 234 { 235 $space = ' '; 236 $spaceset = str_repeat($space,$level); 237 $name = $spaceset . $GLOBALS['egw']->strip_html($cat['name']) . $appendix; 238 } 239 240 $descr = $GLOBALS['egw']->strip_html($cat['description']); 241 if (!$descr) { $descr = ' '; } 242 243 if (is_array($edata)) 244 { 245 if (!is_array($data)) 246 { 247 $holder = '<td> </td>' . "\n"; 248 $placeholder = str_repeat($holder,count($edata)); 249 $GLOBALS['egw']->template->set_var('td_data',$placeholder); 250 } 251 else 252 { 253 $GLOBALS['egw']->template->set_var('td_data',$this->cat_data($edata,$data)); 254 } 255 } 256 257 if ($level == 0) 258 { 259 $name = '<font color="FF0000"><b>' . $GLOBALS['egw']->strip_html($cat['name']) . '</b></font>' . $appendix; 260 $descr = '<font color="FF0000"><b>' . $descr . '</b></font>'; 261 } 262 263 $GLOBALS['egw']->template->set_var(array( 264 'name' => $name, 265 'descr' => $descr 266 )); 267 268 $GLOBALS['egw']->template->set_var('app_url',$GLOBALS['egw']->link('/' . $cats_app . '/index.php','cat_id=' . $cat['id'])); 269 270 if ($cats_level || ($level == 0)) 271 { 272 if ($cat['owner'] == $this->account || $cat['app_name'] == 'phpgw') 273 { 274 $link_data['menuaction'] = 'preferences.uicategories.edit'; 275 $link_data['cat_parent'] = $cat['id']; 276 unset($link_data['cat_id']); 277 $GLOBALS['egw']->template->set_var('add_sub',$GLOBALS['egw']->link('/index.php',$link_data)); 278 $GLOBALS['egw']->template->set_var('lang_sub_entry',lang('Add sub')); 279 } 280 } 281 else 282 { 283 $GLOBALS['egw']->template->set_var('add_sub',''); 284 $GLOBALS['egw']->template->set_var('lang_sub_entry',' '); 285 } 286 287 $link_data['cat_id'] = $cat['id']; 288 if ($cat['owner'] == $this->account && $cat['app_name'] != 'phpgw') 289 { 290 $link_data['menuaction'] = 'preferences.uicategories.edit'; 291 $GLOBALS['egw']->template->set_var('edit',$GLOBALS['egw']->link('/index.php',$link_data)); 292 $GLOBALS['egw']->template->set_var('lang_edit_entry',lang('Edit')); 293 294 $link_data['menuaction'] = 'preferences.uicategories.delete'; 295 $GLOBALS['egw']->template->set_var('delete',$GLOBALS['egw']->link('/index.php',$link_data)); 296 $GLOBALS['egw']->template->set_var('lang_delete_entry',lang('Delete')); 297 } 298 else 299 { 300 $GLOBALS['egw']->template->set_var('edit',''); 301 $GLOBALS['egw']->template->set_var('lang_edit_entry',' '); 302 303 $GLOBALS['egw']->template->set_var('delete',''); 304 $GLOBALS['egw']->template->set_var('lang_delete_entry',' '); 305 } 306 $GLOBALS['egw']->template->fp('list','cat_list',True); 307 } 308 $link_data['menuaction'] = 'preferences.uicategories.edit'; 309 unset($link_data['cat_id']); 310 unset($link_data['cat_parent']); 311 $GLOBALS['egw']->template->set_var('add_action',$GLOBALS['egw']->link('/index.php',$link_data)); 312 $this->save_sessiondata($cats_app); 313 314 $GLOBALS['egw']->template->pfp('out','cat_list_t',True); 315 } 316 317 function edit() 318 { 319 $cats_app = get_var('cats_app',array('GET','POST')); 320 $extra = get_var('extra',array('GET','POST')); 321 $global_cats = get_var('global_cats',array('GET','POST')); 322 $cats_level = get_var('cats_level',array('GET','POST')); 323 $cat_id = get_var('cat_id',array('GET','POST')); 324 325 $link_data = array 326 ( 327 'menuaction' => 'preferences.uicategories.index', 328 'cats_app' => $cats_app, 329 'extra' => $extra, 330 'global_cats' => $global_cats, 331 'cats_level' => $cats_level, 332 'cat_id' => $cat_id 333 ); 334 $new_parent = $_POST['new_parent']; 335 $cat_parent = $_POST['cat_parent']; 336 $cat_name = $_POST['cat_name']; 337 $cat_description = $_POST['cat_description']; 338 $cat_data = $_POST['cat_data']; 339 $cat_access = $_POST['cat_access']; 340 $old_parent = $_POST['old_parent']; 341 342 $GLOBALS['egw']->template->set_file(array('form' => 'category_form.tpl')); 343 $GLOBALS['egw']->template->set_block('form','data_row','row'); 344 $GLOBALS['egw']->template->set_block('form','add','addhandle'); 345 $GLOBALS['egw']->template->set_block('form','edit','edithandle'); 346 347 $this->set_langs(); 348 $GLOBALS['egw']->template->set_var('cancel_url',$GLOBALS['egw']->link('/index.php',$link_data)); 349 350 if ($new_parent) 351 { 352 $cat_parent = $new_parent; 353 } 354 355 if (!$global_cats) 356 { 357 $global_cats = False; 358 } 359 360 if ($_POST['save']) 361 { 362 $values = array 363 ( 364 'id' => (int)$cat_id, 365 'parent' => $cat_parent, 366 'descr' => $cat_description, 367 'name' => $cat_name, 368 'access' => $cat_access, 369 'data' => serialize($cat_data), 370 ); 371 if ((int)$cat_id) 372 { 373 $values['id'] = (int)$cat_id; 374 $values['old_parent'] = $old_parent; 375 } 376 377 $error = $this->bo->check_values($values); 378 if (is_array($error)) 379 { 380 $GLOBALS['egw']->template->set_var('message',$GLOBALS['egw']->common->error_list($error)); 381 } 382 else 383 { 384 $cat_id = $this->bo->save_cat($values); 385 return $this->index(); 386 //$GLOBALS['egw']->template->set_var('message',lang('Category %1 has been updated !',$cat_name)); 387 } 388 } 389 390 if ($cat_id) 391 { 392 list($cat) = $this->bo->cats->return_single($cat_id); 393 $cat['data'] = unserialize($cat['data']); 394 } 395 else 396 { 397 $cat = array(); 398 $cat['parent'] = $_GET['cat_parent']; 399 } 400 // update the old calendar color format, color was added to the description 401 if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches)) 402 { 403 $cat['data']['color'] = $matches[1]; 404 $cat['description'] = str_replace($matches[1],'',$cat['description']); 405 } 406 407 $link_data['menuaction'] = 'preferences.uicategories.edit'; 408 $GLOBALS['egw']->template->set_var('actionurl',$GLOBALS['egw']->link('/index.php',$link_data)); 409 410 $GLOBALS['egw']->template->set_var('cat_name',$GLOBALS['egw']->strip_html($cat['name'])); 411 $GLOBALS['egw']->template->set_var('cat_description',$GLOBALS['egw']->strip_html($cat['description'])); 412 413 $hidden_vars = '<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">'; 414 415 if ($cats_level) 416 { 417 $type = 'all'; 418 } 419 else 420 { 421 $type = 'mains'; 422 } 423 424 $GLOBALS['egw']->template->set_var('category_list',$this->bo->cats->formated_list(array( 425 'type' => $type,'selected' => $cat['parent'], 426 'globals' => $global_cats, 'self' => $cat_id 427 ))); 428 429 $GLOBALS['egw']->template->set_var('access','<input type="checkbox" name="cat_access" value="True"' 430 . ($cat['access'] == 'private' ? ' checked' : '') . '>'); 431 432 if (!is_object($GLOBALS['egw']->html)) 433 { 434 $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); 435 } 436 $GLOBALS['egw']->template->set_var('color',$GLOBALS['egw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color'))); 437 438 $options = '<option value=""'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n"; 439 foreach ($this->icons as $icon) 440 { 441 $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'. 442 ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon))."</option>\n"; 443 } 444 $GLOBALS['egw']->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n"); 445 $GLOBALS['egw']->template->set_var('icon','<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">'); 446 447 $already_done = array('icon','color'); 448 449 if ($extra) 450 { 451 foreach(explode(',',$extra) as $i => $name) 452 { 453 $GLOBALS['egw']->template->set_var('class',($i & 1) ? 'row_on' : 'row_off'); 454 $GLOBALS['egw']->template->set_var('td_data','<input name="cat_data[' . htmlspecialchars($name) . ']" size="50" value="' . htmlspecialchars($cat['data'][$name]) . '">'); 455 $GLOBALS['egw']->template->set_var('lang_data',lang($name)); 456 $GLOBALS['egw']->template->fp('row','data_row',True); 457 $already_done[] = $name; 458 } 459 } 460 // preserv everything in the data array, not already shown via extra 461 if (is_array($cat['data'])) 462 { 463 foreach($cat['data'] as $name => $value) 464 { 465 if (!in_array($name,$already_done)) 466 { 467 $hidden_vars .= '<input type="hidden" name="cat_data['.htmlspecialchars($name).']" value="' . htmlspecialchars($value) . '">'; 468 } 469 } 470 } 471 $GLOBALS['egw']->template->set_var('hidden_vars',$hidden_vars); 472 473 if ($cat['owner'] == $this->account) 474 { 475 $link_data['menuaction'] = 'preferences.uicategories.delete'; 476 $GLOBALS['egw']->template->set_var('delete','<form method="POST" action="' . $GLOBALS['egw']->link('/index.php',$link_data) 477 . '"><input type="submit" value="' . lang('Delete') .'"></form>'); 478 } 479 else 480 { 481 $GLOBALS['egw']->template->set_var('delete',' '); 482 } 483 484 $GLOBALS['egw_info']['flags']['app_header'] = lang($cat_id ? 'Edit %1 category for' : 'Add %1 category for', 485 $GLOBALS['egw_info']['apps'][$cats_app]['title']).': '.$this->user; 486 $GLOBALS['egw']->common->egw_header(); 487 echo parse_navbar(); 488 489 $GLOBALS['egw']->template->set_var('edithandle',''); 490 $GLOBALS['egw']->template->set_var('addhandle',''); 491 $GLOBALS['egw']->template->pfp('out','form'); 492 $GLOBALS['egw']->template->pfp('edithandle','edit'); 493 } 494 495 function delete() 496 { 497 $cats_app = get_var('cats_app',array('GET','POST')); 498 $extra = get_var('extra',array('GET','POST')); 499 $global_cats = get_var('global_cats',array('GET','POST')); 500 $cats_level = get_var('cats_level',array('GET','POST')); 501 $cat_id = get_var('cat_id',array('GET','POST')); 502 503 $link_data = array 504 ( 505 'menuaction' => 'preferences.uicategories.index', 506 'cats_app' => $cats_app, 507 'extra' => $extra, 508 'global_cats' => $global_cats, 509 'cats_level' => $cats_level, 510 'cat_id' => $cat_id 511 ); 512 513 if (!$cat_id || $_POST['cancel']) 514 { 515 $GLOBALS['egw']->redirect_link('/index.php',$link_data); 516 } 517 518 if ($_POST['confirm']) 519 { 520 if ($_POST['subs']) 521 { 522 $this->bo->delete($cat_id,True); 523 } 524 else 525 { 526 $this->bo->delete($cat_id,False); 527 } 528 $GLOBALS['egw']->redirect_link('/index.php',$link_data); 529 } 530 else 531 { 532 $GLOBALS['egw']->template->set_file(array('category_delete' => 'delete.tpl')); 533 534 $GLOBALS['egw_info']['flags']['app_header'] = lang('Delete Categories'); 535 $GLOBALS['egw']->common->egw_header(); 536 echo parse_navbar(); 537 538 $GLOBALS['egw']->template->set_var('deleteheader',lang('Are you sure you want to delete this category ?')); 539 540 $exists = $this->bo->exists(array 541 ( 542 'type' => 'subs', 543 'cat_name' => '', 544 'cat_id' => $cat_id 545 )); 546 547 if ($exists) 548 { 549 $GLOBALS['egw']->template->set_var('lang_subs',lang('Do you also want to delete all subcategories ?')); 550 $GLOBALS['egw']->template->set_var('subs','<input type="checkbox" name="subs" value="True">'); 551 } 552 else 553 { 554 $GLOBALS['egw']->template->set_var('lang_subs',''); 555 $GLOBALS['egw']->template->set_var('subs', ''); 556 } 557 558 $GLOBALS['egw']->template->set_var('lang_no',lang('No')); 559 $link_data['menuaction'] = 'preferences.uicategories.delete'; 560 $GLOBALS['egw']->template->set_var('action_url',$GLOBALS['egw']->link('/index.php',$link_data)); 561 $GLOBALS['egw']->template->set_var('lang_yes',lang('Yes')); 562 $GLOBALS['egw']->template->pfp('out','category_delete'); 563 } 564 } 565 } 566 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |