~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to user/groupaddnote.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

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