<?php 

function get_activity_log($args) {
	$query = new query;
	$sql = "SELECT * FROM notification
			WHERE `user_id` = '".$args['args']['user_id']."'";
	if(isset($args['args']['status']) && $args['args']['status'] !== "") {
		$sql .= " AND `status` = '".$args['args']['status']."'";
	}
	$sql .=	" ORDER BY `last_sent` DESC".
			" LIMIT ".$args['limit']." OFFSET ".$args['offset'];
	$res = $query->get_results($sql, ARRAY_A);
	if(_count($res) && is_array($res)) {
		$table = new table("log_table", $res);
		$table->set_display_columns([
			'sn' => 'SN',
			'last_sent' => 'TIME',
			'content' => 'MESSAGE',
			'status' => 'STATUS',
			'action' => 'ACTION'
		]);
		$table->set_dynamic_columns([
			'last_sent' => '_tf_get_time_date',
			'action' => '_tf_get_link'
		]);
		if(isset($args['temp'])) {
			$table->temp = $args['temp'];
		}
		
		if($args['count'] > 0) {
			$response['html'] = $table->table_rows();
		} else $response['html'] = $table->table_html();
		
		$response['temp'] = $table->temp;
		$response['continue'] = true;
	}
	else {
		if($args['count'] > 0) {
			$response['html'] = "";
		} else $response['html'] = "no result found";
		$response['continue'] = false;
	}
	$response['container'] = "log_table tbody";
	return $response;
}

function get_admin_log($args) {
	$post = new post;
	if(isset($args['args']['from']) && $args['args']['from'] !== "") {
		$args['args']["_range_from"] = strtotime($args['args']['from']);
	}
	if(isset($args['args']['to']) && $args['args']['to'] !== "") {
		$args['args']["_range_to"] = strtotime("11.59 PM ". $args['args']['to']);
	}
	unset($args['args']['from']);
	unset($args['args']['to']);
	$res = $post->get_post_by_meta_data($args['args'], "LIKE", false, $args['limit'], $args['offset'], 'post_id', 'DESC');
	if(_count($res) && is_array($res)) {
		$table = new table("log_table", $res);
		$table->set_display_columns([
			'posted_on' => 'TIME',
			'narration' => 'ACTIVITY',
			'posted_by' => 'ADMIN'
		]);
		$table->set_dynamic_columns([
			'last_sent' => '_tf_get_time_date'
		]);
		if(isset($args['temp'])) {
			$table->temp = $args['temp'];
		}

		if($args['count'] > 0) {
			$response['html'] = $table->table_rows();
		} else $response['html'] = $table->table_html();

		$response['temp'] = $table->temp;
		$response['continue'] = true;
	}
	else {
		if($args['count'] > 0) {
			$response['html'] = "";
		} else $response['html'] = "no result found";
		$response['continue'] = false;
	}
	$response['container'] = "log_table tbody";
	return $response;
}