Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
enum_choice.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  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: enum_choice.php,v 1.53 2009/01/08 17:48:27 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 
22 function enum_choice(&$action)
23 {
24  // list of choice to be insert in attribute values
25  $docid = GetHttpVars("docid"); // document being edition
26  if ($docid == "") $docid = GetHttpVars("fromid", 0); // in case of docid is null
27  $attrid = GetHttpVars("attrid", 0); // attribute need to enum
28  $sorm = GetHttpVars("sorm", "single"); // single or multiple
29  $index = GetHttpVars("index", ""); // index of the attributes for arrays
30  $domindex = GetHttpVars("domindex", ""); // index in dom of the attributes for arrays
31  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
32  $action->parent->AddJsRef("FDL/Layout/common.js");
33  $dbaccess = $action->GetParam("FREEDOM_DB");
34 
36 
37  if ($docid == 0) {
38  // specific interface
39  $value = "";
40  $label = GetHttpVars("label", _("no label"));
41  $index = "";
42  $jsevent = "";
43  $format = "";
44  $repeat = false;
45  $order = 0;
46  $link = "";
47  $visibility = "W";
48  $needed = "N";
49  $isInTitle = false;
50  $isInAbstract = false;
51  $phpfile = GetHttpVars("phpfile");
52  $phpfunc = GetHttpVars("phpfunc");
53  $fieldSet = $doc->attr["FIELD_HIDDENS"];
54  $elink = "";
55  $phpconstraint = "";
56  $usefor = "";
57  $eformat = "";
58  $options = "";
59  $oattr = new NormalAttribute($attrid, $doc->id, $label, "text", $format, $repeat, $order, $link, $visibility, $needed, $isInTitle, $isInAbstract, $fieldSet, $phpfile, $phpfunc, $elink, $phpconstraint, $usefor, $eformat, $options);
60  } else {
61  $oattr = $doc->GetAttribute($attrid);
62  if (!$oattr) $action->exitError(sprintf(_("unknown attribute %s") , $attrid));
63  }
64  $notalone = "true";
65 
66  if (preg_match("/([a-z]*)-alone/", $sorm, $reg)) {
67  $sorm = $reg[1];
68  $notalone = "false";
69  }
70  $action->lay->set("notalone", $notalone);
71 
72  $action->parent->AddJsRef($action->GetParam("CORE_STANDURL") . "app=FDL&action=ENUMCHOICEJS");
73  $phpfunc = $oattr->phpfunc;
74  // capture title
75  $ititle = "";
76 
77  if ($phpfunc[0] == "[") {
78  if (preg_match('/\[(.*)\](.*)/', $phpfunc, $reg)) {
79  $oattr->phpfunc = $reg[2];
80 
81  $ititle = addslashes($reg[1]);
82  }
83  }
84  $action->lay->set("ititle", $ititle);
85 
86  $res = getResPhpFunc($doc, $oattr, $rargids, $tselect, $tval, true, $index);
87 
88  if (!is_array($res)) {
89  if ($res == "") $res = sprintf(_("error in calling function %s") , $oattr->phpfunc);
90  $action->exitError($res);
91  }
92  if (count($res) == 0) $action->exitError(sprintf(_("no match for %s") , $oattr->getLabel()));
93 
94  if ($sorm == "single") {
95 
96  $action->lay->SetBlockData("SELECTSINGLE", array(
97  array(
98  "zou"
99  )
100  ));
101  } else {
102 
103  $action->lay->SetBlockData("SELECTMULTIPLE", array(
104  array(
105  "zou"
106  )
107  ));
108  $action->lay->Set("nselect", (count($tselect) > 7) ? 7 : count($tselect));
109  }
110  // add index for return args
111  foreach ($rargids as $k => $v) {
112  $rargids[$k] = trim($v);
113  $rargids[$k].= $domindex;
114  }
115  $sattrid = "[";
116  $sattrid.= strtolower("'" . implode("','", $rargids) . "'");
117  $sattrid.= "]";
118  $action->lay->Set("attrid", $sattrid);
119  $action->lay->SetBlockData("SELECT", $tselect);
120  $action->lay->SetBlockData("ATTRVAL", $tval);
121 }
122 
124 {
125  $sorm = GetHttpVars("sorm", "single"); // single or multiple
126  $notalone = "true";
127 
128  if (preg_match("/([a-z]*)-alone/", $sorm, $reg)) {
129  $sorm = $reg[1];
130  $notalone = "false";
131  }
132  $action->lay->set("notalone", $notalone);
133 }
134 
135 function getFuncVar($n, $def = "", $whttpvars, &$doc, &$oa)
136 {
137  if ($whttpvars) return GetHttpVars("_" . strtolower($n) , $def);
138  else {
139  $h = GetHttpVars(strtolower($n));
140  if ($h) return $h;
141  if (!$oa) return ($n);
142  if (($oa->repeat) || $oa->inArray()) $r = $doc->getTValue($n);
143  else $r = $doc->getValue($n);
144  if ($r === "") return false;
145  return $r;
146  }
147 }
148 function getResPhpFunc(&$doc, &$oattr, &$rargids, &$tselect, &$tval, $whttpvars = true, $index = "")
149 {
150  global $action;
151 
152  $phpfunc = $oattr->phpfunc;
153  $phpfunc = str_replace(array(
154  '\)',
155  '\('
156  ) , array(
157  '&rparenthesis;',
158  '&lparenthesis;'
159  ) , $phpfunc);
160  if (!preg_match("/(.*)\((.*)\)\:(.*)/", $phpfunc, $reg)) {
161  return sprintf(_("the pluggins function description '%s' is not conform for %s attribut") , $phpfunc, $oattr->id);
162  }
163  $callfunc = $reg[1];
164  if (!function_exists($callfunc)) {
165  if (!@file_exists("EXTERNALS/$oattr->phpfile")) {
166  return sprintf(_("the external pluggin file %s cannot be read") , $oattr->phpfile);
167  } else {
168  include_once ("EXTERNALS/$oattr->phpfile");
169  }
170  }
171  if (!function_exists($callfunc)) {
172  return sprintf(_("function '%s' declared in %s is not found") , $callfunc, $oattr->id);
173  }
174  $rargids = explode(",", $reg[3]); // return args
175  // change parameters familly
176  $iarg = preg_replace("/\{([^\}]+)\}/e",
177  //"/\{([a-zA-Z0-9_]+)\}/e",
178  "getAttr('\\1')", $reg[2]);
179  $argids = explode(",", $iarg); // input args
180  foreach ($argids as $k => $v) {
181  $v = str_replace(array(
182  '&rparenthesis;',
183  '&lparenthesis;'
184  ) , array(
185  ')',
186  '('
187  ) , $v);
188  if ($v != " ") $v = trim($v);
189 
190  $unser = unserialize($v);
191  if ($unser != "") $arg[$k] = $unser;
192  elseif ($v == "A") {
193  global $action;
194  $arg[$k] = & $action;
195  } else if ($v == "D") $arg[$k] = $doc->dbaccess;
196  else if ($v == "I") $arg[$k] = $doc->id;
197  else if ($v == "WIID") $arg[$k] = getHttpVars("wiid");
198  else if ($v == "K") $arg[$k] = $index;
199  else if ($v == "T") $arg[$k] = & $doc;
200  else if (($v[0] == "'") || ($v[0] == '"')) {
201  $lc = substr($v, -1);
202  if ($lc == $v[0]) $arg[$k] = mb_substr($v, 1, -1);
203  else $arg[$k] = mb_substr($v, 1);
204  } else if ($doc->getProperty($v) !== false) $arg[$k] = $doc->getProperty($v);
205  else {
206  // can be values or family parameter
207  $a = $doc->GetAttribute($v);
208  if ($index === "") {
209  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
210  if ($ta === false) return false;
211 
212  if (is_array($ta)) {
213  unset($ta["-1"]); // suppress hidden row because not set yet
214  $arg[$k] = $ta;
215  } else $arg[$k] = trim($ta);
216  } else {
217  if ($a && ($a->usefor == "Q")) {
218  if (($a->fieldSet->id == $oattr->fieldSet->id)) { // search with index
219  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
220  if ($ta === false) return false;
221  $arg[$k] = trim($ta[$index]);
222  } else {
223  $arg[$k] = $doc->getParamValue($v);
224  }
225  } else if ($a && $a->inArray()) {
226  if (($a->fieldSet->id == $oattr->fieldSet->id)) { // search with index
227  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
228  if ($ta === false) return false;
229  $arg[$k] = trim($ta[$index]);
230  } else {
231  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
232  if ($ta === false) return false;
233 
234  if (is_array($ta)) {
235  unset($ta["-1"]); // suppress hidden row because not set yet
236  $arg[$k] = $ta;
237  } else $arg[$k] = trim($ta);
238  $arg[$k] = $ta;
239  }
240  } else {
241  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
242  if ($ta === false) return false;
243  if (is_array($ta)) {
244  if ($index !== "") $arg[$k] = trim($ta[$index]);
245  else $arg[$k] = $ta;
246  } else $arg[$k] = trim($ta);
247  }
248  }
249  if ($a && ($a->usefor == "Q")) {
250  if (getFuncVar($v, false, $whttpvars, $doc, $a) === false) $arg[$k] = $doc->getParamValue($v);
251  }
252  }
253  }
254 
255  $res = call_user_func_array($callfunc, $arg);
256 
257  if (is_array($res) && (count($res) > 0)) {
258  // addslahes for JS array
259  reset($res);
260  foreach ($res as $k => $v) {
261  foreach ($v as $k2 => $v2) {
262  // not for the title
263  if ($k2 > 0) $res[$k][$k2] = addslashes(str_replace("\r", "", str_replace("\n", "\\n", $v2))); // because JS array
264  else $res[$k][$k2] = str_replace(array(
265  "<script",
266  "/script>"
267  ) , array(
268  "&lt;",
269  "&gt;"
270  ) , $res[$k][$k2]);
271  }
272  }
273  $tselect = array();
274  $tval = array();
275  reset($res);
276  $ki = 0;
277  while (list($k, $v) = each($res)) {
278  $tselect[$k]["choice"] = $v[0];
279  $tselect[$k]["cindex"] = $ki; // numeric index needed
280  $tval[$k]["index"] = $ki;
281  array_shift($v);
282 
283  $tval[$k]["attrv"] = "['" . implode("','", $v) . "']";
284  $ki++;
285  }
286  }
287 
288  return $res;
289 }
290 
291 function getAttr($aid)
292 {
293  $r = GetParam($aid);
294  if ($r == "") $r = getFamIdFromName(GetParam("FREEDOM_DB") , $aid);
295 
296  return $r;
297 }
298 ?>
← centre documentaire © anakeen - published under CC License - Dynacase