edit_l3int.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. $sSQL = "SELECT * FROM devices WHERE id=$id";
  6. $device_info = get_record_sql($db_link, $sSQL);
  7. if (isset($_POST["s_remove"])) {
  8. $s_id = $_POST["s_id"];
  9. foreach ($s_id as $key => $val) {
  10. if (isset($val)) {
  11. LOG_INFO($db_link, "Remove l3_interface id: $val");
  12. delete_record($db_link, "device_l3_interfaces", "id=" . $val);
  13. }
  14. }
  15. header("Location: " . $_SERVER["REQUEST_URI"]);
  16. }
  17. if (isset($_POST['s_save'])) {
  18. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  19. for ($i = 0; $i < $len; $i ++) {
  20. $save_id = intval($_POST['s_save'][$i]);
  21. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  22. for ($j = 0; $j < $len_all; $j ++) {
  23. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  24. $new['name'] = trim($_POST['s_name'][$j]);
  25. $new['interface_type'] = $_POST['s_type'][$j]*1;
  26. update_record($db_link, "device_l3_interfaces", "id='{$save_id}'", $new);
  27. }
  28. }
  29. header("Location: " . $_SERVER["REQUEST_URI"]);
  30. }
  31. if (isset($_POST["s_create"])) {
  32. if (!empty($_POST["s_create_name"])) {
  33. $new['name'] = trim($_POST["s_create_name"]);
  34. $new['device_id'] = $id;
  35. $new['interface_type'] = 0;
  36. LOG_INFO($db_link, "Create new l3_interface ".$new['name']." as local");
  37. insert_record($db_link, "device_l3_interfaces", $new);
  38. }
  39. header("Location: " . $_SERVER["REQUEST_URI"]);
  40. }
  41. unset($_POST);
  42. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  43. ?>
  44. <div id="cont">
  45. <br>
  46. <form name="def" action="edit_l3int.php" method="post">
  47. <b>Список L3 интерфейсов <?php print_url($device_info['device_name'],"/admin/devices/editdevice.php?id=$id"); ?></b> <br>
  48. <table class="data">
  49. <tr align="center">
  50. <td></td>
  51. <td width=30><b>id</b></td>
  52. <td><b>Название</b></td>
  53. <td><b>Тип</b></td>
  54. <td><input type="submit" onclick="return confirm('Удалить?')" name="s_remove" value="Удалить"></td>
  55. </tr>
  56. <?
  57. $t_l3_interface = get_records($db_link,'device_l3_interfaces',"device_id=$id ORDER BY name");
  58. foreach ( $t_l3_interface as $row ) {
  59. print "<tr align=center>\n";
  60. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  61. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  62. print "<td class=\"data\"><input type=\"text\" name='s_name[]' value='{$row['name']}'></td>\n";
  63. print "<td class=\"data\">"; print_qa_l3int_select('s_type[]',$row['interface_type']); print "</td>\n";
  64. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  65. print "</tr>\n";
  66. }
  67. ?>
  68. <tr>
  69. <td colspan=4>Добавить интерфейс :<?php print "<input type=\"text\" name='s_create_name' value=''";?>
  70. </td>
  71. <td><input type="submit" name="s_create" value="Добавить"></td>
  72. </tr>
  73. </table>
  74. </form>
  75. <?php
  76. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  77. ?>