Remove event template code #2178
	
		
	
				
					
				
			- Tables removed: event_email_template, event_sent, user_rel_event_typepull/2650/head
							parent
							
								
									37e8d7f209
								
							
						
					
					
						commit
						e5c84cbcd5
					
				@ -1,67 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Events' configuration | 
				
			||||
 * @deprecated to be removed in 2.x | 
				
			||||
 * Used to configure each event and to link them to functions the event'll fire. | 
				
			||||
 * The flow is like the following : | 
				
			||||
 * 1. somewhere in the application an event is fired | 
				
			||||
 * 2. that event is intercepted by the switch EventsDispatcher | 
				
			||||
 * 3. that switch will go all over the "actions" in the event_config initialized beneath us according to the event | 
				
			||||
 * 4. that switch will see if the function actually exists (if not, we get dont do anything) | 
				
			||||
 * 5. then it will see if a filter for that function exists (if it does, the filter is executed) | 
				
			||||
 * 6. if the filter says it's ok, the function linked to the event is executed | 
				
			||||
 * 7. and that function will actually call the truly interesting function with the good require_once  | 
				
			||||
 */ | 
				
			||||
global $event_config; | 
				
			||||
 | 
				
			||||
$event_config = array( | 
				
			||||
    'portal_homepage_edited' => array( // key for "user registration" event | 
				
			||||
        'actions' => array( // we link this event to a bunch of functions that will be triggered when the event is fired | 
				
			||||
            'event_send_mail' // don't forget to actually write this function in the events.lib.php file | 
				
			||||
        ), | 
				
			||||
        'self_sent' => false, // this key states that we can't add user to this event through the admin panel | 
				
			||||
        'name_lang_var' => get_lang('PortalHomepageEdited'), | 
				
			||||
        'desc_lang_var' => get_lang('PortalHomepageEdited'), | 
				
			||||
        'available_keyvars' => array (// keys used for the mail template | 
				
			||||
            'url'           => 'portal', | 
				
			||||
            'sitename'      => 'sitename', | 
				
			||||
            'firstname'     => 'firstname', | 
				
			||||
            'lastname'      => 'lastname', | 
				
			||||
            'username'      => 'username', | 
				
			||||
            'usermail'      => 'usermail', | 
				
			||||
            'password'      => 'password', | 
				
			||||
            'user_lang'     => 'language', | 
				
			||||
            'admin_name'    => 'administrator_name', | 
				
			||||
            'admin_surname' => 'administrator_surname', | 
				
			||||
            'admin_phone'   => 'administrator_phone', | 
				
			||||
            'admin_email'   => 'administrator_email', | 
				
			||||
        ) | 
				
			||||
    ), | 
				
			||||
    'user_registration' => array( // key for "user registration" event | 
				
			||||
        'actions' => array( // we link this event to a bunch of functions that will be triggered when the event is fired | 
				
			||||
            'event_send_mail' // don't forget to actually write this function in the events.lib.php file | 
				
			||||
        ), | 
				
			||||
        'self_sent' => true, // this key states that we can't add user to this event through the admin panel | 
				
			||||
        'name_lang_var' => get_lang('UserRegistrationTitle'), | 
				
			||||
        'desc_lang_var' => get_lang('UserRegistrationComment'), | 
				
			||||
        'available_keyvars' => array (// keys used for the mail template | 
				
			||||
            'url'           => 'portal', | 
				
			||||
            'sitename'      => 'sitename', | 
				
			||||
            'firstname'     => 'firstname', | 
				
			||||
            'lastname'      => 'lastname', | 
				
			||||
            'username'      => 'username', | 
				
			||||
            'usermail'      => 'usermail', | 
				
			||||
            'password'      => 'password', | 
				
			||||
            'user_lang'     => 'language', | 
				
			||||
            'admin_name'    => 'administrator_name', | 
				
			||||
            'admin_surname' => 'administrator_surname', | 
				
			||||
            'admin_phone'   => 'administrator_phone', | 
				
			||||
            'admin_email'   => 'administrator_email', | 
				
			||||
        ) | 
				
			||||
    ), | 
				
			||||
); | 
				
			||||
 | 
				
			||||
 | 
				
			||||
@include 'events.conf.local.php'; | 
				
			||||
@ -1,144 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @deprecated | 
				
			||||
 * Class EventEmailTemplate | 
				
			||||
 */ | 
				
			||||
class EventEmailTemplate extends Model | 
				
			||||
{ | 
				
			||||
    public $table; | 
				
			||||
    public $columns = [ | 
				
			||||
        'id', | 
				
			||||
        'message', | 
				
			||||
        'subject', | 
				
			||||
        'event_type_name', | 
				
			||||
        'activated', | 
				
			||||
    ]; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Constructor. | 
				
			||||
     */ | 
				
			||||
    public function __construct() | 
				
			||||
    { | 
				
			||||
        $this->table = Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @param array $where_conditions | 
				
			||||
     * | 
				
			||||
     * @return array | 
				
			||||
     */ | 
				
			||||
    public function get_all($where_conditions = []) | 
				
			||||
    { | 
				
			||||
        return Database::select( | 
				
			||||
            '*', | 
				
			||||
            $this->table, | 
				
			||||
            ['where' => $where_conditions, 'order' => 'name ASC'] | 
				
			||||
        ); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Displays the title + grid. | 
				
			||||
     */ | 
				
			||||
    public function display() | 
				
			||||
    { | 
				
			||||
        // action links | 
				
			||||
        $content = Display::actions( | 
				
			||||
            [ | 
				
			||||
                [ | 
				
			||||
                    'url' => 'event_type.php', | 
				
			||||
                    'content' => Display::return_icon( | 
				
			||||
                        'new_document.png', | 
				
			||||
                        get_lang('Add'), | 
				
			||||
                        [], | 
				
			||||
                        ICON_SIZE_MEDIUM | 
				
			||||
                    ), | 
				
			||||
                 ], | 
				
			||||
            ] | 
				
			||||
        ); | 
				
			||||
        $content .= Display::grid_html('event_email_template'); | 
				
			||||
 | 
				
			||||
        return $content; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @return array | 
				
			||||
     */ | 
				
			||||
    public function get_status_list() | 
				
			||||
    { | 
				
			||||
        return [ | 
				
			||||
            EVENT_EMAIL_TEMPLATE_ACTIVE => get_lang('Enabled'), | 
				
			||||
            EVENT_EMAIL_TEMPLATE_INACTIVE => get_lang('Disabled'), | 
				
			||||
        ]; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Returns a Form validator Obj. | 
				
			||||
     * | 
				
			||||
     * @param string $url | 
				
			||||
     * @param string $action add, edit | 
				
			||||
     * | 
				
			||||
     * @return FormValidator | 
				
			||||
     */ | 
				
			||||
    public function return_form($url, $action) | 
				
			||||
    { | 
				
			||||
        $form = new FormValidator('career', 'post', $url); | 
				
			||||
        // Setting the form elements | 
				
			||||
        $header = get_lang('Add'); | 
				
			||||
        if ($action == 'edit') { | 
				
			||||
            $header = get_lang('Modify'); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        $form->addElement('header', $header); | 
				
			||||
        $id = isset($_GET['id']) ? intval($_GET['id']) : ''; | 
				
			||||
        $form->addElement('hidden', 'id', $id); | 
				
			||||
        $form->addElement('text', 'name', get_lang('Name'), ['size' => '70']); | 
				
			||||
        $form->addHtmlEditor( | 
				
			||||
            'description', | 
				
			||||
            get_lang('Description'), | 
				
			||||
            false, | 
				
			||||
            false, | 
				
			||||
            [ | 
				
			||||
                'ToolbarSet' => 'careers', | 
				
			||||
                'Width' => '100%', | 
				
			||||
                'Height' => '250', | 
				
			||||
            ] | 
				
			||||
        ); | 
				
			||||
        $status_list = $this->get_status_list(); | 
				
			||||
        $form->addElement('select', 'status', get_lang('Status'), $status_list); | 
				
			||||
        if ($action == 'edit') { | 
				
			||||
            $form->addElement('text', 'created_at', get_lang('CreatedAt')); | 
				
			||||
            $form->freeze('created_at'); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        if ($action == 'edit') { | 
				
			||||
            $form->addButtonSave(get_lang('Modify'), 'submit'); | 
				
			||||
        } else { | 
				
			||||
            $form->addButtonCreate(get_lang('Add'), 'submit'); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        // Setting the defaults | 
				
			||||
        $defaults = $this->get($id); | 
				
			||||
 | 
				
			||||
        if (!empty($defaults['created_at'])) { | 
				
			||||
            $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); | 
				
			||||
        } | 
				
			||||
        if (!empty($defaults['updated_at'])) { | 
				
			||||
            $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); | 
				
			||||
        } | 
				
			||||
        $form->setDefaults($defaults); | 
				
			||||
 | 
				
			||||
        // Setting the rules | 
				
			||||
        $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); | 
				
			||||
 | 
				
			||||
        return $form; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function get_count() | 
				
			||||
    { | 
				
			||||
        $row = Database::select('count(*) as count', $this->table, [], 'first'); | 
				
			||||
 | 
				
			||||
        return $row['count']; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,55 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 *  Class EventsDispatcher | 
				
			||||
 * Entry point for every event in the application. | 
				
			||||
 * | 
				
			||||
 * @deprecated to be removed in 2.x | 
				
			||||
 * Fires the functions linked to the events according to the event's conf. | 
				
			||||
 * Every function got its own filter, it's fired inside the functiones fired | 
				
			||||
 * by this class. The filter config is next to the event config, in conf/events.conf.php | 
				
			||||
 */ | 
				
			||||
class EventsDispatcher | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @param string $event_name | 
				
			||||
     * @param array  $event_data | 
				
			||||
     * | 
				
			||||
     * @return bool | 
				
			||||
     */ | 
				
			||||
    public static function events($event_name, $event_data = []) | 
				
			||||
    { | 
				
			||||
        global $event_config; | 
				
			||||
        // get the config for the event passed in parameter ($event_name) | 
				
			||||
        // and execute every actions with the values | 
				
			||||
 | 
				
			||||
        foreach ($event_config[$event_name]["actions"] as $func) { | 
				
			||||
            $execute = true; | 
				
			||||
            // if the function doesn't exist, we log | 
				
			||||
            if (!function_exists($func)) { | 
				
			||||
                error_log("EventsDispatcher warning : ".$func." does not exist."); | 
				
			||||
                $execute = false; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            // check if the event's got a filter | 
				
			||||
            if (function_exists($event_name."_".$func."_filter_func")) { | 
				
			||||
                $filter = $event_name."_".$func."_filter_func"; | 
				
			||||
                // if it does, we execute the filter (which changes the data | 
				
			||||
                // in-place and returns true on success or false on error) | 
				
			||||
                $execute = $filter($event_data); | 
				
			||||
            } else { | 
				
			||||
                // if there's no filter | 
				
			||||
                error_log("EventsDispatcher warning : ".$event_name."_".$func."_filter_func does not exist."); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            if (!$execute) { | 
				
			||||
                // if the filter says we cannot send the mail, we get out of here | 
				
			||||
                return false; | 
				
			||||
            } | 
				
			||||
            // finally, if the filter says yes (or the filter doesn't exist), | 
				
			||||
            // we execute the in-between function that will call the needed | 
				
			||||
            // function | 
				
			||||
            $func($event_name, $event_data); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,285 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Class EventsMail. | 
				
			||||
 * | 
				
			||||
 * @deprecated to be removed in 2.x | 
				
			||||
 * manages the e-mail sending action when a event requires it | 
				
			||||
 */ | 
				
			||||
class EventsMail | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * Sends email according to an event. | 
				
			||||
     * | 
				
			||||
     * @param string $event_name the name of the event that was triggered | 
				
			||||
     * @param array  $event_data what to put in the mail | 
				
			||||
     * | 
				
			||||
     * Possible key : | 
				
			||||
     * - $event_data["about_user"] (= $user_id) | 
				
			||||
     * - $event_data["prior_lang"] | 
				
			||||
     * | 
				
			||||
     * Warning : | 
				
			||||
     * - $event_data["send_to"] MUST BE an array | 
				
			||||
     */ | 
				
			||||
    public static function send_mail($event_name, $event_data) | 
				
			||||
    { | 
				
			||||
        /** | 
				
			||||
         * Global explanation : | 
				
			||||
         * 1. we get information about the user that fired the event (in $event_data["about_user"]) | 
				
			||||
         * 2. we send mail to people that are in the $event_data["send_to"] | 
				
			||||
         * 2b. if a language was specified, we use that one to send the mail, | 
				
			||||
         * else we get the user's language, if there isn't any, we get the english one | 
				
			||||
         * 3. we do the same with the people associated to the event through the admin panel. | 
				
			||||
         */ | 
				
			||||
        global $event_config; | 
				
			||||
 | 
				
			||||
        // common variable for every mail sent | 
				
			||||
        $sender_name = api_get_person_name( | 
				
			||||
            api_get_setting('administratorName'), | 
				
			||||
            api_get_setting('administratorSurname'), | 
				
			||||
            null, | 
				
			||||
            PERSON_NAME_EMAIL_ADDRESS | 
				
			||||
        ); | 
				
			||||
        $email_admin = api_get_setting('emailAdministrator'); | 
				
			||||
        // basic  keys | 
				
			||||
        $event_data["sitename"] = api_get_setting('siteName'); | 
				
			||||
        $event_data["administrator_name"] = api_get_setting('administratorName'); | 
				
			||||
        $event_data["administrator_surname"] = api_get_setting('administratorSurname'); | 
				
			||||
        $event_data["administrator_phone"] = api_get_setting('administratorTelephone'); | 
				
			||||
        $event_data["administrator_email"] = api_get_setting('emailAdministrator'); | 
				
			||||
        $event_data["portal"] = api_get_path(WEB_PATH); | 
				
			||||
 | 
				
			||||
        // Fill the array's cells with info regarding the user that fired the event | 
				
			||||
        // (for the keys in the template) | 
				
			||||
        if (isset($event_data["about_user"])) { | 
				
			||||
            $about_user = api_get_user_info($event_data["about_user"]); | 
				
			||||
            $event_data["firstname"] = $about_user["firstname"]; | 
				
			||||
            $event_data["lastname"] = $about_user["lastname"]; | 
				
			||||
            $event_data["username"] = $about_user["username"]; | 
				
			||||
            $event_data["usermail"] = $about_user["mail"]; | 
				
			||||
            $event_data["language"] = $about_user["language"]; | 
				
			||||
            $event_data["user_id"] = $about_user["user_id"]; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        // First, we send the mail to people we put in the $event_data["send_to"] | 
				
			||||
        if ($event_data["send_to"] != null) { | 
				
			||||
            // the users we precised need to receive the mail | 
				
			||||
            foreach ($event_data["send_to"] as $id) { | 
				
			||||
                // for every member put in the array | 
				
			||||
                // get user's info (to know where to send) | 
				
			||||
                $user_info = api_get_user_info($id); | 
				
			||||
 | 
				
			||||
                // get the language the email will be in | 
				
			||||
                if ($event_data["prior_lang"] != null) { | 
				
			||||
                    // if $lang is not null, we use that lang | 
				
			||||
                    $language = $event_data["prior_lang"]; | 
				
			||||
                } else { | 
				
			||||
                    // else we use the user's language | 
				
			||||
                    $sql = 'SELECT language | 
				
			||||
                            FROM '.Database::get_main_table(TABLE_MAIN_USER).' u | 
				
			||||
                            WHERE u.user_id = "'.$id.'" | 
				
			||||
                    '; | 
				
			||||
                    $language = Database::store_result( | 
				
			||||
                        Database::query($sql), | 
				
			||||
                        'ASSOC' | 
				
			||||
                    ); | 
				
			||||
                    $language = $language[0]["language"]; | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                // we get the message in the correct language (or in english if doesn't exist) | 
				
			||||
                $result = self::getMessage($event_name, $language); | 
				
			||||
                $message = ""; | 
				
			||||
                $subject = ""; | 
				
			||||
                self::getCorrectMessage($message, $subject, $language, $result); | 
				
			||||
 | 
				
			||||
                // replace the keycodes used in the message | 
				
			||||
                self::formatMessage($message, $subject, $event_config, $event_name, $event_data); | 
				
			||||
 | 
				
			||||
                // sending email | 
				
			||||
                $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname']); | 
				
			||||
 | 
				
			||||
                // checks if there's a file we need to join to the mail | 
				
			||||
                if (isset($values["certificate_pdf_file"])) { | 
				
			||||
                    $message = str_replace("\n", "<br />", $message); | 
				
			||||
                    api_mail_html( | 
				
			||||
                        $recipient_name, | 
				
			||||
                        $user_info["mail"], | 
				
			||||
                        $subject, | 
				
			||||
                        $message, | 
				
			||||
                        $sender_name, | 
				
			||||
                        $email_admin, | 
				
			||||
                        null, | 
				
			||||
                        [$values['certificate_pdf_file']] | 
				
			||||
                    ); | 
				
			||||
                } else { | 
				
			||||
                    api_mail_html( | 
				
			||||
                        $recipient_name, | 
				
			||||
                        $user_info["mail"], | 
				
			||||
                        $subject, | 
				
			||||
                        $message, | 
				
			||||
                        $sender_name, | 
				
			||||
                        $email_admin | 
				
			||||
                    ); | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                // If the mail only need to be send once (we know that thanks to the events.conf), we log it in the table | 
				
			||||
                if ($event_config[$event_name]["sending_mail_once"]) { | 
				
			||||
                    $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_SENT).' (user_from, user_to, event_type_name) | 
				
			||||
                            VALUES ('.$event_data["user_id"].', '.$id.' ,"'.Database::escape_string($event_name).'") | 
				
			||||
                    '; | 
				
			||||
                    Database::query($sql); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        // Second, we send to people linked to the event | 
				
			||||
        // So, we get everyone | 
				
			||||
        $sql = 'SELECT u.user_id, u.language, u.email, u.firstname, u.lastname | 
				
			||||
                FROM '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' ue | 
				
			||||
                INNER JOIN '.Database::get_main_table(TABLE_MAIN_USER).' u ON u.user_id = ue.user_id | 
				
			||||
                WHERE event_type_name = "'.$event_name.'"'; | 
				
			||||
        $result = Database::store_result(Database::query($sql), 'ASSOC'); | 
				
			||||
        // for each of the linked users | 
				
			||||
        foreach ($result as $key => $value) { | 
				
			||||
            // we get the language | 
				
			||||
            if ($event_data["prior_lang"] != null) { | 
				
			||||
                // if $lang is not null, we use that lang | 
				
			||||
                $language = $event_data["prior_lang"]; | 
				
			||||
            } else { | 
				
			||||
                // else we get the user's lang | 
				
			||||
                $sql = 'SELECT language FROM '.Database::get_main_table(TABLE_MAIN_USER).' | 
				
			||||
                    where user_id = '.$value["user_id"].' '; | 
				
			||||
                $result = Database::store_result(Database::query($sql), 'ASSOC'); | 
				
			||||
 | 
				
			||||
                $language = $result[0]["language"]; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            // we get the message in the correct language (or in english if doesn't exist) | 
				
			||||
            $result = self::getMessage($event_name, $language); | 
				
			||||
            $message = ''; | 
				
			||||
            $subject = ''; | 
				
			||||
            self::getCorrectMessage($message, $subject, $language, $result); | 
				
			||||
 | 
				
			||||
            // replace the keycodes used in the message | 
				
			||||
            self::formatMessage($message, $subject, $event_config, $event_name, $event_data); | 
				
			||||
 | 
				
			||||
            // we send the mail | 
				
			||||
            $recipient_name = api_get_person_name($value['firstname'], $value['lastname']); | 
				
			||||
 | 
				
			||||
            api_mail_html( | 
				
			||||
                $recipient_name, | 
				
			||||
                $value["email"], | 
				
			||||
                $subject, | 
				
			||||
                $message, | 
				
			||||
                $sender_name, | 
				
			||||
                $email_admin | 
				
			||||
            ); | 
				
			||||
 | 
				
			||||
            // If the mail only need to be send once (we know that thanks to the events.conf, we log it in the table | 
				
			||||
            if ($event_config[$event_name]["sending_mail_once"]) { | 
				
			||||
                $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_SENT).' | 
				
			||||
                    (user_from, user_to, event_type_name) | 
				
			||||
                    VALUES ('.$event_data["user_id"].', '.$value["user_id"].' , "'.Database::escape_string($event_name).'"); | 
				
			||||
                    '; | 
				
			||||
                Database::query($sql); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Checks if a message in a language exists, if the event is activated | 
				
			||||
     * and if "manage event" is checked in admin panel. | 
				
			||||
     * If yes to three, we can use this class, else we still use api_mail. | 
				
			||||
     * | 
				
			||||
     * @param string $event_name | 
				
			||||
     * | 
				
			||||
     * @return bool | 
				
			||||
     */ | 
				
			||||
    public static function check_if_using_class($event_name) | 
				
			||||
    { | 
				
			||||
        if (api_get_setting('activate_email_template') === 'false') { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
        $current_language = api_get_interface_language(); | 
				
			||||
 | 
				
			||||
        $sql = 'SELECT COUNT(*) as total | 
				
			||||
                FROM '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).' em | 
				
			||||
                INNER JOIN '.Database::get_main_table(TABLE_MAIN_LANGUAGE).' l | 
				
			||||
                ON em.language_id = l.id | 
				
			||||
                WHERE | 
				
			||||
                    em.event_type_name = "'.$event_name.'" and | 
				
			||||
                    l.dokeos_folder = "'.$current_language.'" and | 
				
			||||
                    em.activated = 1'; | 
				
			||||
 | 
				
			||||
        $exists = Database::store_result(Database::query($sql), 'ASSOC'); | 
				
			||||
        if ($exists[0]["total"]) { | 
				
			||||
            return true; | 
				
			||||
        } else { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get the record containing the good message and subject. | 
				
			||||
     * | 
				
			||||
     * @param string $event_name | 
				
			||||
     * @param string $language | 
				
			||||
     * | 
				
			||||
     * @return array | 
				
			||||
     */ | 
				
			||||
    private static function getMessage($event_name, $language) | 
				
			||||
    { | 
				
			||||
        $sql = 'SELECT message, subject, l.dokeos_folder | 
				
			||||
                FROM '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).' em | 
				
			||||
                INNER JOIN '.Database::get_main_table(TABLE_MAIN_LANGUAGE).' l | 
				
			||||
                ON em.language_id = l.id | 
				
			||||
                WHERE | 
				
			||||
                    em.event_type_name = "'.$event_name.'" AND | 
				
			||||
                    (l.dokeos_folder = "'.$language.'" OR l.dokeos_folder = "english") AND | 
				
			||||
                    em.message <> "" | 
				
			||||
                '; | 
				
			||||
 | 
				
			||||
        return Database::store_result(Database::query($sql), 'ASSOC'); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get the correct message, meaning in the specified language or in english if previous one doesn't exist. | 
				
			||||
     * | 
				
			||||
     * @param string $message | 
				
			||||
     * @param string $subject | 
				
			||||
     * @param string $language | 
				
			||||
     * @param array  $result | 
				
			||||
     */ | 
				
			||||
    private static function getCorrectMessage(&$message, &$subject, $language, $result) | 
				
			||||
    { | 
				
			||||
        foreach ($result as $msg) { | 
				
			||||
            if ($msg["dokeos_folder"] == $language) { | 
				
			||||
                $message = $msg["message"]; | 
				
			||||
                $subject = $msg["subject"]; | 
				
			||||
                break; | 
				
			||||
            } else { | 
				
			||||
                if ($msg["dokeos_folder"] == "english") { | 
				
			||||
                    $message = $msg["message"]; | 
				
			||||
                    $subject = $msg["subject"]; | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Replaces the ((key)) by the good values. | 
				
			||||
     * | 
				
			||||
     * @param string $message | 
				
			||||
     * @param string $subject | 
				
			||||
     * @param array  $event_config | 
				
			||||
     * @param string $event_name | 
				
			||||
     */ | 
				
			||||
    private static function formatMessage(&$message, &$subject, $event_config, $event_name, &$event_data) | 
				
			||||
    { | 
				
			||||
        foreach ($event_config[$event_name]["available_keyvars"] as $key => $word) { | 
				
			||||
            $message = str_replace('(('.$key.'))', $event_data[$word], $message); | 
				
			||||
            $subject = str_replace('(('.$key.'))', $event_data[$word], $subject); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,193 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\CoreBundle\Entity; | 
				
			||||
 | 
				
			||||
use Doctrine\ORM\Mapping as ORM; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * EventEmailTemplate. | 
				
			||||
 * | 
				
			||||
 * @ORM\Table( | 
				
			||||
 *     name="event_email_template", | 
				
			||||
 *     options={"row_format":"DYNAMIC"}, | 
				
			||||
 *     indexes={@ORM\Index(name="event_name_index", columns={"event_type_name"})} | 
				
			||||
 * ) | 
				
			||||
 * @ORM\Entity | 
				
			||||
 */ | 
				
			||||
class EventEmailTemplate | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @var string | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="message", type="text", nullable=true) | 
				
			||||
     */ | 
				
			||||
    protected $message; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var string | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="subject", type="string", length=255, nullable=true) | 
				
			||||
     */ | 
				
			||||
    protected $subject; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var string | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="event_type_name", type="string", length=255, nullable=true) | 
				
			||||
     */ | 
				
			||||
    protected $eventTypeName; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var bool | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="activated", type="boolean", nullable=false) | 
				
			||||
     */ | 
				
			||||
    protected $activated; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="language_id", type="integer", nullable=true) | 
				
			||||
     */ | 
				
			||||
    protected $languageId; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="id", type="integer") | 
				
			||||
     * @ORM\Id | 
				
			||||
     * @ORM\GeneratedValue(strategy="IDENTITY") | 
				
			||||
     */ | 
				
			||||
    protected $id; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set message. | 
				
			||||
     * | 
				
			||||
     * @param string $message | 
				
			||||
     * | 
				
			||||
     * @return EventEmailTemplate | 
				
			||||
     */ | 
				
			||||
    public function setMessage($message) | 
				
			||||
    { | 
				
			||||
        $this->message = $message; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get message. | 
				
			||||
     * | 
				
			||||
     * @return string | 
				
			||||
     */ | 
				
			||||
    public function getMessage() | 
				
			||||
    { | 
				
			||||
        return $this->message; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set subject. | 
				
			||||
     * | 
				
			||||
     * @param string $subject | 
				
			||||
     * | 
				
			||||
     * @return EventEmailTemplate | 
				
			||||
     */ | 
				
			||||
    public function setSubject($subject) | 
				
			||||
    { | 
				
			||||
        $this->subject = $subject; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get subject. | 
				
			||||
     * | 
				
			||||
     * @return string | 
				
			||||
     */ | 
				
			||||
    public function getSubject() | 
				
			||||
    { | 
				
			||||
        return $this->subject; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set eventTypeName. | 
				
			||||
     * | 
				
			||||
     * @param string $eventTypeName | 
				
			||||
     * | 
				
			||||
     * @return EventEmailTemplate | 
				
			||||
     */ | 
				
			||||
    public function setEventTypeName($eventTypeName) | 
				
			||||
    { | 
				
			||||
        $this->eventTypeName = $eventTypeName; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get eventTypeName. | 
				
			||||
     * | 
				
			||||
     * @return string | 
				
			||||
     */ | 
				
			||||
    public function getEventTypeName() | 
				
			||||
    { | 
				
			||||
        return $this->eventTypeName; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set activated. | 
				
			||||
     * | 
				
			||||
     * @param bool $activated | 
				
			||||
     * | 
				
			||||
     * @return EventEmailTemplate | 
				
			||||
     */ | 
				
			||||
    public function setActivated($activated) | 
				
			||||
    { | 
				
			||||
        $this->activated = $activated; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get activated. | 
				
			||||
     * | 
				
			||||
     * @return bool | 
				
			||||
     */ | 
				
			||||
    public function getActivated() | 
				
			||||
    { | 
				
			||||
        return $this->activated; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set languageId. | 
				
			||||
     * | 
				
			||||
     * @param int $languageId | 
				
			||||
     * | 
				
			||||
     * @return EventEmailTemplate | 
				
			||||
     */ | 
				
			||||
    public function setLanguageId($languageId) | 
				
			||||
    { | 
				
			||||
        $this->languageId = $languageId; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get languageId. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getLanguageId() | 
				
			||||
    { | 
				
			||||
        return $this->languageId; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get id. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getId() | 
				
			||||
    { | 
				
			||||
        return $this->id; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,127 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\CoreBundle\Entity; | 
				
			||||
 | 
				
			||||
use Doctrine\ORM\Mapping as ORM; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * EventSent. | 
				
			||||
 * | 
				
			||||
 * @ORM\Table(name="event_sent", indexes={@ORM\Index(name="event_name_index", columns={"event_type_name"})}) | 
				
			||||
 * @ORM\Entity | 
				
			||||
 */ | 
				
			||||
class EventSent | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="id", type="integer") | 
				
			||||
     * @ORM\Id | 
				
			||||
     * @ORM\GeneratedValue(strategy="IDENTITY") | 
				
			||||
     */ | 
				
			||||
    protected $id; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="user_from", type="integer", nullable=false) | 
				
			||||
     */ | 
				
			||||
    protected $userFrom; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="user_to", type="integer", nullable=true) | 
				
			||||
     */ | 
				
			||||
    protected $userTo; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var string | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="event_type_name", type="string", length=100, nullable=true) | 
				
			||||
     */ | 
				
			||||
    protected $eventTypeName; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set userFrom. | 
				
			||||
     * | 
				
			||||
     * @param int $userFrom | 
				
			||||
     * | 
				
			||||
     * @return EventSent | 
				
			||||
     */ | 
				
			||||
    public function setUserFrom($userFrom) | 
				
			||||
    { | 
				
			||||
        $this->userFrom = $userFrom; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get userFrom. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getUserFrom() | 
				
			||||
    { | 
				
			||||
        return $this->userFrom; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set userTo. | 
				
			||||
     * | 
				
			||||
     * @param int $userTo | 
				
			||||
     * | 
				
			||||
     * @return EventSent | 
				
			||||
     */ | 
				
			||||
    public function setUserTo($userTo) | 
				
			||||
    { | 
				
			||||
        $this->userTo = $userTo; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get userTo. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getUserTo() | 
				
			||||
    { | 
				
			||||
        return $this->userTo; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set eventTypeName. | 
				
			||||
     * | 
				
			||||
     * @param string $eventTypeName | 
				
			||||
     * | 
				
			||||
     * @return EventSent | 
				
			||||
     */ | 
				
			||||
    public function setEventTypeName($eventTypeName) | 
				
			||||
    { | 
				
			||||
        $this->eventTypeName = $eventTypeName; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get eventTypeName. | 
				
			||||
     * | 
				
			||||
     * @return string | 
				
			||||
     */ | 
				
			||||
    public function getEventTypeName() | 
				
			||||
    { | 
				
			||||
        return $this->eventTypeName; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get id. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getId() | 
				
			||||
    { | 
				
			||||
        return $this->id; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,102 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\CoreBundle\Entity; | 
				
			||||
 | 
				
			||||
use Doctrine\ORM\Mapping as ORM; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * UserRelEventType. | 
				
			||||
 * | 
				
			||||
 * @ORM\Table( | 
				
			||||
 *     name="user_rel_event_type", | 
				
			||||
 *     options={"row_format":"DYNAMIC"}, | 
				
			||||
 *     indexes={ | 
				
			||||
 *         @ORM\Index(name="event_name_index", columns={"event_type_name"}) | 
				
			||||
 *     } | 
				
			||||
 * ) | 
				
			||||
 * @ORM\Entity | 
				
			||||
 */ | 
				
			||||
class UserRelEventType | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="id", type="integer") | 
				
			||||
     * @ORM\Id | 
				
			||||
     * @ORM\GeneratedValue | 
				
			||||
     */ | 
				
			||||
    protected $id; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var int | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="user_id", type="integer", nullable=false) | 
				
			||||
     */ | 
				
			||||
    protected $userId; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @var string | 
				
			||||
     * | 
				
			||||
     * @ORM\Column(name="event_type_name", type="string", length=255, nullable=false) | 
				
			||||
     */ | 
				
			||||
    protected $eventTypeName; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set userId. | 
				
			||||
     * | 
				
			||||
     * @param int $userId | 
				
			||||
     * | 
				
			||||
     * @return UserRelEventType | 
				
			||||
     */ | 
				
			||||
    public function setUserId($userId) | 
				
			||||
    { | 
				
			||||
        $this->userId = $userId; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get userId. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getUserId() | 
				
			||||
    { | 
				
			||||
        return $this->userId; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Set eventTypeName. | 
				
			||||
     * | 
				
			||||
     * @param string $eventTypeName | 
				
			||||
     * | 
				
			||||
     * @return UserRelEventType | 
				
			||||
     */ | 
				
			||||
    public function setEventTypeName($eventTypeName) | 
				
			||||
    { | 
				
			||||
        $this->eventTypeName = $eventTypeName; | 
				
			||||
 | 
				
			||||
        return $this; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get eventTypeName. | 
				
			||||
     * | 
				
			||||
     * @return string | 
				
			||||
     */ | 
				
			||||
    public function getEventTypeName() | 
				
			||||
    { | 
				
			||||
        return $this->eventTypeName; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Get id. | 
				
			||||
     * | 
				
			||||
     * @return int | 
				
			||||
     */ | 
				
			||||
    public function getId() | 
				
			||||
    { | 
				
			||||
        return $this->id; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue