Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
editutil.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  * Edition functions utilities
9  *
10  * @author Anakeen 2000
11  * @version $Id: editutil.php,v 1.182 2009/01/14 12:33:31 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 // ---------------------------------------------------------------
20 include_once ("FDL/Class.Doc.php");
21 include_once ("FDL/Class.DocAttr.php");
22 include_once ("VAULT/Class.VaultFile.php");
23 /**
24  * Compose html code to insert input
25  * @param Doc &$doc document to edit
26  * @param DocAttribute &$attr attribute to edit
27  * @param string $value value of the attribute
28  * @param string $index in case of array : row of the array
29  * @param string $jsevent add an javascript callback on input (like onblur or onmouseover)
30  * @param string $notd not add cells in html input generated (by default inputs are in arrays)
31  */
32 function getHtmlInput(&$doc, &$oattr, $value, $index = "", $jsevent = "", $notd = false)
33 {
34  global $action;
35  $docid = intval($doc->id);
36  if ($docid == 0) $docid = intval($doc->fromid);
37  $attrtype = $oattr->type;
38  $usephpfunc = true;
39  $alone = $oattr->isAlone; // set by method caller in special case to display alone
40  $linkprefix = "";
41  $attrid = $oattr->id;
42  $attrin = '_' . $oattr->id; // for js name => for return values from client
43  if ($index !== "") $attridk = $oattr->id . '_' . $index;
44  else $attridk = $oattr->id . $index;
45  if ($oattr->inArray()) {
46  if ($index == - 1) {
47  $attrin.= '[-1]';
48  $attridk = $oattr->id . '__1x_';
49  } else $attrin.= "[$index]";
50  }
51  if (isset($oattr->mvisibility)) $visibility = $oattr->mvisibility;
52  else $visibility = $oattr->visibility;
53  if ($visibility == "I") return ""; // not editable attribute
54  $idisabled = " disabled readonly=1 title=\"" . _("read only") . "\" ";
55  $input = "";
56 
57  if (!$notd) $classname = "class=\"fullresize\"";
58  else $classname = "";
59 
60  if (($visibility == "H") || ($visibility == "R")) {
61  $input = "<input type=\"hidden\" name=\"" . $attrin . "\" value=\"" . chop(htmlentities(stripslashes($value) , ENT_COMPAT, "UTF-8")) . "\"";
62  $input.= " id=\"" . $attridk . "\" ";
63  $input.= " > ";
64  if (!$notd) $input.= '</td><td class="hiddenAttribute">';
65  return $input;
66  }
67 
68  $oc = "$jsevent onchange=\"document.isChanged=true\" "; // use in "pleaseSave" js function
69  if ($docid == 0) {
70  // case of specific interface
71  $iopt = '&phpfile=' . $oattr->phpfile . '&phpfunc=' . $oattr->phpfunc . '&label=' . ($oattr->getLabel());
72  } else $iopt = "";
73  if (($oattr->type != "array") && ($oattr->type != "htmltext") && ($oattr->type != "docid")) {
74  if ($visibility != "S") {
75  if ($usephpfunc && ($oattr->phpfunc != "") && ($oattr->phpfile != "") && ($oattr->type != "enum") && ($oattr->type != "enumlist")) {
76  if ($oattr->getOption("autosuggest", "yes") != "no") {
77  $autocomplete = " autocomplete=\"off\" autoinput=\"1\" onfocus=\"activeAuto(event," . $docid . ",this,'$iopt','$attrid','$index')\" ";
78  $oc.= $autocomplete;
79  }
80  }
81  }
82  }
83  // output change with type
84  switch ($attrtype) {
85  //----------------------------------------
86 
87  case "image":
88  if (preg_match(PREGEXPFILE, $value, $reg)) {
89  $check = "";
90  $originalname = "";
91  $dbaccess = GetParam("FREEDOM_DB");
93  $info = array();
94  if ($vf->Show($reg[2], $info) == "") {
95  $vid = $reg[2];
96  $fname = "<A target=\"_self\" href=\"" . GetParam("CORE_BASEURL") . "app=FDL&action=EXPORTFILE&vid=$vid&docid=$docid&attrid=$attrid&index=$index\" title=\"{$info->name}\">";
97  // put image
98  $fname.= "<IMG id=\"img_$attridk\" style=\"vertical-align:bottom;border:none;width:30px\" SRC=\"";
99  $fname.= GetParam("CORE_BASEURL") . "app=FDL&action=EXPORTFILE&width=30&vid=$vid&docid=" . $docid . "&attrid=" . $attrid . "&index=$index";
100  $fname.= "\">";
101 
102  $fname.= "</A>";
103  if ($oattr->getOption("preventfilechange") == "yes") {
104  include_once ("FDL/Lib.Vault.php");
105  $check = vault_uniqname($vid);
106  $originalname = "<input id=\"IFORI$attridk\" name=\"IFORI$attrin\" type=\"hidden\" orivalue=\"" . $doc->vault_filename($attrid, false, ($index ? $index : -1)) . "\">";
107  }
108  } else $fname = _("error in filename");
109  } else {
110  if ($value) {
111  $fname.= "<img id=\"img_$attridk\" style=\"vertical-align:bottom;width:30px\" SRC=\"";
112  $fname.= $action->getImageUrl($value);
113  $fname.= "\">";
114  } else {
115 
116  $fname = $action->GetIcon($oattr->getOption("defaultimage", "noimage.png") , _("no image") , 30);
117  $fname = str_replace("<img", '<img id="img_' . $attridk . '" style="vertical-align:bottom"', $fname);
118  }
119  }
120 
121  $input = $fname;
122 
123  $input = "<span id=\"IFERR" . $attridk . "\" class=\"Error\"></span><span class=\"FREEDOMText\">" . $fname . "</span><br/>";
124  $input.= $originalname;
125  // input
126  $input.= "<input name=\"" . $attrin . "\" type=\"hidden\" value=\"" . $value . "\" id=\"" . $attridk . "\">";
127  $input.= "<input type=\"hidden\" value=\"" . $value . "\" id=\"INIV" . $attridk . "\">";
128 
129  if (($visibility == "W") || ($visibility == "O")) {
130  $input.= "<span><input onchange=\"document.isChanged=true;changeFile(this,'$attridk','$check')\" $classname accept=\"image/*\" size=15 type=\"file\" id=\"IF_$attridk\" name=\"_UPL" . $attrin . "\"";
131  $input.= " ></span> ";
132  }
133  break;
134  //----------------------------------------
135 
136  case "file":
137  if (preg_match(PREGEXPFILE, $value, $reg)) {
138  $check = "";
139  $originalname = "";
140  $dbaccess = $action->GetParam("FREEDOM_DB");
142  if ($vf->Show($reg[2], $info) == "") {
143  $vid = $reg[2];
144  $DAV = getParam("FREEDAV_SERVEUR", false);
145 
146  if ($DAV) {
147  global $action;
148  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/DAV/Layout/getsessionid.js");
149  $oc = sprintf(" onclick='this.href=getPrivateDavHref(\"%s\",\"%s\",\"%s\",this.getAttribute(\"filename\"))' filename=\"%s\"", $docid, $vid, $DAV, str_replace('"', '%22', $info->name));
150  //$oc="onclick=\"var sid=getsessionid('".$docid."','$vid');this.href='asdav://$DAV/freedav/vid-'+sid+'/'.$info->name."e";
151  $fname = "<A title=\"" . _("open file with your editor") . "\" href=\"#\" $oc><img style=\"border:none\" src=\"Images/davedit.png\">";
152  } else {
153  $fname = "<A target=\"_self\" title=\"" . _("download file") . "\" href=\"" . $action->GetParam("CORE_BASEURL") . "app=FDL&action=EXPORTFILE&vid=$vid&docid=$docid&attrid=$attrid&index=$index\">";
154  }
155  $fname.= $info->name;
156  $fname.= "</A>";
157  if ($oattr->getOption("preventfilechange") == "yes") {
158  include_once ("FDL/Lib.Vault.php");
159  $check = vault_uniqname($vid);
160  $originalname = "<input id=\"IFORI$attridk\" name=\"IFORI$attrin\" type=\"hidden\" orivalue=\"" . $doc->vault_filename($attrid, false, ($index ? $index : -1)) . "\">";
161  }
162  } else $fname = _("error in filename");
163  } else $fname = _("no filename");
164 
165  $input = "<span id=\"IFERR" . $attridk . "\" class=\"Error\"></span><span class=\"FREEDOMText\">" . $fname . "</span><br/>";
166  $input.= $originalname;
167  // input
168  $input.= "<input name=\"" . $attrin . "\" type=\"hidden\" value=\"" . $value . "\" id=\"" . $attridk . "\">";
169  $input.= "<input type=\"hidden\" value=\"" . $value . "\" id=\"INIV" . $attridk . "\">";
170  $input.= "<span><input onchange=\"document.isChanged=true;changeFile(this,'$attridk','$check')\" class=\"\" size=15 type=\"file\" id=\"IF_$attridk\" name=\"_UPL" . $attrin . "\" value=\"" . chop(htmlentities($value, ENT_COMPAT, "UTF-8")) . "\"";
171 
172  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
173  $input.= " ></span> ";
174  break;
175  //----------------------------------------
176 
177  case "longtext":
178  case "xml":
179  $lh = $oattr->getOption("editheight", "2em");
180  $elabel = $oattr->getOption("elabel");
181  if ($elabel != "") $oc.= " title=\"$elabel\"";
182 
183  $input = "<textarea $oc wrap=\"virtual\" onkeyup=\"textautovsize(event,this)\" onclick=\"textautovsize(event,this)\" class=\"autoresize\" style=\"height:$lh\" name=\"" . $attrin . "\" ";
184  $input.= " id=\"" . $attridk . "\" ";
185  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
186  $input.= " >" . str_replace(array(
187  "[",
188  "$"
189  ) , array(
190  "&#091;",
191  "&#036;"
192  ) , htmlentities(stripslashes(str_replace("<BR>", "\n", $value)) , ENT_COMPAT, "UTF-8")) . "</textarea>";
193 
194  break;
195  //----------------------------------------
196 
197  case "htmltext":
198 
199  if (($visibility == "H") || ($visibility == "R")) {
200  $input = "<textarea name=\"$attrin\">$value</textarea>";
201  } elseif ($visibility == "S") {
202  // no input : just text
203  if ($value == "") $value = '<br/>';
204  $input = "<div class=\"static\" name=\"$attrin\">$value</div>";
205  } else {
206  $lay = new Layout("FDL/Layout/fckeditor.xml", $action);
207  $lay->set("Value", str_replace(array(
208  "\n",
209  "\r",
210  "script>",
211  '&quot;',
212  '&lt;',
213  '&gt;'
214  ) , array(
215  " ",
216  " ",
217  "pre>",
218  '&amp;quot;',
219  '&amp;lt;',
220  '&amp;gt;'
221  ) , $value));
222  $lay->set("label", ucFirst($oattr->getLabel()));
223  $lay->set("need", $oattr->needed);
224  $lay->set("height", $oattr->getOption("editheight", "150px"));
225  $lay->set("toolbar", $oattr->getOption("toolbar", "Simple"));
226  $lay->set("toolbarexpand", (strtolower($oattr->getOption("toolbarexpand")) == "no") ? "false" : "true");
227  $lay->set("aid", $attridk);
228  $lay->set("aname", $attrin);
229  if (($visibility == "R") || ($visibility == "S")) $lay->set("disabled", $idisabled);
230  else $lay->set("disabled", "");
231  $input = $lay->gen();
232  }
233 
234  break;
235  //----------------------------------------
236 
237  case "idoc":
238 
239  $input.= getLayIdoc($doc, $oattr, $attridk, $attrin, $value);
240 
241  break;
242  //----------------------------------------
243 
244  case "array":
245 
246  $lay = new Layout("FDL/Layout/editarray.xml", $action);
247  $rn = $oattr->getOption("roweditzone");
248  if ($rn) getZoneLayArray($lay, $doc, $oattr, $rn);
249  else getLayArray($lay, $doc, $oattr);
250 
251  $input = $lay->gen();
252  break;
253 
254  case "thesaurus":
255  $multi = $oattr->getOption("multiple");
256  if ($multi) {
257 
258  $lay = new Layout("THESAURUS/Layout/editmultiinputthconcept.xml");
259  $lay->set("atitle", false);
260  $lay->set("elabel", $oattr->getOption("elabel", _("Display available choices")));
261  $top = array();
262  if ($value) {
263  $thids = explode("<BR>", str_replace("\n", "<BR>", $value));
264  foreach ($thids as $kth => $vth) {
265  $th = new_doc($doc->dbaccess, trim($vth));
266  if ($th->isAlive()) {
267  $thtitle = $th->getLangTitle();
268  $top[] = array(
269  "ltitle" => substr($thtitle, 0, 100) ,
270  "ldocid" => $vth
271  );
272  }
273  }
274  $lay->setBlockData("options", $top);
275  $lay->set("size", count($top));
276  } else $lay->set("size", 1); // may be up to zero
277  $lay->set("empty", count($top) == 0);
278  } else {
279  $lay = new Layout("THESAURUS/Layout/editinputthconcept.xml");
280  if ($value) {
281  $th = new_doc($doc->dbaccess, $value);
282  $thtitle = $th->getLangTitle();
283  $lay->set("atitle", $thtitle);
284  } else $lay->set("atitle", false);
285  }
286  $lay->set("value", $value);
287  $lay->set("aname", $attrin);
288  $lay->set("aid", $attridk);
289  $idth = $oattr->format;
290 
291  $thid = $doc->getValue($idth);
292  if (!$thid) $thid = $idth; // direct logical name
293  $lay->set("thesaurus", $thid);
294  $notd = true; // autonome input
295  $input = $lay->gen();
296  break;
297  //----------------------------------------
298 
299  case "doc":
300 
301  $lay = new Layout("FDL/Layout/editadoc.xml", $action);
302  getLayAdoc($lay, $doc, $oattr, $value, $attrin, $index);
303 
304  if (($visibility == "R") || ($visibility == "S")) $lay->set("disabled", $idisabled);
305  else $lay->set("disabled", "");
306  $input = $lay->gen();
307  break;
308  //----------------------------------------
309 
310 
311  case "docid":
312  $famid = $oattr->format;
313  if ($famid) {
314  $needLatest = ($oattr->getOption("docrev", "latest") == "latest");
315  // edit document relation
316  $multi = $oattr->getOption("multiple");
317  $input = "";
318  $linkprefix = "ilink_";
319  if ($multi == "yes") {
320  $lay = new Layout("FDL/Layout/editmdoc.xml", $action);
321  getLayMultiDoc($lay, $doc, $oattr, $value, $attrin, $index);
322 
323  $cible = "mdocid_work";
324  if (($visibility == "R") || ($visibility == "S")) $lay->set("disabled", $idisabled);
325  else $lay->set("disabled", "");
326  $lay->set("cible", $cible);
327 
328  $input2 = $lay->gen();
329  } else {
330  $input2 = "";
331 
332  if ($doc->usefor == "D") $input = "<input type=\"text\" title=\"" . _("real value to set") . "\" name=\"" . $attrin . "\"";
333  else $input = "<input type=\"hidden\" name=\"" . $attrin . "\"";
334  $input.= " id=\"" . $attridk . "\" value=\"$value\">";
335  $cible = "";
336  $textvalue = $doc->getTitle(trim($value) , '', $needLatest);
337  }
338 
339  if (!$oattr->phpfile) {
340  $oattr->phpfile = "fdl.php";
341  $oattr->phpfunc = "lfamily(D,$famid,${linkprefix}${attrid}):${cible}$attrid,${linkprefix}${attrid}";
342  } else {
343  $phpfunc = preg_replace('/([\s|,|:])CT([\s|,|\)]|$)/', '$1' . $linkprefix . $attrid . '$2', $oattr->phpfunc);
344  $phpfunc = str_replace("):$attrid,", "):${cible}${attrid},", $phpfunc);
345  $phpfunc = str_replace("):" . strtoupper($attrid) . ",", "):${cible}${attrid},", $phpfunc);
346  $oattr->phpfunc = $phpfunc;
347  }
348  if ($docid == 0) {
349  // case of specific interface
350  $iopt = '&phpfile=' . $oattr->phpfile . '&phpfunc=' . $oattr->phpfunc . '&label=' . ($oattr->getLabel());
351  }
352  $autocomplete = " autocomplete=\"off\" autoinput=\"1\" onfocus=\"activeAuto(event," . $docid . ",this,'$iopt','$attrid','$index')\" ";
353  $oc.= $autocomplete;
354 
355  $famid = $oattr->format;
356  $input.= "<input $classname $autocomplete $jsevent onchange=\"addmdocs('$attrin');document.isChanged=true\" type=\"text\" name=\"_${linkprefix}" . substr($attrin, 1) . "\"";
357  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
358  $input.= " id=\"${linkprefix}" . $attridk . "\" value=\"" . $textvalue . "\">";
359 
360  if (!$cible) {
361  $doc->addparamrefresh($attrid, $linkprefix . $attrid);
362  } else {
363  $input = $input2 . $input;
364  }
365  } else {
366  $input = "<input $oc $classname type=\"text\" name=\"" . $attrin . "\" value=\"" . $value . "\"";
367  $input.= " id=\"" . $attridk . "\" ";
368  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
369  $input.= " > ";
370  }
371  break;
372 
373  case "enum":
374  if ($oattr->eformat == "") $oattr->eformat = $oattr->getOption("eformat");
375  if (($oattr->repeat) && (!$oattr->inArray())) { // enumlist
376  switch ($oattr->eformat) {
377  case "vcheck":
378  $lay = new Layout("FDL/Layout/editenumlistvcheck.xml", $action);
379  break;
380 
381  case "hcheck":
382  $lay = new Layout("FDL/Layout/editenumlisthcheck.xml", $action);
383  break;
384 
385  case "auto":
386  $lay = new Layout("FDL/Layout/editenumlistauto.xml", $action);
387  break;
388 
389  default:
390  $lay = new Layout("FDL/Layout/editenumlist.xml", $action);
391  }
392  } else {
393  $enuml = $oattr->getenumlabel();
394  $lunset = current($enuml);
395  if ($value == "") {
396  if (($oattr->eformat == 'bool') || ($oattr->getOption("eunset") != "yes")) $value = key($enuml);
397  else $value = " ";
398  }
399  switch ($oattr->eformat) {
400  case "vcheck":
401  $lay = new Layout("FDL/Layout/editenumvcheck.xml", $action);
402  break;
403 
404  case "hcheck":
405  $lay = new Layout("FDL/Layout/editenumhcheck.xml", $action);
406  break;
407 
408  case "auto":
409  $lay = new Layout("FDL/Layout/editenumauto.xml", $action);
410  //$notd = true;
411  break;
412 
413  case "bool":
414  $lay = new Layout("FDL/Layout/editenumbool.xml", $action);
415 
416  $lset = next($enuml);
417  $boolkeys = array_keys($enuml);
418  if ($value == key($enuml)) $lay->set("checkedyesno", "checked");
419  else $lay->set("checkedyesno", "");
420  $lay->set("tyesno", sprintf(_("set for %s, unset for %s") , $lset, $lunset));
421  $lay->set("val1", $boolkeys[0]);
422  $lay->set("val2", $boolkeys[1]);
423  break;
424 
425  default:
426  $lay = new Layout("FDL/Layout/editenum.xml", $action);
427  }
428  }
429 
430  getLayOptions($lay, $doc, $oattr, $value, $attrin, $index);
431  $lay->set("msize", $oattr->getOption("mselectsize", 3));
432  if (($visibility == "R") || ($visibility == "S")) $lay->set("disabled", $idisabled);
433  else $lay->set("disabled", "");
434 
435  $lay->set("NOTD", $notd);
436  $input = $lay->gen();
437  break;
438  //----------------------------------------
439 
440 
441  case "color":
442  $elabel = $oattr->getOption("elabel");
443  if ($elabel != "") $eopt.= " title=\"$elabel\"";
444  $input = "<input size=7 $eopt style=\"background-color:$value\" type=\"text\" name=\"" . $attrin . "\" value=\"" . chop(htmlentities($value, ENT_COMPAT, "UTF-8")) . "\"";
445  $input.= " id=\"" . $attridk . "\" ";
446 
447  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
448  else if ($doc->usefor != 'D') $input.= " disabled "; // always but default
449  $input.= " class=\"color {pickerOnfocus:false,pickerClosable:true,pickerCloseText:'" . _("Close") . "',hash:true,required:false}\" ";
450 
451  $input.= " >&nbsp;";
452  if (!(($visibility == "R") || ($visibility == "S"))) {
453  $input.= "<input id=\"ic_$attridk\" type=\"button\" value=\"&#133;\"" . " title=\"" . _("color picker") . "\" onclick=\"jscolor.init(); document.getElementById('$attridk').color.showPicker()\"" . ">";
454  }
455  break;
456  //----------------------------------------
457 
458 
459  case "date":
460  $lay = new Layout("FDL/Layout/editdate.xml", $action);
461  getLayDate($lay, $doc, $oattr, $value, $attrin, $index);
462 
463  $lay->set("disabled", "");
464  if (($visibility == "R") || ($visibility == "S")) {
465  $lay->set("disabled", $idisabled);
466  } else if ($doc->usefor != 'D') $lay->set("disabled", "disabled");
467 
468  if (!(($visibility == "R") || ($visibility == "S"))) {
469  $lay->setBlockData("VIEWCALSEL", array(
470  array(
471  "zou"
472  )
473  ));
474  }
475  if (($doc->usefor != 'D') && ($doc->usefor != 'Q')) $lay->setBlockData("CONTROLCAL", array(
476  array(
477  "zou"
478  )
479  ));
480  $input = trim($lay->gen());
481  break;
482  //----------------------------------------
483 
484 
485  case "timestamp":
486  $lay = new Layout("FDL/Layout/edittimestamp.xml", $action);
487  getLayDate($lay, $doc, $oattr, $value, $attrin, $index);
488 
489  $lay->set("readonly", false);
490  $lay->set("disabled", "");
491  if (($visibility == "R") || ($visibility == "S")) {
492  $lay->set("disabled", $idisabled);
493  $lay->set("readonly", true);
494  } else if ($doc->usefor != 'D') $lay->set("disabled", "disabled");
495 
496  $input = $lay->gen();
497  break;
498  //----------------------------------------
499 
500 
501  case "time":
502  $isDisabled = "";
503  if (($visibility == "R") || ($visibility == "S")) $isDisabled = $idisabled;
504  list($hh, $mm, $ss) = explode(":", $value);
505  $input = "<input $isDisabled size=2 maxlength=2 onchange=\"chtime('$attridk')\" type=\"text\" value=\"" . $hh . "\" id=\"hh" . $attridk . "\">:";
506 
507  $input.= "<input $isDisabled size=2 maxlength=2 onchange=\"chtime('$attridk')\" type=\"text\" value=\"" . $mm . "\"id=\"mm" . $attridk . "\">";
508 
509  $input.= "<input type=\"hidden\" onchange=\"displayTime(this)\" name=\"" . $attrin . "\" id=\"" . $attridk . "\" value=\"" . $value . "\">";
510 
511  break;
512  //----------------------------------------
513 
514  case "password":
515  // don't see the value
516  $eopt = "$classname ";
517  $esize = $oattr->getOption("esize");
518  if ($esize > 0) $eopt = "size=$esize";
519  $input = "<input $oc $eopt type=\"password\" name=\"" . $attrin . "\" value=\"" . "\"";
520  $input.= " id=\"" . $attridk . "\" ";
521 
522  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
523 
524  $input.= " > ";
525  break;
526  //----------------------------------------
527 
528  case "option":
529 
530  $lay = new Layout("FDL/Layout/editdocoption.xml", $action);
531  getLayDocOption($lay, $doc, $oattr, $value, $attrin, $index);
532  if (($visibility == "R") || ($visibility == "S")) $lay->set("disabled", $idisabled);
533  else $lay->set("disabled", "");
534  $input = $lay->gen();
535  break;
536  //----------------------------------------
537 
538  default:
539 
540  if (($oattr->repeat) && (!$oattr->inArray())) { // textlist
541  $input = "<textarea $oc $classname rows=2 name=\"" . $attrin . "\" ";
542  $input.= " id=\"" . $attridk . "\" ";
543  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
544  $input.= " >\n" . htmlentities(stripslashes(str_replace("<BR>", "\n", $value)) , ENT_COMPAT, "UTF-8") . "</textarea>";
545  } else {
546  $hvalue = str_replace(array(
547  "[",
548  "$"
549  ) , array(
550  "&#091;",
551  "&#036;"
552  ) , chop(htmlentities(stripslashes($value) , ENT_COMPAT, "UTF-8")));
553 
554  if ($oattr->eformat != "") {
555  // input help with selector
556  $lay = new Layout("FDL/Layout/edittextlist.xml", $action);
557  if (getLayTextOptions($lay, $doc, $oattr, $value, $attrin, $index)) {
558  if (($visibility == "R") || ($visibility == "S")) $lay->set("disabled", $idisabled);
559  else $lay->set("disabled", "");
560  $lay->set("adisabled", $idisabled);
561  $lay->set("oc", $jsevent);
562 
563  if ($oattr->eformat == "hlist") $lay->set("atype", "hidden");
564  else $lay->set("atype", "text");
565  $input = $lay->gen();
566  $usephpfunc = false; // disabled default input help
567 
568  } else {
569  $oattr->eformat = ""; // restore default display
570 
571  }
572  }
573  if ($oattr->eformat == "") {
574  //Common representation
575  $eopt = "$classname ";
576  $esize = $oattr->getOption("esize");
577  if ($esize > 0) $eopt = "size=$esize";
578  $elabel = $oattr->getOption("elabel");
579  if ($elabel != "") $eopt.= " title=\"$elabel\"";
580  $ecolor = $oattr->getOption("color");
581  $estyle = ""; // css style
582  if ($ecolor != "") $estyle = "color:$ecolor;";
583  $ealign = $oattr->getOption("align");
584  if ($ealign != "") $estyle.= "text-align:$ealign";
585  if ($estyle) $estyle = "style=\"$estyle\"";
586 
587  $input = "<input $oc $eopt $estyle type=\"text\" name=\"" . $attrin . "\" value=\"" . $hvalue . "\"";
588  $input.= " id=\"" . $attridk . "\" ";
589  if (($visibility == "R") || ($visibility == "S")) $input.= $idisabled;
590  $input.= " > ";
591  }
592  }
593  break;
594  }
595 
596  if (($oattr->type != "array")) {
597  if ($visibility != "S") {
598  if ($usephpfunc && ($oattr->phpfunc != "") && ($oattr->phpfile != "") && ($oattr->type != "enum") && ($oattr->type != "enumlist")) {
599  $phpfunc = $oattr->phpfunc;
600 
601  $linkprefixCT = "ilink_";
602  $phpfunc = preg_replace('/([\s|,|:])CT\[([^]]+)\]/e', "'\\1'.$linkprefixCT.strtolower('\\2')", $phpfunc);
603  // capture title
604  //if (isUTF8($oattr->getLabel())) $oattr->labelText=utf8_decode($oattr->getLabel());
605  $ititle = sprintf(_("choose inputs for %s") , ($oattr->getLabel()));
606  if ($oattr->getOption("ititle") != "") $ititle = str_replace("\"", "'", $oattr->getOption("ititle"));
607 
608  if ($phpfunc[0] == "[") {
609  if (preg_match('/\[(.*)\](.*)/', $phpfunc, $reg)) {
610  $phpfunc = $reg[2];
611  $ititle = addslashes($reg[1]);
612  }
613  }
614  if (!$notd) $input.= "</td><td class=\"editbutton\">";
615  if (preg_match("/list/", $attrtype, $reg)) $ctype = "multiple";
616  else $ctype = "single";
617 
618  if ($alone) $ctype.= "-alone";
619  /*$input.="<input id=\"ic2_$attridk\" type=\"button\" value=\"&#133;\"".
620  " title=\"".$ititle."\"".
621  " onclick=\"sendEnumChoice(event,".$docid.
622  ",this,'$attridk','$ctype','$iopt')\">";*/
623  if (preg_match('/[A-Z_\-0-9]+:[A-Z_\-0-9]+\(/i', $phpfunc)) {
624  $mheight = $oattr->getOption('mheight', 30);
625  $mwidth = $oattr->getOption('mwidth', 290);
626  $input.= "<input id=\"ic_${linkprefix}$attridk\" type=\"button\" value=\"Z\"" . " title=\"" . $ititle . "\"" . " onclick=\"sendSpecialChoice(event,'${linkprefix}${attridk}'," . $docid . ",'$attrid','$index','$mheight','$mwidth')\">";
627  } else {
628  $ib = "<input id=\"ic_${linkprefix}$attridk\" type=\"button\" value=\"&#133;\"" . " title=\"" . $ititle . "\"" . " onclick=\"sendAutoChoice(event," . $docid . ",this,'${linkprefix}${attridk}','$iopt','$attrid','$index')\">";
629  $input.= $ib;
630  }
631  // clear button
632  if (($oattr->type == "docid") && ($oattr->getOption("multiple") == "yes")) {
633  $ib = "<input id=\"ix_$attridk\" type=\"button\" value=\"&times;\"" . " title=\"" . _("clear selected inputs") . "\" disabled " . " onclick=\"clearDocIdInputs('$attridk','mdocid_isel_$attridk',this)\">";
634  //$input.="</td><td>";
635  $input.= $ib;
636  } elseif (preg_match('/(.*)\((.*)\)\:(.*)/', $phpfunc, $reg)) {
637  if ($alone && $oattr->type != "docid") {
638  $arg = array(
639  $oattr->id
640  );
641  } else {
642  $argids = explode(",", $reg[3]); // output args
643  $arg = array();
644  $outsideArg = array();
645  foreach ($argids as $k => $v) {
646  $linkprefix = "ilink_";
647  $isILink = false;
648  $attrId = $argids[$k];
649  if (substr($attrId, 0, strlen($linkprefix)) == $linkprefix) {
650  $attrId = substr($attrId, strlen($linkprefix));
651  $isILink = true;
652  }
653  $docAttr = $doc->getAttribute($attrId);
654  if (is_object($docAttr) && !$docAttr->inArray()) {
655  $targid = trim(strtolower($attrId));
656  if ($isILink) {
657  $targid = $linkprefix . $targid;
658  }
659  $outsideArg[] = $targid;
660  } else {
661  $targid = strtolower(trim($attrId));
662  if ($isILink) {
663  $targid = $linkprefix . $targid;
664  }
665  if (strlen($attrId) > 1) $arg[$targid] = $targid;
666  }
667  }
668  }
669  if (count($arg) > 0 || count($outsideArg) > 0) {
670  if (count($arg) == 0) {
671  $jarg = "'" . implode("','", $outsideArg) . "'";
672  } else {
673  $jarg = "'" . implode("','", $arg) . "'";
674  $jOutsideArg = "";
675  if (count($outsideArg) > 0) {
676  $jOutsideArg = "'" . implode("','", $outsideArg) . "'";
677  }
678  if (!empty($jOutsideArg)) {
679  $jOutsideArg = ",[$jOutsideArg]";
680  }
681  }
682 
683  $input.= "<input id=\"ix_$attridk\" type=\"button\" value=\"&times;\"" . " title=\"" . _("clear inputs") . "\"" . " onclick=\"clearInputs([$jarg],'$index','$attridk' $jOutsideArg)\">";
684  }
685  }
686  } else if (($oattr->type == "date") || ($oattr->type == "timestamp")) {
687  $input.= "<input id=\"ix_$attridk\" type=\"button\" value=\"&times;\"" . " title=\"" . _("clear inputs") . "\"" . " onclick=\"clearInputs(['$attrid'],'$index')\">";
688  if (!$notd) $input.= "</td><td class=\"nowrap\">";
689  } else if ($oattr->type == "color") {
690  $input.= "<input id=\"ix_$attridk\" type=\"button\" value=\"&times;\"" . " title=\"" . _("clear inputs") . "\"" . " onclick=\"clearInputs(['$attrid'],'$index')\">";
691  $input.= "</td><td class=\"nowrap\">";
692  } else if ($oattr->type == "time") {
693  $input.= "<input id=\"ix_$attridk\" type=\"button\" value=\"&times;\"" . " title=\"" . _("clear inputs") . "\"" . " onclick=\"clearTime('$attridk')\">";
694  if (!$notd) $input.= "</td><td class=\"nowrap\">";
695  } else if (($oattr->type == "file") || ($oattr->type == "image")) {
696  $input.= "<input id=\"ix_$attridk\" type=\"button\" style=\"vertical-align:baseline\" value=\"&times;\"" . " title=\"" . _("clear file") . "\"" . " title1=\"" . _("clear file") . "\"" . " value1=\"&times;\"" . " title2=\"" . _("restore original file") . "\"" . " value2=\"&minus;\"" . " onclick=\"clearFile(this,'$attridk')\">";
697  if (!$notd) $input.= "</td><td class=\"nowrap\">";
698  } else {
699  if (!$notd) $input.= "</td><td class=\"nowrap\">";
700  }
701  } else {
702  if (!$notd) $input.= "</td><td class=\"nowrap\">";
703  }
704 
705  $input.= addDocidCreate($oattr, $doc, $attridk, $value, $index);
706  if ($oattr->elink != "" && (!$alone)) {
707  if (substr($oattr->elink, 0, 3) == "JS:") {
708  // javascript action
709  $url = elinkEncode($doc, $attridk, substr($oattr->elink, 3) , $index, $ititle, $isymbol);
710 
711  $jsfunc = $url;
712  } else {
713  $url = elinkEncode($doc, $attridk, $oattr->elink, $index, $ititle, $isymbol);
714 
715  $target = $oattr->getOption("eltarget", $attrid);
716 
717  $jsfunc = "subwindow(300,500,'$target','$url');";
718  }
719 
720  if ($oattr->getOption("elsymbol") != "") $isymbol = $oattr->getOption("elsymbol");
721  if ($oattr->getOption("eltitle") != "") $ititle = str_replace("\"", "'", $oattr->getOption("eltitle"));
722  $input.= "<input type=\"button\" value=\"$isymbol\"" . " title=\"" . $ititle . "\"" . " onclick=\"$jsfunc;";
723 
724  $input.= "\">";
725  }
726  if (GetHttpVars("viewconstraint") == "Y") { // set in modcard
727  if (($oattr->phpconstraint != "") && ($index != "__1x_")) {
728  $res = $doc->verifyConstraint($oattr->id, ($index == "") ? -1 : $index);
729  if (($res["err"] == "") && (count($res["sug"]) == 0)) $color = 'mediumaquamarine';
730  if (($res["err"] == "") && (count($res["sug"]) > 0)) $color = 'orange';
731  if (($res["err"] != "")) $color = 'tomato';
732 
733  $input.= "<input style=\"background-color:$color;\"type=\"button\" class=\"constraint\" id=\"co_$attridk\" value=\"C\"" . " onclick=\"vconstraint(this," . $doc->fromid . ",'$attrid');\">";
734  }
735  }
736  } elseif ($oattr->type == "htmltext") {
737  if (!$notd) $input.= "</td><td class=\"nowrap\">";
738  }
739 
740  return $input;
741  }
742 
743  function elinkEncode(&$doc, $attrik, $link, $index, &$ititle = "", &$isymbol = "")
744  {
745 
746  $linkprefix = "ilink_";
747  $ititle = _("add inputs");
748  $isymbol = '+';
749 
750  $urllink = "";
751  if ($link[0] == "[") {
752  if (preg_match('/\[(.*)\|(.*)\](.*)/', $link, $reg)) {
753  $link = $reg[3];
754  $ititle = $reg[1];
755  $isymbol = $reg[2];
756  }
757  }
758 
759  for ($i = 0; $i < strlen($link); $i++) {
760  switch ($link[$i]) {
761  case '%':
762  $i++; // skip end '%'
763  $sattrid = "";
764  while (($link[$i] != "%") && ($i <= strlen($link))) {
765  $sattrid.= $link[$i];
766  $i++;
767  }
768 
769  switch ($sattrid) {
770  case "B": // baseurl
771  $urllink.= GetParam("CORE_BASEURL");
772  break;
773 
774  case "S": // standurl
775  $urllink.= GetParam("CORE_STANDURL");
776  break;
777 
778  case "K":
779  $urllink.= $index;
780  break;
781 
782  case "I":
783  $urllink.= $doc->id;
784  break;
785 
786  case "F":
787  $urllink.= $doc->fromid;
788  break;
789 
790  case "A":
791  $urllink.= $attrik;
792  break;
793 
794  case "CT":
795  $urllink.= "'+elinkvalue('${linkprefix}${attrik}')+'";
796  break;
797 
798  default:
799  $prop = $doc->getProperty($sattrid);
800  if ($prop !== false) {
801  $urllink.= $prop;
802  } else {
803  $sattrid = strtolower($sattrid);
804 
805  $attr = $doc->getAttribute($sattrid);
806  if (!$attr) {
807  global $action;
808  $action->exitError(sprintf(_("elinkEncode::attribute not found %s in %s : %s") , $sattrid, $attrik, $link));
809  }
810  if ($attr->inArray()) $sattrid.= '_' . $index;
811  //print "attr=$sattrid";
812  $urllink.= "'+elinkvalue('$sattrid')+'";
813  }
814  }
815  break;
816 
817  case "{":
818  $i++;
819 
820  $sattrid = "";
821  while ($link[$i] != '}') {
822  $sattrid.= $link[$i];
823  $i++;
824  }
825  // print "attr=$sattrid";
826  $ovalue = GetParam($sattrid, getFamIdFromName(GetParam("FREEDOM_DB") , $sattrid));
827 
828  $urllink.= $ovalue;
829 
830  break;
831 
832  default:
833  $urllink.= $link[$i];
834  }
835  }
836 
837  return ($urllink);
838  }
839 
840  function getLayArray(&$lay, &$doc, &$oattr, $row = - 1)
841  {
842  global $action;
843 
844  $attrid = $oattr->id;
845  $ta = $doc->attributes->getArrayElements($attrid);
846 
847  $height = $oattr->getOption("height", false);
848  $lay->set("tableheight", $height);
849  $tableStyle = $oattr->getOption("tstyle", '');
850  $lay->set("tableStyle", $tableStyle);
851  $lay->set("thspan", "2");
852 
853  $talabel = array();
854  $tilabel = array();
855  $tvattr = array();
856 
857  $max = - 1;
858  $max0 = - 1;
859 
860  foreach ($ta as $k => $v) { // detect uncompleted rows
861  $t = $doc->getTValue($k);
862  $c = count($t);
863  if ($c > $max) {
864  if ($max0 < 0) $max0 = $c;
865  $max = $c;
866  }
867  }
868 
869  if ($max > $max0) {
870  foreach ($ta as $k => $v) { // fill uncompleted rows
871  $t = $doc->getTValue($k);
872  $c = count($t);
873  if ($c < $max) {
874  $t = array_pad($t, $max, "");
875  $doc->setValue($k, $t);
876  }
877  }
878  }
879  // get default values
880  $ddoc = createDoc($doc->dbaccess, $doc->fromid == 0 ? $doc->id : $doc->fromid, false);
881  $ddoc->setDefaultValues($ddoc->getFamDoc()->getDefValues() , true, true);
882 
883  $tad = $ddoc->attributes->getArrayElements($attrid);
884  $tval = array();
885  $nbcolattr = 0; // number of column
886  $autoWidthAttr = false; //is there at least one attribute displayed with width auto?
887  foreach ($ta as $k => $v) {
888  if ($v->mvisibility == "R") {
889  $v->mvisibility = "H"; // don't see read attribute
890  $ta[$k]->mvisibility = "H";
891  }
892  $visible = ($v->mvisibility != "H");
893  $width = $v->getOption("cwidth", "auto");
894  $talabel[] = array(
895  "alabel" => (!$visible) ? "" : $v->getLabel() ,
896  "elabel" => $v->getOption("elabel") ,
897  "astyle" => $v->getOption("cellheadstyle") ,
898  "ahclass" => (!$visible) ? "hiddenAttribute" : "visibleAttribute"
899  );
900  $tilabel[] = array(
901  "ilabel" => getHtmlInput($doc, $v, $ddoc->getValue($tad[$k]->id) , '__1x_') ,
902  "ihw" => (!$visible) ? "0px" : $width,
903  "bgcolor" => $v->getOption("bgcolor", "inherit") ,
904  "tdstyle" => $v->getOption("cellbodystyle") ,
905  "cellatype" => $v->type,
906  "cellattrid" => $v->id,
907  "cellmultiple" => ($v->getOption("multiple") == "yes") ? "true" : "false",
908  "ihclass" => (!$visible) ? "hiddenAttribute" : "visibleAttribute"
909  );
910 
911  if ($visible) $nbcolattr++;
912  $tval[$k] = $doc->getTValue($k);
913  $nbitem = count($tval[$k]);
914 
915  if (($visible) && ($width == "auto")) {
916  $autoWidthAttr = true;
917  }
918 
919  if ($nbitem == 0) {
920  // add first range
921  if ($oattr->format != "empty" && $oattr->getOption("empty") != "yes") {
922  $tval[$k] = array(
923  0 => ""
924  );
925  $nbitem = 1;
926  }
927  }
928  //Dead code?
929  //("bvalue_" or "ivalue" could not be found in editarray.xml neither in this function.
930  // and $tivalue is redefined as empty array in code below.
931  /*
932  $tivalue=array();
933  for ($i=0;$i<$nbitem;$i++) {
934  $tivalue[]=array("ivalue"=>$tval[$k][$i]);
935  }
936  $lay->setBlockData("bvalue_$k",$tivalue);
937  */
938  }
939  //No more required (works even in IE6 which is no more supported)
940  /*
941  if ($action->read("navigator") == "EXPLORER") {
942  // compute col width explicitly
943  if ($nbcolattr> 0) {
944  $aw=sprintf("%d%%",100/$nbcolattr);
945 
946  foreach ($talabel as $ka => $va) {
947  if ($va["ahw"]=="auto") {
948  $talabel[$ka]["ahw"]=$aw;
949  $tilabel[$ka]["ihw"]=$aw;
950  }
951  }
952  }
953  }
954  */
955  $pindex = '';
956  if (($row >= 0) && ($oattr->mvisibility == "W" || $oattr->mvisibility == "O" || $oattr->mvisibility == "U")) {
957  $oattr->mvisibility = "U";
958  $pindex = 's';
959  }
960  //Compute table width with some compatibility rules
961  $tableWidth = $oattr->getOption("twidth", '100%'); //compatibility
962  //but if all columns are fixed, you probably want an 'auto' layout...
963  if ((!$autoWidthAttr) && ($tableWidth != 'auto')) {
964  //TODO: should write something in the log
965  $tableWidth = 'auto';
966  }
967  $lay->set("tableWidth", $tableWidth);
968 
969  $lay->setBlockData("TATTR", $talabel);
970  $lay->setBlockData("IATTR", $tilabel);
971  $lay->set("attrid", $attrid);
972  if ($oattr->getOption("vlabel", "up") == "up") $lay->set("caption", $oattr->getLabel());
973  else $lay->set("caption", "");
974  $lay->set("footspan", count($ta) * 2);
975 
976  reset($tval);
977  $nbitem = count(current($tval));
978 
979  $tvattr = array();
980  for ($k = 0; $k < $nbitem; $k++) {
981  if (($row >= 0) && ($k != $row)) continue;
982  $tvattr[] = array(
983  "bevalue" => "bevalue_$k",
984  "index" => $k
985  );
986  reset($ta);
987  $tivalue = array();
988  $ika = 0;
989  foreach ($ta as $ka => $va) {
990 
991  $visible = ($va->mvisibility != "H");
992 
993  $tivalue[] = array(
994  "eivalue" => getHtmlInput($doc, $va, $tval[$ka][$k], $pindex . $k) ,
995  "bgcolor" => $va->getOption("bgcolor", "inherit") ,
996  "cellatype" => $va->type,
997  "cellattrid" => $va->id,
998  "cellmultiple" => ($va->getOption("multiple") == "yes") ? "true" : "false",
999  "tdstyle" => $va->getOption("cellbodystyle") ,
1000  "vhw" => (!$visible) ? "0px" : $va->getOption("cwidth", "auto") ,
1001  "eiclass" => (!$visible) ? "hiddenAttribute" : "visibleAttribute"
1002  );
1003  $ika++;
1004  }
1005  $lay->setBlockData("bevalue_$k", $tivalue);
1006  }
1007  $lay->set("addfunc", false);
1008  if (($oattr->phpfunc != "") && ($oattr->phpfile != "")) {
1009  if (preg_match('/[A-Z_\-0-9]+:[A-Z_\-0-9]+\(/i', $oattr->phpfunc)) {
1010  $mheight = $oattr->getOption('mheight', 30);
1011  $mwidth = $oattr->getOption('mwidth', 290);
1012  $lay->set("addtitle", $oattr->getOption("ltitle", _("Modify table")));
1013  $lay->set("addsymbol", $oattr->getOption("lsymbol"));
1014  $lay->set("addfunc", "sendSpecialChoice(event,'{$oattr->id}'," . ($doc->id ? $doc->id : $doc->fromid) . ",'" . $oattr->id . "','" . $row . "','" . $mheight . "','" . $mwidth . "')");
1015  }
1016  }
1017 
1018  $lay->set("useadd", ($oattr->getOption("userowadd") != "no"));
1019  $lay->set("readonly", ($oattr->mvisibility == 'U'));
1020  if (count($tvattr) > 0) $lay->setBlockData("EATTR", $tvattr);
1021  }
1022 
1023  function getZoneLayArray(&$lay, &$doc, &$oattr, $zone)
1024  {
1025  global $action;
1026 
1027  $height = $oattr->getOption("height", false);
1028  $lay->set("tableheight", $height);
1029  $lay->set("readonly", ($oattr->mvisibility == 'U'));
1030  $lay->set("thspan", "1");
1031 
1032  if (($zone != "") && preg_match("/([A-Z_-]+):([^:]+):{0,1}[A-Z]{0,1}/", $zone, $reg)) {
1033  $attrid = $oattr->id;
1034  $ta = $doc->attributes->getArrayElements($attrid);
1035 
1036  $dxml = new DomDocument();
1037  $rowlayfile = getLayoutFile($reg[1], ($reg[2]));
1038  if (!@$dxml->load($rowlayfile)) {
1039  AddwarningMsg(sprintf(_("cannot open %s layout file") , DEFAULT_PUBDIR . "/$rowlayfile"));
1040  return;
1041  }
1042  $theads = $dxml->getElementsByTagName('table-head');
1043  if ($theads->length > 0) {
1044  $thead = $theads->item(0);
1045  $theadcells = $thead->getElementsByTagName('cell');
1046  $talabel = array();
1047  for ($i = 0; $i < $theadcells->length; $i++) {
1048  $th = xt_innerXML($theadcells->item($i));
1049  $thstyle = $theadcells->item($i)->getAttribute("style");
1050 
1051  $talabel[] = array(
1052  "alabel" => $th,
1053  "ahw" => "auto",
1054  "astyle" => $thstyle,
1055  "ahclass" => "",
1056  "ahvis" => "visible"
1057  );
1058  }
1059  $lay->setBlockData("TATTR", $talabel);
1060  }
1061 
1062  $tbodies = $dxml->getElementsByTagName('table-body');
1063  if ($tbodies->length > 0) {
1064  $tbody = $tbodies->item(0);
1065  $tbodycells = $tbody->getElementsByTagName('cell');
1066  for ($i = 0; $i < $tbodycells->length; $i++) {
1067  $tr[] = xt_innerXML($tbodycells->item($i));
1068  $tcellstyle[] = $tbodycells->item($i)->getAttribute("style");
1069  }
1070  }
1071 
1072  $nbitem = 0;
1073 
1074  foreach ($ta as $k => $v) {
1075  $tval[$k] = $doc->getTValue($k);
1076  $nbitem = max($nbitem, count($tval[$k]));
1077  $lay->set("L_" . strtoupper($v->id) , ucfirst($v->getLabel()));
1078  }
1079 
1080  $lay->set("attrid", $attrid);
1081 
1082  if ($oattr->getOption("vlabel", "up") == "up") $lay->set("caption", $oattr->getLabel());
1083  else $lay->set("caption", "");
1084  $lay->set("footspan", count($ta) * 2);
1085  $lay->set("eiclass", '');
1086  $lay->set("tableWidth", $oattr->getOption("twidth", '100%'));
1087  $lay->set("tableStyle", $oattr->getOption("tstyle", ''));
1088  // get default values
1089  $fdoc = $doc->getFamDoc();
1090  $defval = $fdoc->getDefValues();
1091 
1092  $tvattr = array();
1093  for ($k = 0; $k < $nbitem; $k++) {
1094  $tvattr[] = array(
1095  "bevalue" => "bevalue_$k"
1096  );
1097  $tivalue = array();
1098 
1099  foreach ($tr as $kd => $td) {
1100  $val = preg_replace('/\[([^\]]*)\]/e', "rowattrReplace(\$doc,'\\1',$k)", $td);
1101  $tivalue[] = array(
1102  "eivalue" => $val,
1103  "ehvis" => "visible",
1104  "tdstyle" => $tcellstyle[$kd],
1105  "bgcolor" => "inherit",
1106  "vhw" => "auto"
1107  );
1108  }
1109  $lay->setBlockData("bevalue_$k", $tivalue);
1110  }
1111 
1112  foreach ($tr as $kd => $td) {
1113  $dval = preg_replace('/\[([^\]]*)\]/e', "rowattrReplace(\$doc,'\\1','__1x_',\$defval)", $td);
1114  $tilabel[] = array(
1115  "ilabel" => $dval,
1116  "ihw" => "auto",
1117  "tdstyle" => $tcellstyle[$kd],
1118  "bgcolor" => "inherit",
1119  "ihvis" => "visible"
1120  );
1121  }
1122  $lay->set("addfunc", false);
1123  if (($oattr->phpfunc != "") && ($oattr->phpfile != "")) {
1124  if (preg_match('/[A-Z_\-0-9]+:[A-Z_\-0-9]+\(/i', $oattr->phpfunc)) {
1125  $row = '';
1126  $mheight = $oattr->getOption('mheight', 30);
1127  $mwidth = $oattr->getOption('mwidth', 290);
1128  $docid = $doc->id ? $doc->id : $doc->fromid;
1129  $lay->set("addtitle", $oattr->getOption("ltitle", _("Modify table")));
1130  $lay->set("addsymbol", $oattr->getOption("lsymbol"));
1131  $lay->set("addfunc", "sendSpecialChoice(event,'{$oattr->id}',$docid,'{$oattr->id}','$row','$mheight','$mwidth')");
1132  }
1133  }
1134  $lay->setBlockData("IATTR", $tilabel);
1135  $lay->set("readonly", ($oattr->mvisibility == 'U'));
1136  $lay->set("useadd", ($oattr->getOption("userowadd") != "no"));
1137  if (count($tvattr) > 0) $lay->setBlockData("EATTR", $tvattr);
1138  }
1139  }
1140 
1141  function rowattrReplace(&$doc, $s, $index, &$defval = null)
1142  {
1143  if (substr($s, 0, 2) == "L_") return "[$s]";
1144  if (substr($s, 0, 2) == "V_") {
1145  $s = substr($s, 2);
1146  if ($index != - 1) $value = $doc->getTValue($s, "", $index);
1147  else $value = $defval[strtolower($s) ];
1148  $oattr = $doc->getAttribute($s);
1149  if (!$oattr) return sprintf(_("unknow attribute %s") , $s);
1150  $v = getHtmlInput($doc, $oattr, $value, $index, "", true);
1151  } else {
1152  $sl = strtolower($s);
1153  if (!isset($doc->$sl)) return "[$s]";
1154  if ($index == - 1) $v = $doc->getValue($sl);
1155  else $v = $doc->getTValue($sl, "", $index);
1156  }
1157  return $v;
1158  }
1159  /**
1160  * generate HTML for inline document (not virtual)
1161  *
1162  * @param Layout $lay template of html input
1163  * @param Doc $doc current document in edition
1164  * @param DocAttribute $oattr current attribute for input
1165  * @param string $value value of the attribute to display (generaly the value comes from current document)
1166  * @param string $aname input HTML name (generaly it is '_'+$oattr->id)
1167  * @param int $index current row number if it is in array ("" if it is not in array)
1168  */
1169  function getLayAdoc(&$lay, &$doc, &$oattr, $value, $aname, $index)
1170  {
1171  $idocid = $oattr->format . $index;
1172  $lay->set("name", $aname);
1173  $lay->set("id", $oattr->id . $index);
1174  $lay->set("idocid", strtolower($idocid));
1175  $lay->set("value", $value);
1176  }
1177  /**
1178  * generate HTML for multiple docid
1179  *
1180  * @param Layout $lay template of html input
1181  * @param Doc $doc current document in edition
1182  * @param DocAttribute $oattr current attribute for input
1183  * @param string $value value of the attribute to display (generaly the value comes from current document)
1184  * @param string $aname input HTML name (generaly it is '_'+$oattr->id)
1185  * @param int $index current row number if it is in array ("" if it is not in array)
1186  */
1187  function getLayMultiDoc(&$lay, &$doc, &$oattr, $value, $aname, $index)
1188  {
1189  if ($index !== "") $idocid = $oattr->id . '_' . $index;
1190  else $idocid = $oattr->id;
1191  $needLatest = ($oattr->getOption("docrev", "latest") == "latest");
1192 
1193  $lay->set("name", $aname);
1194  $lay->set("aid", $idocid);
1195  $lay->set("value", $value);
1196  $lay->set("docid", ($doc->id == 0) ? $doc->fromid : $doc->id);
1197  $value = str_replace("\n", "<BR>", $value);
1198  $topt = array();
1199  $lay->set("size", 1);
1200  if ($value != "") {
1201  $tval = explode("<BR>", $value);
1202  foreach ($tval as $k => $v) {
1203  $topt[] = array(
1204  "ltitle" => $doc->getTitle($v, '', $needLatest) ,
1205  "ldocid" => $v
1206  );
1207  }
1208  $lay->set("size", min(count($topt) , 6));
1209  }
1210  $lay->setBlockData("options", $topt);
1211  }
1212  /**
1213  * generate HTML for date attribute
1214  *
1215  * @param Layout $lay template of html input
1216  * @param Doc $doc current document in edition
1217  * @param DocAttribute $oattr current attribute for input
1218  * @param string $value value of the attribute to display (generaly the value comes from current document)
1219  * @param string $aname input HTML name (generaly it is '_'+$oattr->id)
1220  * @param int $index current row number if it is in array ("" if it is not in array)
1221  */
1222  function getLayDate(&$lay, &$doc, &$oattr, $value, $aname, $index)
1223  {
1224  if ($index !== "") $idocid = $oattr->format . '_' . $index;
1225  else $idocid = $oattr->format;
1226  $lay->set("name", $aname);
1227 
1228  $localeconfig = getLocaleConfig();
1229  if ($localeconfig != false) {
1230  $lay->set("dateformat", $localeconfig['dateFormat']);
1231  $lay->set("datetimeformat", $localeconfig['dateTimeFormat']);
1233  } else {
1234  $lay->set("dateformat", '');
1235  $lay->set("datetimeformat", '');
1236  }
1237 
1238  if ($index !== "") $lay->set("id", $oattr->id . '_' . $index);
1239  else $lay->set("id", $oattr->id);
1240  $lay->set("idocid", strtolower($idocid));
1241  $lay->set("value", $value);
1242  }
1243  /**
1244  * generate HTML for enum attributes
1245  *
1246  * @param Layout $lay template of html input
1247  * @param Doc $doc current document in edition
1248  * @param DocAttribute $oattr current attribute for input
1249  * @param string $value value of the attribute to display (generaly the value comes from current document)
1250  * @param string $aname input HTML name (generaly it is '_'+$oattr->id)
1251  * @param int $index current row number if it is in array ("" if it is not in array)
1252  */
1253  function getLayOptions(&$lay, &$doc, &$oattr, $value, $aname, $index)
1254  {
1255  if ($index !== "") $idocid = $oattr->format . '_' . $index;
1256  else $idocid = $oattr->format;
1257  $lay->set("name", $aname);
1258  if ($index !== "") $idx = $oattr->id . '_' . $index;
1259  else $idx = $oattr->id;
1260 
1261  $lay->set("id", $idx);
1262  $lay->set("idi", $oattr->id);
1263  $etype = $oattr->getOption("etype");
1264  $eformat = $oattr->getOption("eformat");
1265  $multiple = $oattr->getOption("multiple");
1266  if (($eformat == "auto") && ($multiple != "yes")) $doc->addParamRefresh($oattr->id, "li_" . $oattr->id);
1267 
1268  $lay->set("isopen", ($etype == "open"));
1269  $lay->set("isfreeselected", false);
1270  $lay->set("isfree", ($etype == "free"));
1271  $tvalue = $doc->_val2array($value);
1272 
1273  $lay->set("lvalue", $value);
1274  $enuml = $oattr->getenumlabel();
1275 
1276  $enumk = array_keys($enuml);
1277  if (($etype == "free") && ($eformat != "auto")) {
1278  $enuml['...'] = _("Other...");
1279  }
1280 
1281  if (($eformat == "") && ($value == " ") && ($oattr->getOption("eunset") == "yes")) {
1282  $enuml[' '] = _("Do choice");
1283  }
1284 
1285  $ki = 0;
1286  $noselect = true;
1287  $topt = array();
1288 
1289  foreach ($enuml as $k => $v) {
1290  if (in_array($k, $tvalue)) {
1291  $topt[$k]["selected"] = "selected";
1292  $topt[$k]["checked"] = "checked";
1293  $lay->set("lvalue", $v);
1294  $noselect = false;
1295  } else {
1296  if ($eformat != "auto") {
1297  $topt[$k]["selected"] = "";
1298  $topt[$k]["checked"] = "nochecked";
1299  }
1300  }
1301  if (($eformat != "auto") || ($topt[$k]["selected"] == "selected")) {
1302  if ($k == "...") $topt[$k]["optid"] = $idx . '___';
1303  else $topt[$k]["optid"] = $idx . '_' . $ki;
1304  $topt[$k]["fvalue"] = $v;
1305  $topt[$k]["kvalue"] = $k;
1306  $topt[$k]["ki"] = $ki;
1307  $topt[$k]["other"] = false;
1308  }
1309  $ki++;
1310  }
1311  if (($eformat == "auto") && ($multiple == "yes")) $lay->set("isopen", false); // set by typing
1312  if ($noselect && ($etype == "free")) {
1313  if ((trim($value) != "") && ($value != "\t")) {
1314  if ($eformat != "auto") {
1315  $topt['...']["fvalue"] = "";
1316  $topt['...']["kvalue"] = "";
1317  $topt['...']["selected"] = "selected";
1318  $topt['...']["checked"] = "checked";
1319  }
1320  $lay->set("isfreeselected", true);
1321  $lay->set("lvalue", $lay->get("lvalue") . ' ' . _("(Other)"));
1322  if (!$eformat) {
1323  if ($multiple != "yes") {
1324  $topt['.sel.'] = $topt['...'];
1325  $topt['.sel.']["fvalue"] = $value . ' ' . _("(Other input)");
1326  $topt['.sel.']["kvalue"] = $value;
1327  }
1328  $topt['...']["selected"] = "";
1329  $topt['...']["checked"] = "";
1330  $lay->set("isfreeselected", false);
1331  }
1332  }
1333  // $lay->set("isfree",true);
1334 
1335  }
1336 
1337  if ($multiple && ($etype == "free")) {
1338  $lay->set("freevalue", "");
1339  if ($eformat != "auto") $topt['...']["other"] = true;
1340  foreach ($tvalue as $kv) {
1341  if (trim($kv) && (!in_array($kv, $enumk))) {
1342  if (($eformat == "auto") || ($eformat == "")) {
1343  $topt[$kv]["fvalue"] = $kv . ' ' . _("(Other)");
1344  $topt[$kv]["kvalue"] = $kv;
1345  $topt[$kv]["ki"] = $ki++;
1346  $topt[$kv]["selected"] = "selected";
1347  } else {
1348  if ($eformat) {
1349  $topt['...']["selected"] = "selected";
1350  $topt['...']["checked"] = "checked";
1351  $lay->set("isfreeselected", true);
1352  $lay->set("freevalue", $kv);
1353  }
1354  }
1355  }
1356  }
1357  }
1358  $lay->setBlockData("OPTIONS", $topt);
1359  $lay->set("value", $value);
1360  $lay->set("docid", ($doc->id == 0) ? $doc->fromid : $doc->id);
1361  $lay->set("index", $index);
1362  }
1363  /**
1364  * generate HTML for option attributes
1365  *
1366  * @param Layout $lay template of html input
1367  * @param Doc $doc current document in edition
1368  * @param DocAttribute $oattr current attribute for input
1369  * @param string $value value of the attribute to display (generaly the value comes from current document)
1370  * @param string $aname input HTML name (generaly it is '_'+$oattr->id)
1371  * @param int $index current row number if it is in array ("" if it is not in array)
1372  */
1373  function getLayDocOption(&$lay, &$doc, &$oattr, $value, $aname, $index)
1374  {
1375  if ($index !== "") $idocid = $oattr->format . '_' . $index;
1376  else $idocid = $oattr->format;
1377  $lay->set("name", $aname);
1378  $idx = $oattr->id . $index;
1379  $lay->set("id", $idx);
1380  $lay->set("didx", $index);
1381  $lay->set("di", trim(strtolower($oattr->format)));
1382  if ($index !== "") $lay->set("said", $doc->getTValue($oattr->format, "", $index));
1383  else $lay->set("said", $doc->getValue($oattr->format));
1384 
1385  $lay->set("value", $value);
1386  $lay->set("uuvalue", urlencode($value));
1387  }
1388  /**
1389  * generate HTML for text attributes with help function
1390  *
1391  * @param Layout $lay template of html input
1392  * @param Doc $doc current document in edition
1393  * @param DocAttribute $oattr current attribute for input
1394  * @param string $value value of the attribute to display (generaly the value comes from current document)
1395  * @param string $aname input HTML name (generaly it is '_'+$oattr->id)
1396  * @param int $index current row number if it is in array ("" if it is not in array)
1397  */
1398  function getLayTextOptions(&$lay, &$doc, &$oattr, $value, $aname, $index)
1399  {
1400  include_once ("FDL/enum_choice.php");
1401  if ($index !== "") $idocid = $oattr->format . '_' . $index;
1402  else $idocid = $oattr->format;
1403  $lay->set("name", $aname);
1404  $idx = $oattr->id . $index;
1405  $lay->set("id", $idx);
1406 
1407  $res = getResPhpFunc($doc, $oattr, $rargids, $tselect, $tval, false);
1408 
1409  if ($res === false) return false; // one or more attribute are not set
1410  $sattrid = "[";
1411  if (is_array($rargids)) $sattrid.= strtolower("'" . implode("','", $rargids) . "'");
1412  $sattrid.= "]";
1413  $lay->Set("attrid", $sattrid);
1414 
1415  if (is_array($tselect)) {
1416  foreach ($tselect as $k => $v) {
1417  if ($v["choice"] == $value) $tselect[$k]["selected"] = "selected";
1418  else $tselect[$k]["selected"] = "";
1419  }
1420  $lay->SetBlockData("SELECTENUM", $tselect);
1421  }
1422 
1423  $lay->SetBlockData("ATTRVAL", $tval);
1424 
1425  $lay->set("value", $value);
1426  return true;
1427  }
1428  /**
1429  * generate HTML for idoc attribute
1430  *
1431  * @param DocAttribute $oattr current attribute for input
1432  * @param string $value value of the attribute to display (generaly the value comes from current document)
1433  * @return String the formated output
1434  */
1435  function getLayIdoc(&$doc, &$oattr, $attridk, $attrin, $value, $zone = "")
1436  {
1437 
1438  $idocfamid = $oattr->format;
1439  if ($value != "") {
1440  $temp = base64_decode($value);
1441  $entete = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\" ?>";
1442  $xml = $entete;
1443  $xml.= $temp;
1444  $title = recup_argument_from_xml($xml, "title"); //in freedom_util.php
1445 
1446  } else {
1447  $famname = $doc->getTitle($idocfamid);
1448  $title = sprintf(_("create new %s") , $famname);
1449  }
1450  $input = "<INPUT id=\"_" . $attridk . "\" TYPE=\"hidden\" name=$attrin value=\"" . $value . " \"><a id='iti_$attridk' " . " oncontextmenu=\"viewidoc_in_popdoc(event,'$attridk','_$attridk','$idocfamid')\"" . " onclick=\"editidoc('_$attridk','_$attridk','$idocfamid','$zone');\">$title</a> ";
1451  return $input;
1452  }
1453  /**
1454  * add different js files needed in edition mode
1455  */
1456  function editmode(&$action)
1457  {
1458  $action->parent->AddJsRef(sprintf("%sapp=FDL&action=ALLEDITJS&wv=%s", $action->GetParam("CORE_SSTANDURL") , $action->GetParam("WVERSION")));
1459  $action->parent->AddCssRef(sprintf("%sapp=FDL&action=ALLEDITCSS&wv=%s", $action->GetParam("CORE_SSTANDURL") , $action->GetParam("WVERSION")));
1460  }
1461  /**
1462  * add button to create/modify document relation
1463  *
1464  * @param DocAttribute $oattr
1465  */
1466  function addDocIdCreate(BasicAttribute & $oattr, Doc & $doc, $attridk, $value, $index)
1467  {
1468  if ($oattr->type == "docid") {
1469  $creation = $oattr->getOption("creation");
1470  if ($creation && ($creation != "no")) {
1471 
1472  $reldoc = new_doc($doc->dbaccess, $oattr->format);
1473  if ($reldoc->control('icreate') != "") return '';
1474 
1475  $urlcreate = '';
1476  if ($creation != "yes") {
1477  $create = str_replace('"', '&quote;', $creation);
1478  $create = str_replace(array(
1479  '{',
1480  '}',
1481  ':',
1482  ','
1483  ) , array(
1484  '{"',
1485  '"}',
1486  '":"',
1487  '","'
1488  ) , $create);
1489 
1490  $jscreate = json_decode($create);
1491  if ($jscreate === null) {
1492  addWarningMsg(sprintf("creation option syntax error:%s [%s] ", $oattr->id, $creation));
1493  } else {
1494  foreach ($jscreate as $k => $v) {
1495  $kl = trim(strtolower($k));
1496  $v = str_replace('&quote;', '"', $v);
1497 
1498  if ($v[0] == '"') {
1499  $urlcreate.= sprintf("&%s=%s", $kl, urlencode(trim($v, '"')));
1500  } else {
1501  $urlcreate.= sprintf("&%s=%s", $kl, elinkencode($doc, $attridk, "%$v%", $index));
1502  }
1503  }
1504  }
1505  }
1506  $esymbol = '&nbsp;';
1507  if (!$attridk) $attridk = $oattr->id;
1508  $ectitle = sprintf(_("create a %s document") , $reldoc->getTitle());
1509 
1510  $emtitle = sprintf(_("modify document"));
1511 
1512  $jsfunc = sprintf("editRelation('%s',elinkvalue('%s'),'%s','%s')", $oattr->format, $attridk, $attridk, ($urlcreate));
1513  $input = sprintf("<input id=\"icr_%s\" class=\"%s\" type=\"button\" value=\"%s\" titleedit=\"%s\" titleview=\"%s\" onclick=\"%s\">", $attridk, "add-doc", $esymbol, $ectitle, $emtitle, $jsfunc);
1514  return $input;
1515  }
1516  }
1517  return '';
1518  }
1519 ?>
← centre documentaire © anakeen - published under CC License - Dynacase