building.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. foreach ($fid as $key => $val) {
  7. if (isset($val) and $val > 1) {
  8. LOG_INFO($db_link,'Remove building id: '. $val .' '. dump_record($db_link,'building','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['r_id']) ? count($_POST['r_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['r_id']) ? count($_POST['r_id']) : 0;
  23. for ($j = 0; $j < $len_all; $j ++) {
  24. if (intval($_POST['r_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,"Change building 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,'Add building $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_control_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><?php echo WEB_cell_name; ?></b></td>
  61. <td><b><?php echo WEB_cell_comment; ?></b></td>
  62. <td>
  63. <input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="remove" value="<?php print WEB_btn_remove; ?>">
  64. </td>
  65. </tr>
  66. <?php
  67. $t_building = get_records($db_link,'building','TRUE ORDER BY id');
  68. foreach ($t_building as $row) {
  69. print "<tr align=center>\n";
  70. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  71. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  72. print "<td class=\"data\"><input type=\"text\" name='f_building_name[]' value='{$row['name']}'></td>\n";
  73. print "<td class=\"data\"><input type=\"text\" name='f_building_comment[]' value='{$row['comment']}'></td>\n";
  74. print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  75. print "</tr>\n";
  76. }
  77. ?>
  78. </table>
  79. <table>
  80. <tr>
  81. <td><input type=text name=new_building value="Unknown"></td>
  82. <td>
  83. <input type="submit" name="create" value="<?php print WEB_btn_add; ?>">
  84. </td>
  85. <td align="right"></td>
  86. </tr>
  87. </table>
  88. </form>
  89. <?php
  90. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  91. ?>