PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/expedition.php

https://github.com/asterix14/dolibarr
PHP | 615 lines | 445 code | 103 blank | 67 comment | 88 complexity | 3a09b2e8fc75bcceee87e0026cf50268 MD5 | raw file
Possible License(s): LGPL-2.0
  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."/core/lib/admin.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php');
  31. $langs->load("admin");
  32. $langs->load("sendings");
  33. $langs->load("deliveries");
  34. if (!$user->admin) accessforbidden();
  35. $action=GETPOST("action");
  36. $value=GETPOST("value");
  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 ($action == 'specimen')
  45. {
  46. $modele=GETPOST("module");
  47. $exp = new Expedition($db);
  48. $exp->initAsSpecimen();
  49. //$exp->fetch_commande();
  50. // Charge le modele
  51. $dir = DOL_DOCUMENT_ROOT . "/core/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='<font class="error">'.$obj->error.'</font>';
  66. dol_syslog($obj->error, LOG_ERR);
  67. }
  68. }
  69. else
  70. {
  71. $mesg='<font class="error">'.$langs->trans("ErrorModuleNotFound").'</font>';
  72. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  73. }
  74. }
  75. // Activate a model
  76. if ($action == 'set')
  77. {
  78. $label = GETPOST("label");
  79. $scandir = GETPOST("scandir");
  80. $type='shipping';
  81. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  82. $sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
  83. $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
  84. $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
  85. $sql.= ")";
  86. if ($db->query($sql))
  87. {
  88. }
  89. }
  90. if ($action == 'del')
  91. {
  92. $type='shipping';
  93. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  94. $sql.= " WHERE nom = '".$db->escape($value)."'";
  95. $sql.= " AND type = '".$type."'";
  96. $sql.= " AND entity = ".$conf->entity;
  97. if ($db->query($sql))
  98. {
  99. if ($conf->global->EXPEDITION_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF',$conf->entity);
  100. }
  101. }
  102. // Set default model
  103. if ($action == 'setdoc')
  104. {
  105. $label = GETPOST("label");
  106. $scandir = GETPOST("scandir");
  107. $db->begin();
  108. if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  109. {
  110. $conf->global->EXPEDITION_ADDON_PDF = $value;
  111. }
  112. // On active le modele
  113. $type='shipping';
  114. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  115. $sql_del.= " WHERE nom = '".$db->escape($value)."'";
  116. $sql_del.= " AND type = '".$type."'";
  117. $sql_del.= " AND entity = ".$conf->entity;
  118. $result1=$db->query($sql_del);
  119. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  120. $sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", ";
  121. $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
  122. $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
  123. $sql.= ")";
  124. $result2=$db->query($sql);
  125. if ($result1 && $result2)
  126. {
  127. $db->commit();
  128. }
  129. else
  130. {
  131. $db->rollback();
  132. }
  133. }
  134. // TODO A quoi servent les methode d'expedition ?
  135. if ($action == 'setmethod' || $action== 'setmod')
  136. {
  137. $module=GETPOST("module");
  138. $moduleid=GETPOST("moduleid");
  139. $statut=GETPOST("statut");
  140. require_once(DOL_DOCUMENT_ROOT."/core/modules/expedition/methode_expedition_$module.modules.php");
  141. $classname = "methode_expedition_$module";
  142. $expem = new $classname($db);
  143. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_shipment_mode";
  144. $sql.= " WHERE rowid = ".$moduleid;
  145. $resql = $db->query($sql);
  146. if ($resql && ($statut == 1 || $action == 'setmod'))
  147. {
  148. $db->begin();
  149. $sqlu = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode";
  150. $sqlu.= " SET statut=1";
  151. $sqlu.= " WHERE rowid=".$moduleid;
  152. $result=$db->query($sqlu);
  153. if ($result)
  154. {
  155. $db->commit();
  156. }
  157. else
  158. {
  159. $db->rollback();
  160. }
  161. }
  162. if ($statut == 1 || $action == 'setmod')
  163. {
  164. $db->begin();
  165. $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (rowid,code,libelle,description,statut)";
  166. $sql.= " VALUES (".$moduleid.",'".$expem->code."','".$expem->name."','".$expem->description."',1)";
  167. $result=$db->query($sql);
  168. if ($result)
  169. {
  170. $db->commit();
  171. }
  172. else
  173. {
  174. //dol_print_error($db);
  175. $db->rollback();
  176. }
  177. }
  178. else if ($statut == 0)
  179. {
  180. $db->begin();
  181. $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode";
  182. $sql.= " SET statut=0";
  183. $sql.= " WHERE rowid=".$moduleid;
  184. $result=$db->query($sql);
  185. if ($result)
  186. {
  187. $db->commit();
  188. }
  189. else
  190. {
  191. $db->rollback();
  192. }
  193. }
  194. }
  195. if ($action == 'setmod')
  196. {
  197. // TODO Verifier si module numerotation choisi peut etre active
  198. // par appel methode canBeActivated
  199. $module=GETPOST("module");
  200. dolibarr_set_const($db, "EXPEDITION_ADDON",$module,'chaine',0,'',$conf->entity);
  201. }
  202. if ($action == 'updateMask')
  203. {
  204. $maskconst=GETPOST("maskconstexpedition");
  205. $maskvalue=GETPOST("maskexpedition");
  206. if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
  207. if (! $res > 0) $error++;
  208. if (! $error)
  209. {
  210. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  211. }
  212. else
  213. {
  214. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  215. }
  216. }
  217. if ($action == 'setmodel')
  218. {
  219. dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
  220. }
  221. if ($action == 'set_SHIPPING_DRAFT_WATERMARK')
  222. {
  223. $draft=GETPOST("SHIPPING_DRAFT_WATERMARK");
  224. $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
  225. if (! $res > 0) $error++;
  226. if (! $error)
  227. {
  228. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  229. }
  230. else
  231. {
  232. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  233. }
  234. }
  235. if ($action == 'set_SHIPPING_FREE_TEXT')
  236. {
  237. $free=GETPOST("SHIPPING_FREE_TEXT");
  238. $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$free,'chaine',0,'',$conf->entity);
  239. if (! $res > 0) $error++;
  240. if (! $error)
  241. {
  242. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  243. }
  244. else
  245. {
  246. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  247. }
  248. }
  249. /*
  250. * View
  251. */
  252. $form=new Form($db);
  253. llxHeader("","");
  254. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  255. print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup');
  256. print '<br>';
  257. //if ($mesg) print $mesg.'<br>';
  258. $h = 0;
  259. $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
  260. $head[$h][1] = $langs->trans("Setup");
  261. $h++;
  262. $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
  263. $head[$h][1] = $langs->trans("Sending");
  264. $hselected=$h;
  265. $h++;
  266. if ($conf->global->MAIN_SUBMODULE_LIVRAISON)
  267. {
  268. $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
  269. $head[$h][1] = $langs->trans("Receivings");
  270. $h++;
  271. }
  272. dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
  273. /*
  274. * Numbering module
  275. */
  276. //print "<br>";
  277. print_titre($langs->trans("SendingsNumberingModules"));
  278. print '<table class="noborder" width="100%">';
  279. print '<tr class="liste_titre">';
  280. print '<td width="100">'.$langs->trans("Name").'</td>';
  281. print '<td>'.$langs->trans("Description").'</td>';
  282. print '<td>'.$langs->trans("Example").'</td>';
  283. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  284. print '<td align="center" width="80">'.$langs->trans("Infos").'</td>';
  285. print "</tr>\n";
  286. clearstatcache();
  287. foreach ($conf->file->dol_document_root as $dirroot)
  288. {
  289. $dir = $dirroot . "/core/modules/expedition/";
  290. if (is_dir($dir))
  291. {
  292. $handle = opendir($dir);
  293. if (is_resource($handle))
  294. {
  295. $var=true;
  296. while (($file = readdir($handle))!==false)
  297. {
  298. if (substr($file, 0, 15) == 'mod_expedition_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  299. {
  300. $file = substr($file, 0, dol_strlen($file)-4);
  301. require_once(DOL_DOCUMENT_ROOT ."/core/modules/expedition/".$file.".php");
  302. $module = new $file;
  303. // Show modules according to features level
  304. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  305. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  306. if ($module->isEnabled())
  307. {
  308. $var=!$var;
  309. print '<tr '.$bc[$var].'><td>'.$module->nom."</td>\n";
  310. print '<td>';
  311. print $module->info();
  312. print '</td>';
  313. // Show example of numbering module
  314. print '<td nowrap="nowrap">';
  315. $tmp=$module->getExample();
  316. if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
  317. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  318. else print $tmp;
  319. print '</td>'."\n";
  320. print '<td align="center">';
  321. if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file")
  322. {
  323. print img_picto($langs->trans("Activated"),'switch_on');
  324. }
  325. else
  326. {
  327. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;value='.$file.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  328. print img_picto($langs->trans("Disabled"),'switch_off');
  329. print '</a>';
  330. }
  331. print '</td>';
  332. $expedition=new Expedition($db);
  333. $expedition->initAsSpecimen();
  334. // Info
  335. $htmltooltip='';
  336. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  337. $facture->type=0;
  338. $nextval=$module->getNextValue($mysoc,$expedition);
  339. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  340. {
  341. $htmltooltip.=''.$langs->trans("NextValue").': ';
  342. if ($nextval)
  343. {
  344. $htmltooltip.=$nextval.'<br>';
  345. }
  346. else
  347. {
  348. $htmltooltip.=$langs->trans($module->error).'<br>';
  349. }
  350. }
  351. print '<td align="center">';
  352. print $form->textwithpicto('',$htmltooltip,1,0);
  353. print '</td>';
  354. print '</tr>';
  355. }
  356. }
  357. }
  358. closedir($handle);
  359. }
  360. }
  361. }
  362. print '</table><br>';
  363. /*
  364. * Modeles de documents
  365. */
  366. print_titre($langs->trans("SendingsReceiptModel"));
  367. // Defini tableau def de modele invoice
  368. $type="shipping";
  369. $def = array();
  370. $sql = "SELECT nom";
  371. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  372. $sql.= " WHERE type = '".$type."'";
  373. $sql.= " AND entity = ".$conf->entity;
  374. $resql=$db->query($sql);
  375. if ($resql)
  376. {
  377. $i = 0;
  378. $num_rows=$db->num_rows($resql);
  379. while ($i < $num_rows)
  380. {
  381. $array = $db->fetch_array($resql);
  382. array_push($def, $array[0]);
  383. $i++;
  384. }
  385. }
  386. else
  387. {
  388. dol_print_error($db);
  389. }
  390. print '<table class="noborder" width="100%">';
  391. print '<tr class="liste_titre">';
  392. print '<td width="140">'.$langs->trans("Name").'</td>';
  393. print '<td>'.$langs->trans("Description").'</td>';
  394. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  395. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  396. print '<td align="center" width="80" nowrap="nowrap">'.$langs->trans("Infos").'</td>';
  397. print "</tr>\n";
  398. clearstatcache();
  399. foreach ($conf->file->dol_document_root as $dirroot)
  400. {
  401. $dir = $dirroot . "/core/modules/expedition/pdf/";
  402. if (is_dir($dir))
  403. {
  404. $handle=opendir($dir);
  405. $var=true;
  406. if (is_resource($handle))
  407. {
  408. while (($file = readdir($handle))!==false)
  409. {
  410. if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,15) == 'pdf_expedition_')
  411. {
  412. $name = substr($file, 15, dol_strlen($file) - 27);
  413. $classname = substr($file, 0, dol_strlen($file) - 12);
  414. $var=!$var;
  415. print "<tr $bc[$var]><td>";
  416. print $name;
  417. print "</td><td>\n";
  418. require_once($dir.$file);
  419. $module = new $classname();
  420. print $module->description;
  421. print '</td>';
  422. // Active
  423. if (in_array($name, $def))
  424. {
  425. print "<td align=\"center\">\n";
  426. //if ($conf->global->EXPEDITION_ADDON_PDF != $name)
  427. //{
  428. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'">';
  429. print img_picto($langs->trans("Activated"),'switch_on');
  430. print '</a>';
  431. //}
  432. //else
  433. //{
  434. // print img_picto($langs->trans("Activated"),'switch_on');
  435. //}
  436. print "</td>";
  437. }
  438. else
  439. {
  440. print "<td align=\"center\">\n";
  441. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  442. print "</td>";
  443. }
  444. // Default
  445. print "<td align=\"center\">";
  446. if ($conf->global->EXPEDITION_ADDON_PDF == $name)
  447. {
  448. print img_picto($langs->trans("Default"),'on');
  449. }
  450. else
  451. {
  452. 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>';
  453. }
  454. print '</td>';
  455. // Info
  456. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  457. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  458. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  459. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  460. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  461. print '<td align="center">';
  462. $link='<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>';
  463. print $form->textwithpicto(' &nbsp; &nbsp; '.$link,$htmltooltip,-1,0);
  464. print '</td>';
  465. print '</tr>';
  466. }
  467. }
  468. closedir($handle);
  469. }
  470. }
  471. }
  472. print '</table>';
  473. print '<br>';
  474. /*
  475. * Other options
  476. *
  477. */
  478. print_titre($langs->trans("OtherOptions"));
  479. $var=true;
  480. print "<table class=\"noborder\" width=\"100%\">";
  481. print "<tr class=\"liste_titre\">";
  482. print "<td>".$langs->trans("Parameter")."</td>\n";
  483. print '<td width="60" align="center">'.$langs->trans("Value")."</td>\n";
  484. print "<td>&nbsp;</td>\n";
  485. print "</tr>";
  486. $var=! $var;
  487. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  488. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  489. print '<input type="hidden" name="action" value="set_SHIPPING_FREE_TEXT">';
  490. print '<tr '.$bc[$var].'><td colspan="2">';
  491. print $langs->trans("FreeLegalTextOnShippings").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  492. print '<textarea name="SHIPPING_FREE_TEXT" class="flat" cols="120">'.$conf->global->SHIPPING_FREE_TEXT.'</textarea>';
  493. print '</td><td align="right">';
  494. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  495. print "</td></tr>\n";
  496. print '</form>';
  497. $var=!$var;
  498. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  499. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  500. print '<input type="hidden" name="action" value="set_SHIPPING_DRAFT_WATERMARK">';
  501. print '<tr '.$bc[$var].'><td colspan="2">';
  502. print $langs->trans("WatermarkOnDraft").'<br>';
  503. print '<input size="50" class="flat" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.$conf->global->SHIPPING_DRAFT_WATERMARK.'">';
  504. print '</td><td align="right">';
  505. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  506. print "</td></tr>\n";
  507. print '</form>';
  508. print '</table>';
  509. dol_htmloutput_mesg($mesg);
  510. $db->close();
  511. llxFooter();
  512. ?>