19 include_once (
'FDL/Class.Doc.php');
20 include_once (
'FDL/Class.DocFam.php');
32 $phpAdoc =
new Layout(
"FDL/Layout/Class.Doc.xml", $action);
34 if (
$tdoc[
"classname"] ==
"") {
35 if (
$tdoc[
"fromid"] == 0)
$tdoc[
"classname"] =
"DocFile";
36 else $tdoc[
"classname"] =
"Doc" .
$tdoc[
"fromid"];
39 $phpAdoc->Set(
"docid",
$tdoc[
"id"]);
40 $phpAdoc->Set(
"include",
"");
41 $phpAdoc->Set(
"GEN",
"");
42 if (
$tdoc[
"fromid"] == 0) {
43 $phpAdoc->Set(
"DocParent",
$tdoc[
"classname"]);
44 $phpAdoc->Set(
"AParent",
"ADoc");
45 $phpAdoc->Set(
"fromid",
"");
46 $phpAdoc->Set(
"pinit",
"DocCtrl");
48 $phpAdoc->Set(
"fromid",
$tdoc[
"fromid"]);
49 if (
$tdoc[
"classname"] !=
"Doc" .
$tdoc[
"fromid"]) {
50 $phpAdoc->Set(
"DocParent",
$tdoc[
"classname"]);
51 $phpAdoc->Set(
"pinit",
$tdoc[
"classname"]);
52 $phpAdoc->Set(
"include",
"include_once(\"FDL$GEN/Class.Doc" .
$tdoc[
"fromid"] .
".php\");");
54 $phpAdoc->Set(
"GEN", $GEN);
55 $phpAdoc->Set(
"DocParent",
"Doc" .
$tdoc[
"fromid"]);
56 if (
$tdoc[
"usefor"] ==
"W") $phpAdoc->Set(
"pinit",
"WDoc");
57 else $phpAdoc->Set(
"pinit",
"DocCtrl");
59 $phpAdoc->Set(
"AParent",
"ADoc" .
$tdoc[
"fromid"]);
61 $phpAdoc->Set(
"title",
$tdoc[
"title"]);
64 $query->order_by =
"ordered";
68 $phpAdoc->Set(
"sattr",
"");
70 $phpAdoc->set(
"hasattr",
false);
83 $type = trim(strtok($v->type,
"("));
84 if (
$type ==
"docid") {
86 if (preg_match(
"/doctitle=([A-Za-z0-9_-]+)/", $v->options, $reg)) {
88 if ($doctitle ==
"auto") $doctitle = $v->id .
"_title";
89 $doctitle = strtolower($doctitle);
90 $table1[$doctitle] = clone ($v);
91 $table1[$doctitle]->id = $doctitle;
92 $table1[$doctitle]->type =
"text";
93 $table1[$doctitle]->visibility =
"H";
94 $table1[$doctitle]->phpfile =
"";
95 if (!preg_match(
"/docrev=(fixed|state)/", $v->options)) {
96 $table1[$doctitle]->phpfunc =
"::getLastTitle(" . $v->id .
",' )";
98 $table1[$doctitle]->phpfunc =
"::getTitle(" . $v->id .
",' )";
100 $table1[$doctitle]->options =
"autotitle=yes";
101 $table1[$doctitle]->title =
"N";
102 $table1[$doctitle]->abstract =
"N";
103 $table1[$doctitle]->needed =
"N";
104 $table1[$doctitle]->usefor =
"A";
106 $table1[$doctitle]->phpconstraint =
"";
107 $table1[$doctitle]->labeltext = $v->labeltext .
' ' . _(
"(title)");
108 $table1[$doctitle]->ordered = $v->ordered + 1;
113 foreach (
$table1 as $k => $v) {
116 if ($v->visibility ==
"F") $v->type =
"frame";
117 if ($v->visibility ==
"M") $v->type =
"menu";
118 if ($v->type ==
"integer") $v->type =
"int";
119 $v->phpfunc = str_replace(
"\"",
"\\\"", $v->phpfunc);
120 switch (strtolower($v->type)) {
122 if (substr($v->link, 0, 2) ==
"::") {
123 if (preg_match(
'/::([^\(]+)\(([^\)]*)\)/', $v->link, $reg)) {
134 $v->link =
"%S%app=FDL&action=FDL_METHOD&id=%I%&method=$method";
137 $tmenu[strtolower($v->id) ] = array(
138 "attrid" => strtolower($v->id) ,
139 "label" => str_replace(
"\"",
"\\\"", $v->labeltext) ,
140 "order" => intval($v->ordered) ,
141 "link" => str_replace(
"\"",
"\\\"", $v->link) ,
142 "visibility" => $v->visibility,
143 "options" => str_replace(
"\"",
"\\\"", $v->options) ,
144 "precond" => $v->phpfunc
150 $tfield[strtolower($v->id) ] = array(
151 "attrid" => strtolower($v->id) ,
152 "visibility" => $v->visibility,
153 "label" => str_replace(
"\"",
"\\\"", $v->labeltext) ,
154 "usefor" => $v->usefor,
156 "options" => str_replace(
"\"",
"\\\"", $v->options) ,
157 "frame" => ($v->frameid ==
"") ?
"FIELD_HIDDENS" : strtolower($v->frameid)
162 $taction[strtolower($v->id) ] = array(
163 "attrid" => strtolower($v->id) ,
164 "visibility" => $v->visibility,
165 "label" => str_replace(
"\"",
"\\\"", $v->labeltext) ,
166 "order" => intval($v->ordered) ,
167 "options" => str_replace(
"\"",
"\\\"", $v->options) ,
168 "wapplication" => $v->phpfile,
169 "waction" => $v->phpfunc,
170 "precond" => str_replace(
"\"",
"\\\"", $v->phpconstraint)
175 if (preg_match(
'/\[([a-z=0-9]+)\](.*)/', $v->phpfunc, $reg)) {
176 $v->phpfunc = $reg[2];
177 $funcformat = $reg[1];
182 if (preg_match(
"/([a-z]+)\([\"'](.*)[\"']\)/i", $v->type, $reg)) {
185 if ($atype ==
"idoc") {
192 if (preg_match(
"/([a-z]+)list/i", $atype, $reg)) {
196 if ($tnormal[strtolower($v->frameid) ][
"type"] ==
"array") $repeat =
"true";
197 else if (strpos($v->options,
"multiple=yes") !==
false) $repeat =
"true";
198 else if (
getTypeMain($pa[strtolower($v->frameid) ][
"type"]) ==
"array") $repeat =
"true";
199 else $repeat =
"false";
201 $atype = strtolower(trim($atype));
203 if (substr($v->phpfunc, 0, 2) ==
"::") {
204 if (preg_match(
'/::([^\(]+)\(([^\)]*)\)[:]{0,1}(.*)/', $v->phpfunc, $reg)) {
205 $iattr = explode(
",", $reg[2]);
208 foreach ($iattr as $ka => $va) {
212 if (($va[0] ==
"'") || ($va[0] ==
'"')) unset($iattr2[$ka]);
217 $phpAdoc->SetBlockData(
"biattr" . $v->id, $tiattr);
220 "callmethod" => $v->phpfunc,
221 "callattr" => $v->id,
222 "biattr" =>
"biattr" . $v->id,
223 "rarg" => ($reg[3] ==
"") ? $v->id : trim($reg[3]) ,
224 "niargs" => implode(
",", $iattr2)
229 $v->id = chop(strtolower($v->id));
231 if (!$v->phpconstraint) {
232 if (($atype ==
"integer") || ($atype ==
"int")) {
233 $v->phpconstraint = sprintf(
"::isInteger(%s)", $v->id);
234 } elseif (($atype ==
"money") || ($atype ==
"double")) {
235 $v->phpconstraint = sprintf(
"::isFloat(%s)", $v->id);
238 $tnormal[($v->id) ] = array(
239 "attrid" => ($v->id) ,
240 "label" => str_replace(
"\"",
"\\\"", $v->labeltext) ,
242 "format" => str_replace(
"\"",
"\\\"", $aformat) ,
243 "eformat" => str_replace(
"\"",
"\\\"", $funcformat) ,
244 "options" => str_replace(
"\"",
"\\\"", $v->options) ,
245 "order" => intval($v->ordered) ,
246 "link" => str_replace(
"\"",
"\\\"", $v->link) ,
247 "visibility" => $v->visibility,
248 "needed" => ($v->needed ==
"Y") ?
"true" :
"false",
249 "title" => ($v->title ==
"Y") ?
"true" :
"false",
251 "abstract" => ($v->abstract ==
"Y") ?
"true" :
"false",
252 "frame" => ($v->frameid ==
"") ?
"FIELD_HIDDENS" : strtolower($v->frameid) ,
253 "elink" => $v->elink,
254 "phpfile" => $v->phpfile,
255 "phpfunc" => str_replace(
", |",
", |", $v->phpfunc) ,
256 "phpconstraint" => str_replace(
"\"",
"\\\"", $v->phpconstraint) ,
257 "usefor" => $v->usefor
260 if (($atype !=
"array") && ($v->usefor !=
"Q")) {
261 if ($atype !=
"array") $tattr[$v->id] = array(
264 if (($repeat ==
"true") || ($tnormal[$v->frameid][
"type"] ==
"array")) {
265 $attrids[$v->id] = ($v->id) .
" text";
272 $attrids[$v->id] = ($v->id) .
" float8";
277 $attrids[$v->id] = ($v->id) .
" int4";
281 $attrids[$v->id] = ($v->id) .
" date";
285 $attrids[$v->id] = ($v->id) .
" timestamp without time zone";
289 $attrids[$v->id] = ($v->id) .
" time";
293 $attrids[$v->id] = ($v->id) .
" text";
300 $phpAdoc->Set(
"sattr", implode(
",", $attrids));
301 $phpAdoc->SetBlockData(
"MATTR", $tmenu);
302 $phpAdoc->SetBlockData(
"FATTR", $tfield);
303 $phpAdoc->SetBlockData(
"AATTR", $taction);
304 $phpAdoc->SetBlockData(
"NATTR", $tnormal);
305 $phpAdoc->SetBlockData(
"ATTRFIELD", $tattr);
307 $phpAdoc->set(
"hasattr", (count($tattr) > 0));
308 $phpAdoc->SetBlockData(
"ACALC", $tcattr);
312 if (
$tdoc[
"name"] !=
"") {
313 $phpAdoc->SetBlockData(
"CLASSALIAS", array(
318 $phpAdoc->Set(
"docName",
$tdoc[
"name"]);
319 $phpAdoc->Set(
"PHPclassName", str_replace(array(
322 ) ,
"_",
$tdoc[
"name"]));
324 $phpAdoc->Set(
"docTitle", str_replace(
'"',
'\\"',
$tdoc[
"title"]));
328 if (isset(
$tdoc[
"methods"]) && (
$tdoc[
"methods"] !=
"")) {
329 $tfmethods = explode(
"\n",
$tdoc[
"methods"]);
331 foreach ($tfmethods as $fmethods) {
332 if ($fmethods[0] ==
"*") {
333 $cmethod = substr($fmethods, 1);
334 $filename = GetParam(
"CORE_PUBDIR") .
"/FDL/" . $cmethod;
336 $contents2 = fread($fd, filesize(
$filename));
337 $contents2 = preg_replace(
'%(?: //[^\n]*\@begin-method-ignore| /\*+[^/]*?\@begin-method-ignore)(.*?)(?: //[^\n]*\@end-method-ignore[^\n]*| /\*+[^/]*?\@end-method-ignore[^/]*?\*/)%xms',
'', $contents2);
340 $filename = GetParam(
"CORE_PUBDIR") .
"/FDL/" . $fmethods;
342 $contents.= fread($fd, filesize(
$filename));
346 $contents = preg_replace(
'%(?: //[^\n]*\@begin-method-ignore| /\*+[^/]*?\@begin-method-ignore)(.*?)(?: //[^\n]*\@end-method-ignore[^\n]*| /\*+[^/]*?\@end-method-ignore[^/]*?\*/)%xms',
'', $contents);
347 $phpAdoc->Set(
"METHODS", str_replace(array(
352 }
else $phpAdoc->Set(
"METHODS",
"");
354 $phpAdoc->Set(
"DocParent1", $phpAdoc->Get(
"DocParent"));
355 if ($cmethod !=
"") {
356 $phpAdoc->Set(
"METHODS2", str_replace(array(
360 ) ,
"", $contents2));
361 $phpAdoc->SetBlockData(
"INDIRECT", array(
366 $phpAdoc->Set(
"docNameIndirect",
"Doc" .
$tdoc[
"id"] .
"__");
367 $phpAdoc->Set(
"RedirectDocParent", $phpAdoc->Get(
"DocParent"));
368 $phpAdoc->Set(
"DocParent", $phpAdoc->Get(
"docNameIndirect"));
370 return $phpAdoc->gen();
378 $err =
$doc->exec_query(
"SELECT oid FROM pg_class where relname='doc" .
$docid .
"';");
379 if (
$doc->numrows() == 0) {
380 $msg.=
"Create table doc" .
$docid .
"\n";
383 $triggers = $cdoc->sqltrigger(
false,
true);
384 $cdoc->exec_query($triggers, 1);
389 $err =
$doc->exec_query(
"SELECT oid FROM pg_class where relname='doc" .
$docid .
"';");
390 if (
$doc->numrows() == 0) {
391 $msg.=
"Cannot create Table : $err\n";
394 $row =
$doc->fetch_array(0, PGSQL_ASSOC);
395 $relid = $row[
"oid"];
397 if ($docname !=
"") {
398 $docname = strtolower($docname);
399 $err =
$doc->exec_query(sprintf(
"SELECT oid from pg_class where relname='%s' and relnamespace=(select oid from pg_namespace where nspname='family');", $docname));
401 if (
$doc->numrows() == 1) {
403 $sql = sprintf(
"drop view family.\"%s\"", $docname);
407 $err =
$doc->exec_query(sprintf(
"SELECT oid from pg_class where relname='%s' and relnamespace=(select oid from pg_namespace where nspname='family');", $docname));
408 if (
$doc->numrows() == 0) {
409 if (!$updateview) $msg.=
"Create view family." . $docname .
"\n";
411 $sql = sprintf(
"create view family.\"%s\" as select * from doc%d", ($docname) ,
$docid);
414 $err =
$doc->exec_query(sprintf(
"SELECT oid from pg_class where relname='%s' and relnamespace=(select oid from pg_namespace where nspname='family');", $docname));
415 if (
$doc->numrows() == 0) {
416 $msg.=
"Cannot create view : $err\n";
421 $sqlquery =
"select attname FROM pg_attribute where attrelid=$relid;";
422 $doc->exec_query($sqlquery, 1);
423 $nbidx =
$doc->numrows();
425 for (
$c = 0;
$c < $nbidx;
$c++) {
426 $row =
$doc->fetch_array(
$c, PGSQL_ASSOC);
427 $pgatt[$row[
"attname"]] = $row[
"attname"];
431 $classname =
"Doc" .
$docid;
432 include_once (
"FDL$GEN/Class.$classname.php");
436 $qattr->AddQuery(
"docid=" .
$docid);
437 $qattr->AddQuery(
"type != 'menu'");
438 $qattr->AddQuery(
"type != 'frame'");
439 $qattr->AddQuery(
"type != 'tab'");
440 $qattr->AddQuery(
"type != 'action'");
441 $qattr->AddQuery(
"id !~ '^:'");
443 $qattr->AddQuery(
"visibility != 'M'");
444 $qattr->AddQuery(
"visibility != 'F'");
445 $qattr->AddQuery(
"usefor != 'Q' or usefor is null");
447 $oattr = $qattr->Query();
448 if ($qattr->nb > 0) {
449 foreach ($oattr as $ka => $attr) {
450 $tattr[strtolower($attr->id) ] = $attr;
451 if ($attr->type ==
'file') {
452 $tattr[strtolower($attr->id) .
'_txt'] = $attr;
453 $tattr[strtolower($attr->id) .
'_vec'] = clone ($attr);
454 $tattr[strtolower($attr->id) .
'_vec']->type =
'tsvector';
455 }
else if (substr($attr->type, 0, 5) ==
"docid") {
456 if (preg_match(
"/doctitle=([A-Za-z0-9_-]+)/", $attr->options, $reg)) {
458 if ($doctitle ==
"auto") $doctitle = $attr->id .
"_title";
459 $doctitle = strtolower($doctitle);
460 $tattr[$doctitle] = $attr;
461 $tattr[$doctitle]->id = $doctitle;
462 $tattr[$doctitle]->type =
"text";
467 foreach ($tattr as $ka => $attr) {
468 $attr->id = chop($attr->id);
469 if (substr($attr->type, 0, 5) ==
"array")
continue;
470 if ($attr->docid ==
$docid) {
471 if (!in_array($ka, $pgatt)) {
472 $msg.=
"add field $ka in table doc" .
$docid .
"\n";
474 if (($attr->repeat) || (($tattr[$attr->frameid]->type ==
"array") && ($attr->type !=
'tsvector'))) {
479 $rtype = strtok($attr->type,
"(");
484 $sqltype =
" float8";
497 $sqltype =
" timestamp without time zone";
505 $sqltype =
" tsvector";
512 $sqlquery =
"ALTER TABLE doc" .
$docid .
" ADD COLUMN $ka $sqltype;";
513 $doc->exec_query($sqlquery, 1);
521 if (isset($ncdoc->attributes->fromids) && (in_array(2, $ncdoc->attributes->fromids)) && ($ncdoc->usefor ==
"N")) {
523 $ncdoc->usefor =
"F";
524 print
"\nchange usefor to F\n";
535 $pubdir = GetParam(
"CORE_PUBDIR");
536 $dfile =
"$pubdir/FDL$GEN/Class.Doc" .
$tdoc[
"id"] .
".php";
538 $fphp = fopen($dfile,
"w");
543 @chmod($dfile, 0666);
555 $msg = $cdoc->exec_query($cdoc->sqltrigger(
false,
true) , 1);
556 $sqlcmds = explode(
";", $cdoc->SqlTrigger());
559 foreach (
$sqlcmds as $k => $sqlquery) {
560 if ($sqlquery !=
"") $msg = $cdoc->exec_query($sqlquery, 1);
566 $indexes = $cdoc->GetSqlIndex();
567 if ($indexes) $msg = $cdoc->exec_query($indexes);
574 $query->AddQuery(
"doctype='C'");
575 $query->AddQuery(
"id=$docid");
596 $ta->id = substr(
$ta->id, 1);
598 $tfromid[] = $fromid;
600 $tfromid[] = $fromid;
602 $tfromid[] =
$ta->docid;
605 $query->AddQuery(
"id='" . pg_escape_string(
$ta->id) .
"'");
606 $query->order_by =
"docid";
607 $tas =
$query->Query(0, 0,
"TABLE");
610 error_log(
"MODATTR error for " .
$ta->id);
615 foreach ($tas as $ta1) {
616 foreach ($ta1 as $k => $v) {
617 if ($v && (!
$ta->$k)) $tw->$k = $v;
618 if (
$ta->$k ==
"-") $tw->$k =
"";
633 $query->AddQuery(
"docid=" . $fromid);
635 $pa =
$query->Query(0, 0,
"TABLE");
641 foreach ($pa as $v) $paf[$v[
"id"]] = $v;
656 if (preg_match(
'/^\s*(?P<type>[a-z]+)(?P<format>\(.+\))?\s*$/i',
$type, $m)) {
658 $m[
'format'] = substr($m[
'format'], 1, -1);
660 'type' => $m[
'type'],
661 'format' => $m[
'format']