/**
 * This function prints blocks.
 *
 * @uses $CGF, $USER
 * @param int $userid User ID
 * @param int $courseid Course ID
 * @param boolean $printsearchblock Print search block
 * @return NULL
 * @todo Finish documenting this function
 **/
function email_printblocks($userid, $courseid, $printsearchblock = true)
{
    global $CFG, $USER;
    $strcourse = get_string('course');
    $strcourses = get_string('mailboxs', 'block_email_list');
    $strsearch = get_string('search');
    $strmail = get_string('name', 'block_email_list');
    // For title blocks
    $startdivtitle = '<div class="title">';
    $enddivtitle = '</div>';
    $list = array();
    $icons = array();
    if ($printsearchblock) {
        // Print search block
        $form = email_get_search_form($courseid);
        print_side_block_start($startdivtitle . $strsearch . $enddivtitle);
        echo $form;
        print_side_block_end();
    }
    // Print my folders
    email_print_tree_myfolders($userid, $courseid);
    // Remove old fields
    unset($list);
    unset($icons);
    // Get my course
    $mycourses = get_my_courses($USER->id, NULL, 'id, fullname, visible');
    $list = array();
    $icons = array();
    // Get courses
    foreach ($mycourses as $mycourse) {
        $context = get_context_instance(CONTEXT_COURSE, $mycourse->id);
        //Get the number of unread mails
        $numberunreadmails = email_count_unreaded_mails($USER->id, $mycourse->id);
        $unreadmails = '';
        // Only show if has unreaded mails
        if ($numberunreadmails > 0) {
            $unreadmails = '<b>(' . $numberunreadmails . ')</b>';
            // Define default path of icon for course
            $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/openicon.gif" height="16" width="16" alt="' . $strcourse . '" />';
        } else {
            // Define default path of icon for course
            $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/icon.gif" height="16" width="16" alt="' . $strcourse . '" />';
        }
        $linkcss = $mycourse->visible ? '' : ' class="dimmed" ';
        if (!$mycourse->visible and !has_capability('moodle/legacy:student', $context, $USER->id, false) or !has_capability('moodle/legacy:student', $context, $USER->id, false) or has_capability('moodle/legacy:student', $context, $USER->id, false) and $mycourse->visible) {
            $list[] = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '" ' . $linkcss . '>' . $mycourse->fullname . ' ' . $unreadmails . '</a>';
            $icons[] = $icon;
        }
    }
    // Print block of my courses
    print_side_block($startdivtitle . $strcourses . $enddivtitle, '', $list, $icons);
}
Example #2
0
/**
 * This function prints blocks.
 *
 * @uses $CGF, $USER, $OUTPUT
 * @param int $userid User ID
 * @param int $courseid Course ID
 * @param boolean $printsearchblock Print search block
 * @return NULL
 * @todo Finish documenting this function
 **/
function email_printblocks($userid, $courseid, $printsearchblock = true)
{
    global $CFG, $USER, $OUTPUT;
    $strcourse = get_string('course');
    $strcourses = get_string('mailboxs', 'block_email_list');
    $strsearch = get_string('search');
    $strmail = get_string('name', 'block_email_list');
    // For title blocks
    $startdivtitle = '<div class="title">';
    $enddivtitle = '</div>';
    $list = array();
    $icons = array();
    if ($printsearchblock) {
        // Print search block
        $form = email_get_search_form($courseid);
        print_side_block_start($startdivtitle . $strsearch . $enddivtitle);
        echo $form;
        print_side_block_end();
    }
    // Print my folders
    email_print_tree_myfolders($userid, $courseid);
    // Remove old fields
    unset($list);
    unset($icons);
    // Get my course
    $mycourses = get_my_courses($USER->id, NULL, 'id, fullname, shortname, visible', false, $CFG->email_max_number_courses);
    // Limit
    $list = array();
    $icons = array();
    $number = 0;
    // Get courses
    foreach ($mycourses as $mycourse) {
        ++$number;
        // increment for first course
        if ($number > $CFG->email_max_number_courses && !empty($CFG->email_max_number_courses)) {
            continue;
        }
        $context = get_context_instance(CONTEXT_COURSE, $mycourse->id);
        //Get the number of unread mails
        $numberunreadmails = email_count_unreaded_mails($USER->id, $mycourse->id);
        $unreadmails = '';
        // Only show if has unreaded mails
        if ($numberunreadmails > 0) {
            $unreadmails = '<b>(' . $numberunreadmails . ')</b>';
            // Define default path of icon for course
            $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/openicon.gif" height="16" width="16" alt="' . $strcourse . '" />';
        } else {
            // Define default path of icon for course
            $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/icon.gif" height="16" width="16" alt="' . $strcourse . '" />';
        }
        $linkcss = $mycourse->visible ? '' : ' class="dimmed" ';
        $coursename = $CFG->email_display_course_fullname ? $mycourse->fullname : $mycourse->shortname;
        // If I'm student
        if (has_capability('moodle/course:viewhiddencourses', $context)) {
            // Thanks Tim
            // If course visible
            if ($mycourse->visible) {
                $list[] = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '" ' . $linkcss . '>' . $coursename . ' ' . $unreadmails . '</a>';
                $icons[] = $icon;
            }
        } else {
            $list[] = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '" ' . $linkcss . '>' . $coursename . ' ' . $unreadmails . '</a>';
            $icons[] = $icon;
        }
    }
    // Print block of my courses
    print_side_block($startdivtitle . $strcourses . $enddivtitle, '', $list, $icons);
}