[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/workflow/inc/ -> class.workflow.inc.php (source)

   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      class workflow
   5      {
   6          var $public_functions = array(
   7              'export'    => true,
   8          );
   9          //the template
  10          var $t;
  11  
  12          var $wf_p_id;
  13  
  14          var $message = array();
  15  
  16          //TODO: when migration to bo_workflow_forms will be closed erase theses vars--------------
  17          //nextmatchs (max number of rows per page) and associated vars
  18          var $nextmatchs;
  19          var $start; //actual starting row number
  20          var $total_records; //total number of rows
  21          var $order; //column used for order
  22          var $sort; //ASC or DESC
  23          var $sort_mode; //combination of order and sort
  24          var $search_str;
  25          //------------------------------------------------------------------------------------------
  26  
  27          var $stats;
  28  
  29          var $wheres = array();
  30  
  31  		function workflow()
  32          {
  33              // check version
  34              if (substr($GLOBALS['egw_info']['apps']['workflow']['version'],0,6) != '1.2.01')
  35              {
  36                  $GLOBALS['egw']->common->egw_header();
  37                  echo parse_navbar();
  38                  die("Please upgrade this application to be able to use it");
  39              }
  40  
  41              $this->t        =& $GLOBALS['egw']->template;
  42              $this->wf_p_id        = (int)get_var('p_id', 'any', 0);
  43              $this->start        = (int)get_var('start', 'any', 0);
  44              $this->search_str    = get_var('find', 'any', '');
  45              $this->nextmatchs    =& CreateObject('phpgwapi.nextmatchs');
  46          }
  47  
  48  		function fill_proc_bar($proc_info)
  49          {
  50              //echo "proc_info: <pre>";print_r($proc_info);echo "</pre>";
  51              $this->t->set_file('proc_bar_tpl', 'proc_bar.tpl');
  52  
  53              if ($proc_info['wf_is_valid'] == 'y')
  54              {
  55                  $dot_color = 'green';
  56                  $alt_validity = lang('valid');
  57              }
  58              else
  59              {
  60                  $dot_color = 'red';
  61                  $alt_validity = lang('invalid');
  62              }
  63  
  64              // 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.
  65              if ($proc_info['wf_is_active'] == 'y')
  66              {
  67                  $start_stop = '<td><a href="'. $GLOBALS['egw']->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="'. $GLOBALS['egw']->common->image('workflow', 'stop') .'" alt="'. lang('stop') .'" title="'. lang('stop') .'" />'.lang('stop').'</a></td>';
  68              }
  69              elseif ($proc_info['wf_is_valid'] == 'y')
  70              {
  71                  $start_stop = '<td><a href="'. $GLOBALS['egw']->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="'. $GLOBALS['egw']->common->image('workflow', 'refresh2') .'" alt="'. lang('activate') .'" title="'. lang('activate') .'" />'.lang('activate').'</a></td>';
  72              }
  73              else
  74              {
  75                  $start_stop = '';
  76              }
  77              $this->t->set_var(array(
  78                  'proc_name'            => $proc_info['wf_name'],
  79                  'version'            => $proc_info['wf_version'],
  80                  'img_validity'            => $GLOBALS['egw']->common->image('workflow', $dot_color.'_dot'),
  81                  'alt_validity'            => $alt_validity,
  82                  'start_stop'            => $start_stop,
  83                  'link_admin_activities'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&p_id='. $proc_info['wf_p_id']),
  84                  'img_activity'            => $GLOBALS['egw']->common->image('workflow', 'Activity'),
  85                  'link_admin_processes'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminprocesses.form&p_id='. $proc_info['wf_p_id']),
  86                  'img_change'            => $GLOBALS['egw']->common->image('workflow', 'change'),
  87                  'link_admin_shared_source'    => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminsource.form&p_id='. $proc_info['wf_p_id']),
  88                  'img_code'            => $GLOBALS['egw']->common->image('workflow', 'code'),
  89                  'link_admin_export'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.workflow.export&p_id='. $proc_info['wf_p_id']),
  90                  'link_admin_roles'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form&p_id='. $proc_info['wf_p_id']),
  91                  'img_roles'            => $GLOBALS['egw']->common->image('workflow', 'roles'),
  92                  'link_graph'            => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.show_graph&p_id=' . $proc_info['wf_p_id']),
  93                  'img_process'            => $GLOBALS['egw']->common->image('workflow', 'Process'),
  94                  'link_save_process'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminprocesses.save_process&id='. $proc_info['wf_p_id']),
  95                  'img_save'            => $GLOBALS['egw']->common->image('workflow', 'save'),
  96                  'link_compile'            => $GLOBALS['egw']->link('/index.php', array(
  97                      'menuaction'    =>     'workflow.ui_adminactivities.form',
  98                      'p_id'        =>    $proc_info['wf_p_id'],
  99                      'compile'    =>    true,
 100                  )),
 101                  'img_compile'            => $GLOBALS['egw']->common->image('workflow', 'compilation'),
 102              ));
 103  
 104              $this->translate_template('proc_bar_tpl');
 105              return $this->t->parse('proc_bar', 'proc_bar_tpl');
 106          }
 107  
 108  		function act_icon($type, $interactive)
 109          {
 110              switch($type)
 111              {
 112                  case 'activity':
 113                      $ic = "mini_".(($interactive == 'y')? 'blue_':'')."rectangle.gif";
 114                      break;
 115                  case 'switch':
 116                      $ic = "mini_".(($interactive == 'y')? 'blue_':'')."diamond.gif";
 117                      break;
 118                  case 'start':
 119                      $ic="mini_".(($interactive == 'y')? 'blue_':'')."circle.gif";
 120                      break;
 121                  case 'end':
 122                      $ic="mini_".(($interactive == 'y')? 'blue_':'')."dbl_circle.gif";
 123                      break;
 124                  case 'split':
 125                      $ic="mini_".(($interactive == 'y')? 'blue_':'')."triangle.gif";
 126                      break;
 127                  case 'join':
 128                      $ic="mini_".(($interactive == 'y')? 'blue_':'')."inv_triangle.gif";
 129                      break;
 130                  case 'standalone':
 131                      $ic="mini_".(($interactive == 'y')? 'blue_':'')."hexagon.gif";
 132                      break;
 133                  case 'view':
 134                      $ic="mini_blue_eyes.gif";
 135                      break;
 136                  default:
 137                      $ic="no-activity.gif";
 138              }
 139              return '<img src="'. $GLOBALS['egw']->common->image('workflow', $ic) .'" alt="'. lang($type) .'" title="'. lang($type) .'" />';
 140          }
 141  
 142  		function translate_template($template_name)
 143          {
 144              $undef = $this->t->get_undefined($template_name);
 145              if ($undef != False)
 146              {
 147                  foreach ($undef as $value)
 148                  {
 149                      $valarray = explode('_', $value);
 150                      $type = array_shift($valarray);
 151                      $newval = implode(' ', $valarray);
 152                      if ($type == 'lang')
 153                      {
 154                          $this->t->set_var($value, lang($newval));
 155                      }
 156                  }
 157              }
 158          }
 159  
 160  		function show_errors(&$activity_manager, &$error_str)
 161          {
 162              $valid = $activity_manager->validate_process_activities($this->wf_p_id);
 163              if (!$valid)
 164              {
 165                  $errors = $activity_manager->get_error(true);
 166                  $error_str = '<b>' . lang('The following items must be corrected to be able to activate this process').':</b><br/><small><ul>';
 167                  foreach ($errors as $error)
 168                  {
 169                      $error_str .= '<li>'. $error . '<br/>';
 170                  }
 171                  $error_str .= '</ul></small>';
 172                  return 'n';
 173              }
 174              else
 175              {
 176                  $error_str = '';
 177                  return 'y';
 178              }
 179          }
 180  
 181  		function get_source($proc_name, $act_name, $type)
 182          {
 183              switch($type)
 184              {
 185                  case 'code':
 186                      $path =  'activities' . SEP . $act_name . '.php';
 187                      break;
 188                  case 'template':
 189                      $path = 'templates' . SEP . $act_name . '.tpl';
 190                      break;
 191                  default:
 192                      $path = 'shared.php';
 193                      break;
 194              }
 195              $complete_path = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'code' . SEP . $path;
 196                                                  if (!$file_size = filesize($complete_path)) return '';
 197              $fp = fopen($complete_path, 'r');
 198              $data = fread($fp, $file_size);
 199              fclose($fp);
 200              return $data;
 201          }
 202  
 203  		function save_source($proc_name, $act_name, $type, $source)
 204          {
 205                                               // in case code was filtered
 206                                               if (!$source) $source = @$GLOBALS['egw_unset_vars']['_POST[source]'];
 207  
 208              switch($type)
 209              {
 210                  case 'code':
 211                      $path =  'activities' . SEP . $act_name . '.php';
 212                      break;
 213                  case 'template':
 214                      $path = 'templates' . SEP . $act_name . '.tpl';
 215                      break;
 216                  default:
 217                      $path = 'shared.php';
 218                      break;
 219              }
 220              $complete_path = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'code' . SEP . $path;
 221              // In case you want to be warned when source code is changed:
 222              // mail('yourmail@domain.com', 'source changed', "PATH: $complete_path \n\n SOURCE: $source");
 223              $fp = fopen($complete_path, 'w');
 224              fwrite($fp, $source);
 225              fclose($fp);
 226          }
 227  
 228  		function export()
 229          {
 230              $this->process_manager    =& CreateObject('workflow.workflow_processmanager');
 231  
 232              // retrieve process info
 233              $proc_info = $this->process_manager->get_process($this->wf_p_id);
 234              $filename = $proc_info['wf_normalized_name'].'.xml';
 235              $out = $this->process_manager->serialize_process($this->wf_p_id);
 236              $mimetype = 'application/xml';
 237              // 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:
 238              if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7'))
 239                  $mimetype = 'application/x-download';
 240              // Show appropiate header for a file to be downloaded:
 241              header("content-disposition: attachment; filename=$filename");
 242              header("content-type: $mimetype");
 243              header('content-length: ' . strlen($out));
 244              echo $out;
 245          }
 246          
 247          /**
 248           *  get the href link for the css file, searching for themes specifics stylesheet if any
 249          *  * @param $css_name is the name of the css file, without the .css extension
 250          *  * @param $print_mode is false by default, if true '_print.css' is appended to the name if this 
 251          *  * css print file exists
 252           */
 253  		function get_css_link($css_name, $print_mode=false)
 254          {
 255              if (!!($print_mode))
 256              {
 257                  $css_file = SEP.'workflow'.SEP.'templates'.SEP
 258                      .$GLOBALS['egw_info']['server']['template_set'].SEP.'css'.SEP.$css_name.'_print.css';
 259                  if(file_exists(EGW_SERVER_ROOT.$css_file))
 260                  {
 261                      return $GLOBALS['egw_info']['server']['webserver_url'].$css_file;
 262                  }
 263                  else
 264                  {
 265                      $css_file = SEP.'workflow'.SEP.'templates'.SEP.'default'
 266                          .SEP.'css'.SEP.$css_name.'_print.css';
 267                      if(file_exists(EGW_SERVER_ROOT.$css_file))
 268                      {
 269                          return $GLOBALS['egw_info']['server']['webserver_url'].$css_file;
 270                      }
 271                  }
 272              }
 273              $css_file = SEP.'workflow'.SEP.'templates'.SEP
 274                      .$GLOBALS['egw_info']['server']['template_set'].SEP.'css'.SEP.$css_name.'.css';
 275              if(file_exists(EGW_SERVER_ROOT.$css_file))
 276              {
 277                  return $GLOBALS['egw_info']['server']['webserver_url'].$css_file;
 278              }
 279              else
 280              {
 281                  return $GLOBALS['egw_info']['server']['webserver_url'].SEP.'workflow'
 282                          .SEP.'templates'.SEP.'default'.SEP.'css'.SEP.$css_name.'.css';
 283              }
 284          }
 285          
 286          //! return a given duration in human readable form, usefull for workitems duration
 287  		function time_diff($to) {
 288              $days = (int)($to/(24*3600));
 289              $to = $to - ($days*(24*3600));
 290              $hours = (int)($to/3600);
 291              $to = $to - ($hours*3600);
 292              $min = date("i", $to);
 293              $to = $to - ($min*60);            
 294              $sec = date("s", $to);
 295  
 296              return lang('%1 days, %2:%3:%4',$days,$hours,$min,$sec);
 297          }
 298  
 299      }
 300  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7