diff options
| author | Antonio Gallo <tonicucoz@gmail.com> | 2011-03-02 23:48:56 +0000 | 
|---|---|---|
| committer | Antonio Gallo <tonicucoz@gmail.com> | 2011-03-02 23:48:56 +0000 | 
| commit | fdd5ccda63a6c6825035f99c3e6b6df93814cebe (patch) | |
| tree | 5ba045ff3cb29d94f8216706130471e8fa6c71a7 /h-source/Application/Controllers/GenericController.php | |
| parent | 632f611689562bb79dfb18065b6d0851a5c2077e (diff) | |
vendor is now automatically obtained from vendorid, except for notebooks
Diffstat (limited to 'h-source/Application/Controllers/GenericController.php')
| -rw-r--r-- | h-source/Application/Controllers/GenericController.php | 96 | 
1 files changed, 73 insertions, 23 deletions
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|<i>VendorID:ProductID</i> 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|<i>VendorID:ProductID</i> 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|<i>VendorID:ProductID</i> 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|<i>VendorID:ProductID</i> 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 = "<div class='alert'>Vendorid code non present in the list, please open an issue <a href='".$this->baseUrl."/issues/viewall/".Lang::$current."'>here</a> in order to ask the insertion of your vendor</div>\n"; +						return false; +					} +				} +				else +				{ +					$this->m['HardwareModel']->result = false; +					$this->m['HardwareModel']->notice = "<div class='alert'><i>VendorID:ProductID</i> has to have the following format: [a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}</div>"; +				} +			} +			else +			{ +				$this->m['HardwareModel']->result = false; +				$this->m['HardwareModel']->notice = "<div class='alert'>Vendorid:Productid code not defined..</div>\n"; +				return false; +			} +		} +		$this->m['HardwareModel']->result = false; +		return false; +	}  	protected function checkDist()  	{  | 
