delivery.php 15 KB

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