<?
include "header.php";
echo $header;

if($admin_info[demo_feature] == "on") {
  $demo_user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE email='$admin_info[demo_email]'"));

  $total_users = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE u_id <> '$demo_user_info[u_id]' AND is_approved='yes'"));
  $total_pending_users = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE is_approved <> 'yes' AND u_id <> '$demo_user_info[u_id]'"));
  $total_folders = mysql_num_rows(mysql_query("SELECT * FROM ims_folders WHERE u_id <> '$demo_user_info[u_id]'"));
  $total_images = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE u_id <> '$demo_user_info[u_id]'"));

  $space_used = mysql_fetch_assoc(mysql_query("SELECT sum(size) AS size FROM ims_image WHERE u_id <> '$demo_user_info[u_id]'"));
  if($space_used[size] == NULL) { $space_used[size] = 0; }
  $space_used = ($space_used[size]) / (1024 * 1024);
  $space_used = rounder($space_used);

  $bandwidth_used = mysql_fetch_assoc(mysql_query("SELECT sum(bandwidth_used) AS bandwidth_used FROM ims WHERE u_id <> '$demo_user_info[u_id]'"));
  if($bandwidth_used[bandwidth_used] == "") { $bandwidth_used[bandwidth_used] = 0; }
  $bandwidth_used = ($bandwidth_used[bandwidth_used]) / (1024 * 1024);
  $bandwidth_used = rounder($bandwidth_used);

  $demo_total_folders = mysql_num_rows(mysql_query("SELECT * FROM ims_folders WHERE u_id = '$demo_user_info[u_id]'"));
  $demo_total_images = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE u_id = '$demo_user_info[u_id]'"));

  $demo_space_used = mysql_fetch_assoc(mysql_query("SELECT sum(size) AS size FROM ims_image WHERE u_id='$demo_user_info[u_id]'"));
  if($demo_space_used[size] == NULL) { $demo_space_used[size] = 0; }
  $demo_space_used = ($demo_space_used[size]) / (1024 * 1024);
  $demo_space_used = rounder($demo_space_used);

  if($demo_user_info[bandwidth_used] == "") { $demo_user_info[bandwidth_used] = 0; }
  $demo_bandwidth_used = ($demo_user_info[bandwidth_used]) / (1024 * 1024);
  $demo_bandwidth_used = rounder($demo_bandwidth_used);

} else {

  $total_users = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE is_approved='yes'"));
  $total_pending_users = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE is_approved <> 'yes'"));
  $total_folders = mysql_num_rows(mysql_query("SELECT * FROM ims_folders"));
  $total_images = mysql_num_rows(mysql_query("SELECT * FROM ims_image"));

  $space_used = mysql_fetch_assoc(mysql_query("SELECT sum(size) AS size FROM ims_image"));
  if($space_used[size] == NULL) { $space_used[size] = 0; }
  $space_used = ($space_used[size]) / (1024 * 1024);
  $space_used = rounder($space_used);

  $bandwidth_used = mysql_fetch_assoc(mysql_query("SELECT sum(bandwidth_used) AS bandwidth_used FROM ims"));
  if($bandwidth_used[bandwidth_used] == "") { $bandwidth_used[bandwidth_used] = 0; }
  $bandwidth_used = ($bandwidth_used[bandwidth_used]) / (1024 * 1024);
  $bandwidth_used = rounder($bandwidth_used);
}


echo "
<b>Welcome to your IMS Administration Area</b><br>
To begin, please choose a section of your administration area from the menu.<br>
Your system statistics are displayed below for your convenience.

<br><br>

<table width='516' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF; margin-bottom: 8px;'>
<tr><td width='20' style='padding: 5px; padding-right: 0px;'><img src='../icons/users.gif' border='0'></td>
<td style='padding: 3px; padding-top: 2px;'>
<b>User Accounts</b><br>
Total Users: $total_users<font class='gray'> &nbsp;|&nbsp; </font>
Pending Users: $total_pending_users<font class='gray'> &nbsp;|&nbsp; </font>
Total Folders: $total_folders<font class='gray'> &nbsp;|&nbsp; </font>
Total Images: $total_images<font class='gray'>
</td>
</tr></table>

<table width='516' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;"; if($admin_info[demo_feature] == "on") { echo " margin-bottom: 8px;"; } echo "'>
<tr><td width='20' style='padding: 5px; padding-right: 0px;'><img src='../icons/transfer.gif' border='0'></td>
<td style='padding: 3px; padding-top: 2px;'>
<b>Space & Bandwidth Usage</b>"; if($admin_info[demo_feature] == "on") { echo " (not including demo user)"; } echo "<br>
Total Space Usage: ".$space_used." MB<font class='gray'> &nbsp;|&nbsp; </font>
Total Bandwidth Usage: ".$bandwidth_used." MB<font class='gray'>
</td>
</tr></table>
";

if($admin_info[demo_feature] == "on") {
echo "
<table width='516' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;'>
<tr><td width='20' style='padding: 5px; padding-right: 0px;'><img src='../icons/demo.gif' border='0'></td>
<td style='padding: 3px; padding-top: 2px;'>
<b>Demonstration User</b><br>
Space Used: ".$demo_space_used." MB of ".$demo_user_info[space_avail]." MB<font class='gray'> &nbsp;|&nbsp; </font>
Bandwidth Used: ".$demo_bandwidth_used." MB of ".$demo_user_info[bandwidth_allotted]." MB<font class='gray'> &nbsp;|&nbsp; </font>
Total Images: ".$demo_total_images."<font class='gray'>
</td>
</tr></table>
";
}


echo $footer;
?>