25 require
'../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/contract.lib.php';
32 $langs->loadLangs(array(
"admin",
"errors",
"contracts"));
38 $action =
GETPOST(
'action',
'aZ09');
39 $value =
GETPOST(
'value',
'alpha');
40 $modulepart =
GETPOST(
'modulepart',
'aZ09');
42 $label =
GETPOST(
'label',
'alpha');
43 $scandir =
GETPOST(
'scan_dir',
'alpha');
46 if (empty($conf->global->CONTRACT_ADDON)) {
47 $conf->global->CONTRACT_ADDON =
'mod_contract_serpis';
55 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
57 if ($action ==
'updateMask') {
58 $maskconst =
GETPOST(
'maskconstcontract',
'alpha');
59 $maskvalue =
GETPOST(
'maskcontract',
'alpha');
61 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
73 } elseif ($action ==
'specimen') {
74 $modele =
GETPOST(
'module',
'alpha');
77 $contract->initAsSpecimen();
80 $file =
''; $classname =
''; $filefound = 0;
81 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
82 foreach ($dirmodels as $reldir) {
83 $file =
dol_buildpath($reldir.
"core/modules/contract/doc/pdf_".$modele.
".modules.php", 0);
84 if (file_exists($file)) {
86 $classname =
"pdf_".$modele;
94 $module =
new $classname($db);
96 if ($module->write_file($contract, $langs) > 0) {
97 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=contract&file=SPECIMEN.pdf");
105 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
107 } elseif ($action ==
'set') {
110 } elseif ($action ==
'del') {
113 if ($conf->global->CONTRACT_ADDON_PDF ==
"$value") {
117 } elseif ($action ==
'setdoc') {
119 if (
dolibarr_set_const($db,
"CONTRACT_ADDON_PDF", $value,
'chaine', 0,
'', $conf->entity)) {
122 $conf->global->CONTRACT_ADDON_PDF = $value;
130 } elseif ($action ==
'setmod') {
135 } elseif ($action ==
'set_other') {
136 $freetext =
GETPOST(
'CONTRACT_FREE_TEXT',
'restricthtml');
137 $res1 =
dolibarr_set_const($db,
"CONTRACT_FREE_TEXT", $freetext,
'chaine', 0,
'', $conf->entity);
139 $draft =
GETPOST(
'CONTRACT_DRAFT_WATERMARK',
'alpha');
140 $res2 =
dolibarr_set_const($db,
"CONTRACT_DRAFT_WATERMARK", trim($draft),
'chaine', 0,
'', $conf->entity);
142 $value =
GETPOST(
'activate_hideClosedServiceByDefault',
'alpha');
143 $res3 =
dolibarr_set_const($db,
"CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT", $value,
'chaine', 0,
'', $conf->entity);
145 if (!($res1 > 0) || !($res2 > 0) || !($res3 > 0)) {
161 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
167 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
168 print
load_fiche_titre($langs->trans(
"ContractsSetup"), $linkback,
'title_setup');
172 print
dol_get_fiche_head($head,
'contract', $langs->trans(
"Contracts"), -1,
'contract');
180 print
'<table class="noborder centpercent">';
181 print
'<tr class="liste_titre">';
182 print
'<td width="100">'.$langs->trans(
"Name").
'</td>';
183 print
'<td>'.$langs->trans(
"Description").
'</td>';
184 print
'<td>'.$langs->trans(
"Example").
'</td>';
185 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
186 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
191 foreach ($dirmodels as $reldir) {
195 $handle = opendir($dir);
196 if (is_resource($handle)) {
197 while (($file = readdir($handle)) !==
false) {
198 if (substr($file, 0, 13) ==
'mod_contract_' && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
199 $file = substr($file, 0,
dol_strlen($file) - 4);
201 require_once $dir.$file.
'.php';
203 $module =
new $file($db);
206 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
209 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
213 if ($module->isEnabled()) {
214 print
'<tr class="oddeven"><td>'.$module->nom.
"</td><td>\n";
215 print $module->info();
219 print
'<td class="nowrap">';
220 $tmp = $module->getExample();
221 if (preg_match(
'/^Error/', $tmp)) {
222 $langs->load(
"errors");
223 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
224 } elseif ($tmp ==
'NotConfigured') {
225 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
231 print
'<td class="center">';
232 if ($conf->global->CONTRACT_ADDON ==
"$file") {
233 print
img_picto($langs->trans(
"Activated"),
'switch_on');
235 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&value='.urlencode($file).
'">';
236 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
242 $contract->initAsSpecimen();
246 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
247 $nextval = $module->getNextValue($mysoc, $contract);
248 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
249 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
251 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
252 $nextval = $langs->trans($nextval);
254 $htmltooltip .= $nextval.
'<br>';
256 $htmltooltip .= $langs->trans($module->error).
'<br>';
260 print
'<td class="center">';
261 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
273 print
'</table><br>';
284 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
285 $sql .=
" WHERE type = '".$db->escape($type).
"'";
286 $sql .=
" AND entity = ".$conf->entity;
287 $resql = $db->query($sql);
290 $num_rows = $db->num_rows(
$resql);
291 while ($i < $num_rows) {
292 $array = $db->fetch_array(
$resql);
293 array_push($def, $array[0]);
301 print
'<table class="noborder centpercent">';
302 print
'<tr class="liste_titre">';
303 print
'<td>'.$langs->trans(
"Name").
'</td>';
304 print
'<td>'.$langs->trans(
"Description").
'</td>';
305 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
306 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
307 print
'<td class="center" width="80">'.$langs->trans(
"ShortInfo").
'</td>';
308 print
'<td class="center" width="80">'.$langs->trans(
"Preview").
'</td>';
313 foreach ($dirmodels as $reldir) {
314 foreach (array(
'',
'/doc') as $valdir) {
315 $realpath = $reldir.
"core/modules/contract".$valdir;
319 $handle = opendir($dir);
320 if (is_resource($handle)) {
321 while (($file = readdir($handle)) !==
false) {
327 foreach ($filelist as $file) {
328 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
329 if (file_exists($dir.
'/'.$file)) {
330 $name = substr($file, 4,
dol_strlen($file) - 16);
331 $classname = substr($file, 0,
dol_strlen($file) - 12);
333 require_once $dir.
'/'.$file;
334 $module =
new $classname($db);
336 $modulequalified = 1;
337 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
338 $modulequalified = 0;
340 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
341 $modulequalified = 0;
344 if ($modulequalified) {
345 print
'<tr class="oddeven"><td width="100">';
346 print (empty($module->name) ? $name : $module->name);
348 if (method_exists($module,
'info')) {
349 print $module->info($langs);
351 print $module->description;
356 if (in_array($name, $def)) {
357 print
'<td class="center">'.
"\n";
358 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
359 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
363 print
'<td class="center">'.
"\n";
364 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=set&token='.
newToken().
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'">'.
img_picto($langs->trans(
"Disabled"),
'switch_off').
'</a>';
369 print
'<td class="center">';
370 if ($conf->global->CONTRACT_ADDON_PDF == $name) {
371 print
img_picto($langs->trans(
"Default"),
'on');
373 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=setdoc&token='.
newToken().
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'" alt="'.$langs->trans(
"Default").
'">'.
img_picto($langs->trans(
"Disabled"),
'off').
'</a>';
378 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
379 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
380 if ($module->type ==
'pdf') {
381 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
383 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
385 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
386 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
387 $htmltooltip .=
'<br>'.$langs->trans(
"PaymentMode").
': '.
yn($module->option_modereg, 1, 1);
388 $htmltooltip .=
'<br>'.$langs->trans(
"PaymentConditions").
': '.
yn($module->option_condreg, 1, 1);
389 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
390 $htmltooltip .=
'<br>'.$langs->trans(
"WatermarkOnDraftOrders").
': '.
yn($module->option_draft_watermark, 1, 1);
393 print
'<td class="center">';
394 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
398 print
'<td class="center">';
399 if ($module->type ==
'pdf') {
400 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.$name.
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
402 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
424 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
425 print
'<input type="hidden" name="token" value="'.newToken().
'">';
426 print
'<input type="hidden" name="action" value="set_other">';
429 print
'<table class="noborder centpercent">';
430 print
'<tr class="liste_titre">';
431 print
'<td>'.$langs->trans(
"Parameter").
'</td>';
432 print
'<td class="center" width="60">'.$langs->trans(
"Value").
'</td>';
436 $substitutionarray[
'__(AnyTranslationKey)__'] = $langs->trans(
"Translation");
437 $htmltext =
'<i>'.$langs->trans(
"AvailableVariables").
':<br>';
438 foreach ($substitutionarray as $key => $val) {
439 $htmltext .= $key.
'<br>';
443 print
'<tr class="oddeven"><td colspan="2">';
444 print
$form->textwithpicto($langs->trans(
"FreeLegalTextOnContracts"), $langs->trans(
"AddCRIfTooLong").
'<br><br>'.$htmltext, 1,
'help',
'', 0, 2,
'tooltiphelp');
446 $variablename =
'CONTRACT_FREE_TEXT';
447 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
448 print
'<textarea name="'.$variablename.
'" class="flat" cols="120">'.
getDolGlobalString($variablename).
'</textarea>';
450 include_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
452 print $doleditor->Create();
454 print
'</td></tr>'.
"\n";
458 print
'<tr class="oddeven"><td>';
459 print
$form->textwithpicto($langs->trans(
"WatermarkOnDraftContractCards"), $htmltext, 1,
'help',
'', 0, 2,
'watermarktooltip').
'<br>';
461 print
'<input class="flat minwidth200" type="text" name="CONTRACT_DRAFT_WATERMARK" value="'.dol_escape_htmltag(
getDolGlobalString(
'CONTRACT_DRAFT_WATERMARK')).
'">';
462 print
'</td></tr>'.
"\n";
464 print
'<tr class="oddeven">';
465 print
'<td>'.$langs->trans(
"HideClosedServiceByDefault").
'</td>';
466 print
'<td width="60" class="right">';
467 print
$form->selectyesno(
"activate_hideClosedServiceByDefault", (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) ? $conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT : 0), 1);
473 print
$form->buttonsSaveCancel(
"Save",
'');