/** * Override standard validation and sending notification to send the good PDF reports with * appropriate rigths. * * @see NotificationTarget::validateSendTo() * * @param string $event notification event * @param Array $infos Current user informations * @param Boolean $notify_me Notify the current user of his own actions ? * * @return boolean false to prevent standard mail sending */ function validateSendTo($event, array $infos, $notify_me = false) { global $DB; if (isset($infos['users_id'])) { // save session variables $saved_session = $_SESSION; // Get current user full informations $user = new User(); $user->getFromDB($infos['users_id']); // inialize session for user to build the proper PDF report unset($_SESSION['glpiprofiles'], $_SESSION['glpiactiveentities'], $_SESSION['glpiactiveprofile']); Session::initEntityProfiles($infos['users_id']); // Use default profile if exist if (isset($_SESSION['glpiprofiles'][$user->fields['profiles_id']])) { Session::changeProfile($user->fields['profiles_id']); // Else use first } else { Session::changeProfile(key($_SESSION['glpiprofiles'])); } $user_name = $infos['username'] . '_'; $file_name = $this->_buildPDF($user_name); $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/notifications/' . $file_name; $mmail = new NotificationMail(); $mmail->AddCustomHeader("Auto-Submitted: auto-generated"); // For exchange $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN"); // Get current entity administrator info to send the email from him $admin = $this->getSender(); $mmail->From = $admin['email']; $mmail->FromName = $admin['name']; // Attach pdf to mail $mmail->AddAttachment($path, $file_name); // Get content infos $query = 'SELECT * FROM glpi_notificationtemplatetranslations WHERE notificationtemplates_id = ( SELECT id FROM glpi_notificationtemplates WHERE itemtype = "PluginMreportingNotification" ) AND (language LIKE "' . $_SESSION['glpilanguage'] . '" OR language LIKE "") ORDER BY language DESC LIMIT 0, 1'; $result = $DB->query($query); $translation = $result->fetch_array(); $mmail->isHTML(true); $mmail->Subject = $translation['subject']; $mmail->Body = $translation['content_html']; $mmail->AltBody = $translation['content_text']; $mmail->AddAddress($infos['email']); if ($mmail->Send()) { } //restore session unset($_SESSION); $_SESSION = $saved_session; } return false; }
if (isset($_GET['help'])) { die("usage php testmail.php [ --from=email ] --to=email [ --enc=7bit|8bit|binary|base64|quoted-printable ]\n"); } $dat = date('r'); $secret = "l'été, ça roule !"; echo "From : $from\n"; echo "To : $dest\n"; echo "Date : $dat\n"; $mmail = new NotificationMail(); $mmail->From=$from; $mmail->FromName="GLPI test"; $mmail->isHTML(true); if ($enc) { $mmail->Encoding = $enc; } $mmail->Subject="GLPI test mail" . ($enc ? " ($enc)" : ''); $mmail->Body="<html><body><h3>GLPI test mail</h3><p>Encoding = <span class='b'>$enc</span></p>". "<p>Date = <span class='b'>$dat</span></p><p>Secret = <span class='b'>$secret</span>". "</p></body></html>"; $mmail->AltBody="GLPI test mail\nEncoding : $enc\nDate : $dat\nSecret=$secret"; $mmail->AddAddress($dest, ""); $logo=file_get_contents("../pics/logo-glpi-login.png"); $mmail->AddStringAttachment($logo,'glpi.png',($enc?$enc:'base64'),'image/png');