devmodels.php 6.7 KB

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