control-options.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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['r_id']) ? count($_POST['r_id']) : 0;
  23. for ($j = 0; $j < $len_all; $j ++) {
  24. if (intval($_POST['r_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_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>"></td>
  69. </tr>
  70. <?php
  71. $descr_field = "description.".HTML_LANG;
  72. $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
  73. `config`.`option_id`=`config_options`.`id` ORDER BY `option_name`");
  74. while ($row = mysqli_fetch_array($t_config)) {
  75. print "<tr align=center>\n";
  76. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  77. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  78. print "<td class=\"data\"><input type=\"text\" name='f_config_option[]' value='{$row['option_name']}' disabled=true readonly=true></td>\n";
  79. $type = $row['type'];
  80. print "<td class=\"data\">";
  81. $option_value = $row['value'];
  82. if ($row['option_id']==29) { $option_value='********'; }
  83. if (!isset($option_value)) {
  84. $option_value = get_option($db_link, $row['option_id']);
  85. set_option($db_link, $row['option_id'], $option_value);
  86. }
  87. if ($type == 'int') {
  88. $min = '';
  89. $max = '';
  90. if (!empty($row['min_value']) or $row['min_value']==0) { $min="min=".$row['min_value']; }
  91. if (!empty($row['max_value'])) { $max="max=".$row['max_value']; }
  92. print "<input type=\"number\" name='f_config_value[]' value='$option_value' $min $max>";
  93. }
  94. if ($type == 'text') {
  95. print "<input type=\"text\" name='f_config_value[]' value='$option_value' size=30>";
  96. }
  97. if ($type == 'bool') {
  98. print_qa_select("f_config_value[]", $option_value);
  99. }
  100. print "</td>\n";
  101. print "<td class=\"data\">".$row[$descr_field]."</td>\n";
  102. print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  103. print "</tr>\n";
  104. }
  105. ?>
  106. <tr>
  107. <td colspan=5 class="data"><?php print WEB_btn_add." ".mb_strtolower(WEB_config_option).":&nbsp"; print_option_select($db_link, "f_new_option"); ?></td>
  108. <td><input type="submit" name="create" value="<?php echo WEB_btn_add; ?>"></td>
  109. </tr>
  110. </table>
  111. </form>
  112. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>