[ 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.bo_uiinstance.inc.php (source)

   1  <?php
   2      class bo_uiinstance extends workflow
   3      {
   4          //template given by ui classes
   5          var $t;
   6          //var $activity_t;
   7          //workflow objects
   8          var $process;
   9          //category object
  10          var $cat;
  11          
  12  		function bo_uiinstance($template)
  13          {
  14              parent::workflow();
  15              
  16              $this->t    =& $template;
  17              $this->process  =& CreateObject('workflow.workflow_process');
  18              $this->cat    =& CreateObject('phpgwapi.categories');
  19          }
  20          
  21          //! parse common fields of an instance, by default in read-only mode, with the instance.tpl template
  22  		function parse_instance(&$instance, $readonly=true)
  23          {
  24              if($this->t == '')
  25              {
  26                  return false;
  27              }
  28              
  29              $this->t->set_file('instance_tpl', 'instance.tpl');
  30              $iid         = $instance->getInstanceId();
  31              $pid         = $instance->getProcessId();
  32              $this->process->getProcess($pid);
  33  
  34              $this->show_select_owner($instance->getOwner(), $readonly);
  35              $this->show_select_sendto($pid, $readonly);
  36              $this->show_instance_acts($iid, $instance->activities, $readonly);
  37              $this->show_properties($iid, $instance->properties, $readonly);
  38  
  39              // fill the general variables of the template
  40              $ended = $instance->getEnded();
  41              $status = $instance->getStatus();
  42              $category = $instance->getCategory();
  43              if (!($readonly))
  44              {
  45                  $selectcategory =  $this->cat_option($instance->getCategory(),False);
  46              }
  47              else
  48              {
  49                  $selectcategory = '<input {input_type} name="instance_category" value="'.$this->cat->id2name($instance->getCategory()).'" />';
  50              }
  51              $this->t->set_var(array(
  52                  'iid'            => $iid,
  53                  'instance_process'    => lang('Instance: %1 (Process: %2)', $iid, $this->process->getName() . ' ' . $this->process->getVersion()),
  54                  'inst_started'        => $GLOBALS['egw']->common->show_date($instance->getStarted()),
  55                  'inst_ended'         => ($ended==0)? '-' : $GLOBALS['egw']->common->show_date($ended),
  56                  'instance_name'        => htmlspecialchars($instance->getName()),
  57                  'status'        => htmlspecialchars($instance->getStatus()),
  58                  'instance_priority'    => $instance->getPriority(),
  59                  'instance_category'    => $category,
  60                  'instance_category_select'=> $selectcategory,
  61                  'status_active'        => ($status == 'active')? 'selected="selected"' : '',
  62                  'status_exception'    => ($status == 'exception')? 'selected="selected"' : '',
  63                  'status_completed'    => ($status == 'completed')? 'selected="selected"' : '',
  64                  'status_aborted'    => ($status == 'aborted')? 'selected="selected"' : '',
  65              ));
  66  
  67              //showing or not the update button and some fields type
  68              $this->t->set_block('instance_tpl', 'block_button_update', 'button_update');
  69              if ($readonly)
  70              {
  71                  $this->t->set_var(array(
  72                      'button_update'    => '',
  73                      'input_type'    => 'readonly="readonly"',
  74                      'textarea_type'    => 'readonly="readonly"',
  75                      'select_type'    => 'readonly="readonly" disabled="true"',
  76                  ));
  77              }
  78              else
  79              {
  80                  $this->t->set_var(array(
  81                      'input_type'     => 'type="text"',
  82                      'textarea_type'    => '',
  83                      'select_type'    => '',
  84                  ));
  85                  $this->translate_template('block_button_update');
  86                  $this->t->parse('button_update', 'block_button_update', true);
  87              }
  88              $this->translate_template('instance_tpl');
  89          }
  90          
  91          //! parse workitems/history fields of an instance on the history.tpl template
  92  		function parse_instance_history(&$workitems)
  93          {
  94              if($this->t == '')
  95              {
  96                  return false;
  97              }
  98              
  99              $this->t->set_file('history_tpl', 'history.tpl');
 100              $this->show_workitems($workitems);
 101              $this->translate_template('history_tpl');
 102          }
 103  
 104  		function show_select_owner($actual_owner, $readonly)
 105          {
 106              if ($readonly)
 107              {//we just need to read actual owner name
 108                  $GLOBALS['egw']->accounts->get_account_name($actual_owner,$lid,$owner_fname,$owner_lname);
 109                  $myselect = '<input {input_type} name="owner" value="'.$owner_fname.' '.$owner_lname.'" />';
 110              }
 111              else
 112              {//we prepare a big select
 113                  if (!is_object($GLOBALS['egw']->uiaccountsel))
 114                  {
 115                      $GLOBALS['egw']->uiaccountsel =& CreateObject('phpgwapi.uiaccountsel');
 116                  }
 117                                                                                                                                                                   
 118                  $myselect = $GLOBALS['egw']->uiaccountsel->selection('owner', 'owner',$actual_owner,'workflow',0,False,'','',lang('None'),False);
 119              }
 120          
 121              $this->t->set_var(array(
 122                  'owner'        => $actual_owner,
 123                  'select_owner'    => $myselect,
 124              ));
 125          }
 126          
 127  		function show_select_sendto($pid, $readonly)
 128          {
 129  
 130              $this->t->set_block('instance_tpl','block_select_sendto','select_sendto');
 131              $this->t->set_block('instance_tpl','block_sendallactivities','sendallactivities');
 132              if ($readonly)
 133              {//we show nothing
 134                  $this->t->set_var('sendallactivities','');
 135              }
 136              else
 137              {
 138                  //we need an activity manager to retrieve list of all avaible activities
 139                  $activity_manager =& CreateObject('workflow.workflow_activitymanager');
 140                  $proc_activities =& $activity_manager->list_activities($pid, 0, -1, 'wf_flow_num__asc', '', '');
 141                  foreach ($proc_activities['data'] as $activity)
 142                  {
 143                      $this->t->set_var(array(
 144                          'sendto_act_value'    => $activity['wf_activity_id'],
 145                          'sendto_act_name'    => $activity['wf_name'],
 146                      ));
 147                      $this->t->parse('select_sendto', 'block_select_sendto', true);
 148                  }
 149                  if (!($proc_activities['cant'])) $this->t->set_var('select_sendto', '');
 150  
 151                  $this->translate_template('block_sendallactivities');
 152                  $this->t->parse('sendallactivities', 'block_sendallactivities', true);
 153              }
 154          }
 155              
 156  		function show_instance_acts($iid, &$instance_acts,$readonly)
 157          {
 158              $this->t->set_block('instance_tpl', 'block_instance_acts_table_users', 'instance_acts_table_users');
 159              
 160              if ($instance_acts)
 161              {
 162                  $this->t->set_block('instance_tpl', 'block_instance_acts_table', 'instance_acts_table');
 163                  foreach ($instance_acts as $activity)
 164                  {
 165                      $aid = $activity['wf_activity_id'];
 166                      $send_button =  '';
 167                      $restart_button = '';
 168                      //handle user or user selection
 169                      if ($readonly)
 170                      {//we just need to read actual user name
 171                          if ($activity['wf_user']=='*')
 172                          {
 173                              $fname = lang('Nobody');
 174                              $lname = '';
 175                          }
 176                          else
 177                          {
 178                              $GLOBALS['egw']->accounts->get_account_name($activity['wf_user'],$lid,$fname,$lname);
 179                          }
 180                          $users = '<input {input_type} name="acts['.$aid.']" value="'.$fname.' '.$lname.'" />';
 181                          //no action
 182                      }
 183                      else
 184                      {//we prepare a big select
 185                          if (!is_object($GLOBALS['egw']->uiaccountsel))
 186                          {
 187                              $GLOBALS['egw']->uiaccountsel =& CreateObject('phpgwapi.uiaccountsel');
 188                          }
 189                      
 190                          $users = $GLOBALS['egw']->uiaccountsel->selection('acts['.$aid.']','acts['.$aid.']',$activity['wf_user'],'workflow',0,False,'','','*',False);
 191                          //for actions there is 2 avaible actions
 192                          //    * send : send after a completed activity, maybe the transitions failed the first time
 193                          //    * restart : restart an automated activity which have meybe failed while running
 194                          if (($activity['wf_status']=='completed') && ($activity['wf_is_autorouted']=='y') )
 195                          {
 196                              //this activity shouldn't be there in completed status, need to send manually the transition
 197                              //and we do it there because no user will have the right to send manually an autorouted activity
 198                              $send_button =  '<a href="'.$GLOBALS['egw']->link('/index.php',array(
 199                                                                          'menuaction'    => 'workflow.ui_userinstances.form',
 200                                                                          'iid'        => $activity['wf_instance_id'],
 201                                                                          'filter_instance'=> $activity['wf_instance_id'],
 202                                                                          'aid'        => $activity['wf_activity_id'],
 203                                  'send'        => true,
 204                                  'add_advanced_actions'=>true,
 205                                  )).'"><img src="'.$GLOBALS['egw']->common->image('workflow', 'linkto')
 206                                  .'" name="send_instance" alt="'.lang('send').'">'.lang('send transition').'</a>';
 207                          }
 208                          if (($activity['wf_status']=='running') && ($activity['wf_is_interactive']=='n') )
 209                          {
 210                              //this activity should terminate, this is not the case
 211                              //so we will restart it
 212                              $restart_button = '<a href="'.$GLOBALS['egw']->link('/index.php',array(
 213                                                                          'menuaction'    => 'workflow.ui_userinstances.form',
 214                                                                          'iid'        => $activity['wf_instance_id'],
 215                                                                          'filter_instance'=> $activity['wf_instance_id'],
 216                                                                          'aid'        => $activity['wf_activity_id'],
 217                                  'restart'    => true,
 218                                  'add_advanced_actions'=>true,
 219                                  )).'"><img src="'.$GLOBALS['egw']->common->image('workflow', 'runform')
 220                                  .'" name="restart activity" alt="'.lang('restart').'">'.lang('restart activity').'</a>';;
 221                          }
 222                      }
 223                      $this->t->set_var(array(
 224                          'select_user'            => $users,
 225                          'activity_user'            => $activity['wf_user'],
 226                          'inst_act_name'            => $activity['wf_name'],
 227                          'inst_act_status'        => $activity['wf_status'],
 228                          'inst_act_id'            => $aid,
 229                          'send'                => $send_button,
 230                          'restart'            => $restart_button,
 231                      ));
 232  
 233  
 234                      $this->t->parse('instance_acts_table', 'block_instance_acts_table', true);
 235                  }
 236  
 237                  $this->t->set_block('instance_tpl', 'block_instance_acts', 'instance_acts');
 238                  $this->translate_template('block_instance_acts');
 239                  $this->t->parse('instance_acts', 'block_instance_acts');
 240              }
 241              else
 242              {
 243                  $this->t->set_block('instance_tpl', 'block_instance_acts', 'instance_acts');
 244                  $this->t->set_var('instance_acts', '');
 245              }
 246          }
 247  
 248          //! display the property list, if readonly is false then it is possible to delete/add/modify the properties
 249  		function show_properties($iid, &$props, $readonly)
 250          {
 251  
 252              $this->t->set_block('instance_tpl', 'block_properties', 'properties');
 253              $this->t->set_block('block_properties', 'block_button_delete', 'button_delete');
 254              if (!(empty($props)))
 255              {
 256                  $parsed =& $props;
 257              }
 258              else
 259              {
 260                  $parsed = Array('--' => '--');
 261              }
 262              foreach ($parsed as $key=>$prop)
 263              {
 264                  $prop = htmlspecialchars($prop);
 265                  //make textarea for big properties
 266                  if (strlen($prop) > 80)
 267                  {
 268                      $this->t->set_var('prop_value', '<textarea {textarea_type} name="props['. $key .']" cols="80" rows="5">'. $prop .'</textarea>');
 269                  }
 270                  //and bigger input for long properties
 271                  elseif (strlen($prop) > 25)
 272                  {
 273                      $this->t->set_var('prop_value', '<input {input_type} size="80" name="props['. $key .']" value="'. $prop .'" />');
 274                  }
 275                  else
 276                  {
 277                      $this->t->set_var('prop_value', '<input {input_type} size="25" name="props['. $key .']" value="'. $prop .'" />');
 278                  }
 279  
 280                  if ($readonly)
 281                  {
 282                      $this->t->set_var(array(
 283                          'button_delete'        => '',
 284                          'prop_key'        => $key,
 285                          'color_line'        => $this->nextmatchs->alternate_row_color($tr_color, true),
 286                      ));
 287                  }
 288                  else
 289                  {
 290                      $this->t->set_var(array(
 291                          'prop_href'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_admininstance.form&iid='. $iid .'&unsetprop='. $key),
 292                          'img_trash'        => $GLOBALS['egw']->common->image('workflow', 'trash'),
 293                          'prop_key'        => $key,
 294                          'color_line'        => $this->nextmatchs->alternate_row_color($tr_color, true),
 295                      ));
 296  
 297                      $this->t->parse('button_delete', 'block_button_delete', false);
 298                  }
 299                  $this->translate_template('block_properties');
 300                  $this->t->parse('properties', 'block_properties', true);
 301              }
 302              //if no property actually
 303              if (!count($props)) $this->t->set_var('properties', '<tr><td colspan="2" align="center">'. lang('There are no properties available') .'</td></tr>');
 304              
 305              //showing or not the update button and the 'add property' zone
 306              $this->t->set_block('instance_tpl', 'block_button_update_properties', 'button_update_properties');
 307              $this->t->set_block('instance_tpl', 'block_add_property', 'add_property');
 308              if ($readonly)
 309              {
 310                  $this->t->set_var(array(
 311                      'button_update_properties'    => '',
 312                      'add_property'            => '',
 313                  ));
 314              }
 315              else
 316              {
 317                  $this->translate_template('block_button_update_properties');
 318                  $this->translate_template('block_add_property');
 319                  $this->t->parse('button_update_properties', 'block_button_update_properties', true);
 320                  $this->t->parse('add_property', 'block_add_property', true);
 321              }
 322          }
 323  
 324          //! display the workitems list (history) on history_tpl
 325  		function show_workitems(&$works)
 326          {
 327              $this->t->set_block('history_tpl', 'block_history_line', 'history_line');
 328              $view = $GLOBALS['egw']->common->image('workflow', 'view');
 329              
 330              // access granted to the view workitem function?
 331              // need access to the monitor screens. Workitems contains the whole properties for example
 332              $access_granted = true;
 333              if(!$GLOBALS['egw']->acl->check('run',1,'admin'))
 334              {
 335                  if(!$GLOBALS['egw']->acl->check('monitor_workflow',1,'workflow'))
 336                  {
 337                      $access_granted = false;
 338                  }
 339              }
 340              //fill rows
 341              foreach ($works as $work)
 342              {
 343                  if ($work['wf_user']=='*')
 344                  {
 345                      $fname = lang('Nobody');
 346                      $lname = '';
 347                  }
 348                  else
 349                  {
 350                      $GLOBALS['egw']->accounts->get_account_name($work['wf_user'],$lid,$fname,$lname);
 351                  }
 352  
 353                  if ($access_granted)
 354                  {
 355                      $address = $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_viewworkitem.form&itemId='.$work['wf_item_id']);
 356                      $history_link = '<a href="'.$address.'"><img src="'.$view.'" alt="'.lang('Details').'" /></a>';
 357                  }
 358                  else
 359                  {
 360                      $history_link = '&nbsp;';
 361                  }
 362                  $this->t->set_var(array(
 363                      'act_icon'        => $this->act_icon($work['wf_type'],$work['wf_is_interactive']),
 364                      'history_activity'    => $work['wf_name'],
 365                      'history_started'    => $GLOBALS['egw']->common->show_date($work['wf_started']),
 366                      'history_duration'    => $this->time_diff($work['wf_ended']-$work['wf_started']),
 367                      'history_user'        => $fname.' '.$lname,
 368                      'history_link'        => $history_link,
 369                      'color_line'        => $this->nextmatchs->alternate_row_color($tr_color, true),
 370                  ));
 371                  
 372                  $this->translate_template('block_history_line');
 373                  $this->t->parse('history_line', 'block_history_line', true);
 374              }
 375              //if no workitems actually
 376              if (!count($works)) $this->t->set_var('history_line', '<tr><td colspan="5" align="center">'. lang('There are no workitems available') .'</td></tr>');
 377          }
 378          
 379          /* Return a select form element with the categories option dialog in it */
 380  		function cat_option($cat_id='',$notall=False,$java=True,$multiple=False)
 381          {
 382              if($java)
 383              {
 384                          $jselect = ' ';
 385                      }
 386                      /* Setup all and none first */
 387                      $cats_link  = "\n" .'<select name="instance_category'.(($multiple)? '[]':'').'"' .$jselect . (($multiple)? 'multiple ' : '') . ">\n";
 388                      if(!$notall)
 389                      {
 390                          $cats_link .= '<option value=""';
 391                          if($cat_id == 'all')
 392                          {
 393                              $cats_link .= ' selected';
 394                  }
 395                  $cats_link .= '>'.lang("all").'</option>'."\n";
 396              }
 397                  
 398              /* Get app-specific category listings */
 399              $cats_link .= $this->cat->formated_list('select','all',$cat_id,False);
 400              $cats_link .= '</select>'."\n";
 401              return $cats_link;
 402          }
 403  
 404      }
 405  ?>


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