devmodels.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. $default_displayed=25;
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/vendorfilter.php");
  6. /*
  7. if (isset($_POST["remove"])) {
  8. $fid = $_POST["f_id"];
  9. foreach ($fid as $key => $val) {
  10. if (isset($val) and $val > 0 and $val < 10000) {
  11. $new['device_model_id'] = 0;
  12. update_record($db_link, "User_auth", "device_model_id=" . $val, $new);
  13. update_record($db_link, "devices", "device_model_id=" . $val, $new);
  14. delete_record($db_link, "device_models", "id=" . $val);
  15. }
  16. }
  17. header("Location: " . $_SERVER["REQUEST_URI"]);
  18. }
  19. */
  20. if (isset($_POST['save'])) {
  21. $saved = array();
  22. //button save
  23. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  24. for ($i = 0; $i < $len; $i ++) {
  25. $save_id = intval($_POST['save'][$i]);
  26. if ($save_id == 0) { continue; }
  27. if ($save_id <10000) { continue; }
  28. array_push($saved,$save_id);
  29. }
  30. //select box
  31. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  32. if ($len>0) {
  33. for ($i = 0; $i < $len; $i ++) {
  34. $save_id = intval($_POST['f_id'][$i]);
  35. if ($save_id == 0) { continue; }
  36. if ($save_id <10000) { continue; }
  37. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  38. }
  39. }
  40. //save changes
  41. $len = is_array($saved) ? count($saved) : 0;
  42. for ($i = 0; $i < $len; $i ++) {
  43. $save_id = intval($saved[$i]);
  44. if ($save_id == 0) { continue; }
  45. if ($save_id <10000) { continue; }
  46. $len_all = is_array($_POST['id']) ? count($_POST['id']) : 0;
  47. for ($j = 0; $j < $len_all; $j ++) {
  48. if (intval($_POST['id'][$j]) != $save_id) { continue; }
  49. $new['vendor_id'] = $_POST['f_vendor'][$j];
  50. $new['model_name'] = $_POST['f_name'][$j];
  51. $new['nagios_template'] = $_POST['f_nagios'][$j];
  52. update_record($db_link, "device_models", "id='{$save_id}'", $new);
  53. }
  54. }
  55. header("Location: " . $_SERVER["REQUEST_URI"]);
  56. }
  57. if (isset($_POST["create"])) {
  58. $model_name = $_POST["new_model"];
  59. if (isset($model_name)) {
  60. $max_record = get_record_sql($db_link,"SELECT MAX(id) as max_id FROM device_models");
  61. if (!isset($max_record) or $max_record['max_id']<10000) { $next_id = 10000; } else { $next_id = $max_record['max_id'] + 1; }
  62. $new['vendor_id']=1;
  63. $new['id'] = $next_id;
  64. if (isset($f_vendor_select) and $f_vendor_select>1) { $new['vendor_id']=$f_vendor_select; }
  65. $new['model_name'] = $model_name;
  66. insert_record($db_link, "device_models", $new);
  67. }
  68. header("Location: " . $_SERVER["REQUEST_URI"]);
  69. }
  70. unset($_POST);
  71. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  72. print_device_submenu($page_url);
  73. ?>
  74. <div id="cont">
  75. <form name="def" action="devmodels.php" method="post">
  76. <table class="data">
  77. <tr>
  78. <td><b>Список моделей</b></td>
  79. <td><?php print_vendor_select($db_link,'vendor_select',$f_vendor_select); ?></td>
  80. <td>Отображать:<?php print_row_at_pages('rows',$displayed); ?></td>
  81. <td><input type="submit" name="OK" value="Показать"></td>
  82. </tr>
  83. </table>
  84. <?php
  85. $v_filter='';
  86. if (!empty($f_vendor_select)) { $v_filter = "WHERE vendor_id=".$f_vendor_select; }
  87. $countSQL="SELECT Count(*) FROM device_models $v_filter";
  88. $res = mysqli_query($db_link, $countSQL);
  89. $count_records = mysqli_fetch_array($res);
  90. $total=ceil($count_records[0]/$displayed);
  91. if ($page>$total) { $page=$total; }
  92. if ($page<1) { $page=1; }
  93. $start = ($page * $displayed) - $displayed;
  94. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  95. ?>
  96. <table class="data">
  97. <tr align="center">
  98. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  99. <td><b>Id</b></td>
  100. <td><b>Производитель</b></td>
  101. <td><b>Название</b></td>
  102. <td><b>Шаблон Nagios</b></td>
  103. <td><input type="submit" name='save' value="Сохранить"></td>
  104. </tr>
  105. <?
  106. $t_ou = get_records_sql($db_link,'SELECT * FROM device_models '.$v_filter." ORDER BY vendor_id, model_name LIMIT $start,$displayed");
  107. foreach ($t_ou as $row) {
  108. print "<tr align=center>\n";
  109. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  110. print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  111. print "<td class=\"data\" width=150>"; print_vendor_set($db_link,'f_vendor[]',$row['vendor_id']); print "</td>\n";
  112. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='{$row['model_name']}'></td>\n";
  113. print "<td class=\"data\"><input type=\"text\" name='f_nagios[]' value='{$row['nagios_template']}'></td>\n";
  114. print "<td class=\"data\"></td>\n";
  115. print "</tr>\n";
  116. }
  117. ?>
  118. </table>
  119. <table>
  120. <tr>
  121. <td><input type=text name=new_model value="Unknown"></td>
  122. <td><input type="submit" name="create" value="Добавить"></td>
  123. <td align="right"></td>
  124. </tr>
  125. </table>
  126. </form>
  127. <?php
  128. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  129. ?>