aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/web/offline.php
blob: f4b26c6dce5d74e7b18addd883d42b6ebbe00531 (plain)
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
<?php
include("../config/os_modules_mysql.php");

define("C_DB_TYPE","mysql");
define("C_DB_HOST",$DB_HOST);
define("C_DB_NAME",$DB_NAME);
define("C_DB_USER",$DB_USER);
define("C_DB_PASS",$DB_PASSWORD);
define("C_OFFLINE_IM_TBL", "Offline_IM");
include("offline_mysql.php");
$DbLink = new DB;
$method = $_SERVER["PATH_INFO"];
if ($method == "/SaveMessage/")
{
    $msg = $HTTP_RAW_POST_DATA;
    $start = strpos($msg, "?>");
    if ($start != -1)
    {
	$start+=2;
	$msg = substr($msg, $start);
	$parts = split("[<>]", $msg);
	$to_agent = $parts[12];
	$DbLink->query("insert into ".C_OFFLINE_IM_TBL." (uuid, message) values ('" .
	mysql_escape_string($to_agent) . "', '" .
	mysql_escape_string($msg) . "')");
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><boolean>true</boolean>";
    }
    else
    {
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><boolean>false</boolean>";
    }
    exit;
}
if ($method == "/RetrieveMessages/")
{
    $parms = $HTTP_RAW_POST_DATA;
    $parts = split("[<>]", $parms);
    $agent_id = $parts[6];
    $DbLink->query("select message from ".C_OFFLINE_IM_TBL." where uuid='" .
    mysql_escape_string($agent_id) . "'");
    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfGridInstantMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
    while(list($message) = $DbLink->next_record())
    {
	echo $message;
    }
    echo "</ArrayOfGridInstantMessage>";
    $DbLink->query("delete from ".C_OFFLINE_IM_TBL." where uuid='" .
    mysql_escape_string($agent_id) . "'");
    exit;
}
?>