livraison.php 16 KB

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