Advertisement
michaelyuen

Untitled

Jan 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.61 KB | None | 0 0
  1. <?php include_once('include/sys.inc.php'); ?>
  2. <?php
  3. require('Pusher.php');
  4.  
  5. $app_id = 'xxxxxxx';
  6. $app_key = 'xxxxxx';
  7. $app_secret = 'xxxxxxxxx';
  8.  
  9. $pusher = new Pusher($app_key, $app_secret, $app_id);
  10.  
  11. if (ISSET($_POST['user'])) {
  12.     $_SESSION['msg']['msg_user_id'] = $_POST['user'];
  13.     $msg_hide_id = $_POST['user'];
  14. }
  15.    
  16. if (ISSET($_POST['submit_message']) && !EMPTY($_POST['message'])) {
  17.     if (EMPTY($_POST['from_id']) && EMPTY($_POST['to_id'])) {
  18.         $error = 'No Sender Selected';
  19.     } else {
  20.         if (ISSET($_POST['from_id'])) {
  21.         $from_id = $_POST['from_id'];
  22.         } else {
  23.         $from_id = NULL;
  24.         }
  25.         if (ISSET($_POST['to_id'])) {
  26.         $to_id = $_POST['to_id'];
  27.         } else {
  28.         $to_id = NULL;
  29.         }
  30.         $message = str_replace('<br />', PHP_EOL, $_POST['message']);
  31.         $message = htmlentities('<p>'.$_POST['message'].'</p>');
  32.    
  33.     $sql="INSERT INTO `messaging` (`from_id`, `to_id`, `message`)
  34.     VALUES
  35.     ('$from_id', '$to_id', '$message')";
  36.     if (!mysqli_query($con, $sql))
  37.         {
  38.         die('Error: ' . mysqli_error($con));
  39.         }
  40.  
  41.     $data['message'] = '<a href="messaging.php"><div class="yes_msg"></div></a>';
  42.     $data['userid'] = $to_id;
  43.     $pusher->trigger('gsm_channel', 'gms_chat', $data);
  44.     }
  45. }
  46. ?>
  47. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
  48. <html xmlns="http://www.w3.org/1999/xhtml">
  49.   <head>
  50.     <meta charset="utf-8">
  51.     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  52.     <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
  53.     <meta name="viewport" content="width=1080" />
  54.     <meta name="description" content="">
  55.     <meta name="author" content="">
  56.     <link href="css/style.css?v=<?php echo filemtime("css/style.css"); ?>" rel="stylesheet">
  57.     <link rel="stylesheet" href="css/jquery-ui.css">
  58.     <script src="js/jquery.min.js"></script>
  59.     <script src="//js.pusher.com/2.2/pusher.min.js" type="text/javascript"></script>
  60.     <script src="js/jquery.autosize.min.js"</script>
  61.     <script type="text/javascript">
  62.     $(document).ready(function(){
  63.  
  64.             //Check if the current URL contains '#'
  65.             if(document.URL.indexOf("#")==-1)
  66.             {
  67.                     // Set the URL to whatever it was plus "#".
  68.                     url = document.URL+"#";
  69.                     location = "#";
  70.  
  71.                     //Reload the page
  72.                     location.reload(true);
  73.  
  74.             }
  75.     });
  76.     </script>
  77.     <script>
  78.             $(function(){
  79.                 $('.normal').autosize();
  80.                 $('.animated').autosize();
  81.             });
  82.         </script>
  83.     <title>Project Detail</title>
  84.     </head>
  85. <body>
  86. <audio id="audiotag1" src="http://domain.com/ding.wav" preload="auto"></audio>
  87. <?php
  88. if (ISSET($error)) {
  89.     echo $error;
  90. }
  91.  
  92. if (ISSET($_POST['msg_reload_time'])) {
  93.     $_SESSION['msg']['reload_time'] = $_POST['msg_reload_time'];
  94. } else {
  95.     $_SESSION['msg']['reload_time'] = '60';
  96. }
  97.  
  98. if (ISSET($_POST['msg_user_id'])) {
  99.     $_SESSION['msg']['msg_user_id'] = $_POST['msg_user_id'];
  100. } else if ($_SESSION['user']['usergroup'] != 'admin') {
  101.     $_SESSION['msg']['msg_user_id'] = $_SESSION['user']['id'];
  102. } else {}
  103. ?>
  104. <?php include('headbanner.inc.php'); ?>
  105. <div class="wrapper">
  106. <iframe id="chat" src="messages.php#end"  scrolling="yes" style="width: 100%; border: none; height: 400px; margin: 25px 0 25px 0; padding: 0;"></iframe>
  107. <?php /*
  108. <form style="float: right;" action="" method="POST" id="msg_reload" onchange='document.getElementById("msg_reload").submit();'>
  109.     Message Reload Time: <select name="msg_reload_time">
  110.         <option value="10" <?php if ($_SESSION['msg']['reload_time'] == 10) { echo "selected"; } ?>>10 seconds</option>
  111.         <option value="60" <?php if ($_SESSION['msg']['reload_time'] == 60) { echo "selected"; } ?>>60 seconds</option>
  112.         <option value="120" <?php if ($_SESSION['msg']['reload_time'] == 120) { echo "selected"; } ?>>2 minutes</option>
  113.         <option value="999999" <?php if ($_SESSION['msg']['reload_time'] == 999999) { echo "selected"; } ?>>Stop</option>
  114.     </select>
  115. </form>
  116. */ ?>
  117. <?php
  118. if($_SESSION['user']['usergroup'] == 'admin') {
  119. ?>
  120. <form style="float: left;" action="" method="POST" id="user_select" style="margin-top: 15px;" onchange='document.getElementById("user_select").submit();'>
  121. <?php
  122.     $query_user = "SELECT * FROM `user` WHERE `usergroup` != 'admin' ORDER BY `company_name`";
  123.     if ($result_user = $con->query($query_user)) {
  124.         $row_cnt = $result_user->num_rows;
  125.         if($row_cnt > 0){
  126.         echo '<b>Message To</b>: <select name="msg_user_id">';
  127.         echo '<option value="">Please Select</option>';
  128.             while($row = $result_user->fetch_assoc()){
  129. ?>
  130.                 <option value="<?php echo $row['id']; ?>"<?php if (ISSET($_SESSION['msg']['msg_user_id'])) { if ($_SESSION['msg']['msg_user_id'] == $row['id']) { echo ' selected'; }} ?>><?php echo $row['company_name'].' - '.$row['username']; ?></option>
  131. <?php
  132.             }
  133.             echo '</select>';
  134.         }
  135.     }
  136. ?>
  137. </form>
  138. <?php
  139. }
  140. ?>
  141.     <form action="" method="POST">
  142.     <div class="message_send_box" style="clear: both;" >
  143.         <b><?php if ($_SESSION['user']['usergroup'] == 'admin') { echo 'Message'; } else { echo 'Message To Site Administrator'; } ?></b>: <br />
  144.         <textarea class="message_send normal" name="message"></textarea><br />
  145. <?php
  146.     if ($_SESSION['user']['usergroup'] == 'admin'){
  147. ?>
  148.         <input type="hidden" name="to_id" value="<?php if(ISSET($_SESSION['msg']['msg_user_id'])) { echo $_SESSION['msg']['msg_user_id']; } ?>" />
  149.         <input type="hidden" name="from_id" value="admin" />
  150.         <input type="hidden" name="msg_user_id" value="<?php echo $_SESSION['msg']['msg_user_id']; ?>" />
  151. <?php
  152.     } else {
  153. ?>
  154.         <input type="hidden" name="from_id" value="<?php echo $_SESSION['user']['id']; ?>" />
  155.         <input type="hidden" name="to_id" value="admin" />
  156. <?php  
  157.     }
  158. ?>
  159.         <input type="submit" name="submit_message" accesskey="s" value="Send (Alt + S)" style="float: right; margin-top: 10px;" />
  160.     </div>
  161.     </form>
  162. <?php   $msg_hide_id = ''; ?>
  163.  
  164. <?php
  165.     $query_recheck_msg = "SELECT from `message` WHERE `to_id` = '".$_SESSION['user']['msgid']."' AND `read` = 0 GROUP BY `from_id`";
  166.     if ($query_recheck_msg_result = $con->query($query_recheck_msg)) {
  167.         $row_cnt = $result_recheck_msg_result->num_rows;
  168.         if($row_cnt > 0){
  169.             $data = '<li><a href="messaging.php"><div class="yes_msg"></div></a><ul>';
  170.             while ($row_recheck_msg_result = $result_recheck_msg_result ->fetch_assoc()){
  171.                 $msg_list .= '<li><a href="messaging.php?user='.$row_recheck_msg_result['from_id'].'">'.$row_recheck_msg_result['from_id'].'</a></li>';
  172.             }
  173.             $data .= '</ul></li>';
  174.             $data['userid'] = $_SESSION['user']['msgid'];
  175.             $pusher->trigger('gms_channel', 'gms_chat', $data);
  176.         } else {
  177.             $data = '<div class="no_msg"></div>';
  178.             $data['userid'] = $_SESSION['user']['msgid'];
  179.             $pusher->trigger('gms_channel', 'gms_chat', $data);
  180.         }
  181.     }
  182. ?>
  183.  
  184. </div>
  185. <?php include('footer.inc.php'); ?>
  186. </body>
  187. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement