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


if($task == "settings_do") {
$site_name = str_replace("'", "&#39;", $_POST['site_name']);
$site_url = str_replace("'", "&#39;", $_POST['site_url']);
$login_name = $_POST['login_name'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$paypal_email = $_POST['paypal_email'];
$timezone = $_POST['timezone'];
$debug_mode = $_POST['debug_mode'];

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

if(preg_match("/[^a-z,A-Z,0-9,\_,\-]/", $login_name) | str_replace(" ", "", $login_name) == "") {
$is_error = "yes";
$error .= "Username contains invalid characters.<br>";
}

if(preg_match("/[^a-z,A-Z,0-9]/", $password)) {
$is_error = "yes";
$error .= "Password contains invalid characters.<br>";
}

if($password != $password2) { 
$is_error = "yes";
$error .= "Password does not match Confirmation Password.<br>";
}

if(!preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email) | str_replace(" ", "", $email) == "") {
$is_error = "yes";
$error .= "Email address is not valid.<br>";
}

$plans = mysql_num_rows(mysql_query("SELECT * FROM ims_plans WHERE price > 0"));
if($plans > 0) {
if(!preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $paypal_email) | str_replace(" ", "", $paypal_email) == "") {
$is_error = "yes";
$error .= "PayPal address is not valid.<br>";
}}

if($is_error == "yes") {
echo "
$header
<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td><b>Error</b></td>
</tr><tr>
<td>
$error
<b>Please use your browser's back button to try again.</b>
</td>
</tr>
</table>
$footer";
exit();
}

if($password != "") {
mysql_query("UPDATE ims_admin SET
site_name = '$site_name',
site_url = '$site_url',
login_name = '$login_name',
password = '$password',
email = '$email',
paypal_email = '$paypal_email',
timezone = '$timezone',
debug_mode = '$debug_mode'
");
$pass_cookie = encrypt($password);
setcookie("pass_cookie", "$pass_cookie", 0, "/"); 
} else {
mysql_query("UPDATE ims_admin SET
site_name = '$site_name',
site_url = '$site_url',
login_name = '$login_name',
email = '$email',
paypal_email = '$paypal_email',
timezone = '$timezone',
debug_mode = '$debug_mode'
");
}

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




echo $header;
echo "
<b>General Settings</b><br>
Welcome to your General Settings area. Use this page to configure the general settings of your IMS.<br>
<b>$results</b><br>

<form name='info' action='settings_general.php' method='POST'>
<table width='100' cellpadding='0' cellspacing='0'>
<tr>
<td>Website Name<br><input type='text' class='text' name='site_name' value='$admin_info[site_name]' size='23' maxlength='150'>&nbsp;&nbsp;</td>
<td>Website URL (e.g. http://www.yoursite.com)<br><input type='text' class='text' name='site_url' value='$admin_info[site_url]' size='49' maxlength='150'></td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td>Admin Username<br><input type='text' size='23' class='text' name='login_name' value='$admin_info[login_name]' maxlength='150'>&nbsp;&nbsp;</td>
<td>New Password<br><input type='password' size='23' name='password' maxlength='150'>&nbsp;&nbsp;</td>
<td>Confirm New Password<br><input type='password' size='23' name='password2' maxlength='150'></td>
</tr>
<tr><td colspan='3'>(Only use this if you want to change your login info - CaSe SeNsItIvE and alphanumeric characters only)</td></tr>
</table>

<br>

<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td>Admin/System Email Address</td>
</tr>
</table>
<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td><input type='text' class='text' name='email' value='$admin_info[email]' size='25' maxlength='150'><br>
<font class='small'>(All automatic emails sent by the IMS will use this address.)</font>
</td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td>PayPal Email Address</td>
</tr>
</table>
<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td><input type='text' class='text' name='paypal_email' value='$admin_info[paypal_email]' size='25' maxlength='150'><br>
<font class='small'>
(Enter your primary PayPal username here. 
Please note that this must be the email address
that you have designated as your <b>primary</b> login
for your PayPal account, otherwise the subscriptions may
not be created properly. WARNING: If you change this field after
users have already created subscriptions to the old address, each of
their subscriptions will need to be manually updated!)
</font>
</td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td>Timezone</td>
</tr>
</table>
<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td><select name='timezone' style='margin-top: 1px;'>
<option value='-8'"; if($admin_info[timezone] == "-8") { echo "selected"; } echo ">Pacific Time (US & Canada)</option>
<option value='-7'"; if($admin_info[timezone] == "-7") { echo "selected"; } echo ">Mountain Time (US & Canada)</option>
<option value='-6'"; if($admin_info[timezone] == "-6") { echo "selected"; } echo ">Central Time (US & Canada)</option>
<option value='-5'"; if($admin_info[timezone] == "-5") { echo "selected"; } echo ">Eastern Time (US & Canada)</option>
<option value='-4'"; if($admin_info[timezone] == "-4") { echo "selected"; } echo ">Atlantic Time (Canada)</option>
<option value='-9'"; if($admin_info[timezone] == "-9") { echo "selected"; } echo ">Alaska (US & Canada)</option>
<option value='-10'"; if($admin_info[timezone] == "-10") { echo "selected"; } echo ">Hawaii (US)</option>
<option value='-11'"; if($admin_info[timezone] == "-11") { echo "selected"; } echo ">Midway Island, Samoa</option>
<option value='-12'"; if($admin_info[timezone] == "-12") { echo "selected"; } echo ">Eniwetok, Kwajalein</option>
<option value='-3.3'"; if($admin_info[timezone] == "-3.3") { echo "selected"; } echo ">Newfoundland</option>
<option value='-3'"; if($admin_info[timezone] == "-3") { echo "selected"; } echo ">Brasilia, Buenos Aires, Georgetown</option>
<option value='-2'"; if($admin_info[timezone] == "-2") { echo "selected"; } echo ">Mid-Atlantic</option>
<option value='-1'"; if($admin_info[timezone] == "-1") { echo "selected"; } echo ">Azores, Cape Verde Is.</option>
<option value='0'"; if($admin_info[timezone] == "0") { echo "selected"; } echo ">Greenwich Mean Time (Lisbon, London)</option>
<option value='1'"; if($admin_info[timezone] == "1") { echo "selected"; } echo ">Amsterdam, Berlin, Paris, Rome, Madrid</option>
<option value='2'"; if($admin_info[timezone] == "2") { echo "selected"; } echo ">Athens, Helsinki, Istanbul, Cairo, E. Europe</option>
<option value='3'"; if($admin_info[timezone] == "3") { echo "selected"; } echo ">Baghdad, Kuwait, Nairobi, Moscow</option>
<option value='3.3'"; if($admin_info[timezone] == "3.3") { echo "selected"; } echo ">Tehran</option>
<option value='4'"; if($admin_info[timezone] == "4") { echo "selected"; } echo ">Abu Dhabi, Kazan, Muscat</option>
<option value='4.3'"; if($admin_info[timezone] == "4.3") { echo "selected"; } echo ">Kabul</option>
<option value='5'"; if($admin_info[timezone] == "5") { echo "selected"; } echo ">Islamabad, Karachi, Tashkent</option>
<option value='5.5'"; if($admin_info[timezone] == "5.5") { echo "selected"; } echo ">Bombay, Calcutta, New Delhi</option>
<option value='6'"; if($admin_info[timezone] == "6") { echo "selected"; } echo ">Almaty, Dhaka</option>
<option value='7'"; if($admin_info[timezone] == "7") { echo "selected"; } echo ">Bangkok, Jakarta, Hanoi</option>
<option value='8'"; if($admin_info[timezone] == "8") { echo "selected"; } echo ">Beijing, Hong Kong, Singapore, Taipei</option>
<option value='9'"; if($admin_info[timezone] == "9") { echo "selected"; } echo ">Tokyo, Osaka, Sapporto, Seoul, Yakutsk</option>
<option value='9.3'"; if($admin_info[timezone] == "9.3") { echo "selected"; } echo ">Adelaide, Darwin</option>
<option value='10'"; if($admin_info[timezone] == "10") { echo "selected"; } echo ">Brisbane, Melbourne, Sydney, Guam</option>
<option value='11'"; if($admin_info[timezone] == "11") { echo "selected"; } echo ">Magadan, Soloman Is., New Caledonia</option>
<option value='12'"; if($admin_info[timezone] == "12") { echo "selected"; } echo ">Fiji, Kamchatka, Marshall Is., Wellington</option>
</select><br>
<font class='small'>(Set this to your local timezone.)</font>
</td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td>Debugging Mode</td>
</tr>
</table>
<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td><input type='radio' name='debug_mode' value='on'"; if($admin_info[debug_mode] == "on") { echo " CHECKED"; } echo "> ON<br>
<input type='radio' name='debug_mode' value='off'"; if($admin_info[debug_mode] == "off") { echo " CHECKED"; } echo "> OFF<br>
<font class='small'>(When on, this feature will display errors.)</font>
</td>
</tr>
</table>

<br>

<table cellpadding='0' cellspacing='0' width='500'>
<tr>
<td colspan='2' style='padding: 0px; padding-top: 3px'>

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

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

";



echo $footer;
?>