mirrored from git://git.moodle.org/moodle.git
/
view.php
196 lines (163 loc) · 7.38 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?PHP // $Id$
require_once("../../config.php");
require_once("lib.php");
require_once("locallib.php");
require_variable($id); // Course Module ID
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
if (! $dialogue = get_record("dialogue", "id", $cm->instance)) {
error("Course module is incorrect");
}
require_login($course->id);
add_to_log($course->id, "dialogue", "view", "view.php?id=$cm->id", $dialogue->id, $cm->id);
if (! $cw = get_record("course_sections", "id", $cm->section)) {
error("Course module is incorrect");
}
// set up some general variables
$usehtmleditor = can_use_html_editor();
if ($course->category) {
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
}
$strdialogue = get_string("modulename", "dialogue");
$strdialogues = get_string("modulenameplural", "dialogue");
print_header("$course->shortname: $dialogue->name", "$course->fullname",
"$navigation <a href=\"index.php?id=$course->id\">$strdialogues</a> -> $dialogue->name",
"", "", true,
update_module_button($cm->id, $course->id, $strdialogue), navmenu($course, $cm));
// ...and if necessary set default action
optional_variable($action);
if (!isguest()) { // it's a teacher or student
if (!$cm->visible and isstudent($course->id)) {
$action = 'notavailable';
}
if (empty($action)) {
$action = 'view';
}
}
else { // it's a guest, oh no!
$action = 'notavailable';
}
/*********************** dialogue not available (for gusets mainly)***********************/
if ($action == 'notavailable') {
print_heading(get_string("notavailable", "dialogue"));
}
/************ view **************************************************/
elseif ($action == 'view') {
print_simple_box( format_text($dialogue->intro) , "center");
echo "<br />";
// get some stats
$countneedingrepliesself = dialogue_count_needing_replies_self($dialogue, $USER);
$countneedingrepliesother = dialogue_count_needing_replies_other($dialogue, $USER);
$countclosed = dialogue_count_closed($dialogue, $USER);
// set the pane if it's in a GET or POST
if (isset($_REQUEST['pane'])) {
$pane = $_REQUEST['pane'];
} else {
// set default pane
$pane = 0;
if ($countneedingrepliesother) {
$pane = 2;
}
if ($countneedingrepliesself) {
$pane =1;
}
}
// override pane setting if teacher has changed group
if (isset($_GET['group'])) {
$pane = 0;
}
// set up tab table
$tabs->names[0] = get_string("pane0", "dialogue");
if ($countneedingrepliesself == 1) {
$tabs->names[1] = get_string("pane1one", "dialogue");
} else {
$tabs->names[1] = get_string("pane1", "dialogue", $countneedingrepliesself);
}
if ($countneedingrepliesother == 1) {
$tabs->names[2] = get_string("pane2one", "dialogue");
} else {
$tabs->names[2] = get_string("pane2", "dialogue", $countneedingrepliesother);
}
if ($countclosed == 1) {
$tabs->names[3] = get_string("pane3one", "dialogue");
} else {
$tabs->names[3] = get_string("pane3", "dialogue", $countclosed);
}
$tabs->urls[0] = "view.php?id=$cm->id&pane=0";
$tabs->urls[1] = "view.php?id=$cm->id&pane=1";
$tabs->urls[2] = "view.php?id=$cm->id&pane=2";
$tabs->urls[3] = "view.php?id=$cm->id&pane=3";
$tabs->highlight = $pane;
dialogue_print_tabbed_heading($tabs);
echo "<br/><center>\n";
switch ($pane) {
case 0:
if (isteacher($course->id)) {
/// Check to see if groups are being used in this dialogue
/// and if so, set $currentgroup to reflect the current group
$changegroup = isset($_GET['group']) ? $_GET['group'] : -1; // Group change requested?
$groupmode = groupmode($course, $cm); // Groups are being used?
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
/// Allow the teacher to change groups (for this session)
if ($groupmode) {
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
}
}
}
if ($names = dialogue_get_available_users($dialogue)) {
print_simple_box_start("center");
echo "<center>";
echo "<form name=\"startform\" method=\"post\" action=\"dialogues.php\">\n";
echo "<input type=\"hidden\" name=\"id\"value=\"$cm->id\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"openconversation\">\n";
echo "<table border=\"0\"><tr>\n";
echo "<td align=\"right\"><b>".get_string("openadialoguewith", "dialogue").
" : </b></td>\n";
echo "<td>";
choose_from_menu($names, "recipientid");
echo "</td></tr>\n";
echo "<tr><td align=\"right\"><b>".get_string("subject", "dialogue")." : </b></td>\n";
echo "<td><input type=\"text\" size=\"50\" maxsize=\"100\" name=\"subject\"
value=\"\"></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\" valign=\"top\"><i>".
get_string("typefirstentry", "dialogue")."</i></td></tr>\n";
echo "<tr><td valign=\"top\" align=\"right\">\n";
helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
echo "<br />";
echo "</td><td>\n";
print_textarea($usehtmleditor, 20, 75, 630, 300, "firstentry");
use_html_editor();
echo "</td></tr>";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"".
get_string("opendialogue","dialogue")."\"></td></tr>\n";
echo "</table></form>\n";
echo "</center>";
print_simple_box_end();
} else {
print_heading(get_string("noavailablepeople", "dialogue"));
print_continue("view.php?id=$cm->id");
}
break;
case 1:
// print active conversations requiring a reply
dialogue_list_conversations_self($dialogue, $USER);
break;
case 2:
// print active conversations requiring a reply from the other person.
dialogue_list_conversations_other($dialogue, $USER);
break;
case 3:
dialogue_list_conversations_closed($dialogue, $USER);
}
}
/*************** no man's land **************************************/
else {
error("Fatal Error: Unknown Action: ".$action."\n");
}
print_footer($course);
?>