delivery.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <?php
  2. /* Copyright (C) 2003-2005 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-2014 Regis Houssin <regis.houssin@inodbox.com>
  8. * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/admin/delivery.php
  27. * \ingroup delivery
  28. * \brief age to setup extra fields of delivery
  29. */
  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.'/delivery/class/delivery.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("admin", "sendings", "deliveries", "other"));
  37. if (!$user->admin) accessforbidden();
  38. $action = GETPOST('action', 'alpha');
  39. $value = GETPOST('value', 'alpha');
  40. $label = GETPOST('label', 'alpha');
  41. $scandir = GETPOST('scan_dir', 'alpha');
  42. $type = 'delivery';
  43. /*
  44. * Actions
  45. */
  46. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  47. if ($action == 'updateMask')
  48. {
  49. $maskconstdelivery = GETPOST('maskconstdelivery', 'alpha');
  50. $maskdelivery = GETPOST('maskdelivery', 'alpha');
  51. if ($maskconstdelivery) $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity);
  52. if (!$res > 0) $error++;
  53. if (!$error)
  54. {
  55. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  56. } else {
  57. setEventMessages($langs->trans("Error"), null, 'errors');
  58. }
  59. }
  60. if ($action == 'set_DELIVERY_FREE_TEXT')
  61. {
  62. $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
  63. $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity);
  64. if (!$res > 0) $error++;
  65. if (!$error)
  66. {
  67. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  68. } else {
  69. setEventMessages($langs->trans("Error"), null, 'errors');
  70. }
  71. }
  72. if ($action == 'specimen')
  73. {
  74. $modele = GETPOST('module', 'alpha');
  75. $sending = new Delivery($db);
  76. $sending->initAsSpecimen();
  77. // Search template files
  78. $file = ''; $classname = ''; $filefound = 0;
  79. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  80. foreach ($dirmodels as $reldir)
  81. {
  82. $file = dol_buildpath($reldir."core/modules/livraison/doc/pdf_".$modele.".modules.php", 0);
  83. if (file_exists($file))
  84. {
  85. $filefound = 1;
  86. $classname = "pdf_".$modele;
  87. break;
  88. }
  89. }
  90. if ($filefound)
  91. {
  92. require_once $file;
  93. $module = new $classname($db);
  94. if ($module->write_file($sending, $langs) > 0)
  95. {
  96. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf");
  97. return;
  98. } else {
  99. setEventMessages($module->error, $module->errors, 'errors');
  100. dol_syslog($module->error, LOG_ERR);
  101. }
  102. } else {
  103. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  104. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  105. }
  106. }
  107. if ($action == 'set')
  108. {
  109. $ret = addDocumentModel($value, $type, $label, $scandir);
  110. }
  111. if ($action == 'del')
  112. {
  113. $ret = delDocumentModel($value, $type);
  114. if ($ret > 0)
  115. {
  116. if ($conf->global->LIVRAISON_ADDON_PDF == "$value") dolibarr_del_const($db, 'LIVRAISON_ADDON_PDF', $conf->entity);
  117. }
  118. }
  119. if ($action == 'setdoc')
  120. {
  121. if (dolibarr_set_const($db, "LIVRAISON_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
  122. {
  123. // La constante qui a ete lue en avant du nouveau set
  124. // on passe donc par une variable pour avoir un affichage coherent
  125. $conf->global->LIVRAISON_ADDON_PDF = $value;
  126. }
  127. // On active le modele
  128. $ret = delDocumentModel($value, $type);
  129. if ($ret > 0)
  130. {
  131. $ret = addDocumentModel($value, $type, $label, $scandir);
  132. }
  133. }
  134. if ($action == 'setmod')
  135. {
  136. // TODO Verifier si module numerotation choisi peut etre active
  137. // par appel methode canBeActivated
  138. dolibarr_set_const($db, "LIVRAISON_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
  139. }
  140. /*
  141. * View
  142. */
  143. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  144. llxHeader("", "");
  145. $form = new Form($db);
  146. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  147. print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
  148. print '<br>';
  149. $head = expedition_admin_prepare_head();
  150. dol_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'shipment');
  151. // Delivery numbering model
  152. print load_fiche_titre($langs->trans("DeliveryOrderNumberingModules"), '', '');
  153. print '<table class="noborder centpercent">';
  154. print '<tr class="liste_titre">';
  155. print '<td width="100">'.$langs->trans("Name").'</td>';
  156. print '<td>'.$langs->trans("Description").'</td>';
  157. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  158. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  159. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  160. print '</tr>'."\n";
  161. clearstatcache();
  162. foreach ($dirmodels as $reldir)
  163. {
  164. $dir = dol_buildpath($reldir."core/modules/livraison/");
  165. if (is_dir($dir))
  166. {
  167. $handle = opendir($dir);
  168. if (is_resource($handle))
  169. {
  170. while (($file = readdir($handle)) !== false)
  171. {
  172. if (substr($file, 0, 14) == 'mod_livraison_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
  173. {
  174. $file = substr($file, 0, dol_strlen($file) - 4);
  175. require_once $dir.$file.'.php';
  176. $module = new $file;
  177. if ($module->isEnabled())
  178. {
  179. // Show modules according to features level
  180. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  181. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  182. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  183. print $module->info();
  184. print '</td>';
  185. // Show example of numbering module
  186. print '<td class="nowrap">';
  187. $tmp = $module->getExample();
  188. if (preg_match('/^Error/', $tmp)) {
  189. $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
  190. } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
  191. else print $tmp;
  192. print '</td>'."\n";
  193. print '<td class="center">';
  194. if ($conf->global->LIVRAISON_ADDON_NUMBER == "$file")
  195. {
  196. print img_picto($langs->trans("Activated"), 'switch_on');
  197. } else {
  198. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;token='.newToken().'&amp;value='.urlencode($file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  199. }
  200. print '</td>';
  201. $delivery = new Delivery($db);
  202. $delivery->initAsSpecimen();
  203. // Info
  204. $htmltooltip = '';
  205. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  206. $nextval = $module->getNextValue($mysoc, $delivery);
  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. $htmltooltip .= $nextval.'<br>';
  213. } else {
  214. $htmltooltip .= $langs->trans($module->error).'<br>';
  215. }
  216. }
  217. print '<td class="center">';
  218. print $form->textwithpicto('', $htmltooltip, 1, 0);
  219. print '</td>';
  220. print '</tr>';
  221. }
  222. }
  223. }
  224. closedir($handle);
  225. }
  226. }
  227. }
  228. print '</table>';
  229. /*
  230. * Documents Models for delivery
  231. */
  232. print '<br>';
  233. print load_fiche_titre($langs->trans("DeliveryOrderModel"), '', '');
  234. // Defini tableau def de modele
  235. $type = "delivery";
  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. {
  244. $i = 0;
  245. $num_rows = $db->num_rows($resql);
  246. while ($i < $num_rows)
  247. {
  248. $array = $db->fetch_array($resql);
  249. array_push($def, $array[0]);
  250. $i++;
  251. }
  252. } else {
  253. dol_print_error($db);
  254. }
  255. print '<table class="noborder centpercent">';
  256. print '<tr class="liste_titre">';
  257. print '<td width="140">'.$langs->trans("Name").'</td>';
  258. print '<td>'.$langs->trans("Description").'</td>';
  259. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  260. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  261. print '<td align="center" width="32">'.$langs->trans("ShortInfo").'</td>';
  262. print '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
  263. print "</tr>\n";
  264. clearstatcache();
  265. foreach ($dirmodels as $reldir)
  266. {
  267. $dir = dol_buildpath($reldir."core/modules/livraison/doc/");
  268. if (is_dir($dir))
  269. {
  270. $handle = opendir($dir);
  271. if (is_resource($handle))
  272. {
  273. while (($file = readdir($handle)) !== false)
  274. {
  275. $filelist[] = $file;
  276. }
  277. closedir($handle);
  278. arsort($filelist);
  279. foreach ($filelist as $file)
  280. {
  281. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
  282. {
  283. if (file_exists($dir.'/'.$file))
  284. {
  285. $name = substr($file, 4, dol_strlen($file) - 16);
  286. $classname = substr($file, 0, dol_strlen($file) - 12);
  287. require_once $dir.'/'.$file;
  288. $module = new $classname($db);
  289. $modulequalified = 1;
  290. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
  291. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
  292. if ($modulequalified)
  293. {
  294. print '<tr class="oddeven"><td width="100">';
  295. print (empty($module->name) ? $name : $module->name);
  296. print "</td><td>\n";
  297. if (method_exists($module, 'info')) print $module->info($langs);
  298. else print $module->description;
  299. print '</td>';
  300. // Active
  301. if (in_array($name, $def))
  302. {
  303. print "<td align=\"center\">\n";
  304. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  305. print img_picto($langs->trans("Enabled"), 'switch_on');
  306. print '</a>';
  307. print "</td>";
  308. } else {
  309. print "<td align=\"center\">\n";
  310. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  311. print "</td>";
  312. }
  313. // Default
  314. print "<td align=\"center\">";
  315. if ($conf->global->LIVRAISON_ADDON_PDF == "$name")
  316. {
  317. print img_picto($langs->trans("Default"), 'on');
  318. } else {
  319. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  320. }
  321. print '</td>';
  322. // Info
  323. $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  324. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  325. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").'</u>:';
  326. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  327. print '<td class="center">';
  328. print $form->textwithpicto('', $htmltooltip, 1, 0);
  329. print '</td>';
  330. // Preview
  331. print '<td class="center">';
  332. if ($module->type == 'pdf')
  333. {
  334. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'sending').'</a>';
  335. } else {
  336. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  337. }
  338. print '</td>';
  339. print '</tr>';
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. print '</table>';
  348. /*
  349. * Autres Options
  350. */
  351. print "<br>";
  352. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  353. print '<table class="noborder centpercent">';
  354. print '<tr class="liste_titre">';
  355. print '<td>'.$langs->trans("Parameter").'</td>';
  356. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  357. print '<td width="80">&nbsp;</td>';
  358. print "</tr>\n";
  359. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  360. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  361. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  362. foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
  363. $htmltext .= '</i>';
  364. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  365. print '<input type="hidden" name="token" value="'.newToken().'">';
  366. print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
  367. print '<tr class="oddeven"><td colspan="2">';
  368. print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  369. $variablename = 'DELIVERY_FREE_TEXT';
  370. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  371. {
  372. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  373. } else {
  374. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  375. $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
  376. print $doleditor->Create();
  377. }
  378. print '</td><td class="right">';
  379. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  380. print "</td></tr>\n";
  381. print '</form>';
  382. print '</table>';
  383. // End of page
  384. llxFooter();
  385. $db->close();