Пример #1
0
 public function initialise_form()
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/mod/dialogue/formlib.php';
     $cm = $this->dialogue->cm;
     $context = $this->dialogue->context;
     $dialogueid = $this->dialogue->dialogueid;
     $conversationid = $this->conversation->conversationid;
     $form = new \mod_dialogue_reply_form('reply.php');
     // point specifically
     // setup important hiddens
     $form->set_data(array('id' => $cm->id));
     $form->set_data(array('dialogueid' => $dialogueid));
     $form->set_data(array('conversationid' => $conversationid));
     $form->set_data(array('messageid' => $this->_messageid));
     if (is_null($this->_messageid)) {
         $form->set_data(array('action' => 'create'));
     } else {
         $form->set_data(array('action' => 'edit'));
     }
     // setup body, set new $draftitemid directly on _bodydraftid and rewritten
     // html on _body
     $this->_body = file_prepare_draft_area($this->_bodydraftid, $context->id, 'mod_dialogue', 'message', $this->_messageid, \mod_dialogue_reply_form::editor_options(), $this->_body);
     $form->set_data(array('body' => array('text' => $this->_body, 'format' => $this->_bodyformat, 'itemid' => $this->_bodydraftid)));
     // setup attachments, set new $draftitemid directly on _attachmentsdraftid
     file_prepare_draft_area($this->_attachmentsdraftid, $context->id, 'mod_dialogue', 'attachment', $this->_messageid, \mod_dialogue_reply_form::attachment_options());
     // using a post array for attachments
     $form->set_data(array('attachments[itemid]' => $this->_attachmentsdraftid));
     // remove any form buttons the user shouldn't have
     if ($this->conversation->state == dialogue::STATE_CLOSED) {
         $form->remove_from_group('send', 'actionbuttongroup');
     }
     // remove any unecessary buttons
     if ($USER->id != $this->author->id or is_null($this->messageid)) {
         $form->remove_from_group('delete', 'actionbuttongroup');
     }
     // remove any unecessary buttons
     if ($USER->id != $this->author->id or is_null($this->messageid)) {
         $form->remove_from_group('trash', 'actionbuttongroup');
     }
     return $this->_form = $form;
 }
Пример #2
0
/**
 * 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) . "&nbsp;</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&amp;id={$cm->id}&amp;cid={$conversation->id}&amp;pane=" . DIALOGUEPANE_CURRENT . "\">" . get_string('addsubject', 'dialogue') . "</a>\n";
        helpbutton('addsubject', get_string('addsubject', 'dialogue'), 'dialogue');
        echo '&nbsp; | ';
    }
    if (!$conversation->closed && has_capability('mod/dialogue:close', $context)) {
        echo "<a href=\"dialogues.php?action=confirmclose&amp;id={$cm->id}&amp;cid={$conversation->id}&amp;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&amp;id={$cm->id}&amp;entryid={$entry->id}&amp;pane=" . DIALOGUEPANE_CURRENT . "\">" . get_string('edit') . '</a>';
                    } else {
                        echo "<a href=\"dialogues.php?action=editreply&amp;id={$cm->id}&amp;entryid={$entry->id}&amp;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);
}
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}&amp;action=deleteconversation&amp;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") . "\" >&nbsp</a></td></tr>\n";
    //     echo "<td><i>".clean_text($conversation->subject)."&nbsp;</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&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=2\">".
    //             get_string("addsubject", "dialogue")."</a>\n";
    //         helpbutton("addsubject", get_string("addsubject", "dialogue"), "dialogue");
    //         echo "&nbsp; | ";
    //     }
    //     if (!$conversation->closed && has_capability('mod/dialogue:close', $context)) {
    //     echo "<a href=\"dialogues.php?action=confirmclose&amp;id=$cm->id&amp;cid=$conversation->id&amp;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&amp;id={$cm->id}&amp;entryid={$entry->id}&amp;pane=2\">[" . get_string('edit') . ']</a>';
                    } else {
                        echo "<a href=\"dialogues.php?action=editreply&amp;id={$cm->id}&amp;entryid={$entry->id}&amp;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);
}
Пример #4
0
     if (isset($_POST['reply' . $entry->conversationid])) {
         $reply = addslashes(clean_param($_POST['reply' . $entry->conversationid], PARAM_CLEANHTML));
         if ($params->deleteattachment && $entry->attachment) {
             $dir = dialogue_file_area_name($entry);
             unlink($CFG->dataroot . '/' . $dir . '/' . $entry->attachment);
             set_field('dialogue_entries', 'attachment', '', 'id', $entry->id);
         }
         set_field('dialogue_entries', 'text', $reply, 'id', $entry->id);
         set_field('dialogue_entries', 'timemodified', time(), 'id', $entry->id);
         if ($entry->attachment = dialogue_add_attachment($entry, 'attachment', $messages)) {
             set_field('dialogue_entries', 'attachment', $entry->attachment, 'id', $entry->id);
         }
         add_to_log($course->id, 'dialogue', 'edit entry', "view.php?id={$cm->id}", $entry->id, $cm->id);
         redirect("dialogues.php?id={$cm->id}&amp;pane={$params->pane}&amp;action=printdialogue&amp;cid={$entry->conversationid}", get_string('replyupdated', 'dialogue'));
     }
     $mform = new mod_dialogue_reply_form('dialogues.php', array('conversationid' => $entry->conversationid, 'currentattachment' => $entry->attachment));
     $mform->set_data(array('id' => $cm->id, 'entryid' => $entry->id, 'action' => 'editreply', "reply{$entry->conversationid}" => $entry->text));
     $mform->display();
 } else {
     if ($params->action == 'editconversation') {
         /****************** edit a conversation ****************************************/
         $entry = get_record('dialogue_entries', 'id', $params->entryid);
         $conversation = get_record('dialogue_conversations', 'id', $entry->conversationid);
         if (!empty($params->firstentry)) {
             set_field('dialogue_entries', 'text', addslashes($params->firstentry), 'id', $entry->id);
             set_field('dialogue_entries', 'timemodified', time(), 'id', $entry->id);
             set_field('dialogue_conversations', 'recipientid', $params->recipientid, 'id', $conversation->id);
             set_field('dialogue_conversations', 'lastrecipientid', $params->recipientid, 'id', $conversation->id);
             set_field('dialogue_conversations', 'subject', $params->subject, 'id', $conversation->id);
             if ($entry->attachment = dialogue_add_attachment($entry, 'attachment', $messages)) {
                 set_field('dialogue_entries', 'attachment', $entry->attachment, 'id', $entry->id);