Jump to content

Confusing problems (Personal Messages)


xyn

Recommended Posts

Hey there,

 

OK, I can code these but, I've decided the try a new method

because in this new Personal Messenger, I wish to allow the

members to COPY the private messages / Send to Multiple

members.

 

Problem is i didn't know how to get around this and i've tried

to come to a conclusion but i don't know how to fix this...

 

My Code:

<?php
include("mem_sessions.php");	//Check their Logged In
include("mem_messenger_auth.php"); //Check they aren't banned from PMs

if(!isset($_POST['submit']))
{	//SubmitFalseShowForm
?>
<form method="POST" action="<?=$_SERVER['PHP_SELF'];?>?cid=5&id=1">
  <div align="center">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="411">
      <tr>
        <td>
        <p align="center">
        <img border="0" src="/tmp/banners/members.PNG" width="301" height="89"></p>
        </td>
      </tr>
      <tr>
        <td height="5"></td>
      </tr>
      <tr>
        <td>
        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="411">
          <tr>
            <td width="93"><p>To:</td>
            <td width="318"><input type="text" name="to" size="27"></td>
          </tr>
          <tr>
            <td width="93" valign="top"><p>Cc:</td>
            <td width="318"><p><textarea rows="3" name="cc" cols="23"></textarea><br>
            <font size="1">(Separate each by a comma, ie: tom,paul,lucy)</font></td>
          </tr>
          <tr>
            <td width="93" height="5"></td>
            <td width="318" height="5"></td>
          </tr>
          <tr>
            <td width="93"><p>Subject:</td>
            <td width="318"><input type="text" name="subject" size="37"></td>
          </tr>
          <tr>
            <td width="93" valign="top"><p>Message:</td>
            <td width="318"><textarea rows="5" name="message" cols="31"></textarea></td>
          </tr>
          <tr>
            <td width="93" height="5"></td>
            <td width="318" height="5"></td>
          </tr>
          <tr>
            <td width="411" colspan="2">
            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="411">
              <tr>
                <td width="33" align="center">
                <input type="checkbox" name="draft" value="TRUE"></td>
                <td width="378"><p>Save as a draft copy</td>
              </tr>
              <tr>
                <td width="33" align="center">
                <input type="checkbox" name="copy" value="TRUE"></td>
                <td width="378"><p>Save a copy to &#39;sent items&#39;</td>
              </tr>
            </table>
            </td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>
        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="411">
          <tr>
            <td width="411" height="5"></td>
          </tr>
          <tr>
            <td width="411" height="20">
            <p align="center">
            <input type="submit" value="Send Message" name="submit"></p>
            </td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    </center>
  </div>
</form>
<?
}
else
{	//SubmitPressed
if(!isset($_POST['to']))
{
	$error[] = "Please enter a username, who will receive this message.";
}
if(!isset($_POST['subject']))
{
	$error[] = "Please enter the subject of the message.";
}
if(!isset($_POST['message']))
{
	$error[] = "Please enter the message.";
}

if(is_array($error))
{
	echo("<UL>Please fix the errors below:");
	foreach($error as $key => $value)
	{
		echo("<li><span id=\"text\">" .$value. "</span></li><br>");
	}
	echo("</ul>");
	exit();
}

if(isset($_POST['cc']))
{	//CcIsSetSoCopyMessages
	$SQL_from = mysql_query("SELECT `user` FROM `accounts` WHERE `id`='".$_SESSION['UID']."'");
	while($q_data = mysql_fetch_array($SQL_from))
	{
		$user_from=$q_data[0];
		$date = date("j/m/Y, g:ia");
	}

	$To_CC = explode("," $_POST['cc']);
	foreach($To_CC as $key => $To_User)
	{	//LetsSendMessageToEveryOne
		$SQL_pm_check = mysql_query("SELECT * FROM `options` WHERE `id`='$u_UID'");
		while($i_data = mysql_fetch_array($SQL_pm_check))
		{
			if($i_data['pm_ban'] == "0" && $i_data['pm_on'] == "1")
			{
				$Max=$i_data['pm_max'];
				$SQL_pm_max = mysql_query("SELECT * FROM `pm_inbox` WHERE `userid`='$To_User'");
				$rows=mysql_num_rows($SQL_pm_max);

				if($Max < "$rows")
				{
					$SQL_check_user = mysql_query("SELECT * FROM `accounts` WHERE `user`='$To_User'");
					if(mysql_num_rows($SQL_check_user) >0)
					{
						mysql_query("INSERT INTO `pm_inbox` (`userid`, `from`, `title`, `message`, `date`, `folder`, `stats`, `reported`) 
						VALUES 
						('".Secure($To_User)."', '".$user_from."', '".Secure(Filter($_POST['subject']))."', '".Secure(Filter($_POST['message']))."', '$date', 'inbox', '0', '0')");
					}
				}
			}
		}
	}
}
else
{	//CcNotSetSentMessageAnyWay
	while($q_uid = mysql_fetch_array($SQL_check))
	{
		$u_UID=$q_uid['id'];
	}

	$SQL_check = mysql_query("SELECT * FROM `accounts` WHERE `user`='".Secure($_POST['to'])."'");
	if(!mysql_num_rows($SQL_check))
	{
		echo("sorry, this user doesn't exist");
		return false;
	}

	$SQL_pm_check = mysql_query("SELECT `pm_ban` FROM `options` WHERE `id`='$u_UID'");
	while($i_data = mysql_fetch_array($SQL_pm_check))
	{
		if($i_data[0] == "1")
		{
			echo ("The member receiving this PM, does not allow Personal Messages");
		}
	}

	mysql_query("INSERT INTO `pm_inbox` (`userid`, `from`, `title`, `message`, `date`, `folder`, `stats`, `reported`) 
	VALUES 
	('".Secure($_POST['to'])."', '".$user_from."', '".Secure(Filter($_POST['subject']))."', '".Secure(Filter($_POST['message']))."', '$date', 'inbox', '0', '0')");
}
echo ("Message Sent");
}
return true;
?>

 

Mod edit : changed your PHP tags to CODE tags (Barand)

Link to comment
https://forums.phpfreaks.com/topic/39895-confusing-problems-personal-messages/
Share on other sites

Meaning where he had

 

 

<?php
    // some code
?>

 

I changed it to

 

<?php
    // some code
?>

 

 

so that it formatted correctly in a scrollable code window like this

 


<?php
    // some code
?>

 

instead of

 

 

<?php

    // some code

?>

 

What exactly is going wrong? Is it sending to one member and not the others? Not sending at all? Are you getting errors?

 

You may consider authorizing the member right from the start before you explode and get into the for each loops. Right now there are a lot of nested conditionals, so it is hard to tell where it is getting hung up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.