diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index 4c3ee7207df..2abb2b5acad 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -35,8 +35,9 @@ if (!$user->admin) accessforbidden(); $action = GETPOST('action','alpha'); $value = GETPOST('value','alpha'); +$label = GETPOST('label','alpha'); $scandir = GETPOST('scandir','alpha'); -$type='contrat'; +$type='contract'; if (empty($conf->global->CONTRACT_ADDON)) { @@ -111,6 +112,35 @@ else if ($action == 'specimen') // For contract } } +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $post_size=count($_POST); + + $db->begin(); + + for($i=0;$i < $post_size;$i++) + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + if (! $error) + { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + } + else + { + $db->rollback(); + setEventMessage($langs->trans("Error"),'errors'); + } +} + // Activate a model else if ($action == 'set') { @@ -192,7 +222,7 @@ else if ($action == 'set_CONTRACT_DRAFT_WATERMARK') */ $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); - + llxHeader(); $form=new Form($db); @@ -318,7 +348,6 @@ print '
'; print_titre($langs->trans("TemplatePDFContracts")); // Defini tableau def des modeles -$type='contrat'; $def = array(); $sql = "SELECT nom"; $sql.= " FROM ".MAIN_DB_PREFIX."document_model"; diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index 5503a906af2..328866eb964 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -171,28 +171,27 @@ if ($action == 'setModuleOptions') $db->begin(); for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } if (! $error) - { - $db->commit(); - setEventMessage($langs->trans("SetupSaved")); - } - else - { - $db->rollback(); - setEventMessage($langs->trans("Error"),'errors'); + { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + } + else + { + $db->rollback(); + setEventMessage($langs->trans("Error"),'errors'); } } - // Activate a model if ($action == 'set') { diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 5cb25a5bed4..c4596c96a76 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2013 Christophe Battarel @@ -29,17 +29,18 @@ */ require ("../main.inc.php"); -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; -if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/contract.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/modules/contract/modules_contract.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; +if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; if (! empty($conf->projet->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; + require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; } require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; @@ -70,6 +71,15 @@ $hookmanager->initHooks(array('contractcard')); $object = new Contrat($db); $extrafields = new ExtraFields($db); +// Load object +if ($id > 0 || ! empty($ref)) { + $ret = $object->fetch($id, $ref); + if ($ret > 0) + $ret = $object->fetch_thirdparty(); + if ($ret < 0) + dol_print_error('', $object->error); +} + // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); @@ -84,7 +94,6 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { - $object->fetch($id); $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); if ($result > 0) @@ -106,7 +115,6 @@ else if ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->c } if (! $error) { - $object->fetch($id); $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment'))); if ($result > 0) { @@ -363,7 +371,6 @@ if ($action == 'add' && $user->rights->contrat->creer) else if ($action == 'classin' && $user->rights->contrat->creer) { - $object->fetch($id); $object->setProject(GETPOST('projectid')); } @@ -402,14 +409,6 @@ else if ($action == 'addline' && $user->rights->contrat->creer) if (! $error) { - $ret=$object->fetch($id); - if ($ret < 0) - { - setEventMessage($object->error,'errors'); - exit; - } - $ret=$object->fetch_thirdparty(); - // Clean parameters $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); @@ -584,14 +583,6 @@ else if ($action == 'addline' && $user->rights->contrat->creer) else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST('cancel')) { - $ret=$object->fetch($id); - if ($ret < 0) - { - dol_print_error($db,$object->error); - exit; - } - - $object->fetch_thirdparty(); $objectline = new ContratLigne($db); if ($objectline->fetch(GETPOST('elrowid'))) { @@ -647,7 +638,6 @@ else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST( else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) { - $object->fetch($id); $result = $object->deleteline(GETPOST('lineid'),$user); if ($result >= 0) @@ -663,21 +653,17 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) { - $object->fetch($id); $result = $object->validate($user); } // Close all lines else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) { - $object->fetch($id); $result = $object->cloture($user); } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) { - $object->fetch($id); - $object->fetch_thirdparty(); $result=$object->delete($user); if ($result >= 0) { @@ -714,7 +700,6 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra } } else if ($action == 'update_extras') { // Fill array 'array_options' with data from update form - $object->fetch($id); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) @@ -734,10 +719,6 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra setEventMessage($object->error,'errors'); } } elseif ($action=='setref_customer') { - $result = $object->fetch($id); - if ($result < 0) { - setEventMessage($object->errors,'errors'); - } $object->ref_customer=GETPOST('ref_customer','alpha'); $result = $object->update($user); @@ -749,10 +730,6 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra exit; } } elseif ($action=='setref') { - $result = $object->fetch($id); - if ($result < 0) { - setEventMessage($object->errors,'errors'); - } $object->ref=GETPOST('ref','alpha'); $result = $object->update($user); @@ -765,17 +742,53 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra } } +// Generation doc (depuis lien ou depuis cartouche doc) +else if ($action == 'builddoc' && $user->rights->contrat->creer) { + if (GETPOST('model')) { + $object->setDocModel($user, GETPOST('model')); + } + + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) { + $outputlangs = new Translate("", $conf); + $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret = $object->fetch($id); // Reload to get new records + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + + if ($result <= 0) { + dol_print_error($db, $result); + exit(); + } else { + header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc')); + exit(); + } +} + +// Remove file in doc form +else if ($action == 'remove_file' && $user->rights->contrat->creer) { + if ($object->id > 0) { + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + + $langs->load("other"); + $upload_dir = $conf->contrat->dir_output; + $file = $upload_dir . '/' . GETPOST('file'); + $ret = dol_delete_file($file, 0, 0, 0, $object); + if ($ret) + setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); + else + setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); + } +} + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) { if ($action == 'addcontact') { - $result = $object->fetch($id); - - if ($result > 0 && $id > 0) - { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source')); - } + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); + $result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source')); if ($result >= 0) { @@ -799,20 +812,12 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat- // bascule du statut d'un contact else if ($action == 'swapstatut') { - if ($object->fetch($id)) - { - $result=$object->swapContactStatus(GETPOST('ligne')); - } - else - { - setEventMessage($object->error,'errors'); - } + $result=$object->swapContactStatus(GETPOST('ligne')); } // Efface un contact else if ($action == 'deletecontact') { - $object->fetch($id); $result = $object->delete_contact(GETPOST('lineid')); if ($result >= 0) @@ -834,6 +839,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat- llxHeader('',$langs->trans("ContractCard"),"Contrat"); $form = new Form($db); +$formfile = new FormFile($db); $objectlignestatic=new ContratLigne($db); @@ -1032,14 +1038,10 @@ else { $now=dol_now(); - if ($id > 0 || ! empty($ref)) + if ($object->id > 0) { - $result=$object->fetch($id,$ref); - if ($result < 0) dol_print_error($db,$object->error); $result=$object->fetch_lines(); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed if ($result < 0) dol_print_error($db,$object->error); - $result=$object->fetch_thirdparty(); - if ($result < 0) dol_print_error($db,$object->error); $nbofservices=count($object->lines); @@ -1793,16 +1795,29 @@ else print ""; } + print '
'; - print '
'; + /* + * Documents generes + */ + $filename = dol_sanitizeFileName($object->ref); + $filedir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); + $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; + $genallowed = $user->rights->contrat->creer; + $delallowed = $user->rights->contrat->supprimer; + + $var = true; + + $somethingshown = $formfile->show_documents('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); /* * Linked object block - */ - $somethingshown=$object->showLinkedObjectBlock(); + */ + $somethingshown = $object->showLinkedObjectBlock(); - print ''; - print '
'; + print '
'; + + print '
'; } } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 0a71f9eee2e..0ddb1618f34 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2012 Destailleur Laurent - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2008 Raphael Bertrand * Copyright (C) 2010-2014 Juanjo Menent @@ -65,6 +65,7 @@ class Contrat extends CommonObject var $note; // deprecated var $note_private; var $note_public; + var $modelpdf; var $fk_projet; @@ -401,7 +402,7 @@ class Contrat extends CommonObject $sql.= " fk_user_author,"; $sql.= " fk_projet,"; $sql.= " fk_commercial_signature, fk_commercial_suivi,"; - $sql.= " note_private, note_public, extraparams"; + $sql.= " note_private, note_public, model_pdf, extraparams"; $sql.= " ,ref_customer"; $sql.= " ,ref_ext"; $sql.= " FROM ".MAIN_DB_PREFIX."contrat"; @@ -436,6 +437,7 @@ class Contrat extends CommonObject $this->note = $result["note_private"]; // deprecated $this->note_private = $result["note_private"]; $this->note_public = $result["note_public"]; + $this->modelpdf = $result["model_pdf"]; $this->fk_projet = $result["fk_projet"]; // deprecated $this->fk_project = $result["fk_projet"]; @@ -744,7 +746,7 @@ class Contrat extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat"); - + // Load object modContract $module=(! empty($conf->global->CONTRACT_ADDON)?$conf->global->CONTRACT_ADDON:'mod_contract_olive'); if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') @@ -1866,6 +1868,40 @@ class Contrat extends CommonObject $this->total_tva = $xnbp*19.6; $this->total_ttc = $xnbp*119.6; } + + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force model to use ('' to not force) + * @param Translate $outputlangs Object langs to use for output + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf,$user,$langs; + + $langs->load("contracts"); + + // Positionne le modele sur le nom du modele a utiliser + if (! dol_strlen($modele)) + { + if (! empty($conf->global->CONTRACT_ADDON_PDF)) + { + $modele = $conf->global->CONTRACT_ADDON_PDF; + } + else + { + $modele = 'strato'; + } + } + + $modelpath = "core/modules/contract/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 447f96ff61c..e473fdc3d98 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -355,6 +355,15 @@ class FormFile $modellist=ModelePDFFactures::liste_modeles($this->db); } } + elseif ($modulepart == 'contract') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; + $modellist=ModelePDFContract::liste_modeles($this->db); + } + } elseif ($modulepart == 'project') { if (is_array($genallowed)) $modellist=$genallowed; diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php similarity index 99% rename from htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php rename to htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php index 5b3aa9a85e2..fc18f1068ce 100644 --- a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php @@ -19,7 +19,7 @@ */ /** - * \file htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php + * \file htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php * \ingroup project * \brief File of class to build ODT documents for third parties */ diff --git a/htdocs/core/modules/project/pdf/index.html b/htdocs/core/modules/project/doc/index.html similarity index 100% rename from htdocs/core/modules/project/pdf/index.html rename to htdocs/core/modules/project/doc/index.html diff --git a/htdocs/core/modules/project/pdf/pdf_baleine.modules.php b/htdocs/core/modules/project/doc/pdf_baleine.modules.php similarity index 99% rename from htdocs/core/modules/project/pdf/pdf_baleine.modules.php rename to htdocs/core/modules/project/doc/pdf_baleine.modules.php index 502e98eece2..6ce839daf99 100644 --- a/htdocs/core/modules/project/pdf/pdf_baleine.modules.php +++ b/htdocs/core/modules/project/doc/pdf_baleine.modules.php @@ -17,7 +17,7 @@ */ /** - * \file htdocs/core/modules/project/pdf/pdf_baleine.modules.php + * \file htdocs/core/modules/project/doc/pdf_baleine.modules.php * \ingroup project * \brief Fichier de la classe permettant de generer les projets au modele Baleine * \author Regis Houssin diff --git a/htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php similarity index 96% rename from htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php rename to htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php index acbd33bcc5a..dd70a49f3e1 100644 --- a/htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php +++ b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php @@ -1,28 +1,28 @@ * Copyright (C) 2012 Juanjo Menent -* Copyright (C) 2013 Florian Henry -* -* 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 . -* or see http://www.gnu.org/ -*/ + * Copyright (C) 2013 Florian Henry + * + * 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 . + * or see http://www.gnu.org/ + */ /** - * \file htdocs/core/modules/project/task/pdf/doc_generic_task_odt.modules.php + * \file htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php * \ingroup project * \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.'/core/modules/project/task/modules_task.php'; @@ -304,7 +304,7 @@ class doc_generic_task_odt extends ModelePDFTask $texte = $this->description.".
\n"; $texte.= '
'; $texte.= ''; - $texte.= ''; + $texte.= ''; $texte.= ''; $texte.= ''; @@ -367,7 +367,7 @@ class doc_generic_task_odt extends ModelePDFTask */ function write_file($object,$outputlangs,$srctemplatepath) { - global $user,$langs,$conf,$mysoc; + global $user,$langs,$conf,$mysoc,$hookmanager; if (empty($srctemplatepath)) { @@ -819,8 +819,8 @@ class doc_generic_task_odt extends ModelePDFTask // Call the beforeODTSave hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - - + + // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { try { @@ -838,9 +838,9 @@ class doc_generic_task_odt extends ModelePDFTask return -1; } } - + $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - + if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); diff --git a/htdocs/core/modules/project/task/pdf/index.html b/htdocs/core/modules/project/task/doc/index.html similarity index 100% rename from htdocs/core/modules/project/task/pdf/index.html rename to htdocs/core/modules/project/task/doc/index.html diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 9e109cd311f..778b3f2b9ff 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1083,3 +1083,5 @@ CREATE TABLE llx_usergroup_extrafields ( ) ENGINE=innodb; ALTER TABLE llx_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); + +ALTER TABLE llx_contrat ADD COLUMN model_pdf varchar(255) DEFAULT NULL AFTER note_public; diff --git a/htdocs/install/mysql/tables/llx_contrat.sql b/htdocs/install/mysql/tables/llx_contrat.sql index 496ecd4c97d..4631b660d46 100644 --- a/htdocs/install/mysql/tables/llx_contrat.sql +++ b/htdocs/install/mysql/tables/llx_contrat.sql @@ -1,7 +1,7 @@ -- ============================================================================ -- Copyright (C) 2002-2004 Rodolphe Quiedeville -- Copyright (C) 2004-2005 Laurent Destailleur --- Copyright (C) 2005-2012 Regis Houssin +-- Copyright (C) 2005-2014 Regis Houssin -- -- 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 @@ -40,6 +40,7 @@ create table llx_contrat fk_user_cloture integer, note_private text, note_public text, + model_pdf varchar(255), import_key varchar(14), extraparams varchar(255) diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index a23f65edafb..bf9951129ad 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -1,9 +1,9 @@ - * Copyright (C) 2011 Laurent Destailleur - * Copyright (C) 2011-2012 Juanjo Menent - * Copyright (C) 2011-2013 Philippe Grand - * Copyright (C) 2013 Florian Henry +/* Copyright (C) 2010-2014 Regis Houssin + * Copyright (C) 2011 Laurent Destailleur + * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2011-2013 Philippe Grand + * Copyright (C) 2013 Florian Henry * * 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 @@ -99,7 +99,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/doc/pdf_".$modele.".modules.php",0); if (file_exists($file)) { $filefound=1; @@ -144,7 +144,7 @@ else if ($action == 'specimentask') $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); foreach($dirmodels as $reldir) { - $file=dol_buildpath($reldir."core/modules/project/task/pdf/pdf_".$modele.".modules.php",0); + $file=dol_buildpath($reldir."core/modules/project/task/doc/pdf_".$modele.".modules.php",0); if (file_exists($file)) { $filefound=1; @@ -177,6 +177,35 @@ else if ($action == 'specimentask') } } +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $post_size=count($_POST); + + $db->begin(); + + for($i=0;$i < $post_size;$i++) + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + if (! $error) + { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + } + else + { + $db->rollback(); + setEventMessage($langs->trans("Error"),'errors'); + } +} + // Activate a model else if ($action == 'set') { @@ -256,26 +285,10 @@ else if ($action == 'setmodtask') dolibarr_set_const($db, "PROJECT_TASK_ADDON",$value,'chaine',0,'',$conf->entity); } -else if ($action=='setModuleOptions') { - if (dolibarr_set_const($db, "PROJECT_ADDON_PDF_ODT_PATH",GETPOST('value1'),'chaine',0,'',$conf->entity)) - { - // La constante qui a ete lue en avant du nouveau set - // on passe donc par une variable pour avoir un affichage coherent - $conf->global->PROJECT_ADDON_PDF_ODT_PATH = GETPOST('value1'); - } -} -else if ($action=='setModuleOptionsTask') { - if (dolibarr_set_const($db, "PROJECT_TASK_ADDON_PDF_ODT_PATH",GETPOST('value1'),'chaine',0,'',$conf->entity)) - { - // La constante qui a ete lue en avant du nouveau set - // on passe donc par une variable pour avoir un affichage coherent - $conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH = GETPOST('value1'); - } -} /* * View -*/ + */ $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); @@ -542,99 +555,108 @@ clearstatcache(); $var=true; foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/project/pdf/"); - - if (is_dir($dir)) + foreach (array('','/doc') as $valdir) { - $handle=opendir($dir); - if (is_resource($handle)) + $dir = dol_buildpath($reldir."core/modules/project/".$valdir); + + if (is_dir($dir)) { - while (($file = readdir($handle))!==false) + $handle=opendir($dir); + if (is_resource($handle)) { - if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) + while (($file = readdir($handle))!==false) { - if (file_exists($dir.'/'.$file)) + $filelist[]=$file; + } + closedir($handle); + arsort($filelist); + + foreach($filelist as $file) + { + 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); - - 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) + if (file_exists($dir.'/'.$file)) { - $var=!$var; - print '\n"; + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); - // Active - if (in_array($name, $def)) - { - print ""; - } - else - { - print ""; - } + require_once $dir.'/'.$file; + $module = new $classname($db); - // Default - print "'; + $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; - // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - if ($module->type == 'pdf') + if ($modulequalified) { - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - } - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - - print ''; + $var=!$var; + print '\n"; - // Preview - print ''; + // Active + if (in_array($name, $def)) + { + print ""; + } + else + { + print ""; + } - print "\n"; - } + // Default + print "'; + + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + if ($module->type == 'pdf') + { + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + } + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + + print ''; + + // Preview + print ''; + + print "\n"; + } + } } } } - closedir($handle); } } } @@ -688,98 +710,107 @@ clearstatcache(); $var=true; foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/project/task/pdf/"); - - if (is_dir($dir)) + foreach (array('','/doc') as $valdir) { - $handle=opendir($dir); - if (is_resource($handle)) + $dir = dol_buildpath($reldir."core/modules/project/task/".$valdir); + + if (is_dir($dir)) { - while (($file = readdir($handle))!==false) + $handle=opendir($dir); + if (is_resource($handle)) { - if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) + while (($file = readdir($handle))!==false) { - if (file_exists($dir.'/'.$file)) + $filelist[]=$file; + } + closedir($handle); + arsort($filelist); + + foreach($filelist as $file) + { + 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); - - 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) + if (file_exists($dir.'/'.$file)) { - $var = !$var; - print '\n"; + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); - // Active - if (in_array($name, $def)) - { - print ""; - } - else - { - print ""; - } + require_once $dir.'/'.$file; + $module = new $classname($db); - // Defaut - print "'; + $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; - // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - if ($module->type == 'pdf') + if ($modulequalified) { - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - } - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - - print ''; + $var = !$var; + print '\n"; - // Preview - print '"; + } + else + { + print ""; + } + + // Defaut + print "'; + + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + if ($module->type == 'pdf') + { + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + } + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + + print ''; + + // Preview + print ''; + print "\n"; } - else - { - print img_object($langs->trans("PreviewNotAvailable"),'generic'); - } - print ''; - print "\n"; } } } } - closedir($handle); } } } diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index fb7da8636b2..9659eb2ffe8 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1368,7 +1368,7 @@ class Project extends CommonObject } } - $modelpath = "core/modules/project/pdf/"; + $modelpath = "core/modules/project/doc/"; return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 2f4cc85cf7f..13360110310 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1343,7 +1343,7 @@ class Task extends CommonObject } } - $modelpath = "core/modules/project/task/pdf/"; + $modelpath = "core/modules/project/task/doc/"; return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php index 3f20b99fd14..3ed7a6524c7 100644 --- a/test/phpunit/BuildDocTest.php +++ b/test/phpunit/BuildDocTest.php @@ -42,7 +42,7 @@ require_once dirname(__FILE__).'/../../htdocs/core/lib/pdf.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/doc/pdf_crabe.modules.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/doc/pdf_azur.modules.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/doc/pdf_einstein.modules.php'; -require_once dirname(__FILE__).'/../../htdocs/core/modules/project/pdf/pdf_baleine.modules.php'; +require_once dirname(__FILE__).'/../../htdocs/core/modules/project/doc/pdf_baleine.modules.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/doc/pdf_merou.modules.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/doc/pdf_rouget.modules.php';
'; - print (empty($module->name)?$name:$module->name); - print "\n"; - if (method_exists($module,'info')) print $module->info($langs); - else print $module->description; - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print ''; - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; - print ""; - if ($conf->global->PROJECT_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; - } - print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print '
'; + print (empty($module->name)?$name:$module->name); + print "\n"; + if (method_exists($module,'info')) print $module->info($langs); + else print $module->description; + print "'; - if ($module->type == 'pdf') - { - print ''.img_object($langs->trans("Preview"),'bill').''; - } - else - { - print img_object($langs->trans("PreviewNotAvailable"),'generic'); - } - print '\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print "
"; + if ($conf->global->PROJECT_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + if ($module->type == 'pdf') + { + print ''.img_object($langs->trans("Preview"),'bill').''; + } + else + { + print img_object($langs->trans("PreviewNotAvailable"),'generic'); + } + print '
'; - print (empty($module->name)?$name:$module->name); - print "\n"; - if (method_exists($module,'info')) print $module->info($langs); - else print $module->description; - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print ''; - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; - print ""; - if ($conf->global->PROJECT_TASK_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; - } - print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print '
'; + print (empty($module->name)?$name:$module->name); + print "\n"; + if (method_exists($module,'info')) print $module->info($langs); + else print $module->description; + print "'; - if ($module->type == 'pdf') - { - print ''.img_object($langs->trans("Preview"),'bill').''; + // Active + if (in_array($name, $def)) + { + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print ""; + if ($conf->global->PROJECT_TASK_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + if ($module->type == 'pdf') + { + print ''.img_object($langs->trans("Preview"),'bill').''; + } + else + { + print img_object($langs->trans("PreviewNotAvailable"),'generic'); + } + print '