livraison.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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-2011 Regis Houssin <regis@dolibarr.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/livraison.php
  24. * \ingroup livraison
  25. * \brief Page d'administration/configuration du module Livraison
  26. */
  27. require("../main.inc.php");
  28. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/livraison/class/livraison.class.php");
  30. $langs->load("admin");
  31. $langs->load("bills");
  32. $langs->load("other");
  33. $langs->load("sendings");
  34. $langs->load("deliveries");
  35. if (!$user->admin) accessforbidden();
  36. /*
  37. * Actions
  38. */
  39. if ($_POST["action"] == 'updateMask')
  40. {
  41. $maskconstdelivery=$_POST['maskconstdelivery'];
  42. $maskdelivery=$_POST['maskdelivery'];
  43. if ($maskconstdelivery) dolibarr_set_const($db,$maskconstdelivery,$maskdelivery,'chaine',0,'',$conf->entity);
  44. }
  45. if ($_GET["action"] == 'specimen')
  46. {
  47. $modele=$_GET["module"];
  48. $sending = new Livraison($db);
  49. $sending->initAsSpecimen();
  50. //$sending->fetch_commande();
  51. // Charge le modele
  52. $dir = DOL_DOCUMENT_ROOT . "/includes/modules/livraison/pdf/";
  53. $file = "pdf_".$modele.".modules.php";
  54. if (file_exists($dir.$file))
  55. {
  56. $classname = "pdf_".$modele;
  57. require_once($dir.$file);
  58. $obj = new $classname($db);
  59. if ($obj->write_file($sending,$langs) > 0)
  60. {
  61. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf");
  62. return;
  63. }
  64. else
  65. {
  66. $mesg='<div class="error">'.$obj->error.'</div>';
  67. dol_syslog($obj->error, LOG_ERR);
  68. }
  69. }
  70. else
  71. {
  72. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  73. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  74. }
  75. }
  76. if ($_GET["action"] == 'set')
  77. {
  78. $type='delivery';
  79. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  80. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  81. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  82. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  83. $sql.= ")";
  84. if ($db->query($sql))
  85. {
  86. }
  87. }
  88. if ($_GET["action"] == 'del')
  89. {
  90. $type='delivery';
  91. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  92. $sql.= " WHERE nom = '".$_GET["value"]."'";
  93. $sql.= " AND type = '".$type."'";
  94. $sql.= " AND entity = ".$conf->entity;
  95. if ($db->query($sql))
  96. {
  97. }
  98. }
  99. if ($_GET["action"] == 'setdoc')
  100. {
  101. $db->begin();
  102. if (dolibarr_set_const($db, "LIVRAISON_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity))
  103. {
  104. $conf->global->LIVRAISON_ADDON_PDF = $_GET["value"];
  105. }
  106. // On active le modele
  107. $type='delivery';
  108. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  109. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'";
  110. $sql_del.= " AND type = '".$type."'";
  111. $sql_del.= " AND entity = ".$conf->entity;
  112. $result1=$db->query($sql_del);
  113. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  114. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  115. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  116. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  117. $sql.= ")";
  118. $result2=$db->query($sql);
  119. if ($result1 && $result2)
  120. {
  121. $db->commit();
  122. }
  123. else
  124. {
  125. $db->rollback();
  126. }
  127. }
  128. if ($_POST["action"] == 'set_DELIVERY_FREE_TEXT')
  129. {
  130. dolibarr_set_const($db, "DELIVERY_FREE_TEXT",$_POST["DELIVERY_FREE_TEXT"],'chaine',0,'',$conf->entity);
  131. }
  132. if ($_GET["action"] == 'setmod')
  133. {
  134. // TODO Verifier si module numerotation choisi peut etre active
  135. // par appel methode canBeActivated
  136. dolibarr_set_const($db, "LIVRAISON_ADDON",$_GET["value"],'chaine',0,'',$conf->entity);
  137. }
  138. /*
  139. * View
  140. */
  141. $html=new Form($db);
  142. llxHeader("","");
  143. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  144. print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup');
  145. print '<br>';
  146. $h = 0;
  147. $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
  148. $head[$h][1] = $langs->trans("Setup");
  149. $h++;
  150. if ($conf->global->MAIN_SUBMODULE_EXPEDITION)
  151. {
  152. $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
  153. $head[$h][1] = $langs->trans("Sending");
  154. $h++;
  155. }
  156. $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
  157. $head[$h][1] = $langs->trans("Receivings");
  158. $hselected=$h;
  159. $h++;
  160. dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
  161. /*
  162. * Module numerotation
  163. */
  164. print_titre($langs->trans("DeliveryOrderNumberingModules"));
  165. print '<table class="noborder" width="100%">';
  166. print '<tr class="liste_titre">';
  167. print '<td width="100">'.$langs->trans("Name").'</td>';
  168. print '<td>'.$langs->trans("Description").'</td>';
  169. print '<td nowrap>'.$langs->trans("Example").'</td>';
  170. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  171. print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
  172. print '</tr>'."\n";
  173. clearstatcache();
  174. foreach ($conf->file->dol_document_root as $dirroot)
  175. {
  176. $dir = $dirroot . "/includes/modules/livraison/";
  177. if (is_dir($dir))
  178. {
  179. $handle = opendir($dir);
  180. if (is_resource($handle))
  181. {
  182. $var=true;
  183. while (($file = readdir($handle))!==false)
  184. {
  185. if (substr($file, 0, 14) == 'mod_livraison_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  186. {
  187. $file = substr($file, 0, dol_strlen($file)-4);
  188. require_once(DOL_DOCUMENT_ROOT ."/includes/modules/livraison/".$file.".php");
  189. $module = new $file;
  190. // Show modules according to features level
  191. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  192. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  193. if ($module->isEnabled())
  194. {
  195. $var=!$var;
  196. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  197. print $module->info();
  198. print '</td>';
  199. // Show example of numbering module
  200. print '<td nowrap="nowrap">';
  201. $tmp=$module->getExample();
  202. if (preg_match('/^Error/',$tmp)) print $langs->trans($tmp);
  203. else print $tmp;
  204. print '</td>'."\n";
  205. print '<td align="center">';
  206. if ($conf->global->LIVRAISON_ADDON == "$file")
  207. {
  208. print img_picto($langs->trans("Activated"),'on');
  209. }
  210. else
  211. {
  212. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  213. }
  214. print '</td>';
  215. $livraison=new Livraison($db);
  216. $livraison->initAsSpecimen();
  217. // Info
  218. $htmltooltip='';
  219. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  220. $facture->type=0;
  221. $nextval=$module->getNextValue($mysoc,$livraison);
  222. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  223. {
  224. $htmltooltip.=''.$langs->trans("NextValue").': ';
  225. if ($nextval)
  226. {
  227. $htmltooltip.=$nextval.'<br>';
  228. }
  229. else
  230. {
  231. $htmltooltip.=$langs->trans($module->error).'<br>';
  232. }
  233. }
  234. print '<td align="center">';
  235. print $html->textwithpicto('',$htmltooltip,1,0);
  236. print '</td>';
  237. print '</tr>';
  238. }
  239. }
  240. }
  241. closedir($handle);
  242. }
  243. }
  244. }
  245. print '</table>';
  246. /*
  247. * Modeles de documents
  248. */
  249. print '<br>';
  250. print_titre($langs->trans("DeliveryOrderModel"));
  251. // Defini tableau def de modele invoice
  252. $type="delivery";
  253. $def = array();
  254. $sql = "SELECT nom";
  255. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  256. $sql.= " WHERE type = '".$type."'";
  257. $sql.= " AND entity = ".$conf->entity;
  258. $resql=$db->query($sql);
  259. if ($resql)
  260. {
  261. $i = 0;
  262. $num_rows=$db->num_rows($resql);
  263. while ($i < $num_rows)
  264. {
  265. $array = $db->fetch_array($resql);
  266. array_push($def, $array[0]);
  267. $i++;
  268. }
  269. }
  270. else
  271. {
  272. dol_print_error($db);
  273. }
  274. print '<table class="noborder" width="100%">';
  275. print '<tr class="liste_titre">';
  276. print '<td width="140">'.$langs->trans("Name").'</td>';
  277. print '<td>'.$langs->trans("Description").'</td>';
  278. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  279. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  280. print '<td align="center" width="32" colspan="2">'.$langs->trans("Infos").'</td>';
  281. print "</tr>\n";
  282. clearstatcache();
  283. foreach ($conf->file->dol_document_root as $dirroot)
  284. {
  285. $dir = $dirroot . "/includes/modules/livraison/pdf/";
  286. if (is_dir($dir))
  287. {
  288. $handle = opendir($dir);
  289. if (is_resource($handle))
  290. {
  291. while (($file = readdir($handle))!==false)
  292. {
  293. if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_')
  294. {
  295. $name = substr($file, 4, dol_strlen($file) - 16);
  296. $classname = substr($file, 0, dol_strlen($file) - 12);
  297. $var=!$var;
  298. print "<tr $bc[$var]><td>";
  299. print $name;
  300. print "</td><td>\n";
  301. require_once($dir.$file);
  302. $module = new $classname($db);
  303. print $module->description;
  304. print '</td>';
  305. // Activ
  306. if (in_array($name, $def))
  307. {
  308. print "<td align=\"center\">\n";
  309. if ($conf->global->LIVRAISON_ADDON_PDF != "$name")
  310. {
  311. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  312. print img_picto($langs->trans("Enabled"),'on');
  313. print '</a>';
  314. }
  315. else
  316. {
  317. print img_picto($langs->trans("Enabled"),'on');
  318. }
  319. print "</td>";
  320. }
  321. else
  322. {
  323. print "<td align=\"center\">\n";
  324. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  325. print "</td>";
  326. }
  327. // Defaut
  328. print "<td align=\"center\">";
  329. if ($conf->global->LIVRAISON_ADDON_PDF == "$name")
  330. {
  331. print img_picto($langs->trans("Default"),'on');
  332. }
  333. else
  334. {
  335. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  336. }
  337. print '</td>';
  338. // Info
  339. $htmltooltip = ''.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  340. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  341. $htmltooltip.='<br><br>'.$langs->trans("FeaturesSupported").':';
  342. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  343. print '<td align="center">';
  344. print $html->textwithpicto('',$htmltooltip,1,0);
  345. print '</td>';
  346. print '<td align="center">';
  347. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'sending').'</a>';
  348. print '</td>';
  349. print '</tr>';
  350. }
  351. }
  352. closedir($handle);
  353. }
  354. }
  355. }
  356. print '</table>';
  357. /*
  358. *
  359. *
  360. */
  361. print "<br>";
  362. print_titre($langs->trans("OtherOptions"));
  363. print '<table class="noborder" width="100%">';
  364. print '<tr class="liste_titre">';
  365. print '<td>'.$langs->trans("Parameter").'</td>';
  366. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  367. print '<td width="80">&nbsp;</td>';
  368. print "</tr>\n";
  369. $var=true;
  370. $var=! $var;
  371. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  372. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  373. print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
  374. print '<tr '.$bc[$var].'><td colspan="2">';
  375. print $langs->trans("FreeLegalTextOnDeliveryReceipts").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  376. print '<textarea name="DELIVERY_FREE_TEXT" class="flat" cols="120">'.$conf->global->DELIVERY_FREE_TEXT.'</textarea>';
  377. print '</td><td align="right">';
  378. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  379. print "</td></tr>\n";
  380. print '</form>';
  381. print '</table>';
  382. $db->close();
  383. llxFooter();
  384. ?>