control-options.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. if (isset($_POST["remove"])) {
  5. $fid = $_POST["f_id"];
  6. if (!empty($fid)) {
  7. foreach ($fid as $key => $val) {
  8. if (isset($val) and $val != 1) {
  9. LOG_INFO($db_link, "Remove config option id: $val");
  10. delete_record($db_link, "config", "id=" . $val);
  11. }
  12. }
  13. }
  14. header("Location: " . $_SERVER["REQUEST_URI"]);
  15. exit;
  16. }
  17. if (isset($_POST['save'])) {
  18. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  19. for ($i = 0; $i < $len; $i ++) {
  20. $save_id = intval($_POST['save'][$i]);
  21. $len_all = is_array($_POST['id']) ? count($_POST['id']) : 0;
  22. for ($j = 0; $j < $len_all; $j ++) {
  23. if (intval($_POST['id'][$j]) != $save_id) { continue; }
  24. $value = $_POST['f_config_value'][$j];
  25. if (isset($value) and $value!=='********') {
  26. $new['value'] = $value;
  27. update_record($db_link, "config", "id='{$save_id}'", $new);
  28. }
  29. }
  30. }
  31. header("Location: " . $_SERVER["REQUEST_URI"]);
  32. exit;
  33. }
  34. if (isset($_POST["create"])) {
  35. $new_option = $_POST["f_new_option"];
  36. if (isset($new_option)) {
  37. $new['option_id'] = $new_option;
  38. $new['value'] = get_option($db_link,$new_option);
  39. LOG_INFO($db_link, "Add config option $new_option");
  40. insert_record($db_link, "config", $new);
  41. }
  42. header("Location: " . $_SERVER["REQUEST_URI"]);
  43. exit;
  44. }
  45. unset($_POST);
  46. fix_auth_rules($db_link);
  47. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  48. print_control_submenu($page_url);
  49. ?>
  50. <div id="cont">
  51. <br>
  52. <form name="def" action="control-options.php" method="post">
  53. <br><b>Настройки</b><br>
  54. <table class="data" width=800>
  55. <tr align="center">
  56. <td width=20><input type="checkbox" onClick="checkAll(this.checked);"></td>
  57. <td width=30><b>Id</b></td>
  58. <td width=150><b>Параметр</b></td>
  59. <td width=150><b>Значение</b></td>
  60. <td width=350><b>Комментарий</b></td>
  61. <td width=100><input type="submit" onclick="return confirm('Удалить?')" name="remove" value="Удалить"></td>
  62. </tr>
  63. <?php
  64. $t_config = mysqli_query($db_link, "select config.id,option_id,option_name,value,type,description,min_value,max_value from config,config_options where config.option_id=config_options.id order by option_name");
  65. while ($row = mysqli_fetch_array($t_config)) {
  66. print "<tr align=center>\n";
  67. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  68. print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  69. print "<td class=\"data\"><input type=\"text\" name='f_config_option[]' value='{$row['option_name']}' disabled=true readonly=true></td>\n";
  70. $type = $row['type'];
  71. print "<td class=\"data\">";
  72. $option_value = $row['value'];
  73. if ($row['option_id']==29) { $option_value='********'; }
  74. if (!isset($option_value)) {
  75. $option_value = get_option($db_link, $row['option_id']);
  76. set_option($db_link, $row['option_id'], $option_value);
  77. }
  78. if ($type == 'int') {
  79. $min = '';
  80. $max = '';
  81. if (!empty($row['min_value']) or $row['min_value']==0) { $min="min=".$row['min_value']; }
  82. if (!empty($row['max_value'])) { $max="max=".$row['max_value']; }
  83. print "<input type=\"number\" name='f_config_value[]' value='$option_value' $min $max>";
  84. }
  85. if ($type == 'text') {
  86. print "<input type=\"text\" name='f_config_value[]' value='$option_value' size=30>";
  87. }
  88. if ($type == 'bool') {
  89. print_qa_select("f_config_value[]", $option_value);
  90. }
  91. print "</td>\n";
  92. print "<td class=\"data\">".$row['description']."</td>\n";
  93. print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  94. print "</tr>\n";
  95. }
  96. ?>
  97. <tr>
  98. <td colspan=5 class="data">Добавить параметр :<?php print_option_select($db_link, "f_new_option"); ?></td>
  99. <td><input type="submit" name="create" value="Добавить"></td>
  100. </tr>
  101. </table>
  102. </form>
  103. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>