/[drupal]/contributions/modules/messagebox/messagebox.module
ViewVC logotype

Diff of /contributions/modules/messagebox/messagebox.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Fri Nov 23 20:39:06 2007 UTC revision 1.2, Sat Nov 24 00:34:58 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id:$  // $Id: messagebox.module,v 1.1 2007/11/23 20:39:06 panis Exp $
3    
4  /**  /**
5    A Drupal messenger module (http://Drupal.org).    A Drupal messenger module (http://Drupal.org).
# Line 88  function _messagebox_get_users() { Line 88  function _messagebox_get_users() {
88          uid != 0          uid != 0
89          AND uid != %d          AND uid != %d
90          AND status = 1          AND status = 1
         AND login != 0  
91        ORDER BY        ORDER BY
92          status, name', time() - $time_period, $user->uid);          status, name', time() - $time_period, $user->uid);
93    }    }
# Line 399  function _messagebox_submit($rid, $messa Line 398  function _messagebox_submit($rid, $messa
398    rid,    rid,
399    aid,    aid,
400    message,    message,
401      headers,
402    timestamp    timestamp
403        )        )
404        VALUES (        VALUES (
# Line 406  function _messagebox_submit($rid, $messa Line 406  function _messagebox_submit($rid, $messa
406    %d,    %d,
407    %d,    %d,
408    \'%s\',    \'%s\',
409      \'\',
410    %d    %d
411      )', $user->uid, $rid, $aid, $message, time());      )', $user->uid, $rid, $aid, $message, time());
412    }    }
# Line 446  function messagebox_sent_messages($user) Line 447  function messagebox_sent_messages($user)
447    //    //
448    $result = db_query($query, $user->uid);    $result = db_query($query, $user->uid);
449    
450    $output .= '<div class="sent">';    $img_attach = drupal_get_path('module', 'messagebox') . '/images/ImgAttachment.gif';
451    $output .= '<h2 class="title">' . t('Sent Messages') . '</h2>';    $rows = array();
452    if(db_num_rows($result)) {    if(db_num_rows($result)) {
     // title  
   
453      // "delete all" link      // "delete all" link
     $output .= '<div id="messagebox_delete_all">';  
     $output .= l(t('[Delete all Sent]'), "/messagebox/delete_all_sent/$user->uid");  
     $output .= '</div>';  
454    
455      while($msg = db_fetch_object($result)) {      while($msg = db_fetch_object($result)) {
456    $rids = unserialize($msg->headers);                          $rids = unserialize($msg->headers);
457    
458    $names = array();                          $names = array();
459    if($rids && is_array($rids)) {                          if($rids && is_array($rids)) {
460      foreach($rids as $rid) {                                  foreach($rids as $rid) {
461        $account = user_load(array('uid'=>$rid));                                          $account = user_load(array('uid'=>$rid));
462        $names[] = theme_username($account);                                          $names[] = theme_username($account);
463      }                                  }
464    }                          }
465    
466          if( $msg->aid ) {
467                                    $aid = '<a href="' . url("node/$msg->aid") . '"><img src="' . $img_attach . '"/>';
468                            }
469                            $rows[] = array(implode(', ', $names),
470                                                                                            $aid,
471                                                                                            $msg->title,
472                                                                                            format_date($msg->timestamp),
473                                                                                            l(t('Forward'), "messagebox/new/$user->uid/$msg->mid"),
474                                                                                            l(t('Delete'), "messagebox/del/$user->uid/$msg->mid"));
475          $rows[] = array(array('data'=>check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE), 'colspan'=>6));;
476          $output .= check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE);
477        }
478      }
479      $header = array(t('To'),
480                      '<img alt="Attachment" src="' . $img_attach . '"/>',
481                      t('Subject'),
482                      t('Sent'),
483                      t('Forward'),
484                      t('Delete'));
485    
486          $output .= '<div class="messagebox">';    $output = '<div class="sent">';
487          $output .= '<div class="header">';    $output .= '<h2 class="title">' . t('Sent Messages') . '</h2>';
488          $output .= '<div class="user">';    $output .= l(t('[Delete all Sent]'), "/messagebox/delete_all_sent/$user->uid");
489          $output .= implode(', ', $names) . ' - ' . format_date($msg->timestamp);    $output .= theme('table', $header, $rows);
         $output .= '</div>';  
   
         $output .= '<div class="operations">';  
         $output .= l(t('[Forward]'), "messagebox/new/$user->uid/$msg->mid");  
         $output .= l(t('[Delete]'), "messagebox/del/$user->uid/$msg->mid");  
         $output .= '</div>';  
         $output .= '<span class="clear">&nbsp;</span>';  
         $output .= '</div>';  
   
         $output .= '<div class="message">';  
         $output .= check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE);  
         $output .= '</div>';  
         if ($msg->aid) {  
           $output .= '<div class="attachment">';  
           $output .= l(t('Attachment'), "node/$msg->aid");  
           $output .= '</div>';  
         }  
         $output .= '</div>';  
     }  
   
   }  
490    $output .= '</div>';    $output .= '</div>';
   
491    return $output;    return $output;
492  }  }
493    
# Line 523  function messagebox_inbox($user) { Line 517  function messagebox_inbox($user) {
517    
518    $form = array();    $form = array();
519    
520    $output .= '<div class="unread">';    $rows = array();
521    $output .= '<h2 class="title">' . t('Unread messages') . '</h2>';    $img_attach = drupal_get_path('module', 'messagebox') . '/images/ImgAttachment.gif';
522    if(db_num_rows($result)) {    if(db_num_rows($result)) {
523      // title      // title
524    
     // the "mark all as read" link  
     $output .= '<div id="messagebox_mark_all_as_read">';  
     $output .= l(t('[Mark all as read]'), "/messagebox/mark_all_as_read/$user->uid");  
     $output .= '</div>';  
525    
526      while($msg = db_fetch_object($result)) {      while($msg = db_fetch_object($result)) {
       if($msg->name) {  
527          $account->uid = $msg->sid;          $account->uid = $msg->sid;
528          $account->name = $msg->name;          $account->name = $msg->name;
529    
530          $output .= '<div class="messagebox">';                                  $aid = $msg->aid?l('<img alt="Attachment" src="' . $img_attach . '"/>', "node/$msg->aid"):'';
         $output .= '<div class="header">';  
         $output .= '<div class="user">';  
         $output .= theme_username($account) . ' - ' . format_date($msg->timestamp);  
         $output .= '</div>';  
   
         $output .= '<div class="operations">';  
         $output .= l(t('[Reply]'), "messagebox/new/$user->uid/$msg->mid");  
         $output .= l(t('[Forward]'), "messagebox/new/$user->uid/$msg->mid");  
         $output .= l(t('[Mark as read]'), "messagebox/mark_as_read/$user->uid/$msg->mid");  
         $output .= '</div>';  
         $output .= '<span class="clear">&nbsp;</span>';  
         $output .= '</div>';  
   
         $output .= '<div class="message">';  
         $output .= check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE);  
         $output .= '</div>';  
         if ($msg->aid) {  
           $output .= '<div class="attachment">';  
           $output .= l(t('Attachment'), "node/$msg->aid");  
           $output .= '</div>';  
         }  
         $output .= '</div>';  
       }  
       else {  
         $output .= '<div class="messagebox">';  
         $output .= '<div class="header">';  
         $output .= '<div class="user">';  
         $output .= variable_get('anonymous', t('Anonymous')) . ' - ' . format_date($msg->timestamp);  
         $output .= '</div>';  
   
         $output .= '<div class="operations">';  
         $output .= '<a href="javascript:messagebox_mark_as_read_click(\'' . $msg->mid . '\')" title="' . t('Mark as read') . '">' . t('Mark as read') . '</a>';  
         $output .= '</div>';  
         $output .= '<span class="clear">&nbsp;</span>';  
         $output .= '</div>';  
   
         $output .= '<div class="message">';  
         $output .= check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE);  
         $output .= '</div>';  
         if ($msg->aid) {  
           $output .= '<div class="attachment">';  
           $output .= l(t('Attachment'), "node/$msg->aid");  
           $output .= '</div>';  
         }  
         $output .= '</div>';  
       }  
     }  
531    
532                                    $rows[] = array(theme_username($account),
533                                                                                            $aid,
534                                                                                            $msg->title,
535                                                                                            format_date($msg->timestamp),
536                                                                                            l(t('Reply'), "messagebox/new/$user->uid/$msg->mid"),
537                                                                                            l(t('Forward'), "messagebox/new/$user->uid/$msg->mid"),
538                                                                                            l(t('Mark read'), "messagebox/mark_as_read/$user->uid/$msg->mid"));
539            $rows[] = array(array('data'=>check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE), 'colspan'=>7));;
540          }
541    }    }
542    
543      $header = array(t('From'),
544                      '<img alt="Attachment" src="' . $img_attach . '"/>',
545                      t('Subject'),
546                      t('Received'),
547                      t('Reply'),
548                      t('Forward'),
549                      t('Mark Read'));
550    
551      $output .= '<div class="unread">';
552      $output .= '<h2 class="title">' . t('Unread messages') . '</h2>';
553            // the "mark all as read" link
554            $output .= '<div id="messagebox_mark_all_as_read">';
555            $output .= l(t('[Mark all as read]'), "/messagebox/mark_all_as_read/$user->uid");
556            $output .= '</div>';
557    
558      $output .= theme('table', $header, $rows);
559    $output .= '</div>';    $output .= '</div>';
560    return $output;    return $output;
561  }  }
562    
563  function messagebox_archive($user) {  function messagebox_archive($user) {
564    //  
   // get the 'Message archive'  
   //  
565    $query = '    $query = '
566      SELECT      SELECT
567        m.mid,        m.mid,
# Line 614  function messagebox_archive($user) { Line 580  function messagebox_archive($user) {
580        AND is_read = %d        AND is_read = %d
581      ORDER BY      ORDER BY
582        m.timestamp';        m.timestamp';
583    
584      // get all the 'read messages' sent to this user
585    $result = db_query($query, $user->uid, 1);    $result = db_query($query, $user->uid, 1);
586    
587    $output .= '<div class="archive">';    $form = array();
588    $output .= '<h2 class="title">' . t('Message archive') . '</h2>';  
589      $rows = array();
590      $img_attach = drupal_get_path('module', 'messagebox') . '/images/ImgAttachment.gif';
591    if(db_num_rows($result)) {    if(db_num_rows($result)) {
592      // title      // title
593    
     // "delete all" link  
     $output .= '<div id="messagebox_delete_all">';  
     $output .= l(t('[Delete all Archived]'), "/messagebox/delete_all_archived/$user->uid");  
     $output .= '</div>';  
   
594      while($msg = db_fetch_object($result)) {      while($msg = db_fetch_object($result)) {
       if($msg->name) {  
595          $account->uid = $msg->sid;          $account->uid = $msg->sid;
596          $account->name = $msg->name;          $account->name = $msg->name;
597    
598          $output .= '<div class="messagebox">';                                  $aid = $msg->aid?l('<img alt="Attachment" src="' . $img_attach . '"/>', "node/$msg->aid"):'';
         $output .= '<div class="header">';  
         $output .= '<div class="user">';  
         $output .= theme_username($account) . ' - ' . format_date($msg->timestamp);  
         $output .= '</div>';  
   
         $output .= '<div class="operations">';  
         $output .= l(t('[Reply]'), "messagebox/new/$user->uid/$msg->mid");  
         $output .= l(t('[Forward]'), "messagebox/new/$user->uid/$msg->mid");  
         $output .= l(t('[Delete]'), "messagebox/del/$user->uid/$msg->mid");  
         $output .= '</div>';  
         $output .= '<span class="clear">&nbsp;</span>';  
         $output .= '</div>';  
   
         $output .= '<div class="message">';  
         $output .= check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE);  
         $output .= '</div>';  
         if ($msg->aid) {  
           $output .= '<div class="attachment">';  
           $output .= l(t('Attachment'), "node/$msg->aid");  
           $output .= '</div>';  
         }  
         $output .= '</div>';  
       }  
       else {  
         $output .= '<div class="messagebox">';  
         $output .= '<div class="header">';  
         $output .= '<div class="user">';  
         $output .= variable_get('anonymous', t('Anonymous')) . ' - ' . format_date($msg->timestamp);  
         $output .= '</div>';  
   
         $output .= '<div class="operations">';  
         $output .= '<a href="javascript:messagebox_delete_click(\'' . $msg->mid . '\')" title="' . t('Delete') . '">' . t('Delete') . '</a>';  
         $output .= '</div>';  
         $output .= '<span class="clear">&nbsp;</span>';  
         $output .= '</div>';  
   
         $output .= '<div class="message">';  
         $output .= check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE);  
         $output .= '</div>';  
         if ($msg->aid) {  
           $output .= '<div class="attachment">';  
           $output .= l(t('Attachment'), "node/$msg->aid");  
           $output .= '</div>';  
         }  
         $output .= '</div>';  
       }  
     }  
599    
600                                    $rows[] = array(theme_username($account),
601                                                                                            $aid,
602                                                                                            $msg->title,
603                                                                                            format_date($msg->timestamp),
604                                                                                            l(t('Reply'), "messagebox/new/$user->uid/$msg->mid"),
605                                                                                            l(t('Forward'), "messagebox/new/$user->uid/$msg->mid"),
606                                                                                            l(t('Delete'), "messagebox/del/$user->uid/$msg->mid"));
607            $rows[] = array(array('data'=>check_markup($msg->message, FILTER_FORMAT_DEFAULT, FALSE), 'colspan'=>7));;
608          }
609    }    }
610    
611      $header = array(t('From'),
612                      '<img alt="Attachment" src="' . $img_attach . '"/>',
613                      t('Subject'),
614                      t('Received'),
615                      t('Reply'),
616                      t('Forward'),
617                      t('Mark Read'));
618    
619      $output = '<div class="archive">';
620      $output .= '<h2 class="title">' . t('Message archive') . '</h2>';
621            $output .= '<div id="messagebox_delete_all">';
622            $output .= l(t('[Delete all Archived]'), "/messagebox/delete_all_archived/$user->uid");
623            $output .= '</div>';
624    
625      $output .= theme('table', $header, $rows);
626    $output .= '</div>';    $output .= '</div>';
627    return $output;    return $output;
628  }  }
# Line 809  function messagebox_block($op = 'list', Line 751  function messagebox_block($op = 'list',
751  /**  /**
752   * menu callback, display the messagebox page   * menu callback, display the messagebox page
753   */   */
754  function messagebox_page() {  function messagebox_age() {
755    return drupal_get_form('messagebox_form');    return drupal_get_form('messagebox_form');
   $output = '';  
   
   $tabs = messagebox_table();  
   $output .= '<div id="messagebox-notify-message"></div>';  
   $output .= drupal_get_form('messagebox_form');  
   $tabs['messagebox']['tab-new'] = array(  
         '#type' => 'tabpage',  
         '#title' => t('New'),  
         '#content'=> $output,  
         );  
   
756    return tabs_render($tabs);    return tabs_render($tabs);
757  }  }
758    
# Line 850  function messagebox_menu($may_cache) { Line 781  function messagebox_menu($may_cache) {
781    if($may_cache) {    if($may_cache) {
782      $items[] = array('path' => 'messagebox',      $items[] = array('path' => 'messagebox',
783        'title' => t('Messenger'),        'title' => t('Messenger'),
784        'callback' => 'messagebox_page',        'callback' => 'drupal_get_form',
785                'callback arguments' => array('messagebox_new'),
786        'access' => $access,        'access' => $access,
787        'type' => MENU_SUGGESTED_ITEM,        'type' => MENU_SUGGESTED_ITEM,
788      );      );
# Line 924  function messagebox_menu($may_cache) { Line 856  function messagebox_menu($may_cache) {
856    
857      //create tabs for the messages...      //create tabs for the messages...
858      if(arg(0) == 'messagebox') {      if(arg(0) == 'messagebox') {
859      if( user_access('administer users') && is_numeric(arg(2)) ) {      if( user_access('administer users') && is_numeric(arg(2)) && arg(2) > 0 ) {
860          $account = user_load(array('uid'=>arg(2)));          $account = user_load(array('uid'=>arg(2)));
861      }      }
862      else {      else {
# Line 962  function messagebox_menu($may_cache) { Line 894  function messagebox_menu($may_cache) {
894          'path' => "messagebox/new/$account->uid",          'path' => "messagebox/new/$account->uid",
895          'title' => 'New',          'title' => 'New',
896          'callback' => 'drupal_get_form',          'callback' => 'drupal_get_form',
897          'callback arguments' => array('messagebox_new', $account),          'callback arguments' => array('messagebox_new', $account, arg(2)),
898          'weight'=> 2,          'weight'=> 2,
899          'type' => MENU_LOCAL_TASK,          'type' => MENU_LOCAL_TASK,
900          );          );
# Line 1020  function messagebox_link($type, $node = Line 952  function messagebox_link($type, $node =
952    return $links;    return $links;
953  }  }
954    
955  function messagebox_new($user) {  function messagebox_new($user=null, $mid=0, $aid=0) {
956    
957      $form = messagebox_form();
958    
959    if(is_numeric(arg(3))) {    if(is_numeric(arg(3))) {
960          //is a reply.. store it if necessary          //is a reply.. store it if necessary
961        $mid = arg(3);        $mid = arg(3);
962        drupal_set_message('Replying to: ' . $mid);                          $msg = db_fetch_object(db_query('SELECT * FROM {messenger} WHERE mid=%d', $mid));
963    
964                            $form['fieldset']['messagebox_message']['#default_value'] =
965                                    t('Forwarded Message') . "\n" .
966                                    t('From: ') . $msg->name . "\n" .
967            $msg->message;
968    }    }
969    
970    if(is_numeric(arg(4))) {    if(is_numeric(arg(4))) {
# Line 1033  function messagebox_new($user) { Line 972  function messagebox_new($user) {
972          $aid = arg(4);          $aid = arg(4);
973    }    }
974    
   $form = messagebox_form();  
975    unset($form['fieldset']['messagebox_submit']);    unset($form['fieldset']['messagebox_submit']);
976    $form['messagebox_aid'] = array(    $form['messagebox_aid'] = array(
977      '#type' => 'value',      '#type' => 'value',

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2