| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: addnote.php,v 1.5.2.1 2008/03/24 23:05:13 stronk7 Exp $ 2 require_once("../config.php"); 3 require_once($CFG->dirroot .'/notes/lib.php'); 4 5 $id = required_param('id', PARAM_INT); // course id 6 $users = optional_param('userid', array(), PARAM_INT); // array of user id 7 $contents = optional_param('contents', array(), PARAM_RAW); // array of user notes 8 $states = optional_param('states', array(), PARAM_ALPHA); // array of notes states 9 if (! $course = get_record('course', 'id', $id)) { 10 error("Course ID is incorrect"); 11 } 12 13 $context = get_context_instance(CONTEXT_COURSE, $id); 14 require_login($course->id); 15 16 // to create notes the current user needs a capability 17 require_capability('moodle/notes:manage', $context); 18 19 if (!empty($users) && confirm_sesskey()) { 20 if (count($users) != count($contents) || count($users) != count($states)) { 21 error('Parameters malformation', $CFG->wwwroot.'/user/index.php?id='.$id); 22 } 23 24 $note = new object(); 25 $note->courseid = $id; 26 $note->format = FORMAT_PLAIN; 27 foreach ($users as $k => $v) { 28 if(!$user = get_record('user', 'id', $v) || empty($contents[$k])) { 29 continue; 30 } 31 $note->id = 0; 32 $note->content = $contents[$k]; 33 $note->publishstate = $states[$k]; 34 $note->userid = $v; 35 if (note_save($note)) { 36 add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); 37 } 38 } 39 redirect("$CFG->wwwroot/user/index.php?id=$id"); 40 } 41 42 /// Print headers 43 44 $straddnote = get_string('addnewnote', 'notes'); 45 46 $navlinks = array(); 47 $navlinks[] = array('name' => $straddnote, 'link' => null, 'type' => 'misc'); 48 $navigation = build_navigation($navlinks); 49 50 print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname, $navigation, "", "", true, " ", navmenu($course)); 51 52 // this will contain all available the based On select options, but we'll disable some on them on a per user basis 53 54 print_heading($straddnote); 55 echo '<form method="post" action="addnote.php">'; 56 echo '<fieldset class="invisiblefieldset">'; 57 echo '<input type="hidden" name="id" value="'.$course->id.'" />'; 58 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'; 59 echo '</fieldset>'; 60 $table->head = array (get_string('fullname'), 61 get_string('content', 'notes') . helpbutton('writing', get_string('helpwriting'), 'moodle', true, false, '', true), 62 get_string('publishstate', 'notes') . helpbutton('status', get_string('publishstate', 'notes'), 'notes', true, false, '', true), 63 ); 64 $table->align = array ('left', 'center', 'center'); 65 $state_names = note_get_state_names(); 66 67 // the first time list hack 68 if (empty($users)) { 69 foreach ($_POST as $k => $v) { 70 if (preg_match('/^user(\d+)$/',$k,$m)) { 71 $users[] = $m[1]; 72 } 73 } 74 } 75 76 foreach ($users as $k => $v) { 77 if(!$user = get_record('user', 'id', $v)) { 78 continue; 79 } 80 $checkbox = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], '', '', '0', true); 81 $table->data[] = array( 82 '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true), 83 '<textarea name="contents['. $k . ']" rows="2" cols="40">' . strip_tags(@$contents[$k]) . '</textarea>', 84 $checkbox 85 ); 86 } 87 print_table($table); 88 echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>'; 89 print_footer($course); 90 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |