function local_mail_extends_navigation($root) { global $CFG, $COURSE, $PAGE, $SESSION, $SITE, $USER, $DB; //Aqui $consulta = "SELECT count(*) as contador\n\t\t FROM " . $CFG->prefix . "course AS c JOIN " . $CFG->prefix . "context AS ctx ON c.id = ctx.instanceid JOIN " . $CFG->prefix . "role_assignments AS ra ON ra.contextid = ctx.id JOIN " . $CFG->prefix . "user AS u ON u.id = ra.userid WHERE (c.id = " . $COURSE->id . " AND u.id = " . $USER->id . " AND ra.roleid = 5) OR ( " . $USER->id . " = 2) OR (u.id =" . $USER->id . " AND ra.roleid = 5)"; $bandera = 0; if ($courses = $DB->get_records_sql($consulta)) { foreach ($courses as $course) { if ($course->contador >= 1) { $bandera = 1; } else { $bandera = 0; } } } if ($bandera == 1) { if (!get_config('local_mail', 'version')) { return; } $courses = local_mail_get_my_courses(); $count = local_mail_message::count_menu($USER->id); // My mail $text = get_string('mymail', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $node = navigation_node::create($text, null, navigation_node::TYPE_ROOTNODE); if (!empty($count->inbox)) { $node->add_class('local_mail_new_messages'); } $child = $root->add_node($node, 'mycourses'); $child->add_class('mail_root'); // Compose $text = get_string('compose', 'local_mail'); $url = new moodle_url('/local/mail/compose.php'); $urlrecipients = new moodle_url('/local/mail/recipients.php'); if ($PAGE->url->compare($url, URL_MATCH_BASE) or $PAGE->url->compare($urlrecipients, URL_MATCH_BASE)) { $url->param('m', $PAGE->url->param('m')); } else { $url = new moodle_url('/local/mail/create.php'); if ($COURSE->id != $SITE->id) { $url->param('c', $COURSE->id); $url->param('sesskey', sesskey()); } } $node->add(s($text), $url); // Inbox $text = get_string('inbox', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox')); $child = $node->add(s($text), $url); $child->add_class('mail_inbox'); // Starred $text = get_string('starredmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'starred')); $node->add(s($text), $url); // Drafts $text = get_string('drafts', 'local_mail'); if (!empty($count->drafts)) { $text .= ' (' . $count->drafts . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'drafts')); $child = $node->add(s($text), $url); $child->add_class('mail_drafts'); // Sent $text = get_string('sentmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'sent')); $node->add(s($text), $url); // Courses if ($courses) { $text = get_string('courses', 'local_mail'); $nodecourses = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($courses as $course) { $text = $course->shortname; if (!empty($count->courses[$course->id])) { $text .= ' (' . $count->courses[$course->id] . ')'; } $params = array('t' => 'course', 'c' => $course->id); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodecourses->add(s($text), $url); $child->hidden = !$course->visible; $child->add_class('mail_course_' . $course->id); } } // Labels $labels = local_mail_label::fetch_user($USER->id); if ($labels) { $text = get_string('labels', 'local_mail'); $nodelabels = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($labels as $label) { $text = $label->name(); if (!empty($count->labels[$label->id()])) { $text .= ' (' . $count->labels[$label->id()] . ')'; } $params = array('t' => 'label', 'l' => $label->id()); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodelabels->add(s($text), $url); $child->add_class('mail_label_' . $label->id()); } } // Trash $text = get_string('trash', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'trash')); $node->add(s($text), $url); //Aqui } // User profile if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); if (local_mail_valid_recipient($userid)) { $vars = array('course' => $COURSE->id, 'recipient' => $userid); $PAGE->requires->string_for_js('sendmessage', 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/user.js'); } } // Users list if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/index.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); $vars = array('course' => $COURSE->id); $PAGE->requires->string_for_js('choosedots', 'moodle'); $PAGE->requires->strings_for_js(array('bulkmessage', 'to', 'cc', 'bcc'), 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/users.js'); } }
function local_mail_extend_navigation($root) { global $CFG, $COURSE, $PAGE, $SESSION, $SITE, $USER; if (!get_config('local_mail', 'version')) { return; } $courses = local_mail_get_my_courses(); $count = local_mail_message::count_menu($USER->id); // My mail $text = get_string('mymail', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $node = navigation_node::create($text, null, navigation_node::TYPE_ROOTNODE); if (!empty($count->inbox)) { $node->add_class('local_mail_new_messages'); } $child = $root->add_node($node, 'mycourses'); $child->add_class('mail_root'); // Compose $text = get_string('compose', 'local_mail'); $url = new moodle_url('/local/mail/compose.php'); $urlrecipients = new moodle_url('/local/mail/recipients.php'); if ($PAGE->url->compare($url, URL_MATCH_BASE) or $PAGE->url->compare($urlrecipients, URL_MATCH_BASE)) { $url->param('m', $PAGE->url->param('m')); } else { $url = new moodle_url('/local/mail/create.php'); if ($COURSE->id != $SITE->id) { $url->param('c', $COURSE->id); $url->param('sesskey', sesskey()); } } $node->add(s($text), $url); // Inbox $text = get_string('inbox', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox')); $child = $node->add(s($text), $url); $child->add_class('mail_inbox'); // Starred $text = get_string('starredmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'starred')); $node->add(s($text), $url); // Drafts $text = get_string('drafts', 'local_mail'); if (!empty($count->drafts)) { $text .= ' (' . $count->drafts . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'drafts')); $child = $node->add(s($text), $url); $child->add_class('mail_drafts'); // Sent $text = get_string('sentmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'sent')); $node->add(s($text), $url); // Courses if ($courses) { $text = get_string('courses', 'local_mail'); $nodecourses = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($courses as $course) { $text = $course->shortname; if (!empty($count->courses[$course->id])) { $text .= ' (' . $count->courses[$course->id] . ')'; } $params = array('t' => 'course', 'c' => $course->id); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodecourses->add(s($text), $url); $child->hidden = !$course->visible; $child->add_class('mail_course_'.$course->id); } } // Labels $labels = local_mail_label::fetch_user($USER->id); if ($labels) { $text = get_string('labels', 'local_mail'); $nodelabels = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($labels as $label) { $text = $label->name(); if (!empty($count->labels[$label->id()])) { $text .= ' (' . $count->labels[$label->id()] . ')'; } $params = array('t' => 'label', 'l' => $label->id()); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodelabels->add(s($text), $url); $child->add_class('mail_label_'.$label->id()); } } // Trash $text = get_string('trash', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'trash')); $node->add(s($text), $url); // Preferences $text = get_string('preferences'); $url = new moodle_url('/local/mail/preferences.php'); $node->add(s($text), $url); // User profile if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); if (local_mail_valid_recipient($userid)) { $vars = array('course' => $COURSE->id, 'recipient' => $userid); $PAGE->requires->string_for_js('sendmessage', 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/user.js'); } } // Users list if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/index.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); $vars = array('course' => $COURSE->id); $PAGE->requires->string_for_js('choosedots', 'moodle'); $PAGE->requires->strings_for_js(array( 'bulkmessage', 'to', 'cc', 'bcc', ), 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/users.js'); } // Block progress if ($PAGE->url->compare(new moodle_url('/blocks/progress/overview.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); $vars = array('course' => $COURSE->id); $PAGE->requires->string_for_js('choosedots', 'moodle'); $PAGE->requires->strings_for_js(array( 'bulkmessage', 'to', 'cc', 'bcc', ), 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/users.js'); } }
$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); $mform->get_data(); // Display page echo $OUTPUT->header(); if ($courses) {