From eb5334ff483a1706e3846fae83d26c9d21863b16 Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Tue, 29 Sep 2009 03:54:14 +0000 Subject: [PATCH] message MDL-19801 Upgrade deprecated calls and added set_url calls --- message/discussion.php | 33 +- message/edit.php | 405 +++++++++--------- message/history.php | 188 ++++---- message/index.php | 196 +++++---- message/lib.php | 30 +- message/messages.php | 36 +- message/output/popup/message_output_popup.php | 46 +- message/refresh.php | 142 +++--- message/send.php | 35 +- message/user.php | 172 +++++--- 10 files changed, 749 insertions(+), 534 deletions(-) diff --git a/message/discussion.php b/message/discussion.php index ba86cf85b7..17be44264b 100644 --- a/message/discussion.php +++ b/message/discussion.php @@ -1,11 +1,34 @@ -. + +/** + * Part of the message section of Moodle + * + * @author Luis Rodrigues and Martin Dougiamas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ require('../config.php'); require('lib.php'); require_login(); - if (isguest()) { + if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { redirect($CFG->wwwroot); } @@ -17,6 +40,12 @@ $userid = required_param('id', PARAM_INT); $noframesjs = optional_param('noframesjs', 0, PARAM_BOOL); + $url = new moodle_url($CFG->wwwroot.'/message/discussion.php', array('id'=>$userid)); + if ($noframesjs !== 0) { + $url->param('noframesjs', $noframesjs); + } + $PAGE->set_url($url); + /// Check the user we are talking to is valid if (! $user = $DB->get_record('user', array('id'=>$userid))) { print_error('invaliduserid'); diff --git a/message/edit.php b/message/edit.php index 8d43000f16..b82f248999 100644 --- a/message/edit.php +++ b/message/edit.php @@ -1,271 +1,270 @@ -. /** * Edit user message preferences * * @author Luis Rodrigues and Martin Dougiamas - * @version $Id$ - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message */ +require_once('../config.php'); +require_once($CFG->libdir.'/messagelib.php'); - require_once('../config.php'); - require_once($CFG->libdir.'/messagelib.php'); +$userid = optional_param('id', $USER->id, PARAM_INT); // user id +$course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) - $userid = optional_param('id', $USER->id, PARAM_INT); // user id - $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) +$url = new moodle_url($CFG->wwwroot.'/message/edit.php'); +if ($userid !== $USER->id) { + $url->param('id', $userid); +} +if ($course !== SITEID) { + $url->param('course', $course); +} +$PAGE->set_url($url); - if (!$course = $DB->get_record('course', array('id' => $course))) { - print_error('invalidcourseid'); - } +if (!$course = $DB->get_record('course', array('id' => $course))) { + print_error('invalidcourseid'); +} - if ($course->id != SITEID) { - require_login($course); +if ($course->id != SITEID) { + require_login($course); - } else { - if (!isloggedin()) { - if (empty($SESSION->wantsurl)) { - $SESSION->wantsurl = $CFG->httpswwwroot.'/message/edit.php'; - } - redirect(get_login_url()); +} else { + if (!isloggedin()) { + if (empty($SESSION->wantsurl)) { + $SESSION->wantsurl = $CFG->httpswwwroot.'/message/edit.php'; } + redirect(get_login_url()); } +} - if (isguestuser()) { - print_error('guestnoeditmessage', 'message'); - } +if (isguestuser()) { + print_error('guestnoeditmessage', 'message'); +} - if (!$user = $DB->get_record('user', array('id' => $userid))) { - print_error('invaliduserid'); - } +if (!$user = $DB->get_record('user', array('id' => $userid))) { + print_error('invaliduserid'); +} - $systemcontext = get_context_instance(CONTEXT_SYSTEM); - $personalcontext = get_context_instance(CONTEXT_USER, $user->id); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); +$systemcontext = get_context_instance(CONTEXT_SYSTEM); +$personalcontext = get_context_instance(CONTEXT_USER, $user->id); +$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - // check access control - if ($user->id == $USER->id) { - //editing own message profile - require_capability('moodle/user:editownmessageprofile', $systemcontext); +// check access control +if ($user->id == $USER->id) { + //editing own message profile + require_capability('moodle/user:editownmessageprofile', $systemcontext); - } else { - // teachers, parents, etc. - require_capability('moodle/user:editmessageprofile', $personalcontext); - // no editing of guest user account - if (isguestuser($user->id)) { - print_error('guestnoeditmessageother', 'message'); - } - // no editing of primary admin! - $mainadmin = get_admin(); - if ($user->id == $mainadmin->id) { - print_error('adminprimarynoedit'); - } +} else { + // teachers, parents, etc. + require_capability('moodle/user:editmessageprofile', $personalcontext); + // no editing of guest user account + if (isguestuser($user->id)) { + print_error('guestnoeditmessageother', 'message'); + } + // no editing of primary admin! + $mainadmin = get_admin(); + if ($user->id == $mainadmin->id) { + print_error('adminprimarynoedit'); } +} /// Save new preferences if data was submited - if (($form = data_submitted()) && confirm_sesskey()) { - $preferences = array(); - - /// Set all the preferences for all the message providers - $providers = message_get_my_providers(); - foreach ( $providers as $providerid => $provider){ - foreach (array('loggedin', 'loggedoff') as $state){ - $linepref = ''; - foreach ($form->{$provider->component.'_'.$provider->name.'_'.$state} as $process=>$one){ - if ($linepref == ''){ - $linepref = $process; - } else { - $linepref .= ','.$process; - } - } - $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_'.$state] = $linepref; - } - } - - /// Set all the processor options as well - $processors = $DB->get_records('message_processors'); - foreach ( $processors as $processorid => $processor){ - $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php'; - if ( is_readable($processorfile) ) { - include_once( $processorfile ); - - $processclass = 'message_output_' . $processor->name; - if ( class_exists($processclass) ){ - $pclass = new $processclass(); - $pclass->process_form($form, $preferences); - } else{ - print_error('errorcallingprocessor', 'message'); - } - } - } +if (($form = data_submitted()) && confirm_sesskey()) { + $preferences = array(); - /// Save all the new preferences to the database - if (!set_user_preferences( $preferences, $user->id ) ){ - print_error('cannotupdateusermsgpref'); - } - - redirect("$CFG->wwwroot/message/edit.php?id=$user->id&course=$course->id"); - } - -/// Load preferences - $preferences = new object(); - -/// Get providers preferences +/// Set all the preferences for all the message providers $providers = message_get_my_providers(); foreach ( $providers as $providerid => $provider){ foreach (array('loggedin', 'loggedoff') as $state){ - $linepref = get_user_preferences('message_provider_'.$provider->component.'_'.$provider->name.'_'.$state, '', $user->id); - if ($linepref == ''){ - continue; - } - $lineprefarray = explode(',', $linepref); - $preferences->{$provider->component.'_'.$provider->name.'_'.$state} = array(); - foreach ($lineprefarray as $pref){ - $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$pref] = 1; + $linepref = ''; + foreach ($form->{$provider->component.'_'.$provider->name.'_'.$state} as $process=>$one){ + if ($linepref == ''){ + $linepref = $process; + } else { + $linepref .= ','.$process; + } } + $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_'.$state] = $linepref; } } -/// For every processors put its options on the form (need to get function from processor's lib.php) +/// Set all the processor options as well $processors = $DB->get_records('message_processors'); - foreach ( $processors as $processorid => $processor){ + foreach ( $processors as $processorid => $processor){ $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php'; if ( is_readable($processorfile) ) { - include_once( $processorfile ); - $processclass = 'message_output_' . $processor->name; - if ( class_exists($processclass) ){ + include_once( $processorfile ); + + $processclass = 'message_output_' . $processor->name; + if ( class_exists($processclass) ){ $pclass = new $processclass(); - $pclass->load_data($preferences, $user->id); - } else{ + $pclass->process_form($form, $preferences); + } else{ print_error('errorcallingprocessor', 'message'); } } } -/// Display page header - $streditmymessage = get_string('editmymessage', 'message'); - $strparticipants = get_string('participants'); - $userfullname = fullname($user, true); +/// Save all the new preferences to the database + if (!set_user_preferences( $preferences, $user->id ) ){ + print_error('cannotupdateusermsgpref'); + } + + redirect("$CFG->wwwroot/message/edit.php?id=$user->id&course=$course->id"); +} + +/// Load preferences +$preferences = new object(); - if (has_capability('moodle/course:viewparticipants', $coursecontext) || - has_capability('moodle/site:viewparticipants', $systemcontext)) { - $PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/message/index.php', array('id'=>$course->id))); +/// Get providers preferences +$providers = message_get_my_providers(); +foreach ( $providers as $providerid => $provider){ + foreach (array('loggedin', 'loggedoff') as $state){ + $linepref = get_user_preferences('message_provider_'.$provider->component.'_'.$provider->name.'_'.$state, '', $user->id); + if ($linepref == ''){ + continue; + } + $lineprefarray = explode(',', $linepref); + $preferences->{$provider->component.'_'.$provider->name.'_'.$state} = array(); + foreach ($lineprefarray as $pref){ + $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$pref] = 1; + } } - $PAGE->navbar->add($userfullname, new moodle_url($CFG->wwwroot.'/message/view.php', array('id'=>$user->id, 'course'=>$course->id))); - $PAGE->navbar->add($streditmymessage); - $PAGE->set_title("$course->shortname: $streditmymessage"); - if ($course->id != SITEID) { - $PAGE->set_heading("$course->fullname: $streditmymessage"); - } else { - $PAGE->set_heading($course->fullname); +} + +/// For every processors put its options on the form (need to get function from processor's lib.php) +$processors = $DB->get_records('message_processors'); +foreach ( $processors as $processorid => $processor){ + $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php'; + if ( is_readable($processorfile) ) { + include_once( $processorfile ); + $processclass = 'message_output_' . $processor->name; + if ( class_exists($processclass) ){ + $pclass = new $processclass(); + $pclass->load_data($preferences, $user->id); + } else{ + print_error('errorcallingprocessor', 'message'); + } } - echo $OUTPUT->header(); +} + +/// Display page header +$streditmymessage = get_string('editmymessage', 'message'); +$strparticipants = get_string('participants'); +$userfullname = fullname($user, true); + +if (has_capability('moodle/course:viewparticipants', $coursecontext) || + has_capability('moodle/site:viewparticipants', $systemcontext)) { + $PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/message/index.php', array('id'=>$course->id))); +} +$PAGE->navbar->add($userfullname, new moodle_url($CFG->wwwroot.'/message/view.php', array('id'=>$user->id, 'course'=>$course->id))); +$PAGE->navbar->add($streditmymessage); +$PAGE->set_title("$course->shortname: $streditmymessage"); +if ($course->id != SITEID) { + $PAGE->set_heading("$course->fullname: $streditmymessage"); +} else { + $PAGE->set_heading($course->fullname); +} +echo $OUTPUT->header(); /// Print tabs at the top - $showroles = 1; - $currenttab = 'editmessage'; - require('../user/tabs.php'); +$showroles = 1; +$currenttab = 'editmessage'; +require('../user/tabs.php'); /// Start the form. We're not using mform here because of our special formatting needs ... - echo '
'; +echo ''; /// Settings table... - echo '
'; - echo ''.get_string('providers_config', 'message').''; - $providers = message_get_my_providers(); - $processors = $DB->get_records('message_processors'); - $number_procs = count($processors); - echo ''."\n"; - foreach ( $processors as $processorid => $processor){ - echo ''; +echo '
'; +echo ''.get_string('providers_config', 'message').''; +$providers = message_get_my_providers(); +$processors = $DB->get_records('message_processors'); +$number_procs = count($processors); +echo '
 '.get_string($processor->name, 'messageprocessor_'.$processor->name).'
'."\n"; +foreach ( $processors as $processorid => $processor){ + echo ''; +} +echo ''; + +foreach ( $providers as $providerid => $provider){ + $providername = get_string('messageprovider:'.$provider->name, $provider->component); + +/// TODO XXX: This is only a quick hack ... helpfile locations should be provided as part of the provider definition + if ($provider->component == 'moodle') { + $helpbtn = $OUTPUT->help_icon(moodle_help_icon::make('moodle_'.$provider->name, $providername, 'message')); + } else { + $helpbtn = $OUTPUT->help_icon(moodle_help_icon::make('message_'.$provider->name, $providername, basename($provider->component))); } - echo ''; - - foreach ( $providers as $providerid => $provider){ - $providername = get_string('messageprovider:'.$provider->name, $provider->component); - - /// TODO XXX: This is only a quick hack ... helpfile locations should be provided as part of the provider definition - if ($provider->component == 'moodle') { - $helpbtn = $OUTPUT->help_icon(moodle_help_icon::make('moodle_'.$provider->name, $providername, 'message')); - } else { - $helpbtn = $OUTPUT->help_icon(moodle_help_icon::make('message_'.$provider->name, $providername, basename($provider->component))); - } - echo ''."\n"; - foreach (array('loggedin', 'loggedoff') as $state){ - $state_res = get_string($state, 'message'); - echo ''."\n"; - foreach ( $processors as $processorid => $processor) { - if (!isset($preferences->{$provider->component.'_'.$provider->name.'_'.$state})) { - $checked = ''; - } else if (!isset($preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name])) { - $checked = ''; - } else { - $checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":""; - } - echo ''."\n"; + echo ''."\n"; + foreach (array('loggedin', 'loggedoff') as $state){ + $state_res = get_string($state, 'message'); + echo ''."\n"; + foreach ( $processors as $processorid => $processor) { + if (!isset($preferences->{$provider->component.'_'.$provider->name.'_'.$state})) { + $checked = ''; + } else if (!isset($preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name])) { + $checked = ''; + } else { + $checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":""; } - echo ''."\n"; + echo ''."\n"; } + echo ''."\n"; } - echo '
 '.get_string($processor->name, 'messageprocessor_'.$processor->name).'
'.$providername.$helpbtn.'
'.$state_res.'
'.$providername.$helpbtn.'
'.$state_res.'
'; - echo '
'; +} +echo ''; +echo ''; /// Show all the message processors - $processors = $DB->get_records('message_processors'); +$processors = $DB->get_records('message_processors'); - foreach ($processors as $processorid => $processor) { - $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php'; - if (is_readable($processorfile)) { - include_once($processorfile); - $processclass = 'message_output_' . $processor->name; +foreach ($processors as $processorid => $processor) { + $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php'; + if (is_readable($processorfile)) { + include_once($processorfile); + $processclass = 'message_output_' . $processor->name; - if (class_exists($processclass)) { - $pclass = new $processclass(); - echo '
'; - echo ''.get_string($processor->name, 'messageprocessor_'.$processor->name).''; + if (class_exists($processclass)) { + $pclass = new $processclass(); + echo '
'; + echo ''.get_string($processor->name, 'messageprocessor_'.$processor->name).''; - echo $pclass->config_form($preferences); + echo $pclass->config_form($preferences); - echo '
'; + echo '
'; - } else{ - print_error('errorcallingprocessor', 'message'); - } + } else{ + print_error('errorcallingprocessor', 'message'); } } +} - echo '
'; - echo '
'; +echo '
'; +echo '
'; - echo "
"; +echo ""; - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/message/history.php b/message/history.php index b6d7255408..cd3f7ca4d3 100644 --- a/message/history.php +++ b/message/history.php @@ -1,110 +1,134 @@ -. + +/** + * For listing message histories between any two users + * + * @author Luis Rodrigues and Martin Dougiamas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ - require('../config.php'); - require('lib.php'); +require('../config.php'); +require('lib.php'); - require_login(); +require_login(); - if (isguest()) { - redirect($CFG->wwwroot); - } +if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { + redirect($CFG->wwwroot); +} - if (empty($CFG->messaging)) { - print_error('disabled', 'message'); - } +if (empty($CFG->messaging)) { + print_error('disabled', 'message'); +} - $PAGE->set_title(get_string('messagehistory', 'message')); +$PAGE->set_title(get_string('messagehistory', 'message')); /// Script parameters - $userid1 = required_param('user1', PARAM_INT); - if (! $user1 = $DB->get_record("user", array("id"=>$userid1))) { // Check it's correct +$userid1 = required_param('user1', PARAM_INT); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/message/history.php', array('user1'=>$userid1))); +if (! $user1 = $DB->get_record("user", array("id"=>$userid1))) { // Check it's correct + print_error('invaliduserid'); +} + +if ($user1->deleted) { + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('userdeleted').': '.$userid1, 1); + echo $OUTPUT->footer(); + die; +} + +if (has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) { // Able to see any discussion + $userid2 = optional_param('user2', $USER->id, PARAM_INT); + $PAGE->url->param('user2', $userid2); + if (! $user2 = $DB->get_record("user", array("id"=>$userid2))) { // Check print_error('invaliduserid'); } - - if ($user1->deleted) { + if ($user2->deleted) { echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('userdeleted').': '.$userid1, 1); + echo $OUTPUT->heading(get_string('userdeleted').': '.$userid2, 1); echo $OUTPUT->footer(); die; } +} else { + $userid2 = $USER->id; // Can only see messages involving yourself + $user2 = $USER; +} +$search = optional_param('search', '', PARAM_CLEAN); - if (has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) { // Able to see any discussion - $userid2 = optional_param('user2', $USER->id, PARAM_INT); - if (! $user2 = $DB->get_record("user", array("id"=>$userid2))) { // Check - print_error('invaliduserid'); - } - if ($user2->deleted) { - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('userdeleted').': '.$userid2, 1); - echo $OUTPUT->footer(); - die; - } - } else { - $userid2 = $USER->id; // Can only see messages involving yourself - $user2 = $USER; - } - $search = optional_param('search', '', PARAM_CLEAN); - - add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&user2='.$userid2, $userid1); +add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&user2='.$userid2, $userid1); /// Our two users are defined - let's set up the page - echo $OUTPUT->header(); +echo $OUTPUT->header(); /// Print out a heading including the users we are looking at - echo $OUTPUT->box_start('center'); - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - $userpic = moodle_user_picture::make($user1, SITEID); - $userpic->size = 100; - $userpic->link = true; - echo $OUTPUT->user_picture($userpic).'
'; - echo fullname($user1); - echo '
'; - echo ''.get_string('from').''; - echo ''.get_string('to').''; - echo ''; - $userpic = moodle_user_picture::make($user2, SITEID); - $userpic->size = 100; - $userpic->link = true; - echo $OUTPUT->user_picture($userpic).'
'; - echo fullname($user2); - echo '
'; - echo $OUTPUT->box_end(); +echo $OUTPUT->box_start('center'); +echo ''; +echo ''; +echo ''; +echo ''; +echo '
'; +$userpic = moodle_user_picture::make($user1, SITEID); +$userpic->size = 100; +$userpic->link = true; +echo $OUTPUT->user_picture($userpic).'
'; +echo fullname($user1); +echo '
'; +echo ''.get_string('from').''; +echo ''.get_string('to').''; +echo ''; +$userpic = moodle_user_picture::make($user2, SITEID); +$userpic->size = 100; +$userpic->link = true; +echo $OUTPUT->user_picture($userpic).'
'; +echo fullname($user2); +echo '
'; +echo $OUTPUT->box_end(); /// Get all the messages and print them - if ($messages = message_get_history($user1, $user2)) { - $current->mday = ''; - $current->month = ''; - $current->year = ''; - $messagedate = get_string('strftimetime'); - $blockdate = get_string('strftimedaydate'); - foreach ($messages as $message) { - $date = usergetdate($message->timecreated); - if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) { - $current->mday = $date['mday']; - $current->month = $date['month']; - $current->year = $date['year']; - echo ''; - echo $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'center'); - } - if ($message->useridfrom == $user1->id) { - echo message_format_message($message, $user1, $messagedate, $search, 'other'); - } else { - echo message_format_message($message, $user2, $messagedate, $search, 'me'); - } +if ($messages = message_get_history($user1, $user2)) { + $current->mday = ''; + $current->month = ''; + $current->year = ''; + $messagedate = get_string('strftimetime'); + $blockdate = get_string('strftimedaydate'); + foreach ($messages as $message) { + $date = usergetdate($message->timecreated); + if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) { + $current->mday = $date['mday']; + $current->month = $date['month']; + $current->year = $date['year']; + echo ''; + echo $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'center'); + } + if ($message->useridfrom == $user1->id) { + echo message_format_message($message, $user1, $messagedate, $search, 'other'); + } else { + echo message_format_message($message, $user2, $messagedate, $search, 'me'); } - } else { - echo $OUTPUT->heading(get_string('nomessagesfound', 'message'), 1); } +} else { + echo $OUTPUT->heading(get_string('nomessagesfound', 'message'), 1); +} - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/message/index.php b/message/index.php index 056cf64c22..879063cdd9 100644 --- a/message/index.php +++ b/message/index.php @@ -1,94 +1,138 @@ -wwwroot); - } - - if (empty($CFG->messaging)) { - print_error('disabled', 'message'); - } +. + +/** + * Main interface window for messaging + * + * @author Luis Rodrigues and Martin Dougiamas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ + +require('../config.php'); +require('lib.php'); + +require_login(0, false); + +if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { + redirect($CFG->wwwroot); +} + +if (empty($CFG->messaging)) { + print_error('disabled', 'message'); +} /// Optional variables that may be passed in - $tab = optional_param('tab', 'contacts', PARAM_ALPHA); // current tab - default to contacts - $addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact - $removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact - $blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact - $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact - $popup = optional_param('popup', false, PARAM_ALPHANUM); // If set then starts a new popup window +$tab = optional_param('tab', 'contacts', PARAM_ALPHA); // current tab - default to contacts +$addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact +$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact +$blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact +$unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact +$popup = optional_param('popup', false, PARAM_ALPHANUM); // If set then starts a new popup window + +$url = new moodle_url($CFG->wwwroot.'/message/index.php', array('id'=>$id)); +if ($tab !== 'contacts') { + $url->param('tab', $tab); +} +if ($addcontact !== 0) { + $url->param('addcontact', $addcontact); +} +if ($removecontact !== 0) { + $url->param('removecontact', $removecontact); +} +if ($blockcontact !== 0) { + $url->param('blockcontact', $blockcontact); +} +if ($unblockcontact !== 0) { + $url->param('unblockcontact', $unblockcontact); +} +if ($popup !== false) { + $url->param('popup', $popup); +} +$PAGE->set_url($url); + /// Popup a window if required and quit (usually from external links). - if ($popup) { - $PAGE->set_generaltype('popup'); - $OUTPUT->header(); - echo $PAGE->requires->js_function_call('openpopup', Array('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0))->asap(); - redirect("$CFG->wwwroot/", '', 0); - exit; - } +if ($popup) { + $PAGE->set_generaltype('popup'); + $OUTPUT->header(); + echo $PAGE->requires->js_function_call('openpopup', Array('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0))->asap(); + redirect("$CFG->wwwroot/", '', 0); + exit; +} /// Process any contact maintenance requests there may be - if ($addcontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact); - message_add_contact($addcontact); - } - if ($removecontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact); - message_remove_contact($removecontact); - } - if ($blockcontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact); - message_block_contact($blockcontact); - } - if ($unblockcontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact); - message_unblock_contact($unblockcontact); - } +if ($addcontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact); + message_add_contact($addcontact); +} +if ($removecontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact); + message_remove_contact($removecontact); +} +if ($blockcontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact); + message_block_contact($blockcontact); +} +if ($unblockcontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact); + message_unblock_contact($unblockcontact); +} /// Header on this page - if ($tab == 'contacts') { - $PAGE->set_periodic_refresh_delay($CFG->message_contacts_refresh); - } +if ($tab == 'contacts') { + $PAGE->set_periodic_refresh_delay($CFG->message_contacts_refresh); +} - $PAGE->set_generaltype('popup'); - $PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname)); - echo $OUTPUT->header(); - echo ''; - echo ''; +$PAGE->set_generaltype('popup'); +$PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname)); +echo $OUTPUT->header(); +echo '
'; +echo ''; /// Print out the tabs - echo ''; - - - echo ''; +echo ''; + + +echo ''; /// Print out contents of the tab - echo '
'; - $tabrow = array(); - $tabrow[] = new tabobject('contacts', $CFG->wwwroot.'/message/index.php?tab=contacts', - get_string('contacts', 'message')); - $tabrow[] = new tabobject('search', $CFG->wwwroot.'/message/index.php?tab=search', - get_string('search', 'message')); - $tabrow[] = new tabobject('settings', $CFG->wwwroot.'/message/index.php?tab=settings', - get_string('settings', 'message')); - $tabrows = array($tabrow); - - print_tabs($tabrows, $tab); - - echo '
'; +$tabrow = array(); +$tabrow[] = new tabobject('contacts', $CFG->wwwroot.'/message/index.php?tab=contacts', + get_string('contacts', 'message')); +$tabrow[] = new tabobject('search', $CFG->wwwroot.'/message/index.php?tab=search', + get_string('search', 'message')); +$tabrow[] = new tabobject('settings', $CFG->wwwroot.'/message/index.php?tab=settings', + get_string('settings', 'message')); +$tabrows = array($tabrow); + +print_tabs($tabrows, $tab); + +echo '
'; +echo ''; /// a print function is associated with each tab - $tabprintfunction = 'message_print_'.$tab; - if (function_exists($tabprintfunction)) { - $tabprintfunction(); - } +$tabprintfunction = 'message_print_'.$tab; +if (function_exists($tabprintfunction)) { + $tabprintfunction(); +} - echo '
'; - echo $OUTPUT->footer(); +echo ' '; +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/message/lib.php b/message/lib.php index f8a6d7f17f..b6856f0f3a 100644 --- a/message/lib.php +++ b/message/lib.php @@ -1,5 +1,27 @@ -. + +/** + * Library functions for messaging + * + * @copyright Luis Rodrigues + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ require_once($CFG->libdir.'/eventslib.php'); @@ -1133,6 +1155,4 @@ function message_get_popup_messages($destuserid, $fromuserid=NULL){ } } return $messages; -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/message/messages.php b/message/messages.php index d872faa3b0..5c9be78a66 100644 --- a/message/messages.php +++ b/message/messages.php @@ -1,13 +1,35 @@ . - @header('Content-Type: text/html; charset=utf-8'); +/** + * @copyright Luis Rodrigues + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ - $PAGE->set_generaltype('popup'); - $PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname)); - echo $OUTPUT->header(); - echo "
"; - echo $OUTPUT->footer(); +require('../config.php'); + +@header('Content-Type: text/html; charset=utf-8'); + +$PAGE->set_generaltype('popup'); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/message/messages.php')); +$PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname)); +echo $OUTPUT->header(); +echo "
"; +echo $OUTPUT->footer(); ?> \ No newline at end of file diff --git a/message/output/popup/message_output_popup.php b/message/output/popup/message_output_popup.php index ea4e537f53..6d1b36d426 100644 --- a/message/output/popup/message_output_popup.php +++ b/message/output/popup/message_output_popup.php @@ -1,35 +1,26 @@ . /** * Popup message processor - stores the message to be shown using the message popup * - * @author Luis Rodrigues - * @version $Id$ - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package + * @copyright Luis Rodrigues + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later + * @package message */ require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'); //included from messagelib (how to fix?) @@ -83,5 +74,4 @@ class message_output_popup extends message_output{ $preferences->noframesjs = get_user_preferences( 'message_noframesjs', '', $userid); return true; } -} -?> +} \ No newline at end of file diff --git a/message/refresh.php b/message/refresh.php index 342c2374ad..0b1c4858a3 100644 --- a/message/refresh.php +++ b/message/refresh.php @@ -1,72 +1,94 @@ -. - define('MESSAGE_DEFAULT_REFRESH', 5); +/** + * @author Luis Rodrigues and Martin Dougiamas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ - require_login(); +require('../config.php'); +require('lib.php'); - if (isguest()) { - redirect($CFG->wwwroot); - } +define('MESSAGE_DEFAULT_REFRESH', 5); - if (empty($CFG->messaging)) { - print_error('disabled', 'message'); - } +require_login(); - $PAGE->set_generaltype('popup'); - $PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname)); - header('Expires: Sun, 28 Dec 1997 09:32:45 GMT'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - header('Cache-Control: no-cache, must-revalidate'); - header('Pragma: no-cache'); - header('Content-Type: text/html; charset=utf-8'); - - /// Script parameters - $userid = required_param('id', PARAM_INT); - $userfullname = strip_tags(required_param('name', PARAM_RAW)); - $wait = optional_param('wait', MESSAGE_DEFAULT_REFRESH, PARAM_INT); - - /*Get still to be read message, use message/lib.php funtion*/ - $messages = message_get_popup_messages($USER->id, $userid); - $jsmessages = Array(); - if ($messages ) { - foreach ($messages as $message) { - $time = userdate($message->timecreated, get_string('strftimedatetimeshort')); - - $options = new object(); - $options->para = false; - $options->newlines = true; - $printmessage = format_text($message->fullmessage, $message->fullmessageformat, $options, 0); - $printmessage = '
'.s($userfullname).' '. - '['.$time.']: '. - ''.$printmessage.'
'; - $jsmessages[count($jsmessages)] = $printmessage; - } - if (get_user_preferences('message_beepnewmessage', 0)) { - $playbeep = true; - } - $wait = MESSAGE_DEFAULT_REFRESH; - } else { - if ($wait < 300) { // Until the wait is five minutes - $wait = ceil(1.2 * (float)$wait); // Exponential growth - } - } +if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { + redirect($CFG->wwwroot); +} + +if (empty($CFG->messaging)) { + print_error('disabled', 'message'); +} + +$PAGE->set_generaltype('popup'); +$PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname)); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/message/refresh.php')); +header('Expires: Sun, 28 Dec 1997 09:32:45 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); +header('Cache-Control: no-cache, must-revalidate'); +header('Pragma: no-cache'); +header('Content-Type: text/html; charset=utf-8'); - $PAGE->requires->js('message/message.js')->in_head(); - $PAGE->requires->js_function_call('refresh_parent_messages_frame'); - $PAGE->requires->data_for_js('chatmessages', Array('msgcount'=>count($jsmessages), 'msg'=>$jsmessages))->in_head(); +/// Script parameters +$userid = required_param('id', PARAM_INT); +$userfullname = strip_tags(required_param('name', PARAM_RAW)); +$wait = optional_param('wait', MESSAGE_DEFAULT_REFRESH, PARAM_INT); - echo $OUTPUT->header(); - if (!empty($playbeep)) { - echo ''; - echo $PAGE->requires->js_function_call('parent.send.focus')->asap(); +/*Get still to be read message, use message/lib.php funtion*/ +$messages = message_get_popup_messages($USER->id, $userid); +$jsmessages = Array(); +if ($messages ) { + foreach ($messages as $message) { + $time = userdate($message->timecreated, get_string('strftimedatetimeshort')); + + $options = new object(); + $options->para = false; + $options->newlines = true; + $printmessage = format_text($message->fullmessage, $message->fullmessageformat, $options, 0); + $printmessage = '
'.s($userfullname).' '. + '['.$time.']: '. + ''.$printmessage.'
'; + $jsmessages[count($jsmessages)] = $printmessage; + } + if (get_user_preferences('message_beepnewmessage', 0)) { + $playbeep = true; + } + $wait = MESSAGE_DEFAULT_REFRESH; +} else { + if ($wait < 300) { // Until the wait is five minutes + $wait = ceil(1.2 * (float)$wait); // Exponential growth } +} + +$PAGE->requires->js('message/message.js')->in_head(); +$PAGE->requires->js_function_call('refresh_parent_messages_frame'); +$PAGE->requires->data_for_js('chatmessages', Array('msgcount'=>count($jsmessages), 'msg'=>$jsmessages))->in_head(); + +echo $OUTPUT->header(); +if (!empty($playbeep)) { + echo ''; + echo $PAGE->requires->js_function_call('parent.send.focus')->asap(); +} - // Javascript for Mozilla to cope with the redirect bug from editor being on in this page - $PAGE->requires->js_function_call('refresh_page', Array(($wait*1000), "refresh.php?id=$userid&name=".urlencode($userfullname)."&wait=$wait")); +// Javascript for Mozilla to cope with the redirect bug from editor being on in this page +$PAGE->requires->js_function_call('refresh_page', Array(($wait*1000), "refresh.php?id=$userid&name=".urlencode($userfullname)."&wait=$wait")); - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/message/send.php b/message/send.php index 9e522521f8..40dc44ea90 100644 --- a/message/send.php +++ b/message/send.php @@ -1,4 +1,25 @@ -. + +/** + * @author Luis Rodrigues and Martin Dougiamas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ require('../config.php'); require('lib.php'); @@ -26,6 +47,15 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE $message = optional_param('message', '', PARAM_CLEANHTML); $format = optional_param('format', FORMAT_MOODLE, PARAM_INT); + $url = new moodle_url($CFG->wwwroot.'/message/send.php', array('id'=>$userid)); + if ($message !== 0) { + $url->param('message', $message); + } + if ($format !== 0) { + $url->param('format', $format); + } + $PAGE->set_url($url); + /// Check the user we are talking to is valid if (! $user = $DB->get_record('user', array('id'=>$userid))) { print_error('invaliduserid'); @@ -98,5 +128,4 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE $PAGE->requires->js_function_call('set_focus', Array('edit-message')); echo $OUTPUT->footer(); -} -?> +} \ No newline at end of file diff --git a/message/user.php b/message/user.php index f86a99f295..f377d28d76 100644 --- a/message/user.php +++ b/message/user.php @@ -1,85 +1,121 @@ -. + +/** + * @author Luis Rodrigues and Martin Dougiamas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package message + */ - require('../config.php'); - require('lib.php'); +require('../config.php'); +require('lib.php'); - require_login(); +require_login(); - if (isguest()) { - redirect($CFG->wwwroot); - } +if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { + redirect($CFG->wwwroot); +} - if (empty($CFG->messaging)) { - print_error('disabled', 'message'); - } +if (empty($CFG->messaging)) { + print_error('disabled', 'message'); +} /// Script parameters - $userid = required_param('id', PARAM_INT); +$userid = required_param('id', PARAM_INT); + +$addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact +$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact +$blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact +$unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact - $addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact - $removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact - $blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact - $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact +$url = new moodle_url($CFG->wwwroot.'/message/user.php', array('id'=>$userid)); +if ($addcontact !== 0) { + $url->param('addcontact', $addcontact); +} +if ($removecontact !== 0) { + $url->param('removecontact', $removecontact); +} +if ($blockcontact !== 0) { + $url->param('blockcontact', $blockcontact); +} +if ($unblockcontact !== 0) { + $url->param('unblockcontact', $unblockcontact); +} +$PAGE->set_url($url); /// Check the user we are talking to is valid - if (! $user = $DB->get_record('user', array('id'=>$userid))) { - print_error('invaliduserid'); - } +if (! $user = $DB->get_record('user', array('id'=>$userid))) { + print_error('invaliduserid'); +} /// Possibly change some contacts if requested - if ($addcontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'add contact', - 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact); - message_add_contact($addcontact); - } - if ($removecontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'remove contact', - 'history.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact); - message_remove_contact($removecontact); - } - if ($blockcontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'block contact', - 'history.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact); - message_block_contact($blockcontact); - } - if ($unblockcontact and confirm_sesskey()) { - add_to_log(SITEID, 'message', 'unblock contact', - 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact); - message_unblock_contact($unblockcontact); - } - - //$PAGE->set_title('Message History'); - $PAGE->set_generaltype('popup'); - echo $OUTPUT->header(); - echo ''; - echo ''; - echo '
'; - $userpic = moodle_user_picture::make($user, SITEID); - $userpic->size = 48; - $userpic->link = true; - echo $OUTPUT->user_picture($userpic) .''; - - echo '
'.fullname($user).'
'; - - echo '
'; - if ($contact = $DB->get_record('message_contacts', array('userid'=>$USER->id, 'contactid'=>$user->id))) { - if ($contact->blocked) { - message_contact_link($user->id, 'add', false, 'user.php?id='.$user->id, true); - message_contact_link($user->id, 'unblock', false, 'user.php?id='.$user->id, true); - } else { - message_contact_link($user->id, 'remove', false, 'user.php?id='.$user->id, true); - message_contact_link($user->id, 'block', false, 'user.php?id='.$user->id, true); - } - } else { +if ($addcontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'add contact', + 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact); + message_add_contact($addcontact); +} +if ($removecontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'remove contact', + 'history.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact); + message_remove_contact($removecontact); +} +if ($blockcontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'block contact', + 'history.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact); + message_block_contact($blockcontact); +} +if ($unblockcontact and confirm_sesskey()) { + add_to_log(SITEID, 'message', 'unblock contact', + 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact); + message_unblock_contact($unblockcontact); +} + +//$PAGE->set_title('Message History'); +$PAGE->set_generaltype('popup'); +echo $OUTPUT->header(); +echo ''; +echo ''; +echo '
'; +$userpic = moodle_user_picture::make($user, SITEID); +$userpic->size = 48; +$userpic->link = true; +echo $OUTPUT->user_picture($userpic) .''; + +echo '
'.fullname($user).'
'; + +echo '
'; +if ($contact = $DB->get_record('message_contacts', array('userid'=>$USER->id, 'contactid'=>$user->id))) { + if ($contact->blocked) { message_contact_link($user->id, 'add', false, 'user.php?id='.$user->id, true); + message_contact_link($user->id, 'unblock', false, 'user.php?id='.$user->id, true); + } else { + message_contact_link($user->id, 'remove', false, 'user.php?id='.$user->id, true); message_contact_link($user->id, 'block', false, 'user.php?id='.$user->id, true); - } - message_history_link($user->id, 0, false, '', '', 'both'); - echo '
'; + } +} else { + message_contact_link($user->id, 'add', false, 'user.php?id='.$user->id, true); + message_contact_link($user->id, 'block', false, 'user.php?id='.$user->id, true); +} +message_history_link($user->id, 0, false, '', '', 'both'); +echo ''; - echo '
'; +echo '
'; - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file -- 2.39.5