Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
editcard.php
Go to the documentation of this file.
1 <?php
2 /*
3  * generate form interface for document
4  * @author Anakeen
5  * @package FDL
6 */
7 /**
8  */
9 include_once ("FDL/Class.Doc.php");
10 include_once ("FDL/Class.DocAttr.php");
11 include_once ("FDL/editutil.php");
12 
13 function editcard(Action & $action)
14 {
15  $docid = GetHttpVars("id", 0); // document to edit
16  $classid = GetHttpVars("classid", 0); // use when new doc or change class
17  $zonebodycard = GetHttpVars("zone"); // define view action
18  $usefor = GetHttpVars("usefor"); // default values for a document
19  $vid = GetHttpVars("vid"); // special controlled view
20  $mskid = GetHttpVars("mskid"); // special mask
21  $dbaccess = $action->dbaccess;
22 
23  $temporaryMode = $action->getParam("overrideICreate") == "true";
24  editmode($action);
25  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
26  $doc = $fdoc = null;
27  if (($usefor == "D") && ($zonebodycard == "")) $zonebodycard = "FDL:EDITBODYCARD"; // always default view for default document
28  if ($docid == 0) {
29  // new document
30  if ($classid > 0) {
31  if (!$doc) $doc = createDoc($dbaccess, $classid, true, ($usefor != "D"));
32  if (!$doc) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
33  $fdoc = new DocFam($dbaccess, $classid);
34  if (!$temporaryMode) {
35  if ($fdoc->control('icreate') != "") $action->exitError(sprintf(_("no privilege to create interactivaly this kind (%s) of document") , $fdoc->title));
36  }
37  }
38  } else {
39  // update document
40  $doc = new_Doc($dbaccess, $docid, true);
41  $docid = $doc->id;
42  if ($doc->isConfidential()) {
43  redirect($action, "FDL", "FDL_CONFIDENTIAL&&id=" . $doc->id);
44  }
45  $classid = $doc->fromid;
46  $fdoc = new DocFam($dbaccess, $classid);
47  }
48 
49  if (($usefor == "D") || ($usefor == "Q")) {
50  // special edit
51  $zonebodycard = "FDL:EDITBODYCARD";
52  switch ($usefor) {
53  case "D":
54  $doc->usefor = 'D';
55  $doc->setDefaultValues($fdoc->getDefValues() , false);
56  $doc->state = '';
57  break;
58 
59  case "Q":
60  $doc->usefor = 'Q';
61  $doc->setDefaultValues($fdoc->getParams() , false);
62  $doc->state = '';
63 
64  $action->parent->addJsRef("FDL:editfamilyparam.js", true);
65  break;
66  }
67  } else {
68  // normal edit
69  if ($doc->wid > 0) {
70  $err = $doc->setMask(0);
71  if ($err) addWarningMsg($err);
72  }
73  /*
74  * @var CVDoc $cvdoc
75  */
76  /*
77  * doc->cvid | vid != '' | mskid != '' || mask to apply
78  * -----------+-----------+-------------++-----------------
79  * 0 | 0 | 0 || setMask(0)
80  * 0 | 0 | 1 || setMask(mskid)
81  * 0 | 1 | 0 || (!) Not possible as a vid is the id of a view in doc->cvid
82  * 0 | 1 | 1 || (!) Not possible as a vid is the id of a view in doc->cvid
83  * 1 | 0 | 0 || setMask(Doc::USEMASKCVEDIT)
84  * 1 | 0 | 1 || setMask(mskid)
85  * 1 | 1 | 0 || setMask(cvid->vid->mskid) OR setMask(Doc::USEMASKCVEDIT)
86  * 1 | 1 | 1 || setMask(cvid->vid->mskid) OR setMask(Doc::USEMASKCVEDIT)
87  */
88  if ($doc->cvid) {
89 
90  $cvdoc = new_Doc($dbaccess, $doc->cvid);
91  $cvdoc->set($doc);
92  if (!$cvdoc->isAlive()) {
93  $err = "document not alive";
94  $action->exitError("CV:" . $doc->cvid . "\n" . $err);
95  return;
96  }
97  if ($vid != '') {
98  $err = $cvdoc->control(trim($vid));
99  if ($err != '') {
100  $action->exitError("CV:" . $cvdoc->title . "\n" . $err);
101  return;
102  }
103  $tview = $cvdoc->getView($vid);
104  if (isset($tview['CV_MSKID']) && $tview['CV_MSKID'] != '') {
105  $err = $doc->setMask($tview["CV_MSKID"]);
106  if ($err != '') {
108  }
109  }
110  if ($zonebodycard == "") {
111  $zonebodycard = $tview["CV_ZVIEW"];
112  }
113  } else {
114  $vid = $doc->getDefaultView(true, "id");
115  setHttpVar("vid", $vid);
116  if ($vid && $zonebodycard == "") {
117  $tview = $cvdoc->getView($vid);
118  $zonebodycard = $tview["CV_ZVIEW"];
119  }
120 
121  if ($mskid != '') {
122  /**
123  * Apply specified mask
124  *
125  * @var \Dcp\Family\MASK $mask
126  */
127  $mask = new_Doc($dbaccess, $mskid);
128  if ($mask->isAlive() && $mask->control('view') == '') {
129  $err = $doc->setMask($mask->id);
130  if ($err != '') {
132  }
133  }
134  } else {
135  $doc->setMask(Doc::USEMASKCVEDIT);
136  }
137  }
138  } else {
139  if ($vid != '') {
140  /* Not possible to have a vid without a doc->cvid */
141  } else {
142  if ($mskid != '') {
143  /**
144  * Apply specified mask
145  *
146  * @var \Dcp\Family\MASK $mask
147  */
148  $mask = new_Doc($dbaccess, $mskid);
149  if ($mask->isAlive() && $mask->control('view') == '') {
150  $err = $doc->setMask($mask->id);
151  if ($err != '') {
153  }
154  }
155  } else {
156  $doc->setMask(0);
157  }
158  }
159  }
160 
161  if (GetHttpVars("viewconstraint") == "Y") { // from modcard function if constraint error
162  include_once ("FDL/modcard.php");
163  setPostVars($doc); // HTTP VARS comes from previous edition
164 
165  }
166 
167  $msg = $doc->preEdition();
168  if ($zonebodycard == "") {
169  if ((!$docid) && $doc->defaultcreate != "") $zonebodycard = $doc->defaultcreate;
170  else $zonebodycard = $doc->defaultedit;
171  }
172  }
173  if ($zonebodycard == "") $zonebodycard = "FDL:EDITBODYCARD";
174  $action->lay->eSet("classid", $classid);
175  $action->lay->eSet("usefor", $usefor);
176 
177  if ($usefor == "D") {
179  // contruct js functions
180  $jsfile = $action->GetLayoutFile("editcard.js");
181  $jslay = new Layout($jsfile, $action);
182  $jslay->Set("attrnid", '[]');
183  $jslay->Set("attrntitle", '[]');
184  $jslay->SetBlockData("RATTR", array());
185  $action->parent->AddJsCode($jslay->gen());
186  $action->lay->Set("ZONEBODYCARD", $doc->viewDoc($zonebodycard));
187  } else {
188  if ($doc->id == 0) {
189  if (fdl_setHttpVars($doc)) $doc->refresh();
190  }
191  if ($usefor === "Q") {
193  }
194  setRefreshAttributes($action, $doc);
195  $action->lay->Set("ZONEBODYCARD", $doc->viewDoc($zonebodycard));
196  setNeededAttributes($action, $doc);
197  }
198  $action->lay->set("maxFileUpload", ini_get("max_file_uploads"));
199  $action->lay->Set("NOFORM", (preg_match("/[A-Z]+:[^:]+:U/", $zonebodycard, $reg)));
200  // compute modify condition js
201 
202 }
203 /**
204  * set with own parameters
205  * @param Doc $doc
206  */
208 {
209  $listattr = $doc->getParamAttributes();
210  if (is_a($doc, "DocFam")) {
211  $fam = $doc;
212  } else {
213  $fam = $doc->getFamilyDocument();
214  }
215 
216  $expertMode = getHttpVars("mode") === "expert";
217  foreach ($listattr as $aid => $attr) {
218  /*
219  * @var NormalAttribute $attr
220  */
221  $defParamValue = $fam->getDefValue($aid);
222  if ($attr->type !== "array" && $expertMode) {
223  if ($attr->type === "htmltext" || $attr->type === "longtext") {
224  $attr->type = "longtext";
225  } else {
226  $attr->type = "text";
227  }
228  $attr->format = "";
229  $attr->phpfile = '';
230  $attr->phpfunc = '';
231  }
232  if ($defParamValue) {
233  $attr->setOption("elabel", _("default value") . ": \n" . $defParamValue);
234  }
235  $doc->$aid = ''; // delete all value to set only own default values
236 
237  }
238 
239  $defVal = $fam->getOwnParams();
240  foreach ($defVal as $aid => $value) {
241  $doc->$aid = $value; // use raw affect to see method declaration
242  $oa = $doc->getAttribute($aid);
243  if (Doc::seemsMethod($value)) {
244  if ($oa->type === "htmltext" || $oa->type === "longtext") {
245  $oa->type = "longtext";
246  } else {
247  $oa->type = "text";
248  }
249  $oa->mvisibility = "W";
250  $oa->format = "";
251  $oa->phpfile = '';
252  $oa->phpfunc = '';
253  }
254  }
255 }
256 /**
257  * set all attribute in W visibility
258  *
259  * @param Doc $doc
260  */
262 {
263  // transform hidden to writted attribut for default document
264  $listattr = $doc->GetAttributes();
265  foreach ($listattr as $aid => $attr) {
266  $attr->setVisibility("W");
267 
268  if (is_a($attr, "NormalAttribute")) {
269  /*
270  * @var NormalAttribute $attr
271  */
272  if ($attr->type == "enum") {
273  $attr->setOption("eunset", "yes");
274  $attr->setOption("eformat", "auto");
275  $attr->setOption("etype", "free");
276  } elseif ($attr->type == "array") {
277  $attr->setOption("empty", "yes");
278  }
279  $doc->clearValue($attr->id); // delete all value to set only own default values
280 
281  }
282  }
283  if (is_a($doc, "DocFam")) {
284  /*
285  * @var DocFam $doc
286  */
287  $defVal = $doc->getOwnDefValues();
288  } else {
289  $fam = $doc->getFamilyDocument();
290  $defVal = $fam->getOwnDefValues();
291  }
292  foreach ($defVal as $aid => $value) {
293  $doc->$aid = $value; // use raw affect to see method declaration
294 
295  }
296 }
297 
298 function setNeededAttributes(Action & $action, Doc & $doc)
299 {
300  if ($doc->usefor == 'Q') {
301  $attrn = array();
302  } else {
303  $attrn = $doc->GetNeededAttributes($doc->usefor == 'Q');
304  }
305 
306  if (count($attrn) == 0) {
307  $sattrNid = "[]";
308  $sattrNtitle = "[]";
309  } else {
310  $attrNid = $attrNtitle = array();
311  /*
312  * @var NormalAttribute $v
313  */
314  foreach ($attrn as $v) {
315  $attrNid[] = $v->id;
316  $attrNtitle[] = addslashes($v->getLabel());
317  }
318  $sattrNid = "['" . implode("','", $attrNid) . "']";
319  $sattrNtitle = "['" . implode("','", $attrNtitle) . "']";
320  }
321  //compute constraint for enable/disable input
322  $tjsa = array();
323  if ($doc->usefor != "D") {
324  /*
325  if (GetHttpVars("viewconstraint")!="Y") $doc->Refresh();
326  else {
327  $err=$doc->SpecRefresh(); // to use addParamRefresh
328  $err.=$doc->SpecRefreshGen(true);
329  }
330  */
331  $ka = 0;
332  foreach ($doc->paramRefresh as $k => $v) {
333  $tjsa[] = array(
334  "jstain" => "['" . implode("','", $v["in"]) . "']",
335  "jstaout" => "['" . implode("','", $v["out"]) . "']",
336  "jska" => "$ka"
337  );
338  $ka++;
339  }
340  }
341  // contruct js functions
342  $jsfile = $action->GetLayoutFile("editcard.js");
343  $jslay = new Layout($jsfile, $action);
344  $jslay->Set("attrnid", $sattrNid);
345  $jslay->Set("attrntitle", $sattrNtitle);
346  $jslay->SetBlockData("RATTR", $tjsa);
347  $action->parent->AddJsCode($jslay->gen());
348 }
349 
350 function setRefreshAttributes(Action & $action, Doc & $doc)
351 {
352  if ($doc->usefor != "D") {
353  if ($doc->usefor == "Q") {
354  // parameters
355  $doc->SpecRefreshGen(true);
356  } else {
357  $doc->Refresh();
358  }
359  }
360 }
361 
362 function moreone($v)
363 {
364  return (strlen($v) > 1);
365 }
366 
367 function cmp_cvorder2($a, $b)
368 {
369  if ($a["cv_order"] == $b["cv_order"]) {
370  return 0;
371  }
372  return ($a["cv_order"] < $b["cv_order"]) ? -1 : 1;
373 }
374 /**
375  * set values from http var in case of creation of doc
376  * values are set only if not set before
377  *
378  * @param Doc $doc current document to edit
379  * @return bool true if , at least, one value is modified
380  */
382 {
383  global $_GET, $_POST, $ZONE_ARGS;
384  $ismod = false;
385  $http = array();
386  foreach ($_POST as $k => $v) {
387  $http[$k] = $v;
388  }
389  foreach ($_GET as $k => $v) {
390  $http[$k] = $v;
391  }
392  if (is_array($ZONE_ARGS)) {
393  foreach ($ZONE_ARGS as $k => $v) {
394  $http[$k] = $v;
395  }
396  }
397 
398  foreach ($http as $k => $v) {
399  $oa = $doc->getAttribute($k);
400  if ($oa) {
401  $curVal = $doc->getRawValue($k);
402  if (($curVal === "") || ($oa->inArray() && trim($curVal) === "")) {
403  if ($oa->inArray() && (!is_array($v))) $v = $doc->rawValueToArray(str_replace('\n', "\n", $v));
404  $doc->setValue($k, $v);
405  // print "<br>Set $k to ";print_r($v);
406  $ismod = true;
407  }
408  }
409  }
410 
411  return $ismod;
412 }
Layout is a template generator.
global $action
& getAttribute($idAttr, &$oa=null, $useMask=true)
Definition: Class.Doc.php:2152
global $_POST
Definition: chgpasswd.php:17
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
fdl_setHttpVars(&$doc)
Definition: editcard.php:381
getFamilyDocument()
Definition: Class.Doc.php:1482
addWarningMsg($msg)
Definition: Lib.Common.php:95
clearValue($attrid)
Definition: Class.Doc.php:4409
moreone($v)
Definition: editcard.php:362
setNeededAttributes(Action &$action, Doc &$doc)
Definition: editcard.php:298
getParamAttributes()
Definition: Class.Doc.php:2515
static seemsMethod($method)
Definition: Class.Doc.php:4495
setDocDefaultValues(Doc &$doc)
Definition: editcard.php:261
setPostVars(Doc &$doc, &$info=array())
Definition: modcard.php:259
Set($name, &$parent)
setRefreshAttributes(Action &$action, Doc &$doc)
Definition: editcard.php:350
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
global $_GET
Definition: wsh.php:37
const USEMASKCVEDIT
Definition: Class.Doc.php:61
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
getFamIdFromName($dbaccess, $name)
new_Doc($dbaccess, $id= '', $latest=false)
getParam($name, $def="")
useOwnParamters(Doc &$doc)
Definition: editcard.php:207
editmode(Action &$action)
Definition: editutil.php:41
cmp_cvorder2($a, $b)
Definition: editcard.php:367
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
$value
← centre documentaire © anakeen