control-options.php 4.2 KB

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