1<?php 2/** 3 * @package tikiwiki 4 */ 5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 6// 7// All Rights Reserved. See copyright.txt for details and a complete list of authors. 8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 9// $Id$ 10// Live Support CHAT server. 11// This PHP script handles all the messaging between the clients 12// and the server (this script). Messaging is done using a REST 13// model based on HTTP GET requests. 14// Clients use JavaScript to send messages to this server. 15// clients of this server are: 16// * The operator console 17// * The operator chat window 18// * The client chat window 19// Long includes and heavy operations should be avoided to maximize the 20// response time of this script which is critical. 21 22include "tiki-setup.php"; 23header('Content-Type: text/xml'); 24if ($prefs['feature_live_support'] != 'y') { 25 die; 26} 27include_once('lib/live_support/lslib.php'); 28header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past 29header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified 30header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 31header("Cache-Control: post-check=0, pre-check=0", false); 32header("Pragma: no-cache"); // HTTP/1.0 33// A user requests a chat 34if (isset($_REQUEST['request_chat'])) { 35 // The server receives a chat request 36 // if then inserts a row in the support_requests table 37 // with the name of the user (or anonymous) and the reason for 38 // the request. 39 // Operator windows polling this server will be notified of current 40 // 'active' chat requests 41 header("Content-type: text/plain"); 42 $id = $lslib->new_user_request($_REQUEST['user'], $_REQUEST['tiki_user'], $_REQUEST['email'], $_REQUEST['reason']); 43 print ($id); 44} 45if (isset($_REQUEST['set_operator_status'])) { 46 $lslib->set_operator_status($_REQUEST['set_operator_status'], $_REQUEST['status']); 47} 48if (isset($_REQUEST['operators_online'])) { 49 if ($lslib->operators_online()) { 50 header("Content-type: image/png"); 51 readfile('img/icons/live-support-on.png'); 52 } else { 53 header("Content-type: image/png"); 54 readfile('img/icons/live-support-off.png'); 55 } 56} 57if (isset($_REQUEST['write'])) { 58 if ($_REQUEST['role'] == 'operator') { 59 $color = 'blue'; 60 } 61 if ($_REQUEST['role'] == 'user') { 62 $color = 'black'; 63 } 64 if ($_REQUEST['role'] == 'observer') { 65 $color = 'grey'; 66 } 67 if (! strstr($_REQUEST['msg'], 'has left')) { 68 $_REQUEST['msg'] = '<span style="color:' . $color . ';">(' . $_REQUEST['name'] . ')' . ' ' . $_REQUEST['msg'] . '</span>'; 69 } 70 $lslib->put_message($_REQUEST['write'], $_REQUEST['msg'], $_REQUEST['senderId']); 71} 72if (isset($_REQUEST['get_last_event'])) { 73 header("Content-type: text/plain"); 74 echo $lslib->get_last_event($_REQUEST['get_last_event'], $_REQUEST['senderId']); 75} 76if (isset($_REQUEST['get_event'])) { 77 header("Content-type: text/plain"); 78 echo $lslib->get_support_event($_REQUEST['get_event'], $_REQUEST['last'], $_REQUEST['senderId']); 79} 80// A client closes its window 81if (isset($_REQUEST['client_close'])) { 82 $lslib->user_close_request($_REQUEST['client_close']); 83} 84// An operator closes its window 85if (isset($_REQUEST['operator_close'])) { 86 $lslib->operator_close_request($_REQUEST['operator_close']); 87} 88// A client polls for a connection 89if (isset($_REQUEST['get_status'])) { 90 header("Content-type: text/plain"); 91 echo $lslib->get_request_status($_REQUEST['get_status']); 92} 93// Operator console gets requests 94if (isset($_REQUEST['poll_requests'])) { 95 // Now we can format this as XML 96 header("Content-type: text/plain"); 97 echo $lslib->get_last_request(); 98} 99