function dialogue_print_conversation($dialogue, $conversation) { // print a conversation and allow a new entry global $USER, $CFG; if (!($course = get_record("course", "id", $dialogue->course))) { error("Course is misconfigured"); } if (!($cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id))) { error("Course Module ID was incorrect"); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); $dialoguemanagers = array_keys(get_users_by_capability($context, 'mod/dialogue:manage')); $timenow = time(); $showbutton = false; require_once 'dialogue_reply_form.php'; $mform = new mod_dialogue_reply_form('dialogues.php', array('conversationid' => $conversation->id)); $mform->set_data(array('id' => $cm->id, 'action' => 'insertentries', 'pane' => 2)); $showbutton = true; print_simple_box_start("center", ""); // back navigation button to the list of Conversations echo "<div style=\"float:left;\"><input type=button value=\"" . get_string('back') . "\" onClick=\"history.go(-1)\"></div>"; echo "<table align=\"center\" border=\"1\" cellspacing=\"0\" valign=\"top\" cellpadding=\"4\" \n width=\"100%\">\n"; echo "<tr>"; echo "<tr><td> " . get_string('from') . " : " . fullname($USER) . "</td></tr>"; echo "<tr><td> " . get_string('course') . " : {$course->shortname} </td></tr>"; echo "<td>" . get_string('recipients', 'dialogue') . ": "; if (in_array($USER->id, $dialoguemanagers)) { if (!in_array($conversation->userid, $dialoguemanagers)) { if (!($otheruser = get_record("user", "id", $conversation->userid))) { error("User's record not found"); } } else { if (!($otheruser = get_record("user", "id", $conversation->recipientid))) { error("User's record not found"); } } } else { if ($USER->id != $conversation->userid) { if (!($otheruser = get_record("user", "id", $conversation->userid))) { error("User's record not found"); } } else { if (!($otheruser = get_record("user", "id", $conversation->recipientid))) { error("User's record not found"); } } } // used to display only the picture of the current/first user in the list of users that got // this internal message. // $picture = print_user_picture($otheruser->id, $course->id, $otheruser->picture, false, true); // echo $picture." <b>".get_string("dialoguewith", "dialogue", fullname($otheruser)). // display the names and pictures of the recipients that got the same message $recipients = get_records_select("dialogue_conversations", "subject = '{$conversation->subject}'", "recipientid"); foreach ($recipients as $recipient) { if (!($otherrecipient = get_record("user", "id", $recipient->recipientid))) { error("User not found"); } else { //$picture = print_user_picture($otherrecipient->id, $course->id, $otherrecipient->picture, false, true); //echo $picture." <b> ". fullname($otherrecipient)."</b>"; echo " <b> " . fullname($otherrecipient) . "</b> |"; } } echo "</td>"; echo "<td>" . get_string("deleteconversation", "dialogue") . "<a href=\"dialogues.php?id={$cm->id}&action=deleteconversation&cid={$conversation->id}\">" . "<img src=\"{$CFG->wwwroot}/mod/dialogue/pix/mail-delete.png\" height=11 width=14 alt=\"" . get_string("deleteconversation", "dialogue") . "\" title=\"" . get_string("deleteconversation", "dialogue") . "\" > </a></td></tr>\n"; // echo "<td><i>".clean_text($conversation->subject)." </i><br />\n"; // echo "<div align=\"right\">\n"; // if (!$conversation->subject) { // // conversation does not have a subject, show add subject link // echo "<a href=\"dialogues.php?action=getsubject&id=$cm->id&cid=$conversation->id&pane=2\">". // get_string("addsubject", "dialogue")."</a>\n"; // helpbutton("addsubject", get_string("addsubject", "dialogue"), "dialogue"); // echo " | "; // } // if (!$conversation->closed && has_capability('mod/dialogue:close', $context)) { // echo "<a href=\"dialogues.php?action=confirmclose&id=$cm->id&cid=$conversation->id&pane=2\">". // get_string("close", "dialogue")."</a>\n"; // helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue"); // } // echo "</div></td></tr>\n"; //echo "</tr>\n"; if ($entries = get_records_select("dialogue_entries", "conversationid = {$conversation->id}", "id")) { $firstentry = true; foreach ($entries as $entry) { if (!($otheruser = get_record("user", "id", $entry->userid))) { error("User not found"); } // always CAN EDIT :-) /* $canedit = false; if (!$conversation->closed && $entry->userid == $USER->id && $timenow < $entry->timecreated+($dialogue->edittime * 60)) { $canedit = true; } */ $canedit = true; if ($entry->timecreated != $entry->timemodified) { $modified = get_string('updated', 'dialogue', userdate($entry->timemodified)); } else { $modified = ''; } if ($entry->userid == $USER->id) { echo "<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\">\n"; echo "<div class=\"msgheader\" style=\"background-color:Beige;color:Brown;\"><font size=\"1\">" . get_string("onyouwrote", "dialogue", userdate($entry->timecreated) . ' ' . $modified); echo ":</font></div>" . clean_text($entry->text) . "<br />"; if ($canedit) { if ($firstentry) { echo "<a href=\"dialogues.php?action=editconversation&id={$cm->id}&entryid={$entry->id}&pane=2\">[" . get_string('edit') . ']</a>'; } else { echo "<a href=\"dialogues.php?action=editreply&id={$cm->id}&entryid={$entry->id}&pane=2\">[" . get_string('edit') . ']</a>'; } } } else { echo "<tr><td colspan=\"2\">\n"; echo "<p><font size=\"1\">" . get_string("onwrote", "dialogue", userdate($entry->timecreated) . " {$modified} " . fullname($otheruser)); echo ":</font></p><br />" . clean_text($entry->text); } echo dialogue_print_attachments($entry); echo "</td></tr>\n"; $firstentry = false; } } echo "</table><br />\n"; if (!$conversation->closed && (has_capability('mod/dialogue:participateany', $context) || $conversation->userid == $USER->id || $conversation->recipientid == $USER->id)) { $mform->display(); } print_simple_box_end(); if (!$conversation->seenon && $conversation->lastrecipientid == $USER->id) { set_field('dialogue_conversations', 'seenon', time(), 'id', $conversation->id); } dialogue_mark_conversation_read($conversation->id, $USER->id); }
/** * Print a conversation and allow a new entry * * Render out entries for the specified conversation as HTML showing the * avatar for the user who initiated the dialogue. Follow up with a text * box to allow user to add a new response entry * * @param object $dialogue * @param int $conversation */ function dialogue_print_conversation($dialogue, $conversation) { global $USER, $CFG; if (!($course = get_record('course', 'id', $dialogue->course))) { error('Course is misconfigured'); } if (!($cm = get_coursemodule_from_instance('dialogue', $dialogue->id, $course->id))) { error('Course Module ID was incorrect'); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); $dialoguemanagers = array_keys(get_users_by_capability($context, 'mod/dialogue:manage')); $timenow = time(); $showbutton = false; require_once 'dialogue_reply_form.php'; $mform = new mod_dialogue_reply_form('dialogues.php', array('conversationid' => $conversation->id)); $mform->set_data(array('id' => $cm->id, 'action' => 'insertentries', 'pane' => DIALOGUEPANE_CURRENT)); $showbutton = true; print_simple_box_start('center', ''); echo "<table align=\"center\" border=\"1\" cellspacing=\"0\" valign=\"top\" cellpadding=\"4\" \n width=\"100%\">\n"; echo "<tr><td>\n"; if (in_array($USER->id, $dialoguemanagers)) { if (!in_array($conversation->userid, $dialoguemanagers)) { if (!($otheruser = get_record('user', 'id', $conversation->userid))) { error("User's record not found"); } } else { if (!($otheruser = get_record('user', 'id', $conversation->recipientid))) { error("User's record not found"); } } } else { if ($USER->id != $conversation->userid) { if (!($otheruser = get_record('user', 'id', $conversation->userid))) { error("User's record not found"); } } else { if (!($otheruser = get_record('user', 'id', $conversation->recipientid))) { error("User's record not found"); } } } $picture = print_user_picture($otheruser->id, $course->id, $otheruser->picture, false, true); echo $picture . " <b>" . get_string('dialoguewith', 'dialogue', fullname($otheruser)) . '</b></td>'; echo '<td><i>' . format_string($conversation->subject) . " </i><br />\n"; echo "<div align=\"right\">\n"; if (!$conversation->subject) { // conversation does not have a subject, show add subject link echo "<a href=\"dialogues.php?action=getsubject&id={$cm->id}&cid={$conversation->id}&pane=" . DIALOGUEPANE_CURRENT . "\">" . get_string('addsubject', 'dialogue') . "</a>\n"; helpbutton('addsubject', get_string('addsubject', 'dialogue'), 'dialogue'); echo ' | '; } if (!$conversation->closed && has_capability('mod/dialogue:close', $context)) { echo "<a href=\"dialogues.php?action=confirmclose&id={$cm->id}&cid={$conversation->id}&pane=" . DIALOGUEPANE_CURRENT . "\">" . get_string('close', 'dialogue') . "</a>\n"; helpbutton('closedialogue', get_string('close', 'dialogue'), 'dialogue'); } echo "</div></td></tr>\n"; if ($entries = get_records_select('dialogue_entries', "conversationid = {$conversation->id}", 'id')) { $firstentry = true; foreach ($entries as $entry) { if (!($otheruser = get_record('user', 'id', $entry->userid))) { error('User not found'); } $canedit = false; if (!$conversation->closed && $entry->userid == $USER->id && $timenow < $entry->timecreated + $dialogue->edittime * 60) { $canedit = true; } if ($entry->timecreated != $entry->timemodified) { $modified = get_string('updated', 'dialogue', userdate($entry->timemodified)); } else { $modified = ''; } if ($entry->userid == $USER->id) { echo "<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\">\n"; if ($canedit) { if ($firstentry) { echo "<a href=\"dialogues.php?action=editconversation&id={$cm->id}&entryid={$entry->id}&pane=" . DIALOGUEPANE_CURRENT . "\">" . get_string('edit') . '</a>'; } else { echo "<a href=\"dialogues.php?action=editreply&id={$cm->id}&entryid={$entry->id}&pane=" . DIALOGUEPANE_CURRENT . "\">" . get_string('edit') . '</a>'; } } echo "<p><font size=\"1\">" . get_string('onyouwrote', 'dialogue', userdate($entry->timecreated) . ' ' . $modified); echo ":</font></p><br />" . format_text($entry->text); } else { echo "<tr><td colspan=\"2\">\n"; echo "<p><font size=\"1\">" . get_string("onwrote", "dialogue", userdate($entry->timecreated) . " {$modified} " . fullname($otheruser)); echo ":</font></p><br />" . format_text($entry->text); } echo dialogue_print_attachments($entry); echo "</td></tr>\n"; $firstentry = false; } } echo "</table><br />\n"; if (!$conversation->closed && (has_capability('mod/dialogue:participateany', $context) || $conversation->userid == $USER->id || $conversation->recipientid == $USER->id)) { $mform->display(); } print_simple_box_end(); if (!$conversation->seenon && $conversation->lastrecipientid == $USER->id) { set_field('dialogue_conversations', 'seenon', time(), 'id', $conversation->id); } dialogue_mark_conversation_read($conversation->id, $USER->id); }
$entry->text = addslashes($params->firstentry); if (!($entry->id = insert_record('dialogue_entries', $entry))) { error('Insert Entries: Could not insert dialogue record!'); } add_to_log($course->id, 'dialogue', 'add entry', "view.php?id={$cm->id}", $entry->id, $cm->id); if (isset($srcattachment)) { $entry->attachment = $srcattachment->attachment; $srcdir = dialogue_file_area($srcattachment); $dstdir = dialogue_file_area($entry); copy($srcdir . '/' . $entry->attachment, $dstdir . '/' . $entry->attachment); set_field('dialogue_entries', 'attachment', $entry->attachment, 'id', $entry->id); } elseif ($entry->attachment = dialogue_add_attachment($entry, 'attachment', $messages)) { $srcattachment = clone $entry; set_field('dialogue_entries', 'attachment', $entry->attachment, 'id', $entry->id); } dialogue_mark_conversation_read($conversation->id, $USER->id); $n++; } $a = new stdClass(); $a->edittime = $dialogue->edittime; $a->number = $n; if ($n > 1) { // return to dialogue page if more than one recipent redirect("view.php?id={$cm->id}", get_string('numberofentriesadded', 'dialogue', $a)); } else { // if only one recipent show the new conversation with them redirect("dialogues.php?id={$cm->id}&action=printdialogue&cid={$conversation->id}", get_string('numberofentriesadded', 'dialogue', $a)); } } else { redirect("view.php?id={$cm->id}", get_string('noavailablepeople', 'dialogue')); }