expedition.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("admin", "sendings", "deliveries", "other"));
  37. if (!$user->admin) {
  38. accessforbidden();
  39. }
  40. $action = GETPOST('action', 'aZ09');
  41. $value = GETPOST('value', 'alpha');
  42. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  43. $label = GETPOST('label', 'alpha');
  44. $scandir = GETPOST('scan_dir', 'alpha');
  45. $type = 'shipping';
  46. if (empty($conf->global->EXPEDITION_ADDON_NUMBER)) {
  47. $conf->global->EXPEDITION_ADDON_NUMBER = 'mod_expedition_safor';
  48. }
  49. /*
  50. * Actions
  51. */
  52. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  53. if ($action == 'updateMask') {
  54. $maskconst = GETPOST('maskconstexpedition', 'aZ09');
  55. $maskvalue = GETPOST('maskexpedition', 'alpha');
  56. if (!empty($maskconst) && preg_match('/_MASK$/', $maskconst)) {
  57. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  58. }
  59. if (isset($res)) {
  60. if ($res > 0) {
  61. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  62. } else {
  63. setEventMessages($langs->trans("Error"), null, 'errors');
  64. }
  65. }
  66. } elseif ($action == 'set_param') {
  67. $freetext = GETPOST('SHIPPING_FREE_TEXT', 'restricthtml'); // 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. $error++;
  71. setEventMessages($langs->trans("Error"), null, 'errors');
  72. }
  73. $draft = GETPOST('SHIPPING_DRAFT_WATERMARK', 'alpha');
  74. $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
  75. if ($res <= 0) {
  76. $error++;
  77. setEventMessages($langs->trans("Error"), null, 'errors');
  78. }
  79. if (!$error) {
  80. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  81. }
  82. } elseif ($action == 'specimen') {
  83. $modele = GETPOST('module', 'alpha');
  84. $exp = new Expedition($db);
  85. $exp->initAsSpecimen();
  86. // Search template files
  87. $file = ''; $classname = ''; $filefound = 0;
  88. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  89. foreach ($dirmodels as $reldir) {
  90. $file = dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php", 0);
  91. if (file_exists($file)) {
  92. $filefound = 1;
  93. $classname = "pdf_".$modele;
  94. break;
  95. }
  96. }
  97. if ($filefound) {
  98. require_once $file;
  99. $module = new $classname($db);
  100. if ($module->write_file($exp, $langs) > 0) {
  101. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
  102. return;
  103. } else {
  104. setEventMessages($module->error, $module->errors, 'errors');
  105. dol_syslog($module->error, LOG_ERR);
  106. }
  107. } else {
  108. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  109. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  110. }
  111. } elseif ($action == 'set') {
  112. // Activate a model
  113. $ret = addDocumentModel($value, $type, $label, $scandir);
  114. } elseif ($action == 'del') {
  115. $ret = delDocumentModel($value, $type);
  116. if ($ret > 0) {
  117. if (getDolGlobalString('EXPEDITION_ADDON_PDF') == "$value") {
  118. dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF', $conf->entity);
  119. }
  120. }
  121. } elseif ($action == 'setdoc') {
  122. // Set default model
  123. if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  124. // La constante qui a ete lue en avant du nouveau set
  125. // on passe donc par une variable pour avoir un affichage coherent
  126. $conf->global->EXPEDITION_ADDON_PDF = $value;
  127. }
  128. // On active le modele
  129. $ret = delDocumentModel($value, $type);
  130. if ($ret > 0) {
  131. $ret = addDocumentModel($value, $type, $label, $scandir);
  132. }
  133. } elseif ($action == 'setmodel') {
  134. dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
  135. }
  136. /*
  137. * View
  138. */
  139. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  140. $form = new Form($db);
  141. llxHeader("", $langs->trans("SendingsSetup"));
  142. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  143. print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
  144. print '<br>';
  145. $head = expedition_admin_prepare_head();
  146. print dol_get_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'shipment');
  147. // Shipment numbering model
  148. print load_fiche_titre($langs->trans("SendingsNumberingModules"), '', '');
  149. print '<table class="noborder centpercent">';
  150. print '<tr class="liste_titre">';
  151. print '<td width="100">'.$langs->trans("Name").'</td>';
  152. print '<td>'.$langs->trans("Description").'</td>';
  153. print '<td>'.$langs->trans("Example").'</td>';
  154. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  155. print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  156. print "</tr>\n";
  157. clearstatcache();
  158. foreach ($dirmodels as $reldir) {
  159. $dir = dol_buildpath($reldir."core/modules/expedition/");
  160. if (is_dir($dir)) {
  161. $handle = opendir($dir);
  162. if (is_resource($handle)) {
  163. while (($file = readdir($handle)) !== false) {
  164. if (preg_match('/^mod_expedition_([a-z0-9_]*)\.php$/', $file)) {
  165. $file = substr($file, 0, dol_strlen($file) - 4);
  166. require_once $dir.$file.'.php';
  167. $module = new $file;
  168. if ($module->isEnabled()) {
  169. // Show modules according to features level
  170. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  171. continue;
  172. }
  173. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  174. continue;
  175. }
  176. print '<tr><td>'.$module->name."</td>\n";
  177. print '<td>';
  178. print $module->info($langs);
  179. print '</td>';
  180. // Show example of numbering module
  181. print '<td class="nowrap">';
  182. $tmp = $module->getExample();
  183. if (preg_match('/^Error/', $tmp)) {
  184. $langs->load("errors");
  185. print '<div class="error">'.$langs->trans($tmp).'</div>';
  186. } elseif ($tmp == 'NotConfigured') {
  187. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  188. } else {
  189. print $tmp;
  190. }
  191. print '</td>'."\n";
  192. print '<td class="center">';
  193. if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file") {
  194. print img_picto($langs->trans("Activated"), 'switch_on');
  195. } else {
  196. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.urlencode($file).'&label='.urlencode($module->name).'">';
  197. print img_picto($langs->trans("Disabled"), 'switch_off');
  198. print '</a>';
  199. }
  200. print '</td>';
  201. $expedition = new Expedition($db);
  202. $expedition->initAsSpecimen();
  203. // Info
  204. $htmltooltip = '';
  205. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  206. $nextval = $module->getNextValue($mysoc, $expedition);
  207. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  208. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  209. if ($nextval) {
  210. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  211. $nextval = $langs->trans($nextval);
  212. }
  213. $htmltooltip .= $nextval.'<br>';
  214. } else {
  215. $htmltooltip .= $langs->trans($module->error).'<br>';
  216. }
  217. }
  218. print '<td class="center">';
  219. print $form->textwithpicto('', $htmltooltip, 1, 0);
  220. print '</td>';
  221. print '</tr>';
  222. }
  223. }
  224. }
  225. closedir($handle);
  226. }
  227. }
  228. }
  229. print '</table><br>';
  230. /*
  231. * Documents models for Sendings Receipt
  232. */
  233. print load_fiche_titre($langs->trans("SendingsReceiptModel"), '', '');
  234. // Defini tableau def de modele invoice
  235. $type = "shipping";
  236. $def = array();
  237. $sql = "SELECT nom";
  238. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  239. $sql .= " WHERE type = '".$db->escape($type)."'";
  240. $sql .= " AND entity = ".$conf->entity;
  241. $resql = $db->query($sql);
  242. if ($resql) {
  243. $i = 0;
  244. $num_rows = $db->num_rows($resql);
  245. while ($i < $num_rows) {
  246. $array = $db->fetch_array($resql);
  247. array_push($def, $array[0]);
  248. $i++;
  249. }
  250. } else {
  251. dol_print_error($db);
  252. }
  253. print '<table class="noborder centpercent">';
  254. print '<tr class="liste_titre">';
  255. print '<td width="140">'.$langs->trans("Name").'</td>';
  256. print '<td>'.$langs->trans("Description").'</td>';
  257. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  258. print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
  259. print '<td class="nowrap center" width="80">'.$langs->trans("ShortInfo").'</td>';
  260. print '<td class="nowrap center" width="80" >'.$langs->trans("Preview").'</td>';
  261. print "</tr>\n";
  262. clearstatcache();
  263. foreach ($dirmodels as $reldir) {
  264. foreach (array('', '/doc') as $valdir) {
  265. $dir = dol_buildpath($reldir."core/modules/expedition".$valdir);
  266. if (is_dir($dir)) {
  267. $handle = opendir($dir);
  268. if (is_resource($handle)) {
  269. while (($file = readdir($handle)) !== false) {
  270. $filelist[] = $file;
  271. }
  272. closedir($handle);
  273. arsort($filelist);
  274. foreach ($filelist as $file) {
  275. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  276. if (file_exists($dir.'/'.$file)) {
  277. $name = substr($file, 4, dol_strlen($file) - 16);
  278. $classname = substr($file, 0, dol_strlen($file) - 12);
  279. require_once $dir.'/'.$file;
  280. $module = new $classname($db);
  281. $modulequalified = 1;
  282. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  283. $modulequalified = 0;
  284. }
  285. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  286. $modulequalified = 0;
  287. }
  288. if ($modulequalified) {
  289. print '<tr><td width="100">';
  290. print (empty($module->name) ? $name : $module->name);
  291. print "</td><td>\n";
  292. if (method_exists($module, 'info')) {
  293. print $module->info($langs);
  294. } else {
  295. print $module->description;
  296. }
  297. print '</td>';
  298. // Active
  299. if (in_array($name, $def)) {
  300. print '<td class="center">'."\n";
  301. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  302. print img_picto($langs->trans("Enabled"), 'switch_on');
  303. print '</a>';
  304. print '</td>';
  305. } else {
  306. print '<td class="center">'."\n";
  307. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  308. print "</td>";
  309. }
  310. // Defaut
  311. print '<td class="center">';
  312. if (getDolGlobalString('EXPEDITION_ADDON_PDF') == $name) {
  313. print img_picto($langs->trans("Default"), 'on');
  314. } else {
  315. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  316. }
  317. print '</td>';
  318. // Info
  319. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  320. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  321. if ($module->type == 'pdf') {
  322. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  323. }
  324. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  325. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  326. $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
  327. $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
  328. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  329. $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
  330. print '<td class="center">';
  331. print $form->textwithpicto('', $htmltooltip, 1, 0);
  332. print '</td>';
  333. // Preview
  334. print '<td class="center">';
  335. if ($module->type == 'pdf') {
  336. 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"), 'pdf').'</a>';
  337. } else {
  338. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  339. }
  340. print '</td>';
  341. print "</tr>\n";
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. print '</table>';
  351. print '<br>';
  352. /*
  353. * Other options
  354. *
  355. */
  356. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  357. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  358. print '<input type="hidden" name="token" value="'.newToken().'">';
  359. print '<input type="hidden" name="action" value="set_param">';
  360. print "<table class=\"noborder\" width=\"100%\">";
  361. print "<tr class=\"liste_titre\">";
  362. print "<td>".$langs->trans("Parameter")."</td>\n";
  363. print "</tr>";
  364. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  365. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  366. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  367. foreach ($substitutionarray as $key => $val) {
  368. $htmltext .= $key.'<br>';
  369. }
  370. $htmltext .= '</i>';
  371. print '<tr><td>';
  372. print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  373. $variablename = 'SHIPPING_FREE_TEXT';
  374. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
  375. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  376. } else {
  377. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  378. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  379. print $doleditor->Create();
  380. }
  381. print "</td></tr>\n";
  382. print '<tr><td>';
  383. print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
  384. print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
  385. print "</td></tr>\n";
  386. print '</table>';
  387. print $form->buttonsSaveCancel("Modify", '');
  388. print '</form>';
  389. // End of page
  390. llxFooter();
  391. $db->close();