<?
$page = "settings.php";
include "manager_header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }

if($user_status == "member") { exit(); }

// SET ERROR REPORTING VARIABLES
$is_error = "no";
$result = "";
$mailing_list_error = "";
$title_error = "";
$description_error = "";
$wc_id_error = "";
$entries_per_page_error = "";
$recent_entries_error = "";



// CHECK FOR ERRORS AND SAVE INFO
if($task == "dosave") {
$bad_words = explode(",", trim($admin_info[banned_badwords]));
$bad_words_replace = explode(",", trim($admin_info[banned_badwords_replace]));

$entries_per_page = htmlspecialchars(stripslashes($_POST['entries_per_page']), ENT_QUOTES);
$timezone = $_POST['timezone'];
$format_date = $_POST['format_date'];
$format_time = $_POST['format_time'];
$showtitle = $_POST['showtitle'];
$default_advanced = $_POST['default_advanced'];
$recent_entries = htmlspecialchars(stripslashes($_POST['recent_entries']), ENT_QUOTES);
$entry_default = str_replace("&lt;", "<", $_POST['entry_default']);
$title = str_replace($bad_words, $bad_words_replace, htmlspecialchars(stripslashes($_POST['title']), ENT_QUOTES));
$description = str_replace($bad_words, $bad_words_replace, htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES));
$wc_id = $_POST['wc_id'];


if($owner_group_info[allow_privacy] == 1) {
$default_privacy = $_POST['default_privacy'];
} else {
$default_privacy = $weblog_info[default_privacy];
}

if($owner_group_info[allow_mailinglist] == 1) {
$mailing_list = str_replace("&lt;", "<", $_POST['mailing_list']);
} else {
$mailing_list = "";
}

if($owner_group_info[allow_banning] == 1) {
$banned_ips = str_replace(" ", "", str_replace("&lt;", "<", $_POST['banned_ips']));
} else {
$banned_ips = "";
}

if($owner_group_info[allow_friends] == 1 & $owner_group_info[allow_multiauthor] == 1) {
$friends = $_POST['friends'];
} else {
$friends = "0";
}


// CHECK IF MAILING LIST IS OVER 30 EMAIL ADDRESSES
$num_list = substr_count($mailing_list, "@");
if($num_list > 30) { $is_error = "yes"; $mailing_list_error = "error"; }
// OTHER ERRORS
if(str_replace(" ", "", $title) == "" & $admin_info[field_title] == "3") { $is_error = "yes"; $title_error = "error"; }
if(str_replace(" ", "", $description) == "" & $admin_info[field_description] == "3") { $is_error = "yes"; $description_error = "error"; }
if($wc_id == "" & $admin_info[categories_on] == "2") { $is_error = "yes"; $wc_id_error = "error"; }
if($entries_per_page != (int) $entries_per_page | !is_numeric($entries_per_page) | $entries_per_page < 1) { $is_error = "yes"; $entries_per_page_error = "error"; } 
if($recent_entries != (int) $recent_entries | !is_numeric($recent_entries)) { $is_error = "yes"; $recent_entries_error = "error"; }


if($is_error != "yes") {
mysql_query("UPDATE bhost_weblogs SET wc_id='$wc_id', title='$title', description='$description', entries_per_page='$entries_per_page', recent_entries='$recent_entries', timezone='$timezone', format_date='$format_date', format_time='$format_time', showtitle='$showtitle', entry_default='$entry_default', default_advanced='$default_advanced', default_privacy='$default_privacy', mailing_list='$mailing_list', banned_ips='$banned_ips', friends='$friends' WHERE w_id='$weblog_info[w_id]'");
$weblog_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_weblogs WHERE w_id='$weblog_info[w_id]'"));
$result = "<img src='../images/saved_icon.gif' border='0' class='success'> <font class='success'>$settings2</font><br><br>";
}

$task = "main";
}




if($is_error != "yes") {
$title = $weblog_info[title];
$description = $weblog_info[description];
$wc_id = $weblog_info[wc_id];
$entries_per_page = $weblog_info[entries_per_page];
$recent_entries = $weblog_info[recent_entries];
$friends = $weblog_info[friends];
$timezone = $weblog_info[timezone];
$format_date = $weblog_info[format_date];
$format_time = $weblog_info[format_time];
$showtitle = $weblog_info[showtitle];
$default_advanced = $weblog_info[default_advanced];
$default_privacy = $weblog_info[default_privacy];
$entry_default = str_replace("<", "&lt;", $weblog_info[entry_default]);
$mailing_list = str_replace("<", "&lt;", $weblog_info[mailing_list]);
$banned_ips = str_replace("<", "&lt;", $weblog_info[banned_ips]);
} else {
$entry_default = str_replace("<", "&lt;", stripslashes($entry_default));
$mailing_list = str_replace("<", "&lt;", stripslashes($mailing_list));
$banned_ips = str_replace("<", "&lt;", stripslashes($banned_ips));
}




if($task == "main") {
echo $head;
echo "
<h2>$settings1</h2>
$settings4
<br><br>
$result
<table cellpadding='0' cellspacing='0' class='form'>
<form action='settings.php' method='POST'>
";

if($admin_info[field_title] != "0") {
echo "
<tr>
<td class='form1$title_error'>$settings25"; if($admin_info[field_title] == "3") { echo "*"; } echo "</td>
<td class='form2'><input type='text' class='text' name='title' size='50' value='$title' maxlength='250'>"; tip2("5", "6");
if($title_error == "error") { echo "<br>"; show_error($settings37); }
echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='title' value='$weblog_info[title]'>";
}

if($admin_info[field_description] != "0") {
echo "
<tr>
<td class='form1$description_error' valign='top'>$settings27"; if($admin_info[field_description] == "3") { echo "*"; } echo "</td>
<td class='form2'><textarea rows='4' cols='60' name='description'>$description</textarea>";
if($description_error == "error") { echo "<br>"; show_error($settings42); }
echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='description' value='$weblog_info[description]'>";
}


$categories = mysql_query("SELECT * FROM bhost_categories ORDER BY name");
if($admin_info[categories_on] == 1 & mysql_num_rows($categories) != 0) {
echo "

<tr>
<td class='form1$wc_id_error'>$settings30"; if($admin_info[categories_on] == "2") { echo "*"; } echo "</td>
<td class='form2'>
<select name='wc_id'>
<option></option>
";
while($category_info = mysql_fetch_assoc($categories)) {
echo "<option value='$category_info[wc_id]'"; if($wc_id == $category_info[wc_id]) { echo " SELECTED"; } echo ">$category_info[name]</option>";
}

echo "</select>"; 
if($wc_id_error == "error") { echo "<br>"; show_error($settings39); }
echo "
</td>
</tr>
";
} else {
 echo "<input type='hidden' name='wc_id' value='0'>";
}


$time = "460269000";


echo "
<tr>
<td class='form1$entries_per_page_error'>$settings5*</td>
<td class='form2'><input name='entries_per_page' value='$entries_per_page' maxlength='5' size='3'>"; tip2("27", "28");
if($entries_per_page_error == "error") { echo "<br>"; show_error($settings40); }
echo "
</td>
</tr>

<tr>
<td class='form1$recent_entries_error'>$settings7*</td>
<td class='form2'><input name='recent_entries' value='$recent_entries' maxlength='5' size='3'>"; tip2("29", "30");
if($recent_entries_error == "error") { echo "<br>"; show_error($settings41); }
echo "
</td>
</tr>
";


if($owner_group_info[allow_friends] == 1 & $owner_group_info[allow_multiauthor] == 1) {
echo "
<tr>
<td class='form1'>$settings33*</td>
<td class='form2'>
<select name='friends'>
<option value='0'"; if($friends == "0") { echo " SELECTED"; } echo ">$settings34</option>
<option value='1'"; if($friends == "1") { echo " SELECTED"; } echo ">$settings35</option>
<option value='2'"; if($friends == "2") { echo " SELECTED"; } echo ">$settings36</option>
</select>";tip2("66", "67");echo"
</td>
</tr>
";
} else {
echo "<input type='hidden' name='friends' value='0'>";
}


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

<tr>
<td class='form1'>$settings10*</td>
<td class='form2'><select name='format_date'>
<option value='n/j/Y'"; if($format_date == "n/j/Y") { echo " SELECTED"; } echo ">".cdate("n/j/Y", time())."</option>
<option value='n.j.Y'"; if($format_date == "n.j.Y") { echo " SELECTED"; } echo ">".cdate("n.j.Y", time())."</option>
<option value='n-j-Y'"; if($format_date == "n-j-Y") { echo " SELECTED"; } echo ">".cdate("n-j-Y", time())."</option>
<option value='Y/n/j'"; if($format_date == "Y/n/j") { echo " SELECTED"; } echo ">".cdate("Y/n/j", time())."</option>
<option value='Y-n-j'"; if($format_date == "Y-n-j") { echo " SELECTED"; } echo ">".cdate("Y-n-j", time())."</option>
<option value='Y-m-d'"; if($format_date == "Y-m-d") { echo " SELECTED"; } echo ">".cdate("Y-m-d", time())."</option>
<option value='Ynj'"; if($format_date == "Ynj") { echo " SELECTED"; } echo ">".cdate("Ynj", time())."</option>
<option value='j/n/Y'"; if($format_date == "j/n/Y") { echo " SELECTED"; } echo ">".cdate("j/n/Y", time())."</option>
<option value='j.n.Y'"; if($format_date == "j.n.Y") { echo " SELECTED"; } echo ">".cdate("j.n.Y", time())."</option>
<option value='M. j, Y'"; if($format_date == "M. j, Y") { echo " SELECTED"; } echo ">".cdate("M. j, Y", time())."</option>
<option value='F j, Y'"; if($format_date == "F j, Y") { echo " SELECTED"; } echo ">".cdate("F j, Y", time())."</option>
<option value='j F Y'"; if($format_date == "j F Y") { echo " SELECTED"; } echo ">".cdate("j F Y", time())."</option>
<option value='l, F j, Y'"; if($format_date == "l, F j, Y") { echo " SELECTED"; } echo ">".cdate("l, F j, Y", time())."</option>
<option value='l, F j'"; if($format_date == "l, F j") { echo " SELECTED"; } echo ">".cdate("l, F j", time())."</option>
<option value='l'"; if($format_date == "l") { echo " SELECTED"; } echo ">".cdate("l", time())."</option>
<option value='D-j-M-Y'"; if($format_date == "D-j-M-Y") { echo "SELECTED"; } echo ">".cdate("D-j-M-Y", time())."</option>
<option value='D j M Y'"; if($format_date == "D j M Y") { echo "SELECTED"; } echo ">".cdate("D j M Y", time())."</option>
<option value='D j F Y'"; if($format_date == "D j F Y") { echo "SELECTED"; } echo ">".cdate("D j F Y", time())."</option>
<option value='l j F Y'"; if($format_date == "l j F Y") { echo "SELECTED"; } echo ">".cdate("l j F Y", time())."</option>
<option value='Y-M-j'"; if($format_date == "Y-M-j") { echo "SELECTED"; } echo ">".cdate("Y-M-j", time())."</option>
<option value='j-M-Y'"; if($format_date == "j-M-Y") { echo "SELECTED"; } echo ">".cdate("j-M-Y", time())."</option>
</select>
</td>
</tr>

<tr>
<td class='form1'>$settings11*</td>
<td class='form2'>
<select name='format_time'>
<option value='g:i A'"; if($format_time == "g:i A") { echo " SELECTED"; } echo ">".cdate("g:i A", $time)."</option>
<option value='h:i A'"; if($format_time == "h:i A") { echo " SELECTED"; } echo ">".cdate("h:i A", $time)."</option>
<option value='g:i'"; if($format_time == "g:i") { echo " SELECTED"; } echo ">".cdate("g:i", $time)."</option>
<option value='h:i'"; if($format_time == "h:i") { echo " SELECTED"; } echo ">".cdate("h:i", $time)."</option>
<option value='H:i'"; if($format_time == "H:i") { echo " SELECTED"; } echo ">".cdate("H:i", $time)."</option>
<option value='H\hi'"; if($format_time == "H\hi") { echo " SELECTED"; } echo ">".cdate("H\hi", $time)."</option>
</select>
</td>
</tr>

<tr>
<td class='form1'>$settings12*</td>
<td class='form2'>
<select name='showtitle'>
<option value='1'"; if($showtitle == "1") { echo " SELECTED"; } echo ">$settings13</option>
<option value='0'"; if($showtitle == "0") { echo " SELECTED"; } echo ">$settings14</option>
</select>";tip2("31", "32");echo"
</td>
</tr>

<tr>
<td class='form1'>$settings3</td>
<td class='form2'><select name='default_advanced'>
<option value='1'"; if($default_advanced == "1") { echo " SELECTED"; } echo ">$settings13</option>
<option value='0'"; if($default_advanced == "0") { echo " SELECTED"; } echo ">$settings14</option>
</select>
</td>
</tr>
";

if($owner_group_info[allow_privacy] == 1) {
echo "
<tr>
<td class='form1'>$settings16*</td>
<td class='form2'><select name='default_privacy'>
<option value='3'"; if($default_privacy == "3") { echo " SELECTED"; } echo ">$settings17</option>
<option value='2'"; if($default_privacy == "2") { echo " SELECTED"; } echo ">$settings18</option>
<option value='1'"; if($default_privacy == "1") { echo " SELECTED"; } echo ">$settings19</option>
<option value='0'"; if($default_privacy == "0") { echo " SELECTED"; } echo ">$settings20</option>
</select>";tip2("34", "35");echo"
</td>
</tr>
";
}

echo "
<tr>
<td class='form1' valign='top'>$settings23</td>
<td class='form2'><textarea name='entry_default' rows='6' cols='40' class='settings'>$entry_default</textarea>";tip2("36", "37");echo "<br><div class='help'>$settings31</div></td>
</tr>
";

if($owner_group_info[allow_mailinglist] == 1) {
echo "
<tr>
<td class='form1$mailing_list_error' valign='top'>$settings26</td>
<td class='form2'><textarea name='mailing_list' rows='3' cols='40' class='settings'>$mailing_list</textarea>";tip2("38", "39"); echo "<br><div class='help'>$settings32</div>";
if($mailing_list_error == "error") { echo "<br>"; show_error($settings38); }
echo "
</td>
</tr>
";
}

if($owner_group_info[allow_banning] == 1) {
echo "
<tr>
<td class='form1' valign='top'>$settings29</td>
<td class='form2'><textarea name='banned_ips' rows='3' cols='40' class='settings'>$banned_ips</textarea>";tip2("40", "41");echo "</td>
</tr>
";
}

echo "
</table>
<br>
<input type='submit' class='button' value='$settings28'>
<input type='hidden' name='task' value='dosave'>
</form>
";

echo $foot;
}
?>