2009-09-25 04:02:46 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file allows you to add a note for a user
|
|
|
|
*
|
|
|
|
* @copyright 1999 Martin Dougiamas http://dougiamas.com
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2014-02-18 10:12:42 +13:00
|
|
|
* @package core_user
|
2009-09-25 04:02:46 +00:00
|
|
|
*/
|
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
require_once("../config.php");
|
|
|
|
require_once($CFG->dirroot .'/notes/lib.php');
|
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
$id = required_param('id', PARAM_INT); // Course id.
|
|
|
|
$users = optional_param_array('userid', array(), PARAM_INT); // Array of user id.
|
|
|
|
$contents = optional_param_array('contents', array(), PARAM_RAW); // Array of user notes.
|
|
|
|
$states = optional_param_array('states', array(), PARAM_ALPHA); // Array of notes states.
|
|
|
|
$PAGE->set_url('/user/addnote.php', array('id' => $id));
|
2009-09-25 04:02:46 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $id))) {
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-08-17 19:09:11 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 11:38:02 +08:00
|
|
|
$context = context_course::instance($id);
|
2012-04-22 17:41:47 +02:00
|
|
|
require_login($course);
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
// To create notes the current user needs a capability.
|
2007-08-17 19:09:11 +00:00
|
|
|
require_capability('moodle/notes:manage', $context);
|
|
|
|
|
2008-08-26 05:45:07 +00:00
|
|
|
if (empty($CFG->enablenotes)) {
|
|
|
|
print_error('notesdisabled', 'notes');
|
|
|
|
}
|
2012-04-11 17:18:58 +12:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
if (!empty($users) && confirm_sesskey()) {
|
|
|
|
if (count($users) != count($contents) || count($users) != count($states)) {
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('invalidformdata', '', $CFG->wwwroot.'/user/index.php?id='.$id);
|
2007-08-17 19:09:11 +00:00
|
|
|
}
|
|
|
|
|
2010-09-21 08:27:29 +00:00
|
|
|
$note = new stdClass();
|
2007-08-17 19:09:11 +00:00
|
|
|
$note->courseid = $id;
|
|
|
|
$note->format = FORMAT_PLAIN;
|
|
|
|
foreach ($users as $k => $v) {
|
2015-11-05 14:13:47 +00:00
|
|
|
$user = $DB->get_record('user', array('id' => $v));
|
2015-11-12 09:54:39 +00:00
|
|
|
$content = trim($contents[$k]);
|
|
|
|
if (!$user || empty($content)) {
|
2007-08-17 19:09:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$note->id = 0;
|
2015-11-12 09:54:39 +00:00
|
|
|
$note->content = $content;
|
2007-08-17 19:09:11 +00:00
|
|
|
$note->publishstate = $states[$k];
|
|
|
|
$note->userid = $v;
|
2013-01-07 12:01:22 +08:00
|
|
|
note_save($note);
|
2007-08-17 19:09:11 +00:00
|
|
|
}
|
|
|
|
redirect("$CFG->wwwroot/user/index.php?id=$id");
|
|
|
|
}
|
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
// Print headers.
|
2007-08-17 19:09:11 +00:00
|
|
|
$straddnote = get_string('addnewnote', 'notes');
|
|
|
|
|
2009-09-02 08:36:16 +00:00
|
|
|
$PAGE->navbar->add($straddnote);
|
|
|
|
$PAGE->set_title("$course->shortname: ".get_string('extendenrol'));
|
|
|
|
$PAGE->set_heading($course->fullname);
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2009-09-02 08:36:16 +00:00
|
|
|
echo $OUTPUT->header();
|
2014-02-18 10:12:42 +13:00
|
|
|
// This will contain all available the based On select options, but we'll disable some on them on a per user basis.
|
2009-08-06 08:15:05 +00:00
|
|
|
echo $OUTPUT->heading($straddnote);
|
2007-08-17 19:09:11 +00:00
|
|
|
echo '<form method="post" action="addnote.php">';
|
2007-09-28 07:25:09 +00:00
|
|
|
echo '<fieldset class="invisiblefieldset">';
|
2007-08-17 19:09:11 +00:00
|
|
|
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
|
2009-01-02 10:36:25 +00:00
|
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
2008-03-24 23:06:08 +00:00
|
|
|
echo '</fieldset>';
|
2009-08-20 08:50:22 +00:00
|
|
|
$table = new html_table();
|
MDL-13481 Strings fullname and shortname are now deprecated
This is a final cleanup commit of fullname and shortname issue. All
places where these strings were detected yet have been replaced with
proper fullnamecourse or fullnameuser or some other context specific
string.
AMOS BEGIN
CPY [fullname,core],[outcomefullname,core_grades]
CPY [shortname,core],[outcomeshortname,core_grades]
CPY [name,core],[rolefullname,core_role]
CPY [shortname,core],[roleshortname,core_role]
AMOS END
2011-02-22 10:12:10 +01:00
|
|
|
$table->head = array (get_string('fullnameuser'),
|
MDL-21695 Migrating the usage of root help files so far re-worded
AMOS BEGIN
HLP forcepasswordchange.html,[forcepasswordchange_help,core]
HLP interestslist.html,[interestslist_help,core]
HLP newpassword.html,[newpassword_help,core]
HLP permissions.html,[permissions_help,core_role]
HLP picture.html,[newpicture_help,core]
HLP picture.html,[newpicture_help,core_group]
HLP roles.html,[roles_help,core_role]
AMOS END
2010-05-06 21:27:58 +00:00
|
|
|
get_string('content', 'notes'),
|
2010-08-16 15:29:46 +00:00
|
|
|
get_string('publishstate', 'notes') . $OUTPUT->help_icon('publishstate', 'notes'),
|
2007-08-17 19:09:11 +00:00
|
|
|
);
|
|
|
|
$table->align = array ('left', 'center', 'center');
|
2014-02-18 10:12:42 +13:00
|
|
|
$statenames = note_get_state_names();
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
// The first time list hack.
|
2011-07-15 15:00:49 +02:00
|
|
|
if (empty($users) and $post = data_submitted()) {
|
|
|
|
foreach ($post as $k => $v) {
|
2014-02-18 10:12:42 +13:00
|
|
|
if (preg_match('/^user(\d+)$/', $k, $m)) {
|
2007-08-17 19:09:11 +00:00
|
|
|
$users[] = $m[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($users as $k => $v) {
|
2014-02-18 10:12:42 +13:00
|
|
|
if (!$user = $DB->get_record('user', array('id' => $v))) {
|
2007-08-17 19:09:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-02-08 14:25:00 +08:00
|
|
|
$checkbox = html_writer::label(get_string('selectnotestate', 'notes'), 'menustates_'.$v, false, array('class' => 'accesshide'));
|
2014-02-18 10:12:42 +13:00
|
|
|
$checkbox .= html_writer::select($statenames, 'states[' . $k . ']',
|
2016-02-08 14:25:00 +08:00
|
|
|
empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false, array('id' => 'menustates_'.$v));
|
2007-08-17 19:09:11 +00:00
|
|
|
$table->data[] = array(
|
|
|
|
'<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
|
2013-04-07 18:18:01 +02:00
|
|
|
'<textarea name="contents['. $k . ']" rows="2" cols="40" spellcheck="true">' . strip_tags(@$contents[$k]) . '</textarea>',
|
2007-08-17 19:09:11 +00:00
|
|
|
$checkbox
|
|
|
|
);
|
|
|
|
}
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2008-03-24 23:06:08 +00:00
|
|
|
echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
|
2009-08-06 14:08:20 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-11-04 08:11:02 +00:00
|
|
|
|