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); }
require_once 'create_form.php'; $courseid = optional_param('c', $SITE->id, PARAM_INT); $recipient = optional_param('r', false, PARAM_INT); $recipients = optional_param('rs', '', PARAM_SEQUENCE); $role = optional_param('local_mail_role', 0, PARAM_INT); // Setup page if (!($course = $DB->get_record('course', array('id' => $courseid)))) { print_error('invalidcourse', 'error'); } $url = new moodle_url('/local/mail/create.php'); local_mail_setup_page($course, $url); $context = context_course::instance($course->id); // Create message if ($course->id != $SITE->id and has_capability('local/mail:usemail', $context)) { require_sesskey(); $message = local_mail_message::create($USER->id, $course->id); if ($recipients) { local_mail_add_recipients($message, explode(',', $recipients), $role); } else { if (local_mail_valid_recipient($recipient)) { $message->add_recipient('to', $recipient); } } $params = array('m' => $message->id()); $url = new moodle_url('/local/mail/compose.php', $params); redirect($url); } // Setup form $courses = local_mail_get_my_courses(); $customdata = array('courses' => $courses); $mform = new local_mail_create_form($url, $customdata);
// 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);
public function test_fetch_index_attachment_deleted() { $message = local_mail_message::create(201, 101); $message->save('subject1', 'content1', 301 , false); $message->add_recipient('to', 202); $this->assertTrue($message->draft()); $result = local_mail_message::fetch_index(201, 'attachment', false); $this->assertEquals(array($message), $result); }
$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);
function local_mail_searchmessages($type, $itemid, $query, $offset = false, $perpage = false) { global $USER, $PAGE; $prev = $next = false; $date = $nummsgs = ''; $url = new moodle_url('/local/mail/view.php', array('t' => $type)); $PAGE->set_url($url); $mailoutput = $PAGE->get_renderer('local_mail'); if (!empty($query['time'])) { $date = $query['time']; $time = explode(',', $query['time']); if (count($time) == 3) { $query['time'] = make_timestamp($time[0], $time[1], $time[2], 23, 59, 59); } else { $query['time'] = ''; } } $query['before'] = $query['before'] == 0 ? '' : $query['before']; $query['after'] = $query['after'] == 0 ? '' : $query['after']; $mailpagesize = $query['limit']; $query['limit'] += 1; if ($perpage) { $query['before'] = $query['perpageid'] == 0 ? '' : $query['perpageid']; $query['after'] = ''; } $messages = local_mail_message::search_index($USER->id, $type, $itemid, $query); $nummsgs = count($messages); if ($nummsgs == $query['limit']) { if (!empty($query['after'])) { $query['perpageid'] = $messages[0]->id(); $messages = array_slice($messages, 1, count($messages)); $prev = true; } else { $messages = array_slice($messages, 0, count($messages) - 1); $next = true; } } else { if (!empty($query['after']) and $nummsgs < $query['limit']) { $query['limit'] -= $nummsgs; $query['after'] = ''; $query['before'] = isset($messages[$nummsgs - 1]) ? $messages[$nummsgs - 1]->id() : ''; $newmessages = local_mail_message::search_index($USER->id, $type, $itemid, $query); if (count($newmessages) == $query['limit']) { $newmessages = array_slice($newmessages, 0, count($newmessages) - 1); $next = true; } $query['before'] = ''; $messages = array_merge($messages, $newmessages); } } $content = local_mail_print_messages($itemid, $type, 0, $messages, false); $prev = ($prev or !empty($query['before'])); $next = ($next or !empty($query['after'])); if (!$prev) { $query['perpageid'] = 0; } $data = array('query' => $query['pattern'], 'searchfrom' => $query['searchfrom'], 'searchto' => $query['searchto'], 'unread' => !empty($query['unread']), 'attach' => !empty($query['attach']), 'date' => $date, 'prev' => $prev, 'next' => $next, 'idafter' => !empty($query['after']) ? $query['after'] : false, 'idbefore' => !empty($query['before']) ? $query['before'] : false, 'perpageid' => $query['perpageid']); return array('info' => '', 'html' => $content, 'search' => $data, 'perpage' => $offset !== false ? $mailoutput->perpage($offset, $mailpagesize) : ''); }