Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
defattr.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  * Display family attributes
9  *
10  * @author Anakeen 2000
11  * @version $Id: defattr.php,v 1.28 2009/01/14 09:18:05 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 
19 include_once ("FDL/Lib.Dir.php");
20 include_once ("FDL/Class.Doc.php");
21 include_once ("FDL/Class.DocAttr.php");
22 
23 function defattr(&$action)
24 {
25  $dbaccess = $action->GetParam("FREEDOM_DB");
26  $docid = GetHttpVars("id", 0);
27  $classid = GetHttpVars("classid", 0); // use when new doc or change class
28  $dirid = GetHttpVars("dirid", 0); // directory to place doc if new doc
29  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
30 
32  if (!$doc->isAlive()) {
33  $action->exitError(sprintf(_("document %s not found") , $docid));
34  } elseif ($doc->doctype != 'C') {
35  $action->exitError(sprintf(_("document %s is not a family") , $doc->getTitle()));
36  }
37  $docid = $doc->id;
38 
39  $action->lay->Set("docid", $docid);
40  $action->lay->Set("dirid", $dirid);
41  // build values type array
42  $odocattr = new DocAttr($dbaccess);
43 
44  $action->lay->Set("TITLE", _("new document family"));
45  // when modification
46  if (($classid == 0) && ($docid != 0)) $classid = $doc->fromid;
47  else
48  // to show inherit attributes
49  if (($docid == 0) && ($classid > 0)) $doc = new_Doc($dbaccess, $classid); // the doc inherit from chosen class
50  $selectclass = array();
51  $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, $classid, "TABLE");
52  while (list($k, $cdoc) = each($tclassdoc)) {
53  $selectclass[$k]["idcdoc"] = $cdoc["id"];
54  $selectclass[$k]["classname"] = $cdoc["title"];
55  $selectclass[$k]["selected"] = "";
56  }
57 
58  $selectframe = array();
59 
60  $nbattr = 0; // if new document
61  // display current values
62  $newelem = array();
63  if ($docid > 0) {
64  // control if user can update
65  $err = $doc->CanLockFile();
66  if ($err != "") $action->ExitError($err);
67  $action->lay->Set("TITLE", $doc->title);
68  }
69  if (($classid > 0) || ($doc->doctype = 'C')) {
70  // selected the current class document
71  while (list($k, $cdoc) = each($selectclass)) {
72 
73  if ($classid == $selectclass[$k]["idcdoc"]) {
74 
75  $selectclass[$k]["selected"] = "selected";
76  }
77  }
78 
79  $ka = 0; // index attribute
80  // ------------------------------------------
81  // -------------------- FIELDSET ----------------------
82  $tattr = $doc->GetFieldAttributes();
83 
84  $selectframe = array();
85  $selectframe[0]["framevalue"] = "-";
86  $selectframe[0]["frameid"] = "";
87  $selectframe[0]["frameclass"] = "";
88  $selectframe[0]["selected"] = "";
89  $selecttab = $selectframe;
90 
91  foreach ($tattr as $k => $attr) {
92  if ($attr->docid > 0 && $attr->usefor != 'Q') {
93  $selectframe[$k]["framevalue"] = $attr->getLabel();
94  $selectframe[$k]["frameid"] = $attr->id;
95  $selectframe[$k]["frameclass"] = strtok($attr->type, '(');
96  $selectframe[$k]["selected"] = "";
97  if ($attr->type == "tab") $selecttab[$k] = $selectframe[$k];
98  }
99  }
100  foreach ($tattr as $k => $attr) {
101  if ($attr->docid > 0 && $attr->usefor != 'Q') {
102  $newelem[$k]["attrid"] = $attr->id;
103  $newelem[$k]["attrname"] = $attr->getLabel();
104  $newelem[$k]["neweltid"] = $k;
105  $newelem[$k]["visibility"] = $attr->visibility;
106  $newelem[$k]["options"] = $attr->options;
107  $newelem[$k]["typevalue"] = $attr->type;
108  $newelem[$k]["classvalue"] = strtok($attr->type, '(') . ' F' . strtok($attr->fieldSet->type, '(');
109  $newelem[$k]["disabledid"] = "disabled";
110  $newelem[$k]["order"] = "0";
111  $newelem[$k]["displayorder"] = - 2;
112  $newelem[$k]["profond"] = getAttributeProfunder($attr) * 10;
113  $newelem[$k]["profundator"] = getPuceAttributeProfunder($attr);
114  $newelem[$k]["SELECTFRAME"] = "SELECTFRAME_$k";
115 
116  if ($attr->type == "frame") {
117  foreach ($selecttab as $kopt => $opt) {
118  if ($opt["frameid"] == $attr->fieldSet->id) {
119  $selecttab[$kopt]["selected"] = "selected";
120  } else {
121  $selecttab[$kopt]["selected"] = "";
122  }
123  }
124  $action->lay->SetBlockData($newelem[$k]["SELECTFRAME"], $selecttab);
125  }
126  if ($attr->docid == $docid) {
127  $newelem[$k]["disabled"] = "";
128  } else {
129  $newelem[$k]["disabled"] = "disabled";
130  }
131  // unused be necessary for layout
132  $newelem[$k]["link"] = "";
133  $newelem[$k]["phpfile"] = "";
134  $newelem[$k]["phpfunc"] = "";
135  $newelem[$k]["phpconstraint"] = "";
136  $newelem[$k]["elink"] = "";
137  $newelem[$k]["abscheck"] = "";
138  $newelem[$k]["neededcheck"] = "";
139  $newelem[$k]["titcheck"] = "";
140  }
141  $ka++;
142  }
143  // ------------------------------------------
144  // -------------------- NORMAL ----------------------
145  $tattr = $doc->GetNormalAttributes();
146 
147  uasort($tattr, "tordered");
148  reset($tattr);
149  while (list($k, $attr) = each($tattr)) {
150  if ($attr->type == "array") {
151  $selectframe[$k]["framevalue"] = $attr->getLabel();
152  $selectframe[$k]["frameid"] = $attr->id;
153  $selectframe[$k]["selected"] = "";
154  }
155  $newelem[$k]["attrid"] = $attr->id;
156  $newelem[$k]["attrname"] = $attr->getLabel();
157  $newelem[$k]["order"] = $attr->ordered;
158  $newelem[$k]["displayorder"] = $attr->ordered;
159  $newelem[$k]["profond"] = getAttributeProfunder($attr) * 10;
160  $newelem[$k]["profundator"] = getPuceAttributeProfunder($attr);
161  $newelem[$k]["visibility"] = $attr->visibility;
162  $newelem[$k]["link"] = $attr->link;
163  $newelem[$k]["phpfile"] = $attr->phpfile;
164  $newelem[$k]["phpfunc"] = htmlspecialchars($attr->phpfunc);
165  $newelem[$k]["options"] = $attr->options;
166  $newelem[$k]["phpconstraint"] = $attr->phpconstraint;
167  $newelem[$k]["elink"] = $attr->elink;
168  $newelem[$k]["disabledid"] = "disabled";
169  $newelem[$k]["neweltid"] = $k;
170  if ($attr->isInAbstract) {
171  $newelem[$k]["abscheck"] = "checked";
172  } else {
173  $newelem[$k]["abscheck"] = "";
174  }
175  if ($attr->isInTitle) {
176  $newelem[$k]["titcheck"] = "checked";
177  } else {
178  $newelem[$k]["titcheck"] = "";
179  }
180 
181  $newelem[$k]["neededcheck"] = ($attr->needed) ? "checked" : "";
182 
183  if (($attr->docid == $docid) && ($attr->usefor != "A")) {
184  $newelem[$k]["disabled"] = "";
185  } else {
186  $newelem[$k]["disabled"] = "disabled";
187  }
188 
189  $newelem[$k]["typevalue"] = $attr->type;
190  $newelem[$k]["classvalue"] = strtok($attr->type, '(') . ' F' . strtok($attr->fieldSet->type, '(');
191  //if (($attr->repeat) && (!$attr->inArray())) $newelem[$k]["typevalue"].="list"; // add list if repetable attribute without array
192  if ($attr->format != "") $newelem[$k]["typevalue"].= "(\"" . $attr->format . "\")";
193  if ($attr->eformat != "") $newelem[$k]["phpfunc"] = "[" . $attr->eformat . "]" . $newelem[$k]["phpfunc"];
194 
195  $selectedSet = false;
196 
197  foreach ($selectframe as $kopt => $opt) {
198  if ($opt["frameid"] == $attr->fieldSet->id) {
199  $selectframe[$kopt]["selected"] = "selected";
200  $selectedSet = true;
201  if ($newelem[$kopt]["displayorder"] < 0) {
202  $newelem[$kopt]["displayorder"] = $attr->ordered - 1;
203  if ($attr->fieldSet->fieldSet && $attr->fieldSet->fieldSet->id) {
204  if ($newelem[$attr->fieldSet->fieldSet->id]["displayorder"] < 0) {
205  $newelem[$attr->fieldSet->fieldSet->id]["displayorder"] = $newelem[$kopt]["displayorder"] - 1;
206  }
207  }
208  }
209  } else {
210  $selectframe[$kopt]["selected"] = "";
211  }
212  }
213 
214  if (!$attr->fieldSet) {
215  simpleQuery($dbaccess, sprintf("select frameid from docattr where id='%s'", $attr->id) , $kset, true, true);
216 
217  $selectframe[$kset] = $selectframe[0];
218  $selectframe[$kset]["selected"] = "selected";
219  $selectframe[$kset]["framevalue"] = "INVALID $kset";
220  $selectframe[$kset]["frameid"] = "$kset";
221  $selectframe[$kset]["frameclass"] = "invalid";
222  $newelem[$k]["classvalue"] = "invalid";
223  }
224  $newelem[$k]["SELECTFRAME"] = "SELECTFRAME_$k";
225  $action->lay->SetBlockData($newelem[$k]["SELECTFRAME"], $selectframe);
226 
227  $ka++;
228  }
229  }
230  // reset default values
231  while (list($kopt, $opt) = each($selectframe)) $selectframe[$kopt]["selected"] = "";
232 
233  $action->lay->SetBlockData("SELECTCLASS", $selectclass);
234 
235  uasort($newelem, 'sortnewelem');
236  // ------------------------------------------
237  // -------------------- MENU ----------------------
238  $tattr = $doc->GetMenuAttributes(true);
239 
240  foreach ($tattr as $k => $attr) {
241  if ($attr->docid > 0) {
242  $newelem[$k]["attrid"] = $attr->id;
243  $newelem[$k]["attrname"] = $attr->getLabel();
244  $newelem[$k]["neweltid"] = $k;
245  $newelem[$k]["visibility"] = $attr->visibility;
246  $newelem[$k]["typevalue"] = $attr->type;
247  $newelem[$k]["classvalue"] = $attr->type;
248  $newelem[$k]["order"] = $attr->ordered;
249  $newelem[$k]["displayorder"] = $attr->ordered;
250  $newelem[$k]["disabledid"] = "disabled";
251  $newelem[$k]["options"] = $attr->options;
252  $newelem[$k]["SELECTFRAME"] = "SELECTFRAME_$k";
253  if ($attr->docid == $docid) {
254  $newelem[$k]["disabled"] = "";
255  } else {
256  $newelem[$k]["disabled"] = "disabled";
257  }
258 
259  $newelem[$k]["link"] = $attr->link;
260  $newelem[$k]["phpfunc"] = $attr->precond;;
261  // unused be necessary for layout
262  $newelem[$k]["phpfile"] = "";
263  $newelem[$k]["phpconstraint"] = "";
264  $newelem[$k]["elink"] = "";
265  $newelem[$k]["abscheck"] = "";
266  $newelem[$k]["titcheck"] = "";
267  }
268  $ka++;
269  }
270  // ------------------------------------------
271  // -------------------- Action ----------------------
272  $tattr = $doc->GetActionAttributes();
273 
274  foreach ($tattr as $k => $attr) {
275  if ($attr->docid > 0) {
276  $newelem[$k]["attrid"] = $attr->id;
277  $newelem[$k]["attrname"] = $attr->getLabel();
278  $newelem[$k]["neweltid"] = $k;
279  $newelem[$k]["visibility"] = $attr->visibility;
280  $newelem[$k]["typevalue"] = $attr->type;
281  $newelem[$k]["classvalue"] = $attr->type;
282  $newelem[$k]["order"] = $attr->ordered;
283  $newelem[$k]["displayorder"] = $attr->ordered;
284  $newelem[$k]["disabledid"] = "disabled";
285  $newelem[$k]["options"] = $attr->options;
286  $newelem[$k]["SELECTFRAME"] = "SELECTFRAME_$k";
287  if ($attr->docid == $docid) {
288  $newelem[$k]["disabled"] = "";
289  } else {
290  $newelem[$k]["disabled"] = "disabled";
291  }
292 
293  $newelem[$k]["link"] = $attr->link;
294  $newelem[$k]["phpfile"] = $attr->wapplication;
295  $newelem[$k]["phpfunc"] = $attr->waction;
296  // unused be necessary for layout
297  $newelem[$k]["phpconstraint"] = "";
298  $newelem[$k]["elink"] = "";
299  $newelem[$k]["abscheck"] = "";
300  $newelem[$k]["titcheck"] = "";
301  }
302  $ka++;
303  }
304  // add 3 new attributes to be defined
305  for ($k = $ka; $k < 3 + $ka; $k++) {
306  $newelem[$k]["neweltid"] = $k;
307  $newelem[$k]["attrname"] = "";
308  $newelem[$k]["disabledid"] = "";
309  $newelem[$k]["typevalue"] = "";
310  $newelem[$k]["classvalue"] = "";
311  $newelem[$k]["visibility"] = "W";
312  $newelem[$k]["link"] = "";
313  $newelem[$k]["elink"] = "";
314  $newelem[$k]["phpfile"] = "";
315  $newelem[$k]["phpfunc"] = "";
316  $newelem[$k]["phpconstraint"] = "";
317  $newelem[$k]["order"] = "";
318  $newelem[$k]["displayorder"] = "";
319  $newelem[$k]["attrid"] = "";
320 
321  $newelem[$k]["SELECTFRAME"] = "SELECTFRAME_$k";
322  $action->lay->SetBlockData($newelem[$k]["SELECTFRAME"], $selectframe);
323  $newelem[$k]["disabled"] = "";
324  }
325  unset($newelem["FIELD_HIDDENS"]);
326 
327  foreach ($newelem as $ia => $va) {
328  foreach ($va as $ip => $vp) {
329  $newelem[$ia][$ip] = str_replace('"', '&quot;', $vp);
330  }
331  }
332 
333  $action->lay->SetBlockData("NEWELEM", $newelem);
334 }
335 /**
336  * use to usort attributes
337  * @param BasicAttribute $a
338  * @param BasicAttribute $b
339  */
340 function sortnewelem($a, $b)
341 {
342  if (isset($a["displayorder"]) && isset($b["displayorder"])) {
343  if ($a["displayorder"] == $b["displayorder"]) return 0;
344  if ($a["displayorder"] > $b["displayorder"]) return 1;
345  return -1;
346  }
347  if (isset($a["displayorder"])) return 1;
348  if (isset($b["displayorder"])) return -1;
349  return 0;
350 }
351 
352 function getAttributeProfunder(&$oa)
353 {
354  if (!$oa) return 0;
355  if (!$oa->fieldSet) return 0;
356  if ($oa->fieldSet->id == 'FIELD_HIDDENS') return 0;
357  return 1 + getAttributeProfunder($oa->fieldSet);
358 }
360 {
361  $p = getAttributeProfunder($oa);
362  switch ($p) {
363  case 0:
364  return '';
365  case 1:
366  if ($oa->fieldSet->type == 'frame') {
367  return '<span class="frame">---</span>';
368  } elseif ($oa->fieldSet->type == 'tab') {
369  return '<span class="tab">---</span>';
370  } else {
371  return '<span class="unknow">---</span>';
372  }
373  case 2:
374  if ($oa->fieldSet->type == 'array') {
375  return '<span class="frame">---</span><span class="array">---</span>';
376  } elseif ($oa->fieldSet->type == 'frame') {
377  return '<span class="tab">---</span><span class="frame">---</span>';
378  } else {
379  return '<span class="unknow">---</span>';
380  }
381  case 3:
382  return '<span class="tab">---</span><span class="frame">---</span><span class="array">---</span>';
383  }
384 }
385 ?>
← centre documentaire © anakeen - published under CC License - Dynacase