Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.ImportDescription.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Import documents
8  *
9  * @author Anakeen
10  * @package FDL
11  * @subpackage
12  */
13 /**
14  */
15 
16 include_once ("FDL/import_file.php");
17 
19 {
20  const attributePrefix = ":ATTR:";
21  const documentPrefix = ":DOC:";
22  private $dirid = 0;
23  private $analyze = false;
24  private $policy = "update";
25  private $reinit = false;
26  private $csvSeparator = SEPCHAR;
27  private $csvEnclosure = '';
28  private $csvLinebreak = '\n';
29  private $beginLine = 0;
30  private $familyIcon = 0;
31  private $nLine = 0;
32  private $nbDoc = 0;
33  private $ods2CsvFile = '';
34  private $reset = array();
35  /* Store erroneous family's ORDER line to prevent import of document from that family */
36  private $badOrderErrors = array();
37  /**
38  * @var bool verify attribute access (visibility "I")
39  */
40  private $verifyAttributeAccess = true;
41  /**
42  * @var StructAttribute
43  */
44  private $structAttr = null;
45  /**
46  * @var array
47  */
48  private $colOrders = array();
49  /**
50  * @var array
51  */
52  private $tcr = array();
53  private $dbaccess = '';
54  private $needCleanStructure = false;
55  private $needCleanParamsAndDefaults = false;
56  private $importFileName = '';
57  /*
58  * @var ressource
59  */
60  private $fdoc;
61  /**
62  * @var DocFam
63  */
64  private $doc;
65  /**
66  * Store attributes defined/updated by the current import session.
67  *
68  * @var array
69  */
70  private $importedAttribute = array();
71  /**
72  * Store known logical names
73  *
74  * @var array
75  */
76  private $knownLogicalNames = array();
77  private $userIds = [];
78  /**
79  * @param string $importFile
80  * @throws Dcp\Exception
81  */
82  public function __construct($importFile)
83  {
84  if (seemsODS($importFile)) {
85  $this->ods2CsvFile = ods2csv($importFile);
86  $this->fdoc = fopen($this->ods2CsvFile, "r");
87  } else {
88  $this->fdoc = fopen($importFile, "r");
89  }
90  if (!$this->fdoc) {
91  throw new Dcp\Exception(sprintf("no import file found : %s", $importFile));
92  }
93  $this->importFileName = $importFile;
94  $this->dbaccess = getDbAccess();
95  }
96  /**
97  * @param boolean $verifyAttributeAccess
98  */
99  public function setVerifyAttributeAccess($verifyAttributeAccess)
100  {
101  $this->verifyAttributeAccess = $verifyAttributeAccess;
102  }
103 
104  public function analyzeOnly($analyze)
105  {
106  $this->analyze = $analyze;
107  }
108 
109  public function setPolicy($policy)
110  {
111  if (!$policy) {
112  $policy = "update";
113  }
114  $this->policy = $policy;
115  }
116 
117  public function setImportDirectory($dirid)
118  {
119  $this->dirid = $dirid;
120  }
121 
122  public function reinitAttribute($reinit)
123  {
124  $this->reinit = $reinit;
125  }
126 
127  public function reset($reset)
128  {
129 
130  if ($reset && !is_array($reset)) {
131  $reset = array(
132  $reset
133  );
134  }
135  $this->reset = $reset;
136  }
137  public function setComma($comma)
138  {
139  $this->csvSeparator = $comma;
140  }
141 
142  public function setCsvOptions($csvSeparator = ';', $csvEnclosure = '"', $csvLinebreak = '\n')
143  {
144  $this->csvSeparator = $csvSeparator;
145  $this->csvEnclosure = $csvEnclosure;
146  $this->csvLinebreak = $csvLinebreak;
147 
148  $this->setAutoCsvOptions();
149  return array(
150  "separator" => $this->csvSeparator,
151  "enclosure" => $this->csvEnclosure,
152  "linebreak" => $this->csvLinebreak
153  );
154  }
155  /**
156  * Detect csv options - separator and enclosure arguments are modified if set to auto
157  * @param $csvFileName
158  * @param string &$separator need to set to 'auto' to detect
159  * @param string &$enclosure need to set to 'auto' to detect
160  * @return array associaive array "enclosure", "separator" keys
161  * @throws Dcp\Exception
162  */
163  public static function detectAutoCsvOptions($csvFileName, &$separator = 'auto', &$enclosure = 'auto')
164  {
165  $content = file_get_contents($csvFileName);
166  if ($separator == 'auto') {
167  $detector = new \Dcp\Utils\CSVFormatDetector\Detector();
168  $detected = $detector->detect($content);
169  if (!isset($detected['separator']['char']) || $detected['separator']['char'] === null) {
170  throw new Dcp\Exception(sprintf("cannot find csv separator in %s file", $csvFileName));
171  }
172  $separator = $detected['separator']['char'];
173  }
174  if ($enclosure == 'auto') {
175  $detector = new \Dcp\Utils\CSVFormatDetector\Detector();
176  $detector->separators = array(
177  $separator
178  );
179  $detected = $detector->detect($content);
180  if (isset($detected['enclosure']['char']) && $detected['enclosure']['char'] !== null) {
181  $enclosure = $detected['enclosure']['char'];
182  } else {
183  $enclosure = '';
184  }
185  }
186  return array(
187  "separator" => $separator,
188  "enclosure" => $enclosure
189  );
190  }
191 
192  protected function setAutoCsvOptions()
193  {
194  if (!$this->ods2CsvFile) {
195  if (($this->csvSeparator == 'auto') || ($this->csvEnclosure == 'auto')) {
196  $this->detectAutoCsvOptions($this->importFileName, $this->csvSeparator, $this->csvEnclosure);
197  }
198  } else {
199  // converted from ods
200  // separator is ; no enclosure
201  $this->csvEnclosure = '';
202  $this->csvSeparator = ';';
203  $this->csvLinebreak = '\n';
204  }
205  }
206  public function import()
207  {
209 
210  $this->nbDoc = 0; // number of imported document
211  $this->dbaccess = getDbAccess();
212  $this->structAttr = null;
213  $this->colOrders = array();
214  $this->ods2CsvFile = "";
215 
216  $this->nLine = 0;
217  $this->beginLine = 0;
218  $csvLinebreak = $this->csvLinebreak;
219  if (!$this->csvSeparator && !$csvLinebreak) {
220  $csvLinebreak = '\n';
221  }
222  while (!feof($this->fdoc)) {
223  if (!$this->csvEnclosure) {
224  $buffer = rtrim(fgets($this->fdoc));
225  $data = explode($this->csvSeparator, $buffer);
226  $data = array_map(function ($v) use ($csvLinebreak)
227  {
228  return str_replace(array(
229  $csvLinebreak,
230  ALTSEPCHAR
231  ) , array(
232  "\n",
233  ';'
234  ) , $v);
235  }
236  , $data);
237  } else {
238  $data = fgetcsv($this->fdoc, 0, $this->csvSeparator, $this->csvEnclosure);
239  if ($data === false) {
240  continue;
241  }
242  if ($csvLinebreak) {
243  $data = array_map(function ($v) use ($csvLinebreak)
244  {
245  return str_replace($csvLinebreak, "\n", $v);
246  }
247  , $data);
248  }
249  }
250  $this->nLine++;
251 
252  if (!isUTF8($data)) $data = array_map("utf8_encode", $data);
253  // return structure
254  if (count($data) < 1) continue;
255  $this->tcr[$this->nLine] = array(
256  "err" => "",
257  "msg" => "",
258  "specmsg" => "",
259  "folderid" => 0,
260  "foldername" => "",
261  "filename" => "",
262  "title" => "",
263  "id" => "",
264  "values" => array() ,
265  "familyid" => 0,
266  "familyname" => "",
267  "action" => " "
268  );
269  $this->tcr[$this->nLine]["title"] = substr($data[0], 0, 10);
270  $data[0] = trim($data[0]);
271  switch ($data[0]) {
272  // -----------------------------------
273 
274  case "BEGIN":
275  $this->doBegin($data);
276  break;
277  // -----------------------------------
278 
279  case "END":
280 
281  $this->doEnd($data);
282 
283  break;
284 
285  case "RESET":
286  $this->doReset($data);
287  break;
288  // -----------------------------------
289 
290  case "DOC":
291 
292  $this->doDoc($data);
293  break;
294  // -----------------------------------
295 
296  case "SEARCH":
297  $this->doSearch($data);
298 
299  break;
300  // -----------------------------------
301 
302  case "TYPE":
303  if (!$this->doc) {
304  break;
305  }
306 
307  $this->doc->doctype = $data[1];
308  $this->tcr[$this->nLine]["msg"] = sprintf(_("set doctype to '%s'") , $data[1]);
309  break;
310  // -----------------------------------
311 
312  case "GENVERSION":
313  if (!$this->doc) {
314  break;
315  }
316 
317  $this->doc->genversion = $data[1];
318  $this->tcr[$this->nLine]["msg"] = sprintf(_("generate version '%s'") , $data[1]);
319  break;
320  // -----------------------------------
321 
322  case "MAXREV":
323  if (!$this->doc) {
324  break;
325  }
326 
327  $this->doc->maxrev = intval($data[1]);
328  $this->tcr[$this->nLine]["msg"] = sprintf(_("max revision '%d'") , $data[1]);
329  break;
330  // -----------------------------------
331 
332  case "ICON": // for family
333  $this->doIcon($data);
334  break;
335 
336  case "DOCICON":
337  $this->doDocIcon($data);
338  break;
339 
340  case "DOCATAG":
341  $this->doDocAtag($data);
342  break;
343 
344  case "DFLDID":
345  $this->doDfldid($data);
346  break;
347 
348  case "CFLDID":
349  $this->doCfldid($data);
350  break;
351 
352  case "WID":
353  $this->doWid($data);
354  break;
355 
356  case "CVID":
357  $this->doCvid($data);
358  break;
359 
360  case "SCHAR":
361  if (!$this->doc) {
362  break;
363  }
364 
365  $this->doc->schar = $data[1];
366  $this->tcr[$this->nLine]["msg"] = sprintf(_("set special characteristics to '%s'") , $data[1]);
367  break;
368  // -----------------------------------
369 
370  case "CLASS":
371  $this->doClass($data);
372  break;
373 
374  case "METHOD":
375  $this->doMethod($data);
376  break;
377 
378  case "USEFORPROF":
379  if (!$this->doc) {
380  break;
381  }
382 
383  $this->doc->usefor = "P";
384  $this->tcr[$this->nLine]["msg"] = sprintf(_("change special use to '%s'") , $this->doc->usefor);
385  break;
386 
387  case "USEFOR":
388  if (!$this->doc) {
389  break;
390  }
391 
392  $this->doc->usefor = $data[1];
393  $this->tcr[$this->nLine]["msg"] = sprintf(_("change special use to '%s'") , $this->doc->usefor);
394  break;
395 
396  case "TAG":
397  $this->doATag($data);
398  break;
399 
400  case "CPROFID":
401  $this->doCprofid($data);
402  break;
403 
404  case "PROFID":
405  $this->doProfid($data);
406  break;
407 
408  case "DEFAULT":
409  $this->doDefault($data);
410  break;
411 
412  case "INITIAL":
413  $this->doInitial($data);
414  break;
415 
416  case "IATTR":
417  $this->doIattr($data);
418  break;
419 
420  case "PARAM":
421  case "OPTION":
422  case "ATTR":
423  case "MODATTR":
424  $this->doAttr($data);
425  break;
426 
427  case "ORDER":
428  $this->doOrder($data);
429  break;
430 
431  case "KEYS":
432  $this->doKeys($data);
433  break;
434 
435  case "TAGABLE":
436  $this->doTagable($data);
437  break;
438 
439  case "PROFIL":
440  $this->doProfil($data);
441  break;
442 
443  case "ACCESS":
444  $this->doAccess($data);
445  break;
446 
447  case "LDAPMAP":
448  $this->doLdapmap($data);
449 
450  break;
451 
452  case "PROP":
453  $this->doProp($data);
454  break;
455 
456  default:
457  // uninterpreted line
458  unset($this->tcr[$this->nLine]);
459  }
460  }
461 
462  fclose($this->fdoc);
463 
464  if ($this->ods2CsvFile) {
465  unlink($this->ods2CsvFile);
466  } // temporary csvfile
467  return $this->tcr;
468  }
469  /**
470  * add application tag
471  * @param array $data
472  */
473  protected function doATag(array $data)
474  {
475  if (!$this->doc) return;
476  $err = $this->doc->AddATag($data[1]);
477  if (!$err) $this->tcr[$this->nLine]["msg"] = sprintf(_("change application tag to '%s'") , $this->doc->atags);
478  else {
479  $this->tcr[$this->nLine]["err"] = "ATAG:" . $err;
480  $this->tcr[$this->nLine]["action"] = "ignored";
481  }
482  }
483  /**
484  * analyze BEGIN
485  * @param array $data line of description file
486  */
487  protected function doBegin(array $data)
488  {
489  $err = "";
490  $data = array_map("trim", $data);
491  // search from name or from id
492  try {
493  $this->doc = null;
494  $this->beginLine = $this->nLine;
495  $check = new CheckBegin();
496  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
497  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
498  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
499  $this->tcr[$this->nLine]["action"] = "warning"; #_("warning")
500  return;
501  }
502  if ($this->tcr[$this->nLine]["err"] == "") {
503  if (($data[3] == "") || ($data[3] == "-")) $this->doc = new DocFam($this->dbaccess, getFamIdFromName($this->dbaccess, $data[5]) , '', 0, false);
504  else $this->doc = new DocFam($this->dbaccess, $data[3], '', 0, false);
505 
506  $this->familyIcon = "";
507 
508  if (!$this->doc->isAffected()) {
509 
510  if (!$this->analyze) {
511  $this->doc = new DocFam($this->dbaccess);
512 
513  if (isset($data[3]) && ($data[3] > 0)) $this->doc->id = $data[3]; // static id
514  if (is_numeric($data[1])) $this->doc->fromid = $data[1];
515  else $this->doc->fromid = getFamIdFromName($this->dbaccess, $data[1]);
516  if (isset($data[5])) $this->doc->name = $data[5]; // internal name
517  $err = $this->doc->Add();
518  }
519  $this->tcr[$this->nLine]["msg"] = sprintf(_("create %s family %s") , $data[2], $data[5]);
520  $this->tcr[$this->nLine]["action"] = "added";
521  } else {
522  $this->tcr[$this->nLine]["action"] = "updated";
523  $this->tcr[$this->nLine]["msg"] = sprintf(_("update %s family %s") , $data[2], $data[5]);
524  }
525  if ($data[1] && ($data[1] != '-')) {
526  if ($data[1] == '--') $this->doc->fromid = 0;
527  else if (is_numeric($data[1])) $this->doc->fromid = $data[1];
528  else $this->doc->fromid = getFamIdFromName($this->dbaccess, $data[1]);
529  }
530  if ($data[2] && ($data[2] != '-')) $this->doc->title = $data[2];
531  if ($data[4] && ($data[4] != '-')) $this->doc->classname = $data[4]; // new classname for familly
532  if ($data[4] == "--") $this->doc->classname = '';
533  $this->tcr[$this->nLine]["err"].= $check->checkClass($data, $this->doc)->getErrors();
534 
535  if ($data[5] && ($data[5] != '-')) $this->doc->name = $data[5]; // internal name
536  $this->tcr[$this->nLine]["err"].= $err;
537 
538  if ($this->reinit) {
539  $this->tcr[$this->nLine]["msg"].= sprintf(_("reinit all attributes"));
540  if ($this->analyze) return;
541  $oattr = new DocAttr($this->dbaccess);
542  $oattr->docid = intval($this->doc->id);
543  if ($oattr->docid > 0) {
544  $err = $oattr->exec_query(sprintf("delete from docattr where docid=%d", $oattr->docid));
545  // $err .= $oattr->exec_query(sprintf("update docfam set defval=null,param=null where id=%d", $oattr->docid));
546 
547  }
548  $this->tcr[$this->nLine]["err"].= $err;
549  }
550  if ($this->reset) {
551  foreach ($this->reset as $reset) {
552  $this->doReset(array(
553  "RESET",
554  $reset
555  ));
556  }
557  }
558  } else {
559  $this->tcr[$this->nLine]["err"].= $err;
560  }
561  }
562  catch(Exception $e) {
563  $this->tcr[$this->nLine]["err"].= $e->getMessage();
564  }
565  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
566  }
567  /**
568  * analyze END
569  * @param array $data line of description file
570  */
571  protected function doEnd(array $data)
572  {
573  if (!$this->doc) return;
574  // add messages
575  $msg = sprintf(_("modify %s family") , $this->doc->title);
576  $this->tcr[$this->nLine]["msg"] = $msg;
577 
578  $ferr = '';
579  for ($i = $this->beginLine; $i < $this->nLine; $i++) {
580  if (!empty($this->tcr[$i]["err"])) $ferr.= $this->tcr[$i]["err"];
581  }
582  if ($this->analyze) {
583  $this->nbDoc++;
584  if ($ferr) {
585  $this->tcr[$this->beginLine]["action"] = "warning";
586  }
587  return;
588  }
589  if ((count($data) > 3) && ($data[3] != "")) $this->doc->doctype = "S";
590  if ($ferr == "") {
591  $now = gettimeofday();
592  $this->doc->revdate = $now['sec'];
593  $this->doc->modify();
594 
595  $check = new CheckEnd($this);
596  if ($this->doc->doctype == "C") {
597  global $tFamIdName;
598  $check->checkMaxAttributes($this->doc);
599  $err = $check->getErrors();
600 
601  if ($err && $this->analyze) {
602  $this->tcr[$this->nLine]["msg"].= sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
603  $this->tcr[$this->nLine]["action"] = "warning";
604  return;
605  }
606  if ($err == '') {
607  if (strpos($this->doc->usefor, "W") !== false) $this->doc->postImport(); //special to add calculated attributes
608  $msg = \Dcp\FamilyImport::refreshPhpPgDoc($this->dbaccess, $this->doc->id);
609  if ($msg !== '') {
610  $this->tcr[$this->nLine]["err"].= $msg;
611  $this->tcr[$this->nLine]["action"] = "ignored";
612  $this->tcr[$this->beginLine]["action"] = "ignored";
613  return;
614  }
615  if (isset($tFamIdName)) $tFamIdName[$this->doc->name] = $this->doc->id; // refresh getFamIdFromName for multiple family import
616  $checkCr = checkDb::verifyDbFamily($this->doc->id);
617  if (count($checkCr) > 0) {
618  $this->tcr[$this->nLine]["err"].= ErrorCode::getError('ATTR1700', implode(",", $checkCr));
619  } else {
620  // Need to update child family in case of new attribute
621  $childsFams = ($this->doc->getChildFam());
622  foreach ($childsFams as $famInfo) {
623  \Dcp\FamilyImport::createDocFile($this->dbaccess, $famInfo);
624  }
625  }
626  } else {
627  $this->tcr[$this->nLine]["err"].= $err;
628  }
629  }
630 
631  if ($this->needCleanParamsAndDefaults) {
632  $this->needCleanParamsAndDefaults = false;
634  }
635 
636  $this->tcr[$this->nLine]["err"].= $check->check($data, $this->doc)->getErrors();
637  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
638  $this->tcr[$this->nLine]["msg"].= sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
639  $this->tcr[$this->nLine]["action"] = "warning";
640  return;
641  }
642 
643  if ((!$this->analyze) && ($this->familyIcon != "")) $this->doc->changeIcon($this->familyIcon);
644  $this->tcr[$this->nLine]["msg"].= $this->doc->postImport();
645  if (!$this->tcr[$this->nLine]["err"]) {
646  $check->checkMaxAttributes($this->doc);
647  $this->tcr[$this->nLine]["err"] = $check->getErrors();
648  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
649  $this->tcr[$this->nLine]["msg"].= sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
650  $this->tcr[$this->nLine]["action"] = "warning";
651  return;
652  }
653  }
654 
655  $this->doc->addHistoryEntry(_("Update by importation"));
656 
657  $this->nbDoc++;
658 
659  clearCacheDoc($this->doc->id);
660  if ($this->tcr[$this->nLine]["err"]) {
661  $this->tcr[$this->beginLine]["action"] = "ignored";
662  $this->tcr[$this->nLine]["action"] = "ignored";
663  }
664  } else {
665  $this->tcr[$this->beginLine]["action"] = "ignored";
666  $this->tcr[$this->nLine]["action"] = "ignored";
667  }
668  if ($this->needCleanStructure) {
669  $this->needCleanStructure = false;
670  if (!$this->tcr[$this->nLine]["err"]) {
671  $this->cleanStructure();
672  }
673  }
674  }
675  /**
676  * Delete undeclared sql columns
677  */
678  protected function cleanStructure()
679  {
680  if (!$this->doc) return;
681 
682  $orphanAttributes = CheckDb::getOrphanAttributes($this->doc->id);
683  if ($orphanAttributes) {
684 
685  $sql = array();
686  foreach ($orphanAttributes as $orphanAttrId) {
687  $sql[] = sprintf("alter table doc%d drop column %s cascade; ", $this->doc->id, $orphanAttrId);
688 
689  $this->tcr[$this->nLine]["msg"].= "\nDestroy values for \"$orphanAttrId\".";
690  }
691  $sql[] = sprintf("create view family.\"%s\" as select * from doc%d", strtolower($this->doc->name) , $this->doc->id);
692 
693  foreach ($sql as $aSql) {
694  simpleQuery('', $aSql);
695  }
696  }
697  }
698 
699  protected function cleanDefaultAndParametersValues()
700  {
701 
702  $defs = $this->doc->getOwnDefValues();
703  foreach ($defs as $aid => $v) {
704  if (!$this->doc->getAttribute($aid)) {
705  $this->doc->setDefValue($aid, '', false);
706  $this->tcr[$this->nLine]["msg"].= "\nClear default value \"$aid\".";
707  }
708  }
709  $defs = $this->doc->getOwnParams();
710  foreach ($defs as $aid => $v) {
711  if (!$this->doc->getAttribute($aid)) {
712  $this->doc->setParam($aid, '', false);
713  $this->tcr[$this->nLine]["msg"].= "\nClear parameter value \"$aid\".";
714  }
715  }
716 
717  $this->doc->modify();
718  }
719  /**
720  * analyze RESET²
721  * @param array $data line of description file
722  */
723  protected function doReset(array $data)
724  {
725  if (!$this->doc) return;
726  $err = "";
727  $data = array_map("trim", $data);
728  $check = new CheckReset();
729  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
730  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
731  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
732  $this->tcr[$this->nLine]["action"] = "warning";
733  return;
734  }
735  if (!$this->tcr[$this->nLine]["err"]) {
736  switch (strtolower($data[1])) {
737  case 'attributes':
738  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("reinit all attributes"));
739  if ($this->analyze) {
740  return;
741  }
742 
743  $sql = sprintf("delete from docattr where docid=%d", $this->doc->id);
744  simpleQuery($this->dbaccess, $sql);
745 
746  $this->needCleanParamsAndDefaults = true;
747  break;
748 
749  case 'default':
750  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("Reset defaults values"));
751  $this->doc->defval = '';
752  break;
753 
754  case 'parameters':
755  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("Reset parameters values"));
756  $this->doc->param = '';
757  break;
758 
759  case 'enums':
760  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("Reset enums definition"));
761  $sql = sprintf("update docattr set phpfunc=null from docenum where docattr.docid=docenum.famid and docattr.id = docenum.attrid and docattr.type ~ 'enum' and docattr.docid=%d", $this->doc->id);
762  simpleQuery($this->dbaccess, $sql);
763  $sql = sprintf("delete from docenum where famid=%d", $this->doc->id);
764  simpleQuery($this->dbaccess, $sql);
765 
766  break;
767 
768  case 'properties':
769 
770  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("reinit all properties"));
771  if ($this->analyze) {
772  return;
773  }
774  $this->doc->resetPropertiesParameters();
775  break;
776 
777  case 'structure':
778  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("Reset attribute structure"));
779  if ($this->analyze) {
780  return;
781  }
782  $sql = sprintf("delete from docattr where docid=%d", $this->doc->id);
783  simpleQuery($this->dbaccess, $sql);
784  $this->needCleanStructure = true;
785  $this->needCleanParamsAndDefaults = true;
786  break;
787  }
788  } else {
789  $this->tcr[$this->nLine]["action"] = "ignored";
790  }
791  $this->tcr[$this->nLine]["err"].= $err;
792  }
793  /**
794  * analyze DOC
795  * @param array $data line of description file
796  */
797  protected function doDoc(array $data)
798  {
799  $check = new CheckDoc();
800  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
801  $famName = $check->getParsedFamName();
802  if ($this->tcr[$this->nLine]["err"]) {
803  if ($this->analyze) {
804  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
805  $this->tcr[$this->nLine]["action"] = "warning";
806  } else {
807  $this->tcr[$this->nLine]["action"] = "ignored";
808  }
809  return;
810  }
811  if ($famName !== false && isset($this->badOrderErrors[$famName])) {
812  /* Do not import the document if the ORDER line of its family was erroneous */
813  if ($this->analyze) {
814  $this->tcr[$this->nLine]["msg"] = sprintf(_("Cannot import document because the ORDER line for family '%s' is incorrect: %s") , $famName, $this->badOrderErrors[$famName]);
815  $this->tcr[$this->nLine]["action"] = "warning";
816  } else {
817  $this->tcr[$this->nLine]["msg"] = sprintf(_("Cannot import document because the ORDER line for family '%s' is incorrect: %s") , $famName, $this->badOrderErrors[$famName]);
818  $this->tcr[$this->nLine]["action"] = "ignored";
819  }
820  return;
821  }
822  // case of specific order
823  if (is_numeric($data[1])) $fromid = $data[1];
824  else $fromid = getFamIdFromName($this->dbaccess, $data[1]);
825 
826  if (isset($tkeys[$fromid])) $tk = $tkeys[$fromid];
827  else $tk = array(
828  "title"
829  );
830 
831  $torder = array();
832  if (isset($this->colOrders[$fromid])) {
833  $torder = $this->colOrders[$fromid];
834  }
835  // $this->tcr[$this->nLine] = csvAddDoc($this->dbaccess, $data, $this->dirid, $this->analyze, '', $this->policy, $tk, array() , $torder);
836  $oImportDocument = new importSingleDocument();
837  if ($tk) {
838  $oImportDocument->setKey($tk);
839  }
840  if ($torder) {
841  $oImportDocument->setOrder($torder);
842  }
843  $oImportDocument->analyzeOnly($this->analyze);
844  $oImportDocument->setPolicy($this->policy);
845  $oImportDocument->setTargetDirectory($this->dirid);
846  $oImportDocument->setVerifyAttributeAccess($this->verifyAttributeAccess);
847  /**
848  * Append current document's logical name to list of known logical names
849  * and configure the importer to use this list to check for unknown
850  * logical names
851  */
852  if ($data[2] != '' && !in_array($data[2], $this->knownLogicalNames)) {
853  $this->knownLogicalNames[] = $data[2];
854  }
855  $oImportDocument->setKnownLogicalNames($this->knownLogicalNames);
856 
857  $this->tcr[$this->nLine] = $oImportDocument->import($data)->getImportResult();
858 
859  if ($this->tcr[$this->nLine]["err"] == "") {
860  $this->nbDoc++;
861  } else {
862  $check->addError($this->tcr[$this->nLine]["err"]);
863  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
864  $this->tcr[$this->nLine]["action"] = "warning";
865  }
866  }
867  /**
868  * analyze SEARCH
869  * @param array $data line of description file
870  */
871  protected function doSearch(array $data)
872  {
873  $err = '';
874  if ($data[1] != '') {
875  $this->tcr[$this->nLine]["id"] = $data[1];
876  /*
877  * @var DocSearch $search
878  */
879  $search = new_Doc($this->dbaccess, $data[1]);
880  if (!$search->isAffected()) {
881  $search = createDoc($this->dbaccess, 5);
882  if (!$this->analyze) {
883  if ($data[1] && is_numeric($data[1])) {
884  $search->id = $data[1]; // static id
885 
886  }
887  $err = $search->Add();
888  if ($data[1] && !is_numeric($data[1])) {
889  $search->setLogicalName($data[1]);
890  }
891  }
892  $this->tcr[$this->nLine]["msg"] = sprintf(_("update %s search") , $data[3]);
893  $this->tcr[$this->nLine]["action"] = "updated";
894  }
895  } else {
896  $search = createDoc($this->dbaccess, 5);
897  if (!$this->analyze) {
898  $err = $search->Add();
899  }
900  $this->tcr[$this->nLine]["msg"] = sprintf(_("add %s search") , $data[3]);
901  $this->tcr[$this->nLine]["action"] = "added";
902  $this->tcr[$this->nLine]["err"].= $err;
903  }
904  if (($err != "") && ($search->id > 0)) { // case only modify
905  if ($search->Select($search->id)) $err = "";
906  }
907  if (!$this->analyze) {
908  // update title in finish
909  $search->title = $data[3];
910  $err = $search->modify();
911  $this->tcr[$this->nLine]["err"].= $err;
912 
913  if (($data[4] != "")) { // specific search
914  $err = $search->AddStaticQuery($data[4]);
915  $this->tcr[$this->nLine]["err"].= $err;
916  }
917 
918  if ($data[2] != '') { // dirid
919 
920  /*
921  * @var Dir $dir
922  */
923  $dir = new_Doc($this->dbaccess, $data[2]);
924  if ($dir->isAlive() && method_exists($dir, "insertDocument")) $dir->insertDocument($search->id);
925  }
926  }
927  $this->nbDoc++;
928  }
929  /**
930  * analyze DOCICON
931  * @param array $data line of description file
932  */
933  protected function doDocIcon(array $data)
934  {
935  $idoc = new_doc($this->dbaccess, $data[1]);
936  if (!$this->analyze) $idoc->changeIcon($data[2]);
937  if ($idoc->isAlive()) $this->tcr[$this->nLine]["msg"] = sprintf(_("document %s : set icon to '%s'") , $idoc->title, $data[2]);
938  else {
939  $this->tcr[$this->nLine]["err"] = sprintf(_("no change icon : document %s not found") , $data[1]);
940  $this->tcr[$this->nLine]["action"] = "ignored";
941  }
942  }
943  /**
944  * analyze DOCATAG
945  * @param array $data line of description file
946  */
947  protected function doDocAtag(array $data)
948  {
949  $check = new CheckDocATag();
950  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
951  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
952  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
953  $this->tcr[$this->nLine]["action"] = "warning";
954  return;
955  }
956  if ($this->tcr[$this->nLine]["err"]) {
957  $this->tcr[$this->nLine]["action"] = "ignored";
958  return;
959  }
960  $idoc = new_doc($this->dbaccess, $data[1]);
961 
962  $i = 4;
963  $tags = [];
964  while (!empty($data[$i])) {
965  $tags[] = $data[$i];
966  $i++;
967  }
968 
969  $tagAction = $data[3];
970  if (!$tagAction) {
971  $tagAction = "ADD";
972  }
973 
974  if (!$this->analyze) {
975  if ($tagAction === "SET") {
976  $idoc->atags = '';
977  if (!$tags) {
978  $err = $idoc->modify(true, array("atags"), true);
979  if ($err) {
980  $this->tcr[$this->nLine]["err"] = $err;
981  }
982  }
983  }
984  foreach ($tags as $tag) {
985  if ($tagAction === "DELETE") {
986  $err = $idoc->delATag($tag);
987  } else {
988  $err = $idoc->addATag($tag);
989  }
990  if ($err) {
991  $this->tcr[$this->nLine]["err"] = $err;
992  }
993  }
994  }
995  switch ($tagAction) {
996  case "ADD":
997  $this->tcr[$this->nLine]["msg"] = sprintf(_("Add atags \"%s\"") , implode("\", \"", $tags));
998  break;
999 
1000  case "DELETE":
1001  $this->tcr[$this->nLine]["msg"] = sprintf(_("Del atags \"%s\"") , implode("\", \"", $tags));
1002  break;
1003 
1004  case "SET":
1005  $this->tcr[$this->nLine]["msg"] = sprintf(_("Set atags \"%s\"") , implode("\", \"", $tags));
1006  break;
1007  }
1008  }
1009  /**
1010  * analyze ICON
1011  * @param array $data line of description file
1012  */
1013  protected function doIcon(array $data)
1014  {
1015  if (empty($data[1])) {
1016  $this->tcr[$this->nLine]["msg"] = sprintf(_("No Icon specified"));
1017  } elseif ($this->doc->icon == "") {
1018  $this->familyIcon = $data[1]; // reported to end section
1019  $this->tcr[$this->nLine]["msg"] = sprintf(_("set icon to '%s'") , $data[1]);
1020  } else {
1021  $this->tcr[$this->nLine]["msg"] = sprintf(_("icon already set. No update allowed"));
1022  }
1023  }
1024  /**
1025  * analyze DFLDID
1026  * @param array $data line of description file
1027  */
1028  protected function doDfldid(array $data)
1029  {
1030  if (!$this->doc) return;
1031  if (!isset($data[1])) $data[1] = '';
1032  $check = new CheckDfldid();
1033  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1034  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1035  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1036  $this->tcr[$this->nLine]["action"] = "warning";
1037  return;
1038  }
1039  if (!$this->tcr[$this->nLine]["err"]) {
1040  $fldid = 0;
1041  if ($data[1] == "auto") {
1042  if ($this->doc->dfldid == "") {
1043  if (!$this->analyze) {
1044  // create auto
1045  include_once ("FDL/freedom_util.php");
1046  $fldid = createAutoFolder($this->doc);
1047  $this->tcr[$this->nLine]["msg"].= sprintf(_("create default folder (id [%d])\n") , $fldid);
1048  }
1049  } else {
1050  $fldid = $this->doc->dfldid;
1051  $this->tcr[$this->nLine]["msg"] = sprintf(_("default folder already set. Auto ignored"));
1052  }
1053  } elseif (is_numeric($data[1])) $fldid = $data[1];
1054  else $fldid = getIdFromName($this->dbaccess, $data[1], 2);
1055  $this->doc->dfldid = $fldid;
1056  $this->tcr[$this->nLine]["msg"].= sprintf(_("set default folder to '%s'") , $data[1]);
1057  } else {
1058  $this->tcr[$this->nLine]["action"] = "ignored";
1059  }
1060  }
1061  /**
1062  * analyze CFLDID
1063  * @param array $data line of description file
1064  */
1065  protected function doCfldid(array $data)
1066  {
1067  if (!$this->doc) return;
1068 
1069  $check = new CheckCfldid();
1070  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1071  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1072  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1073  $this->tcr[$this->nLine]["action"] = "warning";
1074  return;
1075  }
1076  if (!$this->tcr[$this->nLine]["err"]) {
1077  if (is_numeric($data[1])) $cfldid = $data[1];
1078  else $cfldid = getIdFromName($this->dbaccess, $data[1]);
1079  $this->doc->cfldid = $cfldid;
1080  $this->tcr[$this->nLine]["msg"] = sprintf(_("set primary folder to '%s'") , $data[1]);
1081  } else {
1082  $this->tcr[$this->nLine]["action"] = "ignored";
1083  }
1084  }
1085  /**
1086  * analyze WID
1087  * @param array $data line of description file
1088  */
1089  protected function doWid(array $data)
1090  {
1091  if (!$this->doc) return;
1092  if (!isset($data[1])) $data[1] = '';
1093  $check = new CheckWid();
1094  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1095  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1096  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1097  $this->tcr[$this->nLine]["action"] = "warning";
1098  return;
1099  }
1100  if ($this->tcr[$this->nLine]["err"]) {
1101  $this->tcr[$this->nLine]["action"] = "ignored";
1102  return;
1103  }
1104  if (is_numeric($data[1])) $wid = $data[1];
1105  else $wid = getIdFromName($this->dbaccess, $data[1], 20);
1106  if ($data[1]) {
1107  try {
1108  $wdoc = new_doc($this->dbaccess, $wid);
1109  if (!$wdoc->isAlive()) {
1110  $this->tcr[$this->nLine]["err"] = sprintf(_("WID : workflow '%s' not found") , $data[1]);
1111  } else {
1112  if (!is_subclass_of($wdoc, "WDoc")) {
1113  $this->tcr[$this->nLine]["err"] = sprintf(_("WID : workflow '%s' is not a workflow") , $data[1]);
1114  } else {
1115  $this->doc->wid = $wdoc->id;
1116  }
1117  }
1118  $this->tcr[$this->nLine]["msg"] = sprintf(_("set default workflow to '%s'") , $data[1]);
1119  }
1120  catch(Exception $e) {
1121  $this->tcr[$this->nLine]["err"] = sprintf(_("WID : %s") , $e->getMessage());
1122  }
1123  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1124  } else {
1125  $this->doc->wid = '';
1126 
1127  $this->tcr[$this->nLine]["msg"] = _("unset default workflow");
1128  }
1129  }
1130  /**
1131  * analyze CVID
1132  * @param array $data line of description file
1133  */
1134  protected function doCvid(array $data)
1135  {
1136  if (!$this->doc) return;
1137  $check = new CheckCvid();
1138  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1139  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1140  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1141  $this->tcr[$this->nLine]["action"] = "warning";
1142  return;
1143  }
1144  if ($this->tcr[$this->nLine]["err"]) {
1145  $this->tcr[$this->nLine]["action"] = "ignored";
1146  return;
1147  }
1148 
1149  if (is_numeric($data[1])) $cvid = $data[1];
1150  else $cvid = getIdFromName($this->dbaccess, $data[1], 28);
1151 
1152  if ($data[1]) {
1153  try {
1154  $cvdoc = new_doc($this->dbaccess, $cvid);
1155  if (!$cvdoc->isAlive()) {
1156  $this->tcr[$this->nLine]["err"] = sprintf(_("CVID : view control '%s' not found") , $data[1]);
1157  } else {
1158  $this->doc->ccvid = $cvdoc->id;
1159  }
1160  $this->tcr[$this->nLine]["msg"] = sprintf(_("set default view control to '%s'") , $data[1]);
1161  }
1162  catch(Exception $e) {
1163  $this->tcr[$this->nLine]["err"] = sprintf(_("CVID : %s") , $e->getMessage());
1164  }
1165  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1166  } else {
1167  $this->doc->ccvid = '';
1168 
1169  $this->tcr[$this->nLine]["msg"] = _("unset default view control");
1170  }
1171  }
1172  /**
1173  * analyze CLASS
1174  * @param array $data line of description file
1175  */
1176  protected function doClass(array $data)
1177  {
1178  if (!$this->doc) return;
1179  $data = array_map("trim", $data);
1180  $check = new CheckClass();
1181  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1182  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1183  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1184  $this->tcr[$this->nLine]["action"] = "warning";
1185  return;
1186  }
1187  if ($this->tcr[$this->nLine]["err"]) {
1188  $this->tcr[$this->nLine]["action"] = "ignored";
1189  return;
1190  }
1191  $this->doc->classname = $data[1];
1192  }
1193  /**
1194  * analyze METHOD
1195  * @param array $data line of description file
1196  */
1197  protected function doMethod(array $data)
1198  {
1199  if (!$this->doc) return;
1200  $data = array_map("trim", $data);
1201  $check = new CheckMethod();
1202  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1203  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1204  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1205  $this->tcr[$this->nLine]["action"] = "warning";
1206  return;
1207  }
1208  if ($this->tcr[$this->nLine]["err"]) {
1209  $this->tcr[$this->nLine]["action"] = "ignored";
1210  return;
1211  }
1212 
1213  if (!isset($data[1])) $aMethod = null;
1214  else $aMethod = $data[1];
1215  $s1 = ($aMethod) ? $aMethod[0] : '';
1216  if (($s1 == "+") || ($s1 == "*")) {
1217  if ($s1 == "*") $method = $aMethod;
1218  else $method = substr($aMethod, 1);
1219 
1220  if ($this->doc->methods == "") {
1221  $this->doc->methods = $method;
1222  } else {
1223  $this->doc->methods.= "\n$method";
1224  // not twice
1225  $tmeth = explode("\n", $this->doc->methods);
1226  $tmeth = array_unique($tmeth);
1227  $this->doc->methods = implode("\n", $tmeth);
1228  }
1229  } else $this->doc->methods = $aMethod;
1230 
1231  $this->tcr[$this->nLine]["msg"] = sprintf(_("change methods to '%s'") , $this->doc->methods);
1232  if ($this->doc->methods) {
1233  $tmethods = explode("\n", $this->doc->methods);
1234  foreach ($tmethods as $method) {
1235  $fileMethod = ($method && $method[0] == '*') ? substr($method, 1) : $method;
1236  if (!file_exists(sprintf("FDL/%s", $fileMethod))) {
1237  $this->tcr[$this->nLine]["err"].= sprintf("Method file '%s' not found.", $fileMethod);
1238  }
1239  }
1240  }
1241  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1242  }
1243  /**
1244  * analyze CPROFID
1245  * @param array $data line of description file
1246  */
1247  protected function doCprofid(array $data)
1248  {
1249  if (!$this->doc) return;
1250  $check = new CheckCprofid();
1251  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1252  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1253  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1254  $this->tcr[$this->nLine]["action"] = "warning";
1255  return;
1256  }
1257  if ($this->tcr[$this->nLine]["err"]) {
1258  $this->tcr[$this->nLine]["action"] = "ignored";
1259  return;
1260  }
1261 
1262  if (is_numeric($data[1])) $pid = $data[1];
1263  else $pid = getIdFromName($this->dbaccess, $data[1], 3);
1264  $this->doc->cprofid = $pid;
1265  $this->tcr[$this->nLine]["msg"] = sprintf(_("change default creation profile id to '%s'") , $data[1]);
1266  }
1267  /**
1268  * analyze PROFID
1269  * @param array $data line of description file
1270  */
1271  protected function doProfid(array $data)
1272  {
1273  if (!$this->doc) return;
1274 
1275  $check = new CheckProfid();
1276  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
1277  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1278  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1279  $this->tcr[$this->nLine]["action"] = "warning";
1280  return;
1281  }
1282  if ($this->tcr[$this->nLine]["err"]) {
1283  $this->tcr[$this->nLine]["action"] = "ignored";
1284  return;
1285  }
1286  if (is_numeric($data[1])) $pid = $data[1];
1287  else $pid = getIdFromName($this->dbaccess, $data[1], 3);
1288  $this->doc->setProfil($pid); // change profile
1289  $this->tcr[$this->nLine]["msg"] = sprintf(_("change profile id to '%s'") , $data[1]);
1290  }
1291  /**
1292  * analyze INITIAL
1293  * @param array $data line of description file
1294  */
1295  protected function doInitial(array $data)
1296  {
1297 
1298  if (!$this->doc) return;
1299  $check = new CheckInitial();
1300  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1301  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1302  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1303  $this->tcr[$this->nLine]["action"] = "warning";
1304  return;
1305  }
1306  if ($this->tcr[$this->nLine]["err"]) {
1307  $this->tcr[$this->nLine]["action"] = "ignored";
1308  return;
1309  }
1310 
1311  if (!isset($data[2])) $data[2] = '';
1312  $attrid = trim(strtolower($data[1]));
1313  $newValue = $data[2];
1314  $opt = (isset($data[3])) ? trim(strtolower($data[3])) : null;
1315  $force = (str_replace(" ", "", $opt) == "force=yes");
1316  $params = $this->doc->getOwnParams();
1317  $previousValue = isset($params[$attrid]) ? $params[$attrid] : null;
1318  if ((!empty($previousValue)) && (!$force)) {
1319  // reset default
1320  $this->tcr[$this->nLine]["msg"] = sprintf("keep default value %s : %s. No use %s", $attrid, $previousValue, $data[2]);
1321  } else {
1322 
1323  if ($force || ($previousValue === null)) {
1324  $this->doc->setParam($attrid, $newValue, false);
1325  $this->tcr[$this->nLine]["msg"] = "reset default parameter";
1326  }
1327  $this->tcr[$this->nLine]["msg"].= sprintf(_("add default value %s %s") , $attrid, $data[2]);
1328  }
1329  }
1330  /**
1331  * analyze DEFAULT
1332  * @param array $data line of description file
1333  */
1334  protected function doDefault(array $data)
1335  {
1336 
1337  if (!$this->doc) return;
1338  $check = new CheckDefault();
1339  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1340  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1341  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1342  $this->tcr[$this->nLine]["action"] = "warning";
1343  return;
1344  }
1345  if ($this->tcr[$this->nLine]["err"]) {
1346  $this->tcr[$this->nLine]["action"] = "ignored";
1347  return;
1348  }
1349 
1350  if (!isset($data[2])) $data[2] = '';
1351  $attrid = trim(strtolower($data[1]));
1352  $defv = $data[2];
1353  $opt = (isset($data[3])) ? trim(strtolower($data[3])) : null;
1354  $force = (str_replace(" ", "", $opt) == "force=yes");
1355  $ownDef = $this->doc->getOwnDefValues();
1356  if ((!empty($ownDef[$attrid])) && (!$force)) {
1357  // reset default
1358  $this->tcr[$this->nLine]["msg"] = sprintf("keep default value %s : %s. No use %s", $attrid, $ownDef[$attrid], $data[2]);
1359  } else {
1360  $this->doc->setDefValue($attrid, $defv, false);
1361  if ($force || (!$this->doc->getParameterRawValue($attrid))) {
1362  // TODO : not really exact here : must verify if it is really a parameter
1363  //$this->doc->setParam($attrid, $defv);
1364  //$this->tcr[$this->nLine]["msg"] = "reset default parameter";
1365 
1366  }
1367  $this->tcr[$this->nLine]["msg"].= sprintf(_("add default value %s %s") , $attrid, $data[2]);
1368  }
1369  }
1370  /**
1371  * analyze ACCESS
1372  * @param array $data line of description file
1373  */
1374  protected function doAccess(array $data)
1375  {
1376 
1377  global $action;
1378  $check = new CheckAccess();
1379  $this->tcr[$this->nLine]["err"] = $check->check($data, $action)->getErrors();
1380  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1381  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1382  $this->tcr[$this->nLine]["action"] = "warning";
1383  return;
1384  }
1385  if ($this->tcr[$this->nLine]["err"]) {
1386  $this->tcr[$this->nLine]["action"] = "ignored";
1387  return;
1388  }
1389  if (ctype_digit(trim($data[1]))) $wid = trim($data[1]);
1390  else {
1391  $pid = getIdFromName($this->dbaccess, trim($data[1]));
1392  $tdoc = getTDoc($this->dbaccess, $pid);
1393  $wid = getv($tdoc, "us_whatid");
1394  }
1395  $idapp = $action->parent->GetIdFromName($data[2]);
1396  if ($idapp == 0) {
1397  $this->tcr[$this->nLine]["err"] = sprintf(_("%s application not exists") , $data[2]);
1398  } else {
1399  $this->tcr[$this->nLine]["msg"] = "user #$wid";
1400  array_shift($data);
1401  array_shift($data);
1402  array_shift($data);
1403  $q = new QueryDb("", "Acl");
1404  $q->AddQuery("id_application=$idapp");
1405  $la = $q->Query(0, 0, "TABLE");
1406  if (!$la) {
1407  $this->tcr[$this->nLine]["err"] = sprintf(_("%s application has no aclss") , $data[2]);
1408  } else {
1409  $tacl = array();
1410  foreach ($la as $k => $v) {
1411  $tacl[$v["name"]] = $v["id"];
1412  }
1413 
1414  $p = new Permission();
1415  $p->id_user = $wid;
1416  $p->id_application = $idapp;
1417  foreach ($data as $v) {
1418  $v = trim($v);
1419  if ($v != "") {
1420  if ($this->analyze) {
1421  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("try add acl %s") , $v);
1422  $this->tcr[$this->nLine]["action"] = "added";
1423  continue;
1424  }
1425  if (substr($v, 0, 1) == '-') {
1426  $aclneg = true;
1427  $v = substr($v, 1);
1428  } else $aclneg = false;
1429  if (isset($tacl[$v])) {
1430  $p->id_acl = $tacl[$v];
1431  if ($aclneg) $p->id_acl = - $p->id_acl;
1432  $p->deletePermission($p->id_user, $p->id_application, $p->id_acl);
1433  $err = $p->Add();
1434  if ($err) $this->tcr[$this->nLine]["err"].= "\n$err";
1435  else {
1436  if ($aclneg) $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("add negative acl %s") , $v);
1437  else $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("add acl %s") , $v);
1438  }
1439  } else {
1440  $this->tcr[$this->nLine]["err"].= "\n" . sprintf(_("unknow acl %s") , $v);
1441  }
1442  }
1443  }
1444  }
1445  }
1446  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1447  }
1448  /**
1449  * analyze TAGABLE
1450  * @param array $data tagable parameter
1451  */
1452  protected function doTagable(array $data)
1453  {
1454  if (!$this->doc) {
1455  return;
1456  }
1457  if (class_exists("CheckTagable")) {
1458  /** @noinspection PhpUndefinedClassInspection
1459  * Defined in dynacase-tags module
1460  */
1461  $check = new CheckTagable();
1462  } else {
1463  $this->tcr[$this->nLine]["err"] = ErrorCode::getError('PROP0102', "TAGABLE", "dynacase-tags");
1464  $this->tcr[$this->nLine]["action"] = "ignored";
1465  error_log("ERROR:" . $this->tcr[$this->nLine]["err"]);
1466  return;
1467  }
1468  /*
1469  * @var CheckData $check
1470  */
1471  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
1472  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1473  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1474  $this->tcr[$this->nLine]["action"] = "warning";
1475  return;
1476  }
1477  if ($this->tcr[$this->nLine]["err"]) {
1478  $this->tcr[$this->nLine]["action"] = "ignored";
1479  return;
1480  }
1481  $this->doc->tagable = $data[1] === "no" ? "" : $data[1];
1482  $this->tcr[$this->nLine]["msg"] = sprintf(_("change tagable parameter to '%s'") , $this->doc->tagable);
1483  }
1484  /**
1485  * analyze PROFIL
1486  * @param array $data line of description file
1487  */
1488  protected function doProfil(array $data)
1489  {
1490  $check = new CheckProfil();
1491  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
1492  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1493  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1494  $this->tcr[$this->nLine]["action"] = "warning";
1495  return;
1496  }
1497  if ($this->tcr[$this->nLine]["err"]) {
1498  $this->tcr[$this->nLine]["action"] = "ignored";
1499  return;
1500  }
1501 
1502  if (ctype_digit(trim($data[1]))) $pid = trim($data[1]);
1503  else $pid = getIdFromName($this->dbaccess, trim($data[1]));
1504 
1505  if (!($pid > 0)) $this->tcr[$this->nLine]["err"] = sprintf(_("profil id unkonow %s") , $data[1]);
1506  else {
1507  clearCacheDoc(); // need to reset computed acls
1508 
1509  /*
1510  * @var PDoc $pdoc
1511  */
1512  $pdoc = new_Doc($this->dbaccess, $pid);
1513  if ($pdoc->isAlive()) {
1514  $this->tcr[$this->nLine]["msg"] = sprintf(_("change profil %s") , $data[1]);
1515  $this->tcr[$this->nLine]["action"] = "modprofil";
1516  if ($this->analyze) return;
1517  $fpid = $data[2];
1518  if (($fpid != "") && (!is_numeric($fpid))) $fpid = getIdFromName($this->dbaccess, $fpid);
1519  if ($fpid != "") {
1520  // profil related of other profil
1521  $pdoc->setProfil($fpid);
1522  $this->tcr[$this->nLine]["err"] = $pdoc->modify(false, array(
1523  "profid"
1524  ) , true);
1525  } else {
1526  // specific profil
1527  if ($pdoc->profid != $pid) {
1528  $pdoc->setProfil($pid);
1529  $pdoc->SetControl(false);
1530  $pdoc->disableEditControl(); // need because new profil is not enable yet
1531  $this->tcr[$this->nLine]["err"] = $pdoc->modify();
1532  }
1533 
1534  $defaultUseType = trim($data[2]);
1535  $optprof = strtoupper(trim($data[3]));
1536  $initialPerms = array();
1537  $profilingHasChanged = false;
1538  if ($optprof == "RESET") {
1539  $pdoc->removeControl();
1540  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("reset profil %s") , $pid);
1541  } elseif ($optprof == "SET") {
1542  $initialPerms = array_merge(DocPerm::getPermsForDoc($pdoc->id) , DocPermExt::getPermsForDoc($pdoc->id));
1543  $pdoc->removeControl();
1544  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("set profile %s") , $pid);
1545  }
1546  $tacls = array_slice($data, 2);
1547  foreach ($tacls as $acl) {
1548  if (preg_match("/([^=]+)=(.*)/", $acl, $reg)) {
1549  $tuid = explode(",", $reg[2]);
1550  $aclname = trim($reg[1]);
1551 
1552  $perr = "";
1553  if ($optprof == "DELETE") {
1554  foreach ($tuid as $uid) {
1555  $perr.= $pdoc->delControl($this->getProfilUid($defaultUseType, $uid) , $aclname);
1556  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("delete %s for %s") , $aclname, $uid);
1557  }
1558  } else { // the "ADD" by default
1559  foreach ($tuid as $uid) {
1560  $perr.= $pdoc->addControl($this->getProfilUid($defaultUseType, $uid) , $aclname);
1561  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("add %s for %s") , $aclname, $uid);
1562  }
1563  }
1564  $this->tcr[$this->nLine]["err"] = $perr;
1565  }
1566  }
1567  if ($optprof == "SET") {
1568  $newPerms = array_merge(DocPerm::getPermsForDoc($pdoc->id) , DocPermExt::getPermsForDoc($pdoc->id));
1569  $profilingHasChanged = (serialize($newPerms) != serialize($initialPerms));
1570  }
1571  if ($optprof == "RESET" || ($optprof == "SET" && $profilingHasChanged)) {
1572  // need reset all documents
1573  $pdoc->addHistoryEntry(_('Recomputing profiled documents') , DocHisto::INFO, 'RECOMPUTE_PROFILED_DOCUMENT');
1574  $pdoc->recomputeProfiledDocument();
1575  }
1576  }
1577  } else {
1578  $this->tcr[$this->nLine]["err"] = sprintf(_("profil id unknow %s") , $data[1]);
1579  }
1580  }
1581  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1582  }
1583 
1584  protected function getProfilUid($defaultReferenceType, $reference)
1585  {
1586 
1587  $reference = trim($reference);
1588  $this->extractAccount($defaultReferenceType, $reference, $type, $value);
1589  switch ($type) {
1590  case ':useAccount':
1591  return $this->getUserId($value);
1592  break;
1593 
1594  case ':useAttribute':
1595  return self::attributePrefix . $value;
1596  break;
1597 
1598  case ':useDocument':
1599  return self::documentPrefix . $value;
1600  break;
1601 
1602  default:
1603  return $value;
1604  }
1605  }
1606 
1607  private function extractAccount($defaultReferenceType, $reference, &$type, &$value)
1608  {
1609  if (preg_match('/^attribute\((.*)\)$/', $reference, $reg)) {
1610  $type = ":useAttribute";
1611  $value = trim($reg[1]);
1612  } elseif (preg_match('/^account\((.*)\)$/', $reference, $reg)) {
1613  $type = ":useAccount";
1614  $value = trim($reg[1]);
1615  } elseif (preg_match('/^document\((.*)\)$/', $reference, $reg)) {
1616  $type = ":useDocument";
1617  $value = trim($reg[1]);
1618  } else {
1619  $value = $reference;
1620  $type = $defaultReferenceType;
1621  }
1622  }
1623 
1624  protected function getUserId($login)
1625  {
1626  $login = mb_strtolower($login);
1627  if (!isset($this->userIds[$login])) {
1628  simpleQuery("", sprintf("select id from users where login='%s'", pg_escape_string($login)) , $uid, true, true);
1629  if (!$uid) {
1630  throw new \Dcp\Exception("PRFL0204", $login);
1631  }
1632  $this->userIds[$login] = $uid;
1633  }
1634  return $this->userIds[$login];
1635  }
1636  /**
1637  * analyze KEYS
1638  * @param array $data line of description file
1639  */
1640  protected function doKeys(array $data)
1641  {
1642  $check = new CheckKeys();
1643  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
1644  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1645  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1646  $this->tcr[$this->nLine]["action"] = "warning";
1647  return;
1648  }
1649  if ($this->tcr[$this->nLine]["err"]) {
1650  $this->tcr[$this->nLine]["action"] = "ignored";
1651  return;
1652  }
1653  if (is_numeric($data[1])) $orfromid = $data[1];
1654  else $orfromid = getFamIdFromName($this->dbaccess, $data[1]);
1655 
1656  $tkeys[$orfromid] = getOrder($data);
1657  if (($tkeys[$orfromid][0] == "") || (count($tkeys[$orfromid]) == 0)) {
1658  $this->tcr[$this->nLine]["err"] = sprintf(_("error in import keys : %s") , implode(" - ", $tkeys[$orfromid]));
1659  unset($tkeys[$orfromid]);
1660  $this->tcr[$this->nLine]["action"] = "ignored";
1661  } else {
1662  $this->tcr[$this->nLine]["msg"] = sprintf(_("new import keys : %s") , implode(" - ", $tkeys[$orfromid]));
1663  }
1664  }
1665  /**
1666  * analyze ORDER
1667  * @param array $data line of description file
1668  */
1669  protected function doOrder(array $data)
1670  {
1671  $check = new CheckOrder();
1672  $this->tcr[$this->nLine]["err"] = $check->check($data)->getErrors();
1673  $famName = $check->getParsedFamName();
1674  if ($this->tcr[$this->nLine]["err"]) {
1675  if ($famName !== false) {
1676  $this->badOrderErrors[$famName] = $this->tcr[$this->nLine]["err"];
1677  }
1678  if ($this->analyze) {
1679  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1680  $this->tcr[$this->nLine]["action"] = "warning";
1681  } else {
1682  $this->tcr[$this->nLine]["action"] = "ignored";
1683  }
1684  return;
1685  }
1686  if ($famName !== false && isset($this->badOrderErrors[$famName])) {
1687  unset($this->badOrderErrors[$famName]);
1688  }
1689  if (is_numeric($data[1])) $orfromid = $data[1];
1690  else $orfromid = getFamIdFromName($this->dbaccess, $data[1]);
1691 
1692  $this->colOrders[$orfromid] = getOrder($data);
1693  $this->tcr[$this->nLine]["msg"] = sprintf(_("new column order %s") , implode(" - ", $this->colOrders[$orfromid]));
1694  }
1695  /**
1696  * analyze LDAPMAP
1697  * @param array $data line of description file
1698  */
1699  protected function doLdapmap(array $data)
1700  {
1701  $err = '';
1702  if (is_numeric($data[1])) $fid = $data[1];
1703  else $fid = getFamIdFromName($this->dbaccess, $data[1]);
1704  $aid = (trim($data[2]));
1705  $index = $data[5];
1706  $oa = new DocAttrLDAP($this->dbaccess, array(
1707  $fid,
1708  $aid,
1709  $index
1710  ));
1711  // print_r2($oa);
1712  if (substr($data[2], 0, 2) == "::") $oa->ldapname = $data[2];
1713  else $oa->ldapname = strtolower(trim($data[2]));
1714 
1715  $oa->ldapclass = trim($data[4]);
1716  $oa->famid = $fid;
1717  $oa->ldapmap = $data[3];
1718  $oa->index = $index;
1719  $oa->ldapname = $aid;
1720 
1721  if ($oa->isAffected()) {
1722  if (!$this->analyze) $err = $oa->modify();
1723  $this->tcr[$this->nLine]["msg"] = sprintf(_("LDAP Attribute modified to %s %s") , $oa->ldapname, $oa->ldapmap);
1724  $this->tcr[$this->nLine]["action"] = "updated";
1725  } else {
1726  if (!$this->analyze) $err = $oa->add();
1727 
1728  $this->tcr[$this->nLine]["msg"] = sprintf(_("LDAP Attribute added to %s %s") , $oa->ldapname, $oa->ldapmap);
1729  $this->tcr[$this->nLine]["action"] = "added";
1730  }
1731  $this->tcr[$this->nLine]["err"].= $err;
1732  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1733  }
1734  /**
1735  * Verify compatibility between 2 type
1736  * @param string $curType
1737  * @param string $newType
1738  * @return bool
1739  */
1740  protected function isTypeCompatible($curType, $newType)
1741  {
1742  if ($curType == $newType) return true;
1743  $tc = array(
1744  "docid" => "account",
1745  "text" => "longtext",
1746  "longtext" => "htmltext",
1747  "file" => "image",
1748  "image" => "file",
1749  "integer" => "int", // old compatibility
1750  "float" => "double"
1751  // old compatibility
1752 
1753  );
1754  return isset($tc[$curType]) && ($tc[$curType] == $newType);
1755  }
1756  /**
1757  * analyze IATTR
1758  * @param array $data line of description file
1759  */
1760  protected function doAttr(array $data)
1761  {
1762 
1763  if (!$this->doc) return;
1764  $check = new CheckAttr();
1765  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1766  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1767  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1768  $this->tcr[$this->nLine]["action"] = "warning";
1769  return;
1770  }
1771  if ($this->tcr[$this->nLine]["err"]) {
1772  $this->tcr[$this->nLine]["action"] = "ignored";
1773  return;
1774  }
1775 
1776  if (!$this->structAttr) {
1777  $this->structAttr = new StructAttribute();
1778  }
1779  $this->structAttr->set($data);
1780 
1781  if (trim($data[1]) == '') {
1782  $this->tcr[$this->nLine]["err"].= sprintf(_("attr key is empty"));
1783  } else {
1784  $modattr = ($data[0] == "MODATTR");
1785  if ($data[0] == "MODATTR") $this->structAttr->id = ':' . $this->structAttr->id; // to mark the modified
1786  $this->tcr[$this->nLine]["msg"].= sprintf(_("update %s attribute") , $this->structAttr->id);
1787  if ($this->analyze) return;
1788  $oattr = new DocAttr($this->dbaccess, array(
1789  $this->doc->id,
1790  strtolower($this->structAttr->id)
1791  ));
1792 
1793  if ($oattr->isAffected()) {
1794  // modification of type is forbidden
1795  $curType = trim(strtok($oattr->type, '('));
1796  $newType = trim(strtok($this->structAttr->type, '('));
1797  if ($curType != $newType && (!$this->isTypeCompatible($curType, $newType))) {
1798  $this->tcr[$this->nLine]["err"].= sprintf("cannot change attribute %s type definition from %s to %s", $this->structAttr->id, $curType, $newType);
1799  }
1800  // modification of target is forbidden
1801  if (($data[0] == "PARAM") && ($oattr->usefor != 'Q')) {
1802  $this->tcr[$this->nLine]["err"].= sprintf("cannot change attribute declaration to PARAM for %s", $this->structAttr->id);
1803  } elseif (($data[0] == "ATTR") && ($oattr->usefor == 'Q')) {
1804  $this->tcr[$this->nLine]["err"].= sprintf("cannot change attribute declaration to ATTR for %s", $this->structAttr->id);
1805  }
1806  }
1807 
1808  if (!$this->tcr[$this->nLine]["err"]) {
1809  if ($data[0] == "PARAM") $oattr->usefor = 'Q'; // parameters
1810  elseif ($data[0] == "OPTION") $oattr->usefor = 'O'; // options
1811  else $oattr->usefor = 'N'; // normal
1812  $oattr->docid = $this->doc->id;
1813  $oattr->id = trim(strtolower($this->structAttr->id));
1814 
1815  $oattr->frameid = trim(strtolower($this->structAttr->setid));
1816  $oattr->labeltext = $this->structAttr->label;
1817 
1818  $oattr->title = ($this->structAttr->istitle == "Y") ? "Y" : "N";
1819 
1820  $oattr->abstract = ($this->structAttr->isabstract == "Y") ? "Y" : "N";
1821  if ($modattr) $oattr->abstract = $this->structAttr->isabstract;
1822 
1823  $oattr->type = trim($this->structAttr->type);
1824 
1825  $oattr->ordered = $this->structAttr->order;
1826  $oattr->visibility = $this->structAttr->visibility;
1827  $oattr->needed = ($this->structAttr->isneeded == "Y") ? "Y" : "N";
1828  if ($modattr) {
1829  $oattr->title = $this->structAttr->istitle;
1830  $oattr->needed = $this->structAttr->isneeded;
1831  }
1832  $oattr->link = $this->structAttr->link;
1833  $oattr->phpfile = $this->structAttr->phpfile;
1834  if ($this->structAttr->elink) $oattr->elink = $this->structAttr->elink;
1835  else $oattr->elink = '';
1836  if ($this->structAttr->constraint) $oattr->phpconstraint = $this->structAttr->constraint;
1837  else $oattr->phpconstraint = '';
1838  if ($this->structAttr->options) $oattr->options = $this->structAttr->options;
1839  else $oattr->options = '';
1840 
1841  if (((($this->structAttr->phpfile != "") && ($this->structAttr->phpfile != "-")) || (($this->structAttr->type != "enum") && ($this->structAttr->type != "enumlist"))) || ($oattr->phpfunc == "") || (strpos($oattr->options, "system=yes") !== false)) {
1842  // don't modify enum possibilities if exists and non system
1843  $oattr->phpfunc = $this->structAttr->phpfunc;
1844  if ($oattr->type == "enum") {
1845  if (strlen($this->structAttr->phpfile) < 2) {
1846  // don't record if enum comes from function
1847  $reset = (strpos($oattr->options, "system=yes") !== false);
1848  $this->recordEnum($this->doc->id, $oattr->id, $this->structAttr->phpfunc, $reset);
1849  //$oattr->phpfunc = "-";
1850 
1851  }
1852  }
1853  }
1854  if ($oattr->ordered && !is_numeric($oattr->ordered)) {
1855  $oattr->options.= ($oattr->options) ? "|" : "";
1856  $oattr->options.= sprintf("relativeOrder=%s", $oattr->ordered);
1857  $oattr->ordered = $this->nLine;
1858  }
1859  if ($oattr->isAffected()) $err = $oattr->Modify();
1860  else $err = $oattr->Add();
1861  $this->addImportedAttribute($this->doc->id, $oattr);
1862 
1863  $this->tcr[$this->nLine]["err"].= $err;
1864  }
1865  }
1866  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1867  }
1868  /**
1869  * @param int $famid family identifier
1870  * @param string $attrid attribute identifier
1871  * @param string $phpfunc enum flat description
1872  * @param bool $reset set to true to delete old items before recorded
1873  * @return string error message
1874  */
1875  public static function recordEnum($famid, $attrid, $phpfunc, $reset = false)
1876  {
1877  static $oe = null;
1878 
1879  $err = '';
1880  if ($oe === null) $oe = new DocEnum();
1881  $enums = array();
1883  $oe->famid = $famid;
1884  $oe->attrid = $attrid;
1885  $oe->eorder = 0;
1886  if ($reset) {
1887  $sql = sprintf("delete from docenum where famid='%s' and attrid='%s'", pg_escape_string($famid) , pg_escape_string($attrid));
1888  simpleQuery('', $sql);
1889  }
1890 
1891  foreach ($enums as $itemKey => $itemLabel) {
1892  $oe->label = $itemLabel;
1893  $oe->eorder++;
1894  $antiItemKey = str_replace("\\.", "--dot--", $itemKey);
1895  if (strpos($antiItemKey, '.') !== false) {
1896  $tkeys = explode(".", $itemKey);
1897  $oe->key = array_pop($tkeys);
1898  $oe->parentkey = array_pop($tkeys);
1899  } else {
1900 
1901  $oe->key = str_replace("\\.", ".", $itemKey);
1902 
1903  $oe->parentkey = '';
1904  }
1905  $err = '';
1906  if ($oe->exists()) {
1907  // $err=$oe->add();
1908  // " skipped [$itemKey]";
1909 
1910  } else {
1911  // " added [$itemKey]";
1912  $err.= $oe->add();
1913  }
1914  }
1915  return $err;
1916  }
1917  /**
1918  * analyze IATTR
1919  * @param array $data line of description file
1920  */
1921  protected function doIattr(array $data)
1922  {
1923  if (!$this->doc) return;
1924  // import attribute definition from another family
1925  $err = '';
1926  $fiid = $data[3];
1927  if (!is_numeric($fiid)) $fiid = getFamIdFromName($this->dbaccess, $fiid);
1928  $fi = new_Doc($this->dbaccess, $fiid);
1929  if ($fi->isAffected()) {
1930  $fa = $fi->getAttribute($data[1]);
1931  if ($fa) {
1932  $oattri = new DocAttr($this->dbaccess, array(
1933  $fiid,
1934  strtolower($data[1])
1935  ));
1936  $oattr = new DocAttr($this->dbaccess, array(
1937  $this->doc->id,
1938  strtolower($data[1])
1939  ));
1940  $oattri->docid = $this->doc->id;
1941  $this->tcr[$this->nLine]["msg"] = sprintf(_("copy attribute %s from %s") , $data[1], $data[3]);
1942  if (!$this->analyze) {
1943  if ($oattr->isAffected()) {
1944  $err = $oattri->modify();
1945  } else {
1946  $oattri->id = strtolower($data[1]);
1947  $err = $oattri->add();
1948  }
1949  $this->tcr[$this->nLine]["err"] = $err;
1950  }
1951 
1952  if (($err == "") && (strtolower(get_class($fa)) == "fieldsetattribute")) {
1953  $frameid = $fa->id;
1954  // import attributes included in fieldset
1955  foreach ($fi->attributes->attr as $k => $v) {
1956  if (strtolower(get_class($v)) == "normalattribute") {
1957 
1958  if (($v->fieldSet->id == $frameid) || ($v->fieldSet->fieldSet->id == $frameid)) {
1959  $this->tcr[$this->nLine]["msg"].= "\n" . sprintf(_("copy attribute %s from %s") , $v->id, $data[3]);
1960  $oattri = new DocAttr($this->dbaccess, array(
1961  $fiid,
1962  $v->id
1963  ));
1964  $oattr = new DocAttr($this->dbaccess, array(
1965  $this->doc->id,
1966  $v->id
1967  ));
1968  $oattri->docid = $this->doc->id;
1969  if (!$this->analyze) {
1970  if ($oattr->isAffected()) {
1971  $err = $oattri->modify();
1972  } else {
1973  $oattri->id = $v->id;
1974  $err = $oattri->add();
1975  }
1976  $this->tcr[$this->nLine]["err"].= $err;
1977  }
1978  }
1979  }
1980  }
1981  }
1982  }
1983  }
1984  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
1985  }
1986  /**
1987  * analyze PROP
1988  * @param array $data line of description file
1989  */
1990  protected function doProp($data)
1991  {
1992  $check = new CheckProp();
1993  $this->tcr[$this->nLine]["err"] = $check->check($data, $this->doc)->getErrors();
1994  if ($this->tcr[$this->nLine]["err"] && $this->analyze) {
1995  $this->tcr[$this->nLine]["msg"] = sprintf(_("Element can't be perfectly analyze, some error might occur or be corrected when importing"));
1996  $this->tcr[$this->nLine]["action"] = "warning";
1997  return;
1998  }
1999  if ($this->tcr[$this->nLine]["err"]) {
2000  $this->tcr[$this->nLine]["action"] = "ignored";
2001  return;
2002  }
2003 
2004  $propName = $check->propName;
2005  $values = $check->parameters;
2006 
2007  if ($this->analyze) {
2008  return;
2009  }
2010 
2011  foreach ($values as $value) {
2012  $pName = $value['name'];
2013  $pValue = $value['value'];
2014  if (!$this->doc->setPropertyParameter($propName, $pName, $pValue)) {
2015  $this->tcr[$this->nLine]["err"].= sprintf(_("error storing configuration property (%s, %s, %s)") , $propName, $pName, $pValue);
2016  return;
2017  }
2018  }
2019  if ($this->tcr[$this->nLine]["err"]) $this->tcr[$this->nLine]["action"] = "ignored";
2020  }
2021  protected function addImportedAttribute($famId, DocAttr & $oa)
2022  {
2023  if (!isset($this->importedAttribute[$famId])) {
2024  $this->importedAttribute[$famId] = array();
2025  }
2026  $this->importedAttribute[$famId][$oa->id] = $oa;
2027  }
2028  public function getImportedAttribute($famId, $attrId)
2029  {
2030  if (isset($this->importedAttribute[$famId][$attrId])) {
2031  return $this->importedAttribute[$famId][$attrId];
2032  }
2033  return false;
2034  }
2035 }
2036 
static verifyDbFamily($famid, NormalAttribute $aoa=null)
Check PROP import lines.
Definition: CheckProp.php:12
setCsvOptions($csvSeparator= ';', $csvEnclosure= '"', $csvLinebreak = '\n')
seemsODS($filename)
$tdoc
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
global $action
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
Check profil when importing definition.
Definition: CheckProfil.php:12
getProfilUid($defaultReferenceType, $reference)
clearCacheDoc($id=0)
getv(&$t, $k, $d="")
static detectAutoCsvOptions($csvFileName, &$separator= 'auto', &$enclosure= 'auto')
addImportedAttribute($famId, DocAttr &$oa)
static getPermsForDoc($docid)
setVerifyAttributeAccess($verifyAttributeAccess)
const SEPCHAR
Definition: import_file.php:26
const ALTSEPCHAR
Definition: import_file.php:25
static getError($code, $args=null)
Definition: ErrorCode.php:27
getOrder(array $orderdata)
Definition: import_file.php:97
isUTF8($string)
Definition: Lib.Common.php:748
static flatEnumNotationToEnumArray($phpfunc, array &$theEnum, array &$theEnumlabel=array(), $locale= '')
Check application accesses when importing definition.
Definition: CheckAccess.php:12
static getPermsForDoc($docid)
$idoc
Definition: csv2sql.php:34
Check application accesses when importing definition.
Definition: checkAttr.php:12
$search
static recordEnum($famid, $attrid, $phpfunc, $reset=false)
static createDocFile($dbaccess, $tdoc)
createAutoFolder(&$doc)
$force
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
$login
Definition: dav.php:40
$oe
Definition: migrEnum.php:37
getFamIdFromName($dbaccess, $name)
getDbAccess()
Definition: Lib.Common.php:368
ods2csv($odsfile)
new_Doc($dbaccess, $id= '', $latest=false)
$dir
Definition: resizeimg.php:144
setMaxExecutionTimeTo($limit)
Definition: Lib.Common.php:121
getIdFromName($dbaccess, $name)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
static refreshPhpPgDoc($dbaccess, $docid)
if($file) if($subject==""&&$file) if($subject=="") $err
Check family profid property when importing definition.
Definition: CheckProfid.php:12
$value
$data
← centre documentaire © anakeen