[1349] | 1 | <?php |
---|
| 2 | //set here the global DEBUG level which is actually 0 (nothing) or 1 (all) |
---|
| 3 | if (!defined('_DEBUG')) define('_DEBUG', 0); |
---|
| 4 | /** |
---|
| 5 | * @package Workflow |
---|
| 6 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 7 | */ |
---|
| 8 | class WorkflowUtils |
---|
| 9 | { |
---|
| 10 | /** |
---|
| 11 | * @var array $public_functions Array of public functions |
---|
| 12 | * @access public |
---|
| 13 | */ |
---|
| 14 | var $public_functions = array( |
---|
| 15 | 'export' => true, |
---|
| 16 | ); |
---|
| 17 | /** |
---|
| 18 | * @var object $t the template |
---|
| 19 | * @access public |
---|
| 20 | */ |
---|
| 21 | var $t; |
---|
| 22 | /** |
---|
| 23 | * @var int wf_p_id |
---|
| 24 | * @access public |
---|
| 25 | */ |
---|
| 26 | var $wf_p_id; |
---|
| 27 | /** |
---|
| 28 | * @var array $message message array |
---|
| 29 | * @access public |
---|
| 30 | */ |
---|
| 31 | var $message = array(); |
---|
| 32 | |
---|
| 33 | //TODO: when migration to bo_workflow_forms will be closed erase theses vars-------------- |
---|
| 34 | //nextmatchs (max number of rows per page) and associated vars |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * @var int $nextmatchs |
---|
| 38 | * @access public |
---|
| 39 | */ |
---|
| 40 | var $nextmatchs; |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * @var int $start actual starting row number |
---|
| 44 | * @access public |
---|
| 45 | */ |
---|
| 46 | var $start; |
---|
| 47 | /** |
---|
| 48 | * @var int $total_records total number of rows |
---|
| 49 | * @access public |
---|
| 50 | */ |
---|
| 51 | var $total_records; |
---|
| 52 | /** |
---|
| 53 | * @var array $message message array column used for order |
---|
| 54 | * @access public |
---|
| 55 | */ |
---|
| 56 | var $order; |
---|
| 57 | /** |
---|
| 58 | * @var string $sort ASC or DESC |
---|
| 59 | * @access public |
---|
| 60 | */ |
---|
| 61 | var $sort; |
---|
| 62 | /** |
---|
| 63 | * @var array $sort_mode combination of order and sort |
---|
| 64 | * @access public |
---|
| 65 | */ |
---|
| 66 | var $sort_mode; |
---|
| 67 | /** |
---|
| 68 | * @var array $search_str |
---|
| 69 | * @access public |
---|
| 70 | */ |
---|
| 71 | var $search_str; |
---|
| 72 | //------------------------------------------------------------------------------------------ |
---|
| 73 | /** |
---|
| 74 | * @var array $stats |
---|
| 75 | * @access public |
---|
| 76 | */ |
---|
| 77 | var $stats; |
---|
| 78 | /** |
---|
| 79 | * @var array $wheres |
---|
| 80 | * @access public |
---|
| 81 | */ |
---|
| 82 | var $wheres = array(); |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * Constructor of workflow class |
---|
| 86 | * |
---|
| 87 | * @access public |
---|
| 88 | * @return void |
---|
| 89 | */ |
---|
| 90 | function WorkflowUtils() |
---|
| 91 | { |
---|
| 92 | // check version |
---|
| 93 | if (alessthanb($GLOBALS['phpgw_info']['apps']['workflow']['version'], '1.2.01.006')) |
---|
| 94 | { |
---|
| 95 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 96 | echo parse_navbar(); |
---|
| 97 | die("Please upgrade this application to be able to use it"); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | $this->t =& $GLOBALS['phpgw']->template; |
---|
| 101 | $this->wf_p_id = (int)get_var('p_id', 'any', 0); |
---|
| 102 | $this->start = (int)get_var('start', 'any', 0); |
---|
| 103 | $this->search_str = get_var('find', 'any', ''); |
---|
| 104 | $this->nextmatchs = CreateObject('phpgwapi.nextmatchs'); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * Fill the process bar |
---|
| 109 | * |
---|
| 110 | * @param array $proc_info |
---|
| 111 | * @access public |
---|
| 112 | * @return string |
---|
| 113 | */ |
---|
| 114 | function fill_proc_bar($proc_info) |
---|
| 115 | { |
---|
| 116 | //echo "proc_info: <pre>";print_r($proc_info);echo "</pre>"; |
---|
| 117 | $this->t->set_file('proc_bar_tpl', 'proc_bar.tpl'); |
---|
| 118 | $templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer'); |
---|
| 119 | |
---|
| 120 | if ($proc_info['wf_is_valid'] == 'y') |
---|
| 121 | { |
---|
| 122 | $dot_color = 'green'; |
---|
| 123 | $alt_validity = lang('valid'); |
---|
| 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | $dot_color = 'red'; |
---|
| 128 | $alt_validity = lang('invalid'); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | // if process is active show stop button. Else show start button, but only if it is valid. If it's not valid, don't show any activation or stop button. |
---|
| 132 | if ($proc_info['wf_is_active'] == 'y') |
---|
| 133 | { |
---|
| 134 | $start_stop = '<td><a href="'. $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&p_id='. $proc_info['wf_p_id'] .'&deactivate_proc='. $proc_info['wf_p_id']) .'"><img border ="0" src="'. $templateServer->generateImageLink('stop.gif') .'" alt="'. lang('stop') .'" title="'. lang('stop') .'" />'.lang('stop').'</a></td>'; |
---|
| 135 | } |
---|
| 136 | elseif ($proc_info['wf_is_valid'] == 'y') |
---|
| 137 | { |
---|
| 138 | $start_stop = '<td><a href="'. $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&p_id='. $proc_info['wf_p_id'] .'&activate_proc='. $proc_info['wf_p_id']) .'"><img border ="0" src="'. $templateServer->generateImageLink('refresh2.gif') .'" alt="'. lang('activate') .'" title="'. lang('activate') .'" />'.lang('activate').'</a></td>'; |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | $start_stop = ''; |
---|
| 143 | } |
---|
| 144 | $this->t->set_var(array( |
---|
| 145 | 'proc_name' => $proc_info['wf_name'], |
---|
| 146 | 'version' => $proc_info['wf_version'], |
---|
| 147 | 'img_validity' => $templateServer->generateImageLink($dot_color.'_dot.gif'), |
---|
| 148 | 'alt_validity' => $alt_validity, |
---|
| 149 | 'start_stop' => $start_stop, |
---|
| 150 | 'link_admin_activities' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&p_id='. $proc_info['wf_p_id']), |
---|
| 151 | 'img_activity' => $templateServer->generateImageLink('Activity.gif'), |
---|
| 152 | 'link_admin_jobs' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminjobs.form&p_id='. $proc_info['wf_p_id']), |
---|
| 153 | 'img_job' => $templateServer->generateImageLink('clock.png'), |
---|
| 154 | 'link_admin_processes' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminprocesses.form&p_id='. $proc_info['wf_p_id']), |
---|
| 155 | 'img_change' => $templateServer->generateImageLink('change.gif'), |
---|
| 156 | 'link_admin_shared_source' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminsource.form&p_id='. $proc_info['wf_p_id']), |
---|
| 157 | 'img_code' => $templateServer->generateImageLink('code.png'), |
---|
| 158 | 'link_admin_export' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.WorkflowUtils.export&p_id='. $proc_info['wf_p_id']), |
---|
| 159 | 'link_admin_roles' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form&p_id='. $proc_info['wf_p_id']), |
---|
| 160 | 'img_roles' => $templateServer->generateImageLink('roles.png'), |
---|
| 161 | 'link_graph' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.show_graph&p_id=' . $proc_info['wf_p_id']), |
---|
| 162 | 'img_process' => $templateServer->generateImageLink('Process.gif'), |
---|
| 163 | 'link_save_process' => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminprocesses.save_process&id='. $proc_info['wf_p_id']), |
---|
| 164 | 'img_save' => $templateServer->generateImageLink('save.png') |
---|
| 165 | )); |
---|
| 166 | |
---|
| 167 | $this->translate_template('proc_bar_tpl'); |
---|
| 168 | return $this->t->parse('proc_bar', 'proc_bar_tpl'); |
---|
| 169 | } |
---|
| 170 | /** |
---|
| 171 | * Select activity representation icon |
---|
| 172 | * |
---|
| 173 | * @var string $type type of activity |
---|
| 174 | * @var bool $interactive interactive? |
---|
| 175 | * @access public |
---|
| 176 | * @return void |
---|
| 177 | */ |
---|
| 178 | function act_icon($type, $interactive) |
---|
| 179 | { |
---|
| 180 | switch($type) |
---|
| 181 | { |
---|
| 182 | case 'activity': |
---|
| 183 | $ic = "mini_".(($interactive == 'y')? 'blue_':'')."rectangle.gif"; |
---|
| 184 | break; |
---|
| 185 | case 'switch': |
---|
| 186 | $ic = "mini_".(($interactive == 'y')? 'blue_':'')."diamond.gif"; |
---|
| 187 | break; |
---|
| 188 | case 'start': |
---|
| 189 | $ic="mini_".(($interactive == 'y')? 'blue_':'')."circle.gif"; |
---|
| 190 | break; |
---|
| 191 | case 'end': |
---|
| 192 | $ic="mini_".(($interactive == 'y')? 'blue_':'')."dbl_circle.gif"; |
---|
| 193 | break; |
---|
| 194 | case 'split': |
---|
| 195 | $ic="mini_".(($interactive == 'y')? 'blue_':'')."triangle.gif"; |
---|
| 196 | break; |
---|
| 197 | case 'join': |
---|
| 198 | $ic="mini_".(($interactive == 'y')? 'blue_':'')."inv_triangle.gif"; |
---|
| 199 | break; |
---|
| 200 | case 'standalone': |
---|
| 201 | $ic="mini_".(($interactive == 'y')? 'blue_':'')."hexagon.gif"; |
---|
| 202 | break; |
---|
| 203 | case 'view': |
---|
| 204 | $ic="mini_blue_eyes.gif"; |
---|
| 205 | break; |
---|
| 206 | default: |
---|
| 207 | $ic="no-activity.gif"; |
---|
| 208 | } |
---|
| 209 | return '<img src="'. $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink($ic) .'" alt="'. lang($type) .'" title="'. lang($type) .'" />'; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | /** |
---|
| 213 | * Translate template file |
---|
| 214 | * @param string $template_name template name |
---|
| 215 | * @return void |
---|
| 216 | * @access public |
---|
| 217 | */ |
---|
| 218 | function translate_template($template_name) |
---|
| 219 | { |
---|
| 220 | $undef = $this->t->get_undefined($template_name); |
---|
| 221 | if ($undef != False) |
---|
| 222 | { |
---|
| 223 | foreach ($undef as $value) |
---|
| 224 | { |
---|
| 225 | $valarray = explode('_', $value); |
---|
| 226 | $type = array_shift($valarray); |
---|
| 227 | $newval = implode(' ', $valarray); |
---|
| 228 | if ($type == 'lang') |
---|
| 229 | { |
---|
| 230 | $this->t->set_var($value, lang($newval)); |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | /** |
---|
| 236 | * Show errors |
---|
| 237 | * @param object $activity_manager |
---|
| 238 | * @param string $error_str destination string to place errors |
---|
| 239 | * @return bool |
---|
| 240 | * @access public |
---|
| 241 | */ |
---|
| 242 | function show_errors(&$activity_manager, &$error_str) |
---|
| 243 | { |
---|
| 244 | $valid = $activity_manager->validate_process_activities($this->wf_p_id); |
---|
| 245 | $errors = $activity_manager->get_error(true); |
---|
| 246 | $warnings = $activity_manager->get_warning(true); |
---|
| 247 | $tmp = array(); |
---|
| 248 | |
---|
| 249 | /* remove empty errors from the error list */ |
---|
| 250 | foreach ($errors as $index => $error) |
---|
| 251 | if (trim($error) == '') |
---|
| 252 | unset($errors[$index]); |
---|
| 253 | |
---|
| 254 | if ((count($warnings) > 0) || (count($errors) > 0)) |
---|
| 255 | { |
---|
| 256 | $error_str = ''; |
---|
| 257 | $output = 'y'; |
---|
| 258 | if (count($errors) > 0) |
---|
| 259 | { |
---|
| 260 | $error_str = '<b>' . lang('The following items must be corrected to be able to activate this process').':</b><br/><small><ul>'; |
---|
| 261 | foreach ($errors as $error) |
---|
| 262 | { |
---|
| 263 | $error_str .= '<li>'. $error . '<br/>'; |
---|
| 264 | } |
---|
| 265 | $error_str .= '</ul></small>'; |
---|
| 266 | $output = 'n'; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | if (count($warnings) > 0) |
---|
| 270 | { |
---|
| 271 | if ($error_str != '') |
---|
| 272 | $error_str .= "<br />"; |
---|
| 273 | |
---|
| 274 | $error_str .= '<b>' . lang('warnings in this process').':</b><br/><small><ul>'; |
---|
| 275 | foreach ($warnings as $warning) |
---|
| 276 | if (trim($warning) != '') |
---|
| 277 | $error_str .= '<li>'. $warning . '<br/>'; |
---|
| 278 | |
---|
| 279 | $error_str .= '</ul></small>'; |
---|
| 280 | } |
---|
| 281 | return $output; |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | $error_str = ''; |
---|
| 286 | return 'y'; |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | /** |
---|
| 291 | * Get source code |
---|
| 292 | * @param string $proc_name process name |
---|
| 293 | * @param string $act_name activity name |
---|
| 294 | * @param string $type actyvity type |
---|
| 295 | * @access public |
---|
| 296 | * @return string source code dat |
---|
| 297 | */ |
---|
| 298 | function get_source($proc_name, $act_name, $type) |
---|
| 299 | { |
---|
| 300 | switch($type) |
---|
| 301 | { |
---|
| 302 | case 'code': |
---|
| 303 | $path = 'activities' . SEP . $act_name . '.php'; |
---|
| 304 | break; |
---|
| 305 | case 'template': |
---|
| 306 | $path = 'templates' . SEP . $act_name . '.tpl'; |
---|
| 307 | break; |
---|
| 308 | default: |
---|
| 309 | $path = 'shared.php'; |
---|
| 310 | break; |
---|
| 311 | } |
---|
| 312 | $complete_path = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'code' . SEP . $path; |
---|
| 313 | if (!$file_size = filesize($complete_path)) return ''; |
---|
| 314 | $fp = fopen($complete_path, 'r'); |
---|
| 315 | $data = fread($fp, $file_size); |
---|
| 316 | fclose($fp); |
---|
| 317 | return $data; |
---|
| 318 | } |
---|
| 319 | /** |
---|
| 320 | * Save the source of process |
---|
| 321 | * |
---|
| 322 | * @param string $proc_name process name |
---|
| 323 | * @param string $act_name activity name |
---|
| 324 | * @param string $type type of activity |
---|
| 325 | * @param string $source source code of activity |
---|
| 326 | * @return void |
---|
| 327 | * @access public |
---|
| 328 | */ |
---|
| 329 | function save_source($proc_name, $act_name, $type, $source) |
---|
| 330 | { |
---|
| 331 | // in case code was filtered |
---|
| 332 | if (!$source) $source = @$GLOBALS['egw_unset_vars']['_POST[source]']; |
---|
| 333 | |
---|
| 334 | switch($type) |
---|
| 335 | { |
---|
| 336 | case 'code': |
---|
| 337 | $path = 'activities' . SEP . $act_name . '.php'; |
---|
| 338 | break; |
---|
| 339 | case 'template': |
---|
| 340 | $path = 'templates' . SEP . $act_name . '.tpl'; |
---|
| 341 | break; |
---|
| 342 | default: |
---|
| 343 | $path = 'shared.php'; |
---|
| 344 | break; |
---|
| 345 | } |
---|
| 346 | $complete_path = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'code' . SEP . $path; |
---|
| 347 | // In case you want to be warned when source code is changed: |
---|
| 348 | // mail('yourmail@domain.com', 'source changed', "PATH: $complete_path \n\n SOURCE: $source"); |
---|
| 349 | $fp = fopen($complete_path, 'w'); |
---|
| 350 | fwrite($fp, $source); |
---|
| 351 | fclose($fp); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | /** |
---|
| 355 | * Export process to a xml file to be downloaded |
---|
| 356 | * @access public |
---|
| 357 | * @return void |
---|
| 358 | */ |
---|
| 359 | function export() |
---|
| 360 | { |
---|
| 361 | $this->process_manager = CreateObject('workflow.workflow_processmanager'); |
---|
| 362 | |
---|
| 363 | // retrieve process info |
---|
| 364 | $proc_info = $this->process_manager->get_process($this->wf_p_id); |
---|
| 365 | $filename = $proc_info['wf_normalized_name'].'.xml'; |
---|
| 366 | $out = $this->process_manager->serialize_process($this->wf_p_id); |
---|
| 367 | $mimetype = 'application/xml'; |
---|
| 368 | // MSIE5 and Opera show allways the document if they recognise. But we want to oblige them do download it, so we use the mimetype x-download: |
---|
| 369 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7')) |
---|
| 370 | $mimetype = 'application/x-download'; |
---|
| 371 | // Show appropiate header for a file to be downloaded: |
---|
| 372 | header("content-disposition: attachment; filename=$filename"); |
---|
| 373 | header("content-type: $mimetype"); |
---|
| 374 | header('content-length: ' . strlen($out)); |
---|
| 375 | echo $out; |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | /** |
---|
| 379 | * Get the href link for the css file, searching for themes specifics stylesheet if any |
---|
| 380 | * @param string $css_name is the name of the css file, without the .css extension |
---|
| 381 | * @param bool $print_mode is false by default, if true '_print.css' is appended to the name if this css print file exists |
---|
| 382 | * @return string a string containing the link to a css file that you can use in a href, you'll have at least a link |
---|
| 383 | * to a non-existent css in template/default/css/ |
---|
| 384 | * @access public |
---|
| 385 | */ |
---|
| 386 | function get_css_link($css_name, $print_mode = false) |
---|
| 387 | { |
---|
| 388 | $file = "css/$css_name" . (($print_mode !== false) ? '_print' : '') . '.css'; |
---|
| 389 | return $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->getWebFile($file); |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | /** |
---|
| 393 | * Return a given duration in human readable form, usefull for workitems duration |
---|
| 394 | * @param int $to given duration |
---|
| 395 | * @return string given duration in human readable form |
---|
| 396 | * @access public |
---|
| 397 | */ |
---|
| 398 | function time_diff($to) { |
---|
| 399 | $days = (int)($to/(24*3600)); |
---|
| 400 | $to = $to - ($days*(24*3600)); |
---|
| 401 | $hours = (int)($to/3600); |
---|
| 402 | $to = $to - ($hours*3600); |
---|
| 403 | $min = date("i", $to); |
---|
| 404 | $to = $to - ($min*60); |
---|
| 405 | $sec = date("s", $to); |
---|
| 406 | |
---|
| 407 | return lang('%1 days, %2:%3:%4',$days,$hours,$min,$sec); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | } |
---|
| 411 | ?> |
---|