Jump to content

Sending messages to multiple users on a social networking site help !!


ukscotth

Recommended Posts

Hi,

 

I run a social networking site which uses the joovili script and i would like members to be able to send a message to more than one person at once, I guess the best way would be to seperate the usernames with a coma e.g in the 'send to' field the user would put something like fred,mary,bill,sue

 

Can someone plz help me code this as im new to php and cant work it out, at the moment this is the code that puts the message in the messages table :

 

mysql_query("INSERT INTO joovili_messages 
		  (message_to,message_from,message_subject,message_body,message_date) 
		  VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
		  '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");

 

Hope someone can help as I have to send a message out to 50 users and dont want to have to do it one by one :(

 

Thanks,

 

Scott

Link to comment
Share on other sites

ok thanks.

 

<?php
/***************************************************************************
*
*   Copyright © 2007 Joovili
*   -------------------------------------
*   Version: 2.1
*   -------------------------------------
*   www.joovili.com
*
****************************************************************************
*   Page: my_messages_new.php
***************************************************************************/

include("include/settings.inc.php");


/***************************************************************************
* USER LOGGED IN --->
***************************************************************************/

session_exists ($session_logged);


/***************************************************************************
* CHECK PRIVILEGES --->
***************************************************************************/

$messages_date = gmdate("jS M Y");

$check_sent_messages = sql_number("SELECT * FROM joovili_messages 
								  WHERE message_from='".$user_info['username']."' 
								  AND message_date LIKE '%".$messages_date."%'");

if (($user_info['account_type']==1 || $user_info['account_type']==3)&&($site_settings['joovili_upgrades']=='Yes')){

$total_messages = $site_privileges['u_messages'];

} else {

$total_messages = $site_privileges['f_messages'];

}


/***************************************************************************
* SEND MESSAGE --->
***************************************************************************/

if (isset($_POST['message_send'])){

## STOP THE SMART PEOPLE FROM SENDING MORE MESSAGES THAN THEY ARE ALLOWED
$check_sent_again = sql_number("SELECT * FROM joovili_messages WHERE 
message_from='".$user_info['username']."' AND message_date LIKE '%".$messages_date."%'");

if (1==1) {

## CHECK USER EXISTS AND IF BLOCKED
$check_user_exists = mysql_query("SELECT * FROM joovili_users 
							   WHERE username='".$_POST['message_to']."'");
							   
$check_blocked = mysql_query("SELECT * FROM joovili_block 
							   WHERE blocked='".$user_info['username']."' AND blocker='".$_POST['message_to']."'");								   

if (empty($_POST['message_to'])){

header ('Location: my_messages_new.php?action=error_empty&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}

else if (mysql_num_rows($check_blocked)!=0){

header ('Location: my_messages_new.php?action=error_blocked&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}


else if (mysql_num_rows($check_user_exists)==0){

header ('Location: my_messages_new.php?action=error_user&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}

else if (empty($_POST['message_subject'])){

header ('Location: my_messages_new.php?action=error_empty&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}

else if (empty($_POST['message_body'])){

header ('Location: my_messages_new.php?action=error_empty&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

} else {

mysql_query("INSERT INTO joovili_messages 
		  (message_to,message_from,message_subject,message_body,message_date) 
		  VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
		  '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");
		  
mysql_query("INSERT INTO message_history 
		  (message_to,message_from,message_subject,message_body,message_date) 
		  VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
		  '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");			  
		  
mysql_query("INSERT INTO joovili_messages_outbox 
		  (message_to,message_from,message_subject,message_body,message_date) 
		  VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
		  '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");	
		  
		  
#### START OF VIRTUAL GIFT CODE	

$rates = sql_row("SELECT * FROM joovili_earning_rates WHERE rate_set='standard'");		  		  
mysql_query("UPDATE joovili_users SET user_points=user_points+'".$rates['message_rate']."' WHERE username='".$user_info['username']."'");

### END OF VIRTUAL GIFT CODE

while($checked_user_exists = mysql_fetch_array($check_user_exists)){

if ($checked_user_exists['notify_messages']==1){

include("include/emails.inc.php");

mail($checked_user_exists['email'], $email_message_subject, $email_message, $headers);

}
}

header ('Location: my_messages.php?action=message_sent');

}
}
}

/***************************************************************************
* MESSAGES SUB MENU
***************************************************************************/
$sub_menu = '<a href="my_messages.php" class="sub_page_titles">
			 ' . $lang['messages_inbox'] . '</a> 
		 (' . user_info($user_info['username'], new_messages) . ') | 
		 <a href="my_outbox.php" class="sub_page_titles">
		 ' . $lang['messages_outbox'] . '</a> | 
		 <a href="my_notifications.php" class="sub_page_titles">
		 ' . $lang['messages_notifications'] . '</a> 
		 (' . user_info($user_info['username'], new_notifications) . ') | 
		 <a href="my_messages_new.php" class="sub_page_titles">
		 ' . $lang['messages_new']. '</a>';

/***************************************************************************
* INCLUDE HEADER
***************************************************************************/
include("themes/".$site_theme."/joovili_header.php");

?>

<table width="100%" border="0">
  <tr>
    <td width="50%"><table width="100%" border="0">
      <tr>
        <td class="page_titles"><?php echo $lang['messages_new_message'];?></td>
      </tr>
      <tr>
        <td height="20">
	<img src="themes/<?php echo $site_theme;?>/images/014.gif" width="100%" height="1" /></td>
      </tr>
  <tr>
        <td align="right" class="sub_page_titles"><?php echo $sub_menu; ?></td>
      </tr>
    </table>
<br />
<?php
		/*********************************************
		* ERROR! EMPTY FIELDS -->
		*********************************************/
		if ($_GET['action'] == 'error_empty') {
		?>
    <table width="100%" border="0" cellpadding="4" cellspacing="0" class="error_table">
      <tr>
        <td width="10%" align="center"><img src="themes/<?php echo $site_theme;?>/images/icons/017.gif" /></td>
        <td width="90%"><?php echo $lang['messages_send_error_empty'];?></td>
      </tr>
    </table>
    <br />
    <?php } ?>
    <?php

/*********************************************
		* ERROR! BLOCKED -->
		*********************************************/
		if ($_GET['action'] == 'error_blocked') {
		?>
    <table width="100%" border="0" cellpadding="4" cellspacing="0" class="error_table">
      <tr>
        <td width="10%" align="center"><img src="themes/<?php echo $site_theme;?>/images/icons/017.gif" /></td>
        <td width="90%"><?php echo "Sorry but this user has blocked you from contacting them";?></td>
      </tr>
    </table>
    <br />
    <?php } ?>
    <?php







		/*********************************************
		* ERROR! SEND TO DOES NOT EXIST -->
		*********************************************/
		if ($_GET['action'] == 'error_user') {
		?>
    <table width="100%" border="0" cellpadding="4" cellspacing="0" class="error_table">
      <tr>
        <td width="10%" align="center"><img src="themes/<?php echo $site_theme;?>/images/icons/017.gif" /></td>
        <td width="90%"><?php echo $lang['messages_send_error_exist'];?></td>
      </tr>
    </table>
    <br />
    <?php } ?>
    <?php
		if (1==3){
		?>
    <table width="100%" border="0" cellpadding="4" cellspacing="0" class="error_table">
      <tr>
        <td width="10%" align="center"><img src="themes/<?php echo $site_theme;?>/images/icons/017.gif" /></td>
        <td width="90%"><?php echo $lang['messages_send_limit'];?></td>
      </tr>
    </table>
    <br />
    <?php

		} else {

		echo "<form method=\"post\" action=\"my_messages_new.php\">";

		}
		?>
		<table width="100%" border="0" cellpadding="4" cellspacing="1" class="table">
              <tr>
                <td colspan="3" class="titles"><?php echo $lang['messages_new_message'];?></td>
              </tr>
              <tr>
                <td width="20%" class="text">To</td>
                <td width="75%" colspan="2"><input name="message_to" type="text" class="form_text_field" value="<?php if (isset($_GET['username'])){ echo $_GET['username']; } else { echo $_POST['message_to']; } ?>" maxlength="40" /></td>
              </tr>
              <tr>
                <td class="text">Subject</td>
                <td colspan="2"><input name="message_subject" type="text" class="form_text_field" value="<?php if ($_GET['subject']){ echo $_GET['subject']; } else { echo $_POST['message_subject']; }?>" maxlength="40" /></td>
              </tr>
              <tr>
                <td valign="top" class="text">Message</td>
                <td width="40%"><textarea name="message_body" id="message_body" rows="7" class="form_text_area" style="width: 100%;"><?php if ($_GET['message']){ echo $_GET['message']; } else { echo $_POST['message_body']; } ?></textarea></td>
                <td width="40%"><table border="0" align="center" cellpadding="2" cellspacing="1" class="smilies_table">
                  <tr>
                    <td width="5%"><img src="themes/<?php echo $site_theme;?>/images/smilies/001.gif" width="20" onclick="document.getElementById('message_body').value+=''" style="cursor: pointer; cursor: hand;" /></td>
                    <td width="20%"></td>
                    <td width="5%"><img src="themes/<?php echo $site_theme;?>/images/smilies/006.gif" width="20" onclick="document.getElementById('message_body').value+=':|'" style="cursor: pointer; cursor: hand;" /></td>
                    <td width="20%">:|</td>
                    <td width="5%"><img src="themes/<?php echo $site_theme;?>/images/smilies/011.gif" width="20" onclick="document.getElementById('message_body').value+=':roll:'" style="cursor: pointer; cursor: hand;" /></td>
                    <td width="20%">:roll:</td>
                    <td width="5%"><img src="themes/<?php echo $site_theme;?>/images/smilies/005.gif" width="20" onclick="document.getElementById('message_body').value+=':cool:'" style="cursor: pointer; cursor: hand;" /></td>
                    <td width="20%">:cool:</td>
                  </tr>
                  <tr>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/002.gif" width="20" onclick="document.getElementById('message_body').value+=''" style="cursor: pointer; cursor: hand;" /></td>
                    <td></td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/007.gif" width="20" onclick="document.getElementById('message_body').value+=':S'" style="cursor: pointer; cursor: hand;" /></td>
                    <td>:S</td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/012.gif" width="20" onclick="document.getElementById('message_body').value+=':oO:'" style="cursor: pointer; cursor: hand;" /></td>
                    <td>:oO:</td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/010.gif" width="20" onclick="document.getElementById('message_body').value+=':oo:'" style="cursor: pointer; cursor: hand;" /></td>
                    <td>:oo:</td>
                  </tr>
                  <tr>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/003.gif" width="20" onclick="document.getElementById('message_body').value+=':A'" style="cursor: pointer; cursor: hand;" /></td>
                    <td>:A</td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/008.gif" width="20" onclick="document.getElementById('message_body').value+=''" style="cursor: pointer; cursor: hand;" /></td>
                    <td></td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/013.gif" width="20" onclick="document.getElementById('message_body').value+=':Y'" style="cursor: pointer; cursor: hand;" /></td>
                    <td>:Y</td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/015.gif" width="20" onclick="document.getElementById('message_body').value+=''" style="cursor: pointer; cursor: hand;" /></td>
                    <td></td>
                  </tr>
                  <tr>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/004.gif" width="20" onclick="document.getElementById('message_body').value+=''" style="cursor: pointer; cursor: hand;" /></td>
                    <td></td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/009.gif" width="20" onclick="document.getElementById('message_body').value+=''" style="cursor: pointer; cursor: hand;" /></td>
                    <td></td>
                    <td><img src="themes/<?php echo $site_theme;?>/images/smilies/014.gif" width="20" onclick="document.getElementById('message_body').value+=':W'" style="cursor: pointer; cursor: hand;" /></td>
                    <td>:W</td>
                    <td> </td>
                    <td> </td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td> </td>
                <td colspan="2"><input name="message_send" type="submit" class="form_button" value="<?php echo $lang['messages_button'];?>" /></td>
              </tr>
            </table>
		</form>
		</td>
  </tr>
</table>
  <div align="center"><a href="http://www.sound-light-company.co.uk" target="_blank"><img src="Adverts/slc.gif" width="510" height="100" border="0" /></a></div>
<?php include("themes/".$site_theme."/joovili_footer.php");?>

Link to comment
Share on other sites

ok,  change this section of code;

 

} else {

mysql_query("INSERT INTO joovili_messages 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");
           
mysql_query("INSERT INTO message_history 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");           
           
mysql_query("INSERT INTO joovili_messages_outbox 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$_POST['message_to']."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");   
           
           
#### START OF VIRTUAL GIFT CODE 

 

to this;

 

} else {

$to = $_POST['message_to'];
$to_users = explode(";", $to);

for($i=0;$i<count($to_users);$i++){


mysql_query("INSERT INTO joovili_messages 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$to_users[$i]."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");
           
mysql_query("INSERT INTO message_history 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$to_users[$i]."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");           
           
mysql_query("INSERT INTO joovili_messages_outbox 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$to_users[$i]."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");   
}
           
#### START OF VIRTUAL GIFT CODE 

Link to comment
Share on other sites

<?php
## CHECK USER EXISTS AND IF BLOCKED


$to = $_POST['message_to'];
$to_users = explode(";", $to);

for($i=0;$i<count($to_users);$i++){


$check_user_exists = mysql_query("SELECT * FROM joovili_users 
                           WHERE username='".$to_users[$i]."'");
                           
$check_blocked = mysql_query("SELECT * FROM joovili_block 
                           WHERE blocked='".$user_info['username']."' AND blocker='".$to_users[$i]."'");                           

if (empty($_POST['message_to'])){

header ('Location: my_messages_new.php?action=error_empty&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}

else if (mysql_num_rows($check_blocked)!=0){

header ('Location: my_messages_new.php?action=error_blocked&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}


else if (mysql_num_rows($check_user_exists)==0){

header ('Location: my_messages_new.php?action=error_user&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}

else if (empty($_POST['message_subject'])){

header ('Location: my_messages_new.php?action=error_empty&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

}

else if (empty($_POST['message_body'])){

header ('Location: my_messages_new.php?action=error_empty&username='.$_POST['message_to'].'&subject='.$_POST['message_subject'].'&message='.$_POST['message_body']);

} else {

mysql_query("INSERT INTO joovili_messages 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$to_users[$i]."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");
           
mysql_query("INSERT INTO message_history 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$to_users[$i]."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");           
           
mysql_query("INSERT INTO joovili_messages_outbox 
           (message_to,message_from,message_subject,message_body,message_date) 
           VALUES ('".$to_users[$i]."', '".$user_info['username']."', 
           '".$_POST['message_subject']."', '".$_POST['message_body']."', '".date_time(normal)."')");   
           
}

#### START OF VIRTUAL GIFT CODE  
?>

 

try that one

Link to comment
Share on other sites

Thanks so much for your help. Ive just upgraded to the latest version of joovili and theyve changed the code for the messages  :( :( :( :(

 

any chance you could help me on this file, ive tried myself by copying what you did but for some reason it wont work  ??? ???

 

## SEND NEW MESSAGE

function send_message() {

global $lang, $message_count, $max_messages, $session_logged;

if ($session_logged == 'true') { if ($message_count <= $max_messages) {

	$to = $_POST['to'];
$to_users = explode(";", $to);

for($i=0;$i<count($to_users);$i++){

$userexists = sql_query("SELECT * FROM joovili_users WHERE username = '".$to_users[$i]."' LIMIT 1");

$blockexists = sql_query("SELECT * FROM joovili_blocked WHERE block_username = '".$to_users[$i]."' 
AND block_who = '".$_COOKIE['session_username']."'");

if (mysql_num_rows($userexists) == 0 ) {

return message_status('error', $lang['messages_error_uexists']);

} else if (mysql_num_rows($blockexists) != 0 ) {

return message_status('error', $lang['messages_error_ublock']);

} else if ($_POST['to'] == $_COOKIE['session_username']) {

return message_status('error', $lang['messages_error_uself']);

} else if (empty($_POST['subject'])) {

return message_status('error', $lang['messages_error_esubject']);

} else if (empty($_POST['message'])) {

return message_status('error', $lang['messages_error_emessage']);

} else {

sql_query("INSERT INTO joovili_messages (message_to, message_from, message_subject, message_body, message_date) 
VALUES ('".$to_users[$i]."', '".$_COOKIE['session_username']."', '".$_POST['subject']."', '".$_POST['message']."', 
'".date_time('datetime')."')");

$user = mysql_fetch_array($userexists);

if ($user['notify_messages'] == '1') {

include("language/".SITELANG."/joovili_emails.php");

mail($user['email'], $message_subject, $message_email.$footers, $headers);

} }

return message_status('done', $lang['messages_sending']);

} } } } 

 

Original code before i messed with it

 

## SEND NEW MESSAGE

function send_message() {

global $lang, $message_count, $max_messages, $session_logged;

if ($session_logged == 'true') { if ($message_count <= $max_messages) {

$userexists = sql_query("SELECT * FROM joovili_users WHERE username = '".$_POST['to']."' LIMIT 1");

$blockexists = sql_query("SELECT * FROM joovili_blocked WHERE block_username = '".$_POST['to']."' 
AND block_who = '".$_COOKIE['session_username']."'");

if (mysql_num_rows($userexists) == 0 ) {

return message_status('error', $lang['messages_error_uexists']);

} else if (mysql_num_rows($blockexists) != 0 ) {

return message_status('error', $lang['messages_error_ublock']);

} else if ($_POST['to'] == $_COOKIE['session_username']) {

return message_status('error', $lang['messages_error_uself']);

} else if (empty($_POST['subject'])) {

return message_status('error', $lang['messages_error_esubject']);

} else if (empty($_POST['message'])) {

return message_status('error', $lang['messages_error_emessage']);

} else {

sql_query("INSERT INTO joovili_messages (message_to, message_from, message_subject, message_body, message_date) 
VALUES ('".$_POST['to']."', '".$_COOKIE['session_username']."', '".$_POST['subject']."', '".$_POST['message']."', 
'".date_time('datetime')."')");

$user = mysql_fetch_array($userexists);

if ($user['notify_messages'] == '1') {

include("language/".SITELANG."/joovili_emails.php");

mail($user['email'], $message_subject, $message_email.$footers, $headers);

}

return message_status('done', $lang['messages_sending']);

} } } }

Link to comment
Share on other sites

I presume its done in this file :

 

<?php
/***************************************************************************
*
*   Copyright © 2007 Joovili
*   -------------------------------------
*   Version: 3.0
*   -------------------------------------
*   www.joovili.com
*
****************************************************************************
*   Page: messages.php
***************************************************************************/

include("include/joovili.settings.php");

session_exists($session_logged);
sent_messages_access($_SERVER['QUERY_STRING']);

include("include/joovili.javascript.php");
include("modules/messages.functions.php");
include("modules/block.functions.php");

if (isset($_POST['delete_inbox'])) { $do_update = delete_inbox(); }
if (isset($_POST['delete_sent'])) { $do_update = delete_sent(); }
if (isset($_POST['delete_notifications'])) { $do_update = delete_notifications(); }
if (isset($_POST['delete_inbox_message'])) { $do_update = delete_inbox_message(); }
if (isset($_POST['delete_sent_message'])) { $do_update = delete_sent_message(); }
if (isset($_POST['delete_notification_message'])) { $do_update = delete_notification_message(); }
if (isset($_POST['send_message'])) { $do_update = send_message(); }

?>

<?php include_once("themes/".SITETHEME."/joovili.header.php"); ?>
      
  <table width="100%" border="0" cellpadding="4">
        <tr>
          <td width="25%" valign="top">
	  <table width="100%" border="0" cellpadding="6" cellspacing="2" class="table_1_css">
            <tr>
              <td class="quick_menu"><a href="messages.php?do=inbox" class="quick_menu">
		  <?php echo $lang['messages_inbox'];?> (<?php echo message_stats('inbox_total');?>)</a></td>
            </tr>
            <tr>
              <td class="quick_menu"><a href="messages.php?do=sent" class="quick_menu">
		  <?php echo $lang['messages_sent'];?> (<?php echo message_stats('sent_total');?>)</a></td>
            </tr>
            <tr>
              <td class="quick_menu"><a href="messages.php?do=notifications" class="quick_menu">
		  <?php echo $lang['messages_notifications'];?> (<?php echo message_stats('notifications_total'); ?>)</a></td>
            </tr>
            <tr>
              <td class="quick_menu"><a href="blocked.php" class="quick_menu">
		  <?php echo $lang['block'];?> (<?php echo block_stats('block_total');?>)</a></td>
            </tr>
            <tr>
              <td class="quick_menu"><a href="messages.php?do=new" class="quick_menu"><?php echo $lang['messages_new'];?></a></td>
            </tr>
          </table></td>
          <td width="75%">
	   <table width="100%" border="0" cellpadding="4">
            <tr>
              <td class="text_1_css"><?php echo $lang['menu_user_messages'];?></td>
            </tr>
          </table>
	  <?php echo $do_update . message_reach('message');?>
	  <br />
	  <?php if ($_GET['do'] == 'inbox') { ?>
	  <table width="100%" border="0" class="table_1_css">
            <tr>
              <td class="text_5_css"><?php echo $lang['messages_inbox'];?></td>
            </tr>
          </table>
	  <form method="post" action="messages.php?do=inbox">
	  <table width="100%" border="0" cellpadding="4" cellspacing="2" class="text_2_css">
	  <?php
	  
	  $fetch_all_messages = sql_query("SELECT * FROM joovili_messages 
	  WHERE message_to = '".$_COOKIE['session_username']."' AND message_deleted = '0'");
	  
	  if (mysql_num_rows($fetch_all_messages) == 0) {
	  
	  ?>
	  <tr>
	    <td colspan="5"><?php echo $lang['messages_inbox_empty'];?></td>
	  </tr>
	  <?php
	  
	  }
	  
	  $fetch_new_messages = sql_query("SELECT * FROM joovili_messages WHERE message_to = '".$_COOKIE['session_username']."' 
	  AND message_status = '0' AND message_deleted = '0' ORDER BY message_id DESC");
	  
	  while ($new_messages = mysql_fetch_array($fetch_new_messages)) {
	  
	  ?>
            <tr>
              <td width="1%"><img src="themes/<?php echo SITETHEME;?>/images/icons/016.gif" /></td>
              <td><a href="messages.read.php?do=inbox&id=<?php echo $new_messages['message_id'];?>" class="text_2_css">
		  <?php echo $new_messages['message_subject'];?></a></td>
              <td><?php echo $new_messages['message_from'];?></td>
              <td width="30%"><?php echo $new_messages['message_date'];?></td>
              <td width="1%"><input type="checkbox" name="del[]" value="<?php echo $new_messages['message_id'];?>" /></td>
            </tr>
          <?php
	  
	  }
	  
	  if (!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; }
	  
	  $results = '10';
	  
	  $from = (($page * $results) - $results);
	  
	  $fetch_old_messages = sql_query("SELECT * FROM joovili_messages 
	  WHERE message_to = '".$_COOKIE['session_username']."' AND message_status = '1' AND message_deleted = '0' 
	  ORDER BY message_id DESC LIMIT $from, $results");
	  
	  while ($old_messages = mysql_fetch_array($fetch_old_messages)) {
	  
	  ?>
            <tr>
              <td width="1%"><img src="themes/<?php echo SITETHEME;?>/images/icons/017.gif" /></td>
              <td><a href="messages.read.php?do=inbox&id=<?php echo $old_messages['message_id'];?>" class="text_2_css">
		  <?php echo $old_messages['message_subject'];?></a></td>
              <td><?php echo $old_messages['message_from'];?></td>
              <td width="30%"><?php echo $old_messages['message_date'];?></td>
              <td width="1%"><input type="checkbox" name="del[]" value="<?php echo $old_messages['message_id'];?>" /></td>
            </tr>
            <?php } ?>
          </table>
	  <br />
	  <table width="100%" border="0">
            <tr>
              <td colspan="3" class="divider"> </td>
            </tr>
            <tr>
              <td class="pagination_text">
		  <?php
		  
		  ## INBOX PAGINATION
		  
		  define('pagination_max_link',10);
		  
		  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM joovili_messages 
		  WHERE message_to = '".$_COOKIE['session_username']."' AND message_status='1' AND message_deleted = '0'"),0);
		  
		  $total_pages = ceil($total_results / $results);
		  
		  if($page > 1)
		  echo '<a href="'.$_SERVER['PHP_SELF'].'?do=inbox&page='.($page-1).'" class="pagination_text">
		  '.$lang['common_previous'].'</a>   ';
		  
		  $start = floor($page/pagination_max_link)*pagination_max_link;
		  $end = ($start+pagination_max_link>$total_pages) ? $total_pages : $start+
		  pagination_max_link;
		  
		  for($i = $start+1; $i <= $end; $i++)
		  echo ($page) == $i	?	'<font color="#000000">'.$i.'</font> '  : 
		  '<a href="'.$_SERVER['PHP_SELF'].'?do=inbox&page='.$i.'" class="pagination_text">'.$i.'</a> ';
		  
		  if($page < $total_pages)
		  echo '   <a href="'.$_SERVER['PHP_SELF'].'?do=inbox&page='.($page+1).'" 
		  class="pagination_text">'.$lang['common_next'].'</a>';
		  
		  ?></td>
              <td width="1%"><input type="button" class="form_button" onClick="this.value=check(this.form)" value="<?php echo $lang['common_check'];?>" /></td>
              <td width="1%"><input name="delete_inbox" type="submit" class="form_button" value="<?php echo $lang['messages_delete'];?>" /></td>
            </tr>
          </table>
	  </form>
	  <?php } else if ($_GET['do'] == 'sent') { ?>
	  <table width="100%" border="0" class="table_1_css">
            <tr>
              <td class="text_5_css"><?php echo $lang['messages_sent'];?></td>
            </tr>
          </table>
	  <form method="post" action="messages.php?do=sent">
	  <table width="100%" border="0" cellpadding="4" cellspacing="2" class="text_2_css">
	  <?php
	  
	  if (!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; }
	  
	  $results = '10';
	  
	  $from = (($page * $results) - $results);
	  
	  $fetch_sent_messages = sql_query("SELECT * FROM joovili_messages 
	  WHERE message_from = '".$_COOKIE['session_username']."' AND message_deleted_sent = '0' 
	  ORDER BY message_id DESC LIMIT $from, $results");
	  
	  if (mysql_num_rows($fetch_sent_messages) == 0) {
	  
	  ?>
	    <tr>
              <td colspan="5"><?php echo $lang['messages_sent_empty'];?></td>
            </tr>
	  <?php } else { while ($sent_messages = mysql_fetch_array($fetch_sent_messages)) { ?>
            <tr>
              <td width="1%"><img src="themes/<?php echo SITETHEME;?>/images/icons/018.gif" /></td>
              <td><a href="messages.read.php?do=sent&id=<?php echo $sent_messages['message_id'];?>" class="text_2_css">
		  <?php echo $sent_messages['message_subject'];?></a></td>
              <td><?php echo $sent_messages['message_to'];?></td>
              <td width="30%"><?php echo $sent_messages['message_date'];?></td>
              <td width="1%"><input type="checkbox" name="del[]" value="<?php echo $sent_messages['message_id'];?>" /></td>
            </tr>
            <?php } } ?>
          </table>
	  <br />
	  <table width="100%" border="0">
            <tr>
              <td colspan="3" class="divider"> </td>
            </tr>
            <tr>
              <td class="pagination_text">
		  <?php
		  
		  ## SENT PAGINATION
		  
		  define('pagination_max_link',10);
		  
		  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM joovili_messages 
		  WHERE message_from = '".$_COOKIE['session_username']."' AND message_deleted_sent = '0'"),0);
		  
		  $total_pages = ceil($total_results / $results);
		  
		  if($page > 1)
		  echo '<a href="'.$_SERVER['PHP_SELF'].'?do=sent&page='.($page-1).'" class="pagination_text">
		  '.$lang['common_previous'].'</a>   ';
		  
		  $start = floor($page/pagination_max_link)*pagination_max_link;
		  $end = ($start+pagination_max_link>$total_pages) ? $total_pages : $start+
		  pagination_max_link;
		  
		  for($i = $start+1; $i <= $end; $i++)
		  echo ($page) == $i	?	'<font color="#000000">'.$i.'</font> '  : 
		  '<a href="'.$_SERVER['PHP_SELF'].'?do=sent&page='.$i.'" class="pagination_text">'.$i.'</a> ';
		  
		  if($page < $total_pages)
		  echo '   <a href="'.$_SERVER['PHP_SELF'].'?do=sent&page='.($page+1).'" 
		  class="pagination_text">'.$lang['common_next'].'</a>';
		  
		  ?></td>
              <td width="1%"><input type="button" class="form_button" onClick="this.value=check(this.form)" value="<?php echo $lang['common_check'];?>" /></td>
              <td width="1%"><input name="delete_sent" type="submit" class="form_button" value="<?php echo $lang['messages_delete'];?>" /></td>
            </tr>
          </table>
	  </form>
	  <?php } else if ($_GET['do'] == 'notifications') { ?>
	  <br />
	  <table width="100%" border="0" class="table_1_css">
            <tr>
              <td class="text_5_css"><?php echo $lang['messages_notifications'];?></td>
            </tr>
          </table>
	  <form method="post" action="messages.php?do=notifications">
	  <table width="100%" border="0" cellpadding="4" cellspacing="2" class="text_2_css">
	  <?php
	  
	  $fetch_all_notifications = sql_query("SELECT * FROM joovili_notifications 
	  WHERE notification_to = '".$_COOKIE['session_username']."'");
	  
	  if (mysql_num_rows($fetch_all_notifications) == 0) {
	  
	  ?>
	  <tr>
	    <td colspan="5"><?php echo $lang['messages_notifications_empty'];?></td>
	  </tr>
	  <?php
	  
	  }
	  
	  $fetch_new_notifications = sql_query("SELECT * FROM joovili_notifications 
	  WHERE notification_to = '".$_COOKIE['session_username']."' AND notification_status = '0'");
	  
	  while ($new_notifications = mysql_fetch_array($fetch_new_notifications)) {
	  
	  ?>
            <tr>
              <td width="1%"><img src="themes/<?php echo SITETHEME;?>/images/icons/019.gif" /></td>
              <td>
		  <a href="messages.read.php?do=notification&id=<?php echo $new_notifications['notification_id'];?>" class="text_2_css">
		  <?php echo $new_notifications['notification_subject'];?></a></td>
              <td><?php echo $new_notifications['notification_from'];?></td>
              <td width="30%"><?php echo $new_notifications['notification_date'];?></td>
              <td width="1%"><input type="checkbox" name="del[]" value="<?php echo $new_notifications['notification_id'];?>" /></td>
            </tr>
          <?php
	  
	  }
	  
	  if (!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; }
	  
	  $results = '10';
	  
	  $from = (($page * $results) - $results);
	  
	  $fetch_old_notifications = sql_query("SELECT * FROM joovili_notifications 
	  WHERE notification_to = '".$_COOKIE['session_username']."' AND notification_status = '1' 
	  ORDER BY notification_id DESC LIMIT $from, $results");
	  
	  while ($old_notifications = mysql_fetch_array($fetch_old_notifications)) {
	  
	  ?>
            <tr>
              <td width="1%"><img src="themes/<?php echo SITETHEME;?>/images/icons/020.gif" /></td>
              <td>
		  <a href="messages.read.php?do=notification&id=<?php echo $old_notifications['notification_id'];?>" class="text_2_css">
		  <?php echo $old_notifications['notification_subject'];?></a></td>
              <td><?php echo $old_notifications['notification_from'];?></td>
              <td width="30%"><?php echo $old_notifications['notification_date'];?></td>
              <td width="1%"><input type="checkbox" name="del[]" value="<?php echo $old_notifications['notification_id'];?>" /></td>
            </tr>
            <?php } ?>
          </table>
	  <br />
	  <table width="100%" border="0">
            <tr>
              <td colspan="3" class="divider"> </td>
            </tr>
            <tr>
              <td class="pagination_text">
		  <?php
		  
		  ## NOTIFICATIONS PAGINATION
		  
		  define('pagination_max_link',10);
		  
		  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM joovili_notifications 
		  WHERE notification_to = '".$_COOKIE['session_username']."' AND notification_status='1'"),0);
		  
		  $total_pages = ceil($total_results / $results);
		  
		  if($page > 1)
		  echo '<a href="'.$_SERVER['PHP_SELF'].'?do=notifications&page='.($page-1).'" class="pagination_text">
		  '.$lang['common_previous'].'</a>   ';
		  
		  $start = floor($page/pagination_max_link)*pagination_max_link;
		  $end = ($start+pagination_max_link>$total_pages) ? $total_pages : $start+
		  pagination_max_link;
		  
		  for($i = $start+1; $i <= $end; $i++)
		  echo ($page) == $i	?	'<font color="#000000">'.$i.'</font> '  : 
		  '<a href="'.$_SERVER['PHP_SELF'].'?do=notifications&page='.$i.'" class="pagination_text">'.$i.'</a> ';
		  
		  if($page < $total_pages)
		  echo '   <a href="'.$_SERVER['PHP_SELF'].'?do=notifications&page='.($page+1).'" 
		  class="pagination_text">'.$lang['common_next'].'</a>';
		  
		  ?></td>
              <td width="1%"><input type="button" class="form_button" onClick="this.value=check(this.form)" value="<?php echo $lang['common_check'];?>" /></td>
              <td width="1%"><input name="delete_notifications" type="submit" class="form_button" value="<?php echo $lang['messages_delete'];?>" /></td>
            </tr>
          </table>
	  </form>
	  <?php } else if ($_GET['do'] == 'new') { ?>
	  <table width="100%" border="0" class="table_1_css">
            <tr>
              <td class="text_5_css"><?php echo $lang['messages_new'];?></td>
            </tr>
          </table>
	  <?php echo message_reach('form');?>
	  <table width="100%" border="0" cellpadding="4" cellspacing="2" class="text_2_css">
	  <tr>
	    <td width="50%"><?php echo $lang['messages_to'];?></td>
	    <td width="50%"><?php echo $lang['messages_subject'];?></td>
	  </tr>
            <tr>
              <td>
		  <input name="to" type="text" class="form_field" style="width:100%;" maxlength="40" value="<?php if ($_GET['to']) { echo $_GET['to']; } else { echo $_POST['to']; } ?>" />			  </td>
              <td>
		  <input name="subject" type="text" class="form_field" style="width:100%;" maxlength="40" value="<?php if ($_GET['sub']) { echo $_GET['sub']; } else { echo $_POST['subject']; } ?>" /></td>
            </tr>
            <tr>
              <td colspan="2"><?php echo $lang['messages_message'];?></td>
            </tr>
            <tr>
              <td><textarea id="message" name="message" rows="10" class="form_textarea" style="width:99%;"><?php echo $_POST['message'];?></textarea></td>
              <td><?php echo display_smilies('message', '3');?></td>
            </tr>
            <tr>
              <td colspan="2">
		  <input name="send_message" type="submit" class="form_button" value="<?php echo $lang['messages_send'];?>" /></td>
            </tr>
          </table>
	  <br />
	  <table width="100%" border="0">
            <tr>
              <td colspan="3" class="divider"> </td>
            </tr>
          </table>
	  </form>
	  <?php } ?>
	  </td>
        </tr>
      </table>
      <?php include_once("themes/".SITETHEME."/joovili.footer.php");?>

 

thanks again for ur help with this, ur a star :)

Link to comment
Share on other sites

Sorry buddy, but from what I can see there's no way of simply adding code in this version for this to work perfectly. This code stops running if there's a problem with the user rather than trying to send and logging the error for after, so if you tried to send a message to 5 users and there was a problem with the third, only the first ans second user would get the message.

 

The only solution is to re-write the function fully (do joovili) let you do this?

Link to comment
Share on other sites

hey, i think this could work for you.

 

It's the best I can get it really.

 

<?php
## SEND NEW MESSAGE

function send_message(){
global $lang,$message_count,$max_messages,$session_logged;


$message_to_full = $_POST['to'];
$to_individuals = explode(";", $message_to_full);
for($i=0;$i<count($to_individuals);$i++){
	if($session_logged == 'true'){
		if($message_count <= $max_messages){
			$userexists = sql_query("SELECT * FROM joovili_users WHERE username = '".$to_individuals[$i]."' LIMIT 1");
			$blockexists = sql_query("SELECT * FROM joovili_blocked WHERE block_username = '".$to_individuals[$i]."'
			AND block_who = '".$_COOKIE['session_username']."'");
			if(mysql_num_rows($userexists) == 0) return message_status('error', $lang['messages_error_uexists']);
			elseif(mysql_num_rows($blockexists) != 0 ) return message_status('error', $lang['messages_error_ublock']);
			elseif($_POST['to'] == $_COOKIE['session_username']) return message_status('error', $lang['messages_error_uself']);
			elseif(empty($_POST['subject'])) return message_status('error', $lang['messages_error_esubject']);
			elseif(empty($_POST['message'])) return message_status('error', $lang['messages_error_emessage']);
			else {
				sql_query("INSERT INTO joovili_messages (message_to, message_from, message_subject, message_body, message_date)
				VALUES ('".$to_individuals[$i]."', '".$_COOKIE['session_username']."', '".$_POST['subject']."', '".$_POST['message']."',
				'".date_time('datetime')."')");
				$user = mysql_fetch_array($userexists);
				if($user['notify_messages'] == '1'){
					include("language/".SITELANG."/joovili_emails.php");
					mail($user['email'], $message_subject, $message_email.$footers, $headers);
				}
			}
			$message_count++;
		}
	}
}
return message_status('done', $lang['messages_sending']);
}

 

If a user is blocked or doesn't exist the script will stop, apart from that it should keep running unless you run out of allowed sent messages

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.