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

/htdocs/admin/livraison.php

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