<?php
//assign the page variable
if ((!empty($_GET['subpage']))&& (intval($_GET['subpage']) != 0)){
$page = $_GET['subpage']; //using the get method
} else {
$page = 1; //if we don't have a page number then assume we are on the first page
}
if(isset($_GET['sortby'])){
$sort = $_GET['sortby'];
}else{
$sort = "id";
}
if(isset($_GET['order'])){
$order = $_GET['order'];
}else{
$order = "asc";
}
$rows = mysql_numrows(get_all_presentations());
$rows_per_page = 10;
$pages = ceil($rows/$rows_per_page);
$result = get_all_presentations_with_pagination($page, $rows_per_page, $sort, $order);
echo("<table class=\"table_datagrid\" id=\"table_datagrid_presentation\">");
echo("<thead>");
echo("<tr>");
echo("<th scope=\"col\">Id <a href=\"index.php?page=presentation&subpage={$page}&sortby=id&order=asc\" title=\"Sort ascending by id\" id=\"image_asc\"><img src=\"../images/asc.png\" /></a><a href=\"index.php?page=presentation&subpage={$page}&sortby=id&order=desc\" title=\"Sort descending by id\" id=\"image_dsc\"><img src=\"../images/dsc.png\" /></a></th>");
echo("<th scope=\"col\">Name <a href=\"index.php?page=presentation&subpage={$page}&sortby=name&order=asc\" title=\"Sort ascending by name\" id=\"image_asc\"><img src=\"../images/asc.png\" /></a><a href=\"index.php?page=presentation&subpage={$page}&sortby=name&order=desc\" title=\"Sort descending by name\" id=\"image_dsc\"><img src=\"../images/dsc.png\" /></a></th>");
echo("<th scope=\"col\">Created By <a href=\"index.php?page=presentation&subpage={$page}&sortby=userid&order=asc\" title=\"Sort ascending by author\" id=\"image_asc\"><img src=\"../images/asc.png\" /></a><a href=\"index.php?page=presentation&subpage={$page}&sortby=userid&order=desc\" title=\"Sort descending by author\" id=\"image_dsc\"><img src=\"../images/dsc.png\" /></a></th>");
echo("<th scope=\"col\">Created On <a href=\"index.php?page=presentation&subpage={$page}&sortby=date_created&order=asc\" title=\"Sort ascending by created date\" id=\"image_asc\"><img src=\"../images/asc.png\" /></a><a href=\"index.php?page=presentation&subpage={$page}&sortby=date_created&order=desc\" title=\"Sort descending by created date\" id=\"image_dsc\"><img src=\"../images/dsc.png\" /></a></th>");
echo("<th scope=\"col\">Details<img id=\"image_asc\" src=\"../images/default.png\" /></th>");
echo("<th scope=\"col\">Delete <img id=\"image_asc\" src=\"../images/default.png\" /></th>");
echo("</tr>");
echo("</thead>");
echo("<tbody>");
while ($array = mysql_fetch_array($result)){
$username = get_user_by_id($array['userid']);
echo("<tr>");
echo("<td>" . $array['id'] . "</td><td>" . $array['name'] . "</td><td>" . $username['username'] . "</td><td>" . date("Y/m/d", strtotime($array['date_created'])) . "</td>");
echo("<td><a href=\"#\" id=\"details\" title=\"View details of the presentation\" onclick=\"window.open('presentation_details.php?details={$array['id']}', 'Presentation', 'scrollbars=1, menubar=0, directories=0, resizable=1, location=0, status=0, width=800, height=600'); return false\"><img src=\"../images/page_preview.png\" /></a></td>");
echo("<td>");
if(($_SESSION['username'] == $username['username']) || ($_SESSION['usertype'] == 'Admin')){echo("<a href=\"index.php?page=presentation&sortby={$sort}&order={$order}&delete={$array['id']}¬ification=presentationdeletedfailed\" title=\"Delete the presentation\" id=\"delete\" onclick=\"return confirm('Are you sure that you want to delete this presentation?');\"><img id=\"delete\" src=\"../images/delete.png\" /></a>");};
echo("</td>");
echo("</tr>");
}
echo("</tbody>");
echo("<tfoot>");
echo("<tr>");
echo("<td colspan=\"7\">");
echo(generate_links_pagination($page, $pages, "presentation", $sort, $order));
echo("</td>");
echo("</tr>");
echo("</tfoot>");
echo("</table>");
?>