control-options.php 3.8 KB

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