<?php
session_start();
ini_set('max_execution_time', 300000);
include("include/setsession.php");
require_once("include/connect.inc");
require_once("include/functions.php");
mysqli_query($link, "SET character_set_results=utf8");

$txt="";

$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction

if(!$sidx) $sidx =1;
$totalrows = isset($_REQUEST['totalrows']) ? $_REQUEST['totalrows']: false;
if($totalrows) {
	$limit = $totalrows;
}

$values = mysqli_query($link, "SELECT count(*) AS tot FROM ".$s_prefix."_uploads") or die('Query failed: ' . mysqli_error($link));
$row = mysqli_fetch_array($values, MYSQLI_ASSOC);
$count = $row['tot'];
/*
if( $count >0 ) {
	$total_pages = ceil($count/$limit);
} else {
	$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
if ($limit<0) $limit = 0;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;

$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
*/
$i=0;

$query_select="SELECT a.id, 
					DATE_FORMAT(a.dateup, '%d-%m-%Y %k:%i:%S') as dateup, 
					d.description AS edition,
					b.timeedition,
					a.dateedition,
					c.usr,
					a.filename
					FROM ".$s_prefix."_uploads a, ".$s_prefix."_editions b, ".$s_prefix."_tb_users c, ".$s_prefix."_editionstype d
					WHERE
					a.idedition=b.id AND
					b.idtype=d.id AND
					a.iduser=c.id
					ORDER BY a.id DESC";
$values = mysqli_query($link, $query_select) or die('Query failed: ' . mysqli_error($link));
while ($row = mysqli_fetch_array($values, MYSQLI_ASSOC)) {
	$responce->rows[$i]['id']=$row['id'];
	$responce->rows[$i]['cell']=array($row['dateup'],
								$row['edition'],
								formatHHMM($row['timeedition']/1000),
								$row['dateedition'],
								$row['usr'],
								$row['filename']);
								
	$i++;
}
echo json_encode($responce);
?>