[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> email_queue_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis 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 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis 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 Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: email_queue_api.php,v 1.2.2.1 2007-10-13 22:35:25 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      class EmailData {
  25          // properties set during creation
  26          var $email = '';
  27          var $subject = '';
  28          var $body = '';
  29          var $metadata = array( 'headers' => array() );
  30  
  31          // auto-populated properties
  32          var $email_id = 0;
  33          var $submitted = '';
  34      };
  35  
  36      # --------------------
  37      # Return a copy of the bug structure with all the instvars prepared for db insertion
  38  	function email_queue_prepare_db( $p_email_data ) {
  39          $t_email_data = new EmailData;
  40  
  41          $t_email_data->email_id = db_prepare_int( $p_email_data->email_id );
  42          $t_email_data->email = db_prepare_string( $p_email_data->email );
  43          $t_email_data->subject = db_prepare_string( $p_email_data->subject );
  44          $t_email_data->body = db_prepare_string( $p_email_data->body );
  45  
  46          $t_email_data->metadata = array();
  47  
  48          foreach( $p_email_data->metadata as $t_key => $t_value ) {
  49              if ( $t_key != 'headers' ) {
  50                  $t_email_data->metadata[$t_key] = db_prepare_string( $t_value );
  51              }
  52          }
  53  
  54          foreach( $p_email_data->metadata['headers'] as $t_key => $t_value ) {
  55              $t_email_data->metadata['headers'][$t_key] = db_prepare_string( $t_value );
  56          }
  57  
  58          $t_email_data->submitted = db_prepare_string( $p_email_data->submitted );
  59  
  60          return $t_email_data;
  61      }
  62  
  63      # --------------------
  64  	function email_queue_add( $p_email_data ) {
  65          $t_email_data = email_queue_prepare_db( $p_email_data );
  66  
  67          # email cannot be blank
  68          if ( is_blank( $t_email_data->email ) ) {
  69              error_parameters( lang_get( 'email' ) );
  70              trigger_error( ERROR_EMPTY_FIELD, ERROR );
  71          }
  72  
  73          # subject cannot be blank
  74          if ( is_blank( $t_email_data->subject ) ) {
  75              error_parameters( lang_get( 'subject' ) );
  76              trigger_error( ERROR_EMPTY_FIELD, ERROR );
  77          }
  78  
  79          # body cannot be blank
  80          if ( is_blank( $t_email_data->body ) ) {
  81              error_parameters( lang_get( 'body' ) );
  82              trigger_error( ERROR_EMPTY_FIELD, ERROR );
  83          }
  84  
  85          $t_email_table = config_get( 'mantis_email_table' );
  86  
  87          $c_email = $t_email_data->email;
  88          $c_subject = $t_email_data->subject;
  89          $c_body = $t_email_data->body;
  90          $c_metadata = serialize( $t_email_data->metadata );
  91  
  92          $query = "INSERT INTO $t_email_table
  93                      ( email,
  94                        subject,
  95                        body,
  96                        submitted,
  97                        metadata)
  98                    VALUES
  99                      ( '$c_email',
 100                        '$c_subject',
 101                        '$c_body',
 102                        " . db_now() . ",
 103                        '$c_metadata'
 104                      )";
 105          db_query( $query );
 106  
 107          return db_insert_id( $t_email_table );
 108      }
 109  
 110      # --------------------
 111  	function email_queue_row_to_object( $p_row ) {
 112          # typically this function takes as an input the result of db_fetch_array() which can be false.
 113          if ( $p_row === false ) {
 114              return false;
 115          }
 116  
 117          $t_row = $p_row;
 118          $t_row['submitted']    = db_unixtimestamp( $t_row['submitted'] );
 119          $t_row['metadata'] = unserialize( $t_row['metadata'] );
 120  
 121          $t_email_data = new EmailData;
 122  
 123          $t_row_keys = array_keys( $t_row );
 124          $t_vars = get_object_vars( $t_email_data );
 125  
 126          # Check each variable in the class
 127          foreach ( $t_vars as $t_var => $t_value ) {
 128              # If we got a field from the DB with the same name
 129              if ( in_array( $t_var, $t_row_keys, true ) ) {
 130                  # Store that value in the object
 131                  $t_email_data->$t_var = $t_row[$t_var];
 132              }
 133          }
 134  
 135          return $t_email_data;
 136      }
 137  
 138      # --------------------
 139  	function email_queue_get( $p_email_id ) {
 140          $c_email_id = db_prepare_int( $p_email_id );
 141          $t_email_table = config_get( 'mantis_email_table' );
 142  
 143          $query = "SELECT *
 144                    FROM $t_email_table
 145                    WHERE email_id='$c_email_id'";
 146          $result = db_query( $query );
 147  
 148          $t_row = db_fetch_array( $result );
 149  
 150          return email_queue_row_to_object( $t_row );
 151      }
 152      
 153      # --------------------
 154  	function email_queue_delete( $p_email_id ) {
 155          $c_email_id = db_prepare_int( $p_email_id );
 156          $t_email_table = config_get( 'mantis_email_table' );
 157  
 158          $query = "DELETE FROM $t_email_table
 159                    WHERE email_id='$c_email_id'";
 160          db_query( $query );
 161      }
 162  
 163      # --------------------
 164  	function email_queue_get_ids() {
 165          $t_email_table = config_get( 'mantis_email_table' );
 166  
 167          $query = "SELECT email_id
 168                    FROM $t_email_table
 169                    ORDER BY email_id DESC";
 170          $result = db_query( $query );
 171  
 172          $t_ids = array();
 173          while ( ( $t_row = db_fetch_array( $result ) ) !== false ) {
 174              $t_ids[] = $t_row['email_id'];
 175          }
 176  
 177          return $t_ids;
 178      }
 179  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics