control-options.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. if (!empty($_POST["f_id"])) {
  6. $fid = $_POST["f_id"];
  7. foreach ($fid as $option_id => $config_id) {
  8. $opt_def = get_record($db_link, "config_options", "id=" . $option_id);
  9. LOG_INFO($db_link, WEB_config_remove_option . " id: " . $config_id . " name: " . $opt_def["option_name"]);
  10. delete_record($db_link, "config", "id=" . $config_id);
  11. }
  12. }
  13. header("Location: " . $_SERVER["REQUEST_URI"]);
  14. exit;
  15. }
  16. if (isset($_POST['save'])) {
  17. if (!empty($_POST["f_id"])) {
  18. $fid = $_POST["f_id"];
  19. foreach ($fid as $option_id => $config_id) {
  20. $value = $_POST['f_config_value'][$config_id];
  21. $option = get_record_sql($db_link, "SELECT * FROM config_options WHERE id=" . $option_id);
  22. if (isset($value) and $value !== '********') {
  23. $new['value'] = $value;
  24. }
  25. LOG_INFO($db_link, WEB_config_set_option . " id: " . $config_id . " name: " . $opttion["option_name"] . " = " . $value);
  26. if (!empty($new)) {
  27. update_record($db_link, "config", "id=" . $config_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. $opt_def = get_record($db_link, "config_options", "id=$new_option");
  40. LOG_INFO($db_link, WEB_config_add_option . " id: " . $new_option . " name: " . $opt_def["option_name"] . " = " . $new['value']);
  41. insert_record($db_link, "config", $new);
  42. }
  43. header("Location: " . $_SERVER["REQUEST_URI"]);
  44. exit;
  45. }
  46. unset($_POST);
  47. fix_auth_rules($db_link);
  48. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  49. print_control_submenu($page_url);
  50. ?>
  51. <div id="cont">
  52. <br>
  53. <form name="def" action="control-options.php" method="post">
  54. <br><b><?php print WEB_config_parameters; ?></b><br>
  55. <table class="data" width=800>
  56. <tr align="center">
  57. <td width=20><input type="checkbox" onClick="checkAll(this.checked);"></td>
  58. <td width=150><b><?php print WEB_config_option; ?></b></td>
  59. <td width=150><b><?php print WEB_config_value; ?></b></td>
  60. <td width=350><b><?php print WEB_msg_comment; ?></b></td>
  61. <td class="warn">
  62. <input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>">
  63. </td>
  64. <td class="up">
  65. <button name='save'><?php print WEB_btn_save; ?></button>
  66. </td>
  67. </tr>
  68. <?php
  69. $descr_field = "description." . HTML_LANG;
  70. $t_config = mysqli_query($db_link, "SELECT `config`.`id`,`option_id`,`option_name`,`value`,`type`,`" . $descr_field . "`,`min_value`,`max_value` FROM `config`,`config_options` WHERE
  71. `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[" . $row["option_id"] . "] value='" . $row['id'] . "'></td>\n";
  75. print "<td class=\"data\"><input type=\"text\" value='" . $row['option_name'] . "' disabled=true readonly=true></td>\n";
  76. $type = $row['type'];
  77. print "<td class=\"data\">";
  78. $option_value = $row['value'];
  79. if ($row['option_id'] == 29) {
  80. $option_value = '********';
  81. }
  82. if (!isset($option_value)) {
  83. $option_value = get_option($db_link, $row['option_id']);
  84. set_option($db_link, $row['option_id'], $option_value);
  85. }
  86. if ($type == 'int') {
  87. $min = '';
  88. $max = '';
  89. if (!empty($row['min_value']) or $row['min_value'] == 0) {
  90. $min = "min=" . $row['min_value'];
  91. }
  92. if (!empty($row['max_value'])) {
  93. $max = "max=" . $row['max_value'];
  94. }
  95. print "<input type=\"number\" name='f_config_value[" . $row['id'] . "]' value='$option_value' $min $max>";
  96. }
  97. if ($type == 'text') {
  98. print "<input type=\"text\" name='f_config_value[" . $row['id'] . "]' value='$option_value' size=30>";
  99. }
  100. if ($type == 'bool') {
  101. print_qa_select("f_config_value[" . $row['id'] . "]", $option_value);
  102. }
  103. print "</td>\n";
  104. print "<td colspan=3 class=\"data\">" . $row[$descr_field] . "</td>\n";
  105. print "</tr>\n";
  106. }
  107. ?>
  108. <tr>
  109. <td colspan=4 class="data"><?php print WEB_btn_add . " " . mb_strtolower(WEB_config_option) . ":&nbsp";
  110. print_option_select($db_link, "f_new_option"); ?></td>
  111. <td class="up" align="center"><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  112. <td colspan=2 class="data"></td>
  113. </tr>
  114. </table>
  115. </form>
  116. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>