Exemple #1
0
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');
    }
}
    public function toolbar($type, $courseid = 0, $params = null) {

        $replyall = isset($params['replyall']) ? $params['replyall'] : false;
        $paging = isset($params['paging']) ? $params['paging'] : null;
        $trash = isset($params['trash']) ? $params['trash'] : false;
        $labelid = isset($params['labelid']) ? $params['labelid'] : false;

        $toolbardown = false;
        if ($type === 'reply') {
            $viewcourse = array_key_exists($courseid, local_mail_get_my_courses());
            $output = $this->reply($viewcourse);
            // all recipients
            $output .= $this->replyall(($viewcourse and $replyall));
            $output .= $this->forward($viewcourse);
            $toolbardown = true;
        } else if ($type === 'forward') {
            $viewcourse = array_key_exists($courseid, local_mail_get_my_courses());
            $output = $this->forward($viewcourse);
            $toolbardown = true;
        } else {
            $selectall = $this->selectall();
            $labels = $extended = $goback = $search = $selectedlbl = '';
            if (!$trash and $type !== 'trash') {
                $labels = $this->labels($type);
            }
            $read = $unread = '';
            if ($type !== 'drafts') {
                $unread = $this->unread($type);
                $delete = $this->delete($trash);
            } else {
                $delete = $this->discard();
            }
            $pagingbar = '';
            if ($type !== 'view') {
                if ($type !== 'drafts') {
                    $read = $this->read();
                }
                $pagingbar = $this->paging($paging['offset'],
                                        $paging['count'],
                                        $paging['totalcount']);
                $search = $this->search();
            } else {
                $goback = $this->goback($paging);
            }
            if ($type === 'label') {
                $extended = $this->optlabels();
                $selectedlbl = $this->label(local_mail_label::fetch($labelid));
            }
            $more = $this->moreactions();
            $clearer = $this->output->container('', 'clearer');
            $left = html_writer::tag('div',
                $goback . $selectall . $labels . $read . $unread . $delete . $extended . $more . $search . $selectedlbl,
                array('class' => 'mail_buttons'));
            $output = $left . $pagingbar . $clearer;
        }
        return $this->output->container($output, ($toolbardown ? 'mail_toolbar_down' : 'mail_toolbar'));
    }
$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) {
    $mform->display();
} else {
    echo $OUTPUT->notification(get_string('cannotcompose', 'local_mail'));
}
echo $OUTPUT->footer();
Exemple #4
0
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');
    }
}
Exemple #5
0
function local_mail_get_info()
{
    global $USER;
    $count = local_mail_message::count_menu($USER->id);
    $text = get_string('mymail', 'local_mail');
    if (empty($count->inbox)) {
        $count->root = $text;
    } else {
        $count->root = $text . ' (' . $count->inbox . ')';
    }
    $text = get_string('inbox', 'local_mail');
    if (empty($count->inbox)) {
        $count->inbox = $text;
    } else {
        $count->inbox = $text . ' (' . $count->inbox . ')';
    }
    $text = get_string('drafts', 'local_mail');
    if (empty($count->drafts)) {
        $count->drafts = $text;
    } else {
        $count->drafts = $text . ' (' . $count->drafts . ')';
    }
    $labels = local_mail_label::fetch_user($USER->id);
    if ($labels) {
        foreach ($labels as $label) {
            $text = $label->name();
            if (empty($count->labels[$label->id()])) {
                $count->labels[$label->id()] = $text;
            } else {
                $count->labels[$label->id()] = $text . ' (' . $count->labels[$label->id()] . ')';
            }
        }
    }
    if (!($courses = local_mail_get_my_courses())) {
        return;
    }
    foreach ($courses as $course) {
        $text = $course->shortname;
        if (empty($count->courses[$course->id])) {
            $count->courses[$course->id] = $text;
        } else {
            $count->courses[$course->id] = $text . ' (' . $count->courses[$course->id] . ')';
        }
    }
    return $count;
}