1
0

devices_apply.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. if (!defined("CONFIG")) die("Not defined");
  5. if (isset($_POST["ApplyForAll"])) {
  6. $dev_id = $_POST["fid"];
  7. if (empty($_POST["a_dev_type"])) { $_POST["a_dev_type"] = 0; }
  8. if (empty($_POST["a_device_model_id"])) { $_POST["a_device_model_id"] = 0; }
  9. if (empty($_POST["a_building_id"])) { $_POST["a_building_id"] = 0; }
  10. if (empty($_POST["a_snmp_version"])) { $_POST["a_snmp_version"] = 0; }
  11. if (empty($_POST["a_ro_community"])) { $_POST["a_ro_community"] = 'public'; }
  12. if (empty($_POST["a_rw_community"])) { $_POST["a_rw_community"] = 'private'; }
  13. $a_dev_type = $_POST["a_dev_type"];
  14. $a_device_model_id = $_POST["a_device_model_id"];
  15. $a_building_id = $_POST["a_building_id"];
  16. $a_snmp_version = $_POST["a_snmp_version"];
  17. $a_ro_community = $_POST["a_ro_community"];
  18. $a_rw_community = $_POST["a_rw_community"];
  19. $msg = "Massive change devices!";
  20. LOG_WARNING($db_link, $msg);
  21. $all_ok = 1;
  22. foreach ($dev_id as $key => $val) {
  23. if (!empty($val)) {
  24. unset($device);
  25. if (isset($_POST["e_set_type"])) { $device['device_type'] = $a_dev_type; }
  26. if (isset($_POST["e_set_model"])) {
  27. $device['device_model_id'] = $a_device_model_id;
  28. $device['vendor_id'] = get_device_model_vendor($db_link,$a_device_model_id);
  29. }
  30. //snmp
  31. if (isset($_POST["e_set_snmp_version"])) { $device['snmp_version'] = $a_snmp_version * 1; }
  32. if (isset($_POST["e_set_ro_community"])) { $device['community'] = $a_ro_community; }
  33. if (isset($_POST["e_set_rw_community"])) { $device['rw_community'] = $a_rw_community; }
  34. //location
  35. if (isset($_POST["e_set_building"])) { $device['building_id'] = $a_building_id * 1; }
  36. if (!empty($device)) {
  37. $ret = update_record($db_link, "devices", "id='" . $val . "'", $device);
  38. if (!$ret) { $all_ok = 0; }
  39. }
  40. }
  41. }
  42. if ($all_ok) {
  43. print "Success!";
  44. } else {
  45. print "Fail!";
  46. }
  47. }