contract.php 16 KB

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