Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/message/output/email/message_output_email.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // NOTICE OF COPYRIGHT                                                   //
00006 //                                                                       //
00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00008 //          http://moodle.com                                            //
00009 //                                                                       //
00010 // Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
00011 //                                                                       //
00012 // This program is free software; you can redistribute it and/or modify  //
00013 // it under the terms of the GNU General Public License as published by  //
00014 // the Free Software Foundation; either version 2 of the License, or     //
00015 // (at your option) any later version.                                   //
00016 //                                                                       //
00017 // This program is distributed in the hope that it will be useful,       //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00020 // GNU General Public License for more details:                          //
00021 //                                                                       //
00022 //          http://www.gnu.org/copyleft/gpl.html                         //
00023 //                                                                       //
00025 
00033 require_once($CFG->dirroot.'/message/output/lib.php');
00034 
00035 class message_output_email extends message_output {
00040     function send_message($eventdata) {
00041         global $CFG;
00042 
00043         if (!empty($CFG->noemailever)) {
00044             // hidden setting for development sites, set in config.php if needed
00045             debugging('$CFG->noemailever active, no email message sent.', DEBUG_MINIMAL);
00046             return true;
00047         }
00048 
00049         // skip any messaging suspended and deleted users
00050         if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
00051             return true;
00052         }
00053 
00054         //the user the email is going to
00055         $recipient = null;
00056 
00057         //check if the recipient has a different email address specified in their messaging preferences Vs their user profile
00058         $emailmessagingpreference = get_user_preferences('message_processor_email_email', null, $eventdata->userto);
00059         $emailmessagingpreference = clean_param($emailmessagingpreference, PARAM_EMAIL);
00060         if (!empty($emailmessagingpreference)) {
00061             //clone to avoid altering the actual user object
00062             $recipient = clone($eventdata->userto);
00063             $recipient->email = $emailmessagingpreference;
00064         } else {
00065             $recipient = $eventdata->userto;
00066         }
00067         $result = email_to_user($recipient, $eventdata->userfrom, $eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);
00068 
00069         return $result;
00070     }
00071 
00076     function config_form($preferences){
00077         global $USER, $OUTPUT;
00078 
00079         $inputattributes = array('size'=>'30', 'name'=>'email_email', 'value'=>$preferences->email_email);
00080         $string = get_string('email','message_email') . ': ' . html_writer::empty_tag('input', $inputattributes);
00081 
00082         if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
00083             $string .= ' ('.get_string('default').': '.s($preferences->userdefaultemail).')';
00084         }
00085 
00086         if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {
00087             $string .= $OUTPUT->container(get_string('invalidemail'), 'error');
00088         }
00089 
00090         return $string;
00091     }
00092 
00098     function process_form($form, &$preferences){
00099         if (isset($form->email_email)) {
00100             $preferences['message_processor_email_email'] = $form->email_email;
00101         }
00102     }
00103 
00109     public function get_default_messaging_settings() {
00110         return MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF;
00111     }
00112 
00118     function load_data(&$preferences, $userid){
00119         $preferences->email_email = get_user_preferences( 'message_processor_email_email', '', $userid);
00120     }
00121 }
 All Data Structures Namespaces Files Functions Variables Enumerations