Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

GUI.php

00001 <?php
00002 include_once(GALAXIA_LIBRARY.'/src/common/Base.php');
00005 
00008 class GUI extends Base {
00009 
00022   function gui_list_user_processes($user,$offset,$maxRecords,$sort_mode,$find,$where='')
00023   {
00024     // FIXME: this doesn't support multiple sort criteria
00025     //$sort_mode = $this->convert_sortmode($sort_mode);
00026     $sort_mode = str_replace("_"," ",$sort_mode);
00027 
00028     $mid = "where gp.isActive=? and gur.user=?";
00029     $bindvars = array('y',$user);
00030     if($find) {
00031       $findesc = '%'.$find.'%';
00032       $mid .= " and ((gp.name like ?) or (gp.description like ?))";
00033       $bindvars[] = $findesc;
00034       $bindvars[] = $findesc;
00035     }
00036     if($where) {
00037       $mid.= " and ($where) ";
00038     }
00039     
00040     $query = "select distinct(gp.pId), 
00041                      gp.isActive,                    
00042                      gp.name as procname, 
00043                      gp.normalized_name as normalized_name, 
00044                      gp.version as version
00045               from ".GALAXIA_TABLE_PREFIX."processes gp
00046                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.pId=ga.pId
00047                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=ga.activityId
00048                 INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.roleId=gar.roleId
00049                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gr.roleId
00050               $mid order by $sort_mode";
00051     $query_cant = "select count(distinct(gp.pId))
00052               from ".GALAXIA_TABLE_PREFIX."processes gp
00053                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.pId=ga.pId
00054                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=ga.activityId
00055                 INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.roleId=gar.roleId
00056                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gr.roleId
00057               $mid";
00058     $result = $this->query($query,$bindvars,$maxRecords,$offset);
00059     $cant = $this->getOne($query_cant,$bindvars);
00060     $ret = Array();
00061     while($res = $result->fetchRow()) {
00062       // Get instances per activity
00063       $pId=$res['pId'];
00064       $res['activities']=$this->getOne("select count(distinct(ga.activityId))
00065               from ".GALAXIA_TABLE_PREFIX."processes gp
00066                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.pId=ga.pId
00067                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=ga.activityId
00068                 INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.roleId=gar.roleId
00069                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gr.roleId
00070               where gp.pId=? and gur.user=?",
00071               array($pId,$user));
00072       $res['instances']=$this->getOne("select count(distinct(gi.instanceId))
00073               from ".GALAXIA_TABLE_PREFIX."instances gi
00074                 INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.instanceId=gia.instanceId
00075                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.activityId=gar.activityId
00076                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.roleId=gur.roleId
00077               where gi.pId=? and ((gia.user=?) or (gia.user=? and gur.user=?))",
00078               array($pId,$user,'*',$user));
00079       $ret[] = $res;
00080     }
00081     $retval = Array();
00082     $retval["data"] = $ret;
00083     $retval["cant"] = $cant;
00084     return $retval;
00085   }
00086 
00087 
00088   function gui_list_user_activities($user,$offset,$maxRecords,$sort_mode,$find,$where='')
00089   {
00090     // FIXME: this doesn't support multiple sort criteria
00091     //$sort_mode = $this->convert_sortmode($sort_mode);
00092     $sort_mode = str_replace("_"," ",$sort_mode);
00093 
00094     $mid = "where gp.isActive=? and gur.user=?";
00095     $bindvars = array('y',$user);
00096     if($find) {
00097       $findesc = '%'.$find.'%';
00098       $mid .= " and ((ga.name like ?) or (ga.description like ?))";
00099       $bindvars[] = $findesc;
00100       $bindvars[] = $findesc;
00101     }
00102     if($where) {
00103       $mid.= " and ($where) ";
00104     }
00105     
00106     $query = "select distinct(ga.activityId),                     
00107                      ga.name,
00108                      ga.type,
00109                      gp.name as procname, 
00110                      ga.isInteractive,
00111                      ga.isAutoRouted,
00112                      ga.activityId,
00113                      gp.version as version,
00114                      gp.pId,
00115                      gp.isActive
00116               from ".GALAXIA_TABLE_PREFIX."processes gp
00117                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.pId=ga.pId
00118                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=ga.activityId
00119                 INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.roleId=gar.roleId
00120                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gr.roleId
00121               $mid order by $sort_mode";
00122     $query_cant = "select count(distinct(ga.activityId))
00123               from ".GALAXIA_TABLE_PREFIX."processes gp
00124                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.pId=ga.pId
00125                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=ga.activityId
00126                 INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.roleId=gar.roleId
00127                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gr.roleId
00128               $mid";
00129     $result = $this->query($query,$bindvars,$maxRecords,$offset);
00130     $cant = $this->getOne($query_cant,$bindvars);
00131     $ret = Array();
00132     while($res = $result->fetchRow()) {
00133       // Get instances per activity
00134       $res['instances']=$this->getOne("select count(distinct(gi.instanceId))
00135               from ".GALAXIA_TABLE_PREFIX."instances gi
00136                 INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.instanceId=gia.instanceId
00137                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.activityId=gar.activityId
00138                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.roleId=gur.roleId
00139               where gia.activityId=? and ((gia.user=?) or (gia.user=? and gur.user=?))",
00140               array($res['activityId'],$user,'*',$user));
00141       $ret[] = $res;
00142     }
00143     $retval = Array();
00144     $retval["data"] = $ret;
00145     $retval["cant"] = $cant;
00146     return $retval;
00147   }
00148 
00149 
00150   function gui_list_user_instances($user,$offset,$maxRecords,$sort_mode,$find,$where='')
00151   {
00152     // FIXME: this doesn't support multiple sort criteria
00153     //$sort_mode = $this->convert_sortmode($sort_mode);
00154     $sort_mode = str_replace("_"," ",$sort_mode);
00155 
00156     $mid = "where (gia.user=? or (gia.user=? and gur.user=?))";
00157     $bindvars = array($user,'*',$user);
00158     if($find) {
00159       $findesc = '%'.$find.'%';
00160       $mid .= " and ((ga.name like ?) or (ga.description like ?))";
00161       $bindvars[] = $findesc;
00162       $bindvars[] = $findesc;
00163     }
00164     if($where) {
00165       $mid.= " and ($where) ";
00166     }
00167     
00168     $query = "select distinct(gi.instanceId),                     
00169                      gi.started,
00170                      gi.owner,
00171                      gia.user,
00172                      gi.status,
00173                      gia.status as actstatus,
00174                      ga.name,
00175                      ga.type,
00176                      gp.name as procname, 
00177                      ga.isInteractive,
00178                      ga.isAutoRouted,
00179                      ga.activityId,
00180                      gp.version as version,
00181                      gp.pId
00182               from ".GALAXIA_TABLE_PREFIX."instances gi 
00183                 INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.instanceId=gia.instanceId
00184                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gia.activityId = ga.activityId
00185                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.activityId=gar.activityId
00186                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gar.roleId
00187                 INNER JOIN ".GALAXIA_TABLE_PREFIX."processes gp ON gp.pId=ga.pId
00188               $mid order by $sort_mode";
00189     $query_cant = "select count(distinct(gi.instanceId))
00190               from ".GALAXIA_TABLE_PREFIX."instances gi 
00191                 INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.instanceId=gia.instanceId
00192                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gia.activityId = ga.activityId
00193                 INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.activityId=gar.activityId
00194                 INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.roleId=gar.roleId
00195                 INNER JOIN ".GALAXIA_TABLE_PREFIX."processes gp ON gp.pId=ga.pId
00196               $mid";
00197     $result = $this->query($query,$bindvars,$maxRecords,$offset);
00198     $cant = $this->getOne($query_cant,$bindvars);
00199     $ret = Array();
00200     while($res = $result->fetchRow()) {
00201       // Get instances per activity
00202       $ret[] = $res;
00203     }
00204     $retval = Array();
00205     $retval["data"] = $ret;
00206     $retval["cant"] = $cant;
00207     return $retval;
00208   }
00209 
00213   function gui_abort_instance($user,$activityId,$instanceId)
00214   {
00215     // Users can only abort instances they're currently running, or instances that they're the owner of
00216     if(!$this->getOne("select count(*)
00217                        from ".GALAXIA_TABLE_PREFIX."instance_activities gia, ".GALAXIA_TABLE_PREFIX."instances gi
00218                        where gia.instanceId=gi.instanceId and activityId=? and gia.instanceId=? and (user=? or owner=?)",
00219                        array($activityId,$instanceId,$user,$user)))
00220       return false;
00221     include_once(GALAXIA_LIBRARY.'/src/API/Instance.php');
00222     $instance = new Instance($this->db);
00223     $instance->getInstance($instanceId);
00224     if (!empty($instance->instanceId)) {
00225         $instance->abort($activityId,$user);
00226     }
00227     unset($instance);
00228   }
00229   
00234   function gui_exception_instance($user,$activityId,$instanceId)
00235   {
00236     // Users can only do exception handling for instances they're currently running, or instances that they're the owner of
00237     if(!$this->getOne("select count(*)
00238                        from ".GALAXIA_TABLE_PREFIX."instance_activities gia, ".GALAXIA_TABLE_PREFIX."instances gi
00239                        where gia.instanceId=gi.instanceId and activityId=? and gia.instanceId=? and (user=? or owner=?)",
00240                        array($activityId,$instanceId,$user,$user)))
00241       return false;
00242     $query = "update ".GALAXIA_TABLE_PREFIX."instances
00243               set status=?
00244               where instanceId=?";
00245     $this->query($query, array('exception',$instanceId));
00246   }
00247 
00251   function gui_resume_instance($user,$activityId,$instanceId)
00252   {
00253     // Users can only resume instances they're currently running, or instances that they're the owner of
00254     if(!$this->getOne("select count(*)
00255                        from ".GALAXIA_TABLE_PREFIX."instance_activities gia, ".GALAXIA_TABLE_PREFIX."instances gi
00256                        where gia.instanceId=gi.instanceId and activityId=? and gia.instanceId=? and (user=? or owner=?)",
00257                        array($activityId,$instanceId,$user,$user)))
00258       return false;
00259     $query = "update ".GALAXIA_TABLE_PREFIX."instances
00260               set status=?
00261               where instanceId=?";
00262     $this->query($query, array('active',$instanceId));
00263   }
00264 
00265   
00266   function gui_send_instance($user,$activityId,$instanceId)
00267   {
00268     if(!
00269       ($this->getOne("select count(*)
00270                       from ".GALAXIA_TABLE_PREFIX."instance_activities
00271                       where activityId=? and instanceId=? and user=?",
00272                       array($activityId,$instanceId,$user)))
00273       ||
00274       ($this->getOne("select count(*) 
00275                       from ".GALAXIA_TABLE_PREFIX."instance_activities gia
00276                       INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=gia.activityId
00277                       INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.roleId=gur.roleId
00278                       where gia.instanceId=? and gia.activityId=? and gia.user=? and gur.user=?",
00279                       array($instanceId,$activityId,'*',$user)))
00280       ) return false;
00281     include_once(GALAXIA_LIBRARY.'/src/API/Instance.php');
00282     $instance = new Instance($this->db);
00283     $instance->getInstance($instanceId);
00284     $instance->complete($activityId,true,false);
00285     unset($instance);  
00286   }
00287   
00288   function gui_release_instance($user,$activityId,$instanceId)
00289   {
00290     if(!$this->getOne("select count(*)
00291                        from ".GALAXIA_TABLE_PREFIX."instance_activities
00292                        where activityId=? and instanceId=? and user=?",
00293                        array($activityId,$instanceId,$user))) return false;
00294     $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities
00295               set user=?
00296               where instanceId=? and activityId=?";
00297     $this->query($query, array('*',$instanceId,$activityId));
00298   }
00299   
00300   function gui_grab_instance($user,$activityId,$instanceId)
00301   {
00302     // Grab only if roles are ok  
00303     if(!$this->getOne("select count(*) 
00304                       from ".GALAXIA_TABLE_PREFIX."instance_activities gia
00305                       INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.activityId=gia.activityId
00306                       INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.roleId=gur.roleId
00307                       where gia.instanceId=? and gia.activityId=? and gia.user=? and gur.user=?",
00308                       array($instanceId,$activityId,'*',$user)))  return false;
00309     $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities
00310               set user=?
00311               where instanceId=? and activityId=?";
00312     $this->query($query, array($user,$instanceId,$activityId));
00313   }
00314 }
00315 ?>

Generated on Mon Jun 7 16:37:37 2004 for Galaxia by doxygen 1.3.4