diff --git a/api/v1/get/equipments.php b/api/v1/get/equipments.php index 5b085a6..2b45597 100644 --- a/api/v1/get/equipments.php +++ b/api/v1/get/equipments.php @@ -51,7 +51,7 @@ if(isset($get_content) && $get_content!=''){ $v = explode("=", $y); //INCLUDE VARIABLES IN ARRAY $criterias[$v[0]] = $v[1]; - if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='download'){ + if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='download' || $v[0] =='sort'){ //do nothing } elseif ($v[0] == 'equipmentid') { @@ -124,8 +124,52 @@ elseif (isset($criterias['history']) && $criterias['history'] ==''){ $sql ='SELECT h.rowID as historyID, e.rowID as equipmentID, h.equipmentid as h_equipmentid, e.serialnumber, h.type, h.description, h.created, h.createdby from history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.''; } else { + // GET SORT INDICATOR + $sort_indicator = $criterias['sort'] ?? ''; + + /* + 1 Serialnumber ASC + 2 Serialnumber DESC + 3 Status ASC + 4 Status DESC + 5 Warranty ASC + 6 Warranty DESC + 7 Service ASC + 8 Service DESC + */ + + switch ($sort_indicator){ + case 1: + $sort = ' e.serialnumber ASC '; + break; + case 2: + $sort = ' e.serialnumber DESC '; + break; + case 3: + $sort = ' e.status ASC '; + break; + case 4: + $sort = ' e.status DESC '; + break; + case 5: + $sort = ' e.warranty_date ASC '; + break; + case 6: + $sort = ' e.warranty_date DESC '; + break; + case 7: + $sort = ' e.service_date ASC '; + break; + case 8: + $sort = ' e.service_date DESC '; + break; + default: + $sort = ' equipmentID '; + break; + } + //SQL for Paging - $sql = 'SELECT e.rowID as equipmentID, e.productrowid, e.serialnumber, e.status, e.created, e.createdby, e.hw_version, e.sw_version, e.accounthierarchy, e.service_date, e.warranty_date, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY equipmentID LIMIT :page,:num_products'; + $sql = 'SELECT e.rowID as equipmentID, e.productrowid, e.serialnumber, e.status, e.created, e.createdby, e.hw_version, e.sw_version, e.accounthierarchy, e.service_date, e.warranty_date, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products'; } $stmt = $pdo->prepare($sql); diff --git a/equipments.php b/equipments.php index 740e2c1..1a01238 100644 --- a/equipments.php +++ b/equipments.php @@ -24,6 +24,7 @@ $create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permis //GET PARAMETERS $pagination_page = isset($_GET['p']) ? $_GET['p'] : 1; $status = isset($_GET['status']) ? '&status='.$_GET['status'] : ''; +$sort = isset($_GET['sort']) ? '&sort='.$_GET['sort'] : ''; $search = isset($_GET['search']) ? '&search='.$_GET['search'] : ''; $software = isset($_GET['firmware']) ? '&firmware='.$_GET['firmware'] : ''; $servicedate = isset($_GET['servicedate']) ? '&servicedate='.$_GET['servicedate'] : ''; @@ -31,7 +32,7 @@ $warrantydate = isset($_GET['warrantydate']) ? '&warrantydate='.$_GET['warrantyd $partnerid = isset($_GET['partnerid']) ? '&partnerid='.$_GET['partnerid'] : ''; // Determine the URL -$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid; +$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort; //GET Details from URL $GET_VALUES = urlGETdetails($_GET) ?? ''; //CALL TO API @@ -103,6 +104,24 @@ $view .= ' + + + + +