Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/notes/index.php
Go to the documentation of this file.
00001 <?php
00002 
00009 require_once('../config.php');
00010 require_once('lib.php');
00011 
00013 $courseid     = optional_param('course', SITEID, PARAM_INT);
00014 $userid       = optional_param('user', 0, PARAM_INT);
00015 $filtertype   = optional_param('filtertype', '', PARAM_ALPHA);
00016 $filterselect = optional_param('filterselect', 0, PARAM_INT);
00017 
00018 $url = new moodle_url('/notes/index.php');
00019 if ($courseid != SITEID) {
00020     $url->param('course', $courseid);
00021 }
00022 if ($userid !== 0) {
00023     $url->param('user', $userid);
00024 }
00025 $PAGE->set_url($url);
00026 
00028 switch($filtertype) {
00029     case 'course':
00030         $courseid = $filterselect;
00031         break;
00032     case 'site':
00033         $courseid = SITEID;
00034         break;
00035 }
00036 
00037 if (empty($courseid)) {
00038     $courseid = SITEID;
00039 }
00040 
00042 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
00043 
00045 if ($userid) {
00046     $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
00047     $filtertype = 'user';
00048     $filterselect = $user->id;
00049 
00050     if ($user->deleted) {
00051         echo $OUTPUT->header();
00052         echo $OUTPUT->heading(get_string('userdeleted'));
00053         echo $OUTPUT->footer();
00054         die;
00055     }
00056 
00057 } else {
00058     $filtertype = 'course';
00059     $filterselect = $course->id;
00060 }
00061 
00063 require_login($course);
00064 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
00065 
00066 if (empty($CFG->enablenotes)) {
00067     print_error('notesdisabled', 'notes');
00068 }
00069 
00071 if ($course->id == SITEID) {
00072     $coursecontext = get_context_instance(CONTEXT_SYSTEM);   // SYSTEM context
00073 } else {
00074     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);   // Course context
00075 }
00076 $systemcontext = get_context_instance(CONTEXT_SYSTEM);   // SYSTEM context
00077 
00078 $strnotes = get_string('notes', 'notes');
00079 if ($userid) {
00080     $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
00081     $PAGE->navigation->extend_for_user($user);
00082 } else {
00083     $link = null;
00084     if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
00085         $link = new moodle_url('/user/index.php',array('id'=>$course->id));
00086     }
00087 }
00088 
00089 $PAGE->set_pagelayout('course');
00090 $PAGE->set_title($course->shortname . ': ' . $strnotes);
00091 $PAGE->set_heading($course->fullname);
00092 
00093 echo $OUTPUT->header();
00094 if ($userid) {
00095     echo $OUTPUT->heading(fullname($user).': '.$strnotes);
00096 } else {
00097     echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $coursecontext)).': '.$strnotes);
00098 }
00099 
00100 $strsitenotes = get_string('sitenotes', 'notes');
00101 $strcoursenotes = get_string('coursenotes', 'notes');
00102 $strpersonalnotes = get_string('personalnotes', 'notes');
00103 $straddnewnote = get_string('addnewnote', 'notes');
00104 
00105 echo $OUTPUT->box_start();
00106 
00107 if ($courseid != SITEID) {
00108     //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
00109     $context = get_context_instance(CONTEXT_COURSE, $courseid);
00110     $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
00111     $view = has_capability('moodle/notes:view', $context);
00112     $fullname = format_string($course->fullname, true, array('context' => $context));
00113     note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
00114     note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
00115     note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
00116 
00117 } else {  // Normal course
00118     //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
00119     $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
00120     note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
00121     echo '<a name="coursenotes"></a>';
00122 
00123     if (!empty($userid)) {
00124         $courses = enrol_get_users_courses($userid);
00125         foreach($courses as $c) {
00126             $ccontext = get_context_instance(CONTEXT_COURSE, $c->id);
00127             $cfullname = format_string($c->fullname, true, array('context' => $ccontext));
00128             $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
00129             if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
00130                 $addid = $c->id;
00131             } else {
00132                 $addid = 0;
00133             }
00134             note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
00135         }
00136     }
00137 }
00138 
00139 echo $OUTPUT->box_end();
00140 
00141 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations