<?
include "header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "settings"; }
$results = "";



if($task == "settings_do") {
$rotate_feature = $_POST['rotate_feature'];
$resize_feature = $_POST['resize_feature'];
$notify = $_POST['notify'];
$welcome = $_POST['welcome'];
$welcome_sub = str_replace("'", "&#39;", $_POST['welcome_sub']);
$welcome_note = $_POST['welcome_note'];
$approve_deny = $_POST['approve_deny'];
$appr_email = $_POST['appr_email'];
$appr_sub = str_replace("'", "&#39;", $_POST['appr_sub']);
$appr_message = $_POST['appr_message'];
$den_email = $_POST['den_email'];
$den_sub = str_replace("'", "&#39;", $_POST['den_sub']);
$den_message = $_POST['den_message'];
$users_per_page = $_POST['users_per_page'];
$inactivity = $_POST['inactivity'];
$ban_ip = $_POST['ban_ip'];
$ban_email = $_POST['ban_email'];

if(str_replace(" ", "", $inactivity) == "" | $inactivity != (int)$inactivity | !is_numeric($inactivity)) { $inactivity = (int) $inactivity; }

mysql_query("UPDATE ims_admin SET
rotate_feature = '$rotate_feature',
resize_feature = '$resize_feature',
notify = '$notify',
welcome = '$welcome',
welcome_sub = '$welcome_sub',
welcome_note = '$welcome_note',
approve_deny = '$approve_deny',
appr_email = '$appr_email',
appr_sub = '$appr_sub',
appr_message = '$appr_message',
den_email = '$den_email',
den_sub = '$den_sub',
den_message = '$den_message',
users_per_page = '$users_per_page',
inactivity = '$inactivity',
ban_ip = '$ban_ip',
ban_email = '$ban_email'
");

if($admin_info[approve_deny] == "yes" AND $approve_deny != "yes") {
$pending_users = mysql_query("SELECT * FROM ims WHERE is_approved <> 'yes'");
while($pending_users_info = mysql_fetch_assoc($pending_users)) {
$appr_sub = str_replace("&#39;", "'", stripslashes($admin_info[appr_sub]));
$appr_message = str_replace("&#39;", "'", stripslashes($admin_info[appr_message]));
$appr_message = str_replace("[email]", "$pending_users_info[email]", $appr_message);
$appr_sub = str_replace("[email]", "$pending_users_info[email]", $appr_sub);
$appr_message = str_replace("[password]", "$pending_users_info[password]", $appr_message);
$appr_sub = str_replace("[password]", "$pending_users_info[password]", $appr_sub);
$fname = str_replace("&#39;", "'", $pending_users_info[fname]);
$lname = str_replace("&#39;", "'", $pending_users_info[lname]);
$appr_message = str_replace("[name]", "$fname $lname", $appr_message);
$appr_sub = str_replace("[name]", "$fname $lname", $appr_sub);
$appr_message = str_replace("[url]", "$login_url", $appr_message);
$appr_sub = str_replace("[url]", "$login_url", $appr_sub);
mail($pending_users_info[email], $appr_sub, $appr_message, "From: $admin_info[email]");
}
mysql_query("UPDATE ims SET is_approved='yes'");
}

$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));
$results = "<br>Your changes have been saved.<br>";

}



echo $header;

echo "
<b>User Settings</b><br>
Use this page to configure how the IMS interacts with your users.<br> If you would like
to modify an individual user's account, please visit the <a href='users.php'>User Manager</a>.<br>
When you are finished, be sure to click the \"Save Changes\" button.<br>
<b>$results</b><br>

<table cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF; margin-bottom: 10px;'>
<tr><td style='padding: 5px; padding-left: 7px;'>
<table width='502' cellpadding='0' cellspacing='0'>
<form action='settings_users.php' method='POST' style='margin-bottom: none;'>
<tr>
<td>
<b>Rotate Image Feature</b><br>
Allow users to rotate their images?</td>
<td>
<input type='radio' name='rotate_feature' value='yes'"; if($admin_info[rotate_feature] == "yes") { echo " checked"; } echo "> ON<br>
<input type='radio' name='rotate_feature' value='no'"; if($admin_info[rotate_feature] != "yes") { echo " checked"; } echo "> OFF</td>
</tr>
<tr><td colspan='2'>&nbsp;</td></tr>
<tr>
<td>
<b>Resize Image Feature</b><br>
Allow users to resize their images?</td>
<td>
<input type='radio' name='resize_feature' value='yes'"; if($admin_info[resize_feature] == "yes") { echo " checked"; } echo "> ON<br>
<input type='radio' name='resize_feature' value='no'"; if($admin_info[resize_feature] != "yes") { echo " checked"; } echo "> OFF</td>
</tr>
</table>
</td></tr></table>

<table cellpadding='0' cellspacing='0' style='margin-bottom: 12px;'>
<tr><td style='padding-left: 8px;'>
Note: You may want to turn off these features if you have a slow server.
<br>GIF images cannot be rotated/resized due to <a href='http://www.php.net/manual/en/function.imagegif.php' target='_blank'>copyright restrictions</a>. 
<br>These features are also unavailable for PDF images.
</td></tr></table>

<table cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF; margin-bottom: 10px;'>
<tr><td style='padding: 5px; padding-left: 7px;'>
<table width='502' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2'><b>New User Signup Settings</b><br>
<font class='small'>These settings apply to all new user signups.</font><br>
Note: You can change your admin email address in the <a href='settings_general.php'>General Settings</a> section.

<br><br></td>
</tr>
<tr>
<td colspan='2'><input type='checkbox' name='notify' value='yes'"; if($admin_info[notify] == "yes") { echo " checked"; } echo "> Email you ($admin_info[email]) each time a new account is created?</td>
</tr>
<tr>
<td colspan='2'><input type='checkbox' name='welcome' value='yes'"; if($admin_info[welcome] == "yes") { echo " checked"; } echo "> Send an email to new users when they signup? If checked, enter the subject/message below.<br><br>Subject:<br><input type='text' class='text' name='welcome_sub' value='$admin_info[welcome_sub]' size='50' maxlength='150'><br><br>Message:<br><textarea name='welcome_note' rows='8' cols='70'>$admin_info[welcome_note]</textarea>
<br>
You may include the following user variables in your subject or message:<br><br>[name] = Customer Name<br>[email] = Email (username)<br>[password] = Password<br>[url] = Link to user's account.
</td>
</tr>
</table>
</td></tr></table>

<table cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF; margin-bottom: 10px;'>
<tr><td style='padding: 5px; padding-left: 7px;'>
<table width='502' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2'><b>New Account Approval/Rejection Settings</b><br>
<font class='small'>Turn signup approval/rejection on or off. This feature, when activated, will force new users to wait until you have approved their account in the <a href='users_pending.php'>Pending Users</a> section before they can login. Here you can specify the approval/rejection emails.</font><br><br></td>
</tr>
<tr>
<td colspan='2'><input type='checkbox' name='approve_deny' value='yes'"; if($admin_info[approve_deny] == "yes") { echo " checked"; } echo "> Turn on the signup approval/rejection feature?";
if($admin_info[approve_deny] == "yes" & mysql_num_rows(mysql_query("SELECT * FROM ims WHERE is_approved <> 'yes'")) > 0) { 
echo "<br>Warning: If you have any <a href='users_pending.php'>pending users</a> waiting to be rejected/approved, they will be approved and notified if you turn this feature off!<br>";
}
echo "
<br>
</td>
</tr>
<tr>
<td colspan='2'><input type='checkbox' name='appr_email' value='yes'"; if($admin_info[appr_email] == "yes") { echo " checked"; } echo "> Send an email to new users upon approval? If checked, enter the subject/message below.<br><br>Subject:<br><input type='text' class='text' name='appr_sub' value='$admin_info[appr_sub]' size='50' maxlength='150'><br><br>Message:<br><textarea name='appr_message' rows='8' cols='70'>$admin_info[appr_message]</textarea>
<br>
You may include the following user variables in your subject or message:<br><br>[name] = Customer Name<br> [email] = Email (username)<br> [password] = Password<br> [url] = Link to user's account.
</td>
</tr>
<tr>
<td>
<br>
<input type='checkbox' name='den_email' value='yes'"; if($admin_info[den_email] == "yes") { echo " checked"; } echo "> Send an email to new users upon rejection? If checked, enter the subject/message below.<br><br>Subject:<br><input type='text' class='text' name='den_sub' value='$admin_info[den_sub]' size='50' maxlength='150'><br><br>Message:<br><textarea name='den_message' rows='8' cols='70'>$admin_info[den_message]</textarea>
<br>
You may include the following user variables in your subject or message:<br><br>[name] = Customer Name<br>[email] = Email (username)<br>[password] = Password
</td>
</tr>
</table>
</td></tr></table>

<table cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF; margin-bottom: 10px;'>
<tr><td style='padding: 5px; padding-left: 7px;'>
<table width='502' cellpadding='0' cellspacing='0'>
<tr>
<td><b>User Display & Banning Settings</b><br>
These settings affect how your <a href='users.php'>User Manager</a> displays users. You
also have the option of banning user signups by email or IP address.
<br><br>
</td>
</tr>
<tr>
<td>
Display <select name='users_per_page'>
<option value='10'"; if($admin_info[users_per_page] == "10") { echo " selected"; } echo ">10</option>
<option value='25'"; if($admin_info[users_per_page] == "25") { echo " selected"; } echo ">25</option>
<option value='50'"; if($admin_info[users_per_page] == "50") { echo " selected"; } echo ">50</option>
<option value='100'"; if($admin_info[users_per_page] == "100") { echo " selected"; } echo ">100</option>
</select> users per page. Users are listed alphabetically.
</td>
</tr>
<tr>
<td>
Users are marked as \"inactive\" after <input type='text' name='inactivity' value='$admin_info[inactivity]' maxlength='3' size='2'> days. (Set inactivity to 0 to disable the feature.)
<br><br>
</td>
</tr>
<tr>
<td>
Ban signups by email (separate by commas only):<br> 
<textarea rows='3' cols='70' name='ban_email'>$admin_info[ban_email]</textarea><br><br>
Ban signups by IP address (separate by commas only):<br>
 <textarea rows='3' cols='70' name='ban_ip'>$admin_info[ban_ip]</textarea>
</td>
</tr>
</table>
</td></tr></table>

<table cellpadding='0' cellspacing='0'>
<tr><td>
<input class='button' type='submit' value='Save Changes'>
<input type='hidden' name='task' value='settings_do'>
</td>
</form>
</tr></table>
";

echo $footer;
?>