| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /** 3 * eGroupWare - resources 4 * 5 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License 6 * @package resources 7 * @link http://www.egroupware.org 8 * @author Cornelius Weiss <egw@von-und-zu-weiss.de> 9 * @author Lukas Weiss <wnz_gh05t@users.sourceforge.net> 10 * @version $Id: class.ui_resources.inc.php 21604 2006-05-18 15:29:34Z nelius_weiss $ 11 */ 12 13 /** 14 * General userinterface object for resources 15 * 16 * @package resources 17 */ 18 class ui_resources 19 { 20 var $public_functions = array( 21 'index' => True, 22 'edit' => True, 23 'show' => True, 24 'select' => True, 25 'admin' => True, 26 'writeLangFile' => True 27 ); 28 29 /** 30 * constructor of class ui_resources 31 * 32 */ 33 function ui_resources() 34 { 35 // print_r($GLOBALS['egw_info']); die(); 36 $this->tmpl =& CreateObject('etemplate.etemplate','resources.show'); 37 $this->bo =& CreateObject('resources.bo_resources'); 38 $this->html =& $GLOBALS['egw']->html; 39 // $this->calui = CreateObject('resources.ui_calviews'); 40 41 if(!@is_object($GLOBALS['egw']->js)) 42 { 43 $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript'); 44 } 45 } 46 47 /** 48 * main resources list. 49 * 50 * Cornelius Weiss <egw@von-und-zu-weiss.de> 51 * @param array $content content from eTemplate callback 52 * 53 * FIXME don't translate cats in nextmach 54 */ 55 function index($content='') 56 { 57 if (is_array($content)) 58 { 59 $sessiondata = $content['nm']; 60 unset($sessiondata['rows']); 61 $GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata); 62 63 if (isset($content['back'])) 64 { 65 unset($sessiondata['view_accs_of']); 66 $GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata); 67 return $this->index(); 68 } 69 if (isset($content['btn_delete_selected'])) 70 { 71 foreach($content['nm']['rows'] as $row) 72 { 73 if($res_id = $row['checkbox'][0]) 74 { 75 $msg .= '<p>'. $this->bo->delete($res_id). '</p><br>'; 76 } 77 } 78 return $this->index($msg); 79 } 80 81 foreach($content['nm']['rows'] as $row) 82 { 83 if(isset($row['delete'])) 84 { 85 $res_id = array_search('pressed',$row['delete']); 86 return $this->index($this->bo->delete($res_id)); 87 } 88 if(isset($row['view_acc'])) 89 { 90 $sessiondata['view_accs_of'] = array_search('pressed',$row['view_acc']); 91 $GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata); 92 return $this->index(); 93 } 94 } 95 } 96 $msg = $content; 97 $content = array(); 98 $content['msg'] = $msg; 99 100 $content['nm']['header_left'] = 'resources.resource_select.header'; 101 $content['nm']['get_rows'] = 'resources.bo_resources.get_rows'; 102 $content['nm']['no_filter'] = False; 103 $content['nm']['filter_label'] = 'Category'; 104 $content['nm']['filter_help'] = lang('Select a category'); // is this used??? 105 $content['nm']['no_filter2'] = true; 106 $content['nm']['filter_no_lang'] = true; 107 $content['nm']['no_cat'] = true; 108 $content['nm']['bottom_too'] = true; 109 $content['nm']['order'] = 'name'; 110 $content['nm']['sort'] = 'ASC'; 111 112 $nm_session_data = $GLOBALS['egw']->session->appsession('session_data','resources_index_nm'); 113 if($nm_session_data) 114 { 115 $content['nm'] = $nm_session_data; 116 } 117 $content['nm']['options-filter']= array(''=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ); 118 119 // check if user is permitted to add resources 120 if(!$this->bo->acl->get_cats(EGW_ACL_ADD)) 121 { 122 $no_button['add'] = true; 123 } 124 $no_button['back'] = true; 125 $no_button['add_sub'] = true; 126 $GLOBALS['egw_info']['flags']['app_header'] = lang('resources'); 127 128 $GLOBALS['egw_info']['flags']['java_script'] .= "<script LANGUAGE=\"JavaScript\"> 129 function js_btn_book_selected(form) 130 { 131 resources = ''; 132 133 el = form.getElementsByTagName(\"input\"); 134 for (var i = 0; i < el.length; i++) 135 { 136 if(el[i].name.substr(el[i].name.length-12,el[i].name.length) == '[checkbox][]' && el[i].checked) 137 { 138 if(resources.length > 0) 139 { 140 resources += ','; 141 } 142 resources += 'r' + el[i].value; 143 } 144 } 145 if(resources.length == 0) 146 { 147 alert('". lang('No resources selected'). "'); 148 return false; 149 } 150 return resources; 151 } 152 </script>"; 153 154 if($content['nm']['view_accs_of']) 155 { 156 $master = $this->bo->so->read(array('res_id' => $content['nm']['view_accs_of'])); 157 $content['view_accs_of'] = $content['nm']['view_accs_of']; 158 $content['nm']['get_rows'] = 'resources.bo_resources.get_rows'; 159 $content['nm']['no_filter'] = true; 160 $content['nm']['no_filter2'] = true; 161 $no_button['back'] = false; 162 $no_button['add'] = true; 163 $no_button['add_sub'] = false; 164 $GLOBALS['egw_info']['flags']['app_header'] = lang('resources') . ' - ' . lang('accessories of '). ' '. $master['name'] . 165 ($master['short_description'] ? ' [' . $master['short_description'] . ']' : ''); 166 } 167 $preserv = $content; 168 $GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$content['nm']); 169 $this->tmpl->read('resources.show'); 170 return $this->tmpl->exec('resources.ui_resources.index',$content,$sel_options,$no_button,$preserv); 171 } 172 173 /** 174 * @author Cornelius Weiss <egw@von-und-zu-weiss.de> 175 * invokes add or edit dialog for resources 176 * 177 * @param $content Content from the eTemplate Exec call or id on inital call 178 */ 179 function edit($content=0,$accessory_of = -1) 180 { 181 if (is_array($content)) 182 { 183 if(isset($content['save']) || isset($content['delete'])) 184 { 185 if(isset($content['save'])) 186 { 187 unset($content['save']); 188 // if($content['id'] != 0) 189 // { 190 // // links are already saved by eTemplate 191 // unset($resource['link_to']['to_id']); 192 // } 193 $content['msg'] = $this->bo->save($content); 194 } 195 if(isset($content['delete'])) 196 { 197 unset($content['delete']); 198 $content['msg'] = $this->bo->delete($content['res_id']); 199 } 200 201 if($content['msg']) 202 { 203 return $this->edit($content); 204 } 205 $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php', 206 array('menuaction' => 'resources.ui_resources.index'))."';"; 207 $js .= 'window.close();'; 208 echo "<html><body><script>$js</script></body></html>\n"; 209 $GLOBALS['egw']->common->egw_exit(); 210 } 211 } 212 else 213 { 214 $res_id = $content; 215 if (isset($_GET['res_id'])) $res_id = $_GET['res_id']; 216 if (isset($_GET['accessory_of'])) $accessory_of = $_GET['accessory_of']; 217 $content = array('res_id' => $res_id); 218 219 if ($res_id > 0) 220 { 221 $content = $this->bo->read($res_id); 222 $content['gen_src_list'] = strstr($content['picture_src'],'.') ? $content['picture_src'] : false; 223 $content['picture_src'] = strstr($content['picture_src'],'.') ? 'gen_src' : $content['picture_src']; 224 $content['link_to'] = array( 225 'to_id' => $res_id, 226 'to_app' => 'resources' 227 ); 228 } 229 230 } 231 // some presetes 232 $content['resource_picture'] = $this->bo->get_picture($content['res_id'],$content['picture_src'],$size=true); 233 $content['quantity'] = $content['quantity'] ? $content['quantity'] : 1; 234 $content['useable'] = $content['useable'] ? $content['useable'] : 1; 235 $content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : $accessory_of; 236 237 $sel_options['gen_src_list'] = $this->bo->get_genpicturelist(); 238 $sel_options['cat_id'] = $this->bo->acl->get_cats(EGW_ACL_ADD); 239 $sel_options['cat_id'] = count($sel_options['cat_id']) == 1 ? $sel_options['cat_id'] : 240 $content['cat_id'] ? $sel_options['cat_id'] : array('' => lang('select one')) + $sel_options['cat_id']; 241 if($accessory_of > 0 || $content['accessory_of'] > 0) 242 { 243 $content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : $accessory_of; 244 $catofmaster = $this->bo->so->get_value('cat_id',$content['accessory_of']); 245 $sel_options['cat_id'] = array($catofmaster => $sel_options['cat_id'][$catofmaster]); 246 } 247 248 // $content['general|page|pictures|links'] = 'resources.edit_tabs.page'; //debug 249 $no_button = array(); // TODO: show delete button only if allowed to delete resource 250 $preserv = $content; 251 $this->tmpl->read('resources.edit'); 252 return $this->tmpl->exec('resources.ui_resources.edit',$content,$sel_options,$no_button,$preserv,2); 253 254 } 255 256 /** 257 * adminsection of resources 258 * 259 * @author Cornelius Weiss <egw@von-und-zu-weiss.de> 260 */ 261 function admin($content='') 262 { 263 if(is_array($content)) 264 { 265 if(isset($content['save'])) 266 { 267 $this->bo->conf->read_repository(); 268 $this->bo->conf->save_value('dont_use_vfs',$content['dont_use_vfs']); 269 } 270 else 271 { 272 return $GLOBALS['egw']->redirect_link('/admin/index.php'); 273 } 274 } 275 $content = $this->bo->conf->read_repository(); 276 $this->tmpl->read('resources.admin'); 277 $this->tmpl->exec('resources.ui_resources.admin',$content,$sel_options,$no_button,$preserv); 278 } 279 280 /** 281 * showes a single resource 282 * 283 * @param int $res_id resource id 284 * @author Lukas Weiss <wnz.gh05t@users.sourceforge.net> 285 */ 286 function show($res_id=0) 287 { 288 if (is_array($content = $res_id)) 289 { 290 if(isset($content['btn_delete'])) 291 { 292 $content['msg'] = $this->bo->delete($content['res_id']); 293 if($content['msg']) 294 { 295 return $this->show($content); 296 } 297 $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php', 298 array('menuaction' => 'resources.ui_resources.index'))."';"; 299 $js .= 'window.close();'; 300 echo "<html><body><script>$js</script></body></html>\n"; 301 $GLOBALS['egw']->common->egw_exit(); 302 } 303 if(isset($content['btn_edit'])) 304 { 305 return $this->edit($content['res_id']); 306 } 307 308 } 309 if (isset($_GET['res_id'])) $res_id = $_GET['res_id']; 310 311 $content = array('res_id' => $res_id); 312 $content = $this->bo->read($res_id); 313 $content['gen_src_list'] = strstr($content['picture_src'],'.') ? $content['picture_src'] : false; 314 $content['picture_src'] = strstr($content['picture_src'],'.') ? 'gen_src' : $content['picture_src']; 315 $content['link_to'] = array( 316 'to_id' => $res_id, 317 'to_app' => 'resources' 318 ); 319 320 $content['resource_picture'] = $this->bo->get_picture($content['res_id'],$content['picture_src'],$size=true); 321 $content['quantity'] = $content['quantity'] ? $content['quantity'] : 1; 322 $content['useable'] = $content['useable'] ? $content['useable'] : 1; 323 324 $content['quantity'] = ($content['useable'] == $content['quantity']) ? $content['quantity'] : $content['quantity'].' ('.lang('useable').' '.$content['useable'].')'; 325 326 //$sel_options['gen_src_list'] = $this->bo->get_genpicturelist(); 327 328 $content['cat_name'] = $this->bo->acl->get_cat_name($content['cat_id']); 329 $content['cat_admin'] = $this->bo->acl->get_cat_admin($content['cat_id']); 330 331 /* if($content['accessory_of'] > 0) 332 { 333 $catofmaster = $this->bo->so->get_value('cat_id',$content['accessory_of']); 334 $sel_options['cat_id'] = array($catofmaster => $sel_options['cat_id'][$catofmaster]); 335 } 336 */ 337 $content['description'] = chop($content['long_description']) ? $content['long_description'] : (chop($content['short_description']) ? $content['short_description'] : lang("no description available")); 338 $content['description'] = $content['description'] ? $content['description'] : lang('no description available'); 339 $content['link_to'] = array( 340 'to_id' => $res_id, 341 'to_app' => 'resources' 342 ); 343 $sel_options = array(); 344 $no_button = array( 345 'btn_buy' => !$content['buyable'], 346 'btn_book' => !$content['bookable'], 347 'btn_calendar' => !$content['bookable'], 348 'btn_edit' => !$this->bo->acl->is_permitted($content['cat_id'],EGW_ACL_EDIT), 349 'btn_delete' => !$this->bo->acl->is_permitted($content['cat_id'],EGW_ACL_DELETE) 350 ); 351 $preserv = $content; 352 $this->tmpl->read('resources.showdetails'); 353 return $this->tmpl->exec('resources.ui_resources.show',$content,$sel_options,$no_button,$preserv,2); 354 355 } 356 357 /** 358 * select resources 359 * 360 * @author Lukas Weiss <wnz.gh05t@users.sourceforge.net> 361 */ 362 function select($content='') 363 { 364 if (!is_object($GLOBALS['phpgw']->js)) 365 { 366 $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); 367 } 368 $GLOBALS['phpgw']->js->set_onload("copyOptions('exec[resources][selectbox]');"); 369 370 $GLOBALS['egw_info']['flags']['java_script'] .= "<script LANGUAGE=\"JavaScript\"> 371 window.focus(); 372 373 openerid='resources_selectbox'; 374 id='exec[nm][rows][selectbox]'; 375 376 function addOption(label,value,button_id,useable) 377 { 378 quantity = document.getElementById(button_id+'[default_qty]').value; 379 value = value+':'+quantity; 380 if(quantity>useable) { 381 alert('".lang('You chose more resources than available')."'); 382 return false; 383 } 384 label = label+'['+quantity+'/'+useable+']'; 385 openerSelectBox = opener.document.getElementById(openerid); 386 if (openerSelectBox) { 387 select = ''; 388 for(i=0; i < openerSelectBox.length; i++) { 389 with (openerSelectBox.options[i]) { 390 if (selected || openerSelectBox.selectedIndex == i) { 391 select += (value.slice(0,1)==',' ? '' : ',')+value; 392 } 393 } 394 } 395 select += (select ? ',' : '')+value; 396 opener.selectbox_add_option(openerid,label,value,0); 397 } 398 selectBox = document.getElementById(id); 399 if (selectBox) { 400 var resource_value = value.split(':'); 401 for (i=0; i < selectBox.length; i++) { 402 var selectvalue = selectBox.options[i].value.split(':'); 403 if (selectvalue[0] == resource_value[0]) { 404 selectBox.options[i] = null; 405 selectBox.options[selectBox.length] = new Option(label,value,false,true); 406 break; 407 } 408 } 409 if (i >= selectBox.length) { 410 selectBox.options[selectBox.length] = new Option(label,value,false,true); 411 } 412 } 413 } 414 415 function removeSelectedOptions() 416 { 417 openerSelectBox = opener.document.getElementById(openerid); 418 if (openerSelectBox == null) window.close(); 419 selectBox = document.getElementById(id); 420 for (i=0; i < selectBox.length; i++) { 421 if (selectBox.options[i].selected) { 422 for (j=0; j < openerSelectBox.length; j++) { 423 if (openerSelectBox[j].value == selectBox.options[i].value) { 424 openerSelectBox.removeChild(openerSelectBox[j]); 425 } 426 } 427 selectBox.options[i--] = null; 428 } 429 } 430 } 431 432 function copyOptions() 433 { 434 openerSelectBox = opener.document.getElementById(openerid); 435 selectBox = document.getElementById(id); 436 for (i=0; i < openerSelectBox.length; i++) { 437 with (openerSelectBox.options[i]) { 438 if (selected && value.slice(0,1) != ',') { 439 selectBox.options[selectBox.length] = new Option(text,value); 440 } 441 } 442 } 443 } 444 445 function oneLineSubmit() 446 { 447 /* 448 openerSelectBox = opener.document.getElementById(openerid); 449 450 if (openerSelectBox) { 451 if (openerSelectBox.selectedIndex >= 0) { 452 selected = openerSelectBox.options[openerSelectBox.selectedIndex].value; 453 if (selected.slice(0,1) == ',') selected = selected.slice(1); 454 opener.selectbox_add_option(openerid,'multiple*',selected,1); 455 } 456 else { 457 for (i=0; i < openerSelectBox.length; i++) { 458 with (openerSelectBox.options[i]) { 459 if (selected) { 460 opener.selectbox_add_option(openerid,text,value,1); 461 break; 462 } 463 } 464 } 465 } 466 } 467 */ 468 window.close(); 469 }</script>"; 470 471 $content['nm']['header_left'] = 'resources.resource_select.header'; 472 $content['nm']['show_bookable'] = true; 473 $content['nm']['get_rows'] = 'resources.bo_resources.get_rows'; 474 $content['nm']['no_filter'] = False; 475 $content['nm']['filter_label'] = 'Category'; 476 $content['nm']['filter_help'] = lang('Select a category'); // is this used??? 477 $content['nm']['options-filter']= array(''=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ); 478 $content['nm']['no_filter2'] = true; 479 $content['nm']['filter_no_lang'] = true; 480 $content['nm']['no_cat'] = true; 481 $content['nm']['rows']['js_id'] = 1; 482 483 $sel_options = array(); 484 $no_button = array(); 485 $this->tmpl->read('resources.resource_select'); 486 return $this->tmpl->exec('resources.ui_resources.select',$content,$sel_options,$no_button,$preserv,2); 487 } 488 489 /** 490 * get_calendar_sidebox 491 * get data für calendar sidebox 492 * 493 * @author Lukas Weiss <wnz_gh05t@users.sourceforge.net> 494 * @param array $param with keys menuaction, owner and optional date 495 * @return array with: label=>link or array with text 496 */ 497 function get_calendar_sidebox($param) 498 { 499 $cats = $this->bo->acl->get_cats(EGW_ACL_READ); 500 if (!$cats) return array(); 501 502 $owners = explode(',',$param['owner']); 503 unset($param['owner']); 504 $res_cats = $selected = array(); 505 506 // this gets the resource-ids of the cats and implodes them to the array-key of the selectbox, 507 // so it is possible to select all resources of a category 508 foreach($cats as $cat_id => $cat_name) 509 { 510 if ($resources = $this->bo->so->search(array('cat_id' => $cat_id, 'bookable' => '1'),'res_id')) 511 { 512 $keys = array(); 513 foreach($resources as $res) 514 { 515 $keys[] = 'r'.$res['res_id']; 516 } 517 $res_cats[implode(',',$keys)] = $cat_name; 518 519 if (count(array_intersect($keys,$owners)) == count($keys)) 520 { 521 $selected[] = implode(',',$keys); 522 $owners = array_diff($owners,$keys); 523 } 524 } 525 } 526 // add already selected single resources to the selectbox, eg. call of the resource-calendar from the resources app 527 $resources = array('r0' => lang('none')); 528 $res_ids = array(); 529 foreach($owners as $key => $owner) 530 { 531 if ($owner{0} == 'r') 532 { 533 $res_ids[] = (int) substr($owner,1); 534 $selected[] = $owner; 535 } 536 } 537 if (count($res_ids)) 538 { 539 foreach($this->bo->so->search(array('res_id' => $res_ids),'res_id,name') as $data) 540 { 541 $resources['r'.$data['res_id']] = $data['name']; 542 } 543 } 544 $selectbox = $this->html->select( 545 'owner', 546 $selected, 547 array_merge($resources,$res_cats), 548 $no_lang=true, 549 $options='style="width: 165px;" onchange="load_cal(\''. 550 $GLOBALS['egw']->link('/index.php',$param).'\',\'uical_select_resource\');" id="uical_select_resource"', 551 $multiple=count($selected) ? 4 : 0 552 ); 553 return array( 554 array( 555 'text' => $selectbox, 556 'no_lang' => True, 557 'link' => False 558 ) 559 ); 560 } 561 } 562
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 |