1
0

devmodels.php 5.0 KB

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