Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocFam.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  * Family Document Class
9  *
10  * @author Anakeen 2000
11  * @version $Id: Class.DocFam.php,v 1.31 2008/09/16 16:09:59 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 include_once ('FDL/Class.PFam.php');
18 
19 class DocFam extends PFam
20 {
21 
22  var $dbtable = "docfam";
23 
24  var $sqlcreate = "
25 create table docfam (cprofid int ,
26  dfldid int,
27  cfldid int,
28  ccvid int,
29  ddocid int,
30  methods text,
31  defval text,
32  schar char,
33  param text,
34  genversion float,
35  maxrev int,
36  usedocread int) inherits (doc);
37 create unique index idx_idfam on docfam(id);";
38 
39  var $defDoctype = 'C';
40 
41  var $defaultview = "FDL:VIEWFAMCARD";
42 
43  var $attr;
44  public $specialmenu = "FDL:POPUPFAMDETAIL";
45  public $addfields = array(
46  "dfldid",
47  "cfldid",
48  "ccvid",
49  "cprofid",
50  "ddocid",
51  "methods",
52  "defval",
53  "param",
54  "genversion",
55  "usedocread",
56  "schar",
57  "maxrev"
58  );
59 
60  function __construct($dbaccess = '', $id = '', $res = '', $dbid = 0, $include = true)
61  {
62 
63  foreach ($this->addfields as $f) $this->fields[$f] = $f;
64  // specials characteristics R : revised on each modification
65  parent::__construct($dbaccess, $id, $res, $dbid);
66 
67  $this->doctype = 'C';
68  if ($include && ($this->id > 0) && ($this->isAffected())) {
69  $adoc = "Doc" . $this->id;
70  $GEN = getGen($dbaccess);
71  include_once ("FDL$GEN/Class.$adoc.php");
72  $adoc = "ADoc" . $this->id;
73  $this->attributes = new $adoc();
74  uasort($this->attributes->attr, "tordered");
75  }
76  }
77  function preDocDelete()
78  {
79  return _("cannot delete family");
80  }
81  /**
82  * return i18n title for family
83  * based on name
84  * @return string
85  */
86  function getSpecTitle()
87  {
88  $r = $this->name . '#title';
89  $i = _($r);
90  if ($i != $r) return $i;
91  return $this->title;
92  }
93 
94  static function getLangTitle($values)
95  {
96  $r = $values["name"] . '#title';
97  $i = _($r);
98  if ($i != $r) return $i;
99  return $values["title"];
100  }
101  function PostModify()
102  {
103  include_once ("FDL/Lib.Attr.php");
104  return refreshPhpPgDoc($this->dbaccess, $this->id);
105  }
106  function preCreated()
107  {
108  $cdoc = $this->getFamDoc();
109  if ($cdoc->isAlive()) {
110  if (!$this->ccvid) $this->ccvid = $cdoc->ccvid;
111  if (!$this->cprofid) $this->cprofid = $cdoc->cprofid;
112  if (!$this->defval) $this->defval = $cdoc->defval;
113  if (!$this->schar) $this->schar = $cdoc->schar;
114  }
115  }
116  /**
117  * update attributes of workflow if needed
118  */
119  function postImport()
120  {
121  if ($this->usefor == 'W') {
122  $w = createDoc($this->dbaccess, $this->id);
123  if ($w) {
124  if (method_exists($w, "createProfileAttribute")) {
125  $w->createProfileAttribute();
126  }
127  }
128  }
129  }
130  // -----------------------------------
131  function viewfamcard($target = "_self", $ulink = true, $abstract = false)
132  {
133  // -----------------------------------
134  global $action;
135 
136  $this->lay->set("modifyacl", ($this->control("modifyacl") == ""));
137  $this->lay->set("canInitProfil", $action->HasPermission("FREEDOM_ADMIN", "FREEDOM"));
138 
139  foreach ($this->fields as $k => $v) {
140 
141  $this->lay->set("$v", $this->$v ? $this->$v : false);
142  switch ($v) {
143  case cprofid:
144  if ($this->$v > 0) {
145  $tdoc = new_Doc($this->dbaccess, $this->$v);
146 
147  $this->lay->set("cmodifyacl", ($tdoc->control("modifyacl") == ""));
148 
149  $this->lay->set("cproftitle", $tdoc->title);
150  $this->lay->set("cprofdisplay", "");
151  $hascontrol = ($this->controlUserId($this->$v, $this->userid, "modifyacl") == "");
152  $this->lay->set("ca_" . $v, $hascontrol);
153  } else {
154  $this->lay->set("cprofdisplay", "none");
155  }
156  break;
157 
158  case cfldid:
159  if ($this->$v > 0) {
160  $tdoc = new_Doc($this->dbaccess, $this->$v);
161  $this->lay->set("cfldtitle", $tdoc->title);
162  $this->lay->set("cflddisplay", "");
163  } else {
164  $this->lay->set("cflddisplay", "none");
165  }
166  break;
167 
168  case dfldid:
169  if ($this->$v > 0) {
170  $tdoc = new_Doc($this->dbaccess, $this->$v);
171  $this->lay->set("dfldtitle", $tdoc->title);
172  $this->lay->set("dflddisplay", "");
173  } else {
174  $this->lay->set("dflddisplay", "none");
175  }
176  break;
177 
178  case wid:
179  if ($this->$v > 0) {
180  $tdoc = new_Doc($this->dbaccess, $this->$v);
181  $this->lay->set("wtitle", $tdoc->title);
182  $this->lay->set("wdisplay", true);
183  $this->lay->set("wactif", ($tdoc->profid > 0));
184  $hascontrol = ($tdoc->control("modifyacl") == "");
185  $this->lay->set("wcontrol", $hascontrol);
186  $this->lay->set("wedit", ($tdoc->control("edit") == ""));
187  $states = $tdoc->getStates();
188  $tstates = array();
189  $tnoprofilstates = array();
190  foreach ($states as $st) {
191  $pid = $tdoc->getStateProfil($st);
192  if ($pid) {
193  $pdoc = new_doc($this->dbaccess, $pid);
194  $tstates[$pid]["smodifyacl"] = ($pdoc->control("modifyacl") == "");
195  $tstates[$pid]["sactif"] = $pdoc->profid;
196  $tstates[$pid]["pstateid"] = $pid;
197  $tstates[$pid]["states"][] = _($st);
198  } else {
199  $tnoprofilstates[_($st) ] = array(
200  "pstateattrid" => $tdoc->getStateProfilAttribute($st) ,
201  "states" => _($st)
202  );
203  }
204  }
205 
206  $this->lay->set("noprofilstate", implode(", ", array_keys($tnoprofilstates)));
207  foreach ($tstates as $k => $v) {
208  $tstates[$k]["states"] = implode(", ", $v["states"]);
209  }
210  $this->lay->setBlockData("pstate", $tstates);
211  $this->lay->setBlockData("nopstate", $tnoprofilstates);
212  } else {
213  $this->lay->set("wdisplay", false);
214  }
215  break;
216 
217  case ccvid:
218  if ($this->$v > 0) {
219  $tdoc = new_Doc($this->dbaccess, $this->$v);
220  $this->lay->set("cvtitle", $tdoc->title);
221  $this->lay->set("cvdisplay", "");
222  } else {
223  $this->lay->set("cvdisplay", "none");
224  }
225  break;
226 
227  case forumid:
228  $this->lay->set("forum", ($this->forumid == "" ? _("disable forum") : _("enable forum")));
229  break;
230 
231  case maxrev:
232  if (!$this->maxrev) {
233  if ($this->schar == 'S') $this->lay->set("maxrevision", _("no revisable"));
234  else $this->lay->set("maxrevision", _("unlimited revisions"));
235  } else $this->lay->set("maxrevision", $this->maxrev);
236 
237  break;
238  }
239  }
240  }
241  //~~~~~~~~~~~~~~~~~~~~~~~~~ PARAMETERS ~~~~~~~~~~~~~~~~~~~~~~~~
242 
243  /**
244  * return family parameter
245  *
246  * @param string $idp parameter identificator
247  * @param string $def default value if parameter not found or if it is null
248  * @return string parameter value
249  */
250  final public function getParamValue($idp, $def = "")
251  {
252  return $this->getXValue("param", $idp, $def);
253  }
254  /**
255  * return all family parameter
256  *
257  * @return array string parameter value
258  */
259  function getParams()
260  {
261  return $this->getXValues("param");
262  }
263  /**
264  * return the value of an list parameter document
265  *
266  * the parameter must be in an array or of a type '*list' like enumlist or textlist
267  * @param string $idAttr identificator of list parameter
268  * @param string $def default value returned if parameter not found or if is empty
269  * @return array the list of parameter values
270  */
271  function getParamTValue($idAttr, $def = "", $index = - 1)
272  {
273  $t = $this->_val2array($this->getParamValue("$idAttr", $def));
274  if ($index == - 1) return $t;
275  if (isset($t[$index])) return $t[$index];
276  else return $def;
277  }
278  /**
279  * set family parameter value
280  *
281  * @param string $idp parameter identificator
282  * @param string $val value of the parameter
283  */
284  function setParam($idp, $val)
285  {
286  $this->setChanged();
287  if (is_array($val)) $val = $this->_array2val($val);
288  return $this->setXValue("param", $idp, $val);
289  }
290  //~~~~~~~~~~~~~~~~~~~~~~~~~ DEFAULT VALUES ~~~~~~~~~~~~~~~~~~~~~~~~
291 
292  /**
293  * return family default value
294  *
295  * @param string $idp parameter identificator
296  * @param string $def default value if parameter not found or if it is null
297  * @return string default value
298  */
299  function getDefValue($idp, $def = "")
300  {
301  return $this->getXValue("defval", $idp, $def);
302  }
303  /**
304  * return all family default values
305  *
306  * @return array string default value
307  */
308  function getDefValues()
309  {
310  return $this->getXValues("defval");
311  }
312  /**
313  * set family default value
314  *
315  * @param string $idp parameter identificator
316  * @param string $val value of the default
317  */
318  function setDefValue($idp, $val)
319  {
320  return $this->setXValue("defval", $idp, $val);
321  }
322  //~~~~~~~~~~~~~~~~~~~~~~~~~ X VALUES ~~~~~~~~~~~~~~~~~~~~~~~~
323 
324  /**
325  * return family default value
326  *
327  * @param string $idp parameter identificator
328  * @param string $def default value if parameter not found or if it is null
329  * @return string default value
330  */
331  function getXValue($X, $idp, $def = "")
332  {
333  $tval = "t$X";
334  if (!isset($this->$tval)) $this->getXValues($X);
335 
336  $tval2 = $this->$tval;
337  $v = $tval2[strtolower($idp) ];
338  if ($v != "") return $v;
339  return $def;
340  }
341  /**
342  * return all family default values
343  *
344  * @return array string default value
345  */
346  function getXValues($X)
347  {
348  $tval = "t$X";
349  $defval = $this->$X;
350 
351  $tdefattr = explode("][", substr($defval, 1, strlen($defval) - 2));
352  $this->$tval = array();
353 
354  $txval = array();
355  foreach ($tdefattr as $k => $v) {
356 
357  $aid = substr($v, 0, strpos($v, '|'));
358  $dval = substr(strstr($v, '|') , 1);
359 
360  $txval[$aid] = $dval;
361  }
362  $this->$tval = $txval;
363 
364  return $this->$tval;
365  }
366  /**
367  * set family default value
368  *
369  * @param string $idp parameter identificator
370  * @param string $val value of the default
371  */
372  function setXValue($X, $idp, $val)
373  {
374  $tval = "t$X";
375  if (is_array($val)) $val = $this->_array2val($val);
376 
377  if (!isset($this->$tval)) $this->getXValues($X);
378  $txval = $this->$tval;
379  $txval[strtolower($idp) ] = $val;
380  $this->$tval = $txval;
381 
382  $tdefattr = array();
383  foreach ($txval as $k => $v) {
384  if ($k && ($v !== '')) $tdefattr[] = "$k|$v";
385  }
386 
387  $this->$X = "[" . implode("][", $tdefattr) . "]";
388  }
389 
390  final public function UpdateVaultIndex()
391  {
392  $dvi = new DocVaultIndex($this->dbaccess);
393  $err = $dvi->DeleteDoc($this->id);
394 
395  $fa = $this->getParamAttributes();
396 
397  $tvid = array();
398 
399  foreach ($fa as $aid => $oattr) {
400  if ($oattr->inArray()) {
401  $ta = $this->_val2array($this->getParamValue($aid));
402  } else {
403  $ta = array(
404  $this->getParamValue($aid)
405  );
406  }
407  foreach ($ta as $k => $v) {
408  $vid = "";
409  if (preg_match(PREGEXPFILE, $v, $reg)) {
410  $vid = $reg[2];
411  $tvid[$vid] = $vid;
412  }
413  }
414  }
415 
416  foreach ($tvid as $k => $vid) {
417  $dvi->docid = $this->id;
418  $dvi->vaultid = $vid;
419  $dvi->Add();
420  }
421  }
422 
423  function saveVaultFile($vid, $stream)
424  {
425  if (is_resource($stream) && get_resource_type($stream) == "stream") {
426  $ext = "nop";
427  $filename = uniqid(getTmpDir() . "/_fdl") . ".$ext";
428  $tmpstream = fopen($filename, "w");
429  while (!feof($stream)) {
430  if (false === fwrite($tmpstream, fread($stream, 4096))) {
431  $err = "403 Forbidden";
432  break;
433  }
434  }
435  fclose($tmpstream);
436  $vf = newFreeVaultFile($this->dbaccess);
437  $err = $vf->Retrieve($vid, $info);
438  if ($err == "") $err = $vf->Save($filename, false, $vid);
439  unlink($filename);
440  return $err;
441  }
442  }
443  /**
444  * read xml configuration file
445  */
446  function getConfiguration()
447  {
448  if (!$this->_configuration) {
449  if ($this->name) {
450  $dxml = new DomDocument();
451  $famfile = DEFAULT_PUBDIR . sprintf("/families/%s.fam", $this->name);
452  if (!@$dxml->load($famfile)) {
453  return null;
454 
455  return $o;
456  } else {
457  $properties = $dxml->getElementsByTagName('property');
458  foreach ($properties as $prop) {
459  $name = $prop->getAttribute('name');
460  $value = $prop->nodeValue;
461  $o->properties[$name] = $value;
462  }
463  $views = $dxml->getElementsByTagName('view');
464  foreach ($views as $view) {
465  $name = $view->getAttribute('name');
466  foreach ($view->attributes as $a) {
467  $o->views[$name][$a->name] = $a->value;
468  }
469  }
470  }
471  $this->_configuration = $o;
472  }
473  }
474  return $this->_configuration;
475  }
476 
477  function getXmlSchema()
478  {
479  $lay = new Layout(getLayoutFile("FDL", "family_schema.xml"));
480  $lay->set("famname", strtolower($this->name));
481  $lay->set("famtitle", strtolower($this->getTitle()));
482  $lay->set("includefdlxsd", file_get_contents(getLayoutFile("FDL", "fdl.xsd")));
483 
484  $level1 = array();
485  $la = $this->getAttributes();
486  $tax = array();
487 
488  foreach ($la as $k => $v) {
489  if ((!$v) || ($v->getOption("autotitle") == "yes") || ($v->usefor == 'Q')) unset($la[$k]);
490  }
491  foreach ($la as $k => $v) {
492  if (($v->id != "FIELD_HIDDENS") && ($v->type == 'frame' || $v->type == "tab") && ((!$v->fieldSet) || $v->fieldSet->id == "FIELD_HIDDENS")) {
493  $level1[] = array(
494  "level1name" => $k
495  );
496  $tax[] = array(
497  "tax" => $v->getXmlSchema($la)
498  );
499  } else {
500  // if ($v) $tax[]=array("tax"=>$v->getXmlSchema());
501 
502  }
503  };
504 
505  $lay->setBlockData("ATTR", $tax);
506  $lay->setBlockData("LEVEL1", $level1);
507  return ($lay->gen());
508  }
509  }
510 ?>
← centre documentaire © anakeen - published under CC License - Dynacase