delivery.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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) {
  38. accessforbidden();
  39. }
  40. $action = GETPOST('action', 'alpha');
  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 = 'delivery';
  46. /*
  47. * Actions
  48. */
  49. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  50. // Shipment note
  51. if (isModEnabled('expedition') && !getDolGlobalString('MAIN_SUBMODULE_EXPEDITION')) {
  52. // This option should always be set to on when module is on.
  53. dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity);
  54. }
  55. /*
  56. if ($action == 'activate_sending')
  57. {
  58. dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1",'chaine',0,'',$conf->entity);
  59. header("Location: confexped.php");
  60. exit;
  61. }
  62. if ($action == 'disable_sending')
  63. {
  64. dolibarr_del_const($db, "MAIN_SUBMODULE_EXPEDITION",$conf->entity);
  65. header("Location: confexped.php");
  66. exit;
  67. }
  68. */
  69. // Delivery note
  70. if ($action == 'activate_delivery') {
  71. dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity); // We must also enable this
  72. dolibarr_set_const($db, "MAIN_SUBMODULE_DELIVERY", "1", 'chaine', 0, '', $conf->entity);
  73. header("Location: delivery.php");
  74. exit;
  75. } elseif ($action == 'disable_delivery') {
  76. dolibarr_del_const($db, "MAIN_SUBMODULE_DELIVERY", $conf->entity);
  77. header("Location: delivery.php");
  78. exit;
  79. }
  80. if ($action == 'updateMask') {
  81. $maskconstdelivery = GETPOST('maskconstdelivery', 'aZ09');
  82. $maskdelivery = GETPOST('maskdelivery', 'alpha');
  83. if ($maskconstdelivery && preg_match('/_MASK$/', $maskconstdelivery)) {
  84. $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity);
  85. }
  86. if (!($res > 0)) {
  87. $error++;
  88. }
  89. if (!$error) {
  90. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  91. } else {
  92. setEventMessages($langs->trans("Error"), null, 'errors');
  93. }
  94. }
  95. if ($action == 'set_DELIVERY_FREE_TEXT') {
  96. $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
  97. $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity);
  98. if (!($res > 0)) {
  99. $error++;
  100. }
  101. if (!$error) {
  102. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  103. } else {
  104. setEventMessages($langs->trans("Error"), null, 'errors');
  105. }
  106. }
  107. if ($action == 'specimen') {
  108. $modele = GETPOST('module', 'alpha');
  109. $sending = new Delivery($db);
  110. $sending->initAsSpecimen();
  111. // Search template files
  112. $file = '';
  113. $classname = '';
  114. $filefound = 0;
  115. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  116. foreach ($dirmodels as $reldir) {
  117. $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0);
  118. if (file_exists($file)) {
  119. $filefound = 1;
  120. $classname = "pdf_".$modele;
  121. break;
  122. }
  123. }
  124. if ($filefound) {
  125. require_once $file;
  126. $module = new $classname($db);
  127. if ($module->write_file($sending, $langs) > 0) {
  128. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf");
  129. return;
  130. } else {
  131. setEventMessages($module->error, $module->errors, 'errors');
  132. dol_syslog($module->error, LOG_ERR);
  133. }
  134. } else {
  135. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  136. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  137. }
  138. }
  139. if ($action == 'set') {
  140. $ret = addDocumentModel($value, $type, $label, $scandir);
  141. }
  142. if ($action == 'del') {
  143. $ret = delDocumentModel($value, $type);
  144. if ($ret > 0) {
  145. if (getDolGlobalString('DELIVERY_ADDON_PDF') == $value) {
  146. dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity);
  147. }
  148. }
  149. }
  150. if ($action == 'setdoc') {
  151. if (dolibarr_set_const($db, "DELIVERY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  152. // La constante qui a ete lue en avant du nouveau set
  153. // on passe donc par une variable pour avoir un affichage coherent
  154. $conf->global->DELIVERY_ADDON_PDF = $value;
  155. }
  156. // On active le modele
  157. $ret = delDocumentModel($value, $type);
  158. if ($ret > 0) {
  159. $ret = addDocumentModel($value, $type, $label, $scandir);
  160. }
  161. }
  162. if ($action == 'setmod') {
  163. // TODO Verifier si module numerotation choisi peut etre active
  164. // par appel methode canBeActivated
  165. dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
  166. }
  167. /*
  168. * View
  169. */
  170. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  171. llxHeader("", "");
  172. $form = new Form($db);
  173. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  174. print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
  175. print '<br>';
  176. $head = expedition_admin_prepare_head();
  177. print dol_get_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'shipment');
  178. print '<br>';
  179. print '<div class="inline-block valignmiddle">'.$langs->trans("DeliveriesOrderAbility").'</div>';
  180. if (!getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
  181. print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=activate_delivery&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  182. } else {
  183. print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=disable_delivery&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
  184. }
  185. print '<br><span class="opacitymedium">'.info_admin($langs->trans("NoNeedForDeliveryReceipts"), 0, 1).'</span>';
  186. print '<br>';
  187. print '<br>';
  188. if (getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
  189. // Delivery numbering model
  190. print load_fiche_titre($langs->trans("DeliveryOrderNumberingModules"), '', '');
  191. print '<table class="noborder centpercent">';
  192. print '<tr class="liste_titre">';
  193. print '<td width="100">'.$langs->trans("Name").'</td>';
  194. print '<td>'.$langs->trans("Description").'</td>';
  195. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  196. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  197. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  198. print '</tr>'."\n";
  199. clearstatcache();
  200. foreach ($dirmodels as $reldir) {
  201. $dir = dol_buildpath($reldir."core/modules/delivery/");
  202. if (is_dir($dir)) {
  203. $handle = opendir($dir);
  204. if (is_resource($handle)) {
  205. while (($file = readdir($handle)) !== false) {
  206. if (preg_match('/^mod_delivery_([a-z0-9_]*)\.php$/', $file)) {
  207. $file = substr($file, 0, dol_strlen($file) - 4);
  208. require_once $dir.$file.'.php';
  209. $module = new $file();
  210. if ($module->isEnabled()) {
  211. // Show modules according to features level
  212. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  213. continue;
  214. }
  215. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  216. continue;
  217. }
  218. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  219. print $module->info($langs);
  220. print '</td>';
  221. // Show example of numbering module
  222. print '<td class="nowrap">';
  223. $tmp = $module->getExample();
  224. if (preg_match('/^Error/', $tmp)) {
  225. $langs->load("errors");
  226. print '<div class="error">'.$langs->trans($tmp).'</div>';
  227. } elseif ($tmp == 'NotConfigured') {
  228. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  229. } else {
  230. print $tmp;
  231. }
  232. print '</td>'."\n";
  233. print '<td class="center">';
  234. if ($conf->global->DELIVERY_ADDON_NUMBER == "$file") {
  235. print img_picto($langs->trans("Activated"), 'switch_on');
  236. } else {
  237. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  238. }
  239. print '</td>';
  240. $delivery = new Delivery($db);
  241. $delivery->initAsSpecimen();
  242. // Info
  243. $htmltooltip = '';
  244. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  245. $nextval = $module->getNextValue($mysoc, $delivery);
  246. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  247. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  248. if ($nextval) {
  249. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  250. $nextval = $langs->trans($nextval);
  251. }
  252. $htmltooltip .= $nextval.'<br>';
  253. } else {
  254. $htmltooltip .= $langs->trans($module->error).'<br>';
  255. }
  256. }
  257. print '<td class="center">';
  258. print $form->textwithpicto('', $htmltooltip, 1, 0);
  259. print '</td>';
  260. print '</tr>';
  261. }
  262. }
  263. }
  264. closedir($handle);
  265. }
  266. }
  267. }
  268. print '</table>';
  269. /*
  270. * Documents Models for delivery
  271. */
  272. print '<br>';
  273. print load_fiche_titre($langs->trans("DeliveryOrderModel"), '', '');
  274. // Defini tableau def de modele
  275. $type = "delivery";
  276. $def = array();
  277. $sql = "SELECT nom";
  278. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  279. $sql .= " WHERE type = '".$db->escape($type)."'";
  280. $sql .= " AND entity = ".$conf->entity;
  281. $resql = $db->query($sql);
  282. if ($resql) {
  283. $i = 0;
  284. $num_rows = $db->num_rows($resql);
  285. while ($i < $num_rows) {
  286. $array = $db->fetch_array($resql);
  287. array_push($def, $array[0]);
  288. $i++;
  289. }
  290. } else {
  291. dol_print_error($db);
  292. }
  293. print '<table class="noborder centpercent">';
  294. print '<tr class="liste_titre">';
  295. print '<td width="140">'.$langs->trans("Name").'</td>';
  296. print '<td>'.$langs->trans("Description").'</td>';
  297. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  298. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  299. print '<td align="center" width="32">'.$langs->trans("ShortInfo").'</td>';
  300. print '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
  301. print "</tr>\n";
  302. clearstatcache();
  303. foreach ($dirmodels as $reldir) {
  304. $dir = dol_buildpath($reldir."core/modules/delivery/doc/");
  305. if (is_dir($dir)) {
  306. $handle = opendir($dir);
  307. if (is_resource($handle)) {
  308. while (($file = readdir($handle)) !== false) {
  309. $filelist[] = $file;
  310. }
  311. closedir($handle);
  312. arsort($filelist);
  313. foreach ($filelist as $file) {
  314. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  315. if (file_exists($dir.'/'.$file)) {
  316. $name = substr($file, 4, dol_strlen($file) - 16);
  317. $classname = substr($file, 0, dol_strlen($file) - 12);
  318. require_once $dir.'/'.$file;
  319. $module = new $classname($db);
  320. $modulequalified = 1;
  321. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  322. $modulequalified = 0;
  323. }
  324. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  325. $modulequalified = 0;
  326. }
  327. if ($modulequalified) {
  328. print '<tr class="oddeven"><td width="100">';
  329. print(empty($module->name) ? $name : $module->name);
  330. print "</td><td>\n";
  331. if (method_exists($module, 'info')) {
  332. print $module->info($langs);
  333. } else {
  334. print $module->description;
  335. }
  336. print '</td>';
  337. // Active
  338. if (in_array($name, $def)) {
  339. print "<td align=\"center\">\n";
  340. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
  341. print img_picto($langs->trans("Enabled"), 'switch_on');
  342. print '</a>';
  343. print "</td>";
  344. } else {
  345. print "<td align=\"center\">\n";
  346. print '<a 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>';
  347. print "</td>";
  348. }
  349. // Default
  350. print "<td align=\"center\">";
  351. if (getDolGlobalString('DELIVERY_ADDON_PDF') == "$name") {
  352. print img_picto($langs->trans("Default"), 'on');
  353. } else {
  354. print '<a 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>';
  355. }
  356. print '</td>';
  357. // Info
  358. $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  359. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  360. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").'</u>:';
  361. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  362. print '<td class="center">';
  363. print $form->textwithpicto('', $htmltooltip, 1, 0);
  364. print '</td>';
  365. // Preview
  366. print '<td class="center">';
  367. if ($module->type == 'pdf') {
  368. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  369. } else {
  370. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  371. }
  372. print '</td>';
  373. print '</tr>';
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. print '</table>';
  382. // Other Options
  383. print "<br>";
  384. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  385. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  386. print '<input type="hidden" name="token" value="'.newToken().'">';
  387. print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
  388. print '<table class="noborder centpercent">';
  389. print '<tr class="liste_titre">';
  390. print '<td>'.$langs->trans("Parameter").'</td>';
  391. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  392. print '<td width="80">&nbsp;</td>';
  393. print "</tr>\n";
  394. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  395. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  396. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  397. foreach ($substitutionarray as $key => $val) {
  398. $htmltext .= $key.'<br>';
  399. }
  400. $htmltext .= '</i>';
  401. print '<tr class="oddeven"><td colspan="2">';
  402. print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  403. $variablename = 'DELIVERY_FREE_TEXT';
  404. if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
  405. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  406. } else {
  407. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  408. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  409. print $doleditor->Create();
  410. }
  411. print '</td><td class="right">';
  412. print "</td></tr>\n";
  413. print '</table>';
  414. print '<div class="center">';
  415. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  416. print '</div>';
  417. print '</form>';
  418. }
  419. // End of page
  420. llxFooter();
  421. $db->close();