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