diff --git a/documents/doctemplates/project/template_project.odt b/documents/doctemplates/project/template_project.odt new file mode 100755 index 0000000000000000000000000000000000000000..fcf5f52d80126f4af6bd2ecb629f5721a5b606f1 Binary files /dev/null and b/documents/doctemplates/project/template_project.odt differ diff --git a/documents/doctemplates/project/template_task_summary.odt b/documents/doctemplates/project/template_task_summary.odt new file mode 100755 index 0000000000000000000000000000000000000000..67c43a785d2dbac54867ce9f13a7565ed4acdeac Binary files /dev/null and b/documents/doctemplates/project/template_task_summary.odt differ diff --git a/htdocs/admin/project.php b/htdocs/admin/project.php index f2f216d7b5257bea7e0d7cff60d80de458124048..e971eb92e5116c1f04195f22c5795b274ba64b66 100644 --- a/htdocs/admin/project.php +++ b/htdocs/admin/project.php @@ -1,28 +1,28 @@ <?php /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net> - * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es> - * Copyright (C) 2011-2013 Philippe Grand <philippe.grand@atoo-net.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es> +* Copyright (C) 2011-2013 Philippe Grand <philippe.grand@atoo-net.com> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ /** * \file htdocs/admin/project.php * \ingroup project * \brief Page to setup project module - */ +*/ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; @@ -45,7 +45,7 @@ $type='project'; /* * Actions - */ +*/ if ($action == 'updateMask') { @@ -56,14 +56,14 @@ if ($action == 'updateMask') if (! $res > 0) $error++; - if (! $error) - { - $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>"; - } - else - { - $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>"; - } + if (! $error) + { + $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>"; + } + else + { + $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>"; + } } else if ($action == 'specimen') @@ -78,7 +78,7 @@ else if ($action == 'specimen') $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); foreach($dirmodels as $reldir) { - $file=dol_buildpath($reldir."core/modules/project/pdf/pdf_".$modele.".modules.php",0); + $file=dol_buildpath($reldir."core/modules/project/pdf/pdf_".$modele.".modules.php",0); if (file_exists($file)) { $filefound=1; @@ -95,8 +95,8 @@ else if ($action == 'specimen') if ($module->write_file($project,$langs) > 0) { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf"); - return; + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf"); + return; } else { @@ -122,7 +122,7 @@ else if ($action == 'del') $ret = delDocumentModel($value, $type); if ($ret > 0) { - if ($conf->global->PROJECT_ADDON_PDF == "$value") dolibarr_del_const($db, 'PROJECT_ADDON_PDF',$conf->entity); + if ($conf->global->PROJECT_ADDON_PDF == "$value") dolibarr_del_const($db, 'PROJECT_ADDON_PDF',$conf->entity); } } @@ -154,7 +154,7 @@ else if ($action == 'setmod') /* * View - */ +*/ $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); @@ -179,8 +179,8 @@ dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup")); /* * Projects Numbering model - */ - +*/ + print_titre($langs->trans("ProjectsNumberingModules")); print '<table class="noborder" width="100%">'; @@ -284,7 +284,7 @@ print '</table><br>'; /* * Document templates generators - */ +*/ print_titre($langs->trans("ProjectsModelModule")); @@ -337,59 +337,80 @@ foreach ($dirmodels as $reldir) { while (($file = readdir($handle))!==false) { - if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_') + if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) { - $name = substr($file, 4, dol_strlen($file) -16); - $classname = substr($file, 0, dol_strlen($file) -12); - - $var=!$var; - print "<tr ".$bc[$var].">\n <td>$name"; - print "</td>\n <td>\n"; - require_once $dir.$file; - $module = new $classname($db); - print $module->description; - print "</td>\n"; - - // Active - if (in_array($name, $def)) - { - print "<td align=\"center\">\n"; - print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print '</a>'; - print "</td>"; - } - else + if (file_exists($dir.'/'.$file)) { - print "<td align=\"center\">\n"; - print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>'; - print "</td>"; - } + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); - // Default - print "<td align=\"center\">"; - if ($conf->global->PROJECT_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; + require_once $dir.'/'.$file; + $module = new $classname($db); + + $modulequalified=1; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; + + if ($modulequalified) + { + $var=!$var; + print '<tr '.$bc[$var].'><td width="100">'; + print (empty($module->name)?$name:$module->name); + print "</td><td>\n"; + if (method_exists($module,'info')) print $module->info($langs); + else print $module->description; + print "</td>\n"; + + // Active + if (in_array($name, $def)) + { + print "<td align=\"center\">\n"; + print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print '</a>'; + print "</td>"; + } + else + { + print "<td align=\"center\">\n"; + print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>'; + print "</td>"; + } + + // Default + print "<td align=\"center\">"; + if ($conf->global->PROJECT_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&scandir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; + } + print '</td>'; + + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>'; + $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + + // Preview + print '<td align="center">'; + if ($module->type == 'pdf') + { + print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'bill').'</a>'; + } + else + { + print img_object($langs->trans("PreviewNotAvailable"),'generic'); + } + print '</td>'; + + print "</tr>\n"; + } } - print '</td>'; - - // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>'; - $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - print '<td align="center">'; - $link='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'project').'</a>'; - print $form->textwithpicto(' '.$link,$htmltooltip,-1,0); - print '</td>'; - - print "</tr>\n"; } } closedir($handle); diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 877bea83b229361f22ddfad8bb7c8a4538b00e69..a17835ddcc640f7c19fd5803b59ca3a57597d63e 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -86,6 +86,13 @@ class modProjet extends DolibarrModules $this->const[$r][4] = 0; $r++; + $r++; + $this->const[$r][0] = "PROJECT_ADDON_PDF_ODT_PATH"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/project"; + $this->const[$r][3] = ""; + $this->const[$r][4] = 0; + // Boxes $this->boxes = array(); diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php new file mode 100644 index 0000000000000000000000000000000000000000..7ba6defaa3bfb80e2aec8bb207177255f02e8242 --- /dev/null +++ b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php @@ -0,0 +1,481 @@ +<?php +/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es> + * Copyright (C) 2013 Florian Henry <florian.henry@ope-concept.pro> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php + * \ingroup commande + * \brief File of class to build ODT documents for third parties + */ + +require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php'; + + +/** + * Class to build documents using ODF templates generator + */ +class doc_generic_project_odt extends ModelePDFProjects +{ + var $emetteur; // Objet societe qui emet + + var $phpmin = array(5,2,0); // Minimum version of PHP required by module + var $version = 'dolibarr'; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + global $conf,$langs,$mysoc; + + $langs->load("main"); + $langs->load("companies"); + + $this->db = $db; + $this->name = "ODT templates"; + $this->description = $langs->trans("DocumentModelOdt"); + $this->scandir = 'PROJECT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan + + // Dimension page pour format A4 + $this->type = 'odt'; + $this->page_largeur = 0; + $this->page_hauteur = 0; + $this->format = array($this->page_largeur,$this->page_hauteur); + $this->marge_gauche=0; + $this->marge_droite=0; + $this->marge_haute=0; + $this->marge_basse=0; + + $this->option_logo = 1; // Affiche logo + $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION + $this->option_modereg = 0; // Affiche mode reglement + $this->option_condreg = 0; // Affiche conditions reglement + $this->option_codeproduitservice = 0; // Affiche code produit-service + $this->option_multilang = 0; // Dispo en plusieurs langues + $this->option_escompte = 0; // Affiche si il y a eu escompte + $this->option_credit_note = 0; // Support credit notes + $this->option_freetext = 1; // Support add of a personalised text + $this->option_draft_watermark = 0; // Support add of a watermark on drafts + + // Recupere emetteur + $this->emetteur=$mysoc; + if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini + } + + + /** + * Define array with couple substitution key => substitution value + * + * @param Object $object Main object to use as data source + * @param Translate $outputlangs Lang object to use for output + * @return array Array of substitution + */ + function get_substitutionarray_object($object,$outputlangs) + { + global $conf; + dol_syslog(get_class($this)."::get_substitutionarray_object object=".var_export($object,true), LOG_DEBUG); + return array( + 'object_id'=>$object->id, + 'object_ref'=>$object->ref, + 'object_title'=>$object->title, + 'object_description'=>$object->description, + 'object_date_creation'=>dol_print_date($object->date_c,'day'), + 'object_date_modification'=>dol_print_date($object->date_m,'day'), + 'object_date_start'=>dol_print_date($object->date_start,'day'), + 'object_date_end'=>dol_print_date($object->date_end,'day'), + 'object_note_private'=>$object->note_private, + 'object_note_public'=>$object->note_public, + 'object_public'=>$object->public, + 'object_statut'=>$object->getLibStatut() + ); + } + + /** + * Define array with couple substitution key => substitution value + * + * @param array $line Array of lines + * @param Translate $outputlangs Lang object to use for output + * @return array Return a substitution array + */ + function get_substitutionarray_lines($line,$outputlangs) + { + global $conf; + + return array( + 'line_ref'=>$line->ref, + 'line_fk_project'=>$line->fk_project, + 'line_projectref'=>$line->projectref, + 'line_projectlabel'=>$line->projectlabel, + 'line_label'=>$line->label, + 'line_description'=>$line->description, + 'line_fk_parent'=>$line->fk_parent, + 'line_duration'=>$line->duration, + 'line_progress'=>$line->progress, + 'line_public'=>$line->public, + 'line_date_start'=>dol_print_date($line->date_start,'day'), + 'line_date_end'=>dol_print_date($line->date_end,'day') + ); + } + + /** + * Return description of a module + * + * @param Translate $langs Lang object to use for output + * @return string Description + */ + function info($langs) + { + global $conf,$langs; + + $langs->load("companies"); + $langs->load("errors"); + + $form = new Form($this->db); + + $texte = $this->description.".<br>\n"; + $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; + $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; + $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; + $texte.= '<input type="hidden" name="param1" value="PROJECT_ADDON_PDF_ODT_PATH">'; + $texte.= '<table class="nobordernopadding" width="100%">'; + + // List of directories area + $texte.= '<tr><td>'; + $texttitle=$langs->trans("ListOfDirectories"); + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROJECT_ADDON_PDF_ODT_PATH))); + $listoffiles=array(); + foreach($listofdir as $key=>$tmpdir) + { + $tmpdir=trim($tmpdir); + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); + if (! $tmpdir) { unset($listofdir[$key]); continue; } + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); + else + { + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.odt'); + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); + } + } + $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); + // Add list of substitution keys + $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it + + $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); + $texte.= '<table><tr><td>'; + $texte.= '<textarea class="flat" cols="60" name="value1">'; + $texte.=$conf->global->PROJECT_ADDON_PDF_ODT_PATH; + $texte.= '</textarea>'; + $texte.= '</td>'; + $texte.= '<td align="center"> '; + $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; + $texte.= '</td>'; + $texte.= '</tr>'; + $texte.= '</table>'; + + // Scan directories + if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; + + $texte.= '</td>'; + + + $texte.= '<td valign="top" rowspan="2">'; + $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); + $texte.= '</td>'; + $texte.= '</tr>'; + + /*$texte.= '<tr>'; + $texte.= '<td align="center">'; + $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; + $texte.= '</td>'; + $texte.= '</tr>';*/ + + $texte.= '</table>'; + $texte.= '</form>'; + + return $texte; + } + + /** + * Function to build a document on disk using the generic odt module. + * + * @param Commande $object Object source to build document + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @return int 1 if OK, <=0 if KO + */ + function write_file($object,$outputlangs,$srctemplatepath) + { + global $user,$langs,$conf,$mysoc; + + if (empty($srctemplatepath)) + { + dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); + return -1; + } + + if (! is_object($outputlangs)) $outputlangs=$langs; + $sav_charset_output=$outputlangs->charset_output; + $outputlangs->charset_output='UTF-8'; + + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("projects"); + + if ($conf->projet->dir_output) + { + // If $object is id instead of object + if (! is_object($object)) + { + $id = $object; + $object = new Project($this->db); + $result=$object->fetch($id); + if ($result < 0) + { + dol_print_error($this->db,$object->error); + return -1; + } + } + + $dir = $conf->projet->dir_output; + $objectref = dol_sanitizeFileName($object->ref); + if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; + $file = $dir . "/" . $objectref . ".odt"; + + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); + return -1; + } + } + + if (file_exists($dir)) + { + //print "srctemplatepath=".$srctemplatepath; // Src filename + $newfile=basename($srctemplatepath); + $newfiletmp=preg_replace('/\.odt/i','',$newfile); + $newfiletmp=preg_replace('/template_/i','',$newfiletmp); + $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); + $newfiletmp=$objectref.'_'.$newfiletmp; + //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; + $file=$dir.'/'.$newfiletmp.'.odt'; + //print "newdir=".$dir; + //print "newfile=".$newfile; + //print "file=".$file; + //print "conf->societe->dir_temp=".$conf->societe->dir_temp; + + dol_mkdir($conf->projet->dir_temp); + + + // List of all contact + $usecontact=false; + $arrayidcontact=$object->liste_contact(-1,'internal'); + if (count($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]['id']); + } + + $socobject=$object->thirdparty; + + // Make substitution + $substitutionarray=array( + '__FROM_NAME__' => $this->emetteur->nom, + '__FROM_EMAIL__' => $this->emetteur->email, + ); + complete_substitutions_array($substitutionarray, $langs, $object); + + // Open and load template + require_once ODTPHP_PATH.'odf.php'; + $odfHandler = new odf( + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->projet->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' + ) + ); + // After construction $odfHandler->contentXml contains content and + // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by + // [!-- BEGIN lines --]*[!-- END lines --] + //print html_entity_decode($odfHandler->__toString()); + //print exit; + + // Make substitutions into odt of user info + $tmparray=$this->get_substitutionarray_user($user,$outputlangs); + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + // Make substitutions into odt of mysoc + $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + + // Make substitutions into odt of thirdparty + $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + + // Replace tags of object + external modules + $tmparray=$this->get_substitutionarray_object($object,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object); + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + + // Replace tags of lines + try + { + $listlines = $odfHandler->setSegment('lines'); + + $taskstatic = new Task($this->db); + + // Security check + $socid=0; + if (!empty($object->fk_soc)) $socid = $object->fk_soc; + + $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); + + foreach ($tasksarray as $task) + { + $tmparray=$this->get_substitutionarray_lines($task,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object, $task, "completesubstitutionarray_lines"); + foreach($tmparray as $key => $val) + { + try + { + $listlines->setVars($key, $val, true, 'UTF-8'); + } + catch(OdfException $e) + { + } + catch(SegmentException $e) + { + } + } + $listlines->merge(); + } + $odfHandler->mergeSegment($listlines); + } + catch(OdfException $e) + { + $this->error=$e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; + } + + // Write new file + //$result=$odfHandler->exportAsAttachedFile('toto'); + $odfHandler->saveToDisk($file); + + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); + + $odfHandler=null; // Destroy object + + return 1; // Success + } + else + { + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); + return -1; + } + } + + return -1; + } + +} + +?> diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 97eb27745a8d811c30f39563a83b1c1ab240efb0..226d7246e9b5b05f9f6325d0b68b691d96e6e465 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -260,7 +260,7 @@ class Project extends CommonObject if (empty($id) && empty($ref)) return -1; $sql = "SELECT rowid, ref, title, description, public, datec"; - $sql.= ", tms, dateo, datee, fk_soc, fk_user_creat, fk_statut, note_private, note_public"; + $sql.= ", tms, dateo, datee, fk_soc, fk_user_creat, fk_statut, note_private, note_public,model_pdf"; $sql.= " FROM " . MAIN_DB_PREFIX . "projet"; if (! empty($id)) { @@ -298,6 +298,7 @@ class Project extends CommonObject $this->user_author_id = $obj->fk_user_creat; $this->public = $obj->public; $this->statut = $obj->fk_statut; + $this->modelpdf = $obj->model_pdf; $this->db->free($resql);