[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - InfoLog * 4 * http://www.egroupware.org * 5 * Written and copyright by Ralf Becker <RalfBecker@outdoor-training.de> * 6 * originaly based on todo written by Joseph Engo <jengo@phpgroupware.org> * 7 * -------------------------------------------- * 8 * This program is free software; you can redistribute it and/or modify it * 9 * under the terms of the GNU General Public License as published by the * 10 * Free Software Foundation; either version 2 of the License, or (at your * 11 * option) any later version. * 12 \**************************************************************************/ 13 14 /* $Id: class.uiinfolog.inc.php 22848 2006-11-15 10:32:03Z ralfbecker $ */ 15 16 include_once (EGW_INCLUDE_ROOT.'/infolog/inc/class.boinfolog.inc.php'); 17 18 /** 19 * This class is the UI-layer (user interface) of InfoLog 20 * 21 * @package infolog 22 * @author Ralf Becker <RalfBecker@outdoor-training.de> 23 * @copyright (c) by Ralf Becker <RalfBecker@outdoor-training.de> 24 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License 25 */ 26 class uiinfolog 27 { 28 var $public_functions = array 29 ( 30 'index' => True, 31 'edit' => True, 32 'delete' => True, 33 'close' => True, 34 'admin' => True, 35 'hook_view' => True, 36 'writeLangFile' => True 37 ); 38 var $prefs; 39 /** 40 * @var boinfolog-object $bo 41 */ 42 var $bo; 43 /** 44 * @var bolink-object $link reference to instance of the link-class of bo 45 */ 46 var $link; 47 /** 48 * @var string $duration_format allowed units and hours per day, can be overwritten by the projectmanager configuration, default all units, 8h 49 */ 50 var $duration_format = ','; // comma is necessary! 51 52 var $icons = array( 53 'type' => array( 54 'task' => 'task.gif', 'task_alt' => 'Task', 55 'phone' => 'phone.gif', 'phone_alt' => 'Phonecall', 56 'note' => 'note.gif', 'note_alt' => 'Note', 57 'confirm' => 'confirm.gif', 'confirm_alt' => 'Confirmation', 58 'reject' => 'reject.gif', 'reject_alt' => 'Reject', 59 'email' => 'email.gif', 'email_alt' => 'Email' ), 60 'action' => array( 61 'new' => 'new.gif', 'new_alt' => 'Add Sub', 62 'view' => 'view.gif', 'view_alt' => 'View Subs', 63 'parent' => 'parent.gif', 'parent_alt' => 'View other Subs', 64 'edit' => 'edit.gif', 'edit_alt' => 'Edit', 65 'addfile' => 'addfile.gif', 'addfile_alt' => 'Add a file', 66 'delete' => 'delete.gif', 'delete_alt' => 'Delete', 67 'close' => 'done.gif', 'close_alt' => 'Close' ), 68 'status' => array( 69 'billed' => 'billed.gif', 'billed_alt' => 'billed', 70 'done' => 'done.gif', 'done_alt' => 'done', 71 'will-call' => 'will-call.gif', 'will-call_alt' => 'will-call', 72 'call' => 'call.gif', 'call_alt' => 'call', 73 'ongoing' => 'ongoing.gif', 'ongoing_alt' => 'ongoing', 74 'offer' => 'offer.gif', 'offer_alt' => 'offer' ) 75 ); 76 var $filters = array( 77 'none' => 'no Filter', 78 'done' => 'done', 79 'my' => 'responsible', 80 'my-open-today' => 'responsible open', 81 'my-open-overdue' => 'responsible overdue', 82 'my-upcoming' => 'responsible upcoming', 83 'own' => 'own', 84 'own-open-today' => 'own open', 85 'own-open-overdue' => 'own overdue', 86 'own-upcoming' => 'own upcoming', 87 'open-today' => 'open', 88 'open-overdue' => 'overdue', 89 'upcoming' => 'upcoming' 90 ); 91 var $messages = array( 92 'edit' => 'InfoLog - Edit', 93 'add' => 'InfoLog - New', 94 'add_sub' => 'InfoLog - New Subproject', 95 'sp' => '- Subprojects from', 96 're' => 'Re:' 97 ); 98 99 function uiinfolog() 100 { 101 $this->bo =& new boinfolog(); 102 103 $this->link = &$this->bo->link; 104 105 $this->tmpl =& CreateObject('etemplate.etemplate'); 106 $this->html =& $this->tmpl->html; 107 108 $this->user = $GLOBALS['egw_info']['user']['account_id']; 109 110 $this->prefs =& $GLOBALS['egw_info']['user']['preferences']['infolog']; 111 112 // read the duration format from project-manager 113 if ($GLOBALS['egw_info']['apps']['projectmanager']) 114 { 115 $pm_config =& CreateObject('phpgwapi.config','projectmanager'); 116 $pm_config->read_repository(); 117 $this->duration_format = str_replace(',','',$pm_config->config_data['duration_units']).','.$pm_config->config_data['hours_per_workday']; 118 unset($pm_config); 119 } 120 $GLOBALS['uiinfolog'] =& $this; // make ourself availible for ExecMethod of get_rows function 121 } 122 123 function get_info($info,&$readonlys,$action='',$action_id='',$show_links=false,$details = 1) 124 { 125 if (!is_array($info)) 126 { 127 $info = $this->bo->read($info); 128 } 129 $id = $info['info_id']; 130 $done = $info['info_status'] == 'done' || $info['info_status'] == 'billed'; 131 $info['sub_class'] = $this->bo->enums['priority'][$info['info_priority']] . ($done ? '_done' : ''); 132 if (!$done && $info['info_enddate'] < $this->bo->user_time_now) 133 { 134 $info['end_class'] = 'overdue'; 135 } 136 if (!isset($info['info_anz_subs'])) $info['info_anz_subs'] = $this->bo->anzSubs($id); 137 $this->bo->link_id2from($info,$action,$action_id); // unset from for $action:$action_id 138 $info['info_percent'] = (int) $info['info_percent'].'%'; 139 140 $readonlys["edit[$id]"] = !$this->bo->check_access($info,EGW_ACL_EDIT); 141 $readonlys["close[$id]"] = $done || ($readonlys["edit_status[$id]"] = !($this->bo->check_access($info,EGW_ACL_EDIT) || 142 in_array($this->user, (array)$info['info_responsible']))); 143 $readonlys["edit_status[$id]"] = $readonlys["edit_percent[$id]"] = 144 !$this->bo->check_access($info,EGW_ACL_EDIT) && !in_array($this->user, (array)$info['info_responsible']); 145 $readonlys["delete[$id]"] = !$this->bo->check_access($info,EGW_ACL_DELETE); 146 $readonlys["sp[$id]"] = !$this->bo->check_access($info,EGW_ACL_ADD); 147 $readonlys["view[$id]"] = $info['info_anz_subs'] < 1; 148 $readonlys['view[0]'] = True; // no parent 149 $readonlys["timesheet[$id]"] = !$this->prefs['show_times'] || !isset($GLOBALS['egw_info']['user']['apps']['timesheet']); 150 151 if (!$show_links) $show_links = $this->prefs['show_links']; 152 153 if (($show_links != 'none' && $show_links != 'no_describtion' || 154 $this->prefs['show_times'] && isset($GLOBALS['egw_info']['user']['apps']['timesheet'])) && 155 ($links = $this->link->get_links('infolog',$info['info_id']))) 156 { 157 $timesheets = array(); 158 foreach ($links as $link) 159 { 160 if ($show_links != 'none' && $show_links != 'no_describtion' && 161 $link['link_id'] != $info['info_link_id'] && 162 ($link['app'] != $action || $link['id'] != $action_id) && 163 ($show_links == 'all' || ($show_links == 'links') === ($link['app'] != $this->link->vfs_appname))) 164 { 165 $info['filelinks'][] = $link; 166 } 167 if (!$info['pm_id'] && $link['app'] == 'projectmanager') 168 { 169 $info['pm_id'] = $link['id']; 170 } 171 if ($link['app'] == 'timesheet') $timesheets[] = $link['id']; 172 173 if ($link['app'] != 'timesheet' && $link['app'] != $this->link->vfs_appname) 174 { 175 $info['extra_links'] .= '&link_app[]='.$link['app'].'&link_id[]='.$link['id']; 176 } 177 } 178 if ($this->prefs['show_times'] && isset($GLOBALS['egw_info']['user']['apps']['timesheet']) && $timesheets) 179 { 180 $sum = ExecMethod('timesheet.botimesheet.sum',$timesheets); 181 $info['info_sum_timesheets'] = $sum['duration']; 182 } 183 } 184 $info['info_type_label'] = $this->bo->enums['type'][$info['info_type']]; 185 $info['info_status_label'] = $this->bo->status[$info['info_type']][$info['info_status']]; 186 187 if (!$this->prefs['show_percent'] || $this->prefs['show_percent'] == 2 && !$details) 188 { 189 if ($info['info_status'] == 'ongoing' && $info['info_type'] != 'phone') 190 { 191 $info['info_status'] = $info['info_status_label'] = $info['info_percent']; 192 } 193 $readonlys["edit_percent[$id]"] = true; 194 } 195 elseif($readonlys["edit_percent[$id]"]) // show percent, but button is switched off 196 { 197 $info['info_percent2'] = $info['info_percent']; 198 } 199 if ($this->prefs['show_id'] == 1 || $this->prefs['show_id'] == 2 && $details) 200 { 201 $info['info_number'] = $info['info_id']; 202 } 203 return $info; 204 } 205 206 function save_sessiondata($values) 207 { 208 $for = @$values['session_for'] ? $values['session_for'] : @$this->called_by; 209 //echo "<p>$for: uiinfolog::save_sessiondata(".print_r($values,True).") called_by='$this->called_by', for='$for'<br />".function_backtrace()."</p>\n"; 210 $GLOBALS['egw']->session->appsession($for.'session_data','infolog',array( 211 'search' => $values['search'], 212 'start' => $values['start'], 213 'num_rows' => $values['num_rows'], 214 'filter' => $values['filter'], 215 'filter2' => $values['filter2'], 216 'cat_id' => $values['cat_id'], 217 'order' => $values['order'], 218 'sort' => $values['sort'], 219 'action' => $values['action'], 220 'action_id' => $values['action_id'], 221 'col_filter' => $values['col_filter'], 222 'session_for' => $for 223 )); 224 } 225 226 function read_sessiondata() 227 { 228 $values = $GLOBALS['egw']->session->appsession(@$this->called_by.'session_data','infolog'); 229 if (!@$values['session_for'] && $this->called_by) 230 { 231 $values['session_for'] = $this->called_by; 232 $this->save_sessiondata($values); 233 } 234 //echo "<p>called_by='$this->called_by': uiinfolog::read_sessiondata() = ".print_r($values,True)."</p>\n"; 235 return $values; 236 } 237 238 function get_rows($query,&$rows,&$readonlys) 239 { 240 //echo "<p>uiinfolog.get_rows(start=$query[start],search='$query[search]',filter='$query[filter]',cat_id=$query[cat_id],action='$query[action]/$query[action_id]',col_filter=".print_r($query['col_filter'],True).")</p>\n"; 241 if (!isset($query['start'])) $query['start'] = 0; 242 243 $this->save_sessiondata($query); 244 245 $ids = $this->bo->search($query); 246 if (!is_array($ids)) 247 { 248 $ids = array( ); 249 } 250 $details = $query['filter2'] == 'all'; 251 $readonlys = $rows = array(); 252 foreach($ids as $id => $info) 253 { 254 $info = $this->get_info($info,$readonlys,$query['action'],$query['action_id'],$query['filter2'],$details); 255 if (!$query['filter2'] && $this->prefs['show_links'] == 'no_describtion' || 256 $query['filter2'] == 'no_describtion') 257 { 258 unset($info['info_des']); 259 } 260 $rows[] = $info; 261 } 262 if ($query['no_actions']) $rows['no_actions'] = true; 263 $rows['no_modified'] = !$this->prefs['show_modified'] || $this->prefs['show_modified'] == 2 && !$details; 264 $rows['no_times'] = !$this->prefs['show_times'] || $this->prefs['show_times'] == 2 && !$details; 265 $rows['no_timesheet'] = !isset($GLOBALS['egw_info']['user']['apps']['timesheet']); 266 $rows['duration_format'] = ','.$this->duration_format.',,1'; 267 //echo "<p>readonlys = "; _debug_array($readonlys); 268 //echo "rows=<pre>".print_r($rows,True)."</pre>\n"; 269 270 if ($GLOBALS['egw_info']['flags']['currentapp'] == 'infolog') 271 { 272 $GLOBALS['egw_info']['flags']['app_header'] = lang('Infolog').($query['filter'] == 'none' ? '' : 273 ' - '.lang($this->filters[$query['filter']])); 274 } 275 return $query['total']; 276 } 277 278 /** 279 * Shows the infolog list 280 * 281 * @param array/string $values=null etemplate content or 'reset_action_view' if called by index.php to reset an action-view 282 * @param string $action='' if set only entries liked to that $action:$action_id are shown 283 * @param string $action_id='' if set only entries liked to that $action:$action_id are shown 284 * @param mixed $called_as=0 this is how we got called, for a hook eg. the call-params of that page containing the hook 285 * @param boolean $extra_app_header=false 286 * @param boolean $return_html=false 287 * @param string $own_referer='' this is our own referer 288 */ 289 function index($values = null,$action='',$action_id='',$called_as=0,$extra_app_header=False,$return_html=False,$own_referer='') 290 { 291 if (is_array($values)) 292 { 293 $called_as = $values['called_as']; 294 $own_referer = $values['own_referer']; 295 } 296 elseif ($own_referer === '') 297 { 298 $own_referer = $GLOBALS['egw']->common->get_referer(); 299 if (strstr($own_referer,'menuaction=infolog.uiinfolog.edit')) 300 { 301 $own_referer = $GLOBALS['egw']->session->appsession('own_session','infolog'); 302 } 303 else 304 { 305 $GLOBALS['egw']->session->appsession('own_session','infolog',$own_referer); 306 } 307 } 308 if (!$action) 309 { 310 $action = $values['action'] ? $values['action'] : get_var('action',array('POST','GET')); 311 $action_id = $values['action_id'] ? $values['action_id'] : get_var('action_id',array('POST','GET')); 312 313 if ($values === 'reset_action_view') // only read action from session, if not called by index.php 314 { 315 $session = $this->read_sessiondata(); 316 $session['action'] = $action = ''; 317 $session['action_id'] = $action_id = 0; 318 $this->save_sessiondata($session); 319 unset($session); 320 } 321 elseif (!$action) 322 { 323 $session = $this->read_sessiondata(); 324 $action = $session['action']; 325 $action_id = $session['action_id']; 326 unset($session); 327 } 328 } 329 //echo "<p>uiinfolog::index(action='$action/$action_id',called_as='$called_as/$values[referer]',own_referer='$own_referer') values=\n"; _debug_array($values); 330 if (!is_array($values)) 331 { 332 $values = array('nm' => $this->read_sessiondata()); 333 if (isset($_GET['filter']) && $_GET['filter'] != 'default' || !isset($values['nm']['filter']) && !$this->called_by) 334 { 335 $values['nm']['filter'] = $_GET['filter'] && $_GET['filter'] != 'default' ? $_GET['filter'] : 336 $this->prefs['defaultFilter']; 337 } 338 if (!isset($values['nm']['order']) || !$values['nm']['order']) 339 { 340 $values['nm']['order'] = 'info_datemodified'; 341 $values['nm']['sort'] = 'DESC'; 342 } 343 $values['msg'] = $_GET['msg']; 344 $values['action'] = $action; 345 $values['action_id'] = $action_id; 346 } 347 if ($values['nm']['add']) 348 { 349 $values['add'] = $values['nm']['add']; 350 unset($values['nm']['add']); 351 } 352 if ($values['add'] || $values['cancel'] || isset($values['nm']['rows']) || isset($values['main'])) 353 { 354 if ($values['add']) 355 { 356 list($type) = each($values['add']); 357 return $this->edit(0,$action,$action_id,$type,$called_as); 358 } 359 elseif ($values['cancel'] && $own_referer) 360 { 361 $session = $this->read_sessiondata(); 362 unset($session['action']); 363 unset($session['action_id']); 364 $this->save_sessiondata($session); 365 $this->tmpl->location($own_referer); 366 } 367 else 368 { 369 list($do,$do_id) = isset($values['main']) ? each($values['main']) : @each($values['nm']['rows']); 370 list($do_id) = @each($do_id); 371 //echo "<p>infolog::index: do='$do/$do_id', referer="; _debug_array($called_as); 372 switch($do) 373 { 374 case 'edit': 375 case 'edit_status': 376 return $this->edit($do_id,$action,$action_id,'',$called_as); 377 case 'delete': 378 if (!($values['msg'] = $this->delete($do_id,$called_as,$called_as ? '' : 'index'))) return; 379 break; 380 case 'close': 381 return $this->close($do_id,$called_as,$do == 'close_subs'); 382 case 'sp': 383 return $this->edit(0,'sp',$do_id,'',$called_as); 384 case 'view': 385 $value = array(); 386 $action = 'sp'; 387 $action_id = $do_id; 388 break; 389 default: 390 $value = array(); 391 $action = ''; 392 $action_id = 0; 393 break; 394 } 395 } 396 } 397 switch ($action) 398 { 399 case 'sp': 400 if (!$this->bo->read($action_id)) 401 { 402 $action = ''; 403 $action_id = 0; 404 break; 405 } 406 $values['main'][1] = $this->get_info($action_id,$readonlys['main']); 407 $values['main']['no_times'] = !$this->prefs['show_times']; 408 break; 409 } 410 $readonlys['cancel'] = $action != 'sp'; 411 412 $this->tmpl->read('infolog.index'); 413 414 $values['nm']['options-filter'] = $this->filters; 415 $values['nm']['get_rows'] = 'infolog.uiinfolog.get_rows'; 416 $values['nm']['options-filter2'] = (in_array($this->prefs['show_links'],array('all','no_describtion')) ? array() : array( 417 '' => 'default', 418 )) + array( 419 'no_describtion' => 'no details', 420 'all' => 'details', 421 ); 422 if(!isset($values['nm']['filter2'])) $values['nm']['filter2'] = $this->prefs['show_links']; 423 $values['nm']['header_right'] = 'infolog.index.header_right'; 424 if ($extra_app_header) 425 { 426 $values['nm']['header_left'] = 'infolog.index.header_left'; 427 } 428 $values['nm']['bottom_too'] = True; 429 $values['nm']['never_hide'] = isset($this->prefs['never_hide']) ? 430 $this->prefs['never_hide'] : $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 15; 431 $values['action'] = $persist['action'] = $values['nm']['action'] = $action; 432 $values['action_id'] = $persist['action_id'] = $values['nm']['action_id'] = $action_id; 433 $persist['called_as'] = $called_as; 434 $persist['own_referer'] = $own_referer; 435 436 $all_stati = array(); 437 foreach($this->bo->status as $typ => $stati) 438 { 439 if ($typ != 'defaults') $all_stati += $stati; 440 } 441 if (!$called_as) 442 { 443 $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog'); 444 $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualInfologIndex'); 445 } 446 else 447 { 448 $values['css'] = '<style type="text/css">@import url('.$GLOBALS['egw_info']['server']['webserver_url'].'/infolog/templates/default/app.css);'."</style>"; 449 } 450 return $this->tmpl->exec('infolog.uiinfolog.index',$values,array( 451 'info_type' => $this->bo->enums['type'], 452 'info_status' => $all_stati 453 ),$readonlys,$persist,$return_html ? -1 : 0); 454 } 455 456 function close($values=0,$referer='') 457 { 458 $info_id = (int) (is_array($values) ? $values['info_id'] : ($values ? $values : $_GET['info_id'])); 459 $referer = is_array($values) ? $values['referer'] : $referer; 460 461 if ($info_id) 462 { 463 $values = array( 464 'info_id' => $info_id, 465 'info_status' => 'done', 466 'info_percent'=> 100, 467 'info_datecompleted' => $this->bo->now_su, 468 ); 469 $this->bo->write($values); 470 471 $query = array('action'=>'sp','action_id'=>$info_id); 472 foreach((array)$this->bo->search($query) as $info) 473 { 474 if ($info['info_id_parent'] == $info_id) // search also returns linked entries! 475 { 476 $this->close($info['info_id'],$referer); // we call ourselfs recursive to process subs from subs too 477 } 478 } 479 } 480 return $referer ? $this->tmpl->location($referer) : $this->index(); 481 } 482 483 function delete($values=0,$referer='',$called_by='') 484 { 485 $info_id = (int) (is_array($values) ? $values['info_id'] : ($values ? $values : $_GET['info_id'])); 486 $referer = is_array($values) ? $values['referer'] : $referer; 487 488 if (!is_array($values) && $info_id > 0 && !$this->bo->anzSubs($info_id)) // entries without subs get confirmed by javascript 489 { 490 $values = array('delete' => true); 491 } 492 //echo "<p>uiinfolog::delete(".print_r($values,true).",'$referer','$called_by') info_id=$info_id</p>\n"; 493 494 if (is_array($values) || $info_id <= 0) 495 { 496 if (($values['delete'] || $values['delete_subs']) && $info_id > 0 && $this->bo->check_access($info_id,EGW_ACL_DELETE)) 497 { 498 $deleted = $this->bo->delete($info_id,$values['delete_subs'],$values['info_id_parent']); 499 } 500 if ($called_by) // direct call from the same request 501 { 502 return $deleted ? lang('InfoLog entry deleted') : ''; 503 } 504 if ($values['called_by'] == 'edit') // we run in the edit popup => give control back to edit 505 { 506 $this->edit(array( 507 'info_id' => $info_id, 508 'button' => array('deleted' => true), // not delete! 509 'referer' => $referer, 510 'msg' => $deleted ? lang('Infolog entry deleted') : '', 511 )); 512 } 513 return $referer ? $this->tmpl->location($referer) : $this->index(); 514 } 515 $readonlys = $values = array(); 516 $values['main'][1] = $this->get_info($info_id,$readonlys['main']); 517 518 $this->tmpl->read('infolog.delete'); 519 520 $values['nm'] = array( 521 'action' => 'sp', 522 'action_id' => $info_id, 523 'options-filter' => $this->filters, 524 'get_rows' => 'infolog.uiinfolog.get_rows', 525 'no_filter2' => True, 526 'never_hide' => isset($this->prefs['never_hide']) ? 527 $this->prefs['never_hide'] : 528 $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 15, 529 ); 530 $values['main']['no_actions'] = $values['nm']['no_actions'] = True; 531 532 $persist['info_id'] = $info_id; 533 $persist['referer'] = $referer; 534 $persist['info_id_parent'] = $values['main'][1]['info_id_parent']; 535 $persist['called_by'] = $called_by; 536 537 $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Delete'); 538 $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualInfologDelete'); 539 540 $this->tmpl->exec('infolog.uiinfolog.delete',$values,'',$readonlys,$persist,$called_by == 'edit' ? 2 : 0); 541 } 542 543 /** 544 * Edit/Create an InfoLog Entry 545 * 546 * @param array $content=null Content from the eTemplate Exec call or info_id on inital call 547 * @param string $action='' Name of an app of 'sp' for a infolog-sub 548 * @param int $action_id=0 Id of app-entry to which a link is created 549 * @param string $type='' Type of log-entry: note,todo,task 550 * @param string $referer='' array with param/get-vars of the refering page 551 */ 552 function edit($content = null,$action = '',$action_id=0,$type='',$referer='') 553 { 554 $tabs = 'description|links|delegation|project|customfields'; 555 556 if (is_array($content)) 557 { 558 //echo "uiinfolog::edit: content="; _debug_array($content); 559 $info_id = $content['info_id']; 560 $action = $content['action']; 561 $action_id = $content['action_id']; 562 $referer = $content['referer']; 563 $no_popup = $content['no_popup']; 564 $caller = $content['caller']; 565 566 if (isset($content['link_to']['primary'])) 567 { 568 $content['info_link_id'] = $content['link_to']['primary']; 569 } 570 list($button) = @each($content['button']); 571 unset($content['button']); 572 if ($button) 573 { 574 //echo "<p>uiinfolog::edit(info_id=$info_id) '$button' button pressed, content="; _debug_array($content); 575 if (($button == 'save' || $button == 'apply') && $info_id) 576 { 577 if (!($edit_acl = $this->bo->check_access($info_id,EGW_ACL_EDIT))) 578 { 579 $old = $this->bo->read($info_id); 580 $status_only = in_array($this->user, $old['info_responsible']); 581 } 582 } 583 if (($button == 'save' || $button == 'apply') && (!$info_id || $edit_acl || $status_only)) 584 { 585 if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) 586 { 587 if (strstr($content['info_link_id'],':') !== False) 588 { 589 $info_link_id = $content['info_link_id']; 590 $content['info_link_id'] = 0; // as field has to be int 591 } 592 } 593 $active_tab = $content[$tabs]; 594 if (!($info_id = $this->bo->write($content))) 595 { 596 $content['msg'] = $info_id !== 0 || !$content['info_id'] ? lang('Error: saving the entry') : 597 lang('Error: the entry has been updated since you opened it for editing!').'<br />'. 598 lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.','<a href="'. 599 htmlspecialchars($GLOBALS['egw']->link('/index.php',array( 600 'menuaction' => 'infolog.uiinfolog.edit', 601 'info_id' => $content['info_id'], 602 'no_popup' => $no_popup, 603 'referer' => $referer, 604 ))).'">','</a>'); 605 $button = ''; // not exiting edit 606 $info_id = $content['info_id']; 607 } 608 else 609 { 610 $content['msg'] = lang('InfoLog entry saved'); 611 $content['js'] = "opener.location.href='".($link=$GLOBALS['egw']->link($referer,array('msg' => $content['msg'])))."';"; 612 } 613 $content[$tabs] = $active_tab; 614 if ((int) $content['pm_id'] != (int) $content['old_pm_id']) 615 { 616 //echo "<p>pm_id changed: $content[old_pm_id] -> $content[pm_id]</p>\n"; 617 // update links accordingly, if selected project changed 618 if ($content['pm_id']) 619 { 620 //echo "<p>this->link->link('infolog',{$content['link_to']['to_id']},'projectmanager',{$content['pm_id']});</p>"; 621 $this->link->link('infolog',$content['link_to']['to_id'],'projectmanager',$content['pm_id']); 622 // making the project the selected link, if no other link selected 623 if (!$info_link_id || $info_link_id == 'projectmanager:'.$content['old_pm_id']) 624 { 625 $info_link_id = 'projectmanager:'.$content['pm_id']; 626 } 627 } 628 if ($content['old_pm_id']) 629 { 630 //echo "<p>this->link->unlink2(0,infolog,{$content['link_to']['to_id']},0,'projectmanager',{$content['old_pm_id']});</p>\n"; 631 $this->link->unlink2(0,infolog,$content['link_to']['to_id'],0,'projectmanager',$content['old_pm_id']); 632 $content['old_pm_id'] = $content['pm_id']; 633 } 634 } 635 // writing links for a new entry 636 if ($info_id && is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) 637 { 638 $this->link->link('infolog',$info_id,$content['link_to']['to_id']); 639 $content['link_to']['to_id'] = $info_id; 640 } 641 if (strstr($info_link_id,':') !== false) // updating info_link_id if necessary 642 { 643 list($app,$id) = explode(':',$info_link_id); 644 $link = $this->link->get_link('infolog',$info_id,$app,$id); 645 if ((int) $content['info_link_id'] != (int) $link['link_id']) 646 { 647 $content['info_link_id'] = $link['link_id']; 648 649 $to_write = array( 650 'info_id' => $content['info_id'], 651 'info_link_id' => $content['info_link_id'], 652 'info_from' => $content['info_from'], 653 'info_owner' => $content['info_owner'], 654 ); 655 $this->bo->write($to_write,False); 656 // we need eg. the new modification date, for further updates 657 $content = array_merge($content,$to_write); 658 } 659 } 660 } 661 elseif ($button == 'delete' && $info_id > 0) 662 { 663 if (!$referer && $action) $referer = array( 664 'menuaction' => 'infolog.uiinfolog.index', 665 'action' => $action, 666 'action_id' => $action_id 667 ); 668 if (!($content['msg'] = $this->delete($info_id,$referer,'edit'))) return; // checks ACL first 669 670 $content['js'] = "opener.location.href='".$GLOBALS['egw']->link($referer,array('msg' => $content['msg']))."';"; 671 } 672 // called again after delete confirmation dialog 673 elseif ($button == 'deleted' && $content['msg']) 674 { 675 $content['js'] = "opener.location.href='".$GLOBALS['egw']->link($referer,array('msg' => $content['msg']))."';"; 676 } 677 if ($button == 'save' || $button == 'cancel' || $button == 'delete' || $button == 'deleted') 678 { 679 if ($no_popup) 680 { 681 $GLOBALS['egw']->redirect_link($referer,array('msg' => $content['msg'])); 682 } 683 $content['js'] .= 'window.close();'; 684 echo '<html><body onload="'.$content['js'].'"></body></html>'; 685 $GLOBALS['egw']->common->egw_exit(); 686 } 687 if ($content['js']) $content['js'] = '<script>'.$content['js'].'</script>'; 688 } 689 // on a type-change, set the status to the default status of that type, if the actual status is not supported by the new type 690 if (!in_array($content['info_status'],$this->bo->status[$content['info_type']])) 691 { 692 $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; 693 if ($content['info_status'] != 'done') $content['info_datecompleted'] = ''; 694 } 695 } 696 else 697 { 698 //echo "<p>uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'</p>\n"; 699 $action = $action ? $action : get_var('action', array('POST','GET')); 700 $action_id = $action_id ? $action_id : get_var('action_id',array('POST','GET')); 701 $info_id = $content ? $content : get_var('info_id', array('POST','GET')); 702 $type = $type ? $type : get_var('type', array('POST','GET')); 703 $ref=$referer = $referer !== '' ? $referer : ($_GET['referer'] ? $_GET['referer'] : 704 $GLOBALS['egw']->common->get_referer('/index.php?menuaction=infolog.uiinfolog.index')); 705 $referer = preg_replace('/([&?]{1})msg=[^&]+&?/','\\1',$referer); // remove previou/old msg from referer 706 $no_popup = $_GET['no_popup']; 707 //echo "<p>uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'</p>\n"; 708 709 $content = $this->bo->read( $info_id || $action != 'sp' ? $info_id : $action_id ); 710 711 if (is_numeric($_REQUEST['cat_id'])) 712 { 713 $content['info_cat'] = (int) $_REQUEST['cat_id']; 714 } 715 switch($this->prefs['set_start']) 716 { 717 case 'date': default: $set_startdate = mktime(0,0,0,date('m',$this->bo->user_time_now),date('d',$this->bo->user_time_now),date('Y',$this->bo->user_time_now)); break; 718 case 'datetime': $set_startdate = $this->bo->user_time_now; break; 719 case 'empty': $set_startdate = 0; break; 720 } 721 if (intval($content['info_link_id']) > 0 && !$this->link->get_link($content['info_link_id'])) 722 { 723 $content['info_link_id'] = 0; // link has been deleted 724 } 725 726 if (!$info_id && $action_id && $action == 'sp') // new SubProject 727 { 728 if (!$this->bo->check_access($action_id,EGW_ACL_ADD)) 729 { 730 return $referer ? $this->tmpl->location($referer) : $this->index(0,$action,$action_id); 731 } 732 $parent = $this->bo->so->data; 733 $content['info_id'] = $info_id = 0; 734 $content['info_owner'] = $this->user; 735 $content['info_id_parent'] = $parent['info_id']; 736 /* 737 if ($parent['info_type']=='task' && $parent['info_status']=='offer') 738 { 739 $content['info_type'] = 'confirm'; // confirmation to parent 740 $content['info_responsible'] = $parent['info_owner']; 741 } 742 */ 743 $content['info_type'] = $parent['info_type']; 744 $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; 745 $content['info_percent'] = $content['info_status'] == 'done' ? '100%' : '0%'; 746 $content['info_datecompleted'] =$content['info_status'] == 'done' ? $this->bo->user_time_now : 0; 747 $content['info_confirm'] = 'not'; 748 $content['info_subject']=lang($this->messages['re']).' '.$parent['info_subject']; 749 $content['info_des'] = ''; 750 $content['info_lastmodified'] = ''; 751 if ($content['info_startdate'] < $this->bo->user_time_now) // parent-startdate is in the past => today 752 { 753 $content['info_startdate'] = $set_startdate; 754 } 755 if ($content['info_enddate'] < $this->bo->user_time_now) // parent-enddate is in the past => empty 756 { 757 $content['info_enddate'] = ''; 758 } 759 } 760 else 761 { 762 if ($info_id && !$this->bo->check_access($info_id,EGW_ACL_EDIT) && !in_array($this->user, (array)$content['info_responsible'])) 763 { 764 if ($no_popup) 765 { 766 $GLOBALS['egw']->common->egw_header(); 767 parse_navbar(); 768 echo '<p class="redItalic" align="center">'.lang('Permission denied')."</p>\n"; 769 $GLOBALS['egw']->common->egw_exit(); 770 } 771 $js = "alert('".lang('Permission denied')."'); window.close();"; 772 echo '<html><body onload="'.$js.'"></body></html>'; 773 $GLOBALS['egw']->common->egw_exit(); 774 } 775 } 776 $content['links'] = $content['link_to'] = array( 777 'to_id' => $info_id, 778 'to_app' => 'infolog', 779 ); 780 switch ($action) 781 { 782 case 'sp': 783 $links = $this->link->get_links('infolog',$parent['info_id'],'!'.$this->link->vfs_appname); 784 foreach($links as $link) 785 { 786 $link_id = $this->link->link('infolog',$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']); 787 788 if ($parent['info_link_id'] == $link['link_id']) 789 { 790 $content['info_link_id'] = $link_id; 791 } 792 } 793 break; 794 795 case 'projectmanager': 796 $pm_links = array($action_id); 797 case 'addressbook': 798 case 'projects': 799 case 'calendar': 800 default: // to allow other apps to participate 801 $content['info_link_id'] = $this->link->link('infolog',$content['link_to']['to_id'],$action,$action_id); 802 $content['blur_title'] = $this->link->title($action,$action_id); 803 804 case '': 805 if ($info_id) 806 { 807 if (!isset($pm_links)) 808 { 809 $pm_links = $this->link->get_links('infolog',$info_id,'projectmanager'); 810 } 811 break; // normal edit 812 } 813 case 'new': // new entry 814 $content['info_startdate'] = (int) $_GET['startdate'] ? (int) $_GET['startdate'] : $set_startdate; 815 $content['info_priority'] = 1; // normal 816 $content['info_owner'] = $this->user; 817 if ($type != '') 818 { 819 $content['info_type'] = $type; 820 } 821 $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; 822 $content['info_percent'] = $content['info_status'] == 'done' ? '100%' : '0%'; 823 break; 824 } 825 if (!isset($this->bo->enums['type'][$content['info_type']])) 826 { 827 $content['info_type'] = 'note'; 828 } 829 } 830 // for implizit edit of responsible user make all fields readonly, but status and percent 831 if ($info_id && !$this->bo->check_access($info_id,EGW_ACL_EDIT) && in_array($this->user, (array)$content['info_responsible'])) 832 { 833 $content['status_only'] = !in_array('link_to',$this->bo->responsible_edit); 834 foreach(array_diff(array_merge(array_keys($content),array('pm_id')),$this->bo->responsible_edit) as $name) 835 { 836 $readonlys[$name] = true; 837 } 838 // need to set all customfields extra, as they are not set if empty 839 foreach($this->bo->customfields as $name => $value) 840 { 841 $readonlys['#'.$name] = true; 842 } 843 } 844 // we allways need to set a non-empty/-zero primary, to make the radiobutton appear 845 $content['link_to']['primary'] = $content['info_link_id'] ? $content['info_link_id'] : '#'; 846 847 if (!($readonlys['button[delete]'] = !$info_id || !$this->bo->check_access($info_id,EGW_ACL_DELETE))) 848 { 849 $content['info_anz_subs'] = $this->bo->anzSubs($info_id); // to determine js confirmation of delete or not 850 } 851 $GLOBALS['egw_info']['flags']['app_header'] = lang($this->messages[$info_id ? 'edit' : ($action == 'sp' ? 'add_sub' : 'add')]); 852 853 $this->tmpl->read('infolog.edit'); 854 if ($this->bo->has_customfields($content['info_type'])) 855 { 856 $content['customfields'] = $this->bo->customfields; 857 $content['customfields']['###typ###'] = $content['info_type']; 858 } 859 else 860 { 861 $readonlys[$tabs] = array('customfields' => true); 862 } 863 if (!isset($GLOBALS['egw_info']['user']['apps']['projectmanager'])) 864 { 865 $readonlys[$tabs]['project'] = true; // disable the project tab 866 } 867 $content['duration_format'] = $this->duration_format; 868 869 $old_pm_id = is_array($pm_links) ? array_shift($pm_links) : $content['old_pm_id']; 870 if (!isset($content['pm_id']) && $old_pm_id) $content['pm_id'] = $old_pm_id; 871 872 $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '. 873 ($content['status_only'] ? lang('Edit Status') : lang('Edit')); 874 $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => ($info_id ? 'ManualInfologEdit' : 'ManualInfologAdd')); 875 //echo "<p>uiinfolog.edit(info_id='$info_id',action='$action',action_id='$action_id') readonlys="; print_r($readonlys); echo ", content = "; _debug_array($content); 876 $this->tmpl->exec('infolog.uiinfolog.edit',$content,array( 877 'info_type' => $this->bo->enums['type'], 878 'info_priority' => $this->bo->enums['priority'], 879 'info_confirm' => $this->bo->enums['confirm'], 880 'info_status' => $this->bo->status[$content['info_type']] 881 ),$readonlys,array( // preserved values 882 'info_id' => $info_id, 883 'info_id_parent'=> $content['info_id_parent'], 884 'info_link_id' => $content['info_link_id'], 885 'info_owner' => $content['info_owner'], 886 'info_datemodified' => $content['info_datemodified'], 887 'info_modifier' => $content['info_modifier'], 888 'action' => $action, 889 'action_id' => $action_id, 890 'referer' => $referer, 891 'no_popup' => $no_popup, 892 'link_to' => array('to_id' => $content['link_to']['to_id']), // in case tab gets not viewed 893 'blur_title' => $content['blur_title'], 894 'old_pm_id' => $old_pm_id, 895 // preserv project fields, in case project tab is disabled, but user has rights to edit the entry 896 'pl_id' => $content['pl_id'], 897 'info_price' => $content['info_price'], 898 'info_used_time' => $content['info_used_time'], 899 'info_planned_time' => $content['info_planned_time'], 900 ),$no_popup ? 0 : 2); 901 } 902 903 function menuaction($action = 'get_list',$app='infolog') 904 { 905 return array( 'menuaction' => "$app.ui$app.$action" ); 906 } 907 908 function icon($cat,$id,$status='') 909 { 910 if (!$status || !($icon = $this->icons[$cat][$id.'_'.$status])) 911 { 912 $icon = $this->icons[$cat][$id]; 913 } 914 if ($icon && !is_readable($GLOBALS['egw']->common->get_image_dir() . '/' . $icon)) 915 { 916 $icon = False; 917 } 918 if (!$status || !($alt = $this->icons[$cat][$id.'_'.$status.'_alt'])) 919 { 920 if (!($alt = $this->icons[$cat][$id.'_alt'])) 921 { 922 $alt = $id; 923 } 924 } 925 return $icon ? $this->html->image('infolog',$icon,lang($alt),'border=0') : lang($alt); 926 } 927 928 function admin( ) 929 { 930 $fields = array( 931 'info_cat' => 'Category', 932 'info_from' => 'Contact', 933 'info_addr' => 'Phone/Email', 934 'info_subject' => 'Subject', 935 'info_des' => 'Description', 936 'link_to' => 'Links', 937 'info_priority' => 'Priority', 938 'info_location' => 'Location', 939 'info_planned_time' => 'Planned time', 940 'info_used_time' => 'Used time', 941 ); 942 if($_POST['save'] || $_POST['apply']) 943 { 944 $this->link_pathes = $this->bo->send_file_ips = array(); 945 946 $valid = get_var('valid',Array('POST')); 947 $trans = get_var('trans',Array('POST')); 948 $ip = get_var('ip',Array('POST')); 949 while(list($key,$val) = each($valid)) 950 { 951 if($val = stripslashes($val)) 952 { 953 $this->link_pathes[$val] = stripslashes($trans[$key]); 954 $this->bo->send_file_ips[$val] = stripslashes($ip[$key]); 955 } 956 } 957 $this->bo->responsible_edit = array('info_status','info_percent','info_datecompleted'); 958 if ($_POST['responsible_edit']) 959 { 960 $extra = array_intersect($_POST['responsible_edit'],array_keys($fields)); 961 $this->bo->responsible_edit = array_merge($this->bo->responsible_edit,$extra); 962 } 963 $this->bo->implicit_rights = $_POST['implicit_rights'] == 'edit' ? 'edit' : 'read'; 964 $this->bo->config->config_data += array( // only "adding" the changed items, to not delete other config like custom fields 965 'link_pathes' => $this->link_pathes, 966 'send_file_ips' => $this->bo->send_file_ips, 967 'implicit_rights' => $this->bo->implicit_rights, 968 'responsible_edit' => is_array($extra) ? implode(',',$extra) : $extra, 969 ); 970 $this->bo->config->save_repository(True); 971 } 972 if($_POST['cancel'] || $_POST['save']) 973 { 974 $GLOBALS['egw']->redirect_link('/admin/index.php'); 975 } 976 977 $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Configuration'); 978 $GLOBALS['egw']->common->egw_header(); 979 980 $GLOBALS['egw']->template->set_file(array('info_admin_t' => 'admin.tpl')); 981 $GLOBALS['egw']->template->set_block('info_admin_t', 'admin_line'); 982 $GLOBALS['egw']->template->set_block('info_admin_t', 'info_admin'); 983 984 $GLOBALS['egw']->template->set_var(Array( 985 'lang_responsible_rights' => lang('Rights for the responsible'), 986 'lang_implicit_rights' => lang('Which implicit ACL rights should the responsible get?'), 987 'implicit_rights' => $this->html->select('implicit_rights',$this->bo->implicit_rights,array( 988 'read' => 'read rights (default)', 989 'edit' => 'edit rights (full edit rights incl. making someone else responsible!)', 990 )), 991 'lang_responsible_edit' => lang('Which additional fields should the responsible be allowed to edit without having edit rights?<br />Status, percent and date completed are always allowed.'), 992 'responsible_edit' => $this->html->checkbox_multiselect('responsible_edit',$this->bo->responsible_edit,$fields,false,'',11), 993 'text' => lang('<b>file-attachments via symlinks</b> instead of uploads and retrieval via file:/path for direct lan-clients'), 994 'action_url' => $this->html->link('/index.php',$this->menuaction('admin')), 995 'save_button' => $this->html->submit_button('save','Save'), 996 'apply_button' => $this->html->submit_button('apply','Apply'), 997 'cancel_button' => $this->html->submit_button('cancel','Cancel'), 998 'lang_valid' => lang('valid path on clientside<br>eg. \\\\Server\\Share or e:\\'), 999 'lang_trans' => lang('path on (web-)serverside<br>eg. /var/samba/Share'), 1000 'lang_ip' => lang('reg. expr. for local IP\'s<br>eg. ^192\\.168\\.1\\.') 1001 )); 1002 1003 if (!is_array($this->bo->send_file_ips)) 1004 { 1005 $this->bo->send_file_ips = $this->link_pathes = array(); 1006 } 1007 $i = 0; @reset($this->link_pathes); 1008 do { 1009 list($valid,$trans) = @each($this->link_pathes); 1010 $GLOBALS['egw']->template->set_var(array( 1011 'tr_color' => $i & 1 ? 'row_off' : 'row_on', 1012 'num' => $i+1, 1013 'val_valid' => $this->html->input("valid[$i]",$valid), 1014 'val_trans' => $this->html->input("trans[$i]",$trans), 1015 'val_ip' => $this->html->input("ip[$i]",$this->bo->send_file_ips[$valid]) 1016 )); 1017 $GLOBALS['egw']->template->parse('admin_lines','admin_line',True); 1018 ++$i; 1019 } while ($valid); 1020 1021 if (!$this->tmpl->xslt) 1022 { 1023 echo parse_navbar(); 1024 $GLOBALS['egw']->template->pfp('phpgw_body','info_admin'); 1025 } 1026 else 1027 { 1028 $GLOBALS['egw']->template->fp('phpgw_body','info_admin'); 1029 } 1030 } 1031 1032 /** 1033 * writes langfile with all templates and messages registered here 1034 * 1035 * called via [write Langfile] in the etemplate-editor or as http://domain/egroupware/index.php?menuaction=infolog.uiinfolog.writeLangFile 1036 */ 1037 function writeLangFile() 1038 { 1039 $extra = $this->messages + $this->filters; 1040 $enums = $this->bo->enums + $this->bo->status; 1041 unset($enums['defaults']); 1042 foreach($enums as $key => $msg_arr) 1043 { 1044 $extra += $msg_arr; 1045 } 1046 return $this->tmpl->writeLangFile('infolog','en',$extra); 1047 } 1048 1049 /** 1050 * shows infolog in other applications 1051 * 1052 * @param $args['location'] location des hooks: {addressbook|projects|calendar}_view|infolog 1053 * @param $args['view'] menuaction to view, if location == 'infolog' 1054 * @param $args['app'] app-name, if location == 'infolog' 1055 * @param $args['view_id'] name of the id-var for location == 'infolog' 1056 * @param $args[$args['view_id']] id of the entry 1057 * this function can be called for any app, which should include infolog: \ 1058 * $GLOBALS['egw']->hooks->process(array( \ 1059 * * 'location' => 'infolog', \ 1060 * * 'app' => <your app>, \ 1061 * * 'view_id' => <id name>, \ 1062 * * <id name> => <id value>, \ 1063 * * 'view' => <menuaction to view an entry in your app> \ 1064 * )); 1065 */ 1066 function hook_view($args) 1067 { 1068 switch ($args['location']) 1069 { 1070 case 'addressbook_view': 1071 $app = 'addressbook'; 1072 $view_id = 'ab_id'; 1073 $view_id2 = 'contact_id'; 1074 $view = 'addressbook.uicontacts.view'; 1075 break; 1076 case 'projects_view': 1077 $app = 'projects'; 1078 $view_id = 'project_id'; 1079 $view = 'projects.uiprojects.view'; 1080 break; 1081 default: 1082 $app = $args['app']; 1083 $view_id = $args['view_id']; 1084 $view = $args['view']; 1085 } 1086 if (!is_array($args) || $args['debug']) 1087 { 1088 echo "<p>uiinfolog::hook_view("; print_r($args); echo "): app='$app', $view_id='$args[$view_id]', view='$view'</p>\n"; 1089 } 1090 if (!isset($app) || !isset($args[$view_id])) 1091 { 1092 return False; 1093 } 1094 $this->called_by = $app; // for read/save_sessiondata, to have different sessions for the hooks 1095 1096 $GLOBALS['egw']->translation->add_app('infolog'); 1097 1098 $GLOBALS['egw_info']['etemplate']['hooked'] = True; 1099 $this->index(0,$app,$args[$view_id],array( 1100 'menuaction' => $view, 1101 isset($view_id2) ? $view_id2 : $view_id => $args[$view_id] 1102 ),True); 1103 unset($GLOBALS['egw_info']['etemplate']['hooked']); 1104 } 1105 }
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 |