MDL-10181, user management improvements fixes

This commit is contained in:
toyomoyo 2007-07-13 08:26:47 +00:00
parent 0a5a42ed76
commit c55dee3fa9
12 changed files with 127 additions and 109 deletions

30
lang/en_utf8/help/notes.php Executable file
View File

@ -0,0 +1,30 @@
<?php // $Id$
// note.php
$string['note'] = 'Note';
$string['notes'] = 'Notes';
$string['sitenotes'] = 'Site notes';
$string['coursenotes'] = 'Course notes';
$string['personalnotes'] = 'Personal notes';
$string['created'] = 'created';
$string['nonotes'] = 'There are no notes.';
$string['notesnotvisible'] = 'You are not allowed to view the notes.';
$string['addnewnote'] = 'Add a new note';
$string['editnote'] = 'Edit note';
$string['groupaddnewnote'] = 'Add a new note for all';
$string['deleteconfirm'] = 'Delete this note?';
$string['content'] = 'Content';
$string['nocontent'] = 'Note content can not be empty';
$string['nouser'] = 'You must select a user';
$string['rating'] = 'Rating';
$string['low'] = 'low';
$string['belownormal'] = 'below normal';
$string['normal'] = 'normal';
$string['abovenormal'] = 'above normal';
$string['high'] = 'high';
$string['unknown'] = 'unknown';
$string['bynameondate'] = 'by $a->name - $a->date';
$string['publishstate'] = 'Status';
$string['personal'] = 'personal';
$string['course'] = 'course';
$string['site'] = 'site';

View File

@ -0,0 +1,8 @@
<h1>Status</h1>
<p>There are 3 possible settings here</p>
<ul>
<li><strong>Personal</strong> - The note will be visible only to you</li>
<li><strong>Course</strong> - The note will be visible to teachers in this course</li>
<li><strong>Site</strong> - The note will be visible to teachers in all courses</li>
</ul>

View File

@ -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();

View File

@ -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 '<br />';
note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
print_footer();
}
}

View File

@ -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.'&amp;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();

View File

@ -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->setHelpButton('content', 'writing');
$mform->addElement('select', 'rating', get_string('rating', 'notes'), note_get_rating_names());
$mform->setDefault('rating', 3);
$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();

View File

@ -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 '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if (has_capability('moodle/notes:manage', $context)) {
$addlink = $CFG->wwwroot .'/notes/add.php?course=' . $courseid . '&amp;user=' . $userid;
echo '<p><a href="'. $addlink . '">' . get_string('addnewnote', 'notes') . '</a></p>';
}
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('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes, $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
note_print_notes('<a name="personalnotes"></a>' . $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 '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
$view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
echo '<a name="coursenotes"></a>';
if($userid) {
$courses = get_my_courses($userid);
foreach($courses as $c) {
$header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
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.'&amp;user='.$userid, 'view notes');
print_footer($course);
print_footer($course);

View File

@ -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 '<div class="header">';
echo '<div class="user">';
print_user_picture($user->id, $note->courseid, $user->picture);
echo fullname($user) . '</div>';
echo '<div class="rating rating' . $note->rating . '">' . get_string('rating', 'notes') . ': ' . note_get_rating_name($note->rating) . '</div>';
echo '<div class="info">' .
get_string('bynameondate', 'notes', $authoring) .
' (' . get_string('created', 'notes') . ': ' . userdate($note->created) . ')</div>';
@ -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 '<div class="footer">';
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?note='.$note->id. '">'. get_string('edit') .'</a>';
echo '<div class="footer"><p>';
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?note='.$note->id. '">'. get_string('edit') .'</a> | ';
echo '<a href="'.$CFG->wwwroot.'/notes/delete.php?note='.$note->id. '">'. get_string('delete') .'</a>';
echo '</div>';
echo '</p></div>';
}
}
echo '</div>';
@ -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 '<h3 id="notestitle">' . $header . '</h3>';
}
if (has_capability('moodle/notes:view', $context)) {
if ($addcourseid) {
echo '<p><a href="'. $CFG->wwwroot .'/notes/add.php?course=' . $addcourseid . '&amp;user=' . $userid . '&amp;state=' . $state . '">' . get_string('addnewnote', 'notes') . '</a></p>';
}
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 '<p>' . get_string('notesnotvisible', 'notes') . '</p>';
}
}
}

View File

@ -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)

View File

@ -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;
}
/***

View File

@ -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 '<form method="post" action="addnote.php">';
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
$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(
'<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
'<textarea name="contents['. $k . ']" rows="2" cols="30">' . strip_tags(@$contents[$k]) . '</textarea>',
$checkbox,
$checkbox2,
'<textarea name="contents['. $k . ']" rows="2" cols="40">' . strip_tags(@$contents[$k]) . '</textarea>',
$checkbox
);
}
print_table($table);

View File

@ -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 '<form method="post" action="groupaddnote.php" >';
echo '<div style="width:100%;text-align:center;">';
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
$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 '<p>';
echo get_string('users'). ': ' . implode(', ', $userlist) . '.';
echo '</p>';
echo '<p>' . get_string('content', 'notes') . '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';
echo '<p>' . get_string('rating', 'notes') . ' ' . choose_from_menu($rating_names, 'rating', empty($rating) ? NOTES_RATING_NORMAL : $rating, '', '', '0', true) . '</p>';
echo '<p>' . get_string('publishstate', 'notes') . ' ' . choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, '', '', '0', true) . '</p>';
echo '<p>' . get_string('content', 'notes');
helpbutton('writing', get_string('helpwriting'));
echo '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';
echo '<p>' . $strpublishstate;
helpbutton('status', $strpublishstate, 'notes');
choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, '');
echo '</p>';
echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
print_footer($course);