PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/const.php

https://github.com/asterix14/dolibarr
PHP | 282 lines | 198 code | 47 blank | 37 comment | 36 complexity | a83bf828b595343bf251bd99742cb98f MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 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."/core/lib/admin.lib.php");
  26. $langs->load("admin");
  27. if (! $user->admin) accessforbidden();
  28. $action = GETPOST('action');
  29. $typeconst=array('yesno','texte','chaine');
  30. /*
  31. * Actions
  32. */
  33. if ($action == 'add')
  34. {
  35. $error=0;
  36. if (empty($_POST["constname"]))
  37. {
  38. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")).'</div>';
  39. $error++;
  40. }
  41. if ($_POST["constvalue"]=='')
  42. {
  43. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Value")).'</div>';
  44. $error++;
  45. }
  46. if (! $error)
  47. {
  48. if (dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],1,isset($_POST["constnote"])?$_POST["constnote"]:'',$_POST["entity"]) < 0)
  49. {
  50. dolibarr_print_error($db);
  51. }
  52. }
  53. }
  54. if (($_POST["const"] && isset($_POST["update"]) && $_POST["update"] == $langs->trans("Modify")))
  55. {
  56. foreach($_POST["const"] as $const)
  57. {
  58. if ($const["check"])
  59. {
  60. if (dolibarr_set_const($db, $const["name"],$const["value"],$const["type"],1,$const["note"],$const["entity"]) < 0)
  61. {
  62. dolibarr_print_error($db);
  63. }
  64. }
  65. }
  66. }
  67. // Delete several lines at once
  68. if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
  69. {
  70. foreach($_POST["const"] as $const)
  71. {
  72. if ($const["check"]) // Is checkbox checked
  73. {
  74. if (dolibarr_del_const($db, $const["rowid"], -1) < 0)
  75. {
  76. dolibarr_print_error($db);
  77. }
  78. }
  79. }
  80. }
  81. // Delete line from delete picto
  82. if ($action == 'delete')
  83. {
  84. if (dolibarr_del_const($db, $_GET["rowid"], $_GET["entity"]) < 0)
  85. {
  86. dolibarr_print_error($db);
  87. }
  88. }
  89. /*
  90. * View
  91. */
  92. llxHeader('',$langs->trans("OtherSetup"));
  93. // Add logic to show/hide buttons
  94. if ($conf->use_javascript_ajax)
  95. {
  96. ?>
  97. <script type="text/javascript">
  98. jQuery(document).ready(function() {
  99. jQuery("#updateconst").hide();
  100. jQuery("#delconst").hide();
  101. jQuery(".checkboxfordelete").click(function() {
  102. jQuery("#delconst").show();
  103. });
  104. jQuery(".inputforupdate").keypress(function() {
  105. var field_id = jQuery(this).attr("id");
  106. var row_num = field_id.split("_");
  107. jQuery("#updateconst").show();
  108. jQuery("#check_" + row_num[1]).attr("checked",true);
  109. });
  110. });
  111. </script>
  112. <?php
  113. }
  114. print_fiche_titre($langs->trans("OtherSetup"),'','setup');
  115. print $langs->trans("ConstDesc")."<br>\n";
  116. print "<br>\n";
  117. if ($mesg) print $mesg;
  118. print '<table class="noborder" width="100%">';
  119. print '<tr class="liste_titre">';
  120. print '<td>'.$langs->trans("Name").'</td>';
  121. print '<td>'.$langs->trans("Value").'</td>';
  122. print '<td>'.$langs->trans("Comment").'</td>';
  123. if (! empty($conf->multicompany->enabled) && !$user->entity) print '<td>'.$langs->trans("Entity").'</td>';
  124. print '<td align="center">'.$langs->trans("Action").'</td>';
  125. print "</tr>\n";
  126. $form = new Form($db);
  127. // Line to add new record
  128. $var=false;
  129. print "\n";
  130. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  131. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  132. print '<input type="hidden" name="action" value="add">';
  133. print '<tr '.$bc[$var].'><td><input type="text" class="flat" size="24" name="constname" value=""></td>'."\n";
  134. print '<td>';
  135. print '<input type="text" class="flat" size="30" name="constvalue" value="">';
  136. print '</td><td>';
  137. print '<input type="text" class="flat" size="40" name="constnote" value="">';
  138. print '</td>';
  139. // Limit to superadmin
  140. if (! empty($conf->multicompany->enabled) && !$user->entity)
  141. {
  142. print '<td>';
  143. print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
  144. print '</td>';
  145. }
  146. else
  147. {
  148. print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
  149. }
  150. print '<td align="center">';
  151. print '<input type="submit" class="button" value="'.$langs->trans("Add").'" name="Button">';
  152. print "</td>\n";
  153. print '</tr>';
  154. print '</form>';
  155. print "\n";
  156. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  157. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  158. // Show constants
  159. $sql = "SELECT";
  160. $sql.= " rowid";
  161. $sql.= ", ".$db->decrypt('name')." as name";
  162. $sql.= ", ".$db->decrypt('value')." as value";
  163. $sql.= ", type";
  164. $sql.= ", note";
  165. $sql.= ", entity";
  166. $sql.= " FROM ".MAIN_DB_PREFIX."const";
  167. $sql.= " WHERE entity IN (".$user->entity.",".$conf->entity.")";
  168. if ($user->entity || empty($conf->multicompany->enabled)) $sql.= " AND visible = 1";
  169. $sql.= " ORDER BY entity, name ASC";
  170. dol_syslog("Const::listConstant sql=".$sql);
  171. $result = $db->query($sql);
  172. if ($result)
  173. {
  174. $num = $db->num_rows($result);
  175. $i = 0;
  176. $var=false;
  177. while ($i < $num)
  178. {
  179. $obj = $db->fetch_object($result);
  180. $var=!$var;
  181. print "\n";
  182. print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
  183. print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
  184. print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
  185. print '<tr '.$bc[$var].'><td>'.$obj->name.'</td>'."\n";
  186. // Value
  187. print '<td>';
  188. print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.htmlspecialchars($obj->value).'"';
  189. print '>';
  190. print '</td><td>';
  191. // Note
  192. print '<input type="text" id="note_'.$i.'"class="flat inputforupdate" size="40" name="const['.$i.'][note]" value="'.htmlspecialchars($obj->note,1).'"';
  193. print '>';
  194. print '</td>';
  195. // Entity limit to superadmin
  196. if (! empty($conf->multicompany->enabled) && !$user->entity)
  197. {
  198. print '<td>';
  199. print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
  200. print '</td>';
  201. }
  202. else
  203. {
  204. print '<input type="hidden" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
  205. }
  206. print '<td align="center">';
  207. if ($conf->use_javascript_ajax)
  208. {
  209. print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
  210. print ' &nbsp; ';
  211. }
  212. else
  213. {
  214. print '<a href="const.php?rowid='.$obj->rowid.'&entity='.$obj->entity.'&action=delete">'.img_delete().'</a>';
  215. }
  216. print "</td></tr>\n";
  217. print "\n";
  218. $i++;
  219. }
  220. }
  221. print '</table>';
  222. if ($conf->use_javascript_ajax)
  223. {
  224. print '<br>';
  225. print '<div id="updateconst" align="right">';
  226. print '<input type="submit" name="update" class="button" value="'.$langs->trans("Modify").'">';
  227. print '</div>';
  228. print '<div id="delconst" align="right">';
  229. print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
  230. print '</div>';
  231. }
  232. print "</form>\n";
  233. $db->close();
  234. llxFooter();
  235. ?>