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




// IF MAX NUMBER OF WEBLOGS HAS BEEN REACHED
$num_weblogs = mysql_num_rows(mysql_query("SELECT w_id FROM bhost_weblogs WHERE u_id='$user_info[u_id]'"));
if($num_weblogs >= $group_info[num_weblogs]) {
echo $head;
echo "
$create_weblog24
<br><br>
<form action='index.php' method='POST'>
<input type='submit' class='button' value='$create_weblog25'>
</form>
";
echo $foot;
exit();
}








// SET ERROR VARS
$is_error = "no";
$result = "";
$weblog_error = "";
$weblog_is_error = "";
$title_error = "";
$title_is_error = "";
$description_error = "";
$description_is_error = "";
$wc_id_error = "";
$wc_id_is_error = "";
$code_error = "";
$code_is_error = "";


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






if($task == "step3") {
$weblog = htmlspecialchars(stripslashes($_POST['weblog']), ENT_QUOTES);
$title = str_replace($bad_words, $bad_words_replace, str_replace("'", "&#39;", htmlspecialchars(stripslashes($_POST['title']), ENT_QUOTES)));
$description = str_replace($bad_words, $bad_words_replace, str_replace("'", "&#39;", htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES)));
$wc_id = $_POST['wc_id'];
$template = $_POST['template'];
$date_created = time();

// CHECK ERRORS AGAIN
 $banned_weblogs = explode(",", $admin_info[banned_weblogs]);
 if(in_array($weblog, $banned_weblogs)) {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog1";
 }
 if(is_dir($weblog) | $weblog == "interests" | $weblog == "profiles" | $weblog == "albums") {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog2";
 }
 $duplicates = mysql_num_rows(mysql_query("SELECT w_id FROM bhost_weblogs WHERE weblog='$weblog'"));
 if($duplicates != 0) {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog3";
 }
 if(preg_match("/[^a-z,A-Z,0-9]/", $weblog)) {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog4";
 }
 if(str_replace(" ", "", $weblog) == "") {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog5";
 }
 if(str_replace(" ", "", $title) == "" & $admin_info[field_title] == "3") {
  $is_error = "yes";
  $title_is_error = "error";
  $title_error = "$create_weblog6";
 } else {
  $title = $create_weblog27;
 }
 if(str_replace(" ", "", $description) == "" & $admin_info[description_field] == "3") {
  $is_error = "yes";
  $description_is_error = "error";
  $description_error = "$create_weblog7";
 }
 if($wc_id == "") {
  $is_error = "yes";
  $wc_id_is_error = "error";
  $wc_id_error = "$create_weblog8";
 }
 if($admin_info[signup_image] == 1 AND function_exists('gd_info')) {
  $codesent = $_POST['codesent'];
  $code = $_POST['code'];
  $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 = "yes";
   $code_is_error = "error";
   $code_error = "$create_weblog9";
  }
 }

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

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

// ADD WEBLOG IF NO ERRORS
if($is_error == "no") {
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]',
'',
'',
'',
'$date_created',
'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'
)");
header("Location: index.php");
exit();
} else {
$task = "step1";
}
}






if($task == "step2") {
$weblog = htmlspecialchars(stripslashes($_POST['weblog']), ENT_QUOTES);
$title = str_replace($bad_words, $bad_words_replace, str_replace("'", "&#39;", htmlspecialchars(stripslashes($_POST['title']), ENT_QUOTES)));
$description = str_replace($bad_words, $bad_words_replace, str_replace("'", "&#39;", htmlspecialchars(stripslashes($_POST['description']), ENT_QUOTES)));
$wc_id = $_POST['wc_id'];


 $banned_weblogs = explode(",", $admin_info[banned_weblogs]);
 if(in_array($weblog, $banned_weblogs)) {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog1";
 }
 if(is_dir($weblog) | $weblog == "interests" | $weblog == "profiles" | $weblog == "albums") {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog2";
 }
 $duplicates = mysql_num_rows(mysql_query("SELECT w_id FROM bhost_weblogs WHERE weblog='$weblog'"));
 if($duplicates != 0) {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog3";
 }
 if(preg_match("/[^a-z,A-Z,0-9]/", $weblog)) {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog4";
 }
 if(str_replace(" ", "", $weblog) == "") {
  $is_error = "yes";
  $weblog_is_error = "error";
  $weblog_error = "$create_weblog5";
 }
 if(str_replace(" ", "", $title) == "" & $admin_info[field_title] == "3") {
  $is_error = "yes";
  $title_is_error = "error";
  $title_error = "$create_weblog6";
 }
 if(str_replace(" ", "", $description) == "" & $admin_info[field_description] == "3") {
  $is_error = "yes";
  $description_is_error = "error";
  $description_error = "$create_weblog7";
 }
 if($wc_id == "") {
  $is_error = "yes";
  $wc_id_is_error = "error";
  $wc_id_error = "$create_weblog8";
 }
 if($admin_info[signup_image] == 1 AND function_exists('gd_info')) {
  $codesent = $_POST['codesent'];
  $code = $_POST['code'];
  $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 = "yes";
   $code_is_error = "error";
   $code_error = "$create_weblog9";
  }
 }

// DISPLAY STEP 2 IF NO ERROR 
if($is_error == "no") {
echo $head;

echo "
<h2>$create_weblog22</h2>
$create_weblog23
<br>

<table cellpadding='0' cellspacing='0'>
<form action='create_weblog.php' method='POST'>
<tr>
<td>

";

$template_array = explode(",", $group_info[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 .. IS IN THE IMAGE URL
  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' id='template_$template[t_id]' value='$template[t_id]'"; if($tempcount == 1) { echo " CHECKED"; } echo "></td><td class='templatename'><font class='bold'><label for='template_$template[t_id]'>$template[name]</label></font></td></tr>
</table>
</div>
</div>
";
}}

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

<br>
<input type='submit' class='button' value='$create_weblog20'>
<input type='hidden' name='task' value='step3'>
<input type='hidden' name='weblog' value='$weblog'>
<input type='hidden' name='title' value='$title'>
<input type='hidden' name='description' value='$description'>
<input type='hidden' name='wc_id' value='$wc_id'>
<input type='hidden' name='code' value='$code'>
<input type='hidden' name='codesent' value='$codesent'>
</form>
";
echo $foot;
exit;
} else {
$task = "step1";
}
}









if($is_error == "no") {
$weblog = "";
$title = "";
$description = "";
$wc_id = "";
$codesent = "";
}




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

$path = url("index", "<!>PATH<!>");
$path = str_replace("<!>PATH<!>", "&nbsp;<input type='text' class='text' name='weblog' value='$weblog' tabindex='1'>&nbsp;", $path);

if(substr($path, -1) == "/") { $path = substr($path, 0, -1); }

echo "
$create_weblog10
<br><br>
<table cellpadding='0' cellspacing='0' class='form'>
<form action='create_weblog.php' method='POST'>
<tr>
<td class='form1$weblog_is_error' valign='top'>$create_weblog11*</td>
<td class='form2' valign='top'>
 <font class='code'>$path</font>
 <div class='help'>$create_weblog12</div>
 "; show_error($weblog_error); echo "
</td>
</tr>
";
if($admin_info[field_title] == "3" | $admin_info[field_title] == "2") {
echo "
<tr>
<td class='form1$title_is_error' valign='top'>$create_weblog13"; if($admin_info[field_title] == "3") { echo "*"; } echo "</td>
<td class='form2'><input type='text' class='text' name='title' value='$title' size='50' tabindex='2'><br><div class='help'>$create_weblog14</div>"; show_error($title_error); echo "</td>
</tr>
";
} else {
echo "<input type='hidden' name='title' value=''>";
}
if($admin_info[field_description] == "3" | $admin_info[field_description] == "2") {
echo "
<tr>
<td class='form1$description_is_error' valign='top'>$create_weblog15"; if($admin_info[field_description] == "3") { echo "*"; } echo "</td>
<td class='form2'><textarea name='description' rows='7' cols='51' tabindex='3'>$description</textarea><br><div class='help'>$create_weblog16</div>"; show_error($description_error); echo "</td>
</tr>
";
}

$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_is_error' valign='top'>$create_weblog17*</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><div class='help'>$create_weblog21</div>"; show_error($wc_id_error); echo "</td></tr>";
} else {
 echo "<input type='hidden' name='wc_id' value='0'>";
}




// 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$code_is_error' valign='top'>$create_weblog18*</td>
<td class='form2'>
 <table cellpadding='0' cellspacing='0'>
 <tr>
 <td><input type='text' name='codesent' class='text' size='6' maxlength='10' tabindex='5'></td>
 <td style='padding-left: 10px;'><img src='create_weblog.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>
 <div class='help'>$create_weblog19</div>
 "; show_error($code_error); echo "
</td>
</tr>
";
}

echo "
</table>

<br>
";

// IF USER DOES NOT CHOOSE TEMPLATE
if($admin_info[signup_choosetemplate] == 1) {
 $template_array = explode(",", $group_info[templates]);
 $count = 0;
 $templates = mysql_query("SELECT * 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 * FROM bhost_templates LIMIT 1"));
 echo "<input type='hidden' name='task' value='step3'><input type='hidden' name='template' value='$template_info[t_id]'>";
 } else {
 echo "<input type='hidden' name='task' value='step2'>";
 }
} else {
echo "
<input type='hidden' name='task' value='step3'>
<input type='hidden' name='template' value='$admin_info[signup_templatedefault]'>
";
}

echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='submit' class='button' value='$create_weblog20' tabindex='6'>&nbsp;</td>
</form>
<form action='index.php' method='POST'>
<td><input type='submit' class='button' value='$create_weblog26'></td>
</tr>
</form>
</table>
";

echo $foot;
}

?>