<?
$page = "edit_profile.php";
include "manager_header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }


// SET ERROR VARS
$is_error = "";
$avatar_error = "";
$avatar_size = "";
$avatar_type = "";
$avatar_dim = "";
$display_name_error = "";
$lname_error = "";
$fname_error = "";
$email_error = "";
$birthday_error = "";
$website_error = "";
$screenname_error = "";
$gender_error = "";
$city_error = "";
$state_error = "";
$country_error = "";
$interests_error = "";
$custom_fields = mysql_query("SHOW COLUMNS FROM bhost_profile FROM `$mysql_database`");
while($custom = mysql_fetch_assoc($custom_fields)) {
if($custom[Field] != "p_id" & $custom[Field] != "u_id") {
${"$custom[Field]_error"} = "";
}}




if($task == "save_do") {

// CREATE BAD WORD ARRAYS
$bad_words = explode(",", trim($admin_info[banned_badwords]));
$bad_words_replace = explode(",", trim($admin_info[banned_badwords_replace]));
$language = $_POST['language'];
$show_name = $_POST['show_name'];
$show_email = $_POST['show_email'];
$show_friendlist = $_POST['show_friendlist'];
$show_userstats = $_POST['show_userstats'];
$show_teammembers = $_POST['show_teammembers'];
$profile_privacy = $_POST['profile_privacy'];
$fname = htmlspecialchars(stripslashes($_POST['fname']), ENT_QUOTES);
$lname = htmlspecialchars(stripslashes($_POST['lname']), ENT_QUOTES);
$display_name = str_replace($bad_words, $bad_words_replace, htmlspecialchars(stripslashes($_POST['display_name']), ENT_QUOTES));
$email = htmlspecialchars(stripslashes($_POST['email']), ENT_QUOTES);
$website = htmlspecialchars(stripslashes($_POST['website']), ENT_QUOTES);
$screenname = htmlspecialchars(stripslashes($_POST['screenname']), ENT_QUOTES);
$screenname_type = $_POST['screenname_type'];
$gender = $_POST['gender'];
$city = htmlspecialchars(stripslashes($_POST['city']), ENT_QUOTES);
$state = htmlspecialchars(stripslashes($_POST['state']), ENT_QUOTES);
$country = $_POST['country'];
$interests = htmlspecialchars(stripslashes($_POST['interests']), ENT_QUOTES);

$birthday_month = $_POST['birthday_month'];
$birthday_day = $_POST['birthday_day'];
$birthday_year = $_POST['birthday_year'];
 if($birthday_month == 0 | $birthday_day == 0 | $birthday_year == 0) {
  $b_month = 0;
  $b_day = 0;
  $b_year = 0;
 } else {
  $b_month = $birthday_month;
  $b_day = $birthday_day;
  $b_year = $birthday_year;
 }
$birthday = MakeTime("0", "0", "0", "$b_month", "$b_day", "$b_year");
if($show_name != 1) { $show_name = 0; }
if($show_email != 1) { $show_email = 0; }


// SET ERRORS
if(str_replace(" ", "", $display_name) == "" & $admin_info[field_display_name] == "3") { $is_error = "yes"; $display_name_error = "error"; $error[display_name] = "$edit_profile48"; }
if(str_replace(" ", "", $lname) == "" & $admin_info[field_lname] == "3") { $is_error = "yes"; $lname_error = "error"; $error[lname] = "$edit_profile20"; }
if(str_replace(" ", "", $fname) == "" & $admin_info[field_fname] == "3") { $is_error = "yes"; $fname_error = "error"; $error[fname] = "$edit_profile16"; }
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)) { $is_error = "yes"; $email_error = "error"; $error[email] = "$edit_profile30"; }
if($birthday == "-2019787262" & $admin_info[field_birthday] == "3") { $is_error = "yes"; $birthday_error = "error"; $error[birthday] = "$edit_profile6"; }
if(str_replace(" ", "", $website) == "" & $admin_info[field_website] == "3") { $is_error = "yes"; $website_error = "error"; $error[website] = "$edit_profile34"; }
if(str_replace(" ", "", $screenname) == "" & $admin_info[field_screenname] == "3") { $is_error = "yes"; $screenname_error = "error"; $error[screenname] = "$edit_profile36"; }
if(str_replace(" ", "", $gender) == "" & $admin_info[field_gender] == "3") { $is_error = "yes"; $gender_error = "error"; $error[gender] = "$edit_profile38"; }
if(str_replace(" ", "", $city) == "" & $admin_info[field_city] == "3") { $is_error = "yes"; $city_error = "error"; $error[city] = "$edit_profile43"; }
if(str_replace(" ", "", $state) == "" & $admin_info[field_state] == "3") { $is_error = "yes"; $state_error = "error"; $error[state] = "$edit_profile45"; }
if(str_replace(" ", "", $country) == "" & $admin_info[field_country] == "3") { $is_error = "yes"; $country_error = "error"; $error[country] = "$edit_profile46"; }
if(str_replace(" ", "", $interests) == "" & $admin_info[field_interests] == "3") { $is_error = "yes"; $interests_error = "error"; $error[interests] = "$edit_profile47"; }




$custom_fields = mysql_query("SHOW COLUMNS FROM bhost_profile FROM `$mysql_database`");
while($custom = mysql_fetch_assoc($custom_fields)) {
 if($custom[Field] != "p_id" & $custom[Field] != "u_id") {
  $custom_name = str_replace("_", " ", substr($custom[Field], 0, -3));
  $custom_required = substr($custom[Field], -3, 2);
  $custom_field = $custom[Field];
  $custom_field_value = $_POST[$custom_field];
  ${"$custom[Field]_value"} = htmlspecialchars(stripslashes($custom_field_value), ENT_QUOTES);
  if($custom_required == "_3" & str_replace(" ", "", $custom_field_value) == "") {
  $is_error = "yes";
  ${"$custom[Field]_error"} = "error";
  $error[custom] = "$edit_profile4";
  }
 }
}



if($is_error != "yes") {
$is_error = "no";




// PROCESS INTERESTS
$interests = str_replace(", ", ",", $interests);



// UPDATE THE USER
mysql_query("UPDATE bhost_users SET fname='$fname', lname='$lname', email='$email', language='$language', display_name='$display_name', website='$website', screenname='$screenname', screenname_type='$screenname_type', gender='$gender', birthday='$birthday', city='$city', state='$state', country='$country', interests='$interests', show_name='$show_name', show_email='$show_email', show_friendlist='$show_friendlist', show_userstats='$show_userstats', show_teammembers='$show_teammembers', profile_privacy='$profile_privacy' WHERE u_id='$user_info[u_id]'");
$user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_users WHERE u_id='$user_info[u_id]'"));

$custom_fields = mysql_query("SHOW COLUMNS FROM bhost_profile FROM `$mysql_database`");
$user_profile = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_profile WHERE u_id='$user_info[u_id]'"));
while($custom = mysql_fetch_assoc($custom_fields)) {
 if($custom[Field] != "p_id" & $custom[Field] != "u_id") {
  $custom_name = str_replace("_", " ", substr($custom[Field], 0, -3));
  $custom_required = substr($custom[Field], -3, 2);
  $custom_field = $custom[Field];
  $custom_field_value = $_POST[$custom_field];
  if($custom_required != "_0") {
  $custom_field_value = str_replace("'", "&#39;", str_replace($bad_words, $bad_words_replace, htmlspecialchars($custom_field_value)));
  mysql_query("UPDATE bhost_profile SET $custom_field='$custom_field_value' WHERE u_id='$user_info[u_id]'");
  }
 }
}
}
$task = "main";
}















if($task == "avatar_remove") {
if($user_info[avatar] != "") {
$avatar = "../uploads/avatars/".basename($user_info[avatar]);
@unlink($avatar);
mysql_query("UPDATE bhost_users SET avatar='' WHERE u_id='$user_info[u_id]'");
header("Location: edit_profile.php");
exit();
}
}







if($task == "avatar_upload") {

$file_name = $_FILES['avatar']['name'];
$file_type = $_FILES['avatar']['type'];
$file_size = $_FILES['avatar']['size'];
$file_tempname = $_FILES['avatar']['tmp_name'];
$file_error = $_FILES['avatar']['error'];
$sizes = @getimagesize($file_tempname);

// FILE IS AN UPLOADED FILE, LOOK FOR PROBLEMS
if(!is_uploaded_file($file_tempname)) {
header("Location: edit_profile.php");
exit();
}

// CHECK FILESIZE
if($file_size > (1024*$admin_info[avatar_filesize])) {
$avatar_error = "error";
$avatar_size = "yes";
}

// CHECK THAT IMAGE IS JPG, GIF, OR PNG, THEN CHECK MIME TYPES
$ext = strtolower(strrchr($file_name, "."));
$ext = str_replace(".", "", $ext);
$type = strtolower($file_type);

if($ext == "jpg" OR $ext == "jpeg") {
if($type != "image/jpeg" AND $type != "image/jpg" AND $type != "image/jpe" AND $type != "image/pjpeg" AND $type != "image/pjpg" AND $type != "image/x-jpeg" AND $type != "image/x-jpg") {
$avatar_error = "error";
$avatar_type = "yes";
}
} elseif($ext == "gif") {
if($type != "image/gif" AND $type != "image/x-gif") {
$avatar_error = "error";
$avatar_type = "yes";
}
} elseif($ext == "png") {
if($type != "image/png" AND $type != "image/x-png") {
$avatar_error = "error";
$avatar_type = "yes";
}
} else {
$avatar_error = "error";
$avatar_type = "yes";
}

// CHECK FILETYPES AGAIN TO BE SURE
if($sizes == false) {
$avatar_error = "error";
$avatar_type = "yes";
}

// IF IMAGE IS TOO BIG, SHOW ERROR
$width = $sizes[0];
$height = $sizes[1];
if($width > $admin_info[avatar_width] OR $height > $admin_info[avatar_height]) { 
$avatar_error = "error";
$avatar_dim = "yes";
}




// SHOW ERROR
if($avatar_error == "") { 
// DELETE OLD AVATAR
if($user_info[avatar] != "") {
$old_avatar = "../uploads/avatars/".basename($user_info[avatar]);
@unlink($old_avatar);
}


// RENAME IMAGE
$rand = rand(1000, 9999);
$newfilename = "$user_info[u_id]_$rand.$ext";
$path = "/uploads/avatars/$newfilename";
$server_array = explode("/", $_SERVER['PHP_SELF']);
$server_info = implode("/", $server_array);
$avatar_path = str_replace("/manager/edit_profile.php", "$path", "http://".$_SERVER['HTTP_HOST'].$server_info);

	// SUCCESS, UPLOAD FILE
	if(move_uploaded_file($file_tempname, "..".$path)) {
		mysql_query("UPDATE bhost_users SET avatar='$avatar_path' WHERE u_id='$user_info[u_id]'");
		@chmod($path, 0777);
	} else {
                // ERROR

                header("Location: edit_profile.php");
		exit();
	}

}
$user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_users WHERE u_id='$user_info[u_id]'"));
$task = "main";
}






















// SET VARS
if($is_error != "yes") {
$fname = $user_info[fname];
$lname = $user_info[lname];
$email = $user_info[email];
$display_name = $user_info[display_name];
$website = $user_info[website];
$screenname = $user_info[screenname];
$screenname_type = $user_info[screenname_type];
$gender = $user_info[gender];
if($user_info[birthday] != "-2019787262") {
 $birthday = MakeDate($user_info[birthday]);
 $birthday_month = $birthday[0];
 $birthday_day = $birthday[1];
 $birthday_year = $birthday[2];
} else {
 $birthday_month = 0;
 $birthday_day = 0;
 $birthday_year = 0;
}
$city = $user_info[city];
$state = $user_info[state];
$country = $user_info[country];
$language = $user_info[language];
$interests = $user_info[interests];
$custom_fields = mysql_query("SHOW COLUMNS FROM bhost_profile FROM `$mysql_database`");
$user_profile = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_profile WHERE u_id='$user_info[u_id]'"));
while($custom = mysql_fetch_assoc($custom_fields)) {
 if($custom[Field] != "p_id" & $custom[Field] != "u_id") {
  $custom_name = str_replace("_", " ", substr($custom[Field], 0, -3));
  $custom_required = substr($custom[Field], -3, 2);
  $custom_field = $custom[Field];
  $custom_field_value = $user_profile[$custom_field];
  ${"$custom[Field]_value"} = $custom_field_value;
 }
}
}










if($task == "main") {
echo $head;

$profile_url = url("profile", "", "$user_info[username]");

echo "
<h2>$edit_profile7 <font class='url'>( <a href='$profile_url'>$profile_url</a> )</font></h2>
$edit_profile8

<br><br>
"; 

if($is_error == "no") { 
echo "<img src='../images/saved_icon.gif' border='0' class='success'> <font class='success'>$edit_profile14</font><br><br>"; 
} elseif($is_error == "yes") {
 show_error($edit_profile5);
 echo "<br>";
}

// SHOW AVATAR UPLOAD FIELD
if($admin_info[allow_avatars] == "1") {
echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td valign='top'>

  <table cellpadding='0' cellspacing='0' class='form'>
  <form action='edit_profile.php' name='avatarform' method='POST' enctype='multipart/form-data'>
  <tr>
  <td class='form1$avatar_error' NOWRAP>
  $edit_profile60<br><br>
  <input type='file' name='avatar' class='text' size='45'>
  <input type='submit' value='$edit_profile61'>&nbsp;&nbsp;
  <div class='help'>
  "; if($avatar_size == "yes") { echo "<font class='error'>$edit_profile62 $admin_info[avatar_filesize]kb.</font>"; } else { echo "$edit_profile62 $admin_info[avatar_filesize]kb."; } echo "<br>
  "; if($avatar_type == "yes") { echo "<font class='error'>$edit_profile63</font>"; } else { echo "$edit_profile63"; } echo "<br>
  "; if($avatar_dim == "yes") { echo "<font class='error'>$edit_profile56 $admin_info[avatar_width]x$admin_info[avatar_height]px.</font>"; } else { echo "$edit_profile56 $admin_info[avatar_width]x$admin_info[avatar_height]px."; } echo "
  </div>
  </td>
  </tr>
  <input type='hidden' name='task' value='avatar_upload'>
  <input type='hidden' name='MAX_FILE_SIZE' value='10000000'>
  </form>
  </table>

</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td align='center'>
";

if($user_info[avatar] == "") {
echo "<img src='../images/noavatar.gif' border='0' class='avatar'>";
} else {
echo "
<img src='$user_info[avatar]' border='0' class='avatar'><br>
<div class='help'>[ <a href='edit_profile.php?task=avatar_remove'>$edit_profile64</a> ]</div>
";
}

echo "
</td>
</tr>
</table>

<br>
";

}



echo "
<table cellpadding='0' cellspacing='0' class='form'>
<form action='edit_profile.php' method='POST' name='profilepage'>
";
if($admin_info[field_fname] != "0") {
echo "
<tr>
<td class='form1$fname_error'>$edit_profile9"; if($admin_info[field_fname] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='fname' value='$fname'>"; show_error($error[fname]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='fname' value='$user_info[fname]'>";
}

if($admin_info[field_lname] != "0") {
echo "
<tr>
<td class='form1$lname_error'>$edit_profile10"; if($admin_info[field_lname] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='lname' value='$lname'>"; show_error($error[lname]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='lname' value='$user_info[lname]'>";
}

echo "
<tr>
<td class='form1$email_error'>$edit_profile11*</td>
<td class='form2'>
<input type='text' class='text' name='email' value='$email'>"; show_error($error[email]); echo "
</td>
</tr>
";

if($admin_info[field_display_name] != "0") {
echo "
<tr>
<td class='form1$display_name_error' valign='top'>$edit_profile12"; if($admin_info[field_display_name] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='display_name' value='$display_name'>
<div class='help'>$edit_profile1</div>
"; show_error($error[display_name]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='display_name' value='$user_info[display_name]'>";
}



if($admin_info[field_website] != 0) {
echo "
<tr>
<td class='form1$website_error' valign='top'>$edit_profile17"; if($admin_info[field_website] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='website' value='$website' size='40'>
<div class='help'>$edit_profile3</div>
"; show_error($error[website]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='website' value='$user_info[website]'>";
}



if($admin_info[field_screenname] != 0) {
echo "
<tr>
<td class='form1$screenname_error' valign='top'>$edit_profile19"; if($admin_info[field_screenname] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='screenname' value='$screenname' size='28'>
<select name='screenname_type'>
<option value='AIM'"; if($screenname_type == "AIM") { echo " SELECTED"; } echo ">AIM</option>
<option value='ICQ'"; if($screenname_type == "ICQ") { echo " SELECTED"; } echo ">ICQ</option>
<option value='MSN'"; if($screenname_type == "MSN") { echo " SELECTED"; } echo ">MSN</option>
<option value='Yahoo!'"; if($screenname_type == "Yahoo!") { echo " SELECTED"; } echo ">Yahoo!</option>
</select>
<div class='help'>$edit_profile2</div>
"; show_error($error[screenname]); echo "
</td>
</tr>
";
} else {
echo "
<input type='hidden' name='screenname' value='$user_info[screenname]'>
<input type='hidden' name='screenname_type' value='$user_info[screenname_type]'>
";
}


if($admin_info[field_gender] != 0) {
echo "
<tr>
<td class='form1$gender_error'>$edit_profile21"; if($admin_info[field_gender] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<select name='gender'>
<option></option>
<option value='$edit_profile22'"; if($gender == "$edit_profile22") { echo " SELECTED"; } echo ">$edit_profile22</option>
<option value='$edit_profile23'"; if($gender == "$edit_profile23") { echo " SELECTED"; } echo ">$edit_profile23</option>
</select>"; show_error($error[gender]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='gender' value='$user_info[gender]'>";
}









if($admin_info[field_birthday] != 0) {

$thism = $birthday_month;
$thisd = $birthday_day;
$thisy = $birthday_year;

// MONTHBOX
if($admin_info[signup_format_date] == "n/j/Y" OR $admin_info[signup_format_date] == "n.j.Y" OR $admin_info[signup_format_date] == "n-j-Y" OR $admin_info[signup_format_date] == "Y/n/j" OR $admin_info[signup_format_date] == "Y-n-j" OR $admin_info[signup_format_date] == "Ynj" OR $admin_info[signup_format_date] == "j/n/Y" OR $admin_info[signup_format_date] == "j.n.Y") {
 $mf = "n";
} elseif($admin_info[signup_format_date] == "Y-m-d") { 
 $mf = "m";
} elseif($admin_info[signup_format_date] == "M. j, Y" OR $admin_info[signup_format_date] == "l") {
 $mf = "M";
} elseif($admin_info[signup_format_date] == "F j, Y" OR $admin_info[signup_format_date] == "l, F j, Y" OR $admin_info[signup_format_date] == "l j F Y" OR $admin_info[signup_format_date] == "l, F j" OR $admin_info[signup_format_date] == "j F Y") {
 $mf = "F";
}

$mbox = "
<select name='birthday_month'>
<option value='0'></option>
<option"; if($thism == "1") { $mbox .= " SELECTED"; } $mbox .= " value='1'>".cdate("$mf", "864000")."</option>
<option"; if($thism == "2") { $mbox .= " SELECTED"; } $mbox .= " value='2'>".cdate("$mf", "3542400")."</option>
<option"; if($thism == "3") { $mbox .= " SELECTED"; } $mbox .= " value='3'>".cdate("$mf", "6220800")."</option>
<option"; if($thism == "4") { $mbox .= " SELECTED"; } $mbox .= " value='4'>".cdate("$mf", "8899200")."</option>
<option"; if($thism == "5") { $mbox .= " SELECTED"; } $mbox .= " value='5'>".cdate("$mf", "11577600")."</option>
<option"; if($thism == "6") { $mbox .= " SELECTED"; } $mbox .= " value='6'>".cdate("$mf", "14256000")."</option>
<option"; if($thism == "7") { $mbox .= " SELECTED"; } $mbox .= " value='7'>".cdate("$mf", "16934400")."</option>
<option"; if($thism == "8") { $mbox .= " SELECTED"; } $mbox .= " value='8'>".cdate("$mf", "19612800")."</option>
<option"; if($thism == "9") { $mbox .= " SELECTED"; } $mbox .= " value='9'>".cdate("$mf", "22291200")."</option>
<option"; if($thism == "10") { $mbox .= " SELECTED"; } $mbox .= " value='10'>".cdate("$mf", "24969600")."</option>
<option"; if($thism == "11") { $mbox .= " SELECTED"; } $mbox .= " value='11'>".cdate("$mf", "27648000")."</option>
<option"; if($thism == "12") { $mbox .= " SELECTED"; } $mbox .= " value='12'>".cdate("$mf", "30326400")."</option>
</select>
";


// DAYBOX
if($admin_info[signup_format_date] == "Y-m-d") { $z = "0"; } else { $z = ""; }
$dbox = "<select name='birthday_day'><option value='0'></option>";
$daycount = 1;
while($daycount <= 31) {
if($z == "0" AND $daycount > 9) { $z = ""; }
$dbox .= "
<option"; if($thisd == "$daycount") { $dbox .= " SELECTED"; } $dbox .= " value='$daycount'>".$z."$daycount</option>
";
$daycount++;
}
$dbox .= "</select>";

// YEARBOX
$ybox = "<select name='birthday_year'><option value='0'></option>";
$endyear = 1920;
$count = cdate("Y", time());
while($count >= $endyear) {
$ybox .= "
<option"; if($thisy == "$count") { $ybox .= " SELECTED"; } $ybox .= " value='$count'>$count</option>
";
$count--;
}

$ybox .= "</select>";


if($admin_info[signup_format_date] == "n/j/Y" OR $admin_info[signup_format_date] == "n.j.Y" OR $admin_info[signup_format_date] == "n-j-Y" OR $admin_info[signup_format_date] == "M. j, Y" OR $admin_info[signup_format_date] == "F j, Y" OR $admin_info[signup_format_date] == "l, F j, Y") {
$boxes = "$mbox $dbox $ybox";
} elseif($admin_info[signup_format_date] == "Y/n/j" OR $admin_info[signup_format_date] == "Y-n-j" OR $admin_info[signup_format_date] == "Y-m-d" OR $admin_info[signup_format_date] == "Ynj") {
$boxes = "$ybox $mbox $dbox";
} elseif($admin_info[signup_format_date] == "j/n/Y" OR $admin_info[signup_format_date] == "j.n.Y" OR $admin_info[signup_format_date] == "j F Y"  OR $admin_info[signup_format_date] == "l j F Y") {
$boxes = "$dbox $mbox $ybox";
} elseif($admin_info[signup_format_date] == "l, F j" OR $admin_info[signup_format_date] == "l") {
$boxes = "$mbox $dbox $ybox"; 
}

echo "
<tr>
<td class='form1$birthday_error'>$edit_profile24"; if($admin_info[field_birthday] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<table cellpadding='0' cellspacing='0'>
<tr><td>$boxes</td></tr>
</table>
"; show_error($error[birthday]); echo "
</td>
</tr>
";
} else {
$thism = cdate("n", $user_info[birthday]);
$thisd = cdate("j", $user_info[birthday]);
$thisy = cdate("Y", $user_info[birthday]);
echo "
<input type='hidden' name='birthday_month' value='$thism'>
<input type='hidden' name='birthday_day' value='$thisd'>
<input type='hidden' name='birthday_year' value='$thisy'>
";
}









if($admin_info[field_city] != 0) {
echo "
<tr>
<td class='form1$city_error'>$edit_profile26"; if($admin_info[field_city] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='city' value='$city' size=30'>"; show_error($error[city]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='city' value='$user_info[city]'>";
}


if($admin_info[field_state] != 0) {
echo "
<tr>
<td class='form1$state_error'>$edit_profile27"; if($admin_info[field_state] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<input type='text' class='text' name='state' value='$state' size='30'>"; show_error($error[state]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='state' value='$user_info[state]'>";
}


if($admin_info[field_country] != 0) {
$c = $country;
include "../countries.php";
echo "
<tr>
<td class='form1$country_error'>$edit_profile28"; if($admin_info[field_country] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<select name='country'>
$countrylist
</select>"; show_error($error[country]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='country' value='$user_info[country]'>";
}





if($group_info[allow_language] == "1") {
// SHOW LANGUAGE
echo "
<tr>
<td class='form1' valign='top'>$edit_profile54</td>
<td class='form2'>
<select name='language'>
";
$handle = opendir("../lang/"); 
 while($filename = readdir($handle)) {
  if ($filename != "." && $filename != ".." && $filename != "index.php") {
   echo "<option value='$filename'"; if($language == "$filename") { echo " SELECTED"; } echo ">$filename</option>";
  }
 }
closedir($handle);

echo "
</select><br><div class='help'>$edit_profile55</div>
</td></tr>
";
}




if($admin_info[field_interests] != 0) {

$interests = str_replace(",", ", ", $interests);

echo "
<tr>
<td class='form1$interests_error' valign='top'>$edit_profile44"; if($admin_info[field_interests] == "3") { echo "*"; } echo "</td>
<td class='form2'>
<textarea name='interests' rows='4' cols='60'>$interests</textarea>"; show_error($error[interests]); echo "
</td>
</tr>
";
} else {
echo "<input type='hidden' name='interests' value='$user_info[interests]'>";
}










$custom_fields = mysql_query("SHOW COLUMNS FROM bhost_profile FROM `$mysql_database`");
$user_profile = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_profile WHERE u_id='$user_info[u_id]'"));
while($custom = mysql_fetch_assoc($custom_fields)) {
 if($custom[Field] != "p_id" & $custom[Field] != "u_id") {
  $custom_name = str_replace("_", " ", substr($custom[Field], 0, -3));
  $custom_required = substr($custom[Field], -3, 2);
  $custom_type = $custom[Type];
  $custom_field = $custom[Field];
  $required = "";
  if($custom_required == "_3") { $required = "*"; }
  if($custom_required != "_0") {
   if(${"$custom[Field]_error"} != "") { $custom_error = $error[custom]; } else { $custom_error = ""; }
  echo "
<tr>";
 if($custom_type == "text") {
 echo "<td class='form1".${"$custom[Field]_error"}."' valign='top'>$custom_name$required</td><td class='form2'><textarea name='$custom_field' rows='4' cols='60'>".${"$custom[Field]_value"}."</textarea>"; show_error($custom_error);
 } else {
 echo "<td class='form1'>$custom_name$required</td><td class='form2'><input type='text' class='text' name='$custom_field' maxlength='250' size='40' value='".${"$custom[Field]_value"}."'>"; show_error($custom_error);
 }
$tips = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_profile WHERE u_id='0'"));
tip($tips[$custom_field]);
echo "
</td>
</tr>
  ";
  }
 }
}


echo "
<tr>
<td class='form1'>$edit_profile31</td>
<td class='form2' style='padding-left: 5px;'>
<table cellpadding='0' cellspacing='0'><tr>
<td><input type='radio' name='show_name' value='1'"; if($user_info[show_name] == "1") { echo " CHECKED"; } echo "></td><td>$edit_profile32&nbsp;&nbsp; </td>
<td><input type='radio' name='show_name' value='0'"; if($user_info[show_name] == "0") { echo " CHECKED"; } echo "></td><td>$edit_profile33</td>
<td>&nbsp;"; tip2("44", "45"); echo "</td>
</tr></table>
</td>
</tr>

<tr>
<td class='form1'>$edit_profile35</td>
<td class='form2' style='padding-left: 5px;'>
<table cellpadding='0' cellspacing='0'><tr>
<td><input type='radio' name='show_email' value='1'"; if($user_info[show_email] == "1") { echo " CHECKED"; } echo "></td><td>$edit_profile32&nbsp;&nbsp; </td>
<td><input type='radio' name='show_email' value='0'"; if($user_info[show_email] == "0") { echo " CHECKED"; } echo "></td><td>$edit_profile33</td>
<td>&nbsp;"; tip2("46", "47"); echo "</td>
</tr></table>
</td>
</tr>
";

if($admin_info[show_friendlist] == 1 AND $group_info[allow_friends] == 1) {
echo "
<tr>
<td class='form1'>$edit_profile37</td>
<td class='form2' style='padding-left: 5px;'>
<table cellpadding='0' cellspacing='0'><tr>
<td><input type='radio' name='show_friendlist' value='1'"; if($user_info[show_friendlist] == "1") { echo " CHECKED"; } echo "></td><td>$edit_profile32&nbsp;&nbsp; </td>
<td><input type='radio' name='show_friendlist' value='0'"; if($user_info[show_friendlist] == "0") { echo " CHECKED"; } echo "></td><td>$edit_profile33</td>
<td>&nbsp;"; tip2("48", "49"); echo "</td>
</tr></table>
</td>
</tr>
";
}

if($admin_info[show_userstats] == 1) {
echo "
<tr>
<td class='form1'>$edit_profile39</td>
<td class='form2' style='padding-left: 5px;'>
<table cellpadding='0' cellspacing='0'><tr>
<td><input type='radio' name='show_userstats' value='1'"; if($user_info[show_userstats] == "1") { echo " CHECKED"; } echo "></td><td>$edit_profile32&nbsp;&nbsp; </td>
<td><input type='radio' name='show_userstats' value='0'"; if($user_info[show_userstats] == "0") { echo " CHECKED"; } echo "></td><td>$edit_profile33</td>
<td>&nbsp;"; tip2("50", "51"); echo "</td>
</tr></table>
</td>
</tr>
";
}


if($group_info[allow_multiauthor] == 1 & $admin_info[show_teammembers] == 1) {
echo "
<tr>
<td class='form1'>$edit_profile40</td>
<td class='form2' style='padding-left: 5px;'>
<table cellpadding='0' cellspacing='0'><tr>
<td><input type='radio' name='show_teammembers' value='1'"; if($user_info[show_teammembers] == "1") { echo " CHECKED"; } echo "></td><td>$edit_profile32&nbsp;&nbsp; </td>
<td><input type='radio' name='show_teammembers' value='0'"; if($user_info[show_teammembers] == "0") { echo " CHECKED"; } echo "></td><td>$edit_profile33</td>
<td>&nbsp;"; tip2("64", "65"); echo "</td>
</tr></table>
</td>
</tr>
";
}

if($group_info[allow_profileprivacy] == 1) {
echo "
<tr>
<td class='form1'>$edit_profile49</td>
<td class='form2' style='padding-left: 5px;'>
<table cellpadding='0' cellspacing='0'><tr>
<td><select name='profile_privacy'>
<option value='3'"; if($user_info[profile_privacy] == "3") { echo " SELECTED"; } echo ">$edit_profile50</option>
<option value='2'"; if($user_info[profile_privacy] == "2") { echo " SELECTED"; } echo ">$edit_profile51</option>
"; if($group_info[allow_friends] == "1") { echo "<option value='1'"; if($user_info[profile_privacy] == "1") { echo " SELECTED"; } echo ">$edit_profile52</option>"; } echo "
<option value='0'"; if($user_info[profile_privacy] == "0") { echo " SELECTED"; } echo ">$edit_profile53</option>
</select></td>
<td>&nbsp;"; tip2("7", "8"); echo "</td>
</tr></table>
</td>
</tr>
";
} else {
echo "<input type='hidden' name='profile_privacy' value='3'>";
}

echo "
</table>
<br>
<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='submit' class='button' value='$edit_profile41'></td>
<td>&nbsp;&nbsp; $edit_profile42</td>
<input type='hidden' name='task' value='save_do'>
</tr>
</table>
</form>
";

echo $foot;
}
?>