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