Beispiel #1
0
function local_mail_pluginfile($course, $cm, $context, $filearea, $args,
                               $forcedownload, array $options=array()) {
    global $SITE, $USER;

    require_login($SITE, false);

    // Check message

    $messageid = (int) array_shift($args);
    $message = local_mail_message::fetch($messageid);
    if ($filearea != 'message' or !$message or !$message->viewable($USER->id, true)) {
        return false;
    }

    // Fetch file info

    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/$context->id/local_mail/$filearea/$messageid/$relativepath";
    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
        return false;
    }

    send_stored_file($file, 0, 0, true, $options);
}
// 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/>.
/**
 * @package    local-mail
 * @copyright  Albert Gasset <*****@*****.**>
 * @copyright  Marc Català <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once 'locallib.php';
require_once 'recipients_selector.php';
$messageid = required_param('m', PARAM_INT);
// Fetch message
$message = local_mail_message::fetch($messageid);
if (!$message or !$message->editable($USER->id)) {
    print_error('invalidmessage', 'local_mail');
}
// Set up page
$params = array('m' => $messageid);
$url = new moodle_url('/local/mail/recipients.php', $params);
$activeurl = new moodle_url('/local/mail/compose.php', $params);
local_mail_setup_page($message->course(), $url);
navigation_node::override_active_url($activeurl);
// Check group
$groupid = groups_get_course_group($COURSE, true);
if (!$groupid and $COURSE->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $PAGE->context)) {
    echo $OUTPUT->header();
    echo $OUTPUT->heading(get_string('notingroup', 'local_mail'));
    echo $OUTPUT->continue_button($activeurl);
Beispiel #3
0
                 $message->set_deleted($USER->id, !$message->deleted($USER->id));
             }
             $totalcount -= 1;
         }
     }
     if ($offset > $totalcount - 1) {
         $url->offset = min(0, $offset - $mailpagesize);
     } else {
         $url->offset = $offset;
     }
     redirect($url);
 }
 // Starred
 if ($starred) {
     require_sesskey();
     $message = local_mail_message::fetch($starred);
     if (!$message or !$message->viewable($USER->id) or $message->deleted($USER->id)) {
         print_error('invalidmessage', 'local_mail');
     }
     $message->set_starred($USER->id, !$message->starred($USER->id));
     redirect($url);
 }
 // Read or Unread
 if ($read || $unread) {
     require_sesskey();
     foreach ($messages as $message) {
         if (in_array($message->id(), $msgs)) {
             $message->set_unread($USER->id, $unread);
         }
     }
     redirect($url);
    public function test_fetch() {
        $label1 = local_mail_label::create(201, 'label1');
        $label2 = local_mail_label::create(201, 'label2');
        $label3 = local_mail_label::create(202, 'label3');
        $this->loadRecords('local_mail_messages', array(
            array('id', 'courseid', 'subject',  'content', 'format', 'draft', 'time'),
            array( 501,  101,       'subject1', 'content1', 301,      0,       1234567890 ),
            array( 502,  101,       'subject2', 'content2', 301,      1,       1234567891 ),
            array( 503,  101,       'subject3', 'content3', 301,      0,       1234567892 ),
            array( 504,  101,       'subject4', 'content4', 301,      0,       1234567893 ),
        ));
        $this->loadRecords('local_mail_message_refs', array(
            array('messageid', 'reference'),
            array( 501,         504 ),
            array( 501,         503 ),
            array( 502,         501 ),
        ));
        $this->loadRecords('local_mail_message_users', array(
             array('messageid', 'userid', 'role', 'unread', 'starred',  'deleted'),
             array( 501,         201,     'from',  0,        0,          1 ),
             array( 501,         202,     'to',    0,        1,          0 ),
             array( 501,         203,     'cc',    1,        0,          0 ),
             array( 502,         201,     'from',  0,        0,          0 ),
             array( 503,         201,     'from',  0,        0,          0 ),
             array( 503,         202,     'to',    0,        0,          0 ),
             array( 504,         202,     'from',  0,        0,          0 ),
             array( 504,         201,     'to',    0,        0,          0 ),
        ));
        $this->loadRecords('local_mail_message_labels', array(
            array('messageid', 'labelid'),
            array( 501,         $label1->id() ),
            array( 501,         $label2->id() ),
            array( 502,         $label3->id() ),
        ));

        $result = local_mail_message::fetch(501);

        $this->assertInstanceOf('local_mail_message', $result);
        $this->assertEquals(501, $result->id());
        $this->assertEquals($this->course1, $result->course());
        $this->assertEquals('subject1', $result->subject());
        $this->assertEquals('content1', $result->content());
        $this->assertEquals(301, $result->format());
        $this->assertFalse($result->draft());
        $this->assertEquals(1234567890, $result->time());
        $references = array(local_mail_message::fetch(504), local_mail_message::fetch(503));
        $this->assertEquals($references, $result->references());
        $this->assertEquals($this->user1, $result->sender());
        $this->assertFalse($result->unread(201));
        $this->assertFalse($result->starred(201));
        $this->assertTrue($result->deleted(201));
        $this->assertCount(1, $result->recipients('to'));
        $this->assertCount(1, $result->recipients('cc'));
        $this->assertCount(0, $result->recipients('bcc'));
        $this->assertContains($this->user2, $result->recipients('to'));
        $this->assertContains($this->user3, $result->recipients('cc'));
        $this->assertFalse($result->unread(202));
        $this->assertTrue($result->starred(202));
        $this->assertFalse($result->deleted(202));
        $this->assertTrue($result->unread(203));
        $this->assertFalse($result->starred(203));
        $this->assertFalse($result->deleted(203));
        $this->assertCount(2, $result->labels());
        $this->assertContains($label1, $result->labels());
        $this->assertContains($label2, $result->labels());

        $this->assertFalse(local_mail_message::fetch(505));
    }
Beispiel #5
0
$validactions = array('starred', 'unstarred', 'delete', 'restore', 'markasread', 'markasunread', 'prevpage', 'nextpage', 'perpage', 'viewmail', 'goback', 'assignlabels', 'newlabel', 'setlabel', 'getrecipients', 'updaterecipients', 'search');
$nomessageactions = array('prevpage', 'nextpage', 'perpage', 'goback', 'setlabel', 'search');
if ($action and in_array($action, $validactions) and !empty($USER->id)) {
    if (!confirm_sesskey($sesskey)) {
        echo json_encode(array('msgerror' => get_string('invalidsesskey', 'error')));
        die;
    }
    $params = array();
    $offset = max(0, $offset);
    if (empty($msgs) and !in_array($action, $nomessageactions)) {
        echo json_encode(array('msgerror' => get_string('nomessageserror', 'local_mail')));
        die;
    }
    if (!in_array($action, $nomessageactions)) {
        if ($action == 'viewmail' or $action == 'getrecipients' or $action == 'updaterecipients') {
            $message = local_mail_message::fetch($msgs);
            if (!$message or !$message->viewable($USER->id)) {
                echo json_encode(array('msgerror' => get_string('invalidmessage', 'local_mail')));
                die;
            }
        } else {
            $msgsids = explode(',', $msgs);
            $messages = local_mail_message::fetch_many($msgsids);
        }
    }
    $mailpagesize = get_user_preferences('local_mail_mailsperpage', MAIL_PAGESIZE, $USER->id);
    $params = array();
    $searchdata = array();
    if ($searching) {
        $searchdata = array('pattern' => $search, 'searchfrom' => $searchfrom, 'searchto' => $searchto, 'time' => $time, 'unread' => $unread, 'attach' => $attach, 'before' => $before, 'after' => $after, 'limit' => $mailpagesize, 'perpageid' => $perpageid);
    }