contract.php 17 KB

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