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


// SHOW IMAGE
if($task == "image") {
$code = $_GET['code'];
image_verification($code);
exit();
}


// SHOW TERMS
if($task == "terms") {
echo $head;
echo $admin_info[signup_termstext];
echo $foot;
exit();
}




// SET ERROR VARS
$is_error = Array();
$error = Array();


// GET POSTED VARIABLES
if($task != "step_one") {
  $bad_words = explode(",", trim($admin_info[banned_badwords]));
  $bad_words_replace = explode(",", trim($admin_info[banned_badwords_replace]));

  $g_id = $_POST['g_id'];
   if($g_id == 0 | mysql_num_rows(mysql_query("SELECT g_id FROM bhost_groups WHERE g_id='$g_id'")) == 0) { $group = mysql_fetch_assoc(mysql_query("SELECT g_id FROM bhost_groups WHERE default_group='1' LIMIT 1")); $g_id = $group[g_id]; }

  $group = mysql_fetch_assoc(mysql_query("SELECT num_weblogs FROM bhost_groups WHERE g_id='$g_id'"));
  if($group[num_weblogs] != "0") {
   $weblog = stripslashes($_POST['weblog']);
   $title = str_replace($bad_words, $bad_words_replace, htmlspecialchars(stripslashes($_POST['title']), ENT_QUOTES));
   $wc_id = $_POST['wc_id'];
   $description = str_replace($bad_words, $bad_words_replace, htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES));
  }
  $username = stripslashes($_POST['username']);
  $password = stripslashes($_POST['password']);
  $password1 = stripslashes($_POST['password1']);
  $password2 = stripslashes($_POST['password2']);
   if($task != "step_two") { $password1 = base64_decode($password); $password2 = $password1; }
  $email = stripslashes($_POST['email']);
  $codesent = $_POST['codesent'];
  $code = $_POST['code'];
  $agree = $_POST['agree'];

  $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));
  $website = htmlspecialchars(stripslashes($_POST['website']), ENT_QUOTES);
  $screenname = htmlspecialchars(stripslashes($_POST['screenname']), ENT_QUOTES);
  $screenname_type = $_POST['screenname_type'];
  $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_year = 0;
    $b_month = 0;
    $b_day = 0;
   } else {
    $b_year = $birthday_year;
    $b_month = $birthday_month;
    $b_day = $birthday_day;
   }
   $birthday = MakeTime("0", "0", "0", "$b_month", "$b_day", "$b_year");
  $city = htmlspecialchars(stripslashes($_POST['city']), ENT_QUOTES);
  $state = htmlspecialchars(stripslashes($_POST['state']), ENT_QUOTES);
  $country = htmlspecialchars(stripslashes($_POST['country']), ENT_QUOTES);
  $interests = str_replace($bad_words, $bad_words_replace, htmlspecialchars(stripslashes($_POST['interests']), ENT_QUOTES));
   $interests = str_replace(", ", ",", $interests);
   $interests = preg_replace("/[^a-z,A-Z,0-9,\-, ,_]/", "", $interests);
  $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 = $custom[Field];
    ${"$custom_field"} = htmlspecialchars(stripslashes($_POST[$custom_field]), ENT_QUOTES);
   }
  }

  $template = $_POST['template'];
}



// SET ERRORS
if($task == "step_two" | $task == "step_three" | $task == "step_four") {
  $group = mysql_fetch_assoc(mysql_query("SELECT num_weblogs FROM bhost_groups WHERE g_id='$g_id'"));
  if($group[num_weblogs] != "0") {
   if($weblog != "" & in_array($weblog, explode(",", $admin_info[banned_weblogs]))) { $is_error[1] = "yes"; $error[weblog] = "$signup29"; }
   if(($weblog != "" & is_dir($weblog)) | $weblog == "interests" | $weblog == "profiles" | $weblog == "albums") { $is_error[1] = "yes"; $error[weblog] = "$signup29"; }
   if(preg_match("/[^a-z,A-Z,0-9]/", $weblog)) { $is_error[1] = "yes"; $error[weblog] = "$signup27"; }
   if(str_replace(" ", "", $weblog) == "" & $admin_info[field_address] == "3") { $is_error[1] = "yes"; $error[weblog] = "$signup20"; }
   if(mysql_num_rows(mysql_query("SELECT w_id FROM bhost_weblogs WHERE weblog='$weblog'")) != 0) { $is_error[1] = "yes"; $error[weblog] = "$signup28"; }
   if(str_replace(" ", "", $title) == "" & $admin_info[field_title] == "3") { $is_error[1] = "yes"; $error[title] = "$signup21"; }
    if(str_replace(" ", "", $title) == "" & $admin_info[field_title] != "3") { $title = "$signup77"; }
   if(str_replace(" ", "", $wc_id) == "" & $admin_info[categories_on] == "2") { $is_error[1] = "yes"; $error[wc_id] = "$signup22"; }
   if(str_replace(" ", "", $description) == "" & $admin_info[field_description] == "3") { $is_error[1] = "yes"; $error[description] = "$signup23"; }
  }
  if(in_array($username, explode(",", $admin_info[banned_usernames]))) { $is_error[1] = "yes"; $error[username] = "$signup30"; }
  if(preg_match("/[^a-z,A-Z,0-9]/", $username)) { $is_error[1] = "yes"; $error[username] = "$signup15"; }
  if(str_replace(" ", "", $username) == "") { $is_error[1] = "yes"; $error[username] = "$signup24"; }
  if(mysql_num_rows(mysql_query("SELECT u_id FROM bhost_users WHERE username='$username'")) != 0) { $is_error[1] = "yes"; $error[username] = "$signup18"; }
  if(preg_match("/[^a-z,A-Z,0-9]/", $password1)) { $is_error[1] = "yes"; $error[password1] = "$signup14"; }
  if(strlen($password1) < 4) { $is_error[1] = "yes"; $error[password1] = "$signup19"; }
  if(str_replace(" ", "", $password1) == "") { $is_error[1] = "yes"; $error[password1] = "$signup25"; }
  if($password1 != $password2 | str_replace(" ", "", $password2) == "") { $is_error[1] = "yes"; $error[password2] = "$signup16"; }

  $email_begin = strrev(strstr(strrev($email), "@"));
  if(in_array($email, explode(",", str_replace("*@", "$email_begin", $admin_info[banned_emails])))) { $is_error[1] = "yes"; $error[email] = "$signup31"; }

  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[1] = "yes"; $error[email] = "$signup17"; }
  if($admin_info[signup_emailcheck] == 1 & checkdns_record($email) == FALSE) { $is_error[1] = "yes"; $error[email] = "$signup17"; }
  if($admin_info[signup_emaildupeok] == 0 & mysql_num_rows(mysql_query("SELECT * FROM bhost_users WHERE email='$email'")) != 0) { $is_error[1] = "yes"; $error[email] = "$signup26"; }
  if($admin_info[signup_emaildomain] != "" & str_replace("@", "", strstr($email, '@')) != $admin_info[signup_emaildomain]) { $is_error[1] = "yes"; $error[email] = "$signup33"; }
  if($admin_info[signup_image] == 1 AND function_exists('gd_info')) {
   $code1 = strrev($code);
   $code1 = preg_replace("([a-zA-Z])", "-", $code1); 
   $number = explode("-", $code1);
   $nums = $number[0] / $number[6];
   $nums .= $number[1] / $number[7];
   $nums .= $number[2] / $number[8];
   $nums .= $number[3] / $number[9];
   $nums.= $number[4] / $number[10];
   $nums .= $number[5] / $number[11];
   if($codesent != $nums) {
   $is_error[1] = "yes"; 
   $error[code] = "$signup34";
   }
  }
  if($admin_info[signup_terms] == 1 & $agree != "yes") { $is_error[1] = "yes"; $error[agree] = "$signup35"; }
  if($admin_info['banned_ips'] != "") {
   $myip = $_SERVER['REMOTE_ADDR'];
   $banned_ip = explode(",", $admin_info['banned_ips']);
   $total = count($banned_ip);
   $count = 0;
   while($count < $total) {
   $set = explode(".", $banned_ip[$count]);
   $myset = explode(".", $myip);
   $c = 0;
   $match = "";
   while($c < 4) {
   if($set[$c] == "*") { $match[$c] = 1; } else { if($set[$c] == $myset[$c]) { $match[$c] = 1; }}
   $c++;
   }
   if($match[0] == 1 AND $match[1] == 1 AND $match[2] == 1 AND $match[3] == 1) {
   $is_error[1] = "yes";
   $error[general] = "$signup32";
   }
   $count++;
   }
  }
  if($task == "step_two") {
   $custom_signup = "0";
   $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") {
    if(substr($custom[Field], -3, 2) == "_3" | substr($custom[Field], -3, 2) == "_2") { $custom_signup = "1"; }
   }}
   if(($admin_info[field_fname] == "0" | $admin_info[field_fname] == "1") & ($admin_info[field_lname] == "0" | $admin_info[field_lname] == "1") & ($admin_info[field_display_name] == "0" | $admin_info[field_display_name] == "1") & ($admin_info[field_website] == "0" | $admin_info[field_website] == "1") & ($admin_info[field_screenname] == "0" | $admin_info[field_screenname] == "1") & ($admin_info[field_gender] == "0" | $admin_info[field_gender] == "1") & ($admin_info[field_birthday] == "0" | $admin_info[field_birthday] == "1") & ($admin_info[field_city] == "0" | $admin_info[field_city] == "1") & ($admin_info[field_state] == "0" | $admin_info[field_state] == "1") & ($admin_info[field_country] == "0" | $admin_info[field_country] == "1") & ($admin_info[field_interests] == "0" | $admin_info[field_interests] == "1") & $custom_signup == "0") { 
    $task = "step_three"; 
   }
  }
  if($is_error[1] == "yes") { $task = "step_one"; }
}


if($task == "step_three" | $task == "step_four") {
  if(str_replace(" ", "", $fname) == "" & $admin_info[field_fname] == "3") { $is_error[2] = "yes"; $error[fname] = "$signup36"; }
  if(str_replace(" ", "", $lname) == "" & $admin_info[field_lname] == "3") { $is_error[2] = "yes"; $error[lname] = "$signup37"; }
  if(str_replace(" ", "", $display_name) == "" & $admin_info[field_display_name] == "3") { $is_error[2] = "yes"; $error[display_name] = "$signup38"; }
  if($admin_info[field_website] == "3" & str_replace(" ", "", $website) == "") { $is_error[2] = "yes"; $error[website] = "$signup39"; }
  if($admin_info[field_screenname] == "3" & str_replace(" ", "", $screenname) == "") { $is_error[2] = "yes"; $error[screenname] = "$signup40"; }
  if($admin_info[field_gender] == "3" & str_replace(" ", "", $gender) == "") { $is_error[2] = "yes"; $error[gender] = "$signup41"; }
  if($admin_info[field_birthday] == "3" & $birthday == "-2019787262") { $is_error[2] = "yes"; $error[birthday] = "$signup76"; }
  if($admin_info[field_city] == "3" & str_replace(" ", "", $city) == "") { $is_error[2] = "yes"; $error[city] = "$signup42"; }
  if($admin_info[field_state] == "3" & str_replace(" ", "", $state) == "") { $is_error[2] = "yes"; $error[state] = "$signup43"; }
  if($admin_info[field_country] == "3" & str_replace(" ", "", $country) == "") { $is_error[2] = "yes"; $error[country] = "$signup44"; }
  if($admin_info[field_interests] == "3" & str_replace(" ", "", $interests) == "") { $is_error[2] = "yes"; $error[interests] = "$signup45"; }
  $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_required = substr($custom[Field], -3, 2);
    $custom_field = $custom[Field];
    $custom_field_value = ${"$custom_field"};
    if($custom_required == "_3" & str_replace(" ", "", $custom_field_value) == "") { $is_error[2] = "yes"; $error[$custom_field] = "$signup46"; }
   }
  }

  $template_info = mysql_query("SELECT * FROM bhost_templates WHERE t_id='$template'");
  if($admin_info[signup_choosetemplate] == 1) {
   if($task != "step_four" | mysql_num_rows($template_info) == "0") {
    $group = mysql_query("SELECT * FROM bhost_groups WHERE g_id='$g_id' LIMIT 1");
    if(mysql_num_rows($group) == 0) { $group = mysql_query("SELECT * FROM bhost_groups WHERE default_group='1' LIMIT 1"); }
    $default_group = mysql_fetch_assoc($group);
    $template_array = explode(",", $default_group[templates]);
    $count = 0;
    $templates = mysql_query("SELECT t_id FROM bhost_templates");
    while($template = mysql_fetch_assoc($templates)) { if(in_array($template[t_id], $template_array)) { $count = $count + 1; }}
    if($count == "0") {
      $template_info = mysql_fetch_assoc(mysql_query("SELECT t_id FROM bhost_templates LIMIT 1"));
      $task = "step_four"; 
      $template = $template_info[t_id];
    }
    if($default_group[num_weblogs] == "0" | $weblog == "") {
     $template_info = mysql_fetch_assoc(mysql_query("SELECT t_id FROM bhost_templates LIMIT 1"));
     $task = "step_four"; 
     $template = $template_info[t_id];
    }
   }
  } else {
    $task = "step_four";
    $template = $admin_info[signup_templatedefault];
  }

  if($is_error[2] == "yes") { $task = "step_two"; }
}













// STEP FOUR
if($task == "step_four") {
  $duplicates = mysql_num_rows(mysql_query("SELECT * FROM bhost_users WHERE username='$username'"));
  if($duplicates != 0) { header("Location: login.php"); exit(); }
  $duplicates2 = mysql_num_rows(mysql_query("SELECT * FROM bhost_weblogs WHERE weblog='$weblog'"));
  if($duplicates2 != 0) { header("Location: login.php"); exit(); }

  $template_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_templates WHERE t_id='$template'"));
  $template_html = str_replace("'", "\\'", $template_info[html]);

  $signup_date = time();
  $signup_ip = $_SERVER['REMOTE_ADDR'];

  if($admin_info[signup_emailverify] == 1) { $verified = "0"; } else { $verified = "1"; }

  $code = randomcode();
  $password = base64_decode($password);
  $crypt_password = crypt($password, $code);


  // ADD NEW USER
  mysql_query("INSERT INTO bhost_users (
  g_id,
  username, 
  password, 
  enabled,
  code,
  email, 
  fname, 
  lname, 
  signup_date,
  signup_ip,
  verified, 
  last_login,
  last_payment,
  notes,
  language,
  num_entries,
  display_name, 
  website, 
  screenname, 
  screenname_type, 
  gender, 
  birthday, 
  city, 
  state, 
  country,
  interests,
  avatar,
  show_name, 
  show_email, 
  show_friendlist, 
  show_userstats,
  show_teammembers,
  profile_privacy
  ) VALUES (
  '$g_id',
  '$username', 
  '$crypt_password',
  '1', 
  '$code',
  '$email', 
  '$fname', 
  '$lname', 
  '$signup_date', 
  '$signup_ip',
  '$verified',
  '0',
  '0',
  '',
  '',
  '0',
  '$display_name', 
  '$website', 
  '$screenname', 
  '$screenname_type', 
  '$gender', 
  '$birthday', 
  '$city', 
  '$state', 
  '$country', 
  '$interests',
  '',
  '1', 
  '0', 
  '1', 
  '1',
  '0',
  '3'
  )");

  $user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_users WHERE username='$username' AND password='$crypt_password' ORDER BY u_id DESC LIMIT 1"));
  mysql_query("INSERT INTO bhost_profile (u_id) VALUES ('$user_info[u_id]')");

  $moblog_secret = strtolower(randomcode("16"));

 $group = mysql_fetch_assoc(mysql_query("SELECT num_weblogs FROM bhost_groups WHERE g_id='$g_id'"));
 if($group[num_weblogs] != "0" & $weblog != "") {

  // ADD NEW WEBLOG
  mysql_query("INSERT INTO bhost_weblogs (
  u_id,
  wc_id,
  enabled,
  owner,
  level1,
  level2,
  invited,
  date_created,
  num_entries,
  weblog,
  title,
  description,
  template,
  show_comments,
  who_comments,
  default_comments,
  notify_comments,
  logip_comments,
  manage_comments,
  default_advanced,
  default_privacy,
  default_trackbacks,
  detect_trackbacks,
  tb_blacklist,
  entries_per_page,
  recent_entries,
  timezone,
  format_date,
  format_time,
  showtitle,
  entry_default,
  mailing_list,
  banned_ips,
  rss_on,
  rss_entries,
  rss_html,
  links_url,
  links_title,
  moblog_secret,
  moblog_on,
  moblog_emails,
  friends
  ) VALUES (
  '$user_info[u_id]',
  '$wc_id',
  '1',
  '$user_info[username]',
  '',
  '',
  '',
  '$signup_date',
  '0',
  '$weblog',
  '$title', 
  '$description', 
  '$template_html', 
  '3', 
  '3', 
  '1', 
  '0', 
  '0', 
  '3', 
  '0',
  '3', 
  '0',
  '0',
  '',
  '20', 
  '5', 
  '$admin_info[signup_timezone]', 
  '$admin_info[signup_format_date]', 
  '$admin_info[signup_format_time]', 
  '1', 
  '', 
  '',
  '',
  '0',
  '10',
  '0',
  '',
  '',
  '$moblog_secret',
  '0',
  '',
  '0'
  )") or die(mysql_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_required = substr($custom[Field], -3, 2);
    $custom_field = $custom[Field];
    $custom_field_value = ${"$custom_field"};
    if($custom_required == "_3" | $custom_required == "_2") { 
     mysql_query("UPDATE bhost_profile SET $custom_field='$custom_field_value' WHERE u_id='$user_info[u_id]'");
    }
   }
  }

  // CREATE USER FOLDER
  $letter = strtolower(substr($username, 0, 1));
  @mkdir("./uploads/$letter/$username", 0700);
  @chmod("./uploads/$letter/$username", 0777);  
  $filename = "./uploads/$letter/$username/index.php";
  $somecontent = "";
  $handle = fopen($filename, 'w+');
  fwrite($handle, $somecontent);
  fclose($handle);


  if($admin_info[allow_password] == 0) {
   $subject = $admin_info[user_password_subject];
   $subject = str_replace("<username>", "$username", $subject);
   $subject = str_replace("<password>", "$password", $subject);
   $subject = str_replace("<fname>", $fname, $subject);
   $subject = str_replace("<lname>", $lname, $subject);
   $message = $admin_info[user_password_email];
   $message = str_replace("<username>", "$username", $message);
   $message = str_replace("<password>", "$password", $message);
   $message = str_replace("<fname>", $fname, $message);
   $message = str_replace("<lname>", $lname, $message);
   mail("$email", "$subject", "$message", "From: $admin_info[email]");
  }

  // SEND NOTIFICATION EMAIL TO ADMIN IF TURNED ON
  if($admin_info[signup_notify] == 1) {
   $notify_subject = "$signup1 $username";
   $notify_message = "$signup2\n\n$signup3 $username\n$signup5 $fname\n$signup6 $lname";
   $notify_headers = "From: BlogHoster System <$admin_info[email]>";
   mail($admin_info[email], $notify_subject, $notify_message, $notify_headers);
  }

  // SEND WELCOME EMAIL TO USER IF TURNED ON
  if($admin_info[signup_sendemail] == 1) {
   $welcome_subject = $admin_info[welcome_subject];
   $welcome_subject = str_replace("<fname>", $fname, $welcome_subject);
   $welcome_subject = str_replace("<lname>", $lname, $welcome_subject);
   $welcome_subject = str_replace("<link>", url("index", "$weblog"), $welcome_subject);
   $welcome_subject = str_replace("<username>", $username, $welcome_subject);
   $welcome_subject = str_replace("<password>", $password, $welcome_subject);
   $welcome_message = $admin_info[welcome_message];
   $welcome_message = str_replace("<fname>", $fname, $welcome_message);
   $welcome_message = str_replace("<lname>", $lname, $welcome_message);
   $welcome_message = str_replace("<link>", url("index", "$weblog"), $welcome_message);
   $welcome_message = str_replace("<username>", $username, $welcome_message);
   $welcome_message = str_replace("<password>", $password, $welcome_message);
   $welcome_headers = "From: $admin_info[fname] $admin_info[lname] <$admin_info[email]>";
   mail($email, $welcome_subject, $welcome_message, $welcome_headers);
  }

  // SEND VERIFICATION EMAIL TO USER IF TURNED ON
  if($admin_info[signup_emailverify] == 1) {
   $server_array = explode("/", $_SERVER['PHP_SELF']);
   $server_array_mod = array_pop($server_array);
   $server_info = implode("/", $server_array);
   $server = "http://".$_SERVER['HTTP_HOST'].$server_info;
   $verify_subject = $admin_info[verify_subject];
   $verify_subject = str_replace("<fname>", $fname, $verify_subject);
   $verify_subject = str_replace("<lname>", $lname, $verify_subject);
   $verify_subject = str_replace("<link>", "$server/verify.php?u=$user_info[u_id]", $verify_subject);
   $verify_message = $admin_info[verify_message];
   $verify_message = str_replace("<fname>", $fname, $verify_message);
   $verify_message = str_replace("<lname>", $lname, $verify_message);
   $verify_message = str_replace("<link>", "$server/verify.php?u=$user_info[u_id]&c=$user_info[code]", $verify_message);
   $verify_headers = "From: $admin_info[fname] $admin_info[lname] <$admin_info[email]>";
   mail($email, $verify_subject, $verify_message, $verify_headers);
  }

  if($admin_info[allow_password] == 1 & $admin_info[signup_emailverify] != "1") {
   $username_cookie = crypt($user_info[username], $user_info[code]);
   $date = time();
   $ipaddress = $_SERVER['REMOTE_ADDR'];
   mysql_query("UPDATE bhost_users SET last_login='$date' WHERE u_id='$user_info[u_id]'");
   mysql_query("INSERT INTO bhost_log (date, username, password, ipaddress, result) VALUES ('$date', '$user_info[username]', '$password', '$ipaddress', '1')");
   bumplog();
   setcookie("username", "$username_cookie", time()+60*999999, "/");
   setcookie("password", "$user_info[password]", time()+60*999999, "/");
   setcookie("u_id", "$user_info[u_id]", time()+60*999999, "/");
   $action = "manager/index.php";
  } else {
   $action = "login.php";
  }

   echo $head;
   echo "
   <h2>$signup7</h2>
   $signup8<br>";
   if($admin_info[allow_password] != 1) { echo "$signup9<br>"; }
   if($admin_info[signup_emailverify] == 1) { echo "$signup10<br>"; }
   echo "
   <br>
   <form action='$action' method='POST'>
   <input type='submit' class='button' value='$signup4'>
   </form>
   ";
   echo $foot;
   exit();
   exit();
}









// STEP THREE
if($task == "step_three") {
  echo $head;
  echo "
  <h2>$signup12</h2>
  $signup13
  <br>

  <table cellpadding='0' cellpsacing='0'>
  <form action='signup.php' method='POST'>
  <tr><td>
  ";

  $group = mysql_query("SELECT * FROM bhost_groups WHERE g_id='$g_id' LIMIT 1");
  if(mysql_num_rows($group) == 0) { $group = mysql_query("SELECT * FROM bhost_groups WHERE default_group='1' LIMIT 1"); }
  $default_group = mysql_fetch_assoc($group);
  $template_array = explode(",", $default_group[templates]);

  $tempcount = 0;
  $templates = mysql_query("SELECT * FROM bhost_templates");
  while($template = mysql_fetch_assoc($templates)) {
   if(in_array($template[t_id], $template_array)) {
    $tempcount++;
    if($template[image] != "" AND $template[image] != "http://") { 
     $imageurl = $template[image];
     if(strstr($imageurl, "..") != false) { 
      $imagepath = realpath($imageurl);
      if(!file_exists($imagepath)) { $imageurl = str_replace("..", ".", $imageurl); }
      if(!file_exists(realpath($imageurl))) { $imageurl = "./images/noimage.gif"; }
     } 
     $image = "<img src='$imageurl' border='0' class='template'>"; 
    } else {
     $image = "<img src='./images/noimage.gif' border='0' class='template'>"; 
    }
    $image = "<a href='example.php?t_id=$template[t_id]' target='_blank'>$image</a>"; 
    
    echo "
    <div class='float'>
    <div class='templatebox' valign='top' align='center'>$image<br>
    <table cellpadding='0' cellspacing='0' align='left'>
    <tr><td class='templatename'><input type='radio' name='template' value='$template[t_id]'"; if($tempcount == 1) { echo " CHECKED"; } echo " id='temp$template[t_id]'></td><td class='templatename'><b><label for='temp$template[t_id]'>$template[name]</label></b></td></tr>
    </table>
    </div>
    </div>
    ";
   }
  }

  echo "
  </td>
  </tr>
  </table>
  <br>
  <input type='submit' class='button' value='$signup4'>
  <input type='hidden' name='task' value='step_four'>
  <input type='hidden' name='g_id' value='$g_id'>
  <input type='hidden' name='weblog' value='$weblog'>
  <input type='hidden' name='title' value='$title'>
  <input type='hidden' name='wc_id' value='$wc_id'>
  <input type='hidden' name='description' value='$description'>
  <input type='hidden' name='username' value='$username'>
  <input type='hidden' name='password' value='$password'>
  <input type='hidden' name='email' value='$email'>
  <input type='hidden' name='code' value='$code'>
  <input type='hidden' name='codesent' value='$codesent'>
  <input type='hidden' name='agree' value='$agree'>
  <input type='hidden' name='fname' value='$fname'>
  <input type='hidden' name='lname' value='$lname'>
  <input type='hidden' name='display_name' value='$display_name'>
  <input type='hidden' name='website' value='$website'>
  <input type='hidden' name='screenname' value='$screenname'>
  <input type='hidden' name='screenname_type' value='$screenname_type'>
  <input type='hidden' name='gender' value='$gender'>
  <input type='hidden' name='birthday_month' value='$birthday_month'>
  <input type='hidden' name='birthday_day' value='$birthday_day'>
  <input type='hidden' name='birthday_year' value='$birthday_year'>
  <input type='hidden' name='city' value='$city'>
  <input type='hidden' name='state' value='$state'>
  <input type='hidden' name='country' value='$country'>
  <input type='hidden' name='interests' value='$interests'>
  ";
  $customfieldlist = "";
  $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 = $custom[Field];
    $customfieldlist .= "<input type='hidden' name='$custom_field' value='".${"$custom_field"}."'>";
   }
  }
  echo "
  $customfieldlist
  </form>
  ";

  echo $foot;
  exit();
}










// STEP TWO
if($task == "step_two") {
  $password = base64_encode($password1);
  if($is_error[2] != "yes") {
   $fname = "";
   $lname = "";
   $display_name = "";
   $website = "";
   $screenname = "";
   $screenname_type = "";
   $birthday_month = "";
   $birthday_day = "";
   $birthday_year = "";
   $birthday = "";
   $city = "";
   $state = "";
   $country = "";
   $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 = $custom[Field];
     ${"$custom_field"} = "";
    }
   }
  }

  echo $head;
  echo "
  <h2>$signup47</h2>
  $signup48
  <br><br>

  <table cellpadding='3' cellspacing='0' class='form'>
  <form action='signup.php' method='POST'>
  ";

  if($admin_info[field_fname] == "3" | $admin_info[field_fname] == "2") {
  echo "
  <tr>
  <td class='form1"; if($error[fname] != "") { echo "error"; } echo "'>$signup49"; if($admin_info[field_fname] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='fname' maxlength='100' size='20' value='$fname' tabindex='1'><br>"; show_error($error[fname]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='fname' value=''>";
  }

  if($admin_info[field_lname] == "3" | $admin_info[field_lname] == "2") {
  echo "
  <tr>
  <td class='form1"; if($error[lname] != "") { echo "error"; } echo "'>$signup50"; if($admin_info[field_lname] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='lname' maxlength='100' size='20' value='$lname' tabindex='2'><br>"; show_error($error[lname]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='lname' value=''>";
  }

  if($admin_info[field_display_name] == "3" | $admin_info[field_display_name] == "2") {
  echo "
  <tr>
  <td class='form1"; if($error[display_name] != "") { echo "error"; } echo "'>$signup51"; if($admin_info[field_display_name] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='display_name' maxlength='100' size='20' value='$display_name' tabindex='3'><br>"; show_error($error[display_name]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='display_name' value=''>";
  }

  if($admin_info[field_website] == "3" | $admin_info[field_website] == "2") {
  echo "
  <tr>
  <td class='form1"; if($error[website] != "") { echo "error"; } echo "'>$signup52"; if($admin_info[field_website] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='website' maxlength='100' size='40' value='$website' tabindex='4'><br>"; show_error($error[website]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='website' value=''>";
  }

  if($admin_info[field_screenname] == 3 | $admin_info[field_screenname] == 2) {
  echo "
  <tr>
  <td class='form1"; if($error[screenname] != "") { echo "error"; } echo "'>$signup53"; if($admin_info[field_screenname] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='screenname' value='$screenname' maxlength='100' size='18' tabindex='5'>
  <select name='screenname_type' tabindex='6'>
  <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><br>"; show_error($error[screenname]); echo "
  </td>
  </tr>
  ";
  } else {
  echo "
  <input type='hidden' name='screenname' value=''>
  <input type='hidden' name='screenname_type' value=''>
  ";
  }

  if($admin_info[field_gender] == 3 | $admin_info[field_gender] == 2) {
  echo "
  <tr>
  <td class='form1"; if($error[gender] != "") { echo "error"; } echo "'>$signup54"; if($admin_info[field_gender] == "3") { echo "*"; } echo "</td>
  <td class='form2'><select name='gender' tabindex='7'><option></option><option value='$signup55'"; if($gender == "$signup55") { echo " SELECTED"; } echo ">$signup55</option><option value='$signup56'"; if($gender == "$signup56") { echo " SELECTED"; } echo ">$signup56</option></select>"; show_error($error[gender]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='gender' value=''>";
  }


  if($admin_info[field_birthday] == 3 | $admin_info[field_birthday] == 2) {
   if($birthday != "") {
    $thism = $birthday_month;
    $thisd = $birthday_day;
    $thisy = $birthday_year;
   } else {
    $thism = 0;
    $thisd = 0;
    $thisy = 0;
   }

   // DETERMINE ORDER OF TABS
   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" OR $admin_info[signup_format_date] == "l, F j" OR $admin_info[signup_format_date] == "l, F j" OR $admin_info[signup_format_date] == "l") {
    $mbox_tabindex = "8";
    $dbox_tabindex = "9";
    $ybox_tabindex = "10";
   } 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" OR $admin_info[signup_format_date] == "Y-M-j") {
    $ybox_tabindex = "8";
    $mbox_tabindex = "9";
    $dbox_tabindex = "10";
   } 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] == "D-j-M-Y" OR $admin_info[signup_format_date] == "D j M Y" OR $admin_info[signup_format_date] == "D j F Y" OR $admin_info[signup_format_date] == "l j F Y" OR $admin_info[signup_format_date] == "j-M-Y") {
    $dbox_tabindex = "8";
    $mbox_tabindex = "9";
    $ybox_tabindex = "10";
   }

   // 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" OR $admin_info[signup_format_date] == "Y-M-j" OR $admin_info[signup_format_date] == "D-j-M-Y" OR $admin_info[signup_format_date] == "D j M Y" OR $weblog_info[date_format] == "j-M-Y") {
    $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, F j" OR $admin_info[signup_format_date] == "j F Y" OR $admin_info[signup_format_date] == "l j F Y") {
    $mf = "F";
   }
   $mbox = "
   <select name='birthday_month' tabindex='$mbox_tabindex'>
   <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' tabindex='$dbox_tabindex'><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' tabindex='$ybox_tabindex'><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" OR $admin_info[signup_format_date] == "l, F j") {
    $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" OR $admin_info[signup_format_date] == "Y-M-j") {
    $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] == "D-j-M-Y" OR $admin_info[signup_format_date] == "D j M Y" OR $admin_info[signup_format_date] == "D j F Y" OR $admin_info[signup_format_date] == "l j F Y" OR $admin_info[signup_format_date] == "j-M-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"; if($error[birthday] != "") { echo "error"; } echo "'>$signup57"; 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] == 3 | $admin_info[field_city] == 2) {
  echo "
  <tr>
  <td class='form1"; if($error[city] != "") { echo "error"; } echo "'>$signup58"; if($admin_info[field_city] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='city' value='$city' maxlength='250' size='30' tabindex='11'>"; show_error($error[city]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='city' value=''>";
  }

  if($admin_info[field_state] == 3 | $admin_info[field_state] == 2) {
  echo "
  <tr>
  <td class='form1"; if($error[state] != "") { echo "error"; } echo "'>$signup59"; if($admin_info[field_state] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='state' value='$state' maxlength='250' size='30' tabindex='12'>"; show_error($error[state]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='state' value=''>";
  }

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

  if($admin_info[field_interests] == 3 | $admin_info[field_interests] == 2) {
  echo "
  <tr>
  <td class='form1"; if($error[interests] != "") { echo "error"; } echo "'>$signup61"; if($admin_info[field_interests] == "3") { echo "*"; } echo "</td>
  <td class='form2'><textarea name='interests' rows='4' cols='60' tabindex='14'>$interests</textarea>"; show_error($error[interests]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='interests' value=''>";
  }

  $custom_fields = mysql_query("SHOW COLUMNS FROM bhost_profile FROM `$mysql_database`");
  $tabindex = 15;
  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];
    $custom_field_value = ${"$custom_field"};
    $required = "";
    if($custom_required == "_3") { $required = "*"; }
    if($custom_required == "_3" | $custom_required == "_2") {
     $tips = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_profile WHERE u_id='0'"));
     if($custom_type == "text") {
      echo "
      <tr>
      <td class='form1"; if($error[$custom_field] != "") { echo "error"; } echo "'>$custom_name$required</td>
      <td class='form2'><textarea name='$custom_field' rows='4' cols='60' tabindex='$tabindex'>$custom_field_value</textarea>"; tip($tips[$custom_field]); echo "<br>"; show_error($error[$custom_field]); echo "</td>
      </tr>
      ";
     } else {
      echo "
      <tr>
      <td class='form1"; if($error[$custom_field] != "") { echo "error"; } echo "'>$custom_name$required</td>
      <td class='form2'><input type='text' class='text' name='$custom_field' maxlength='250' size='30' value='$custom_field_value' tabindex='$tabindex'>"; tip($tips[$custom_field]); echo "<br>"; show_error($error[$custom_field]); echo "</td>
      </tr>
      ";
     }
     $tabindex++;
    } else {
     echo "<input type='hidden' name='$custom_field' value=''>";
    }
   }
  }

  echo "
  </table>
  <br>
  <input type='submit' value='$signup4' class='button'>
  <input type='hidden' name='task' value='step_three'>
  <input type='hidden' name='g_id' value='$g_id'>
  <input type='hidden' name='weblog' value='$weblog'>
  <input type='hidden' name='title' value='$title'>
  <input type='hidden' name='wc_id' value='$wc_id'>
  <input type='hidden' name='description' value='$description'>
  <input type='hidden' name='username' value='$username'>
  <input type='hidden' name='password' value='$password'>
  <input type='hidden' name='email' value='$email'>
  <input type='hidden' name='code' value='$code'>
  <input type='hidden' name='codesent' value='$codesent'>
  <input type='hidden' name='agree' value='$agree'>
  </form>
  ";
  echo $foot;
  exit();
}











// STEP ONE
if($task == "step_one") {
  if($is_error[1] != "yes") {
  $g_id = "";
  $weblog = "";
  $title = "";
  $wc_id = "";
  $description = "";
  $username = "";
  $password1 = "";
  $password2 = "";
  $email = "";
  }


  $path = url("index", "<!>PATH<!>");
  $path = str_replace("<!>PATH<!>", "&nbsp;<input type='text' class='text' name='weblog' maxlength='20' size='15' value='$weblog' tabindex='2'>&nbsp;", $path);
  if(substr($path, -1) == "/") { $path = substr($path, 0, -1); }

  echo $head;
  echo "
  <h2>$signup62</h2>
  $signup63
  <br><br>
  ";
 
  if($error[general] != "") {
  show_error($error[general]);
  echo "<br><br>";
  }

  echo "
  <table cellpadding='3' cellspacing='0' class='form'>
  <form action='signup.php' method='POST' name='signupstepone'>
  ";

  $groups = mysql_query("SELECT * FROM bhost_groups WHERE show_group='1' ORDER BY g_id");
  if(mysql_num_rows($groups) != 0) {
  echo "
  <tr>
  <td class='form1'>$signup64*</td>
  <td class='form2'>
  <select name='g_id' tabindex='1'>
  ";
  while($group_info = mysql_fetch_assoc($groups)) {
  echo "<option value='$group_info[g_id]'"; if($g_id == "$group_info[g_id]") { echo " SELECTED"; } echo ">$group_info[group_name]</option>";
  }
  echo "
  </select>
  </td>
  </tr>
  ";
  $num_weblogs = 1;
  } else {
  $default = mysql_fetch_assoc(mysql_query("SELECT g_id, num_weblogs FROM bhost_groups WHERE default_group='1' LIMIT 1"));
  $num_weblogs = $default[num_weblogs];
  echo "<input type='hidden' name='g_id' value='$default[g_id]'>";
  }

  if($num_weblogs != "0") {

  if($admin_info[field_address] != "1") {
  echo "
  <tr>
  <td class='form1"; if($error[weblog] != "") { echo "error"; } echo "'>$signup65"; if($admin_info[field_address] == "3") { echo "*"; } echo "</td>
  <td class='form2'><font class='code'>$path</font>"; tip2("68", "69"); echo "<div class='help'>$signup75</div>"; show_error($error[weblog]); echo "</td>
  </tr>
  ";
  }
 
  if($admin_info[field_title] == "3" | $admin_info[field_title] == "2") {
  echo "
  <tr>
  <td class='form1"; if($error[title] != "") { echo "error"; } echo "'>$signup66"; if($admin_info[field_title] == "3") { echo "*"; } echo "</td>
  <td class='form2'><input type='text' class='text' name='title' maxlength='100' size='40' value='$title' tabindex='3'>"; tip2("5", "6"); echo "<br>"; show_error($error[title]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='title' value=''>";
  }

  $categories = mysql_query("SELECT * FROM bhost_categories ORDER BY name");
  if($admin_info[categories_on] != 0 & mysql_num_rows($categories) != 0) {
  echo "
  <tr>
  <td class='form1"; if($error[wc_id] != "") { echo "error"; } echo "'>$signup67"; if($admin_info[categories_on] == "2") { echo "*"; } echo "</td>
  <td class='form2'><select name='wc_id' tabindex='4'><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><br>"; show_error($error[wc_id]); echo "</td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='wc_id' value='0'>";
  }

  if($admin_info[field_description] == "3" | $admin_info[field_description] == "2") {
  echo "
  <tr>
  <td class='form1"; if($error[description] != "") { echo "error"; } echo "' valign='top'>$signup68"; if($admin_info[field_description] == "3") { echo "*"; } echo "</td>
  <td class='form2'><textarea name='description' rows='4' cols='55' tabindex='5'>$description</textarea><br>"; show_error($error[description]); echo "</td>
  </tr>
  ";

  } else {
  echo "<input type='hidden' name='description' value=''>";
  }



  }


  echo "
  <tr>
  <td class='form1"; if($error[username] != "") { echo "error"; } echo "'>$signup69*</td>
  <td class='form2'><input type='text' class='text' name='username' maxlength='20' size='20' value='$username' tabindex='6'>"; tip2("11", "12"); echo "<br>"; show_error($error[username]); echo "</td>
  </tr>
  ";

  if($admin_info[allow_password] == 1) {
  echo "
  <tr>
  <td class='form1"; if($error[password1] != "") { echo "error"; } echo "'>$signup70*</td>
  <td class='form2'><input type='password' class='text' name='password1' maxlength='20' size='20' tabindex='7'>"; tip2("13", "14"); echo "<br>"; show_error($error[password1]); echo "</td>
  </tr>

  <tr>
  <td class='form1"; if($error[password2] != "") { echo "error"; } echo "'>$signup71*</td>
  <td class='form2'><input type='password' class='text' name='password2' maxlength='20' size='20' tabindex='8'>"; tip2("15", "16"); echo "<br>"; show_error($error[password2]); echo "</td>
  </tr>
  ";
  } else {
  $password = randomcode();
  echo "
  <input type='hidden' name='password1' value='$password'>
  <input type='hidden' name='password2' value='$password'>
  ";
  }

  echo "
  <tr>
  <td class='form1"; if($error[email] != "") { echo "error"; } echo "'>$signup72*</td>
  <td class='form2'><input type='text' class='text' name='email' maxlength='100' size='20' value='$email' tabindex='9'><br>"; show_error($error[email]); echo "</td>
  </tr>
  ";

  // SHOW IMAGE CODE VERIFICATION ROW IF ENABLED AND GD IS INSTALLED
  if($admin_info[signup_image] AND function_exists('gd_info')) {
  for($c = 1; $c < 7; $c++) { $mul[$c] = rand(20,50); }
  for($c = 1; $c < 7; $c++) { $num[$c] = rand(2,9) * $mul[$c]; }
  for($c = 1; $c < 13; $c++) { $let[$c] = randLetter(); }
  $code = strrev("$num[1]$let[1]$num[2]$let[2]$num[3]$let[3]$num[4]$let[4]$num[5]$let[5]$num[6]$let[6]$mul[1]$let[7]$mul[2]$let[8]$mul[3]$let[9]$mul[4]$let[10]$mul[5]$let[11]$mul[6]");
  echo "
  <tr>
  <td class='form1"; if($error[code] != "") { echo "error"; } echo "'>$signup73*</td>
  <td class='form2'>
    <table cellpadding='0' cellspacing='0'>
    <tr>
    <td><input type='text' name='codesent' class='text' size='6' maxlength='10' tabindex='10'></td>
    <td style='padding-left: 10px;'><img src='signup.php?task=image&code=$code' border='0' height='20' width='67' style='border: 1px solid #AAAAAA;'></td>
    <td style='padding-left: 1px;'>"; tip2("17", "18"); echo "&nbsp;</td>
    </tr>
    <input type='hidden' name='code' value='$code'>
    </table>
    "; show_error($error[code]); echo "
  </td>
  </tr>
  ";
  } else {
  echo "
  <input type='hidden' name='code' value=''>
  <input type='hidden' name='codesent' value=''>
  ";
  }

  // SHOW TERMS AND CONDITIONS ROW IF ENABLED
  if($admin_info[signup_terms] == 1) {
  echo "
  <tr>
  <td class='form1"; if($error[agree] != "") { echo "error"; } echo "'>&nbsp;</td>
  <td class='form2'>
    <table cellpadding='0' cellspacing='0'>
    <tr>
    <td><input type='checkbox' name='agree' value='yes' id='agree' tabindex='11'></td>
    <td><label for='agree'>$signup74</label></td>
    </tr>
    </table>
    "; show_error($error[agree]); echo "
  </td>
  </tr>
  ";
  } else {
  echo "<input type='hidden' name='agree' value=''>";
  }

  echo "
  </table>
  <br>
  <input type='submit' value='$signup4' class='button' tabindex='12'>
  <input type='hidden' name='task' value='step_two'>
  </form>
  ";
  echo $foot;
  exit();
}




?>