Location: PHPKode > projects > WH Community > wh_community/create_pm.php
<?php require('layout/header.php'); ?>

    <script type="text/javascript">
    	function insert(was) {
    	document.pm.message.value += was + " ";
    	document.pm.message.focus();
    	}
    </script>
    
    <script type="text/javascript">
    	function showSuccessMessage() {
    	showNotification({
    	type : "success",
    	message: "<?php echo $lang['success_pm']; ?>"
    	});    
        }
    </script>

<div id="content_wrapper">
    <div class="content"><?php

        if(!isset($_SESSION['signed_in'])) {
        
		echo '<p class="false">' . $lang['just_for_users'] . '!</p>
              <p>' . $lang['you_need_to'] . ' <a href="signin.php">' . $lang['signin_s'] . '</a>.
              - ' . $lang['not_yet'] . ' <a href="signup.php">' . $lang['registered'] . '</a>?</p>';

		}else{

		echo '<table align="center" class="usertable">
		<tr>
			<td align="center"><ul class="usermenu">
				<li><a href="myprofile.php">' . $lang['my_profile'] . '</a></li>
				<li><a href="guestbook.php">' . $lang['guestbook'] . '</a></li>
				<li><a href="messagebox.php">' . $lang['messagebox'] . '</a></li>
				<li><a href="password.php">' . $lang['password'] . '</a></li>
				<li><a href="inbox.php">' . $lang['inbox'] . '</a></li>
				<li><a href="outbox.php">' . $lang['outbox'] . '</a></li>
				<li><a href="create_pm.php">' . $lang['m_newpm'] . '</a></li>
				<li><a href="mypostings.php">' . $lang['my_posts'] . '</a></li>
				<li><a href="infos.php">' . $lang['informations'] . '</a></li>
				<li><a href="todo.php">' . $lang['m_todo'] . '</a></li>
				<li><a href="news.php">' . $lang['news'] . '</a></li>
			</ul></td>
		</tr>
		<tr>
			<td><h1>' . $lang['write_pm'] . '</h1></td>
		</tr>';
		
		echo '<tr><td>';
		
		$form = TRUE;
		$otitle = '';
		$orecip = '';
		$omessage = '';
		
		if(isset($_POST['title'], $_POST['recip'], $_POST['message'])) {
		
			$otitle = htmlentities($_POST['title']);
			$orecip = htmlentities($_POST['recip']);
			$omessage = htmlentities($_POST['message']);
		
		if($_POST['title']!='' AND $_POST['recip']!='' AND $_POST['message']!='') {
		
			$title = mysql_real_escape_string($otitle);
			$recip = mysql_real_escape_string($orecip);
			$message = mysql_real_escape_string($omessage);
		
		$sql = mysql_fetch_array(mysql_query("SELECT count(user_id) AS recip, user_id AS recipid, (select count(*) FROM messages) AS npm FROM users WHERE user_name='" . $recip . "'"));
		
		if($sql['recip']==1) {
		
		if($sql['recipid'] != (int)$_SESSION['user_id']) {
		
		$id = $sql['npm']+1;
		
		if(mysql_query("INSERT INTO messages (pm_id, pm_id2, title, user1, user2, message, timestamp, user1read, user2read)VALUES('" . $id . "', '1', '" . $title . "', '" . (int)$_SESSION['user_id'] . "', '" . $sql['recipid'] . "', '" . $message . "', '" . time() . "', 'yes', 'no')")) {
		
		echo '<p class="right">' . $lang['success_pm'] . '</p>
		      <p>[ <a href="inbox.php?user_id=' . (int)$_SESSION['user_id'] . '">' . $lang['inbox'] . '</a> | <a href="outbox.php?user_id=' . (int)$_SESSION['user_id'] . '">' . $lang['outbox'] . '</a> ]</p>';
		echo "<script type=\"text/javascript\">showSuccessMessage();</script>";
		
		$form = FALSE;
		
		}else{
		$error = '<p class="false">' . $lang['error_occurred'] . '.</p>';
		}
		
		}else{
		$error = '<p class="false">' . $lang['not_send_self'] . '.</p>';
		}
		
		}else{
		$error = '<p class="false">' . $lang['user_not_exists'] . '.</p>';
		}
		
		}else{
		$error = '<p class="false">' . $lang['not_filled_all'] . '.</p>';
		}
		
			}elseif(is_numeric($_GET['recip'])) {
			
			$orecip = htmlentities($_GET['recip']);
			$orecip = intval($_GET['recip']);
			}
		
		if($form) {
		if(isset($error)) {
		
		echo $error;
		}
		
		echo "<form action=\"create_pm.php\" method=\"post\" name=\"pm\">
    		  <input type=\"text\" value='" . htmlentities($otitle, ENT_QUOTES) . "' id=\"title\" name=\"title\" size=\"40\" class=\"fields\"> <strong>" . $lang['subject'] . "</strong><br><br>
    		  <input type=\"text\" value='" . htmlentities($orecip, ENT_QUOTES) . "' id=\"recip\" name=\"recip\" size=\"40\" class=\"fields\"> <strong>" . $lang['receiver'] . "</strong> <small>(User Name)</small><br><br>
    		  <strong>" . $lang['message'] . "</strong><br>
    		  <textarea cols=\"40\" rows=\"5\" id=\"message\" name=\"message\" class=\"fields_text\">" . htmlentities($omessage, ENT_QUOTES) . "</textarea>
    		  <input type=\"submit\" value=\"" . $lang['send'] . "\" class=\"button\">
    		  </form>";
    		  }
		}
		
		echo '<br></td></tr>
		      </table>';
		
		echo '<div class="spacer_div">&nbsp;</div>';

		?>
    </div>
</div>

<div id="infobox_wrapper">
    <div class="infobox">
        <?php include('layout/infobox.php'); ?>
    </div>
</div>

<?php require('layout/footer.php'); ?>
Return current item: WH Community