expedition.php 18 KB

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