[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/user/ -> addnote.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file allows you to add a note for a user
  19   *
  20   * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   * @package core_user
  23   */
  24  
  25  require_once("../config.php");
  26  require_once($CFG->dirroot .'/notes/lib.php');
  27  
  28  $id    = required_param('id', PARAM_INT);              // Course id.
  29  $users = optional_param_array('userid', array(), PARAM_INT); // Array of user id.
  30  $contents = optional_param_array('contents', array(), PARAM_RAW); // Array of user notes.
  31  $states = optional_param_array('states', array(), PARAM_ALPHA); // Array of notes states.
  32  $PAGE->set_url('/user/addnote.php', array('id' => $id));
  33  
  34  if (! $course = $DB->get_record('course', array('id' => $id))) {
  35      print_error('invalidcourseid');
  36  }
  37  
  38  $context = context_course::instance($id);
  39  require_login($course);
  40  
  41  // To create notes the current user needs a capability.
  42  require_capability('moodle/notes:manage', $context);
  43  
  44  if (empty($CFG->enablenotes)) {
  45      print_error('notesdisabled', 'notes');
  46  }
  47  
  48  if (!empty($users) && confirm_sesskey()) {
  49      if (count($users) != count($contents) || count($users) != count($states)) {
  50          print_error('invalidformdata', '', $CFG->wwwroot.'/user/index.php?id='.$id);
  51      }
  52  
  53      $note = new stdClass();
  54      $note->courseid = $id;
  55      $note->format = FORMAT_PLAIN;
  56      foreach ($users as $k => $v) {
  57          $user = $DB->get_record('user', array('id' => $v));
  58          $content = trim($contents[$k]);
  59          if (!$user || empty($content)) {
  60              continue;
  61          }
  62          $note->id = 0;
  63          $note->content = $content;
  64          $note->publishstate = $states[$k];
  65          $note->userid = $v;
  66          note_save($note);
  67      }
  68      redirect("$CFG->wwwroot/user/index.php?id=$id");
  69  }
  70  
  71  // Print headers.
  72  $straddnote = get_string('addnewnote', 'notes');
  73  
  74  $PAGE->navbar->add($straddnote);
  75  $PAGE->set_title("$course->shortname: ".get_string('extendenrol'));
  76  $PAGE->set_heading($course->fullname);
  77  
  78  echo $OUTPUT->header();
  79  // This will contain all available the based On select options, but we'll disable some on them on a per user basis.
  80  echo $OUTPUT->heading($straddnote);
  81  echo '<form method="post" action="addnote.php">';
  82  echo '<fieldset class="invisiblefieldset">';
  83  echo '<input type="hidden" name="id" value="'.$course->id.'" />';
  84  echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
  85  echo '</fieldset>';
  86  $table = new html_table();
  87  $table->head  = array (get_string('fullnameuser'),
  88      get_string('content', 'notes'),
  89      get_string('publishstate', 'notes') . $OUTPUT->help_icon('publishstate', 'notes'),
  90      );
  91  $table->align = array ('left', 'center', 'center');
  92  $statenames = note_get_state_names();
  93  
  94  // The first time list hack.
  95  if (empty($users) and $post = data_submitted()) {
  96      foreach ($post as $k => $v) {
  97          if (preg_match('/^user(\d+)$/', $k, $m)) {
  98              $users[] = $m[1];
  99          }
 100      }
 101  }
 102  foreach ($users as $k => $v) {
 103      if (!$user = $DB->get_record('user', array('id' => $v))) {
 104          continue;
 105      }
 106      $checkbox = html_writer::label(get_string('selectnotestate', 'notes'), 'menustates_'.$v, false, array('class' => 'accesshide'));
 107      $checkbox .= html_writer::select($statenames, 'states[' . $k . ']',
 108          empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false, array('id' => 'menustates_'.$v));
 109      $table->data[] = array(
 110          '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
 111          '<textarea name="contents['. $k . ']" rows="2" cols="40" spellcheck="true">' . strip_tags(@$contents[$k]) . '</textarea>',
 112          $checkbox
 113      );
 114  }
 115  echo html_writer::table($table);
 116  echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
 117  echo $OUTPUT->footer();
 118  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1