Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
editcard.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  * generate interface for the rdition of document
9  *
10  * @author Anakeen 2003
11  * @version $Id: editcard.php,v 1.76 2008/11/10 16:53:06 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.Doc.php");
20 include_once ("FDL/Class.DocAttr.php");
21 include_once ("FDL/editutil.php");
22 
23 function editcard(&$action)
24 {
25 
26  $docid = GetHttpVars("id", 0); // document to edit
27  $classid = GetHttpVars("classid", 0); // use when new doc or change class
28  $zonebodycard = GetHttpVars("zone"); // define view action
29  $usefor = GetHttpVars("usefor"); // default values for a document
30  $vid = GetHttpVars("vid"); // special controlled view
31  $mskid = GetHttpVars("mskid"); // special mask
32  $dbaccess = $action->GetParam("FREEDOM_DB");
34  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
35 
36  if (($usefor == "D") && ($zonebodycard == "")) $zonebodycard = "FDL:EDITBODYCARD"; // always default view for default document
37  if ($docid == 0) { // new document
38  if ($classid > 0) {
39  $doc = createDoc($dbaccess, $classid, true, ($usefor != "D"));
40  }
41  } else { // modify document
43  $docid = $doc->id;
44  if ($doc->isConfidential()) {
45  redirect($action, "FDL", "FDL_CONFIDENTIAL&&id=" . $doc->id);
46  }
47  $classid = $doc->fromid;
48  }
49 
50  $usefor = GetHttpVars("usefor"); // default values for a document
51  $vid = GetHttpVars("vid"); // special controlled view
52  $mskid = GetHttpVars("mskid"); // special mask
53  $dbaccess = $action->GetParam("FREEDOM_DB");
55  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
56 
57  if (($usefor == "D") && ($zonebodycard == "")) $zonebodycard = "FDL:EDITBODYCARD"; // always default view for default document
58  if ($docid == 0) { // new document
59  if ($classid > 0) {
60  $doc = createDoc($dbaccess, $classid, true, ($usefor != "D"));
61  if (!$doc) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
62  $fdoc = new DocFam($dbaccess, $classid);
63  if ($fdoc->control('icreate') != "") $action->exitError(sprintf(_("no privilege to create interactivaly this kind (%s) of document") , $fdoc->title));
64  }
65  } else { // modify document
67  $docid = $doc->id;
68  if ($doc->isConfidential()) {
69  redirect($action, "FDL", "FDL_CONFIDENTIAL&&id=" . $doc->id);
70  }
71  $fdoc = new DocFam($dbaccess, $classid);
72  }
73 
74  if (($usefor == "D") || ($usefor == "Q")) {
75  // special edit
76  $zonebodycard = "FDL:EDITBODYCARD";
77  switch ($usefor) {
78  case "D":
79  $doc->usefor = 'D';
80  $doc->setDefaultValues($fdoc->getDefValues() , false);
81  $doc->state = '';
82  break;
83 
84  case "Q":
85  $doc->usefor = 'Q';
86  $doc->setDefaultValues($fdoc->getParams() , false);
87  $doc->state = '';
88  break;
89  }
90  } else {
91  // normal edit
92  if ($doc->cvid > 0) {
93  if (!$vid) $vid = $doc->getDefaultView(true, "id");
94 
95  if ($vid) setHttpVar("vid", $vid);
96  // special controlled view
97  $cvdoc = new_Doc($dbaccess, $doc->cvid);
98  $cvdoc->set($doc);
99  }
100 
101  if (($vid != "") && ($doc->cvid > 0)) {
102  $err = $cvdoc->control(trim($vid)); // control special view
103  if ($err != "") $action->exitError("CV:" . $cvdoc->title . "\n" . $err);
104  $tview = $cvdoc->getView($vid);
105  $doc->setMask($tview["CV_MSKID"]);
106  if ($zonebodycard == "") $zonebodycard = $tview["CV_ZVIEW"];
107  }
108 
109  if (($vid == "") && ($mskid != "")) {
110  $mdoc = new_Doc($dbaccess, $mskid);
111  if ($mdoc->isAlive() && ($mdoc->control('view') == "")) $doc->setMask($mdoc->id);
112  }
113 
114  if (GetHttpVars("viewconstraint") == "Y") { // from modcard function if constraint error
115  include_once ("FDL/modcard.php");
116  setPostVars($doc); // HTTP VARS comes from previous edition
117 
118  }
119 
120  $msg = $doc->preEdition();
121  if ($zonebodycard == "") {
122  if ((!$docid) && $doc->defaultcreate != "") $zonebodycard = $doc->defaultcreate;
123  else $zonebodycard = $doc->defaultedit;
124  }
125  }
126  if ($zonebodycard == "") $zonebodycard = "FDL:EDITBODYCARD";
127  $action->lay->Set("classid", $classid);
128  $action->lay->Set("usefor", $usefor);
129 
130  if ($usefor == "D") {
131  $doc->SetWriteVisibility();
132  // contruct js functions
133  $jsfile = $action->GetLayoutFile("editcard.js");
134  $jslay = new Layout($jsfile, $action);
135  $jslay->Set("attrnid", '[]');
136  $jslay->Set("attrntitle", '[]');
137  $jslay->SetBlockData("RATTR", $tjsa);
138  $action->parent->AddJsCode($jslay->gen());
139  $action->lay->Set("ZONEBODYCARD", $doc->viewDoc($zonebodycard));
140  } else {
141  if ($doc->id == 0) {
142  if (fdl_setHttpVars($doc)) $doc->refresh();
143  }
145  $action->lay->Set("ZONEBODYCARD", $doc->viewDoc($zonebodycard));
147  }
148  $action->lay->set("maxFileUpload", ini_get("max_file_uploads"));
149  $action->lay->Set("NOFORM", (preg_match("/[A-Z]+:[^:]+:U/", $zonebodycard, $reg)));
150  // compute modify condition js
151 
152 }
153 
155 {
156  $attrn = $doc->GetNeededAttributes($doc->usefor == 'Q');
157 
158  if (count($attrn) == 0) {
159  $sattrNid = "[]";
160  $sattrNtitle = "[]";
161  } else {
162  while (list($k, $v) = each($attrn)) {
163  $attrNid[] = $v->id;
164  $attrNtitle[] = addslashes($v->getLabel());
165  }
166  $sattrNid = "['" . implode("','", $attrNid) . "']";
167  $sattrNtitle = "['" . implode("','", $attrNtitle) . "']";
168  }
169  //compute constraint for enable/disable input
170  $tjsa = array();
171  if ($doc->usefor != "D") {
172  /*
173  if (GetHttpVars("viewconstraint")!="Y") $doc->Refresh();
174  else {
175  $err=$doc->SpecRefresh(); // to use addParamRefresh
176  $err.=$doc->SpecRefreshGen(true);
177  }
178  */
179  $ka = 0;
180  foreach ($doc->paramRefresh as $k => $v) {
181  $tjsa[] = array(
182  "jstain" => "['" . implode("','", $v["in"]) . "']",
183  "jstaout" => "['" . implode("','", $v["out"]) . "']",
184  "jska" => "$ka"
185  );
186  $ka++;
187  }
188  }
189  // contruct js functions
190  $jsfile = $action->GetLayoutFile("editcard.js");
191  $jslay = new Layout($jsfile, $action);
192  $jslay->Set("attrnid", $sattrNid);
193  $jslay->Set("attrntitle", $sattrNtitle);
194  $jslay->SetBlockData("RATTR", $tjsa);
195  $action->parent->AddJsCode($jslay->gen());
196 }
198 {
199  if ($doc->usefor != "D") {
200  if ($doc->usefor == "Q") {
201  // parameters
202  $doc->SpecRefreshGen(true);
203  } else {
204  $doc->Refresh();
205  }
206  }
207 }
208 function moreone($v)
209 {
210  return (strlen($v) > 1);
211 }
212 
213 function cmp_cvorder2($a, $b)
214 {
215  if ($a["cv_order"] == $b["cv_order"]) {
216  return 0;
217  }
218  return ($a["cv_order"] < $b["cv_order"]) ? -1 : 1;
219 }
220 /**
221  * set values from http var in case of creation of doc
222  * values are set only if not set before
223  *
224  * @param Doc $doc current document to edit
225  * @return bool true if , at least, one value is modified
226  */
228 {
229  global $_GET, $_POST, $ZONE_ARGS;
230  $ismod = false;
231  $http = array();
232  foreach ($_POST as $k => $v) {
233  $http[$k] = $v;
234  }
235  foreach ($_GET as $k => $v) {
236  $http[$k] = $v;
237  }
238  if (is_array($ZONE_ARGS)) {
239  foreach ($ZONE_ARGS as $k => $v) {
240  $http[$k] = $v;
241  }
242  }
243 
244  foreach ($http as $k => $v) {
245  $oa = $doc->getAttribute($k);
246  if ($oa) {
247  if ($doc->getValue($k) == "") {
248  if ($oa->inArray() && (!is_array($v))) $v = $doc->_val2array(str_replace('\n', "\n", $v));
249  $doc->setValue($k, $v);
250  // print "<br>Set $k to ";print_r($v);
251  $ismod = true;
252  }
253  }
254  }
255 
256  return $ismod;
257 }
258 ?>
← centre documentaire © anakeen - published under CC License - Dynacase