<?php

if (!defined("WHMCS"))
	die("This file cannot be accessed directly");

if (!$rating) { $rating='1'; }
if (!$startdate) { $startdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-7,date("Y"))); } else { $startdate=substr($startdate,6,4).'-'.substr($startdate,3,2).'-'.substr($startdate,0,2); }
if (!$enddate) { $enddate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y"))); } else { $enddate=substr($enddate,6,4).'-'.substr($enddate,3,2).'-'.substr($enddate,0,2); }

$rsel[$rating] = ' selected';

$query = "SELECT tblticketreplies.*,tbltickets.tid AS ticketid FROM tblticketreplies INNER JOIN tbltickets ON tbltickets.id=tblticketreplies.tid WHERE tblticketreplies.admin!='' AND tblticketreplies.rating='$rating' AND tblticketreplies.date BETWEEN '$startdate' AND '$enddate' ORDER BY date DESC";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

$startdate = fromMySQLDate($startdate);
$enddate = fromMySQLDate($enddate);

$reportdata["title"] = "Support Ticket Ratings Reviewer";
$reportdata["description"] = "This report is showing all $num_rows ticket replies rated $rating between $startdate & $enddate for review";

$reportdata["headertext"] = '<form method="post" action="reports.php?report=ticket_ratings_reviewer">
<p align="center"><b>Filter:</b> Rating: <select name="rating"><option'.$rsel[1].'>1</option><option'.$rsel[2].'>2</option><option'.$rsel[3].'>3</option><option'.$rsel[4].'>4</option><option'.$rsel[5].'>5</option></select> Between Dates: <input type="text" name="startdate" value="'.$startdate.'" size="12" /> and <input type="text" name="enddate" value="'.$enddate.'" size="12" /> <input type="submit" value="Filter List" /></p>
</form>';

$reportdata["tableheadings"] = array("Ticket #","Date","Message","Admin","Rating");

while ($data = mysql_fetch_array($result)) {
	$tid = $data["tid"];
    $ticketid = $data["ticketid"];
	$date = $data["date"];
	$message = $data["message"];
	$admin = $data["admin"];
	$rating = $data["rating"];

	$date = fromMySQLDate($date,true);

	$reportdata["tablevalues"][] = array('<a href="supporttickets.php?action=viewticket&id='.$tid.'">'.$ticketid.'</a>',$date,'<div align="left">'.$message.'</div>',$admin,$rating);
}

?>