From fdd5ccda63a6c6825035f99c3e6b6df93814cebe Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Wed, 2 Mar 2011 23:48:56 +0000 Subject: vendor is now automatically obtained from vendorid, except for notebooks --- .../Application/Controllers/GenericController.php | 96 ++++++++++++++++------ 1 file changed, 73 insertions(+), 23 deletions(-) (limited to 'h-source/Application/Controllers/GenericController.php') diff --git a/h-source/Application/Controllers/GenericController.php b/h-source/Application/Controllers/GenericController.php index 884f915..f58fa24 100644 --- a/h-source/Application/Controllers/GenericController.php +++ b/h-source/Application/Controllers/GenericController.php @@ -79,25 +79,31 @@ class GenericController extends BaseController { if ($this->checkDist()) { - $pci_id = $this->request->post('pci_id','','sanitizeAll'); - if (strcmp($pci_id,'') !== 0) + if ($this->checkVendorId()) { - $this->m['HardwareModel']->databaseConditions['insert']['+checkUnique'] = 'pci_id|VendorID:ProductID is already present in the database. This means that the device you are trying to insert is already in the database'; - } - - //insert the new device - $this->m['HardwareModel']->updateTable('insert'); - - if ($this->m['HardwareModel']->queryResult) - { - if (strcmp($this->controller,'notebooks') === 0) + $pci_id = $this->request->post('pci_id','','sanitizeAll'); + + if (strcmp($this->m['HardwareModel']->type,'notebook') !== 0) + { + $this->m['HardwareModel']->values['vendor'] = sanitizeAll(Vendors::getName($pci_id)); + + $this->m['HardwareModel']->databaseConditions['insert']['+checkUnique'] = 'pci_id|VendorID:ProductID is already present in the database. This means that the device you are trying to insert is already in the database'; + } + + //insert the new device + $this->m['HardwareModel']->updateTable('insert'); + + if ($this->m['HardwareModel']->queryResult) { - session_start(); - $_SESSION['notebook_inserted'] = 'yes'; + if (strcmp($this->controller,'notebooks') === 0) + { + session_start(); + $_SESSION['notebook_inserted'] = 'yes'; + } } + + $this->viewRedirect($this->m['HardwareModel']->lastId); } - - $this->viewRedirect($this->m['HardwareModel']->lastId); } } @@ -216,16 +222,22 @@ class GenericController extends BaseController { if ($this->checkDist()) { - $pci_id = $this->request->post('pci_id','','sanitizeAll'); - if (strcmp($pci_id,'') !== 0) + if ($this->checkVendorId()) { - $this->m['HardwareModel']->databaseConditions['update']['+checkUniqueCompl'] = 'pci_id|VendorID:ProductID is already present in the database. This means that the device you are trying to insert is already in the database'; + $pci_id = $this->request->post('pci_id','','sanitizeAll'); + + if (strcmp($this->m['HardwareModel']->type,'notebook') !== 0) + { + $this->m['HardwareModel']->values['vendor'] = sanitizeAll(Vendors::getName($pci_id)); + + $this->m['HardwareModel']->databaseConditions['update']['+checkUniqueCompl'] = 'pci_id|VendorID:ProductID is already present in the database. This means that the device you are trying to insert is already in the database'; + } + + //carry out the update database action + $this->m['HardwareModel']->updateTable('update'); + + $this->viewRedirect($this->m['HardwareModel']->lastId); } - - //carry out the update database action - $this->m['HardwareModel']->updateTable('update'); - - $this->viewRedirect($this->m['HardwareModel']->lastId); } } @@ -260,6 +272,44 @@ class GenericController extends BaseController $this->redirect($this->controller.'/catalogue/'.$this->lang); } } + + protected function checkVendorId() + { + if (strcmp($this->m['HardwareModel']->type,'notebook') === 0) return true; + + if (array_key_exists('pci_id',$_POST)) + { + if (strcmp($_POST['pci_id'],"") !== 0) + { + if (preg_match('/^[a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}$/',$_POST['pci_id'])) + { + if (Vendors::check($_POST['pci_id'])) + { + return true; + } + else + { + $this->m['HardwareModel']->result = false; + $this->m['HardwareModel']->notice = "
Vendorid code non present in the list, please open an issue here in order to ask the insertion of your vendor
\n"; + return false; + } + } + else + { + $this->m['HardwareModel']->result = false; + $this->m['HardwareModel']->notice = "
VendorID:ProductID has to have the following format: [a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}
"; + } + } + else + { + $this->m['HardwareModel']->result = false; + $this->m['HardwareModel']->notice = "
Vendorid:Productid code not defined..
\n"; + return false; + } + } + $this->m['HardwareModel']->result = false; + return false; + } protected function checkDist() { -- cgit v1.2.3