]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7077, MDL-10181, adding notes for students
authortoyomoyo <toyomoyo>
Thu, 5 Jul 2007 06:53:17 +0000 (06:53 +0000)
committertoyomoyo <toyomoyo>
Thu, 5 Jul 2007 06:53:17 +0000 (06:53 +0000)
17 files changed:
lang/en_utf8/notes.php [new file with mode: 0755]
lang/en_utf8/role.php
lib/db/access.php
lib/weblib.php
notes/add.php [new file with mode: 0644]
notes/delete.php [new file with mode: 0644]
notes/edit.php [new file with mode: 0644]
notes/edit_form.php [new file with mode: 0644]
notes/index.php [new file with mode: 0644]
notes/lib.php [new file with mode: 0644]
notes/version.php [new file with mode: 0644]
theme/standard/styles_layout.css
user/action_redir.php
user/addnote.php [new file with mode: 0644]
user/groupaddnote.php [new file with mode: 0644]
user/index.php
user/tabs.php

diff --git a/lang/en_utf8/notes.php b/lang/en_utf8/notes.php
new file mode 100755 (executable)
index 0000000..d0d32f7
--- /dev/null
@@ -0,0 +1,29 @@
+<?PHP // $Id$\r
+      // note.php \r
+$string['notes'] = 'Notes';\r
+$string['sitenotes'] = 'Site notes';\r
+$string['coursenotes'] = 'Course notes';\r
+$string['personalnotes'] = 'Personal notes';\r
+$string['created'] = 'created';\r
+$string['rating'] = 'Rating';\r
+$string['nonotes'] = 'There are no notes.';\r
+$string['notesnotvisible'] = 'You are not allowed to view the notes.';\r
+$string['addnewnote'] = 'Add a new note';\r
+$string['groupaddnewnote'] = 'Add a new note for all';\r
+$string['deleteconfirm'] = 'Delete this note?';\r
+$string['content'] = 'Note content';\r
+$string['nocontent'] = 'Note content can not be empty';\r
+$string['nouser'] = 'You must select a user';\r
+$string['rating'] = 'Rating';\r
+$string['low'] = 'low';\r
+$string['belownormal'] = 'below normal';\r
+$string['normal'] = 'normal';\r
+$string['abovenormal'] = 'above normal';\r
+$string['high'] = 'high';\r
+$string['unknown'] = 'unknown';\r
+$string['bynameondate'] = 'by $a->name - $a->date';\r
+$string['publishstate'] = 'Status';\r
+$string['personal'] = 'personal';\r
+$string['course'] = 'course';\r
+$string['site'] = 'site';\r
+?>
\ No newline at end of file
index d470f127395449ddc0fcfa654e52b7e61cb77b11..633021ea547c6e4244fc4221e33f5b096bf40ef4 100644 (file)
@@ -145,4 +145,8 @@ $string['xuserswiththerole'] = 'Users with the role \"$a->role\": $a->number';
 $string['site:mnetlogintoremote'] = 'Roam to a remote Moodle';
 $string['site:mnetloginfromremote'] = 'Login from a remote Moodle';
 
+// Notes
+$string['notes:view'] = 'View notes';
+$string['notes:manage'] = 'Manage notes';
+
 ?>
index 7b23058838a517910c5056e9a3832a975e7664f3..6267042c3f645c2f07619b67147e25d49f4db889 100644 (file)
@@ -1015,8 +1015,27 @@ $moodle_capabilities = array(
         'legacy' => array(
             'user' => CAP_ALLOW
         )
-    )
-        
+    ),
+    
+    'moodle/notes:view' => array(
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'moodle/notes:manage' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),    
 );
 
 ?>
index 6bb1835bdc808f418bc325cbbe27a5985d1810e8..6ca90a4e73298fa7e333c5ceb67a2c1070818ac8 100644 (file)
@@ -3744,7 +3744,11 @@ has_capability('moodle/course:viewhiddenuserfields', $context)) {
     if ($CFG->bloglevel > 0) {
         $output .= '<a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$user->id.'">'.get_string('blogs','blog').'</a><br />';
     }
-
+    //link to notes
+    if (has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context)) {
+        $output .= '<a href="'.$CFG->wwwroot.'/notes/index.php?course=' . $course->id. '&amp;user='.$user->id.'">'.get_string('notes','notes').'</a><br />';
+    }
+    
     if (has_capability('moodle/site:viewreports', $context)) {
         $timemidnight = usergetmidnight(time());
         $output .= '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->activity .'</a><br />';
diff --git a/notes/add.php b/notes/add.php
new file mode 100644 (file)
index 0000000..60fbb91
--- /dev/null
@@ -0,0 +1,76 @@
+<?php // $Id$\r
+\r
+require_once('../config.php');\r
+require_once('lib.php');\r
+\r
+// retrieve parameters\r
+$courseid      = required_param('course', PARAM_INT);\r
+$userid        = optional_param('user', 0, PARAM_INT);\r
+\r
+// locate course information\r
+if (!($course = get_record('course', 'id', $courseid))) {\r
+    error('Incorrect course id found');\r
+}\r
+\r
+// locate context information\r
+$context = get_context_instance(CONTEXT_COURSE, $course->id);\r
+\r
+// check capability\r
+if (!has_capability('moodle/notes:manage', $context)) {\r
+    error('You may not create notes');\r
+}\r
+\r
+// build-up form\r
+require_once('edit_form.php');\r
+// get option values for the user select\r
+$extradata['userlist'] = array();\r
+$usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})";\r
+$userlist = get_records_sql($usersincourse);\r
+// format userdata using fullname\r
+if($userlist) {\r
+    foreach($userlist as $user) {\r
+        $extradata['userlist'][$user->id] = fullname($user);\r
+    }\r
+}\r
+// create form\r
+$noteform = new note_edit_form(null, $extradata);\r
+\r
+// if form was cancelled then return to the previous notes list\r
+if ($noteform->is_cancelled()) {\r
+    redirect($CFG->wwwroot . '/notes/index.php?course=' . $courseid . '&amp;user=' . $userid);\r
+}\r
+\r
+// if data was submitted and validated, then save it to database\r
+if ($formdata = $noteform->get_data()) {\r
+    $note = new object();\r
+    $note->courseid = $formdata->course;\r
+    $note->content = $formdata->content;\r
+    $note->format = FORMAT_PLAIN;\r
+    $note->rating = $formdata->rating;\r
+    $note->userid = $formdata->user;\r
+    $note->publishstate = $formdata->publishstate;\r
+    if (note_save($note)) {\r
+        add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');\r
+    }\r
+// redirect to notes list that contains this note\r
+    redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);\r
+}\r
+\r
+if($noteform->is_submitted()) {\r
+// if data was submitted with errors, then use it as default for new form\r
+    $note = $noteform->get_submitted_data(false);\r
+} else {\r
+// if data was not submitted yet, then use default values\r
+    $note = new object();\r
+    $note->id = 0;\r
+    $note->course = $courseid;\r
+    $note->user = $userid;\r
+    \r
+}\r
+$noteform->set_data($note);\r
+$strnotes = get_string('notes', 'notes');\r
+\r
+// output HTML\r
+print_header($course->shortname . ': ' . $strnotes, $course->fullname);\r
+$noteform->display();\r
+print_footer();\r
diff --git a/notes/delete.php b/notes/delete.php
new file mode 100644 (file)
index 0000000..e7de35c
--- /dev/null
@@ -0,0 +1,46 @@
+<?php // $Id$\r
+\r
+require_once('../config.php');\r
+require_once('lib.php');\r
+\r
+// retrieve parameters\r
+$noteid       = required_param('note', PARAM_INT);\r
+\r
+// locate note information\r
+if (!$note = note_load($noteid)) {\r
+    error('Incorrect note id specified');\r
+}\r
+\r
+// locate course information\r
+if (!$course = get_record('course', 'id', $note->courseid)) {\r
+    error('Incorrect course id found');\r
+}\r
+\r
+// locate context information\r
+$context = get_context_instance(CONTEXT_COURSE, $course->id);\r
+\r
+// check capability\r
+if (!has_capability('moodle/notes:manage', $context)) {\r
+    error('You may not delete this note');\r
+}\r
+\r
+if (data_submitted() && confirm_sesskey()) {\r
+//if data was submitted and is valid, then delete note\r
+    $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;\r
+    if (note_delete($noteid)) {\r
+        add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');\r
+    } else {\r
+        error('Error occured while deleting post', $returnurl);\r
+    }\r
+    redirect($returnurl);\r
+} else {\r
+// if data was not submitted yet, then show note data with a delete confirmation form\r
+    $strnotes = get_string('notes', 'notes');\r
+    $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey());\r
+    $optionsno = array('course'=>$course->id, 'user'=>$note->userid);\r
+    print_header($course->shortname . ': ' . $strnotes, $course->fullname);\r
+    notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');\r
+    echo '<br />';\r
+    note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);\r
+    print_footer();\r
+}\r
diff --git a/notes/edit.php b/notes/edit.php
new file mode 100644 (file)
index 0000000..48c04d4
--- /dev/null
@@ -0,0 +1,82 @@
+<?php // $Id$\r
+\r
+require_once('../config.php');\r
+require_once('lib.php');\r
+\r
+// retrieve parameters\r
+$noteid       = required_param('note', PARAM_INT);\r
+\r
+// locate note information\r
+if (!$note = note_load($noteid)) {\r
+    error('Incorrect note id specified');\r
+}\r
+\r
+// locate course information\r
+if (!$course = get_record('course', 'id', $note->courseid)) {\r
+    error('Incorrect course id found');\r
+}\r
+\r
+// locate context information\r
+$context = get_context_instance(CONTEXT_COURSE, $course->id);\r
+\r
+// check capability\r
+if (!has_capability('moodle/notes:manage', $context)) {\r
+    error('You may not modify notes');\r
+}\r
+\r
+// build-up form\r
+require_once('edit_form.php');\r
+// get option values for the user select\r
+$extradata['userlist'] = array();\r
+if ($course->id == SITEID) {\r
+    $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id={$userid}";\r
+} else {\r
+    $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})";\r
+}\r
+$userlist = get_records_sql($usersincourse);\r
+// format userdata using fullname\r
+if($userlist) {\r
+    foreach($userlist as $user) {\r
+        $extradata['userlist'][$user->id] = fullname($user);\r
+    }\r
+}\r
+// create form\r
+$noteform = new note_edit_form(null, $extradata);\r
+\r
+// if form was cancelled then return to the notes list of the note\r
+if ($noteform->is_cancelled()) {\r
+    redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);\r
+}\r
+\r
+// if data was submitted and validated, then save it to database\r
+if ($formdata = $noteform->get_data()){\r
+    $note->courseid = $formdata->course;\r
+    $note->userid = $formdata->user;\r
+    $note->content = $formdata->content;\r
+    $note->format = FORMAT_PLAIN;\r
+    $note->rating = $formdata->rating;\r
+    $note->publishstate = $formdata->publishstate;\r
+    if (note_save($note)) {\r
+        add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id, 'update note');\r
+    }\r
+// redirect to notes list that contains this note\r
+    redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);\r
+}\r
+\r
+\r
+if($noteform->is_submitted()) {\r
+// if data was submitted with errors, then use it as default for new form\r
+    $note = $noteform->get_submitted_data(false);\r
+}else{\r
+// if data was not submitted yet, then used values retrieved from the database\r
+    $note->user = $note->userid;\r
+    $note->course = $note->courseid;\r
+    $note->note = $note->id;\r
+}\r
+$noteform->set_data($note);\r
+$strnotes = get_string('notes', 'notes');\r
+\r
+// output HTML\r
+print_header($course->shortname . ': ' . $strnotes, $course->fullname);\r
+$noteform->display();\r
+print_footer();\r
diff --git a/notes/edit_form.php b/notes/edit_form.php
new file mode 100644 (file)
index 0000000..0816f1c
--- /dev/null
@@ -0,0 +1,35 @@
+<?php  // $Id$\r
+\r
+require_once($CFG->libdir.'/formslib.php');\r
+\r
+class note_edit_form extends moodleform {\r
+\r
+    function definition() {\r
+        $mform    =& $this->_form;\r
+\r
+        $mform->addElement('header', 'general', get_string('general', 'form'));\r
+\r
+        $mform->addElement('select', 'user', get_string('user'), $this->_customdata['userlist']);\r
+        $mform->addRule('user', get_string('nouser', 'notes'), 'required', null, 'client');\r
+\r
+        $mform->addElement('textarea', 'content', get_string('content', 'notes'), array('rows'=>15, 'cols'=>40));\r
+        $mform->setType('content', PARAM_RAW);\r
+        $mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client');\r
+        $mform->setHelpButton('content', array('writing', 'richtext'), false, 'editorhelpbutton');\r
+\r
+        $mform->addElement('select', 'rating', get_string('rating', 'notes'), note_get_rating_names());\r
+        $mform->setDefault('rating', 3);\r
+\r
+        $mform->addElement('select', 'publishstate', get_string('publishstate', 'notes'), note_get_state_names());\r
+        $mform->setDefault('publishstate', NOTES_STATE_PUBLIC);\r
+        $mform->setType('publishstate', PARAM_ALPHA);\r
+\r
+        $this->add_action_buttons();\r
+\r
+        $mform->addElement('hidden', 'course');\r
+        $mform->setType('course', PARAM_INT);\r
+\r
+        $mform->addElement('hidden', 'note');\r
+        $mform->setType('note', PARAM_INT);\r
+    }\r
+}\r
diff --git a/notes/index.php b/notes/index.php
new file mode 100644 (file)
index 0000000..1720558
--- /dev/null
@@ -0,0 +1,77 @@
+<?php // $Id$\r
+\r
+/**\r
+ * file index.php\r
+ * index page to view notes. \r
+ * if a course id is specified then the entries from that course are shown\r
+ * if a user id is specified only notes related to that user are shown\r
+ */\r
+require_once('../config.php');\r
+require_once('lib.php');\r
+// retrieve parameters\r
+$courseid     = optional_param('course', SITEID, PARAM_INT);\r
+$userid       = optional_param('user', 0, PARAM_INT);\r
+$filtertype   = optional_param('filtertype', '', PARAM_ALPHA);\r
+$filterselect = optional_param('filterselect', 0, PARAM_INT);\r
+\r
+// tabs compatibility\r
+switch($filtertype) {\r
+    case 'course':\r
+        $courseid = $filterselect;\r
+        break;\r
+    case 'site':\r
+        $courseid = SITEID;\r
+        break;\r
+}\r
+\r
+// locate course information\r
+if (!$course = get_record('course', 'id', $courseid)) {\r
+    error('Incorrect course id specified');\r
+}\r
+\r
+// locate user information\r
+if ($userid) {\r
+    if(!$user = get_record('user', 'id', $userid)) {\r
+        error('Incorrect user id specified');\r
+    }\r
+    $filtertype = 'user';\r
+    $filterselect = $user->id;\r
+} else {\r
+    $filtertype = 'course';\r
+    $filterselect = $course->id;\r
+}\r
+\r
+// require login to access notes\r
+require_login($course->id);\r
+$strnotes = get_string('notes', 'notes');\r
+$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));\r
+$currenttab = 'notes';\r
+// output HTML\r
+print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));\r
+\r
+require_once($CFG->dirroot .'/user/tabs.php');\r
+\r
+if($courseid != SITEID) {\r
+    $context = get_context_instance(CONTEXT_COURSE, $courseid);\r
+    if (has_capability('moodle/notes:manage', $context)) {\r
+        $addlink = $CFG->wwwroot .'/notes/add.php?course=' . $courseid . '&amp;user=' . $userid;\r
+        echo '<p><a href="'. $addlink . '">' . get_string('addnewnote', 'notes') . '</a></p>';\r
+    }\r
+    note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0);\r
+    note_print_notes(get_string('coursenotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_PUBLIC, 0);\r
+    note_print_notes(get_string('personalnotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);\r
+} else {\r
+    $context = get_context_instance(CONTEXT_SYSTEM);\r
+    note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0);\r
+    if($userid) {\r
+        $courses = get_my_courses($userid);\r
+        foreach($courses as $c) {\r
+            $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';\r
+            note_print_notes($header, $context, $c->id, $userid, NOTES_STATE_PUBLIC, 0);\r
+        }\r
+    }\r
+}    \r
+\r
+add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');\r
+\r
+print_footer($course);\r
diff --git a/notes/lib.php b/notes/lib.php
new file mode 100644 (file)
index 0000000..b097580
--- /dev/null
@@ -0,0 +1,278 @@
+<?php // $Id$\r
+\r
+/**\r
+ * Library of functions and constants for notes\r
+ */\r
+\r
+/**\r
+ * Constants for ratings.\r
+ */\r
+define('NOTES_RATING_LOW', '1');\r
+define('NOTES_RATING_BELOWNORMAL', '2');\r
+define('NOTES_RATING_NORMAL', '3');\r
+define('NOTES_RATING_ABOVENORMAL', '4');\r
+define('NOTES_RATING_HIGH', '5');\r
+\r
+/**\r
+ * Constants for states.\r
+ */\r
+define('NOTES_STATE_DRAFT', 'draft');\r
+define('NOTES_STATE_PUBLIC', 'public');\r
+define('NOTES_STATE_SITE', 'site');\r
+\r
+/**\r
+ * Constants for note parts (flags used by note_print and note_print_list).\r
+ */\r
+define('NOTES_SHOW_FULL', 0x07);\r
+define('NOTES_SHOW_HEAD', 0x02);\r
+define('NOTES_SHOW_BODY', 0x01);\r
+define('NOTES_SHOW_FOOT', 0x04);\r
+\r
+/**\r
+ * Retrieves a list of note objects with specific atributes.\r
+ *\r
+ * @param int    $courseid id of the course in which the notes were posted (0 means any)\r
+ * @param int    $userid id of the user to which the notes refer (0 means any)\r
+ * @param string $state state of the notes (i.e. draft, public, site) ('' means any)\r
+ * @param int    $author id of the user who modified the note last time (0 means any)\r
+ * @param string $order an order to sort the results in\r
+ * @param int    $limitfrom number of records to skip (offset)\r
+ * @param int    $limitnum number of records to fetch\r
+ * @return array of note objects\r
+ */\r
+function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='lastmodified DESC', $limitfrom=0, $limitnum=0) {\r
+    // setup filters\r
+    $select = array();\r
+    if($courseid) {\r
+        $selects[] = 'courseid=' . $courseid;\r
+    }\r
+    if($userid) {\r
+        $selects[] = 'userid=' . $userid;\r
+    }\r
+    if($author) {\r
+        $selects[] = 'usermodified=' . $author;\r
+    }\r
+    if($state) {\r
+        $selects[] = 'publishstate="' . $state . '"';\r
+    }\r
+    $selects[] = 'module="notes"';\r
+    $select = implode(' AND ', $selects);\r
+    $fields = 'id,courseid,userid,content,format,rating,created,lastmodified,usermodified,publishstate';\r
+    // retrieve data\r
+    $rs =& get_recordset_select('post', $select, $order, $fields, $limitfrom, $limitnum);\r
+    return recordset_to_array($rs);\r
+}\r
+\r
+/**\r
+ * Retrieves a note object based on its id.\r
+ *\r
+ * @param int    $note_id id of the note to retrieve\r
+ * @return note object\r
+ */\r
+function note_load($note_id) {\r
+    $fields = 'id,courseid,userid,content,format,rating,created,lastmodified,usermodified,publishstate';\r
+    return get_record_select('post', 'id=' . $note_id . ' AND module="notes"', $fields);\r
+}\r
+\r
+/**\r
+ * Saves a note object. The note object is passed by reference and its fields (i.e. id) \r
+ * might change during the save.\r
+ *\r
+ * @param note   $note object to save\r
+ * @return boolean true if the object was saved; false otherwise\r
+ */\r
+function note_save(&$note) {\r
+    global $USER;\r
+    // setup & clean fields\r
+    $note->module = 'notes';\r
+    $note->lastmodified = time();\r
+    $note->usermodified = $USER->id;\r
+    if(empty($note->rating)) {\r
+        $note->rating = NOTES_RATING_NORMAL;\r
+    }\r
+    if(empty($note->format)) {\r
+        $note->format = FORMAT_PLAIN;\r
+    }\r
+    if(empty($note->publishstate)) {\r
+        $note->publishstate = NOTES_STATE_PUBLIC;\r
+    }\r
+    // save data\r
+    if(empty($note->id)) {\r
+        // insert new note\r
+        $note->created = $note->lastmodified;\r
+        if($id = insert_record('post', $note)) {\r
+            $note->id = $id;\r
+            $result = true;\r
+        } else {\r
+            $result = false;\r
+        }\r
+    } else {\r
+        // update old note\r
+        $result = update_record('post', $note);\r
+    }\r
+    unset($note->module);\r
+    return $result;\r
+}\r
+\r
+/**\r
+ * Deletes a note object based on its id.\r
+ *\r
+ * @param int    $note_id id of the note to delete\r
+ * @return boolean true if the object was deleted; false otherwise\r
+ */\r
+function note_delete($noteid) {\r
+    return delete_records_select('post', 'id=' . $noteid . ' AND module="notes"');\r
+}\r
+\r
+/**\r
+ * Converts a rating value to its corespondent name\r
+ *\r
+ * @param int    $rating rating value to convert\r
+ * @return string corespondent rating name\r
+ */\r
+function note_get_rating_name($rating) {\r
+    // cache rating names\r
+    static $ratings;\r
+    if (empty($ratings)) {\r
+        $ratings =& note_get_rating_names();\r
+    }\r
+    return @$ratings[$rating];\r
+}\r
+\r
+/**\r
+ * Returns an array of mappings from rating values to rating names\r
+ *\r
+ * @return array of mappings\r
+ */\r
+function note_get_rating_names() {\r
+    return array(\r
+        1 => get_string('low', 'notes'),\r
+        2 => get_string('belownormal', 'notes'),\r
+        3 => get_string('normal', 'notes'),\r
+        4 => get_string('abovenormal', 'notes'),\r
+        5 => get_string('high', 'notes'),\r
+    );\r
+}\r
+\r
+/**\r
+ * Converts a state value to its corespondent name\r
+ *\r
+ * @param string  $state state value to convert\r
+ * @return string corespondent state name\r
+ */\r
+function note_get_state_name($state) {\r
+    // cache state names\r
+    static $states;\r
+    if (empty($states)) {\r
+        $states = note_get_state_names();\r
+    }\r
+    return @$states[$state];\r
+}\r
+\r
+/**\r
+ * Returns an array of mappings from state values to state names\r
+ *\r
+ * @return array of mappings\r
+ */\r
+function note_get_state_names() {\r
+    return array(\r
+        NOTES_STATE_DRAFT => get_string('personal', 'notes'),\r
+        NOTES_STATE_PUBLIC => get_string('course', 'notes'),\r
+        NOTES_STATE_SITE => get_string('site', 'notes'),\r
+    );\r
+}\r
+\r
+/**\r
+ * Prints a note object\r
+ *\r
+ * @param note  $note the note object to print\r
+ * @param int   $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print\r
+ */\r
+function note_print($note, $detail = NOTES_SHOW_FULL) {\r
+\r
+    global $CFG, $USER;\r
+    $user = get_record('user','id',$note->userid);\r
+    $context = get_context_instance(CONTEXT_COURSE, $note->courseid);\r
+    $sitecontext = get_context_instance(CONTEXT_SYSTEM);\r
+    $authoring->name = fullname(get_record('user','id',$note->usermodified));\r
+    $authoring->date = userdate($note->lastmodified);\r
+    echo '<div class="notepost '. $note->publishstate . 'notepost' . \r
+        ($note->usermodified == $USER->id ? ' ownnotepost' : '')  .\r
+        '" id="note-'. $note->id .'">';\r
+\r
+    // print note head (e.g. author, user refering to, rating, etc)\r
+    if($detail & NOTES_SHOW_HEAD) {\r
+        echo '<div class="header">';\r
+        echo '<div class="user">';\r
+        print_user_picture($user->id, $note->courseid, $user->picture);\r
+        echo fullname($user) . '</div>';\r
+        echo '<div class="rating rating' . $note->rating . '">' . get_string('rating', 'notes') . ': ' . note_get_rating_name($note->rating) . '</div>';\r
+        echo '<div class="info">' . \r
+            get_string('bynameondate', 'notes', $authoring) . \r
+            ' (' . get_string('created', 'notes') . ': ' . userdate($note->created) . ')</div>';\r
+        echo '</div>';\r
+    }\r
+    \r
+    // print note content\r
+    if($detail & NOTES_SHOW_BODY) {\r
+        echo '<div class="content">';\r
+        echo format_text($note->content, $note->format);\r
+        echo '</div>';\r
+    }\r
+    \r
+    // print note options (e.g. delete, edit)\r
+    if($detail & NOTES_SHOW_FOOT) {\r
+        if (has_capability('moodle/notes:manage', $sitecontext) && $note->publishstate == NOTES_STATE_SITE || \r
+            has_capability('moodle/notes:manage', $context) && ($note->publishstate == NOTES_STATE_PUBLIC || $note->usermodified == $USER->id)) {\r
+            echo '<div class="footer">';\r
+            echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?note='.$note->id. '">'. get_string('edit') .'</a>';\r
+            echo '<a href="'.$CFG->wwwroot.'/notes/delete.php?note='.$note->id. '">'. get_string('delete') .'</a>';\r
+            echo '</div>';\r
+        }\r
+    }\r
+    echo '</div>';\r
+}\r
+\r
+/**\r
+ * Prints a list of note objects\r
+ *\r
+ * @param array  $notes array of note objects to print\r
+ * @param int   $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print\r
+ */\r
+function note_print_list($notes, $detail = NOTES_SHOW_FULL) {\r
+\r
+    /// Start printing of the note\r
+    echo '<div class="notelist">';\r
+    foreach ($notes as $note) {\r
+        note_print($note, $detail);\r
+    }\r
+    echo '</div>';\r
+}\r
+\r
+/**\r
+ * Retrieves and prints a list of note objects with specific atributes.\r
+ *\r
+ * @param string  $header HTML to print above the list\r
+ * @param object  $context context in which the notes will be displayed (used to check capabilities)\r
+ * @param int     $courseid id of the course in which the notes were posted (0 means any)\r
+ * @param int     $userid id of the user to which the notes refer (0 means any)\r
+ * @param string  $state state of the notes (i.e. draft, public, site) ('' means any)\r
+ * @param int     $author id of the user who modified the note last time (0 means any)\r
+ */\r
+function note_print_notes($header, $context, $courseid = 0, $userid = 0, $state = '', $author = 0)\r
+{\r
+    global $CFG;\r
+    if ($header) {\r
+        echo '<h3 id="notestitle">' . $header . '</h3>';\r
+    }\r
+    if (has_capability('moodle/notes:view', $context)) {\r
+        $notes =& note_list($courseid, $userid, $state, $author);\r
+        if($notes) {\r
+            note_print_list($notes);\r
+        } else {\r
+            echo '<p>' . get_string('nonotes', 'notes') . '</p>';\r
+        }\r
+    } else {\r
+        echo '<p>' . get_string('notesnotvisible', 'notes') . '</p>';\r
+    }\r
+}\r
diff --git a/notes/version.php b/notes/version.php
new file mode 100644 (file)
index 0000000..fe471b8
--- /dev/null
@@ -0,0 +1,9 @@
+<?php   // $Id$\r
+\r
+/////////////////////////////////////////////////////////////////////////////////\r
+///  Code fragment to define the version of the note module\r
+///  This fragment is called by moodle_needs_upgrading() and /admin/index.php\r
+/////////////////////////////////////////////////////////////////////////////////\r
+\r
+$note_version  = 2007070300;  // The current version of note module (Date: YYYYMMDDXX)\r
+$module->cron     = 1800;           // Period for cron to check this module (secs)\r
index d1b8fc8b5bed07dc4fa52dc1d7563cc7ea9622d1..400132642fc42ccd8a9bed0ca244109fe6d2c51a 100644 (file)
@@ -19,6 +19,8 @@
   grades
   login
   message
+  notes
+  mymoodle
   question
   tabs
   user
@@ -2347,6 +2349,52 @@ body#message-messages {
   padding:10px;
 }
 
+/***
+ *** Notes
+ ***/
+.notepost {
+    margin-bottom: 1em;
+    background-color: #F0F0F0;
+}
+.sitenotepost {
+    background-color: #FFFFF0;
+}
+.coursenotepost {
+}
+.draftnotepost {
+    background-color: #F0FFF0;
+}
+
+.ownnotepost .info {
+    font-weight: bolder;
+}
+
+.notepost .header {  
+}
+
+.notepost .user {
+    font-weight: bolder;
+}
+
+.notepost .userpicture {
+    float: left;
+    margin: 5px;
+}
+.notepost .rating5 {
+    color: red;
+}
+.notepost .rating1 {
+    color: orange;
+}
+.notepost .info, .notepost .rating {
+    font-size: smaller;
+}
+
+.notepost .content {
+}
+
+.notepost .footer {
+}
 
 /***
  *** MyMoodle
index 4351c3f3918d4574c54685a520afdd2af4a9467f..9880d356f99d2d35d67ddbdbc7ae0c0c4f862b3c 100644 (file)
@@ -13,6 +13,8 @@ $actions = array(
         'messageselect.php',
         'extendenrol.php',
         'groupextendenrol.php',
+        'addnote.php',
+        'groupaddnote.php',
         );
 
 if (array_search($formaction, $actions) === false) {
diff --git a/user/addnote.php b/user/addnote.php
new file mode 100644 (file)
index 0000000..731e283
--- /dev/null
@@ -0,0 +1,91 @@
+<?php  // $Id$\r
+require_once("../config.php");\r
+require_once($CFG->dirroot .'/notes/lib.php');\r
+\r
+$id    = required_param('id', PARAM_INT);              // course id\r
+$users = optional_param('userid', array(), PARAM_INT); // array of user id\r
+$contents = optional_param('contents', array(), PARAM_RAW); // array of user notes\r
+$ratings = optional_param('ratings', array(), PARAM_INT); // array of notes ratings\r
+$states = optional_param('states', array(), PARAM_ALPHA); // array of notes states\r
+if (! $course = get_record('course', 'id', $id)) {\r
+    error("Course ID is incorrect");\r
+}\r
+\r
+$context = get_context_instance(CONTEXT_COURSE, $id);\r
+require_login($course->id);\r
+\r
+// to create notes the current user needs a capability\r
+require_capability('moodle/notes:manage', $context);\r
+\r
+if (!empty($users) && confirm_sesskey()) {\r
+    if (count($users) != count($contents) || count($users) != count($ratings) || count($users) != count($states)) {\r
+        error('Parameters malformation', $CFG->wwwroot.'/user/index.php?id='.$id);\r
+    }\r
+\r
+    $note = new object();\r
+    $note->courseid = $id;\r
+    $note->format = FORMAT_PLAIN;\r
+    foreach ($users as $k => $v) {\r
+        if(!$user = get_record('user', 'id', $v) || empty($contents[$k])) {\r
+            continue;\r
+        }\r
+        $note->id = 0;\r
+        $note->content = $contents[$k];\r
+        $note->rating = $ratings[$k];\r
+        $note->publishstate = $states[$k];\r
+        $note->userid = $v;\r
+        if (note_save($note)) {\r
+            add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');\r
+        }\r
+    }\r
+    redirect("$CFG->wwwroot/user/index.php?id=$id");\r
+}\r
+\r
+/// Print headers\r
+\r
+$straddnote = get_string('addnewnote', 'notes');\r
+if ($course->id != SITEID) {\r
+    print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname,\r
+    "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".\r
+    $straddnote, "", "", true, "&nbsp;", navmenu($course));\r
+} else {\r
+    print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname,\r
+    $straddnote, "", "", true, "&nbsp;", navmenu($course));\r
+}\r
+\r
+// this will contain all available the based On select options, but we'll disable some on them on a per user basis\r
+\r
+print_heading($straddnote);\r
+echo '<form method="post" action="addnote.php">';\r
+echo '<input type="hidden" name="id" value="'.$course->id.'" />';\r
+echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';\r
+$table->head  = array (get_string('fullname'), get_string('content', 'notes'), get_string('rating', 'notes'), get_string('publishstate', 'notes'), );\r
+$table->align = array ('left', 'center', 'center', 'center');\r
+$rating_names = note_get_rating_names();\r
+$state_names = note_get_state_names();\r
+\r
+// the first time list hack\r
+if (empty($users)) {\r
+    foreach ($_POST as $k => $v) {\r
+        if (preg_match('/^user(\d+)$/',$k,$m)) {\r
+            $users[] = $m[1];\r
+        }\r
+    }\r
+}\r
+\r
+foreach ($users as $k => $v) {\r
+    if(!$user = get_record('user', 'id', $v)) {\r
+        continue;\r
+    }\r
+    $checkbox = choose_from_menu($rating_names, 'ratings[' . $k . ']', empty($ratings[$k]) ? NOTES_RATING_NORMAL : $ratings[$k], '', '', '0', true);\r
+    $checkbox2 = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], '', '', '0', true);\r
+    $table->data[] = array(\r
+        '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),\r
+        '<textarea name="contents['. $k . ']" rows="2" cols="30">' . strip_tags(@$contents[$k]) . '</textarea>',\r
+        $checkbox,\r
+        $checkbox2,\r
+    );\r
+}\r
+print_table($table);\r
+echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';\r
+print_footer($course);\r
diff --git a/user/groupaddnote.php b/user/groupaddnote.php
new file mode 100644 (file)
index 0000000..c0fa956
--- /dev/null
@@ -0,0 +1,90 @@
+<?php  // $Id$\r
+require_once("../config.php");\r
+require_once($CFG->dirroot .'/notes/lib.php');\r
+\r
+$id    = required_param('id', PARAM_INT);              // course id\r
+$users = optional_param('userid', array(), PARAM_INT); // array of user id\r
+$content = optional_param('content', '', PARAM_RAW); // note content\r
+$rating = optional_param('rating', 0, PARAM_INT); // note rating\r
+$state = optional_param('state', '', PARAM_ALPHA); // note publish state\r
+\r
+if (! $course = get_record('course', 'id', $id)) {\r
+    error("Course ID is incorrect");\r
+}\r
+\r
+$context = get_context_instance(CONTEXT_COURSE, $id);\r
+require_login($course->id);\r
+\r
+// to create notes the current user needs a capability\r
+require_capability('moodle/notes:manage', $context);\r
+\r
+if (!empty($users) && !empty($content) && confirm_sesskey()) {\r
+    $note = new object();\r
+    $note->courseid = $id;\r
+    $note->format = FORMAT_PLAIN;\r
+    $note->content = $content;\r
+    $note->rating = $rating;\r
+    $note->publishstate = $state;\r
+    foreach ($users as $k => $v) {\r
+        if(!$user = get_record('user', 'id', $v)) {\r
+            continue;\r
+        }\r
+        $note->id = 0;\r
+        $note->userid = $v;\r
+        if (note_save($note)) {\r
+            add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');\r
+        }\r
+    }\r
+    \r
+    redirect("$CFG->wwwroot/user/index.php?id=$id");\r
+}\r
+\r
+/// Print headers\r
+\r
+$straddnote = get_string('groupaddnewnote', 'notes');\r
+if ($course->id != SITEID) {\r
+    print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname,\r
+    "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".\r
+    $straddnote, "", "", true, "&nbsp;", navmenu($course));\r
+} else {\r
+    print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname,\r
+    $straddnote, "", "", true, "&nbsp;", navmenu($course));\r
+}\r
+\r
+// this will contain all available the based On select options, but we'll disable some on them on a per user basis\r
+\r
+print_heading($straddnote);\r
+echo '<form method="post" action="groupaddnote.php" >';\r
+echo '<div style="width:100%;text-align:center;">';\r
+echo '<input type="hidden" name="id" value="'.$course->id.'" />';\r
+echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';\r
+$rating_names = note_get_rating_names();\r
+$state_names = note_get_state_names();\r
+\r
+// the first time list hack\r
+if (empty($users)) {\r
+    foreach ($_POST as $k => $v) {\r
+        if (preg_match('/^user(\d+)$/',$k,$m)) {\r
+            $users[] = $m[1];\r
+        }\r
+    }\r
+}\r
+\r
+$userlist = array();\r
+foreach ($users as $k => $v) {\r
+    if(!$user = get_record('user', 'id', $v)) {\r
+        continue;\r
+    }\r
+    echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';\r
+    $userlist[] = fullname($user, true);\r
+}\r
+echo '<p>';\r
+echo get_string('users'). ': ' . implode(', ', $userlist) . '.';\r
+echo '</p>';\r
+\r
+echo '<p>' . get_string('content', 'notes') . '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';\r
+echo '<p>' . get_string('rating', 'notes') . ' ' . choose_from_menu($rating_names, 'rating', empty($rating) ? NOTES_RATING_NORMAL : $rating, '', '', '0', true) . '</p>';\r
+echo '<p>' . get_string('publishstate', 'notes') . ' ' . choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, '', '', '0', true) . '</p>';\r
+\r
+echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';\r
+print_footer($course);\r
index 1beca2599b9caa209f2a8325e871c91352540194..9537a78c0dfaa6e4722064e3a57b23e944a7eb6e 100644 (file)
         if (has_capability('moodle/site:readallmessages', $context) && !empty($CFG->messaging)) {
             $displaylist['messageselect.php'] = get_string('messageselectadd');
         }
-        
+        if (has_capability('moodle/notes:manage', $context)) {
+            $displaylist['addnote.php'] = get_string('addnewnote', 'notes');
+            $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
+        }
         $displaylist['extendenrol.php'] = get_string('extendenrol');
         $displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
         
index 9e47313dc181348a665e9904d74601ab3f69896c..71c4103cb9acb169bf8fc109c2d9a9123899ac17 100644 (file)
     } else if ($filtertype == 'course' && $filterselect) {
 
         $course = get_record('course','id',$filterselect);
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         print_heading(format_string($course->fullname));
 
-        if ($CFG->bloglevel >= 3) {
-
-            $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect.'&amp;group=0',
-                get_string('participants'));    //the groupid hack is necessary, otherwise the group in the session willbe used
+        $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect.'&amp;group=0',
+            get_string('participants'));    //the groupid hack is necessary, otherwise the group in the session willbe used
         
+        if ($CFG->bloglevel >= 3) {
             $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=course&amp;filterselect='.$filterselect, get_string('blogs','blog'));
         }
 
+        if (has_capability('moodle/notes:manage', $coursecontext) || has_capability('moodle/notes:view', $coursecontext)) {
+            $toprow[] = new tabobject('notes', $CFG->wwwroot.'/notes/index.php?filtertype=course&amp;filterselect=' . $filterselect, get_string('notes', 'notes'));
+        }
+
     /**************************************
      * Group Level participation or Blogs  *
      **************************************/
             $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?userid='.$user->id.'&amp;courseid='.$course->id, get_string('blog', 'blog'));
         }
 
+        if (has_capability('moodle/notes:manage', $coursecontext) || has_capability('moodle/notes:view', $coursecontext)) {
+            $toprow[] = new tabobject('notes', $CFG->wwwroot.'/notes/index.php?course='.$course->id . '&amp;user=' . $user->id, get_string('notes', 'notes'));
+        }
+
     /// Current user must be teacher of the course or the course allows user to view their reports
     
     //print_object($course);