control-options.php 5.0 KB

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