Core  3.2
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  * @package FDL
5 */
6 /**
7  * Generated Header (not documented yet)
8  *
9  * @author Anakeen
10  * @version $Id: enum_choice.php,v 1.53 2009/01/08 17:48:27 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 include_once ("FDL/Class.DocAttr.php");
19 
21 {
22  $sorm = GetHttpVars("sorm", "single"); // single or multiple
23  $notalone = "true";
24 
25  if (preg_match("/([a-z]*)-alone/", $sorm, $reg)) {
26  $sorm = $reg[1];
27  $notalone = "false";
28  }
29  $action->lay->set("notalone", $notalone);
30 }
31 /**
32  * @param string $n
33  * @param string $def
34  * @param bool $whttpvars
35  * @param Doc $doc
36  * @param NormalAttribute $oa
37  * @return array|bool|string
38  */
39 function getFuncVar($n, $def = "", $whttpvars, &$doc, &$oa)
40 {
41  if ($whttpvars) {
42  return GetHttpVars("_" . strtolower($n) , $def);
43  }
44  $h = GetHttpVars(strtolower($n));
45  if ($h) {
46  return $h;
47  }
48  if (!$oa) {
49  return ($n);
50  }
51  if (($oa->repeat) || $oa->inArray()) {
52  $r = $doc->getMultipleRawValues($n);
53  } else {
54  $r = $doc->getRawValue($n);
55  }
56  if ($r === "") {
57  return false;
58  }
59 
60  return $r;
61 }
62 function getResPhpFunc(Doc & $doc, NormalAttribute & $oattr, &$rargids, &$tselect, &$tval, $whttpvars = true, $index = "")
63 {
64  $phpfunc = $oattr->phpfunc;
65  $phpfunc = str_replace(array(
66  '\)',
67  '\('
68  ) , array(
69  '&rparenthesis;',
70  '&lparenthesis;'
71  ) , $phpfunc);
72  $oParse = new parseFamilyFunction();
73  $strucFunc = $oParse->parse($phpfunc);
74  if ($strucFunc->getError()) {
75  return $strucFunc->getError();
76  }
77 
78  if (!preg_match('/(.*)\((.*)\)\:(.*)/', $phpfunc, $reg)) {
79  return sprintf(_("the pluggins function description '%s' is not conform for %s attribut") , $phpfunc, $oattr->id);
80  }
81  $callfunc = $oParse->functionName;
82  if (!function_exists($callfunc)) {
83  if (!@file_exists("EXTERNALS/$oattr->phpfile")) {
84  return sprintf(_("the external pluggin file %s cannot be read") , $oattr->phpfile);
85  } else {
86  include_once ("EXTERNALS/$oattr->phpfile");
87  }
88  }
89  if (!function_exists($callfunc)) {
90  error_log(__METHOD__ . " $callfunc not found from " . $oattr->phpfile);
91  return sprintf(_("function '%s' declared in %s is not found") , $callfunc, $oattr->id);
92  }
93  $rargids = $oParse->outputs; // return args
94  $arg = array();
95  foreach ($strucFunc->inputs as $k => $inpArg) {
96  $v = str_replace(array(
97  '&rparenthesis;',
98  '&lparenthesis;'
99  ) , array(
100  ')',
101  '('
102  ) , $inpArg->name);
103  if ($v != " ") {
104  $v = trim($v);
105  }
106 
107  $unser = @unserialize($v); // try unserial to see if it is object
108  if ($unser != "") {
109  $arg[$k] = $unser;
110  } elseif (substr($v, 0, 1) == '{' && substr($v, -1, 1) == '}') {
111  /* Evaluate '{FAM_NAME}' or '{APP_PARAM_NAME}' notation */
112  $arg[$k] = getAttr($doc->dbaccess, substr($v, 1, -1));
113  } elseif ($inpArg->type == "string") {
114  $arg[$k] = $v;
115  } elseif ($v == "A") {
116  global $action;
117  $arg[$k] = & $action;
118  } elseif ($v == "D") {
119  $arg[$k] = $doc->dbaccess;
120  } elseif ($v == "I") {
121  $arg[$k] = $doc->id;
122  } else if ($v == "WIID") {
123  $arg[$k] = getHttpVars("wiid");
124  } elseif ($v == "K") {
125  $arg[$k] = $index;
126  } elseif ($v == "T") {
127  $arg[$k] = & $doc;
128  } elseif (($v[0] == "'") || ($v[0] == '"')) {
129  $lc = substr($v, -1);
130  if ($lc == $v[0]) {
131  $arg[$k] = mb_substr($v, 1, -1);
132  } else {
133  $arg[$k] = mb_substr($v, 1);
134  }
135  } elseif ($doc->getPropertyValue($v) !== false) {
136  $arg[$k] = $doc->getPropertyValue($v);
137  } else {
138  // can be values or family parameter
139  $a = $doc->GetAttribute($v);
140 
141  if ($index === "" || $index === null) {
142  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
143  if ($ta === false) {
144  return false;
145  }
146  if (is_array($ta)) {
147  unset($ta["__1x_"]); // suppress hidden row because not set yet
148  $arg[$k] = $ta;
149  } else {
150  $arg[$k] = trim($ta);
151  }
152  } else {
153  if ($a && ($a->usefor == "Q")) {
154  if (($a->fieldSet->id == $oattr->fieldSet->id)) { // search with index
155  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
156  if ($ta === false) {
157  return false;
158  }
159  $arg[$k] = trim($ta[$index]);
160  } else {
161  $arg[$k] = $doc->getFamilyParameterValue($v);
162  }
163  } elseif ($a && $a->inArray()) {
164  if (($a->fieldSet->id == $oattr->fieldSet->id)) { // search with index
165  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
166  if ($ta === false) {
167  return false;
168  }
169  $arg[$k] = trim($ta[$index]);
170  } else {
171  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
172  if ($ta === false) {
173  return false;
174  }
175  if (is_array($ta)) {
176  unset($ta["-1"]); // suppress hidden row because not set yet
177  $arg[$k] = $ta;
178  } else {
179  $arg[$k] = trim($ta);
180  }
181  $arg[$k] = $ta;
182  }
183  } else {
184  $ta = getFuncVar($v, $v, $whttpvars, $doc, $a);
185  if ($ta === false) {
186  return false;
187  }
188  if (is_array($ta)) {
189  if ($index !== "") {
190  $arg[$k] = trim($ta[$index]);
191  } else {
192  $arg[$k] = $ta;
193  }
194  } else {
195  $arg[$k] = trim($ta);
196  }
197  }
198  }
199  if ($a && ($a->usefor == "Q")) {
200  if (getFuncVar($v, false, $whttpvars, $doc, $a) === false) {
201  $arg[$k] = $doc->getFamilyParameterValue($v);
202  }
203  }
204  }
205  }
206  try {
207  $res = call_user_func_array($callfunc, $arg);
208  }
209  catch(Exception $e) {
210  $res = $e->getMessage();
211  }
212 
213  if (is_array($res) && (count($res) > 0)) {
214  reset($res);
215  foreach ($res as $k => $v) {
216  if (!is_array($v)) {
217  $err = ErrorCode::getError("INH0001", $callfunc, $oattr->id);
218  error_log($err);
219  return $err;
220  }
221  foreach ($v as $k2 => $v2) {
222  if (!seems_utf8($v2)) {
223  $err = ErrorCode::getError("INH0002", iconv('ISO-8859-1', "UTF-8//TRANSLIT", $v2) , $callfunc, $oattr->id);
224  error_log($err);
225  return $err;
226  }
227  // not for the title
228  if ($k2 > 0) {
229  $res[$k][$k2] = str_replace("\r", "", $v2);
230  }
231  }
232  }
233  $tselect = array();
234  $tval = array();
235  reset($res);
236  $ki = 0;
237  foreach ($res as $k => $v) {
238  $tselect[$k]["choice"] = $v[0];
239  $tselect[$k]["cindex"] = $ki; // numeric index needed
240  $tval[$k]["index"] = $ki;
241  array_shift($v);
242 
243  $tval[$k]["attrv"] = "['" . implode("','", $v) . "']";
244  $ki++;
245  }
246  }
247 
248  return $res;
249 }
250 
251 function getAttr($dbaccess, $aid)
252 {
253  $r = GetParam($aid);
254  if ($r == "") $r = getFamIdFromName($dbaccess, $aid);
255 
256  return $r;
257 }
getResPhpFunc(Doc &$doc, NormalAttribute &$oattr, &$rargids, &$tselect, &$tval, $whttpvars=true, $index="")
Definition: enum_choice.php:62
getAttr($dbaccess, $aid)
seems_utf8($Str)
Definition: Lib.Common.php:759
global $action
getPropertyValue($prop)
Definition: Class.Doc.php:2114
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
getFuncVar($n, $def="", $whttpvars, &$doc, &$oa)
Definition: enum_choice.php:39
static getError($code, $args=null)
Definition: ErrorCode.php:27
getFamilyParameterValue($idp, $def="")
Definition: Class.Doc.php:1538
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
getFamIdFromName($dbaccess, $name)
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
enumjschoice(&$action)
Definition: enum_choice.php:20
← centre documentaire © anakeen