dolibarr 22.0.5
propal_pdf.php
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.'/comm/propal/class/propal.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.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", "propal"));
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 = 'propal';
66
67/*
68 * Actions
69 */
70
71include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
72
73$error = 0;
74if ($action == "update") {
75 if (GETPOSTISSET('MAIN_PDF_ADD_TERMSOFSALE_PROPAL')) {
76 dolibarr_set_const($db, "MAIN_PDF_ADD_TERMSOFSALE_PROPAL", GETPOST("MAIN_PDF_ADD_TERMSOFSALE_PROPAL", 'int'), 'chaine', 0, '', $conf->entity);
77 }
78 if (GETPOSTISSET('MAIN_GENERATE_PROPOSALS_WITH_PICTURE')) {
79 dolibarr_set_const($db, "MAIN_GENERATE_PROPOSALS_WITH_PICTURE", GETPOST("MAIN_GENERATE_PROPOSALS_WITH_PICTURE"), 'chaine', 0, '', $conf->entity);
80 }
81
82 // Terms of sale
83 if ($_FILES['termsofsale']["name"]) {
84 if (!preg_match('/(\.pdf)$/i', $_FILES['termsofsale']["name"])) { // Document can be used on a lot of different places. Only pdf can be supported.
85 $langs->load("errors");
86 setEventMessages($langs->trans("ErrorBadFormat"), null, 'errors');
87 } else {
88 $dirforterms = $conf->propal->dir_output.'/';
89 $original_file = $_FILES['termsofsale']["name"];
90 $result = dol_move_uploaded_file($_FILES['termsofsale']["tmp_name"], $dirforterms.$original_file, 1, 0, $_FILES['termsofsale']['error']);
91 if ($result) {
92 dolibarr_set_const($db, 'MAIN_INFO_PROPAL_TERMSOFSALE', $original_file, 'chaine', 0, '', $conf->entity);
93 }
94 }
95 }
96
97 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
98
99 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
100 exit;
101}
102
103// Terms of sale
104if ($action == 'removetermsofsale') {
105 $filename = getDolGlobalString('MAIN_INFO_PROPAL_TERMSOFSALE');
106 $file = $conf->propal->dir_output.'/'.$filename;
107
108 if ($filename != '') {
109 dol_delete_file($file);
110 }
111 dolibarr_del_const($db, 'MAIN_INFO_PROPAL_TERMSOFSALE', $conf->entity);
112}
113
114/*
115 * View
116 */
117
118$form = new Form($db);
119$formfile = new FormFile($db);
120
121$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
122
123llxHeader('', $langs->trans("PropalSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-propal');
124
125//if ($mesg) print $mesg;
126
127$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
128print load_fiche_titre($langs->trans("PropalSetup"), $linkback, 'title_setup');
129
131
132print dol_get_fiche_head($head, 'pdf', $langs->trans("Proposals"), -1, 'propal');
133
134print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'">';
135print '<input type="hidden" name="token" value="'.newToken().'">';
136print '<input type="hidden" name="action" value="update">';
137
138print '<div class="div-table-responsive-no-min">';
139print '<table summary="more" class="noborder centpercent">';
140print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td width="200px"></td></tr>';
141
142print '<tr class="oddeven"><td>';
143print $form->textwithpicto($langs->trans("MAIN_PDF_ADD_TERMSOFSALE_PROPAL"), $langs->trans("PdfAddTermOfSaleHelp"));
144print '</td><td>';
145if ($conf->use_javascript_ajax) {
146 print ajax_constantonoff('MAIN_PDF_ADD_TERMSOFSALE_PROPAL', array(), null, 0, 0, 1);
147} else {
148 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
149 print $form->selectarray("MAIN_PDF_ADD_TERMSOFSALE_PROPAL", $arrval, $conf->global->MAIN_PDF_ADD_TERMSOFSALE_PROPAL);
150}
151print '</td></tr>';
152
153print '<tr class="oddeven"><td>';
154print $form->textwithpicto($langs->trans("MAIN_GENERATE_PROPOSALS_WITH_PICTURE"), $langs->trans("RandomlySelectedIfSeveral"));
155print '</td><td>';
156if ($conf->use_javascript_ajax) {
157 print ajax_constantonoff('MAIN_GENERATE_PROPOSALS_WITH_PICTURE');
158} else {
159 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
160 print $form->selectarray("MAIN_GENERATE_PROPOSALS_WITH_PICTURE", $arrval, $conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE);
161}
162print '</td></tr>';
163
164print '</table>';
165print '</div>';
166
167if (empty($conf->use_javascript_ajax)) {
168 print '<center><input type="submit" class="button button-edit reposition" value="'.$langs->trans("Save").'"></center>';
169}
170
171
172if (getDolGlobalString('MAIN_PDF_ADD_TERMSOFSALE_PROPAL')) {
173 print '<br>';
174 print load_fiche_titre($langs->trans("FileToConcatToGeneratedPDF"), '', 'file');
175
176 print '<div class="div-table-responsive-no-min">';
177 print '<table summary="more" class="noborder centpercent">';
178 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td width="200px"></td></tr>';
179
180 // Terms of sale
181 $tooltiptermsofsale = $langs->trans('AvailableFormats').' : pdf';
182 $maxfilesizearray = getMaxFileSizeArray();
183 $tooltiptermsofsale .= ($maxfilesizearray['maxmin'] > 0) ? '<br>'.$langs->trans('MaxSize').' : '.$maxfilesizearray['maxmin'].' '.$langs->trans('Kb') : '';
184 $documenturl = DOL_URL_ROOT.'/document.php';
185 if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
186 $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP;
187 }
188 $modulepart = 'propal';
189
190 print '<tr class="oddeven"><td><label for="logo">'.$form->textwithpicto($langs->trans("FileToConcatToGeneratedPDF"), $tooltiptermsofsale).'</label></td><td>';
191 print '<div class="centpercent nobordernopadding valignmiddle "><div class="inline-block marginrightonly">';
192 print '<input type="file" class="flat minwidth100 maxwidthinputfileonsmartphone" name="termsofsale" id="termsofsale" accept="application/pdf">';
193 if (getDolGlobalString("MAIN_INFO_PROPAL_TERMSOFSALE")) {
194 $termofsale = getDolGlobalString("MAIN_INFO_PROPAL_TERMSOFSALE");
195 if (file_exists($conf->propal->dir_output.'/'.$termofsale)) {
196 $file = dol_dir_list($conf->propal->dir_output, 'files', 0, $termofsale);
197 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, '');
198 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>';
199 }
200 }
201 print '</div>';
202 print '</td></tr>';
203 print '</table>';
204 print '</div>';
205
206 print '<center><input type="submit" class="button button-edit reposition" value="'.$langs->trans("Save").'"></center>';
207}
208
209
210print '</form>';
211
212
213print '<br><br>';
214
215// End of page
216llxFooter();
217$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.
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
propal_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.