<?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['invite_groups'] = invite_groups('all');
$pagedResults = new Paginated($_SESSION['invite_groups'], 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()) {
$user_id = get('user_id','groups','id',$row['group_id'],'one');
$user = get('f_name','users','id',$user_id,'one').' '.get('l_name','users','id',$user_id,'one');
$group = get('g_name','groups','id',$row['group_id'],'one');
$devices_r = get('edit','device','',$row['group_id'],'all');
$devs = null;
foreach($devices_r as $dev){
	$devs .= $dev['id'].', ';
}
$devs = substr($devs,0,-2);
echo "	<tr>
			<td>$user</td>
			<td>Σας προσκάλεσε στην ομάδα</td>
			<td>$group</td>
			<td>$devs</td>
			<td>
				<form method=\"post\" action=\"groups_invite.php\" accept-charset=\"utf-8\">
					<input type=\"hidden\" name=\"hidden\" value=\"".$row['id']."\" />
					<input type=\"submit\" title=\"Αποδεχτείτε την πρόσκληση\" name=\"accept\" value=\"\" class=\"ok\"/>
				</form>
				<form method=\"post\" class=\"more_left_g\" action=\"groups_invite.php\" accept-charset=\"utf-8\">
					<input type=\"hidden\" name=\"hidden\" value=\"".$row['id']."\" />
					<input type=\"submit\" title=\"Απορρίψτε την πρόσκληση\" name=\"deny\" value=\"\" class=\"no\"/>
				</form>
			</td>
		</tr>";
}
echo '	
		</tbody>
		<tfoot>';
		$pagedResults->setLayout(new DoubleBarLayout());
		echo '
		<tr>
			<td colspan="5">';
		if(sizeof($_SESSION['invite_groups'])>8){
			echo $pagedResults->fetchPagedNavigation();
		}
		echo '
			</td>
		</tr>
		</tfoot>
	</table>';
}
?>