Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocHtmlFormat.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Get Html Value for document
8  * @class DocHtmlFormat
9  *
10  */
12 {
13  /**
14  * @var Doc
15  */
16  public $doc = null;
17  private $index = - 1;
18  private $target = '_self';
19  /**
20  * @var NormalAttribute
21  */
22  private $oattr = null;
23  private $attrid = '';
24  /**
25  * format set in type
26  * @var string
27  */
28  private $cFormat = '';
29  private $cancelFormat = false;
30  private $htmlLink = true;
31  private $useEntities = true;
32  private $abstractMode = false;
33  /**
34  * @var bool to send once vault error
35  */
36  private $vaultErrorSent = false;
37 
38  public function __construct(Doc & $doc)
39  {
40  $this->setDoc($doc);
41  }
42 
43  public function setDoc(Doc & $doc)
44  {
45  $this->doc = $doc;
46  }
47  /**
48  * get html fragment for a value of an attribute
49  * for multiple values if index >= 0 the value must be the ith value of array values
50  * @param NormalAttribute $oattr
51  * @param string $value raw value
52  * @param string $target
53  * @param bool $htmlLink
54  * @param int $index
55  * @param bool $useEntities
56  * @param bool $abstractMode
57  * @return string the HTML formated value
58  */
59  public function getHtmlValue($oattr, $value, $target = "_self", $htmlLink = true, $index = - 1, $useEntities = true, $abstractMode = false)
60  {
61  global $action;
62 
63  $this->oattr = $oattr;
64  $this->target = $target;
65  $this->index = $index;
66  $this->cFormat = $this->oattr->format;
67  $this->cancelFormat = false;
68  $atype = $this->oattr->type;
69  $this->htmlLink = $htmlLink;
70  $this->useEntities = $useEntities;
71  $this->abstractMode = $abstractMode;
72 
73  $showEmpty = $this->oattr->getOption('showempty');
74 
75  if (($this->oattr->repeat) && ($this->index < 0)) {
76  $tvalues = explode("\n", $value);
77  } else {
78  $tvalues[$this->index] = $value;
79  }
80  $this->attrid = $this->oattr->id;
81  $thtmlval = array();
82  foreach ($tvalues as $kvalue => $avalue) {
83  if ($abstractMode && empty($avalue) && !$showEmpty) {
84  $thtmlval[$kvalue] = '';
85  } else {
86  switch ($atype) {
87  case "image":
88  $htmlval = $this->formatImage($kvalue, $avalue);
89  break;
90 
91  case "file":
92 
93  $htmlval = $this->formatFile($kvalue, $avalue);
94  break;
95 
96  case "longtext":
97  case "xml":
98 
99  $htmlval = $this->formatLongtext($kvalue, $avalue);
100  break;
101 
102  case "password":
103 
104  $htmlval = $this->formatPassword($kvalue, $avalue);
105  break;
106 
107  case "enum":
108 
109  $htmlval = $this->formatEnum($kvalue, $avalue);
110  break;
111 
112  case "array":
113 
114  $htmlval = $this->formatArray($kvalue, $avalue);
115  break;
116 
117  case "doc":
118  $htmlval = $this->formatDoc($kvalue, $avalue);
119  break;
120 
121  case "account":
122  $htmlval = $this->formatAccount($kvalue, $avalue);
123  break;
124 
125  case "docid":
126  $htmlval = $this->formatDocid($kvalue, $avalue);
127  break;
128 
129  case "thesaurus":
130 
131  $htmlval = $this->formatThesaurus($kvalue, $avalue);
132  break;
133 
134  case "option":
135 
136  $htmlval = $this->formatOption($kvalue, $avalue);
137  break;
138 
139  case 'money':
140 
141  $htmlval = $this->formatMoney($kvalue, $avalue);
142  break;
143 
144  case 'htmltext':
145 
146  $htmlval = $this->formatHtmltext($kvalue, $avalue);
147  break;
148 
149  case 'date':
150 
151  $htmlval = $this->formatDate($kvalue, $avalue);
152  break;
153 
154  case 'time':
155 
156  $htmlval = $this->formatTime($kvalue, $avalue);
157  break;
158 
159  case 'timestamp':
160 
161  $htmlval = $this->formatTimeStamp($kvalue, $avalue);
162 
163  break;
164 
165  case 'ifile':
166 
167  $htmlval = $this->formatIfile($kvalue, $avalue);
168  break;
169 
170  case 'color':
171  $htmlval = $this->formatColor($kvalue, $avalue);
172  break;
173 
174  default:
175  $htmlval = $this->formatDefault($kvalue, $avalue);
176 
177  break;
178  }
179 
180  $abegin = $aend = '';
181 
182  if ($htmlval === '' && $showEmpty) {
183  if ($abstractMode) {
184  // if we are not in abstract mode, the same heuristic is at array level,
185  // but arrays does not exists in abstract mode
186  if (!$oattr->inArray()) {
187  $htmlval = $showEmpty;
188  } elseif ((count($tvalues) > 1)) {
189  // we are in an array, ensure the array is not totally empty
190  $htmlval = $showEmpty;
191  }
192  } else {
193  $htmlval = $showEmpty;
194  }
195  } elseif ($htmlval === "\t" && $oattr->inArray() && $showEmpty) {
196  // array with single empty line
197  $htmlval = $showEmpty;
198  } elseif (($this->cFormat != "" && $this->cancelFormat === false) && ($htmlval !== '') && ($atype != "doc") && ($atype != "array") && ($atype != "option")) {
199  //printf($htmlval);
200  $htmlval = sprintf($this->cFormat, $htmlval);
201  }
202  // add link if needed
203  if ($this->htmlLink && ($this->oattr->link != "")) {
204  $ititle = "";
205  $hlink = $this->oattr->link;
206  if ($hlink[0] == "[") {
207  if (preg_match('/\[(.*)\](.*)/', $hlink, $reg)) {
208  $hlink = $reg[2];
209  $ititle = str_replace("\"", "'", $reg[1]);
210  }
211  }
212  if ($ulink = $this->doc->urlWhatEncode($hlink, $kvalue)) {
213  if ($this->target == "ext") {
214  if (preg_match("/FDL_CARD.*id=([0-9]+)/", $ulink, $reg)) {
215 
216  $abegin = $this->doc->getDocAnchor($reg[1], $this->target, true, html_entity_decode($htmlval, ENT_QUOTES, 'UTF-8'));
217  $htmlval = '';
218  $aend = "";
219  } else if (true || preg_match("/^http:/", $ulink, $reg)) {
220  $ec = getSessionValue("ext:targetUrl");
221 
222  if ($ec) {
223  $ec = str_replace("%V%", $ulink, $ec);
224  $ec = str_replace("%L%", $this->oattr->getLabel() , $ec);
225  $ecu = str_replace("'", "\\'", $this->doc->urlWhatEncode($ec));
226  $abegin = "<a onclick='parent.$ecu'>";
227  } else {
228  $ltarget = $this->oattr->getOption("ltarget");
229  $abegin = "<a target=\"$ltarget\" href=\"$ulink\">";
230  }
231 
232  $aend = "</a>";
233  }
234  } else if ($this->target == "mail") {
235  $scheme = "";
236  if (preg_match("/^([[:alpha:]]*):(.*)/", $ulink, $reg)) {
237  $scheme = $reg[1];
238  }
239  $abegin = "<a target=\"$this->target\" href=\"";
240  if ($scheme == "") $abegin.= $action->GetParam("CORE_URLINDEX", ($action->GetParam("CORE_ABSURL") . "/")) . $ulink;
241  else $abegin.= $ulink;
242  $abegin.= "\">";
243  $aend = "</a>";
244  } else {
245  $ltarget = $this->oattr->getOption("ltarget");
246  if ($ltarget != "") $this->target = $ltarget;
247  $ltitle = $this->oattr->getOption("ltitle");
248  if ($ltitle != "") $ititle = str_replace("\"", "'", $ltitle);
249  $abegin = "<a target=\"$this->target\" title=\"$ititle\" onmousedown=\"document.noselect=true;\" href=\"";
250  $abegin.= $ulink . "\" ";
251  if ($this->htmlLink > 1) {
252  $scheme = "";
253  if (preg_match("/^([[:alpha:]]*):(.*)/", $ulink, $reg)) {
254  $scheme = $reg[1];
255  }
256  if (($scheme == "") || ($scheme == "http")) {
257  if ($scheme == "") $ulink.= "&ulink=1";
258  $abegin.= " oncontextmenu=\"popdoc(event,'$ulink');return false;\" ";
259  }
260  }
261  $abegin.= ">";
262  $aend = "</a>";
263  }
264  } else {
265  $abegin = "";
266  $aend = "";
267  }
268  } else {
269  $abegin = "";
270  $aend = "";
271  }
272 
273  $thtmlval[$kvalue] = $abegin . $htmlval . $aend;
274  }
275  }
276 
277  return implode("<BR>", $thtmlval);
278  }
279  /**
280  * format Default attribute
281  * @param $kvalue
282  * @param $avalue
283  * @return string HTML value
284  */
285  public function formatDefault($kvalue, $avalue)
286  {
287  if ($this->useEntities) $avalue = htmlentities(($avalue) , ENT_COMPAT, "UTF-8");
288  else $avalue = ($avalue);
289  $htmlval = str_replace(array(
290  "[",
291  "$"
292  ) , array(
293  "&#091;",
294  "&#036;"
295  ) , $avalue);
296  return $htmlval;
297  }
298  /**
299  * format Image attribute
300  * @param $kvalue
301  * @param $avalue
302  * @return string HTML value
303  */
304  public function formatImage($kvalue, $avalue)
305  {
306 
307  global $action;
308  if ($this->target == "mail") {
309  $htmlval = "cid:" . $this->oattr->id;
310  if ($this->index >= 0) $htmlval.= "+$this->index";
311  }
312  if ($this->target == "te") {
313  $htmlval = "file://" . $this->doc->vault_filename($this->oattr->id, true, $kvalue);
314  } else {
315  if (preg_match(PREGEXPFILE, $avalue, $reg)) {
316  $fileInfo = new VaultFileInfo();
317  $vf = newFreeVaultFile($this->doc->dbaccess);
318  if ($vf->Show($reg[2], $fileInfo) == "") {
319  if (!file_exists($fileInfo->path)) {
320  if (!$vf->storage->fs->isAvailable()) {
321  if (!$this->vaultErrorSent) addWarningMsg(sprintf(_("cannot access to vault file system")));
322  $this->vaultErrorSent = true;
323  } else {
324  addWarningMsg(sprintf(_("file %s not found") , $fileInfo->name));
325  }
326  }
327  }
328  if (($this->oattr->repeat) && ($this->index <= 0)) $idx = $kvalue;
329  else $idx = $this->index;
330  $inline = $this->oattr->getOption("inline");
331  $htmlval = $this->doc->getFileLink($this->oattr->id, $idx, false, ($inline == "yes") , $avalue, $fileInfo);
332  } else {
333  if (empty($avalue)) {
334  $localImage = $this->oattr->getOption('showempty');
335  if ($localImage) {
336  $htmlval = $action->parent->getImageLink($localImage);
337  } else {
338  $htmlval = $action->parent->getImageLink($avalue);
339  }
340  } else {
341  $htmlval = $action->parent->getImageLink($avalue);
342  }
343  }
344  }
345  return $htmlval;
346  }
347  /**
348  * format File attribute
349  * @param $kvalue
350  * @param $avalue
351  * @return string HTML value
352  */
353  public function formatFile($kvalue, $avalue)
354  {
355  static $vf = null;
356 
357  if (!$vf) $vf = newFreeVaultFile($this->doc->dbaccess);
358  $vid = "";
359  $fileInfo = false;
360  $mime = '';
361  $fname = _("no file");
362  $htmlval = '';
363  if (preg_match(PREGEXPFILE, $avalue, $reg)) {
364  // reg[1] is mime type
365  $vid = $reg[2];
366  $mime = $reg[1];
367  include_once ("FDL/Lib.Dir.php");
368 
369  $fileInfo = new VaultFileInfo();
370  if ($vf->Show($reg[2], $fileInfo) == "") {
371  $fname = $fileInfo->name;
372  if (!file_exists($fileInfo->path)) {
373  if (!$vf->storage->fs->isAvailable()) {
374  if (!$this->vaultErrorSent) addWarningMsg(sprintf(_("Cannot access to vault file system")));
375  $this->vaultErrorSent = true;
376  } else {
377  addWarningMsg(sprintf(_("file %s not found") , $fileInfo->name));
378  }
379 
380  $fname.= ' ' . _("(file not found)");
381  }
382  } else $htmlval = _("vault file error");
383  } else {
384  if ($this->oattr->getOption('showempty')) {
385  $htmlval = $this->oattr->getOption('showempty');
386  $this->cancelFormat = true;
387  } else {
388  $htmlval = _("no filename");
389  }
390  }
391 
392  if ($this->target == "mail") {
393  $htmlval = "<a target=\"_blank\" href=\"";
394  $htmlval.= "cid:" . $this->oattr->id;
395  if ($this->index >= 0) $htmlval.= "+$this->index";
396  $htmlval.= "\">" . htmlspecialchars($fname, ENT_QUOTES) . "</a>";
397  } else {
398  if ($fileInfo) {
399  if ($fileInfo->teng_state < 0 || $fileInfo->teng_state > 1) {
400  $htmlval = "";
401  if (\Dcp\Autoloader::classExists('Dcp\TransformationEngine\Client')) {
402  switch (intval($fileInfo->teng_state)) {
403  case \Dcp\TransformationEngine\Client::error_convert: // convert fail
404  $textval = _("file conversion failed");
405  break;
406 
407  case \Dcp\TransformationEngine\Client::error_noengine: // no compatible engine
408  $textval = _("file conversion not supported");
409  break;
410 
411  case \Dcp\TransformationEngine\Client::error_connect: // no compatible engine
412  $textval = _("cannot contact server");
413  break;
414 
415  case \Dcp\TransformationEngine\Client::status_waiting: // waiting
416  $textval = _("waiting conversion file");
417  break;
418 
419  case \Dcp\TransformationEngine\Client::status_inprogress: // in progress
420  $textval = _("generating file");
421  break;
422 
423  default:
424  $textval = sprintf(_("unknown file state %s") , $fileInfo->teng_state);
425  }
426  } else {
427  $textval = sprintf(_("unknown file state %s") , $fileInfo->teng_state);
428  }
429  if ($this->htmlLink) {
430  //$errconvert=trim(file_get_contents($info->path));
431  //$errconvert=sprintf('<p>%s</p>',str_replace(array("'","\r","\n"),array("&rsquo;",""),nl2br(htmlspecialchars($errconvert,ENT_COMPAT,"UTF-8"))));
432  if ($fileInfo->teng_state > 1) $waiting = "<img class=\"mime\" src=\"Images/loading.gif\">";
433  else $waiting = "<img class=\"mime\" needresize=1 src=\"Images/bullet_error.png\">";
434  $htmlval = sprintf('<a _href_="%s" vid="%d" onclick="popdoc(event,this.getAttribute(\'_href_\')+\'&inline=yes\',\'%s\')">%s %s</a>', $this->doc->getFileLink($this->oattr->id, $this->index) , $fileInfo->id_file, str_replace("'", "&rsquo;", _("file status")) , $waiting, $textval);
435  if ($fileInfo->teng_state < 0) {
436  $htmlval.= sprintf('<a href="?app=FDL&action=FDL_METHOD&id=%d&method=resetConvertVaultFile(\'%s,%s)"><img class="mime" title="%s" src="%s"></a>', $this->doc->id, $this->oattr->id, $this->index, _("retry file conversion") , "Images/arrow_refresh.png");
437  }
438  } else {
439  $htmlval = $textval;
440  }
441  } elseif ($this->htmlLink) {
442 
443  $mimeicon = getIconMimeFile($fileInfo->mime_s == "" ? $mime : $fileInfo->mime_s);
444  if (($this->oattr->repeat) && ($this->index <= 0)) $idx = $kvalue;
445  else $idx = $this->index;
446  $standardview = true;
447  $infopdf = false;
448  $viewfiletype = $this->oattr->getOption("viewfiletype");
449  $imageview = false;
450  $pages = 0;
451  if ($viewfiletype == "image" || $viewfiletype == "pdf") {
452  global $action;
453  $waiting = false;
454  if (substr($fileInfo->mime_s, 0, 5) == "image") {
455  $imageview = true;
456  $viewfiletype = 'png';
457  $pages = 1;
458  } elseif (substr($fileInfo->mime_s, 0, 4) == "text") {
459  $imageview = true;
460  $viewfiletype = 'embed';
461  $pages = 1;
462  } else {
463  $infopdf = new VaultFileInfo();
464  $err = $vf->Show($vid, $infopdf, 'pdf');
465  if ($err == "" && \Dcp\Autoloader::classExists('Dcp\TransformationEngine\Client')) {
466  if ($infopdf->teng_state == \Dcp\TransformationEngine\Client::status_done || $infopdf->teng_state == \Dcp\TransformationEngine\Client::status_waiting || $infopdf->teng_state == \Dcp\TransformationEngine\Client::status_inprogress) {
467  $imageview = true;
468  if ($viewfiletype == 'image') $viewfiletype = 'png';
469  else if ($viewfiletype == 'pdf') $viewfiletype = 'embed';
470 
471  $pages = getPdfNumberOfPages($infopdf->path);
472  if ($infopdf->teng_state == \Dcp\TransformationEngine\Client::status_waiting || $infopdf->teng_state == \Dcp\TransformationEngine\Client::status_inprogress) $waiting = true;
473  }
474  }
475  }
476 
477  if ($imageview && (!$this->abstractMode)) {
478  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/widgetFile.js");
479  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/detectPdfPlugin.js");
480  $lay = new Layout("FDL/Layout/viewfileimage.xml", $action);
481  $lay->set("docid", $this->doc->id);
482  $lay->set("waiting", ($waiting ? 'true' : 'false'));
483  $lay->set("attrid", $this->oattr->id);
484  $lay->set("index", $idx);
485  $lay->set("viewtype", $viewfiletype);
486  $lay->set("mimeicon", $mimeicon);
487  $lay->set("vid", ($infopdf ? $infopdf->id_file : $vid));
488  $lay->set("filetitle", json_encode((string)$fname));
489  $lay->set("height", $this->oattr->getOption('viewfileheight', '300px'));
490  $lay->set("filelink", $this->doc->getFileLink($this->oattr->id, $idx, false, false));
491 
492  $lay->set("pdflink", '');
493  if ($pdfattr = $this->oattr->getOption('pdffile')) {
494  //$infopdf=$this->doc->vault_properties($this->doc->getAttribute($pdfattr));
495  if (!preg_match('/^(text|image)/', $fileInfo->mime_s)) {
496  //$pdfidx=($idx <0)?0:$idx;
497  if ($waiting || preg_match('/(pdf)/', $infopdf->mime_s)) {
498  $lay->set("pdflink", $this->doc->getFileLink($pdfattr, $idx, false, false));
499  }
500  }
501  }
502  $lay->set("pages", $pages); // todo
503  $htmlval = $lay->gen();
504  $standardview = false;
505  }
506  }
507  if ($standardview) {
508  global $action;
509  $size = self::human_size($fileInfo->size);
510  $utarget = ($action->Read("navigator", "") == "NETSCAPE") ? "_self" : "_blank";
511  $inline = $this->oattr->getOption("inline");
512  $htmlval = "<a onmousedown=\"document.noselect=true;\" title=\"$size\" target=\"$utarget\" type=\"$mime\" href=\"" . $this->doc->getFileLink($this->oattr->id, $idx, false, ($inline == "yes") , $avalue, $fileInfo) . "\">";
513  if ($mimeicon) $htmlval.= "<img class=\"mime\" needresize=1 src=\"Images/$mimeicon\">&nbsp;";
514  $htmlval.= htmlspecialchars($fname, ENT_QUOTES) . "</a>";
515  }
516  } else {
517  $htmlval = $fileInfo->name;
518  }
519  }
520  }
521  return $htmlval;
522  }
523  /**
524  * format Longtext attribute
525  * @param $kvalue
526  * @param $avalue
527  * @return string HTML value
528  */
529  public function formatLongtext($kvalue, $avalue)
530  {
531  if ($this->useEntities) $bvalue = nl2br(htmlentities((str_replace("<BR>", "\n", $avalue)) , ENT_COMPAT, "UTF-8"));
532  else $bvalue = (str_replace("<BR>", "\n", $avalue));
533  $shtmllink = $this->htmlLink ? "true" : "false";
534  $bvalue = preg_replace_callback('/(\[|&#x5B;)ADOC ([^\]]*)\]/', function ($matches) use ($shtmllink)
535  {
536  return $this->doc->getDocAnchor($matches[2], $this->target, $shtmllink);
537  }
538  , $bvalue);
539  $htmlval = str_replace(array(
540  "[",
541  "$"
542  ) , array(
543  "&#091;",
544  "&#036;"
545  ) , $bvalue);
546  return $htmlval;
547  }
548  /**
549  * format Password attribute
550  * @param $kvalue
551  * @param $avalue
552  * @return string HTML value
553  */
554  public function formatPassword($kvalue, $avalue)
555  {
556  if (strlen($avalue) > 0) {
557  $htmlval = '*****';
558  } else {
559  $htmlval = '';
560  }
561  return $htmlval;
562  }
563  /**
564  * format Enum attribute
565  * @param $kvalue
566  * @param $avalue
567  * @return string HTML value
568  */
569  public function formatEnum($kvalue, $avalue)
570  {
571  $enumlabel = $this->oattr->getEnumlabel();
572  $colors = $this->oattr->getOption("boolcolor");
573  if ($colors != "") {
574  if (isset($enumlabel[$avalue])) {
575  reset($enumlabel);
576  $tcolor = explode(",", $colors);
577  if (current($enumlabel) == $enumlabel[$avalue]) {
578  $color = $tcolor[0];
579  $htmlval = sprintf('<pre style="background-color:%s;display:inline">&nbsp;-&nbsp;</pre>', $color);
580  } else {
581  $color = $tcolor[1];
582  $htmlval = sprintf('<pre style="background-color:%s;display:inline">&nbsp;&bull;&nbsp;</pre>', $color);
583  }
584  } else $htmlval = $avalue;
585  } else {
586  if (array_key_exists($avalue, $enumlabel)) $htmlval = $enumlabel[$avalue];
587  else $htmlval = $avalue;
588  }
589  return $htmlval;
590  }
591  /**
592  * format Array attribute
593  * @param $kvalue
594  * @param $avalue
595  * @return string HTML value
596  */
597  public function formatArray($kvalue, $avalue)
598  {
599 
600  global $action;
601  $htmlval = '';
602  if (count($this->doc->getArrayRawValues($this->oattr->id)) == 0 && $this->oattr->getOption('showempty')) {
603  $htmlval = $this->oattr->getOption('showempty');
604  return $htmlval;
605  }
606  $viewzone = $this->oattr->getOption("rowviewzone");
607  $sort = $this->oattr->getOption("sorttable");
608  if ($sort == "yes") {
609  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FREEDOM/Layout/sorttable.js");
610  }
611  $displayRowCount = $this->oattr->getOption("displayrowcount", 10);
612  if (!is_numeric($displayRowCount)) {
613  $displayRowCount = 10;
614  }
615 
616  $lay = new Layout("FDL/Layout/viewdocarray.xml", $action);
617  $lay->set("issort", ($sort == "yes"));
618  if (!method_exists($this->doc->attributes, "getArrayElements")) {
619  return $htmlval;
620  }
621  $height = $this->oattr->getOption("height", false);
622  $lay->set("tableheight", $height);
623  $lay->set("caption", $this->oattr->getLabel());
624  $lay->set("aid", $this->oattr->id);
625 
626  if (($viewzone != "") && preg_match("/([A-Z_-]+):([^:]+):{0,1}[A-Z]{0,1}/", $viewzone, $reg)) {
627  // detect special row zone
628  $dxml = new DomDocument();
629  $rowlayfile = getLayoutFile($reg[1], ($reg[2]));
630  if (!file_exists($rowlayfile)) {
631  $htmlval = sprintf(_("cannot open layout file : %s") , $rowlayfile);
632  AddwarningMsg(sprintf(_("cannot open layout file : %s") , $rowlayfile));
633  return $htmlval;
634  }
635  if (!@$dxml->load($rowlayfile)) {
636  AddwarningMsg(sprintf(_("cannot load xml template : %s") , print_r(libxml_get_last_error() , true)));
637  $htmlval = sprintf(_("cannot load xml layout file : %s") , $rowlayfile);
638  return $htmlval;
639  }
640  $theads = $dxml->getElementsByTagName('table-head');
641  if ($theads->length > 0) {
642  /*
643  * @var DOMElement $thead
644  */
645  $thead = $theads->item(0);
646  $theadcells = $thead->getElementsByTagName('cell');
647  $talabel = array();
648  for ($i = 0; $i < $theadcells->length; $i++) {
649  /*
650  * @var DOMElement $item
651  */
652  $item = $theadcells->item($i);
653  $th = xt_innerXML($item);
654  $thstyle = $item->getAttribute("style");
655  $thclass = $item->getAttribute("class");
656  if ($thstyle != "") $thstyle = "style=\"$thstyle\"";
657  if ($thclass) $thstyle.= ' class="' . $thclass . '"';
658  $talabel[] = array(
659  "alabel" => $th,
660  "astyle" => $thstyle,
661  "cwidth" => "auto"
662  );
663  }
664  $lay->setBlockData("TATTR", $talabel);
665  }
666 
667  $tbodies = $dxml->getElementsByTagName('table-body');
668  $tr = $tcellstyle = $tcellclass = array();
669 
670  if ($tbodies->length > 0) {
671  /*
672  * @var DOMElement $tbody
673  */
674  $tbody = $tbodies->item(0);
675  $tbodycells = $tbody->getElementsByTagName('cell');
676  for ($i = 0; $i < $tbodycells->length; $i++) {
677  /*
678  * @var DOMElement $item
679  */
680  $item = $tbodycells->item($i);
681  $tr[] = xt_innerXML($item);
682  $tcellstyle[] = $item->getAttribute("style");
683  $tcellclass[] = $item->getAttribute("class");
684  }
685  }
686  $ta = $this->doc->attributes->getArrayElements($this->oattr->id);
687  $nbitem = 0;
688  $tval = array();
689  foreach ($ta as $k => $v) {
690  $tval[$k] = $this->doc->getMultipleRawValues($k);
691  $nbitem = max($nbitem, count($tval[$k]));
692  $lay->set("L_" . strtoupper($v->id) , $v->getLabel());
693  }
694  // view values
695  $tvattr = array();
696  for ($k = 0; $k < $nbitem; $k++) {
697  $tvattr[] = array(
698  "bevalue" => "bevalue_$k"
699  );
700  reset($ta);
701  $tivalue = array();
702 
703  foreach ($tr as $kd => $vd) {
704 
705  $hval = preg_replace_callback('/\[([^\]]*)\]/', function ($matches) use ($k)
706  {
707  return $this->rowattrReplace($matches[1], $k);
708  }
709  , $vd);
710  $tivalue[] = array(
711  "evalue" => $hval,
712  "color" => "inherit",
713  "tdstyle" => $tcellstyle[$kd],
714  "tdclass" => $tcellclass[$kd],
715  "bgcolor" => "inherit",
716  "align" => "inherit"
717  );
718  }
719  $lay->setBlockData("bevalue_$k", $tivalue);
720  }
721  $lay->setBlockData("EATTR", $tvattr);
722  $caption = '';
723  if ($this->oattr->getOption("vlabel") == "up") {
724  $caption = $this->oattr->getLabel();
725  }
726 
727  if ($nbitem > 10) $caption.= " ($nbitem)";
728  $lay->set("caption", $caption);
729  $htmlval = $lay->gen();
730  } else {
731  $ta = $this->doc->attributes->getArrayElements($this->oattr->id);
732  $talabel = array();
733  $tvattr = array();
734 
735  $emptyarray = true;
736  $nbitem = 0;
737 
738  $tval = array();
739  foreach ($ta as $k => $v) {
740  if (($v->mvisibility == "H") || ($v->mvisibility == "I") || ($v->mvisibility == "O")) continue;
741  $talabel[] = array(
742  "alabel" => ucfirst($v->getLabel()) ,
743  "astyle" => $v->getOption("cellheadstyle") ,
744  "cwidth" => $v->getOption("cwidth", "auto")
745  );
746  $tval[$k] = $this->doc->getMultipleRawValues($k);
747  $nbitem = max($nbitem, count($tval[$k]));
748  if ($emptyarray && ($this->doc->getRawValue($k) != "")) $emptyarray = false;
749  }
750  if (!$emptyarray) {
751  if ($this->oattr->getOption("vlabel") == "up") {
752  $caption = $this->oattr->getLabel();
753  if ($nbitem > 10) $caption.= " ($nbitem)";
754  } else {
755  $caption = "";
756  if ($displayRowCount >= 0 && ($displayRowCount == 0 || $nbitem > $displayRowCount)) {
757  if (count($talabel) > 0) {
758  $talabel[0]["alabel"].= " ($nbitem)";
759  }
760  }
761  }
762 
763  $lay->setBlockData("TATTR", $talabel);
764  $lay->set("caption", $caption);
765  $tvattr = array();
766  for ($k = 0; $k < $nbitem; $k++) {
767  $tvattr[] = array(
768  "bevalue" => "bevalue_$k"
769  );
770  $tivalue = array();
771  /*
772  * @var NormalAttribute $va
773  */
774  foreach ($ta as $ka => $va) {
775  if (($va->mvisibility == "H") || ($va->mvisibility == "I") || ($va->mvisibility == "O")) continue;
776  if (isset($tval[$ka][$k])) $hval = $this->doc->getHtmlValue($va, $tval[$ka][$k], $this->target, $this->htmlLink, $k);
777  else $hval = '';
778  if ($va->type == "image") {
779  $iwidth = $va->getOption("iwidth", "80px");
780  if (empty($tval[$ka][$k])) $hval = "";
781  else if ($va->link == "") {
782  if (strstr($hval, '?')) $optwidth = "&width=" . intval($iwidth);
783  else $optwidth = '';
784  $hval = "<a href=\"$hval\"><img border='0' width=\"$iwidth\" src=\"" . $hval . $optwidth . "\"></a>";
785  } else {
786  $hval = preg_replace("/>(.+)</", ">&nbsp;<img class=\"button\" width=\"$iwidth\" src=\"\\1\">&nbsp;<", $hval);
787  }
788  }
789  $tivalue[] = array(
790  "evalue" => $hval,
791  "attrid" => $va->id,
792  "atype" => $va->type,
793  "tdstyle" => $va->getOption("cellbodystyle") ,
794  "color" => $va->getOption("color", "inherit") ,
795  "bgcolor" => $va->getOption("bgcolor", "inherit") ,
796  "tdclass" => $va->getOption("className", '') ,
797  "align" => $va->getOption("align", "inherit")
798  );
799  }
800  $lay->setBlockData("bevalue_$k", $tivalue);
801  }
802  $lay->setBlockData("EATTR", $tvattr);
803 
804  $htmlval = $lay->gen();
805  } else {
806  $htmlval = "";
807  }
808  }
809  return $htmlval;
810  }
811  /**
812  * format Doc attribute
813  * @param $kvalue
814  * @param $avalue
815  * @return string HTML value
816  */
817  public function formatDoc($kvalue, $avalue)
818  {
819  $htmlval = "";
820  if ($avalue != "") {
821  if ($kvalue > - 1) $idocid = $this->doc->getMultipleRawValues($this->cFormat, "", $kvalue);
822  else $idocid = $this->doc->getRawValue($this->cFormat);
823 
824  if ($idocid > 0) {
825  //$lay = new Layout("FDL/Layout/viewadoc.xml", $action);
826  //$lay->set("id",$idocid);
827  $idoc = new_Doc($this->doc->dbaccess, $idocid);
828  $htmlval = $idoc->viewDoc("FDL:VIEWTHUMBCARD:T", "finfo");
829  //$htmlval =$lay->gen();
830 
831  }
832  }
833  return $htmlval;
834  }
835  /**
836  * format Account attribute
837  * @param $kvalue
838  * @param $avalue
839  * @return string HTML value
840  */
841  public function formatAccount($kvalue, $avalue)
842  {
843  if (!$this->oattr->format) $this->oattr->format = "x";
844  return $this->formatDocid($kvalue, $avalue);
845  }
846  /**
847  * format Docid attribute
848  * @param $kvalue
849  * @param $avalue
850  * @return string HTML value
851  */
852  public function formatDocid($kvalue, $avalue)
853  {
854  if ($this->oattr->format != "") {
855 
856  $this->cancelFormat = true;
857  $multiple = ($this->oattr->getOption("multiple") == "yes");
858  $dtarget = $this->target;
859  if ($this->target != "mail") {
860  $ltarget = $this->oattr->getOption("ltarget");
861  if ($ltarget != "") $dtarget = $ltarget;
862  }
863  $isLatest = $this->oattr->getOption("docrev", "latest") == "latest";
864  if ($multiple) {
865  $avalue = str_replace("\n", "<BR>", $avalue);
866  $tval = explode("<BR>", $avalue);
867  $thval = array();
868  foreach ($tval as $kv => $vv) {
869  if (trim($vv) == "") $thval[] = $vv;
870  else {
871  $title = DocTitle::getRelationTitle(trim($vv) , $isLatest, $this->doc);
872  if ($this->oattr->link != "" && $title) {
873  $link = $this->doc->urlWhatEncode($this->oattr->link, $kvalue);
874  if ($link) $thval[] = '<a target="' . $dtarget . '" href="' . $link . '">' . $this->doc->htmlEncode($title) . '</a>';
875  else {
876  if ($title === false) $title = $this->doc->htmlEncode($this->oattr->getOption("noaccesstext", _("information access deny")));
877  $thval[] = $this->doc->htmlEncode($title);
878  }
879  } else {
880 
881  if ($title === false) $thval[] = $this->doc->htmlEncode($this->oattr->getOption("noaccesstext", _("information access deny")));
882  else $thval[] = $this->doc->getDocAnchor(trim($vv) , $dtarget, $this->htmlLink, $title, true, $this->oattr->getOption("docrev") , true);
883  }
884  }
885  }
886  if ($this->oattr->link) $this->htmlLink = false;
887  $htmlval = implode("<br/>", $thval);
888  } else {
889  if ($avalue == "") $htmlval = $avalue;
890  elseif ($this->oattr->link != "") {
891  $title = DocTitle::getRelationTitle(trim($avalue) , $isLatest, $this->doc);
892  $htmlval = $this->doc->htmlEncode($title);
893  } else {
894  $title = DocTitle::getRelationTitle(trim($avalue) , $isLatest, $this->doc);
895  if ($title === false) $htmlval = $this->doc->htmlEncode($this->oattr->getOption("noaccesstext", _("information access deny")));
896  else $htmlval = $this->doc->getDocAnchor(trim($avalue) , $dtarget, $this->htmlLink, $title, true, $this->oattr->getOption("docrev") , true);
897  }
898  }
899  } else $htmlval = $avalue;
900  return $htmlval;
901  }
902  /**
903  * format Image attribute
904  * @param $kvalue
905  * @param $avalue
906  * @return string HTML value
907  */
908  public function formatThesaurus($kvalue, $avalue)
909  {
910  $this->cancelFormat = true;
911  $multiple = ($this->oattr->getOption("multiple") == "yes");
912  if ($multiple) {
913  $avalue = str_replace("\n", "<BR>", $avalue);
914  $tval = explode("<BR>", $avalue);
915  $thval = array();
916  foreach ($tval as $vv) {
917  if (trim($vv) == "") $thval[] = $vv;
918  else {
919  $thc = new_doc($this->doc->dbaccess, trim($vv));
920  if ($thc->isAlive()) $thval[] = $this->doc->getDocAnchor(trim($vv) , $this->target, $this->htmlLink, $thc->getCustomTitle());
921  else $thval[] = "th error1 $vv";
922  }
923  }
924  $htmlval = implode("<br/>", $thval);
925  } else {
926  if ($avalue == "") $htmlval = $avalue;
927  else {
928  $avalue = trim($avalue);
929  $thc = new_doc($this->doc->dbaccess, $avalue);
930  if ($thc->isAlive()) $htmlval = $this->doc->getDocAnchor(trim($avalue) , $this->target, $this->htmlLink, $thc->getCustomTitle());
931  else $htmlval = "th error2 [$avalue]";
932  }
933  }
934  return $htmlval;
935  }
936  /**
937  * format Option attribute
938  *
939  * @param $kvalue
940  * @param $avalue
941  *
942  * @return string HTML value
943  */
944  public function formatOption($kvalue, $avalue)
945  {
946  global $action;
947  $lay = new Layout("FDL/Layout/viewdocoption.xml", $action);
948  $htmlval = "";
949 
950  if ($kvalue > - 1) $di = $this->doc->getMultipleRawValues($this->oattr->format, "", $kvalue);
951  else $di = $this->doc->getRawValue($this->oattr->format);
952  if ($di > 0) {
953  $lay->set("said", $di);
954  $lay->set("uuvalue", urlencode($avalue));
955 
956  $htmlval = $lay->gen();
957  }
958  return $htmlval;
959  }
960  /**
961  * format Money attribute
962  *
963  * @param $kvalue
964  * @param $avalue
965  *
966  * @return string
967  */
968  public function formatMoney($kvalue, $avalue)
969  {
970  if ($avalue == '' && $this->oattr->getOption('showempty')) {
971  $htmlval = $this->oattr->getOption('showempty');
972  $this->cancelFormat = true;
973  } else {
974  if ($avalue !== '') {
975  $htmlval = money_format('%!.2n', doubleval($avalue));
976  $htmlval = str_replace(" ", "&nbsp;", $htmlval); // need to replace space by non breaking spaces
977 
978  } else {
979  $htmlval = '';
980  }
981  }
982  return $htmlval;
983  }
984  /**
985  * format HTML attribute
986  *
987  * @param $kvalue
988  * @param $avalue
989  *
990  * @return string
991  */
992  public function formatHtmltext($kvalue, $avalue)
993  {
994  if ($avalue == '' && $this->oattr->getOption('showempty')) {
995  $avalue = $this->oattr->getOption('showempty');
996  $this->cancelFormat = true;
997  }
998  $shtmllink = $this->htmlLink ? "true" : "false";
999  $avalue = preg_replace_callback('/(\[|&#x5B;)ADOC ([^\]]*)\]/', function ($matches) use ($shtmllink)
1000  {
1001  return $this->doc->getDocAnchor($matches[2], $this->target, $shtmllink);
1002  }
1003  , $avalue);
1004  if (stripos($avalue, "data-initid") !== false) {
1005  try {
1006  $domDoc = new DOMDocument();
1007 
1008  $domDoc->loadHTML(mb_convert_encoding($avalue, 'HTML-ENTITIES', 'UTF-8'));
1009 
1010  $aElements = $domDoc->getElementsByTagName("a");
1011  /*
1012  * @var DOMElement $currentA
1013  */
1014  foreach ($aElements as $currentA) {
1015 
1016  if ($currentA->hasAttribute("data-initid")) {
1017  $newA = $this->doc->getDocAnchor($currentA->getAttribute("data-initid") , $this->target, $shtmllink, false, true, $currentA->getAttribute("data-docrev"));
1018  $newAFragment = $domDoc->createDocumentFragment();
1019  $newAFragment->appendXML($newA);
1020  $currentA->parentNode->replaceChild($newAFragment, $currentA);
1021  }
1022  }
1023 
1024  $avalue = $domDoc->saveHTML();
1025  }
1026  catch(Exception $e) {
1027  error_log(sprintf("%s unable to parse/create html width docLink elements(document :%s, error %)s", __METHOD__, $this->doc->id, $e->getMessage()));
1028  }
1029  } else {
1030  $prefix = uniqid("");
1031  $avalue = str_replace(array(
1032  "[",
1033  "&#x5B;",
1034  "]"
1035  ) , array(
1036  "B$prefix",
1037  "B$prefix",
1038  "D$prefix"
1039  ) , $avalue);
1040  $avalue = \Dcp\Utils\htmlclean::normalizeHTMLFragment(mb_convert_encoding($avalue, 'HTML-ENTITIES', 'UTF-8') , $error);
1041  $avalue = str_replace(array(
1042  "B$prefix",
1043  "D$prefix"
1044  ) , array(
1045  "[",
1046  "]"
1047  ) , $avalue);
1048  if ($error != '') {
1049  addWarningMsg(_("Malformed HTML:") . "\n" . $error);
1050  }
1051  if ($avalue === false) {
1052  $avalue = '';
1053  }
1054  }
1055  $htmlval = '<div class="htmltext">' . str_replace("[", "&#x5B;", $avalue) . '</div>';
1056  return $htmlval;
1057  }
1058  /**
1059  * format Date attribute
1060  * @param $kvalue
1061  * @param $avalue
1062  *
1063  * @return string
1064  */
1065  public function formatDate($kvalue, $avalue)
1066  {
1067  if (($this->cFormat != "") && (trim($avalue) != "")) {
1068  if ($avalue) $htmlval = strftime($this->cFormat, stringDateToUnixTs($avalue));
1069  else $htmlval = $avalue;
1070  } elseif (trim($avalue) == "") {
1071  $htmlval = "";
1072  } else {
1073  $htmlval = stringDateToLocaleDate($avalue);
1074  }
1075  $this->cancelFormat = true;
1076  return $htmlval;
1077  }
1078  /**
1079  * format Time attribute
1080  *
1081  * @param $kvalue
1082  * @param $avalue
1083  *
1084  * @return string
1085  */
1086  public function formatTime($kvalue, $avalue)
1087  {
1088  if (($this->cFormat != "") && (trim($avalue) != "")) {
1089  if ($avalue) $htmlval = strftime($this->cFormat, strtotime($avalue));
1090  else $htmlval = $avalue;
1091  } else {
1092  if ($avalue) {
1093  $htmlval = (string)substr($avalue, 0, 5); // do not display second
1094 
1095  } else {
1096  $htmlval = '';
1097  }
1098  }
1099  $this->cancelFormat = true;
1100  return $htmlval;
1101  }
1102  /**
1103  * format TimeStamp attribute
1104  *
1105  * @param $kvalue
1106  * @param $avalue
1107  *
1108  * @return string
1109  */
1110  public function formatTimestamp($kvalue, $avalue)
1111  {
1112  if (($this->cFormat != "") && (trim($avalue) != "")) {
1113  if ($avalue) $htmlval = strftime($this->cFormat, stringDateToUnixTs($avalue));
1114  else $htmlval = $avalue;
1115  } elseif (trim($avalue) == "") {
1116  $htmlval = "";
1117  } else {
1118  $htmlval = stringDateToLocaleDate($avalue);
1119  }
1120  $this->cancelFormat = true;
1121  return $htmlval;
1122  }
1123  /**
1124  * format IFile attribute
1125  *
1126  * @param $kvalue
1127  * @param $avalue
1128  *
1129  * @return string
1130  */
1131  public function formatIfile($kvalue, $avalue)
1132  {
1133  global $action;
1134  $lay = new Layout("FDL/Layout/viewifile.xml", $action);
1135  $lay->set("aid", $this->oattr->id);
1136  $lay->set("id", $this->doc->id);
1137  $lay->set("iheight", $this->oattr->getOption("height", "200px"));
1138  $htmlval = $lay->gen();
1139  return $htmlval;
1140  }
1141  /**
1142  * format Color attribute
1143  *
1144  * @param $kvalue
1145  * @param $avalue
1146  *
1147  * @return string
1148  */
1149  public function formatColor($kvalue, $avalue)
1150  {
1151  if ($avalue) {
1152  $htmlval = sprintf("<span style=\"background-color:%s\">%s</span>", $avalue, $avalue);
1153  } else {
1154  $htmlval = '';
1155  }
1156  return $htmlval;
1157  }
1158  private function rowattrReplace($s, $index)
1159  {
1160  if (substr($s, 0, 2) == "L_") return "[$s]";
1161  if (substr($s, 0, 2) == "V_") {
1162  $sl = substr(strtolower($s) , 2);
1163  $vis = $this->doc->getAttribute($sl)->mvisibility;
1164 
1165  if (($vis == "H") || ($vis == "I") || ($vis == "O")) $v = "";
1166  else $v = $this->doc->GetHtmlAttrValue($sl, "_self", 2, $index);
1167  } else {
1168  $sl = strtolower($s);
1169  if (!isset($this->doc->$sl)) return "[$s]";
1170  $v = $this->doc->getMultipleRawValues($sl, "", $index);
1171  }
1172  return $v;
1173  }
1174  /**
1175  * Format the given size in human readable SI format (up to terabytes).
1176  *
1177  * @param int $size
1178  * @return string
1179  */
1180  private static function human_size($size)
1181  {
1182  if (abs($size) < 1000) {
1183  return sprintf("%d %s", $size, n___("unit:byte", "unit:bytes", abs($size)));
1184  }
1185  $size = $size / 1000;
1186  foreach (array(
1187  _("unit:kB") ,
1188  _("unit:MB") ,
1189  _("unit:GB")
1190  ) as $unit) {
1191  if (abs($size) < 1000) {
1192  return sprintf("%3.2f %s", $size, $unit);
1193  }
1194  $size = $size / 1000;
1195  }
1196  return sprintf("%.2f %s", $size, _("unit:TB"));
1197  }
1198 }
Layout is a template generator.
global $action
newFreeVaultFile($dbaccess)
Definition: Lib.Util.php:17
formatDoc($kvalue, $avalue)
formatTime($kvalue, $avalue)
formatIfile($kvalue, $avalue)
getHtmlValue($oattr, $value, $target="_self", $htmlLink=true, $index=-1, $useEntities=true, $abstractMode=false)
formatDate($kvalue, $avalue)
stringDateToLocaleDate($fdate, $format= '')
Definition: Lib.Util.php:98
$size
Definition: resizeimg.php:110
addWarningMsg($msg)
Definition: Lib.Common.php:95
const PREGEXPFILE
Definition: Class.Doc.php:54
if($famId) $s
getPdfNumberOfPages($file)
static getRelationTitle($docid, $latest=true, Doc $doc, $docrevOption="", array &$info=array())
getIconMimeFile($sysmime)
n___($message, $message_plural, $num, $context="")
Definition: Lib.Common.php:55
formatDocid($kvalue, $avalue)
formatLongtext($kvalue, $avalue)
$idoc
Definition: csv2sql.php:34
getLayoutFile($app, $layfile)
Definition: Lib.Common.php:258
formatArray($kvalue, $avalue)
formatTimestamp($kvalue, $avalue)
formatHtmltext($kvalue, $avalue)
xt_innerXML(&$node)
getSessionValue($name, $def="")
Definition: Lib.Common.php:240
new_Doc($dbaccess, $id= '', $latest=false)
formatAccount($kvalue, $avalue)
formatPassword($kvalue, $avalue)
stringDateToUnixTs($isodate, $utc=false)
Definition: Lib.Util.php:217
formatFile($kvalue, $avalue)
$vf
Definition: geticon.php:28
formatThesaurus($kvalue, $avalue)
formatDefault($kvalue, $avalue)
if($file) if($subject==""&&$file) if($subject=="") $err
formatColor($kvalue, $avalue)
formatMoney($kvalue, $avalue)
formatEnum($kvalue, $avalue)
$value
__construct(Doc &$doc)
formatImage($kvalue, $avalue)
formatOption($kvalue, $avalue)
← centre documentaire © anakeen