expedition.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <?php
  2. /* Copyright (C) 2003-2008 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. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/admin/expedition.php
  25. * \ingroup expedition
  26. * \brief Page d'administration/configuration du module Expedition
  27. */
  28. require("../main.inc.php");
  29. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php');
  31. $langs->load("admin");
  32. $langs->load("bills");
  33. $langs->load("other");
  34. $langs->load("sendings");
  35. $langs->load("deliveries");
  36. if (!$user->admin) accessforbidden();
  37. if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
  38. {
  39. $conf->global->EXPEDITION_ADDON_NUMBER='mod_expedition_safor';
  40. }
  41. /*
  42. * Actions
  43. */
  44. if ($_GET["action"] == 'specimen')
  45. {
  46. $modele=$_GET["module"];
  47. $exp = new Expedition($db);
  48. $exp->initAsSpecimen();
  49. //$exp->fetch_commande();
  50. // Charge le modele
  51. $dir = DOL_DOCUMENT_ROOT . "/includes/modules/expedition/pdf/";
  52. $file = "pdf_expedition_".$modele.".modules.php";
  53. if (file_exists($dir.$file))
  54. {
  55. $classname = "pdf_expedition_".$modele;
  56. require_once($dir.$file);
  57. $obj = new $classname($db);
  58. if ($obj->write_file($exp,$langs) > 0)
  59. {
  60. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
  61. return;
  62. }
  63. else
  64. {
  65. $mesg='<div class="error">'.$obj->error.'</div>';
  66. dol_syslog($obj->error, LOG_ERR);
  67. }
  68. }
  69. else
  70. {
  71. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  72. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  73. }
  74. }
  75. // Activate a model
  76. if ($_GET["action"] == 'set')
  77. {
  78. $type='shipping';
  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='shipping';
  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. // Set default model
  100. if ($_GET["action"] == 'setdoc')
  101. {
  102. $db->begin();
  103. if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity))
  104. {
  105. $conf->global->EXPEDITION_ADDON_PDF = $_GET["value"];
  106. }
  107. // On active le modele
  108. $type='shipping';
  109. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  110. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'";
  111. $sql_del.= " AND type = '".$type."'";
  112. $sql_del.= " AND entity = ".$conf->entity;
  113. $result1=$db->query($sql_del);
  114. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  115. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  116. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  117. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  118. $sql.= ")";
  119. $result2=$db->query($sql);
  120. if ($result1 && $result2)
  121. {
  122. $db->commit();
  123. }
  124. else
  125. {
  126. $db->rollback();
  127. }
  128. }
  129. // TODO A quoi servent les methode d'expedition ?
  130. if ($_GET["action"] == 'setmethod' || $_GET["action"] == 'setmod')
  131. {
  132. $module=$_GET["module"];
  133. $moduleid=$_GET["moduleid"];
  134. $statut=$_GET["statut"];
  135. require_once(DOL_DOCUMENT_ROOT."/includes/modules/expedition/methode_expedition_$module.modules.php");
  136. $classname = "methode_expedition_$module";
  137. $expem = new $classname($db);
  138. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_shipment_mode";
  139. $sql.= " WHERE rowid = ".$moduleid;
  140. $resql = $db->query($sql);
  141. if ($resql && ($statut == 1 || $_GET["action"] == 'setmod'))
  142. {
  143. $db->begin();
  144. $sqlu = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode";
  145. $sqlu.= " SET statut=1";
  146. $sqlu.= " WHERE rowid=".$moduleid;
  147. $result=$db->query($sqlu);
  148. if ($result)
  149. {
  150. $db->commit();
  151. }
  152. else
  153. {
  154. $db->rollback();
  155. }
  156. }
  157. if ($statut == 1 || $_GET["action"] == 'setmod')
  158. {
  159. $db->begin();
  160. $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (rowid,code,libelle,description,statut)";
  161. $sql.= " VALUES (".$moduleid.",'".$expem->code."','".$expem->name."','".$expem->description."',1)";
  162. $result=$db->query($sql);
  163. if ($result)
  164. {
  165. $db->commit();
  166. }
  167. else
  168. {
  169. //dol_print_error($db);
  170. $db->rollback();
  171. }
  172. }
  173. else if ($statut == 0)
  174. {
  175. $db->begin();
  176. $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode";
  177. $sql.= " SET statut=0";
  178. $sql.= " WHERE rowid=".$moduleid;
  179. $result=$db->query($sql);
  180. if ($result)
  181. {
  182. $db->commit();
  183. }
  184. else
  185. {
  186. $db->rollback();
  187. }
  188. }
  189. }
  190. if ($_GET["action"] == 'setmod')
  191. {
  192. // TODO Verifier si module numerotation choisi peut etre active
  193. // par appel methode canBeActivated
  194. dolibarr_set_const($db, "EXPEDITION_ADDON",$_GET["module"],'chaine',0,'',$conf->entity);
  195. }
  196. if ($_POST["action"] == 'updateMask')
  197. {
  198. $maskconst=$_POST['maskconstexpedition'];
  199. $maskvalue=$_POST['maskexpedition'];
  200. if ($maskconst) dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
  201. }
  202. if ($_GET["action"] == 'setmodel')
  203. {
  204. dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$_GET["value"],'chaine',0,'',$conf->entity);
  205. }
  206. if ($_POST["action"] == 'set_SHIPPING_DRAFT_WATERMARK')
  207. {
  208. dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($_POST["SHIPPING_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity);
  209. }
  210. if ($_POST["action"] == 'set_SHIPPING_FREE_TEXT')
  211. {
  212. dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$_POST["SHIPPING_FREE_TEXT"],'chaine',0,'',$conf->entity);
  213. }
  214. /*
  215. * View
  216. */
  217. $html=new Form($db);
  218. llxHeader("","");
  219. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  220. print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup');
  221. print '<br>';
  222. if ($mesg) print $mesg.'<br>';
  223. $h = 0;
  224. $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
  225. $head[$h][1] = $langs->trans("Setup");
  226. $h++;
  227. $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
  228. $head[$h][1] = $langs->trans("Sending");
  229. $hselected=$h;
  230. $h++;
  231. if ($conf->global->MAIN_SUBMODULE_LIVRAISON)
  232. {
  233. $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
  234. $head[$h][1] = $langs->trans("Receivings");
  235. $h++;
  236. }
  237. dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
  238. /*
  239. * Numbering module
  240. */
  241. //print "<br>";
  242. print_titre($langs->trans("SendingsNumberingModules"));
  243. print '<table class="noborder" width="100%">';
  244. print '<tr class="liste_titre">';
  245. print '<td width="100">'.$langs->trans("Name").'</td>';
  246. print '<td>'.$langs->trans("Description").'</td>';
  247. print '<td>'.$langs->trans("Example").'</td>';
  248. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  249. print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
  250. print "</tr>\n";
  251. clearstatcache();
  252. foreach ($conf->file->dol_document_root as $dirroot)
  253. {
  254. $dir = $dirroot . "/includes/modules/expedition/";
  255. if (is_dir($dir))
  256. {
  257. $handle = opendir($dir);
  258. if (is_resource($handle))
  259. {
  260. $var=true;
  261. while (($file = readdir($handle))!==false)
  262. {
  263. if (substr($file, 0, 15) == 'mod_expedition_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  264. {
  265. $file = substr($file, 0, dol_strlen($file)-4);
  266. require_once(DOL_DOCUMENT_ROOT ."/includes/modules/expedition/".$file.".php");
  267. $module = new $file;
  268. // Show modules according to features level
  269. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  270. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  271. if ($module->isEnabled())
  272. {
  273. $var=!$var;
  274. print '<tr '.$bc[$var].'><td>'.$module->nom."</td>\n";
  275. print '<td>';
  276. print $module->info();
  277. print '</td>';
  278. // Show example of numbering module
  279. print '<td nowrap="nowrap">';
  280. $tmp=$module->getExample();
  281. if (preg_match('/^Error/',$tmp))
  282. {
  283. $langs->load('errors');
  284. print $langs->trans($tmp);
  285. }
  286. else print $tmp;
  287. print '</td>'."\n";
  288. print '<td align="center">';
  289. if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file")
  290. {
  291. print img_picto($langs->trans("Activated"),'on');
  292. }
  293. else
  294. {
  295. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;value='.$file.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  296. print img_picto($langs->trans("Disabled"),'off');
  297. print '</a>';
  298. }
  299. print '</td>';
  300. $expedition=new Expedition($db);
  301. $expedition->initAsSpecimen();
  302. // Info
  303. $htmltooltip='';
  304. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  305. $facture->type=0;
  306. $nextval=$module->getNextValue($mysoc,$expedition);
  307. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  308. {
  309. $htmltooltip.=''.$langs->trans("NextValue").': ';
  310. if ($nextval)
  311. {
  312. $htmltooltip.=$nextval.'<br>';
  313. }
  314. else
  315. {
  316. $htmltooltip.=$langs->trans($module->error).'<br>';
  317. }
  318. }
  319. print '<td align="center">';
  320. print $html->textwithpicto('',$htmltooltip,1,0);
  321. print '</td>';
  322. print '</tr>';
  323. }
  324. }
  325. }
  326. closedir($handle);
  327. }
  328. }
  329. }
  330. print '</table><br>';
  331. /*
  332. * Modeles de documents
  333. */
  334. print_titre($langs->trans("SendingsReceiptModel"));
  335. // Defini tableau def de modele invoice
  336. $type="shipping";
  337. $def = array();
  338. $sql = "SELECT nom";
  339. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  340. $sql.= " WHERE type = '".$type."'";
  341. $sql.= " AND entity = ".$conf->entity;
  342. $resql=$db->query($sql);
  343. if ($resql)
  344. {
  345. $i = 0;
  346. $num_rows=$db->num_rows($resql);
  347. while ($i < $num_rows)
  348. {
  349. $array = $db->fetch_array($resql);
  350. array_push($def, $array[0]);
  351. $i++;
  352. }
  353. }
  354. else
  355. {
  356. dol_print_error($db);
  357. }
  358. print '<table class="noborder" width="100%">';
  359. print '<tr class="liste_titre">';
  360. print '<td width="140">'.$langs->trans("Name").'</td>';
  361. print '<td>'.$langs->trans("Description").'</td>';
  362. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  363. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  364. print '<td align="center" width="32" colspan="2">'.$langs->trans("Infos").'</td>';
  365. print "</tr>\n";
  366. clearstatcache();
  367. foreach ($conf->file->dol_document_root as $dirroot)
  368. {
  369. $dir = $dirroot . "/includes/modules/expedition/pdf/";
  370. if (is_dir($dir))
  371. {
  372. $handle=opendir($dir);
  373. $var=true;
  374. if (is_resource($handle))
  375. {
  376. while (($file = readdir($handle))!==false)
  377. {
  378. if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,15) == 'pdf_expedition_')
  379. {
  380. $name = substr($file, 15, dol_strlen($file) - 27);
  381. $classname = substr($file, 0, dol_strlen($file) - 12);
  382. $var=!$var;
  383. print "<tr $bc[$var]><td>";
  384. print $name;
  385. print "</td><td>\n";
  386. require_once($dir.$file);
  387. $module = new $classname();
  388. print $module->description;
  389. print '</td>';
  390. // Active
  391. if (in_array($name, $def))
  392. {
  393. print "<td align=\"center\">\n";
  394. if ($conf->global->EXPEDITION_ADDON_PDF != $name)
  395. {
  396. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'">';
  397. print img_picto($langs->trans("Activated"),'on');
  398. print '</a>';
  399. }
  400. else
  401. {
  402. print img_picto($langs->trans("Activated"),'on');
  403. }
  404. print "</td>";
  405. }
  406. else
  407. {
  408. print "<td align=\"center\">\n";
  409. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  410. print "</td>";
  411. }
  412. // Default
  413. print "<td align=\"center\">";
  414. if ($conf->global->EXPEDITION_ADDON_PDF == $name)
  415. {
  416. print img_picto($langs->trans("Default"),'on');
  417. }
  418. else
  419. {
  420. 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>';
  421. }
  422. print '</td>';
  423. // Info
  424. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  425. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  426. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  427. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  428. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  429. print '<td align="center">';
  430. print $html->textwithpicto('',$htmltooltip,1,0);
  431. print '</td>';
  432. print '<td align="center">';
  433. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_object($langs->trans("Preview"),'sending').'</a>';
  434. print '</td>';
  435. print '</tr>';
  436. }
  437. }
  438. closedir($handle);
  439. }
  440. }
  441. }
  442. print '</table>';
  443. print '<br>';
  444. /*
  445. * Other options
  446. *
  447. */
  448. print_titre($langs->trans("OtherOptions"));
  449. $var=true;
  450. print "<table class=\"noborder\" width=\"100%\">";
  451. print "<tr class=\"liste_titre\">";
  452. print "<td>".$langs->trans("Parameter")."</td>\n";
  453. print '<td width="60" align="center">'.$langs->trans("Value")."</td>\n";
  454. print "<td>&nbsp;</td>\n";
  455. print "</tr>";
  456. $var=! $var;
  457. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  458. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  459. print '<input type="hidden" name="action" value="set_SHIPPING_FREE_TEXT">';
  460. print '<tr '.$bc[$var].'><td colspan="2">';
  461. print $langs->trans("FreeLegalTextOnShippings").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  462. print '<textarea name="SHIPPING_FREE_TEXT" class="flat" cols="120">'.$conf->global->SHIPPING_FREE_TEXT.'</textarea>';
  463. print '</td><td align="right">';
  464. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  465. print "</td></tr>\n";
  466. print '</form>';
  467. $var=!$var;
  468. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  469. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  470. print '<input type="hidden" name="action" value="set_SHIPPING_DRAFT_WATERMARK">';
  471. print '<tr '.$bc[$var].'><td colspan="2">';
  472. print $langs->trans("WatermarkOnDraft").'<br>';
  473. print '<input size="50" class="flat" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.$conf->global->SHIPPING_DRAFT_WATERMARK.'">';
  474. print '</td><td align="right">';
  475. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  476. print "</td></tr>\n";
  477. print '</form>';
  478. print '</table>';
  479. $db->close();
  480. llxFooter();
  481. ?>