/** * Builds and returns the body of the email notification in plain text. * * @param object $post * @param object $userto * @return string The email body in plain text format. */ public function makeMailText($post, $userto) { global $CFG, $cm; $praxe = praxe_record::getData(); if (!isset($userto->viewfullnames[$praxe->id])) { if (!($cm = get_coursemodule_from_instance('praxe', $praxe->id, $this->course->id))) { print_error('Course Module ID was incorrect'); } $modcontext = context_module::instance($cm->id); $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); } else { $viewfullnames = $userto->viewfullnames[$praxe->id]; } //$by = New stdClass; //$by->name = fullname($userfrom, $viewfullnames); //$by->date = userdate($post->modified, "", $userto->timezone); //$strbynameondate = get_string('bynameondate', 'forum', $by); $strpraxes = get_string('modulenameplural', 'praxe'); $posttext = ''; $posttext = $this->course->shortname . " -> " . $strpraxes . " -> " . format_string($praxe->name, true); $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= format_string($this->subject, true); //$posttext .= "\n".$strbynameondate."\n"; $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= format_text_email(trusttext_strip($post), FORMAT_PLAIN); $posttext .= "\n\n---------------------------------------------------------------------\n"; $site = get_site(); foreach ($this->linkstofoot as $link) { $posttext .= $link->text . ": " . $link->link . "\t"; //$posttext .= get_string('confirmorrefusestudent','praxe').": ".$CFG->wwwroot.'/course/view.php?id='.$cm->id."\n\n"; } $posttext .= "\n\n" . $site->shortname . ": " . $CFG->wwwroot . "\n"; return $posttext; }
public function test_format_text_email() { $this->assertSame("This is a TEST", format_text_email('<p>This is a <strong>test</strong></p>', FORMAT_HTML)); $this->assertSame("This is a TEST", format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>', FORMAT_HTML)); $this->assertSame('& so is this', format_text_email('& so is this', FORMAT_HTML)); $this->assertSame('Two bullets: ' . core_text::code2utf8(8226) . ' *', format_text_email('Two bullets: • •', FORMAT_HTML)); $this->assertSame(core_text::code2utf8(0x7fd2) . core_text::code2utf8(0x7fd2), format_text_email('習習', FORMAT_HTML)); }
function test_format_text_email() { $this->assertEqual('This is a test', format_text_email('<p>This is a <strong>test</strong></p>', FORMAT_HTML)); $this->assertEqual('This is a test', format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>', FORMAT_HTML)); $this->assertEqual('& so is this', format_text_email('<p>& so is this</p>', FORMAT_HTML)); $tl = textlib_get_instance(); $this->assertEqual('Two bullets: ' . $tl->code2utf8(8226) . ' ' . $tl->code2utf8(8226), format_text_email('<p>Two bullets: • •</p>', FORMAT_HTML)); $this->assertEqual($tl->code2utf8(0x7fd2) . $tl->code2utf8(0x7fd2), format_text_email('<p>習習</p>', FORMAT_HTML)); }
function apply($discussion, $all, $selected, $formdata) { global $COURSE, $USER, $CFG; // Begin with standard text $a = (object) array('name' => fullname($USER, true)); // TODO Is this needed? It doesn't work; $CFG->stylesheets not there // $allhtml = "<head>"; // foreach ($CFG->stylesheets as $stylesheet) { // $allhtml .= '<link rel="stylesheet" type="text/css" href="' . // $stylesheet . '" />' . "\n"; // } // $allhtml .= "</head>\n'; $allhtml = "<body id='forumng-email'>\n"; $preface = get_string('forward_preface', 'forumngfeature_forward', $a); $allhtml .= $preface; $alltext = format_text_email($preface, FORMAT_HTML); // Include intro if specified if (!preg_match('~^(<br[^>]*>|<p>|</p>|\\s)*$~', $formdata->message['text'])) { $alltext .= "\n" . mod_forumng_cron::EMAIL_DIVIDER . "\n"; $allhtml .= '<hr size="1" noshade="noshade" />'; // Add intro $message = trusttext_strip($formdata->message['text']); $allhtml .= format_text($message, $formdata->message['format']); $alltext .= format_text_email($message, $formdata->message['format']); } // Get list of all post ids in discussion order $alltext .= "\n" . mod_forumng_cron::EMAIL_DIVIDER . "\n"; $allhtml .= '<hr size="1" noshade="noshade" />'; $poststext = ''; $postshtml = ''; $discussion->build_selected_posts_email($selected, $poststext, $postshtml); $alltext .= $poststext; $allhtml .= $postshtml . '</body>'; $emails = preg_split('~[; ]+~', $formdata->email); $subject = $formdata->subject; foreach ($emails as $email) { $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => 0); $from = $USER; $from->maildisplay = 999; // Nasty hack required for OU moodle if (!email_to_user($fakeuser, $from, $subject, $alltext, $allhtml)) { print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $formdata->email); } } // Log that it was sent $discussion->log('forward discussion', $formdata->email); if (!empty($formdata->ccme)) { if (!email_to_user($USER, $from, $subject, $alltext, $allhtml)) { print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $USER->email); } } $out = $discussion->init_page($discussion->get_moodle_url(), $this->get_page_name()); print $out->header(); print $out->box(get_string('forward_done', 'forumngfeature_forward')); print $out->continue_button(new moodle_url('/mod/forumng/discuss.php', $discussion->get_link_params_array())); print $out->footer(); }
public function apply($discussion, $all, $selected, $formdata) { global $COURSE, $USER, $CFG; // Begin with standard text. $a = (object) array('name' => fullname($USER, true)); $allhtml = "<body id='forumng-email'>\n"; $preface = get_string('forward_preface', 'forumngfeature_forward', $a); $allhtml .= $preface; $alltext = format_text_email($preface, FORMAT_HTML); // Include intro if specified. if (!preg_match('~^(<br[^>]*>|<p>|</p>|\\s)*$~', $formdata->message['text'])) { $alltext .= "\n" . \mod_forumng_cron::EMAIL_DIVIDER . "\n"; $allhtml .= '<hr size="1" noshade="noshade" />'; // Add intro. $message = trusttext_strip($formdata->message['text']); $allhtml .= format_text($message, $formdata->message['format']); $alltext .= format_text_email($message, $formdata->message['format']); } // Get list of all post ids in discussion order. $alltext .= "\n" . \mod_forumng_cron::EMAIL_DIVIDER . "\n"; $allhtml .= '<hr size="1" noshade="noshade" />'; $poststext = ''; $postshtml = ''; $discussion->build_selected_posts_email($selected, $poststext, $postshtml); $alltext .= $poststext; $allhtml .= $postshtml . '</body>'; $emails = preg_split('~[; ]+~', $formdata->email); $subject = $formdata->subject; foreach ($emails as $email) { $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => -1); $from = $USER; $from->maildisplay = 999; // Nasty hack required for OU moodle. if (!email_to_user($fakeuser, $from, $subject, $alltext, $allhtml)) { print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $formdata->email); } } // Log that it was sent. $params = array('context' => $discussion->get_forum()->get_context(), 'objectid' => $discussion->get_id(), 'other' => array('logurl' => $discussion->get_log_url(), 'info' => $formdata->email)); $event = \forumngfeature_forward\event\discussion_forwarded::create($params); $event->add_record_snapshot('course_modules', $discussion->get_course_module()); $event->add_record_snapshot('course', $discussion->get_course()); $event->trigger(); if (!empty($formdata->ccme)) { if (!email_to_user($USER, $from, $subject, $alltext, $allhtml)) { print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $USER->email); } } if ($this->printout) { $out = $discussion->init_page($discussion->get_moodle_url(), $this->get_page_name()); print $out->header(); print $out->box(get_string('forward_done', 'forumngfeature_forward')); print $out->continue_button(new \moodle_url('/mod/forumng/discuss.php', $discussion->get_link_params_array())); print $out->footer(); } }
function apply($discussion, $all, $selected, $formdata) { global $COURSE, $USER, $CFG; // Begin with standard text $a = (object) array('name' => fullname($USER, true)); $allhtml = "<head>"; foreach ($CFG->stylesheets as $stylesheet) { $allhtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n"; } $allhtml .= "</head>\n<body id='forumng-email'>\n"; $preface = get_string('forward_preface', 'forumng', $a); $allhtml .= $preface; $alltext = format_text_email($preface, FORMAT_HTML); // Include intro if specified if (!preg_match('~^(<br[^>]*>|<p>|</p>|\\s)*$~', $formdata->message)) { $alltext .= "\n" . forum_cron::EMAIL_DIVIDER . "\n"; $allhtml .= '<hr size="1" noshade="noshade" />'; // Add intro $message = trusttext_strip(stripslashes($formdata->message)); $allhtml .= format_text($message, $formdata->format); $alltext .= format_text_email($message, $formdata->format); } // Get list of all post ids in discussion order $alltext .= "\n" . forum_cron::EMAIL_DIVIDER . "\n"; $allhtml .= '<hr size="1" noshade="noshade" />'; $poststext = ''; $postshtml = ''; $discussion->build_selected_posts_email($selected, $poststext, $postshtml); $alltext .= $poststext; $allhtml .= $postshtml . '</body>'; $emails = preg_split('~[; ]+~', $formdata->email); $subject = stripslashes($formdata->subject); foreach ($emails as $email) { $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => 0); $from = $USER; $from->maildisplay = 999; // Nasty hack required for OU moodle if (!email_to_user($fakeuser, $from, $subject, $alltext, $allhtml)) { print_error('error_forwardemail', 'forumng', $formdata->email); } } // Log that it was sent $discussion->log('forward discussion', $formdata->email); if (!empty($formdata->ccme)) { if (!email_to_user($USER, $from, $subject, $alltext, $allhtml)) { print_error('error_forwardemail', 'forumng', $USER->email); } } $discussion->print_subpage_header($this->get_page_name()); print_box(get_string('forward_done', 'forumng')); print_continue('../../discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN)); print_footer($COURSE); }
/** * Builds and returns the body of the email notification in plain text. * * @global object * @global object * @uses CONTEXT_MODULE * @param object $course * @param object $cm * @param object $forum * @param object $discussion * @param object $post * @param object $userfrom * @param object $userto * @param boolean $bare * @param string $replyaddress The inbound address that a user can reply to the generated e-mail with. [Since 2.8]. * @return string The email body in plain text format. */ function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $bare = false, $replyaddress = null) { global $CFG, $USER; $modcontext = context_module::instance($cm->id); if (!isset($userto->viewfullnames[$forum->id])) { $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); } else { $viewfullnames = $userto->viewfullnames[$forum->id]; } if (!isset($userto->canpost[$discussion->id])) { $canreply = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext); } else { $canreply = $userto->canpost[$discussion->id]; } $by = new stdClass(); $by->name = fullname($userfrom, $viewfullnames); $by->date = userdate($post->modified, "", $userto->timezone); $strbynameondate = get_string('bynameondate', 'forum', $by); $strforums = get_string('forums', 'forum'); $canunsubscribe = !\mod_forum\subscriptions::is_forcesubscribed($forum); $posttext = ''; if (!$bare) { $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $posttext .= "{$shortname} -> {$strforums} -> " . format_string($forum->name, true); if ($discussion->name != $forum->name) { $posttext .= " -> " . format_string($discussion->name, true); } } // add absolute file links $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id); $posttext .= "\n"; $posttext .= $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $discussion->id; $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= format_string($post->subject, true); if ($bare) { $posttext .= " ({$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id})"; } $posttext .= "\n" . $strbynameondate . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= format_text_email($post->message, $post->messageformat); $posttext .= "\n\n"; $posttext .= forum_print_attachments($post, $cm, "text"); if (!$bare) { if ($canreply) { $posttext .= "---------------------------------------------------------------------\n"; $posttext .= get_string("postmailinfo", "forum", $shortname) . "\n"; $posttext .= "{$CFG->wwwroot}/mod/forum/post.php?reply={$post->id}\n"; } if ($canunsubscribe) { if (\mod_forum\subscriptions::is_subscribed($userto->id, $forum, null, $cm)) { // If subscribed to this forum, offer the unsubscribe link. $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("unsubscribe", "forum"); $posttext .= ": {$CFG->wwwroot}/mod/forum/subscribe.php?id={$forum->id}\n"; } // Always offer the unsubscribe from discussion link. $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("unsubscribediscussion", "forum"); $posttext .= ": {$CFG->wwwroot}/mod/forum/subscribe.php?id={$forum->id}&d={$discussion->id}\n"; } } $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("digestmailpost", "forum"); $posttext .= ": {$CFG->wwwroot}/mod/forum/index.php?id={$forum->course}\n"; if ($replyaddress) { $posttext .= "\n\n" . get_string('replytopostbyemail', 'mod_forum'); } return $posttext; }
/** * The plaintext version of the e-mail message. * * @param \stdClass $cm * @param \stdClass $post * @return string */ public function format_message_text($cm, $post) { $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', \context_module::instance($cm->id)->id, 'mod_forum', 'post', $post->id); return format_text_email($message, $post->messageformat); }
/** * Builds and returns the body of the email notification in plain text. * * @param object $course * @param object $forum * @param object $discussion * @param object $post * @param object $userfrom * @param object $userto * @param boolean $bare * @return string The email body in plain text format. */ function forum_make_mail_text($course, $forum, $discussion, $post, $userfrom, $userto, $bare = false) { global $CFG, $USER; if (!isset($userto->viewfullnames[$forum->id])) { if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id))) { error('Course Module ID was incorrect'); } $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); } else { $viewfullnames = $userto->viewfullnames[$forum->id]; } if (!isset($userto->canpost[$discussion->id])) { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $canreply = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext); } else { $canreply = $userto->canpost[$discussion->id]; } $by = new stdClass(); $by->name = fullname($userfrom, $viewfullnames); $by->date = userdate($post->modified, "", $userto->timezone); $strbynameondate = get_string('bynameondate', 'forum', $by); $strforums = get_string('forums', 'forum'); $canunsubscribe = !forum_is_forcesubscribed($forum); $posttext = ''; if (!$bare) { $posttext = "{$course->shortname} -> {$strforums} -> " . format_string($forum->name, true); if ($discussion->name != $forum->name) { $posttext .= " -> " . format_string($discussion->name, true); } } $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= format_string($post->subject, true); if ($bare) { $posttext .= " ({$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id})"; } $posttext .= "\n" . $strbynameondate . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= format_text_email(trusttext_strip($post->message), $post->format); $posttext .= "\n\n"; if ($post->attachment) { $post->course = $course->id; $post->forum = $forum->id; $posttext .= forum_print_attachments($post, "text"); } if (!$bare && $canreply) { $posttext .= "---------------------------------------------------------------------\n"; $posttext .= get_string("postmailinfo", "forum", $course->shortname) . "\n"; $posttext .= "{$CFG->wwwroot}/mod/forum/post.php?reply={$post->id}\n"; } if (!$bare && $canunsubscribe) { $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("unsubscribe", "forum"); $posttext .= ": {$CFG->wwwroot}/mod/forum/subscribe.php?id={$forum->id}\n"; } return $posttext; }
/** * Send a copy to the user email according to the user's preferences * @param block_jmail_message $message A full message object * @return boolean True if the message have been sent succesfully */ private function send_copy($message) { global $DB, $CFG; $mailresult = true; $site = get_site(); // We ensure that is a message sent and approved if (!$message->timesent or !$message->approved) { return false; } add_to_log($this->course->id, 'jmail', 'message sent'); $message = $message->full(); if ($message->destinataries) { $url = $CFG->wwwroot . '/blocks/jmail/mailbox.php?id=' . $this->course->id; foreach ($message->destinataries as $type => $destinataries) { foreach ($destinataries as $dest) { $userprefs = $this->load_user_preferences($dest->userid); if ($userprefs->receivecopies && ($userto = $DB->get_record('user', array('id' => $dest->userid)))) { $bodytext = get_string('emailcopyheader', 'block_jmail', $url) . "<br /><br />"; $bodytext .= $message->body . "<br /><br />"; $bodytext .= get_string('emailcopyfooter', 'block_jmail', $url); $bodytext = format_text_email($bodytext, FORMAT_HTML); $mailresult = email_to_user($userto, $site->shortname, $message->subject, $bodytext, '', '', '', true, ''); } } } } // TODO, handle possible errors return true; }
function message_post_message($userfrom, $userto, $message, $format, $messagetype) { global $CFG, $SITE, $USER; /// Set up current language to suit the receiver of the message $savelang = $USER->lang; if (!empty($userto->lang)) { $USER->lang = $userto->lang; } /// Save the new message in the database $savemessage = NULL; $savemessage->useridfrom = $userfrom->id; $savemessage->useridto = $userto->id; $savemessage->message = $message; $savemessage->format = $format; $savemessage->timecreated = time(); $savemessage->messagetype = 'direct'; if ($CFG->messaging) { if (!($savemessage->id = insert_record('message', $savemessage))) { return false; } $emailforced = false; } else { // $CFG->messaging is not on, we need to force sending of emails $emailforced = true; $savemessage->id = true; } /// Check to see if anything else needs to be done with it $preference = (object) get_user_preferences(NULL, NULL, $userto->id); if ($emailforced || (!isset($preference->message_emailmessages) || $preference->message_emailmessages)) { // Receiver wants mail forwarding if (!isset($preference->message_emailtimenosee)) { $preference->message_emailtimenosee = 10; } if (!isset($preference->message_emailformat)) { $preference->message_emailformat = FORMAT_HTML; } if ($emailforced || time() - $userto->lastaccess > (int) $preference->message_emailtimenosee * 60) { // Long enough $message = stripslashes_safe($message); $tagline = get_string('emailtagline', 'message', $SITE->shortname); $messagesubject = preg_replace('/\\s+/', ' ', strip_tags($message)); // make sure it's all on one line $messagesubject = message_shorten_message($messagesubject, 30) . '...'; $messagetext = format_text_email($message, $format) . "\n\n--\n" . $tagline . "\n" . "{$CFG->wwwroot}/message/index.php?popup=1"; if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) { $messagehtml = format_text($message, $format); // MDL-10294, do not print link if messaging is disabled if ($CFG->messaging) { $messagehtml .= '<hr /><p><a href="' . $CFG->wwwroot . '/message/index.php?popup=1">' . $tagline . '</a></p>'; } } else { $messagehtml = NULL; } if (!empty($preference->message_emailaddress)) { $userto->email = $preference->message_emailaddress; // Use custom messaging address } if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) { $CFG->messagewasjustemailed = true; } sleep(3); } } $USER->lang = $savelang; // restore original language return $savemessage->id; }
function reservasalas_sendMail($values, $error, $user, $asistentes, $eventname, $buildingid) { global $USER, $DB; $userfrom = core_user::get_noreply_user(); $userfrom->maildisplay = true; $sql = "SELECT s.nombre as sedenombre, e.nombre as edificionombre\n\t\t\tFROM {reservasalas_edificios} AS e JOIN {reservasalas_sedes} AS s ON (e.sedes_id = s.id)\n\t\t\tWHERE s.id = ?"; $names = $DB->get_record_sql($sql, array($buildingid)); $message = get_string("dear", "local_reservasalas") . $USER->firstname . " " . $USER->lastname . ": \n \n"; $message .= get_string("bookinginformation", "local_reservasalas") . "\n \n"; $message .= get_string("site", "local_reservasalas") . ": " . $names->sedenombre . "\n"; $message .= get_string("buildings", "local_reservasalas") . ": " . $names->edificionombre . "\n"; $message .= get_string("roomtype", "local_reservasalas") . ": Estudio \n"; $message .= get_string("event", "local_reservasalas") . ": " . $eventname . "\n"; $message .= get_string("assistants", "local_reservasalas") . ": " . $asistentes . "\n"; $message .= get_string("responsibility", "local_reservasalas") . ": " . $USER->firstname . " " . $USER->lastname . "\n"; $message .= get_string("rooms", "local_reservasalas") . ": \n"; foreach ($values as $value) { $stamp = strtotime($value["fecha"]); $day = date("l", $stamp); $message .= get_string("date", "local_reservasalas") . ": " . $day . " " . $value["fecha"] . " - " . get_string("room", "local_reservasalas") . ": " . $value["nombresala"] . " - " . get_string("module", "local_reservasalas") . ": " . $value["nombremodulo"] . "\n"; } // Format each "\n" into a line break $formattedMessage = nl2br($message); $eventdata = new stdClass(); $eventdata->component = "local_reservasalas"; // your component name $eventdata->name = "reservenotification"; // this is the message name from messages.php $eventdata->userfrom = $userfrom; $eventdata->userto = $user; $eventdata->subject = get_string("confirmationbooking", "local_reservasalas"); $eventdata->fullmessage = format_text_email($formattedMessage, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_HTML; $eventdata->fullmessagehtml = ""; $eventdata->smallmessage = ""; $eventdata->notification = 1; // this is only set to 0 for personal messages between users message_send($eventdata); }
function message_post_message($userfrom, $userto, $message, $format, $messagetype) { global $CFG, $SITE; /// Save the new message in the database $savemessage = NULL; $savemessage->useridfrom = $userfrom->id; $savemessage->useridto = $userto->id; $savemessage->message = $message; $savemessage->format = $format; $savemessage->timecreated = time(); $savemessage->messagetype = 'direct'; if (!($savemessage->id = insert_record('message', $savemessage))) { return false; } /// Check to see if anything else needs to be done with it $preference = (object) get_user_preferences(NULL, NULL, $userto->id); if (!isset($preference->message_emailmessages) || $preference->message_emailmessages) { // Receiver wants mail forwarding if (!isset($preference->message_emailtimenosee)) { $preference->message_emailtimenosee = 10; } if (!isset($preference->message_emailformat)) { $preference->message_emailformat = FORMAT_HTML; } if (time() - $userto->lastaccess > (int) $preference->message_emailtimenosee * 60) { // Long enough $message = stripslashes_safe($message); $tagline = get_string('emailtagline', 'message', $SITE->shortname); $messagesubject = message_shorten_message(strip_tags($message), 30) . '...'; $messagetext = format_text_email($message, $format) . "\n\n--\n" . $tagline . "\n" . "{$CFG->wwwroot}/message/index.php?popup=1"; if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) { $messagehtml = format_text($message, $format); $messagehtml .= '<hr /><p><a href="' . $CFG->wwwroot . '/message/index.php?popup=1">' . $tagline . '</a></p>'; } else { $messagehtml = NULL; } if (!empty($preference->message_emailaddress)) { $userto->email = $preference->message_emailaddress; // Use custom messaging address } if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) { $CFG->messagewasjustemailed = true; } sleep(3); } } return $savemessage->id; }
// get the new name (name may change due to filename collisions) $attachname = $um->get_new_filename(); } else { $form->error = get_string("attachmenterror", "block_quickmail", $form->attachment); } } else { $form->attachment = ''; // no attachment } } // no errors, then email if (!isset($form->error)) { $mailedto = array(); // holds all the userid of successful emails // get the correct formating for the emails $form->plaintxt = format_text_email($form->message, $form->format); // plain text $form->html = format_text($form->message, $form->format); // html // run through each user id and send a copy of the email to him/her // not sending 1 email with CC to all user ids because emails were required to be kept private foreach ($form->mailto as $userid) { if (!$courseusers[$userid]->emailstop) { $mailresult = email_to_user($courseusers[$userid], $USER, $form->subject, $form->plaintxt, $form->html, $attachment, $attachname); // checking for errors, if there is an error, store the name if (!$mailresult || (string) $mailresult == 'emailstop') { $form->error = get_string('emailfailerror', 'block_quickmail'); $form->usersfail['emailfail'][] = $courseusers[$userid]->lastname . ', ' . $courseusers[$userid]->firstname; } else { // success $mailedto[] = $userid;
function process($data) { global $CFG, $USER; $this->process_referrals(); // Process Attachment $course = get_record('course', 'id', $this->courseid); list($attachmentname, $attachment) = $this->process_attachment($course); // Outputing info as mtrace in case developers want to report // as Moodle cron mtrace('<div class="report_wrap"> <h2 class="">' . get_string('sending', 'block_student_gradeviewer') . '</h2> <ul class="student_list">'); // Set the from here; If the teacher sends anonymously, // then send with a no reply $from = isset($data->anonymous) ? get_string('noreplyname') : $USER; // Foreach user, send report to mentor foreach ($this->users as $id => $user) { // Find the section the user is enrolled in $section = lookup_section($user, $course); // Format section: DEPT 1001 - 001 $a->course = get_string('format_section', 'block_courseprefs', $section); // Format User's fullname: Firstname Lastname $a->user = fullname($user); // DEPT 1001 - 001 Report For Firstname Lastname $subject = get_string('subject_report', 'block_student_gradeviewer', $a); // Mentee link in student_grade viewer $grade_link = $CFG->wwwroot . '/blocks/student_gradeviewer/mentee.php?id=' . $id . ($this->courseid ? '&courseid=' . $this->courseid : ''); // Grades Overview for Firstname Lastname: $mentee = get_string('grade_link', 'block_student_gradeviewer', $a); $body = $data->report; mtrace('<li><h2>' . $a->user . '</h2> <ul class="student_list">'); // Get this user's mentors to email, if any at all $mentors = lookup_mentors($user); if (!$mentors) { mtrace('<li>' . get_string('no_mentor', 'block_student_gradeviewer', $a) . '</li></ul></li>'); continue; } // If any mentors email them what the teacher said foreach ($mentors as $mentor) { $code = 'success'; mtrace('<li>' . get_string('mentor', 'block_student_gradeviewer', $mentor)); $result = email_to_user($mentor, $from, $subject, format_text_email($body . "\n" . $mentee . $grade_link, 1), format_text($body . "<br/>" . $mentee . '<a href="' . $grade_link . '">' . $grade_link . '</a>', 1), $attachment, $attachmentname); // Email failed if (!$result) { $code = 'fail'; } mtrace(get_string($code, 'block_student_gradeviewer') . '</li>'); } mtrace('</ul></li>'); } mtrace(' </ul>'); if ($this->courseid) { print_continue($CFG->wwwroot . '/course/view.php?id=' . $this->courseid); } mtrace('</div>'); }
// Append links to attachments, if any ///////////////////////////// $data->messageWithSigAndAttach .= quickmail::process_attachments($context, $data, $table, $data->id); // Prepare html content of message $data->message = file_rewrite_pluginfile_urls($data->message, 'pluginfile.php', $context->id, 'block_quickmail', $table, $data->id, $editor_options); // Same user, alternate email ////////////////////////////////////// if (!empty($data->alternateid)) { $user = clone $USER; $user->email = $alternates[$data->alternateid]; } else { $user = $USER; } $data->failuserids = array(); // DWE -> Begin hopefully new way of dealing with messagetext and messagehtml // TEXT // This is where we'll need to factor in the preferences of the receiver. $messagetext = format_text_email($data->messageWithSigAndAttach, $data->format); // HTML $messagehtml = format_text($data->messageWithSigAndAttach, $data->format); if (!empty($data->mailto)) { foreach (explode(',', $data->mailto) as $userid) { // Email gets sent here $success = email_to_user($everyone[$userid], $user, $subject, $messagetext, $messagehtml); if (!$success) { $warnings[] = get_string("no_email", 'block_quickmail', $everyone[$userid]); $data->failuserids[] = $userid; } } } if (!empty($data->additional_emails)) { $additional_email_array = preg_split('/[,;]/', $data->additional_emails); $i = 0;
$attendance_exists = $DB->record_exists('local_attendance_attendance', array('sessionid' => $session, 'userid' => $fromform->userid)); $name = empty($sessiondate->comment) ? get_string('noname', 'local_attendance') : $sessiondate->comment; if (!$attendance_exists) { $dateData .= date('d/m/Y', $sessiondate->date) . ' - ' . $name . '<br>'; if ($DB->insert_record('local_attendance_attendance', array('sessionid' => $session, 'userid' => $fromform->userid))) { $row = new html_table_row(array($name, get_string('yes', 'local_attendance'), '<div class="green">' . get_string('emailsent', 'local_attendance') . '</div>')); $table->data[] = $row; } } else { $row = new html_table_row(array($name, 'No', '<div class="red">' . get_string('alreadypresent', 'local_attendance') . '</div>')); $table->data[] = $row; } } if ($dateData != NULL) { $message = '<br><br><br>' . get_string('dear', 'local_attendance') . ',' . '<br>' . get_string('professor', 'local_attendance') . ' ' . $USER->firstname . ' ' . $USER->lastname . ' ' . get_string('changestatus', 'local_attendance') . ' ' . get_string('attendant', 'local_attendance') . ' ' . get_string('onthecourse', 'local_attendance') . ' ' . $courseName->fullname . ', ' . get_string('inthesession', 'local_attendance') . ':<br><br>' . $dataHead . $dateData; $eventdata->fullmessage = format_text_email($message, FORMAT_HTML); $send = message_send($eventdata); } } $back = new moodle_url('/local/attendance/viewstudentrecord.php', array('action' => 'view_student_details', 'courseid' => $courseid, 'userid' => $userid)); echo $OUTPUT->single_button($back, get_string('back', 'local_attendance')); echo html_writer::table($table); echo $OUTPUT->single_button($back, get_string('back', 'local_attendance')); } else { echo '<div class="alert alert-danger">' . get_string('selectsession', 'local_attendance') . '</div>'; $action = 'view_student_details'; } } } if ($action == 'view_student_details') { $userid = required_param('userid', PARAM_INT);
/** * @return string Message after format_text_email and replacing file URLs */ public function get_email_message() { global $CFG; require_once $CFG->dirroot . '/lib/filelib.php'; $text = file_rewrite_pluginfile_urls($this->postfields->message, 'pluginfile.php', $this->get_forum()->get_context(true)->id, 'mod_forumng', 'message', $this->postfields->id); return format_text_email($text, $this->postfields->messageformat); }
/** * Builds and returns the body of the email notification in plain text. * * @global object * @global object * @uses CONTEXT_MODULE * @param object $course * @param object $cm * @param object $anonforum * @param object $discussion * @param object $post * @param object $userfrom * @param object $userto * @param boolean $bare * @return string The email body in plain text format. */ function anonforum_make_mail_text($course, $cm, $anonforum, $discussion, $post, $userfrom, $userto, $bare = false) { global $CFG, $USER; $modcontext = context_module::instance($cm->id); if (!isset($userto->viewfullnames[$anonforum->id])) { $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); } else { $viewfullnames = $userto->viewfullnames[$anonforum->id]; } if (!isset($userto->canpost[$discussion->id])) { $canreply = anonforum_user_can_post($anonforum, $discussion, $userto, $cm, $course, $modcontext); } else { $canreply = $userto->canpost[$discussion->id]; } $by = new stdClass(); if (empty($post->anonymouspost)) { $by->name = fullname($userfrom, $viewfullnames); } else { $by->name = get_string('anonymoususer', 'anonforum'); } $by->date = userdate($post->modified, "", $userto->timezone); $strbynameondate = get_string('bynameondate', 'anonforum', $by); $stranonforums = get_string('anonforums', 'anonforum'); $canunsubscribe = !anonforum_is_forcesubscribed($anonforum); $posttext = ''; if (!$bare) { $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $posttext = "{$shortname} -> {$stranonforums} -> " . format_string($anonforum->name, true); if ($discussion->name != $anonforum->name) { $posttext .= " -> " . format_string($discussion->name, true); } } // add absolute file links $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_anonforum', 'post', $post->id); $posttext .= "\n"; $posttext .= $CFG->wwwroot . '/mod/anonforum/discuss.php?d=' . $discussion->id; $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= format_string($post->subject, true); if ($bare) { $posttext .= " ({$CFG->wwwroot}/mod/anonforum/discuss.php?d={$discussion->id}#p{$post->id})"; } $posttext .= "\n" . $strbynameondate . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= format_text_email($post->message, $post->messageformat); $posttext .= "\n\n"; $posttext .= anonforum_print_attachments($post, $cm, "text"); if (!$bare && $canreply) { $posttext .= "---------------------------------------------------------------------\n"; $posttext .= get_string("postmailinfo", "anonforum", $shortname) . "\n"; $posttext .= "{$CFG->wwwroot}/mod/anonforum/post.php?reply={$post->id}\n"; } if (!$bare && $canunsubscribe) { $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("unsubscribe", "anonforum"); $posttext .= ": {$CFG->wwwroot}/mod/anonforum/subscribe.php?id={$anonforum->id}\n"; } $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("digestmailpost", "anonforum"); $posttext .= ": {$CFG->wwwroot}/mod/anonforum/index.php?id={$anonforum->course}\n"; return $posttext; }
function send_mail($values, $error, $user, $asistentes, $eventname) { global $USER; $userfrom = core_user::get_noreply_user(); $userfrom->maildisplay = true; $message = get_string('dear', 'local_reservasalas') . $USER->firstname . ' ' . $USER->lastname . ': '; $message .= '<br></br>'; $message .= '<br></br>'; $message .= get_string('bookinginformation', 'local_reservasalas'); $message .= '<br></br>'; $message .= '<br></br>'; $message .= get_string('site', 'local_reservasalas') . ': ' . $campusId->nombre; $message .= '<br></br>'; $message .= get_string('buildings', 'local_reservasalas') . ': ' . $buildingId->nombre; $message .= '<br></br>'; $message .= get_string('roomtype', 'local_reservasalas') . ': Estudio'; $message .= '<br></br>'; $message .= get_string('event', 'local_reservasalas') . ': ' . $eventname; $message .= '<br></br>'; $message .= get_string('assistants', 'local_reservasalas') . ': ' . $asistentes; $message .= '<br></br>'; $message .= get_string('responsibility', 'local_reservasalas') . ': ' . $USER->firstname . ' ' . $USER->lastname; $message .= '<br></br>'; $message .= get_string('rooms', 'local_reservasalas') . ': '; $message .= '<br></br>'; foreach ($values as $value) { $message .= get_string('date', 'local_reservasalas') . ': ' . date("Y-m-d", $value["fecha"]) . ' - ' . get_string('room', 'local_reservasalas') . ': ' . $value['nombresala'] . ' - ' . get_string('module', 'local_reservasalas') . ': ' . $value['nombremodulo']; $message .= '<br></br>'; } $eventdata = new stdClass(); $eventdata->component = 'local_reservasalas'; // your component name $eventdata->name = 'reservenotification'; // this is the message name from messages.php $eventdata->userfrom = $userfrom; $eventdata->userto = $user; $eventdata->subject = get_string('confirmationbooking', 'local_reservasalas'); $eventdata->fullmessage = format_text_email($message, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_HTML; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; $eventdata->notification = 1; // this is only set to 0 for personal messages between users message_send($eventdata); }
/** * Test get_messages. */ public function test_get_messages() { global $CFG; $this->resetAfterTest(true); $this->preventResetByRollback(); // This mark the messages as read!. $sink = $this->redirectMessages(); $user1 = self::getDataGenerator()->create_user(); $user2 = self::getDataGenerator()->create_user(); $user3 = self::getDataGenerator()->create_user(); $course = self::getDataGenerator()->create_course(); // Send a message from one user to another. message_post_message($user1, $user2, 'some random text 1', FORMAT_MOODLE); message_post_message($user1, $user3, 'some random text 2', FORMAT_MOODLE); message_post_message($user2, $user3, 'some random text 3', FORMAT_MOODLE); message_post_message($user3, $user2, 'some random text 4', FORMAT_MOODLE); message_post_message($user3, $user1, 'some random text 5', FORMAT_MOODLE); $this->setUser($user1); // Get read conversations from user1 to user2. $messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(1, $messages['messages']); // Get unread conversations from user1 to user2. $messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', false, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(0, $messages['messages']); // Get read messages send from user1. $messages = core_message_external::get_messages(0, $user1->id, 'conversations', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(2, $messages['messages']); $this->setUser($user2); // Get read conversations from any user to user2. $messages = core_message_external::get_messages($user2->id, 0, 'conversations', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(2, $messages['messages']); $this->setUser($user3); // Get read notifications received by user3. $messages = core_message_external::get_messages($user3->id, 0, 'notifications', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(0, $messages['messages']); // Now, create some notifications... // We are creating fake notifications but based on real ones. // This one omits notification = 1. $eventdata = new stdClass(); $eventdata->modulename = 'moodle'; $eventdata->component = 'enrol_paypal'; $eventdata->name = 'paypal_enrolment'; $eventdata->userfrom = get_admin(); $eventdata->userto = $user1; $eventdata->subject = "Moodle: PayPal payment"; $eventdata->fullmessage = "Your PayPal payment is pending."; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; message_send($eventdata); $message = new stdClass(); $message->notification = 1; $message->component = 'enrol_manual'; $message->name = 'expiry_notification'; $message->userfrom = $user2; $message->userto = $user1; $message->subject = 'Enrolment expired'; $message->fullmessage = 'Enrolment expired blah blah blah'; $message->fullmessageformat = FORMAT_MARKDOWN; $message->fullmessagehtml = markdown_to_html($message->fullmessage); $message->smallmessage = $message->subject; $message->contexturlname = $course->fullname; $message->contexturl = (string) new moodle_url('/course/view.php', array('id' => $course->id)); message_send($message); $userfrom = core_user::get_noreply_user(); $userfrom->maildisplay = true; $eventdata = new stdClass(); $eventdata->component = 'moodle'; $eventdata->name = 'badgecreatornotice'; $eventdata->userfrom = $userfrom; $eventdata->userto = $user1; $eventdata->notification = 1; $eventdata->subject = 'New badge'; $eventdata->fullmessage = format_text_email($eventdata->subject, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $eventdata->subject; $eventdata->smallmessage = $eventdata->subject; message_send($eventdata); $eventdata = new stdClass(); $eventdata->name = 'submission'; $eventdata->component = 'mod_feedback'; $eventdata->userfrom = $user1; $eventdata->userto = $user2; $eventdata->subject = 'Feedback submitted'; $eventdata->fullmessage = 'Feedback submitted from an user'; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = '<strong>Feedback submitted</strong>'; $eventdata->smallmessage = ''; message_send($eventdata); $this->setUser($user1); // Get read notifications from any user to user1. $messages = core_message_external::get_messages($user1->id, 0, 'notifications', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(3, $messages['messages']); // Get one read notifications from any user to user1. $messages = core_message_external::get_messages($user1->id, 0, 'notifications', true, true, 0, 1); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(1, $messages['messages']); // Get unread notifications from any user to user1. $messages = core_message_external::get_messages($user1->id, 0, 'notifications', false, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(0, $messages['messages']); // Get read both type of messages from any user to user1. $messages = core_message_external::get_messages($user1->id, 0, 'both', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(4, $messages['messages']); // Get read notifications from no-reply-user to user1. $messages = core_message_external::get_messages($user1->id, $userfrom->id, 'notifications', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(1, $messages['messages']); // Get notifications send by user1 to any user. $messages = core_message_external::get_messages(0, $user1->id, 'notifications', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(1, $messages['messages']); // Test warnings. $CFG->messaging = 0; $messages = core_message_external::get_messages(0, $user1->id, 'both', true, true, 0, 0); $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages); $this->assertCount(1, $messages['warnings']); // Test exceptions. // Messaging disabled. try { $messages = core_message_external::get_messages(0, $user1->id, 'conversations', true, true, 0, 0); $this->fail('Exception expected due messaging disabled.'); } catch (moodle_exception $e) { $this->assertEquals('disabled', $e->errorcode); } $CFG->messaging = 1; // Invalid users. try { $messages = core_message_external::get_messages(0, 0, 'conversations', true, true, 0, 0); $this->fail('Exception expected due invalid users.'); } catch (moodle_exception $e) { $this->assertEquals('accessdenied', $e->errorcode); } // Invalid user ids. try { $messages = core_message_external::get_messages(2500, 0, 'conversations', true, true, 0, 0); $this->fail('Exception expected due invalid users.'); } catch (moodle_exception $e) { $this->assertEquals('invaliduser', $e->errorcode); } // Invalid users (permissions). $this->setUser($user2); try { $messages = core_message_external::get_messages(0, $user1->id, 'conversations', true, true, 0, 0); $this->fail('Exception expected due invalid user.'); } catch (moodle_exception $e) { $this->assertEquals('accessdenied', $e->errorcode); } }
/** * Creates single message for all notification and sends it out * * @param object $badge A badge which is notified about. */ function badge_assemble_notification(stdClass $badge) { global $DB; $userfrom = core_user::get_noreply_user(); $userfrom->maildisplay = true; if ($msgs = $DB->get_records_select('badge_issued', 'issuernotified IS NULL AND badgeid = ?', array($badge->id))) { // Get badge creator. $creator = $DB->get_record('user', array('id' => $badge->creator), '*', MUST_EXIST); $creatorsubject = get_string('creatorsubject', 'badges', $badge->name); $creatormessage = ''; // Put all messages in one digest. foreach ($msgs as $msg) { $issuedlink = html_writer::link(new moodle_url('/badges/badge.php', array('hash' => $msg->uniquehash)), $badge->name); $recipient = $DB->get_record('user', array('id' => $msg->userid), '*', MUST_EXIST); $a = new stdClass(); $a->user = fullname($recipient); $a->link = $issuedlink; $creatormessage .= get_string('creatorbody', 'badges', $a); $DB->set_field('badge_issued', 'issuernotified', time(), array('badgeid' => $msg->badgeid, 'userid' => $msg->userid)); } // Create a message object. $eventdata = new stdClass(); $eventdata->component = 'moodle'; $eventdata->name = 'badgecreatornotice'; $eventdata->userfrom = $userfrom; $eventdata->userto = $creator; $eventdata->notification = 1; $eventdata->subject = $creatorsubject; $eventdata->fullmessage = format_text_email($creatormessage, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $creatormessage; $eventdata->smallmessage = $creatorsubject; message_send($eventdata); } }
function local_mail_send_notifications($message) { global $SITE; $plaindata = new stdClass; $htmldata = new stdClass; // Send the mail now! foreach ($message->recipients() as $userto) { $attachment = ''; if ($message->has_attachment(false)) { $attachment = get_string('hasattachments', 'local_mail'); } $plaindata->user = fullname($message->sender()); $plaindata->subject = $message->subject() . ' ' . $attachment; $plaindata->content = $message->content(); $htmldata->user = fullname($message->sender()); $htmldata->subject = $message->subject() . ' ' . $attachment; $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox', 'm' => $message->id())); $htmldata->url = $url->out(false); $htmldata->content = $message->content(); $fullplainmessage = format_text_email(get_string('notificationbody', 'local_mail', $plaindata), $message->format()); $eventdata = new stdClass(); $eventdata->component = 'local_mail'; $eventdata->name = 'mail'; $eventdata->userfrom = $message->sender(); $eventdata->userto = core_user::get_user($userto->id); $eventdata->subject = get_string('notificationsubject', 'local_mail', $SITE->shortname); $eventdata->fullmessage = $fullplainmessage; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = get_string('notificationbodyhtml', 'local_mail', $htmldata); $eventdata->notification = 1; $smallmessagestrings = new stdClass(); $smallmessagestrings->user = fullname($message->sender()); $smallmessagestrings->message = $message->subject(); $eventdata->smallmessage = get_string_manager()->get_string('smallmessage', 'local_mail', $smallmessagestrings); $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox', 'm' => $message->id())); $eventdata->contexturl = $url->out(false); $eventdata->contexturlname = $message->subject(); $mailresult = message_send($eventdata); if (!$mailresult) { mtrace("Error: local/mail/locallib.php local_mail_send_mail(): Could not send out mail for id {$message->id()} to user {$message->sender()->id}". " ($userto->email) .. not trying again."); } else if (get_user_preferences('local_mail_markasread', false, $userto)) { // Set message as read depending on user preferences $message->set_unread($userto->id, false); } } }
function local_uai_send_notifications($cron = true, $debug = false, $debugsend = false, $course = 0) { global $DB, $USER; // Get the notifications configured if ($course) { $quiznotifications = $DB->get_records('local_uai_quiz_notifications', array('course' => $course)); } else { $quiznotifications = $DB->get_records('local_uai_quiz_notifications'); } $numnotifications = count($quiznotifications); // If there are any if ($numnotifications > 0) { // Process each course separatedly foreach ($quiznotifications as $quiznotification) { if (!($course = $DB->get_record('course', array('id' => $quiznotification->course)))) { $msg = 'Invalid course id ' . $quiznotification->course; if ($cron) { mtrace($msg); } else { if ($debug) { echo $msg; } } continue; } $msg = 'Processing notifications for course ' . $course->fullname; if ($cron) { mtrace($msg); } else { if ($debug) { echo $msg; } } // Get the attempts $attemptsSemester = local_uai_get_quiz_attempts($course->id, -365); // Calculate stats for the attempts list($studentinfoSemester, $coursestatsSemester) = local_uai_get_stats_from_attempts($attemptsSemester); // Get the attempts $attempts = local_uai_get_quiz_attempts($course->id, -7); $userfrom = \core_user::get_noreply_user(); $userfrom->maildisplay = true; $totalmessages = 1; foreach ($attempts as $studentinfo) { // The user to be notified if ($debugsend) { $userto = $DB->get_record('user', array('id' => $USER->id)); } else { $userto = $DB->get_record('user', array('id' => $studentinfo->uid)); } // Email subject $subject = 'Informe de tu trabajo on-line'; $message = '<html>'; $message .= '<p><strong>Estimado(a) ' . $studentinfo->firstname . ' ' . $studentinfo->lastname . '</strong>,</p>'; $message .= '<p>Quiero que notes que respecto de tu trabajo con los ejercicios de wiris:</p>'; $message .= '<p>Esta semana realizaste ' . $studentinfo->finished . ' intentos'; if ($studentinfo->correct > 0) { $message .= ', de los cuales contestaste adecuadamente ' . $studentinfo->correct; } $message .= '.<br/>'; $message .= 'Desde el inicio del curso hasta ahora llevas acumulado un trabajo de ' . $studentinfoSemester[$studentinfo->uid]->finished . ' intentos y en promedio un '; $message .= 'alumno del curso ha trabajado ' . $coursestatsSemester->avgfinished . ', con un máximo de ' . $coursestatsSemester->maxfinished . ' intentos.</p><br/><br/>'; $message .= 'Quedo en espera de tus dudas.'; $message .= '</html>'; $eventdata = new stdClass(); $eventdata->component = 'local_uai'; $eventdata->name = 'quizzes_notification'; $eventdata->userto = $userto; $eventdata->userfrom = $userfrom; $eventdata->subject = $subject; $eventdata->fullmessage = format_text_email($message, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_HTML; $eventdata->fullmessagehtml = $message; $eventdata->smallmessage = $subject; $eventdata->notification = 1; // this is only set to 0 for personal messages between users if ($userto) { if (!$debug || $debugsend) { $send = message_send($eventdata); } if ($debug) { echo '<hr>'; echo 'Subject: ' . $subject . '<br/>'; echo "To: {$userto->firstname} {$userto->lastname} <{$userto->email}><br/>"; echo $message; } $totalmessages++; } else { if ($cron) { mtrace("Error sending message to {$userto}"); } } if ($debugsend) { break; } } } } return array($totalmessages, $numnotifications); }
function send_mail($values, $error, $user, $asistentes, $eventname, $campusId) { global $USER, $DB; $userfrom = core_user::get_noreply_user(); $userfrom->maildisplay = true; $sql = "SELECT e.nombre AS edificio, \n\t\t\ts.nombre AS sede\n\t\t\tFROM {reservasalas_edificios} AS e, \n\t\t\t{reservasalas_sedes} AS s \n\t\t\tWHERE e.sedes_id=s.id\n\t\t\tAND e.id=?"; $campus = $DB->get_record_sql($sql, array($campusId)); $message = get_string('dear', 'local_reservasalas') . $USER->firstname . ' ' . $USER->lastname . ': '; $message .= '<br></br>'; $message .= '<br></br>'; $message .= get_string('bookinginformation', 'local_reservasalas'); $message .= '<br></br>'; $message .= '<br></br>'; $message .= get_string('site', 'local_reservasalas') . ': ' . $campus->sede; $message .= '<br></br>'; $message .= get_string('buildings', 'local_reservasalas') . ': ' . $campus->edificio; $message .= '<br></br>'; $message .= get_string('roomtype', 'local_reservasalas') . ': Estudio'; $message .= '<br></br>'; $message .= get_string('event', 'local_reservasalas') . ': ' . $eventname; $message .= '<br></br>'; $message .= get_string('assistants', 'local_reservasalas') . ': ' . $asistentes; $message .= '<br></br>'; $message .= get_string('responsibility', 'local_reservasalas') . ': ' . $USER->firstname . ' ' . $USER->lastname; $message .= '<br></br>'; $message .= get_string('rooms', 'local_reservasalas') . ': '; $message .= '<br></br>'; foreach ($values as $value) { $stamp = strtotime($value["fecha"]); $day = date("l", $stamp); $message .= get_string('date', 'local_reservasalas') . ': ' . $day . ' ' . $value["fecha"] . ' - ' . get_string('room', 'local_reservasalas') . ': ' . $value['nombresala'] . ' - ' . get_string('module', 'local_reservasalas') . ': ' . $value['nombremodulo']; $message .= '<br></br>'; } $eventdata = new stdClass(); $eventdata->component = 'local_reservasalas'; // your component name $eventdata->name = 'reservenotification'; // this is the message name from messages.php $eventdata->userfrom = $userfrom; $eventdata->userto = $user; $eventdata->subject = get_string('confirmationbooking', 'local_reservasalas'); $eventdata->fullmessage = format_text_email($message, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_HTML; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; $eventdata->notification = 1; // this is only set to 0 for personal messages between users message_send($eventdata); }
/** * Sends notifications to users about awarded badges. * * @param badge $badge Badge that was issued * @param int $userid Recipient ID * @param string $issued Unique hash of an issued badge * @param string $filepathhash File path hash of an issued badge for attachments */ function badges_notify_badge_award(badge $badge, $userid, $issued, $filepathhash) { global $CFG, $DB; $admin = get_admin(); $userfrom = new stdClass(); $userfrom->id = $admin->id; $userfrom->email = !empty($CFG->badges_defaultissuercontact) ? $CFG->badges_defaultissuercontact : $admin->email; $userfrom->firstname = !empty($CFG->badges_defaultissuername) ? $CFG->badges_defaultissuername : $admin->firstname; $userfrom->lastname = !empty($CFG->badges_defaultissuername) ? '' : $admin->lastname; $userfrom->maildisplay = true; $issuedlink = html_writer::link(new moodle_url('/badges/badge.php', array('hash' => $issued)), $badge->name); $userto = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $params = new stdClass(); $params->badgename = $badge->name; $params->username = fullname($userto); $params->badgelink = $issuedlink; $message = badge_message_from_template($badge->message, $params); $plaintext = format_text_email($message, FORMAT_HTML); if ($badge->attachment && $filepathhash) { $fs = get_file_storage(); $file = $fs->get_file_by_hash($filepathhash); $attachment = $file->copy_content_to_temp(); email_to_user($userto, $userfrom, $badge->messagesubject, $plaintext, $message, str_replace($CFG->dataroot, '', $attachment), str_replace(' ', '_', $badge->name) . ".png"); @unlink($attachment); } else { email_to_user($userto, $userfrom, $badge->messagesubject, $plaintext, $message); } // Notify badge creator about the award if they receive notifications every time. if ($badge->notification == 1) { $creator = $DB->get_record('user', array('id' => $badge->usercreated), '*', MUST_EXIST); $a = new stdClass(); $a->user = fullname($userto); $a->link = $issuedlink; $creatormessage = get_string('creatorbody', 'badges', $a); $creatorsubject = get_string('creatorsubject', 'badges', $badge->name); $eventdata = new stdClass(); $eventdata->component = 'moodle'; $eventdata->name = 'instantmessage'; $eventdata->userfrom = $userfrom; $eventdata->userto = $creator; $eventdata->notification = 1; $eventdata->subject = $creatorsubject; $eventdata->fullmessage = $creatormessage; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = format_text($creatormessage, FORMAT_HTML); $eventdata->smallmessage = ''; message_send($eventdata); $DB->set_field('badge_issued', 'issuernotified', time(), array('badgeid' => $badge->id, 'userid' => $userid)); } }
$a->outof = $answers[$attempt->pageid]->score; } else { $a->earned = $essayinfo->score; $a->outof = 1; } // Set rest of the message values $currentpage = $lesson->load_page($attempt->pageid); $a->question = format_text($currentpage->contents, $currentpage->contentsformat, $formattextdefoptions); $a->response = format_text($essayinfo->answer, $essayinfo->answerformat, array('context' => $context, 'para' => true)); $a->comment = $essayinfo->response; $a->comment = file_rewrite_pluginfile_urls($a->comment, 'pluginfile.php', $context->id, 'mod_lesson', 'essay_responses', $attempt->id); $a->comment = format_text($a->comment, $essayinfo->responseformat, $formattextdefoptions); $a->lesson = format_string($lesson->name, true); // Fetch message HTML and plain text formats $message = get_string('essayemailmessage2', 'lesson', $a); $plaintext = format_text_email($message, FORMAT_HTML); // Subject $subject = get_string('essayemailsubject', 'lesson'); $eventdata = new stdClass(); $eventdata->modulename = 'lesson'; $eventdata->userfrom = $USER; $eventdata->userto = $users[$attempt->userid]; $eventdata->subject = $subject; $eventdata->fullmessage = $plaintext; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $message; $eventdata->smallmessage = ''; // Required for messaging framework $eventdata->component = 'mod_lesson'; $eventdata->name = 'graded_essay'; message_send($eventdata);
/** * Display a post. This method is used for: * - The normal HTML display of a post * - HTML email of a post * - Text-only email of a post * These are all combined in one method since ordinarily they change at * the same time (i.e. if adding/hiding information it is usually added to * or hidden from all views). * * $options is an associative array from a forum_post::OPTION_xx constant. * All available options are always set - if they were not set by * the user, they will have been set to false before this call happens, * so there is no need to use empty() or isset(). * * Options are as follows. These are available in email mode: * * OPTION_TIME_ZONE (int) - Moodle time zone * OPTION_VIEW_FULL_NAMES (bool) - If user is allowed to see full names * OPTION_EMAIL (bool) - True if this is an email (false = standard view) * OPTION_DIGEST (bool) - True if this is part of an email digest * OPTION_COMMAND_REPLY (bool) - True if 'Reply' link should be displayed * (available in email too) * * These options only apply in non-email usage: * * OPTION_SUMMARY (bool) - True if the entire post should not be displayed, * only a short summary * OPTION_NO_COMMANDS (bool) - True if this post is being printed on its own * OPTION_COMMAND_EDIT (bool) - Display 'Edit' command * OPTION_COMMAND_DELETE (bool) - Display 'Edit' command * OPTION_COMMAND_SPLIT (bool) - Display 'Split' command * OPTION_RATINGS_VIEW (bool) - True to display current ratings * OPTION_RATINGS_EDIT (bool) - True to display ratings edit combo * OPTION_LEAVE_DIV_OPEN (bool) - True to not close post div (means that * child posts can be added within). * OPTION_EXPANDED (bool) - True to show full post, otherwise abbreviate * OPTION_DISCUSSION_SUBJECT (bool) - If true, and only IF post is a * discussion root, includes subject (HTML, shortened as it would be for * header display) as a hidden field. * * @param forum_post $post Post object * @param bool $html True if using HTML, false to output in plain text * @param array $options Associative array of name=>option, as above * @return string HTML or text of post */ public function display_post($post, $html, $options) { global $CFG, $USER, $THEME; $discussion = $post->get_discussion(); $expanded = $options[forum_post::OPTION_EXPANDED]; $export = $options[forum_post::OPTION_EXPORT]; $email = $options[forum_post::OPTION_EMAIL]; // When posts are deleted we hide a lot of info - except when the person // viewing it has the ability to view deleted posts. $deletedhide = $post->get_deleted() && !$options[forum_post::OPTION_VIEW_DELETED_INFO]; // Hide deleted messages if they have no replies if ($deletedhide && !$email && !$post->has_children()) { // note: !email check is to deal with posts that are deleted // between when the mail list finds them, and when it sends out // mail. It would be confusing to send out a blank email so let's // not do that. Also, ->has_children() is not safe to call during // email processing because it doesn't load the whole discussion. return ''; } // Save some bandwidth by not sending link full paths except in emails if ($options[forum_post::OPTION_FULL_ADDRESSES]) { $linkprefix = $CFG->wwwroot . '/mod/forumng/'; } else { $linkprefix = ''; } $postnumber = ($options[forum_post::OPTION_NO_COMMANDS] || $email) && !$options[forum_post::OPTION_VISIBLE_POST_NUMBERS] ? '' : $post->get_number(); $lf = "\n"; // Initialise result $out = ''; if ($html) { if ($export) { $out .= '<hr />'; } // Basic intro $classes = $expanded ? ' forumng-full' : ' forumng-short'; $classes .= $post->is_important() ? ' forumng-important' : ''; $classes .= !$email && !$options[forum_post::OPTION_UNREAD_NOT_HIGHLIGHTED] && $post->is_unread() ? ' forumng-unread' : ' forumng-read'; $classes .= $post->get_deleted() ? ' forumng-deleted' : ''; $classes .= ' forumng-p' . $postnumber; $out .= $lf . '<div class="forumng-post' . $classes . '"><a id="p' . $post->get_id() . '"></a>'; if ($options[forum_post::OPTION_FIRST_UNREAD]) { $out .= '<a id="firstunread"></a>'; } // Theme hooks if (!empty($THEME->forumng_post_hooks)) { for ($i = 1; $i <= $THEME->forumng_post_hooks; $i++) { $out .= '<div class="forumng-' . $i . '"></div>'; } } } if ($html || $options[forum_post::OPTION_VISIBLE_POST_NUMBERS]) { // Accessible text giving post a number so we can make links unique // etc. if ($postnumber) { $data = new stdClass(); $data->num = $postnumber; if ($post->get_parent()) { if ($html) { $data->parent = '<a class="forumng-parentlink" href="#p' . $post->get_parent()->get_id() . '">' . $post->get_parent()->get_number() . '</a>'; } else { $data->parent = $post->get_parent()->get_number(); } $data->info = ''; if ($post->is_unread()) { $data->info = get_string('postinfo_unread', 'forumng'); } if (!$expanded) { $data->info .= ' ' . get_string('postinfo_short', 'forumng'); } if ($post->get_deleted()) { $data->info .= ' ' . get_string('postinfo_deleted', 'forumng'); } $data->info = trim($data->info); if ($data->info) { $data->info = ' (' . $data->info . ')'; } $info = get_string('postnumreply', 'forumng', $data); } else { $info = get_string('postnum', 'forumng', $data); } if ($options[forum_post::OPTION_VISIBLE_POST_NUMBERS]) { if (!$html) { $out .= "## " . $info . "\n"; } } } } // Discussion subject (root only) if ($options[forum_post::OPTION_DISCUSSION_SUBJECT] && $post->is_root_post()) { $out .= '<input type="hidden" name="discussion_subject" value="' . shorten_text(htmlspecialchars($post->get_subject())) . '" />'; } // Pictures (HTML version only) if ($html && !$export && $options[forum_post::OPTION_USER_IMAGE]) { $out .= $lf . '<div class="forumng-pic">'; // User picture $out .= $deletedhide ? '' : $post->display_user_picture(); // Group pictures if any - only for expanded version if ($expanded) { $grouppics = $post->display_group_pictures(); if ($grouppics) { $out .= '<div class="forumng-grouppicss">' . $grouppics . '</div>'; } } $out .= '</div>'; } // Link used to expand post $expandlink = ''; if (!$expanded && !$deletedhide) { $expandlink = ' [<a class="forumng-expandlink" ' . 'href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '&expand=1#p' . $post->get_id() . '">' . get_string('expandall', 'forumng') . '</a>] <img src="' . $CFG->pixpath . '/spacer.gif" width="16" height="16" alt="" />'; } // Byline $by = new stdClass(); $by->name = $deletedhide ? '' : fullname($post->get_user(), $options[forum_post::OPTION_VIEW_FULL_NAMES]); $by->date = $deletedhide ? '' : userdate($post->get_created(), get_string('strftimedatetime', 'langconfig'), $options[forum_post::OPTION_TIME_ZONE]); if ($html) { $out .= $lf . '<div class="forumng-info"><h2 class="forumng-author">'; $out .= $post->is_important() ? '<img src="' . $CFG->modpixpath . '/forumng/exclamation_mark.gif" alt="' . get_string('important', 'forumng') . '" ' . 'title = "' . get_string('important', 'forumng') . '"/>' : ''; if ($export) { $out .= $by->name; } else { $out .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_user()->id . ($post->get_forum()->is_shared() ? '' : '&course=' . $post->get_forum()->get_course_id()) . '">' . $by->name . '</a>'; } if ($postnumber) { if ($options[forum_post::OPTION_VISIBLE_POST_NUMBERS]) { $out .= '<span class="accesshide" style="position:static"> ' . $info . ' </span>'; } else { $out .= '<span class="accesshide"> ' . $info . ' </span>'; } } $out .= $deletedhide ? '' : '</h2> <span class="forumng-separator">•</span> '; $out .= '<span class="forumng-date">' . $by->date . '</span>'; if ($edituser = $post->get_edit_user()) { $out .= ' <span class="forumng-separator">•</span> ' . '<span class="forumng-edit">'; $edit = new stdClass(); $edit->date = userdate($post->get_modified(), get_string('strftimedatetime', 'langconfig'), $options[forum_post::OPTION_TIME_ZONE]); $edit->name = fullname($edituser, $options[forum_post::OPTION_VIEW_FULL_NAMES]); if ($edituser->id == $post->get_user()->id) { $out .= get_string('editbyself', 'forumng', $edit->date); } else { $out .= get_string('editbyother', 'forumng', $edit); } if ($options[forum_post::OPTION_COMMAND_HISTORY]) { $out .= ' (<a href="history.php?' . $post->get_link_params(forum::PARAM_HTML) . '">' . get_string('history', 'forumng') . '</a>)'; } $out .= '</span>'; } if ($options[forum_post::OPTION_SELECTABLE]) { $out .= ' • <input type="checkbox" name="selectp' . $post->get_id() . '" id="id_selectp' . $post->get_id() . '" /><label class="accesshide" for="id_selectp' . $post->get_id() . '">' . get_string('selectlabel', 'forumng', $postnumber) . '</label>'; } if ($options[forum_post::OPTION_FLAG_CONTROL]) { $out .= '<div class="forumng-flag">' . '<input type="image" title="' . get_string($post->is_flagged() ? 'clearflag' : 'setflag', 'forumng') . '" src="' . $CFG->modpixpath . '/forumng/flag.' . ($post->is_flagged() ? 'on' : 'off') . '.png" alt="' . get_string($post->is_flagged() ? 'flagon' : 'flagoff', 'forumng') . '" name="action.flag.p_' . $post->get_id() . '.timeread_' . $options[forum_post::OPTION_READ_TIME] . '.flag_' . ($post->is_flagged() ? 0 : 1) . '"/></div>'; } $out .= '</div>'; } else { $out .= $by->name . ' - ' . $by->date . $lf; $out .= forum_cron::EMAIL_DIVIDER; } if ($post->get_deleted()) { $out .= '<p class="forumng-deleted-info"><strong>' . get_string('deletedpost', 'forumng') . '</strong> '; if ($deletedhide) { $out .= get_string($post->get_delete_user()->id == $post->get_user()->id ? 'deletedbyauthor' : 'deletedbymoderator', 'forumng', userdate($post->get_deleted())); } else { $a = new stdClass(); $a->date = userdate($post->get_deleted()); $a->user = '******' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_delete_user()->id . '&course=' . $post->get_forum()->get_course_id() . '">' . fullname($post->get_delete_user(), $options[forum_post::OPTION_VIEW_FULL_NAMES]) . '</a>'; $out .= get_string('deletedbyuser', 'forumng', $a); } $out .= '</p>'; } // Get subject. This may make a db query when showing a single post // (which includes parent subject). if ($options[forum_post::OPTION_EMAIL] || $options[forum_post::OPTION_NO_COMMANDS]) { $subject = $post->get_effective_subject(true); } else { $subject = $post->get_subject(); } // Otherwise, subject is only displayed if it has changed if ($subject !== null && $expanded && !$deletedhide) { if ($html) { $out .= $lf . '<h3 class="forumng-subject">'; if ($options[forum_post::OPTION_DIGEST]) { // Digest contains link to original post $out .= '<a href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '#p' . $post->get_id() . '">' . format_string($subject) . '</a>'; } else { $out .= format_string($subject); } $out .= '</h3>'; } else { $out .= format_string($subject, true); if ($options[forum_post::OPTION_DIGEST]) { // Link to original post $out .= " <{$linkprefix}discuss.php?" . $discussion->get_link_params(forum::PARAM_HTML) . $discussion->get_id() . '#p' . $post->get_id() . '>'; } $out .= $lf; } } // Get content of actual message in HTML if ($html) { $textoptions = new stdClass(); // Don't put a <p> tag round post $textoptions->para = false; // Does not indicate that we trust the text, only that the // TRUSTTEXT marker is supported. $textoptions->trusttext = true; $message = format_text($post->get_message(), $post->get_format(), $textoptions, $post->get_forum()->get_course_id()); if (!$expanded && !$deletedhide) { // When not expanded and no subject, we include a summary of the // message $stripped = strip_tags(preg_replace('~<script.*?</script>~s', '', $message)); $messagetosummarise = $subject !== null ? '<h3>' . $subject . '</h3> ' . $stripped : $stripped; $summary = self::nice_shorten_text($messagetosummarise, 50); $out .= $lf . '<div class="forumng-summary"><div class="forumng-text">' . $summary . '</div> ' . $expandlink . '</div>'; } } // Start of post main section if ($expanded && !$deletedhide) { if ($html) { $out .= '<div class="forumng-postmain">'; } // Attachments $attachments = $post->get_attachment_names(); if (count($attachments)) { if ($html) { $out .= $lf . '<ul class="forumng-attachments">'; } if (count($attachments) == 1) { $attachmentlabel = get_string('attachment', 'forumng'); } else { $attachmentlabel = get_string('attachments', 'forumng'); } $out .= '<span class="accesshide">' . $attachmentlabel . '</span>'; foreach ($attachments as $attachment) { if ($html) { require_once $CFG->libdir . '/filelib.php'; $iconsrc = $CFG->pixpath . '/f/' . mimeinfo('icon', $attachment); $alt = get_mimetype_description(mimeinfo('type', $attachment)); $out .= '<li><a href="' . $linkprefix . 'attachment.php?' . $post->get_link_params(forum::PARAM_HTML) . '&file=' . $attachment . '">' . '<img src="' . $iconsrc . '" alt="' . $alt . '" /> <span>' . htmlspecialchars($attachment) . '</span></a></li>'; } else { // Right-align the entry to 70 characters $padding = 70 - strlen($attachment); if ($padding > 0) { $out .= str_repeat(' ', $padding); } // Add filename $out .= $attachment . $lf; } } if ($html) { $out .= '</ul>' . $lf; } else { $out .= $lf; // Extra line break after attachments } } // Display actual content if ($html) { if ($options[forum_post::OPTION_PRINTABLE_VERSION]) { $message = preg_replace('~<a[^>]*\\shref\\s*=\\s*[\'"](http:.*?)[\'"][^>]*>' . '(?!(http:|www\\.)).*?</a>~', "\$0 [\$1]", $message); } $out .= $lf . '<div class="forumng-message">' . $message . '</div>'; } else { $out .= format_text_email(trusttext_strip($post->get_message()), $post->get_format()); $out .= "\n\n"; } if ($html) { $out .= $lf . '<div class="forumng-postfooter">'; } // Ratings $ratings = ''; $ratingclasses = ''; if ($options[forum_post::OPTION_RATINGS_VIEW]) { $ratingclasses .= ' forumng-canview'; if ($post->get_num_ratings() >= $post->get_forum()->get_rating_threshold()) { if ($html) { $ratings .= '<div class="forumng-rating">'; $a = new stdClass(); $a->avg = '<strong id="rating_for_' . $post->get_id() . '">' . $post->get_average_rating(true) . '</strong>'; $a->num = '<span class="forumng-count">' . $post->get_num_ratings() . '</span>'; $ratings .= get_string('averagerating', 'forumng', $a); $ratings .= '</div>'; } else { $ratings .= strip_tags($post->get_average_rating(true)); } } } if ($options[forum_post::OPTION_RATINGS_EDIT] && $html) { $ratingclasses .= ' forumng-canedit'; $ratings .= '<div class="forumng-editrating">' . get_string('yourrating', 'forumng') . ' '; $ratings .= choose_from_menu($post->get_forum()->get_rating_options(), 'rating' . $post->get_id(), $post->get_own_rating(), '-', '', forum_post::NO_RATING, true); $ratings .= '</div>'; } if ($ratings) { $out .= '<div class="forumng-ratings' . $ratingclasses . '">' . $ratings . '</div>'; } // Commands at bottom of mail if (class_exists('ouflags') && ou_get_is_mobile_from_cookies()) { $mobileclass = ' class="forumng-mobilepost-link"'; } else { $mobileclass = ''; } if ($html) { $commands = ''; $expires = $post->can_ignore_edit_time_limit() ? '' : '&expires=' . ($post->get_edit_time_limit() - time()); // Jump box if ($options[forum_post::OPTION_JUMP_PREVIOUS] || $options[forum_post::OPTION_JUMP_NEXT] || $options[forum_post::OPTION_JUMP_PARENT]) { $commands .= '<li class="forumng-jumpto">' . get_string('jumpto', 'forumng'); if ($nextid = $options[forum_post::OPTION_JUMP_NEXT]) { $commands .= ' <a href="#p' . $nextid . '" class="forumng-next">' . get_string('jumpnext', 'forumng') . '</a>'; } if ($pid = $options[forum_post::OPTION_JUMP_PREVIOUS]) { if ($nextid) { $commands .= ' (<a href="#p' . $pid . '" class="forumng-prev">' . get_string('jumppreviousboth', 'forumng') . '</a>)'; } else { $commands .= ' <a href="#p' . $pid . '" class="forumng-prev">' . get_string('jumpprevious', 'forumng') . '</a>'; } } if ($parentid = $options[forum_post::OPTION_JUMP_PARENT]) { $commands .= ' <a href="#p' . $parentid . '" class="forumng-parent">' . get_string('jumpparent', 'forumng') . '</a>'; } $commands .= '</li>'; } //Direct link if ($options[forum_post::OPTION_COMMAND_DIRECTLINK]) { $commands .= '<li class="forumng-permalink"><a href="discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '#p' . $post->get_id() . '" title="' . get_string('directlinktitle', 'forumng') . '">' . get_string('directlink', 'forumng', $postnumber) . '</a></li>'; } // Alert link if ($options[forum_post::OPTION_COMMAND_REPORT]) { $commands .= '<li><a href="' . $linkprefix . 'alert.php?' . $post->get_link_params(forum::PARAM_HTML) . '" title="' . get_string('alert_linktitle', 'forumng') . '">' . get_string('alert_link', 'forumng', $postnumber) . '</a></li>'; } // Split link if ($options[forum_post::OPTION_COMMAND_SPLIT]) { $commands .= '<li class="forumng-split"><a href="' . $linkprefix . 'splitpost.php?' . $post->get_link_params(forum::PARAM_HTML) . '">' . get_string('split', 'forumng', $postnumber) . '</a></li>'; } // Delete link if ($options[forum_post::OPTION_COMMAND_DELETE]) { $commands .= '<li><a' . $mobileclass . ' href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(forum::PARAM_HTML) . $expires . '">' . get_string('delete', 'forumng', $postnumber) . '</a></li>'; } // Undelete link if ($options[forum_post::OPTION_COMMAND_UNDELETE]) { $commands .= '<li><a href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(forum::PARAM_HTML) . '&delete=0">' . get_string('undelete', 'forumng', $postnumber) . '</a></li>'; } // Edit link if ($options[forum_post::OPTION_COMMAND_EDIT]) { $commands .= '<li><a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?' . $post->get_link_params(forum::PARAM_HTML) . $expires . '">' . get_string('edit', 'forumng', $postnumber) . '</a></li>'; } // Reply link if ($options[forum_post::OPTION_COMMAND_REPLY]) { $commands .= '<li class="forumng-replylink"><a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?replyto=' . $post->get_id() . $post->get_forum()->get_clone_param(forum::PARAM_HTML) . '">' . get_string('reply', 'forumng', $postnumber) . '</a></li>'; } if ($commands) { $out .= $lf . '<ul class="forumng-commands">' . $commands . '</ul>'; } } else { // Reply link if ($options[forum_post::OPTION_COMMAND_REPLY]) { $out .= forum_cron::EMAIL_DIVIDER; if ($options[forum_post::OPTION_EMAIL]) { $course = $post->get_forum()->get_course(); $out .= get_string("postmailinfo", "forumng", $course->shortname) . $lf; } $out .= "{$linkprefix}editpost.php?replyto=" . $post->get_id() . $post->get_forum()->get_clone_param(forum::PARAM_PLAIN) . $lf; } // Only the reply command is available in text mode } // End of post footer and main section if ($html) { $out .= '</div></div>'; } } // End of post div if ($html) { $out .= '<div class="forumng-endpost"></div></div>'; if ($export) { $out .= '<br /><br />'; } } return $out; }
/** * Builds and returns the body of the email notification in plain text. * * @global object * @global object * @uses CONTEXT_MODULE * @param object $course * @param object $cm * @param object $forum * @param object $discussion * @param object $post * @param object $userfrom * @param object $userto * @param boolean $bare * @return string The email body in plain text format. */ function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $bare = false) { global $CFG, $USER; $modcontext = context_module::instance($cm->id); if (!isset($userto->viewfullnames[$forum->id])) { $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); } else { $viewfullnames = $userto->viewfullnames[$forum->id]; } if (!isset($userto->canpost[$discussion->id])) { $canreply = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext); } else { $canreply = $userto->canpost[$discussion->id]; } $by = New stdClass; $by->name = fullname($userfrom, $viewfullnames); $by->date = userdate($post->modified, "", $userto->timezone); $strbynameondate = get_string('bynameondate', 'forum', $by); $strforums = get_string('forums', 'forum'); $canunsubscribe = ! forum_is_forcesubscribed($forum); $posttext = ''; if (!$bare) { $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $posttext = "$shortname -> $strforums -> ".format_string($forum->name,true); if ($discussion->name != $forum->name) { $posttext .= " -> ".format_string($discussion->name,true); } } // add absolute file links $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id); $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= format_string($post->subject,true); if ($bare) { $posttext .= " ($CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id#p$post->id)"; } $posttext .= "\n".$strbynameondate."\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= format_text_email($post->message, $post->messageformat); $posttext .= "\n\n"; $posttext .= forum_print_attachments($post, $cm, "text"); if (!$bare && $canreply) { $posttext .= "---------------------------------------------------------------------\n"; $posttext .= get_string("postmailinfo", "forum", $shortname)."\n"; $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id\n"; } if (!$bare && $canunsubscribe) { $posttext .= "\n---------------------------------------------------------------------\n"; $posttext .= get_string("unsubscribe", "forum"); $posttext .= ": $CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\n"; } return $posttext; }
/** * Sends notifications to users about awarded badges. * * @param badge $badge Badge that was issued * @param int $userid Recipient ID * @param string $issued Unique hash of an issued badge * @param string $filepathhash File path hash of an issued badge for attachments */ function badges_notify_badge_award(badge $badge, $userid, $issued, $filepathhash) { global $CFG, $DB; $admin = get_admin(); $userfrom = new stdClass(); $userfrom->id = $admin->id; $userfrom->email = !empty($CFG->badges_defaultissuercontact) ? $CFG->badges_defaultissuercontact : $admin->email; foreach (get_all_user_name_fields() as $addname) { $userfrom->{$addname} = !empty($CFG->badges_defaultissuername) ? '' : $admin->{$addname}; } $userfrom->firstname = !empty($CFG->badges_defaultissuername) ? $CFG->badges_defaultissuername : $admin->firstname; $userfrom->maildisplay = true; $issuedlink = html_writer::link(new moodle_url('/badges/badge.php', array('hash' => $issued)), $badge->name); $userto = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $params = new stdClass(); $params->badgename = $badge->name; $params->username = fullname($userto); $params->badgelink = $issuedlink; $message = badge_message_from_template($badge->message, $params); $plaintext = format_text_email($message, FORMAT_HTML); // Notify recipient. $eventdata = new stdClass(); $eventdata->component = 'moodle'; $eventdata->name = 'badgerecipientnotice'; $eventdata->userfrom = $userfrom; $eventdata->userto = $userto; $eventdata->notification = 1; $eventdata->subject = $badge->messagesubject; $eventdata->fullmessage = $plaintext; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $message; $eventdata->smallmessage = $plaintext; // Attach badge image if possible. if (!empty($CFG->allowattachments) && $badge->attachment && is_string($filepathhash)) { $fs = get_file_storage(); $file = $fs->get_file_by_hash($filepathhash); $eventdata->attachment = $file; $eventdata->attachname = str_replace(' ', '_', $badge->name) . ".png"; message_send($eventdata); } else { message_send($eventdata); } // Notify badge creator about the award if they receive notifications every time. if ($badge->notification == 1) { $userfrom = core_user::get_noreply_user(); $userfrom->maildisplay = true; $creator = $DB->get_record('user', array('id' => $badge->usercreated), '*', MUST_EXIST); $a = new stdClass(); $a->user = fullname($userto); $a->link = $issuedlink; $creatormessage = get_string('creatorbody', 'badges', $a); $creatorsubject = get_string('creatorsubject', 'badges', $badge->name); $eventdata = new stdClass(); $eventdata->component = 'moodle'; $eventdata->name = 'badgecreatornotice'; $eventdata->userfrom = $userfrom; $eventdata->userto = $creator; $eventdata->notification = 1; $eventdata->subject = $creatorsubject; $eventdata->fullmessage = format_text_email($creatormessage, FORMAT_HTML); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $creatormessage; $eventdata->smallmessage = $creatorsubject; message_send($eventdata); $DB->set_field('badge_issued', 'issuernotified', time(), array('badgeid' => $badge->id, 'userid' => $userid)); } }