Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / dialogue / locallib.php
blobee2e763d8146263e87a8184412c85f9327aa49cd
1 <?php // $Id$
3 /// Library of extra functions for the dialogue module
5 // SQL FUNCTIONS ///////////////////////////////////////////////////////////////////
7 //////////////////////////////////////////////////////////////////////////////////////
8 function dialogue_count_all_needing_replies_self($user = '') {
9 // count [conversations] needing replies [from] self for all dialogues
10 // function requested by Williams Castillo 17 Oct 2003
11 global $USER;
13 if ($user) {
14 return count_records_select("dialogue_conversations", "(userid = $user->id OR
15 recipientid = $user->id) AND lastid != $user->id AND closed = 0");
16 } else {
17 return count_records_select("dialogue_conversations", "(userid = $USER->id OR
18 recipientid = $USER->id) AND lastid != $USER->id AND closed = 0");
23 //////////////////////////////////////////////////////////////////////////////////////
24 function dialogue_count_closed($dialogue, $user) {
26 return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND
27 (userid = $user->id OR recipientid = $user->id) AND closed = 1");
31 //////////////////////////////////////////////////////////////////////////////////////
32 function dialogue_count_open($dialogue, $user) {
34 return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND
35 (userid = $user->id OR recipientid = $user->id) AND closed = 0");
39 //////////////////////////////////////////////////////////////////////////////////////
40 function dialogue_count_needing_replies_other($dialogue, $user) {
41 // count [conversations] needing replies [from] other [person]
42 return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND
43 (userid = $user->id OR recipientid = $user->id) AND lastid = $user->id AND closed = 0");
47 //////////////////////////////////////////////////////////////////////////////////////
48 function dialogue_count_needing_replies_self($dialogue, $user) {
49 // count [conversations] needing replies [from] self
51 return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND
52 (userid = $user->id OR recipientid = $user->id) AND lastid != $user->id AND closed = 0");
56 //////////////////////////////////////////////////////////////////////////////////////
57 function dialogue_get_participants($dialogueid) {
58 //Returns the users with data in one dialogue
59 //(users with records in dialogue_conversations, creators and receivers)
61 global $CFG;
63 //Get conversation's creators
64 $creators = get_records_sql("SELECT DISTINCT u.id, u.id
65 FROM {$CFG->prefix}user u,
66 {$CFG->prefix}dialogue_conversations c
67 WHERE c.dialogueid = '$dialogueid' and
68 u.id = c.userid");
70 //Get conversation's receivers
71 $receivers = get_records_sql("SELECT DISTINCT u.id, u.id
72 FROM {$CFG->prefix}user u,
73 {$CFG->prefix}dialogue_conversations c
74 WHERE c.dialogueid = '$dialogueid' and
75 u.id = c.recipientid");
77 //Add receivers to creators
78 if ($receivers) {
79 foreach ($receivers as $receiver) {
80 $creators[$receiver->id] = $receiver;
84 //Return creators array (it contains an array of unique users, creators and receivers)
85 return ($creators);
88 //////////////////////////////////////////////////////////////////////////////////////
89 function dialogue_get_available_users($dialogue) {
91 if (! $course = get_record("course", "id", $dialogue->course)) {
92 error("Course is misconfigured");
94 switch ($dialogue->dialoguetype) {
95 case 0 : // teacher to student
96 if (isteacher($course->id)) {
97 return dialogue_get_available_students($dialogue);
99 else {
100 return dialogue_get_available_teachers($dialogue);
102 case 1: // student to student
103 if (isstudent($course->id)) {
104 return dialogue_get_available_students($dialogue);
106 else {
107 return;
109 case 2: // everyone
110 if ($teachers = dialogue_get_available_teachers($dialogue)) {
111 foreach ($teachers as $userid=>$name) {
112 $names[$userid] = $name;
114 $names[-1] = "-------------";
116 if ($students = dialogue_get_available_students($dialogue)) {
117 foreach ($students as $userid=>$name) {
118 $names[$userid] = $name;
121 if (isset($names)) {
122 return $names;
124 return;
129 //////////////////////////////////////////////////////////////////////////////////////
130 function dialogue_get_available_students($dialogue) {
131 global $USER;
133 if (! $course = get_record("course", "id", $dialogue->course)) {
134 error("Course is misconfigured");
136 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
137 error("Course Module ID was incorrect");
140 $groupid = get_current_group($course->id);
141 // add current group before list of students if it's the teacher
142 if (isteacher($course->id) and groupmode($course, $cm)) {
143 // show teacher their current group
144 if ($groupid) {
145 if (!$group = get_record("groups", "id", $groupid)) {
146 error("Dialogue get available students: group not found");
148 $gnames["g$groupid"] = $group->name;
149 } else { // all participants
150 $gnames["g0"] = get_string("allparticipants");
152 $gnames["spacer"] = "------------";
154 // get the students on this course (default sort order)...
155 if ($users = get_course_students($course->id)) {
156 foreach ($users as $otheruser) {
157 // ...exclude self and...
158 if ($USER->id != $otheruser->id) {
159 // ...if teacher and groups then exclude students not in the current group
160 if (isteacher($course->id) and groupmode($course, $cm) and $groupid) {
161 if (!ismember($groupid, $otheruser->id)) {
162 continue;
165 // ...if student and groupmode is SEPARATEGROUPS then exclude students not in student's group
166 if (isstudent($course->id) and (groupmode($course, $cm) == SEPARATEGROUPS)) {
167 if (!ismember($groupid, $otheruser->id)) {
168 continue;
171 // ... and any already in any open conversations unless multiple conversations allowed
172 if ($dialogue->multipleconversations or count_records_select("dialogue_conversations",
173 "dialogueid = $dialogue->id AND
174 ((userid = $USER->id AND recipientid = $otheruser->id) OR
175 (userid = $otheruser->id AND recipientid = $USER->id)) AND closed = 0") == 0) {
176 $names[$otheruser->id] = fullname($otheruser);
181 if (isset($gnames)) {
182 $list = $gnames;
184 if (isset($names)) {
185 natcasesort($names);
186 if (isset($list)) {
187 $list += $names;
188 } else {
189 $list = $names;
192 if (isset($list)) {
193 return $list;
194 } else {
195 return;
200 //////////////////////////////////////////////////////////////////////////////////////
201 function dialogue_get_available_teachers($dialogue) {
202 global $USER;
204 if (! $course = get_record("course", "id", $dialogue->course)) {
205 error("Course is misconfigured");
207 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
208 error("Course Module ID was incorrect");
211 $groupid = get_current_group($course->id);
212 // get the teachers on this course (default sort order)...
213 if ($users = get_course_teachers($course->id)) {
214 // $names[0] = "-----------------------";
215 foreach ($users as $otheruser) {
216 // ...exclude self and ...
217 if ($USER->id != $otheruser->id) {
218 // ...if groupmode is SEPARATEGROUPS then exclude teachers not in student's group
219 if ($groupid and (groupmode($course, $cm) == SEPARATEGROUPS)) {
220 if (!ismember($groupid, $otheruser->id)) {
221 continue;
224 // ...any already in open conversations unless multiple conversations allowed
225 if ($dialogue->multipleconversations or count_records_select("dialogue_conversations",
226 "dialogueid = $dialogue->id AND ((userid = $USER->id AND
227 recipientid = $otheruser->id) OR (userid = $otheruser->id AND
228 recipientid = $USER->id)) AND closed = 0") == 0) {
229 $names[$otheruser->id] = fullname($otheruser);
234 if (isset($names)) {
235 natcasesort($names);
236 return $names;
238 return;
243 //////////////////////////////////////////////////////////////////////////////////////
244 function dialogue_get_users_done($dialogue) {
245 global $CFG;
247 // make sure it works on the site course
248 $select = "s.course = '$dialogue->course' AND";
249 if ($courseid == SITEID) {
250 $select = '';
252 if (!$students = get_records_sql("SELECT u.*
253 FROM {$CFG->prefix}user u,
254 {$CFG->prefix}user_students s,
255 {$CFG->prefix}dialogue_entries j
256 WHERE ($select s.userid = u.id)
257 AND u.id = j.userid
258 AND j.dialogue = '$dialogue->id'
259 ORDER BY j.modified DESC")) {
260 $students = array();
262 if (!$teachers = get_records_sql("SELECT u.*
263 FROM {$CFG->prefix}user u,
264 {$CFG->prefix}user_teachers s,
265 {$CFG->prefix}dialogue_entries j
266 WHERE (s.course = '$dialogue->course' AND s.userid = u.id)
267 AND u.id = j.userid
268 AND j.dialogue = '$dialogue->id'
269 ORDER BY j.modified DESC")) {
270 $teachers = array();
272 return $teachers + $students;
274 // The following original version is very inefficient on large sites
275 // return get_records_sql("SELECT u.*
276 // FROM {$CFG->prefix}user u,
277 // {$CFG->prefix}user_students s,
278 // {$CFG->prefix}user_teachers t,
279 // {$CFG->prefix}dialogue_entries j
280 // WHERE ((s.course = '$dialogue->course' AND s.userid = u.id)
281 // OR (t.course = '$dialogue->course' AND t.userid = u.id))
282 // AND u.id = j.userid
283 // AND j.dialogue = '$dialogue->id'
284 // ORDER BY j.modified DESC");
288 // OTHER dialogue FUNCTIONS ///////////////////////////////////////////////////////////////////
290 //////////////////////////////////////////////////////////////////////////////////////
291 function dialogue_list_conversations_closed($dialogue) {
292 // list the closed for the current user
293 global $USER;
295 if (! $course = get_record("course", "id", $dialogue->course)) {
296 error("Course is misconfigured");
298 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
299 error("Course Module ID was incorrect");
302 if ($conversations = dialogue_get_conversations($dialogue, $USER, "closed = 1")) {
303 // reorder the conversations by (other) name
304 foreach ($conversations as $conversation) {
305 if ($USER->id != $conversation->userid) {
306 if (!$with = get_record("user", "id", $conversation->userid)) {
307 error("User's record not found");
310 else {
311 if (!$with = get_record("user", "id", $conversation->recipientid)) {
312 error("User's record not found");
315 $names[$conversation->id] = fullname($with);
317 natcasesort($names);
319 print_simple_box_start("center");
320 $table->head = array (get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"),
321 get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"),
322 get_string("status", "dialogue"));
323 $table->width = "100%";
324 $table->align = array ("left", "left", "center", "left", "left");
325 $table->size = array ("*", "*", "*", "*", "*");
326 $table->cellpadding = 2;
327 $table->cellspacing = 0;
329 foreach ($names as $cid=>$name) {
330 if (!$conversation = get_record("dialogue_conversations", "id", $cid)) {
331 error("Closed conversations: could not find conversation record");
333 $total = dialogue_count_entries($dialogue, $conversation);
334 $byuser = dialogue_count_entries($dialogue, $conversation, $USER);
335 if ($conversation->closed) {
336 $status = get_string("closed", "dialogue");
337 } else {
338 $status = get_string("open", "dialogue");
340 $table->data[] = array("<a href=\"dialogues.php?id=$cm->id&amp;action=showdialogues&amp;cid=$conversation->id\">".
341 "$name</a>", clean_text($conversation->subject), $byuser." ".get_string("of", "dialogue")." ".$total,
342 userdate($conversation->timemodified), $status);
344 print_table($table);
345 print_simple_box_end();
350 //////////////////////////////////////////////////////////////////////////////////////
351 function dialogue_list_conversations_other($dialogue) {
352 // list the conversations of the current user awaiting response from the other person
353 global $THEME, $USER;
355 if (!$course = get_record("course", "id", $dialogue->course)) {
356 error("Course is misconfigured");
358 if (!$cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
359 error("Course Module ID was incorrect");
362 $timenow = time();
363 if ($conversations = dialogue_get_conversations($dialogue, $USER, "lastid = $USER->id AND closed = 0")) {
364 // reorder the conversations by (other) name
365 foreach ($conversations as $conversation) {
366 if ($USER->id != $conversation->userid) {
367 if (!$with = get_record("user", "id", $conversation->userid)) {
368 error("User's record not found");
371 else {
372 if (!$with = get_record("user", "id", $conversation->recipientid)) {
373 error("User's record not found");
376 $names[$conversation->id] = fullname($with);
378 natcasesort($names);
380 print_simple_box_start("center");
381 $table->head = array (get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"),
382 get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"),
383 get_string("status", "dialogue"));
384 $table->width = "100%";
385 $table->align = array ("left", "left", "center", "left", "left");
386 $table->size = array ("*", "*", "*", "*", "*");
387 $table->cellpadding = 2;
388 $table->cellspacing = 0;
390 foreach ($names as $cid=>$name) {
391 if (!$conversation = get_record("dialogue_conversations", "id", $cid)) {
392 error("Closed conversations: could not find conversation record");
394 $total = dialogue_count_entries($dialogue, $conversation);
395 $byuser = dialogue_count_entries($dialogue, $conversation, $USER);
396 if ($conversation->seenon) {
397 $status = get_string("seen", "dialogue", format_time($timenow - $conversation->seenon));
398 } else {
399 $status = get_string("notyetseen", "dialogue");
401 $table->data[] = array("<a href=\"dialogues.php?id=$cm->id&amp;action=printdialogue&amp;cid=$conversation->id\">".
402 "$name</a>", clean_text($conversation->subject), $byuser." ".get_string("of", "dialogue")." ".$total,
403 userdate($conversation->timemodified), $status);
405 print_table($table);
406 print_simple_box_end();
411 //////////////////////////////////////////////////////////////////////////////////////
412 function dialogue_list_conversations_self($dialogue) {
413 // list open conversations of the current user awaiting their reply
414 global $THEME, $USER;
416 if (! $course = get_record("course", "id", $dialogue->course)) {
417 error("Course is misconfigured");
419 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
420 error("Course Module ID was incorrect");
423 // set up some general variables
424 $usehtmleditor = can_use_html_editor();
426 $timenow = time();
427 $showbutton = false;
429 echo "<form name=\"replies\" method=\"post\" action=\"dialogues.php\">\n";
430 echo "<input type=\"hidden\" name=\"action\" value=\"insertentries\"/>\n";
431 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
432 echo "<input type=\"hidden\" name=\"pane\" value=\"1\" />\n";
434 // list the conversations requiring a resonse from this user in full
435 if ($conversations = dialogue_get_conversations($dialogue, $USER, "lastid != $USER->id AND closed = 0")) {
436 $showbutton = true;
437 print_simple_box_start("center");
438 foreach ($conversations as $conversation) {
439 // set seenon if required
440 if (!$conversation->seenon) {
441 if (!set_field("dialogue_conversations", "seenon", $timenow, "id", $conversation->id)) {
442 error("List conversations self: could not set seenon");
445 echo "<table align=\"center\" border=\"1\" cellspacing=\"0\" valign=\"top\" cellpadding=\"4\"
446 width=\"100%\">\n";
447 echo "<tr><td bgcolor=\"$THEME->cellheading2\" valign=\"top\">\n";
448 if ($conversation->userid == $USER->id) {
449 if (!$otheruser = get_record("user", "id", $conversation->recipientid)) {
450 error("User not found");
453 else {
454 if (!$otheruser = get_record("user", "id", $conversation->userid)) {
455 error("User not found");
458 $picture = print_user_picture($otheruser->id, $course->id, $otheruser->picture, false, true);
459 echo $picture." <b>".get_string("dialoguewith", "dialogue", fullname($otheruser)).
460 "</b></td>";
461 echo "<td bgcolor=\"$THEME->cellheading2\"><i>".clean_text($conversation->subject)."&nbsp;</i><br />\n";
462 echo "<div align=\"right\">\n";
463 if (!$conversation->subject) {
464 // conversation does not have a subject, show add subject link
465 echo "<a href=\"dialogues.php?action=getsubject&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=2\">".
466 get_string("addsubject", "dialogue")."</a>\n";
467 helpbutton("addsubject", get_string("addsubject", "dialogue"), "dialogue");
468 echo "&nbsp; | ";
470 if (dialogue_count_entries($dialogue, $conversation)) {
471 echo "<a href=\"dialogues.php?action=confirmclose&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=1\">".
472 get_string("close", "dialogue")."</a>\n";
473 helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue");
475 else {
476 echo "&nbsp;";
478 echo "<div></td></tr>";
480 if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id",
481 "id")) {
482 foreach ($entries as $entry) {
483 if ($entry->userid == $USER->id) {
484 echo "<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\">\n";
485 echo text_to_html("<font size=\"1\">".get_string("onyouwrote", "dialogue",
486 userdate($entry->timecreated)).":</font><br />".clean_text($entry->text));
487 echo "</td></tr>\n";
489 else {
490 echo "<tr><td colspan=\"2\" bgcolor=\"$THEME->body\">\n";
491 echo text_to_html("<font size=\"1\">".get_string("onwrote", "dialogue",
492 userdate($entry->timecreated)." ".$otheruser->firstname).
493 ":</font><br />".clean_text($entry->text));
494 echo "</td></tr>\n";
499 echo "<tr><td colspan=\"2\" align=\"center\" valign=\"top\">\n";
500 if ($entries) {
501 echo "<i>".get_string("typereply", "dialogue")."</i>\n";
503 else {
504 echo "<i>".get_string("typefirstentry", "dialogue")."</i>\n";
506 echo "</td></tr>\n";
507 echo "<tr><td valign=\"top\" align=\"right\">\n";
508 helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
509 echo "<br />";
510 echo "</td><td>\n";
511 // use a cumbersome name on the textarea is just historical :-)
512 print_textarea($usehtmleditor, 20, 75, 630, 300, "reply$conversation->id");
513 echo "</td></tr>";
514 echo "</table><br />\n";
516 print_simple_box_end();
517 use_html_editor();
518 if ($showbutton) {
519 echo "<hr />\n";
520 echo "<p align=\"center\"><input type=\"submit\" value=\"".get_string("addmynewentries", "dialogue").
521 "\"/></p>\n";
523 echo "</form>\n";
528 //////////////////////////////////////////////////////////////////////////////////////
529 function dialogue_print_conversation($dialogue, $conversation) {
530 // print a conversation and allow a new entry
531 global $THEME, $USER;
533 if (! $course = get_record("course", "id", $dialogue->course)) {
534 error("Course is misconfigured");
536 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
537 error("Course Module ID was incorrect");
540 $timenow = time();
541 $showbutton = false;
543 echo "<form name=\"replies\" method=\"post\" action=\"dialogues.php\">\n";
544 echo "<input type=\"hidden\" name=\"action\" value=\"insertentries\"/>\n";
545 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
546 echo "<input type=\"hidden\" name=\"pane\" value=\"2\" />\n";
548 $showbutton = true;
549 print_simple_box_start("center", "", $THEME->cellcontent2);
550 echo "<table align=\"center\" border=\"1\" cellspacing=\"0\" valign=\"top\" cellpadding=\"4\"
551 width=\"100%\">\n";
552 echo "<tr><td bgcolor=\"$THEME->cellheading2\" valign=\"top\">\n";
553 if ($conversation->userid == $USER->id) {
554 if (!$otheruser = get_record("user", "id", $conversation->recipientid)) {
555 error("User not found");
558 else {
559 if (!$otheruser = get_record("user", "id", $conversation->userid)) {
560 error("User not found");
563 $picture = print_user_picture($otheruser->id, $course->id, $otheruser->picture, false, true);
564 echo $picture." <b>".get_string("dialoguewith", "dialogue", fullname($otheruser)).
565 "</b></td>";
566 echo "<td bgcolor=\"$THEME->cellheading2\"><i>".clean_text($conversation->subject)."&nbsp;</i><br />\n";
567 echo "<div align=\"right\">\n";
568 if (!$conversation->subject) {
569 // conversation does not have a subject, show add subject link
570 echo "<a href=\"dialogues.php?action=getsubject&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=2\">".
571 get_string("addsubject", "dialogue")."</a>\n";
572 helpbutton("addsubject", get_string("addsubject", "dialogue"), "dialogue");
573 echo "&nbsp; | ";
575 echo "<a href=\"dialogues.php?action=confirmclose&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=2\">".
576 get_string("close", "dialogue")."</a>\n";
577 helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue");
578 echo "</div></td></tr>\n";
580 if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) {
581 foreach ($entries as $entry) {
582 if ($entry->userid == $USER->id) {
583 echo "<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\">\n";
584 echo text_to_html("<font size=\"1\">".get_string("onyouwrote", "dialogue",
585 userdate($entry->timecreated)).":</font><br />".clean_text($entry->text));
587 else {
588 echo "<tr><td colspan=\"2\" bgcolor=\"$THEME->body\">\n";
589 echo text_to_html("<font size=\"1\">".get_string("onwrote", "dialogue",
590 userdate($entry->timecreated)." ".$otheruser->firstname).":</font><br />".
591 clean_text($entry->text));
594 echo "</td></tr>\n";
596 echo "<tr><td colspan=\"2\" align=\"center\" valign=\"top\"><i>".
597 get_string("typefollowup", "dialogue")."</i></td></tr>\n";
598 echo "<tr><td valign=\"top\" align=\"right\">\n";
599 helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
600 echo "<br />";
601 echo "</td><td>\n";
602 // use a cumbersome name on the textarea for historical reasons :-)
603 $usehtmleditor = can_use_html_editor();
604 print_textarea($usehtmleditor, 20, 75, 630, 300, "reply$conversation->id");
605 use_html_editor();
606 echo "</td></tr>";
607 echo "</table><br />\n";
608 print_simple_box_end();
609 if ($showbutton) {
610 echo "<hr />\n";
611 echo "<br /><input type=\"submit\" value=\"".get_string("addmynewentry", "dialogue")."\" />\n";
613 echo "</form>\n";
617 //////////////////////////////////////////////////////////////////////////////////////
618 function dialogue_print_tabbed_heading($tabs) {
619 // Prints a tabbed heading where one of the tabs highlighted.
620 // $tabs is an object with several properties.
621 // $tabs->names is an array of tab names
622 // $tabs->urls is an array of links
623 // $tabs->align is an array of column alignments (defaults to "center")
624 // $tabs->size is an array of column sizes
625 // $tabs->wrap is an array of "nowrap"s or nothing
626 // $tabs->highlight is an index (zero based) of "active" heading .
627 // $tabs->width is an percentage of the page (defualts to 80%)
628 // $tabs->cellpadding padding on each cell (defaults to 5)
630 global $CFG, $THEME;
632 if (isset($tabs->names)) {
633 foreach ($tabs->names as $key => $name) {
634 if (!empty($tabs->urls[$key])) {
635 $url =$tabs->urls[$key];
636 if ($tabs->highlight == $key) {
637 $tabcontents[$key] = "<b>$name</b>";
638 } else {
639 $tabcontents[$key] = "<a class= \"dimmed\" href=\"$url\"><b>$name</b></a>";
641 } else {
642 $tabcontents[$key] = "<b>$name</b>";
647 if (empty($tabs->width)) {
648 $tabs->width = "80%";
651 if (empty($tabs->cellpadding)) {
652 $tabs->cellpadding = "5";
655 // print_simple_box_start("center", "$table->width", "#ffffff", 0);
656 echo "<table width=\"$tabs->width\" border=\"0\" valign=\"top\" align=\"center\" ";
657 echo " cellpadding=\"$tabs->cellpadding\" cellspacing=\"0\" class=\"generaltable\">\n";
659 if (!empty($tabs->names)) {
660 echo "<tr>";
661 echo "<td class=\"generaltablecell\">".
662 "<img width=\"10\" src=\"$CFG->wwwroot/pix/spacer.gif\" alt=\"\" /></td>\n";
663 foreach ($tabcontents as $key => $tab) {
664 if (isset($align[$key])) {
665 $alignment = "align=\"$align[$key]\"";
666 } else {
667 $alignment = "align=\"center\"";
669 if (isset($size[$key])) {
670 $width = "width=\"$size[$key]\"";
671 } else {
672 $width = "";
674 if (isset($wrap[$key])) {
675 $wrapping = "no wrap";
676 } else {
677 $wrapping = "";
679 if ($key == $tabs->highlight) {
680 echo "<td valign=top class=\"generaltabselected\" $alignment $width $wrapping bgcolor=\"$THEME->cellheading2\">$tab</td>\n";
681 } else {
682 echo "<td valign=top class=\"generaltab\" $alignment $width $wrapping bgcolor=\"$THEME->cellheading\">$tab</td>\n";
684 echo "<td class=\"generaltablecell\">".
685 "<img width=\"10\" src=\"$CFG->wwwroot/pix/spacer.gif\" alt=\"\" /></td>\n";
687 echo "</tr>\n";
688 } else {
689 echo "<tr><td>No names specified</td></tr>\n";
691 // bottom stripe
692 $ncells = count($tabs->names)*2 +1;
693 $height = 2;
694 echo "<tr><td colspan=\"$ncells\" bgcolor=\"$THEME->cellheading2\">".
695 "<img height=\"$height\" src=\"$CFG->wwwroot/pix/spacer.gif\" alt=\"\" /></td></tr>\n";
696 echo "</table>\n";
697 // print_simple_box_end();
699 return true;
704 //////////////////////////////////////////////////////////////////////////////////////
705 function dialogue_show_conversation($dialogue, $conversation) {
706 global $THEME, $USER;
708 if (! $course = get_record("course", "id", $dialogue->course)) {
709 error("Course is misconfigured");
711 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
712 error("Course Module ID was incorrect");
715 $timenow = time();
716 print_simple_box_start("center");
717 echo "<table border=\"1\" cellspacing=\"0\" valign=\"top\" cellpadding=\"4\" width=\"100%\">\n";
719 echo "<tr>";
720 echo "<td bgcolor=\"$THEME->cellheading2\" valign=\"top\">\n";
721 if ($conversation->userid == $USER->id) {
722 if (!$otheruser = get_record("user", "id", $conversation->recipientid)) {
723 error("User not found");
726 else {
727 if (!$otheruser = get_record("user", "id", $conversation->userid)) {
728 error("User not found");
731 $picture = print_user_picture($otheruser->id, $course->id, $otheruser->picture, false, true);
732 echo $picture." <b>".get_string("dialoguewith", "dialogue", fullname($otheruser)).
733 "</b></td>";
734 echo "<td bgcolor=\"$THEME->cellheading2\" valign=\"top\"><i>".clean_text($conversation->subject)."&nbsp;</i></td></tr>";
736 if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) {
737 foreach ($entries as $entry) {
738 if ($entry->userid == $USER->id) {
739 echo "<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\">\n";
740 echo text_to_html("<font size=\"1\">".get_string("onyouwrote", "dialogue",
741 userdate($entry->timecreated)).
742 ":</font><br />".clean_text($entry->text));
743 echo "</td></tr>\n";
745 else {
746 echo "<tr><td colspan=\"2\" bgcolor=\"$THEME->body\">\n";
747 echo text_to_html("<font size=\"1\">".get_string("onwrote", "dialogue",
748 userdate($entry->timecreated)." ".$otheruser->firstname).":</font><br />".clean_text($entry->text));
749 echo "</td></tr>\n";
753 echo "</table><br />\n";
754 print_simple_box_end();
755 print_continue("view.php?id=$cm->id&amp;pane=3");
759 //////////////////////////////////////////////////////////////////////////////////////
760 function dialogue_show_other_conversations($dialogue, $conversation) {
761 // prints the other CLOSED conversations for this pair of users
762 global $THEME;
764 if (! $course = get_record("course", "id", $dialogue->course)) {
765 error("Course is misconfigured");
767 if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
768 error("Course Module ID was incorrect");
771 if (!$user = get_record("user", "id", $conversation->userid)) {
772 error("User not found");
774 if (!$otheruser = get_record("user", "id", $conversation->recipientid)) {
775 error("User not found");
778 if ($conversations = get_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND
779 ((userid = $user->id AND recipientid = $otheruser->id) OR (userid = $otheruser->id AND
780 recipientid = $user->id)) AND closed = 1", "timemodified DESC")) {
781 if (count($conversations) > 1) {
782 $timenow = time();
783 foreach ($conversations as $otherconversation) {
784 if ($conversation->id != $otherconversation->id) {
785 // for this conversation work out which is the other user
786 if ($otherconversation->userid == $user->id) {
787 if (!$otheruser = get_record("user", "id", $otherconversation->recipientid)) {
788 error("Show other conversations: could not get user record");
791 else {
792 if (!$otheruser = get_record("user", "id", $otherconversation->userid)) {
793 error("Show other conversations: could not get user record");
796 print_simple_box_start("center");
797 echo "<table align=\"center\" border=\"1\" cellspacing=\"0\" valign=\"top\" cellpadding=\"4\"
798 width=\"100%\">\n";
799 echo "<tr>";
800 echo "<td bgcolor=\"$THEME->cellheading2\" valign=\"top\">\n";
801 // print_user_picture($otheruser->id, $course->id, $otheruser->picture);
802 echo "<b>".get_string("dialoguewith", "dialogue",
803 fullname($otheruser))."</b></td>";
804 echo "<td bgcolor=\"$THEME->cellheading2\" valign=\"top\"><i>".clean_text($otherconversation->subject)."&nbsp;</i></td></tr>";
805 if ($entries = get_records_select("dialogue_entries",
806 "conversationid = $otherconversation->id", "id")) {
807 foreach ($entries as $entry) {
808 if ($entry->userid == $user->id) {
809 echo "<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\">\n";
810 echo text_to_html("<font size=\"1\">".get_string("onyouwrote", "dialogue",
811 userdate($entry->timecreated)).":</font><br />".clean_text($entry->text));
812 echo "</td></tr>\n";
814 else {
815 echo "<tr><td colspan=\"2\" bgcolor=\"$THEME->body\">\n";
816 echo text_to_html("<font size=\"1\">".get_string("onwrote", "dialogue",
817 userdate($entry->timecreated)." ".$otheruser->firstname).
818 ":</font><br />".clean_text($entry->text));
819 echo "</td></tr>\n";
824 echo "</table><br />\n";
825 print_simple_box_end();
828 print_continue("view.php?id=$cm->id&amp;pane=3");