dolibarr 25.0.0-alpha
contract.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
3 * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
33
43// Load translation files required by the page
44$langs->loadLangs(array("admin", "contracts"));
45
46if (!$user->admin) {
48}
49
50$action = GETPOST('action', 'aZ09');
51$value = GETPOST('value', 'alpha');
52$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
53
54$label = GETPOST('label', 'alpha');
55$scandir = GETPOST('scan_dir', 'alpha');
56$type = 'contract';
57
58if (!getDolGlobalString('CONTRACT_ADDON')) {
59 $conf->global->CONTRACT_ADDON = 'mod_contract_serpis';
60}
61
62
63/*
64 * Actions
65 */
66
67include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
68
69$error = 0;
70
71if ($action == 'updateMask') {
72 $maskconst = GETPOST('maskconstcontract', 'aZ09');
73 $maskvalue = GETPOST('maskcontract', 'alpha');
74 $res = 0;
75 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
76 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
77 }
78
79 if (!($res > 0)) {
80 $error++;
81 }
82
83 if (!$error) {
84 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
85 } else {
86 setEventMessages($langs->trans("Error"), null, 'errors');
87 }
88} elseif ($action == 'specimen') { // For contract
89 $modele = GETPOST('module', 'alpha');
90
91 $contract = new Contrat($db);
92 $contract->initAsSpecimen();
93
94 // Search template files
95 $file = '';
96 $classname = '';
97 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
98 foreach ($dirmodels as $reldir) {
99 $file = dol_buildpath($reldir."core/modules/contract/doc/pdf_".$modele.".modules.php", 0);
100 if (file_exists($file)) {
101 $classname = "pdf_".$modele;
102 break;
103 }
104 }
105
106 if ($classname !== '') {
107 require_once $file;
108
109 $module = new $classname($db);
110 '@phan-var-force ModelePDFContract $module';
111
113 if ($module->write_file($contract, $langs) > 0) {
114 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=contract&file=SPECIMEN.pdf");
115 return;
116 } else {
117 setEventMessages($module->error, $module->errors, 'errors');
118 dol_syslog($module->error, LOG_ERR);
119 }
120 } else {
121 $langs->load('errors');
122 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
123 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
124 }
125} elseif ($action == 'set') {
126 // Activate a model
127 $ret = addDocumentModel($value, $type, $label, $scandir);
128} elseif ($action == 'del') {
129 $ret = delDocumentModel($value, $type);
130 if ($ret > 0) {
131 if (getDolGlobalString('CONTRACT_ADDON_PDF') == "$value") {
132 dolibarr_del_const($db, 'CONTRACT_ADDON_PDF', $conf->entity);
133 }
134 }
135} elseif ($action == 'setdoc') {
136 // Set default model
137 if (dolibarr_set_const($db, "CONTRACT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
138 // The constant that was read before the new set
139 // so we go through a variable to get a consistent display
140 $conf->global->CONTRACT_ADDON_PDF = $value;
141 }
142
143 // On active le modele
144 $ret = delDocumentModel($value, $type);
145 if ($ret > 0) {
146 $ret = addDocumentModel($value, $type, $label, $scandir);
147 }
148} elseif ($action == 'unsetdoc') {
149 dolibarr_del_const($db, "CONTRACT_ADDON_PDF", $conf->entity);
150} elseif ($action == 'setmod') {
151 // TODO Verify si the chosen numbering module can be activated by
152 // the method call canBeActivated
153
154 dolibarr_set_const($db, "CONTRACT_ADDON", $value, 'chaine', 0, '', $conf->entity);
155} elseif ($action == 'set_other') {
156 $freetext = GETPOST('CONTRACT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
157 $res1 = dolibarr_set_const($db, "CONTRACT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
158
159 $draft = GETPOST('CONTRACT_DRAFT_WATERMARK', 'alpha');
160 $res2 = dolibarr_set_const($db, "CONTRACT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
161
162 $value = GETPOST('activate_hideClosedServiceByDefault', 'alpha');
163 $res3 = dolibarr_set_const($db, "CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT", $value, 'chaine', 0, '', $conf->entity);
164
165 if (!($res1 > 0) || !($res2 > 0) || !($res3 > 0)) {
166 $error++;
167 }
168
169 if (!$error) {
170 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
171 } else {
172 setEventMessages($langs->trans("Error"), null, 'errors');
173 }
174} elseif ($action == "allowonlinesign") {
175 if (!dolibarr_set_const($db, "CONTRACT_ALLOW_ONLINESIGN", $value, 'int', 0, '', $conf->entity)) {
176 $error++;
177 }
178} elseif (preg_match('/set_(.*)/', $action, $reg)) {
179 $code = $reg[1];
180 $value = (GETPOST($code) ? GETPOST($code) : 1);
181
182 $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
183 if (!($res > 0)) {
184 $error++;
185 }
186
187 if ($error) {
188 setEventMessages($langs->trans('Error'), null, 'errors');
189 } else {
190 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
191 header("Location: " . $_SERVER["PHP_SELF"]);
192 exit();
193 }
194} elseif (preg_match('/del_(.*)/', $action, $reg)) {
195 $code = $reg[1];
196 $res = dolibarr_del_const($db, $code, $conf->entity);
197
198 if (!($res > 0)) {
199 $error++;
200 }
201
202 if ($error) {
203 setEventMessages($langs->trans('Error'), null, 'errors');
204 } else {
205 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
206 header("Location: " . $_SERVER["PHP_SELF"]);
207 exit();
208 }
209}
210
211
212
213/*
214 * View
215 */
216
217$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
218
219llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-contract');
220
221$form = new Form($db);
222
223$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
224
225print load_fiche_titre($langs->trans("ContractsSetup"), $linkback, 'title_setup');
226
228
229print dol_get_fiche_head($head, 'contract', $langs->trans("Contracts"), -1, 'contract');
230
231/*
232 * Contracts Numbering model
233 */
234
235$contract = new Contrat($db);
236$contract->initAsSpecimen();
237
238printNumberingModuleList('contract', 'mod_contract_', 'CONTRACT_ADDON', $langs->trans("ContractsNumberingModules"), $contract);
239
240print '<br>';
241
242/*
243 * Documents models for Contracts
244 */
245
246printDocumentModelList($type, 'contract', 'CONTRACT_ADDON_PDF', $langs->trans("TemplatePDFContracts"), array(
247 'Logo' => 'option_logo',
248 'PaymentMode' => 'option_modereg',
249 'PaymentConditions' => 'option_condreg',
250 'MultiLanguage' => 'option_multilang',
251 'WatermarkOnDraftOrders' => 'option_draft_watermark',
252), false, '', 1, 'unsetdoc');
253print "<br>";
254
255/*
256 * Other options
257 *
258 */
259
260print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
261print '<input type="hidden" name="token" value="'.newToken().'">';
262print '<input type="hidden" name="action" value="set_other">';
263
264print load_fiche_titre($langs->trans("OtherOptions"), '', '');
265
266print '<div class="div-table-responsive-no-min">';
267print '<table class="noborder centpercent">';
268print '<tr class="liste_titre">';
269print '<td>'.$langs->trans("Parameter").'</td>';
270print '<td class="right"></td>';
271print "</tr>\n";
272
273$substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
274$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
275$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
276foreach ($substitutionarray as $key => $val) {
277 $htmltext .= $key.'<br>';
278}
279$htmltext .= '</i>';
280
281print '<tr class="oddeven"><td colspan="2">';
282print $form->textwithpicto($langs->trans("FreeLegalTextOnContracts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
283print '<br>';
284$variablename = 'CONTRACT_FREE_TEXT';
285if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
286 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
287} else {
288 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
289 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
290 print $doleditor->Create();
291}
292print '</td></tr>'."\n";
293
294//Use draft Watermark
295
296print '<tr class="oddeven"><td>';
297print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
298print '</td><td class="right">';
299print '<input class="flat minwidth200" type="text" name="CONTRACT_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('CONTRACT_DRAFT_WATERMARK')).'">';
300print '</td></tr>'."\n";
301
302print '<tr class="oddeven">';
303print '<td>'.$langs->trans("HideClosedServiceByDefault").'</td>';
304print '<td class="right">';
305print $form->selectyesno("activate_hideClosedServiceByDefault", getDolGlobalInt('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT', 0), 1);
306print '</td>';
307print '</tr>';
308
309// Allow online signing
310print '<tr class="oddeven">';
311print '<td>'.$langs->trans("AllowOnlineSign").'</td>';
312print '<td class="right">';
313if ($conf->use_javascript_ajax) {
314 print ajax_constantonoff('CONTRACT_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, $langs->transnoentitiesnoconv("WarningOnlineSignature", "https://www.dolistore.com"));
315} else {
316 if (getDolGlobalString('CONTRACT_ALLOW_ONLINESIGN')) {
317 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=allowonlinesign&token='.newToken().'&value=0">';
318 print img_picto($langs->trans("Activated"), 'switch_on');
319 print '</a>';
320 } else {
321 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=allowonlinesign&token='.newToken().'&value=1">';
322 print img_picto($langs->trans("Disabled"), 'switch_off');
323 print '</a>';
324 }
325}
326print '</td>';
327print '</tr>';
328
329// Allow external download
330print '<tr class="oddeven">';
331print '<td>'.$langs->trans("AllowExternalDownload").'</td>';
332print '<td class="right">';
333print ajax_constantonoff('CONTRACT_ALLOW_EXTERNAL_DOWNLOAD', array(), null, 0, 0, 0, 2, 0, 1);
334print '</td>';
335print '</tr>';
336
337// Reminder by email before a contract service expires
338if (isModEnabled('cron')) {
339 print '<tr class="oddeven">';
340 print '<td>'.$langs->trans("SendReminderForExpiredServicesTitle").'</td>';
341 print '<td class="right">';
342 print '<a href="'.DOL_URL_ROOT.'cron/list.php?search_label=SendReminderForExpiredServicesTitle&status=-1">'.$langs->trans("ConfigureContractReminderCronjobToSetFrequency").'</a>';
343 print '</td>';
344 print '</tr>';
345}
346print '</table>';
347print '</div>';
348
349print $form->buttonsSaveCancel("Save", '');
350
351print '</form>';
352
353print dol_get_fiche_end();
354
355// End of page
356llxFooter();
357$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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.
delDocumentModel($name, $type)
Delete document model used by doc generator.
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
contract_admin_prepare_head()
Return array head with list of tabs to view object information.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.