<?php
include("../../db/dbconnect.php");
$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
$mysqltable = $_GET['table'];
$func = $_GET['func'];
if(!$sidx) $sidx =1;
if ($func == "getrooms"){
$result = $mysqli->query("SELECT COUNT(*) AS count FROM $mysqltable");// new
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);// new
$count = $row['count']; // new
if( $count > 0 && $limit > 0) { // new
$total_pages = ceil($count/$limit); // new
} else { // new
$total_pages = 0; // new
} // new
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$result = $mysqli->query("SELECT * FROM $mysqltable ORDER BY $sidx $sord LIMIT $start , $limit");
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$responce->rows[$i]['id']=$row['roomId'];
$responce->rows[$i]['cell']=array($row['roomId'],$row['roomNr'],$row['roomType'],$row['squareMeter'],$row['cubicMeter'],$row['createDate'],$row['updateDate'],$row['free']);
$i++;
}
echo json_encode($responce);
}elseif($func == "getnlcontainertype"){
$result = $mysqli->query("SELECT COUNT(*) AS count FROM $mysqltable ");// new
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);// new
$count = $row['count']; // new
if( $count > 0 && $limit > 0) { // new
$total_pages = ceil($count/$limit); // new
} else { // new
$total_pages = 0; // new
} // new
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$result = $mysqli->query("SELECT * FROM $mysqltable ORDER BY $sidx $sord LIMIT $start , $limit");
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$responce->rows[$i]['id']=$row['nlContainerTypeId'];
$responce->rows[$i]['cell']=array($row['nlContainerTypeId'], $row['nlContainerTypeName'],$row['nlContainerTypeDescription']);
$i++;
}
echo json_encode($responce);
}elseif($func == "getnlcontainer"){
$result = $mysqli->query("SELECT COUNT(*) AS count FROM $mysqltable ");// new
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);// new
$count = $row['count']; // new
if( $count > 0 && $limit > 0) { // new
$total_pages = ceil($count/$limit); // new
} else { // new
$total_pages = 0; // new
} // new
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$mysqltable_2 = $_GET['table2'];
$mysqltable_3 = $_GET['table3'];
$mysqltable_4 = $_GET['table4'];
$mysqltable_5 = $_GET['table5'];
/*
$result = $mysqli->query("
SELECT
nlContainer.nlContainerId,
room.roomNr,
room.roomType,
showType.showType,
nlContainer.showInfoId,
nlContainer.containerNr,
nlContainerType.nlContainerTypeName,
nlContainer.volume, nlContainer.volumeCurrent,
nlContainer.sensorDistFull,
nlContainer.sensorDistEmpty,
nlContainer.lastTimeClean,
nlContainer.lastTimeChangeNl,
nlContainer.idealTemp,
nlContainer.state,
nlValues.nlCurrentTemp,
nlValues.nlCurrentWaterLevel,
nlValues.nlCurrentPh,
nlValues.nlCurrentEc
FROM
$mysqltable, $mysqltable_2,$mysqltable_3, $mysqltable_4
LEFT JOIN
nlValues ON nlContainer.nlContainerId = nlValues.nlContainerId
WHERE
nlContainer.showTypeId = showType.showTypeId
AND
nlContainer.nlContainerTypeId = nlContainerType.nlContainerTypeId
AND
nlContainer.roomId=room.roomId
");
*/
$result = $mysqli->query("
SELECT
nlContainer.nlContainerId,
room.roomNr,
room.roomType,
showType.showType,
nlContainer.showInfoId,
nlContainer.containerNr,
nlContainerType.nlContainerTypeName,
nlContainer.sensorDistFull,
nlContainer.sensorDistEmpty,
nlContainer.lastTimeClean,
nlContainer.lastTimeChangeNl,
nlContainer.state,
nlContainer.tempMin,
nlContainer.tempMax,
nlContainer.sensorDistEmpty,
nlContainer.sensorDistEmpty,
nlContainer.nlContainerLength,
nlContainer.nlContainerWidth,
nlValues.nlCurrentTemp,
nlValues.nlCurrentWaterLevel,
nlValues.nlCurrentPh,
nlValues.nlCurrentEc
FROM
$mysqltable
LEFT JOIN
nlValues ON nlContainer.nlContainerId = nlValues.nlContainerId
and nlValues.lastTimeStamp IS NOT NULL
LEFT JOIN
showType ON nlContainer.showTypeId = showType.showTypeId
LEFT JOIN
nlContainerType ON nlContainer.nlContainerTypeId = nlContainerType.nlContainerTypeId
LEFT JOIN
room ON nlContainer.roomId=room.roomId
");
//ORDER BY $sidx $sord LIMIT $start , $limit
//$result = $mysqli->query("SELECT * FROM $mysqltable ORDER BY $sidx $sord LIMIT $start , $limit");
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$responce->rows[$i]['id']=$row['nlContainerId'];
$responce->rows[$i]['stateid']=$row['state'];
$responce->rows[$i]['cell']=array($row['nlContainerId'], $row['roomNr'],
$row['roomType'],$row['containerNr'],$row['showType'],$row['nlContainerTypeName'],
$row['nlCurrentTemp'],$row['nlCurrentPh'],$row['nlCurrentEc'],$row['nlCurrentWaterLevel'],$row['state'],$row['state'], $row['tempMin'],$row['tempMax']
,$row['sensorDistEmpty'],$row['sensorDistFull'],$row['nlContainerLength'],$row['nlContainerWidth']);
$i++;
}
echo json_encode($responce);
}elseif($func == "getnlcontainerdetails"){
$nlContainerId = $_GET['nlContainerId'];
$result = $mysqli->query("SELECT COUNT(*) AS count FROM $mysqltable ");// new
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);// new
$count = $row['count']; // new
if( $count > 0 && $limit > 0) { // new
$total_pages = ceil($count/$limit); // new
} else { // new
$total_pages = 0; // new
} // new
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$result = $mysqli->query("
SELECT
nlContainer.nlContainerId,
nlContainer.tempMin,
nlContainer.TempMax,
nlContainer.sensorDistFull,
nlContainer.sensorDistEmpty,
nlContainer.nlContainerLength,
nlContainer.nlContainerWidth,
nlContainer.lastTimeClean,
nlContainer.lastTimeChangeNl,
nlContainer.tempMin,
nlContainer.tempMax
FROM
$mysqltable
LEFT JOIN
nlValues ON nlContainer.nlContainerId = nlValues.nlContainerId
WHERE
nlContainer.nlContainerId = $nlContainerId
");
//ORDER BY $sidx $sord LIMIT $start , $limit
//$result = $mysqli->query("SELECT * FROM $mysqltable ORDER BY $sidx $sord LIMIT $start , $limit");
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
if ($row['lastTimeClean'] =="0000-00-00 00:00:00" || $row['lastTimeClean'] == NULL){
$row['lastTimeClean'] = '';
}
if ($row['lastTimeChangeNl'] =="0000-00-00 00:00:00" || $row['lastTimeChangeNl'] == NULL){
$row['lastTimeChangeNl'] = '';
}
$responce->rows[$i]['id']=$row['nlContainerId'];
$responce->rows[$i]['cell']=array($row['nlContainerId'], $row['tempMin'],$row['tempMax'],
$row['sensorDistFull'],$row['sensorDistEmpty'],$row['nlContainerLength'],$row['nlContainerWidth'],
$row['lastTimeClean'],$row['lastTimeChangeNl']);
$i++;
}
echo json_encode($responce);
}
?>