livraison.php 16 KB

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