Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
fdl_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  * Execute Freedom Processes
9  *
10  * @author Anakeen 2005
11  * @version $Id: fdl_execute.php,v 1.6 2008/10/02 15:42:43 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 // refreah for a classname
19 // use this only if you have changed title attributes
20 include_once ("FDL/Lib.Attr.php");
21 include_once ("FDL/Class.DocFam.php");
22 
24 $appl->Set("FDL", $core);
25 
26 $dbaccess = $appl->GetParam("FREEDOM_DB");
27 if ($dbaccess == "") {
28  print "Database not found : param FREEDOM_DB";
29  exit;
30 }
31 
32 $docid = GetHttpVars("docid", 0); // special docid
33 $comment = base64_decode(GetHttpVars("comment")); // additionnal comment
34 if (($docid == 0) && (!is_numeric($docid))) $docid = getFamIdFromName($dbaccess, $docid);
35 
36 if ($docid > 0) {
38  if ($doc->locked == - 1) { // it is revised document
39  $doc = new_Doc($dbaccess, $doc->latestId());
40  }
41 
42  $doc->setValue("exec_status", "progressing");
43  $doc->setValue("exec_statusdate", $doc->getTimeDate());
44  $doc->modify(true, array(
45  "exec_status",
46  "exec_statusdate"
47  ) , true);
48  $cmd = $doc->bgCommand($action->user->id == 1);
49  $f = uniqid(getTmpDir() . "/fexe");
50  $fout = "$f.out";
51  $ferr = "$f.err";
52  $cmd.= ">$fout 2>$ferr";
53  $m1 = microtime();
54  system($cmd, $statut);
55  $m2 = microtime_diff(microtime() , $m1);
56  $ms = gmstrftime("%H:%M:%S", $m2);
57 
58  if (file_exists($fout)) {
59  $doc->setValue("exec_detail", file_get_contents($fout));
60  unlink($fout);
61  }
62  if (file_exists($ferr)) {
63  $doc->setValue("exec_detaillog", file_get_contents($ferr));
64  unlink($ferr);
65  }
66 
67  $doc->deleteValue("exec_nextdate");
68  $doc->setValue("exec_elapsed", $ms);
69  $doc->setValue("exec_date", date("d/m/Y H:i "));
70  $doc->deleteValue("exec_status");
71  $doc->deleteValue("exec_statusdate");
72  $doc->setValue("exec_state", (($statut == 0) ? "OK" : $statut));
73  $puserid = $doc->getValue("exec_iduser"); // default exec user
74  $doc->setValue("exec_iduser", $doc->getExecUserID());
75  $doc->refresh();
76  $err = $doc->modify();
77  if ($err == "") {
78  if ($comment != "") $doc->AddComment($comment);
79  $err = $doc->AddRevision(sprintf(_("execution by %s done %s") , $doc->getTitle($doc->getExecUserID()) , $statut));
80  if ($err == "") {
81  $doc->deleteValue("exec_elapsed");
82  $doc->deleteValue("exec_detail");
83  $doc->deleteValue("exec_detaillog");
84  $doc->deleteValue("exec_date");
85  $doc->deleteValue("exec_state");
86  $doc->setValue("exec_iduser", $puserid);
87  $doc->refresh();
88  $err = $doc->modify();
89  }
90  } else {
91  $doc->AddComment($err, HISTO_ERROR);
92  }
93 
94  if ($err != "") exit(1);
95 }
96 ?>
← centre documentaire © anakeen - published under CC License - Dynacase