Store new Model and Manufacturer when saving Monitor

This commit is contained in:
Isaac Connor 2021-07-07 09:47:00 -04:00
parent 3bb2b804b3
commit c6209ce460
1 changed files with 19 additions and 0 deletions

View File

@ -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);