"MDL-13766, use OUTPUT to print box"
[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
12 if (isguest()) {
1b6b9400 13 print_header($strmymoodle);
14 notice_yesno(get_string('noguest', 'my') . '<br /><br />' .
15 get_string('liketologin'), get_login_url(), $CFG->wwwroot);
fdaa6006 16 print_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
b7b2d0f3 27 // Note: MDL-19010 there will be further changes to printing header and blocks.
28 // The code will be much nicer than this eventually.
ee6055eb 29 $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
0d6b9d4f 30
d2b23346 31 if (($edit != -1) and $PAGE->user_allowed_editing()) {
32 $USER->editing = $edit;
0d6b9d4f 33 }
34
1b6b9400 35 $button = update_mymoodle_icon($USER->id);
36 $header = $SITE->shortname . ': ' . $strmymoodle;
37 $navigation = build_navigation($strmymoodle);
38 $loggedinas = user_login_string();
39
40 if (empty($CFG->langmenu)) {
41 $langmenu = '';
42 } else {
43 $currlang = current_language();
44 $langs = get_list_of_languages();
45 $langlabel = get_accesshide(get_string('language'));
46 $langmenu = popup_form($CFG->wwwroot . '/my/index.php?lang=', $langs,
47 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
48 }
49
50 print_header($strmymoodle, $header, $navigation, '', '', true, $button, $loggedinas . $langmenu);
0d6b9d4f 51
355bf907 52 echo '<table id="layout-table">';
0d6b9d4f 53 echo '<tr valign="top">';
54
355bf907 55 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
56 foreach ($lt as $column) {
57 switch ($column) {
58 case 'left':
0d6b9d4f 59
60 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
61
62 if(blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
63 echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
9f7f1a74 64 print_container_start();
0d6b9d4f 65 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 66 print_container_end();
0d6b9d4f 67 echo '</td>';
68 }
355bf907 69
70 break;
71 case 'middle':
72
a06c8c2c 73 echo '<td valign="top" id="middle-column">';
9f7f1a74 74 print_container_start(TRUE);
3131d5c6 75
76/// The main overview in the middle of the page
797c881a 77
78 // limits the number of courses showing up
ebb1a1e8 79 $courses_limit = 21;
8b8ff6ff 80 if (!empty($CFG->mycoursesperpage)) {
ebb1a1e8 81 $courses_limit = $CFG->mycoursesperpage;
82 }
497bad90 83 $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
3131d5c6 84 $site = get_site();
9b02b534 85 $course = $site; //just in case we need the old global $course hack
3131d5c6 86
87 if (array_key_exists($site->id,$courses)) {
88 unset($courses[$site->id]);
89 }
90
9b02b534 91 foreach ($courses as $c) {
40cab82e 92 if (isset($USER->lastcourseaccess[$c->id])) {
93 $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
3131d5c6 94 } else {
9b02b534 95 $courses[$c->id]->lastaccess = 0;
3131d5c6 96 }
97 }
98
99 if (empty($courses)) {
100 print_simple_box(get_string('nocourses','my'),'center');
101 } else {
102 print_overview($courses);
103 }
797c881a 104
105 // if more than 20 courses
106 if (count($courses) > 20) {
107 echo '<br />...';
108 }
3131d5c6 109
9f7f1a74 110 print_container_end();
0d6b9d4f 111 echo '</td>';
355bf907 112
113 break;
114 case 'right':
115
0d6b9d4f 116 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
117
3131d5c6 118 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing()) {
0d6b9d4f 119 echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="right-column">';
9f7f1a74 120 print_container_start();
0d6b9d4f 121 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
9f7f1a74 122 print_container_end();
0d6b9d4f 123 echo '</td>';
124 }
355bf907 125 break;
126 }
127 }
0d6b9d4f 128
129 /// Finish the page
130 echo '</tr></table>';
131
132 print_footer();
133
3131d5c6 134?>