From c6209ce460e4b942d42e9c0a84c10e6f06f38ab5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 7 Jul 2021 09:47:00 -0400 Subject: [PATCH] Store new Model and Manufacturer when saving Monitor --- web/includes/actions/monitor.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/web/includes/actions/monitor.php b/web/includes/actions/monitor.php index 1c6e1f72f..3fafb0f82 100644 --- a/web/includes/actions/monitor.php +++ b/web/includes/actions/monitor.php @@ -45,6 +45,25 @@ if ( $action == 'save' ) { $x10Monitor = array(); } } + if ( !$_REQUEST['newMonitor[ManufacturerId'] and ($_REQUEST['newMonitor[Manufacturer'] != '') ) { + # Need to add a new Manufacturer entry + $newManufacturer = ZM\Manufacturer::find_one(array('Name'=>$_REQUEST['newMonitor[Manufacturer'])); + if (!$newManufacturer) { + $newManufacturer = new ZM\Manufacturer(); + $newManufacturer->save(array('Name'=>$_REQUEST['newMonitor[Manufacturer'])); + } + $_REQUEST['newMonitor[ManufacturerId'] = $newManufacturer->Id(); + } + + if ( !$_REQUEST['newMonitor[ModelId'] and ($_REQUEST['newMonitor[Model'] != '') ) { + # Need to add a new Model entry + $newModel = ZM\Model::find_one(array('Name'=>$_REQUEST['newMonitor[Model'])); + if (!$newModel) { + $newModel = new ZM\Model(); + $newMdoel->save(array('Name'=>$_REQUEST['newMonitor[Model'], 'ManufacturerId'=>$_REQUEST['newMonitor[ManufacturerId'])); + } + $_REQUEST['newMonitor[ModelId'] = $newModel->Id(); + } $monitor = new ZM\Monitor($mid);