17 include_once (
"FDL/enum_choice.php");
22 $docid = GetHttpVars(
"docid");
24 $docid = GetHttpVars(
"classid", 0);
26 $attrid = GetHttpVars(
"attrid", 0);
27 $sorm = GetHttpVars(
"sorm",
"single");
28 $index = GetHttpVars(
"index",
"");
29 $domindex = GetHttpVars(
"domindex",
"");
30 $enum = GetHttpVars(
"enum");
31 $skey = GetHttpVars(
"skey");
32 $acId = GetHttpVars(
"acid",
"");
33 $defaultphpfunc = (
getHttpVars(
"defaultphpfunc",
"no") ===
"yes");
35 header(
'Content-type: text/xml; charset=utf-8');
47 $action->lay->
Set(
"count", 0);
52 throw new Exception(sprintf(_(
"Missing or empty 'acid'.")));
54 $ac = $action->
Read(sprintf(
'autocompletion.%s', $acId));
55 if ($ac ===
'' || $ac ===
'--') {
56 throw new Exception(sprintf(_(
"Missing value for 'autocompletion.%s'.") , $acId));
58 if (!isset($ac[
'phpfile'])) {
59 throw new Exception(sprintf(_(
"Missing 'phpfile' in 'autocompletion.%s'.") , $acId));
61 if (!isset($ac[
'phpfunc'])) {
62 throw new Exception(sprintf(_(
"Missing 'phpfunc' in 'autocompletion.%s'.") , $acId));
64 $label = isset($ac[
'label']) ? $ac[
'label'] : _(
"no label");
65 $phpfile = $ac[
'phpfile'];
66 $phpfunc = $ac[
'phpfunc'];
76 $isInAbstract =
false;
83 $oattr =
new NormalAttribute($attrid,
$doc->id, $label,
"text", $format, $repeat, $order, $link, $visibility, $needed, $isInTitle, $isInAbstract, $fieldSet, $phpfile, $phpfunc, $elink, $phpconstraint, $usefor, $eformat, $options);
86 $err = $e->getMessage();
89 $oattr =
$doc->GetAttribute($attrid);
92 $err = sprintf(_(
"unknown attribute %s") , $attrid);
94 if ($defaultphpfunc) {
99 $xmlDocument =
new DOMDocument();
100 $xmlRoot = $xmlDocument->createElement(
"status");
101 $xmlDocument->appendChild($xmlRoot);
106 if (preg_match(
"/([a-z]*)-alone/", $sorm, $reg)) {
109 $action->lay->set(
"notalone", $notalone);
111 $action->parent->AddJsRef($action->GetParam(
"CORE_STANDURL") .
"app=FDL&action=ENUMCHOICEJS");
112 $phpfunc = $oattr->phpfunc;
116 if ((!empty($phpfunc)) && $phpfunc[0] ==
"[") {
117 if (preg_match(
'/\[(.*)\](.*)/', $phpfunc, $reg)) {
118 $oattr->phpfunc = $reg[2];
120 $ititle = addslashes($reg[1]);
124 $linkprefix =
"ilink_";
125 $action->lay->set(
"ititle", $ititle);
129 $oattr = clone $oattr;
131 $canitem = (!$oattr->existEnum(trim($skey)));
132 if (trim($skey) ==
'' && strpos($oattr->phpfunc,
"linkenum") !==
false) {
136 $oattr->phpfile =
"fdl.php";
137 $oattr->phpfunc = sprintf(
"fdlGetEnumValues('%s,'%s,'%s):li_%s,%s", $oattr->docid, $oattr->id, str_replace(array(
145 ) , $skey) , $oattr->id, $oattr->id);
146 } elseif ($oattr->type ==
"docid" || $oattr->type ==
"account") {
149 $multi = $oattr->getOption(
"multiple");
150 $cible = ($multi ==
"yes") ?
"mdocid_work" :
"";
151 if (!$oattr->phpfile) {
155 $docrev = $oattr->getOption(
"docrev");
156 if ($docrev ==
"fixed") {
158 } elseif ($docrev !=
"latest") {
162 if (preg_match(
"/^state\(([a-zA-Z0-9_:-]+)\)/", $docrev, $matches)) {
163 $filter[] =
"state='" . pg_escape_string($matches[1]) .
"'";
168 $oattr->phpfunc =
"lfamily(D,'$famid',${linkprefix}${aname},0,$sfilter,'$idid):${cible}${aname},${linkprefix}${aname}";
169 $oattr->phpfile =
"fdl.php";
172 $phpfunc = preg_replace(
'/([\s|,|:|\(])CT([\s|,|\)]|$)/',
'$1' . $linkprefix . $aname .
'$2', $oattr->phpfunc);
173 $phpfunc = str_replace(
"):$aname,",
"):${cible}${aname},", $phpfunc);
174 $phpfunc = str_replace(
"):" . strtoupper($aname) .
",",
"):${cible}${aname},", $phpfunc);
175 $oattr->phpfunc = $phpfunc;
178 $oattr->phpfunc = preg_replace_callback(
'/([\s|,|:|\(])CT\[([^]]+)\]/',
function ($matches) use ($linkprefix)
180 return $matches[1] . $linkprefix . strtolower($matches[2]);
186 if (!is_array($res)) {
188 $res = sprintf(_(
"error in calling function %s\n%s") , $oattr->phpfunc, $res);
193 if (count($res) == 0) {
194 $err = sprintf(_(
"no match for %s") , $oattr->getLabel());
197 $err = sprintf(_(
"existing key item %s") , $skey);
199 if ($oattr->getOption(
"etype") ==
"free" || $action->
getArgument(
"usefor") ==
"D") {
202 sprintf(_(
"free item %s") , $skey) ,
203 $skey .
' ' . _(
"(free item)") ,
208 } elseif ($oattr->getOption(
"etype") ==
"open") {
211 sprintf(_(
"new item %s") , $skey) ,
212 $skey .
' ' . _(
"(new item)") ,
218 $err = sprintf(_(
"unknow item %s") , $skey);
223 if ($enum && (trim($skey) !=
"")) {
224 foreach ($res as $kv) {
225 if (($kv[1] == trim($skey)) || ($kv[2] == trim($skey))) $canitem =
false;
228 if ($oattr->getOption(
"etype") ==
"free") {
230 sprintf(_(
"free item %s") , $skey) ,
231 $skey .
' ' . _(
"(free item)") ,
235 } elseif ($oattr->getOption(
"etype") ==
"open") {
237 sprintf(_(
"new item %s") , $skey) ,
238 $skey .
' ' . _(
"(new item)") ,
248 $xmlCibles = $xmlDocument->createElement(
"cibles");
250 foreach ($rargids as $k => $noUsed) {
251 $linkprefix =
"ilink_";
253 $attrId = $rargids[$k];
254 if (substr($attrId, 0, strlen($linkprefix)) == $linkprefix) {
255 $attrId = substr($attrId, strlen($linkprefix));
258 $docAttr =
$doc->getAttribute($attrId);
259 if (is_object($docAttr) && !$docAttr->inArray()) {
260 $targid = trim(strtolower($attrId));
262 $targid = trim(strtolower($attrId . $domindex));
265 $targid = $linkprefix . $targid;
267 $xmlCible = $xmlDocument->createElement(
"cible", $targid);
268 $xmlCibles->appendChild($xmlCible);
270 $xmlRoot->appendChild($xmlCibles);
272 foreach ($res as $k => $v) {
274 $xmlOption = $xmlDocument->createElement(
"option");
275 $xmlOption->setAttribute(
"value", $k);
278 $xmlOptionTitle = $xmlDocument->createElement(
"title");
279 $xmlOptionTitleCData = $xmlDocument->createCDATASection(
$title);
280 $xmlOptionTitle->appendChild($xmlOptionTitleCData);
282 $xmlOption->appendChild($xmlOptionTitle);
284 $xmlOptionValues = $xmlDocument->createElement(
"values");
286 $xmlOptionCurrentValue = $xmlDocument->createElement(
"val");
287 $xmlOptionCurrentValueCData = $xmlDocument->createCDATASection($value);
288 $xmlOptionCurrentValue->appendChild($xmlOptionCurrentValueCData);
289 $xmlOptionValues->appendChild($xmlOptionCurrentValue);
292 $xmlOption->appendChild($xmlOptionValues);
294 $xmlRoot->appendChild($xmlOption);
297 $xmlRoot->setAttribute(
"count", count($tselect));
303 $xmlRoot->setAttribute(
"warning",
$err);
306 $action->lay->noparse =
true;
307 $action->lay->template = $xmlDocument->saveXML();
309 $action->lay->action = null;
316 global
$_POST, $ZONE_ARGS;
318 foreach ($_POST as $k => $v) {
320 foreach ($v as $kv => $vv) $ZONE_ARGS[$k][$kv] = utf8_decode($vv);
322 $ZONE_ARGS[$k] = utf8_decode($v);
329 if ($oattr->type ==
'account') {
331 $oattr->phpfile =
'fdl.php';
332 $options = $oattr->options;
333 if ($oattr->format) {
337 $options.= sprintf(
"family=%s", $oattr->format);
339 $oattr->phpfunc = sprintf(
'fdlGetAccounts(CT,15,"%s"):%s,CT', str_replace(
'"',
'\\"', $options) , $oattr->id);
340 }
else if ($oattr->type ==
'docid') {
342 $oattr->phpfile =
'';
343 $oattr->phpfunc =
'';
getResPhpFunc(Doc &$doc, NormalAttribute &$oattr, &$rargids, &$tselect, &$tval, $whttpvars=true, $index="")
autocompletion(Action &$action)
getHttpVars($name, $def="", $scope="all")
new_Doc($dbaccess, $id= '', $latest=false)
resetAttrDefaultPhpFunc(NormalAttribute &$oattr)
static getArgument($k, $def= '')
if($file) if($subject==""&&$file) if($subject=="") $err