| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Email Queue API 19 * 20 * @package CoreAPI 21 * @subpackage EmailQueueAPI 22 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 23 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 24 * @link http://www.mantisbt.org 25 * 26 * @uses constant_api.php 27 * @uses database_api.php 28 * @uses error_api.php 29 * @uses lang_api.php 30 * @uses utility_api.php 31 */ 32 33 require_api( 'constant_inc.php' ); 34 require_api( 'database_api.php' ); 35 require_api( 'error_api.php' ); 36 require_api( 'lang_api.php' ); 37 require_api( 'utility_api.php' ); 38 39 /** 40 * EmailData Structure Definition 41 * @package MantisBT 42 * @subpackage classes 43 */ 44 class EmailData { 45 // properties set during creation 46 var $email = ''; 47 var $subject = ''; 48 var $body = ''; 49 var $metadata = array( 50 'headers' => array(), 51 ); 52 53 // auto-populated properties 54 var $email_id = 0; 55 var $submitted = ''; 56 }; 57 58 /** 59 * Return a copy of the bug structure with all the instvars prepared for db insertion 60 * @param EmailData $p_email_data 61 * @return EmailData 62 */ 63 function email_queue_prepare_db( $p_email_data ) { 64 $p_email_data->email_id = db_prepare_int( $p_email_data->email_id ); 65 66 return $p_email_data; 67 } 68 69 /** 70 * Add to email queue 71 * @param EmailData $p_email_data 72 * @return int 73 */ 74 function email_queue_add( $p_email_data ) { 75 $t_email_data = email_queue_prepare_db( $p_email_data ); 76 77 # email cannot be blank 78 if( is_blank( $t_email_data->email ) ) { 79 error_parameters( lang_get( 'email' ) ); 80 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 81 } 82 83 # subject cannot be blank 84 if( is_blank( $t_email_data->subject ) ) { 85 error_parameters( lang_get( 'subject' ) ); 86 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 87 } 88 89 # body cannot be blank 90 if( is_blank( $t_email_data->body ) ) { 91 error_parameters( lang_get( 'body' ) ); 92 trigger_error( ERROR_EMPTY_FIELD, ERROR ); 93 } 94 95 $t_email_table = db_get_table( 'email' ); 96 97 $c_email = $t_email_data->email; 98 $c_subject = $t_email_data->subject; 99 $c_body = $t_email_data->body; 100 $c_metadata = serialize( $t_email_data->metadata ); 101 102 $query = "INSERT INTO $t_email_table 103 ( email, 104 subject, 105 body, 106 submitted, 107 metadata) 108 VALUES 109 ( " . db_param() . ", 110 " . db_param() . ", 111 " . db_param() . ", 112 " . db_param() . ", 113 " . db_param() . " 114 )"; 115 db_query_bound( $query, Array( $c_email, $c_subject, $c_body, db_now(), $c_metadata ) ); 116 117 return db_insert_id( $t_email_table, 'email_id' ); 118 } 119 120 /** 121 * Convert email db row to EmailData object 122 * @param array $p_row 123 * @return bool|EmailData 124 */ 125 function email_queue_row_to_object( $p_row ) { 126 # typically this function takes as an input the result of db_fetch_array() which can be false. 127 if( $p_row === false ) { 128 return false; 129 } 130 131 $t_row = $p_row; 132 $t_row['metadata'] = unserialize( $t_row['metadata'] ); 133 134 $t_email_data = new EmailData; 135 136 $t_row_keys = array_keys( $t_row ); 137 $t_vars = get_object_vars( $t_email_data ); 138 139 # Check each variable in the class 140 foreach( $t_vars as $t_var => $t_value ) { 141 # If we got a field from the DB with the same name 142 if( in_array( $t_var, $t_row_keys, true ) ) { 143 144 # Store that value in the object 145 $t_email_data->$t_var = $t_row[$t_var]; 146 } 147 } 148 149 return $t_email_data; 150 } 151 152 /** 153 * Get Corresponding EmailData object 154 * @param int $p_email_id 155 * @return bool|EmailData 156 */ 157 function email_queue_get( $p_email_id ) { 158 $c_email_id = db_prepare_int( $p_email_id ); 159 $t_email_table = db_get_table( 'email' ); 160 161 $query = 'SELECT * FROM ' . $t_email_table . ' WHERE email_id=' . db_param(); 162 $result = db_query_bound( $query, Array( $c_email_id ) ); 163 164 $t_row = db_fetch_array( $result ); 165 166 return email_queue_row_to_object( $t_row ); 167 } 168 169 /** 170 * Delete entry from email queue 171 * @param int $p_email_id 172 * @return null 173 */ 174 function email_queue_delete( $p_email_id ) { 175 $c_email_id = db_prepare_int( $p_email_id ); 176 $t_email_table = db_get_table( 'email' ); 177 178 $query = 'DELETE FROM ' . $t_email_table . ' WHERE email_id=' . db_param(); 179 db_query_bound( $query, Array( $c_email_id ) ); 180 } 181 182 /** 183 * Get array of email queue id's 184 * @return array 185 */ 186 function email_queue_get_ids() { 187 $t_email_table = db_get_table( 'email' ); 188 189 $query = 'SELECT email_id FROM ' . $t_email_table . ' ORDER BY email_id DESC'; 190 $result = db_query_bound( $query ); 191 192 $t_ids = array(); 193 while(( $t_row = db_fetch_array( $result ) ) !== false ) { 194 $t_ids[] = $t_row['email_id']; 195 } 196 197 return $t_ids; 198 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |