[ PHPXref.com ] [ Generated: Sun Jul 20 19:52:25 2008 ] [ PHPOpenChat 3.0.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/include/ -> class.Mail_Dispatcher.inc (source)

   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  //Get default values
  31  require_once (POC_BASE.'/config.inc.php');
  32  require_once (POC_INCLUDE_PATH.'/class.Logger.inc');
  33  
  34  /**
  35  * Mail_Dispatcher sends and gets mail
  36  *
  37  * @author  Michael Oertel <michael@ortelius.de>
  38  * @access  public
  39  * @version $Id: class.Mail_Dispatcher.inc,v 1.13.2.7 2004/02/24 22:21:06 letreo Exp $
  40  */
  41  class POC_Mail_Dispatcher {
  42    
  43    /**
  44    * @var    object
  45    * @access private
  46    * @see    connect()
  47    */
  48    var $db;
  49    
  50    /**
  51    * @var    integer
  52    * @see    connect()
  53    * @see    disconnect()
  54    */
  55    var $connection_count = 0;
  56  
  57    function POC_Mail_Dispatcher()
  58    {
  59      
  60    }
  61    
  62    /**
  63    * Connect to the database
  64    *
  65    * Establish a database connection
  66    *
  67    * @access public
  68    */
  69    function connect()
  70    {
  71      if( ++$this->connection_count > 1 )
  72        return true;
  73  
  74      //create a database object
  75      $this->db = &NewADOConnection( DATABASE_DRIVER );
  76      if( USE_PCONNECT )
  77        $status = $this->db->PConnect( DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_TABLESPACE );
  78      else
  79        $status = $this->db->Connect( DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_TABLESPACE );
  80  
  81      //$status = $this->db->Execute( 'SELECT name FROM '.DATABASE_TABLE_PREFIX.'channels' );
  82  
  83      return $status;
  84    }
  85  
  86    /**
  87    * Disconnect the database
  88    *
  89    * @access public
  90    * @see connect()
  91    
  92    * @desc Disconnect the database
  93  */
  94    function disconnect()
  95    {
  96      if( --$this->connection_count == 0 )
  97      {
  98        $this->db->Close();
  99        return true;
 100      }
 101      
 102      return null;
 103    }
 104    
 105    /**
 106    * Updates a Mail
 107    *
 108    * @param object
 109    */
 110    function make_persistent( $mail )
 111    {
 112      $sender_obj = $mail->get_sender();
 113      $sender = $sender_obj->get_nick();
 114      unset($sender_obj);
 115      
 116      $this->connect();
 117      $rs = $this->db->Execute( 'SELECT * FROM '.DATABASE_TABLE_PREFIX.'mails WHERE SENDER = \''. $sender .'\' AND RECIPIENT=\''.$mail->get_recipient().'\' AND TIME=\''.gmdate('Y-m-d-H-i-s', $mail->get_send_time()).'\'' );
 118      $record = array();
 119      $record[ 'MAIL' ] = serialize($mail);
 120      
 121      $update_sql = $this->db->GetUpdateSQL( $rs, $record );
 122  
 123      //Insert the records into the database
 124      $this->db->Execute( $update_sql );
 125      $this->disconnect();
 126      unset($record);
 127      unset($update_sql);
 128      unset($rs);
 129      
 130    }
 131    
 132    /**
 133    * Sends a Mail
 134    *
 135    * @param object
 136    */
 137    function send_mail( $mail )
 138    {
 139      $sender_obj = $mail->get_sender();
 140      $sender = $sender_obj->get_nick();
 141      unset($sender_obj);
 142      $recipients = array();
 143      $recipients = $mail->get_recipients();
 144      reset($recipients);
 145      
 146      $this->connect();
 147      $sql1 = 'INSERT INTO '.DATABASE_TABLE_PREFIX.'mails (SENDER,RECIPIENT,MAIL,TIME)';
 148      
 149      $timestamp = $mail->get_send_time();
 150      do 
 151      {
 152        $mail->set_recipient( current($recipients) );
 153        $sql2 = 'VALUES (\''.$sender.'\',\''.current($recipients).'\',\''.serialize($mail).'\',\''.gmdate('Y-m-d-H-i-s', $timestamp).'\')';
 154        
 155        //Insert the records into the database
 156        if ( !$this->db->Execute( $sql1.$sql2 ) )
 157          die ( 'POC: Could\'t send mail, because of a DB-Error.' );
 158        
 159        //notify chatter, if he is online
 160        $_SESSION['chat']->connect();
 161        if(isset( $_SESSION['chat']) && $_SESSION['chat']->is_online( current($recipients) ) ) {
 162            $_chatter = $_SESSION['chat']->mkinstance_chatter(current($recipients));
 163            $_SESSION['chat']->write_sys_msg( $_SESSION['translator']->out('YOU_HAVE_NEW_MAIL'),$_chatter, true );
 164        }
 165        $_SESSION['chat']->disconnect();
 166        
 167      }while( next($recipients) );
 168      $this->disconnect();
 169  
 170      unset( $recipients );
 171      unset( $mail_serialized );
 172      unset( $timestamp );
 173      unset( $sql1 );
 174      unset( $sql2 );
 175    }
 176    
 177    /**
 178    * Check if given recipient exists
 179    *
 180    * @param string
 181    * @return boolean
 182    */
 183    function check_recipient( $recipients )
 184    {
 185        $this->connect();
 186        do
 187        {
 188          $rs = $this->db->Execute( 'SELECT NICK FROM '.DATABASE_TABLE_PREFIX.'user_data WHERE NICK = \''.current($recipients).'\'' );
 189          if($rs->EOF)
 190          {
 191            $rs->Close();
 192            $this->disconnect();
 193            return false;
 194          }
 195            
 196          $rs->Close();
 197        }while( next($recipients) );
 198        
 199        $this->disconnect();
 200        
 201        return true;
 202    }
 203    
 204    /**
 205    * Moves a mail into trashbin
 206    *
 207    * @param object
 208    * @param object
 209    * @param object
 210    * @return boolean
 211    */
 212    function trash_mail( $mail, $mailbox, $chatter )
 213    {
 214      $sender_obj = $mail->get_sender();
 215      $sender     = $sender_obj->get_nick();
 216      
 217      $this->connect();
 218      $rs = $this->db->Execute( 'SELECT * FROM '.DATABASE_TABLE_PREFIX.'mails WHERE SENDER = \''. $sender .'\' AND RECIPIENT=\''.$mail->get_recipient().'\' AND TIME=\''.gmdate('Y-m-d-H-i-s', $mail->get_send_time()).'\'' );
 219      $record = array();
 220      
 221      if ($mailbox->get_type() == 'trash')
 222        $flag = 2;//mail is scheduled to delete and is no longer shown within the trashbin
 223      else
 224        $flag = 1;//mail is scheduled to delete and is no longer shown within the trashbin
 225      
 226      
 227      if( $chatter->get_nick() == $mail->get_recipient() )
 228        $record[ 'TRASHED_BY_RECIPIENT' ] = $flag;
 229      elseif( $chatter->get_nick() == $sender )
 230        $record[ 'TRASHED_BY_SENDER' ]    = $flag;
 231      else 
 232        die('maildispatcher->trash_mail(): Can\'t move mail into trashbin.');
 233      
 234      if( $sender == $mail->get_recipient() )
 235      {
 236        $record[ 'TRASHED_BY_RECIPIENT' ] = $flag;
 237        $record[ 'TRASHED_BY_SENDER' ]    = $flag;
 238      }
 239      
 240      $update_sql = $this->db->GetUpdateSQL( $rs, $record );
 241  
 242      //Insert the records into the database
 243      $this->db->Execute( $update_sql );
 244      
 245      if( $mailbox->get_type() == 'trash' )
 246      {
 247        $rs = $this->db->Execute( 'DELETE FROM '.DATABASE_TABLE_PREFIX.'mails WHERE SENDER = \''. $sender .'\' AND RECIPIENT=\''.$mail->get_recipient().'\' AND TIME=\''.gmdate('Y-m-d-H-i-s', $mail->get_send_time()).'\' AND TRASHED_BY_RECIPIENT=2 AND TRASHED_BY_SENDER=2' );
 248      }
 249  
 250      $this->disconnect();
 251      unset($record);
 252      unset($update_sql);
 253      unset($rs);
 254      
 255      return true;
 256    }
 257    
 258    /**
 259    * Deletes a mail
 260    *
 261    * @param string
 262    * @param string
 263    * @param integer
 264    * @return boolean
 265    */
 266    function delete_mail( $sender, $recipient, $time )
 267    {
 268      
 269    }
 270    
 271    /**
 272    * Checks Mails
 273    *
 274    * @param object
 275    */
 276    function check_mail( $mail )
 277    {
 278    }
 279  }
 280  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]