/** * Return a string to show the box with list of available documents for object. * This also set the property $this->numoffiles * * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...) * @param string $modulesubdir Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. * @param string $filedir Directory to scan * @param string $urlsource Url of origin page (for return) * @param int $genallowed Generation is allowed (1/0 or array list of templates) * @param int $delallowed Remove is allowed (1/0) * @param string $modelselected Model to preselect by default * @param string $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) * @param int $iconPDF Deprecated, see getDocumentsLink * @param int $maxfilenamelength Max length for filename shown * @param string $noform Do not output html form tags * @param string $param More param on http links * @param string $title Title to show on top of form * @param string $buttonlabel Label on submit button * @param string $codelang Default language code to use on lang combo box if multilang is enabled * @param string $morepicto Add more HTML content into cell with picto * @return string Output string with HTML array of documents (might be empty string) */ function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $maxfilenamelength = 28, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '', $morepicto = '') { // Deprecation warning if (0 !== $iconPDF) { dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING); } global $langs, $conf, $user, $hookmanager; global $form, $bc; if (!is_object($form)) { $form = new Form($this->db); } include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; // For backward compatibility if (!empty($iconPDF)) { return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir); } $printer = 0; if (in_array($modulepart, array('facture', 'supplier_proposal', 'propal', 'proposal', 'order', 'commande', 'expedition', 'commande_fournisseur'))) { $printer = !empty($user->rights->printing->read) && !empty($conf->printing->enabled) ? true : false; } $hookmanager->initHooks(array('formfile')); $forname = 'builddoc'; $out = ''; $var = true; $headershown = 0; $showempty = 0; $i = 0; $titletoshow = $langs->trans("Documents"); if (!empty($title)) { $titletoshow = $title; } $out .= "\n" . '<!-- Start show_document -->' . "\n"; //print 'filedir='.$filedir; // Show table if ($genallowed) { $modellist = array(); if ($modulepart == 'company') { $showempty = 1; if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php'; $modellist = ModeleThirdPartyDoc::liste_modeles($this->db); } } else { if ($modulepart == 'propal') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php'; $modellist = ModelePDFPropales::liste_modeles($this->db); } } else { if ($modulepart == 'supplier_proposal') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_proposal/modules_supplier_proposal.php'; $modellist = ModelePDFSupplierProposal::liste_modeles($this->db); } } else { if ($modulepart == 'commande') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php'; $modellist = ModelePDFCommandes::liste_modeles($this->db); } } elseif ($modulepart == 'expedition') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php'; $modellist = ModelePDFExpedition::liste_modeles($this->db); } } elseif ($modulepart == 'livraison') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/livraison/modules_livraison.php'; $modellist = ModelePDFDeliveryOrder::liste_modeles($this->db); } } else { if ($modulepart == 'ficheinter') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/fichinter/modules_fichinter.php'; $modellist = ModelePDFFicheinter::liste_modeles($this->db); } } elseif ($modulepart == 'facture') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; $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; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/project/modules_project.php'; $modellist = ModelePDFProjects::liste_modeles($this->db); } } elseif ($modulepart == 'project_task') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/project/task/modules_task.php'; $modellist = ModelePDFTask::liste_modeles($this->db); } } elseif ($modulepart == 'export') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/export/modules_export.php'; $modellist = ModeleExports::liste_modeles($this->db); } } else { if ($modulepart == 'commande_fournisseur') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php'; $modellist = ModelePDFSuppliersOrders::liste_modeles($this->db); } } else { if ($modulepart == 'facture_fournisseur') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php'; $modellist = ModelePDFSuppliersInvoices::liste_modeles($this->db); } } else { if ($modulepart == 'remisecheque') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/cheque/pdf/modules_chequereceipts.php'; $modellist = ModeleChequeReceipts::liste_modeles($this->db); } } elseif ($modulepart == 'donation') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php'; $modellist = ModeleDon::liste_modeles($this->db); } } else { if ($modulepart == 'unpaid') { $modellist = ''; } else { if ($modulepart != 'agenda') { // For normalized standard modules $file = dol_buildpath('/core/modules/' . $modulepart . '/modules_' . $modulepart . '.php', 0); if (file_exists($file)) { $res = (include_once $file); } else { $file = dol_buildpath('/' . $modulepart . '/core/modules/' . $modulepart . '/modules_' . $modulepart . '.php', 0); $res = (include_once $file); } $class = 'Modele' . ucfirst($modulepart); if (class_exists($class)) { $modellist = call_user_func($class . '::liste_modeles', $this->db); } else { dol_print_error($this->db, 'Bad value for modulepart'); return -1; } } } } } } } } } } } $headershown = 1; $buttonlabeltoshow = $buttonlabel; if (empty($buttonlabel)) { $buttonlabel = $langs->trans('Generate'); } if (empty($noform)) { $out .= '<form action="' . $urlsource . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc') . '" name="' . $forname . '" id="' . $forname . '_form" method="post">'; } $out .= '<input type="hidden" name="action" value="builddoc">'; $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; $out .= load_fiche_titre($titletoshow, '', ''); $out .= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">'; $out .= '<tr class="liste_titre">'; // Model if (!empty($modellist)) { $out .= '<th align="center" class="formdoc liste_titre maxwidthonsmartphone">'; $out .= '<span class="hideonsmartphone">' . $langs->trans('Model') . ' </span>'; if (is_array($modellist) && count($modellist) == 1) { $arraykeys = array_keys($modellist); $modelselected = $arraykeys[0]; } $out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', ''); $out .= '</th>'; } else { $out .= '<th align="left" class="formdoc liste_titre">'; $out .= $langs->trans("Files"); $out .= '</th>'; } // Language code (if multilang) $out .= '<th align="center" class="formdoc liste_titre maxwidthonsmartphone">'; if (($allowgenifempty || is_array($modellist) && count($modellist) > 0) && $conf->global->MAIN_MULTILANGS && !$forcenomultilang && (!empty($modellist) || $showempty)) { include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php'; $formadmin = new FormAdmin($this->db); $defaultlang = $codelang ? $codelang : $langs->getDefaultLang(); $morecss = 'maxwidth150'; if (!empty($conf->browser->phone)) { $morecss = 'maxwidth100'; } $out .= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss); } else { $out .= ' '; } $out .= '</th>'; // Button $addcolumforpicto = $delallowed || $printer || $morepicto; $out .= '<th align="center" colspan="' . ($addcolumforpicto ? '2' : '1') . '" class="formdocbutton liste_titre maxwidthonsmartphone">'; $genbutton = '<input class="button" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"'; $genbutton .= ' type="submit" value="' . $buttonlabel . '"'; if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) { $genbutton .= ' disabled'; } $genbutton .= '>'; if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') { $langs->load("errors"); $genbutton .= ' ' . img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); } if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') { $genbutton = ''; } if (empty($modellist) && !$showempty && $modulepart != 'unpaid') { $genbutton = ''; } $out .= $genbutton; $out .= '</th>'; if (!empty($hookmanager->hooks['formfile'])) { foreach ($hookmanager->hooks['formfile'] as $module) { if (method_exists($module, 'formBuilddocLineOptions')) { $out .= '<th></th>'; } } } $out .= '</tr>'; // Execute hooks $parameters = array('socid' => isset($GLOBALS['socid']) ? $GLOBALS['socid'] : '', 'id' => isset($GLOBALS['id']) ? $GLOBALS['id'] : '', 'modulepart' => $modulepart); if (is_object($hookmanager)) { $reshook = $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']); $out .= $hookmanager->resPrint; } } // Get list of files if (!empty($filedir)) { $file_list = dol_dir_list($filedir, 'files', 0, '', '(\\.meta|_preview\\.png)$', 'date', SORT_DESC); // Affiche en-tete tableau si non deja affiche if (!empty($file_list) && !$headershown) { $headershown = 1; $out .= '<div class="titre">' . $titletoshow . '</div>'; $out .= '<table class="border" summary="listofdocumentstable" width="100%">'; } // Loop on each file found if (is_array($file_list)) { foreach ($file_list as $file) { $var = !$var; // Define relative path for download link (depends on module) $relativepath = $file["name"]; // Cas general if ($modulesubdir) { $relativepath = $modulesubdir . "/" . $file["name"]; } // Cas propal, facture... if ($modulepart == 'export') { $relativepath = $file["name"]; } // Other case $out .= "<tr " . $bc[$var] . ">"; $documenturl = DOL_URL_ROOT . '/document.php'; if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) { $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; } // Show file name with link to download $out .= '<td class="nowrap">'; $out .= '<a data-ajax="false" href="' . $documenturl . '?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . '"'; $mime = dol_mimetype($relativepath, '', 0); if (preg_match('/text/', $mime)) { $out .= ' target="_blank"'; } $out .= ' target="_blank">'; $out .= img_mime($file["name"], $langs->trans("File") . ': ' . $file["name"]) . ' ' . dol_trunc($file["name"], $maxfilenamelength); $out .= '</a>' . "\n"; $out .= '</td>'; // Show file size $size = !empty($file['size']) ? $file['size'] : dol_filesize($filedir . "/" . $file["name"]); $out .= '<td align="right" class="nowrap">' . dol_print_size($size) . '</td>'; // Show file date $date = !empty($file['date']) ? $file['date'] : dol_filemtime($filedir . "/" . $file["name"]); $out .= '<td align="right" class="nowrap">' . dol_print_date($date, 'dayhour', 'tzuser') . '</td>'; if ($delallowed || $printer || $morepicto) { $out .= '<td align="right">'; if ($delallowed) { $out .= '<a href="' . $urlsource . (strpos($urlsource, '?') ? '&' : '?') . 'action=remove_file&file=' . urlencode($relativepath); $out .= $param ? '&' . $param : ''; //$out.= '&modulepart='.$modulepart; // TODO obsolete ? //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ? $out .= '">' . img_picto($langs->trans("Delete"), 'delete.png') . '</a>'; //$out.='</td>'; } if ($printer) { //$out.= '<td align="right">'; $out .= ' <a href="' . $urlsource . (strpos($urlsource, '?') ? '&' : '?') . 'action=print_file&printer=' . $modulepart . '&file=' . urlencode($relativepath); $out .= $param ? '&' . $param : ''; $out .= '">' . img_picto($langs->trans("PrintFile", $relativepath), 'printer.png') . '</a>'; } if ($morepicto) { $morepicto = preg_replace('/__FILENAMEURLENCODED__/', urlencode($relativepath), $morepicto); $out .= $morepicto; } $out .= '</td>'; } if (is_object($hookmanager)) { $parameters = array('socid' => isset($GLOBALS['socid']) ? $GLOBALS['socid'] : '', 'id' => isset($GLOBALS['id']) ? $GLOBALS['id'] : '', 'modulepart' => $modulepart, 'relativepath' => $relativepath); $res = $hookmanager->executeHooks('formBuilddocLineOptions', $parameters, $file); if (empty($res)) { $out .= $hookmanager->resPrint; // Complete line $out .= '</tr>'; } else { $out = $hookmanager->resPrint; } // Replace line } } if (count($file_list) == 0 && $headershown) { $out .= '<tr ' . $bc[0] . '><td colspan="3">' . $langs->trans("None") . '</td></tr>'; } $this->numoffiles++; } } if ($headershown) { // Affiche pied du tableau $out .= "</table>\n"; if ($genallowed) { if (empty($noform)) { $out .= '</form>' . "\n"; } } } $out .= '<!-- End show_document -->' . "\n"; //return ($i?$i:$headershown); return $out; }
/** * 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="PROPALE_ADDON_PDF_ODT_PATH">'; if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) { $texte .= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">'; $texte .= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">'; $texte .= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">'; } $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->PROPALE_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, '\\.(ods|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 .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; $texte .= '<textarea class="flat" cols="60" name="value1">'; $texte .= $conf->global->PROPALE_ADDON_PDF_ODT_PATH; $texte .= '</textarea>'; $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; $texte .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="Button">'; $texte .= '<br></div></div>'; // Scan directories if (count($listofdir)) { $texte .= $langs->trans("NumberOfModelFilesFound") . ': <b>' . count($listoffiles) . '</b>'; if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) { // Model for creation $liste = ModelePDFPropales::liste_modeles($this->db); $texte .= '<table width="50%;">'; $texte .= '<tr>'; $texte .= '<td width="60%;">' . $langs->trans("DefaultModelPropalCreate") . '</td>'; $texte .= '<td colspan="">'; $texte .= $form->selectarray('value2', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT); $texte .= "</td></tr>"; $texte .= '<tr>'; $texte .= '<td width="60%;">' . $langs->trans("DefaultModelPropalToBill") . '</td>'; $texte .= '<td colspan="">'; $texte .= $form->selectarray('value3', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL); $texte .= "</td></tr>"; $texte .= '<tr>'; $texte .= '<td width="60%;">' . $langs->trans("DefaultModelPropalClosed") . '</td>'; $texte .= '<td colspan="">'; $texte .= $form->selectarray('value4', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED); $texte .= "</td></tr>"; $texte .= '</table>'; } } $texte .= '</td>'; $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); $texte .= '</td>'; $texte .= '</tr>'; $texte .= '</table>'; $texte .= '</form>'; return $texte; }
print '</td>'; print '</tr>'; } // Incoterms if (!empty($conf->incoterm->enabled)) { print '<tr>'; print '<td><label for="incoterm_id">' . $form->textwithpicto($langs->trans("IncotermLabel"), $soc->libelle_incoterms, 1) . '</label></td>'; print '<td colspan="3" class="maxwidthonsmartphone">'; print $form->select_incoterms(!empty($soc->fk_incoterms) ? $soc->fk_incoterms : '', !empty($soc->location_incoterms) ? $soc->location_incoterms : ''); print '</td></tr>'; } // Template to use by default print '<tr>'; print '<td>' . $langs->trans("DefaultModel") . '</td>'; print '<td colspan="2">'; $liste = ModelePDFPropales::liste_modeles($db); print $form->selectarray('model', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : $conf->global->PROPALE_ADDON_PDF); print "</td></tr>"; // Public note print '<tr>'; print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>'; print '<td valign="top" colspan="2">'; $note_public = $object->getDefaultCreateValueFor('note_public', is_object($objectsrc) ? $objectsrc->note_public : null); $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); // Private note if (empty($user->societe_id)) { print '<tr>'; print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>'; print '<td valign="top" colspan="2">'; $note_private = $object->getDefaultCreateValueFor('note_private', !empty($origin) && !empty($originid) && is_object($objectsrc) ? $objectsrc->note_private : null);
/** * Cree une propale sur disque en fonction du modele de PROPALE_ADDON_PDF * @param db Database handler * @param object Object proposal * @param modele Force model to use ('' to not force) * @param outputlangs Object langs to use for output * @param hidedetails Hide details of lines * @param hidedesc Hide description * @param hideref Hide ref * @return int 0 if KO, 1 if OK */ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) { global $conf, $user, $langs; $langs->load("propale"); $dir = "/includes/modules/propale/"; $srctemplatepath = ''; $modelisok = 0; // Positionne le modele sur le nom du modele a utiliser if (!dol_strlen($modele)) { if (!empty($conf->global->PROPALE_ADDON_PDF)) { $modele = $conf->global->PROPALE_ADDON_PDF; } else { $modele = 'azur'; } } // Positionne modele sur le nom du modele de propale a utiliser $file = "pdf_propale_" . $modele . ".modules.php"; // On verifie l'emplacement du modele $file = dol_buildpath($dir . $file); if ($modele && file_exists($file)) { $modelisok = 1; } // Si model pas encore bon if (!$modelisok) { if ($conf->global->PROPALE_ADDON_PDF) { $modele = $conf->global->PROPALE_ADDON_PDF; } $file = "pdf_propale_" . $modele . ".modules.php"; // On verifie l'emplacement du modele $file = dol_buildpath($dir . $file); if (file_exists($file)) { $modelisok = 1; } } // Si model pas encore bon if (!$modelisok && is_array($liste)) { $liste = array(); $model = new ModelePDFPropales(); $liste = $model->liste_modeles($db); $modele = key($liste); // Renvoie premiere valeur de cle trouve dans le tableau $file = "pdf_propale_" . $modele . ".modules.php"; $file = dol_buildpath($dir . $file); if (file_exists($file)) { $modelisok = 1; } } // Charge le modele if ($modelisok) { $classname = "pdf_propale_" . $modele; require_once $file; $obj = new $classname($db); // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output = $outputlangs->charset_output; if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc) > 0) { $outputlangs->charset_output = $sav_charset_output; // on supprime l'image correspondant au preview propale_delete_preview($db, $object->id); // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($db); $result = $interface->run_triggers('PROPAL_BUILDDOC', $object, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers return 1; } else { $outputlangs->charset_output = $sav_charset_output; dol_syslog("modules_propale::propale_pdf_create error"); dol_print_error($db, $obj->error); return 0; } } else { if (!$conf->global->PROPALE_ADDON_PDF) { print $langs->trans("Error") . " " . $langs->trans("Error_PROPALE_ADDON_PDF_NotDefined"); } else { print $langs->trans("Error") . " " . $langs->trans("ErrorFileDoesNotExists", $file); } return 0; } }
{ print '<tr><td>'.$langs->trans('DeliveryAddress').'</td>'; print '<td colspan="3">'; $numaddress = $html->select_address($soc->fk_delivery_address, $_GET['socid'],'fk_address',1); if ($numaddress==0) { print ' <a href=../comm/address.php?socid='.$soc->id.'&action=create>'.$langs->trans("AddAddress").'</a>'; } print '</td></tr>'; } // Model print '<tr>'; print '<td>'.$langs->trans("DefaultModel").'</td>'; print '<td colspan="2">'; $model=new ModelePDFPropales(); $liste=$model->liste_modeles($db); print $html->selectarray('model',$liste,$conf->global->PROPALE_ADDON_PDF); print "</td></tr>"; // Project if ($conf->projet->enabled) { $projectid = 0; if (isset($_GET["origin"]) && $_GET["origin"] == 'project') $projectid = ($_GET["originid"]?$_GET["originid"]:0); print '<tr>'; print '<td valign="top">'.$langs->trans("Project").'</td><td colspan="2">'; $numprojet=select_projects($soc->id,$projectid); if ($numprojet==0)
/** * Return a string to show the box with list of available documents for object. * This also set the property $this->numoffiles * * @param string $modulepart propal, facture, facture_fourn, ... * @param string $filename Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if $filedir is already complete) * @param string $filedir Directory to scan * @param string $urlsource Url of origin page (for return) * @param int $genallowed Generation is allowed (1/0 or array list of templates) * @param int $delallowed Remove is allowed (1/0) * @param string $modelselected Model to preselect by default * @param string $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) * @param int $iconPDF Show only PDF icon with link (1/0) * @param int $maxfilenamelength Max length for filename shown * @param string $noform Do not output html form tags * @param string $param More param on http links * @param string $title Title to show on top of form * @param string $buttonlabel Label on submit button * @param string $codelang Default language code to use on lang combo box if multilang is enabled * @param HookManager $hookmanager Object hookmanager with instance of external modules hook classes * @return string Output string with HTML array of documents (might be empty string) */ function showdocuments($modulepart, $filename, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $maxfilenamelength = 28, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '', $hookmanager = false) { // filedir = conf->...dir_ouput."/".get_exdir(id) include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; global $langs, $bc, $conf; $forname = 'builddoc'; $out = ''; $var = true; // Clean paramaters if ($iconPDF == 1) { $genallowed = ''; $delallowed = 0; $modelselected = ''; $forcenomultilang = 0; } //$filename = dol_sanitizeFileName($filename); //Must be sanitized before calling show_documents $headershown = 0; $showempty = 0; $i = 0; $titletoshow = $langs->trans("Documents"); if (!empty($title)) { $titletoshow = $title; } $out .= "\n" . '<!-- Start show_document -->' . "\n"; //print 'filedir='.$filedir; // Affiche en-tete tableau if ($genallowed) { $modellist = array(); if ($modulepart == 'company') { $showempty = 1; if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php'; $modellist = ModeleThirdPartyDoc::liste_modeles($this->db); } } else { if ($modulepart == 'propal') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php'; $modellist = ModelePDFPropales::liste_modeles($this->db); } } else { if ($modulepart == 'commande') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php'; $modellist = ModelePDFCommandes::liste_modeles($this->db); } } elseif ($modulepart == 'expedition') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php'; $modellist = ModelePDFExpedition::liste_modeles($this->db); } } elseif ($modulepart == 'livraison') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/livraison/modules_livraison.php'; $modellist = ModelePDFDeliveryOrder::liste_modeles($this->db); } } else { if ($modulepart == 'ficheinter') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/fichinter/modules_fichinter.php'; $modellist = ModelePDFFicheinter::liste_modeles($this->db); } } elseif ($modulepart == 'facture') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; $modellist = ModelePDFFactures::liste_modeles($this->db); } } elseif ($modulepart == 'project') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/project/modules_project.php'; $modellist = ModelePDFProjects::liste_modeles($this->db); } } elseif ($modulepart == 'export') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/export/modules_export.php'; $modellist = ModeleExports::liste_modeles($this->db); } } else { if ($modulepart == 'commande_fournisseur') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php'; $modellist = ModelePDFSuppliersOrders::liste_modeles($this->db); } } else { if ($modulepart == 'facture_fournisseur') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php'; $modellist = ModelePDFSuppliersInvoices::liste_modeles($this->db); } } else { if ($modulepart == 'remisecheque') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/cheque/pdf/modules_chequereceipts.php'; $modellist = ModeleChequeReceipts::liste_modeles($this->db); } } elseif ($modulepart == 'donation') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php'; $modellist = ModeleDon::liste_modeles($this->db); } } else { if ($modulepart == 'unpaid') { $modellist = ''; } else { // Generic feature, for external modules $file = dol_buildpath('/core/modules/' . $modulepart . '/modules_' . $modulepart . '.php', 0); if (file_exists($file)) { $res = (include_once $file); } $class = 'Modele' . ucfirst($modulepart); if (class_exists($class)) { $modellist = call_user_func($class . '::liste_modeles', $this->db); } else { dol_print_error($this->db, 'Bad value for modulepart'); return -1; } } } } } } } } } $headershown = 1; $form = new Form($this->db); $buttonlabeltoshow = $buttonlabel; if (empty($buttonlabel)) { $buttonlabel = $langs->trans('Generate'); } if (empty($noform)) { $out .= '<form action="' . $urlsource . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc') . '" name="' . $forname . '" id="' . $forname . '_form" method="post">'; } $out .= '<input type="hidden" name="action" value="builddoc">'; $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; $out .= '<div class="titre">' . $titletoshow . '</div>'; $out .= '<table class="liste formdoc" summary="listofdocumentstable" width="100%">'; $out .= '<tr class="liste_titre">'; // Model if (!empty($modellist)) { $out .= '<th align="center" class="formdoc liste_titre">'; $out .= $langs->trans('Model') . ' '; if (is_array($modellist) && count($modellist) == 1) { $arraykeys = array_keys($modellist); $modelselected = $arraykeys[0]; } $out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0); $out .= '</th>'; } else { $out .= '<th align="left" class="formdoc liste_titre">'; $out .= $langs->trans("Files"); $out .= '</th>'; } // Language code (if multilang) $out .= '<th align="center" class="formdoc liste_titre">'; if (($allowgenifempty || is_array($modellist) && count($modellist) > 0) && $conf->global->MAIN_MULTILANGS && !$forcenomultilang) { include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php'; $formadmin = new FormAdmin($this->db); $defaultlang = $codelang ? $codelang : $langs->getDefaultLang(); $out .= $formadmin->select_language($defaultlang); } else { $out .= ' '; } $out .= '</th>'; // Button $out .= '<th align="center" colspan="' . ($delallowed ? '2' : '1') . '" class="formdocbutton liste_titre">'; $out .= '<input class="button" id="' . $forname . '_generatebutton"'; $out .= ' type="submit" value="' . $buttonlabel . '"'; if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) { $out .= ' disabled="disabled"'; } $out .= '>'; if ($allowgenifempty && !is_array($modellist) && empty($modellist) && $modulepart != 'unpaid') { $langs->load("errors"); $out .= ' ' . img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); } $out .= '</th>'; $out .= '</tr>'; // Execute hooks $parameters = array('socid' => isset($GLOBALS['socid']) ? $GLOBALS['socid'] : '', 'id' => isset($GLOBALS['id']) ? $GLOBALS['id'] : '', 'modulepart' => $modulepart); if (is_object($hookmanager)) { $out .= $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']); } } // Get list of files if ($filedir) { $png = ''; $filter = ''; if ($iconPDF == 1) { $png = '\\.png$'; $filter = $filename . '.pdf'; } $file_list = dol_dir_list($filedir, 'files', 0, $filter, '\\.meta$' . ($png ? '|' . $png : ''), 'date', SORT_DESC); // Affiche en-tete tableau si non deja affiche if (!empty($file_list) && !$headershown && !$iconPDF) { $headershown = 1; $out .= '<div class="titre">' . $titletoshow . '</div>'; $out .= '<table class="border" summary="listofdocumentstable" width="100%">'; } else { if (empty($file_list) && !empty($iconPDF)) { // For ajax treatment $out .= '<div id="gen_pdf_' . $filename . '" class="linkobject hideobject">' . img_picto('', 'refresh') . '</div>' . "\n"; } } // Loop on each file found foreach ($file_list as $file) { $var = !$var; // Define relative path for download link (depends on module) $relativepath = $file["name"]; // Cas general if ($filename) { $relativepath = $filename . "/" . $file["name"]; } // Cas propal, facture... // Autre cas if ($modulepart == 'donation') { $relativepath = get_exdir($filename, 2) . $file["name"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; } if (!$iconPDF) { $out .= "<tr " . $bc[$var] . ">"; } // Show file name with link to download if (!$iconPDF) { $out .= '<td nowrap="nowrap">'; } $out .= '<a href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . '"'; $mime = dol_mimetype($relativepath, '', 0); if (preg_match('/text/', $mime)) { $out .= ' target="_blank"'; } $out .= '>'; if (!$iconPDF) { $out .= img_mime($file["name"], $langs->trans("File") . ': ' . $file["name"]) . ' ' . dol_trunc($file["name"], $maxfilenamelength); } else { $out .= img_pdf($file["name"], 2); } $out .= '</a>' . "\n"; if (!$iconPDF) { $out .= '</td>'; // Show file size $out .= '<td align="right" nowrap="nowrap">' . dol_print_size(dol_filesize($filedir . "/" . $file["name"])) . '</td>'; // Show file date $out .= '<td align="right" nowrap="nowrap">' . dol_print_date(dol_filemtime($filedir . "/" . $file["name"]), 'dayhour') . '</td>'; } if ($delallowed) { $out .= '<td align="right">'; //$out.= '<a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&modulepart='.$modulepart.'&file='.urlencode($relativepath); $out .= '<a href="' . $urlsource . '&action=remove_file&modulepart=' . $modulepart . '&file=' . urlencode($relativepath); $out .= $param ? '&' . $param : ''; $out .= '&urlsource=' . urlencode($urlsource); $out .= '">' . img_delete() . '</a></td>'; } if (!$iconPDF) { $out .= '</tr>'; } $this->numoffiles++; } } if ($headershown) { // Affiche pied du tableau $out .= "</table>\n"; if ($genallowed) { if (empty($noform)) { $out .= '</form>' . "\n"; } } } $out .= '<!-- End show_document -->' . "\n"; //return ($i?$i:$headershown); return $out; }