PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/product/admin/product.php

https://bitbucket.org/speedealing/speedealing
PHP | 478 lines | 357 code | 64 blank | 57 comment | 76 complexity | cca6f18525ad39cedc6f754b0e6f68e8 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  4. * Copyright (C) 2006-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  5. * Copyright (C) 2007 Auguria SARL <info@auguria.org>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  9. **
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/product/admin/product.php
  25. * \ingroup produit
  26. * \brief Setup page of product module
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  32. $langs->load("admin");
  33. $langs->load("products");
  34. // Security check
  35. if (! $user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled)))
  36. accessforbidden();
  37. $action = GETPOST('action','alpha');
  38. $value = GETPOST('value','alpha');
  39. /*
  40. * Actions
  41. */
  42. if ($action == 'setcodeproduct')
  43. {
  44. if (dolibarr_set_const($db, "PRODUCT_CODEPRODUCT_ADDON",$value,'chaine',0,'',$conf->entity) > 0)
  45. {
  46. header("Location: ".$_SERVER["PHP_SELF"]);
  47. exit;
  48. }
  49. else
  50. {
  51. dol_print_error($db);
  52. }
  53. }
  54. // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
  55. if ($action == 'setModuleOptions')
  56. {
  57. $post_size=count($_POST);
  58. $db->begin();
  59. for($i=0;$i < $post_size;$i++)
  60. {
  61. if (array_key_exists('param'.$i,$_POST))
  62. {
  63. $param=GETPOST("param".$i,'alpha');
  64. $value=GETPOST("value".$i,'alpha');
  65. if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
  66. if (! $res > 0) $error++;
  67. }
  68. }
  69. if (! $error)
  70. {
  71. $db->commit();
  72. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  73. }
  74. else
  75. {
  76. $db->rollback();
  77. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  78. }
  79. }
  80. if ($action == 'nbprod')
  81. {
  82. $res = dolibarr_set_const($db, "PRODUIT_LIMIT_SIZE", $value,'chaine',0,'',$conf->entity);
  83. }
  84. else if ($action == 'multiprix_num')
  85. {
  86. $res = dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", $value,'chaine',0,'',$conf->entity);
  87. }
  88. if ($action == 'multiprix')
  89. {
  90. $multiprix = GETPOST('activate_multiprix','alpha');
  91. $res = dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $multiprix,'chaine',0,'',$conf->entity);
  92. $res =dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "5",'chaine',0,'',$conf->entity);
  93. }
  94. else if ($action == 'sousproduits')
  95. {
  96. $sousproduits = GETPOST('activate_sousproduits','alpha');
  97. $res = dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $sousproduits,'chaine',0,'',$conf->entity);
  98. }
  99. else if ($action == 'viewProdDescInForm')
  100. {
  101. $view = GETPOST('activate_viewProdDescInForm','alpha');
  102. $res = dolibarr_set_const($db, "PRODUIT_DESC_IN_FORM", $view,'chaine',0,'',$conf->entity);
  103. }
  104. else if ($action == 'viewProdTextsInThirdpartyLanguage')
  105. {
  106. $view = GETPOST('activate_viewProdTextsInThirdpartyLanguage','alpha');
  107. $res = dolibarr_set_const($db, "PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE", $view,'chaine',0,'',$conf->entity);
  108. }
  109. else if ($action == 'usesearchtoselectproduct')
  110. {
  111. $usesearch = GETPOST('activate_usesearchtoselectproduct','alpha');
  112. $res = dolibarr_set_const($db, "PRODUIT_USE_SEARCH_TO_SELECT", $usesearch,'chaine',0,'',$conf->entity);
  113. }
  114. else if ($action == 'set')
  115. {
  116. $const = "PRODUCT_SPECIAL_".strtoupper(GETPOST('spe','alpha'));
  117. if (GETPOST('value','alpha')) $res = dolibarr_set_const($db, $const, $value,'chaine',0,'',$conf->entity);
  118. else $res = dolibarr_del_const($db, $const,$conf->entity);
  119. }
  120. /*else if ($action == 'useecotaxe')
  121. {
  122. $ecotaxe = GETPOST("activate_useecotaxe");
  123. $res = dolibarr_set_const($db, "PRODUIT_USE_ECOTAXE", $ecotaxe,'chaine',0,'',$conf->entity);
  124. }*/
  125. if($action)
  126. {
  127. if (! $res > 0) $error++;
  128. if (! $error)
  129. {
  130. $mesg = '<font class="ok">'.$langs->trans("SetupSaved").'</font>';
  131. }
  132. else
  133. {
  134. $mesg = '<font class="error">'.$langs->trans("Error").'</font>';
  135. }
  136. }
  137. /*
  138. * View
  139. */
  140. $formbarcode=new FormBarCode($db);
  141. $title = $langs->trans('ProductServiceSetup');
  142. $tab = $langs->trans("ProductsAndServices");
  143. if (empty($conf->produit->enabled))
  144. {
  145. $title = $langs->trans('ServiceSetup');
  146. $tab = $langs->trans('Services');
  147. }
  148. else if (empty($conf->service->enabled))
  149. {
  150. $title = $langs->trans('ProductSetup');
  151. $tab = $langs->trans('Products');
  152. }
  153. llxHeader('',$title);
  154. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  155. print_fiche_titre($title,$linkback,'setup');
  156. $head = product_admin_prepare_head();
  157. dol_fiche_head($head, 'general', $tab, 0, 'product');
  158. $form=new Form($db);
  159. /*
  160. * Module to manage product / services code
  161. */
  162. $dirproduct=array('/core/modules/product/');
  163. print_titre($langs->trans("ProductCodeChecker"));
  164. print '<table class="noborder" width="100%">'."\n";
  165. print '<tr class="liste_titre">'."\n";
  166. print ' <td>'.$langs->trans("Name").'</td>';
  167. print ' <td>'.$langs->trans("Description").'</td>';
  168. print ' <td>'.$langs->trans("Example").'</td>';
  169. print ' <td align="center" width="80">'.$langs->trans("Status").'</td>';
  170. print ' <td align="center" width="60">'.$langs->trans("Infos").'</td>';
  171. print "</tr>\n";
  172. $var = true;
  173. foreach ($dirproduct as $dirroot)
  174. {
  175. $dir = dol_buildpath($dirroot,0);
  176. $handle = @opendir($dir);
  177. if (is_resource($handle))
  178. {
  179. // Loop on each module find in opened directory
  180. while (($file = readdir($handle))!==false)
  181. {
  182. if (substr($file, 0, 16) == 'mod_codeproduct_' && substr($file, -3) == 'php')
  183. {
  184. $file = substr($file, 0, dol_strlen($file)-4);
  185. try {
  186. dol_include_once($dirroot.$file.'.php');
  187. }
  188. catch(Exception $e)
  189. {
  190. dol_syslog($e->getMessage(), LOG_ERR);
  191. }
  192. $modCodeProduct = new $file;
  193. // Show modules according to features level
  194. if ($modCodeProduct->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  195. if ($modCodeProduct->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  196. $var = !$var;
  197. print '<tr '.$bc[$var].'>'."\n";
  198. print '<td width="140">'.$modCodeProduct->nom.'</td>'."\n";
  199. print '<td>'.$modCodeProduct->info($langs).'</td>'."\n";
  200. print '<td nowrap="nowrap">'.$modCodeProduct->getExample($langs).'</td>'."\n";
  201. if (! empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) && $conf->global->PRODUCT_CODEPRODUCT_ADDON == $file)
  202. {
  203. print '<td align="center">'."\n";
  204. print img_picto($langs->trans("Activated"),'switch_on');
  205. print "</td>\n";
  206. }
  207. else
  208. {
  209. $disabled = false;
  210. if (! empty($conf->multicompany->enabled) && (is_object($mc) && ! empty($mc->sharings['referent']) && $mc->sharings['referent'] == $conf->entity) ? false : true);
  211. print '<td align="center">';
  212. if (! $disabled) print '<a href="'.$_SERVER['PHP_SELF'].'?action=setcodeproduct&value='.$file.'">';
  213. print img_picto($langs->trans("Disabled"),'switch_off');
  214. if (! $disabled) print '</a>';
  215. print '</td>';
  216. }
  217. print '<td align="center">';
  218. $s=$modCodeProduct->getToolTip($langs,null,-1);
  219. print $form->textwithpicto('',$s,1);
  220. print '</td>';
  221. print '</tr>';
  222. }
  223. }
  224. closedir($handle);
  225. }
  226. }
  227. print '</table>';
  228. /*
  229. * Other conf
  230. */
  231. print "<br>";
  232. print_titre($langs->trans("ProductOtherConf"));
  233. $var=true;
  234. print '<table class="noborder" width="100%">';
  235. print '<tr class="liste_titre">';
  236. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  237. print '<td align="right" width="60">'.$langs->trans("Value").'</td>'."\n";
  238. print '<td width="80">&nbsp;</td></tr>'."\n";
  239. /*
  240. * Formulaire parametres divers
  241. */
  242. // multiprix activation/desactivation
  243. $var=!$var;
  244. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  245. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  246. print '<input type="hidden" name="action" value="multiprix">';
  247. print '<tr '.$bc[$var].'>';
  248. print '<td>'.$langs->trans("MultiPricesAbility").'</td>';
  249. print '<td width="60" align="right">';
  250. print $form->selectyesno("activate_multiprix",$conf->global->PRODUIT_MULTIPRICES,1);
  251. print '</td><td align="right">';
  252. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  253. print '</td>';
  254. print '</tr>';
  255. print '</form>';
  256. // multiprix nombre de prix a proposer
  257. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  258. {
  259. $var=!$var;
  260. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  261. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  262. print '<input type="hidden" name="action" value="multiprix_num">';
  263. print '<tr '.$bc[$var].'>';
  264. print '<td>'.$langs->trans("MultiPricesNumPrices").'</td>';
  265. print '<td align="right"><input size="3" type="text" class="flat" name="value" value="'.$conf->global->PRODUIT_MULTIPRICES_LIMIT.'"></td>';
  266. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  267. print '</tr>';
  268. print '</form>';
  269. }
  270. // sousproduits activation/desactivation
  271. $var=!$var;
  272. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  273. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  274. print '<input type="hidden" name="action" value="sousproduits">';
  275. print '<tr '.$bc[$var].'>';
  276. print '<td>'.$langs->trans("AssociatedProductsAbility").'</td>';
  277. print '<td width="60" align="right">';
  278. print $form->selectyesno("activate_sousproduits",$conf->global->PRODUIT_SOUSPRODUITS,1);
  279. print '</td><td align="right">';
  280. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  281. print '</td>';
  282. print '</tr>';
  283. print '</form>';
  284. // utilisation formulaire Ajax sur choix produit
  285. $var=!$var;
  286. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  287. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  288. print '<input type="hidden" name="action" value="usesearchtoselectproduct">';
  289. print '<tr '.$bc[$var].'>';
  290. print '<td>'.$langs->trans("UseSearchToSelectProduct").'</td>';
  291. if (empty($conf->use_javascript_ajax))
  292. {
  293. print '<td nowrap="nowrap" align="right" colspan="2">';
  294. print $langs->trans("NotAvailableWhenAjaxDisabled");
  295. print '</td>';
  296. }
  297. else
  298. {
  299. print '<td width="60" align="right">';
  300. $arrval=array('0'=>$langs->trans("No"),
  301. '1'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",1).')',
  302. '2'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",2).')',
  303. '3'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",3).')',
  304. );
  305. print $form->selectarray("activate_usesearchtoselectproduct",$arrval,$conf->global->PRODUIT_USE_SEARCH_TO_SELECT);
  306. print '</td><td align="right">';
  307. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  308. print '</td>';
  309. }
  310. print '</tr>';
  311. print '</form>';
  312. if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT))
  313. {
  314. $var=!$var;
  315. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  316. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  317. print '<input type="hidden" name="action" value="nbprod">';
  318. print '<tr '.$bc[$var].'>';
  319. print '<td>'.$langs->trans("NumberOfProductShowInSelect").'</td>';
  320. print '<td align="right"><input size="3" type="text" class="flat" name="value" value="'.$conf->global->PRODUIT_LIMIT_SIZE.'"></td>';
  321. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  322. print '</tr>';
  323. print '</form>';
  324. }
  325. // Visualiser description produit dans les formulaires activation/desactivation
  326. $var=!$var;
  327. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  328. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  329. print '<input type="hidden" name="action" value="viewProdDescInForm">';
  330. print '<tr '.$bc[$var].'>';
  331. print '<td>'.$langs->trans("ViewProductDescInFormAbility").'</td>';
  332. print '<td width="60" align="right">';
  333. print $form->selectyesno("activate_viewProdDescInForm",$conf->global->PRODUIT_DESC_IN_FORM,1);
  334. print '</td><td align="right">';
  335. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  336. print '</td>';
  337. print '</tr>';
  338. print '</form>';
  339. // View product description in thirdparty language
  340. if (! empty($conf->global->MAIN_MULTILANGS))
  341. {
  342. $var=!$var;
  343. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  344. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  345. print '<input type="hidden" name="action" value="viewProdTextsInThirdpartyLanguage">';
  346. print '<tr '.$bc[$var].'>';
  347. print '<td>'.$langs->trans("ViewProductDescInThirdpartyLanguageAbility").'</td>';
  348. print '<td width="60" align="right">';
  349. print $form->selectyesno("activate_viewProdTextsInThirdpartyLanguage", (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)?$conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE:0), 1);
  350. print '</td><td align="right">';
  351. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  352. print '</td>';
  353. print '</tr>';
  354. print '</form>';
  355. }
  356. if (! empty($conf->global->PRODUCT_CANVAS_ABILITY))
  357. {
  358. // Add canvas feature
  359. $dir = DOL_DOCUMENT_ROOT . "/product/canvas/";
  360. $var = false;
  361. print '<tr class="liste_titre">';
  362. print '<td>'.$langs->trans("ProductSpecial").'</td>'."\n";
  363. print '<td align="right" width="60">'.$langs->trans("Value").'</td>'."\n";
  364. print '<td width="80">&nbsp;</td></tr>'."\n";
  365. if (is_dir($dir))
  366. {
  367. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  368. $handle=opendir($dir);
  369. if (is_resource($handle))
  370. {
  371. while (($file = readdir($handle))!==false)
  372. {
  373. if (file_exists($dir.$file.'/product.'.$file.'.class.php'))
  374. {
  375. $classfile = $dir.$file.'/product.'.$file.'.class.php';
  376. $classname = 'Product'.ucfirst($file);
  377. require_once $classfile;
  378. $object = new $classname();
  379. $module = $object->module;
  380. if ($conf->$module->enabled)
  381. {
  382. $var=!$var;
  383. print "<tr ".$bc[$var]."><td>";
  384. print $object->description;
  385. print '</td><td align="right">';
  386. $const = "PRODUCT_SPECIAL_".strtoupper($file);
  387. if ($conf->global->$const)
  388. {
  389. print img_picto($langs->trans("Active"),'tick');
  390. print '</td><td align="right">';
  391. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;spe='.$file.'&amp;value=0">'.$langs->trans("Disable").'</a>';
  392. }
  393. else
  394. {
  395. print '&nbsp;</td><td align="right">';
  396. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;spe='.$file.'&amp;value=1">'.$langs->trans("Activate").'</a>';
  397. }
  398. print '</td></tr>';
  399. }
  400. }
  401. }
  402. closedir($handle);
  403. }
  404. }
  405. else
  406. {
  407. print "<tr><td><b>ERROR</b>: $dir is not a directory !</td></tr>\n";
  408. }
  409. print '</table>';
  410. }
  411. dol_htmloutput_mesg($mesg);
  412. llxFooter();
  413. $db->close();
  414. ?>