<?php
@session_start();
if(isset($_SESSION['ekdhlos_userid'])){
include_once('php/functions.php');
require_once "pagination/Paginated.php";
require_once "pagination/DoubleBarLayout.php";
echo '<h6 class="center">Αναφορές Παράδοσης</h6><br /><hr /><br />';
$_SESSION['message_reports'] = messages('all');
$pagedResults = new Paginated($_SESSION['message_reports'], 8, $_SESSION['page']);
echo '
	<table class="width3" id="gradient-style">
		<thead>
		<tr>
			<th scope="col">Συσκευή</th>
			<th scope="col">Κατάσταση</th>
			<th scope="col">Μήνυμα</th>
			<th scope="col">Ημερομηνία</th>
			<th scope="col">Ενέργεια</th>
		</tr>
		</thead>
		<tbody>';
while($row = $pagedResults->fetchPagedRow()) {
$message = get('message','message','id',$row['message_id'],'one');
$total_words = substr_count($message, " ") + 1; // metrame to plithos twn leksewn	
$word = explode(" ", $message); // tis bazoume se pinaka
echo "	<tr>";
			if($_SESSION['ekdhlos_level']==0) echo "<td><a href=\"edit_devices.php?edit_id=".get('id','device','id',$row['device_id'],'one')."\">".get('id','device','id',$row['device_id'],'one')."</a></td>";
			else echo "<td>".get('id','device','id',$row['device_id'],'one')."</td>";
			echo "
			<td>Διάβασε το μήνυμα:</td>
			<td>
				<a href=\"edit_messages.php?edit_id=".$row['message_id']."\">";
				$j=0;
				if($total_words <= 4)for($j; $j < $total_words; $j++)echo $word[$j]." ";
				else if($total_words > 4){
					while($j<=4 ){
						if($j == 4)	echo $word[$j]."..";	
						else echo $word[$j]." ";
						$j++;
					}
				}
echo "			</a>
			</td>
			<td>".fix_date($row['date'])."<br />".fix_hour($row['date'])."</td>
			<td>
				<form method=\"post\" action=\"messages_reports.php\" accept-charset=\"utf-8\">
					<input type=\"hidden\" name=\"hidden\" value=\"".$row['id']."\" />
					<input type=\"submit\" name=\"submit\" value=\"\" class=\"ok\"/>
				</form>
			</td>
		</tr>";
}
echo '	
		</tbody>
		<tfoot>';
		$pagedResults->setLayout(new DoubleBarLayout());
		echo '
		<tr>
			<td colspan="5">';
		if(sizeof($_SESSION['message_reports'])>8){
			echo $pagedResults->fetchPagedNavigation();
		}
		echo '
			</td>
		</tr>
		</tfoot>
	</table>';
}
?>