[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/user/ -> groupaddnote.php (source)

   1  <?php  // $Id: groupaddnote.php,v 1.3 2007/08/17 19:09:26 nicolasconnault 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  $content = optional_param('content', '', PARAM_RAW); // note content
   8  $state = optional_param('state', '', PARAM_ALPHA); // note publish state
   9  
  10  if (! $course = get_record('course', 'id', $id)) {
  11      error("Course ID is incorrect");
  12  }
  13  
  14  $context = get_context_instance(CONTEXT_COURSE, $id);
  15  require_login($course->id);
  16  
  17  // to create notes the current user needs a capability
  18  require_capability('moodle/notes:manage', $context);
  19  
  20  if (!empty($users) && !empty($content) && confirm_sesskey()) {
  21      $note = new object();
  22      $note->courseid = $id;
  23      $note->format = FORMAT_PLAIN;
  24      $note->content = $content;
  25      $note->publishstate = $state;
  26      foreach ($users as $k => $v) {
  27          if(!$user = get_record('user', 'id', $v)) {
  28              continue;
  29          }
  30          $note->id = 0;
  31          $note->userid = $v;
  32          if (note_save($note)) {
  33              add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
  34          }
  35      }
  36  
  37      redirect("$CFG->wwwroot/user/index.php?id=$id");
  38  }
  39  
  40  /// Print headers
  41  
  42  $straddnote = get_string('groupaddnewnote', 'notes');
  43  
  44  $navlinks = array();
  45  $navlinks[] = array('name' => $straddnote, 'link' => null, 'type' => 'misc');
  46  $navigation = build_navigation($navlinks);
  47  
  48  print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname, $navigation, "", "", true, "&nbsp;", navmenu($course));
  49  
  50  // this will contain all available the based On select options, but we'll disable some on them on a per user basis
  51  
  52  print_heading($straddnote);
  53  echo '<form method="post" action="groupaddnote.php" >';
  54  echo '<div style="width:100%;text-align:center;">';
  55  echo '<input type="hidden" name="id" value="'.$course->id.'" />';
  56  echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
  57  $state_names = note_get_state_names();
  58  
  59  // the first time list hack
  60  if (empty($users)) {
  61      foreach ($_POST as $k => $v) {
  62          if (preg_match('/^user(\d+)$/',$k,$m)) {
  63              $users[] = $m[1];
  64          }
  65      }
  66  }
  67  
  68  $strpublishstate = get_string('publishstate', 'notes');
  69  
  70  $userlist = array();
  71  foreach ($users as $k => $v) {
  72      if(!$user = get_record('user', 'id', $v)) {
  73          continue;
  74      }
  75      echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
  76      $userlist[] = fullname($user, true);
  77  }
  78  echo '<p>';
  79  echo get_string('users'). ': ' . implode(', ', $userlist) . '.';
  80  echo '</p>';
  81  
  82  echo '<p>' . get_string('content', 'notes');
  83  helpbutton('writing', get_string('helpwriting'));
  84  echo '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';
  85  
  86  echo '<p>' . $strpublishstate;
  87  helpbutton('status', $strpublishstate, 'notes');
  88  choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, '');
  89  echo '</p>';
  90  
  91  echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
  92  print_footer($course);


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7