dolibarr 22.0.5
order_pdf.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
9 * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
10 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42
52// Load translation files required by the page
53$langs->loadLangs(array("admin", "other", "errors", "orders"));
54
55if (!$user->admin) {
57}
58
59$action = GETPOST('action', 'aZ09');
60$value = GETPOST('value', 'alpha');
61$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
62
63$label = GETPOST('label', 'alpha');
64$scandir = GETPOST('scan_dir', 'alpha');
65$type = 'order';
66$dirforterms = $conf->order->dir_output;
67if (!empty($conf->order->multidir_output[$conf->entity])) {
68 $dirforterms = $conf->order->multidir_output[$conf->entity].'/';
69}
70
71/*
72 * Actions
73 */
74
75include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
76
77$error = 0;
78if ($action == "update") {
79 if (GETPOSTISSET('MAIN_PDF_ADD_TERMSOFSALE_ORDER')) {
80 dolibarr_set_const($db, "MAIN_PDF_ADD_TERMSOFSALE_ORDER", GETPOST("MAIN_PDF_ADD_TERMSOFSALE_ORDER", 'int'), 'chaine', 0, '', $conf->entity);
81 }
82 if (GETPOSTISSET('SALES_ORDER_SHOW_SHIPPING_ADDRESS')) {
83 dolibarr_set_const($db, "SALES_ORDER_SHOW_SHIPPING_ADDRESS", GETPOSTINT("SALES_ORDER_SHOW_SHIPPING_ADDRESS"), 'chaine', 0, '', $conf->entity);
84 dolibarr_del_const($db, "SALES_ORDER_SHOW_SHIPPING_ADDRESS", $conf->entity);
85 }
86
87 // Terms of sale
88 if ($_FILES['termsofsale']["name"]) {
89 if (!preg_match('/(\.pdf)$/i', $_FILES['termsofsale']["name"])) { // Document can be used on a lot of different places. Only pdf can be supported.
90 $langs->load("errors");
91 setEventMessages($langs->trans("ErrorBadFormat"), null, 'errors');
92 } else {
93 $original_file = $_FILES['termsofsale']["name"];
94 $result = dol_move_uploaded_file($_FILES['termsofsale']["tmp_name"], $dirforterms.$original_file, 1, 0, $_FILES['termsofsale']['error']);
95 if ($result) {
96 dolibarr_set_const($db, 'MAIN_INFO_ORDER_TERMSOFSALE', $original_file, 'chaine', 0, '', $conf->entity);
97 }
98 }
99 }
100
101 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
102
103 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
104 exit;
105}
106
107// Terms of sale
108if ($action == 'removetermsofsale') {
109 $filename = getDolGlobalString('MAIN_INFO_ORDER_TERMSOFSALE');
110 $file = $dirforterms.'/'.$filename;
111
112 if ($filename != '') {
113 dol_delete_file($file);
114 }
115 dolibarr_del_const($db, 'MAIN_INFO_ORDER_TERMSOFSALE', $conf->entity);
116}
117
118/*
119 * View
120 */
121
122$form = new Form($db);
123$formfile = new FormFile($db);
124
125$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
126
127llxHeader('', $langs->trans("OrdersSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-order');
128
129//if ($mesg) print $mesg;
130
131$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
132print load_fiche_titre($langs->trans("OrdersSetup"), $linkback, 'title_setup');
133
135
136print dol_get_fiche_head($head, 'pdf', $langs->trans("Orders"), -1, 'order');
137
138print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'">';
139print '<input type="hidden" name="token" value="'.newToken().'">';
140print '<input type="hidden" name="action" value="update">';
141
142print '<div class="div-table-responsive-no-min">';
143print '<table summary="more" class="noborder centpercent">';
144print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td width="200px"></td></tr>';
145
146print '<tr class="oddeven"><td>';
147print $form->textwithpicto($langs->trans("MAIN_PDF_ADD_TERMSOFSALE_ORDER"), $langs->trans("PdfAddTermOfSaleHelp"));
148print '</td><td>';
149if ($conf->use_javascript_ajax) {
150 print ajax_constantonoff('MAIN_PDF_ADD_TERMSOFSALE_ORDER');
151} else {
152 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
153 print $form->selectarray("MAIN_PDF_ADD_TERMSOFSALE_ORDER", $arrval, $conf->global->MAIN_PDF_ADD_TERMSOFSALE_ORDER);
154}
155print '</td></tr>';
156
157print '<tr class="oddeven"><td>';
158print $form->textwithpicto($langs->trans("SALES_ORDER_SHOW_SHIPPING_ADDRESS"), $langs->trans("SALES_ORDER_SHOW_SHIPPING_ADDRESSMore"));
159print '</td><td>';
160if ($conf->use_javascript_ajax) {
161 print ajax_constantonoff('SALES_ORDER_SHOW_SHIPPING_ADDRESS');
162} else {
163 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
164 print $form->selectarray("SALES_ORDER_SHOW_SHIPPING_ADDRESS", $arrval, $conf->global->SALES_ORDER_SHOW_SHIPPING_ADDRESS);
165}
166print '</td></tr>';
167
168print '</table>';
169print '</div>';
170
171print load_fiche_titre($langs->trans("FileToConcatToGeneratedPDF"), '', 'file');
172print '<div class="div-table-responsive-no-min">';
173print '<table summary="more" class="noborder centpercent">';
174print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td width="200px"></td></tr>';
175
176// Terms of sale
177$tooltiptermsofsale = $langs->trans('AvailableFormats').' : pdf';
178$maxfilesizearray = getMaxFileSizeArray();
179$tooltiptermsofsale .= ($maxfilesizearray['maxmin'] > 0) ? '<br>'.$langs->trans('MaxSize').' : '.$maxfilesizearray['maxmin'].' '.$langs->trans('Kb') : '';
180$documenturl = DOL_URL_ROOT.'/document.php';
181if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
182 $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP;
183}
184$modulepart = 'order';
185
186print '<tr class="oddeven"><td><label for="logo">'.$form->textwithpicto($langs->trans("FileToConcatToGeneratedPDF"), $tooltiptermsofsale).'</label></td><td>';
187print '<div class="centpercent nobordernopadding valignmiddle "><div class="inline-block marginrightonly">';
188print '<input type="file" class="flat minwidth100 maxwidthinputfileonsmartphone" name="termsofsale" id="termsofsale" accept="application/pdf">';
189
190if (getDolGlobalString("MAIN_INFO_ORDER_TERMSOFSALE")) {
191 $termofsale = getDolGlobalString("MAIN_INFO_ORDER_TERMSOFSALE");
192 if (file_exists($dirforterms.'/'.$termofsale)) {
193 $file = dol_dir_list($dirforterms, 'files', 0, $termofsale);
194 print '<div class="inline-block valignmiddle marginrightonly"><a href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($termofsale).'">'.$termofsale.'</a>'.$formfile->showPreview($file[0], $modulepart, $termofsale, 0, '');
195 print '<div class="inline-block valignmiddle marginrightonly"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=removetermsofsale&token='.newToken().'">'.img_delete($langs->trans("Delete"), '', 'marginleftonly').'</a></div>';
196 }
197}
198print '</div>';
199print '</td></tr>';
200print '</table>';
201print '</div>';
202
203
204print '<center><input type="submit" class="button button-edit reposition" value="'.$langs->trans("Save").'"></center>';
205
206print '</form>';
207
208
209print '<br><br>';
210
211// End of page
212llxFooter();
213$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
order_admin_prepare_head()
Return array head with list of tabs to view object information.
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.