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", "errors", "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 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
122 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
123 }
124} elseif ($action == 'set') {
125 // Activate a model
126 $ret = addDocumentModel($value, $type, $label, $scandir);
127} elseif ($action == 'del') {
128 $ret = delDocumentModel($value, $type);
129 if ($ret > 0) {
130 if (getDolGlobalString('CONTRACT_ADDON_PDF') == "$value") {
131 dolibarr_del_const($db, 'CONTRACT_ADDON_PDF', $conf->entity);
132 }
133 }
134} elseif ($action == 'setdoc') {
135 // Set default model
136 if (dolibarr_set_const($db, "CONTRACT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
137 // The constant that was read before the new set
138 // so we go through a variable to get a consistent display
139 $conf->global->CONTRACT_ADDON_PDF = $value;
140 }
141
142 // On active le modele
143 $ret = delDocumentModel($value, $type);
144 if ($ret > 0) {
145 $ret = addDocumentModel($value, $type, $label, $scandir);
146 }
147} elseif ($action == 'unsetdoc') {
148 dolibarr_del_const($db, "CONTRACT_ADDON_PDF", $conf->entity);
149} elseif ($action == 'setmod') {
150 // TODO Verify si the chosen numbering module can be activated by
151 // the method call canBeActivated
152
153 dolibarr_set_const($db, "CONTRACT_ADDON", $value, 'chaine', 0, '', $conf->entity);
154} elseif ($action == 'set_other') {
155 $freetext = GETPOST('CONTRACT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
156 $res1 = dolibarr_set_const($db, "CONTRACT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
157
158 $draft = GETPOST('CONTRACT_DRAFT_WATERMARK', 'alpha');
159 $res2 = dolibarr_set_const($db, "CONTRACT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
160
161 $value = GETPOST('activate_hideClosedServiceByDefault', 'alpha');
162 $res3 = dolibarr_set_const($db, "CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT", $value, 'chaine', 0, '', $conf->entity);
163
164 if (!($res1 > 0) || !($res2 > 0) || !($res3 > 0)) {
165 $error++;
166 }
167
168 if (!$error) {
169 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
170 } else {
171 setEventMessages($langs->trans("Error"), null, 'errors');
172 }
173} elseif ($action == "allowonlinesign") {
174 if (!dolibarr_set_const($db, "CONTRACT_ALLOW_ONLINESIGN", $value, 'int', 0, '', $conf->entity)) {
175 $error++;
176 }
177} elseif (preg_match('/set_(.*)/', $action, $reg)) {
178 $code = $reg[1];
179 $value = (GETPOST($code) ? GETPOST($code) : 1);
180
181 $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
182 if (!($res > 0)) {
183 $error++;
184 }
185
186 if ($error) {
187 setEventMessages($langs->trans('Error'), null, 'errors');
188 } else {
189 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
190 header("Location: " . $_SERVER["PHP_SELF"]);
191 exit();
192 }
193} elseif (preg_match('/del_(.*)/', $action, $reg)) {
194 $code = $reg[1];
195 $res = dolibarr_del_const($db, $code, $conf->entity);
196
197 if (!($res > 0)) {
198 $error++;
199 }
200
201 if ($error) {
202 setEventMessages($langs->trans('Error'), null, 'errors');
203 } else {
204 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
205 header("Location: " . $_SERVER["PHP_SELF"]);
206 exit();
207 }
208}
209
210
211
212/*
213 * View
214 */
215
216$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
217
218llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-contract');
219
220$form = new Form($db);
221
222$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>';
223
224print load_fiche_titre($langs->trans("ContractsSetup"), $linkback, 'title_setup');
225
227
228print dol_get_fiche_head($head, 'contract', $langs->trans("Contracts"), -1, 'contract');
229
230/*
231 * Contracts Numbering model
232 */
233
234$contract = new Contrat($db);
235$contract->initAsSpecimen();
236
237printNumberingModuleList('contract', 'mod_contract_', 'CONTRACT_ADDON', $langs->trans("ContractsNumberingModules"), $contract);
238
239print '<br>';
240
241/*
242 * Documents models for Contracts
243 */
244
245printDocumentModelList($type, 'contract', 'CONTRACT_ADDON_PDF', $langs->trans("TemplatePDFContracts"), array(
246 'Logo' => 'option_logo',
247 'PaymentMode' => 'option_modereg',
248 'PaymentConditions' => 'option_condreg',
249 'MultiLanguage' => 'option_multilang',
250 'WatermarkOnDraftOrders' => 'option_draft_watermark',
251), false, '', 1, 'unsetdoc');
252print "<br>";
253
254/*
255 * Other options
256 *
257 */
258
259print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
260print '<input type="hidden" name="token" value="'.newToken().'">';
261print '<input type="hidden" name="action" value="set_other">';
262
263print load_fiche_titre($langs->trans("OtherOptions"), '', '');
264
265print '<div class="div-table-responsive-no-min">';
266print '<table class="noborder centpercent">';
267print '<tr class="liste_titre">';
268print '<td>'.$langs->trans("Parameter").'</td>';
269print '<td class="right"></td>';
270print "</tr>\n";
271
272$substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
273$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
274$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
275foreach ($substitutionarray as $key => $val) {
276 $htmltext .= $key.'<br>';
277}
278$htmltext .= '</i>';
279
280print '<tr class="oddeven"><td colspan="2">';
281print $form->textwithpicto($langs->trans("FreeLegalTextOnContracts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
282print '<br>';
283$variablename = 'CONTRACT_FREE_TEXT';
284if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
285 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
286} else {
287 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
288 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
289 print $doleditor->Create();
290}
291print '</td></tr>'."\n";
292
293//Use draft Watermark
294
295print '<tr class="oddeven"><td>';
296print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
297print '</td><td class="right">';
298print '<input class="flat minwidth200" type="text" name="CONTRACT_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('CONTRACT_DRAFT_WATERMARK')).'">';
299print '</td></tr>'."\n";
300
301print '<tr class="oddeven">';
302print '<td>'.$langs->trans("HideClosedServiceByDefault").'</td>';
303print '<td class="right">';
304print $form->selectyesno("activate_hideClosedServiceByDefault", getDolGlobalInt('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT', 0), 1);
305print '</td>';
306print '</tr>';
307
308// Allow online signing
309print '<tr class="oddeven">';
310print '<td>'.$langs->trans("AllowOnlineSign").'</td>';
311print '<td class="right">';
312if ($conf->use_javascript_ajax) {
313 print ajax_constantonoff('CONTRACT_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, $langs->transnoentitiesnoconv("WarningOnlineSignature", "https://www.dolistore.com"));
314} else {
315 if (getDolGlobalString('CONTRACT_ALLOW_ONLINESIGN')) {
316 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=allowonlinesign&token='.newToken().'&value=0">';
317 print img_picto($langs->trans("Activated"), 'switch_on');
318 print '</a>';
319 } else {
320 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=allowonlinesign&token='.newToken().'&value=1">';
321 print img_picto($langs->trans("Disabled"), 'switch_off');
322 print '</a>';
323 }
324}
325print '</td>';
326print '</tr>';
327
328// Allow external download
329print '<tr class="oddeven">';
330print '<td>'.$langs->trans("AllowExternalDownload").'</td>';
331print '<td class="right">';
332print ajax_constantonoff('CONTRACT_ALLOW_EXTERNAL_DOWNLOAD', array(), null, 0, 0, 0, 2, 0, 1);
333print '</td>';
334print '</tr>';
335
336// Reminder by email before a contract service expires
337if (isModEnabled('cron')) {
338 print '<tr class="oddeven">';
339 print '<td>'.$langs->trans("SendReminderForExpiredServicesTitle").'</td>';
340 print '<td class="right">';
341 print '<a href="'.DOL_URL_ROOT.'cron/list.php?search_label=SendReminderForExpiredServicesTitle&status=-1">'.$langs->trans("ConfigureContractReminderCronjobToSetFrequency").'</a>';
342 print '</td>';
343 print '</tr>';
344}
345print '</table>';
346print '</div>';
347
348print $form->buttonsSaveCancel("Save", '');
349
350print '</form>';
351
352print dol_get_fiche_end();
353
354// End of page
355llxFooter();
356$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
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
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.