expedition.php 17 KB

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