require_once dirname(__FILE__) . '/../../config.php'; require_once $CFG->dirroot . '/blocks/jmail/locallib.php'; require_once $CFG->dirroot . '/blocks/jmail/block_jmail_mailbox.class.php'; $id = optional_param('id', SITEID, PARAM_INT); $to = optional_param('to', 0, PARAM_INT); $PAGE->set_url('/blocks/jmail/mailbox.php', array('id' => $id)); if (!($course = $DB->get_record('course', array('id' => $id)))) { throw new moodle_exception('invalidcourseid', 'error'); } if (!($block = $DB->get_record('block', array('name' => 'jmail', 'visible' => 1)))) { throw new moodle_exception('invalidcourseid', 'error'); } require_login($course->id); $context = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST); $PAGE->set_context($context); if (!($mailbox = new block_jmail_mailbox($course, $context))) { throw new moodle_exception('Invalid mailbox'); } add_to_log($course->id, 'jmail', 'view mailbox'); // TODO, check block disabled or instance not visible? $PAGE->blocks->show_only_fake_blocks(); $renderer = $PAGE->get_renderer('block_jmail'); $strheading = !empty($mailbox->config->title) ? format_string($mailbox->config->title) : get_string('pluginname', 'block_jmail'); $PAGE->navbar->add($strheading); $PAGE->set_title($strheading); $PAGE->set_heading($course->fullname . ': ' . $strheading); $module = array('name' => 'block_jmail', 'fullpath' => '/blocks/jmail/module.js', 'requires' => array('io', 'event-custom', 'json-parse', 'base', 'node', 'tabview', 'datasource-get', 'datasource-jsonschema', 'datatable-base', 'datatable-datasource', 'datatable-sort', 'panel', 'autocomplete', 'autocomplete-highlighters'), 'strings' => array(array('from', 'block_jmail'), array('subject', 'block_jmail'), array('date', 'block_jmail'), array('messagesent', 'block_jmail'), array('reply', 'block_jmail'), array('forward', 'block_jmail'), array('print', 'block_jmail'), array('messagesaved', 'block_jmail'), array('addlabel', 'block_jmail'), array('cc', 'block_jmail'), array('bcc', 'block_jmail'), array('messagedeleted', 'block_jmail'), array('messagesdeleted', 'block_jmail'), array('errortorequired', 'block_jmail'), array('errorsubjectrequired', 'block_jmail'), array('to', 'block_jmail'), array('confirmdelete', 'block_jmail'), array('label', 'block_jmail'), array('labels', 'block_jmail'), array('nomessagesfound', 'block_jmail'), array('re', 'block_jmail'), array('fw', 'block_jmail'), array('attachments', 'block_jmail'), array('preferences', 'block_jmail'), array('approvalpending', 'block_jmail'), array('messagehastobeapproved', 'block_jmail'), array('first', 'block_jmail'), array('last', 'block_jmail'), array('next', 'block_jmail'), array('previous', 'block_jmail'), array('delete', 'block_jmail'), array('save', 'block_jmail'), array('download', 'block_jmail'), array('savetomyprivatefiles', 'block_jmail'), array('filesaved', 'block_jmail'), array('mailbox', 'block_jmail'), array('delivertodifferentcourse', 'block_jmail'), array('delivertoglobalinbox', 'block_jmail'), array('inbox', 'block_jmail'), array('add', 'moodle'), array('deletem', 'block_jmail'), array('rename', 'moodle'), array('edit', 'moodle'), array('ok', 'moodle'), array('cancel', 'moodle'))); $usertoid = 0; $usertoname = ''; if ($userto = $DB->get_record('user', array('id' => $to, 'deleted' => 0))) { $d = new stdClass();
public function get_content() { global $CFG, $DB; if (empty($this->instance)) { $this->content = ''; return $this->content; } if ($this->content !== null) { return $this->content; } // Only for logged and non guest users if (!isloggedin() or isguestuser()) { return ''; } require_once dirname(__FILE__) . '/block_jmail_mailbox.class.php'; $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; $currentcontext = $this->page->context; $renderer = $this->page->get_renderer('block_jmail'); $newmailicon = $renderer->plugin_icon('new'); $mycourses = array(); if ($this->page->course->id == SITEID) { if (!empty($CFG->block_jmail_enable_globalinbox)) { $this->content->footer = $renderer->global_inbox(); } if ($mycourses = block_jmail_mailbox::get_my_mailboxes()) { foreach ($mycourses as $course) { if ($mailbox = new block_jmail_mailbox($course)) { if ($unreadmails = $mailbox->count_unread_messages()) { $this->content->items[] = $renderer->unread_messages($mailbox); $this->content->icons[] = $newmailicon; } } } } } else { $this->content->footer = $renderer->course_inbox($this->page->course); $context = block_jmail_get_context(CONTEXT_COURSE, $this->page->course->id); if ($mailbox = new block_jmail_mailbox($this->page->course, $context)) { if ($unreadmails = $mailbox->count_unread_messages()) { $mailbox->pagesize = 5; if ($messages = $mailbox->get_message_headers('unread', 0, 'date', 'desc', '')) { foreach ($messages[1] as $m) { $strfrom = get_string('from', 'block_jmail'); $messagetext = shorten_text($m->subject, 25) . " (<i>{$strfrom}: " . shorten_text($m->from, 15) . ")</i>"; $this->content->items[] = $messagetext; $this->content->icons[] = ''; } } $this->content->items[] = get_string('unreadmessages', 'block_jmail', $unreadmails); $this->content->icons[] = $newmailicon; } } } if (!count($this->content->items)) { $this->content->items[] = get_string('nonewmessages', 'block_jmail'); } return $this->content; }
*/ define('AJAX_SCRIPT', true); require_once '../../config.php'; require_once $CFG->dirroot . '/blocks/jmail/locallib.php'; require_once $CFG->dirroot . '/blocks/jmail/block_jmail_mailbox.class.php'; $id = required_param('id', PARAM_INT); // course id $action = required_param('action', PARAM_ACTION); $PAGE->set_url(new moodle_url('/blocks/jmail/block_jmail_ajax.php', array('id' => $id))); $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); $context = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST); $PAGE->set_context($context); require_login($course); require_sesskey(); $err = new stdClass(); if (!($mailbox = new block_jmail_mailbox($course, $context))) { $err->error = "Invalid mailbox"; echo json_encode($err); die; } // TODO, check block disabled or instance not visible? if (isguestuser()) { $err->error = get_string('noguest'); die(json_encode($err)); } $data = null; echo $OUTPUT->header(); // send headers switch ($action) { case 'get_message_headers': $label = optional_param('label', 'inbox', PARAM_ALPHANUM);