[ Index ]

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

title

Body

[close]

/notes/ -> add.php (source)

   1  <?php // $Id: add.php,v 1.6.2.1 2008/01/10 10:58:09 tjhunt Exp $
   2  
   3      require_once ('../config.php');
   4      require_once ('lib.php');
   5  
   6  /// retrieve parameters
   7      $courseid      = required_param('course', PARAM_INT);
   8      $userid        = required_param('user', PARAM_INT);
   9  
  10  /// locate course information
  11      if (!($course = get_record('course', 'id', $courseid))) {
  12          error('Incorrect course id found');
  13      }
  14  
  15  /// require login to access notes
  16      require_login($course->id);
  17  
  18  /// locate context information
  19      $context = get_context_instance(CONTEXT_COURSE, $course->id);
  20  
  21  /// check capability
  22      require_capability('moodle/notes:manage', $context);
  23  
  24  
  25  /// locate user information
  26      if (!($user = get_record('user', 'id', $userid))) {
  27          error('Incorrect user id found');
  28      }
  29  
  30  /// build-up form
  31      require_once ('edit_form.php');
  32  
  33  /// create form
  34      $noteform = new note_edit_form();
  35  
  36  /// if form was cancelled then return to the previous notes list
  37      if ($noteform->is_cancelled()) {
  38          redirect($CFG->wwwroot . '/notes/index.php?course=' . $courseid . '&amp;user=' . $userid);
  39      }
  40  
  41  /// if data was submitted and validated, then save it to database
  42      if ($formdata = $noteform->get_data()) {
  43          $note = new object();
  44          $note->courseid = $formdata->course;
  45          $note->content = $formdata->content;
  46          $note->format = FORMAT_PLAIN;
  47          $note->userid = $formdata->user;
  48          $note->publishstate = $formdata->publishstate;
  49          if (note_save($note)) {
  50              add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
  51          }
  52          // redirect to notes list that contains this note
  53          redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
  54      }
  55  
  56      if($noteform->is_submitted()) {
  57          // if data was submitted with errors, then use it as default for new form
  58          $note = $noteform->get_submitted_data(false);
  59      } else {
  60          // if data was not submitted yet, then use default values
  61          $note = new object();
  62          $note->id = 0;
  63          $note->course = $courseid;
  64          $note->user = $userid;
  65          $note->publishstate = optional_param('state', NOTES_STATE_PUBLIC, PARAM_ALPHA);
  66      }
  67      $noteform->set_data($note);
  68      $strnotes = get_string('addnewnote', 'notes');
  69  
  70  /// output HTML
  71      $nav = array();
  72      if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
  73          $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
  74      }
  75      $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
  76      $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
  77      $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'activity');
  78  
  79      print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
  80  
  81      print_heading(fullname($user));
  82  
  83      $noteform->display();
  84      print_footer();
  85  ?>


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