holiday.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. else if ($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. else if ($action == 'set')
  102. {
  103. $ret = addDocumentModel($value, $type, $label, $scandir);
  104. }
  105. else if ($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. else if ($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. else if ($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. else if ($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. $var=true;
  183. while (($file = readdir($handle))!==false)
  184. {
  185. if (substr($file, 0, 12) == 'mod_holiday_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  186. {
  187. $file = substr($file, 0, dol_strlen($file)-4);
  188. require_once $dir.$file.'.php';
  189. $module = new $file($db);
  190. // Show modules according to features level
  191. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  192. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  193. if ($module->isEnabled())
  194. {
  195. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  196. print $module->info();
  197. print '</td>';
  198. // Show example of numbering model
  199. print '<td class="nowrap">';
  200. $tmp=$module->getExample();
  201. if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
  202. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  203. else print $tmp;
  204. print '</td>'."\n";
  205. print '<td align="center">';
  206. if ($conf->global->HOLIDAY_ADDON == "$file")
  207. {
  208. print img_picto($langs->trans("Activated"),'switch_on');
  209. }
  210. else
  211. {
  212. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
  213. print img_picto($langs->trans("Disabled"),'switch_off');
  214. print '</a>';
  215. }
  216. print '</td>';
  217. $holiday=new Holiday($db);
  218. $holiday->initAsSpecimen();
  219. // Info
  220. $htmltooltip='';
  221. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  222. $nextval=$module->getNextValue($mysoc,$holiday);
  223. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  224. $htmltooltip.=''.$langs->trans("NextValue").': ';
  225. if ($nextval) {
  226. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  227. $nextval = $langs->trans($nextval);
  228. $htmltooltip.=$nextval.'<br>';
  229. } else {
  230. $htmltooltip.=$langs->trans($module->error).'<br>';
  231. }
  232. }
  233. print '<td align="center">';
  234. print $form->textwithpicto('',$htmltooltip,1,0);
  235. print '</td>';
  236. print '</tr>';
  237. }
  238. }
  239. }
  240. closedir($handle);
  241. }
  242. }
  243. }
  244. print '</table><br>';
  245. if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
  246. {
  247. /*
  248. * Documents models for Holidays
  249. */
  250. print load_fiche_titre($langs->trans("TemplatePDFHolidays"),'','');
  251. // Defini tableau def des modeles
  252. $def = array();
  253. $sql = "SELECT nom";
  254. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  255. $sql.= " WHERE type = '".$type."'";
  256. $sql.= " AND entity = ".$conf->entity;
  257. $resql=$db->query($sql);
  258. if ($resql)
  259. {
  260. $i = 0;
  261. $num_rows=$db->num_rows($resql);
  262. while ($i < $num_rows)
  263. {
  264. $array = $db->fetch_array($resql);
  265. array_push($def, $array[0]);
  266. $i++;
  267. }
  268. }
  269. else
  270. {
  271. dol_print_error($db);
  272. }
  273. print '<table class="noborder" width="100%">';
  274. print '<tr class="liste_titre">';
  275. print '<td>'.$langs->trans("Name").'</td>';
  276. print '<td>'.$langs->trans("Description").'</td>';
  277. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  278. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  279. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  280. print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
  281. print "</tr>\n";
  282. clearstatcache();
  283. foreach ($dirmodels as $reldir)
  284. {
  285. foreach (array('','/doc') as $valdir)
  286. {
  287. $dir = dol_buildpath($reldir."core/modules/holiday".$valdir);
  288. if (is_dir($dir))
  289. {
  290. $handle=opendir($dir);
  291. if (is_resource($handle))
  292. {
  293. while (($file = readdir($handle))!==false)
  294. {
  295. $filelist[]=$file;
  296. }
  297. closedir($handle);
  298. arsort($filelist);
  299. foreach($filelist as $file)
  300. {
  301. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  302. {
  303. if (file_exists($dir.'/'.$file))
  304. {
  305. $name = substr($file, 4, dol_strlen($file) -16);
  306. $classname = substr($file, 0, dol_strlen($file) -12);
  307. require_once $dir.'/'.$file;
  308. $module = new $classname($db);
  309. $modulequalified=1;
  310. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  311. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  312. if ($modulequalified)
  313. {
  314. print '<tr class="oddeven"><td width="100">';
  315. print (empty($module->name)?$name:$module->name);
  316. print "</td><td>\n";
  317. if (method_exists($module,'info')) print $module->info($langs);
  318. else print $module->description;
  319. print '</td>';
  320. // Active
  321. if (in_array($name, $def))
  322. {
  323. print '<td align="center">'."\n";
  324. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
  325. print img_picto($langs->trans("Enabled"),'switch_on');
  326. print '</a>';
  327. print '</td>';
  328. }
  329. else
  330. {
  331. print '<td align="center">'."\n";
  332. 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>';
  333. print "</td>";
  334. }
  335. // Defaut
  336. print '<td align="center">';
  337. if ($conf->global->HOLIDAY_ADDON_PDF == $name)
  338. {
  339. print img_picto($langs->trans("Default"),'on');
  340. }
  341. else
  342. {
  343. 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>';
  344. }
  345. print '</td>';
  346. // Info
  347. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  348. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  349. if ($module->type == 'pdf')
  350. {
  351. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  352. }
  353. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  354. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  355. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  356. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  357. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  358. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  359. print '<td align="center">';
  360. print $form->textwithpicto('',$htmltooltip,1,0);
  361. print '</td>';
  362. // Preview
  363. print '<td align="center">';
  364. if ($module->type == 'pdf')
  365. {
  366. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
  367. }
  368. else
  369. {
  370. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  371. }
  372. print '</td>';
  373. print "</tr>\n";
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. print '</table>';
  383. print "<br>";
  384. /*
  385. * Other options
  386. */
  387. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  388. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  389. print '<input type="hidden" name="action" value="set_other">';
  390. print load_fiche_titre($langs->trans("OtherOptions"),'','');
  391. print '<table class="noborder" width="100%">';
  392. print '<tr class="liste_titre">';
  393. print '<td>'.$langs->trans("Parameter").'</td>';
  394. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  395. print "</tr>\n";
  396. $substitutionarray=pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
  397. $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
  398. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  399. foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
  400. $htmltext.='</i>';
  401. print '<tr class="oddeven"><td colspan="2">';
  402. print $form->textwithpicto($langs->trans("FreeLegalTextOnHolidays"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
  403. print '<br>';
  404. $variablename='HOLIDAY_FREE_TEXT';
  405. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  406. {
  407. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  408. }
  409. else
  410. {
  411. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  412. $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
  413. print $doleditor->Create();
  414. }
  415. print '</td></tr>'."\n";
  416. //Use draft Watermark
  417. print '<tr class="oddeven"><td>';
  418. print $form->textwithpicto($langs->trans("WatermarkOnDraftHolidayCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
  419. print '</td><td>';
  420. print '<input size="50" class="flat" type="text" name="HOLIDAY_DRAFT_WATERMARK" value="'.$conf->global->HOLIDAY_DRAFT_WATERMARK.'">';
  421. print '</td></tr>'."\n";
  422. print '</table>';
  423. print '<div class="center">';
  424. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  425. print '</div>';
  426. print '</form>';
  427. }
  428. dol_fiche_end();
  429. // End of page
  430. llxFooter();
  431. $db->close();