~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to mod/chat/insert.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
    include("../../config.php");
4
 
    include("lib.php");
5
 
 
6
 
    require_variable($chat_sid);
7
 
    require_variable($chat_version);
8
 
    require_variable($chat_message);
9
 
    optional_variable($groupid);
10
 
 
11
 
    if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
12
 
        echo "Not logged in!";
13
 
        die;
14
 
    }
15
 
 
16
 
    if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
17
 
        error("No chat found");
18
 
    }
19
 
 
20
 
    require_login($chat->course);
21
 
 
22
 
    if ($groupid) {
23
 
        if (!isteacheredit($chat->course) and !ismember($groupid)) {
24
 
            error("You can't chat here!");
25
 
        }
26
 
    }
27
 
 
28
 
/// Clean up the message
29
 
 
30
 
    $chat_message = addslashes(clean_text(stripslashes($chat_message), FORMAT_MOODLE));  // Strip bad tags
31
 
 
32
 
/// Add the message to the database
33
 
 
34
 
    if (!empty($chat_message)) {
35
 
 
36
 
        $message->chatid = $chatuser->chatid;
37
 
        $message->userid = $chatuser->userid;
38
 
        $message->groupid = $groupid;
39
 
        $message->message = $chat_message;
40
 
        $message->timestamp = time();
41
 
 
42
 
        if (!insert_record("chat_messages", $message)) {
43
 
            error("Could not insert a chat message!");
44
 
        }
45
 
 
46
 
        $chatuser->lastmessageping = time() - 2;
47
 
        update_record("chat_users", $chatuser);
48
 
 
49
 
        if ($cm = get_coursemodule_from_instance("chat", $chat->id, $chat->course)) {
50
 
            add_to_log($chat->course, "chat", "talk", "view.php?id=$cm->id", $chat->id, $cm->id);
51
 
        }
52
 
    }
53
 
 
54
 
/// Go back to the other page
55
 
 
56
 
    if ($chat_version == "header" OR $chat_version == "box") {
57
 
        redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid&groupid=$groupid");
58
 
 
59
 
    } else if ($chat_version == 'sockets') {
60
 
        //redirect('./gui_sockets/chatinput.php?chat_sid='.$chat_sid.'&groupid='.$groupid);
61
 
 
62
 
    } else if ($chat_version == "text") {
63
 
        redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid&groupid=$groupid");
64
 
 
65
 
    } else {
66
 
        redirect("empty.php");
67
 
    }
68
 
 
69
 
?>