Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
FDL_external.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  * Functions used for edition help
9  *
10  * @author Anakeen 2003
11  * @version $Id: FDL_external.php,v 1.71 2009/01/13 09:37:25 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.Dir.php");
20 include_once ("FDL/Lib.Dir.php");
21 
22 function vault_filename($th, $fileid)
23 {
24 
25  if (preg_match(PREGEXPFILE, $fileid, $reg)) {
26  // reg[1] is mime type
27  $vf = newFreeVaultFile($th->dbaccess);
28  if ($vf->Show($reg[2], $info) == "") $fname = $info->name;
29  else $fname = sprintf(_("file %d") , $th->initid);
30  } else {
31  $fname = sprintf(_("file %d") , $th->initid);
32  }
33 
34  return array(
35  $fname
36  );
37 }
38 /**
39  * Functions used for edition help
40  *
41  * @param string $dbaccess database specification
42  * @param int $docid identificator document
43  * @return array first item : the title
44  */
46 {
47 
49  if ($doc->isAffected()) return array(
50  $doc->title
51  );
52  return array(
53  "?",
54  " "
55  ); // suppress
56 
57 }
58 /**
59  * link enum definition from other def
60  */
61 function linkenum($famid, $attrid)
62 {
63 
64  $dbaccess = getParam("FREEDOM_DB");
65  if (!is_numeric($famid)) $famid = getFamIdFromName($dbaccess, $famid);
66  $soc = new_Doc($dbaccess, $famid);
67  if ($soc->isAffected()) {
68  $a = $soc->getAttribute($attrid);
69  return $a->phpfunc;
70  }
71  return "";
72 }
73 // liste de personnes
74 function lmail($dbaccess, $name)
75 {
76 
77  global $action;
78 
79  $filter = array();
80  if ($name != "") {
81  $name = pg_escape_string($name);
82  $filter[] = "(title ~* '$name') or (us_mail ~* '$name')";
83  }
84 
85  $filter[] = "us_mail is not null";
87 
88  $tinter = getChildDoc($dbaccess, 0, 0, 100, $filter, $action->user->id, "TABLE", $famid);
89 
90  $tr = array();
91 
92  while (list($k, $v) = each($tinter)) {
93 
94  $mail = getv($v, "us_mail");
95  $usw = getv($v, "us_whatid");
96  $uid = "";
97  if ($usw > 0) {
98  $uid = $v["id"];
99  $type = "link"; //$type="link"; // cause it is a bool
100 
101  } else {
102  $type = "plain"; //$type="plain";
103  $uid = " ";
104  }
105  $tr[] = array(
106  $v["title"],
107  $v["title"] . " <$mail>",
108  $uid,
109  $type
110  );
111  }
112  return $tr;
113 }
114 function tplmail($dbaccess, $type, $famid, $wfamid, $name)
115 {
116  switch ($type) {
117  case 'F': // address fix
118  return lmail($dbaccess, $name);
119  case 'A': // value of attribute
120  if (!$famid) return _("family must be defined");
121  $ta = getFamAttribute($dbaccess, $famid, 'text', false, $name);
122  return $ta;
123  case 'D': // value of attribute
124  if (!$famid) return _("family must be defined");
125  $ta = getFamAttribute($dbaccess, $famid, 'docid', false, $name);
126  return $ta;
127  case 'G': // value of attribute
128  if (!$famid) return _("family must be defined");
129  $ta = getFamAttribute($dbaccess, $famid, 'file', false, $name);
130  $ta = array_merge($ta, getFamAttribute($dbaccess, $famid, 'image', false, $name));
131  return $ta;
132  case 'E': // value of attribute
133  if (!$famid) return _("family must be defined");
134  $ta = getFamAttribute($dbaccess, $famid, '', true, $name);
135  return $ta;
136  case 'WA': // value of attribute
137  if (!$wfamid) return _("cycle family must be defined");
138  $ta = getFamAttribute($dbaccess, $wfamid, 'text', false, $name);
139  return $ta;
140  case 'WE': // value of attribute
141  if (!$wfamid) return _("cycle family must be defined");
142  $ta = getFamAttribute($dbaccess, $wfamid, '', true, $name);
143  return $ta;
144  case 'WD': // value of attribute
145  if (!$wfamid) return _("cycle family must be defined");
146  $ta = getFamAttribute($dbaccess, $wfamid, 'docid', false, $name);
147  return $ta;
148  case 'PR':
149  if (!$famid) return _("family must be defined");
150  $ta = getFamAttribute($dbaccess, $famid, 'docid', true, $name);
151  return $ta;
152  case 'WPR':
153  if (!$wfamid) return _("cycle family must be defined");
154  $ta = getFamAttribute($dbaccess, $wfamid, 'docid', true, $name);
155  return $ta;
156  case 'P':
157  return getGlobalsParameters($name);
158  }
159  return "error tplmail($dbaccess,$type,$famid, $name)";
160  }
161  function tpluser($dbaccess, $type, $famid, $wfamid, $name)
162  {
163  switch ($type) {
164  case 'F': // address fix
165  $users = lfamily($dbaccess, "IUSER", $name);
166  if (is_array($users)) {
167  foreach ($users as $k => $v) {
168  $users[$k][1] = $v[1] . ' (' . $v[2] . ')';
169  }
170  }
171  return $users;
172  default:
173  return tplmail($dbaccess, $type, $famid, $wfamid, $name);
174  }
175  }
177  {
178  include_once ("Class.QueryDb.php");
179  $q = new QueryDb("", "ParamDef");
180 
181  $tr = array();
182  $q->AddQuery("isglob = 'Y'");
183  if ($name) $q->AddQuery("name ~* '" . pg_escape_string($name) . "'");
184  $q->order_by = "name";
185  $la = $q->Query(0, 20, "TABLE");
186  foreach ($la as $k => $v) {
187  $p = $v["name"] . ' (' . $v["descr"] . ')';
188  $tr[] = array(
189  $p,
190  $p
191  );
192  }
193  return $tr;
194  }
195  /**
196  * attribut list to be use in mail template
197  */
198  function getFamAttribute($dbaccess, $famid, $type = "text", $param = false, $name = "")
199  {
200  $doc = createDoc($dbaccess, $famid, false);
201  $tr = array();
202  if ($param) {
203  $tinter = $doc->getParamAttributes();
204  } else {
205  $tinter = $doc->GetNormalAttributes();
206  }
207  $name = strtolower($name);
208  // HERE HERE HERE
209  $pattern_name = preg_quote($name);
210  $pattern_type = ($type);
211  foreach ($tinter as $k => $v) {
212  if (($name == "") || (preg_match("/$pattern_name/i", $v->getLabel() , $reg)) || (preg_match("/$pattern_name/", $v->id, $reg))) {
213  preg_match("/$pattern_type/", $v->type, $reg);
214  if (($type == "") || ($v->type == $type) || ((strpos($type, '|') > 0) && (preg_match("/$pattern_type/", $v->type, $reg)))) {
215  $r = $v->id . ' (' . $v->getLabel() . ')';
216  $tr[] = array(
217  $r,
218  $r
219  );
220  }
221  }
222  }
223  return $tr;
224  }
225  // liste des familles
226  function lfamilies($dbaccess, $name = '', $subfam = "")
227  {
228  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
229  global $action;
230 
231  if ($subfam == "") {
232  $tinter = GetClassesDoc($dbaccess, $action->user->id, 0, "TABLE");
233  } else {
234  if (!is_numeric($subfam)) {
235  $subfam = getFamIdFromName($dbaccess, $subfam);
236  }
237  $cdoc = new_Doc($dbaccess, $subfam);
238  $tinter = $cdoc->GetChildFam();
239  $tinter[] = get_object_vars($cdoc);
240  }
241 
242  $tr = array();
243 
244  $name = strtolower($name);
245  // HERE HERE HERE
246  $pattern_name = preg_quote($name);
247  while (list($k, $v) = each($tinter)) {
248  $ftitle = DocFam::getLangTitle($v);
249  if (($name == "") || (preg_match("/$pattern_name/i", $ftitle, $reg))) {
250  $tr[] = array(
251  $ftitle,
252  $v["id"],
253  $ftitle
254  );
255  }
256  }
257  return $tr;
258  }
259  // liste des documents par familles
260 
261  /**
262  * list of documents of a same family
263  *
264  * @param string $dbaccess database specification
265  * @param string $famid family identifier (if 0 any family). It can be internal name
266  * @param string $name string filter on the title
267  * @param int $dirid identifier of folder for restriction to a folder tree (deprecated)
268  * @param array $filter additionnals SQL filters
269  * @param string $idid the document id to use (default: id)
270  * @return array/string*3 array of (title, identifier, title)
271  */
272  function lfamilly($dbaccess, $famid, $name = "", $dirid = 0, $filter = array() , $idid = "id")
273  {
274  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
275  global $action;
276 
277  if (!is_array($filter)) {
278  if (trim($filter) != "") $filter = array(
279  $filter
280  );
281  else $filter = array();
282  }
283  $only = false;
284  if ($famid[0] == '-') {
285  $only = true;
286  $famid = substr($famid, 1);
287  }
288 
289  if (!is_numeric($famid)) {
291  }
292 
293  if ($name != "" && is_string($name)) {
294  $name = pg_escape_string($name);
295  $filter[] = "title ~* '$name'";
296  }
297  //$famid=-(abs($famid));
298  if ($only) $famid = - ($famid);
299  $tinter = getChildDoc($dbaccess, $dirid, 0, 100, $filter, $action->user->id, "TABLE", $famid, false, "title");
300 
301  $tr = array();
302 
303  foreach ($tinter as $k => $v) {
304  $tr[] = array(
305  $v["title"],
306  $v[$idid],
307  $v["title"]
308  );
309  }
310  return $tr;
311  }
312  // alias name
313  function lfamily($dbaccess, $famid, $name = "", $dirid = 0, $filter = array() , $idid = "id")
314  {
315  return lfamilly($dbaccess, $famid, $name, $dirid, $filter, $idid);
316  }
317  /**
318  * list of documents of a same family and their specific attributes
319  *
320  * @param string $dbaccess database specification
321  * @param string $famid family identifier (if 0 any family). It can be internal name
322  * @param string $name string filter on the title
323  * @param string $attrids argument variable of name of attribute to be returned
324  * @return array/string*3 array of (title, identifier, attr1, attr2, ...)
325  */
327  {
328  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
329  global $action;
330 
331  $only = false;
332  if ($famid[0] == '-') {
333  $only = true;
334  $famid = substr($famid, 1);
335  }
336 
337  if (!is_numeric($famid)) {
339  }
340 
341  if ($name != "") {
342  $name = pg_escape_string($name);
343  $filter[] = "title ~* '$name'";
344  }
345  $attr = array();
346  $args = func_get_args();
347  foreach ($args as $k => $v) {
348  if ($k > 2) $attr[] = strtolower($v);
349  }
350  //$famid=-(abs($famid));
351  if ($only) $famid = - ($famid);
352  $tinter = getChildDoc($dbaccess, $dirid, 0, 100, $filter, $action->user->id, "TABLE", $famid, false, "title");
353 
354  $tr = array();
355 
356  foreach ($tinter as $k => $v) {
357  $tr[$k] = array(
358  $v["title"]
359  );
360  foreach ($attr as $a) {
361  $tr[$k][] = $v[$a];
362  }
363  }
364  return $tr;
365  }
366  /**
367  * list of documents of a same family and which are in the $kid category
368  *
369  * @param string $dbaccess database specification
370  * @param string $famname family internal name
371  * @param string $aid enum attribute identifier
372  * @param string $kid enum key to search
373  * @param string $name string filter on the title
374  * @param array $filter additionnals SQL filters
375  * @return array/string*3 array of (title, identifier, title)
376  */
377  function lkfamily($dbaccess, $famname, $aid, $kid, $name, $filter = array())
378  {
379  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
380  global $action;
381 
382  if ($name != "") {
383  $name = pg_escape_string($name);
384  $filter[] = "title ~* '.*$name.*'";
385  }
386 
387  $tinter = getKindDoc($dbaccess, $famname, $aid, $kid, $name, $filter);
388 
389  $tr = array();
390 
391  while (list($k, $v) = each($tinter)) {
392 
393  $tr[] = array(
394  $v["title"],
395  $v["id"],
396  $v["title"]
397  );
398  }
399  return $tr;
400  }
401  /**
402  * return list of string for multiple static choice
403  *
404  * @param string $val filter value - can be empty => see all choices
405  * @param string $enum possible choices like 'the first|the second|the last'
406  * @return array/string*2 array of (enum, enum)
407  */
408  function lenum($val, $enum)
409  {
410  // $enum like 'a|b|c'
411  $tenum = explode("|", $enum);
412 
413  $tr = array();
414  // HERE HERE HERE
415  $pattern_val = preg_quote($val);
416  while (list($k, $v) = each($tenum)) {
417 
418  if (($val == "") || (preg_match("/$pattern_val/i", $v, $reg))) $tr[] = array(
419  $v,
420  $v
421  );
422  }
423  return $tr;
424  }
425  /**
426  * return list of string for multiple static choice
427  *
428  * @param string $val filter value - can be empty => see all choices
429  * @param string $enum possible choices like 'the first|the second|the last'
430  * @return array/string*2 array of (enum, enum)
431  */
432  function lenumvalues($enum, $val = "")
433  {
434  // $enum like 'a|A,b|B'
435  $val = trim($val);
436  $val = str_replace(array(
437  '&comma;',
438  '&point;'
439  ) , array(
440  ',',
441  '.'
442  ) , $val);
443  $val = str_replace(array(
444  '&lpar;',
445  '&rpar;',
446  ) , array(
447  '(',
448  ')'
449  ) , $val);
450  $enum = str_replace(array(
451  '&lpar;',
452  '&rpar;',
453  ) , array(
454  '(',
455  ')'
456  ) , $enum);
457  $tenum = explode("---", $enum);
458 
459  $tr = array();
460 
461  foreach ($tenum as $k => $v) {
462  list($key, $label) = explode("|", $v);
463  $slabel = str_replace(array(
464  '&comma;',
465  '&point;'
466  ) , array(
467  ',',
468  '.'
469  ) , $label);
470  if (($val == "") || (preg_match("!" . preg_quote($val) . "!i", $slabel, $reg))) $tr[] = array(
471  "$slabel",
472  $slabel,
473  $key
474  );
475  }
476 
477  return $tr;
478  }
479  // liste des profils
480  function lprofil($dbaccess, $name, $famid = 0)
481  {
482  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
483  global $action;
484  $dirid = 0;
485  if ($famid > 0) {
487  if ($fdoc->defDoctype == 'D') return lfamily($dbaccess, 4, $name);
488  else if ($fdoc->defDoctype == 'S') return lfamily($dbaccess, 6, $name);
489  else return lfamily($dbaccess, 3, $name, 0, array(
490  "fromid=3"
491  ));
492  }
493 
494  return lfamily($dbaccess, 3, $name, $dirid);
495  }
496  // liste des masque
497  function lmask($dbaccess, $name, $maskfamid = "")
498  {
499 
500  $filter = array();
501  if ($maskfamid > 0) {
502  $mdoc = new_Doc($dbaccess, $maskfamid);
503  $chdoc = $mdoc->GetFromDoc();
504  $filter[] = GetSqlCond($chdoc, "msk_famid");
505  // $filter[]="msk_famid='$maskfamid'"; // when workflow will have attribut to say the compatible families
506 
507  }
508  return lfamilly($dbaccess, "MASK", $name, 0, $filter);
509  }
510  // view control list
511  function lcvdoc($dbaccess, $name, $cvfamid = "")
512  {
513  $filter = array();
514  if ($cvfamid > 0) {
515  $mdoc = new_Doc($dbaccess, $cvfamid);
516  $chdoc = $mdoc->GetFromDoc();
517  $filter[] = GetSqlCond($chdoc, "cv_famid");
518  }
519  return lfamily($dbaccess, "CVDOC", $name, 0, $filter);
520  }
521  // mail template list
522  function lmailtemplatedoc($dbaccess, $name, $cvfamid = "")
523  {
524  $filter = array();
525  if ($cvfamid > 0) {
526  $mdoc = new_Doc($dbaccess, $cvfamid);
527  $chdoc = $mdoc->GetFromDoc();
528  $filter[] = "tmail_family is null or (" . GetSqlCond($chdoc, "tmail_family") . ')';
529  }
530  return lfamily($dbaccess, "MAILTEMPLATE", $name, 0, $filter);
531  }
532  // timer list
533  function ltimerdoc($dbaccess, $name, $cvfamid = "")
534  {
535  $filter = array();
536  if ($cvfamid > 0) {
537  $mdoc = new_Doc($dbaccess, $cvfamid);
538  $chdoc = $mdoc->GetFromDoc();
539  $filter[] = "tm_family is null or (" . GetSqlCond($chdoc, "tm_family") . ')';
540  }
541  return lfamily($dbaccess, "TIMER", $name, 0, $filter);
542  }
543  /**
544  * search list not filters
545  */
547  {
548 
549  $filter = array(
550  "fromid=5 or fromid=16"
551  );
552  return lfamilly($dbaccess, "SEARCH", $name, 0, $filter);
553  }
554  /**
555  * tab list not filters
556  */
557  function ltabs($dbaccess, $name)
558  {
559 
560  $filter = array(
561  "fromid=5 or fromid=16"
562  );
563  $ls = lfamily($dbaccess, "SEARCH", $name, 0, $filter);
564 
565  $fld = lfamily($dbaccess, "2", $name);
566 
567  $all = array_merge($ls, $fld);
568  return $all;
569  }
570  // liste des zones possibles
571  // $tview VCONS|VEDIT
572  function lzone_($dbaccess, $tview, $famid = "")
573  {
574  $tz = array();
575 
576  $filter = array();
577  if ($famid > 0) {
579  $cdoc = createDoc($dbaccess, $famid, false);
580  if ($tview == "VEDIT") $tz = $cdoc->eviews;
581  else $tz = $cdoc->cviews;
582  $oz = lzone_($dbaccess, $tview, $fdoc->fromid);
583  $tz = array_merge($oz, $tz);
584  } else {
586  if ($tview == "VEDIT") $tz = $fdoc->eviews;
587  else $tz = $fdoc->cviews;
588  }
589 
590  return $tz;
591  }
592 
593  function lzone($dbaccess, $tview, $famid = "")
594  {
595  $tz = lzone_($dbaccess, $tview, $famid);
596  $tz = array_unique($tz);
597  foreach ($tz as $v) {
598  $tr[] = array(
599  $v,
600  $v
601  );
602  }
603 
604  return $tr;
605  }
606 
607  function lview($tidview, $tlview)
608  {
609 
610  foreach ($tidview as $k => $v) {
611  $tr[] = array(
612  $tlview[$k],
613  trim($v) ,
614  $tlview[$k]
615  );
616  }
617 
618  return $tr;
619  }
620  // liste des attributs d'une famille
621  function getDocAttr($dbaccess, $famid, $name = "")
622  {
623  return getSortAttr($dbaccess, $famid, $name, false);
624  }
625  // liste des attributs triable d'une famille
626  function getSortAttr($dbaccess, $famid, $name = "", $sort = true)
627  {
628  //'lsociety(D,US_SOCIETY):US_IDSOCIETY,US_SOCIETY,
629  $doc = createDoc($dbaccess, $famid, false);
630  // internal attributes
631  $ti = array(
632  "title" => _("doctitle") ,
633  "revdate" => _("revdate") ,
634  "revision" => _("revision") ,
635  "owner" => _("owner") ,
636  "state" => _("state")
637  );
638 
639  $tr = array();
640  $pattern_name = preg_quote($name);
641  foreach ($ti as $k => $v) {
642  if (($name == "") || (preg_match("/$pattern_name/i", $v, $reg))) {
643 
644  $tr[] = array(
645  $v,
646  $k,
647  $v
648  );
649  }
650  }
651 
652  if ($sort) {
653  $tinter = $doc->GetSortAttributes();
654  } else {
655  $tinter = $doc->GetNormalAttributes();
656  }
657 
658  foreach ($tinter as $k => $v) {
659  if (($name == "") || (preg_match("/$pattern_name/i", $v->getLabel() , $reg))) {
660  $dv = '<b><i>' . _getParentLabel($v) . '</i></b><br/><span>&nbsp;&nbsp;' . $v->getLabel() . '</span>';
661  $tr[] = array(
662  $dv,
663  $v->id,
664  $v->getLabel()
665  );
666  }
667  }
668  return $tr;
669  }
670  function _getParentLabel($oa)
671  {
672  if ($oa && $oa->fieldSet && $oa->fieldSet->id != 'FIELD_HIDDENS') {
673  return _getParentLabel($oa->fieldSet) . $oa->fieldSet->getLabel() . '/';
674  }
675  return '';
676  }
677 
679  {
680  $filter = array();
681  $filter[] = "act_type='$type'";
682  return lfamilly($dbaccess, $famid, $name, 0, $filter);
683  }
684  /**
685  * return list of what application
686  */
687  function lapplications($n = "")
688  {
689  $q = new QueryDb("", "Application");
690 
691  $tr = array();
692  if ($n != "") $q->AddQuery("name ~* '$n'");
693  $la = $q->Query(0, 0, "TABLE");
694  if (is_array($la)) {
695  foreach ($la as $k => $v) {
696  $tr[] = array(
697  $v["name"] . ":" . $v["short_name"],
698  $v["name"]
699  );
700  }
701  }
702  return $tr;
703  }
704  /**
705  * return list of what action for one application
706  */
707  function lactions($app, $n = "")
708  {
709  $tr = array();
710  $q = new QueryDb("", "Application");
711  $q->AddQuery("name = '$app'");
712  $la = $q->Query(0, 0, "TABLE");
713  if ($q->nb == 1) {
714  $appid = $la[0]["id"];
715  if ($appid > 0) {
716  $q = new QueryDb("", "Action");
717  $q->AddQuery("id_application = $appid");
718  if ($n != "") $q->AddQuery("name ~* '$n'");
719  $la = $q->Query(0, 0, "TABLE");
720 
721  if ($q->nb > 0) {
722  foreach ($la as $k => $v) {
723  $tr[] = array(
724  $v["name"] . ":" . _($v["short_name"]) ,
725  $v["name"]
726  );
727  }
728  }
729  }
730  }
731  return $tr;
732  }
733 
734  function lapi($name = "")
735  {
736  $cmd = sprintf("cd %s/API;ls -1 *.php| cut -f1 -d'.'", escapeshellarg(DEFAULT_PUBDIR));
737  $apis = shell_exec($cmd);
738  $tapi = explode("\n", $apis);
739 
740  $tr = array();
741  // HERE HERE HERE
742  $pattern_name = preg_quote($name);
743  foreach ($tapi as $k => $v) {
744  $v0 = trim($v);
745  if (($name == "") || (preg_match("/$pattern_name/i", $v0, $reg))) $tr[] = array(
746  $v0,
747  $v0
748  );
749  }
750  return ($tr);
751  }
752 
753  function lstates($dbaccess, $wid, $name = "")
754  {
755  $doc = createDoc($dbaccess, $wid, false);
756  if ($doc && method_exists($doc, "getStates")) {
757  $states = $doc->getStates();
758  // HERE HERE HERE
759  $pattern_name = preg_quote($name);
760  foreach ($states as $k => $v) {
761  if (($name == "") || (preg_match("/$pattern_name/i", $v, $reg))) $tr[] = array(
762  $v . ' (' . _($v) . ')',
763  $v
764  );
765  }
766  } else return sprintf(_("need to select workflow"));
767 
768  return $tr;
769  }
770  function ldocstates($dbaccess, $docid, $name = "")
771  {
772  $doc = new_doc($dbaccess, $docid);
773  $tr = array();
774  if ($doc->isAlive() && $doc->wid) {
775  $wdoc = new_doc($dbaccess, $doc->wid, false);
776  if ($wdoc && method_exists($wdoc, "getStates")) {
777  $states = $wdoc->getStates();
778  // HERE HERE HERE
779  $pattern_name = preg_quote($name);
780  foreach ($states as $k => $v) {
781  if (($name == "") || (preg_match("/$pattern_name/i", $v, $reg))) $tr[] = array(
782  $v . ' (' . _($v) . ')',
783  $v . ' (' . _($v) . ')'
784  );
785  }
786  } else return sprintf(_("no workflow for this document"));
787  } else return sprintf(_("no workflow for this document"));
788  return $tr;
789  }
790  function lmethods($dbaccess, $famid, $name = "")
791  {
792  $doc = createDoc($dbaccess, $famid, false);
793  if ($doc) {
794  $methods = get_class_methods($doc);
795  $pattern_name = preg_quote($name);
796  foreach ($methods as $k => $v) {
797  if (($name == "") || (preg_match("/$pattern_name/i", $v, $reg))) $tr[] = array(
798  $v,
799  '::' . $v . '()'
800  );
801  }
802  } else return sprintf(_("need to select family"));
803 
804  return $tr;
805  }
806  /**
807  * retrieve information from postgresql database
808  * @param string $dbaccess the database coordonates
809  * @param string $table the name of sql table where search data
810  * @param string $filter the sql where clause to filter
811  * @param string $more dynamic others arg to define column to retrieve
812  */
814  {
815  $conn = pg_connect($dbaccess);
816  if (!$conn) {
817  return sprintf(_("connexion to %s has failed") , $dbaccess);
818  }
819 
820  $args = func_get_args();
821  $cols = array();
822  $order = '';
823  $tdn = array(); // display name
824  foreach ($args as $k => $v) {
825  if ($k > 2) {
826  if (substr($v, -2) == ":H") {
827  $v = substr($v, 0, -2);
828  } else {
829  if (!$order) $order = strtolower($v);
830  $tdn[] = $k - 3;
831  }
832  $cols[] = (strtolower($v));
833  }
834  }
835  if (count($cols) == 0) {
836  return sprintf(_("no columns specified"));
837  }
838  if (count($tdn) == 0) {
839  return sprintf(_("all columns are hiddens"));
840  }
841 
842  $select = "select " . implode(",", $cols);
843  $from = "from " . pg_escape_string($table);
844  $orderby = "order by " . ($order);
845  foreach ($_POST as $k => $v) {
846  if ($k[0] == '_') {
847  $filter = preg_replace('/' . substr($k, 1) . '/i', pg_escape_string(trim(stripslashes($v))) , $filter);
848  }
849  }
850 
851  $where = "where $filter";
852  $limit = "limit 100";
853  $sql = $select . ' ' . $from . ' ' . $where . ' ' . $orderby . ' ' . $limit;
854  $result = @pg_query($conn, $sql);
855  if (!$result) {
856  return sprintf(_("query %s has failed") , $sql);
857  }
858 
859  $kr = 0;
860  $t = array();
861  while ($row = pg_fetch_row($result)) {
862  $dn = '';
863  foreach ($tdn as $vi) $dn.= $row[$vi] . ' ';
864  $t[$kr][] = $dn;
865  foreach ($row as $ki => $vi) $t[$kr][] = $vi;
866  $kr++;
867  }
868 
869  return $t;
870  }
871 ?>
← centre documentaire © anakeen - published under CC License - Dynacase