"MDL-20470, use a gloabl varible repositoryuseexternallink to make filepicker return...
[moodle.git] / my / index.php
CommitLineData
9b02b534 1<?php // $Id$
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
1a198dde 12 if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
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));
ad52c04f 24 $PAGE->set_url('my/index.php');
cfcfb9f3 25 $PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
0d6b9d4f 26
d2b23346 27 if (($edit != -1) and $PAGE->user_allowed_editing()) {
28 $USER->editing = $edit;
0d6b9d4f 29 }
30
7527a2f0 31 if (!empty($USER->editing)) {
32 $string = get_string('updatemymoodleoff');
33 $edit = '0';
34 } else {
35 $string = get_string('updatemymoodleon');
36 $edit = '1';
37 }
38
39 $form = new html_form();
40 $form->url = new moodle_url("$CFG->wwwroot/my/index.php", array('edit' => $edit));
41 $form->button->text = $string;
42 $button = $OUTPUT->button($form);
43
1b6b9400 44 $header = $SITE->shortname . ': ' . $strmymoodle;
96db467a 45 $PAGE->navbar->add($strmymoodle);
1b6b9400 46 $loggedinas = user_login_string();
47
48 if (empty($CFG->langmenu)) {
49 $langmenu = '';
50 } else {
51 $currlang = current_language();
52 $langs = get_list_of_languages();
7b1f2c82 53 $select = html_select::make_popup_form($CFG->wwwroot .'/my/index.php', 'lang', $langs, 'chooselang', $currlang);
d81b05e7 54 $select->nothinglabel = false;
55 $select->set_label(get_accesshide(get_string('language')));
56 $langmenu = $OUTPUT->select($select);
1b6b9400 57 }
58
609adb68 59 $PAGE->set_title($strmymoodle);
60 $PAGE->set_heading($header);
61 $PAGE->set_button($button);
62 $PAGE->set_headingmenu($loggedinas . $langmenu);
63 echo $OUTPUT->header();
0d6b9d4f 64
3131d5c6 65/// The main overview in the middle of the page
d4a03c00 66
797c881a 67 // limits the number of courses showing up
ebb1a1e8 68 $courses_limit = 21;
8b8ff6ff 69 if (!empty($CFG->mycoursesperpage)) {
ebb1a1e8 70 $courses_limit = $CFG->mycoursesperpage;
71 }
497bad90 72 $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
3131d5c6 73 $site = get_site();
9b02b534 74 $course = $site; //just in case we need the old global $course hack
3131d5c6 75
76 if (array_key_exists($site->id,$courses)) {
77 unset($courses[$site->id]);
78 }
79
9b02b534 80 foreach ($courses as $c) {
40cab82e 81 if (isset($USER->lastcourseaccess[$c->id])) {
82 $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
3131d5c6 83 } else {
9b02b534 84 $courses[$c->id]->lastaccess = 0;
3131d5c6 85 }
86 }
d4a03c00 87
3131d5c6 88 if (empty($courses)) {
c7a2fd97 89 echo $OUTPUT->box(get_string('nocourses','my'));
3131d5c6 90 } else {
91 print_overview($courses);
92 }
d4a03c00 93
797c881a 94 // if more than 20 courses
95 if (count($courses) > 20) {
c7a2fd97 96 echo '<br />...';
797c881a 97 }
0d6b9d4f 98
7e0d6675 99 echo $OUTPUT->footer();
0d6b9d4f 100
3131d5c6 101?>