PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/const.php

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