diff --git a/lang/en/message.php b/lang/en/message.php index 60993bc..34ba71a 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -140,3 +140,4 @@ $string['unreadnewnotifications'] = 'New notifications ({$a})'; $string['userisblockingyou'] = 'This user has blocked you from sending messages to them'; $string['userisblockingyounoncontact'] = 'This user is only accepting messages from people listed as contacts, and you are not currently on the list.'; $string['userssearchresults'] = 'Users found: {$a}'; +$string['finishedpreview'] = 'Finished'; // Added BY: David Varney diff --git a/user/message.php b/user/message.php new file mode 100644 index 0000000..499ceea --- /dev/null +++ b/user/message.php @@ -0,0 +1,85 @@ +dirroot.'/lib/formslib.php'); + +class message_user_form extends moodleform { + + function definition () { + global $USER; + + $mform =& $this->_form; + + $editoroptions = array('trusttext'=>false); + + // Let's assign our hidden form elements + $mform->addElement('hidden', 'id'); + $mform->setType('id', PARAM_INT); + $mform->addElement('hidden', 'returnto'); + $mform->addElement('hidden', 'deluser'); + + $mform->addElement('editor', 'messagebody', ''.get_string('messagebody').':', null, $editoroptions); + + if (has_capability('local/eschool:messageguardian', get_context_instance(CONTEXT_SYSTEM), $USER->id, true)) { + $mform->addElement('checkbox', 'guardians', '', ' Message students\' guardians instead of the students themselves'); + $mform->setDefault('guardians', false); + } + + $mform->addElement('submit', 'preview', get_string('preview')); + $mform->addElement('submit', 'send', get_string('sendmessage', 'message')); + + } + + /** + * Assigns the recipient users to the form + * + * @author David Varney + * + * @param obj $id Id of the course to access $SESSION->emailto + */ + function assign_users_to_form($id){ + global $SESSION, $OUTPUT; + + $this->_form->addElement('html', ''); + + if (count($SESSION->emailto[$id])) { + foreach ($SESSION->emailto[$id] as $user) { + $this->_form->addElement('html', ''); + // Check to see if we should be showing the email address. + if ($user->maildisplay == 0) { // 0 = don't display my email to anyone. + $this->_form->addElement('html', ''); + } + } + else { + $this->_form->addElement('html', ''); + } + $this->_form->addElement('html', '
'.get_string('currentlyselectedusers').'
'.fullname($user,true).''. get_string('emaildisplayhidden') .''); + } else { + $this->_form->addElement('html', ''.$user->email.''); + } + if (empty($user->email)) { + $error = get_string('emailempty'); + } + if (!empty($error)) { + $this->_form->addElement('html', ''.$error.''); + unset($error); + } + $this->_form->addElement('html', '
'.get_string('nousersyet').'
'); + } + + /** + * Used to structure incoming data for the message editor component + * + * @param obj $data + */ + function set_data($data) { + $data->message = array('text'=>$data->message, 'format'=>$data->messageformat); + + parent::set_data($data); + } + +} + +?> diff --git a/user/messageselect.php b/user/messageselect.php index a031892..fba8b64 100644 --- a/user/messageselect.php +++ b/user/messageselect.php @@ -25,15 +25,16 @@ require_once('../config.php'); require_once($CFG->dirroot.'/message/lib.php'); +require_once($CFG->dirroot.'/user/message.php'); $id = required_param('id',PARAM_INT); -$messagebody = optional_param('messagebody','',PARAM_CLEANHTML); +$messagebody = clean_param($_POST['messagebody']['text'], PARAM_CLEANHTML); $send = optional_param('send','',PARAM_BOOL); $preview = optional_param('preview','',PARAM_BOOL); $edit = optional_param('edit','',PARAM_BOOL); $guardians = optional_param('guardians','',PARAM_BOOL); $returnto = optional_param('returnto','',PARAM_LOCALURL); -$format = optional_param('format',FORMAT_MOODLE,PARAM_INT); +$format = clean_param($_POST['messagebody']['format'], PARAM_INT); $deluser = optional_param('deluser',0,PARAM_INT); $url = new moodle_url('/user/messageselect.php', array('id'=>$id)); @@ -141,13 +142,11 @@ if (!empty($messagebody) && !$edit && !$deluser && ($preview || $send)) { echo '
- '; echo "

".get_string('previewhtml')."

\n".format_text($messagebody,$format)."\n
\n"; - echo '

'."\n"; - echo '

'; + echo '

'; echo "\n
"; } else if (!empty($send)) { $good = 1; @@ -185,8 +184,21 @@ if ((!empty($send) || !empty($preview) || !empty($edit)) && (empty($messagebody) } if (count($SESSION->emailto[$id])) { - $usehtmleditor = can_use_html_editor(); - require("message.html"); + if (has_capability('moodle/site:sendmessage', $systemcontext)) { + $mform = new message_user_form('messageselect.php'); + $defaultmessage = new stdClass; + $defaultmessage->id = $id; + $defaultmessage->messagebody['text'] = '';//$messagebody; + $defaultmessage->returnto = $returnto; + $defaultmessage->deluser = $deluser; + $defaultmessage->guardians = $guardians; + // Let's add all of the users that this message is going to + $mform->assign_users_to_form($id); + $mform->set_data($defaultmessage); + echo $OUTPUT->box_start(); + $mform->display(); + echo $OUTPUT->box_end(); + } } echo $OUTPUT->footer();