Sort on equipments

This commit is contained in:
“VeLiTi”
2024-03-19 11:53:44 +01:00
parent 670b00eeab
commit 618f3b1947
4 changed files with 74 additions and 3 deletions

View File

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