MDL-22061 get_mimetype_description() does not rely on get_string() returning square...
[moodle.git] / my / index.php
CommitLineData
1d422980 1<?php
0d6b9d4f 2
3 // this is the 'my moodle' page
4
1b6b9400 5 require_once(dirname(__FILE__) . '/../config.php');
3131d5c6 6 require_once($CFG->dirroot.'/course/lib.php');
ad52c04f 7
0d6b9d4f 8 require_login();
9
1b6b9400 10 $strmymoodle = get_string('mymoodle','my');
fdaa6006 11
4f0c2d00 12 if (isguestuser()) {
609adb68 13 $PAGE->set_title($strmymoodle);
14 echo $OUTPUT->header();
642816a6 15 echo $OUTPUT->confirm(get_string('noguest', 'my') . '<br /><br />' . get_string('liketologin'), get_login_url(), $CFG->wwwroot);
7e0d6675 16 echo $OUTPUT->footer();
1b6b9400 17 die;
fdaa6006 18 }
19
1b6b9400 20 $edit = optional_param('edit', -1, PARAM_BOOL);
d2b23346 21 $blockaction = optional_param('blockaction', '', PARAM_ALPHA);
0d6b9d4f 22
1b6b9400 23 $PAGE->set_context(get_context_instance(CONTEXT_USER, $USER->id));
a6855934 24 $PAGE->set_url('/my/index.php');
191b267b 25 $PAGE->set_pagelayout('mydashboard');
cfcfb9f3 26 $PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
0d6b9d4f 27
d2b23346 28 if (($edit != -1) and $PAGE->user_allowed_editing()) {
29 $USER->editing = $edit;
0d6b9d4f 30 }
31
7527a2f0 32 if (!empty($USER->editing)) {
33 $string = get_string('updatemymoodleoff');
34 $edit = '0';
35 } else {
36 $string = get_string('updatemymoodleon');
37 $edit = '1';
38 }
39
5c2ed7e2
PS
40 $url = new moodle_url("$CFG->wwwroot/my/index.php", array('edit' => $edit));
41 $button = $OUTPUT->single_button($url, $string);
7527a2f0 42
1b6b9400 43 $header = $SITE->shortname . ': ' . $strmymoodle;
1b6b9400 44
609adb68 45 $PAGE->set_title($strmymoodle);
46 $PAGE->set_heading($header);
47 $PAGE->set_button($button);
609adb68 48 echo $OUTPUT->header();
0d6b9d4f 49
3131d5c6 50/// The main overview in the middle of the page
d4a03c00 51
797c881a 52 // limits the number of courses showing up
ebb1a1e8 53 $courses_limit = 21;
e84a97b8 54 if (isset($CFG->mycoursesperpage)) {
ebb1a1e8 55 $courses_limit = $CFG->mycoursesperpage;
56 }
1d422980 57
e84a97b8 58 $morecourses = false;
59 if ($courses_limit > 0) {
60 $courses_limit = $courses_limit + 1;
61 }
1d422980 62
497bad90 63 $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
3131d5c6 64 $site = get_site();
9b02b534 65 $course = $site; //just in case we need the old global $course hack
3131d5c6 66
e84a97b8 67 if (($courses_limit > 0) && (count($courses) >= $courses_limit)) {
68 //remove the 'marker' course that we retrieve just to see if we have more than $courses_limit
69 array_pop($courses);
70 $morecourses = true;
71 }
72
73
3131d5c6 74 if (array_key_exists($site->id,$courses)) {
75 unset($courses[$site->id]);
76 }
77
9b02b534 78 foreach ($courses as $c) {
40cab82e 79 if (isset($USER->lastcourseaccess[$c->id])) {
80 $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
3131d5c6 81 } else {
9b02b534 82 $courses[$c->id]->lastaccess = 0;
3131d5c6 83 }
84 }
d4a03c00 85
3131d5c6 86 if (empty($courses)) {
c7a2fd97 87 echo $OUTPUT->box(get_string('nocourses','my'));
3131d5c6 88 } else {
89 print_overview($courses);
90 }
d4a03c00 91
797c881a 92 // if more than 20 courses
e84a97b8 93 if ($morecourses) {
c7a2fd97 94 echo '<br />...';
797c881a 95 }
0d6b9d4f 96
7e0d6675 97 echo $OUTPUT->footer();
0d6b9d4f 98