PageRenderTime 46ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/commande.php

https://github.com/asterix14/dolibarr
PHP | 561 lines | 374 code | 86 blank | 101 comment | 67 complexity | d93551e6f91a26869663aa1a450ca857 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2006 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 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  8. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  9. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  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 2 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/commande.php
  26. * \ingroup commande
  27. * \brief Setup page of module Order
  28. */
  29. require("../main.inc.php");
  30. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  31. require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
  32. $langs->load("admin");
  33. $langs->load("errors");
  34. if (!$user->admin)
  35. accessforbidden();
  36. $action = GETPOST("action");
  37. $value = GETPOST("value");
  38. /*
  39. * Actions
  40. */
  41. if ($action == 'updateMask')
  42. {
  43. $maskconstorder=GETPOST("maskconstorder");
  44. $maskorder=GETPOST("maskorder");
  45. if ($maskconstorder) $res = dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity);
  46. if (! $res > 0) $error++;
  47. if (! $error)
  48. {
  49. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  50. }
  51. else
  52. {
  53. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  54. }
  55. }
  56. if ($action == 'specimen')
  57. {
  58. $modele=GETPOST("module");
  59. $commande = new Commande($db);
  60. $commande->initAsSpecimen();
  61. // Charge le modele
  62. $dir = DOL_DOCUMENT_ROOT . "/core/modules/commande/";
  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($commande,$langs) > 0)
  70. {
  71. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande&file=SPECIMEN.pdf");
  72. return;
  73. }
  74. else
  75. {
  76. $mesg='<div class="error">'.$obj->error.'</div>';
  77. dol_syslog($obj->error, LOG_ERR);
  78. }
  79. }
  80. else
  81. {
  82. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  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='order';
  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. if ($db->query($sql))
  97. {
  98. }
  99. }
  100. if ($action == 'del')
  101. {
  102. $type='order';
  103. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  104. $sql.= " WHERE nom = '".$db->escape($value)."'";
  105. $sql.= " AND type = '".$type."'";
  106. $sql.= " AND entity = ".$conf->entity;
  107. if ($db->query($sql))
  108. {
  109. if ($conf->global->COMMANDE_ADDON_PDF == "$value") dolibarr_del_const($db, 'COMMANDE_ADDON_PDF',$conf->entity);
  110. }
  111. }
  112. if ($action == 'setdoc')
  113. {
  114. $label = GETPOST("label");
  115. $scandir = GETPOST("scandir");
  116. $db->begin();
  117. if (dolibarr_set_const($db, "COMMANDE_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  118. {
  119. $conf->global->COMMANDE_ADDON_PDF = $value;
  120. }
  121. // On active le modele
  122. $type='order';
  123. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  124. $sql_del.= " WHERE nom = '".$db->escape($value)."'";
  125. $sql_del.= " AND type = '".$type."'";
  126. $sql_del.= " AND entity = ".$conf->entity;
  127. $result1=$db->query($sql_del);
  128. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  129. $sql.= " VALUES ('".$value."', '".$type."', ".$conf->entity.", ";
  130. $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
  131. $sql.= (! empty($scandir)?"'".$scandir."'":"null");
  132. $sql.= ")";
  133. $result2=$db->query($sql);
  134. if ($result1 && $result2)
  135. {
  136. $db->commit();
  137. }
  138. else
  139. {
  140. $db->rollback();
  141. }
  142. }
  143. if ($action == 'setmod')
  144. {
  145. // TODO Verifier si module numerotation choisi peut etre active
  146. // par appel methode canBeActivated
  147. dolibarr_set_const($db, "COMMANDE_ADDON",$value,'chaine',0,'',$conf->entity);
  148. }
  149. if ($action == 'set_COMMANDE_DRAFT_WATERMARK')
  150. {
  151. $draft = GETPOST("COMMANDE_DRAFT_WATERMARK");
  152. $res = dolibarr_set_const($db, "COMMANDE_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
  153. if (! $res > 0) $error++;
  154. if (! $error)
  155. {
  156. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  157. }
  158. else
  159. {
  160. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  161. }
  162. }
  163. if ($action == 'set_COMMANDE_FREE_TEXT')
  164. {
  165. $freetext = GETPOST("COMMANDE_FREE_TEXT");
  166. $res = dolibarr_set_const($db, "COMMANDE_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  167. if (! $res > 0) $error++;
  168. if (! $error)
  169. {
  170. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  171. }
  172. else
  173. {
  174. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  175. }
  176. }
  177. /*
  178. * View
  179. */
  180. llxHeader();
  181. $form=new Form($db);
  182. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  183. print_fiche_titre($langs->trans("OrdersSetup"),$linkback,'setup');
  184. print "<br>";
  185. /*
  186. * Numbering module
  187. */
  188. print_titre($langs->trans("OrdersNumberingModules"));
  189. print '<table class="noborder" width="100%">';
  190. print '<tr class="liste_titre">';
  191. print '<td width="100">'.$langs->trans("Name").'</td>';
  192. print '<td>'.$langs->trans("Description").'</td>';
  193. print '<td>'.$langs->trans("Example").'</td>';
  194. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  195. print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
  196. print "</tr>\n";
  197. clearstatcache();
  198. foreach ($conf->file->dol_document_root as $dirroot)
  199. {
  200. $dir = $dirroot . "/core/modules/commande/";
  201. if (is_dir($dir))
  202. {
  203. $handle = opendir($dir);
  204. if (is_resource($handle))
  205. {
  206. $var=true;
  207. while (($file = readdir($handle))!==false)
  208. {
  209. if (substr($file, 0, 13) == 'mod_commande_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  210. {
  211. $file = substr($file, 0, dol_strlen($file)-4);
  212. require_once(DOL_DOCUMENT_ROOT ."/core/modules/commande/".$file.".php");
  213. $module = new $file;
  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. if ($module->isEnabled())
  218. {
  219. $var=!$var;
  220. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  221. print $module->info();
  222. print '</td>';
  223. // Show example of numbering module
  224. print '<td nowrap="nowrap">';
  225. $tmp=$module->getExample();
  226. if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
  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->COMMANDE_ADDON == "$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.'">';
  238. print img_picto($langs->trans("Disabled"),'switch_off');
  239. print '</a>';
  240. }
  241. print '</td>';
  242. $commande=new Commande($db);
  243. $commande->initAsSpecimen();
  244. // Info
  245. $htmltooltip='';
  246. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  247. $facture->type=0;
  248. $nextval=$module->getNextValue($mysoc,$commande);
  249. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  250. {
  251. $htmltooltip.=''.$langs->trans("NextValue").': ';
  252. if ($nextval)
  253. {
  254. $htmltooltip.=$nextval.'<br>';
  255. }
  256. else
  257. {
  258. $htmltooltip.=$langs->trans($module->error).'<br>';
  259. }
  260. }
  261. print '<td align="center">';
  262. print $form->textwithpicto('',$htmltooltip,1,0);
  263. print '</td>';
  264. print '</tr>';
  265. }
  266. }
  267. }
  268. closedir($handle);
  269. }
  270. }
  271. }
  272. print '</table><br>';
  273. /*
  274. * Modeles de documents
  275. */
  276. print_titre($langs->trans("OrdersModelModule"));
  277. // Defini tableau def de modele
  278. $type='order';
  279. $def = array();
  280. $sql = "SELECT nom";
  281. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  282. $sql.= " WHERE type = '".$type."'";
  283. $sql.= " AND entity = ".$conf->entity;
  284. $resql=$db->query($sql);
  285. if ($resql)
  286. {
  287. $i = 0;
  288. $num_rows=$db->num_rows($resql);
  289. while ($i < $num_rows)
  290. {
  291. $array = $db->fetch_array($resql);
  292. array_push($def, $array[0]);
  293. $i++;
  294. }
  295. }
  296. else
  297. {
  298. dol_print_error($db);
  299. }
  300. print "<table class=\"noborder\" width=\"100%\">\n";
  301. print "<tr class=\"liste_titre\">\n";
  302. print ' <td width="100">'.$langs->trans("Name")."</td>\n";
  303. print " <td>".$langs->trans("Description")."</td>\n";
  304. print '<td align="center" width="40">'.$langs->trans("Status")."</td>\n";
  305. print '<td align="center" width="40">'.$langs->trans("Default")."</td>\n";
  306. print '<td align="center" width="40">'.$langs->trans("Infos").'</td>';
  307. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  308. print "</tr>\n";
  309. clearstatcache();
  310. foreach ($conf->file->dol_document_root as $dirroot)
  311. {
  312. $dir = $dirroot . "/core/modules/commande/";
  313. if (is_dir($dir))
  314. {
  315. $handle = opendir($dir);
  316. if (is_resource($handle))
  317. {
  318. $var=true;
  319. while (($file = readdir($handle))!==false)
  320. {
  321. if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_')
  322. {
  323. $name = substr($file, 4, dol_strlen($file) -16);
  324. $classname = substr($file, 0, dol_strlen($file) -12);
  325. $var=!$var;
  326. print "<tr ".$bc[$var].">\n <td>";
  327. print "$name";
  328. print "</td>\n <td>\n";
  329. require_once($dir.$file);
  330. $module = new $classname($db);
  331. print $module->description;
  332. print "</td>\n";
  333. // Activated
  334. print "<td align=\"center\">\n";
  335. if (in_array($name, $def))
  336. {
  337. //if ($conf->global->COMMANDE_ADDON_PDF != "$name")
  338. //{
  339. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  340. print img_picto($langs->trans("Activated"),'switch_on');
  341. print '</a>';
  342. //}
  343. //else
  344. //{
  345. // print img_picto($langs->trans("Activated"),'switch_on');
  346. //}
  347. }
  348. else
  349. {
  350. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  351. print img_picto($langs->trans("Disabled"),'switch_off');
  352. print '</a>';
  353. }
  354. print "</td>";
  355. // Defaut
  356. print "<td align=\"center\">";
  357. if ($conf->global->COMMANDE_ADDON_PDF == "$name")
  358. {
  359. print img_picto($langs->trans("Yes"),'on');
  360. }
  361. else
  362. {
  363. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  364. print img_picto($langs->trans("No"),'off');
  365. print '</a>';
  366. }
  367. print '</td>';
  368. // Info
  369. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  370. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  371. if ($module->type == 'pdf')
  372. {
  373. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  374. }
  375. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  376. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  377. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  378. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  379. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  380. //$htmltooltip.='<br>'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1);
  381. //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  382. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  383. print '<td align="center">';
  384. print $form->textwithpicto('',$htmltooltip,1,0);
  385. print '</td>';
  386. print '<td align="center">';
  387. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  388. print '</td>';
  389. print "</tr>\n";
  390. }
  391. }
  392. closedir($handle);
  393. }
  394. }
  395. }
  396. print '</table>';
  397. //Autres Options
  398. print "<br>";
  399. print_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>&nbsp;</td>\n";
  405. print "</tr>\n";
  406. $var=true;
  407. // Valider la commande apres cloture de la propale
  408. // permet de na pas passer par l'option commande provisoire
  409. /*
  410. $var=! $var;
  411. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  412. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  413. print '<input type="hidden" name="action" value="setvalidorder">';
  414. print '<tr '.$bc[$var].'>';
  415. print '<td>'.$langs->trans("ValidOrderAfterPropalClosed").'</td>';
  416. print '<td width="60" align="center">'.$form->selectyesno("validorder",$conf->global->COMMANDE_VALID_AFTER_CLOSE_PROPAL,1).'</td>';
  417. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  418. print '</tr>';
  419. print '</form>';
  420. */
  421. // Ajouter une ligne de frais port indiquant le poids de la commande
  422. /*
  423. $var=! $var;
  424. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  425. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  426. print '<input type="hidden" name="action" value="deliverycostline">';
  427. print '<tr '.$bc[$var].'>';
  428. print '<td>'.$langs->trans("AddDeliveryCostLine").'</td>';
  429. print '<td width="60" align="center">'.$form->selectyesno("addline",$conf->global->COMMANDE_ADD_DELIVERY_COST_LINE,1).'</td>';
  430. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  431. print '</tr>';
  432. print '</form>';
  433. */
  434. // Utiliser le contact de la commande dans le document
  435. /*
  436. $var=! $var;
  437. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  438. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  439. print '<input type="hidden" name="action" value="set_use_customer_contact_as_recipient">';
  440. print '<tr '.$bc[$var].'>';
  441. print '<td>'.$langs->trans("UseCustomerContactAsOrderRecipientIfExist").'</td>';
  442. print '<td width="60" align="center">'.$form->selectyesno("use_customer_contact_as_recipient",$conf->global->COMMANDE_USE_CUSTOMER_CONTACT_AS_RECIPIENT,1).'</td>';
  443. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  444. print '</tr>';
  445. print '</form>';
  446. */
  447. $var=! $var;
  448. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  449. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  450. print '<input type="hidden" name="action" value="set_COMMANDE_FREE_TEXT">';
  451. print '<tr '.$bc[$var].'><td colspan="2">';
  452. print $langs->trans("FreeLegalTextOnOrders").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  453. print '<textarea name="COMMANDE_FREE_TEXT" class="flat" cols="120">'.$conf->global->COMMANDE_FREE_TEXT.'</textarea>';
  454. print '</td><td align="right">';
  455. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  456. print "</td></tr>\n";
  457. print '</form>';
  458. //Use draft Watermark
  459. $var=!$var;
  460. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  461. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  462. print "<input type=\"hidden\" name=\"action\" value=\"set_COMMANDE_DRAFT_WATERMARK\">";
  463. print '<tr '.$bc[$var].'><td colspan="2">';
  464. print $langs->trans("WatermarkOnDraftOrders").'<br>';
  465. print '<input size="50" class="flat" type="text" name="COMMANDE_DRAFT_WATERMARK" value="'.$conf->global->COMMANDE_DRAFT_WATERMARK.'">';
  466. print '</td><td align="right">';
  467. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  468. print "</td></tr>\n";
  469. print '</form>';
  470. print '</table>';
  471. print '<br>';
  472. dol_htmloutput_mesg($mesg);
  473. $db->close();
  474. llxFooter();
  475. ?>