control-options.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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)) {
  23. $new['value'] = $value;
  24. }
  25. //crypt password
  26. if ($option_id == 29) {
  27. $new['value']=crypt_string($value);
  28. } else {
  29. //log event if changed option not password
  30. LOG_INFO($db_link, WEB_config_set_option . " id: " . $config_id . " name: " . $option["option_name"] . " = " . $value);
  31. }
  32. if (!empty($new)) {
  33. update_record($db_link, "config", "id=" . $config_id, $new);
  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=150><b><?php print WEB_config_option; ?></b></td>
  65. <td width=150><b><?php print WEB_config_value; ?></b></td>
  66. <td width=350><b><?php print WEB_msg_comment; ?></b></td>
  67. <td class="warn">
  68. <input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>">
  69. </td>
  70. <td class="up">
  71. <button name='save'><?php print WEB_btn_save; ?></button>
  72. </td>
  73. </tr>
  74. <?php
  75. $descr_field = "description." . HTML_LANG;
  76. $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 `config`.`option_id`=`config_options`.`id` ORDER BY `option_name`");
  77. while ($row = mysqli_fetch_array($t_config)) {
  78. print "<tr align=center>\n";
  79. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[" . $row["option_id"] . "] value='" . $row['id'] . "'></td>\n";
  80. print "<td class=\"data\"><input type=\"text\" value='" . $row['option_name'] . "' disabled=true readonly=true></td>\n";
  81. $type = $row['type'];
  82. print "<td class=\"data\">";
  83. $option_value = $row['value'];
  84. if ($row['option_id'] == 29) {
  85. $option_value = '********';
  86. }
  87. if (!isset($option_value)) {
  88. $option_value = get_option($db_link, $row['option_id']);
  89. set_option($db_link, $row['option_id'], $option_value);
  90. }
  91. if ($type == 'int') {
  92. $min = '';
  93. $max = '';
  94. if (!empty($row['min_value']) or $row['min_value'] == 0) {
  95. $min = "min=" . $row['min_value'];
  96. }
  97. if (!empty($row['max_value'])) {
  98. $max = "max=" . $row['max_value'];
  99. }
  100. print "<input type=\"number\" name='f_config_value[" . $row['id'] . "]' value='$option_value' $min $max>";
  101. }
  102. if ($type == 'text') {
  103. print "<input type=\"text\" name='f_config_value[" . $row['id'] . "]' value='$option_value' size=30>";
  104. }
  105. if ($type == 'bool') {
  106. print_qa_select("f_config_value[" . $row['id'] . "]", $option_value);
  107. }
  108. if (preg_match('/^list;/',$type)) {
  109. $value_list=explode(';',$type);
  110. array_splice($value_list,0,1);
  111. print_list_select("f_config_value[" . $row['id'] . "]", $option_value,$value_list);
  112. }
  113. print "</td>\n";
  114. print "<td colspan=3 class=\"data\">" . $row[$descr_field] . "</td>\n";
  115. print "</tr>\n";
  116. }
  117. ?>
  118. <tr>
  119. <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>
  120. <td class="up" align="center"><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  121. <td colspan=2 class="data"></td>
  122. </tr>
  123. </table>
  124. </form>
  125. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>