livraison.php 16 KB

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