Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmail/user/mailedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: mailedit.php 9363 2002-03-23 13:24:54Z fh $
5 //
6 // Created on: <23-Oct-2000 17:53:46 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlocale.php" );
30 // include_once( "classes/ezhttptool.php" );
31 // include_once( "ezfilemanager/classes/ezvirtualfile.php" );
32 // include_once( "ezmail/classes/ezmail.php" );
33 // include_once( "ezuser/classes/ezuser.php" );
34 // include_once( "ezsession/classes/ezpreferences.php" );
35
36 if ( isset( $MailID ) && $MailID != 0 && !eZMail::isOwner( eZUser::currentUser(), $MailID ) )
37 {
38 eZHTTPTool::header( "Location: /error/403/" );
39 exit();
40 }
41
42 if ( isset( $Cancel ) )
43 {
44 if ( $MailID != 0 )
45 {
46 $mail = new eZMail( $MailID );
47 $folderID = $mail->folder( false );
48 }
49 else
50 {
51 $inbox = eZMailFolder::getSpecialFolder( INBOX );
52 $folderID = $inbox->id();
53 }
54 eZHTTPTool::header( "Location: /mail/folder/$folderID" );
55 exit();
56 }
57
58 if ( isset( $ToButton ) )
59 {
60 eZHTTPTool::header( "Location: /contact/person/list" );
61 exit();
62 }
63
64 if ( isset( $AddAttachment ) )
65 {
66 $MailID = save_mail();
67 eZHTTPTool::header( "Location: /mail/fileedit/$MailID" );
68 exit();
69 }
70
71 if ( isset( $DeleteAttachments ) && count( $AttachmentArrayID ) > 0 )
72 {
73 foreach ( $AttachmentArrayID as $attachmentID )
74 {
75 $mail = new eZMail( $MailID );
76 $file = new eZVirtualFile( $attachmentID );
77 $mail->deleteFile( $file );
78 }
79 }
80
81 if ( isset( $Save ) )
82 {
83 $MailID = save_mail();
84 if ( isset( $IDList ) )
85 {
86 $id_array = preg_split( "/;/", $IDList );
87 foreach ( $id_array as $idItem )
88 {
89 eZMail::addContact( $MailID, $idItem, $CompanyList );
90 }
91 }
92 $mail = new eZMail( $MailID );
93 $mail->setStatus( 'READ', true );
94
95 $drafts = eZMailFolder::getSpecialFolder( DRAFTS );
96 $drafts->addMail( $mail );
97 }
98
99 if ( isset( $Preview ) )
100 {
101 $MailID = save_mail();
102 eZHTTPTool::header( "Location: /mail/view/$MailID" );
103 exit();
104 }
105
106 if ( isset( $Send ) )
107 {
108 $MailID = save_mail();
109 if ( isset( $IDList ) )
110 {
111 $id_array = preg_split( "/;/", $IDList );
112 foreach ( $id_array as $idItem )
113 {
114 if ( is_numeric( $idItem ) )
115 eZMail::addContact( $MailID, $idItem, $CompanyList );
116 }
117 }
118 // give error message if no valid users where supplied...
119 $mail = new eZMail( $MailID );
120 if ( $mail->to() == "" && $mail->bcc() == "" && $mail->cc() == "" )
121 {
122 $error = "no_address";
123 }
124 else
125 {
126 $mail->setStatus( 4, true );
127 $mail->send();
128
129 $sent = eZMailFolder::getSpecialFolder( SENT );
130 $sent->addMail( $mail );
131
132 $sentid = $sent->id();
133 eZHTTPTool::header( "Location: /mail/folder/$sentid" );
134 exit();
135 }
136 }
137
138 if ( isset( $CcButton ) )
139 $showcc = true;
140 if ( isset( $BccButton ) )
141 $showbcc = true;
142
143 $ini =& eZINI::instance( 'site.ini' );
144 $Language = $ini->variable( "eZMailMain", "Language" );
145
146 $t = new eZTemplate( "kernel/ezmail/user/" . $ini->variable( "eZMailMain", "TemplateDir" ),
147 "kernel/ezmail/user/intl/", $Language, "mailedit.php" );
148
149 $languageIni = new eZINI( "kernel/ezmail/user/intl/" . $Language . "/mailedit.php.ini", false );
150 $t->setAllStrings();
151
152 $t->set_file( "mail_edit_page_tpl", "mailedit.tpl" );
153
154 $t->set_block( "mail_edit_page_tpl", "error_message_tpl", "error_message" );
155 $t->set_block( "mail_edit_page_tpl", "attachment_delete_tpl", "attachment_delete" );
156 $t->set_block( "mail_edit_page_tpl", "inserted_attachments_tpl", "inserted_attachments" );
157 $t->set_block( "mail_edit_page_tpl", "bcc_single_tpl", "bcc_single" );
158 $t->set_block( "mail_edit_page_tpl", "cc_single_tpl", "cc_single" );
159 $t->set_block( "inserted_attachments_tpl", "attachment_tpl", "attachment" );
160 $t->set_var( "inserted_attachments", "" );
161 $t->set_var( "attachment_delete", "" );
162
163 $t->set_var( "error_message", "" );
164 $t->set_var( "site_style", $siteDesign );
165
166 $to_string = "";
167 $id_string = "";
168 $company_list = false;
169
170 if( isset( $toArray["Email"] ) )
171 for ( $i = 0; $i < count( $toArray["Email"] ); $i++ )
172 {
173 $to_string .= $toArray["Email"][$i];
174 $id_string .= $toArray["ID"][$i];
175 if ( ( $i + 1 ) < count( $toArray["Email"] ) )
176 {
177 $to_string .= "; ";
178 $id_string .= ";";
179 }
180 else
181 {
182 $company_list = $toArray["CompanyEdit"];
183 }
184 }
185
186 $t->set_var( "to_value", $to_string );
187 $t->set_var( "id_value", $id_string );
188 $t->set_var( "company_value", $company_list );
189 $t->set_var( "from_value", "" );
190 $t->set_var( "cc_value", "" );
191 $t->set_var( "bcc_value", "" );
192 $t->set_var( "subject_value", "" );
193 $t->set_var( "mail_body", "" );
194 $t->set_var( "current_mail_id", "" );
195 $t->set_var( "cc_single", "" );
196 $t->set_var( "bcc_single", "" );
197
198 // New mail, lets insert some default values
199 if ( isset( $MailID ) && $MailID == 0 )
200 {
201 $auto_signature =& eZPreferences::variable( "eZMail_AutoSignature" );
202 $signature =& eZPreferences::variable( "eZMail_Signature" );
203 if( $auto_signature && $auto_signature == "true" && $signature != "" )
204 {
205 $comp_sign = "--\n$signature";
206 $t->set_var( "mail_body", htmlspecialchars( $comp_sign ) );
207 }
208 }
209 $user =& eZUser::currentUser();
210 $t->set_var( "from_value", $user->email() );
211
212 // We are editing an allready existant mail... lets insert it's values
213 if ( isset( $MailID ) && $MailID != 0 && eZMail::isOwner( $user, $MailID ) ) // load values from disk!, check that this is really current users mail
214 {
215 $t->set_var( "current_mail_id", $MailID );
216
217 $mail = new eZMail( $MailID );
218 $t->set_var( "to_value", htmlspecialchars( $mail->to() ) );
219
220 if ( $mail->from() != "" )
221 $t->set_var( "from_value", htmlspecialchars( $mail->from() ) );
222 $t->set_var( "subject_value", htmlspecialchars( $mail->subject() ) );
223
224 if( isset( $Signature ) )
225 {
226 $signature =& eZPreferences::variable( "eZMail_Signature" );
227 $mail_body = $mail->body();
228 $comp_sign = "$mail_body\n\n--\n$signature";
229 $t->set_var( "mail_body", htmlspecialchars( $comp_sign ) );
230 }
231 else
232 {
233 $t->set_var( "mail_body", htmlspecialchars( $mail->body() ) );
234 }
235
236 if ( $mail->cc() != "" )
237 {
238 $showcc = true;
239 $t->set_var( "cc_value", htmlspecialchars( $mail->cc() ) );
240 }
241
242 if ( $mail->bcc() != "" )
243 {
244 $showbcc = true;
245 $t->set_var( "bcc_value", htmlspecialchars( $mail->bcc() ) );
246 }
247
248 $files = $mail->files();
249 $i = 0;
250 foreach ( $files as $file )
251 {
252 $t->set_var( "file_name", htmlspecialchars( $file->originalFileName() ) );
253 $t->set_var( "file_id", $file->id() );
254
255 $size = $file->siFileSize();
256 $t->set_var( "file_size", $size["size-string"] . $size["unit"] );
257
258 ( $i % 2 ) ? $t->set_var( "td_class", "bgdark" ) : $t->set_var( "td_class", "bglight" );
259
260 $t->parse( "attachment", "attachment_tpl", true );
261 $i++;
262 }
263 if ( $i > 0 )
264 {
265 $t->parse( "attachment_delete", "attachment_delete_tpl" );
266 $t->parse( "inserted_attachments", "inserted_attachments_tpl", false );
267 }
268 }
269 else if ( isset( $MailID ) && $MailID == 0 && ( isset( $showcc ) && $showcc || isset( $showbcc) && $showbcc || isset( $Signature ) && $Signature ) ) //mail not saved, but there is data
270 {
271 $t->set_var( "to_value", htmlspecialchars( $To ) );
272 $t->set_var( "id_value", $IDList );
273 $t->set_var( "company_value", $CompanyList );
274 $t->set_var( "from_value", htmlspecialchars( $From ) );
275 $t->set_var( "cc_value", htmlspecialchars( $Cc ) );
276 $t->set_var( "bcc_value", htmlspecialchars( $Bcc ) );
277 $t->set_var( "subject_value", htmlspecialchars( $Subject ) );
278 if( $Signature )
279 {
280 $signature =& eZPreferences::variable( "eZMail_Signature" );
281 if( $signature != "" )
282 {
283 $comp_sign = "$MailBody\n\n--\n$signature";
284 $t->set_var( "mail_body", htmlspecialchars( $comp_sign ) );
285 }
286 }
287 else
288 {
289 $t->set_var( "mail_body", htmlspecialchars( $MailBody ) );
290 }
291 if ( $Cc != "" )
292 $showcc = true;
293 if ( $Bcc != "" )
294 $showbcc = true;
295 }
296
297 // check if we have any errors... if yes. show them to the user
298 if ( isset( $error ) )
299 {
300 $t->set_var( "mail_error_message", $languageIni->variable( "strings", "address_error" ) );
301 $t->parse( "error_message", "error_message_tpl", true );
302 }
303
304 if ( isset( $showcc ) )
305 $t->parse( "cc_single", "cc_single_tpl", false );
306 if ( isset( $showbcc ) )
307 $t->parse( "bcc_single", "bcc_single_tpl", false );
308
309 $t->pparse( "output", "mail_edit_page_tpl" );
310
311 /*********************** FUNCTIONS ***************************************/
312
313 /*
314 Saves the mail and returns the ID of the saved mail.
315 */
316 function save_mail()
317 {
318 global $To, $From, $Cc, $Bcc, $Subject, $MailBody, $MailID; // instead of passing them as arguments..
319
320 if ( $MailID == 0 )
321 {
322 $mail = new eZMail();
323 $mail->setOwner( eZUser::currentUser() );
324 }
325 else
326 {
327 $mail = new eZMail( $MailID );
328 }
329 $mail->setTo( $To );
330 $mail->setFrom( $From ); // from NAME
331 $mail->setCc( $Cc );
332 $mail->setBcc( $Bcc );
333 $mail->setStatus( 0, true );
334 // $mail->setReferences( );
335 // $mail->setReplyTo( $ );
336 $mail->setSubject( $Subject );
337 $mail->setBodyText( $MailBody );
338 $mail->calculateSize();
339
340 $mail->store();
341 $folder = eZMailFolder::getSpecialFolder( DRAFTS );
342 $folder->addMail( $mail );
343
344 return $mail->id();
345 }
346
347 ?>
$i
$i
Definition: admin/adlist.php:91
$Signature
$Signature
Definition: admin/useredit.php:417
$files
$files
Definition: articlepreview.php:91
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZINI
Reads and writes .ini style configuration files.
eZMailFolder\getSpecialFolder
static getSpecialFolder( $specialType, $user=false)
Definition: ezmailfolder.php:477
eZMail
Definition: ezmail.php:57
eZMail\isOwner
static isOwner( $user, $mailID)
Definition: ezmail.php:867
eZMail\addContact
addContact( $mailID, $contactID, $companyEdit=true)
Definition: ezmail.php:179
eZPreferences\variable
static variable( $name, $group=false)
Definition: ezpreferences.php:95
eZTemplate
Definition: eztemplate.php:107
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFile
Definition: ezvirtualfile.php:42
$error
$error
Definition: ezarticle/admin/categoryedit.php:51
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
$folder
if(!isset( $FolderID)) $folder
Definition: ezfilemanager/admin/browse.php:74
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$languageIni
$languageIni
Definition: ezmail/user/mailedit.php:149
$t
$t
Definition: ezmail/user/mailedit.php:146
save_mail
save_mail()
Definition: ezmail/user/mailedit.php:316
$to_string
$to_string
Definition: ezmail/user/mailedit.php:166
$company_list
$company_list
Definition: ezmail/user/mailedit.php:168
$Language
$Language
Definition: ezmail/user/mailedit.php:144
$ini
$ini
Definition: ezmail/user/mailedit.php:143
$user
if(isset( $MailID) && $MailID==0) $user
Definition: ezmail/user/mailedit.php:209
$id_string
$id_string
Definition: ezmail/user/mailedit.php:167
SENT
const SENT
Definition: ezmailfolder.php:45
DRAFTS
const DRAFTS
Definition: ezmailfolder.php:44
INBOX
const INBOX
Definition: ezmailfolder.php:43
$Subject
$Subject
Definition: ezmessage/user/messageedit.php:117
$Preview
$Preview
Definition: ezmessage/user/messageedit.php:121
exit
exit
Definition: folder.php:81
$toArray
$toArray
Definition: sendmail.php:29
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.