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