holiday.php 17 KB

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