PHPOpenChat PHP Cross Reference Customer Relationship Management

Source: /mail.php - 427 lines - 16034 bytes - Summary - Text - Print

   1  <?php //-*-php-*-
   2  /*   ********************************************************************   **
   3  **   Copyright notice                                                       **
   4  **                                                                          **
   5  **   (c) 1995-2004 PHPOpenChat Development Team                             **
   6  **   http://phpopenchat.sourceforge.net/                                    **
   7  **                                                                          **
   8  **   All rights reserved                                                    **
   9  **                                                                          **
  10  **   This script is part of the PHPOpenChat project. The PHPOpenChat        **
  11  **   project is free software; you can redistribute it and/or modify        **
  12  **   it under the terms of the GNU General Public License as published by   **
  13  **   the Free Software Foundation; either version 2 of the License, or      **
  14  **   (at your option) any later version.                                    **
  15  **                                                                          **
  16  **   The GNU General Public License can be found at                         **
  17  **   http://www.gnu.org/copyleft/gpl.html.                                  **
  18  **   A copy is found in the textfile GPL and important notices to the       **
  19  **   license from the team is found in the textfile LICENSE distributed     **
  20  **   with these scripts.                                                    **
  21  **                                                                          **
  22  **   This script is distributed in the hope that it will be useful,         **
  23  **   but WITHOUT ANY WARRANTY; without even the implied warranty of         **
  24  **   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          **
  25  **   GNU General Public License for more details.                           **
  26  **                                                                          **
  27  **   This copyright notice MUST APPEAR in all copies of the script!         **
  28  **   ********************************************************************   */
  29  
  30  /*
  31    $Author: letreo $
  32    $Date: 2004/02/25 22:11:06 $
  33    $Source: /cvsroot/phpopenchat/chat3/mail.php,v $
  34    $Revision: 1.30.2.7 $
  35  */
  36  
  37  //Get default values
  38  require_once ('config.inc.php');
  39  
  40  require_once (POC_INCLUDE_PATH.'/adodb/adodb.inc.php');
  41  require_once (POC_INCLUDE_PATH.'/class.Chat.inc');
  42  require_once (POC_INCLUDE_PATH.'/class.Chatter.inc');
  43  require_once (POC_INCLUDE_PATH.'/class.Translator.inc');
  44  require_once (POC_INCLUDE_PATH.'/class.Template.inc');
  45  require_once (POC_INCLUDE_PATH.'/class.Mail.inc');
  46  require_once (POC_INCLUDE_PATH.'/class.Mailbox.inc');
  47  require_once (POC_INCLUDE_PATH.'/class.Mail_Dispatcher.inc');
  48  
  49  session_start();
  50  
  51  //check if chatter is authorized to get this page
  52  if( !isset($_SESSION['chatter']) )
  53    die('Login first!');
  54  
  55  $_SESSION['reload_count'] = 0;//reset chat session expiration time
  56  if( $_SESSION['chatter']->is_guest() )
  57    die($_SESSION['translator']->out('DENIED_FOR_GUESTS'));
  58    
  59  $errors = array();
  60  if( isset($_POST['display_content']) && $_POST['display_content'] == 'compose' )
  61    $_GET['display_content'] = $_POST['display_content'];
  62  
  63  function count_all_mails()
  64  {
  65    $inbox  = &new POC_Mailbox( 'inbox' );
  66    $outbox = &new POC_Mailbox( 'outbox' );
  67    $trash  = &new POC_Mailbox( 'trash' );
  68    
  69    $_SESSION['inbox_count_new'] = $inbox->get_unread_mail_count(); 
  70    $_SESSION['outbox_count_new'] = $outbox->get_unread_mail_count(); 
  71    $_SESSION['trash_count_new'] = $trash->get_unread_mail_count();
  72    
  73    unset($inbox);
  74    unset($outbox);
  75    unset($trash);
  76  }
  77  
  78  function reload_mailbox()
  79  {
  80    $mailbox = &new POC_Mailbox( $_SESSION['current_mailbox_type'] );
  81    $_SESSION['mailbox'] = $mailbox;
  82  }
  83    
  84  function load_subjects()
  85  {
  86    global $TEMPLATE_OUT;
  87    
  88    if( !$_SESSION['mailbox']->is_empty() )
  89    {
  90      $mail_count = $_SESSION['mailbox']->get_mail_count();
  91      $TEMPLATE_OUT['subjects'] = '';
  92      for ($i = 0; $i <= $mail_count-1; $i++)
  93      {
  94        $mail = $_SESSION['mailbox']->get_current_mail( $i );
  95        
  96        if( isset($_SESSION['curr_mail_idx']) 
  97               && $_SESSION['curr_mail_idx'] != null 
  98               && $_SESSION['curr_mail_idx'] == $i )
  99          $class = 'active';
 100        else 
 101          $class = '';
 102          
 103        $sender = $mail->get_sender();
 104              
 105        if( $mail->is_red_by_recipient() ) {
 106          $mail_icon = '<img src="'.$_SESSION['template']->get_theme_path().'/images/icons/openmail.gif" alt="red mail" border="0" />';
 107          $newmail= '';
 108          $newmail_class= '';
 109        } else {
 110          $mail_icon = '<img src="'.$_SESSION['template']->get_theme_path().'/images/icons/newmail.gif" alt="new mail" border="0" />';
 111          $newmail= 'style="font-weight: bolder;"';
 112          $newmail_class=(empty($class))? 'boldLink':' boldLink';
 113        }
 114        if( $mail->get_last_touch_recipient() > 0 )
 115          $rcpt_last_touch = gmdate('d.m.y H:i', $mail->get_last_touch_recipient());
 116        else
 117          $rcpt_last_touch = '--';
 118        $TEMPLATE_OUT['subjects'] .= '
 119              <tr>
 120                <td style="width:30px" class="noDeco">
 121                  <a class="imageLink" href="mail.php?display_content=mailbody&amp;body='.$i.'">'.$mail_icon.'</a></td>
 122                <td class="'.$class.'" '.$newmail.'>
 123                  &nbsp;<a href="mail.php?display_content=mailbody&amp;body='.$i.'" class="'.$class.$newmail_class.'">'.$mail->get_subject().'</a>
 124                </td>
 125                <td class="'.$class.'" '.$newmail.'>
 126                  <a href="mail.php?display_content=mailbody&amp;body='.$i.'" class="'.$class.$newmail_class.'">'.$_SESSION['mailbox']->get_chatter( $mail, $_SESSION['chatter']->get_nick() ).'</a>
 127                </td>
 128                <td class="'.$class.'" '.$newmail.'>
 129                  <a href="mail.php?display_content=mailbody&amp;body='.$i.'" class="'.$class.$newmail_class.'">'.gmdate('d.m.y H:i', $mail->get_send_time()).'</a>
 130                </td>
 131                <td class="'.$class.'" '.$newmail.'>
 132                  <a href="mail.php?display_content=mailbody&amp;body='.$i.'" class="'.$class.$newmail_class.'">'.$rcpt_last_touch.'</a>
 133                </td>
 134              </tr>
 135        ';
 136      }
 137    }
 138  }
 139  
 140  if( isset($_GET['trash']) )
 141  {
 142    $dispatcher = &new POC_Mail_Dispatcher();
 143    $mail = $_SESSION['mailbox']->get_current_mail( $_GET['trash'] );
 144    $dispatcher->trash_mail( $mail, $_SESSION['mailbox'], $_SESSION['chatter']);
 145  
 146    unset($dispatcher);
 147    unset($mail);
 148    
 149    //delete mail from session array
 150    //$_GET['trash'] is verified by dispatcher
 151    $_SESSION['mailbox']->delete_mail($_GET['trash']);
 152    $_SESSION['curr_mail_idx'] = null;
 153  }
 154  
 155  if( isset($_POST['send_mail']) )
 156  {      
 157    $recipients = array();
 158    $recipients = explode(',', $_POST['recipient']);
 159    $recipients = array_unique ($recipients);
 160    $dispatcher = &new POC_Mail_Dispatcher();
 161    
 162    while( true )
 163    {
 164      if( !isset($_POST['recipient']) || !$dispatcher->check_recipient($recipients) )
 165      {
 166        $errors[] = $_SESSION['translator']->out('NO_SUCH_RECIPIENT_FOUND');
 167        break;
 168      }
 169      
 170      //Create mail object
 171      $mail = &new POC_Mail();
 172      reset($recipients);
 173      do {
 174        $mail->add_recipient( current($recipients) );
 175      }while( next($recipients) );
 176      unset($recipients);
 177      if( is_string($_POST['subject']) && $_POST['subject'] != '' )
 178        $mail->set_subject( $_POST['subject'] );
 179      else
 180        $mail->set_subject( '(no subject)' );
 181    
 182      if( is_string($_POST['body']) && strlen($_POST['body']) >= MIN_MAIL_LENGTH )
 183        $mail->set_body( $_POST['body'].NL );
 184      else
 185      {
 186        $errors[] = $_SESSION['translator']->out('BODY_TO_SHORT');
 187        break;
 188      }
 189    
 190      $mail->set_send_time(time());
 191      //Send mail
 192      $dispatcher->send_mail($mail);
 193      unset($dispatcher);
 194      unset($mail);
 195      break;
 196    }
 197  }
 198  
 199  $mail_form = '';
 200  $TEMPLATE_OUT['mail_body'] = '';
 201  $TEMPLATE_OUT['title']     = '';
 202  $TEMPLATE_OUT['subjects']  = '';
 203  $TEMPLATE_OUT['body']      = '';
 204  $TEMPLATE_OUT['class_inbox'] = '';
 205  $TEMPLATE_OUT['class_outbox'] = '';
 206  $TEMPLATE_OUT['class_trash'] = '';
 207  $reply_attribute= '';
 208  $TEMPLATE_OUT['mail_body'] = '';
 209  $TEMPLATE_OUT['mail_subject'] = '';
 210  $TEMPLATE_OUT['mail_to'] = '';
 211  
 212  if( !isset($_GET['display_content']) )
 213    $_GET['display_content'] = '';
 214  
 215  while( count($errors) == 0 )
 216  {
 217    switch ( $_GET['display_content'] )
 218    {
 219      case 'compose':
 220        $TEMPLATE_OUT['title'] = '&nbsp;'.$_SESSION['translator']->out('MAIL').' - '.$_SESSION['translator']->out(strtoupper($_GET['display_content']));
 221        break;
 222      case 'reply':
 223        if( !isset($_SESSION['curr_mail_idx']) 
 224        || is_null($_SESSION['curr_mail_idx']))
 225        {
 226          $errors[] = 'no mail index given';
 227          break 2;
 228        }
 229        $TEMPLATE_OUT['title'] = '&nbsp;'.$_SESSION['translator']->out('MAIL').' - '.$_SESSION['translator']->out(strtoupper($_GET['display_content']));
 230        $mail = $_SESSION['mailbox']->get_current_mail( $_SESSION['curr_mail_idx'] );
 231        $sender_obj = $mail->get_sender();
 232        $TEMPLATE_OUT['mail_to'] = $sender_obj->get_nick();
 233        $TEMPLATE_OUT['mail_subject'] = $mail->get_subject();
 234        $TEMPLATE_OUT['mail_subject'] = preg_replace('/^Re: (.*)|^(.*)/', 'Re: \0', $TEMPLATE_OUT['mail_subject']);
 235        $TEMPLATE_OUT['mail_body'] = $mail->get_body();
 236        $TEMPLATE_OUT['mail_body'] = preg_replace('/(.*)\r\n|(.*)\r|(.*)\n/', '> \0', $TEMPLATE_OUT['mail_body']);
 237        break;
 238      case 'forward':
 239        if( !isset($_SESSION['curr_mail_idx']) 
 240        || is_null($_SESSION['curr_mail_idx']))
 241        {
 242          $errors[] = 'no mail index given';
 243          break 2;
 244        }
 245        $TEMPLATE_OUT['title'] = '&nbsp;'.$_SESSION['translator']->out('MAIL').' - '.$_SESSION['translator']->out(strtoupper($_GET['display_content']));
 246        $mail = $_SESSION['mailbox']->get_current_mail( $_SESSION['curr_mail_idx'] );
 247        $sender_obj = $mail->get_sender();
 248        $sender = $sender_obj->get_nick();
 249        $TEMPLATE_OUT['mail_subject'] = $mail->get_subject();
 250        $TEMPLATE_OUT['mail_subject'] = preg_replace('/^(.*)/', 'Fwd: \0', $TEMPLATE_OUT['mail_subject']);
 251        $TEMPLATE_OUT['mail_body'] = '
 252    
 253    
 254    -------- Original Message --------
 255    Send date: '.gmdate('D, d M Y H:i:s O', $mail->get_send_time()).'
 256    From: '.$sender.'
 257    To: '.$mail->get_recipient().'
 258    X-Mailer: POC-Mail (http://phpopenchat.sourceforge.net/)
 259    
 260    
 261    ';
 262        $TEMPLATE_OUT['mail_body'] .= $mail->get_body();
 263        break;
 264      case 'mailbody':
 265        if( !isset($_SESSION['mailbox']) ){
 266          $current_mailbox_type = 'inbox';
 267          $_SESSION['current_mailbox_type'] = $current_mailbox_type;
 268    
 269          reload_mailbox();
 270        }
 271    
 272        if( isset($_GET['body']) )
 273        {
 274          $_SESSION['curr_mail_idx'] = $_GET['body'];
 275          $reply_attribute='&amp;insert_content=1';
 276          $mail = $_SESSION['mailbox']->get_current_mail( $_GET['body'] );
 277          
 278          //set mail to 'red by reciepient'
 279          if( $_SESSION['mailbox']->get_type() == 'inbox' 
 280             && !$mail->is_red_by_recipient() )
 281          {
 282            $dispatcher = &new POC_Mail_Dispatcher();
 283            $mail->set_first_touch_recipient();
 284            $mail->set_red_by_recipient();
 285            $dispatcher->make_persistent( $mail );
 286            unset($dispatcher);
 287            reload_mailbox();
 288          }
 289          
 290          if( $_SESSION['mailbox']->get_type() == 'inbox' )
 291          {
 292            $dispatcher = &new POC_Mail_Dispatcher();
 293            $mail->set_last_touch_recipient();
 294            $dispatcher->make_persistent( $mail );
 295            unset($dispatcher);
 296            reload_mailbox();        
 297          }
 298          
 299          //set mail to 'red by sender'
 300          if( $_SESSION['mailbox']->get_type() == 'outbox' 
 301             && !$mail->is_red_by_sender() )
 302          {
 303            $dispatcher = &new POC_Mail_Dispatcher();
 304            $mail->set_red_by_sender();
 305            $dispatcher->make_persistent( $mail );
 306            unset($dispatcher);
 307            reload_mailbox();
 308          }
 309          
 310          if($_SESSION['mailbox']->get_type() == 'outbox')
 311          {
 312            $dispatcher = &new POC_Mail_Dispatcher();
 313            $mail->set_last_touch_sender();
 314            $dispatcher->make_persistent( $mail );
 315            unset($dispatcher);
 316            reload_mailbox();        
 317          }
 318          if($mail->get_last_touch_recipient() != 0)
 319          {
 320            if($mail->get_first_touch_recipient() != 0)
 321              $rcpt_time = gmdate('d.m.y H:i', $mail->get_first_touch_recipient());
 322            else
 323              $rcpt_time = '--';
 324          }
 325          else 
 326            $rcpt_time = '';
 327            
 328          $TEMPLATE_OUT['body'] = '<div class="header">';
 329          $sender = $mail->get_sender();
 330          $TEMPLATE_OUT['body'].= 'Send date: '.gmdate('d.m.Y H:i', $mail->get_send_time()).'<br/>';
 331          $TEMPLATE_OUT['body'].= 'Opened by recipient: '.$rcpt_time.'<br/>';
 332          $TEMPLATE_OUT['body'].= 'From: '.$sender->get_nick().'<br/>';
 333          $TEMPLATE_OUT['body'].= 'To: '.$mail->get_recipient().'<br/>';
 334          $TEMPLATE_OUT['body'].= '</div>';
 335          $TEMPLATE_OUT['body'].= preg_replace('/\r\n|\r|\n/', '<br/>', $mail->get_body());
 336        }
 337        load_subjects();
 338        break;
 339      default:
 340        if( $_GET['display_content'] != '' )
 341          die('no such option');
 342        else 
 343        {
 344          if( isset($_GET['current_mailbox_type'] )
 345             && $_GET['current_mailbox_type'] != $_SESSION['current_mailbox_type'])
 346          {
 347            $_SESSION['curr_mail_idx'] = null;
 348            $current_mailbox_type = $_GET['current_mailbox_type'];
 349            $_SESSION['current_mailbox_type'] = $current_mailbox_type;
 350            
 351            reload_mailbox();
 352          }
 353          elseif( !isset($_SESSION['current_mailbox_type']) )
 354          {
 355            $current_mailbox_type = 'inbox';
 356            $_SESSION['current_mailbox_type'] = $current_mailbox_type;
 357            
 358            reload_mailbox();
 359          }
 360          elseif( isset($_GET['trash']) || isset($_GET['reload_mailbox']) )
 361          {
 362            //reload current mailbox
 363            reload_mailbox();
 364          }
 365          
 366          load_subjects();
 367        }
 368    }
 369    break;
 370  }
 371  //${'class_'.$_SESSION['current_mailbox_type']} = 'class="active"';
 372  $TEMPLATE_OUT['mark_'.$_SESSION['current_mailbox_type']]='border-top: thin solid black;border-bottom: thin solid black;';
 373  count_all_mails();
 374  $TEMPLATE_OUT['new_in_inbox'] = '';$TEMPLATE_OUT['newmail_inbox'] ='';
 375  $TEMPLATE_OUT['new_in_outbox']= '';$TEMPLATE_OUT['newmail_outbox']='';
 376  $TEMPLATE_OUT['new_in_trash'] = '';$TEMPLATE_OUT['newmail_trash'] ='';
 377  
 378  if($_SESSION['inbox_count_new'] > 0)
 379  {
 380    $TEMPLATE_OUT['new_in_inbox'] = '<strong>('.$_SESSION['inbox_count_new'].')</strong>';
 381    $TEMPLATE_OUT['newmail_inbox'] = 'font-weight: bolder;';
 382  }
 383  if($_SESSION['outbox_count_new'] > 0)
 384  {
 385    $TEMPLATE_OUT['new_in_outbox'] = '<strong>('.$_SESSION['outbox_count_new'].')</strong>';
 386    $TEMPLATE_OUT['newmail_outbox'] = 'font-weight: bolder;';
 387  }
 388   
 389  if($_SESSION['trash_count_new'] > 0)
 390  {
 391    $TEMPLATE_OUT['new_in_trash'] = '<strong>('.$_SESSION['trash_count_new'].')</strong>';
 392    $TEMPLATE_OUT['newmail_trash'] = 'font-weight: bolder;';
 393  }
 394  
 395  $friends = array();
 396  $friends = $_SESSION['chatter']->get_friends();
 397  $TEMPLATE_OUT['friends_links'] = '';
 398  if( count($friends) > 0 )
 399  {
 400    reset($friends);
 401    do
 402    {
 403      $TEMPLATE_OUT['friends_links'] .= TAB.'<a href="#" onclick="insertValue(\''.current($friends).'\'); toggleDiv(\'friendsList\')" class="friend">'.current($friends).'</a><br />'.NL;
 404    }while( next($friends) );
 405  }
 406  else
 407    $TEMPLATE_OUT['friends_links'] = $_SESSION['translator']->out('NO_FRIENDS_FOUND');
 408  
 409  $TEMPLATE_OUT['error'] = '';
 410  if( count($errors) != 0 )
 411  {
 412    $TEMPLATE_OUT['error'] = '<ul class="error">';
 413    reset($errors);
 414    do{
 415      $TEMPLATE_OUT['error'] .= '<li>'.current($errors).'</li>';
 416    }while( next($errors) );
 417    $TEMPLATE_OUT['error'] .= '</ul>';
 418    
 419    if( isset($_POST['subject']) )
 420      $TEMPLATE_OUT['mail_subject'] = $_POST['subject'];
 421    if( isset($_POST['recipient']) )
 422      $TEMPLATE_OUT['mail_to'] = $_POST['recipient'];
 423    if( isset($_POST['body']) )
 424      $TEMPLATE_OUT['mail_body'] = $_POST['body'];
 425  }
 426  $_SESSION['template']->get_template();
 427  ?>

title

Description

title

Description

title

Description

title

title

Body