expedition.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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-2012 Regis Houssin <regis.houssin@capnetworks.com>
  8. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/admin/expedition.php
  26. * \ingroup expedition
  27. * \brief Page d'administration/configuration du module Expedition
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  34. $langs->load("admin");
  35. $langs->load("sendings");
  36. $langs->load("deliveries");
  37. $langs->load('other');
  38. if (! $user->admin)
  39. accessforbidden();
  40. $action=GETPOST('action','alpha');
  41. $value=GETPOST('value','alpha');
  42. $label = GETPOST('label','alpha');
  43. $scandir = GETPOST('scandir','alpha');
  44. $type='shipping';
  45. if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
  46. {
  47. $conf->global->EXPEDITION_ADDON_NUMBER='mod_expedition_safor';
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'updateMask')
  53. {
  54. $maskconst=GETPOST('maskconstexpedition','alpha');
  55. $maskvalue=GETPOST('maskexpedition','alpha');
  56. if (! empty($maskconst))
  57. $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
  58. if (isset($res))
  59. {
  60. if ($res > 0)
  61. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  62. else
  63. setEventMessages($langs->trans("Error"), null, 'errors');
  64. }
  65. }
  66. else if ($action == 'set_param')
  67. {
  68. $freetext=GETPOST('SHIPPING_FREE_TEXT'); // No alpha here, we want exact string
  69. $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  70. if ($res <= 0)
  71. {
  72. $error++;
  73. setEventMessages($langs->trans("Error"), null, 'errors');
  74. }
  75. $draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha');
  76. $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
  77. if ($res <= 0)
  78. {
  79. $error++;
  80. setEventMessages($langs->trans("Error"), null, 'errors');
  81. }
  82. if (! $error)
  83. {
  84. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  85. }
  86. }
  87. else if ($action == 'specimen')
  88. {
  89. $modele=GETPOST('module','alpha');
  90. $exp = new Expedition($db);
  91. $exp->initAsSpecimen();
  92. // Search template files
  93. $file=''; $classname=''; $filefound=0;
  94. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  95. foreach($dirmodels as $reldir)
  96. {
  97. $file=dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php",0);
  98. if (file_exists($file))
  99. {
  100. $filefound=1;
  101. $classname = "pdf_".$modele;
  102. break;
  103. }
  104. }
  105. if ($filefound)
  106. {
  107. require_once $file;
  108. $module = new $classname($db);
  109. if ($module->write_file($exp,$langs) > 0)
  110. {
  111. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
  112. return;
  113. }
  114. else
  115. {
  116. setEventMessages($module->error, $module->errors, 'errors');
  117. dol_syslog($module->error, LOG_ERR);
  118. }
  119. }
  120. else
  121. {
  122. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  123. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  124. }
  125. }
  126. // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
  127. else if ($action == 'setModuleOptions')
  128. {
  129. $post_size=count($_POST);
  130. $db->begin();
  131. for($i=0;$i < $post_size;$i++)
  132. {
  133. if (array_key_exists('param'.$i,$_POST))
  134. {
  135. $param=GETPOST("param".$i,'alpha');
  136. $value=GETPOST("value".$i,'alpha');
  137. if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
  138. if (! $res > 0) $error++;
  139. }
  140. }
  141. if (! $error)
  142. {
  143. $db->commit();
  144. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  145. }
  146. else
  147. {
  148. $db->rollback();
  149. setEventMessages($langs->trans("Error"), null, 'errors');
  150. }
  151. }
  152. // Activate a model
  153. else if ($action == 'set')
  154. {
  155. $ret = addDocumentModel($value, $type, $label, $scandir);
  156. }
  157. else if ($action == 'del')
  158. {
  159. $ret = delDocumentModel($value, $type);
  160. if ($ret > 0)
  161. {
  162. if ($conf->global->EXPEDITION_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF',$conf->entity);
  163. }
  164. }
  165. // Set default model
  166. else if ($action == 'setdoc')
  167. {
  168. if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  169. {
  170. // La constante qui a ete lue en avant du nouveau set
  171. // on passe donc par une variable pour avoir un affichage coherent
  172. $conf->global->EXPEDITION_ADDON_PDF = $value;
  173. }
  174. // On active le modele
  175. $ret = delDocumentModel($value, $type);
  176. if ($ret > 0)
  177. {
  178. $ret = addDocumentModel($value, $type, $label, $scandir);
  179. }
  180. }
  181. else if ($action == 'setmodel')
  182. {
  183. dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
  184. }
  185. /*
  186. * View
  187. */
  188. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  189. $form=new Form($db);
  190. llxHeader("",$langs->trans("SendingsSetup"));
  191. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  192. print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
  193. print '<br>';
  194. $head = expedition_admin_prepare_head();
  195. dol_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'sending');
  196. // Shipment numbering model
  197. print load_fiche_titre($langs->trans("SendingsNumberingModules"));
  198. print '<table class="noborder" width="100%">';
  199. print '<tr class="liste_titre">';
  200. print '<td width="100">'.$langs->trans("Name").'</td>';
  201. print '<td>'.$langs->trans("Description").'</td>';
  202. print '<td>'.$langs->trans("Example").'</td>';
  203. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  204. print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  205. print "</tr>\n";
  206. clearstatcache();
  207. foreach ($dirmodels as $reldir)
  208. {
  209. $dir = dol_buildpath($reldir."core/modules/expedition/");
  210. if (is_dir($dir))
  211. {
  212. $handle = opendir($dir);
  213. if (is_resource($handle))
  214. {
  215. while (($file = readdir($handle))!==false)
  216. {
  217. if (substr($file, 0, 15) == 'mod_expedition_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  218. {
  219. $file = substr($file, 0, dol_strlen($file)-4);
  220. require_once $dir.$file.'.php';
  221. $module = new $file;
  222. if ($module->isEnabled())
  223. {
  224. // Show modules according to features level
  225. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  226. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  227. print '<tr><td>'.$module->nom."</td>\n";
  228. print '<td>';
  229. print $module->info();
  230. print '</td>';
  231. // Show example of numbering module
  232. print '<td class="nowrap">';
  233. $tmp=$module->getExample();
  234. if (preg_match('/^Error/',$tmp)) {
  235. $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
  236. }
  237. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  238. else print $tmp;
  239. print '</td>'."\n";
  240. print '<td align="center">';
  241. if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file")
  242. {
  243. print img_picto($langs->trans("Activated"),'switch_on');
  244. }
  245. else
  246. {
  247. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;value='.$file.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  248. print img_picto($langs->trans("Disabled"),'switch_off');
  249. print '</a>';
  250. }
  251. print '</td>';
  252. $expedition=new Expedition($db);
  253. $expedition->initAsSpecimen();
  254. // Info
  255. $htmltooltip='';
  256. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  257. $nextval=$module->getNextValue($mysoc,$expedition);
  258. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  259. $htmltooltip.=''.$langs->trans("NextValue").': ';
  260. if ($nextval) {
  261. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  262. $nextval = $langs->trans($nextval);
  263. $htmltooltip.=$nextval.'<br>';
  264. } else {
  265. $htmltooltip.=$langs->trans($module->error).'<br>';
  266. }
  267. }
  268. print '<td align="center">';
  269. print $form->textwithpicto('',$htmltooltip,1,0);
  270. print '</td>';
  271. print '</tr>';
  272. }
  273. }
  274. }
  275. closedir($handle);
  276. }
  277. }
  278. }
  279. print '</table><br>';
  280. /*
  281. * Documents models for Sendings Receipt
  282. */
  283. print load_fiche_titre($langs->trans("SendingsReceiptModel"));
  284. // Defini tableau def de modele invoice
  285. $type="shipping";
  286. $def = array();
  287. $sql = "SELECT nom";
  288. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  289. $sql.= " WHERE type = '".$type."'";
  290. $sql.= " AND entity = ".$conf->entity;
  291. $resql=$db->query($sql);
  292. if ($resql)
  293. {
  294. $i = 0;
  295. $num_rows=$db->num_rows($resql);
  296. while ($i < $num_rows)
  297. {
  298. $array = $db->fetch_array($resql);
  299. array_push($def, $array[0]);
  300. $i++;
  301. }
  302. }
  303. else
  304. {
  305. dol_print_error($db);
  306. }
  307. print '<table class="noborder" width="100%">';
  308. print '<tr class="liste_titre">';
  309. print '<td width="140">'.$langs->trans("Name").'</td>';
  310. print '<td>'.$langs->trans("Description").'</td>';
  311. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  312. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  313. print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>';
  314. print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>';
  315. print "</tr>\n";
  316. clearstatcache();
  317. foreach ($dirmodels as $reldir)
  318. {
  319. foreach (array('','/doc') as $valdir)
  320. {
  321. $dir = dol_buildpath($reldir."core/modules/expedition".$valdir);
  322. if (is_dir($dir))
  323. {
  324. $handle=opendir($dir);
  325. if (is_resource($handle))
  326. {
  327. while (($file = readdir($handle))!==false)
  328. {
  329. $filelist[]=$file;
  330. }
  331. closedir($handle);
  332. arsort($filelist);
  333. foreach($filelist as $file)
  334. {
  335. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  336. {
  337. if (file_exists($dir.'/'.$file))
  338. {
  339. $name = substr($file, 4, dol_strlen($file) -16);
  340. $classname = substr($file, 0, dol_strlen($file) -12);
  341. require_once $dir.'/'.$file;
  342. $module = new $classname($db);
  343. $modulequalified=1;
  344. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  345. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  346. if ($modulequalified)
  347. {
  348. print '<tr><td width="100">';
  349. print (empty($module->name)?$name:$module->name);
  350. print "</td><td>\n";
  351. if (method_exists($module,'info')) print $module->info($langs);
  352. else print $module->description;
  353. print '</td>';
  354. // Active
  355. if (in_array($name, $def))
  356. {
  357. print '<td align="center">'."\n";
  358. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
  359. print img_picto($langs->trans("Enabled"),'switch_on');
  360. print '</a>';
  361. print '</td>';
  362. }
  363. else
  364. {
  365. print '<td align="center">'."\n";
  366. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  367. print "</td>";
  368. }
  369. // Defaut
  370. print '<td align="center">';
  371. if ($conf->global->EXPEDITION_ADDON_PDF == $name)
  372. {
  373. print img_picto($langs->trans("Default"),'on');
  374. }
  375. else
  376. {
  377. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  378. }
  379. print '</td>';
  380. // Info
  381. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  382. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  383. if ($module->type == 'pdf')
  384. {
  385. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  386. }
  387. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  388. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  389. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  390. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  391. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  392. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  393. print '<td align="center">';
  394. print $form->textwithpicto('',$htmltooltip,1,0);
  395. print '</td>';
  396. // Preview
  397. print '<td align="center">';
  398. if ($module->type == 'pdf')
  399. {
  400. 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>';
  401. }
  402. else
  403. {
  404. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  405. }
  406. print '</td>';
  407. print "</tr>\n";
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. }
  416. print '</table>';
  417. print '<br>';
  418. /*
  419. * Other options
  420. *
  421. */
  422. print load_fiche_titre($langs->trans("OtherOptions"));
  423. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  424. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  425. print '<input type="hidden" name="action" value="set_param">';
  426. print "<table class=\"noborder\" width=\"100%\">";
  427. print "<tr class=\"liste_titre\">";
  428. print "<td>".$langs->trans("Parameter")."</td>\n";
  429. print "</tr>";
  430. $substitutionarray=pdf_getSubstitutionArray($langs);
  431. $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
  432. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  433. foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
  434. $htmltext.='</i>';
  435. print '<tr><td>';
  436. print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
  437. $variablename='SHIPPING_FREE_TEXT';
  438. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  439. {
  440. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  441. }
  442. else
  443. {
  444. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  445. $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_details');
  446. print $doleditor->Create();
  447. }
  448. print "</td></tr>\n";
  449. print '<tr><td>';
  450. print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext).'<br>';
  451. print '<input size="50" class="flat" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.$conf->global->SHIPPING_DRAFT_WATERMARK.'">';
  452. print "</td></tr>\n";
  453. print '</table>';
  454. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
  455. print '</form>';
  456. llxFooter();
  457. $db->close();