contract.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/contract.php
  20. * \ingroup contract
  21. * \brief Setup page of module Contracts
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("admin", "errors", "contracts"));
  30. if (!$user->admin) accessforbidden();
  31. $action = GETPOST('action', 'alpha');
  32. $value = GETPOST('value', 'alpha');
  33. $label = GETPOST('label', 'alpha');
  34. $scandir = GETPOST('scan_dir', 'alpha');
  35. $type = 'contract';
  36. if (empty($conf->global->CONTRACT_ADDON))
  37. {
  38. $conf->global->CONTRACT_ADDON = 'mod_contract_serpis';
  39. }
  40. /*
  41. * Actions
  42. */
  43. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  44. if ($action == 'updateMask')
  45. {
  46. $maskconst = GETPOST('maskconstcontract', 'alpha');
  47. $maskvalue = GETPOST('maskcontract', 'alpha');
  48. if ($maskconst) $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  49. if (!$res > 0) $error++;
  50. if (!$error)
  51. {
  52. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  53. } else {
  54. setEventMessages($langs->trans("Error"), null, 'errors');
  55. }
  56. } elseif ($action == 'specimen') // For contract
  57. {
  58. $modele = GETPOST('module', 'alpha');
  59. $contract = new Contrat($db);
  60. $contract->initAsSpecimen();
  61. // Search template files
  62. $file = ''; $classname = ''; $filefound = 0;
  63. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  64. foreach ($dirmodels as $reldir)
  65. {
  66. $file = dol_buildpath($reldir."core/modules/contract/doc/pdf_".$modele.".modules.php", 0);
  67. if (file_exists($file))
  68. {
  69. $filefound = 1;
  70. $classname = "pdf_".$modele;
  71. break;
  72. }
  73. }
  74. if ($filefound)
  75. {
  76. require_once $file;
  77. $module = new $classname($db);
  78. if ($module->write_file($contract, $langs) > 0)
  79. {
  80. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=contract&file=SPECIMEN.pdf");
  81. return;
  82. } else {
  83. setEventMessages($obj->error, $obj->errors, 'errors');
  84. dol_syslog($obj->error, LOG_ERR);
  85. }
  86. } else {
  87. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  88. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  89. }
  90. }
  91. // Activate a model
  92. elseif ($action == 'set')
  93. {
  94. $ret = addDocumentModel($value, $type, $label, $scandir);
  95. } elseif ($action == 'del')
  96. {
  97. $ret = delDocumentModel($value, $type);
  98. if ($ret > 0)
  99. {
  100. if ($conf->global->CONTRACT_ADDON_PDF == "$value") dolibarr_del_const($db, 'CONTRACT_ADDON_PDF', $conf->entity);
  101. }
  102. }
  103. // Set default model
  104. elseif ($action == 'setdoc')
  105. {
  106. if (dolibarr_set_const($db, "CONTRACT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
  107. {
  108. // La constante qui a ete lue en avant du nouveau set
  109. // on passe donc par une variable pour avoir un affichage coherent
  110. $conf->global->CONTRACT_ADDON_PDF = $value;
  111. }
  112. // On active le modele
  113. $ret = delDocumentModel($value, $type);
  114. if ($ret > 0)
  115. {
  116. $ret = addDocumentModel($value, $type, $label, $scandir);
  117. }
  118. } elseif ($action == 'setmod')
  119. {
  120. // TODO Verifier si module numerotation choisi peut etre active
  121. // par appel methode canBeActivated
  122. dolibarr_set_const($db, "CONTRACT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  123. } elseif ($action == 'set_other')
  124. {
  125. $freetext = GETPOST('CONTRACT_FREE_TEXT', 'none'); // No alpha here, we want exact string
  126. $res1 = dolibarr_set_const($db, "CONTRACT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
  127. $draft = GETPOST('CONTRACT_DRAFT_WATERMARK', 'alpha');
  128. $res2 = dolibarr_set_const($db, "CONTRACT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
  129. $value = GETPOST('activate_hideClosedServiceByDefault', 'alpha');
  130. $res3 = dolibarr_set_const($db, "CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT", $value, 'chaine', 0, '', $conf->entity);
  131. if (!$res1 > 0 || !$res2 > 0 || !$res3 > 0) $error++;
  132. if (!$error)
  133. {
  134. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  135. } else {
  136. setEventMessages($langs->trans("Error"), null, 'errors');
  137. }
  138. }
  139. /*
  140. * View
  141. */
  142. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  143. llxHeader();
  144. $form = new Form($db);
  145. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  146. print load_fiche_titre($langs->trans("ContractsSetup"), $linkback, 'title_setup');
  147. $head = contract_admin_prepare_head();
  148. dol_fiche_head($head, 'contract', $langs->trans("Contracts"), -1, 'contract');
  149. /*
  150. * Contracts Numbering model
  151. */
  152. print load_fiche_titre($langs->trans("ContractsNumberingModules"), '', '');
  153. print '<table class="noborder centpercent">';
  154. print '<tr class="liste_titre">';
  155. print '<td width="100">'.$langs->trans("Name").'</td>';
  156. print '<td>'.$langs->trans("Description").'</td>';
  157. print '<td>'.$langs->trans("Example").'</td>';
  158. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  159. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  160. print "</tr>\n";
  161. clearstatcache();
  162. foreach ($dirmodels as $reldir)
  163. {
  164. $dir = dol_buildpath($reldir."core/modules/contract/");
  165. if (is_dir($dir))
  166. {
  167. $handle = opendir($dir);
  168. if (is_resource($handle))
  169. {
  170. while (($file = readdir($handle)) !== false)
  171. {
  172. if (substr($file, 0, 13) == 'mod_contract_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
  173. {
  174. $file = substr($file, 0, dol_strlen($file) - 4);
  175. require_once $dir.$file.'.php';
  176. $module = new $file($db);
  177. // Show modules according to features level
  178. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  179. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  180. if ($module->isEnabled())
  181. {
  182. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  183. print $module->info();
  184. print '</td>';
  185. // Show example of numbering model
  186. print '<td class="nowrap">';
  187. $tmp = $module->getExample();
  188. if (preg_match('/^Error/', $tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
  189. else print $tmp;
  190. print '</td>'."\n";
  191. print '<td class="center">';
  192. if ($conf->global->CONTRACT_ADDON == "$file")
  193. {
  194. print img_picto($langs->trans("Activated"), 'switch_on');
  195. } else {
  196. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
  197. print img_picto($langs->trans("Disabled"), 'switch_off');
  198. print '</a>';
  199. }
  200. print '</td>';
  201. $contract = new Contrat($db);
  202. $contract->initAsSpecimen();
  203. // Info
  204. $htmltooltip = '';
  205. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  206. $nextval = $module->getNextValue($mysoc, $contract);
  207. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  208. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  209. if ($nextval) {
  210. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
  211. $nextval = $langs->trans($nextval);
  212. $htmltooltip .= $nextval.'<br>';
  213. } else {
  214. $htmltooltip .= $langs->trans($module->error).'<br>';
  215. }
  216. }
  217. print '<td class="center">';
  218. print $form->textwithpicto('', $htmltooltip, 1, 0);
  219. print '</td>';
  220. print '</tr>';
  221. }
  222. }
  223. }
  224. closedir($handle);
  225. }
  226. }
  227. }
  228. print '</table><br>';
  229. /*
  230. * Documents models for Contracts
  231. */
  232. print load_fiche_titre($langs->trans("TemplatePDFContracts"), '', '');
  233. // Defini tableau def des modeles
  234. $def = array();
  235. $sql = "SELECT nom";
  236. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  237. $sql .= " WHERE type = '".$type."'";
  238. $sql .= " AND entity = ".$conf->entity;
  239. $resql = $db->query($sql);
  240. if ($resql)
  241. {
  242. $i = 0;
  243. $num_rows = $db->num_rows($resql);
  244. while ($i < $num_rows)
  245. {
  246. $array = $db->fetch_array($resql);
  247. array_push($def, $array[0]);
  248. $i++;
  249. }
  250. } else {
  251. dol_print_error($db);
  252. }
  253. print '<table class="noborder centpercent">';
  254. print '<tr class="liste_titre">';
  255. print '<td>'.$langs->trans("Name").'</td>';
  256. print '<td>'.$langs->trans("Description").'</td>';
  257. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  258. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  259. print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  260. print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
  261. print "</tr>\n";
  262. clearstatcache();
  263. foreach ($dirmodels as $reldir)
  264. {
  265. foreach (array('', '/doc') as $valdir)
  266. {
  267. $realpath = $reldir."core/modules/contract".$valdir;
  268. $dir = dol_buildpath($realpath);
  269. if (is_dir($dir))
  270. {
  271. $handle = opendir($dir);
  272. if (is_resource($handle))
  273. {
  274. while (($file = readdir($handle)) !== false)
  275. {
  276. $filelist[] = $file;
  277. }
  278. closedir($handle);
  279. arsort($filelist);
  280. foreach ($filelist as $file)
  281. {
  282. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
  283. {
  284. if (file_exists($dir.'/'.$file))
  285. {
  286. $name = substr($file, 4, dol_strlen($file) - 16);
  287. $classname = substr($file, 0, dol_strlen($file) - 12);
  288. require_once $dir.'/'.$file;
  289. $module = new $classname($db);
  290. $modulequalified = 1;
  291. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
  292. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
  293. if ($modulequalified)
  294. {
  295. print '<tr class="oddeven"><td width="100">';
  296. print (empty($module->name) ? $name : $module->name);
  297. print "</td><td>\n";
  298. if (method_exists($module, 'info')) print $module->info($langs);
  299. else print $module->description;
  300. print '</td>';
  301. // Active
  302. if (in_array($name, $def))
  303. {
  304. print '<td class="center">'."\n";
  305. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
  306. print img_picto($langs->trans("Enabled"), 'switch_on');
  307. print '</a>';
  308. print '</td>';
  309. } else {
  310. print '<td class="center">'."\n";
  311. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  312. print "</td>";
  313. }
  314. // Defaut
  315. print '<td class="center">';
  316. if ($conf->global->CONTRACT_ADDON_PDF == $name)
  317. {
  318. print img_picto($langs->trans("Default"), 'on');
  319. } else {
  320. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  321. }
  322. print '</td>';
  323. // Info
  324. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  325. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  326. if ($module->type == 'pdf')
  327. {
  328. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  329. }
  330. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  331. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  332. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  333. $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
  334. $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
  335. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  336. $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
  337. print '<td class="center">';
  338. print $form->textwithpicto('', $htmltooltip, 1, 0);
  339. print '</td>';
  340. // Preview
  341. print '<td class="center">';
  342. if ($module->type == 'pdf')
  343. {
  344. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'contract').'</a>';
  345. } else {
  346. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  347. }
  348. print '</td>';
  349. print "</tr>\n";
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. }
  358. print '</table>';
  359. print "<br>";
  360. /*
  361. * Other options
  362. *
  363. */
  364. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  365. print '<input type="hidden" name="token" value="'.newToken().'">';
  366. print '<input type="hidden" name="action" value="set_other">';
  367. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  368. print '<table class="noborder centpercent">';
  369. print '<tr class="liste_titre">';
  370. print '<td>'.$langs->trans("Parameter").'</td>';
  371. print '<td class="center" width="60">'.$langs->trans("Value").'</td>';
  372. print "</tr>\n";
  373. $substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
  374. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  375. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  376. foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
  377. $htmltext .= '</i>';
  378. print '<tr class="oddeven"><td colspan="2">';
  379. print $form->textwithpicto($langs->trans("FreeLegalTextOnContracts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
  380. print '<br>';
  381. $variablename = 'CONTRACT_FREE_TEXT';
  382. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  383. {
  384. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  385. } else {
  386. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  387. $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
  388. print $doleditor->Create();
  389. }
  390. print '</td></tr>'."\n";
  391. //Use draft Watermark
  392. print '<tr class="oddeven"><td>';
  393. print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
  394. print '</td><td>';
  395. print '<input size="50" class="flat" type="text" name="CONTRACT_DRAFT_WATERMARK" value="'.$conf->global->CONTRACT_DRAFT_WATERMARK.'">';
  396. print '</td></tr>'."\n";
  397. print '<tr class="oddeven">';
  398. print '<td>'.$langs->trans("HideClosedServiceByDefault").'</td>';
  399. print '<td width="60" class="right">';
  400. print $form->selectyesno("activate_hideClosedServiceByDefault", (! empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT)?$conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT:0), 1);
  401. print '</td>';
  402. print '</tr>';
  403. print '</table>';
  404. print '<div class="center">';
  405. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  406. print '</div>';
  407. print '</form>';
  408. dol_fiche_end();
  409. // End of page
  410. llxFooter();
  411. $db->close();