PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/user_bak/groupaddnote.php

https://github.com/henriquecrang/e-UNI
PHP | 96 lines | 73 code | 19 blank | 4 comment | 10 complexity | 3d34b4b1b86d67502767d5ec604539a4 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, BSD-3-Clause
  1. <?php // $Id: groupaddnote.php,v 1.3.2.1 2008/11/30 19:25:49 skodak Exp $
  2. require_once("../config.php");
  3. require_once($CFG->dirroot .'/notes/lib.php');
  4. $id = required_param('id', PARAM_INT); // course id
  5. $users = optional_param('userid', array(), PARAM_INT); // array of user id
  6. $content = optional_param('content', '', PARAM_RAW); // note content
  7. $state = optional_param('state', '', PARAM_ALPHA); // note publish state
  8. if (! $course = get_record('course', 'id', $id)) {
  9. error("Course ID is incorrect");
  10. }
  11. $context = get_context_instance(CONTEXT_COURSE, $id);
  12. require_login($course->id);
  13. // to create notes the current user needs a capability
  14. require_capability('moodle/notes:manage', $context);
  15. if (empty($CFG->enablenotes)) {
  16. print_error('notesdisabled', 'notes');
  17. }
  18. if (!empty($users) && !empty($content) && confirm_sesskey()) {
  19. $note = new object();
  20. $note->courseid = $id;
  21. $note->format = FORMAT_PLAIN;
  22. $note->content = $content;
  23. $note->publishstate = $state;
  24. foreach ($users as $k => $v) {
  25. if(!$user = get_record('user', 'id', $v)) {
  26. continue;
  27. }
  28. $note->id = 0;
  29. $note->userid = $v;
  30. if (note_save($note)) {
  31. add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
  32. }
  33. }
  34. redirect("$CFG->wwwroot/user/index.php?id=$id");
  35. }
  36. /// Print headers
  37. $straddnote = get_string('groupaddnewnote', 'notes');
  38. $navlinks = array();
  39. $navlinks[] = array('name' => $straddnote, 'link' => null, 'type' => 'misc');
  40. $navigation = build_navigation($navlinks);
  41. print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname, $navigation, "", "", true, "&nbsp;", navmenu($course));
  42. // this will contain all available the based On select options, but we'll disable some on them on a per user basis
  43. print_heading($straddnote);
  44. echo '<form method="post" action="groupaddnote.php" >';
  45. echo '<div style="width:100%;text-align:center;">';
  46. echo '<input type="hidden" name="id" value="'.$course->id.'" />';
  47. echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
  48. $state_names = note_get_state_names();
  49. // the first time list hack
  50. if (empty($users)) {
  51. foreach ($_POST as $k => $v) {
  52. if (preg_match('/^user(\d+)$/',$k,$m)) {
  53. $users[] = $m[1];
  54. }
  55. }
  56. }
  57. $strpublishstate = get_string('publishstate', 'notes');
  58. $userlist = array();
  59. foreach ($users as $k => $v) {
  60. if(!$user = get_record('user', 'id', $v)) {
  61. continue;
  62. }
  63. echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
  64. $userlist[] = fullname($user, true);
  65. }
  66. echo '<p>';
  67. echo get_string('users'). ': ' . implode(', ', $userlist) . '.';
  68. echo '</p>';
  69. echo '<p>' . get_string('content', 'notes');
  70. helpbutton('writing', get_string('helpwriting'));
  71. echo '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';
  72. echo '<p>' . $strpublishstate;
  73. helpbutton('status', $strpublishstate, 'notes');
  74. choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, '');
  75. echo '</p>';
  76. echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
  77. print_footer($course);