<?php
include("../include/session.php");  
include("appList.class.php");
require_once("../include/accessCheck.php");   

if (isset($_GET['page'])){ //find out what the sub page is
	$page = $_GET['page'];
	}
else{$page = 'display';}

global $pageNum;
if(isset($_GET['pageNum']))
        $pageNum=$_GET['pageNum']; //Get the current page number
    else
        $pageNum=1;
        
/**
* displayApps - Displays the app database table in
* a nicely formatted html table.
*/
function displayApps(){
    global $pageNum, $session;
//paging code below
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++      
if($session->userlevel==2) { 
    $result=appList::showAdminApps($session->userinfo['adminID']);
}
else if($session->userlevel==1) { 
     $result=appList::showAllApps();
}
$nrResults = mysql_numrows($result);

$limit=20; // Limit of result per page 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  

if($session->userlevel==2) { 
    $result=appList::showAdminApps($session->userinfo['adminID'],$pageNum,$limit);
}
else if($session->userlevel==1) { 
    $result = appList::showAllApps($pageNum,$limit); 
}
$num_rows = mysql_numrows($result);
 
if(!$result || ($num_rows < 0)){
echo "Error displaying info";
return;
}
if($num_rows == 0){
echo "No record.";
return;
}

echo "<i>Click 'List Suggestions' to view the suggestions for a selected application below:  </i>";
/* Display table contents */
echo "<table  cellspacing=\"3\" cellpadding=\"2\">";
echo "<tr><th><b>Organization Name</b></th><th><b>Application Name</b></th><th><b>Action</b></th></tr>\n";
for($i=0; $i<$num_rows; $i++){
    
$appID  = mysql_result($result,$i,"appID");
$organizationName  = mysql_result($result,$i,"organizationName");
$appName  = mysql_result($result,$i,"appName"); 

echo '<tr><td class="'.($i%2? "c1":"c2").'">'.$organizationName.'</td>';

echo '<td class="'.($i%2? "c1":"c2").'">'.$appName.'</td>';  
echo '<td class="'.($i%2? "c1":"c2").'"><a href="suggestionList.php?appID='.$appID.'" >List Suggestions</a></td>';  

echo "</tr>\n";
}
echo "</table><br>";
//Paging code below
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    
appList::displayPageNav($nrResults,$limit,$pageNum,$_SERVER['PHP_SELF']);

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="../style.css"/>       
</head>
<body >

<div id="layout">
	<?php require('../include/header.php');   ?>
        
<?php    switch ($page){ //what page to load
		case 'display':  //begin display page?>
			<div id="displayApp" class="in"> 
            <P class=veryLargeBlue>Application List</P>
				<?php if(isset($process_result)) {echo $process_result;}
				displayApps();
				?>
			</div>
		<?php
		break; //end display page
		
		} //end add page and end switch page?> 
<?php require('../include/footer.php'); ?>
</div>
<?php
 unset($_SESSION['error_array']); 
?>
</body>
</html>
