devices_apply.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. $page_url = null;
  6. if (getPOST("ApplyForAll", $page_url) !== null) {
  7. $dev_id = getPOST("fid", $page_url, []);
  8. $a_dev_type = (int)getPOST("a_dev_type", $page_url, 0);
  9. $a_device_model_id = (int)getPOST("a_device_model_id", $page_url, 0);
  10. $a_building_id = (int)getPOST("a_building_id", $page_url, 0);
  11. $a_snmp_version = (int)getPOST("a_snmp_version", $page_url, 0);
  12. $a_ro_community = trim(getPOST("a_ro_community", $page_url, 'public'));
  13. $a_rw_community = trim(getPOST("a_rw_community", $page_url, 'private'));
  14. $all_ok = true;
  15. foreach ($dev_id as $val) {
  16. $id = (int)$val;
  17. if ($id <= 0) {
  18. continue;
  19. }
  20. $device = [];
  21. if (getPOST("e_set_type", $page_url) !== null) {
  22. $device['device_type'] = $a_dev_type;
  23. }
  24. if (getPOST("e_set_model", $page_url) !== null) {
  25. $device['device_model_id'] = $a_device_model_id;
  26. $device['vendor_id'] = get_device_model_vendor($db_link, $a_device_model_id);
  27. }
  28. if (getPOST("e_set_snmp_version", $page_url) !== null) {
  29. $device['snmp_version'] = $a_snmp_version;
  30. }
  31. if (getPOST("e_set_ro_community", $page_url) !== null) {
  32. $device['community'] = $a_ro_community;
  33. }
  34. if (getPOST("e_set_rw_community", $page_url) !== null) {
  35. $device['rw_community'] = $a_rw_community;
  36. }
  37. if (getPOST("e_set_building", $page_url) !== null) {
  38. $device['building_id'] = $a_building_id;
  39. }
  40. if (!empty($device)) {
  41. $ret = update_record($db_link, "devices", "id = ?", $device, [$id]);
  42. if (!$ret) {
  43. $all_ok = false;
  44. }
  45. }
  46. }
  47. echo $all_ok ? "Success!" : "Fail!";
  48. }
  49. ?>