const.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/const.php
  21. * \ingroup setup
  22. * \brief Admin page to define miscellaneous constants
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  26. $langs->load("admin");
  27. if (!$user->admin)
  28. accessforbidden();
  29. //var_dump($_POST);
  30. $typeconst=array('yesno','texte','chaine');
  31. /*
  32. * Actions
  33. */
  34. if ($_POST["action"] == 'add')
  35. {
  36. $error=0;
  37. if (empty($_POST["constname"]))
  38. {
  39. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")).'</div>';
  40. $error++;
  41. }
  42. if ($_POST["constvalue"]=='')
  43. {
  44. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Value")).'</div>';
  45. $error++;
  46. }
  47. if (! $error)
  48. {
  49. if (dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],1,isset($_POST["constnote"])?$_POST["constnote"]:'',$_POST["entity"]) < 0)
  50. {
  51. dolibarr_print_error($db);
  52. }
  53. }
  54. }
  55. if (($_POST["const"] && isset($_POST["update"]) && $_POST["update"] == $langs->trans("Modify")))
  56. {
  57. foreach($_POST["const"] as $const)
  58. {
  59. if ($const["check"])
  60. {
  61. if (dolibarr_set_const($db, $const["name"],$const["value"],$const["type"],1,$const["note"],$const["entity"]) < 0)
  62. {
  63. dolibarr_print_error($db);
  64. }
  65. }
  66. }
  67. }
  68. // Delete several lines at once
  69. if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
  70. {
  71. foreach($_POST["const"] as $const)
  72. {
  73. if ($const["check"]) // Is checkbox checked
  74. {
  75. if (dolibarr_del_const($db, $const["rowid"], -1) < 0)
  76. {
  77. dolibarr_print_error($db);
  78. }
  79. }
  80. }
  81. }
  82. // Delete line from delete picto
  83. if ($_GET["action"] == 'delete')
  84. {
  85. if (dolibarr_del_const($db, $_GET["rowid"],$_GET["entity"]) < 0)
  86. {
  87. dolibarr_print_error($db);
  88. }
  89. }
  90. /*
  91. * View
  92. */
  93. llxHeader('',$langs->trans("OtherSetup"));
  94. // Add logic to show/hide buttons
  95. if ($conf->use_javascript_ajax)
  96. {
  97. ?>
  98. <script type="text/javascript" language="javascript">
  99. jQuery(document).ready(function() {
  100. jQuery("#updateconst").hide();
  101. jQuery("#delconst").hide();
  102. jQuery(".checkboxfordelete").click(function() {
  103. jQuery("#delconst").show();
  104. });
  105. jQuery(".inputforupdate").keypress(function() {
  106. var field_id = jQuery(this).attr("id");
  107. var row_num = field_id.split("_");
  108. jQuery("#updateconst").show();
  109. jQuery("#check_" + row_num[1]).attr("checked",true);
  110. });
  111. });
  112. </script>
  113. <?php
  114. }
  115. print_fiche_titre($langs->trans("OtherSetup"),'','setup');
  116. print $langs->trans("ConstDesc")."<br>\n";
  117. print "<br>\n";
  118. if ($mesg) print $mesg;
  119. print '<table class="noborder" width="100%">';
  120. print '<tr class="liste_titre">';
  121. print '<td>'.$langs->trans("Name").'</td>';
  122. print '<td>'.$langs->trans("Value").'</td>';
  123. print '<td>'.$langs->trans("Comment").'</td>';
  124. if (! empty($conf->multicompany->enabled) && !$user->entity) print '<td>'.$langs->trans("Entity").'</td>';
  125. print '<td align="center">'.$langs->trans("Action").'</td>';
  126. print "</tr>\n";
  127. $form = new Form($db);
  128. // Line to add new record
  129. $var=false;
  130. print "\n";
  131. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  132. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  133. print '<input type="hidden" name="action" value="add">';
  134. print '<tr '.$bc[$var].'><td><input type="text" class="flat" size="24" name="constname" value=""></td>'."\n";
  135. print '<td>';
  136. print '<input type="text" class="flat" size="30" name="constvalue" value="">';
  137. print '</td><td>';
  138. print '<input type="text" class="flat" size="40" name="constnote" value="">';
  139. print '</td>';
  140. // Limit to superadmin
  141. if (! empty($conf->multicompany->enabled) && !$user->entity)
  142. {
  143. print '<td>';
  144. print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
  145. print '</td>';
  146. }
  147. else
  148. {
  149. print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
  150. }
  151. print '<td align="center">';
  152. print '<input type="submit" class="button" value="'.$langs->trans("Add").'" name="Button">';
  153. print "</td>\n";
  154. print '</tr>';
  155. print '</form>';
  156. print "\n";
  157. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  158. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  159. # Affiche lignes des constantes
  160. $sql = "SELECT";
  161. $sql.= " rowid";
  162. $sql.= ", ".$db->decrypt('name')." as name";
  163. $sql.= ", ".$db->decrypt('value')." as value";
  164. $sql.= ", type";
  165. $sql.= ", note";
  166. $sql.= ", entity";
  167. $sql.= " FROM ".MAIN_DB_PREFIX."const";
  168. $sql.= " WHERE entity IN (".$user->entity.",".$conf->entity.")";
  169. if ($user->entity || empty($conf->multicompany->enabled)) $sql.= " AND visible = 1";
  170. $sql.= " ORDER BY entity, name ASC";
  171. dol_syslog("Const::listConstant sql=".$sql);
  172. $result = $db->query($sql);
  173. if ($result)
  174. {
  175. $num = $db->num_rows($result);
  176. $i = 0;
  177. $var=false;
  178. while ($i < $num)
  179. {
  180. $obj = $db->fetch_object($result);
  181. $var=!$var;
  182. print "\n";
  183. print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
  184. print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
  185. print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
  186. print '<tr '.$bc[$var].'><td>'.$obj->name.'</td>'."\n";
  187. // Value
  188. print '<td>';
  189. print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.htmlspecialchars($obj->value).'"';
  190. print '>';
  191. print '</td><td>';
  192. // Note
  193. print '<input type="text" id="note_'.$i.'"class="flat inputforupdate" size="40" name="const['.$i.'][note]" value="'.htmlspecialchars($obj->note,1).'"';
  194. print '>';
  195. print '</td>';
  196. // Entity limit to superadmin
  197. if (! empty($conf->multicompany->enabled) && !$user->entity)
  198. {
  199. print '<td>';
  200. print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
  201. print '</td>';
  202. }
  203. else
  204. {
  205. print '<input type="hidden" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
  206. }
  207. print '<td align="center">';
  208. if ($conf->use_javascript_ajax)
  209. {
  210. print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
  211. print ' &nbsp; ';
  212. }
  213. else
  214. {
  215. print '<a href="const.php?rowid='.$obj->rowid.'&entity='.$obj->entity.'&action=delete">'.img_delete().'</a>';
  216. }
  217. print "</td></tr>\n";
  218. print "\n";
  219. $i++;
  220. }
  221. }
  222. print '</table>';
  223. if ($conf->use_javascript_ajax)
  224. {
  225. print '<br>';
  226. print '<div id="updateconst" align="right">';
  227. print '<input type="submit" name="update" class="button" value="'.$langs->trans("Modify").'">';
  228. print '</div>';
  229. print '<div id="delconst" align="right">';
  230. print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
  231. print '</div>';
  232. }
  233. print "</form>\n";
  234. $db->close();
  235. llxFooter();
  236. ?>