diff --git a/email.php b/email.php
index ff70214c..dbe29ebf 100644
--- a/email.php
+++ b/email.php
@@ -160,240 +160,242 @@
echo html_writer::end_tag('div');
echo $OUTPUT->footer();
-}
+} else {
-// we are presenting the form with values populated from either the log or drafts table in the db
-if (!empty($type)) {
-
- $email = $DB->get_record('block_quickmail_' . $type, array('id' => $typeid));
- //$emailmailto = array();
- if ($type == 'log') {
- $attributes = array ('id' => "{$typeid}_id_message_editor");
- }
+ // we are presenting the form with values populated from either the log or drafts table in the db
+ if (!empty($type)) {
+
+ $email = $DB->get_record('block_quickmail_' . $type, array('id' => $typeid));
+ //$emailmailto = array();
+ if ($type == 'log') {
+ $attributes = array ('id' => "{$typeid}_id_message_editor");
+ }
- if ($messageIDresend == 1) {
- list($email->mailto, $email->additional_emails) = quickmail::clean($email->failuserids);
+ if ($messageIDresend == 1) {
+ list($email->mailto, $email->additional_emails) = quickmail::clean($email->failuserids);
+ }
+ } else {
+ $email = new stdClass;
+ $email->id = null;
}
-} else {
- $email = new stdClass;
- $email->id = null;
-}
-$email->messageformat = editors_get_preferred_format();
-$default_sigid = $DB->get_field('block_quickmail_signatures', 'id', array(
- 'userid' => $USER->id, 'default_flag' => 1
-));
-$email->sigid = $default_sigid ? $default_sigid : -1;
-
-// Some setters for the form
-$email->type = $type;
-$email->typeid = $typeid;
-
-$editor_options = array(
- 'trusttext' => false,
- 'subdirs' => 1,
- 'maxfiles' => EDITOR_UNLIMITED_FILES,
- 'accepted_types' => '*',
- 'context' => $context
-);
-
-$email = file_prepare_standard_editor(
- $email, 'message', $editor_options, $context, 'block_quickmail', $type, $email->id
-);
-$selected = array();
-if (!empty($email->mailto)) {
- foreach (explode(',', $email->mailto) as $id) {
- $selected[$id] = (object) array('id'=>$id,'firstname'=>null,'lastname'=>null,'email'=>$id,'mailformat'=>'1','suspended'=>'0','maildisplay'=>'2','status'=>'0');
- if(is_numeric($selected[$id]->id)) {
- $selected[$id] = $users[$id];
- }
- unset($users[$id]);
+ $email->messageformat = editors_get_preferred_format();
+ $default_sigid = $DB->get_field('block_quickmail_signatures', 'id', array(
+ 'userid' => $USER->id, 'default_flag' => 1
+ ));
+ $email->sigid = $default_sigid ? $default_sigid : -1;
+
+ // Some setters for the form
+ $email->type = $type;
+ $email->typeid = $typeid;
+
+ $editor_options = array(
+ 'trusttext' => false,
+ 'subdirs' => 1,
+ 'maxfiles' => EDITOR_UNLIMITED_FILES,
+ 'accepted_types' => '*',
+ 'context' => $context
+ );
+
+ $email = file_prepare_standard_editor(
+ $email, 'message', $editor_options, $context, 'block_quickmail', $type, $email->id
+ );
+
+ $selected = array();
+ if (!empty($email->mailto)) {
+ foreach (explode(',', $email->mailto) as $id) {
+ $selected[$id] = (object) array('id'=>$id,'firstname'=>null,'lastname'=>null,'email'=>$id,'mailformat'=>'1','suspended'=>'0','maildisplay'=>'2','status'=>'0');
+ if(is_numeric($selected[$id]->id)) {
+ $selected[$id] = $users[$id];
+ }
+ unset($users[$id]);
+ }
}
-}
-$form = new email_form(null, array(
- 'editor_options' => $editor_options,
- 'selected' => $selected,
- 'users' => $users,
- 'roles' => $roles,
- 'groups' => $groups,
- 'users_to_roles' => $users_to_roles,
- 'users_to_groups' => $users_to_groups,
- 'sigs' => array_map(function($sig) { return $sig->title; }, $sigs),
- 'alternates' => $alternates,
- 'attributes' => $attributes
-));
-
-$warnings = array();
-//
-if ($form->is_cancelled()) {
- redirect(new moodle_url('/course/view.php?id=' . $courseid));
- // DWE we should check if we have selected users or emails around here.
-} else if ($data = $form->get_data()) {
- if (empty($data->subject)) {
- $warnings[] = get_string('no_subject', 'block_quickmail');
- }
- if (empty($data->mailto) && empty($data->additional_emails)) {
- $warnings[] = get_string('no_users', 'block_quickmail');
- }
- if (empty($warnings)) {
- // Submitted data //////////////////////////////////////////////////////
- $data->time = time();
- $data->format = $data->message_editor['format'];
- $data->message = $data->message_editor['text'];
- $data->attachment = quickmail::attachment_names($data->attachments);
- $data->messageWithSigAndAttach = "";
- // Store data; id is needed for file storage ///////////////////////////
- if (isset($data->send)) {
- $data->id = $DB->insert_record('block_quickmail_log', $data);
- $table = 'log';
- } else if (isset($data->draft)) {
- $table = 'drafts';
-
- if (!empty($typeid) and $type == 'drafts') {
- $data->id = $typeid;
- $DB->update_record('block_quickmail_drafts', $data);
- } else {
- $data->id = $DB->insert_record('block_quickmail_drafts', $data);
- }
+ $form = new email_form(null, array(
+ 'editor_options' => $editor_options,
+ 'selected' => $selected,
+ 'users' => $users,
+ 'roles' => $roles,
+ 'groups' => $groups,
+ 'users_to_roles' => $users_to_roles,
+ 'users_to_groups' => $users_to_groups,
+ 'sigs' => array_map(function($sig) { return $sig->title; }, $sigs),
+ 'alternates' => $alternates,
+ 'attributes' => $attributes
+ ));
+
+ $warnings = array();
+ //
+ if ($form->is_cancelled()) {
+ redirect(new moodle_url('/course/view.php?id=' . $courseid));
+ // DWE we should check if we have selected users or emails around here.
+ } else if ($data = $form->get_data()) {
+ if (empty($data->subject)) {
+ $warnings[] = get_string('no_subject', 'block_quickmail');
}
- $data = file_postupdate_standard_editor(
- $data, 'message', $editor_options, $context, 'block_quickmail', $table, $data->id
- );
- $DB->update_record('block_quickmail_' . $table, $data);
-
- $prepender = $config['prepend_class'];
- if (!empty($prepender) and !empty($course->$prepender)) {
- $subject = "[{$course->$prepender}] $data->subject";
- } else {
- $subject = $data->subject;
+ if (empty($data->mailto) && empty($data->additional_emails)) {
+ $warnings[] = get_string('no_users', 'block_quickmail');
}
-
- // An instance id is needed before storing the file repository /////////
- file_save_draft_area_files(
- $data->attachments, $context->id, 'block_quickmail', 'attachment_' . $table, $data->id, $editor_options
- );
-
- // Send emails /////////////////////////////////////////////////////////
- if (isset($data->send)) {
- if ($type == 'drafts') {
- quickmail::draft_cleanup($context->id, $typeid);
+ if (empty($warnings)) {
+ // Submitted data //////////////////////////////////////////////////////
+ $data->time = time();
+ $data->format = $data->message_editor['format'];
+ $data->message = $data->message_editor['text'];
+ $data->attachment = quickmail::attachment_names($data->attachments);
+ $data->messageWithSigAndAttach = "";
+ // Store data; id is needed for file storage ///////////////////////////
+ if (isset($data->send)) {
+ $data->id = $DB->insert_record('block_quickmail_log', $data);
+ $table = 'log';
+ } else if (isset($data->draft)) {
+ $table = 'drafts';
+
+ if (!empty($typeid) and $type == 'drafts') {
+ $data->id = $typeid;
+ $DB->update_record('block_quickmail_drafts', $data);
+ } else {
+ $data->id = $DB->insert_record('block_quickmail_drafts', $data);
+ }
}
- // deal with possible signature, will be appended to message in a little bit.
- if (!empty($sigs) and $data->sigid > -1) {
- $sig = $sigs[$data->sigid];
- $signaturetext = file_rewrite_pluginfile_urls($sig->signature, 'pluginfile.php', $context->id, 'block_quickmail', 'signature', $sig->id, $editor_options);
+ $data = file_postupdate_standard_editor(
+ $data, 'message', $editor_options, $context, 'block_quickmail', $table, $data->id
+ );
+ $DB->update_record('block_quickmail_' . $table, $data);
+
+ $prepender = $config['prepend_class'];
+ if (!empty($prepender) and !empty($course->$prepender)) {
+ $subject = "[{$course->$prepender}] $data->subject";
+ } else {
+ $subject = $data->subject;
}
- // Prepare html content of message /////////////////////////////////
- $data->message = file_rewrite_pluginfile_urls($data->message, 'pluginfile.php', $context->id, 'block_quickmail', $table, $data->id, $editor_options);
+ // An instance id is needed before storing the file repository /////////
+ file_save_draft_area_files(
+ $data->attachments, $context->id, 'block_quickmail', 'attachment_' . $table, $data->id, $editor_options
+ );
- if(empty($signaturetext)){
- $data->messageWithSigAndAttach = $data->message;
- }
- else{
- if($data->format == 0 || $data->format == 2 ){
- $data->messageWithSigAndAttach = $data->message . "\n\n" .$signaturetext;
- }else{
- $data->messageWithSigAndAttach = $data->message . "