* @version $Id$
* @access public
* @license http://opensource.org/licenses/gpl-3.0.html
*/
// ////////// Check Inclusion de pages ////////////
if (! class_exists ( 'auth' )) {
include_once ("../lib/lib_common.php");
ReloadIndex ( 'admin' );
}
// //////////
/**
* Prepare email by setting recipient, subject, html and text bodies
* Email is set regarding passed action ($a ['action'])
* @param array $a Provide 'action' and wanted information to send
* @return array $email Returns a formatted array containing email informations
*/
function prepare_email($a) {
/**
* Préparation du mail
* $email_html_body
* $email_txt_body
* $email_subject
* $email_recipient
*/
$email = array ();
$user_path = THEME_PUBLIC_PATH.'override/mail/defined/';
if(file_exists($user_path.$a ['action'].'.php')) {
// Important : do not replace by include_once() because it will works only once !!!
include($user_path.$a ['action'].'.php');
logfile ( LOG_MAINFILE, array ('[action] preparing email', 'using user defined template : ' . $user_path.$a ['action'].'.php'));
} else {
logfile ( LOG_MAINFILE, array ('[action] preparing email', 'using default template : ' . $a ['action']));
switch ($a ['action']) {
// USERS
case 'add_user' :
$email ['html_body'] = _t ( 'user', 'mail_add_body1' ) . "
\n";
$email ['html_body'] .= _t ( 'user', 'mail_add_body2' ) . "
\n";
$email ['html_body'] .= _t ( 'user', 'login' ) . " : " . $a['login'] . "
\n";
$email ['html_body'] .= _t ( 'user', 'password' ) . " : " . $a['password'] . "
\n";
$email ['txt_body'] = _t ( 'user', 'mail_add_body1' ) . "\n";
$email ['txt_body'] .= _t ( 'user', 'mail_add_body2' ) . "\n\n";
$email ['txt_body'] .= _t ( 'user', 'login' ) . " : " . $a['login'] . "\n";
$email ['txt_body'] .= _t ( 'user', 'password' ) . " : " . $a['password'] . "\n";
$email ['subject'] = mb_ucfirst ( _t ( 'user', 'mail_add_subject' ) ) . ' - ' . SITE_NAME;
$email ['recipient'] = $a['recipient'];
break;
case 'change_pass' :
$email ['html_body'] = _t ( 'user', 'mail_changepass_body1' ) . "
\n";
$email ['html_body'] .= _t ( 'user', 'mail_changepass_body2' ) . "
\n";
$email ['html_body'] .= _t ( 'user', 'login' ) . " : " . $a['login'] . "
\n";
$email ['html_body'] .= _t ( 'user', 'password' ) . " : " . $a['password'] . "
\n";
$email ['txt_body'] = _t ( 'user', 'mail_changepass_body1' ) . "\n";
$email ['txt_body'] .= _t ( 'user', 'mail_changepass_body2' ) . "\n";
$email ['txt_body'] .= _t ( 'user', 'login' ) . " : " . $a['login'] . "\n";
$email ['txt_body'] .= _t ( 'user', 'password' ) . " : " . $a['password'] . "\n";
$email ['subject'] = mb_ucfirst ( _t ( 'user', 'mail_changepass_subject' ) ) . ' - ' . SITE_NAME;
$email ['recipient'] = $a['recipient'];
break;
case 'forgot_pass' :
$email ['html_body'] = _t ( 'user', 'mail_forgotpass_body1' ) . "
\n";
$email ['html_body'] .= '' . _t ( 'user', 'mail_forgotpass_body2' ) . "
\n";
$email ['html_body'] .= "" . get_permalink ( $a['linkpassword'] ) . "
\n";
$email ['txt_body'] = _t ( 'user', 'mail_forgotpass_body1' ) . "\n";
$email ['txt_body'] .= _t ( 'user', 'mail_forgotpass_body2' ) . "\n";
$email ['txt_body'] .= get_permalink ( $a['linkpassword'] ) . "\n";
$email ['subject'] = mb_ucfirst ( _t ( 'user', 'mail_forgotpass_subject' ) ) . ' - ' . SITE_NAME;
$email ['recipient'] = $a['recipient'];
break;
case 'change_mail' :
$email ['html_body'] = _t ( 'user', 'mail_changemail_body1' ) . "
\n";
$email ['txt_body'] = _t ( 'user', 'mail_changemail_body1' ) . "\n";
$email ['subject'] = mb_ucfirst ( _t ( 'user', 'mail_changemail_subject' ) ) . ' - ' . SITE_NAME;
$email ['recipient'] = $a['recipient'];
break;
case 'change_login' :
$email ['html_body'] = _t ( 'user', 'mail_changelogin_body1' ) . '' . $a['login'] . "
\n";
$email ['txt_body'] = _t ( 'user', 'mail_changelogin_body1' ) . $a['login'] . "\n";
$email ['subject'] = mb_ucfirst ( _t ( 'user', 'mail_changelogin_subject' ) ) . ' - ' . SITE_NAME;
$email ['recipient'] = $a['recipient'];
break;
case 'user_pm' :
if (isset($a ['reply_to'])) $emailsender = " (" . formatText ( $a ['reply_to'], '2HTML' ) . ") ";
else $emailsender = '';
$email ['html_body'] = '';
if (isset($a ['copy_information'])) $email ['html_body'] .= $a ['copy_information'];
$email ['html_body'] .= "
" . sprintf ( _t ( 'contact', 'pm_contact_from' ), $a['userlink'], $_SESSION ['userlogin'], $emailsender, SITE_NAME ) . "
" . PHP_EOL; $email ['html_body'] .= "" . sprintf ( _t ( 'comment', 'mail_body1' ), $a ['name'], "" . $a ['item_title'] . " (" . $a ['item_type'] . ")" ) . " :
" . PHP_EOL; $email ['html_body'] .= "" . ucfirst ( _t ( 'comment', 'mail_body2' ) ) . " "; $email ['html_body'] .= "(" . _t ( 'comment', 'mail_body_auth' ) . ")
" . PHP_EOL; $email ['txt_body'] = sprintf ( _t ( 'comment', 'mail_body1' ), $a ['name'], $a ['item_title'] . ' (' . $a ['item_type'] . ') : ' ) . PHP_EOL; $email ['txt_body'] .= " - " . $a ['item_link'] . PHP_EOL . PHP_EOL; $email ['txt_body'] .= formatText ( $a ['body'], '2HTML' ) . PHP_EOL . PHP_EOL; $email ['txt_body'] .= ucfirst ( _t ( 'comment', 'mail_body2' ) ) . ' : ' . $a ['moderate_link'] . PHP_EOL; $email ['txt_body'] .= "(" . _t ( 'comment', 'mail_body_auth' ) . ")" . PHP_EOL; $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'comment', 'mail_subject_moderate' ), SITE_NAME ) ); $email ['recipient'] = $a ['recipient']; if (isset($a ['reply_to'])) $email ['reply_to'] = array($a ['reply_to']); break; case 'notify_comment' : $unsubscribe_link = $a ['unsubscribe_link'] . '&email=' . $a ['recipient']; $email ['html_body'] = "" . sprintf ( _t ( 'comment', 'mail_body1' ), $a ['name'], "" . $a ['item_title'] . " (" . $a ['item_type'] . ")" ) . " :
" . PHP_EOL; $email ['html_body'] .= "" . ucfirst ( _t ( 'comment', 'mail_body3' ) ) . "" . $unsubscribe_link . "
" . PHP_EOL; } $email ['txt_body'] = sprintf ( _t ( 'comment', 'mail_body1' ), $a ['name'], $a ['item_title'] . ' (' . $a ['item_type'] . ') : ' ) . PHP_EOL; $email ['txt_body'] .= " - " . $a ['item_link'] . PHP_EOL . PHP_EOL; $email ['txt_body'] .= formatText ( $a ['body'], '2HTML' ) . PHP_EOL . PHP_EOL; if (! isset ( $a ['adminuser'] )) { $email ['txt_body'] .= ucfirst ( _t ( 'comment', 'mail_body3' ) ) . $unsubscribe_link . PHP_EOL; } $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'comment', 'mail_subject_newcomment' ), SITE_NAME ) ); $email ['recipient'] = $a ['recipient']; break; // workgroups case 'file_alert' : if (isset ( $a ['is_shared'] ) && $a ['is_shared'] === true) { $intro = _t ( 'workshop', 'mail_file_body1b' ); $url = get_permalink ( $a['wlinkworkgroups'] ); $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'workshop', 'mail_file_subject_b' ), SITE_NAME ) ); } else { $intro = sprintf ( _t ( 'workshop', 'mail_file_body1' ), $a ['wname'] ); $url = get_permalink ( $a ['wlinkfiles'] ); $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'workshop', 'mail_file_subject' ), $a ['wname'], SITE_NAME ) ); } $email ['html_body'] = "" . $intro . "
" . PHP_EOL; $email ['html_body'] .= "" . sprintf ( _t ( 'workshop', 'mail_file_body2' ), $a ['owner'] ) . "
" . PHP_EOL; $email ['html_body'] .= "" . PHP_EOL; if (isset ( $a ['files'] )) { foreach ( $a ['files'] as $file ) { $email ['html_body'] .= "- " . $file . "" . _t ( 'workshop', 'mail_body_url' ) . "
" . PHP_EOL;
$email ['html_body'] .= "" . $url . "
" . _t ( 'workshop', 'mail_body_auth' ) . "
" . PHP_EOL; $email ['txt_body'] = strip_tags ( $email ['html_body'] ); $email ['recipient'] = $a ['recipient']; break; case 'topic_alert' : $email ['html_body'] = "" . sprintf ( _t ( 'workshop', 'mail_topic_body1' ), $a ['owner'], formatText ( $a ['topic_subject'], '2HTML' ), formatText ( $a ['wname'], '2HTML' ) ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_msg_content' ) . " :
" . PHP_EOL; $email ['html_body'] .= "" . formatText ( $a ['topic_body'], '2HTML' ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_body_url' ) . "
" . PHP_EOL;
$email ['html_body'] .= "" . get_permalink ( $a ['wlinkforum'] ) . "
" . _t ( 'workshop', 'mail_body_auth' ) . "
" . PHP_EOL; $email ['txt_body'] = strip_tags ( $email ['html_body'] ); $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'workshop', 'mail_topic_subject' ), $a ['wname'], SITE_NAME ) ); $email ['recipient'] = $a ['recipient']; break; case 'post_alert' : $email ['html_body'] = "" . sprintf ( _t ( 'workshop', 'mail_post_body1' ), $a ['owner'], formatText ( $a ['topic_subject'], '2HTML' ), formatText ( $a ['wname'], '2HTML' ) ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_msg_content' ) . " :
" . PHP_EOL; $email ['html_body'] .= "" . formatText ( $a ['topic_body'], '2HTML' ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_body_url' ) . "
" . PHP_EOL;
$email ['html_body'] .= "" . get_permalink ( $a ['wlinkforum'] ) . "
" . _t ( 'workshop', 'mail_body_auth' ) . "
" . PHP_EOL; $email ['txt_body'] = strip_tags ( $email ['html_body'] ); $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'workshop', 'mail_post_subject' ), $a ['wname'], SITE_NAME ) ); $email ['recipient'] = $a ['recipient']; break; case 'event_alert' : $email ['html_body'] = "" . sprintf ( _t ( 'workshop', 'mail_calendar_body1' ), $a ['owner'], formatText ( $a ['task_subject'], '2HTML' ), $a ['wname'], formatText ( $a ['task_date'], '2HTML' ) ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_calendar_body2' ) . "
" . PHP_EOL; $email ['html_body'] .= "" . formatText ( $a ['task_body'], '2HTML' ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_body_url' ) . "
" . PHP_EOL;
$email ['html_body'] .= "" . get_permalink ( $a ['wlinkcalendar'] ) . "
"._t('workshop','mail_body_auth') . "
".PHP_EOL; $email ['txt_body'] = strip_tags ( $email ['html_body'] ); $email ['subject'] = mb_ucfirst ( sprintf ( _t ( 'workshop', 'mail_calendar_subject' ), $a ['wname'], SITE_NAME ) ); $email ['recipient'] = $a ['recipient']; break; case 'workgroup_request' : $email ['html_body'] = "" . sprintf ( _t ( 'workshop', 'workgroup_request' ), $_SESSION ['userlogin'] ) . "
" . PHP_EOL; $email ['html_body'] .= "" . $a ['wgroups'] . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'divers', 'comment' ) . " : " . formatText ( $a['comment'], '2HTML' ) . "
" . PHP_EOL; $email ['html_body'] .= "" . _t ( 'workshop', 'mail_body_url' ) . "
" . $a ['moderate_link'] . "
";
$email ['html_body'] .= "(" . _t ( 'workshop', 'mail_body_auth' ) . ")
" . sprintf($a ['message'], '"' . $a['wgname'] . '"') . "
" . PHP_EOL; if($a['flag'] == 'accepted') { $email ['html_body'] .= "" . _t ( 'workshop', 'mail_body_url' ) . "
" . $a ['wglink'] . "
";
$email ['html_body'] .= "(" . _t ( 'workshop', 'mail_body_auth' ) . ")