dolibarr  9.0.0
doc_generic_task_odt.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2013 Florian Henry <florian.henry@ope-concept.pro>
5  * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  * or see http://www.gnu.org/
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
31 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41 if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
42 if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
43 if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
44 if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
45 if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
46 if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
47 if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
48 if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
49 if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
50 if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
51 
52 
57 {
62  public $emetteur;
63 
68  public $phpmin = array(5, 4);
69 
74  public $version = 'dolibarr';
75 
76 
82  function __construct($db)
83  {
84  global $conf, $langs, $mysoc;
85 
86  // Load translation files required by the page
87  $langs->loadLangs(array("main","companies"));
88 
89  $this->db = $db;
90  $this->name = "ODT templates";
91  $this->description = $langs->trans("DocumentModelOdt");
92  $this->scandir = 'PROJECT_TASK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
93 
94  // Dimension page pour format A4
95  $this->type = 'odt';
96  $this->page_largeur = 0;
97  $this->page_hauteur = 0;
98  $this->format = array($this->page_largeur,$this->page_hauteur);
99  $this->marge_gauche=0;
100  $this->marge_droite=0;
101  $this->marge_haute=0;
102  $this->marge_basse=0;
103 
104  $this->option_logo = 1; // Affiche logo
105  $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION
106  $this->option_modereg = 0; // Affiche mode reglement
107  $this->option_condreg = 0; // Affiche conditions reglement
108  $this->option_codeproduitservice = 0; // Affiche code produit-service
109  $this->option_multilang = 0; // Dispo en plusieurs langues
110  $this->option_escompte = 0; // Affiche si il y a eu escompte
111  $this->option_credit_note = 0; // Support credit notes
112  $this->option_freetext = 1; // Support add of a personalised text
113  $this->option_draft_watermark = 0; // Support add of a watermark on drafts
114 
115  // Recupere emetteur
116  $this->emetteur=$mysoc;
117  if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini
118  }
119 
120 
121  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
130  function get_substitutionarray_object($object,$outputlangs,$array_key='object')
131  {
132  // phpcs:enable
133  global $conf;
134 
135  $resarray=array(
136  $array_key.'_id'=>$object->id,
137  $array_key.'_ref'=>$object->ref,
138  $array_key.'_title'=>$object->title,
139  $array_key.'_description'=>$object->description,
140  $array_key.'_date_creation'=>dol_print_date($object->date_c,'day'),
141  $array_key.'_date_modification'=>dol_print_date($object->date_m,'day'),
142  $array_key.'_date_start'=>dol_print_date($object->date_start,'day'),
143  $array_key.'_date_end'=>dol_print_date($object->date_end,'day'),
144  $array_key.'_note_private'=>$object->note_private,
145  $array_key.'_note_public'=>$object->note_public,
146  $array_key.'_public'=>$object->public,
147  $array_key.'_statut'=>$object->getLibStatut()
148  );
149 
150  // Retrieve extrafields
151  if (is_array($object->array_options) && count($object->array_options))
152  {
153  $extrafieldkey=$object->element;
154 
155  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
156  $extrafields = new ExtraFields($this->db);
157  $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
158  $object->fetch_optionals();
159 
160  $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs);
161  }
162 
163  return $resarray;
164  }
165 
166  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
174  function get_substitutionarray_tasks($task,$outputlangs)
175  {
176  // phpcs:enable
177  global $conf;
178 
179  return array(
180  'task_ref'=>$task->ref,
181  'task_fk_project'=>$task->fk_project,
182  'task_projectref'=>$task->projectref,
183  'task_projectlabel'=>$task->projectlabel,
184  'task_label'=>$task->label,
185  'task_description'=>$task->description,
186  'task_fk_parent'=>$task->fk_parent,
187  'task_duration'=>$task->duration,
188  'task_progress'=>$task->progress,
189  'task_public'=>$task->public,
190  'task_date_start'=>dol_print_date($task->date_start,'day'),
191  'task_date_end'=>dol_print_date($task->date_end,'day'),
192  'task_note_private'=>$task->note_private,
193  'task_note_public'=>$task->note_public
194  );
195  }
196 
197  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
205  function get_substitutionarray_project_contacts($contact,$outputlangs)
206  {
207  // phpcs:enable
208  global $conf;
209 
210  return array(
211  'projcontacts_id'=>$contact['id'],
212  'projcontacts_rowid'=>$contact['rowid'],
213  'projcontacts_role'=>$contact['libelle'],
214  'projcontacts_lastname'=>$contact['lastname'],
215  'projcontacts_firstname'=>$contact['firstname'],
216  'projcontacts_fullcivname'=>$contact['fullname'],
217  'projcontacts_socname'=>$contact['socname'],
218  'projcontacts_email'=>$contact['email']
219  );
220  }
221 
222  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
230  function get_substitutionarray_project_file($file,$outputlangs)
231  {
232  // phpcs:enable
233  global $conf;
234 
235  return array(
236  'projfile_name'=>$file['name'],
237  'projfile_date'=>dol_print_date($file['date'],'day'),
238  'projfile_size'=>$file['size']
239  );
240  }
241 
242  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
250  function get_substitutionarray_project_reference($refdetail,$outputlangs)
251  {
252  // phpcs:enable
253  global $conf;
254 
255  return array(
256  'projref_type'=>$refdetail['type'],
257  'projref_ref'=>$refdetail['ref'],
258  'projref_date'=>dol_print_date($refdetail['date'],'day'),
259  'projref_socname'=>$refdetail['socname'],
260  'projref_amountht'=>price($refdetail['amountht'],0,$outputlangs),
261  'projref_amountttc'=>price($refdetail['amountttc'],0,$outputlangs),
262  'projref_status'=>$refdetail['status']
263  );
264  }
265 
266  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
274  function get_substitutionarray_tasksressource($taskressource,$outputlangs)
275  {
276  // phpcs:enable
277  global $conf;
278  //dol_syslog(get_class($this).'::get_substitutionarray_tasksressource taskressource='.var_export($taskressource,true),LOG_DEBUG);
279  return array(
280  'taskressource_rowid'=>$taskressource['rowid'],
281  'taskressource_role'=>$taskressource['libelle'],
282  'taskressource_lastname'=>$taskressource['lastname'],
283  'taskressource_firstname'=>$taskressource['firstname'],
284  'taskressource_fullcivname'=>$taskressource['fullname'],
285  'taskressource_socname'=>$taskressource['socname'],
286  'taskressource_email'=>$taskressource['email']
287  );
288  }
289 
290  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
298  function get_substitutionarray_taskstime($tasktime,$outputlangs)
299  {
300  // phpcs:enable
301  global $conf;
302 
303  return array(
304  'tasktime_rowid'=>$tasktime['rowid'],
305  'tasktime_task_date'=>dol_print_date($tasktime['task_date'],'day'),
306  'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'],'all'),
307  'tasktime_note'=>$tasktime['note'],
308  'tasktime_fk_user'=>$tasktime['fk_user'],
309  'tasktime_user_name'=>$tasktime['name'],
310  'tasktime_user_first'=>$tasktime['firstname'],
311  'tasktime_fullcivname'=>$tasktime['fullcivname']
312  );
313  }
314 
315  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
323  function get_substitutionarray_task_file($file,$outputlangs)
324  {
325  // phpcs:enable
326  global $conf;
327 
328  return array(
329  'tasksfile_name'=>$file['name'],
330  'tasksfile_date'=>dol_print_date($file['date'],'day'),
331  'tasksfile_size'=>$file['size']
332  );
333  }
334 
335 
342  function info($langs)
343  {
344  global $conf,$langs;
345 
346  // Load translation files required by the page
347  $langs->loadLangs(array("errors","companies"));
348 
349  $form = new Form($this->db);
350 
351  $texte = $this->description.".<br>\n";
352  $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
353  $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
354  $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
355  $texte.= '<input type="hidden" name="param1" value="PROJECT_TASK_ADDON_PDF_ODT_PATH">';
356  $texte.= '<table class="nobordernopadding" width="100%">';
357 
358  // List of directories area
359  $texte.= '<tr><td>';
360  $texttitle=$langs->trans("ListOfDirectories");
361  $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)));
362  $listoffiles=array();
363  foreach($listofdir as $key=>$tmpdir)
364  {
365  $tmpdir=trim($tmpdir);
366  $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
367  if (! $tmpdir) {
368  unset($listofdir[$key]); continue;
369  }
370  if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
371  else
372  {
373  $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
374  if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
375  }
376  }
377  $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
378  // Add list of substitution keys
379  $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
380  $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
381 
382  $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
383  $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
384  $texte.= '<textarea class="flat" cols="60" name="value1">';
385  $texte.=$conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH;
386  $texte.= '</textarea>';
387  $texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
388  $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
389  $texte.= '<br></div></div>';
390 
391  // Scan directories
392  $nbofiles=count($listoffiles);
393  if (! empty($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH))
394  {
395  $texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
396  //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
397  $texte.=$nbofiles;
398  //$texte.=$nbofiles?'</a>':'';
399  $texte.='</b>';
400  }
401 
402  if ($nbofiles)
403  {
404  $texte.='<div id="div_'.get_class($this).'" class="hidden">';
405  foreach($listoffiles as $file)
406  {
407  $texte.=$file['name'].'<br>';
408  }
409  $texte.='<div id="div_'.get_class($this).'">';
410  }
411 
412  $texte.= '</td>';
413 
414  $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
415  $texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
416  $texte.= '</td>';
417  $texte.= '</tr>';
418 
419  $texte.= '</table>';
420  $texte.= '</form>';
421 
422  return $texte;
423  }
424 
425  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
434  function write_file($object,$outputlangs,$srctemplatepath)
435  {
436  // phpcs:enable
437  global $user,$langs,$conf,$mysoc,$hookmanager;
438 
439  if (empty($srctemplatepath))
440  {
441  dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
442  return -1;
443  }
444 
445  if (! is_object($outputlangs)) $outputlangs=$langs;
446  $sav_charset_output=$outputlangs->charset_output;
447  $outputlangs->charset_output='UTF-8';
448 
449  // Load translation files required by the page
450  $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
451 
452  if ($conf->projet->dir_output)
453  {
454  // If $object is id instead of object
455  if (! is_object($object))
456  {
457  $id = $object;
458  $object = new Task($this->db);
459  $result=$object->fetch($id);
460  if ($result < 0)
461  {
462  dol_print_error($this->db,$object->error);
463  return -1;
464  }
465  }
466  $project= new Project($this->db);
467  $project->fetch($object->fk_project);
468  $project->fetch_thirdparty();
469 
470  $dir = $conf->projet->dir_output. "/" . $project->ref. "/";
471  $objectref = dol_sanitizeFileName($object->ref);
472  if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
473  $file = $dir . "/" . $objectref . ".odt";
474 
475  if (! file_exists($dir))
476  {
477  print '$dir'.$dir;
478  if (dol_mkdir($dir) < 0)
479  {
480  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
481  return -1;
482  }
483  }
484 
485 
486  if (file_exists($dir))
487  {
488  //print "srctemplatepath=".$srctemplatepath; // Src filename
489  $newfile=basename($srctemplatepath);
490  $newfiletmp=preg_replace('/\.(ods|odt)/i','',$newfile);
491  $newfiletmp=preg_replace('/template_/i','',$newfiletmp);
492  $newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
493  $newfiletmp=$objectref.'_'.$newfiletmp;
494  //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
495  $file=$dir.'/'.$newfiletmp.'.odt';
496  //print "newdir=".$dir;
497  //print "newfile=".$newfile;
498  //print "file=".$file;
499  //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
500 
501  dol_mkdir($conf->projet->dir_temp);
502 
503  $socobject=$project->thirdparty;
504 
505  // Make substitution
506  $substitutionarray=array(
507  '__FROM_NAME__' => $this->emetteur->name,
508  '__FROM_EMAIL__' => $this->emetteur->email,
509  );
510  complete_substitutions_array($substitutionarray, $langs, $object);
511  // Call the ODTSubstitution hook
512  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
513  $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
514 
515  // Open and load template
516  require_once ODTPHP_PATH.'odf.php';
517  try {
518  $odfHandler = new odf(
519  $srctemplatepath,
520  array(
521  'PATH_TO_TMP' => $conf->projet->dir_temp,
522  'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
523  'DELIMITER_LEFT' => '{',
524  'DELIMITER_RIGHT' => '}'
525  )
526  );
527  }
528  catch(Exception $e)
529  {
530  $this->error=$e->getMessage();
531  return -1;
532  }
533  // After construction $odfHandler->contentXml contains content and
534  // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
535  // [!-- BEGIN lines --]*[!-- END lines --]
536  //print html_entity_decode($odfHandler->__toString());
537  //print exit;
538 
539 
540  // Define substitution array
541  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
542  $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
543  $array_objet=$this->get_substitutionarray_object($project,$outputlangs);
544  $array_user=$this->get_substitutionarray_user($user,$outputlangs);
545  $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
546  $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
547  $array_other=$this->get_substitutionarray_other($outputlangs);
548 
549  $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other);
550  complete_substitutions_array($tmparray, $outputlangs, $object);
551 
552  foreach($tmparray as $key=>$value)
553  {
554  try {
555  if (preg_match('/logo$/',$key)) // Image
556  {
557  if (file_exists($value)) $odfHandler->setImage($key, $value);
558  else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
559  }
560  else // Text
561  {
562  $odfHandler->setVars($key, $value, true, 'UTF-8');
563  }
564  } catch (OdfException $e) {
565  dol_syslog($e->getMessage(), LOG_INFO);
566  }
567  }
568 
569  // Replace tags of lines for tasks
570  try
571  {
572  // Security check
573  $socid=0;
574  if (!empty($project->fk_soc)) $socid = $project->fk_soc;
575 
576  $tmparray=$this->get_substitutionarray_tasks($object,$outputlangs);
577  complete_substitutions_array($tmparray, $outputlangs, $object);
578  foreach($tmparray as $key => $val)
579  {
580  try {
581  $odfHandler->setVars($key, $val, true, 'UTF-8');
582  } catch (OdfException $e) {
583  dol_syslog($e->getMessage(), LOG_INFO);
584  } catch(SegmentException $e) {
585  dol_syslog($e->getMessage(), LOG_INFO);
586  }
587  }
588 
589  // Replace tags of lines for contacts task
590  $sourcearray=array('internal','external');
591  $contact_arrray=array();
592  foreach ($sourcearray as $source) {
593  $contact_temp=$object->liste_contact(-1,$source);
594  if ((is_array($contact_temp) && count($contact_temp) > 0))
595  {
596  $contact_arrray=array_merge($contact_arrray,$contact_temp);
597  }
598  }
599  if ((is_array($contact_arrray) && count($contact_arrray) > 0))
600  {
601  $listlinestaskres = $odfHandler->setSegment('tasksressources');
602 
603  foreach ($contact_arrray as $contact)
604  {
605  if ($contact['source']=='internal') {
606  $objectdetail=new User($this->db);
607  $objectdetail->fetch($contact['id']);
608  $contact['socname']=$mysoc->name;
609  } elseif ($contact['source']=='external') {
610  $objectdetail=new Contact($this->db);
611  $objectdetail->fetch($contact['id']);
612 
613  $soc=new Societe($this->db);
614  $soc->fetch($contact['socid']);
615  $contact['socname']=$soc->name;
616  }
617  $contact['fullname']=$objectdetail->getFullName($outputlangs,1);
618 
619  $tmparray=$this->get_substitutionarray_tasksressource($contact,$outputlangs);
620 
621  foreach($tmparray as $key => $val)
622  {
623  try {
624  $listlinestaskres->setVars($key, $val, true, 'UTF-8');
625  } catch (OdfException $e) {
626  dol_syslog($e->getMessage(), LOG_INFO);
627  }
628  catch (SegmentException $e) {
629  dol_syslog($e->getMessage(), LOG_INFO);
630  }
631  }
632  $listlinestaskres->merge();
633  }
634  $odfHandler->mergeSegment($listlinestaskres);
635  }
636 
637  // Time ressources
638  $sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
639  $sql.= ", u.lastname, u.firstname";
640  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
641  $sql .= " , ".MAIN_DB_PREFIX."user as u";
642  $sql .= " WHERE t.fk_task =".$object->id;
643  $sql .= " AND t.fk_user = u.rowid";
644  $sql .= " ORDER BY t.task_date DESC";
645 
646  $resql = $this->db->query($sql);
647  if ($resql)
648  {
649  $num = $this->db->num_rows($resql);
650  $i = 0;
651  $tasks = array();
652  $listlinestasktime = $odfHandler->setSegment('taskstimes');
653  while ($i < $num)
654  {
655  $row = $this->db->fetch_array($resql);
656  if (!empty($row['fk_user'])) {
657  $objectdetail=new User($this->db);
658  $objectdetail->fetch($row['fk_user']);
659  // TODO Use a cache to aoid fetch for same user
660  $row['fullcivname']=$objectdetail->getFullName($outputlangs,1);
661  } else {
662  $row['fullcivname']='';
663  }
664 
665  $tmparray=$this->get_substitutionarray_taskstime($row,$outputlangs);
666 
667  foreach($tmparray as $key => $val)
668  {
669  try
670  {
671  $listlinestasktime->setVars($key, $val, true, 'UTF-8');
672  }
673  catch(OdfException $e)
674  {
675  dol_syslog($e->getMessage(), LOG_INFO);
676  }
677  catch(SegmentException $e)
678  {
679  dol_syslog($e->getMessage(), LOG_INFO);
680  }
681  }
682  $listlinestasktime->merge();
683  $i++;
684  }
685  $this->db->free($resql);
686 
687  $odfHandler->mergeSegment($listlinestasktime);
688  }
689 
690 
691  // Replace tags of project files
692  $listtasksfiles = $odfHandler->setSegment('tasksfiles');
693 
694  $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($object->ref);
695  $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$','name',SORT_ASC,1);
696 
697 
698  foreach ($filearray as $filedetail)
699  {
700  $tmparray=$this->get_substitutionarray_task_file($filedetail,$outputlangs);
701  //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true));
702  foreach($tmparray as $key => $val)
703  {
704  try
705  {
706  $listtasksfiles->setVars($key, $val, true, 'UTF-8');
707  }
708  catch(OdfException $e)
709  {
710  dol_syslog($e->getMessage(), LOG_INFO);
711  }
712  catch(SegmentException $e)
713  {
714  dol_syslog($e->getMessage(), LOG_INFO);
715  }
716  }
717  $listtasksfiles->merge();
718  }
719  //$listlines->merge();
720 
721  $odfHandler->mergeSegment($listtasksfiles);
722  }
723  catch(OdfException $e)
724  {
725  $this->error=$e->getMessage();
726  dol_syslog($this->error, LOG_WARNING);
727  return -1;
728  }
729 
730 
731 
732  // Replace tags of project files
733  try
734  {
735  $listlines = $odfHandler->setSegment('projectfiles');
736 
737  $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref);
738  $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$','name',SORT_ASC,1);
739 
740 
741  foreach ($filearray as $filedetail)
742  {
743  //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true));
744  $tmparray=$this->get_substitutionarray_project_file($filedetail,$outputlangs);
745 
746  foreach($tmparray as $key => $val)
747  {
748  try
749  {
750  $listlines->setVars($key, $val, true, 'UTF-8');
751  }
752  catch(OdfException $e)
753  {
754  dol_syslog($e->getMessage(), LOG_INFO);
755  }
756  catch(SegmentException $e)
757  {
758  dol_syslog($e->getMessage(), LOG_INFO);
759  }
760  }
761  $listlines->merge();
762  }
763  $odfHandler->mergeSegment($listlines);
764  }
765  catch(OdfException $e)
766  {
767  $this->error=$e->getMessage();
768  dol_syslog($this->error, LOG_WARNING);
769  return -1;
770  }
771 
772  // Replace tags of lines for contacts
773  $sourcearray=array('internal','external');
774  $contact_arrray=array();
775  foreach ($sourcearray as $source) {
776  $contact_temp=$project->liste_contact(-1,$source);
777  if ((is_array($contact_temp) && count($contact_temp) > 0))
778  {
779  $contact_arrray=array_merge($contact_arrray,$contact_temp);
780  }
781  }
782  if ((is_array($contact_arrray) && count($contact_arrray) > 0))
783  {
784  try
785  {
786  $listlines = $odfHandler->setSegment('projectcontacts');
787 
788  foreach ($contact_arrray as $contact)
789  {
790  if ($contact['source']=='internal') {
791  $objectdetail=new User($this->db);
792  $objectdetail->fetch($contact['id']);
793  $contact['socname']=$mysoc->name;
794  } elseif ($contact['source']=='external') {
795  $objectdetail=new Contact($this->db);
796  $objectdetail->fetch($contact['id']);
797 
798  $soc=new Societe($this->db);
799  $soc->fetch($contact['socid']);
800  $contact['socname']=$soc->name;
801  }
802  $contact['fullname']=$objectdetail->getFullName($outputlangs,1);
803 
804  $tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs);
805 
806  foreach($tmparray as $key => $val)
807  {
808  try
809  {
810  $listlines->setVars($key, $val, true, 'UTF-8');
811  }
812  catch(OdfException $e)
813  {
814  dol_syslog($e->getMessage(), LOG_INFO);
815  }
816  catch(SegmentException $e)
817  {
818  dol_syslog($e->getMessage(), LOG_INFO);
819  }
820  }
821  $listlines->merge();
822  }
823  $odfHandler->mergeSegment($listlines);
824  }
825  catch(OdfException $e)
826  {
827  $this->error=$e->getMessage();
828  dol_syslog($this->error, LOG_WARNING);
829  return -1;
830  }
831  }
832 
833 
834  // Call the beforeODTSave hook
835  $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
836  $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
837 
838 
839  // Write new file
840  if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
841  try {
842  $odfHandler->exportAsAttachedPDF($file);
843  } catch (Exception $e) {
844  $this->error=$e->getMessage();
845  dol_syslog($e->getMessage(), LOG_INFO);
846  return -1;
847  }
848  }
849  else {
850  try {
851  $odfHandler->saveToDisk($file);
852  } catch (Exception $e) {
853  $this->error=$e->getMessage();
854  dol_syslog($e->getMessage(), LOG_INFO);
855  return -1;
856  }
857  }
858  $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
859  $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
860 
861  if (! empty($conf->global->MAIN_UMASK))
862  @chmod($file, octdec($conf->global->MAIN_UMASK));
863 
864  $odfHandler=null; // Destroy object
865 
866  $this->result = array('fullpath'=>$file);
867 
868  return 1; // Success
869  }
870  else
871  {
872  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
873  return -1;
874  }
875  }
876 
877  return -1;
878  }
879 }
get_substitutionarray_tasks($task, $outputlangs)
Define array with couple substitution key => substitution value.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition: date.lib.php:180
img_warning($titlealt='default', $moreatt='')
Show warning logo.
get_substitutionarray_tasksressource($taskressource, $outputlangs)
Define array with couple substitution key => substitution value.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
Class to manage contact/addresses.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive=true)
Define array with couple subtitution key => subtitution value.
Parent class for projects models.
Class to manage Dolibarr users.
Definition: user.class.php:41
get_substitutionarray_user($user, $outputlangs)
Define array with couple subtitution key => subtitution value.
Class to build documents using ODF templates generator.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
info($langs)
Return description of a module.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
get_substitutionarray_task_file($file, $outputlangs)
Define array with couple substitution key => substitution value.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
get_substitutionarray_project_file($file, $outputlangs)
Define array with couple substitution key => substitution value.
$version
Dolibarr version of the loaded document string.
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple subtitution key => subtitution value.
get_substitutionarray_project_contacts($contact, $outputlangs)
Define array with couple substitution key => substitution value.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:59
get_substitutionarray_taskstime($tasktime, $outputlangs)
Define array with couple substitution key => substitution value.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage tasks.
Definition: task.class.php:33
get_substitutionarray_thirdparty($object, $outputlangs)
Define array with couple subtitution key => subtitution value.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
Fill array with couple extrafield key => extrafield value.
get_substitutionarray_project_reference($refdetail, $outputlangs)
Define array with couple substitution key => substitution value.
get_substitutionarray_other($outputlangs)
Define array with couple subtitution key => subtitution value.
write_file($object, $outputlangs, $srctemplatepath)
Function to build a document on disk using the generic odt module.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
get_substitutionarray_object($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.