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


if($task == "accept") {
if(isset($_GET['w_id'])) { $w_id = $_GET['w_id']; } else { header("Location: index.php"); exit(); }
$weblog_query = mysql_query("SELECT * FROM bhost_weblogs WHERE w_id='$w_id' AND invited LIKE '%,$user_info[u_id],%'");
if(mysql_num_rows($weblog_query) != 1) { header("Location: index.php"); exit(); }
$weblog_info = mysql_fetch_assoc($weblog_query);

if($weblog_info[level2] == "") { $new_level2 = ","; } else { $new_level2 = $weblog_info[level2]; }
$new_level2 .= $user_info[u_id].",";
$new_invited = str_replace(",$user_info[u_id],", ",", $weblog_info[invited]);
mysql_query("UPDATE bhost_weblogs SET level2='$new_level2', invited='$new_invited' WHERE w_id='$weblog_info[w_id]'");
header("Location: index.php");
exit();
}



if($task == "reject") {
if(isset($_GET['w_id'])) { $w_id = $_GET['w_id']; } else { header("Location: index.php"); exit(); }
$weblog_query = mysql_query("SELECT * FROM bhost_weblogs WHERE w_id='$w_id' AND invited LIKE '%,$user_info[u_id],%'");
if(mysql_num_rows($weblog_query) != 1) { header("Location: index.php"); exit(); }
$weblog_info = mysql_fetch_assoc($weblog_query);

$new_invited = str_replace(",$user_info[u_id],", ",", $weblog_info[invited]);

mysql_query("UPDATE bhost_weblogs SET invited='$new_invited' WHERE w_id='$weblog_info[w_id]'");
header("Location: index.php");
exit();
}







echo $head;

// USER WARNING
 if($group_info[type] != 0) {
  $today = MakeTime("0", "0", "0", date("n", time()), date("j", time()), date("Y", time()));
  $last_payment = MakeTime("0", "0", "0", date("n", $user_info[last_payment]), date("j", $user_info[last_payment]), date("Y", $user_info[last_payment]));
  switch($group_info[frequency]) {
   case "weekly":
    $check_last_payment = $today-(7*24*60*60);
    $payment_date = $last_payment+(7*24*60*60);
    break;
   case "monthly":
     if(date("j", $last_payment) == "31" & (date("n", $last_payment) == "3" | date("n", $last_payment) == "5" | date("n", $last_payment) == "8" | date("n", $last_payment) == "10")) { 
      $payment_date = MakeTime("0", "0", "0", date("n", $last_payment)+1, 30, date("Y", $last_payment)); 
     } elseif(date("n", $last_payment) == "1" & (date("j", $last_payment) == "31" | date("j", $last_payment) == "30" | (date("j", $last_payment) == "29" & date("L", $last_payment) != "1"))) { 
      $payment_date = MakeTime("0", "0", "0", date("n", $last_payment)+1, 28, date("Y", $last_payment)); 
     } else { 
      $payment_date = MakeTime("0", "0", "0", date("n", $last_payment)+1, date("j", $last_payment), date("Y", $last_payment));
     }
     if(date("n", $today) == "3" & (date("j", $today) == "31" | date("j", $today) == "30" | date("j", $today) == "29")) {
      if(date("L", $today) == "1") { $day = 29; } else { $day = 28; }
      $check_last_payment = MakeTime("0", "0", "0", date("n", time())-1, $day, date("Y", time()));
     } elseif(date("j", $today) == 31 & (date("n", $today) == "5" | date("n", $today) == "7" | date("n", $today) == "10" | date("n", $today) == "12")) {
      $check_last_payment = MakeTime("0", "0", "0", date("n", time())-1, 30, date("Y", time()));
     } else {
      $check_last_payment = MakeTime("0", "0", "0", date("n", time())-1, date("j", time()), date("Y", time()));
     }
    break;
   case "yearly":
    $lpayday = date("j", $last_payment); 
    $lpayday = date("n", $last_payment); 
    $lpayday = date("Y", $last_payment); 
    $payment_date = MakeTime("0", "0", "0", date("n", $last_payment), date("j", $last_payment), date("Y", $last_payment)+1);
    $check_last_payment = MakeTime("0", "0", "0", date("n", time()), date("j", time()), date("Y", time())-1);
    break;
  }

  $check_warning = $check_last_payment+($group_info[warning]*24*60*60);
  if($user_info[last_payment] <= $check_warning & str_replace(" ", "", $group_info[warning_message]) != "") {
   $warning_message = str_replace("&#39;", "'", $group_info[warning_message]);
   echo "
   <h2>$index10 ".cdate($admin_info[signup_format_date], $payment_date)."</h2>
   <div class='myweblogs_box'>".str_replace("\r\n", "<br>", $warning_message)."</div>
   <br>
   ";
  }
 }



// SHOW GROUP NEWS
if(str_replace(" ", "", $group_info[news]) != "") {
$news_text = str_replace("\r\n", "<br>", $group_info[news]);
echo "
<h2>$index6</h2>
<div class='myweblogs_box'>$news_text</div>
<br>
";
}



// SHOW NEW PRIVATE MESSAGE ALERT
if($group_info[allow_pms] == 1 AND $pms > 0) {
if($pms == 1) {
$pmtext = "$index11 $pms $index12 <a href='".url("profile", "", "$pm_from")."'>$pm_from</a>$index13 &nbsp; [ <a href='messages.php?task=read&pm_id=$pm_id'>$index16</a> ]";
} elseif($pms > 1) {
$pmtext = "$index11 $pms $index14 &nbsp; [ <a href='messages.php'>$index15</a> ]";
}
echo "
<h2>$index17</h2>
<div class='myweblogs_box'>
$pmtext
</div>
<br>
";
}



// SHOW INVITATIONS
$weblogs_invited = mysql_query("SELECT * FROM bhost_weblogs WHERE invited LIKE '%,$user_info[u_id],%'");
if($group_info[allow_multiauthor] == "1" & mysql_num_rows($weblogs_invited) != 0) {
echo "
<h2>$index7</h2>
<div class='myweblogs_box'>
";
$count = 0;
while($weblogs_invited_info = mysql_fetch_assoc($weblogs_invited)) {
$count ++;
if($count > 1) { $class = 2; } else { $class = 1; }
if(str_replace(" ", "", $weblogs_invited_info[title]) == "") { $weblogs_invited_info[title] = $weblogs_invited_info[weblog]; }
echo "
$index22 <font class='bold'><a href='".url("index", $weblogs_invited_info[weblog])."'>$weblogs_invited_info[title]</a></font>&nbsp;&nbsp;&nbsp;&nbsp;
<a href='index.php?task=accept&w_id=$weblogs_invited_info[w_id]'><img src='../images/invite_accept.gif' border='0' class='icon'></a> <a href='index.php?task=accept&w_id=$weblogs_invited_info[w_id]'>$index23</a> &nbsp;
<a href='index.php?task=reject&w_id=$weblogs_invited_info[w_id]'><img src='../images/invite_reject.gif' border='0' class='icon'></a> <a href='index.php?task=reject&w_id=$weblogs_invited_info[w_id]'>$index24</a> &nbsp;
";
}
echo "</div><br>";
}





// SHOW WEBLOGS
$weblogs_own = mysql_query("SELECT * FROM bhost_weblogs WHERE u_id='$user_info[u_id]' ORDER BY weblog");
$weblogs_admin = mysql_query("SELECT * FROM bhost_weblogs WHERE level1 LIKE '%,$user_info[u_id],%' ORDER BY weblog");
$weblogs_member = mysql_query("SELECT * FROM bhost_weblogs WHERE level2 LIKE '%,$user_info[u_id],%' ORDER BY weblog");
$weblogs_total = mysql_num_rows(mysql_query("SELECT w_id FROM bhost_weblogs WHERE u_id='$user_info[u_id]'"));


if($weblogs_total != 0) {
echo "
$index1
<table class='webloglist' cellpadding='0' cellspacing='0'>
";

$count = 0;
while($weblogs_own_info = mysql_fetch_assoc($weblogs_own)) {
$num_entries = mysql_num_rows(mysql_query("SELECT e_id FROM bhost_entries WHERE w_id='$weblogs_own_info[w_id]'"));
$num_comments = mysql_num_rows(mysql_query("SELECT c_id FROM bhost_comments WHERE w_id='$weblogs_own_info[w_id]'"));
$count++;
if($count > 1) { $class = 2; } else { $class = 1; }
echo "
<tr>
<td width='90%' class='webloglist$class' NOWRAP><a href='".url("index", "$weblogs_own_info[weblog]")."'><img src='../images/openfolder.gif' border='0' class='icon'></a> <b><a href='weblog_cookies.php?w_id=$weblogs_own_info[w_id]'>$weblogs_own_info[weblog]</a></b></td>
<td class='webloglist$class' NOWRAP>$num_entries $index8 &nbsp;</td>
<td class='webloglist$class' NOWRAP>$num_comments $index9 &nbsp;</td>
<td class='webloglist$class' NOWRAP><a href='weblog_cookies.php?w_id=$weblogs_own_info[w_id]&t=new'><img src='../images/new_entry.gif' border='0' class='icon'></a> <a href='weblog_cookies.php?w_id=$weblogs_own_info[w_id]&t=new'>$index2</a> &nbsp;</td>
<td class='webloglist$class' NOWRAP><a href='weblog_cookies.php?w_id=$weblogs_own_info[w_id]&t=settings'><img src='../images/settings.gif' border='0' class='icon'></a> <a href='weblog_cookies.php?w_id=$weblogs_own_info[w_id]&t=settings'>$index3</a> &nbsp;</td>
<td class='webloglist$class' NOWRAP><a href='delete_weblog.php?w_id=$weblogs_own_info[w_id]'><img src='../images/delete_weblog.gif' border='0' class='icon'></a> <a href='delete_weblog.php?w_id=$weblogs_own_info[w_id]'>$index4</a> &nbsp;</td>
</tr>
";
}
if($group_info[allow_multiauthor] == "1") {
while($weblogs_admin_info = mysql_fetch_assoc($weblogs_admin)) {
$num_entries = mysql_num_rows(mysql_query("SELECT e_id FROM bhost_entries WHERE w_id='$weblogs_admin_info[w_id]'"));
$num_comments = mysql_num_rows(mysql_query("SELECT c_id FROM bhost_comments WHERE w_id='$weblogs_admin_info[w_id]'"));
$count++;
if($count > 1) { $class = 2; } else { $class = 1; }
echo "
<tr>
<td class='webloglist$class' NOWRAP><a href='".url("index", "$weblogs_admin_info[weblog]")."'><img src='../images/openfolder.gif' border='0' class='icon'></a> <b><a href='weblog_cookies.php?w_id=$weblogs_admin_info[w_id]'>$weblogs_admin_info[weblog]</a></b> &nbsp;</td>
<td class='webloglist$class' NOWRAP>$num_entries $index8 &nbsp;</td>
<td class='webloglist$class' NOWRAP>$num_comments $index9 &nbsp;</td>
<td class='webloglist$class' NOWRAP><a href='weblog_cookies.php?w_id=$weblogs_admin_info[w_id]&t=new'><img src='../images/new_entry.gif' border='0' class='icon'></a> <a href='weblog_cookies.php?w_id=$weblogs_admin_info[w_id]&t=new'>$index2</a> &nbsp;</td>
<td class='webloglist$class' NOWRAP><a href='weblog_cookies.php?w_id=$weblogs_admin_info[w_id]&t=settings'><img src='../images/settings.gif' border='0' class='icon'></a> <a href='weblog_cookies.php?w_id=$weblogs_admin_info[w_id]&t=settings'>$index3</a> &nbsp;</td>
<td class='webloglist$class' NOWRAP><img src='../images/delete_weblog_d.gif' border='0' class='icon'> <font class='gray'>$index4</font> &nbsp;</td>
</tr>
";
}
while($weblogs_member_info = mysql_fetch_assoc($weblogs_member)) {
$num_entries = mysql_num_rows(mysql_query("SELECT e_id FROM bhost_entries WHERE w_id='$weblogs_member_info[w_id]'"));
$num_comments = mysql_num_rows(mysql_query("SELECT c_id FROM bhost_comments WHERE w_id='$weblogs_member_info[w_id]'"));
$count++;
if($count > 1) { $class = 2; } else { $class = 1; }
echo "
<tr>
<td class='webloglist$class' NOWRAP><a href='".url("index", "$weblogs_member_info[weblog]")."'><img src='../images/openfolder.gif' border='0' class='icon'></a> <b><a href='weblog_cookies.php?w_id=$weblogs_member_info[w_id]'>$weblogs_member_info[weblog]</a></b> &nbsp;</td>
<td class='webloglist$class' NOWRAP>$num_entries $index8 &nbsp;</td>
<td class='webloglist$class' NOWRAP>$num_comments $index9 &nbsp;</td>
<td class='webloglist$class' NOWRAP><a href='weblog_cookies.php?w_id=$weblogs_member_info[w_id]&t=new'><img src='../images/new_entry.gif' border='0' class='icon'></a> <a href='weblog_cookies.php?w_id=$weblogs_member_info[w_id]&t=new'>$index2</a> &nbsp;</td>
<td class='webloglist$class' NOWRAP><img src='../images/settings_d.gif' border='0' class='icon'> <font class='gray'>$index3</font> &nbsp;</td>
<td class='webloglist$class' NOWRAP><img src='../images/delete_weblog_d.gif' border='0' class='icon'> <font class='gray'>$index4</font> &nbsp;</td>
</tr>
";
}
}
echo "</table>";
}



// SHOW WARNING IF USER HAS NO BLOGS
if($weblogs_total == 0 AND $group_info[num_weblogs] > 0) {
$no_blogs_warning = "$index5";
if($group_info[num_weblogs] != 0) { $no_blogs_warning .= " $index21"; }
echo "
$index1
<div class='myweblogs_box'>
$no_blogs_warning
</div>
";
}



// SHOW CREATE WEBLOG BUTTON
if($weblogs_total < $group_info[num_weblogs]) {
echo "
<br>
<form action='create_weblog.php' method='POST'>
<input type='submit' class='button' value='$index25'>
</form>
<br>
";
} else {
if($group_info[num_weblogs] != 0) {
echo "
<br>
";
}
}





// SHOW WHO'S ONLINE
if($admin_info[show_whosonline] == "1") {
$online_time = time()-15*60;
$online_users = mysql_query("SELECT username, last_activity FROM bhost_users WHERE last_activity>'$online_time' ORDER BY last_activity DESC LIMIT 2000");
$total_online_users = mysql_num_rows($online_users);
echo "
<h2>$index19 ($total_online_users)</h2>
<div class='myweblogs_box'>
";
$count = 0;
while($online_user = mysql_fetch_assoc($online_users)) {
if($count != 0) { $whosonline .= ", "; }
$online_time = cdate($admin_info[signup_format_time], $online_user[last_activity]);
$whosonline .= "<a href='".url("profile", "", "$online_user[username]")."' title='$online_time'>$online_user[username]</a>";
$count++;
}
$whosonline .= "
</div>
";

echo $whosonline;
}


// SHOW RECENTLY UPDATED BLOGS
$update = "";
if($admin_info[recent_updates] != 0 AND $admin_info[recent_updates] != "") {
$entries = mysql_query("SELECT w_id, author_u_id, max(e_id) AS max_e_id FROM bhost_entries WHERE privacy='3' GROUP BY w_id ORDER BY max_e_id DESC LIMIT $admin_info[recent_updates]");
if(mysql_num_rows($entries) > 0) {
echo "
<br>
<h2>$index18</h2>
<div class='myweblogs_box'>
";
while($entry = mysql_fetch_assoc($entries)) {
$update = "";
$blog = mysql_fetch_assoc(mysql_query("SELECT weblog, title FROM bhost_weblogs WHERE w_id='$entry[w_id]' LIMIT 1"));
if(strlen($blog[title]) > 50) { $blog[title] = substr($blog[title], 0, 30); $blog[title] .= "..."; }
$author = mysql_fetch_assoc(mysql_query("SELECT username FROM bhost_users WHERE u_id='$entry[author_u_id]' LIMIT 1"));

$update = "
<font class='bold'><a href='".url("index", $blog[weblog])."'>$blog[title]</a></font> 
<font class='gray'>(</font> $index20 <a href='".url("profile", "", "$author[username]")."'>$author[username]</a> <font class='gray'>)</font><br>
";

echo $update;
}
echo "
</div>
";

}
}






echo $foot;

?>