devmodels.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. $default_displayed=25;
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/vendorfilter.php");
  6. if (isset($_POST['save'])) {
  7. $saved = array();
  8. //button save
  9. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  10. for ($i = 0; $i < $len; $i ++) {
  11. $save_id = intval($_POST['save'][$i]);
  12. if ($save_id == 0) { continue; }
  13. array_push($saved,$save_id);
  14. }
  15. //select box
  16. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  17. if ($len>0) {
  18. for ($i = 0; $i < $len; $i ++) {
  19. $save_id = intval($_POST['f_id'][$i]);
  20. if ($save_id == 0) { continue; }
  21. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  22. }
  23. }
  24. //save changes
  25. $len = is_array($saved) ? count($saved) : 0;
  26. for ($i = 0; $i < $len; $i ++) {
  27. $save_id = intval($saved[$i]);
  28. if ($save_id == 0) { continue; }
  29. $len_all = is_array($_POST['r_id']) ? count($_POST['r_id']) : 0;
  30. for ($j = 0; $j < $len_all; $j ++) {
  31. if (intval($_POST['r_id'][$j]) != $save_id) { continue; }
  32. if ($save_id>=10000) {
  33. $new['vendor_id'] = $_POST['f_vendor'][$j];
  34. $new['model_name'] = $_POST['f_name'][$j];
  35. $new['poe_in'] = $_POST['f_poe_in'][$j];
  36. $new['poe_out'] = $_POST['f_poe_out'][$j];
  37. }
  38. $new['nagios_template'] = $_POST['f_nagios'][$j];
  39. update_record($db_link, "device_models", "id='{$save_id}'", $new);
  40. }
  41. }
  42. header("Location: " . $_SERVER["REQUEST_URI"]);
  43. exit;
  44. }
  45. if (isset($_POST['remove'])) {
  46. $saved = array();
  47. //button save
  48. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  49. for ($i = 0; $i < $len; $i ++) {
  50. $save_id = intval($_POST['save'][$i]);
  51. if ($save_id == 0) { continue; }
  52. array_push($saved,$save_id);
  53. }
  54. //select box
  55. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  56. if ($len>0) {
  57. for ($i = 0; $i < $len; $i ++) {
  58. $save_id = intval($_POST['f_id'][$i]);
  59. if ($save_id == 0) { continue; }
  60. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  61. }
  62. }
  63. //save changes
  64. $len = is_array($saved) ? count($saved) : 0;
  65. for ($i = 0; $i < $len; $i ++) {
  66. $save_id = intval($saved[$i]);
  67. if ($save_id == 0) { continue; }
  68. $len_all = is_array($_POST['r_id']) ? count($_POST['r_id']) : 0;
  69. for ($j = 0; $j < $len_all; $j ++) {
  70. if (intval($_POST['r_id'][$j]) != $save_id) { continue; }
  71. if ($save_id>=10000) {
  72. delete_record($db_link, "device_models", "id='{$save_id}'");
  73. run_sql($db_link,"UPDATE devices set device_model_id=NULL WHERE device_model_id=".$save_id);
  74. }
  75. }
  76. }
  77. header("Location: " . $_SERVER["REQUEST_URI"]);
  78. exit;
  79. }
  80. if (isset($_POST["create"])) {
  81. $model_name = $_POST["new_model"];
  82. if (isset($model_name)) {
  83. $max_record = get_record_sql($db_link,"SELECT MAX(id) as max_id FROM device_models");
  84. if (!isset($max_record) or $max_record['max_id']<10000) { $next_id = 10000; } else { $next_id = $max_record['max_id'] + 1; }
  85. $new['vendor_id']=1;
  86. $new['id'] = $next_id;
  87. if (isset($f_vendor_select) and $f_vendor_select>1) { $new['vendor_id']=$f_vendor_select; }
  88. $new['model_name'] = $model_name;
  89. insert_record($db_link, "device_models", $new);
  90. }
  91. header("Location: " . $_SERVER["REQUEST_URI"]);
  92. exit;
  93. }
  94. unset($_POST);
  95. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  96. print_control_submenu($page_url);
  97. ?>
  98. <div id="cont">
  99. <br>
  100. <form name="def" action="devmodels.php" method="post">
  101. <table class="data">
  102. <tr>
  103. <td><b><?php echo WEB_list_models; ?></b></td>
  104. <td><?php print_vendor_select($db_link,'vendor_select',$f_vendor_select); ?></td>
  105. <td><?php print WEB_rows_at_page."&nbsp:";print_row_at_pages('rows',$displayed); ?></td>
  106. <td><input type="submit" name="OK" value="<?php print WEB_btn_show; ?>"></td>
  107. </tr>
  108. </table>
  109. <?php
  110. $v_filter='';
  111. if (!empty($f_vendor_select)) { $v_filter = "WHERE vendor_id=".$f_vendor_select; }
  112. $countSQL="SELECT Count(*) FROM device_models $v_filter";
  113. $res = mysqli_query($db_link, $countSQL);
  114. $count_records = mysqli_fetch_array($res);
  115. $total=ceil($count_records[0]/$displayed);
  116. if ($page>$total) { $page=$total; }
  117. if ($page<1) { $page=1; }
  118. $start = ($page * $displayed) - $displayed;
  119. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  120. ?>
  121. <br>
  122. <table class="data">
  123. <tr align="center">
  124. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  125. <td><b>Id</b></td>
  126. <td><b><?php echo WEB_model_vendor; ?></b></td>
  127. <td><b><?php echo WEB_cell_name; ?></b></td>
  128. <td><b><?php echo WEB_cell_poe_in; ?></b></td>
  129. <td><b><?php echo WEB_cell_poe_out; ?></b></td>
  130. <td><b><?php echo WEB_nagios_template; ?></b></td>
  131. <td><input type="submit" name='save' value="<?php echo WEB_btn_save; ?>"></td>
  132. <td><input type="submit" name='remove' value="<?php echo WEB_btn_delete; ?>"></td>
  133. </tr>
  134. <?php
  135. $t_ou = get_records_sql($db_link,'SELECT * FROM device_models '.$v_filter." ORDER BY vendor_id, model_name LIMIT $start,$displayed");
  136. foreach ($t_ou as $row) {
  137. print "<tr align=center>\n";
  138. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  139. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  140. print "<td class=\"data\" width=150>"; print_vendor_set($db_link,'f_vendor[]',$row['vendor_id']); print "</td>\n";
  141. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='{$row['model_name']}'></td>\n";
  142. print "<td class=\"data\">";print_qa_select("f_poe_in", $row['poe_in']); print "</td>\n";
  143. print "<td class=\"data\">";print_qa_select("f_poe_out", $row['poe_out']); print "</td>\n";
  144. print "<td class=\"data\"><input type=\"text\" name='f_nagios[]' value='{$row['nagios_template']}'></td>\n";
  145. print "<td class=\"data\"></td>\n";
  146. print "<td class=\"data\"></td>\n";
  147. print "</tr>\n";
  148. }
  149. ?>
  150. </table>
  151. <div><input type=text name=new_model value="Unknown">
  152. <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
  153. </div>
  154. </form>
  155. <?php
  156. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  157. ?>