building.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. if (isset($_POST["remove"])) {
  5. $fid = $_POST["f_id"];
  6. foreach ($fid as $key => $val) {
  7. if (isset($val) and $val > 1) {
  8. LOG_INFO($db_link,'Удаляем расположение с id: '.$val);
  9. delete_record($db_link, "building", "id=" . $val);
  10. }
  11. }
  12. header("Location: " . $_SERVER["REQUEST_URI"]);
  13. exit;
  14. }
  15. if (isset($_POST['save'])) {
  16. $len = is_array($_POST['id']) ? count($_POST['id']) : 0;
  17. for ($i = 0; $i < $len; $i ++) {
  18. $save_id = intval($_POST['save'][$i]);
  19. if ($save_id == 0) {
  20. continue;
  21. }
  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) {
  25. continue;
  26. }
  27. $value = $_POST['f_building_name'][$j];
  28. $value_comment = $_POST['f_building_comment'][$j];
  29. if (isset($value)) {
  30. $new['name'] = $value;
  31. $new['comment'] = $value_comment;
  32. LOG_INFO($db_link,"Изменяем расположение id='{$save_id}': name=".$value." comment=".$value_comment);
  33. update_record($db_link, "building", "id='{$save_id}'", $new);
  34. }
  35. }
  36. }
  37. header("Location: " . $_SERVER["REQUEST_URI"]);
  38. exit;
  39. }
  40. if (isset($_POST["create"])) {
  41. $building_name = $_POST["new_building"];
  42. if (isset($building_name)) {
  43. $new['name'] = $building_name;
  44. LOG_INFO($db_link,'Добавляем расположение $building_name');
  45. insert_record($db_link, "building", $new);
  46. }
  47. header("Location: " . $_SERVER["REQUEST_URI"]);
  48. exit;
  49. }
  50. unset($_POST);
  51. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  52. print_device_submenu($page_url);
  53. ?>
  54. <div id="cont">
  55. <form name="def" action="building.php" method="post">
  56. <table class="data">
  57. <tr align="center">
  58. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  59. <td><b>id</b></td>
  60. <td><b>Название</b></td>
  61. <td><b>Комментарий</b></td>
  62. <td><input type="submit" onclick="return confirm('Удалить?')" name="remove" value="Удалить"></td>
  63. </tr>
  64. <?php
  65. $t_building = get_records($db_link,'building','TRUE ORDER BY id');
  66. foreach ($t_building as $row) {
  67. print "<tr align=center>\n";
  68. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  69. print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  70. print "<td class=\"data\"><input type=\"text\" name='f_building_name[]' value='{$row['name']}'></td>\n";
  71. print "<td class=\"data\"><input type=\"text\" name='f_building_comment[]' value='{$row['comment']}'></td>\n";
  72. print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  73. print "</tr>\n";
  74. }
  75. ?>
  76. </table>
  77. <table>
  78. <tr>
  79. <td><input type=text name=new_building value="Unknown"></td>
  80. <td><input type="submit" name="create" value="Добавить"></td>
  81. <td align="right"></td>
  82. </tr>
  83. </table>
  84. </form>
  85. <?php
  86. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  87. ?>