Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
editstate.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  * State document edition
9  *
10  * @author Anakeen 2000
11  * @version $Id: editstate.php,v 1.25 2008/11/13 16:45:57 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 include_once ("FDL/Class.WDoc.php");
20 
21 include_once ("Class.QueryDb.php");
22 include_once ("FDL/freedom_util.php");
23 include_once ("FDL/editutil.php");
24 include_once ("FDL/editcard.php");
25 // -----------------------------------
26 function editstate(&$action)
27 {
28  //print "<HR>EDITCARD<HR>";
29  // Get All Parameters
30  $docid = GetHttpVars("id", 0); // document to edit
31  $classid = GetHttpVars("classid", 0); // use when new doc or change class
32  $dirid = GetHttpVars("dirid", 0); // directory to place doc if new doc
33  $usefor = GetHttpVars("usefor"); // special uses
34  $wneed = (GetHttpVars("wneed", "N") == "Y"); // with needed js
36  $dbaccess = $action->GetParam("FREEDOM_DB");
37  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
38  // ------------------------------------------------------
39  // new or modify ?
40  if ($docid == 0) {
41  if ($classid > 0) {
42  $doc = createDoc($dbaccess, $classid); // the doc inherit from chosen class
43  if (!$doc) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
44  $doc->id = $classid;
45  }
46  } else {
47  // when modification
49  }
50  $action->lay->set("tstates", "");
51  $action->lay->set("ttransid", "");
52  $action->lay->set("askes", "");
53  $action->lay->Set("Wattrnid", "");
54  $action->lay->Set("Wattrntitle", "");
55  $action->lay->Set("dcomment", "hidden");
56  $action->lay->Set("WID", false);
57  $action->lay->set("dvalidate", "");
58  if (($usefor != "D") && ($usefor != "Q")) {
59 
60  if ($doc->wid > 0) {
61  // compute the changed state
62  $wdoc = new_Doc($dbaccess, $doc->wid);
63  $wdoc->Set($doc);
64 
65  if (in_array($doc->state, $wdoc->nosave)) {
66  $action->lay->set("dvalidate", "none"); // don't see validate button if we want force change state
67 
68  } else {
69  $action->lay->setBlockData("UNCHANGE", array(
70  array(
71  "zou"
72  )
73  ));
74  }
75  $dcolor = $action->getParam("COLOR_A9");
76  $fstate = $wdoc->GetFollowingStates();
77  $tjsstate = array();
78  $tjstransid = array();
79  $tjsaskes = array();
80  $action->lay->Set("initstatevalue", $doc->state);
81  $action->lay->Set("initstatename", $action->text($doc->state));
82  $tstate = array();
83  $taskes = array();
84  if (isset($wdoc->autonext[$doc->state])) $dstate = $wdoc->autonext[$doc->state];
85  $action->lay->Set("dstate", ""); // default state
86  foreach ($fstate as $k => $v) {
87  $tr = $wdoc->getTransition($doc->state, $v);
88  $tk = $tr["id"];
89  $tstate[$k]["statevalue"] = $v;
90  if ($v == $dstate) {
91  $tstate[$k]["checked"] = "selected";
92  $action->lay->Set("dstate", $dstate);
93  $action->lay->Set("dcomment", "visible");
94  $tstate[$k]["dsubmit"] = "boldstate";
95  } else {
96  $tstate[$k]["checked"] = "";
97  $tstate[$k]["dsubmit"] = "state";
98  }
99 
100  $tstate[$k]["statename"] = _($v);
101  if (_("To" . $v) == "To" . $v) $lnextstate = sprintf(_("to %s") , _($v));
102  else $lnextstate = _("To" . $v);
103  $tstate[$k]["tostatename"] = ucfirst($lnextstate);
104  $tstate[$k]["asktitle"] = str_replace("'", "&rsquo;", sprintf(_("parameters for %s state") , _($v)));
105  $tstate[$k]["transid"] = $tk;
106  $color = $wdoc->getColor($v);;
107  $tstate[$k]["color"] = ($color) ? $color : $dcolor;
108  if (is_array($tr["ask"])) $tjsaskes[] = "['" . implode("','", $tr["ask"]) . "']";
109  else $tjsaskes[] = "[]";
110  if (is_array($tr["ask"])) $taskes = array_merge($taskes, $tr["ask"]);
111  $tjsstate[] = $v;
112  $tjstransid[] = $tk;
113  }
114  $action->lay->set("tstates", "'" . implode("','", $tjsstate) . "'");
115  $action->lay->set("ttransid", "'" . implode("','", $tjstransid) . "'");
116  $action->lay->set("askes", "" . strtolower(implode(",", $tjsaskes)) . "");
117  $action->lay->SetBlockData("NEWSTATE", $tstate);
118  $action->lay->Set("WID", true);
119  $action->lay->Set("NOSTATE", count($tstate) == 0);
120  if ($wdoc->viewlist == "button") {
121  $action->lay->SetBlockData("BUTTONSTATE", array(
122  0 => array(
123  "boo"
124  )
125  ));
126  } elseif ($wdoc->viewlist == "none") {
127  $action->lay->Set("WID", false);
128  } else {
129  $action->lay->SetBlockData("LISTSTATE", array(
130  0 => array(
131  "boo"
132  )
133  ));
134  }
135  $task = array();
136  $tneed = array();
137  $tinputs = array();
138  $taskes = array_unique($taskes);
139  foreach ($taskes as $ka => $va) {
140  $oa = $wdoc->getAttribute($va);
141  if ($oa) {
142  if ($oa->needed) $tneed[$oa->id] = $oa->getLabel();
143  if ($oa->usefor == 'Q') {
144  $wval = $wdoc->getParamValue($oa->id);
145  $wval = $wdoc->getValueMethod($wval);
146  } else {
147  $wval = $wdoc->getValue($oa->id);
148  }
149  $tinputs[] = array(
150  "alabel" => $oa->getLabel() ,
151  "labelclass" => ($oa->needed) ? "FREEDOMLabelNeeded" : "FREEDOMLabel",
152  "avalue" => getHtmlInput($wdoc, $oa, $wval) ,
153  "aid" => $oa->id,
154  "visibility" => ($oa->visibility == "H") ? "hidden" : "visible"
155  );
156  if ($oa->needed) $tneed[$oa->id] = $oa->getLabel();
157  }
158  }
159  $action->lay->SetBlockData("FINPUTS", $tinputs);
160  $action->lay->Set("Wattrntitle", "'" . implode("','", str_replace("'", "&rsquo;", $tneed)) . "'");
161  $action->lay->Set("Wattrnid", "'" . implode("','", array_keys($tneed)) . "'");
162  } else {
163  $fdoc = $doc->getFamDoc();
164 
165  $action->lay->Set("NOSTATE", false);
166  if ($fdoc->schar == "R") {
167  $action->lay->SetBlockData("COMMENT", array(
168  0 => array(
169  "boo"
170  )
171  ));
172  }
173  }
174  if ($wneed) {
176  if ($wdoc->viewlist == "button") {
177  $action->lay->set("dvalidate", "none");
178  }
179  }
180  }
181 }
182 ?>
← centre documentaire © anakeen - published under CC License - Dynacase