Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.34 KB | None | 0 0
  1. <?php
  2. /*
  3. UserSpice 4
  4. An Open Source PHP User Management System
  5. by the UserSpice Team at http://UserSpice.com
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. ?>
  21. <?php
  22. require_once '../users/init.php';
  23. require_once $abs_us_root.$us_url_root.'users/includes/header.php';
  24. require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';
  25. ?>
  26.  
  27. <?php if (!securePage($_SERVER['PHP_SELF'])){die();}
  28. if($settings->messaging != 1){
  29.   Redirect::to('account.php?err=Messaging+is+disabled');
  30. }
  31. $validation = new Validate();
  32. $errors = [];
  33. $successes = [];
  34. ?>
  35. <?php
  36. if (!empty($_POST)) {
  37.   //Delete User Checkboxes
  38.   if (!empty($_POST['archive'])){
  39.     $deletions = $_POST['archive'];
  40.     if ($deletion_count = archiveThreads($deletions,$user->data()->id,1)){
  41.       $successes[] = lang("MESSAGE_ARCHIVE_SUCCESSFUL", array($deletion_count));
  42.       Redirect::to('messages.php');
  43.     }
  44.     else {
  45.       $errors[] = lang("SQL_ERROR");
  46.     }
  47.   }
  48.   if (!empty($_POST['unarchive'])){
  49.     $deletions = $_POST['checkbox'];
  50.     if ($deletion_count = archiveThreads($deletions,$user->data()->id,0)){
  51.       $successes[] = lang("MESSAGE_UNARCHIVE_SUCCESSFUL", array($deletion_count));
  52.     }
  53.     else {
  54.       $errors[] = lang("SQL_ERROR");
  55.     }
  56.   }
  57.   if (!empty($_POST['delete'])){
  58.     $deletions = $_POST['checkbox'];
  59.     if ($deletion_count = deleteThread($deletions,$user->data()->id,1)){
  60.       $successes[] = lang("MESSAGE_DELETE_SUCCESSFUL", array($deletion_count));
  61.     }
  62.     else {
  63.       $errors[] = lang("SQL_ERROR");
  64.     }
  65.   }
  66. if(!empty($_POST['send_message'])){
  67.    
  68.     if (empty(Input::get('user_id'))) {
  69.     $errors[] = "Unknown recipient"; }
  70.  
  71.     if (strlen(Input::get('msg_body')) == 0) {
  72.     $errors[] = "Message cannot be empty"; }
  73.    
  74.   $date = date("Y-m-d H:i:s");
  75.  
  76.   $thread = array(
  77.     'msg_from'    => $user->data()->id,
  78.     'msg_to'      => Input::get('user_id'),
  79.     'msg_subject' => Input::get('msg_subject'),
  80.     'last_update' => $date,
  81.     'last_update_by' => $user->data()->id,
  82.   );
  83.     if (empty($errors)) {
  84.     $db->insert('message_threads',$thread); }
  85.   $newThread = $db->lastId();
  86.  
  87.  
  88.   $fields = array(
  89.     'msg_from'    => $user->data()->id,
  90.     'msg_to'      => Input::get('user_id'),
  91.     'msg_body'    => Input::get('msg_body'),
  92.     'msg_thread'  => $newThread,
  93.     'sent_on'     => $date,
  94.   );
  95.  
  96.     if (empty($errors)) {
  97.   $db->insert('messages',$fields);
  98.  
  99.     $successes[] = "Your message has been sent!"; }
  100. }
  101.  
  102. if(!empty($_POST['send_mass_message'])){
  103.   $date = date("Y-m-d H:i:s");
  104.  
  105.   $userData = fetchMessageUsers(); //Fetch information for all users
  106.     foreach($userData as $v1) {
  107.   $thread = array(
  108.     'msg_from'    => $user->data()->id,
  109.     'msg_to'      => $v1->id,
  110.     'msg_subject' => Input::get('msg_subject'),
  111.     'last_update' => $date,
  112.     'last_update_by' => $user->data()->id,
  113.   );
  114.   $db->insert('message_threads',$thread);
  115.   $newThread = $db->lastId();
  116.  
  117.  
  118.   $fields = array(
  119.     'msg_from'    => $user->data()->id,
  120.     'msg_to'      => $v1->id,
  121.     'msg_body'    => Input::get('msg_body'),
  122.     'msg_thread'  => $newThread,
  123.     'sent_on'     => $date,
  124.   );
  125.  
  126.   $db->insert('messages',$fields);
  127.     }
  128.  
  129.   $successes[] = "Your mass message has been sent!";
  130. } }
  131. $messagesQ = $db->query("SELECT * FROM message_threads WHERE (msg_to = ? AND archive_to = ? AND hidden_to = ?) OR (msg_from = ? AND archive_from = ? AND hidden_from = ?) ORDER BY last_update DESC",array($user->data()->id,0,0,$user->data()->id,0,0));
  132. $messages = $messagesQ->results();
  133. $count = $messagesQ->count();
  134. $archiveCount = $db->query("SELECT * FROM message_threads WHERE (msg_to = ? AND archive_to = ? AND hidden_to = ?) OR (msg_from = ? AND archive_from = ? AND hidden_from = ?) ORDER BY last_update DESC",array($user->data()->id,1,0,$user->data()->id,1,0))->count();
  135. ?>
  136. <div id="page-wrapper">
  137.  
  138. <div class="container">
  139.  
  140. <?=resultBlock($errors,$successes);?>
  141. <?=$validation->display_errors();?>
  142.  
  143.  
  144. <div class="row">
  145.       <div class="col-sm-12">
  146.         <div class="row" id="maindiv">
  147.           <div>
  148.         <h1><?php if (checkMenu(2,$user->data()->id)){  ?><div class="btn-group pull-left"><button type="button" class="btn btn-info" data-toggle="modal" data-target="#composemass"><i class="glyphicon glyphicon-plus"></i> New Mass Message</button></div><?php } ?> <center>Conversations <div class="btn-group pull-right"><button type="button" class="btn btn-info" data-toggle="modal" data-target="#compose"><i class="glyphicon glyphicon-plus"></i> New Message</button></div></center></h1>
  149.       </div>
  150.         <?php if($count > 0) {?><label><input type="checkbox" id="checkall" value="1"
  151.         onclick="checkCheckboxes(this.id, 'maindiv');" >
  152.         [ check/uncheck all ]</label><?php } ?>
  153.       <form name="threads" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  154.         <center><table class="table table-striped">
  155.           <thead>
  156.             <tr>
  157.               <th></th>
  158.               <th></th>
  159.             </tr>
  160.           </thead>
  161.           <tbody>
  162.             <tr>
  163.             <?php if($count > 0) {?>
  164.               <?php foreach($messages as $m){
  165.             if($m->msg_from == $user->data()->id) { $findId = $m->msg_to; } else { $findId = $m->msg_from; }
  166.             $findUser = $db->query("SELECT picture,email FROM users WHERE id = $findId");
  167.             $foundUser = $findUser->first();
  168.              $grav = empty($foundUser->picture) ? get_gravatar(strtolower(trim($foundUser->email))) : $foundUser->picture; ?>
  169.             <?php $lastmessage = strtotime($m->last_update);
  170.                 $difference = ceil((time() - $lastmessage) / (60 * 60 * 24));
  171.                 // if($difference==0) { $last_update = "Today, "; $last_update .= date("g:i A",$lastmessage); }
  172.                 if($difference >= 0 && $difference < 7) {
  173.                     $today = date("j");
  174.                     $last_message = date("j",$lastmessage);
  175.                     if($today==$last_message) { $last_update = "Today, "; $last_update .= date("g:i A",$lastmessage); }
  176.                     else {
  177.                 $last_update = date("l g:i A",$lastmessage); } }
  178.                 elseif($difference >= 7) { $last_update = date("M j, Y g:i A",$lastmessage); }
  179.                 $replies = $db->query("SELECT COUNT(*) AS count FROM messages WHERE msg_thread = ? GROUP BY msg_thread",array($m->id));
  180.                 $repliescount = $replies->count();
  181.                 ?>
  182.                 <td style="width:100px">
  183.                     <center>
  184.                         <span class="chat-img pull-left" style="padding-right:5px">
  185.                             <a class="nounderline" href="message.php?id=<?=$m->id?>">
  186.                                 <img src="<?=$grav ?>" width="75" class="img-thumbnail">
  187.                             </a>
  188.                         </span>
  189.                     </center>
  190.                 </td>
  191.                 <td class="pull-left">
  192.                     <h4>
  193.                         <input type="checkbox" name="archive[<?=$m->id?>]" value="<?=$m->id?>"/>
  194.                         <a class="nounderline" href="message.php?id=<?=$m->id?>">  
  195.                             <?=$m->msg_subject?> - with <?php if($m->msg_from == $user->data()->id) { echouser($m->msg_to); } else { echouser($m->msg_from); } ?>
  196.                         </a>
  197.                         <?php $unread = $db->query("SELECT * FROM messages WHERE msg_thread = ? AND msg_to = ? AND msg_read = ?",array($m->id,$user->data()->id,0));
  198.                                 $unreadCount = $unread->count();?>
  199.                     <?php if($unreadCount > 0) {?> - <font color="red"><?=$unreadCount?> New Message<?php if($unreadCount > 1) {?>s<?php } ?></font><?php } ?></h4>
  200.                     <a class="nounderline" href="message.php?id=<?=$m->id?>">
  201.                         Updated <?=$last_update?> by <?php echouser($m->last_update_by);?>
  202.                     </a>
  203.             </tr>
  204.             <?php } } else {?>
  205.             <td colspan="2"><center><h3>No Conversations</h3></center></td></tr>
  206.             <?php } ?>
  207.               </tbody>
  208.             </table></center>
  209.             <?php if($count > 0) {?><div class="btn-group pull-right"><input class='btn btn-danger' type='submit' name='Submit' value='Archive Selected Threads' /></div><?php } ?>
  210.                 </form>
  211.                 <br /><?php if($archiveCount > 0) {?><center><a href="#" data-toggle="modal" data-target="#archived">View Archived Threads</a></center><?php } ?>
  212.             </div><!-- End of main content section --><br />
  213.           </div> <!-- /.col -->
  214.          
  215. <div id="compose" class="modal fade" role="dialog">
  216.   <div class="modal-dialog">
  217.  
  218.     <!-- Modal content-->
  219.     <div class="modal-content">
  220.       <div class="modal-header">
  221.         <button type="button" class="close" data-dismiss="modal">&times;</button>
  222.         <h4 class="modal-title">New Message</h4>
  223.       </div>
  224.       <div class="modal-body">
  225. <form name="create_message" action="messages.php" method="post">
  226.  
  227.                 <label>Select a user:</label>
  228.                 <select name="user_id" id="combobox" class="form-control combobox" required>
  229.                 <option readonly></option>
  230.                 <?php $userData = fetchMessageUsers(); //Fetch information for all users
  231.                 foreach($userData as $v1) {?>
  232.                 <option value="<?=$v1->id;?>"><?=$v1->fname;?> <?=$v1->lname;?></option>
  233.                 <?php } ?>
  234.                 </select><br />
  235.               <label>Subject:</label>
  236.                 <input required size='100' class='form-control' type='text' name='msg_subject' value='' required/>
  237.                 <br /><label>Body:</label>
  238.                 <textarea rows="20" cols="80"  id="mytextarea" name="msg_body"></textarea>
  239.                 <input required type="hidden" name="csrf" value="<?=Token::generate();?>" >
  240.               </p>
  241.               <p>
  242.                   <br />
  243.       </div>
  244.       <div class="modal-footer">
  245.       <div class="btn-group">   <input type="hidden" name="csrf" value="<?=Token::generate();?>" />
  246.     <input class='btn btn-primary' type='submit' name="send_message" value='Send Message' class='submit' /></div>
  247.     </form>
  248.          <div class="btn-group"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
  249.       </div>
  250.     </div>
  251.     </div>
  252.   </div>
  253.  
  254.   <div id="archived" class="modal fade" role="dialog">
  255.   <div class="modal-dialog">
  256.  
  257.     <!-- Modal content-->
  258.     <div class="modal-content">
  259.       <div class="modal-header">
  260.         <button type="button" class="close" data-dismiss="modal">&times;</button>
  261.         <h4 class="modal-title">Archived Threads</h4>
  262.       </div>
  263.       <div class="modal-body" id="archivediv">
  264.       <?php $messagesQ2 = $db->query("SELECT * FROM message_threads WHERE (msg_to = ? AND archive_to = ? AND hidden_to = ?) OR (msg_from = ? AND archive_from = ? AND hidden_from = ?) ORDER BY last_update DESC",array($user->data()->id,1,0,$user->data()->id,1,0));
  265.             $messages2 = $messagesQ2->results();
  266.             $messagesCount2 = $messagesQ2->count(); ?>
  267.             <?php if($messagesCount2 > 0) {?><label><input type="checkbox" id="checkall" value="1"
  268.         onclick="checkCheckboxes(this.id, 'archivediv');" >
  269.         [ check/uncheck all ]</label><?php } ?>
  270. <form name="uthreads" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  271.         <center><table class="table table-striped">
  272.           <thead>
  273.             <tr>
  274.               <th></th>
  275.               <th></th>
  276.             </tr>
  277.           </thead>
  278.           <tbody>
  279.             <tr>
  280.             <?php if($messagesCount2 > 0) {?>
  281.               <?php foreach($messages2 as $m2){ ?>
  282.               <?php
  283.             if($m2->msg_from == $user->data()->id) { $findId = $m2->msg_to; } else { $findId = $m2->msg_from; }
  284.             $findUser = $db->query("SELECT picture,email FROM users WHERE id = $findId");
  285.             $foundUser = $findUser->first();
  286.             $grav = empty($foundUser->picture) ? get_gravatar(strtolower(trim($foundUser->email))) : $foundUser->picture; ?>
  287.             <?php $lastmessage = strtotime($m2->last_update);
  288.                 $difference = ceil((time() - $lastmessage) / (60 * 60 * 24));
  289.                 // if($difference==0) { $last_update = "Today, "; $last_update .= date("g:i A",$lastmessage); }
  290.                 if($difference >= 0 && $difference < 7) {
  291.                     $today = date("j");
  292.                     $last_message = date("j",$lastmessage);
  293.                     if($today==$last_message) { $last_update = "Today, "; $last_update .= date("g:i A",$lastmessage); }
  294.                     else {
  295.                 $last_update = date("l g:i A",$lastmessage); } }
  296.                 elseif($difference >= 7) { $last_update = date("M j, Y g:i A",$lastmessage); }
  297.                 $replies = $db->query("SELECT COUNT(*) AS count FROM messages WHERE msg_thread = ? GROUP BY msg_thread",array($m2->id));
  298.                 $repliescount = $replies->count();
  299.                 ?>
  300.                 <td style="width:100px">
  301.                     <center>
  302.                         <span class="chat-img pull-left" style="padding-right:5px">
  303.                             <a class="nounderline" href="message.php?id=<?=$m2->id?>">
  304.                                 <img src="<?=$grav ?>" width="75" class="img-thumbnail">
  305.                             </a>
  306.                         </span>
  307.                     </center>
  308.                 </td>
  309.                 <td class="pull-left">
  310.                     <h4>
  311.                         <input type="checkbox" name="checkbox[<?=$m2->id?>]" value="<?=$m2->id?>"/>
  312.                         <a class="nounderline" href="message.php?id=<?=$m2->id?>">  
  313.                             <?=$m2->msg_subject?> - with <?php if($m2->msg_from == $user->data()->id) { echouser($m2->msg_to); } else { echouser($m2->msg_from); } ?>
  314.                         </a>
  315.                     </h4>
  316.                     <a class="nounderline" href="message.php?id=<?=$m2->id?>">
  317.                         Updated <?=$last_update?> by <?php echouser($m2->last_update_by);?>
  318.                     </a>
  319.             </tr>
  320.             <?php } } else {?>
  321.             <td colspan="2"><center><h3>No Archived Conversations</h3></center></td></tr>
  322.             <?php } ?>
  323.               </tbody>
  324.             </table></center>
  325.                   <br />
  326.       </div>
  327.       <div class="modal-footer">
  328.       <div class="btn-group">   <input type="hidden" name="csrf" value="<?=Token::generate();?>" />
  329.     <input class='btn btn-primary' type='submit' name="delete" value='Delete Selected Threads' class='submit' /></div>
  330.     <div class="btn-group"><input class='btn btn-primary' type='submit' name="unarchive" value='Unarchive Selected Threads' class='submit' /></div>
  331.     </form>
  332.          <div class="btn-group"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
  333.       </div>
  334.     </div>
  335.     </div>
  336.   </div>
  337.  
  338.   <div id="composemass" class="modal fade" role="dialog">
  339.   <div class="modal-dialog">
  340.  
  341.     <!-- Modal content-->
  342.     <div class="modal-content">
  343.       <div class="modal-header">
  344.         <button type="button" class="close" data-dismiss="modal">&times;</button>
  345.         <h4 class="modal-title">New Mass Message</h4>
  346.       </div>
  347.       <div class="modal-body">
  348. <form name="create_mass_message" action="messages.php" method="post">
  349.  
  350.               <label>Subject:</label>
  351.                 <input required size='100' class='form-control' type='text' name='msg_subject' value='' required/>
  352.                 <br /><label>Body:</label>
  353.                 <textarea rows="20" cols="80"  id="mytextarea2" name="msg_body"></textarea>
  354.                 <input required type="hidden" name="csrf" value="<?=Token::generate();?>" >
  355.               </p>
  356.               <p>
  357.                   <br />
  358.       </div>
  359.       <div class="modal-footer">
  360.       <div class="btn-group">   <input type="hidden" name="csrf" value="<?=Token::generate();?>" />
  361.     <input class='btn btn-primary' type='submit' name="send_mass_message" value='Send Message' class='submit' /></div>
  362.     </form>
  363.          <div class="btn-group"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
  364.       </div>
  365.     </div>
  366.     </div>
  367.   </div>
  368.          
  369.         </div> <!-- /.row -->
  370.       </div> <!-- /.container -->
  371.     </div> <!-- /.wrapper -->
  372.  
  373.  
  374.     <!-- footers -->
  375.     <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  376.  
  377.     <!-- Place any per-page javascript here -->
  378.     <script src='https://cdn.tinymce.com/4/tinymce.min.js'></script>
  379.     <script src="scripts/jwerty.js"></script>
  380.     <script src="scripts/combobox.js"></script>
  381.     <script>
  382.     $(document).ready(function(){
  383.     $('.combobox').combobox();
  384.     });
  385.     tinymce.init({
  386.     selector: '#mytextarea'
  387.     });
  388.     tinymce.init({
  389.     selector: '#mytextarea2'
  390.     });
  391.     function checkCheckboxes( id, pID ){
  392.  
  393.         $('#'+pID).find(':checkbox').each(function(){
  394.  
  395.             jQuery(this).attr('checked', $('#' + id).is(':checked'));
  396.  
  397.         });    
  398.  
  399.     }
  400.     jwerty.key('esc', function () {
  401.         $('.modal').modal('hide');
  402.     });
  403.     </script>
  404.  
  405.     <?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement