<?php

get();

function connectToDatabase(){
	require_once('db.php');
    $connection = new database();
        return $connection;

}


function get(){
    $connection = connectToDatabase();

    $id = $_REQUEST['id'];
    
    if($id!="" && $connection->checkParameters($id)){
    	$result = $connection->q("select * from banners where id_user_req='$id' or id_user='$id' ");
    	$output = array();
	while($row=$connection->a($result)){
		$record = array();
		$record['ID'] = $row['ID'];
		$record['id_user_req'] = $row['id_user_req'];
		$record['id_user'] = $row['id_user'];
		$record['username_user'] = $row['username_user'];
        $record['comments'] = $row['comments'];
		$record['name_user'] = $row['name_user'];
		$record['pic_user'] = $row['pic_user'];
		$record['id_post'] = $row['id_post'];
		$record['link_post'] = $row['link_post'];
		$record['text_post'] = $row['text_post'];
		$record['darkhasti'] = $row['darkhasti'];
		$record['daryafti'] = $row['daryafti'];
		$record['status'] = $row['status'];
		$record['part'] = $row['part'];
		$d1=strtotime($row['Date']);
		$d2=ceil((time()-$d1)/60);
		$record['Date'] = $d2;
		$output[] = $record;
	}
	echo json_encode($output);
    }else {
    	echo "null";
    }
    
}


?>