Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
autocompletion.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: autocompletion.php,v 1.22 2009/01/13 14:17:36 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/enum_choice.php");
20 
22 {
23  // list of choice to be insert in attribute values
24  $docid = GetHttpVars("docid"); // document being edition
25  if (!$docid) $docid = GetHttpVars("classid", 0); // in case of docid is null
26  $attrid = GetHttpVars("attrid", 0); // attribute need to enum
27  $sorm = GetHttpVars("sorm", "single"); // single or multiple
28  $index = GetHttpVars("index", ""); // index of the attributes for arrays
29  $domindex = GetHttpVars("domindex", ""); // index in dom of the attributes for arrays
30  $enum = GetHttpVars("enum"); // special case when it is an enum
31  $skey = GetHttpVars("skey"); // use only when enum (filter key)
32  header('Content-type: text/xml; charset=utf-8');
33 
34  $action->lay->setEncoding("utf-8");
35  if ($enum != "") $attrid = $enum;
36 
37  $dbaccess = $action->GetParam("FREEDOM_DB");
38  $docid = intval($docid);
40  $action->lay->Set("count", 0);
41  if ($docid == 0) {
42  // specific interface
43  $value = "";
44  $label = GetHttpVars("label", _("no label"));
45  $index = "";
46  $jsevent = "";
47  $format = "";
48  $repeat = false;
49  $order = 0;
50  $link = "";
51  $visibility = "W";
52  $needed = "N";
53  $isInTitle = false;
54  $isInAbstract = false;
55  $phpfile = GetHttpVars("phpfile");
56  $phpfunc = GetHttpVars("phpfunc");
57  $fieldSet = $doc->attr["FIELD_HIDDENS"];
58  $elink = "";
59  $phpconstraint = "";
60  $usefor = "";
61  $eformat = "";
62  $options = "";
63  $oattr = new NormalAttribute($attrid, $doc->id, $label, "text", $format, $repeat, $order, $link, $visibility, $needed, $isInTitle, $isInAbstract, $fieldSet, $phpfile, $phpfunc, $elink, $phpconstraint, $usefor, $eformat, $options);
64  } else {
65  $oattr = $doc->GetAttribute($attrid);
66  if (!$oattr) $err = sprintf(_("unknown attribute %s") , $attrid);
67  }
68  if ($err == "") {
69  $notalone = "true";
70 
71  if (preg_match("/([a-z]*)-alone/", $sorm, $reg)) {
72  $sorm = $reg[1];
73  $notalone = "false";
74  }
75  $action->lay->set("notalone", $notalone);
76 
77  $action->parent->AddJsRef($action->GetParam("CORE_STANDURL") . "app=FDL&action=ENUMCHOICEJS");
78  $phpfunc = $oattr->phpfunc;
79  // capture title
80  $ititle = "";
81 
82  if ($phpfunc[0] == "[") {
83  if (preg_match('/\[(.*)\](.*)/', $phpfunc, $reg)) {
84  $oattr->phpfunc = $reg[2];
85 
86  $ititle = addslashes($reg[1]);
87  }
88  }
89 
90  $linkprefix = "ilink_"; // in coherence with editutil.php
91  $action->lay->set("ititle", $ititle);
92  // Utf8_decode_POST(); // because default is iso8859-1
93  if ($enum != "") {
94  //if (seems_utf8($skey)) $skey=utf8_decode($skey);
95  $canitem = (!$oattr->existEnum(trim($skey)));
96  if (trim($skey) == '' && strpos($oattr->phpfunc, "linkenum") !== false) {
97  $oattr->getEnum();
98  } elseif ((strlen($oattr->phpfunc)>2) && strlen($oattr->phpfile)>2) {
99  $oattr->getEnum();
100  }
101  $eval = $oattr->phpfunc;
102 
103  $oattr->phpfile = "fdl.php";
104  $eval = str_replace(array(
105  '\,',
106  '\.'
107  ) , array(
108  '&comma;',
109  '&point;'
110  ) , $eval);
111  $oattr->phpfunc = sprintf("lenumvalues('%s,'%s):li_%s,%s", str_replace(array(
112  ',',
113  '(',
114  ')'
115  ) , array(
116  '---',
117  '&lpar;',
118  '&rpar;'
119  ) , $eval) , str_replace(array(
120  ')',
121  '(',
122  ','
123  ) , array(
124  '&rpar;',
125  '&lpar;',
126  '&comma;'
127  ) , $skey) , $oattr->id, $oattr->id);
128  } elseif ($oattr->type == "docid") {
129  $aname = $oattr->id;
130  $famid = $oattr->format;
131  $multi = $oattr->getOption("multiple");
132  $cible = ($multi == "yes") ? "mdocid_work" : "";
133  if (!$oattr->phpfile) {
134  $filter = array(); //no filter by default
135  $sfilter = '';
136  $idid = "initid"; //if there's no docrev option (or it's present but not fixed), use initid to have the latest.
137  $docrev = $oattr->getOption("docrev");
138  if ($docrev == "fixed") {
139  $idid = "id";
140  } elseif ($docrev != "latest") {
141  //if $docrev is neither fixed nor latest it should be state=...
142  //if not, we'll just ignore the option
143  $matches = array();
144  if (preg_match("/^state\(([a-zA-Z0-9_:-]+)\)/", $docrev, $matches)) {
145  $filter[] = "state='" . pg_escape_string($matches[1]) . "'";
146  }
147  }
148  //make $filter safe to pass in a string for getResPhpFunc.
149  if (count($filter) == 0) $sfilter = serialize($filter);
150  $oattr->phpfunc = "lfamily(D,$famid,${linkprefix}${aname},0,$sfilter,'$idid):${cible}${aname},${linkprefix}${aname}";
151  $oattr->phpfile = "fdl.php";
152  } else {
153  //getDeclaration(D,ACOM_ENT_ID,ILINK_ACOM_DEPOTDECL):ACOM_DEPOTDECL,ILINK_ACOM_DEPOTDECL
154  $phpfunc = preg_replace('/([\s|,|:])CT([\s|,|\)]|$)/', '$1' . $linkprefix . $aname . '$2', $oattr->phpfunc);
155  $phpfunc = str_replace("):$aname,", "):${cible}${aname},", $phpfunc);
156  $phpfunc = str_replace("):" . strtoupper($aname) . ",", "):${cible}${aname},", $phpfunc);
157  $oattr->phpfunc = $phpfunc;
158  }
159  }
160  $oattr->phpfunc = preg_replace('/([\s|,|:])CT\[([^]]+)\]/e', "'\\1'.$linkprefix.strtolower('\\2')", $oattr->phpfunc);
161 
162  $res = getResPhpFunc($doc, $oattr, $rargids, $tselect, $tval, true, $index);
163  if (!is_array($res)) {
164  if ($res == "") $res = sprintf(_("error in calling function %s\n%s") , $oattr->phpfunc, $res);
165  $err = $res;
166  }
167  if ($err == "") {
168  if (count($res) == 0) {
169  $err = sprintf(_("no match for %s") , $oattr->getLabel());
170  if ($enum) {
171  if (!$canitem) {
172  $err = sprintf(_("existing key item %s") , $skey);
173  } else {
174  if ($oattr->getOption("etype") == "open") {
175  $res = array(
176  array(
177  sprintf(_("new item %s") , $skey) ,
178  $skey . ' ' . _("(new item)") ,
179  $skey
180  )
181  );
182  $err = "";
183  } elseif ($oattr->getOption("etype") == "free") {
184  $res = array(
185  array(
186  sprintf(_("free item %s") , $skey) ,
187  $skey . ' ' . _("(free item)") ,
188  $skey
189  )
190  );
191  $err = "";
192  } else {
193  $err = sprintf(_("unknow item %s") , $skey);
194  }
195  }
196  }
197  } else {
198  if ($enum && (trim($skey) != "")) {
199  foreach ($res as $kr => $kv) { // verify existed key
200  if (($kv[1] == trim($skey)) || ($kv[2] == trim($skey))) $canitem = false;
201  }
202  if ($canitem) {
203  if ($oattr->getOption("etype") == "free") {
204  $res[] = array(
205  sprintf(_("free item %s") , $skey) ,
206  $skey . ' ' . _("(free item)") ,
207  $skey
208  );
209  $err = "";
210  } elseif ($oattr->getOption("etype") == "open") {
211  $res[] = array(
212  sprintf(_("new item %s") , $skey) ,
213  $skey . ' ' . _("(new item)") ,
214  $skey
215  );
216  $err = "";
217  }
218  }
219  }
220  }
221 
222  if ($err == "") {
223  // add index for return args only if the element is not in a array
224  while (list($k, $v) = each($rargids)) {
225  $linkprefix = "ilink_";
226  $isILink = false;
227  $attrId = $rargids[$k];
228  if (substr($attrId, 0, strlen($linkprefix)) == $linkprefix) {
229  $attrId = substr($attrId, strlen($linkprefix));
230  $isILink = true;
231  }
232  $docAttr = $doc->getAttribute($attrId);
233  if (is_object($docAttr) && !$docAttr->inArray()) {
234  $targid = trim(strtolower($attrId));
235  } else {
236  $targid = trim(strtolower($attrId . $domindex));
237  }
238  if ($isILink) {
239  $targid = $linkprefix . $targid;
240  }
241  $targids[]["attrid"] = $targid;
242  }
243 
244  $action->lay->SetBlockData("cibles", $targids);
245  $topt = array();
246  foreach ($res as $k => $v) {
247  $topt[$k]["choice"] = $v[0];
248  $topt[$k]["cindex"] = $k;
249  unset($v[0]);
250  $topt[$k]["values"] = '<val><![CDATA[' . stripslashes(implode("]]></val><val><![CDATA[", $v)) . ']]></val>';
251  }
252 
253  $action->lay->SetBlockData("SELECT", $topt);
254  $action->lay->Set("count", count($tselect));
255  }
256  }
257  }
258 
259  $action->lay->Set("autowarning", $err);
260  $action->lay->action = null; // don't want parameters - conflict with possible parameters
261 
262 }
263 
265 {
266 
267  global $_POST, $ZONE_ARGS;
268 
269  foreach ($_POST as $k => $v) {
270  if (is_array($v)) {
271  foreach ($v as $kv => $vv) $ZONE_ARGS[$k][$kv] = utf8_decode($vv);
272  } else {
273  $ZONE_ARGS[$k] = utf8_decode($v);
274  }
275  }
276 }
277 ?>
← centre documentaire © anakeen - published under CC License - Dynacase