Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.Execute.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Method for processes family
9  *
10  * @author Anakeen 2005
11  * @version $Id: Method.Execute.php,v 1.9 2008/12/02 13:21:27 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 /**
19  * @begin-method-ignore
20  * this part will be deleted when construct document class until end-method-ignore
21  */
22 class _EXEC extends Doc
23 {
24  /*
25  * @end-method-ignore
26  */
27  private $execuserid;
28  /**
29  * execute the action describe in the object
30  * @return int shell status (0 means OK).
31  */
32  function bgExecute($comment = "")
33  {
34 
35  if (!$this->canExecuteAction()) {
36  AddWarningMsg(sprintf(_("Error : need edit privilege to execute")));
37  } else {
38  if (ini_get("max_execution_time") < 3600) ini_set("max_execution_time", 3600);
39  $cmd = getWshCmd(true);
40  $cmd.= " --api=fdl_execute";
41  $cmd.= " --docid=" . $this->id;
42 
43  $cmd.= " --userid=" . $this->userid;
44  if ($comment != "") $cmd.= " --comment=" . base64_encode($comment); // prevent hack
45  system($cmd, $status);
46  if ($status == 0) AddWarningMsg(sprintf(_("Process %s [%d] executed") , $this->title, $this->id));
47  else AddWarningMsg(sprintf(_("Error : Process %s [%d]: status %d") , $this->title, $this->id, $status));
48  return $status;
49  }
50  }
51 
52  function resetExecute()
53  {
54  $this->deleteValue("exec_status");
55  $this->deleteValue("exec_statusdate");
56  $err = $this->modify();
57  return $err;
58  }
59  function isInprogress()
60  {
61  if ($this->canEdit() == "") {
62  if ($this->getvalue("exec_status") == "progressing") return MENU_ACTIVE;
63  }
64  return MENU_INVISIBLE;
65  }
66  function postModify()
67  {
68  $this->setValue("exec_nextdate", $this->getNextExecDate());
69  }
70  /**
71  * return the wsh command which be send
72  */
73  function bgCommand($masteruserid = false)
74  {
75  $bgapp = $this->getValue("exec_application");
76  $bgact = $this->getValue("exec_action");
77  $bgapi = $this->getValue("exec_api");
78 
79  $tp = $this->getAValues("exec_t_parameters");
80 
81  $cmd = getWshCmd(true);
82  if ($masteruserid) {
83  $fuid = $this->getValue("exec_iduser");
84  $fu = getTDoc($this->dbaccess, $fuid);
85  $wuid = $fu["us_whatid"];
86  $this->execuserid = $fuid;
87  } else {
88  $wuid = $this->userid;
89  $this->execuserid = $this->getUserId();
90  }
91  $cmd.= " --userid=$wuid";
92  if (!$bgapi) $cmd.= sprintf(" --app=%s --action=%s", escapeshellarg($bgapp) , escapeshellarg($bgact));
93  else $cmd.= sprintf(" --api=%s", escapeshellarg($bgapi));
94 
95  foreach ($tp as $k => $v) {
96  $b = sprintf(" --%s=%s", escapeshellarg($v["exec_idvar"]) , escapeshellarg($v["exec_valuevar"]));
97  $cmd.= $b;
98  }
99  return $cmd;
100  }
101  /**
102  * return the document user id for the next execution
103  * @return string
104  */
105  function getExecUserID()
106  {
107  return $this->execuserid;
108  }
109  /**
110  * return the next date to execute process
111  * @return date
112  */
113  function getNextExecDate()
114  {
115  $ndh = $this->getValue("exec_handnextdate");
116  if ($ndh == "") {
117  $nday = $this->getValue("exec_periodday", 0);
118  $nhour = $this->getValue("exec_periodhour", 0);
119  $nmin = $this->getValue("exec_periodmin", 0);
120  if (($nday + $nhour + $nmin) > 0) {
121  $ndh = $this->getDate($nday, $nhour, $nmin);
122  } else {
123  $ndh = " ";
124  }
125  }
126 
127  return $ndh;
128  }
129  function getPrevExecDate()
130  {
131  if ($this->revision > 0) {
132  $pid = $this->latestId(true);
133  $td = getTDoc($this->dbaccess, $pid);
134  $ndh = getv($td, "exec_date");
135 
136  return $ndh;
137  }
138  }
139 
140  function isLatestExec()
141  {
142  if ($this->locked == - 1) return MENU_INVISIBLE;
143  if (!$this->canExecuteAction()) return MENU_INACTIVE;
144  return MENU_ACTIVE;
145  }
146 
147  function canExecuteAction()
148  {
149  $err = $this->control('edit');
150  return ($err == "");
151  }
152  /**
153  * @begin-method-ignore
154  * this part will be deleted when construct document class until end-method-ignore
155  */
156 }
157 /*
158  * @end-method-ignore
159 */
160 ?>
← centre documentaire © anakeen - published under CC License - Dynacase