<?
$page = "mobile_settings.php";
include "manager_header.php";
if($owner_group_info[allow_moblogging] != "1") { exit(); }
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }

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












if($task == "dosave") {
$moblog_on = $_POST['moblog_on'];
$moblog_publish = $_POST['moblog_publish'];

//PROCESS EMAILS
$total_emails = $_POST['total_emails'];
$moblog_emails = "";
$moblog_users = "";
for($l=0;$l<($total_emails+1);$l++) {
$var1 = "moblog_email_$l";
$var2 = "moblog_user_$l";
$moblog_email = str_replace("'", "&#39;", str_replace("<!>", "", $_POST[$var1]));
$moblog_user = str_replace("'", "", str_replace("<!>", "", $_POST[$var2]));

// IF THERE ARE OTHER MEMBERS, BE SURE EMAILS AND MEMBERS ARE MATCHED
if(str_replace(" ", "", str_replace(",", "", $weblog_info[level1])) != "" | str_replace(" ", "", str_replace(",", "", $weblog_info[level2])) != "") { 

	if(str_replace(" ", "", $moblog_email) != "" AND str_replace(" ", "", $moblog_user) != "") {

		if($l != 0) { $moblog_emails .= "<!>"; $moblog_users .= "<!>"; }
		$moblog_emails .= "$moblog_email";
		$moblog_users .= "$moblog_user";

	}

// IF THERE ARE NO OTHER MEMBERS, MAKE EMAILS BELONG TO OWNER
} else {

	if(str_replace(" ", "", $moblog_email) != "") {

		if($l != 0) { $moblog_emails .= "<!>"; $moblog_users .= "<!>"; }
		$moblog_emails .= "$moblog_email";
		$moblog_users .= "$user_info[u_id]";

	}

}


}




mysql_query("UPDATE bhost_weblogs SET moblog_on='$moblog_on', moblog_publish='$moblog_publish', moblog_emails='$moblog_emails', moblog_users='$moblog_users' WHERE w_id='$weblog_info[w_id]'");
$weblog_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_weblogs WHERE w_id='$weblog_info[w_id]'"));
$result = "<img src='../images/saved_icon.gif' border='0' class='success'> <font class='success'>$mobile_settings1</font><br><br>";
$task = "main";
}






if($task == "main") {
$secret_email = $weblog_info[moblog_secret].strstr($owner_group_info[moblog_email], "@");
$domain = str_replace("www.", "", $_SERVER['HTTP_HOST']);
$secret_email .= "@$domain";
$mobile_folder = "$mobile_folder_name";

echo $head;

echo "
$mobile_settings3
";

if($weblog_info[moblog_on] == 0) {
echo "$mobile_settings4";
} else {
echo "$mobile_settings5 ";
if($group_info[allow_uploads] == 1) {
	if(str_replace(" ", "", str_replace(",", "", $weblog_info[level1])) != "" | str_replace(" ", "", str_replace(",", "", $weblog_info[level2])) != "") { $othermembers = 1; }
	if($owner_group_info[allow_multiauthor] == 1 AND $othermembers == 1) {
	echo "$mobile_settings20";
	} else {
	echo "$mobile_settings2";
	}
}

echo "
<br><br>
<table cellpadding='0' cellspacing='0'>
<tr><td class='empty'>$mobile_settings19 <font class='bold'>$secret_email</font></td></tr>
</table>

<br>
";
}

if(str_replace(" ", "", str_replace(",", "", $weblog_info[level1])) != "" | str_replace(" ", "", str_replace(",", "", $weblog_info[level2])) != "") { 
$emails_label = $mobile_settings16;
} else {
$emails_label = $mobile_settings9;
}

echo "
$result

<table cellpadding='0' cellspacing='0' class='form'>
<form action='mobile_settings.php' method='POST'>
<tr>
<td class='form1'>$mobile_settings6</td>
<td class='form2'>
<select name='moblog_on'>
<option value='0'"; if($weblog_info[moblog_on] == 0) { echo " SELECTED"; } echo ">$mobile_settings7</option>
<option value='1'"; if($weblog_info[moblog_on] == 1) { echo " SELECTED"; } echo ">$mobile_settings8</option>
</select>
</td>
</tr>
<tr>
<td class='form1'>$mobile_settings10</td>
<td class='form2'>
<select name='moblog_publish'>
<option value='1'"; if($weblog_info[moblog_publish] == 1) { echo " SELECTED"; } echo ">$mobile_settings11</option>
<option value='0'"; if($weblog_info[moblog_publish] == 0) { echo " SELECTED"; } echo ">$mobile_settings12</option>
</select>
</td>
</tr>
<tr>
<td class='form1'>$emails_label</td>
<td class='form2'>
  <table cellpadding='0' cellspacing='0'>
";

if(str_replace(" ", "", str_replace(",", "", $weblog_info[level1])) != "" | str_replace(" ", "", str_replace(",", "", $weblog_info[level2])) != "") { 
echo "
  <tr>
  <td>$mobile_settings14</td>
  <td>$mobile_settings15</td>
  </tr>
";
}

$total_emails = 0;
$count = 0;
if($weblog_info[moblog_emails] != "") {

 $moblog_email = explode("<!>", trim($weblog_info[moblog_emails]));
 $moblog_user = explode("<!>", trim($weblog_info[moblog_users]));

 if($moblog_email[0] == "") { array_shift($moblog_email); }
 if($moblog_user[0] == "") { array_shift($moblog_user); }

 for($l=0;$l<count($moblog_email);$l++) {
  $count++;
  echo "
   <tr>
   <td><input type='text' class='text' name='moblog_email_$l' size='30' value='$moblog_email[$l]'>&nbsp;</td>
  "; 
  if(str_replace(" ", "", str_replace(",", "", $weblog_info[level1])) != "" | str_replace(" ", "", str_replace(",", "", $weblog_info[level2])) != "") { 
   echo "
    <td>
    <select name='moblog_user_$l'>
    <option value=''></option>
    <option value='$owner_info[u_id]'"; if($moblog_user[$l] == "$owner_info[u_id]") { echo " SELECTED"; } echo ">$owner_info[username]</option>
   ";
   $admins = explode(",", trim($weblog_info[level1]));
   for($a=0;$a<count($admins);$a++) {
    $admin_query = mysql_query("SELECT u_id, g_id, username FROM bhost_users WHERE u_id='$admins[$a]'");
    if(mysql_num_rows($admin_query) == 1) { 
     $admin_info = mysql_fetch_assoc($admin_query);
     $admin_group_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_groups WHERE g_id='$admin_info[g_id]'"));
     if($admin_group_info[allow_multiauthor] == "1") {
      echo "<option value='$admin_info[u_id]'"; if($moblog_user[$l] == "$admin_info[u_id]") { echo " SELECTED"; } echo ">$admin_info[username]</option>";
     }
    }
   }
   $members = explode(",", trim($weblog_info[level2]));
   for($a=0;$a<count($members);$a++) {
    $member_query = mysql_query("SELECT u_id, g_id, username FROM bhost_users WHERE u_id='$members[$a]'");
    if(mysql_num_rows($member_query) == 1) { 
     $member_info = mysql_fetch_assoc($member_query);
     $member_group_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_groups WHERE g_id='$member_info[g_id]'"));
     if($member_group_info[allow_multiauthor] == "1") {
      echo "<option value='$member_info[u_id]'"; if($moblog_user[$l] == "$member_info[u_id]") { echo " SELECTED"; } echo ">$member_info[username]</option>";
     }
    }
   }
  echo "
   </select>
   </td>
  "; 
  }
  echo "
   </tr>
  ";
  $total_emails++;
 }
}

echo "
<tr>
<td><input type='text' class='text' name='moblog_email_$total_emails' value='' size='30'>&nbsp;</td>
";

// IF THERE ARE OTHER MEMBERS, SHOW SELECT BOXES
if(str_replace(" ", "", str_replace(",", "", $weblog_info[level1])) != "" | str_replace(" ", "", str_replace(",", "", $weblog_info[level2])) != "") { 
 echo "
 <td>
 <select name='moblog_user_$total_emails'>
 <option value=''></option>
 <option value='$owner_info[u_id]'>$owner_info[username]</option>
 ";
 $admins = explode(",", trim($weblog_info[level1]));
 for($a=0;$a<count($admins);$a++) {
  $admin_query = mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$admins[$a]'");
  if(mysql_num_rows($admin_query) == 1) { 
   $admin_info = mysql_fetch_assoc($admin_query);
   if($admin_group_info[allow_multiauthor] == "1") {
    echo "<option value='$admin_info[u_id]'>$admin_info[username]</option>";
   }
  }
 }
 $members = explode(",", trim($weblog_info[level2]));
 for($a=0;$a<count($members);$a++) {
  $member_query = mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$members[$a]'");
  if(mysql_num_rows($member_query) == 1) { 
   $member_info = mysql_fetch_assoc($member_query);
   if($member_group_info[allow_multiauthor] == "1") {
    echo "<option value='$member_info[u_id]'>$member_info[username]</option>";
   }
  }
 }
 echo "
 </select>
 </td>
 "; 


}

echo "
</tr>
</table>

</td>
</table>

<br>

<input type='submit' class='button' value='$mobile_settings13'>
<input type='hidden' name='task' value='dosave'>
<input type='hidden' name='total_emails' value='$total_emails'>
</form>
";

echo $foot;
exit;
}

?>