From 83e70cc299a8c75e9766b123783d56b3ee93e016 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 31 Aug 2007 04:05:11 +0000 Subject: [PATCH] Some cleaning up of the notes interface and conversion from DOS to unix --- notes/add.php | 156 +++++----- notes/delete.php | 100 +++---- notes/edit.php | 168 +++++------ notes/edit_form.php | 68 ++--- notes/index.php | 187 ++++++------ notes/lib.php | 482 ++++++++++++++++--------------- notes/version.php | 18 +- theme/standard/styles_layout.css | 14 +- 8 files changed, 609 insertions(+), 584 deletions(-) diff --git a/notes/add.php b/notes/add.php index 5dfebf3f8cf..c24c01470e4 100644 --- a/notes/add.php +++ b/notes/add.php @@ -1,78 +1,78 @@ -id); - -// locate context information -$context = get_context_instance(CONTEXT_COURSE, $course->id); - -// check capability -if (!has_capability('moodle/notes:manage', $context)) { - error('You may not create notes'); -} - -// build-up form -require_once('edit_form.php'); -// get option values for the user select -$extradata['userlist'] = array(); -$usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})"; -$userlist = get_records_sql($usersincourse); -// format userdata using fullname -if($userlist) { - foreach($userlist as $user) { - $extradata['userlist'][$user->id] = fullname($user); - } -} -// create form -$noteform = new note_edit_form(null, $extradata); - -// if form was cancelled then return to the previous notes list -if ($noteform->is_cancelled()) { - redirect($CFG->wwwroot . '/notes/index.php?course=' . $courseid . '&user=' . $userid); -} - -// if data was submitted and validated, then save it to database -if ($formdata = $noteform->get_data()) { - $note = new object(); - $note->courseid = $formdata->course; - $note->content = $formdata->content; - $note->format = FORMAT_PLAIN; - $note->userid = $formdata->user; - $note->publishstate = $formdata->publishstate; - if (note_save($note)) { - add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); - } -// redirect to notes list that contains this note - redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); -} - -if($noteform->is_submitted()) { -// if data was submitted with errors, then use it as default for new form - $note = $noteform->get_submitted_data(false); -} else { -// if data was not submitted yet, then use default values - $note = new object(); - $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('addnewnote', 'notes'); - -// output HTML -$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); -print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs)); -$noteform->display(); -print_footer(); +id); + +// locate context information +$context = get_context_instance(CONTEXT_COURSE, $course->id); + +// check capability +if (!has_capability('moodle/notes:manage', $context)) { + error('You may not create notes'); +} + +// build-up form +require_once('edit_form.php'); +// get option values for the user select +$extradata['userlist'] = array(); +$usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})"; +$userlist = get_records_sql($usersincourse); +// format userdata using fullname +if($userlist) { + foreach($userlist as $user) { + $extradata['userlist'][$user->id] = fullname($user); + } +} +// create form +$noteform = new note_edit_form(null, $extradata); + +// if form was cancelled then return to the previous notes list +if ($noteform->is_cancelled()) { + redirect($CFG->wwwroot . '/notes/index.php?course=' . $courseid . '&user=' . $userid); +} + +// if data was submitted and validated, then save it to database +if ($formdata = $noteform->get_data()) { + $note = new object(); + $note->courseid = $formdata->course; + $note->content = $formdata->content; + $note->format = FORMAT_PLAIN; + $note->userid = $formdata->user; + $note->publishstate = $formdata->publishstate; + if (note_save($note)) { + add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); + } +// redirect to notes list that contains this note + redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); +} + +if($noteform->is_submitted()) { +// if data was submitted with errors, then use it as default for new form + $note = $noteform->get_submitted_data(false); +} else { +// if data was not submitted yet, then use default values + $note = new object(); + $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('addnewnote', 'notes'); + +// output HTML +$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 574d7d270cb..a0991cddb8f 100644 --- a/notes/delete.php +++ b/notes/delete.php @@ -1,51 +1,51 @@ -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); - -// check capability -if (!has_capability('moodle/notes:manage', $context)) { - error('You may not delete this note'); -} - -if (data_submitted() && confirm_sesskey()) { -//if data was submitted and is valid, then delete note - $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid; - if (note_delete($noteid)) { - add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'delete note'); - } else { - error('Error occured while deleting post', $returnurl); - } - redirect($returnurl); -} else { -// if data was not submitted yet, then show note data with a delete confirmation form - $strnotes = get_string('notes', 'notes'); - $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey()); - $optionsno = array('course'=>$course->id, 'user'=>$note->userid); - -// 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(); +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); + +// check capability +if (!has_capability('moodle/notes:manage', $context)) { + error('You may not delete this note'); +} + +if (data_submitted() && confirm_sesskey()) { +//if data was submitted and is valid, then delete note + $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid; + if (note_delete($noteid)) { + add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'delete note'); + } else { + error('Error occured while deleting post', $returnurl); + } + redirect($returnurl); +} else { +// if data was not submitted yet, then show note data with a delete confirmation form + $strnotes = get_string('notes', 'notes'); + $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey()); + $optionsno = array('course'=>$course->id, 'user'=>$note->userid); + +// 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 e16b867e415..f8b6f92b18c 100644 --- a/notes/edit.php +++ b/notes/edit.php @@ -1,84 +1,84 @@ -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); - -// check capability -if (!has_capability('moodle/notes:manage', $context)) { - error('You may not modify notes'); -} - -// build-up form -require_once('edit_form.php'); -// get option values for the user select -$extradata['userlist'] = array(); -if ($course->id == SITEID) { - $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id={$userid}"; -} else { - $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})"; -} -$userlist = get_records_sql($usersincourse); -// format userdata using fullname -if($userlist) { - foreach($userlist as $user) { - $extradata['userlist'][$user->id] = fullname($user); - } -} -// create form -$noteform = new note_edit_form(null, $extradata); - -// if form was cancelled then return to the notes list of the note -if ($noteform->is_cancelled()) { - redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); -} - -// if data was submitted and validated, then save it to database -if ($formdata = $noteform->get_data()){ - $note->courseid = $formdata->course; - $note->userid = $formdata->user; - $note->content = $formdata->content; - $note->format = FORMAT_PLAIN; - $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'); - } -// redirect to notes list that contains this note - redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); -} - - -if($noteform->is_submitted()) { -// if data was submitted with errors, then use it as default for new form - $note = $noteform->get_submitted_data(false); -}else{ -// if data was not submitted yet, then used values retrieved from the database - $note->user = $note->userid; - $note->course = $note->courseid; - $note->note = $note->id; -} -$noteform->set_data($note); -$strnotes = get_string('editnote', 'notes'); - -// output HTML -$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); -print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs)); -$noteform->display(); -print_footer(); +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); + +// check capability +if (!has_capability('moodle/notes:manage', $context)) { + error('You may not modify notes'); +} + +// build-up form +require_once('edit_form.php'); +// get option values for the user select +$extradata['userlist'] = array(); +if ($course->id == SITEID) { + $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id={$userid}"; +} else { + $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})"; +} +$userlist = get_records_sql($usersincourse); +// format userdata using fullname +if($userlist) { + foreach($userlist as $user) { + $extradata['userlist'][$user->id] = fullname($user); + } +} +// create form +$noteform = new note_edit_form(null, $extradata); + +// if form was cancelled then return to the notes list of the note +if ($noteform->is_cancelled()) { + redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); +} + +// if data was submitted and validated, then save it to database +if ($formdata = $noteform->get_data()){ + $note->courseid = $formdata->course; + $note->userid = $formdata->user; + $note->content = $formdata->content; + $note->format = FORMAT_PLAIN; + $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'); + } +// redirect to notes list that contains this note + redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); +} + + +if($noteform->is_submitted()) { +// if data was submitted with errors, then use it as default for new form + $note = $noteform->get_submitted_data(false); +}else{ +// if data was not submitted yet, then used values retrieved from the database + $note->user = $note->userid; + $note->course = $note->courseid; + $note->note = $note->id; +} +$noteform->set_data($note); +$strnotes = get_string('editnote', 'notes'); + +// output HTML +$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 30638a92233..7577e2698fb 100644 --- a/notes/edit_form.php +++ b/notes/edit_form.php @@ -1,34 +1,34 @@ -libdir.'/formslib.php'); - -class note_edit_form extends moodleform { - - function definition() { - $mform =& $this->_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', $strcontent, array('rows'=>15, 'cols'=>40)); - $mform->setType('content', PARAM_RAW); - $mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client'); - $mform->setHelpButton('content', 'writing'); - - $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(); - - $mform->addElement('hidden', 'course'); - $mform->setType('course', PARAM_INT); - - $mform->addElement('hidden', 'note'); - $mform->setType('note', PARAM_INT); - } -} +libdir.'/formslib.php'); + +class note_edit_form extends moodleform { + + function definition() { + $mform =& $this->_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', $strcontent, array('rows'=>15, 'cols'=>40)); + $mform->setType('content', PARAM_RAW); + $mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client'); + $mform->setHelpButton('content', 'writing'); + + $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(); + + $mform->addElement('hidden', 'course'); + $mform->setType('course', PARAM_INT); + + $mform->addElement('hidden', 'note'); + $mform->setType('note', PARAM_INT); + } +} diff --git a/notes/index.php b/notes/index.php index 021be395dbb..7fcc1433105 100644 --- a/notes/index.php +++ b/notes/index.php @@ -1,88 +1,99 @@ -id; -} else { - $filtertype = 'course'; - $filterselect = $course->id; -} - -// require login to access notes -require_login($course->id); -$strnotes = get_string('notes', 'notes'); -$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); -$currenttab = 'notes'; -// output HTML -print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs)); - -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); - $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 { - 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 . ''; - 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); \ No newline at end of file +id; + } else { + $filtertype = 'course'; + $filterselect = $course->id; + } + +/// require login to access notes + require_login($course->id); + add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes'); + + +/// output HTML + + $strnotes = get_string('notes', 'notes'); + $nav = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity')); + + print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav)); + + $currenttab = 'notes'; + 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'); + + print_box_start(); + + if ($courseid != SITEID) { + //echo '' . $strsitenotes . ' | ' . $strcoursenotes . ' | ' . $strpersonalnotes . ''; + $context = get_context_instance(CONTEXT_COURSE, $courseid); + $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 { // Normal course + //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 (!empty($userid)) { + $courses = get_my_courses($userid); + foreach($courses as $c) { + $header = '' . $c->fullname . ''; + 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); + } + } + } + + print_box_end(); + + print_footer($course); +?> diff --git a/notes/lib.php b/notes/lib.php index 7dfd6ffdd83..de2752c6167 100644 --- a/notes/lib.php +++ b/notes/lib.php @@ -1,239 +1,243 @@ -module = 'notes'; - $note->lastmodified = time(); - $note->usermodified = $USER->id; - if(empty($note->format)) { - $note->format = FORMAT_PLAIN; - } - if(empty($note->publishstate)) { - $note->publishstate = NOTES_STATE_PUBLIC; - } - // save data - if(empty($note->id)) { - // insert new note - $note->created = $note->lastmodified; - if($id = insert_record('post', $note)) { - $note->id = $id; - $result = true; - } else { - $result = false; - } - } else { - // update old note - $result = update_record('post', $note); - } - unset($note->module); - return $result; -} - -/** - * Deletes a note object based on its id. - * - * @param int $note_id id of the note to delete - * @return boolean true if the object was deleted; false otherwise - */ -function note_delete($noteid) { - return delete_records_select('post', 'id=' . $noteid . ' AND module="notes"'); -} - -/** - * Converts a state value to its corespondent name - * - * @param string $state state value to convert - * @return string corespondent state name - */ -function note_get_state_name($state) { - // cache state names - static $states; - if (empty($states)) { - $states = note_get_state_names(); - } - return @$states[$state]; -} - -/** - * Returns an array of mappings from state values to state names - * - * @return array of mappings - */ -function note_get_state_names() { - return array( - NOTES_STATE_DRAFT => get_string('personal', 'notes'), - NOTES_STATE_PUBLIC => get_string('course', 'notes'), - NOTES_STATE_SITE => get_string('site', 'notes'), - ); -} - -/** - * Prints a note object - * - * @param note $note the note object to print - * @param int $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print - */ -function note_print($note, $detail = NOTES_SHOW_FULL) { - - global $CFG, $USER; - $user = get_record('user','id',$note->userid); - $context = get_context_instance(CONTEXT_COURSE, $note->courseid); - $sitecontext = get_context_instance(CONTEXT_SYSTEM); - $authoring->name = fullname(get_record('user','id',$note->usermodified)); - $authoring->date = userdate($note->lastmodified); - echo '
'; - - // 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('bynameondate', 'notes', $authoring) . - ' (' . get_string('created', 'notes') . ': ' . userdate($note->created) . ')
'; - echo '
'; - } - - // print note content - if($detail & NOTES_SHOW_BODY) { - echo '
'; - echo format_text($note->content, $note->format); - echo '
'; - } - - // print note options (e.g. delete, edit) - 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 '
'; -} - -/** - * Prints a list of note objects - * - * @param array $notes array of note objects to print - * @param int $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print - */ -function note_print_list($notes, $detail = NOTES_SHOW_FULL) { - - /// Start printing of the note - echo '
'; - foreach ($notes as $note) { - note_print($note, $detail); - } - echo '
'; -} - -/** - * Retrieves and prints a list of note objects with specific atributes. - * - * @param string $header HTML to print above the list - * @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, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0) -{ - global $CFG; - if ($header) { - echo '

' . $header . '

'; - } - if ($addcourseid) { - echo '

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

'; - } - if ($viewnotes) { - $notes =& note_list($courseid, $userid, $state, $author); - if($notes) { - note_print_list($notes); - } else { - echo '

' . get_string('nonotes', 'notes') . '

'; - } - } else { - echo '

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

'; - } -} \ No newline at end of file +module = 'notes'; + $note->lastmodified = time(); + $note->usermodified = $USER->id; + if(empty($note->format)) { + $note->format = FORMAT_PLAIN; + } + if(empty($note->publishstate)) { + $note->publishstate = NOTES_STATE_PUBLIC; + } + // save data + if(empty($note->id)) { + // insert new note + $note->created = $note->lastmodified; + if($id = insert_record('post', $note)) { + $note->id = $id; + $result = true; + } else { + $result = false; + } + } else { + // update old note + $result = update_record('post', $note); + } + unset($note->module); + return $result; +} + +/** + * Deletes a note object based on its id. + * + * @param int $note_id id of the note to delete + * @return boolean true if the object was deleted; false otherwise + */ +function note_delete($noteid) { + return delete_records_select('post', 'id=' . $noteid . ' AND module="notes"'); +} + +/** + * Converts a state value to its corespondent name + * + * @param string $state state value to convert + * @return string corespondent state name + */ +function note_get_state_name($state) { + // cache state names + static $states; + if (empty($states)) { + $states = note_get_state_names(); + } + return @$states[$state]; +} + +/** + * Returns an array of mappings from state values to state names + * + * @return array of mappings + */ +function note_get_state_names() { + return array( + NOTES_STATE_DRAFT => get_string('personal', 'notes'), + NOTES_STATE_PUBLIC => get_string('course', 'notes'), + NOTES_STATE_SITE => get_string('site', 'notes'), + ); +} + +/** + * Prints a note object + * + * @param note $note the note object to print + * @param int $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print + */ +function note_print($note, $detail = NOTES_SHOW_FULL) { + + global $CFG, $USER; + $user = get_record('user','id',$note->userid); + $context = get_context_instance(CONTEXT_COURSE, $note->courseid); + $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $authoring->name = fullname(get_record('user','id',$note->usermodified)); + $authoring->date = userdate($note->lastmodified); + echo '
'; + + // 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('bynameondate', 'notes', $authoring) . + ' (' . get_string('created', 'notes') . ': ' . userdate($note->created) . ')
'; + echo '
'; + } + + // print note content + if($detail & NOTES_SHOW_BODY) { + echo '
'; + echo format_text($note->content, $note->format); + echo '
'; + } + + // print note options (e.g. delete, edit) + 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 '
'; +} + +/** + * Prints a list of note objects + * + * @param array $notes array of note objects to print + * @param int $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print + */ +function note_print_list($notes, $detail = NOTES_SHOW_FULL) { + + /// Start printing of the note + echo '
'; + foreach ($notes as $note) { + note_print($note, $detail); + } + echo '
'; +} + +/** + * Retrieves and prints a list of note objects with specific atributes. + * + * @param string $header HTML to print above the list + * @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, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0) +{ + global $CFG; + if ($header) { + echo '

' . $header . '

'; + echo '
'; + } + if ($addcourseid) { + echo '

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

'; + } + if ($viewnotes) { + $notes =& note_list($courseid, $userid, $state, $author); + if ($notes) { + note_print_list($notes); + } + } else { + echo '

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

'; + } + if ($header) { + echo '
'; // notesgroup + } +} + +?> diff --git a/notes/version.php b/notes/version.php index 1b804de7b19..084a681f323 100644 --- a/notes/version.php +++ b/notes/version.php @@ -1,9 +1,9 @@ -cron = 1800; // Period for cron to check this module (secs) +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 0d770a68fe9..923f7217fd9 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -2496,11 +2496,21 @@ body#message-send .notifysuccess { } .notepost .content { - clear: both; + clear: both; } .notepost .footer { - clear: both; + clear: both; +} + +body.notes .generalbox { + margin-left:auto; + margin-right:auto; + width:90%; +} + +body.notes .notesgroup { + margin-left:20px; } /***