<?
include "header.php";
if(isset($_POST['user_task'])) { $user_task = $_POST['user_task']; } elseif(isset($_GET['user_task'])) { $user_task = $_GET['user_task']; } else { $user_task = "main"; }
if(isset($_POST['u_id'])) { $u_id = $_POST['u_id']; } elseif(isset($_GET['u_id'])) { $u_id = $_GET['u_id']; } else { exit; }
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
if(isset($_POST['page'])) { $page = $_POST['page']; } elseif(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; }
if(isset($_POST['s'])) { $s = $_POST['s']; } elseif(isset($_GET['s'])) { $s = $_GET['s']; } else { $s = ""; }
if(isset($_POST['o'])) { $o = $_POST['o']; } elseif(isset($_GET['o'])) { $o = $_GET['o']; } else { $o = "u"; }
if(isset($_POST['t'])) { $t = $_POST['t']; } elseif(isset($_GET['t'])) { $t = $_GET['t']; } else { $t = "e"; }
$user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id='$u_id'"));

$header = "
<html>
<head>
<title>Image Management System - Administration Panel</title>
<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>
<link rel='STYLESHEET' type='text/css' href='../styles.css'>
<script language='javascript'>
<!--
function redirect() {
window.opener.location.href('users.php?task=$task&page=$page&s=$s&o=$o&t=$t');
window.close();
}
// -->
</script>
<style type='text/css'>
body { margin-left: 10px; margin-top: 10px; }
</style>
</head>
<body>

<font style='font-size: 13pt;'><b>View/Modify User</b></font><br>
";

$footer = "
</body>
</html>
";




if($user_task == "ban_email") {
$ban_email = $admin_info[ban_email].",$user_info[email]";
mysql_query("UPDATE ims_admin SET ban_email='$ban_email'");
$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));
}



if($user_task == "ban_ip") {
$ban_ip = $admin_info[ban_ip].",$user_info[IP]";
mysql_query("UPDATE ims_admin SET ban_ip='$ban_ip'");
$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));
}


if($user_task == "unban_email") {
$ban_email = explode(",", $admin_info[ban_email]);
$new_ban_email = "";
$last_email = "yes";
for($i=0;$i<count($ban_email);$i++) {
if($ban_email[$i] != $user_info[email]) {
if($last_email == "no") { $new_ban_email .= ","; }
$new_ban_email .= "$ban_email[$i]";
}}
mysql_query("UPDATE ims_admin SET ban_email='$new_ban_email'");
$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));
}



if($user_task == "unban_ip") {
$ban_ip = explode(",", $admin_info[ban_ip]);
$new_ban_ip = "";
$last_ip = "yes";
for($i=0;$i<count($ban_ip);$i++) {
if($ban_ip[$i] != $user_info[IP]) {
if($last_ip == "no") { $new_ban_ip .= ","; }
$new_ban_ip .= "$ban_ip[$i]";
}}
mysql_query("UPDATE ims_admin SET ban_ip='$new_ban_ip'");
$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));
}




if($user_task == "delete") {
  if(isset($_POST['delete_type'])) {
  if($_POST['delete_type'] == "with") {
  $subject = stripslashes($_POST['subject']);
  $message = stripslashes($_POST['message']);
    if($subject == "" OR $subject == " " OR $message == "" OR $message == " ") {
    echo $header;
    echo "
    <table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
    <tr>
    <td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
    <b>An Error Has Occurred</b><br>
    You must provide both a subject and message for your notification email.
    <br><br>
    <b><font face='verdana'>&#171;</font> <a href=\"javascript:history.go(-1);\">Click here to go back and try again.</a></b>
    </td></tr></table>
    ";
    echo $footer;
    exit();
    } else {
    // SEND DELETE NOTIFICATION
    mail($user_info[email], $subject, $message, "From: $admin_info[email]");
    }
  }
  if(str_replace(" ", "", $u_id) != "") { @deleteuse("../u/$u_id"); }
  mysql_query("DELETE FROM ims WHERE u_id='$u_id'");
  mysql_query("DELETE FROM ims_image WHERE u_id='$u_id'");
  mysql_query("DELETE FROM ims_folders WHERE u_id='$u_id'");
  echo $header;
  echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
  <center>
  The user <b>\"$user_info[email]\"</b> has been deleted.";
if($user_info[price] > 0) {
echo "You have just deleted a paid user and must now log into 
<a href='www.paypal.com' target='_blank'>PayPal</a> and delete the subscription belonging 
to \"$user_info[payer_paypal_email]\". You can find subscriptions in the History area of your 
Paypal account.";
}
echo "<br><br>
  <input class='button' type='submit' value='Close Window' onClick=\"redirect()\">
  </center>
</td></tr></table>
  ";
  echo $footer;
  exit;
  } else {
  echo $header;
  echo "

<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<form action='user_info.php' method='POST'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
You are about to delete <b>\"$user_info[email]\"</b> with an email notification.<br>
Please enter your email subject and message below.";
echo"
<br><br>
<table cellpadding='0' cellspacing='0'>
<tr><td width='60' align='right'>Subject&nbsp;</td><td><input type='text' name='subject' maxlength='250' size='40'></td></tr>
<tr><td align='right' valign='top'>Message&nbsp;</td><td><textarea cols='50' rows='7' name='message'></textarea></td></tr>
</table>

</td></tr></table>

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td>
  <input type='hidden' name='u_id' value='$u_id'>
  <input type='hidden' name='user_task' value='delete'>
  <input type='hidden' name='task' value='$task'>
  <input type='hidden' name='page' value='$page'>
  <input type='hidden' name='s' value='$s'>
  <input type='hidden' name='o' value='$o'>
  <input type='hidden' name='t' value='$t'>
  <input type='hidden' name='delete_type' value='with'>
  <input class='button' type='submit' value='Delete User'>&nbsp;
</td>
  </form>
  <form action='user_info.php' method='POST'>
<td>
  <input type='hidden' name='u_id' value='$u_id'>
  <input type='hidden' name='user_task' value='delete'>
  <input type='hidden' name='task' value='$task'>
  <input type='hidden' name='page' value='$page'>
  <input type='hidden' name='s' value='$s'>
  <input type='hidden' name='o' value='$o'>
  <input type='hidden' name='t' value='$t'>
  <input type='hidden' name='delete_type' value='without'>
  <input class='button' type='submit' value='Delete Without Notification'>&nbsp;
</td>
  </form>
  <form action='user_info.php' method='POST'>
<td>
  <input type='hidden' name='u_id' value='$u_id'>
  <input type='hidden' name='user_task' value='cancel'>
  <input type='hidden' name='task' value='$task'>
  <input type='hidden' name='page' value='$page'>
  <input type='hidden' name='s' value='$s'>
  <input type='hidden' name='o' value='$o'>
  <input type='hidden' name='t' value='$t'>
  <input class='button' type='submit' value='Cancel'>
</td></tr></table>
  ";
  echo $footer;
  exit;
  }
}





if($user_task == "edit") {
$password = $_POST['password'];
$fname = str_replace("'", "&#39;", $_POST['fname']);
$lname = str_replace("'", "&#39;", $_POST['lname']);
$account_active = $_POST['account_active'];
$space_avail = $_POST['space_avail'];
$folders_avail = $_POST['folders_avail'];
$bandwidth_allotted = $_POST['bandwidth_allotted'];
$max_filesize = $_POST['max_filesize'];
$photo_album = $_POST['photo_album'];
$notes = $_POST['notes'];

$ext_list = "";
$lastext = "no";
if(isset($_POST['ext_jpg'])) { $ext_list = "jpg"; $lastext = "yes"; }
if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
if(isset($_POST['ext_jpeg'])) { $ext_list .= "jpeg"; $lastext = "yes"; }
if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
if(isset($_POST['ext_gif'])) { $ext_list .= "gif"; $lastext = "yes"; }
if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
if(isset($_POST['ext_bmp'])) { $ext_list .= "bmp"; $lastext = "yes"; }
if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
if(isset($_POST['ext_png'])) { $ext_list .= "png"; $lastext = "yes"; }
if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
if(isset($_POST['ext_pdf'])) { $ext_list .= "pdf"; $lastext = "yes"; }

$is_error = "no";
$error = "";

if($password == "" | $fname == "" | $lname == "" | $space_avail == "" | $folders_avail == "" | $bandwidth_allotted == "") {
$is_error = "yes";
$error .= "You have omitted the following fields:<br>";
  if($password == "") { $error .= "  -Password<br>"; }
  if($fname == "") { $error .= "  -First Name<br>"; }
  if($lname == "") { $error .= "  -Last Name<br>"; }
  if($space_avail == "") { $error .= "  -Space<br>"; }
  if($folders_avail == "") { $error .= "  -Max. Folders<br>"; }
  if($bandwidth_allotted == "") { $error .= "  -Bandwidth<br>"; }
$error .= "<br>";
}

if(preg_match("/[^a-z,A-Z,0-9]/", $password)) {
$is_error = "yes";
$error .= "Passwords may only contain alpha-numeric characters.<br>";
}

if(!is_numeric($space_avail) | $space_avail <= 0) {
$is_error = "yes";
$error .= "Space must be a numeric value greater than 0.<br>";
}

if((!is_numeric($folders_avail) | $folders_avail != (int)$folders_avail | $folders_avail <= 0) & $folders_avail != "") {
$is_error = "yes";
$error .= "Max. Folders must be an integer value greater than 0.<br>";
}

if(!is_numeric($bandwidth_allotted) | $bandwidth_allotted <= 0) {
$is_error = "yes";
$error .= "Bandwidth must be a numeric value greater than 0.<br>";
}

if($is_error == "yes") {
echo $header;
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
<b>An Error Has Occurred:</b><br>
$error<br>
<b><font face='verdana'>&#171;</font> <a href=\"javascript:history.go(-1);\">Click here to go back and try again.</a></b>
</td></tr></table>
";
echo $footer;
exit;
}

if($space_avail != $user_info[space_avail] | $folders_avail != $user_info[folders_avail] | bandwidth_allotted != $user_info[bandwidth_allotted] | $max_filesize != $user_info[max_filesize] | $ext_list != $user_info[ext_list]) {
$plan = 0;
} else {
$plan = $user_info[plan];
}

mysql_query("UPDATE ims SET
password = '$password',
fname = '$fname',
lname = '$lname',
account_active = '$account_active',
plan = '$plan',
space_avail = '$space_avail',
folders_avail = '$folders_avail',
bandwidth_allotted = '$bandwidth_allotted',
max_filesize = '$max_filesize',
ext_list = '$ext_list',
photo_album = '$photo_album',
notes = '$notes'
WHERE u_id='$u_id'");




echo $header;
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
<center>
The new user information for <b>\"$user_info[email]\"</b> has been saved.<br><br>
<input class='button' type='button' value='Close Window' onClick=\"redirect()\">
</center>
</td></tr></table>
";
echo $footer;
exit;
}





if($user_info[plan] == 0) {
$plan_info[plan] = "Custom Plan";
} else {
$plan_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_plans WHERE p_id='$user_info[plan]'"));
}
$extensions = explode(",", $user_info[ext_list]);
if($user_info[last_login] == "Never") {
$day_difference = time() - $user_info[signup_date];
} else {
$day_difference = time() - $user_info[last_login];
}
$banned_users_email = explode(",", $admin_info[ban_email]);
$banned_users_ip = explode(",", $admin_info[ban_ip]);
if(in_array($user_info[email], $banned_users_email) | (in_array($user_info[IP], $banned_users_ip) & $user_info[IP] != "")) {
$status = "<font color='#FF0000'>Banned</font>";
} elseif($user_info[account_active] != "yes") {
$status = "<font color='#FF0000'>Disabled</font>";
} elseif($day_difference >= ($admin_info[inactivity] * 86400) & $admin_info[inactivity] != 0) {
$status = "<font color='#FF0000'>Inactive</font>";
} else {
$status = "Active";
}










echo $header;
echo "

<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<form action='user_info.php' method='POST'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>

<b>User ID:</b>&nbsp; $user_info[u_id]<br>
<b>Email (username):</b>&nbsp; $user_info[email] "; if(in_array($user_info[email], $banned_users_email)) { echo "<a href='user_info.php?user_task=unban_email&u_id=$u_id&task=$task&page=$page&s=$s&o=$o&t=$t'>(Un-Ban Email)</a>"; } else { echo "<a href='user_info.php?user_task=ban_email&u_id=$u_id&$user_task&task=$task&page=$page&s=$s&o=$o&t=$t'>(Ban Email)</a>"; } echo "<br>
<b>Signup Date:</b>&nbsp; ".date("F d, Y h:ia", timezone($user_info[signup_date]))."<br>
<b>Status:</b>&nbsp; $status<br>
<b>Last Login:</b>&nbsp; "; if($user_info[last_login] == "Never") { echo "Never"; } else { echo date("F d, Y h:ia", timezone($user_info[last_login])); } echo "<br>
<b>Pricing Plan:</b>&nbsp; $plan_info[plan]<br>
<b>IP Address (at signup date):</b> "; if($user_info[IP] == "") { echo "Not Logged"; } else { echo "$user_info[IP] "; if(in_array($user_info[IP], $banned_users_ip) & $user_info[IP] != "") { echo "<a href='user_info.php?user_task=unban_ip&u_id=$u_id&task=$task&page=$page&s=$s&o=$o&t=$t'>(Un-Ban IP)</a>"; } else { echo "<a href='user_info.php?user_task=ban_ip&u_id=$u_id&$user_task&task=$task&page=$page&s=$s&o=$o&t=$t'>(Ban IP)</a>"; }} echo "<br>
<b>Price:</b>&nbsp; $$user_info[price]/month<br>

</td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>

 <table cellpadding='0' cellspacing='0'>
 <tr><td width='80' align='right' NOWRAP>Password</td><td>&nbsp;&nbsp;<input type='text' name='password' value='$user_info[password]' maxlength='100' size='30'></td></tr>
 <tr><td align='right' NOWRAP>First Name</td><td>&nbsp;&nbsp;<input type='text' name='fname' value='$user_info[fname]' maxlength='255' size='30'></td></tr>
 <tr><td align='right' NOWRAP>Last Name</td><td>&nbsp;&nbsp;<input type='text' name='lname' value='$user_info[lname]' maxlength='255' size='30'></td></tr>
 <tr><td align='right' NOWRAP style='padding-top: 4px; padding-bottom: 4px;'>Account Status</td><td>&nbsp;<input type='radio' name='account_active' value='yes'"; if($user_info[account_active] == "yes") { echo " CHECKED"; } echo "> Active&nbsp;<input type='radio' name='account_active' value='no'"; if($user_info[account_active] != "yes") { echo " CHECKED"; } echo "> Disabled</td></tr>
 <tr><td align='right' NOWRAP style='padding-top: 4px; padding-bottom: 4px;'>Extensions</td><td>&nbsp;<input type='checkbox' name='ext_jpg' value='yes'"; if(in_array("jpg", $extensions)) { echo " CHECKED"; } echo ">JPG &nbsp;
 <input type='checkbox' name='ext_jpeg' value='yes'"; if(in_array("jpeg", $extensions)) { echo " CHECKED"; } echo ">JPEG &nbsp;
 <input type='checkbox' name='ext_gif' value='yes'"; if(in_array("gif", $extensions)) { echo " CHECKED"; } echo ">GIF &nbsp;
 <input type='checkbox' name='ext_bmp' value='yes'"; if(in_array("bmp", $extensions)) { echo " CHECKED"; } echo ">BMP &nbsp;
 <input type='checkbox' name='ext_png' value='yes'"; if(in_array("png", $extensions)) { echo " CHECKED"; } echo ">PNG &nbsp;
 <input type='checkbox' name='ext_pdf' value='yes'"; if(in_array("pdf", $extensions)) { echo " CHECKED"; } echo ">PDF &nbsp;
 </td></tr>
 <tr><td align='right' NOWRAP>Photo Album</td><td>&nbsp;<input type='checkbox' name='photo_album' value='yes'"; if($user_info[photo_album] == "yes") { echo " CHECKED"; } echo "></td></tr>
 <tr><td align='right' NOWRAP>Space</td><td>&nbsp;&nbsp;<input type='text' name='space_avail' value='$user_info[space_avail]' maxlength='10' size='7'></td></tr>
 <tr><td align='right' NOWRAP>Max. Folders</td><td>&nbsp;&nbsp;<input type='text' name='folders_avail' value='$user_info[folders_avail]' maxlength='10' size='7'></td></tr>
 <tr><td align='right' NOWRAP>Bandwidth</td><td>&nbsp;&nbsp;<input type='text' name='bandwidth_allotted' value='$user_info[bandwidth_allotted]' maxlength='10' size='7'></td></tr>
 <tr><td align='right' NOWRAP>Max. File Size</td><td>&nbsp;
 <select name='max_filesize' style='margin-top: 1px;'>
 <option value='10'"; if($user_info[max_filesize] == 10) { echo " selected"; } echo ">10 KB</option>
 <option value='25'"; if($user_info[max_filesize] == 25) { echo " selected"; } echo ">25 KB</option>
 <option value='50'"; if($user_info[max_filesize] == 50) { echo " selected"; } echo ">50 KB</option>
 <option value='100'"; if($user_info[max_filesize] == 100) { echo " selected"; } echo ">100 KB</option>
 <option value='200'"; if($user_info[max_filesize] == 200) { echo " selected"; } echo ">200 KB</option>
 <option value='500'"; if($user_info[max_filesize] == 500) { echo " selected"; } echo ">500 KB</option>
 <option value='1024'"; if($user_info[max_filesize] == 1024) { echo " selected"; } echo ">1 MB</option>
 </select>
 </td></tr>
 <tr><td align='right' valign='top'>Notes</td><td>&nbsp;&nbsp;<textarea rows='3' cols='50' name='notes'>$user_info[notes]</textarea></td></tr></td></tr>
 </table>

</td></tr></table>

<br>

<table cellspacing='0' cellpadding='0' style='margin-bottom: 20px;'>
<tr><td>
<input type='hidden' name='u_id' value='$u_id'>
<input type='hidden' name='user_task' value='edit'>
<input type='hidden' name='task' value='$task'>
<input type='hidden' name='page' value='$page'>
<input type='hidden' name='s' value='$s'>
<input type='hidden' name='o' value='$o'>
<input type='hidden' name='t' value='$t'>
<input class='button' type='submit' value='Save Changes'>&nbsp;
</td>
</form><form action='user_info.php' method='POST'>
<td>
<input type='hidden' name='u_id' value='$u_id'>
<input type='hidden' name='user_task' value='delete'>
<input type='hidden' name='task' value='$task'>
<input type='hidden' name='page' value='$page'>
<input type='hidden' name='s' value='$s'>
<input type='hidden' name='o' value='$o'>
<input type='hidden' name='t' value='$t'>
<input class='button' type='submit' value='Delete User'>&nbsp;
</td>
<td>
<input class='button' type='button' value='Cancel' onClick=\"redirect()\">
</td></tr></form></table>

";
echo $footer;

?>