Page 1 of 1

Messaging problem

Posted: Tue Apr 17, 2012 11:04 am
by hassansherif
im new to php and i really have no idea how to do what i want to do, so hopefully you can help me :D

im doing a messaging system and i watch all your private messaging system tutorials but i need to do something different which was not in them.

basically i have users and conferences ... the users can be organizers or authors or reviewers but they are not represented in tables seperately; this means that there is only tables for conferences-users-privileges-messages

the priveleges table describes which user is a reviewer, author, or organizer.

as a conference organizer i should be able to choose the conference i want (via a dropdown list which ive already created) then when i choose the conference a list of all the reviewers and authors should be available infront of me.

then i should choose from these lists whomever i want to be added to the "To: " field in the message.

i wanted to show you part of the code but i honestly have no idea which part should i show you :D

sorry for including to much info about this but i need to finish that in 4 days and i cant find any hints on the internet to help with that part

Re: Messaging problem

Posted: Tue Apr 17, 2012 6:37 pm
by jacek
Okay, well it sounds like you pretty much want a private messaging system so I would start with that.

Then it sounds like you want to have some restrictions on who can talk to who ? If so you can add a few checks to the form checking to make sure the people in the to list are all part of the conference.

The other things like showing the list of users are just selecting stuff from the tables so the first page would show a list of conferences each linked to a second page with their ID in the URL that can then be used to show a list of users or even just put them in the to box.

I think the best way to go would be to start by getting the PM system from the videos working well and then try to think of the few changes that need to be made to get it to be the system you want.

Re: Messaging problem

Posted: Tue Apr 17, 2012 6:56 pm
by hassansherif
yeah i'lll start with the private system you did but im waiting on someone else building the database

thank you so much, when i start and i find there;s something else that i'll need to ask i'll ask you :D

Re: Messaging problem

Posted: Thu Apr 19, 2012 3:55 pm
by hassansherif
what you were doing in part01, the whole $core_path thing

im using netbeans and i dont know how i can do the same thing youre doing but in a different way

what should i do?? :?

Re: Messaging problem

Posted: Sun Apr 22, 2012 8:15 pm
by jacek
You should be able to do it :s It's just PHP code.

What is the problem exactly ?

Re: Messaging problem

Posted: Mon Apr 23, 2012 6:00 am
by hassansherif
i cant run the code as a whole

i have to run each php file on its own

when i run the index file or init file alone i get nothing

if i run the private_message.php i get
{
Notice: Undefined variable: _SESSION in C:\xampp\htdocs\MessagingSystem\private_message.inc.php on line 26

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\MessagingSystem\private_message.inc.php on line 37
}

and when i run the new_conversation page all the error checks work and if i eneter a valid username subject and body and click send i get
{
Notice: Undefined variable: usernames in C:\xampp\htdocs\MessagingSystem\new_conversation.page.inc.php on line 21

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\MessagingSystem\new_conversation.page.inc.php on line 21

Fatal error: Call to undefined function fetch_user_ids() in C:\xampp\htdocs\MessagingSystem\new_conversation.page.inc.php on line 26
}

i have no i dea what to do :S

you said in part 02 i guess that i can include each file manually in the init file instead of doing what you were doing, how can i do that??

Re: Messaging problem

Posted: Mon Apr 23, 2012 5:01 pm
by Temor
hassansherif wrote:you said in part 02 i guess that i can include each file manually in the init file instead of doing what you were doing, how can i do that??
include('folder/file.php');
Do that for each file you want to include.

If you want to, you can post your code here using
[syntax=php]
[/syntax]. We could take a look at it and give you some feedback.

Re: Messaging problem

Posted: Mon Apr 23, 2012 7:48 pm
by hassansherif
i guess that will work too but i decided to start a new simpler one
int this one i choose a conference (the list of choices include only the conferences the user is organizing) and his choice outputs a table that shows all the authors and the reviewers for this conference.

this list of authors and reviewers have checkboxes beside them and i have to select from them which ones i want to send a message to .... basically i got most of it covered but im having problems actually sending the message to these people

i copy pasted my code but if its hard to view just let me know if i can send it to someone's email to view it properly and help me out :D

i have 2 php file ... first one is where the users chooses a conference and the second is where the user chooses who recieves the message and another one that include the sending part

and again sorry for all the code i pasted :D

chooseconference.php
<?php
    $con=mysql_connect('localhost','root','');
    mysql_select_db('mydb');
    $sql = "SELECT conference_id, short_name FROM conference";
    $result = mysql_query($sql);
    $num_rows=mysql_num_rows($result);
    mysql_close($con);
?>

<form name="chooseconference" action="choosepeople.php" method="POST">
    Conference: <select name="conference">
        <?php
            for($i=0;$i<$num_rows;$i++)
            {
                $conference_id=mysql_result($result,$i,0);
                $short_name=mysql_result($result,$i,1);
                echo '<option value="'.$conference_id.'">'.$short_name.'</option>';
            }
        ?>        
    </select>
    </br>
    <input type="submit" value="submit" name="submit" />
</form>
choosepeople.php
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db('mydb');

//$confID = $_POST["conference"];
$confID = 1;
$query = "SELECT M.first_name, M.last_name, M.member_id
FROM Member M INNER JOIN member_privileges MP
ON M.member_id = MP.member_id
INNER JOIN privileges Pr
ON MP.privileges_id = Pr.privileges_id             
WHERE MP.conference_id = $confID 
AND Pr.role = 'author'";
echo '<form name="post" method="POST" action="viewmessages.php">';
$authors = mysql_query($query) or die(mysql_error());
 if (!$query) {echo "query error";}
if ($authors)
{   
    print "<table width=500 border=1>\n"; 
    print "<tr>\n";

    print "<th>  </th>\n"; 
    print "<th><width=\"0%\" height=\"0\" style=\"display:none\" value=\"Member ID\"</th>\n";
    print "<th> Author Name </th>\n";
     
    print "</tr>\n"; 
    //create table 
    $i = 0; 
    while ( $row = mysql_fetch_array($authors) ) { 
        $i++; 
        print "<tr>\n";
        print "<td><input type=\"checkbox\" name=\"authors[]\" value=\"$row[member_id]\"></td>\n";
        echo "<td><width=\"0%\" height=\"0\" style=\"display:none\" value=\"{$row['member_id']}\"</td>\n";
        echo "<td>{$row['first_name']} {$row['last_name']}</td>\n";
        
        echo "</tr>\n";
    }//end while    
print "</table>\n"; 

$reviewers = mysql_query("SELECT M.first_name, M.last_name, M.member_id
FROM Member M 
INNER JOIN member_privileges MP
ON M.member_id = MP.member_id
INNER JOIN privileges Pr
ON MP.privileges_id = Pr.privileges_id                
WHERE MP.conference_id = $confID
AND Pr.role = 'reviewer'") or die(mysql_error());

if ($reviewers)
{   
    print "<table width=500 border=1>\n"; 
    print "<tr>\n";

    print "<th>  </th>\n"; 
    print "<th><width=\"0%\" height=\"0\" style=\"display:none\" value=\"Member ID\"</th>\n";
    print "<th> Reviewer Name </th>\n";
     
    print "</tr>\n"; 
    //create table 
    $i = 0; 
    while ( $row = mysql_fetch_array($reviewers) ) { 
        $i++; 
        print "<tr>\n";
        print "<td><input type=\"checkbox\" name=\"reviewers[]\" value=\"$row[member_id]\"></td>\n";
        echo "<td><width=\"0%\" height=\"0\" style=\"display:none\" value=\"{$row['member_id']}\"</td>\n";
        echo "<td>{$row['first_name']} {$row['last_name']}</td>\n";
        
        echo "</tr>\n";
    }//end while    
print "</table>\n"; 
}
}
mysql_close($con);
?>  
    <div>
        <textarea name="body" rows="20" cols="110"><?php // if(isset($_POST['body']))echo htmlentities($_POST['body']); ?></textarea>
    </div>    
    <div>
        <input type="submit" value="Send" name="Send"/>
    </div>    
</form>
viewmessages.php (idk why named it that)
<?php   
$con=mysql_connect('localhost','root','');
if (!$con) {
    die ("con error");    
}
else
{
  $message=$_POST['body'];
  $x = $_POST['authors'];
  //$fulexp = implode(",", $x);
  //echo $fulexp;
  //$n = count($x);
  if( isset($x) && is_array($x))
  {
      $fulexp = implode(",", $x);
      foreach ($x as $item) 
      {
        $fulexp = implode(",", $x);
        $var = intval($item);    
        mysql_select_db('mydb');
        $re =  mysql_query("INSERT INTO member_message_member (member_id1, member_id2,conference_id, message)
                        VALUES (6, $var, 1,  $message)"); 
        ////the value 6 and 1 are defualt here no need to change now
        if (!$re) {echo "error";}
      }   
}
else {echo "didnot enter foreach";}
mysql_close($con);
}
?>

Re: Messaging problem

Posted: Tue Apr 24, 2012 9:33 pm
by jacek
print "<table width=500 border=1>\n";
:( :( :(