commit
f0aca4e6fc
@ -1,34 +1,35 @@ |
||||
<?php |
||||
error_reporting(E_ERROR); |
||||
|
||||
ob_start(); |
||||
error_reporting(E_ERROR); |
||||
|
||||
require_once '../global.inc.php'; |
||||
ob_start(); |
||||
|
||||
require_once '../global.inc.php'; |
||||
require_once '../lib/usermanager.lib.php'; |
||||
|
||||
$id = isset($_REQUEST['id'])?$_REQUEST['id']:null; |
||||
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
ob_end_clean(); |
||||
|
||||
header('content-type: text/json'); |
||||
|
||||
|
||||
$id = isset($_REQUEST['id'])?$_REQUEST['id']:null; |
||||
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
||||
$actionEventName = isset($_REQUEST['eventName'])?$_REQUEST['eventName']:null; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
ob_end_clean(); |
||||
|
||||
header('content-type: text/json'); |
||||
|
||||
if($action == 'getEventTypes') { |
||||
$events = eventType_getAll(); |
||||
|
||||
$events = get_all_event_types(); |
||||
|
||||
print json_encode($events); |
||||
} |
||||
} |
||||
elseif($action == 'getUsers') { |
||||
$users = UserManager::get_user_list(); |
||||
|
||||
$users = UserManager::get_user_list(); |
||||
|
||||
print json_encode($users); |
||||
} |
||||
elseif($action == 'getEventTypeUsers') { |
||||
$users = eventType_getUsers($id); |
||||
|
||||
} |
||||
elseif($action == 'get_event_users') { |
||||
$users = get_event_users($actionEventName); |
||||
|
||||
print json_encode($users); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,48 @@ |
||||
<?php |
||||
|
||||
require_once api_get_path(CONFIGURATION_PATH).'events.conf.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'events_email.lib.php'; |
||||
|
||||
/** |
||||
* |
||||
* Entry point for every event in the application. |
||||
* 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 |
||||
{ |
||||
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) |
||||
{ |
||||
if(!function_exists($func)) // if the function doesn't exist, we log |
||||
{ |
||||
error_log("EventsDispatcher warning : ".$func." does not exist."); |
||||
} |
||||
|
||||
if (function_exists($event_name."_".$func."_filter_func")) // check if the event's got a filter |
||||
{ |
||||
$filter = $event_name."_".$func."_filter_func"; |
||||
$execute = $filter($event_data); // if it does, we execute the filter |
||||
} |
||||
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, we execute the in-between function that will call the needed function |
||||
$func($event_name, $event_data); |
||||
} |
||||
} |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,252 @@ |
||||
<?php |
||||
|
||||
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 |
||||
* |
||||
* Keys needed : |
||||
* - $event_data["about_user"] (= $user_id) |
||||
* |
||||
* Possible key : |
||||
* - $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_person_name(api_get_setting('administratorName')); |
||||
$event_data["administrator_surname"] = api_get_person_name(api_get_setting('administratorSurname')); |
||||
$event_data["administrator_phone"] = api_get_setting('administratorTelephone'); |
||||
$event_data["administrator_email"] = api_get_setting('emailAdministrator'); |
||||
|
||||
// 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, array($values['certificate_pdf_file'])); |
||||
} |
||||
else |
||||
{ |
||||
@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"]) |
||||
{ |
||||
$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_MAIN_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'); |
||||
|
||||
foreach ($result as $key => $value) // for each of the linked users |
||||
{ |
||||
// 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($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. |
||||
*/ |
||||
public static function check_if_using_class($event_name) |
||||
{ |
||||
if(api_get_setting('activate_email_template') === 'false') |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$sql = 'SELECT COUNT(*) as total FROM ' . Database::get_main_table(TABLE_MAIN_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 = "english" 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 type $event_name |
||||
* @param type $language |
||||
* @return type |
||||
*/ |
||||
private static function getMessage($event_name, $language) |
||||
{ |
||||
$sql = 'SELECT message, subject, l.dokeos_folder FROM ' . Database::get_main_table(TABLE_MAIN_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 type $message |
||||
* @param type $subject |
||||
* @param type $language |
||||
* @param type $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 type $message |
||||
* @param type $subject |
||||
* @param type $event_config |
||||
* @param type $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); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
?> |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
$events_title = 'Event message management'; |
||||
$events_listTitle = 'Events'; |
||||
$events_userListTile = 'Platform users'; |
||||
$events_userSubListTile = 'To-be-warned users\' list'; |
||||
$events_labelSubject = 'Message\'s topic'; |
||||
$events_labelMessage = 'Message'; |
||||
$events_btnMod = 'Edit event message'; |
||||
|
||||
$courseDeletedTitle = 'Delete a training'; |
||||
$courseCreatedTitle = 'Create a training'; |
||||
$userDeletedTitle = 'Delete a user'; |
||||
$userCreatedTitle = 'Create a user'; |
||||
$sessionCreatedTitle = 'Create a session'; |
||||
$sessionDeletedTitle ='Delete a session'; |
||||
$sessionCategoryCreatedTitle = 'Create a session category'; |
||||
$sessionCategoryDeletedTitle = 'Delete a session category'; |
||||
$settingsChangedTitle = 'Change a configuration parameter'; |
||||
$userRegistrationTitle = 'Register a user'; |
||||
$userUnsubscribedTitle = 'Unregister a user'; |
||||
$allCoursesPassedTitle = 'Eight succeeded courses'; |
||||
$notifManagerTitle = 'Sending mail to n+1'; |
||||
$subscribeUserToCourseTitle = 'Subscribe a user to a course'; |
||||
|
||||
$availables_keys = 'Available keys. Use them between (( )).'; |
||||
$checkbox_activated = 'Activated ?'; |
||||
$unsaved_changes = 'You have some unsaved changes. Do you want to abandon them ?'; |
||||
?> |
Loading…
Reference in new issue