building.php 3.2 KB

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