[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 include(dirname(__FILE__) . SEP . 'class.workflow.inc.php'); 4 5 class ui_adminactivities extends workflow 6 { 7 var $public_functions = array( 8 'form' => true, 9 'show_graph' => true 10 ); 11 12 var $process_manager; 13 14 var $activity_manager; 15 16 var $role_manager; 17 18 var $where2; 19 var $sort_mode2; 20 21 //agents handling 22 var $agents=Array(); 23 24 function ui_adminactivities() 25 { 26 parent::workflow(); 27 28 //regis: acl check 29 if ( !(($GLOBALS['egw']->acl->check('run',1,'admin')) || ($GLOBALS['egw']->acl->check('admin_workflow',1,'workflow'))) ) 30 { 31 $GLOBALS['egw']->common->egw_header(); 32 echo parse_navbar(); 33 echo lang('access not permitted'); 34 $GLOBALS['egw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminactivities'); 35 $GLOBALS['egw']->log->commit(); 36 $GLOBALS['egw']->common->egw_exit(); 37 } 38 39 $this->process_manager =& CreateObject('workflow.workflow_processmanager'); 40 $this->activity_manager =& CreateObject('workflow.workflow_activitymanager'); 41 $this->role_manager =& CreateObject('workflow.workflow_rolemanager'); 42 43 } 44 45 function form() 46 { 47 $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Process Activities'); 48 $GLOBALS['egw']->common->egw_header(); 49 echo parse_navbar(); 50 51 $this->t->set_file('admin_activities', 'admin_activities.tpl'); 52 $this->t->set_block('admin_activities', 'block_select_type', 'select_type'); 53 $this->t->set_block('admin_activities', 'block_activity_roles', 'activity_roles'); 54 $this->t->set_block('admin_activities', 'block_process_roles', 'process_roles'); 55 $this->t->set_block('admin_activities', 'block_activity_agents', 'activity_agents'); 56 $this->t->set_block('admin_activities', 'block_select_agents', 'select_agents'); 57 $this->t->set_block('admin_activities', 'block_select_default_user', 'select_default_user'); 58 59 $activity_id = (int)get_var('activity_id', 'any', 0); 60 $name = get_var('name', 'any', ''); 61 62 // TODO: not all variables below are still required. clean up 63 64 $description = get_var('description', 'any', ''); 65 $type = get_var('type', 'any', ''); 66 $is_interactive = get_var('is_interactive', 'any', ''); 67 $is_autorouted = get_var('is_autorouted', 'any', ''); 68 $default_user = get_var('default_user', 'any', ''); 69 $useagent = get_var('useagent', 'POST', ''); 70 $where = get_var('where', array('GET', 'POST'), ''); 71 $this->where2 = get_var('where2', 'any', ''); 72 $find = get_var('find', 'any', ''); 73 $find2 = get_var('find2', 'any', ''); 74 $this->sort_mode2 = get_var('sort_mode2', 'any', ''); 75 $filter_trans_from = get_var('filter_trans_from', 'any', ''); 76 $this->order = get_var('order', 'GET', 'wf_flow_num'); 77 $this->sort = get_var('sort', 'GET', 'asc'); 78 $this->sort_mode = $this->order . '__'. $this->sort; 79 //action compilation 80 $compile = get_var('compile', 'GET', False); 81 //roles 82 $activity_role_ro = get_var('activity_role_ro','POST', Array()); 83 $activity_role_delete = get_var('activity_role_delete','POST', Array()); 84 $remove_roles = get_var('remove_roles', 'POST', false); 85 $rolename = get_var('rolename', 'POST', ''); 86 $roledescription = get_var('roledescription', 'POST', ''); 87 $userole = get_var('userole', 'POST', ''); 88 $userole_ro = get_var('userole_ro', 'POST', 'off'); 89 $newrole_ro = get_var('newrole_ro', 'POST', 'off'); 90 91 92 if (!$this->wf_p_id) die(lang('No process indicated')); 93 94 // ************************************* START OF OPERATIONS COMMANDED BY THIS SAME FORM ****************** 95 // do we need to check validity? do it only if necessary, high load on database 96 $checkvalidity=false; 97 if ($compile) 98 { 99 $process_activities =& $this->activity_manager->list_activities($this->wf_p_id, 0, -1, $this->sort_mode, $find, $where); 100 foreach ($process_activities['data'] as $key => $activity) 101 { 102 $this->message[] = lang('compiling activity %1 : %2',$activity['wf_activity_id'], $activity['wf_name']); 103 $this->message = array_merge($this->message, $this->activity_manager->compile_activity($this->wf_p_id,$activity['wf_activity_id'])); 104 } 105 $checkvalidity = true; 106 } 107 108 // add role to process roles 109 if( !(empty($rolename)) ) 110 { 111 $rolename = trim($rolename); 112 if( strlen($rolename) > 0 ) 113 { 114 //second parameter for read-only mode 115 $newrole_id = $this->add_process_role($rolename, $roledescription); 116 if ($newrole_id) 117 { 118 $this->message[] = lang('Role added to process'); 119 if ($activity_id) 120 { 121 $this->activity_manager->add_activity_role($activity_id, $newrole_id, ($newrole_ro=='on')); 122 $this->message[] = lang('Role added to activity'); 123 } 124 $checkvalidity = true; 125 } 126 127 } 128 else 129 { 130 $this->message[] = lang('Invalid role name'); 131 } 132 } 133 134 // remove activity role 135 if (!!($remove_roles) && $activity_id) 136 { 137 foreach ($activity_role_delete as $role_id => $checked_on) 138 { 139 $this->activity_manager->remove_activity_role($activity_id, $role_id); 140 $this->message[] = lang('Activity role #%1 removed', $role_id); 141 } 142 $this->message[] = $this->activity_manager->get_error(false, _DEBUG); 143 $checkvalidity = true; 144 } 145 146 // remove activity agent 147 if (isset($_GET['remove_agent']) && $activity_id) 148 { 149 $this->activity_manager->remove_activity_agent($activity_id, $_GET['remove_agent'],true); 150 $this->message[] = lang('Activity agent removed'); 151 $this->message[] = $this->activity_manager->get_error(false, _DEBUG); 152 } 153 154 // TODO: activityname need to be valid. Add a validity checking function? 155 // save activity 156 if (isset($_POST['save_act'])) 157 { 158 $activity_id = $this->save_activity($activity_id, $name, $description, $type, $default_user, $is_interactive, $is_autorouted, $userole, $userole_ro, $useagent, $rolename); 159 if( $activity_id ) 160 { 161 $this->message[] = lang('Activity saved'); 162 } 163 //no checkvalidity, this is done already in ActivityManager 164 } 165 166 // delete activity 167 if (isset($_POST['delete_act'])) 168 { 169 if( isset($_POST['activities']) ) 170 { 171 if ($this->delete_activities(array_keys($_POST['activities']))) $this->message[] = lang('Deletion successful'); 172 $checkvalidity = true; 173 } 174 } 175 176 // add transitions 177 if (isset($_POST['add_trans'])) 178 { 179 $this->message[] = $this->add_transition($_POST['wf_act_from_id'], $_POST['wf_act_to_id']); 180 $checkvalidity = true; 181 } 182 183 // delete transitions 184 if (isset($_POST['delete_tran'])) 185 { 186 $this->delete_transitions($_POST['transition']); 187 $checkvalidity = true; 188 } 189 190 // ************************************* END OF OPERATIONS COMMANDED BY THIS SAME FORM ****************** 191 192 // retrieve activity info and its roles and agents 193 if (!$activity_id || isset($_POST['new_activity'])) 194 { 195 $activity_info = array( 196 'wf_name' => '', 197 'wf_description' => '', 198 'wf_activity_id' => 0, 199 'wf_is_interactive' => true, 200 'wf_is_autorouted' => false, 201 'wf_default_user' => '*', 202 'wf_type' => 'activity' 203 ); 204 $activity_roles = array(); 205 $activity_agents = array(); 206 } 207 else 208 { 209 $activity_info =& $this->activity_manager->get_activity($activity_id); 210 $activity_roles =& $this->activity_manager->get_activity_roles($activity_id); 211 $activity_agents =& $this->activity_manager->get_activity_agents($activity_id); 212 //for all agents we create ui_agent object to handle admin agents displays 213 //this array can be already done by the save_activity function, in this case 214 // we will just actualize most of the records 215 foreach ($activity_agents as $agent) 216 { 217 if (empty($this->agents[$agent['wf_agent_type']])) 218 { 219 $ui_agent =& createObject('workflow.ui_agent_'.$agent['wf_agent_type']); 220 $ui_agent->load($agent['wf_agent_id']); 221 $this->agents[$agent['wf_agent_type']] = $ui_agent; 222 unset($ui_agent); 223 } 224 else 225 { 226 $this->agents[$agent['wf_agent_type']]->load($agent['wf_agent_id']); 227 } 228 } 229 } 230 231 // fill type filter select box 232 $activity_types = array('start', 'end', 'activity', 'switch', 'split', 'join', 'standalone', 'view'); 233 $filter_type = get_var('filter_type', 'any', ''); 234 $this->show_select_filter_type($activity_types, $filter_type); 235 236 $filter_interactive = get_var('filter_interactive', 'any', ''); 237 $activity_interactive = array('y' => lang('Interactive'), 'n'=>lang('Automatic')); 238 $this->show_select_filter_interactive($activity_interactive, $filter_interactive); 239 240 $filter_autoroute = get_var('filter_autoroute', 'any', ''); 241 $activity_autoroute = array('y' => lang('Auto Routed'), 'n'=>lang('Manual')); 242 $this->show_select_filter_autoroute($activity_autoroute, $filter_autoroute); 243 244 $where = ''; 245 $wheres = array(); 246 if( !($filter_type == '') ) 247 { 248 $wheres[] = "wf_type = '" .$filter_type. "'"; 249 } 250 if( !($filter_interactive == '') ) 251 { 252 $wheres[] = "wf_is_interactive = '" .$filter_interactive. "'"; 253 } 254 if( !($filter_autoroute == '') ) 255 { 256 $wheres[] = "wf_is_autorouted = '" .$filter_autoroute. "'"; 257 } 258 if( count($wheres) > 0 ) 259 { 260 $where = implode(' and ', $wheres); 261 } 262 263 $proc_info =& $this->process_manager->get_process($this->wf_p_id); 264 if (empty($process_activities)) $process_activities =& $this->activity_manager->list_activities($this->wf_p_id, 0, -1, $this->sort_mode, $find, $where); 265 $all_transition_activities_from =& $this->activity_manager->get_transition_activities($this->wf_p_id, 'end'); 266 $all_transition_activities_to =& $this->activity_manager->get_transition_activities($this->wf_p_id, 'start'); 267 if ($activity_id) $this->search_transitions_act($process_activities, $activity_id); 268 $process_roles =& $this->role_manager->list_roles($this->wf_p_id, 0, -1, 'wf_name__asc', ''); 269 $agents_list =& $this->process_manager->get_agents(); 270 $all_process_transitions =& $this->activity_manager->get_process_transitions($this->wf_p_id); 271 $process_transitions =& $this->activity_manager->get_process_transitions($this->wf_p_id, $filter_trans_from); 272 $process_activities_with_transitions =& $this->activity_manager->get_process_activities_with_transitions($this->wf_p_id); 273 274 // update activities 275 if (isset($_POST['update_act'])) 276 { 277 if( is_array($process_activities['data']) && count($process_activities['data']) > 0 ) 278 { 279 $this->update_activities($process_activities, array_keys($_POST['activity_inter']), array_keys($_POST['activity_route'])); 280 $this->message[] = lang('Activities updated'); 281 } 282 } 283 284 // activate process 285 if (isset($_GET['activate_proc'])) 286 { 287 $this->process_manager->activate_process($_GET['activate_proc']); 288 $proc_info['wf_is_active'] = 'y'; 289 } 290 291 // deactivate process 292 if (isset($_GET['deactivate_proc'])) 293 { 294 $this->process_manager->deactivate_process($_GET['deactivate_proc']); 295 $proc_info['wf_is_active'] = 'n'; 296 } 297 298 //regis : warning, heavy database load! 299 // check process validity and show errors if necessary 300 if ($checkvalidity) $proc_info['wf_is_valid'] = $this->show_errors($this->activity_manager, $error_str); 301 302 // fill proc_bar 303 $this->t->set_var('proc_bar', $this->fill_proc_bar($proc_info)); 304 305 //collect some messages from used objects 306 $this->message[] = $this->activity_manager->get_error(false, _DEBUG); 307 $this->message[] = $this->process_manager->get_error(false, _DEBUG); 308 $this->message[] = $this->role_manager->get_error(false, _DEBUG); 309 310 // fill the general variables of the template 311 $this->t->set_var(array( 312 'message' => implode('<br>', array_filter($this->message)), 313 'errors' => $error_str, 314 'form_details_action' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'), 315 'form_list_transitions_action' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'), 316 'p_id' => $this->wf_p_id, 317 'where' => $where, 318 'where2' => $this->where2, 319 'sort_mode' => $this->sort_mode, 320 'sort_mode2' => $this->sort_mode2, 321 'find' => $find, 322 'find2' => $find2, 323 'activity_id' => $activity_info['wf_activity_id'], 324 'new_act_href' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'), 325 'name' => $activity_info['wf_name'], 326 'description' => $activity_info['wf_description'], 327 'checked_interactive' => ($activity_info['wf_is_interactive'])? 'checked="checked"' : '', 328 'checked_autorouted' => ($activity_info['wf_is_autorouted'])? 'checked="checked"' : '', 329 'img_transition_auto' => '<img src="'.$GLOBALS['egw']->common->image('workflow', 'transition_interactive.gif') .'" alt="'. lang('transition mode') .'" />', 330 'img_interactive' => '<img src="'.$GLOBALS['egw']->common->image('workflow', 'mini_interactive.gif') .'" alt="'. lang('interactivity') .'" />', 331 'img_transition' => '<img src="'.$GLOBALS['egw']->common->image('workflow', 'transition.gif') .'" alt="'. lang('transitions') .'" />', 332 'img_transition_add' => '<img src="'.$GLOBALS['egw']->common->image('workflow', 'transition_add.gif') .'" alt="'. lang('add transition') .'" />', 333 'img_transition_delete' => '<img src="'.$GLOBALS['egw']->common->image('workflow', 'transition_remove.gif') .'" alt="'. lang('delete transition') .'" />', 334 'add_trans_from' => $this->build_select_transition('add_tran_from[]', $all_transition_activities_from['data'], true, false, 'from'), 335 'add_trans_to' => $this->build_select_transition('add_tran_to[]', $all_transition_activities_to['data'], true, false, 'to'), 336 'add_a_trans_from' => $this->build_select_transition('wf_act_from_id', $all_transition_activities_from['data'], false, false), 337 'add_a_trans_to' => $this->build_select_transition('wf_act_to_id', $all_transition_activities_to['data'], false, false) 338 )); 339 340 if( $filter_trans_from ) { 341 $this->t->set_var('filter_trans_from', $this->build_select_transition_filtered('filter_trans_from', $process_activities_with_transitions['data'], false, true, $filter_trans_from)); 342 $this->t->set_var('filter_trans_from_value', $filter_trans_from); 343 } 344 else { 345 $this->t->set_var('filter_trans_from', $this->build_select_transition_filtered('filter_trans_from', $process_activities_with_transitions['data'], false, true, false)); 346 $this->t->set_var('filter_trans_from_value', ''); 347 } 348 349 // show process activities table 350 $this->show_process_activities($process_activities['data']); 351 352 353 foreach ($activity_types as $type) 354 { 355 $this->t->set_var(array( 356 'type_value' => $type, 357 'type_selected' => ($activity_info['wf_type'] == $type)? 'selected="selected"' : '', 358 'type_name' => lang($type) 359 )); 360 $this->t->parse('select_type', 'block_select_type', true); 361 } 362 363 // fill activity roles 364 if (!$activity_roles) 365 { 366 $this->t->set_var('activity_roles', '<tr><td colspan="3">'.lang('No roles asociated with this activity').'</td></tr>'); 367 } 368 else 369 { 370 foreach ($activity_roles as $role) 371 { 372 $this->t->set_var(array( 373 'act_role_name' => $role['wf_name'], 374 'act_role_id' => $role['wf_role_id'], 375 'act_role_ro_checked' => ($role['wf_readonly'])? 'checked="checked"' : '', 376 'act_role_href' => $GLOBALS['egw']->link('/index.php', array( 377 'menuaction' => 'workflow.ui_adminactivities.form', 378 'where2' => $where2, 379 'sort_mode2' => $sort_mode2, 380 'find' => $find, 381 'where' => $where, 382 'activity_id' => $activity_info['wf_activity_id'], 383 'p_id' => $this->wf_p_id, 384 'remove_role' => $role['wf_role_id'], 385 )), 386 'lang_delete' => lang('delete'), 387 )); 388 $this->t->parse('activity_roles', 'block_activity_roles', True); 389 } 390 391 } 392 393 //general texts about roles 394 $this->t->set_var(array( 395 'txt_read_only' => lang('read-only'), 396 'txt_role_name' => lang('Role Name'), 397 'txt_Remove_selected_roles' => lang('remove selected roles'), 398 'txt_Use_existing_roles' => lang('Use existing roles'), 399 ) 400 ); 401 402 // fill activity agents 403 if (!$activity_agents) 404 { 405 $this->t->set_var(array( 406 'activity_agents' => lang('No agents associated with this activity'), 407 'agents_config_rows' => '', 408 )); 409 } 410 else 411 { 412 foreach ($activity_agents as $agent) 413 { 414 $this->t->set_var(array( 415 'act_agent_type' => $agent['wf_agent_type'], 416 'act_agent_href' => $GLOBALS['egw']->link('/index.php', array( 417 'menuaction' => 'workflow.ui_adminactivities.form', 418 'where2' => $where2, 419 'sort_mode2' => $sort_mode2, 420 'find' => $find, 421 'where' => $where, 422 'activity_id' => $activity_info['wf_activity_id'], 423 'p_id' => $this->wf_p_id, 424 'remove_agent' => $agent['wf_agent_id'], 425 )), 426 'lang_delete' => lang('delete'), 427 )); 428 $this->t->parse('activity_agents', 'block_activity_agents', True); 429 } 430 } 431 432 //display agents options 433 $this->display_agents_rows(); 434 435 // fill user list for the Default user menu 436 $users = $GLOBALS['egw']->accounts->get_list('accounts'); 437 // if we have no default user 438 $this->t->set_var(array( 439 'default_user_selected_none' => ($activity_info['wf_default_user'] == '*')? 'selected="selected"' : '', 440 )); 441 // now parse users 442 foreach($users as $user) 443 { 444 if ($user['account_lid'] != '') 445 { 446 $username = $user['account_lastname'].' '. $user['account_firstname'].' ('.$user['account_lid'].')'; 447 } 448 else 449 { 450 $username = $user['account_fullname']; 451 } 452 $this->t->set_var(array( 453 'default_user_value' => $user['account_id'], 454 'default_user_name' => $username, 455 'default_user_selected' => ($activity_info['wf_default_user'] == $user['account_id'])? 'selected="selected"' : '' 456 )); 457 $this->t->parse('select_default_user', 'block_select_default_user', True); 458 } 459 460 // fill process roles 461 foreach ($process_roles['data'] as $role) 462 { 463 $this->t->set_var(array( 464 'proc_roleId' => $role['wf_role_id'], 465 'proc_roleName' => $role['wf_name'] 466 )); 467 $this->t->parse('process_roles', 'block_process_roles', True); 468 } 469 470 // fill agents select 471 foreach ($agents_list as $agent) 472 { 473 $this->t->set_var(array( 474 'select_agentType' => $agent['wf_agent_type'] 475 )); 476 $this->t->parse('select_agents', 'block_select_agents', True); 477 } 478 479 // fill list of transitions table 480 $this->show_transitions_table($process_transitions); 481 $this->t->set_var('filter_type_value', $filter_type); 482 $this->t->set_var('filter_interactive_value', $filter_interactive); 483 $this->t->set_var('filter_autoroute_value', $filter_autoroute); 484 $this->t->set_var('find_value', $find); 485 486 // create graph 487 $this->activity_manager->build_process_graph($this->wf_p_id); 488 489 $this->translate_template('admin_activities'); 490 $this->t->pparse('output', 'admin_activities'); 491 $GLOBALS['egw']->common->egw_footer(); 492 } 493 494 function show_select_filter_type($all_activity_types, $filter_type) 495 { 496 $this->t->set_block('admin_activities', 'block_select_filter_type', 'select_filter_type'); 497 $this->t->set_var('selected_filter_type_all', (!($filter_type))? 'selected="selected"' : ''); 498 499 foreach ($all_activity_types as $type) 500 { 501 $this->t->set_var(array( 502 'selected_filter_type' => ($filter_type == $type)? 'selected="selected"' : '', 503 'filter_type_name' => lang($type), 504 'filter_type_en_name' => $type 505 )); 506 $this->t->parse('select_filter_type', 'block_select_filter_type', true); 507 } 508 } 509 function show_select_filter_interactive($all_activity_interactive, $filter_interactive) 510 { 511 $this->t->set_block('admin_activities', 'block_select_filter_interactive', 'select_filter_interactive'); 512 $this->t->set_var('selected_filter_interactive_all', (!($filter_interactive))? 'selected="selected"' : ''); 513 514 foreach ($all_activity_interactive as $value=>$name) 515 { 516 $this->t->set_var(array( 517 'selected_filter_interactive' => ($filter_interactive == $value)? 'selected="selected"' : '', 518 'filter_interactive_name' => $name, 519 'filter_interactive_value' => $value 520 )); 521 $this->t->parse('select_filter_interactive', 'block_select_filter_interactive', true); 522 } 523 } 524 525 function show_select_filter_autoroute($all_activity_autoroute, $filter_autoroute) 526 { 527 $this->t->set_block('admin_activities', 'block_select_filter_autoroute', 'select_filter_autoroute'); 528 $this->t->set_var('selected_filter_autoroute_all', (!($filter_autoroute))? 'selected="selected"' : ''); 529 530 foreach ($all_activity_autoroute as $value=>$name) 531 { 532 $this->t->set_var(array( 533 'selected_filter_autoroute' => ($filter_autoroute == $value)? 'selected="selected"' : '', 534 'filter_autoroute_name' => $name, 535 'filter_autoroute_value' => $value 536 )); 537 $this->t->parse('select_filter_autoroute', 'block_select_filter_autoroute', true); 538 } 539 } 540 541 function update_activities(&$process_activities, $activities_inter, $activities_route) 542 { 543 $num_activities = count($process_activities['data']); 544 for ($i=0; $i < $num_activities; $i++) 545 { 546 $act_id = $process_activities['data'][$i]['wf_activity_id']; 547 if ($process_activities['data'][$i]['wf_is_interactive'] == 'y' && !in_array($act_id, $activities_inter)) 548 { 549 $process_activities['data'][$i]['wf_is_interactive'] = 'n'; 550 $this->activity_manager->set_interactivity($this->wf_p_id, $act_id, 'n'); 551 } 552 if ($process_activities['data'][$i]['wf_is_interactive'] == 'n' && in_array($act_id, $activities_inter)) 553 { 554 $process_activities['data'][$i]['wf_is_interactive'] = 'y'; 555 $this->activity_manager->set_interactivity($this->wf_p_id, $act_id, 'y'); 556 } 557 if ($process_activities['data'][$i]['wf_is_autorouted'] == 'y' && !in_array($act_id, $activities_route)) 558 { 559 $process_activities['data'][$i]['wf_is_autorouted'] = 'n'; 560 $this->activity_manager->set_autorouting($this->wf_p_id, $act_id, 'n'); 561 } 562 if ($process_activities['data'][$i]['wf_is_autorouted'] == 'n' && in_array($act_id, $activities_route)) 563 { 564 $process_activities['data'][$i]['wf_is_autorouted'] = 'y'; 565 $this->activity_manager->set_autorouting($this->wf_p_id, $act_id, 'y'); 566 } 567 } 568 } 569 570 /** 571 * * Add a role to the process 572 * * @param $rolename is the role name 573 * * @param $roledescription is the role description 574 * * @return new role id 575 */ 576 function add_process_role($rolename, $roledescription) 577 { 578 $vars = array( 579 'wf_name' => $rolename, 580 'wf_description' => $roledescription, 581 ); 582 return $this->role_manager->replace_role($this->wf_p_id, 0, $vars); 583 } 584 585 function search_transitions_act(&$process_activities, $act_id) 586 { 587 for ($i=0; $i < $process_activities['cant']; $i++) 588 { 589 $id = $process_activities['data'][$i]['wf_activity_id']; 590 $process_activities['data'][$i]['to'] = $this->activity_manager->transition_exists($this->wf_p_id, $act_id, $id)? 'y' : 'n'; 591 $process_activities['data'][$i]['from'] = $this->activity_manager->transition_exists($this->wf_p_id, $id, $act_id)? 'y' : 'n'; 592 } 593 } 594 595 function show_process_activities($process_activities_data) 596 { 597 $this->t->set_block('admin_activities', 'block_process_activities', 'process_activities'); 598 $this->t->set_var(array( 599 'form_process_activities_action'=> $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'), 600 'left_arrow' => $this->nextmatchs->left('index.php', $this->start, $this->total), 601 'right_arrow' => $this->nextmatchs->right('index.php', $this->start, $this->total), 602 )); 603 $this->translate_template('block_process_activities'); 604 605 $this->t->set_block('admin_activities', 'block_process_activities_header', 'process_activities_header'); 606 $this->t->set_block('admin_activities', 'block_process_activities_footer', 'process_activities_footer'); 607 if( is_array($process_activities_data) && count($process_activities_data) > 0 ) 608 { 609 $this->t->set_var(array( 610 'header_name' => $this->nextmatchs->show_sort_order($this->sort, 'wf_name', $this->order, 'index.php', lang('Name'), array('p_id'=>$this->wf_p_id)), 611 'header_type' => $this->nextmatchs->show_sort_order($this->sort, 'wf_type', $this->order, 'index.php', lang('Type'), array('p_id'=>$this->wf_p_id)), 612 'header_interactive' => $this->nextmatchs->show_sort_order($this->sort, 'wf_is_interactive', $this->order, 'index.php', lang('Interactive'), array('p_id'=>$this->wf_p_id)), 613 'header_route' => $this->nextmatchs->show_sort_order($this->sort, 'wf_is_autorouted', $this->order, 'index.php', lang('Auto routed'), array('p_id'=>$this->wf_p_id)), 614 'header_default_user' => lang('Default User') 615 )); 616 $this->translate_template('block_process_activities_header'); 617 $this->t->parse('process_activities_header', 'block_process_activities_header', True); 618 foreach ($process_activities_data as $activity) 619 { 620 if($activity['wf_default_user'] == '*' ) 621 { 622 $act_default_user = lang('None'); 623 } 624 else if($activity['wf_default_user'] != '*') 625 { 626 $act_default_user = $GLOBALS['egw']->accounts->id2name($activity['wf_default_user']); 627 } 628 629 $this->t->set_var(array( 630 'act_activity_id' => $activity['wf_activity_id'], 631 'act_flowNum' => $activity['wf_flow_num'], 632 'act_href' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $activity['wf_activity_id']), 633 'act_name' => $activity['wf_name'], 634 'no_roles' => ($activity['wf_roles'] < 1)? '<small>('.lang('no roles').')</small>' : '', 635 'act_icon' => $this->act_icon($activity['wf_type'],$activity['wf_is_interactive']), 636 'act_inter_checked' => ($activity['wf_is_interactive'] == 'y')? 'checked="checked"' : '', 637 'act_route_checked' => ($activity['wf_is_autorouted'] == 'y')? 'checked="checked"' : '', 638 'act_default_user' => $act_default_user, 639 'act_href_edit' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminsource.form&p_id='. $this->wf_p_id .'&activity_id='. $activity['wf_activity_id']), 640 'act_template' => ($activity['wf_is_interactive'] == 'y')? '<a href="'. $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminsource.form&p_id='. $this->wf_p_id .'&activity_id='. $activity['wf_activity_id'] .'&template=1') .'"><img src="'. $GLOBALS['egw']->common->image('workflow', 'template') .'" alt="' .lang('template') .'" title="' . lang('template') .'" /></a>' : '', 641 'img_code' => $GLOBALS['egw']->common->image('workflow', 'code'), 642 'color_line' => $this->nextmatchs->alternate_row_color($tr_color), 643 644 )); 645 $this->t->parse('process_activities', 'block_process_activities', True); 646 } 647 $this->translate_template('block_process_activities_footer'); 648 $this->t->parse('process_activities_footer', 'block_process_activities_footer', True); 649 } 650 else 651 { 652 $this->t->set_var('process_activities_header', ''); 653 $this->t->set_var('process_activities', '<tr><td colspan="7" align="center">'. lang('There are no processes with the current filter') .'</td></tr>'); 654 $this->t->set_var('process_activities_footer', ''); 655 } 656 } 657 658 function show_transitions_table($process_transitions) 659 { 660 $this->t->set_block('admin_activities', 'block_transitions_table', 'transitions_table'); 661 $this->t->set_block('admin_activities', 'block_transitions_table_footer', 'transitions_table_footer'); 662 $this->translate_template('block_transitions_table'); 663 $this->translate_template('block_transitions_table_footer'); 664 665 foreach ($process_transitions as $transition) 666 { 667 $this->t->set_var(array( 668 'trans_actFromId' => $transition['wf_act_from_id'], 669 'trans_actToId' => $transition['wf_act_to_id'], 670 'trans_href_from' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $transition['wf_act_from_id']), 671 'trans_actFromName' => $transition['wf_act_from_name'], 672 'trans_arrow' => $GLOBALS['egw']->common->image('workflow', 'next'), 673 'trans_href_to' => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $transition['wf_act_to_id']), 674 'trans_actToName' => $transition['wf_act_to_name'], 675 'color_line' => $this->nextmatchs->alternate_row_color($tr_color), 676 )); 677 $this->t->parse('transitions_table', 'block_transitions_table', true); 678 } 679 if (!count($process_transitions)) 680 { 681 $this->t->set_var('transitions_table', '<tr><td colspan="2" align="center">'. lang('There are no transitions defined') .'</td></tr>'); 682 $this->t->set_var('transitions_table_footer', ''); 683 } 684 else 685 { 686 $this->t->parse('transitions_table_footer', 'block_transitions_table_footer', true); 687 } 688 } 689 690 function build_select_transition($var_name, $process_activities_data, $multiple=false, $show_all=true, $from_or_to=false) 691 { 692 //echo "process_activities_data: <pre>";print_r($process_activities_data);echo "</pre>"; 693 $select_str = "<select name='$var_name'" . (($multiple)? " multiple='multiple' size='5'" : "" ) . ">"; 694 if ($show_all) $select_str .= '<option value="">'. lang('All') .'</option>'; 695 696 foreach ($process_activities_data as $activity) 697 { 698 if ($from_or_to && isset($activity[$from_or_to]) && $activity[$from_or_to] == 'y') 699 { 700 $selected = 'selected="selected"'; 701 } 702 else 703 { 704 $selected = ''; 705 } 706 $select_str .= '<option value="'. $activity['wf_activity_id'] .'" '. $selected .'>'. $activity['wf_name'] .'</option>'; 707 } 708 $select_str .= "</select>\n"; 709 return $select_str; 710 } 711 function build_select_transition_filtered($var_name, $process_activities_data, $multiple=false, $show_all=true, $from=false) 712 { 713 $select_str = "<select name='$var_name'" . (($multiple)? " multiple='multiple' size='5'" : "" ) . ">"; 714 if ($show_all) $select_str .= '<option value="">'. lang('All') .'</option>'; 715 716 if( is_array($process_activities_data) && count($process_activities_data) > 0 ) 717 { 718 foreach ($process_activities_data as $activity) 719 { 720 if ($from && $activity['wf_activity_id'] == $from ) 721 { 722 $selected = 'selected="selected"'; 723 } 724 else 725 { 726 $selected = ''; 727 } 728 $select_str .= '<option value="'. $activity['wf_activity_id'] .'" '. $selected .'>'. $activity['wf_name'] .'</option>'; 729 } 730 } 731 $select_str .= "</select>\n"; 732 return $select_str; 733 } 734 735 //! save the edited activity. Return the activity_id or false in case of error, $this->message is set in case of error 736 function save_activity($activity_id, $name, $description, $type, $default_user, $is_interactive, $is_autorouted, $userole, $userole_ro, $useagent) 737 { 738 $is_interactive = ($is_interactive == 'on') ? 'y' : 'n'; 739 $is_autorouted = ($is_autorouted == 'on') ? 'y' : 'n'; 740 $vars = array( 741 'wf_name' => $name, 742 'wf_description' => $description, 743 'wf_activity_id' => $activity_id, 744 'wf_is_interactive' => $is_interactive, 745 'wf_is_autorouted' => $is_autorouted, 746 'wf_default_user' => $default_user, 747 'wf_type' => $type, 748 ); 749 750 if( strlen($name) > 0 ) 751 { 752 if ($this->activity_manager->activity_name_exists($this->wf_p_id, $name, $activity_id)) 753 { 754 $this->message[] = ($name . ': '. lang('activity name already exists')); 755 return false; 756 } 757 } 758 else 759 { 760 $this->message[] = lang('Enter an activity name'); 761 return false; 762 } 763 764 $activity_id = $this->activity_manager->replace_activity($this->wf_p_id, $activity_id, $vars); 765 766 // assign role to activity 767 if ($userole) 768 { 769 $this->activity_manager->add_activity_role($activity_id, $userole, ($userole_ro=='on')); 770 } 771 772 // assign agent to activity 773 if ($useagent) 774 { 775 $this->activity_manager->add_activity_agent($activity_id, $useagent); 776 } 777 778 //save agent configuration datas if any 779 if (isset($_POST['wf_agent'])) 780 { 781 $agents_conf =& $_POST['wf_agent']; 782 783 //retrieve agents list 784 $activity_agents =& $this->activity_manager->get_activity_agents($activity_id); 785 //for all agents we create ui_agent object to handle admin agents displays and savings 786 foreach ($activity_agents as $agent) 787 { 788 //create an empty temp ui_agent object 789 $ui_agent =& createObject('workflow.ui_agent_'.$agent['wf_agent_type']); 790 //build this object BUT without loading actual data 791 //because we will save next values soon 792 $ui_agent->load($agent['wf_agent_id'],false); 793 //store it in an array 794 $this->agents[$agent['wf_agent_type']] = $ui_agent; 795 //delete the temp object 796 unset($ui_agent); 797 } 798 // now we save the data obtained from the form in theses agents 799 foreach ($agents_conf as $typeagent => $confarray) 800 { 801 $this->agents[$typeagent]->save($confarray); 802 } 803 } 804 805 // add activity transitions 806 if (isset($_POST['add_tran_from'])) 807 { 808 foreach ($_POST['add_tran_from'] as $act_from) 809 { 810 $this->activity_manager->add_transition($this->wf_p_id, $act_from, $activity_id); 811 } 812 } 813 if (isset($_POST['add_tran_to'])) 814 { 815 foreach ($_POST['add_tran_to'] as $act_to) 816 { 817 $this->activity_manager->add_transition($this->wf_p_id, $activity_id, $act_to); 818 } 819 } 820 $this->activity_manager->validate_process_activities($this->wf_p_id); 821 822 823 return $activity_id; 824 } 825 826 function delete_activities($activities_ids) 827 { 828 foreach ($activities_ids as $act_id) 829 { 830 $this->activity_manager->remove_activity($this->wf_p_id, $act_id); 831 } 832 return true; 833 } 834 835 function delete_transitions($transitions) 836 { 837 if( is_array($transitions) && count($transitions) > 0 ) { 838 foreach (array_keys($transitions) as $transition) 839 { 840 $parts = explode('_', $transition); 841 $this->activity_manager->remove_transition($parts[0], $parts[1]); 842 } 843 $this->message[] = lang('Transitions removed successfully'); 844 } 845 else 846 { 847 $this->message[] = lang('Select a transition to remove'); 848 } 849 } 850 851 function add_transition($from, $to) 852 { 853 if ($this->activity_manager->add_transition($this->wf_p_id, $from, $to)) 854 { 855 $this->activity_manager->validate_process_activities($this->wf_p_id); 856 return lang('New transition added'); 857 } 858 $error_msg = $this->activity_manager->get_error(false, _DEBUG); 859 return lang("Couldn't add transition"). '; '. $error_msg[0]; 860 } 861 862 function show_graph() 863 { 864 $proc_info = $this->process_manager->get_process($this->wf_p_id); 865 $image_name = $proc_info['wf_normalized_name'] . SEP . 'graph' . SEP . $proc_info['wf_normalized_name'] . '.png'; 866 $image = GALAXIA_PROCESSES . SEP . $image_name; 867 //die($image); 868 $dims = getimagesize($image); 869 header('content-disposition: inline; filename=' . $image_name); 870 header('content-type: ' . $dims['mime']); 871 header('content-length: ' . filesize($image)); 872 readfile($image); 873 } 874 875 /** 876 * * dislays th activity agents config rows 877 */ 878 function display_agents_rows() 879 { 880 if (empty($this->agents)) 881 { 882 $this->t->set_var(array('agents_config_rows' => '')); 883 } 884 else 885 { 886 $this->t->set_file('admin_agents', 'admin_agents.tpl'); 887 foreach ($this->agents as $ui_agent) 888 { 889 //this is parsing the agent's admin template in the given template var 890 $ui_agent->showAdminActivityOptions('each_agent_rows'); 891 } 892 $this->translate_template('admin_agents'); 893 $this->t->parse('agents_config_rows', 'admin_agents'); 894 } 895 } 896 } 897 ?>
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 |