Beispiel #1
0
/**
 * Gets the name for the provided section.
 *
 * @param stdClass $course
 * @param stdClass $section
 * @return string
 */
function callback_weeks_get_section_name($course, $section)
{
    // We can't add a node without text
    if (!empty($section->name)) {
        // Return the name the user set
        return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
    } else {
        if ($section->section == 0) {
            // Return the section0name
            return get_string('section0name', 'format_weeks');
        } else {
            // Got to work out the date of the week so that we can show it
            $sections = get_all_sections($course->id);
            $weekdate = $course->startdate + 7200;
            foreach ($sections as $sec) {
                if ($sec->id == $section->id) {
                    break;
                } else {
                    if ($sec->section != 0) {
                        $weekdate += 604800;
                    }
                }
            }
            $strftimedateshort = ' ' . get_string('strftimedateshort');
            $weekday = userdate($weekdate, $strftimedateshort);
            $endweekday = userdate($weekdate + 518400, $strftimedateshort);
            return $weekday . ' - ' . $endweekday;
        }
    }
}
Beispiel #2
0
function all_sections_data()
{
    $sections = array();
    $all_sections = get_all_sections();
    while ($row = mysql_fetch_assoc($all_sections)) {
        $sections[$row['id']] = $row['crn'];
    }
    return $sections;
}
Beispiel #3
0
function list_sections()
{
    $sections = get_all_sections();
    $names = array();
    while ($row = mysql_fetch_assoc($sections)) {
        $names[] = $row['crn'];
    }
    dom::h3('section-title', 'List Sections:');
    dom::push_div('section');
    dom::ul($names);
    dom::pop();
}
function FN_update_course($form, $oldformat = false)
{
    global $CFG;
    /// Updates course specific variables.
    /// Variables are: 'showsection0', 'showannouncements'.
    $config_vars = array('showsection0', 'showannouncements', 'sec0title', 'showhelpdoc', 'showclassforum', 'showclasschat', 'logo', 'mycourseblockdisplay', 'showgallery', 'gallerydefault', 'usesitegroups', 'mainheading', 'topicheading', 'activitytracking', 'ttmarking', 'ttgradebook', 'ttdocuments', 'ttstaff', 'defreadconfirmmess', 'usemandatory', 'expforumsec');
    foreach ($config_vars as $config_var) {
        if ($varrec = get_record('course_config_FN', 'courseid', $form->id, 'variable', $config_var)) {
            $varrec->value = $form->{$config_var};
            update_record('course_config_FN', $varrec);
        } else {
            $varrec->courseid = $form->id;
            $varrec->variable = $config_var;
            $varrec->value = $form->{$config_var};
            insert_record('course_config_FN', $varrec);
        }
    }
    /// We need to have the sections created ahead of time for the weekly nav to work,
    /// so check and create here.
    if (!($sections = get_all_sections($form->id))) {
        $sections = array();
    }
    for ($i = 0; $i <= $form->numsections; $i++) {
        if (empty($sections[$i])) {
            $section = new Object();
            $section->course = $form->id;
            // Create a new section structure
            $section->section = $i;
            $section->summary = "";
            $section->visible = 1;
            if (!($section->id = insert_record("course_sections", $section))) {
                notify("Error inserting new section!");
            }
        }
    }
    /// Check for a change to an FN format. If so, set some defaults as well...
    if ($oldformat != 'FN') {
        /// Set the news (announcements) forum to no force subscribe, and no posts or discussions.
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        $news = forum_get_course_forum($form->id, 'news');
        $news->open = 0;
        $news->forcesubscribe = 0;
        update_record('forum', $news);
    }
    rebuild_course_cache($form->id);
}
function FN_update_course($form, $oldformat = false, $resubmission = false)
{
    global $CFG, $DB, $OUTPUT;
    $config_vars = array('showsection0', 'sec0title', 'mainheading', 'topicheading', 'maxtabs');
    foreach ($config_vars as $config_var) {
        if ($varrec = $DB->get_record('course_config_fn', array('courseid' => $form->id, 'variable' => $config_var))) {
            $varrec->value = $form->{$config_var};
            $DB->update_record('course_config_fn', $varrec);
        } else {
            $varrec->courseid = $form->id;
            $varrec->variable = $config_var;
            $varrec->value = $form->{$config_var};
            $DB->insert_record('course_config_fn', $varrec);
        }
    }
    /// We need to have the sections created ahead of time for the weekly nav to work,
    /// so check and create here.
    if (!($sections = get_all_sections($form->id))) {
        $sections = array();
    }
    for ($i = 0; $i <= $form->numsections; $i++) {
        if (empty($sections[$i])) {
            $section = new Object();
            $section->course = $form->id;
            // Create a new section structure
            $section->section = $i;
            $section->summary = "";
            $section->visible = 1;
            if (!($section->id = $DB->insert_record("course_sections", $section))) {
                $OUTPUT->notification("Error inserting new section!");
            }
        }
    }
    /// Check for a change to an FN format. If so, set some defaults as well...
    if ($oldformat != 'FN') {
        /// Set the news (announcements) forum to no force subscribe, and no posts or discussions.
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        $news = forum_get_course_forum($form->id, 'news');
        $news->open = 0;
        $news->forcesubscribe = 0;
        $DB->update_record('forum', $news);
    }
    rebuild_course_cache($form->id);
}
/**
 * Moodleから呼び出されるバックアップモジュール
 * 
 * @param stream $bf
 * @param object $preferences
 * @return bool
 */
function project_backup_format_data($bf, $preferences)
{
    $status = true;
    // コースセクション一覧を読み込む
    // $preferences->sectionが設定されている場合は1つのタイトルのみ
    if ($sections = get_all_sections($preferences->backup_course)) {
        fwrite($bf, start_tag("SECTIONTITLES", 3, true));
        foreach ($sections as $section) {
            if ((empty($preferences->backup_section) || $preferences->backup_section == $section->section) && $section->id > 0 && ($sectiontitle = get_record('course_project_title', 'sectionid', $section->id))) {
                fwrite($bf, start_tag("SECTIONTITLE", 4, true));
                fwrite($bf, full_tag("ID", 5, false, $sectiontitle->id));
                fwrite($bf, full_tag("SECTIONID", 5, false, $sectiontitle->sectionid));
                fwrite($bf, full_tag("DIRECTORYNAME", 5, false, $sectiontitle->directoryname));
                fwrite($bf, end_tag("SECTIONTITLE", 4, true));
            } else {
                continue;
            }
        }
        $status = fwrite($bf, end_tag("SECTIONTITLES", 3, true));
    } else {
        $status = false;
    }
    return $status;
}
function getmoddata($courseid, $requestid)
{
    global $DB;
    //fetch info and ids about the modules in this course
    $course = $DB->get_record('course', array('id' => $courseid));
    $modinfo =& get_fast_modinfo($course);
    get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
    $sections = get_all_sections($courseid);
    /* Displays the type of mod name - assignment/ quiz etc 
       foreach($modnames as $modname) {
       array_push($return['messages'],$modname);
       }
       */
    $sectionarray = array();
    foreach ($sections as $section) {
        //$sectionarray[$section->id] = get_section_name($course,$section);
        //here we will store all the mods for the section
        $sectionarray[$section->section] = array();
    }
    //for each mod add its name and id to an array for its section
    foreach ($mods as $mod) {
        //$modname = htmlspecialchars($modinfo->cms[$mod->id]->name, ENT_QUOTES);
        $modname = htmlspecialchars($mod->name, ENT_QUOTES);
        $modtype = $mod->modfullname;
        $sectionid = $modinfo->cms[$mod->id]->sectionnum;
        array_push($sectionarray[$sectionid], "<module sectionid='" . $sectionid . "' modid='" . $mod->id . "' modname='" . $modname . "'  modtype='" . $modtype . "'  />");
    }
    //init xml output
    $xml_output = "<course courseid='" . $courseid . "'>";
    //go through each section adding a sect header and all the modules in it
    foreach ($sections as $section) {
        //$sectionarray[$section->id] = get_section_name($course,$section);
        //here we will store all the mods for the section
        $sectionname = htmlspecialchars(get_section_name($course, $section), ENT_QUOTES);
        $xml_output .= "<section sectionid='" . $section->section . "' sectionname='" . $sectionname . "'>";
        foreach ($sectionarray[$section->section] as $line) {
            $xml_output .= "\t" . $line;
        }
        $xml_output .= "</section>";
    }
    //close off xml output
    $xml_output .= "</course>";
    //"section", "section, id, course, name, summary, summaryformat, sequence, visible");
    //Return the data
    //$xml_output = prepareXMLReturn($return,$requestid);
    return $xml_output;
}
 function fetchcourseitems($courseid)
 {
     global $CFG, $DB;
     $xml_output = "";
     if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
         print_error('invalidcourseid');
     }
     require_course_login($course);
     //$modinfo =& get_fast_modinfo($course);
     $modinfo = get_fast_modinfo($course);
     get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
     if (!($sections = get_all_sections($courseid))) {
         $xml_output .= 'Error finding or creating section structures for this course';
     }
     //loop through the sections
     foreach ($sections as $thissection) {
         //display a section seperator for each secton
         if (!$thissection->visible) {
             $xml_output .= "\t<item label='---------(hidden)" . "' url='' />\n";
             continue;
         } else {
             $xml_output .= "\t<item label='-----------------" . "' url='' />\n";
         }
         //loop through all the mods for each section
         $sectionmods = explode(",", $thissection->sequence);
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             $mod = $mods[$modnumber];
             if (isset($modinfo->cms[$modnumber])) {
                 if (!$modinfo->cms[$modnumber]->uservisible) {
                     // visibility shortcut
                     continue;
                 }
                 //here we get the name of the mod. We need to encode it
                 //because the xml breaks otherwise when there arequotes etc.
                 $instancename = htmlspecialchars($modinfo->cms[$modnumber]->name, ENT_QUOTES);
             } else {
                 if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                     // module not installed
                     continue;
                 }
                 if (!coursemodule_visible_for_user($mod)) {
                     // full visibility check
                     continue;
                 }
                 //we have a mod, but for some reasonwe could not establish its name.
                 $instancename = "mod with no name";
             }
             //end of if isset
             //this works for now, but ultimately we will need to ad the "extra" paramaters from $modinfo
             $xml_output .= "\t<item label='" . $instancename . "' url='" . urlencode($CFG->wwwroot . "/mod/" . $mod->modname . "/view.php?id=" . $modnumber) . "' />\n";
         }
         //end of for each mod
     }
     //end of for each section
     return $xml_output;
 }
Beispiel #9
0
 $new_course["student"] = $course->student;
 $new_course["students"] = $course->students;
 $new_course["enrollmentkey"] = !empty($course->password);
 $new_course["numsections"] = $course->numsections;
 $new_course["marker"] = $course->marker;
 $new_course["allows_guests_without_key"] = $course->guest == 1;
 $new_course["allows_guests_with_key"] = $course->guest == 2;
 if ($CFG->rolesactive) {
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     $new_course["can_edit"] = has_capability('moodle/course:manageactivities', $context);
 } else {
     if ($course->id != 1) {
         $new_course["can_edit"] = isteacher($course->id, $USER->id, true);
     }
 }
 $course_sections = get_all_sections($course->id, 'fullname ASC', 0, 1);
 $sections_array = array();
 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
 foreach ($course_sections as $section) {
     $show_hidden_sections = FALSE;
     if ($CFG->rolesactive) {
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         $show_hidden_sections = has_capability('moodle/course:viewhiddensections', $context);
     } else {
         $show_hidden_sections = isteacher($course->id, $USER->id, true);
     }
     $showsection = ($section->visible or $show_hidden_sections);
     $new_section = array();
     $new_section[" id"] = $section->id;
     $new_section["sequence"] = $section->sequence;
     $new_section["section"] = $section->section;
Beispiel #10
0
 /**
  * Adds branches and links to the settings navigation to add course activities
  * and resources.
  *
  * @param stdClass $course
  */
 protected function add_course_editing_links($course)
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     // Add `add` resources|activities branches
     $structurefile = $CFG->dirroot . '/course/format/' . $course->format . '/lib.php';
     if (file_exists($structurefile)) {
         require_once $structurefile;
         $requestkey = call_user_func('callback_' . $course->format . '_request_key');
         $formatidentifier = optional_param($requestkey, 0, PARAM_INT);
     } else {
         $requestkey = get_string('section');
         $formatidentifier = optional_param($requestkey, 0, PARAM_INT);
     }
     $sections = get_all_sections($course->id);
     $addresource = $this->add(get_string('addresource'));
     $addactivity = $this->add(get_string('addactivity'));
     if ($formatidentifier !== 0) {
         $addresource->force_open();
         $addactivity->force_open();
     }
     $this->get_course_modules($course);
     $textlib = textlib_get_instance();
     foreach ($sections as $section) {
         if ($formatidentifier !== 0 && $section->section != $formatidentifier) {
             continue;
         }
         $sectionurl = new moodle_url('/course/view.php', array('id' => $course->id, $requestkey => $section->section));
         if ($section->section == 0) {
             $sectionresources = $addresource->add(get_string('course'), $sectionurl, self::TYPE_SETTING);
             $sectionactivities = $addactivity->add(get_string('course'), $sectionurl, self::TYPE_SETTING);
         } else {
             $sectionname = get_section_name($course, $section);
             $sectionresources = $addresource->add($sectionname, $sectionurl, self::TYPE_SETTING);
             $sectionactivities = $addactivity->add($sectionname, $sectionurl, self::TYPE_SETTING);
         }
         foreach ($resources as $value => $resource) {
             $url = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey(), 'section' => $section->section));
             $pos = strpos($value, '&type=');
             if ($pos !== false) {
                 $url->param('add', $textlib->substr($value, 0, $pos));
                 $url->param('type', $textlib->substr($value, $pos + 6));
             } else {
                 $url->param('add', $value);
             }
             $sectionresources->add($resource, $url, self::TYPE_SETTING);
         }
         $subbranch = false;
         foreach ($activities as $activityname => $activity) {
             if ($activity === '--') {
                 $subbranch = false;
                 continue;
             }
             if (strpos($activity, '--') === 0) {
                 $subbranch = $sectionactivities->add(trim($activity, '-'));
                 continue;
             }
             $url = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey(), 'section' => $section->section));
             $pos = strpos($activityname, '&type=');
             if ($pos !== false) {
                 $url->param('add', $textlib->substr($activityname, 0, $pos));
                 $url->param('type', $textlib->substr($activityname, $pos + 6));
             } else {
                 $url->param('add', $activityname);
             }
             if ($subbranch !== false) {
                 $subbranch->add($activity, $url, self::TYPE_SETTING);
             } else {
                 $sectionactivities->add($activity, $url, self::TYPE_SETTING);
             }
         }
     }
 }
Beispiel #11
0
function certificate_get_mod_grades()
{
    global $course, $CFG;
    $strgrade = get_string('grade', 'certificate');
    /// Collect modules data
    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
    $printgrade = array();
    $sections = get_all_sections($course->id);
    // Sort everything the same as the course
    for ($i = 0; $i <= $course->numsections; $i++) {
        // should always be true
        if (isset($sections[$i])) {
            $section = $sections[$i];
            if ($section->sequence) {
                switch ($course->format) {
                    case 'topics':
                        $sectionlabel = get_string('topic');
                        break;
                    case 'weeks':
                        $sectionlabel = get_string('week');
                        break;
                    default:
                        $sectionlabel = get_string('section');
                }
                $sectionmods = explode(",", $section->sequence);
                foreach ($sectionmods as $sectionmod) {
                    if (empty($mods[$sectionmod])) {
                        continue;
                    }
                    $mod = $mods[$sectionmod];
                    $mod->courseid = $course->id;
                    $instance = get_record($mod->modname, 'id', $mod->instance);
                    if ($grade_items = grade_get_grade_items_for_activity($mod)) {
                        $mod_item = grade_get_grades($course->id, 'mod', $mod->modname, $mod->instance);
                        $item = reset($mod_item->items);
                        if (isset($item->grademax)) {
                            $printgrade[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name . ' ' . $strgrade;
                        }
                    }
                }
            }
        }
    }
    if (isset($printgrade)) {
        $gradeoptions['0'] = get_string('no');
        $gradeoptions['1'] = get_string('coursegrade', 'certificate');
        foreach ($printgrade as $key => $value) {
            $gradeoptions[$key] = $value;
        }
    } else {
        $gradeoptions['0'] = get_string('nogrades', 'certificate');
    }
    return $gradeoptions;
}
Beispiel #12
0
// this will add a new class to the header so we can style differently
$PAGE->print_header(get_string('course') . ': %fullname%', NULL, '', $bodytags);
// Course wrapper start.
echo '<div class="course-content">';
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
if (!($sections = get_all_sections($course->id))) {
    // No sections found
    // Double-check to be extra sure
    if (!($section = get_record('course_sections', 'course', $course->id, 'section', 0))) {
        $section->course = $course->id;
        // Create a default section.
        $section->section = 0;
        $section->visible = 1;
        $section->id = insert_record('course_sections', $section);
    }
    if (!($sections = get_all_sections($course->id))) {
        // Try again
        error('Error finding or creating section structures for this course');
    }
}
if (empty($course->modinfo)) {
    // Course cache was never made.
    rebuild_course_cache($course->id);
    if (!($course = get_record('course', 'id', $course->id))) {
        error("That's an invalid course id");
    }
}
// Include the actual course format.
require $CFG->dirroot . '/course/format/' . $course->format . '/format.php';
// Content wrapper end.
echo "</div>\n\n";
Beispiel #13
0
 /**
  * Get course contents
  *
  * @param int $courseid course id
  * @param array $options These options are not used yet, might be used in later version
  * @return array
  * @since Moodle 2.2
  */
 public static function get_course_contents($courseid, $options = array())
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/course/lib.php";
     //validate parameter
     $params = self::validate_parameters(self::get_course_contents_parameters(), array('courseid' => $courseid, 'options' => $options));
     //retrieve the course
     $course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST);
     //check course format exist
     if (!file_exists($CFG->dirroot . '/course/format/' . $course->format . '/lib.php')) {
         throw new moodle_exception('cannotgetcoursecontents', 'webservice', '', null, get_string('courseformatnotfound', 'error', '', $course->format));
     } else {
         require_once $CFG->dirroot . '/course/format/' . $course->format . '/lib.php';
     }
     // now security checks
     $context = context_course::instance($course->id, IGNORE_MISSING);
     try {
         self::validate_context($context);
     } catch (Exception $e) {
         $exceptionparam = new stdClass();
         $exceptionparam->message = $e->getMessage();
         $exceptionparam->courseid = $course->id;
         throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
     }
     $canupdatecourse = has_capability('moodle/course:update', $context);
     //create return value
     $coursecontents = array();
     if ($canupdatecourse or $course->visible or has_capability('moodle/course:viewhiddencourses', $context)) {
         //retrieve sections
         $modinfo = get_fast_modinfo($course);
         $sections = get_all_sections($course->id);
         //for each sections (first displayed to last displayed)
         foreach ($sections as $key => $section) {
             $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $section->visible or !$course->hiddensections);
             if (!$showsection) {
                 continue;
             }
             // reset $sectioncontents
             $sectionvalues = array();
             $sectionvalues['id'] = $section->id;
             $sectionvalues['name'] = get_section_name($course, $section);
             $sectionvalues['visible'] = $section->visible;
             list($sectionvalues['summary'], $sectionvalues['summaryformat']) = external_format_text($section->summary, $section->summaryformat, $context->id, 'course', 'section', $section->id);
             $sectioncontents = array();
             //for each module of the section
             foreach ($modinfo->sections[$section->section] as $cmid) {
                 //matching /course/lib.php:print_section() logic
                 $cm = $modinfo->cms[$cmid];
                 // stop here if the module is not visible to the user
                 if (!$cm->uservisible) {
                     continue;
                 }
                 $module = array();
                 //common info (for people being able to see the module or availability dates)
                 $module['id'] = $cm->id;
                 $module['name'] = format_string($cm->name, true);
                 $module['modname'] = $cm->modname;
                 $module['modplural'] = $cm->modplural;
                 $module['modicon'] = $cm->get_icon_url()->out(false);
                 $module['indent'] = $cm->indent;
                 $modcontext = context_module::instance($cm->id);
                 if (!empty($cm->showdescription)) {
                     $module['description'] = $cm->get_content();
                 }
                 //url of the module
                 $url = $cm->get_url();
                 if ($url) {
                     //labels don't have url
                     $module['url'] = $cm->get_url()->out();
                 }
                 $canviewhidden = has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id));
                 //user that can view hidden module should know about the visibility
                 $module['visible'] = $cm->visible;
                 //availability date (also send to user who can see hidden module when the showavailabilyt is ON)
                 if ($canupdatecourse or $CFG->enableavailability && $canviewhidden && $cm->showavailability) {
                     $module['availablefrom'] = $cm->availablefrom;
                     $module['availableuntil'] = $cm->availableuntil;
                 }
                 $baseurl = 'webservice/pluginfile.php';
                 //call $modulename_export_contents
                 //(each module callback take care about checking the capabilities)
                 require_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php';
                 $getcontentfunction = $cm->modname . '_export_contents';
                 if (function_exists($getcontentfunction)) {
                     if ($contents = $getcontentfunction($cm, $baseurl)) {
                         $module['contents'] = $contents;
                     }
                 }
                 //assign result to $sectioncontents
                 $sectioncontents[] = $module;
             }
             $sectionvalues['modules'] = $sectioncontents;
             // assign result to $coursecontents
             $coursecontents[] = $sectionvalues;
         }
     }
     return $coursecontents;
 }
 /**
  * Print out the course page. Use the course 'format.php' file. This may make sense to replace with a
  * function at some point, but for now, many things trigger on its existence.
  *
  */
 function print_body()
 {
     /// These globals are needed for the included 'format.php' file.
     global $CFG, $USER, $SESSION, $COURSE, $THEME, $course;
     global $mods, $modnames, $modnamesplural, $modnamesused, $sections;
     /// These are needed in various library functions.
     global $PAGE, $pageblocks, $section, $marker;
     /// These are needed in various library functions.
     global $preferred_width_left, $preferred_width_right;
     /// These may be used in blocks.
     // Course wrapper start.
     echo '<div class="course-content">';
     get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
     if (!($sections = get_all_sections($course->id))) {
         // No sections found
         // Double-check to be extra sure
         if (!($section = get_record('course_sections', 'course', $course->id, 'section', 0))) {
             $section->course = $course->id;
             // Create a default section.
             $section->section = 0;
             $section->visible = 1;
             $section->id = insert_record('course_sections', $section);
         }
         if (!($sections = get_all_sections($course->id))) {
             // Try again
             error('Error finding or creating section structures for this course');
         }
     }
     if (empty($course->modinfo)) {
         // Course cache was never made.
         rebuild_course_cache($course->id);
         if (!($course = get_record('course', 'id', $course->id))) {
             error("That's an invalid course id");
         }
     }
     // Include the actual course format.
     require $CFG->dirroot . '/course/format/' . $course->format . '/format.php';
     // Content wrapper end.
     echo "</div>\n\n";
 }
function get_course_grade($id)
{
    global $course, $CFG, $USER;
    $course = get_record("course", "id", $id);
    $strgrades = get_string("grades");
    $strgrade = get_string("grade");
    $strmax = get_string("maximumshort");
    $stractivityreport = get_string("activityreport");
    /// Get a list of all students
    $columnhtml = array();
    // Accumulate column html in this array.
    $grades = array();
    // Collect all grades in this array
    $maxgrades = array();
    // Collect all max grades in this array
    $totalgrade = 0;
    $totalmaxgrade = 1.0E-6;
    /// Collect modules data
    $test = get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
    /// Search through all the modules, pulling out grade data
    $sections = get_all_sections($course->id);
    // Sort everything the same as the course
    for ($i = 0; $i <= $course->numsections; $i++) {
        if (isset($sections[$i])) {
            // should always be true
            $section = $sections[$i];
            if (!empty($section->sequence)) {
                $sectionmods = explode(",", $section->sequence);
                foreach ($sectionmods as $sectionmod) {
                    $mod = $mods[$sectionmod];
                    if ($mod->visible) {
                        $instance = get_record("{$mod->modname}", "id", "{$mod->instance}");
                        $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php";
                        if (file_exists($libfile)) {
                            require_once $libfile;
                            $gradefunction = $mod->modname . "_grades";
                            if (function_exists($gradefunction)) {
                                // Skip modules without grade function
                                if ($modgrades = $gradefunction($mod->instance)) {
                                    if (empty($modgrades->grades[$USER->id])) {
                                        $grades[] = "";
                                    } else {
                                        $grades[] = $modgrades->grades[$USER->id];
                                        $totalgrade += (double) $modgrades->grades[$USER->id];
                                    }
                                    if (empty($modgrades->maxgrade) || empty($modgrades)) {
                                        $maxgrades[] = "";
                                    } else {
                                        $maxgrades[] = $modgrades->maxgrade;
                                        $totalmaxgrade += $modgrades->maxgrade;
                                    }
                                }
                            }
                            $gradefunction = $mod->modname . "_get_user_grades";
                            if (function_exists($gradefunction)) {
                                // Skip modules without grade function
                                if ($modgrades = $gradefunction($mod->instance)) {
                                    /*                                    if (empty($modgrades->grades[$USER->id])) {
                                                                            $grades[]  = "";
                                                                        } else {
                                                                            $grades[]  = $modgrades->grades[$USER->id];
                                                                            $totalgrade += (float)$modgrades->grades[$USER->id];
                                                                        }
                                                                        if (empty($modgrades->maxgrade) || empty($modgrades)) {
                                                                            $maxgrades[] = "";
                                                                        } else {
                                                                            $maxgrades[]    = $modgrades->maxgrade;
                                                                            $totalmaxgrade += $modgrades->maxgrade;
                                                                        }*/
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $coursegrade->percentage = round($totalgrade * 100 / $totalmaxgrade, 2);
    $coursegrade->points = $totalgrade;
    return $coursegrade;
}
 function sections($config)
 {
     global $COURSE, $CFG, $USER, $THEME;
     // probably inefficient, but it works
     get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused);
     // sections
     $sections = get_all_sections($COURSE->id);
     // name for sections
     $sectionname = get_string("name{$COURSE->format}", "format_{$COURSE->format}");
     // TODO: this fallback should be unnecessary
     if ($sectionname == "[[name{$COURSE->format}]]") {
         $sectionname = get_string("name{$COURSE->format}");
     }
     $return = array();
     // check what the course format is like
     // highlight for current week or highlighted topic
     if (in_array($COURSE->format, array('weeks', 'weekscss'))) {
         $format = 'week';
         $highlight = ceil((time() - $COURSE->startdate) / 604800);
     } else {
         $format = 'topic';
         $highlight = $COURSE->marker;
     }
     $modinfo = unserialize($COURSE->modinfo);
     // I think $display is the section currently being displayed
     // Why are we calling course_set_display?
     // For Moodle 2.0 we should just use $PAGE and check type
     // and also $PAGE->activityrecord
     $path = str_replace($CFG->httpswwwroot . '/', '', $CFG->pagepath);
     if (substr($path, 0, 7) == 'course/') {
         //TODO: this code is hackish, we shouldn't use course_set_display
         # get current section being displayed
         $week = optional_param('week', -1, PARAM_INT);
         if ($week != -1) {
             // the course format should already be doing this
             $display = course_set_display($COURSE->id, $week);
         } else {
             if (isset($USER->display[$COURSE->id])) {
                 $display = $USER->display[$COURSE->id];
             } else {
                 $display = course_set_display($COURSE->id, 0);
             }
         }
     } elseif (substr($path, 0, 4) == 'mod/') {
         // Moodle 2: use $PAGE->activityrecord->section;
         $id = optional_param('id', -1, PARAM_INT);
         if ($id == -1) {
             $display = 0;
         } else {
             $sql = "select section from {$CFG->prefix}course_sections where id=(select section from {$CFG->prefix}course_modules where id={$id})";
             $row = get_record_sql($sql);
             $display = $row->section;
         }
     } else {
         $display = 0;
     }
     foreach ($sections as $section) {
         // don't show the flowing sections
         if (!($section->visible && $section->section && $section->section <= $COURSE->numsections)) {
             continue;
         }
         $text = trim($section->summary);
         if (empty($text)) {
             $text = ucwords($sectionname) . " " . $section->section;
         } else {
             $text = $this->truncate_html(filter_text($text, $COURSE->id), $config);
         }
         // expand section if it's the one currently displayed
         $expand = false;
         if ($section->section == $display) {
             $expand = true;
         }
         $sectionstyle = 'yui_menu_icon_section';
         // highlight marked section
         if ($section->section == $highlight) {
             $sectionstyle .= ' highlight';
         }
         $iconpath = $CFG->wwwroot;
         if ($THEME->custompix) {
             $iconpath .= "/theme/" . current_theme() . "/pix";
         } else {
             $iconpath .= '/pix';
             //$iconpath .= '/';
         }
         $iconpath = $CFG->wwwroot . "/theme/" . current_theme() . "/pix";
         // decide what URL we want to use
         // A lot of this should really be done by the course format
         //
         // = intoaction config values =
         // * 'introhide' link to the section page (this effectively
         //   hides the other sections
         // * 'introscroll' link to the fragment id of the section on
         //   on the current page
         // whether or not any of the sections are hidden
         $hidden = false;
         foreach (array('topic', 'week') as $param) {
             if (isset($_GET[$param]) && $_GET[$param] != 'all') {
                 $hidden = true;
             }
         }
         $introaction = isset($config->introaction) ? $config->introaction : 'introhide';
         if ($introaction == 'introhide' || $hidden) {
             // link to the section, this will effectively hide all
             // the other sections
             $url = "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}" . "&{$format}={$section->section}";
         } else {
             // this pretty much just a hack
             // use $PAGE in Moodle 2 for great justice
             if (strpos($_SERVER['REQUEST_URI'], 'course/view.php') != 0) {
                 $url = "#section-{$section->section}";
             } else {
                 $url = false;
             }
         }
         if ($url === false) {
             $item = new yui_menu_item($this, $text, '');
             //$iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav)
         } else {
             $item = new yui_menu_item_link($this, $text, $url, '');
             // $iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav)
         }
         $item->expand = $expand;
         if (isset($section->sequence)) {
             $sectionmods = explode(",", $section->sequence);
         } else {
             $sectionmods = array();
         }
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             $mod = $mods[$modnumber];
             // don't do anything invisible or labels
             if (!$mod->visible || $mod->modname == 'label') {
                 continue;
             }
             // figure out the text and url
             $text = urldecode($modinfo[$modnumber]->name);
             if (!empty($CFG->filterall)) {
                 $text = filter_text($text, $COURSE->id);
             }
             if (trim($text) == '') {
                 $text = $mod->modfullname;
             }
             $text = $this->truncate_html($text, $config);
             $url = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
             $name = "yui_menu_mod_{$mod->modname}_{$modnumber}";
             // figure out if it is the current page
             $pageurl = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $pageurl = '~https?://' . preg_quote($pageurl, '~') . '~';
             if (preg_match($pageurl, $CFG->wwwroot . $url)) {
                 $style = "yui_menu_mod_{$mod->modname} highlight";
             } else {
                 $style = "yui_menu_mod_{$mod->modname}";
             }
             $icon = "{$iconpath}/mod/{$mod->modname}/icon.gif";
             if ($mod->modname == 'resource') {
                 $info = resource_get_coursemodule_info($mod);
                 if (isset($info) && isset($info->icon)) {
                     $icon = "{$CFG->pixpath}/{$info->icon}";
                 }
             }
             $child = new yui_menu_item_link($this, $text, $url, $icon);
             $child->style = $style;
             $item->children[$modnumber] = $child;
         }
         $return[] = $item;
     }
     return $return;
 }
 function get_content()
 {
     global $USER, $CFG;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = get_record('course', 'id', $this->instance->pageid);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     $isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
     $ismoving = ismoving($this->instance->pageid);
     $sections = get_all_sections($this->instance->pageid);
     if (!empty($sections) && isset($sections[0])) {
         $section = $sections[0];
     }
     if (!empty($section) || $isediting) {
         get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
     }
     $groupbuttons = $course->groupmode;
     $groupbuttonslink = !$course->groupmodeforce;
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     }
     /// Casting $course->modinfo to string prevents one notice when the field is null
     $modinfo = unserialize((string) $course->modinfo);
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/t/move.gif" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . $USER->sesskey . '">' . $strcancel . '</a>)';
     }
     if (!empty($section) && !empty($section->sequence)) {
         $sectionmods = explode(',', $section->sequence);
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             $mod = $mods[$modnumber];
             if ($isediting && !$ismoving) {
                 if ($groupbuttons) {
                     if (!($mod->groupmodelink = $groupbuttonslink)) {
                         $mod->groupmode = $course->groupmode;
                     }
                 } else {
                     $mod->groupmode = false;
                 }
                 $editbuttons = '<div class="buttons">' . make_editing_buttons($mod, true, true) . '</div>';
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 $instancename = urldecode($modinfo[$modnumber]->name);
                 $instancename = format_string($instancename, true, $this->instance->pageid);
                 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                 if (!empty($modinfo[$modnumber]->extra)) {
                     $extra = urldecode($modinfo[$modnumber]->extra);
                 } else {
                     $extra = '';
                 }
                 if (!empty($modinfo[$modnumber]->icon)) {
                     $icon = $CFG->pixpath . '/' . urldecode($modinfo[$modnumber]->icon);
                 } else {
                     $icon = $CFG->modpixpath . '/' . $mod->modname . '/icon.gif';
                 }
                 if ($mod->modname == 'label') {
                     $this->content->items[] = format_text($extra, FORMAT_HTML) . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . $instancename . '</a>' . $editbuttons;
                     //Accessibility: incidental image - should be empty Alt text
                     $this->content->icons[] = '<img src="' . $icon . '" class="icon" alt="" />';
                 }
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     if ($isediting && $modnames) {
         $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
     } else {
         $this->content->footer = '';
     }
     return $this->content;
 }
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     $modinfo = get_fast_modinfo($course);
     /// extra fast view mode
     if (!$isediting) {
         if (!empty($modinfo->sections[0])) {
             $options = array('overflowdiv' => true);
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 list($content, $instancename) = get_print_section_cm_text($cm, $course);
                 if (!($url = $cm->get_url())) {
                     $this->content->items[] = $content;
                     $this->content->icons[] = '';
                 } else {
                     $linkcss = $cm->visible ? '' : ' class="dimmed" ';
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
                     $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>';
                 }
             }
         }
         return $this->content;
     }
     /// slow & hacky editing mode
     $ismoving = ismoving($course->id);
     $sections = get_all_sections($course->id);
     if (!empty($sections) && isset($sections[0])) {
         $section = $sections[0];
     }
     if (!empty($section)) {
         get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
     }
     $groupbuttons = $course->groupmode;
     $groupbuttonslink = !$course->groupmodeforce;
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     }
     /// Casting $course->modinfo to string prevents one notice when the field is null
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '&nbsp;<img align="bottom" src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($section) && !empty($section->sequence)) {
         $sectionmods = explode(',', $section->sequence);
         $options = array('overflowdiv' => true);
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             $mod = $mods[$modnumber];
             if (!$ismoving) {
                 if ($groupbuttons) {
                     if (!($mod->groupmodelink = $groupbuttonslink)) {
                         $mod->groupmode = $course->groupmode;
                     }
                 } else {
                     $mod->groupmode = false;
                 }
                 $editbuttons = '<br />' . make_editing_buttons($mod, true, true);
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 list($content, $instancename) = get_print_section_cm_text($modinfo->cms[$modnumber], $course);
                 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                 if (!($url = $mod->get_url())) {
                     $this->content->items[] = $content . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
                     $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
                 }
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     if ($modnames) {
         $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
     } else {
         $this->content->footer = '';
     }
     return $this->content;
 }
Beispiel #19
0
 function get_course_mods($id, $username = '')
 {
     global $CFG, $DB;
     $username = utf8_decode($username);
     $username = strtolower($username);
     if ($username) {
         $user = get_complete_user_data('username', $username);
     }
     $sections = get_all_sections($id);
     $forum = forum_get_course_forum($id, 'news');
     $news_forum_id = $forum->id;
     get_all_mods($id, $mods, $modnames, $modnamesplural, $modnamesused);
     $context = get_context_instance(CONTEXT_COURSE, $id);
     $e = array();
     foreach ($sections as $section) {
         if (!$section->visible) {
             continue;
         }
         $sectionmods = explode(",", $section->sequence);
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             $mod = $mods[$modnumber];
             $resource['completion_info'] = '';
             if ($username) {
                 $cm = get_coursemodule_from_id(false, $mod->id);
                 if (!coursemodule_visible_for_user($cm, $user->id)) {
                     if (!$mod->showavailability) {
                         // Mod not visible, and no completion info to show
                         continue;
                     }
                     $resource['available'] = 0;
                     $ci = new condition_info($mod);
                     $resource['completion_info'] = $ci->get_full_information();
                 } else {
                     $resource['available'] = 1;
                 }
             } else {
                 $resource['available'] = 1;
             }
             $e[$section->section]['section'] = $section->section;
             $e[$section->section]['name'] = $section->name;
             $e[$section->section]['summary'] = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
             $e[$section->section]['summary'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $e[$section->section]['summary']);
             $resource['id'] = $mod->id;
             $resource['name'] = $mod->name;
             $resource['mod'] = $mod->modname;
             // Format for mod->icon is: f/type-24
             $type = substr($mod->icon, 2);
             $parts = explode('-', $type);
             $type = $parts[0];
             $resource['type'] = $type;
             //In forum, type is unused, so we use it for forum type: news/general
             if ($mod->modname == 'forum') {
                 $cm = get_coursemodule_from_id('forum', $mod->id);
                 if ($cm->instance == $news_forum_id) {
                     $resource['type'] = 'news';
                 }
             }
             $e[$section->section]['mods'][] = $resource;
         }
     }
     return $e;
 }
/**
 * コース内のディレクトリ名の重複をチェックする
 *
 * @param int $courseid
 * @param string $directoryname
 * @param int $section : 上書きするセクション番号(上書きする場合は重複していてもOK)
 * @return bool - TRUE:重複していない, FALSE:重複している
 */
function topicsadv_format_check_directoryname($courseid, $directoryname, $sectionnumber = 0)
{
    // コース内のセクション一覧の取得
    $sections = get_all_sections($courseid);
    // 各ディレクトリ名の検証
    foreach ($sections as $section) {
        if ($sectiontitle = get_record('course_topicsadv_title', 'sectionid', $section->id)) {
            if ($sectiontitle->directoryname == $directoryname && $section->section != $sectionnumber) {
                return false;
            }
        }
    }
    return true;
}
Beispiel #21
0
/**
 * This function is used to generate and display selector form
 *
 * @global stdClass $USER
 * @global stdClass $CFG
 * @global moodle_database $DB
 * @global core_renderer $OUTPUT
 * @global stdClass $SESSION
 * @uses CONTEXT_SYSTEM
 * @uses COURSE_MAX_COURSES_PER_DROPDOWN
 * @uses CONTEXT_COURSE
 * @uses SEPARATEGROUPS
 * @param  stdClass $course course instance
 * @param  int      $selecteduser id of the selected user
 * @param  string   $selecteddate Date selected
 * @param  string   $modname course_module->id
 * @param  string   $modid number or 'site_errors'
 * @param  string   $modaction an action as recorded in the logs
 * @param  int      $selectedgroup Group to display
 * @param  int      $showcourses whether to show courses if we're over our limit.
 * @param  int      $showusers whether to show users if we're over our limit.
 * @param  string   $logformat Format of the logs (downloadascsv, showashtml, downloadasods, downloadasexcel)
 * @return void
 */
function report_log_print_selector_form($course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0, $logformat = 'showashtml')
{
    global $USER, $CFG, $DB, $OUTPUT, $SESSION;
    // first check to see if we can override showcourses and showusers
    $numcourses = $DB->count_records("course");
    if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) {
        $showcourses = 1;
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    /// Setup for group handling.
    if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
        $selectedgroup = -1;
        $showgroups = false;
    } else {
        if ($course->groupmode) {
            $showgroups = true;
        } else {
            $selectedgroup = 0;
            $showgroups = false;
        }
    }
    if ($selectedgroup === -1) {
        if (isset($SESSION->currentgroup[$course->id])) {
            $selectedgroup = $SESSION->currentgroup[$course->id];
        } else {
            $selectedgroup = groups_get_all_groups($course->id, $USER->id);
            if (is_array($selectedgroup)) {
                $selectedgroup = array_shift(array_keys($selectedgroup));
                $SESSION->currentgroup[$course->id] = $selectedgroup;
            } else {
                $selectedgroup = 0;
            }
        }
    }
    // Get all the possible users
    $users = array();
    // Define limitfrom and limitnum for queries below
    // If $showusers is enabled... don't apply limitfrom and limitnum
    $limitfrom = empty($showusers) ? 0 : '';
    $limitnum = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : '';
    $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname ASC', $limitfrom, $limitnum);
    if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) {
        $showusers = 1;
    }
    if ($showusers) {
        if ($courseusers) {
            foreach ($courseusers as $courseuser) {
                $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context));
            }
        }
        $users[$CFG->siteguest] = get_string('guestuser');
    }
    if (has_capability('report/log:view', $sitecontext) && $showcourses) {
        if ($ccc = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) {
            foreach ($ccc as $cc) {
                if ($cc->category) {
                    $courses["{$cc->id}"] = format_string(get_course_display_name_for_list($cc));
                } else {
                    $courses["{$cc->id}"] = format_string($cc->fullname) . ' (Site)';
                }
            }
        }
        asort($courses);
    }
    $activities = array();
    $selectedactivity = "";
    /// Casting $course->modinfo to string prevents one notice when the field is null
    if ($modinfo = unserialize((string) $course->modinfo)) {
        $section = 0;
        $sections = get_all_sections($course->id);
        foreach ($modinfo as $mod) {
            if ($mod->mod == "label") {
                continue;
            }
            if ($mod->section > 0 and $section != $mod->section) {
                $activities["section/{$mod->section}"] = '--- ' . get_section_name($course, $sections[$mod->section]) . ' ---';
            }
            $section = $mod->section;
            $mod->name = strip_tags(format_string($mod->name, true));
            if (textlib::strlen($mod->name) > 55) {
                $mod->name = textlib::substr($mod->name, 0, 50) . "...";
            }
            if (!$mod->visible) {
                $mod->name = "(" . $mod->name . ")";
            }
            $activities["{$mod->cm}"] = $mod->name;
            if ($mod->cm == $modid) {
                $selectedactivity = "{$mod->cm}";
            }
        }
    }
    if (has_capability('report/log:view', $sitecontext) && $course->id == SITEID) {
        $activities["site_errors"] = get_string("siteerrors");
        if ($modid === "site_errors") {
            $selectedactivity = "site_errors";
        }
    }
    $strftimedate = get_string("strftimedate");
    $strftimedaydate = get_string("strftimedaydate");
    asort($users);
    // Prepare the list of action options.
    $actions = array('view' => get_string('view'), 'add' => get_string('add'), 'update' => get_string('update'), 'delete' => get_string('delete'), '-view' => get_string('allchanges'));
    // Get all the possible dates
    // Note that we are keeping track of real (GMT) time and user time
    // User time is only used in displays - all calcs and passing is GMT
    $timenow = time();
    // GMT
    // What day is it now for the user, and when is midnight that day (in GMT).
    $timemidnight = $today = usergetmidnight($timenow);
    // Put today up the top of the list
    $dates = array("{$timemidnight}" => get_string("today") . ", " . userdate($timenow, $strftimedate));
    if (!$course->startdate or $course->startdate > $timenow) {
        $course->startdate = $course->timecreated;
    }
    $numdates = 1;
    while ($timemidnight > $course->startdate and $numdates < 365) {
        $timemidnight = $timemidnight - 86400;
        $timenow = $timenow - 86400;
        $dates["{$timemidnight}"] = userdate($timenow, $strftimedaydate);
        $numdates++;
    }
    if ($selecteddate == "today") {
        $selecteddate = $today;
    }
    echo "<form class=\"logselectform\" action=\"{$CFG->wwwroot}/report/log/index.php\" method=\"get\">\n";
    echo "<div>\n";
    echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n";
    echo "<input type=\"hidden\" name=\"showusers\" value=\"{$showusers}\" />\n";
    echo "<input type=\"hidden\" name=\"showcourses\" value=\"{$showcourses}\" />\n";
    if (has_capability('report/log:view', $sitecontext) && $showcourses) {
        echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
        echo html_writer::select($courses, "id", $course->id, false);
    } else {
        //        echo '<input type="hidden" name="id" value="'.$course->id.'" />';
        $courses = array();
        $courses[$course->id] = get_course_display_name_for_list($course) . ($course->id == SITEID ? ' (' . get_string('site') . ') ' : '');
        echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
        echo html_writer::select($courses, "id", $course->id, false);
        if (has_capability('report/log:view', $sitecontext)) {
            $a = new stdClass();
            $a->url = "{$CFG->wwwroot}/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showcourses=1&showusers={$showusers}";
            print_string('logtoomanycourses', 'moodle', $a);
        }
    }
    if ($showgroups) {
        if ($cgroups = groups_get_all_groups($course->id)) {
            foreach ($cgroups as $cgroup) {
                $groups[$cgroup->id] = $cgroup->name;
            }
        } else {
            $groups = array();
        }
        echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide'));
        echo html_writer::select($groups, "group", $selectedgroup, get_string("allgroups"));
    }
    if ($showusers) {
        echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide'));
        echo html_writer::select($users, "user", $selecteduser, get_string("allparticipants"));
    } else {
        $users = array();
        if (!empty($selecteduser)) {
            $user = $DB->get_record('user', array('id' => $selecteduser));
            $users[$selecteduser] = fullname($user);
        } else {
            $users[0] = get_string('allparticipants');
        }
        echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide'));
        echo html_writer::select($users, "user", $selecteduser, false);
        $a = new stdClass();
        $a->url = "{$CFG->wwwroot}/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showusers=1&showcourses={$showcourses}";
        print_string('logtoomanyusers', 'moodle', $a);
    }
    echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide'));
    echo html_writer::select($dates, "date", $selecteddate, get_string("alldays"));
    echo html_writer::label(get_string('activities'), 'menumodid', false, array('class' => 'accesshide'));
    echo html_writer::select($activities, "modid", $selectedactivity, get_string("allactivities"));
    echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide'));
    echo html_writer::select($actions, 'modaction', $modaction, get_string("allactions"));
    $logformats = array('showashtml' => get_string('displayonpage'), 'downloadascsv' => get_string('downloadtext'), 'downloadasods' => get_string('downloadods'), 'downloadasexcel' => get_string('downloadexcel'));
    echo html_writer::label(get_string('logsformat', 'report_log'), 'menulogformat', false, array('class' => 'accesshide'));
    echo html_writer::select($logformats, 'logformat', $logformat, false);
    echo '<input type="submit" value="' . get_string('gettheselogs') . '" />';
    echo '</div>';
    echo '</form>';
}
Beispiel #22
0
/**
 * Get all the modules
 *
 * @return array
 */
function certificate_get_mods()
{
    global $COURSE, $CFG, $DB;
    $strtopic = get_string("topic");
    $strweek = get_string("week");
    $strsection = get_string("section");
    // Collect modules data
    $modinfo = get_fast_modinfo($COURSE);
    $mods = $modinfo->get_cms();
    $modules = array();
    // Check what version we are running - really we should have separate branch for 2.4, but
    // having a branch called master and one called MOODLE_24_STABLE may be confusing. This
    // module will also be replaced in the future so hack will do. Here we get the course
    // sections and sort the modules as they appear in the course.
    if ($CFG->version >= '2012112900') {
        $sections = $modinfo->get_section_info_all();
    } else {
        $sections = get_all_sections($COURSE->id);
    }
    for ($i = 0; $i <= count($sections) - 1; $i++) {
        // should always be true
        if (isset($sections[$i])) {
            $section = $sections[$i];
            if ($section->sequence) {
                switch ($COURSE->format) {
                    case "topics":
                        $sectionlabel = $strtopic;
                        break;
                    case "weeks":
                        $sectionlabel = $strweek;
                        break;
                    default:
                        $sectionlabel = $strsection;
                }
                $sectionmods = explode(",", $section->sequence);
                foreach ($sectionmods as $sectionmod) {
                    if (empty($mods[$sectionmod])) {
                        continue;
                    }
                    $mod = $mods[$sectionmod];
                    $mod->courseid = $COURSE->id;
                    $instance = $DB->get_record($mod->modname, array('id' => $mod->instance));
                    if ($grade_items = grade_get_grade_items_for_activity($mod)) {
                        $mod_item = grade_get_grades($COURSE->id, 'mod', $mod->modname, $mod->instance);
                        $item = reset($mod_item->items);
                        if (isset($item->grademax)) {
                            $modules[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name;
                        }
                    }
                }
            }
        }
    }
    return $modules;
}
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     require_once $CFG->dirroot . '/course/lib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     } else {
         if ($this->page->course->id == SITEID) {
             // return $this->content = '';
         }
     }
     if (!empty($this->page->id)) {
         $context = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
     }
     if (empty($context)) {
         $context = get_context_instance(CONTEXT_SYSTEM);
     }
     if (!($course = $DB->get_record('course', array('id' => $this->page->course->id)))) {
         $course = $SITE;
     }
     if (!has_capability('moodle/course:view', $context)) {
         // Just return
         return $this->content;
     }
     if ($course->format == 'topics' || $course->format == 'section') {
         $format = 'topic';
     } elseif ($course->format == 'topcoll') {
         $format = 'ctopics';
     } elseif ($course->format == 'weekcoll') {
         $format = 'cweeks';
     } else {
         $format = 'week';
     }
     $current = optional_param($format, -1, PARAM_INT);
     $sections = get_all_sections($course->id);
     foreach ($sections as $section) {
         if ($section->visible && $section->section >= 1 && $section->section <= $course->numsections) {
             $summary = $section->name;
             if (empty($summary)) {
                 $summary = get_string('sectionname', "format_{$course->format}") . ' ' . $section->section;
             }
             if ($format == 'week') {
                 $sectionmenu[$section->section] = $format . ' ' . $section->section . ' - ' . strip_tags($summary);
             } else {
                 $sectionmenu[$section->section] = strip_tags($summary);
             }
         }
     }
     $sectionmenu[0] = 'Show All';
     $this->content->text = '<div class="jumpmenu">';
     $this->content->text .= $OUTPUT->single_select(new moodle_url('/course/view.php?id=' . $course->id), $format, $sectionmenu, $current, array('' => get_string('jumpto')), null);
     $this->content->text .= '</div>';
     $this->content->footer = '';
     return $this->content;
 }
    // ファイルのアップロード
    $mform_post = new course_import_section_form_upload($CFG->wwwroot . '/course/format/project/import_upload.php?id=' . $id . '&section=' . $tosection, array('maxuploadsize' => get_max_upload_file_size()));
    $mform_post->display();
} else {
    if ($fromcourse && !$fromsection || $isexistingdirectory) {
        // ディレクトリ名が重複しているときの注意
        if ($isexistingdirectory) {
            notify(get_string('directoryalreadyexist', 'format_project', $newdirectoryname));
        }
        // ディレクトリ名が入力されていないときの表示
        if ($isemptyname) {
            notify(get_string('directorynameempty', 'format_project'));
        }
        // セクションタイトルの読み込み
        $options = array();
        $sections = get_all_sections($fromcourse);
        foreach ($sections as $section) {
            if ($sectiontitle = get_record('course_project_title', 'sectionid', $section->id)) {
                // セクションの選択
                $options[$section->section] = $sectiontitle->directoryname;
            }
        }
        // 各コースのデータ取得
        if (!($fromcourseobject = get_record("course", "id", $fromcourse))) {
            error("That's an invalid from course id");
        }
        $mform_post = new course_import_section_form_section($CFG->wwwroot . '/course/format/project/import.php', array('options' => $options, 'courseid' => $course->id, 'tosection' => $tosection, 'fromcourse' => $fromcourse, 'text' => get_string('sectionselect', 'format_project'), 'fullname' => $fromcourseobject->fullname));
        $mform_post->display();
    }
}
if (!empty($table)) {
/**
 * Get all the modules
 *
 * @return array
 */
function certificate_get_mods()
{
    global $COURSE, $CFG, $DB;
    $strtopic = get_string("topic");
    $strweek = get_string("week");
    $strsection = get_string("section");
    // Collect modules data
    get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused);
    $modules = array();
    $sections = get_all_sections($COURSE->id);
    // Sort everything the same as the course
    for ($i = 0; $i <= $COURSE->numsections; $i++) {
        // should always be true
        if (isset($sections[$i])) {
            $section = $sections[$i];
            if ($section->sequence) {
                switch ($COURSE->format) {
                    case "topics":
                        $sectionlabel = $strtopic;
                        break;
                    case "weeks":
                        $sectionlabel = $strweek;
                        break;
                    default:
                        $sectionlabel = $strsection;
                }
                $sectionmods = explode(",", $section->sequence);
                foreach ($sectionmods as $sectionmod) {
                    if (empty($mods[$sectionmod])) {
                        continue;
                    }
                    $mod = $mods[$sectionmod];
                    $mod->courseid = $COURSE->id;
                    $instance = $DB->get_record($mod->modname, array('id' => $mod->instance));
                    if ($grade_items = grade_get_grade_items_for_activity($mod)) {
                        $mod_item = grade_get_grades($COURSE->id, 'mod', $mod->modname, $mod->instance);
                        $item = reset($mod_item->items);
                        if (isset($item->grademax)) {
                            $modules[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name;
                        }
                    }
                }
            }
        }
    }
    return $modules;
}
function RWSGUVSList($r_cid)
{
    global $CFG;
    global $RWSUID;
    $r_vs = array();
    if (respondusws_floatcompare($CFG->version, 2012120300, 2) >= 0) {
        $modinfo = get_fast_modinfo($r_cid);
        $r_secs = $modinfo->get_section_info_all();
    } else {
        $r_secs = get_all_sections($r_cid);
    }
    if ($r_secs === false || count($r_secs) == 0) {
        return $r_vs;
    }
    if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) {
        $r_ctx = context_course::instance($r_cid);
    } else {
        $r_ctx = get_context_instance(CONTEXT_COURSE, $r_cid);
    }
    $r_vh = has_capability("moodle/course:viewhiddensections", $r_ctx, $RWSUID);
    if (!$r_vh) {
        $r_vh = is_siteadmin($RWSUID);
    }
    foreach ($r_secs as $r_s) {
        if ($r_s->visible || $r_vh) {
            $r_vs[] = $r_s;
        }
    }
    return $r_secs;
}
Beispiel #27
0
     foreach ($stats as $stat) {
         if (!empty($stat->zerofixed)) {
             // Don't know why this is necessary, see stats_fix_zeros above - MD
             continue;
         }
         $a = array(userdate($stat->timeend, get_string('strftimedate'), $CFG->timezone), $stat->line1);
         $a[] = $stat->line2;
         $a[] = $stat->line3;
         $table->data[] = $a;
     }
     print_table($table);
     break;
 case "outline":
 case "complete":
     get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
     $sections = get_all_sections($course->id);
     for ($i = 0; $i <= $course->numsections; $i++) {
         if (isset($sections[$i])) {
             // should always be true
             $section = $sections[$i];
             $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible or !$course->hiddensections);
             if ($showsection) {
                 // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
                 if ($section->sequence) {
                     echo '<div class="section">';
                     echo '<h2>';
                     switch ($course->format) {
                         case "weeks":
                             print_string("week");
                             break;
                         case "topics":
Beispiel #28
0
$PAGE->navbar->add($strrecentactivity, new moodle_url('/course/recent.php', array('id' => $course->id)));
$PAGE->navbar->add($userinfo);
$PAGE->set_title("{$course->shortname}: {$strrecentactivity}");
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($course->fullname) . ": {$userinfo}", 2);
$mform->display();
$modinfo = get_fast_modinfo($course);
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
if (has_capability('moodle/course:viewhiddensections', $context)) {
    $hiddenfilter = "";
} else {
    $hiddenfilter = "AND cs.visible = 1";
}
$sections = array();
$rawsections = array_slice(get_all_sections($course->id), 0, $course->numsections + 1, true);
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
foreach ($rawsections as $section) {
    if ($canviewhidden || !empty($section->visible)) {
        $sections[$section->section] = $section;
    }
}
if ($param->modid === 'all') {
    // ok
} else {
    if (strpos($param->modid, 'mod/') === 0) {
        $modname = substr($param->modid, strlen('mod/'));
        if (array_key_exists($modname, $modnames) and file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) {
            $filter = $modname;
        }
    } else {
Beispiel #29
0
 function definition()
 {
     global $CFG, $COURSE, $USER;
     $mform =& $this->_form;
     $context = context_course::instance($COURSE->id);
     $modinfo = get_fast_modinfo($COURSE);
     $sections = get_all_sections($COURSE->id);
     $mform->addElement('header', 'filters', get_string('managefilters'));
     //TODO: add better string
     $groupoptions = array();
     if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
         // limited group access
         $groups = groups_get_user_groups($COURSE->id);
         $allgroups = groups_get_all_groups($COURSE->id);
         if (!empty($groups[$COURSE->defaultgroupingid])) {
             foreach ($groups[$COURSE->defaultgroupingid] as $groupid) {
                 $groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context' => $context));
             }
         }
     } else {
         $groupoptions = array('0' => get_string('allgroups'));
         if (has_capability('moodle/site:accessallgroups', $context)) {
             // user can see all groups
             $allgroups = groups_get_all_groups($COURSE->id);
         } else {
             // user can see course level groups
             $allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid);
         }
         foreach ($allgroups as $group) {
             $groupoptions[$group->id] = format_string($group->name, true, array('context' => $context));
         }
     }
     if ($COURSE->id == SITEID) {
         $viewparticipants = has_capability('moodle/site:viewparticipants', context_system::instance());
     } else {
         $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
     }
     if ($viewparticipants) {
         $viewfullnames = has_capability('moodle/site:viewfullnames', context_course::instance($COURSE->id));
         $options = array();
         $options[0] = get_string('allparticipants');
         $options[$CFG->siteguest] = get_string('guestuser');
         if (isset($groupoptions[0])) {
             // can see all enrolled users
             if ($enrolled = get_enrolled_users($context, null, 0, user_picture::fields('u'))) {
                 foreach ($enrolled as $euser) {
                     $options[$euser->id] = fullname($euser, $viewfullnames);
                 }
             }
         } else {
             // can see users from some groups only
             foreach ($groupoptions as $groupid => $unused) {
                 if ($enrolled = get_enrolled_users($context, null, $groupid, user_picture::fields('u'))) {
                     foreach ($enrolled as $euser) {
                         if (!array_key_exists($euser->id, $options)) {
                             $options[$euser->id] = fullname($euser, $viewfullnames);
                         }
                     }
                 }
             }
         }
         $mform->addElement('select', 'user', get_string('participants'), $options);
         $mform->setAdvanced('user');
     }
     $sectiontitle = get_string('sectionname', 'format_' . $COURSE->format);
     $options = array('' => get_string('allactivities'));
     $modsused = array();
     foreach ($modinfo->cms as $cm) {
         if (!$cm->uservisible) {
             continue;
         }
         $modsused[$cm->modname] = true;
     }
     foreach ($modsused as $modname => $unused) {
         $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
         if (!file_exists($libfile)) {
             unset($modsused[$modname]);
             continue;
         }
         include_once $libfile;
         $libfunction = $modname . "_get_recent_mod_activity";
         if (!function_exists($libfunction)) {
             unset($modsused[$modname]);
             continue;
         }
         $options["mod/{$modname}"] = get_string('allmods', '', get_string('modulenameplural', $modname));
     }
     foreach ($modinfo->sections as $section => $cmids) {
         $options["section/{$section}"] = "-- " . get_section_name($COURSE, $sections[$section]) . " --";
         foreach ($cmids as $cmid) {
             $cm = $modinfo->cms[$cmid];
             if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
                 continue;
             }
             $options[$cm->id] = format_string($cm->name);
         }
     }
     $mform->addElement('select', 'modid', get_string('activities'), $options);
     $mform->setAdvanced('modid');
     if ($groupoptions) {
         $mform->addElement('select', 'group', get_string('groups'), $groupoptions);
         $mform->setAdvanced('group');
     } else {
         // no access to groups in separate mode
         $mform->addElement('hidden', 'group');
         $mform->setType('group', PARAM_INT);
         $mform->setConstants(array('group' => -1));
     }
     $options = array('default' => get_string('bycourseorder'), 'dateasc' => get_string('datemostrecentlast'), 'datedesc' => get_string('datemostrecentfirst'));
     $mform->addElement('select', 'sortby', get_string('sortby'), $options);
     $mform->setAdvanced('sortby');
     $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional' => true));
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->setType('courseid', PARAM_INT);
     $this->add_action_buttons(false, get_string('showrecent'));
 }
Beispiel #30
0
/** 
 * Simply prints all grade of one student from all modules from a given course
 * used in the grade book for student view, and grade button under user profile
 * @param int $userid;
 * @param int $courseid;
 */
function print_student_grade($user, $course)
{
    global $CFG;
    if (!empty($user)) {
        $grades[$user->id] = array();
        // Collect all grades in this array
        $gradeshtml[$user->id] = array();
        // Collect all grades html formatted in this array
        $totals[$user->id] = array();
        // Collect all totals in this array
    }
    $strmax = get_string("maximumshort");
    /// Collect modules data
    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
    /// Search through all the modules, pulling out grade data
    $sections = get_all_sections($course->id);
    // Sort everything the same as the course
    // prints table
    // flag for detecting whether to print table header or not
    $nograde = 0;
    for ($i = 0; $i <= $course->numsections; $i++) {
        if (isset($sections[$i])) {
            // should always be true
            $section = $sections[$i];
            if ($section->sequence) {
                $sectionmods = explode(",", $section->sequence);
                foreach ($sectionmods as $sectionmod) {
                    $mod = $mods[$sectionmod];
                    if (empty($mod->modname)) {
                        continue;
                        // Just in case, see MDL-7150
                    }
                    if (!($instance = get_record($mod->modname, 'id', $mod->instance))) {
                        continue;
                    }
                    if (!($cm = get_coursemodule_from_instance($mod->modname, $mod->instance))) {
                        continue;
                    }
                    if (!$cm->visible) {
                        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
                        if (!has_capability('moodle/course:viewhiddenactivities', $modcontext)) {
                            continue;
                        }
                    }
                    $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php";
                    if (file_exists($libfile)) {
                        require_once $libfile;
                        $gradefunction = $mod->modname . '_grades';
                        if (function_exists($gradefunction)) {
                            // Skip modules without grade function
                            if ($modgrades = $gradefunction($mod->instance)) {
                                if (!empty($modgrades->maxgrade)) {
                                    if ($mod->visible) {
                                        $maxgrade = $modgrades->maxgrade;
                                    } else {
                                        $maxgrade = $modgrades->maxgrade;
                                    }
                                } else {
                                    $maxgrade = '';
                                }
                                if ($maxgrade) {
                                    if (!$nograde) {
                                        echo '<table align="center" class="grades"><tr><th scope="col">' . get_string('activity') . '</th><th scope="col">' . get_string('yourgrade', 'grades') . '</th><th scope="col">' . get_string('maxgrade', 'grades') . '</th></tr>';
                                    }
                                    $nograde++;
                                    $link_id = grade_get_module_link($course->id, $mod->instance, $mod->module);
                                    $link = $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $link_id->id;
                                    echo '<tr>';
                                    if (!empty($modgrades->grades[$user->id])) {
                                        $currentgrade = $modgrades->grades[$user->id];
                                        echo "<td><a href='{$link}'>{$mod->modfullname}: " . format_string($instance->name, true) . "</a></td><td>{$currentgrade}</td><td>{$maxgrade}</td>";
                                    } else {
                                        echo "<td><a href='{$link}'>{$mod->modfullname}: " . format_string($instance->name, true) . "</a></td><td>" . get_string('nograde') . "</td><td>{$maxgrade}</td>";
                                    }
                                    echo '</tr>';
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // a new Moodle nesting record? ;-)
    if ($nograde) {
        echo '</table>';
    }
}