aboutsummaryrefslogtreecommitdiff
path: root/h-source/Application/Controllers/GenericController.php
diff options
context:
space:
mode:
Diffstat (limited to 'h-source/Application/Controllers/GenericController.php')
-rw-r--r--h-source/Application/Controllers/GenericController.php96
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()
{