function get_content() { global $USER, $CFG, $COURSE; // It need update? if (email_must_update($this->version)) { $this->content = get_string('mustupdate', 'block_email_list'); } // Get course id if (!empty($COURSE)) { $this->courseid = $COURSE->id; } // If block have content, skip. if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); if ($CFG->email_enable_ssl) { $wwwroot = str_replace('http:', 'https:', $CFG->wwwroot); } else { $wwwroot = $CFG->wwwroot; } // Get context $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id); $emailicon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/sobre.png" height="11" width="15" alt="' . get_string("course") . '" />'; $composeicon = '<img src="' . $CFG->pixpath . '/i/edit.gif" alt="" />'; // Only show all course in principal course, others, show it if ($this->instance->pageid == 1) { //Get the courses of the user $mycourses = get_my_courses($USER->id); $this->content->footer = '<br />' . $emailicon . print_spacer(1, 4, false, true) . '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/">' . get_string('view_all', 'block_email_list') . '</a>'; } else { if (!empty($CFG->mymoodleredirect) and $COURSE->id == 1) { //Get the courses of the user $mycourses = get_my_courses($USER->id); $this->content->footer = '<br />' . $emailicon . print_spacer(1, 4, false, true) . '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/">' . get_string('view_all', 'block_email_list') . '</a>'; } else { // Get this course $course = get_record('course', 'id', $this->instance->pageid); $mycourses[] = $course; $this->content->footer = '<br />' . $emailicon . print_spacer(1, 4, false, true) . '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id . '">' . get_string('view_inbox', 'block_email_list') . '</a>'; $this->content->footer .= '<br />' . $composeicon . print_spacer(1, 4, false, true) . '<a href="' . $wwwroot . '/blocks/email_list/email/sendmail.php?course=' . $course->id . '&folderid=0&filterid=0&folderoldid=0&action=newmail">' . get_string('compose', 'block_email_list') . '</a>'; } } // Count my courses $countmycourses = count($mycourses); //Configure item and icon for this account $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/openicon.gif" height="16" width="16" alt="' . get_string("course") . '" />'; $number = 0; foreach ($mycourses as $mycourse) { ++$number; // increment for first course if ($number > $CFG->email_max_number_courses && !empty($CFG->email_max_number_courses)) { continue; } //Get the number of unread mails $numberunreadmails = email_count_unreaded_mails($USER->id, $mycourse->id); // Only show if has unreaded mails if ($numberunreadmails > 0) { $unreadmails = '<b>(' . $numberunreadmails . ')</b>'; $this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '">' . $mycourse->fullname . ' ' . $unreadmails . '</a>'; $this->content->icons[] = $icon; } } if (count($this->content->items) == 0) { $this->content->items[] = '<div align="center">' . get_string('emptymailbox', 'block_email_list') . '</div>'; } return $this->content; }
/** * 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); }
/** * 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); }
function get_content() { global $USER, $CFG, $COURSE, $DB, $OUTPUT; // Get course id if (!empty($COURSE)) { $this->courseid = $COURSE->id; } // If block have content, skip. if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); // Security. $wwwroot = email_httpsrequired(); $emailicon = '<img src="' . $wwwroot . '/blocks/email_list/email/images/sobre.png" height="11" width="15" alt="' . get_string("course") . '" />'; $pixpath = "{$CFG->wwwroot}/pix"; $composeicon = '<img src="' . $pixpath . '/i/edit.gif" alt="" />'; $spacer = array('height' => 1, 'width' => 4); // Only show all course in principal course, others, show it if ($this->page->course->id == SITEID) { //Get the courses of the user $mycourses = enrol_get_my_courses(); $this->content->footer = '<br />' . $emailicon . $OUTPUT->spacer($spacer) . '<a href="' . $wwwroot . '/blocks/email_list/email/">' . get_string('view_all', 'block_email_list') . '</a>'; } else { if (!empty($CFG->mymoodleredirect) and $COURSE->id == 1) { //Get the courses of the user $mycourses = get_my_courses($USER->id); $this->content->footer = '<br />' . $emailicon . $OUTPUT->spacer($spacer) . '<a href="' . $wwwroot . '/blocks/email_list/email/">' . get_string('view_all', 'block_email_list') . '</a>'; } else { // Get this course $course = $DB->get_record('course', array('id' => $this->page->course->id)); $mycourses[] = $course; $this->content->footer = '<br />' . $emailicon . $OUTPUT->spacer($spacer) . '<a href="' . $wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id . '">' . get_string('view_inbox', 'block_email_list') . '</a>'; $this->content->footer .= '<br />' . $composeicon . $OUTPUT->spacer($spacer) . '<a href="' . $wwwroot . '/blocks/email_list/email/sendmail.php?course=' . $course->id . '&folderid=0&filterid=0&folderoldid=0&action=newmail">' . get_string('compose', 'block_email_list') . '</a>'; } } // Count my courses $countmycourses = count($mycourses); //Configure item and icon for this account $icon = '<img src="' . $wwwroot . '/blocks/email_list/email/images/openicon.gif" height="16" width="16" alt="' . get_string("course") . '" />'; $number = 0; foreach ($mycourses as $mycourse) { ++$number; // increment for first course if ($number > $CFG->email_max_number_courses && !empty($CFG->email_max_number_courses)) { continue; } //Get the number of unread mails $numberunreadmails = email_count_unreaded_mails($USER->id, $mycourse->id); $coursename = $CFG->email_display_course_fullname ? $mycourse->fullname : $mycourse->shortname; // Only show if has unreaded mails if ($numberunreadmails > 0) { $unreadmails = '<b>(' . $numberunreadmails . ')</b>'; $this->content->items[] = '<a href="' . $wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '">' . $coursename . ' ' . $unreadmails . '</a>'; $this->content->icons[] = $icon; } } if (count($this->content->items) == 0) { $this->content->items[] = '<div align="center">' . get_string('emptymailbox', 'block_email_list') . '</div>'; } return $this->content; }