[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/workflow/inc/engine/src/GUI/ -> GUI.php (source)

   1  <?php require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php');
   2  //!! GUI
   3  //! A GUI class for use in typical user interface scripts
   4  /*!
   5  This class provides methods for use in typical user interface scripts
   6  */
   7  class GUI extends Base {
   8  
   9    //security object used to obtain access for the user on certain actions from the engine
  10    var $wf_security;
  11    //process manager object used to retrieve infos from processes
  12    var $pm;
  13    //cache array to avoid queries
  14    var $process_cache=Array();
  15  
  16    /*!
  17    List user processes, user processes should follow one of these conditions:
  18    1) The process has an instance assigned to the user
  19    2) The process has a begin activity with a role compatible to the
  20       user roles
  21    3) The process has an instance assigned to '*' and the
  22       roles for the activity match the roles assigned to
  23       the user
  24    The method returns the list of processes that match this
  25    and it also returns the number of instances that are in the
  26    process matching the conditions.
  27    */
  28    /*
  29    TODO: 
  30     *) more options in list_user_instances, they should not be added by the external modules
  31     */
  32     
  33    /*!
  34    * Constructor takes a PEAR::Db object
  35    */
  36    function GUI(&$db) 
  37    {
  38      $this->child_name = 'GUI';
  39      parent::Base($db);
  40      require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'WfSecurity.php');
  41      $this->wf_security =& new WfSecurity($this->db); 
  42    }
  43  
  44    /*!
  45    * Collect errors from all linked objects which could have been used by this object
  46    * Each child class should instantiate this function with her linked objetcs, calling get_error(true)
  47    * for example if you had a $this->process_manager created in the constructor you shoudl call
  48    * $this->error[] = $this->process_manager->get_error(false, $debug);
  49    * @param $debug is false by default, if true debug messages can be added to 'normal' messages
  50    * @param $prefix is a string appended to the debug message
  51    */
  52    function collect_errors($debug=false, $prefix='')
  53    {
  54      parent::collect_errors($debug, $prefix);
  55      $this->error[] = $this->wf_security->get_error(false, $debug, $prefix);
  56    }
  57  
  58  
  59    function gui_list_user_processes($user,$offset,$maxRecords,$sort_mode,$find,$where='')
  60    {
  61      // FIXME: this doesn't support multiple sort criteria
  62      //$sort_mode = $this->convert_sortmode($sort_mode);
  63      $sort_mode = str_replace("__"," ",$sort_mode);
  64  
  65      $mid = "where gp.wf_is_active=?";
  66      // add group mapping, warning groups and user can have the same id
  67      $groups = galaxia_retrieve_user_groups($user);
  68      $mid .= " and ((gur.wf_user=? and gur.wf_account_type='u')";
  69      if (is_array($groups))
  70      {
  71        $mid .= '    or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
  72      }
  73      $mid .= ')';
  74      $bindvars = array('y',$user);
  75      if($find) {
  76        $findesc = '%'.$find.'%';
  77        $mid .= " and ((gp.wf_name like ?) or (gp.wf_description like ?))";
  78        $bindvars[] = $findesc;
  79        $bindvars[] = $findesc;
  80      }
  81      if($where) {
  82        $mid.= " and ($where) ";
  83      }
  84      
  85      $query = "select distinct(gp.wf_p_id), 
  86                       gp.wf_is_active,                    
  87                       gp.wf_name as wf_procname, 
  88                       gp.wf_normalized_name as normalized_name, 
  89                       gp.wf_version as wf_version,
  90                       gp.wf_version as version
  91                from ".GALAXIA_TABLE_PREFIX."processes gp
  92                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
  93                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
  94                  INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
  95                  INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
  96                $mid";
  97      $query_cant = "select count(distinct(gp.wf_p_id))
  98                from ".GALAXIA_TABLE_PREFIX."processes gp
  99                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 100                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 101                  INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 102                  INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 103                $mid";
 104      $result = $this->query($query,$bindvars,$maxRecords,$offset, true, $sort_mode);
 105      $cant = $this->getOne($query_cant,$bindvars);
 106      $ret = Array();
 107      if (!(empty($result)))
 108      {
 109        while($res = $result->fetchRow()) {
 110          // Get instances and activities per process,
 111          $pId=$res['wf_p_id'];
 112          $query_act = 'select count(distinct(ga.wf_activity_id))
 113                from '.GALAXIA_TABLE_PREFIX.'processes gp
 114                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'activities ga ON gp.wf_p_id=ga.wf_p_id
 115                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 116                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'roles gr ON gr.wf_role_id=gar.wf_role_id
 117                  INNER JOIN '.GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 118                where gp.wf_p_id=? 
 119                and (  ((gur.wf_user=? and gur.wf_account_type='u') ";
 120          if (is_array($groups))
 121          {
 122            $query_act .= ' or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
 123          }
 124          $query_act .= '))';
 125           
 126          $res['wf_activities']=$this->getOne($query_act,array($pId,$user));
 127          //we are counting here instances which are completed/exception or actives
 128          // TODO: maybe we should add a second counter with only running instances
 129          $query_inst = 'select count(distinct(gi.wf_instance_id))
 130                from '.GALAXIA_TABLE_PREFIX.'instances gi
 131                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id
 132                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id
 133                  LEFT JOIN '.GALAXIA_TABLE_PREFIX."user_roles gur ON gar.wf_role_id=gur.wf_role_id
 134                where gi.wf_p_id=? 
 135                and (";
 136          if (is_array($groups))
 137          {
 138            $query_inst .= "(gur.wf_user in (".implode(",",$groups).") and gur.wf_account_type='g') or ";
 139          }
 140          $query_inst .= "(gi.wf_owner=?) 
 141                           or ((gur.wf_user=?) and gur.wf_account_type='u'))";
 142          $res['wf_instances']=$this->getOne($query_inst,array($pId,$user,$user));
 143          $ret[] = $res;
 144        }
 145      }
 146      $retval = Array();
 147      $retval["data"] = $ret;
 148      $retval["cant"] = $cant;
 149      return $retval;
 150    }
 151  
 152    /*! list user activities
 153    * @param $user is the current user id
 154    * @param $offset is the current starting point for the query results
 155    * @param $maxRecords is the max number of results to return
 156    * @param $sort_mode is for sorting
 157    * @param $find is a string to search in activity name or description
 158    * @param $where is deprecated it's a string to add to the query, use with care for SQL injection 
 159    * @param $remove_activities_without_instances is false by default will remove all activities having no instances related at this time
 160    * @param $remove_instances_activities is false by default, if true then all activities related to instances will be avoided 
 161    * (i.e. activities which are not standalone, start or view). If $remove_activities_without_instances is true you'll obtain nothing :-)
 162    * @param $add_start is false by default, if true start activities are added to the listing, no effect if $remove_activities_without_instances is true
 163    * @param $add_standalone is false by default, if true standalone activities are added to the listing, no effect if $remove_activities_without_instances is true
 164    * @param $add_view is false by default, if true view activities are added to the listing, no effect if $remove_activities_without_instances is true
 165    * @return an associative array, key cant gives the number of results, key data is an associative array conteining the results
 166    */
 167    function gui_list_user_activities($user,$offset,$maxRecords,$sort_mode,$find,$where='', $remove_activities_without_instances=false, $remove_instances_activities =false, $add_start = false, $add_standalone = false, $add_view = false)
 168    {
 169      // FIXME: this doesn't support multiple sort criteria
 170      //$sort_mode = $this->convert_sortmode($sort_mode);
 171      $sort_mode = str_replace("__"," ",$sort_mode);
 172      $mid = "where gp.wf_is_active=?";
 173      $bindvars = array('y');
 174      
 175      if ($remove_instances_activities)
 176      {
 177        $mid .= " and ga.wf_type <> ? and ga.wf_type <> ? and ga.wf_type <> ?  and  ga.wf_type <> ?  and  ga.wf_type <> ? ";
 178        $bindvars[] = 'end';
 179        $bindvars[] = 'switch';
 180        $bindvars[] = 'join';
 181        $bindvars[] = 'activity';
 182        $bindvars[] = 'split';
 183      }
 184      if (!($add_start))
 185      {
 186        $mid .= " and ga.wf_type <> ?";
 187        $bindvars[] = 'start';
 188      }
 189      if (!($add_standalone))
 190      {
 191        $mid .= " and ga.wf_type <> ?";
 192        $bindvars[] = 'standalone';
 193      }
 194      if (!($add_view))
 195      {
 196        $mid .= " and ga.wf_type <> ?";
 197        $bindvars[] = 'view';
 198      }
 199  
 200      // add group mapping, warning groups and user can have the same id
 201      $groups = galaxia_retrieve_user_groups($user);
 202      $mid .= " and ((gur.wf_user=? and gur.wf_account_type='u')";
 203      if (is_array($groups))
 204      {
 205        $mid .= '    or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
 206      }
 207      $mid .= ')';
 208      $bindvars[] = $user;
 209      if($find) {
 210        $findesc = '%'.$find.'%';
 211        $mid .= " and ((ga.wf_name like ?) or (ga.wf_description like ?))";
 212        $bindvars[] = $findesc;
 213        $bindvars[] = $findesc;
 214      }
 215      if($where) {
 216        $mid.= " and ($where) ";
 217      }
 218      if ($remove_activities_without_instances)
 219      {
 220        $more_tables = "INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gia.wf_activity_id=gar.wf_activity_id
 221                        INNER JOIN ".GALAXIA_TABLE_PREFIX."instances gi ON gia.wf_instance_id=gi.wf_instance_id";
 222      }
 223      else
 224      {
 225      $more_tables = "";
 226      }
 227      $query = "select distinct(ga.wf_activity_id),                     
 228                       ga.wf_name,
 229                       ga.wf_type,
 230                       gp.wf_name as wf_procname, 
 231                       ga.wf_is_interactive,
 232                       ga.wf_is_autorouted,
 233                       ga.wf_activity_id,
 234                       gp.wf_version as wf_version,
 235                       gp.wf_p_id,
 236                       gp.wf_is_active
 237                  from ".GALAXIA_TABLE_PREFIX."processes gp
 238                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 239                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 240                  INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 241                  INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 242                  $more_tables
 243                  $mid";
 244                
 245      $query_cant = "select count(distinct(ga.wf_activity_id))
 246                from ".GALAXIA_TABLE_PREFIX."processes gp
 247                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 248                  INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 249                  INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 250                  INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 251                  $more_tables
 252                  $mid ";
 253      $result = $this->query($query,$bindvars,$maxRecords,$offset, true, $sort_mode);
 254      $cant = $this->getOne($query_cant,$bindvars);
 255      $ret = Array();
 256      $removed_instances = 0;
 257      if (!(empty($result)))
 258      {
 259        while($res = $result->fetchRow()) 
 260        {
 261          // Get instances per activity
 262          $query_act = 'select count(distinct(gi.wf_instance_id))
 263                from '.GALAXIA_TABLE_PREFIX.'instances gi
 264                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id
 265                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id
 266                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'user_roles gur ON gar.wf_role_id=gur.wf_role_id
 267                where gia.wf_activity_id=? 
 268                and (';
 269          if (is_array($groups))
 270          {
 271            $query_act .= "(gur.wf_user in (".implode(",",$groups).") and gur.wf_account_type='g') or ";
 272          }
 273          $query_act .= "(gi.wf_owner=?) 
 274                     or ((gur.wf_user=?) and gur.wf_account_type='u'))";
 275          $res['wf_instances']=$this->getOne($query_act, array($res['wf_activity_id'],$user,$user));
 276          $ret[] = $res;
 277        }
 278      }
 279      $retval = Array();
 280      $retval["data"] = $ret;
 281      $retval["cant"] = $cant;
 282      return $retval;
 283    }
 284  
 285      /*! list user activities but each activity name (and not id) appears only one time
 286      * @param $user is the current user id
 287      * @param $offset is the current starting point for the query results
 288      * @param $maxRecords is the max number of results to return
 289      * @param $sort_mode is for sorting
 290      * @param $find is a string to search in activity name or description
 291      * @param $where is deprecated it's a string to add to the query, use with care for SQL injection 
 292      * @param $remove_instances_activities is false by default, if true then all activities related to instances will be avoided 
 293      * (i.e. activities which are not standalone, start or view).
 294      * @param $add_start is false by default, if true start activities are added to the listing
 295      * @param $add_standalone is false by default, if true standalone activities are added to the listing
 296      * @param $add_view is false by default, if true view activities are added to the listing
 297      * @return an associative array, key cant gives the number of results, key data is an associative array conteining the results
 298      */
 299  	function gui_list_user_activities_by_unique_name($user,$offset,$maxRecords,$sort_mode,$find,$where='', $remove_instances_activities =false, $add_start = false, $add_standalone = false, $add_view = false)
 300      {
 301          // FIXME: this doesn't support multiple sort criteria
 302          //$sort_mode = $this->convert_sortmode($sort_mode);
 303          $sort_mode = str_replace("__"," ",$sort_mode);
 304          $mid = "where gp.wf_is_active=?";
 305          $bindvars = array('y');
 306          
 307                  if ($remove_instances_activities)
 308                  {
 309                     $mid .= " and ga.wf_type <> ? and ga.wf_type <> ? and ga.wf_type <> ?  and  ga.wf_type <> ?  and  ga.wf_type <> ? ";
 310                     $bindvars[] = 'end';
 311                     $bindvars[] = 'switch';
 312                     $bindvars[] = 'join';
 313                     $bindvars[] = 'activity';
 314                     $bindvars[] = 'split';
 315                  }
 316          if (!($add_start))
 317          {
 318            $mid .= " and ga.wf_type <> ?";
 319            $bindvars[] = 'start';
 320                  }
 321                  if (!($add_standalone))
 322          {
 323            $mid .= " and ga.wf_type <> ?";
 324            $bindvars[] = 'standalone';
 325                  }
 326                  if (!($add_view))
 327          {
 328            $mid .= " and ga.wf_type <> ?";
 329            $bindvars[] = 'view';
 330                  }
 331                  
 332          // add group mapping, warning groups and user can have the same id
 333          $groups = galaxia_retrieve_user_groups($user);
 334          $mid .= " and ((gur.wf_user=? and gur.wf_account_type='u')";
 335          if (is_array($groups))
 336          {
 337            $mid .= ' or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
 338                  }
 339                  $mid .= ')';
 340  
 341          $bindvars[] = $user;
 342          if($find) 
 343          {
 344              $findesc = '%'.$find.'%';
 345              $mid .= " and ((ga.wf_name like ?) or (ga.wf_description like ?))";
 346              $bindvars[] = $findesc;
 347              $bindvars[] = $findesc;
 348          }
 349          if($where) 
 350          {
 351              $mid.= " and ($where) ";
 352          }
 353  
 354          $query = "select distinct(ga.wf_name)
 355              from ".GALAXIA_TABLE_PREFIX."processes gp
 356              INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 357              INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 358              INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 359              INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 360              $mid";
 361  
 362          $query_cant = "select count(distinct(ga.wf_name))
 363              from ".GALAXIA_TABLE_PREFIX."processes gp
 364              INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 365              INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 366              INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 367              INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 368              $mid";
 369          $result = $this->query($query,$bindvars,$maxRecords,$offset, true, $sort_mode);
 370          $cant = $this->getOne($query_cant,$bindvars);
 371          $ret = Array();
 372          if (!(empty($result)))
 373          {
 374            while($res = $result->fetchRow()) 
 375            {
 376              $ret[] = $res;
 377                    }
 378                  }
 379  
 380          $retval = Array();
 381          $retval["data"] = $ret;
 382          $retval["cant"] = $cant;
 383          return $retval;
 384      }
 385  
 386    //! List start activities avaible for a given user
 387    function gui_list_user_start_activities($user,$offset,$maxRecords,$sort_mode,$find,$where='')
 388    {
 389      // FIXME: this doesn't support multiple sort criteria
 390      $sort_mode = str_replace("__"," ",$sort_mode);
 391  
 392      $mid = "where gp.wf_is_active=? and ga.wf_type=?";
 393      // add group mapping, warning groups and user can have the same id
 394      $groups = galaxia_retrieve_user_groups($user);
 395      $mid .= " and ((gur.wf_user=? and gur.wf_account_type='u')";
 396      if (is_array($groups))
 397      {
 398        $mid .= '    or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
 399      }
 400      $mid .= ')';
 401      $bindvars = array('y','start',$user);
 402      if($find)
 403      {
 404        //search on activities and processes
 405        $findesc = '%'.$find.'%';
 406        $mid .= " and ((ga.wf_name like ?) or (ga.wf_description like ?) or (gp.wf_name like ?) or (gp.wf_description like ?))";
 407        $bindvars[] = $findesc;
 408        $bindvars[] = $findesc;
 409        $bindvars[] = $findesc;
 410        $bindvars[] = $findesc;
 411      }
 412      if($where) 
 413      {
 414        $mid.= " and ($where) ";
 415      }
 416  
 417      $query = "select distinct(ga.wf_activity_id), 
 418                                ga.wf_name,
 419                                ga.wf_is_interactive,
 420                                ga.wf_is_autorouted,
 421                                gp.wf_p_id,
 422                                gp.wf_name as wf_procname,
 423                                gp.wf_version
 424          from ".GALAXIA_TABLE_PREFIX."processes gp
 425      INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 426      INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 427      INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 428      INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 429      $mid";
 430      $query_cant = "select count(distinct(ga.wf_activity_id))
 431      from ".GALAXIA_TABLE_PREFIX."processes gp
 432      INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id
 433      INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id
 434      INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id
 435      INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id
 436      $mid";
 437      $result = $this->query($query,$bindvars,$maxRecords,$offset, true, $sort_mode);
 438      $ret = Array();
 439      if (!(empty($result)))
 440      {
 441        while($res = $result->fetchRow()) 
 442        {
 443          $ret[] = $res;
 444        }
 445      }
 446      $retval = Array();
 447      $retval["data"]= $ret;
 448      $retval["cant"]= $this->getOne($query_cant,$bindvars);
 449      
 450      return $retval;
 451    }
 452  
 453    /*!
 454    * List instances avaible for a given user, theses instances are all the instances where the user is able
 455    * to launch a gui action (could be a run --even a run view activity-- or an advanced action like grab, release, admin, etc)
 456    * type of action really avaible are not given by this function. see getUserAction.
 457    * @param $user is the given user id
 458    * @param $offset is the starting number for the returned records
 459    * @param $maxRecords is the limit of records to return in data (but the 'cant' key count the total number without limits)
 460    * @param $sort_mode is the sort mode for the query
 461    * @param $find is a string to look at in activity name, activity description or instance name
 462    * @param $where is an empty string by default, the string let you add a string to the SQL statement -please be carefull with it.
 463    * @param $add_properties, false by default, will add properties in the returned instances
 464    * @return an array with number of records in the 'cant key and instances in the 'data' key. Each instance 
 465    * is an array containing theses keys: wf_instance_id, wf_started, wf_owner, wf_user, wf_status (instance status), wf_category, 
 466    * wf_act_status, wf_name (activity name), wf_type, wf_procname, wf_is_interactive, wf_is_autorouted, wf_activity_id, 
 467    * wf_version (process version), wf_p_id, insname (instance name), wf_priority and wf_readonly (which is true if the user only have 
 468    * read-only roles associated with this activity).
 469    */
 470    function gui_list_user_instances($user,$offset,$maxRecords,$sort_mode,$find,$where='',$add_properties=false)
 471    {
 472      // FIXME: this doesn't support multiple sort criteria
 473      //$sort_mode = $this->convert_sortmode($sort_mode);
 474      $sort_mode = str_replace("__"," ",$sort_mode);
 475  
 476      $mid = 'where gp.wf_is_active=?';
 477      // add group mapping, warning groups and user can have the same id
 478      $groups = galaxia_retrieve_user_groups($user);
 479      $mid .= " and (  ((gur.wf_user=? and gur.wf_account_type='u')";
 480      if (is_array($groups))
 481      {
 482        $mid .= '    or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
 483      }
 484      $mid .= ')';
 485  
 486      // this collect non interactive instances we are owner of
 487      $mid .= "     or ((gi.wf_owner=?) and ga.wf_is_interactive = 'n')"; 
 488      // and this collect completed instances when asked which haven't got any user anymore
 489      $mid .= '   or (gur.wf_user is NULL) )';
 490  
 491      
 492      $bindvars = array('y', $user, $user);
 493      
 494      if($find) {
 495        $findesc = '%'.$find.'%';
 496        $mid .= " and ( (upper(ga.wf_name) like upper(?))";
 497        $mid .= "       or (upper(ga.wf_description) like upper(?))";
 498        $mid .= "       or (upper(gi.wf_name) like upper(?)))";
 499        $bindvars[] = $findesc;
 500        $bindvars[] = $findesc;
 501        $bindvars[] = $findesc;
 502      }
 503      if($where) {
 504        $mid.= " and ($where) ";
 505      }
 506  
 507      // (regis) we need LEFT JOIN because aborted and completed instances are not showned 
 508      // in instance_activities, they're only in instances
 509      $query = 'select distinct(gi.wf_instance_id),
 510                       gi.wf_started,
 511                       gi.wf_owner,
 512                       gia.wf_user,
 513                       gi.wf_status,
 514                       gi.wf_category,
 515                       gia.wf_status as wf_act_status,
 516                       ga.wf_name,
 517                       ga.wf_type,
 518                       gp.wf_name as wf_procname, 
 519                       ga.wf_is_interactive,
 520                       ga.wf_is_autorouted,
 521                       ga.wf_activity_id,
 522                       gp.wf_version as wf_version,
 523                       gp.wf_p_id,
 524                       gi.wf_name as insname,
 525                       gi.wf_priority,
 526                       MIN(gar.wf_readonly) as wf_readonly';
 527      $query .= ($add_properties)? ', gi.wf_properties' : '';
 528      $query .= ' from '.GALAXIA_TABLE_PREFIX."instances gi 
 529                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id
 530                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gia.wf_activity_id = ga.wf_activity_id
 531                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id
 532                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gar.wf_role_id
 533                  INNER JOIN ".GALAXIA_TABLE_PREFIX."processes gp ON gp.wf_p_id=gi.wf_p_id
 534                $mid 
 535                GROUP BY gi.wf_instance_id, gi.wf_started, gi.wf_owner, gia.wf_user, gi.wf_status, gi.wf_category, 
 536                gia.wf_status, ga.wf_name, ga.wf_type, gp.wf_name, ga.wf_is_interactive, ga.wf_is_autorouted, 
 537                ga.wf_activity_id, gp.wf_version, gp.wf_p_id, gi.wf_name, gi.wf_priority";
 538      $query .= ($add_properties)? ', gi.wf_properties' : '';
 539      // (regis) this count query as to count global -unlimited- (instances/activities) not just instances
 540      // as we can have multiple activities for one instance and we will show all of them and the problem is 
 541      // that a user having memberships in several groups having the rights is counted several times. 
 542      // If we count instance_id without distinct we'll have several time the same line.
 543      // the solution is to count distinct instance_id for each activity and to sum theses results
 544      $query_cant = "select count(distinct(gi.wf_instance_id)) as cant, gia.wf_activity_id
 545                from ".GALAXIA_TABLE_PREFIX."instances gi 
 546                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id
 547                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gia.wf_activity_id = ga.wf_activity_id
 548                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id
 549                  LEFT JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gar.wf_role_id
 550                  INNER JOIN ".GALAXIA_TABLE_PREFIX."processes gp ON gp.wf_p_id=gi.wf_p_id
 551                $mid
 552                  GROUP BY gia.wf_activity_id";
 553      //echo "<br> query => ".$query; _debug_array($bindvars);
 554       
 555      $result = $this->query($query,$bindvars,$maxRecords,$offset, true, $sort_mode);
 556      $resultcant = $this->query($query_cant,$bindvars);
 557      $ret = Array();
 558      if (!(empty($result)))
 559      {
 560        $record = Array();
 561        $i = 0;
 562        while($res = $result->fetchRow()) 
 563        {
 564          // Get instances per activity
 565          $ret[]=$res;
 566        }
 567      }
 568      $cant=0;
 569      if (!(empty($resultcant)))
 570      {
 571        while($rescant = $resultcant->fetchRow()) 
 572        {
 573          // Get number of distinct instances per activity
 574          $cant += $rescant['cant'];
 575        }
 576      }
 577      $retval = Array();
 578      $retval["data"] = $ret;
 579      $retval["cant"] = $cant;
 580      return $retval;
 581    }
 582    
 583    /*! Get the view activity id avaible for a given process
 584    * No test is done on real access to this activity for users, this access will be check at runtime (when clicking)
 585    * @param $pId is the process Id
 586    * @return the view activity id or false if no view activity is present dor this process
 587    */
 588    function gui_get_process_view_activity($pId)
 589    {
 590      if (!(isset($this->process_cache[$pId]['view'])))
 591      {
 592        if (!(isset($this->pm)))
 593        {
 594          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'ProcessManager'.SEP.'ProcessManager.php');
 595          $this->pm =& new ProcessManager($this->db);
 596        }
 597        $this->process_cache[$pId]['view'] = $this->pm->get_process_view_activity($pId);
 598      }
 599      return $this->process_cache[$pId]['view'];
 600    }
 601  
 602    //! gets all informations about a given instance and a given user, list activities and status
 603    /*!
 604    * We list activities for which the user is the owner or the actual user or in a role giving him access to the activity
 605    * notice that completed and aborted instances aren't associated with activities and that start and standalone activities
 606    * aren't associated with an instance ==> if instanceId is 0 you'll get all standalone and start activities in the result.
 607    * this is the reason why you can give --if you have it-- the process id, to restrict results to start and standalone
 608    * activities to this process.
 609    * @param $user is the user id
 610    * @param $instance_id is the instance id
 611    * @param $pId is the process id, 0 by default, in such case it is ignored
 612    * @param $add_completed_instances false by default, if true we add completed instances in the result
 613    * @param $add_exception_instances false by default, if true we add instances in exception in the result
 614    * @param $add_aborted_instances false by default, if true we add aborted instances in the result
 615    * @return an associative array containing :
 616    * ['instance'] =>
 617    *     ['instance_id'], ['instance_status'], ['owner'], ['started'], ['ended'], ['priority'], ['instance_name'], 
 618    *    ['process_name'], ['process_version'], ['process_id']
 619    * ['activities'] =>
 620    *     ['activity'] =>
 621    *         ['user']        : actual user
 622    *         ['id']        : activity Id
 623    *         ['name']
 624    *         ['type']
 625    *         ['is_interactive']    : 'y' or 'n'
 626    *         ['is_autorouted']    : 'y' or 'n'
 627    *         ['status']
 628    */
 629    function gui_get_user_instance_status($user,$instance_id, $pId=0, $add_completed_instances=false,$add_exception_instances=false, $add_aborted_instances=false)
 630    {
 631      $bindvars =Array();
 632      $mid = "\n where gp.wf_is_active=?";
 633      $bindvars[] = 'y';
 634      if (!($pId==0))
 635      {
 636        // process restriction
 637        $mid.= " and gp.wf_p_id=?";
 638        $bindvars[] = $pId;
 639      }
 640      if (!($instance_id==0))
 641      {
 642        // instance selection
 643        $mid .= " and (gi.wf_instance_id=?)";
 644        $bindvars[] = $instance_id;
 645        $statuslist[]='active';
 646        if ($add_exception_instances) $statuslist[]='exception';
 647        if ($add_aborted_instances) $statuslist[]='aborted';
 648        if ($add_completed_instances) $statuslist[]='completed';
 649        $status_list = implode ($statuslist,',');
 650        $mid .= " and (gi.wf_status in ('".implode ("','",$statuslist)."'))\n";
 651      }
 652      else
 653      {
 654        // collect NULL instances for start and standalone activities
 655        $mid .= " and (gi.wf_instance_id is NULL)";
 656      }
 657      // add group mapping, warning groups and user can have the same id
 658      $groups = galaxia_retrieve_user_groups($user);
 659      $mid .= "\n and ( ((gur.wf_user=? and gur.wf_account_type='u')";
 660      if (is_array($groups))
 661      {
 662        $mid .= '    or (gur.wf_user in ('.implode(',',$groups).") and gur.wf_account_type='g')";
 663      }
 664      $mid .= ')';
 665      $bindvars[] = $user;
 666      // this collect non interactive instances we are owner of
 667      $mid .= "\n or (gi.wf_owner=?)"; 
 668      $bindvars[] = $user;
 669      // and this collect completed/aborted instances when asked which haven't got any user anymore
 670      if (($add_completed_instances) || ($add_aborted_instances))
 671      {
 672        $mid .= "\n or (gur.wf_user is NULL)";
 673      }
 674      $mid .= ")";
 675      
 676      // we need LEFT JOIN because aborted and completed instances are not showned 
 677      // in instance_activities, they're only in instances
 678      $query = 'select distinct(gi.wf_instance_id) as instance_id,
 679                       gi.wf_status as instance_status,
 680                       gi.wf_owner as owner,
 681                       gi.wf_started as started,
 682                       gi.wf_ended as ended,
 683                       gi.wf_priority as priority,
 684                       gi.wf_name as instance_name,
 685                       gp.wf_name as process_name,
 686                       gp.wf_version as process_version,
 687                       gp.wf_p_id as process_id,
 688                       gia.wf_user as user,
 689                       ga.wf_activity_id as id,
 690                       ga.wf_name as name,
 691                       ga.wf_type as type,
 692                       ga.wf_is_interactive as is_interactive,
 693                       ga.wf_is_autorouted as is_autorouted,
 694                       gia.wf_status as status';
 695      if ($instance_id==0)
 696      {//TODO: this gives all activities, rstrict to standalone and start
 697        $query.=' from '.GALAXIA_TABLE_PREFIX.'activities ga
 698                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'instance_activities gia ON ga.wf_activity_id=gia.wf_activity_id
 699                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'instances gi ON gia.wf_activity_id = gi.wf_instance_id
 700                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id
 701                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'user_roles gur ON gur.wf_role_id=gar.wf_role_id
 702                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'processes gp ON gp.wf_p_id=ga.wf_p_id '.$mid;
 703      }
 704      else
 705      {
 706        $query.=' from '.GALAXIA_TABLE_PREFIX.'instances gi
 707                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id
 708                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'activities ga ON gia.wf_activity_id = ga.wf_activity_id
 709                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id
 710                  LEFT JOIN '.GALAXIA_TABLE_PREFIX.'user_roles gur ON gur.wf_role_id=gar.wf_role_id
 711                  INNER JOIN '.GALAXIA_TABLE_PREFIX.'processes gp ON gp.wf_p_id=gi.wf_p_id '.$mid;
 712      }
 713      $result = $this->query($query,$bindvars);
 714      $retinst = Array();
 715      $retacts = Array();
 716      if (!!$result)
 717      {
 718        while($res = $result->fetchRow()) 
 719        {
 720          // Get instances per activity
 721          if (count($retinst)==0)
 722          {//the first time we retain instance data
 723            $retinst[] = array_slice($res,0,-7);
 724          }
 725          $retacts[] = array_slice($res,10);
 726        }
 727      }
 728      $retval = Array();
 729      $retval["instance"] = $retinst{0};
 730      $retval["activities"] = $retacts;
 731      return $retval;
 732    }
 733    
 734    //!Abort an instance - this terminates the instance with status 'aborted', and removes all running activities
 735    function gui_abort_instance($activityId,$instanceId)
 736    {
 737      $user = galaxia_retrieve_running_user();
 738      
 739      // start a transaction
 740      $this->db->StartTrans();
 741  
 742      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'abort')))
 743      {
 744        $this->error[] = ($this->wf_security->get_error());
 745        $this->db->FailTrans();
 746      }
 747      else
 748      {
 749        //the security object said everything was fine
 750        $instance = new Instance($this->db);
 751        $instance->getInstance($instanceId);
 752        if (!empty($instance->instanceId)) 
 753        {
 754            if (!($instance->abort($activityId,$user)))
 755            {
 756              $this->error[] = ($instance->get_error());
 757              $this->db->FailTrans();
 758            }
 759        }
 760        unset($instance);
 761      }
 762      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 763      return $this->db->CompleteTrans();
 764    }
 765    
 766    //!Exception handling for an instance - this sets the instance status to 'exception', but keeps all running activities.
 767    /*!
 768    * The instance can be resumed afterwards via gui_resume_instance().
 769    */
 770    function gui_exception_instance($activityId,$instanceId)
 771    {
 772      $user = galaxia_retrieve_running_user();
 773      
 774      // start a transaction
 775      $this->db->StartTrans();
 776  
 777      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'exception')))
 778      {
 779        $this->error[] = ($this->wf_security->get_error());
 780        $this->db->FailTrans();
 781      }
 782      else
 783      {
 784        //the security object said everything was fine
 785        $query = "update ".GALAXIA_TABLE_PREFIX."instances
 786                set wf_status=?
 787                where wf_instance_id=?";
 788        $this->query($query, array('exception',$instanceId));
 789      }
 790      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 791      return $this->db->CompleteTrans();
 792    }
 793  
 794    /*!
 795    Resume an instance - this sets the instance status from 'exception' back to 'active'
 796    */
 797    function gui_resume_instance($activityId,$instanceId)
 798    {
 799      $user = galaxia_retrieve_running_user();
 800      
 801      // start a transaction
 802      $this->db->StartTrans();
 803  
 804      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'resume')))
 805      {
 806        $this->error[] = ($this->wf_security->get_error());
 807        $this->db->FailTrans();
 808      }
 809      else
 810      {
 811        //the security object said everything was fine
 812        $query = "update ".GALAXIA_TABLE_PREFIX."instances
 813                set wf_status=?
 814                where wf_instance_id=?";
 815        $this->query($query, array('active',$instanceId));
 816      }
 817      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 818      return $this->db->CompleteTrans();
 819    }
 820  
 821    /*!
 822    * This function restart an automated activity (non-interactive) which is still in running mode (maybe it failed)
 823    * @param $activityId is the activity Id (the starting point)
 824    * @param $instanceId is the instance Id
 825    * @return the result true or false, if false nothing was done
 826    */
 827    function gui_restart_instance($activityId,$instanceId)
 828    {
 829      $user = galaxia_retrieve_running_user();
 830      
 831      //start a transaction
 832      $this->db->StartTrans();
 833      
 834      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'restart')))
 835      {
 836        $this->error[] = ($this->wf_security->get_error());
 837        $this->db->FailTrans();
 838      }
 839      else
 840      {
 841        //the security object said everything was fine
 842        $instance =& new Instance($this->db);
 843        $instance->getInstance($instanceId);
 844        // we force the execution of the activity
 845        $result = $instance->executeAutomaticActivity($activityId, $instanceId);      
 846        //TODO handle information returned in the sendAutorouted like in the completed activity template
 847        //_debug_array($result);
 848        $this->error[] = $instance->get_error();
 849        unset($instance);
 850      }
 851      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 852      return $this->db->CompleteTrans();
 853    }
 854  
 855    /*!
 856    * This function send a non autorouted activity i.e. take the transition which was not
 857    * taken automatically. It can be as well used to walk a transition which failed the first time
 858    * by the admin.
 859    * @param $activityId is the activity Id (the starting point)
 860    * @param $instanceId is the instance Id
 861    * @return the result true or false, if false nothing was done
 862    */
 863    function gui_send_instance($activityId,$instanceId)
 864    {
 865      $user = galaxia_retrieve_running_user();
 866      
 867      //start a transaction
 868      $this->db->StartTrans();
 869      
 870      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'send')))
 871      {
 872        $this->error[] = ($this->wf_security->get_error());
 873        $this->db->FailTrans();
 874      }
 875      else
 876      {
 877        //the security object said everything was fine
 878        $instance =& new Instance($this->db);
 879        $instance->getInstance($instanceId);
 880        // we force the continuation of the flow
 881        $result = $instance->sendAutorouted($activityId,true);
 882        //TODO handle information returned in the sendAutorouted like in the completed activity template
 883        //_debug_array($result);
 884        $this->error[] = $instance->get_error();
 885        unset($instance);
 886      }
 887      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 888      return $this->db->CompleteTrans();
 889    }
 890  
 891    
 892    function gui_release_instance($activityId,$instanceId)
 893    {
 894      $user = galaxia_retrieve_running_user();
 895      
 896      // start a transaction
 897      $this->db->StartTrans();
 898  
 899      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'release')))
 900      {
 901        $this->error[] = ($this->wf_security->get_error());
 902        $this->db->FailTrans();
 903      }
 904      else
 905      {
 906        //the security object said everything was fine
 907        $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities
 908                  set wf_user = ? 
 909                  where wf_instance_id=? and wf_activity_id=?";
 910        $this->query($query, array('*',$instanceId,$activityId));
 911      }
 912      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 913      return $this->db->CompleteTrans();
 914    }
 915    
 916    //! grab the instance for this activity and user if the security object agreed
 917    function gui_grab_instance($activityId,$instanceId)
 918    {
 919      $user = galaxia_retrieve_running_user();
 920      
 921      // start a transaction
 922      $this->db->StartTrans();
 923      //this check will as well lock the table rows
 924      if (!($this->wf_security->checkUserAction($activityId, $instanceId,'grab')))
 925      {
 926        $this->error[] = ($this->wf_security->get_error());
 927        $this->db->FailTrans();
 928      }
 929      else
 930      {
 931        //the security object said everything was fine
 932        $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities
 933                  set wf_user = ? 
 934                  where wf_instance_id=? and wf_activity_id=?";
 935        $this->query($query, array($user,$instanceId,$activityId));
 936      }
 937      // perform commit (return true) or Rollback (return false) if Failtrans it will automatically rollback
 938      return $this->db->CompleteTrans();
 939    }
 940  
 941    
 942    //! Return avaible actions for a given user on a given activity and a given instance assuming he already have access to it.
 943    /*!
 944    * @public
 945    * To be able to decide this function needs the user id, instance_id and activity_id. 
 946    * @param $user must be the user id
 947    * @param $instanceId must be the instance id (can be 0 if you have no instance - for start or standalone activities)
 948    * @param $activityId must be the activity id (can be 0 if you have no activity - for aborted or completed instances)
 949    * @param $readonly is he role mode, if true this is a readonly access, if false it is a not-only-read access
 950    * All other datas can be retrieved by internal queries BUT if you want this function to be fast and if you already 
 951    * have theses datas you should give as well theses fields (all or none): 
 952    * @param $pId the process id
 953    * @param $actType is the activity type string ('split', 'activity', 'switch', etc.)
 954    * @param $actInteractive is the activity interactivity ('y' or 'n')
 955    * @param $actAutorouted is the activity routage ('y' or 'n')
 956    * @param $actStatus is tha activity status ('completed' or 'running')
 957    * @param $instanceOwner is the instance owner user id
 958    * @param $instanceStatus is the instance status ('completed', 'active', 'exception', 'aborted')
 959    * @param $currentUser is the actual user of the instance (user id or '*')
 960    * @return an array of this form:
 961    * array('action name' => 'action description')
 962    * 'actions names' are: 'grab', 'release', 'run', 'send', 'view', 'exception', 'resume' and 'monitor'
 963    * Some config values can change theses rules but basically here they are:
 964    *     * 'grab'    : be the user of this activity. User has access to it and instance status is ok.
 965    *     * 'release'    : let * be the user of this activity. Must be the actual user or the owner of the instance.
 966    *     * 'run'        : run an associated form. This activity is interactive, user has access, instance status is ok.
 967    *     * 'send'    : send this instance, activity was non-autorouted and he has access and status is ok.
 968    *     * 'view'    : view the instance, activity ok, always avaible except for start or standalone act or processes with view activities.
 969    *    * 'viewrun'    : view the instance in a view activity, need to have a role on this view activity
 970    *     * 'abort'    : abort an instance, ok when we are the user
 971    *     * 'exception'     : set the instance status to exception, need to be the user 
 972    *     * 'resume'    : back to running when instance status was exception, need to be the user
 973    *     * 'monitor'     : special user rights to administer the instance
 974    * 'actions description' are translated explanations like 'release access to this activity'
 975    * WARNING: this is a snapshot, the engine give you a snaphsots of the rights a user have on an instance-activity
 976    * at a given time, this is not meaning theses rights will still be there when the user launch the action.
 977    * You should absolutely use the GUI Object to execute theses actions (except monitor) and they could be rejected.
 978    * WARNING: we do not check the user access rights. If you launch this function for a list of instances obtained via this
 979    * GUI object theses access rights are allready checked.
 980    */
 981    function getUserActions($user, $instanceId, $activityId, $readonly, $pId=0, $actType='not_set', $actInteractive='not_set', $actAutorouted='not_set', $actStatus='not_set', $instanceOwner='not_set', $instanceStatus='not_set', $currentUser='not_set') 
 982    {
 983      $result= array();//returned array
 984  
 985      //check if we have all the args and retrieve the ones whe did not have:
 986      if ((!($pId)) ||
 987        ($actType=='not_set') || 
 988        ($actInteractive=='not_set') || 
 989        ($actAutorouted=='not_set') || 
 990        ($actStatus=='not_set') ||
 991        ($instanceOwner=='not_set') ||
 992        ($currentUser=='not_set') ||
 993        ($instanceStatus=='not_set'))
 994      {
 995        // get process_id, type, interactivity, autorouting and act status and others for this instance
 996        // we retrieve info even if ended or in exception or aborted instances
 997        // and if $instanceId is 0 we get all standalone and start activities
 998        //echo '<br> call gui_get_user_instance_status:'.$pId.':'.$actType.':'.$actInteractive.':'.$actAutorouted.':'.$actStatus.':'.$instanceOwner.':'.$currentUser.':'.$instanceStatus;
 999        $array_info = $this->gui_get_user_instance_status($user,$instanceId,0,true,true,true);
1000        
1001        //now set our needed values
1002        $instance = $array_info['instance'];
1003        $pId = $instance['instance_id'];
1004        $instanceStatus = $instance['instance_status'];
1005        $instanceOwner = $instance['owner'];
1006        
1007        if (!((int)$activityId))
1008        {
1009          //we have no activity Id, like for aborted or completed instances, we set default values
1010          $actType = '';
1011          $actInteractive = 'n';
1012          $actAutorouted = 'n';
1013          $actstatus = '';
1014          $currentUser = 0;
1015        }
1016        else
1017        {
1018          $find=false;
1019          foreach ($array_info['activities'] as $activity)
1020          {
1021            //_debug_array($activity);
1022            //echo "<br> ==>".$activity['id']." : ".$activityId;
1023            if ((int)$activity['id']==(int)$activityId)
1024            {
1025              $actType = $activity['type'];
1026              $actInteractive = $activity['is_interactive'];
1027              $actAutorouted = $activity['is_autorouted'];
1028              $actstatus = $activity['status'];
1029              $currentUser = $activity['user'];
1030              $find = true;
1031              break;
1032            }
1033          }
1034          //if the activity_id can't be find we return empty actions
1035          if (!($find))
1036          {
1037            return array();
1038          }
1039        }
1040      }
1041      
1042      //now use the security object to get actions avaible, this object know the rules
1043      $view_activity = $this->gui_get_process_view_activity($pId);
1044      $result =& $this->wf_security->getUserActions($user, $instanceId, $activityId, $readonly, $pId, $actType, $actInteractive, $actAutorouted, $actStatus, $instanceOwner, $instanceStatus, $currentUser, $view_activity);
1045      return $result;
1046    }
1047  
1048    
1049  }
1050  ?>
1051  


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