events correction (adds events.conf.dist, removes api_get_person_name, removes call to email_dispatcher, adds api_get_path instead of [], ...)

skala
Anne-Lise Lambin 14 years ago
parent e766adfe96
commit ddfff56c6f
  1. 1
      main/auth/inscription.php
  2. 99
      main/inc/conf/events.conf.dist.php
  3. 673
      main/inc/lib/events.lib.inc.php
  4. 4
      main/inc/lib/events_dispatcher.class.php
  5. 60
      main/inc/lib/events_email.class.php
  6. 3
      main/inc/lib/usermanager.lib.php
  7. 1
      main/install/install_files.inc.php
  8. 5
      main/install/update-files-1.8.8-1.9.0.inc.php

@ -15,7 +15,6 @@ if (!empty($_POST['language'])) { //quick hack to adapt the registration form re
require_once '../inc/global.inc.php';
require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'events_dispatcher.lib.php';
if (!empty($_SESSION['user_language_choice'])) {
$user_selected_language = $_SESSION['user_language_choice'];

@ -0,0 +1,99 @@
<?php
/**
*
* Events' configuration
* 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(
'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 at the end of this 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',
)
),
);
/**============================================================================
*
* Filter functions
*
*/
/**
* user_registration - send_mail filter
* @param array $values (passing by reference)
* @return boolean
*/
function user_registration_event_send_mail_filter_func(&$values)
{
return true;
}
/**
* For the sake of genericity, this function is a switch.
* It's called by EventsDispatcher and fires the good function
* with the good require_once.
*
* @param string $event_name
* @param array $params
*/
function event_send_mail($event_name, $params)
{
require_once api_get_path(LIBRARY_PATH).'events_email.class.php';
EventsMail::send_mail($event_name, $params);
}
/**
* Internal function checking if the mail was already sent from that user to that user
* @param string $event_name
* @param int $user_from
* @param int $user_to
* @return boolean
*/
function check_if_mail_already_sent($event_name, $user_from, $user_to = null)
{
if ($user_to == null)
{
$sql = 'SELECT COUNT(*) as total FROM ' . Database::get_main_table(TABLE_EVENT_SENT) . '
WHERE user_from = '.$user_from.' AND event_type_name = "'.$event_name.'";
';
}
else
{
$sql = 'SELECT COUNT(*) as total FROM ' . Database::get_main_table(TABLE_EVENT_SENT) . '
WHERE user_from = '.$user_from.' AND user_to = '.$user_to.' AND event_type_name = "'.$event_name.'";
';
}
$result = Database::store_result(Database::query($sql), 'ASSOC');
return $result[0]["total"];
}
?>

File diff suppressed because it is too large Load Diff

@ -18,7 +18,7 @@ class EventsDispatcher
// and execute every actions with the values
foreach ($event_config[$event_name]["actions"] as $func)
{
if(!function_exists($func)) // if the function doesn't exist, we log
if (!function_exists($func)) // if the function doesn't exist, we log
{
error_log("EventsDispatcher warning : ".$func." does not exist.");
}
@ -33,7 +33,7 @@ class EventsDispatcher
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
if (!$execute) // if the filter says we cannot send the mail, we get out of here
{
return false;
}

@ -1,19 +1,21 @@
<?php
/**
*
* Manages the email sending action when a event requires it.
*
*/
class EventsMail
{
/**
* Manages and sends email according to an event
*
* @param type $event_name the name of the event that was triggered
* @param type $values what to put in the mail
* @param array
* Sends email according to an event
*
* Keys needed :
* - $event_data["about_user"] (= $user_id)
* @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 :
@ -35,14 +37,15 @@ class EventsMail
$email_admin = api_get_setting('emailAdministrator');
// basic keys
$event_data["sitename"] = api_get_setting('siteName');
$event_data["administrator_name"] = api_get_person_name(api_get_setting('administratorName'));
$event_data["administrator_surname"] = api_get_person_name(api_get_setting('administratorSurname'));
$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"]))
if ( isset($event_data["about_user"]) )
{
$about_user = api_get_user_info($event_data["about_user"]);
$event_data["firstname"] = $about_user["firstname"];
@ -88,7 +91,7 @@ class EventsMail
$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"]))
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, array($values['certificate_pdf_file']));
@ -98,8 +101,8 @@ class EventsMail
@api_mail($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"])
// 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)
@ -148,7 +151,7 @@ class EventsMail
@api_mail($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"])
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)
@ -163,10 +166,13 @@ class EventsMail
* 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 boolean
*/
public static function check_if_using_class($event_name)
{
if(api_get_setting('activate_email_template') === 'false')
if (api_get_setting('activate_email_template') === 'false')
{
return false;
}
@ -191,9 +197,9 @@ class EventsMail
/**
* Get the record containing the good message and subject
*
* @param type $event_name
* @param type $language
* @return type
* @param string $event_name
* @param string $language
* @return array
*/
private static function getMessage($event_name, $language)
{
@ -207,10 +213,10 @@ class EventsMail
/**
* Get the correct message, meaning in the specified language or in english if previous one doesn't exist
*
* @param type $message
* @param type $subject
* @param type $language
* @param type $result
* @param string $message
* @param string $subject
* @param string $language
* @param array $result
*/
private static function getCorrectMessage(&$message, &$subject, $language, $result)
{
@ -231,12 +237,12 @@ class EventsMail
}
/**
* Replaces the %key% by the good values
* Replaces the ((key)) by the good values
*
* @param type $message
* @param type $subject
* @param type $event_config
* @param type $event_name
* @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)
{

@ -170,7 +170,6 @@ class UserManager {
if(EventsMail::check_if_using_class('user_registration'))
{
$values["about_user"] = $return;
$values["portal"] = $_configuration['root_web'];
$values["password"] = $original_password;
$values["send_to"] = array($return);
@ -182,9 +181,9 @@ class UserManager {
{
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
/* ENDS MANAGE EVENT WITH MAIL */
}
/* ENDS MANAGE EVENT WITH MAIL */
// Add event to system log

@ -30,6 +30,7 @@ if (defined('SYSTEM_INSTALLATION')) {
copy(api_get_path(CONFIGURATION_PATH).'course_info.conf.dist.php', api_get_path(CONFIGURATION_PATH).'course_info.conf.php');
copy(api_get_path(CONFIGURATION_PATH).'mail.conf.dist.php', api_get_path(CONFIGURATION_PATH).'mail.conf.php');
copy(api_get_path(CONFIGURATION_PATH).'profile.conf.dist.php', api_get_path(CONFIGURATION_PATH).'profile.conf.php');
copy(api_get_path(CONFIGURATION_PATH).'events.conf.dist.php', api_get_path(CONFIGURATION_PATH).'events.conf.php');
} else {
echo 'You are not allowed here !';
}

@ -68,6 +68,11 @@ EOP;
fwrite($fh,$string);
fwrite($fh, '?>');
fclose($fh);
//Adds events.conf file
if (! file_exists(api_get_path(CONFIGURATION_PATH).'events.conf.php')) {
copy(api_get_path(CONFIGURATION_PATH).'events.conf.dist.php', api_get_path(CONFIGURATION_PATH).'events.conf.php');
}
} else {

Loading…
Cancel
Save