From c55dee3fa9ae35e7d688074e087790053d656472 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Fri, 13 Jul 2007 08:26:47 +0000 Subject: [PATCH] MDL-10181, user management improvements fixes --- lang/en_utf8/help/notes.php | 30 +++++++++++++ lang/en_utf8/help/notes/status.html | 8 ++++ notes/add.php | 10 +++-- notes/delete.php | 9 +++- notes/edit.php | 8 ++-- notes/edit_form.php | 15 +++---- notes/index.php | 33 +++++++++----- notes/lib.php | 67 ++++++----------------------- notes/version.php | 2 +- theme/standard/styles_layout.css | 18 ++++---- user/addnote.php | 20 ++++----- user/groupaddnote.php | 16 ++++--- 12 files changed, 127 insertions(+), 109 deletions(-) create mode 100755 lang/en_utf8/help/notes.php create mode 100755 lang/en_utf8/help/notes/status.html diff --git a/lang/en_utf8/help/notes.php b/lang/en_utf8/help/notes.php new file mode 100755 index 0000000000..7840ca69e6 --- /dev/null +++ b/lang/en_utf8/help/notes.php @@ -0,0 +1,30 @@ +name - $a->date'; +$string['publishstate'] = 'Status'; +$string['personal'] = 'personal'; +$string['course'] = 'course'; +$string['site'] = 'site'; \ No newline at end of file diff --git a/lang/en_utf8/help/notes/status.html b/lang/en_utf8/help/notes/status.html new file mode 100755 index 0000000000..1034e93614 --- /dev/null +++ b/lang/en_utf8/help/notes/status.html @@ -0,0 +1,8 @@ +

Status

+ +

There are 3 possible settings here

+ \ No newline at end of file diff --git a/notes/add.php b/notes/add.php index 60fbb91d3c..5dfebf3f8c 100644 --- a/notes/add.php +++ b/notes/add.php @@ -11,6 +11,8 @@ $userid = optional_param('user', 0, PARAM_INT); if (!($course = get_record('course', 'id', $courseid))) { error('Incorrect course id found'); } +// require login to access notes +require_login($course->id); // locate context information $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -46,7 +48,6 @@ if ($formdata = $noteform->get_data()) { $note->courseid = $formdata->course; $note->content = $formdata->content; $note->format = FORMAT_PLAIN; - $note->rating = $formdata->rating; $note->userid = $formdata->user; $note->publishstate = $formdata->publishstate; if (note_save($note)) { @@ -65,12 +66,13 @@ if($noteform->is_submitted()) { $note->id = 0; $note->course = $courseid; $note->user = $userid; - + $note->publishstate = optional_param('state', NOTES_STATE_PUBLIC, PARAM_ALPHA); } $noteform->set_data($note); -$strnotes = get_string('notes', 'notes'); +$strnotes = get_string('addnewnote', 'notes'); // output HTML -print_header($course->shortname . ': ' . $strnotes, $course->fullname); +$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); +print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs)); $noteform->display(); print_footer(); diff --git a/notes/delete.php b/notes/delete.php index e7de35cda9..574d7d270c 100644 --- a/notes/delete.php +++ b/notes/delete.php @@ -15,6 +15,8 @@ if (!$note = note_load($noteid)) { if (!$course = get_record('course', 'id', $note->courseid)) { error('Incorrect course id found'); } +// require login to access notes +require_login($course->id); // locate context information $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -38,9 +40,12 @@ if (data_submitted() && confirm_sesskey()) { $strnotes = get_string('notes', 'notes'); $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey()); $optionsno = array('course'=>$course->id, 'user'=>$note->userid); - print_header($course->shortname . ': ' . $strnotes, $course->fullname); + +// output HTML + $crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); + print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs)); notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get'); echo '
'; note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD); print_footer(); -} +} \ No newline at end of file diff --git a/notes/edit.php b/notes/edit.php index 48c04d4291..e16b867e41 100644 --- a/notes/edit.php +++ b/notes/edit.php @@ -15,6 +15,8 @@ if (!$note = note_load($noteid)) { if (!$course = get_record('course', 'id', $note->courseid)) { error('Incorrect course id found'); } +// require login to access notes +require_login($course->id); // locate context information $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -54,7 +56,6 @@ if ($formdata = $noteform->get_data()){ $note->userid = $formdata->user; $note->content = $formdata->content; $note->format = FORMAT_PLAIN; - $note->rating = $formdata->rating; $note->publishstate = $formdata->publishstate; if (note_save($note)) { add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id, 'update note'); @@ -74,9 +75,10 @@ if($noteform->is_submitted()) { $note->note = $note->id; } $noteform->set_data($note); -$strnotes = get_string('notes', 'notes'); +$strnotes = get_string('editnote', 'notes'); // output HTML -print_header($course->shortname . ': ' . $strnotes, $course->fullname); +$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); +print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs)); $noteform->display(); print_footer(); diff --git a/notes/edit_form.php b/notes/edit_form.php index 0816f1c661..30638a9223 100644 --- a/notes/edit_form.php +++ b/notes/edit_form.php @@ -6,23 +6,22 @@ class note_edit_form extends moodleform { function definition() { $mform =& $this->_form; - - $mform->addElement('header', 'general', get_string('general', 'form')); + $strcontent = get_string('content', 'notes'); + $strpublishstate = get_string('publishstate', 'notes'); + $mform->addElement('header', 'general', get_string('note', 'notes')); $mform->addElement('select', 'user', get_string('user'), $this->_customdata['userlist']); $mform->addRule('user', get_string('nouser', 'notes'), 'required', null, 'client'); - $mform->addElement('textarea', 'content', get_string('content', 'notes'), array('rows'=>15, 'cols'=>40)); + $mform->addElement('textarea', 'content', $strcontent, array('rows'=>15, 'cols'=>40)); $mform->setType('content', PARAM_RAW); $mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client'); - $mform->setHelpButton('content', array('writing', 'richtext'), false, 'editorhelpbutton'); - - $mform->addElement('select', 'rating', get_string('rating', 'notes'), note_get_rating_names()); - $mform->setDefault('rating', 3); + $mform->setHelpButton('content', 'writing'); - $mform->addElement('select', 'publishstate', get_string('publishstate', 'notes'), note_get_state_names()); + $mform->addElement('select', 'publishstate', $strpublishstate, note_get_state_names()); $mform->setDefault('publishstate', NOTES_STATE_PUBLIC); $mform->setType('publishstate', PARAM_ALPHA); + $mform->setHelpButton('publishstate', array('status', $strpublishstate, 'notes')); $this->add_action_buttons(); diff --git a/notes/index.php b/notes/index.php index 1720558742..021be395db 100644 --- a/notes/index.php +++ b/notes/index.php @@ -51,27 +51,38 @@ print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_nav require_once($CFG->dirroot .'/user/tabs.php'); +$strsitenotes = get_string('sitenotes', 'notes'); +$strcoursenotes = get_string('coursenotes', 'notes'); +$strpersonalnotes = get_string('personalnotes', 'notes'); +$straddnewnote = get_string('addnewnote', 'notes'); + if($courseid != SITEID) { + echo '' . $strsitenotes . ' | ' . $strcoursenotes . ' | ' . $strpersonalnotes . ''; $context = get_context_instance(CONTEXT_COURSE, $courseid); - if (has_capability('moodle/notes:manage', $context)) { - $addlink = $CFG->wwwroot .'/notes/add.php?course=' . $courseid . '&user=' . $userid; - echo '

' . get_string('addnewnote', 'notes') . '

'; - } - note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0); - note_print_notes(get_string('coursenotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_PUBLIC, 0); - note_print_notes(get_string('personalnotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id); + $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0; + $view = has_capability('moodle/notes:view', $context); + note_print_notes('' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0); + note_print_notes('' . $strcoursenotes, $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0); + note_print_notes('' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id); } else { - $context = get_context_instance(CONTEXT_SYSTEM); - note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0); + echo '' . $strsitenotes . ' | ' . $strcoursenotes . ''; + $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM)); + note_print_notes('' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0); + echo ''; if($userid) { $courses = get_my_courses($userid); foreach($courses as $c) { $header = '' . $c->fullname . ''; - note_print_notes($header, $context, $c->id, $userid, NOTES_STATE_PUBLIC, 0); + if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) { + $addid = $c->id; + }else { + $addid = 0; + } + note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0); } } } add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes'); -print_footer($course); +print_footer($course); \ No newline at end of file diff --git a/notes/lib.php b/notes/lib.php index b097580ceb..7dfd6ffdd8 100644 --- a/notes/lib.php +++ b/notes/lib.php @@ -4,15 +4,6 @@ * Library of functions and constants for notes */ -/** - * Constants for ratings. - */ -define('NOTES_RATING_LOW', '1'); -define('NOTES_RATING_BELOWNORMAL', '2'); -define('NOTES_RATING_NORMAL', '3'); -define('NOTES_RATING_ABOVENORMAL', '4'); -define('NOTES_RATING_HIGH', '5'); - /** * Constants for states. */ @@ -57,7 +48,7 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las } $selects[] = 'module="notes"'; $select = implode(' AND ', $selects); - $fields = 'id,courseid,userid,content,format,rating,created,lastmodified,usermodified,publishstate'; + $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate'; // retrieve data $rs =& get_recordset_select('post', $select, $order, $fields, $limitfrom, $limitnum); return recordset_to_array($rs); @@ -70,7 +61,7 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las * @return note object */ function note_load($note_id) { - $fields = 'id,courseid,userid,content,format,rating,created,lastmodified,usermodified,publishstate'; + $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate'; return get_record_select('post', 'id=' . $note_id . ' AND module="notes"', $fields); } @@ -87,9 +78,6 @@ function note_save(&$note) { $note->module = 'notes'; $note->lastmodified = time(); $note->usermodified = $USER->id; - if(empty($note->rating)) { - $note->rating = NOTES_RATING_NORMAL; - } if(empty($note->format)) { $note->format = FORMAT_PLAIN; } @@ -124,36 +112,6 @@ function note_delete($noteid) { return delete_records_select('post', 'id=' . $noteid . ' AND module="notes"'); } -/** - * Converts a rating value to its corespondent name - * - * @param int $rating rating value to convert - * @return string corespondent rating name - */ -function note_get_rating_name($rating) { - // cache rating names - static $ratings; - if (empty($ratings)) { - $ratings =& note_get_rating_names(); - } - return @$ratings[$rating]; -} - -/** - * Returns an array of mappings from rating values to rating names - * - * @return array of mappings - */ -function note_get_rating_names() { - return array( - 1 => get_string('low', 'notes'), - 2 => get_string('belownormal', 'notes'), - 3 => get_string('normal', 'notes'), - 4 => get_string('abovenormal', 'notes'), - 5 => get_string('high', 'notes'), - ); -} - /** * Converts a state value to its corespondent name * @@ -200,13 +158,12 @@ function note_print($note, $detail = NOTES_SHOW_FULL) { ($note->usermodified == $USER->id ? ' ownnotepost' : '') . '" id="note-'. $note->id .'">'; - // print note head (e.g. author, user refering to, rating, etc) + // print note head (e.g. author, user refering to, etc) if($detail & NOTES_SHOW_HEAD) { echo '
'; echo '
'; print_user_picture($user->id, $note->courseid, $user->picture); echo fullname($user) . '
'; - echo '
' . get_string('rating', 'notes') . ': ' . note_get_rating_name($note->rating) . '
'; echo '
' . get_string('bynameondate', 'notes', $authoring) . ' (' . get_string('created', 'notes') . ': ' . userdate($note->created) . ')
'; @@ -224,10 +181,10 @@ function note_print($note, $detail = NOTES_SHOW_FULL) { if($detail & NOTES_SHOW_FOOT) { if (has_capability('moodle/notes:manage', $sitecontext) && $note->publishstate == NOTES_STATE_SITE || has_capability('moodle/notes:manage', $context) && ($note->publishstate == NOTES_STATE_PUBLIC || $note->usermodified == $USER->id)) { - echo ''; } } echo '
'; @@ -253,19 +210,23 @@ function note_print_list($notes, $detail = NOTES_SHOW_FULL) { * Retrieves and prints a list of note objects with specific atributes. * * @param string $header HTML to print above the list - * @param object $context context in which the notes will be displayed (used to check capabilities) + * @param int $addcourseid id of the course for the add notes link (0 hide link) + * @param boolean $viewnotes true if the notes should be printed; false otherwise (print notesnotvisible string) * @param int $courseid id of the course in which the notes were posted (0 means any) * @param int $userid id of the user to which the notes refer (0 means any) * @param string $state state of the notes (i.e. draft, public, site) ('' means any) * @param int $author id of the user who modified the note last time (0 means any) */ -function note_print_notes($header, $context, $courseid = 0, $userid = 0, $state = '', $author = 0) +function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0) { global $CFG; if ($header) { echo '

' . $header . '

'; } - if (has_capability('moodle/notes:view', $context)) { + if ($addcourseid) { + echo '

' . get_string('addnewnote', 'notes') . '

'; + } + if ($viewnotes) { $notes =& note_list($courseid, $userid, $state, $author); if($notes) { note_print_list($notes); @@ -275,4 +236,4 @@ function note_print_notes($header, $context, $courseid = 0, $userid = 0, $state } else { echo '

' . get_string('notesnotvisible', 'notes') . '

'; } -} +} \ No newline at end of file diff --git a/notes/version.php b/notes/version.php index fe471b86d9..1b804de7b1 100644 --- a/notes/version.php +++ b/notes/version.php @@ -5,5 +5,5 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$note_version = 2007070300; // The current version of note module (Date: YYYYMMDDXX) +$note_version = 2007070700; // The current version of note module (Date: YYYYMMDDXX) $module->cron = 1800; // Period for cron to check this module (secs) diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index cee5b695e7..d9573842d2 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -2377,10 +2377,9 @@ body#message-messages { ***/ .notepost { margin-bottom: 1em; - background-color: #F0F0F0; + background-color: #EEE; } .sitenotepost { - background-color: #FFFFF0; } .coursenotepost { } @@ -2393,6 +2392,8 @@ body#message-messages { } .notepost .header { + background: #DDD; + padding: 5px; } .notepost .user { @@ -2401,22 +2402,19 @@ body#message-messages { .notepost .userpicture { float: left; - margin: 5px; + margin-right: 5px; } -.notepost .rating5 { - color: red; -} -.notepost .rating1 { - color: orange; -} -.notepost .info, .notepost .rating { + +.notepost .info { font-size: smaller; } .notepost .content { + clear: both; } .notepost .footer { + clear: both; } /*** diff --git a/user/addnote.php b/user/addnote.php index 731e283bf1..07adf8127d 100644 --- a/user/addnote.php +++ b/user/addnote.php @@ -5,7 +5,6 @@ require_once($CFG->dirroot .'/notes/lib.php'); $id = required_param('id', PARAM_INT); // course id $users = optional_param('userid', array(), PARAM_INT); // array of user id $contents = optional_param('contents', array(), PARAM_RAW); // array of user notes -$ratings = optional_param('ratings', array(), PARAM_INT); // array of notes ratings $states = optional_param('states', array(), PARAM_ALPHA); // array of notes states if (! $course = get_record('course', 'id', $id)) { error("Course ID is incorrect"); @@ -18,7 +17,7 @@ require_login($course->id); require_capability('moodle/notes:manage', $context); if (!empty($users) && confirm_sesskey()) { - if (count($users) != count($contents) || count($users) != count($ratings) || count($users) != count($states)) { + if (count($users) != count($contents) || count($users) != count($states)) { error('Parameters malformation', $CFG->wwwroot.'/user/index.php?id='.$id); } @@ -31,7 +30,6 @@ if (!empty($users) && confirm_sesskey()) { } $note->id = 0; $note->content = $contents[$k]; - $note->rating = $ratings[$k]; $note->publishstate = $states[$k]; $note->userid = $v; if (note_save($note)) { @@ -59,9 +57,11 @@ print_heading($straddnote); echo '
'; echo ''; echo ''; -$table->head = array (get_string('fullname'), get_string('content', 'notes'), get_string('rating', 'notes'), get_string('publishstate', 'notes'), ); -$table->align = array ('left', 'center', 'center', 'center'); -$rating_names = note_get_rating_names(); +$table->head = array (get_string('fullname'), + get_string('content', 'notes') . helpbutton('writing', get_string('helpwriting'), 'moodle', true, false, '', true), + get_string('publishstate', 'notes') . helpbutton('status', get_string('publishstate', 'notes'), 'notes', true, false, '', true), + ); +$table->align = array ('left', 'center', 'center'); $state_names = note_get_state_names(); // the first time list hack @@ -77,13 +77,11 @@ foreach ($users as $k => $v) { if(!$user = get_record('user', 'id', $v)) { continue; } - $checkbox = choose_from_menu($rating_names, 'ratings[' . $k . ']', empty($ratings[$k]) ? NOTES_RATING_NORMAL : $ratings[$k], '', '', '0', true); - $checkbox2 = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], '', '', '0', true); + $checkbox = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], '', '', '0', true); $table->data[] = array( ''. fullname($user, true), - '', - $checkbox, - $checkbox2, + '', + $checkbox ); } print_table($table); diff --git a/user/groupaddnote.php b/user/groupaddnote.php index c0fa9562c0..4b88a9d1c5 100644 --- a/user/groupaddnote.php +++ b/user/groupaddnote.php @@ -5,7 +5,6 @@ require_once($CFG->dirroot .'/notes/lib.php'); $id = required_param('id', PARAM_INT); // course id $users = optional_param('userid', array(), PARAM_INT); // array of user id $content = optional_param('content', '', PARAM_RAW); // note content -$rating = optional_param('rating', 0, PARAM_INT); // note rating $state = optional_param('state', '', PARAM_ALPHA); // note publish state if (! $course = get_record('course', 'id', $id)) { @@ -23,7 +22,6 @@ if (!empty($users) && !empty($content) && confirm_sesskey()) { $note->courseid = $id; $note->format = FORMAT_PLAIN; $note->content = $content; - $note->rating = $rating; $note->publishstate = $state; foreach ($users as $k => $v) { if(!$user = get_record('user', 'id', $v)) { @@ -58,7 +56,6 @@ echo ''; echo '
'; echo ''; echo ''; -$rating_names = note_get_rating_names(); $state_names = note_get_state_names(); // the first time list hack @@ -70,6 +67,8 @@ if (empty($users)) { } } +$strpublishstate = get_string('publishstate', 'notes'); + $userlist = array(); foreach ($users as $k => $v) { if(!$user = get_record('user', 'id', $v)) { @@ -82,9 +81,14 @@ echo '

'; echo get_string('users'). ': ' . implode(', ', $userlist) . '.'; echo '

'; -echo '

' . get_string('content', 'notes') . '

'; -echo '

' . get_string('rating', 'notes') . ' ' . choose_from_menu($rating_names, 'rating', empty($rating) ? NOTES_RATING_NORMAL : $rating, '', '', '0', true) . '

'; -echo '

' . get_string('publishstate', 'notes') . ' ' . choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, '', '', '0', true) . '

'; +echo '

' . get_string('content', 'notes'); +helpbutton('writing', get_string('helpwriting')); +echo '

'; + +echo '

' . $strpublishstate; +helpbutton('status', $strpublishstate, 'notes'); +choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, ''); +echo '

'; echo '
'; print_footer($course); -- 2.39.5