]> git.mjollnir.org Git - moodle.git/commitdiff
message MDL-19801 Upgrade deprecated calls and added set_url calls
authorsamhemelryk <samhemelryk>
Tue, 29 Sep 2009 03:54:14 +0000 (03:54 +0000)
committersamhemelryk <samhemelryk>
Tue, 29 Sep 2009 03:54:14 +0000 (03:54 +0000)
message/discussion.php
message/edit.php
message/history.php
message/index.php
message/lib.php
message/messages.php
message/output/popup/message_output_popup.php
message/refresh.php
message/send.php
message/user.php

index ba86cf85b70ade1aa3de75d30b00994f5308d026..17be44264b02b38fcdf704ddf2b17aac4086d8db 100644 (file)
@@ -1,11 +1,34 @@
-<?php // $Id$
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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);
     }
 
     $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');
index 8d43000f163d5c60343d72e7a22a8ec1361de581..b82f2489999aecac5a75199024eba81a9dddd60c 100644 (file)
-<?php   // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * 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 '<form class="mform" method="post" action="'.$CFG->wwwroot.'/message/edit.php">';
+echo '<form class="mform" method="post" action="'.$CFG->wwwroot.'/message/edit.php">';
 
 /// Settings table...
-    echo '<fieldset id="providers" class="clearfix">';
-    echo '<legend class="ftoggler">'.get_string('providers_config', 'message').'</legend>';
-    $providers = message_get_my_providers();
-    $processors = $DB->get_records('message_processors');
-    $number_procs = count($processors);
-    echo '<table cellpadding="2"><tr><td>&nbsp;</td>'."\n";
-    foreach ( $processors as $processorid => $processor){
-        echo '<th align="center">'.get_string($processor->name, 'messageprocessor_'.$processor->name).'</th>';
+echo '<fieldset id="providers" class="clearfix">';
+echo '<legend class="ftoggler">'.get_string('providers_config', 'message').'</legend>';
+$providers = message_get_my_providers();
+$processors = $DB->get_records('message_processors');
+$number_procs = count($processors);
+echo '<table cellpadding="2"><tr><td>&nbsp;</td>'."\n";
+foreach ( $processors as $processorid => $processor){
+    echo '<th align="center">'.get_string($processor->name, 'messageprocessor_'.$processor->name).'</th>';
+}
+echo '</tr>';
+
+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 '</tr>';
-
-    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 '<tr><th align="right">'.$providername.$helpbtn.'</th><td colspan="'.$number_procs.'"></td></tr>'."\n";
-        foreach (array('loggedin', 'loggedoff') as $state){
-            $state_res = get_string($state, 'message');
-            echo '<tr><td align="right">'.$state_res.'</td>'."\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 '<td align="center"><input type="checkbox" name="'.$provider->component.'_'.$provider->name.'_'.$state.'['.$processor->name.']" '.$checked.' /></td>'."\n";
+    echo '<tr><th align="right">'.$providername.$helpbtn.'</th><td colspan="'.$number_procs.'"></td></tr>'."\n";
+    foreach (array('loggedin', 'loggedoff') as $state){
+        $state_res = get_string($state, 'message');
+        echo '<tr><td align="right">'.$state_res.'</td>'."\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 '</tr>'."\n";
+            echo '<td align="center"><input type="checkbox" name="'.$provider->component.'_'.$provider->name.'_'.$state.'['.$processor->name.']" '.$checked.' /></td>'."\n";
         }
+        echo '</tr>'."\n";
     }
-    echo '</table>';
-    echo '</fieldset>';
+}
+echo '</table>';
+echo '</fieldset>';
 
 /// 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 '<fieldset id="messageprocessor_'.$processor->name.'" class="clearfix">';
-                echo '<legend class="ftoggler">'.get_string($processor->name, 'messageprocessor_'.$processor->name).'</legend>';
+        if (class_exists($processclass)) {
+            $pclass = new $processclass();
+            echo '<fieldset id="messageprocessor_'.$processor->name.'" class="clearfix">';
+            echo '<legend class="ftoggler">'.get_string($processor->name, 'messageprocessor_'.$processor->name).'</legend>';
 
-                echo $pclass->config_form($preferences); 
+            echo $pclass->config_form($preferences);
 
-                echo '</fieldset>';
+            echo '</fieldset>';
 
-            } else{ 
-                print_error('errorcallingprocessor', 'message');
-            }
+        } else{
+            print_error('errorcallingprocessor', 'message');
         }
     }
+}
 
-    echo '<div><input type="hidden" name="sesskey" value="'.sesskey().'" /></div>';
-    echo '<div style="text-align:center"><input name="submit" value="'. get_string('updatemyprofile') .'" type="submit" /></div>';
+echo '<div><input type="hidden" name="sesskey" value="'.sesskey().'" /></div>';
+echo '<div style="text-align:center"><input name="submit" value="'. get_string('updatemyprofile') .'" type="submit" /></div>';
 
-    echo "</form>";
+echo "</form>";
 
-    echo $OUTPUT->footer();
+echo $OUTPUT->footer();
 
-?>
+?>
\ No newline at end of file
index b6d7255408f639216eea95902e3b8fad4199b5f8..cd3f7ca4d3d26cb0b9615f1ee5fa0d899ea2e8ff 100644 (file)
-<?php // $Id$
-      // For listing message histories between any two users
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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.'&amp;user2='.$userid2, $userid1);
+add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&amp;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 '<table align="center" cellpadding="10"><tr>';
-    echo '<td align="center">';
-    $userpic = moodle_user_picture::make($user1, SITEID);
-    $userpic->size = 100;
-    $userpic->link = true;
-    echo $OUTPUT->user_picture($userpic).'<br />';
-    echo fullname($user1);
-    echo '</td>';
-    echo '<td align="center">';
-    echo '<img src="'.$CFG->wwwroot.'/pix/t/left.gif" alt="'.get_string('from').'" />';
-    echo '<img src="'.$CFG->wwwroot.'/pix/t/right.gif" alt="'.get_string('to').'" />';
-    echo '</td>';
-    echo '<td align="center">';
-    $userpic = moodle_user_picture::make($user2, SITEID);
-    $userpic->size = 100;
-    $userpic->link = true;
-    echo $OUTPUT->user_picture($userpic).'<br />';
-    echo fullname($user2);
-    echo '</td>';
-    echo '</tr></table>';
-    echo $OUTPUT->box_end();
+echo $OUTPUT->box_start('center');
+echo '<table align="center" cellpadding="10"><tr>';
+echo '<td align="center">';
+$userpic = moodle_user_picture::make($user1, SITEID);
+$userpic->size = 100;
+$userpic->link = true;
+echo $OUTPUT->user_picture($userpic).'<br />';
+echo fullname($user1);
+echo '</td>';
+echo '<td align="center">';
+echo '<img src="'.$CFG->wwwroot.'/pix/t/left.gif" alt="'.get_string('from').'" />';
+echo '<img src="'.$CFG->wwwroot.'/pix/t/right.gif" alt="'.get_string('to').'" />';
+echo '</td>';
+echo '<td align="center">';
+$userpic = moodle_user_picture::make($user2, SITEID);
+$userpic->size = 100;
+$userpic->link = true;
+echo $OUTPUT->user_picture($userpic).'<br />';
+echo fullname($user2);
+echo '</td>';
+echo '</tr></table>';
+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 '<a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
-                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 '<a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
+            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
index 056cf64c22ed4bb7e32d0997c13d172d7eb3bce5..879063cdd93ceea66e80fe28e80c54a637d1d624 100644 (file)
-<?php /// $Id$
-       /// Main interface window for messaging
-
-    require('../config.php');
-    require('lib.php');
-
-    require_login(0, false);
-
-    if (isguest()) {
-        redirect($CFG->wwwroot);
-    }
-
-    if (empty($CFG->messaging)) {
-        print_error('disabled', 'message');
-    }
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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.'&amp;user2='.$USER->id, $addcontact);
-        message_add_contact($addcontact);
-    }
-    if ($removecontact and confirm_sesskey()) {
-        add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&amp;user2='.$USER->id, $removecontact);
-        message_remove_contact($removecontact);
-    }
-    if ($blockcontact and confirm_sesskey()) {
-        add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&amp;user2='.$USER->id, $blockcontact);
-        message_block_contact($blockcontact);
-    }
-    if ($unblockcontact and confirm_sesskey()) {
-        add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&amp;user2='.$USER->id, $unblockcontact);
-        message_unblock_contact($unblockcontact);
-    }
+if ($addcontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&amp;user2='.$USER->id, $addcontact);
+    message_add_contact($addcontact);
+}
+if ($removecontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&amp;user2='.$USER->id, $removecontact);
+    message_remove_contact($removecontact);
+}
+if ($blockcontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&amp;user2='.$USER->id, $blockcontact);
+    message_block_contact($blockcontact);
+}
+if ($unblockcontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&amp;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 '<table cellspacing="2" cellpadding="2" border="0" width="95%" class="boxaligncenter">';  
-    echo '<tr>';
+$PAGE->set_generaltype('popup');
+$PAGE->set_title(get_string('messages', 'message').' - '.format_string($SITE->fullname));
+echo $OUTPUT->header();
+echo '<table cellspacing="2" cellpadding="2" border="0" width="95%" class="boxaligncenter">';  
+echo '<tr>';
 
 /// Print out the tabs
-    echo '<td>';
-    $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 '</td>';
-
-
-    echo '</tr><tr>';
+echo '<td>';
+$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 '</td>';
+
+
+echo '</tr><tr>';
 
 /// Print out contents of the tab
-    echo '<td>';
+echo '<td>';
 
 /// 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 '</td> </tr> </table>';
-    echo $OUTPUT->footer();
+echo '</td> </tr> </table>';
+echo $OUTPUT->footer();
 
-?>
+?>
\ No newline at end of file
index f8a6d7f17ff84d4bd1519153b0657727766b5a59..b6856f0f3a48e959b2007fb3dcdb47f39b487bda 100644 (file)
@@ -1,5 +1,27 @@
-<?php  
-///// library functions for messaging %Id%
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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
index d872faa3b0b11faa758b4c7196ffa6cd4eb17eb2..5c9be78a660ee97df908e4d3eb02b4c00bed8db4 100644 (file)
@@ -1,13 +1,35 @@
 <?php
 
-    require('../config.php');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-    @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 "<div id='messages'></div>";
-    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 "<div id='messages'></div>";
+echo $OUTPUT->footer();
     
 ?>
\ No newline at end of file
index ea4e537f53bfb4a0805f7f51419af1c794aa126e..6d1b36d4266315d725f5158ff8028204ffc6005c 100644 (file)
@@ -1,35 +1,26 @@
 <?php
 
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * 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
index 342c2374addb0194a2c25f66578d7cf9b58e6e79..0b1c4858a32b323809fe9f12c3eeed2aa3101086 100644 (file)
@@ -1,72 +1,94 @@
-<?php // $Id$
+<?php
 
-    require('../config.php');
-    require('lib.php');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-    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 = '<div class="message other"><span class="author">'.s($userfullname).'</span> '.
-                '<span class="time">['.$time.']</span>: '.
-                '<span class="content">'.$printmessage.'</span></div>';
-            $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 '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
-        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 = '<div class="message other"><span class="author">'.s($userfullname).'</span> '.
+            '<span class="time">['.$time.']</span>: '.
+            '<span class="content">'.$printmessage.'</span></div>';
+        $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 '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
+    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
index 9e522521f89812a660ec96af87a0c8e75aea5b33..40dc44ea9064acbac5c9a075eee4ee7ef8a5b974 100644 (file)
@@ -1,4 +1,25 @@
-<?php // $Id$
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @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
index f86a99f2952d0e5c49fbf69e01ac03aca942a3fb..f377d28d76fe663fe7387c1bf09cfb6ab5b4c841 100644 (file)
-<?php // $Id$
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @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.'&amp;user2='.$USER->id, $addcontact);
-        message_add_contact($addcontact);
-    }
-    if ($removecontact and confirm_sesskey()) {
-        add_to_log(SITEID, 'message', 'remove contact', 
-                   'history.php?user1='.$removecontact.'&amp;user2='.$USER->id, $removecontact);
-        message_remove_contact($removecontact);
-    }
-    if ($blockcontact and confirm_sesskey()) {
-        add_to_log(SITEID, 'message', 'block contact', 
-                   'history.php?user1='.$blockcontact.'&amp;user2='.$USER->id, $blockcontact);
-        message_block_contact($blockcontact);
-    }
-    if ($unblockcontact and confirm_sesskey()) {
-        add_to_log(SITEID, 'message', 'unblock contact', 
-                   'history.php?user1='.$unblockcontact.'&amp;user2='.$USER->id, $unblockcontact);
-        message_unblock_contact($unblockcontact);
-    }
-
-    //$PAGE->set_title('Message History');
-    $PAGE->set_generaltype('popup');
-    echo $OUTPUT->header();
-    echo '<table width="100%" cellpadding="0" cellspacing="0"><tr>';
-    echo '<td width="100">';
-    $userpic = moodle_user_picture::make($user, SITEID);
-    $userpic->size = 48;
-    $userpic->link = true;
-    echo $OUTPUT->user_picture($userpic) .'</td>';
-    echo '<td valign="middle" align="center">';
-
-    echo '<div class="name">'.fullname($user).'</div>';
-
-    echo '<div class="commands">';
-    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.'&amp;user2='.$USER->id, $addcontact);
+    message_add_contact($addcontact);
+}
+if ($removecontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'remove contact',
+               'history.php?user1='.$removecontact.'&amp;user2='.$USER->id, $removecontact);
+    message_remove_contact($removecontact);
+}
+if ($blockcontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'block contact',
+               'history.php?user1='.$blockcontact.'&amp;user2='.$USER->id, $blockcontact);
+    message_block_contact($blockcontact);
+}
+if ($unblockcontact and confirm_sesskey()) {
+    add_to_log(SITEID, 'message', 'unblock contact',
+               'history.php?user1='.$unblockcontact.'&amp;user2='.$USER->id, $unblockcontact);
+    message_unblock_contact($unblockcontact);
+}
+
+//$PAGE->set_title('Message History');
+$PAGE->set_generaltype('popup');
+echo $OUTPUT->header();
+echo '<table width="100%" cellpadding="0" cellspacing="0"><tr>';
+echo '<td width="100">';
+$userpic = moodle_user_picture::make($user, SITEID);
+$userpic->size = 48;
+$userpic->link = true;
+echo $OUTPUT->user_picture($userpic) .'</td>';
+echo '<td valign="middle" align="center">';
+
+echo '<div class="name">'.fullname($user).'</div>';
+
+echo '<div class="commands">';
+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 '</div>';
+     }
+} 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 '</div>';
 
-    echo '</td></tr></table>';
+echo '</td></tr></table>';
 
-    echo $OUTPUT->footer();
+echo $OUTPUT->footer();
 
-?>
+?>
\ No newline at end of file