1
0

control-options.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. if (getPOST("remove")) {
  5. $fid = getPOST("f_id", null, []);
  6. if (!empty($fid) && is_array($fid)) {
  7. foreach ($fid as $option_id => $config_id) {
  8. $option_id = (int)$option_id;
  9. $config_id = (int)$config_id;
  10. if ($option_id <= 0 || $config_id <= 0) continue;
  11. $opt_def = get_record($db_link, "config_options", "id = ?", [$option_id]);
  12. if ($opt_def) {
  13. LOG_INFO($db_link, WEB_config_remove_option . " id: " . $config_id . " name: " . ($opt_def["option_name"] ?? ''));
  14. }
  15. delete_record($db_link, "config", "id = ?", [$config_id]);
  16. }
  17. }
  18. header("Location: " . $_SERVER["REQUEST_URI"]);
  19. exit;
  20. }
  21. if (getPOST("save")) {
  22. $fid = getPOST("f_id", null, []);
  23. $f_config_value = getPOST("f_config_value", null, []);
  24. if (!empty($fid) && is_array($fid)) {
  25. foreach ($fid as $option_id => $config_id) {
  26. $option_id = (int)$option_id;
  27. $config_id = (int)$config_id;
  28. if ($option_id <= 0 || $config_id <= 0) continue;
  29. $value = trim($f_config_value[$config_id] ?? '');
  30. $option = get_record($db_link, "config_options", "id = ?", [$option_id]);
  31. if (!$option) continue;
  32. $new = [];
  33. if ($option_id == 29) {
  34. // Пароль — шифруем
  35. $new['value'] = crypt_string($value);
  36. } else {
  37. // Обычное значение
  38. $new['value'] = $value;
  39. LOG_INFO($db_link, WEB_config_set_option . " id: " . $config_id . " name: " . ($option["option_name"] ?? '') . " = " . $value);
  40. }
  41. if (!empty($new)) {
  42. update_record($db_link, "config", "id = ?", $new, [$config_id]);
  43. }
  44. }
  45. }
  46. header("Location: " . $_SERVER["REQUEST_URI"]);
  47. exit;
  48. }
  49. if (getPOST("create")) {
  50. $new_option = (int)getPOST("f_new_option", null, 0);
  51. if ($new_option > 0) {
  52. $opt_def = get_record($db_link, "config_options", "id = ?", [$new_option]);
  53. if ($opt_def) {
  54. $new = [
  55. 'option_id' => $new_option,
  56. 'value' => get_option($db_link, $new_option)
  57. ];
  58. LOG_INFO($db_link, WEB_config_add_option . " id: " . $new_option . " name: " . ($opt_def["option_name"] ?? '') . " = " . ($new['value'] ?? ''));
  59. insert_record($db_link, "config", $new);
  60. }
  61. }
  62. header("Location: " . $_SERVER["REQUEST_URI"]);
  63. exit;
  64. }
  65. unset($_POST);
  66. fix_auth_rules($db_link);
  67. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  68. print_control_submenu($page_url);
  69. ?>
  70. <div id="cont">
  71. <br>
  72. <form name="def" action="control-options.php" method="post">
  73. <br><b><?php print WEB_config_parameters; ?></b><br>
  74. <table class="data" width=800>
  75. <tr align="center">
  76. <td width=20><input type="checkbox" onClick="checkAll(this.checked);"></td>
  77. <td width=150><b><?php print WEB_config_option; ?></b></td>
  78. <td width=150><b><?php print WEB_config_value; ?></b></td>
  79. <td width=350><b><?php print WEB_msg_description; ?></b></td>
  80. <td class="warn">
  81. <input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>">
  82. </td>
  83. <td class="up">
  84. <button name='save' value='save'><?php print WEB_btn_save; ?></button>
  85. </td>
  86. </tr>
  87. <?php
  88. $descr_field = "description_" . HTML_LANG;
  89. $config_sql = "SELECT config.id,option_id,option_name,value,option_type," . $descr_field . ",min_value,max_value FROM config,config_options WHERE config.option_id=config_options.id AND config_options.draft=0 ORDER BY option_name";
  90. $t_config = get_records_sql($db_link, $config_sql);
  91. foreach ($t_config as $row) {
  92. print "<tr align=center>\n";
  93. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[" . $row["option_id"] . "] value='" . $row['id'] . "'></td>\n";
  94. print "<td class=\"data\"><input type=\"text\" value='" . $row['option_name'] . "' disabled=true readonly=true></td>\n";
  95. $type = $row['option_type'];
  96. print "<td class=\"data\">";
  97. $option_value = $row['value'];
  98. if ($row['option_id'] == 29) {
  99. $option_value = '********';
  100. }
  101. if (!isset($option_value)) {
  102. $option_value = get_option($db_link, $row['option_id']);
  103. set_option($db_link, $row['option_id'], $option_value);
  104. }
  105. if ($type == 'int') {
  106. $min = '';
  107. $max = '';
  108. if (!empty($row['min_value']) or $row['min_value']==0) {
  109. $min = "min=" . $row['min_value'];
  110. }
  111. if (!empty($row['max_value'])) {
  112. $max = "max=" . $row['max_value'];
  113. }
  114. print "<input type=\"number\" name='f_config_value[" . $row['id'] . "]' value='$option_value' $min $max>";
  115. }
  116. if ($type == 'text') {
  117. print "<input type=\"text\" name='f_config_value[" . $row['id'] . "]' value='$option_value' size=30>";
  118. }
  119. if ($type == 'bool') {
  120. print_qa_select("f_config_value[" . $row['id'] . "]", $option_value);
  121. }
  122. if (preg_match('/^list;/',$type)) {
  123. $value_list=explode(';',$type);
  124. array_splice($value_list,0,1);
  125. print_list_select("f_config_value[" . $row['id'] . "]", $option_value,$value_list);
  126. }
  127. print "</td>\n";
  128. print "<td colspan=3 class=\"data\">" . $row[$descr_field] . "</td>\n";
  129. print "</tr>\n";
  130. }
  131. ?>
  132. <tr>
  133. <td colspan=4 class="data"><?php print WEB_btn_add . " " . mb_strtolower(WEB_config_option) . ":&nbsp"; print_option_select($db_link, "f_new_option"); ?></td>
  134. <td class="up" align="center"><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  135. <td colspan=2 class="data"></td>
  136. </tr>
  137. </table>
  138. </form>
  139. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>