contract.php 18 KB

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