Example #1
0
 function response($chatid, $typing, $admin, $checksum = '', $copage = '')
 {
     $type_limit = 5;
     $chat_limit = time() - $GLOBALS['conf']['chat_timeout'];
     $this->response = '|';
     if ($admin == 'true') {
         $this->result = $GLOBALS['db']->query('SELECT * FROM `sessions` WHERE `chatid`="' . $chatid . '"');
         if ($this->result[0]['alert'] !== 'hold' && $this->result[0]['alert'] !== 'holding') {
             $GLOBALS['db']->query('UPDATE `sessions` SET `timeo`=UNIX_TIMESTAMP() WHERE `chatid`="' . $chatid . '"');
         }
         if ($this->result = $GLOBALS['db']->query('SELECT * FROM `sessions` WHERE `chatid`="' . $chatid . '" ORDER BY `id` DESC LIMIT 1')) {
             if ($this->result[0]['typeg'] !== '0') {
                 $this->response .= 'typing|';
                 if ($this->result[0]['typeg'] < $type_limit) {
                     $GLOBALS['db']->query('UPDATE `sessions` SET `typeg`="0" WHERE `chatid`="' . $chatid . '"');
                 }
             }
             if ($this->result[0]['timeg'] < $chat_limit) {
                 $this->response .= 'close|';
             }
         } else {
             $this->response .= 'close|';
         }
         if ($checksum !== '' && intval($checksum) !== intval($this->checksum($chatid, $admin))) {
             $this->response .= 'display|';
         }
         if ($message = $this->get_message($admin, $chatid)) {
             $this->response .= 'message:' . $message . '|';
         }
         if ($this->allow_transfer($admin, $chatid)) {
             $this->response .= 'upload|';
         }
         if ($filesize = $this->get_files($admin, $chatid)) {
             $this->response .= 'download:' . $filesize . ':' . $_SESSION['hcl_' . $chatid]['fileid'] . '|';
         }
         if ($this->get_transfer($admin, $chatid)) {
             $this->response .= 'transfer-yes|';
             $this->response .= 'transfer-operator:' . $_SESSION['hcl_' . $chatid]['operator'] . '|';
             $this->response .= 'transfer-department:' . $_SESSION['hcl_' . $chatid]['department'] . '|';
         }
         if ($GLOBALS['chat']->no_transfer($admin, $chatid)) {
             $this->response .= 'transfer-no|';
         }
         if ($checksum !== '') {
             if ($typing == 'true') {
                 $GLOBALS['db']->query('UPDATE `sessions` SET `typeo`=UNIX_TIMESTAMP() WHERE `chatid`="' . $chatid . '"');
             } else {
                 $GLOBALS['db']->query('UPDATE `sessions` SET `typeo`="0" WHERE `chatid`="' . $chatid . '"');
             }
         }
     } else {
         $GLOBALS['db']->query('UPDATE `sessions` SET `timeg`=UNIX_TIMESTAMP() WHERE `chatid`="' . $chatid . '"');
         if ($this->result = $GLOBALS['db']->query('SELECT * FROM `sessions` WHERE `chatid`="' . $chatid . '" ORDER BY `id` DESC LIMIT 1')) {
             if ($this->result[0]['typeo'] !== '0') {
                 $this->response .= 'typing|';
                 if ($this->result[0]['typeo'] < $type_limit) {
                     $GLOBALS['db']->query('UPDATE `sessions` SET `typeo`="0" WHERE `chatid`="' . $chatid . '"');
                 }
             }
             if ($this->result[0]['timeo'] < $chat_limit) {
                 $this->response .= 'close|';
             }
         } else {
             $this->response .= 'close|';
         }
         if ($checksum !== '' && intval($checksum) !== intval($this->checksum($chatid, $admin))) {
             $this->response .= 'display|';
         }
         if ($message = $this->get_message($admin, $chatid)) {
             $this->response .= 'message:' . $message . '|';
         }
         if ($push = $this->get_push()) {
             $this->response .= 'push:' . $push . '|';
             $this->keep_awake($admin, $chatid);
         }
         if ($this->allow_transfer($admin, $chatid)) {
             $this->response .= 'upload|';
         }
         if ($this->hold($admin, $chatid)) {
             $this->response .= 'hold|';
         }
         if ($this->resume($admin, $chatid)) {
             $this->response .= 'resume|';
         }
         if ($filesize = $this->get_files($admin, $chatid)) {
             $this->response .= 'download:' . $filesize . ':' . $_SESSION['hcl_' . $chatid]['fileid'] . '|';
         }
         if ($this->get_transfer($admin, $chatid)) {
             $this->response .= 'transfer-yes|';
             $this->response .= 'transfer-operator:' . $_SESSION['hcl_' . $chatid]['operator'] . '|';
             $this->response .= 'transfer-department:' . $_SESSION['hcl_' . $chatid]['department'] . '|';
         }
         if ($GLOBALS['chat']->no_transfer($admin, $chatid)) {
             $this->response .= 'transfer-no|';
         }
         if ($GLOBALS['cobrowse']->started()) {
             $this->response .= 'cobrowse|';
         } elseif (!$GLOBALS['cobrowse']->getpage($chatid)) {
             $this->response .= 'cobrowse-disconnect|';
         }
         if ($GLOBALS['cobrowse']->changedpage($chatid, $copage)) {
             $this->response .= 'copage:' . urlencode($GLOBALS['cobrowse']->getpage($chatid)) . '|';
         }
         if ($forms = $GLOBALS['cobrowse']->getforms($chatid, 'false')) {
             foreach ($forms as $key => $val) {
                 $this->response .= 'coforms:' . $forms[$key]['type'] . ':' . rawurlencode(html_to_char(html_to_char($forms[$key]['name']))) . ':' . rawurlencode(html_to_char(html_to_char($forms[$key]['value']))) . '|';
             }
         }
         if ($marker = $GLOBALS['cobrowse']->getmarker($chatid)) {
             $this->response .= 'comarker:' . $marker['type'] . ':' . $marker['x'] . ':' . $marker['y'] . '|';
         }
         if ($GLOBALS['cobrowse']->clearmarkers($chatid, 'false')) {
             $this->response .= 'comarker-clear|';
         }
         if ($GLOBALS['cobrowse']->enabled($chatid)) {
             $this->response .= 'cobrowse-allow|';
         } else {
             $this->response .= 'cobrowse-disallow|';
         }
         if ($typing == 'true') {
             $GLOBALS['db']->query('UPDATE `sessions` SET `typeg`=UNIX_TIMESTAMP() WHERE `chatid`="' . $chatid . '"');
         } else {
             $GLOBALS['db']->query('UPDATE `sessions` SET `typeg`="0" WHERE `chatid`="' . $chatid . '"');
         }
     }
     return $this->response;
 }
 function get($chatid = '', $id = '', $admin = '')
 {
     if ($chatid == '' && $id == '') {
         $this->transcripts = array();
         if ($GLOBALS['auth']->admin() && $admin == 'admin') {
             if ($this->result = $GLOBALS['db']->query('SELECT * FROM `departments` WHERE 1')) {
                 foreach ($this->result as $key => $val) {
                     if ($this->result2 = $GLOBALS['db']->query('SELECT * FROM `transcripts` WHERE `departmentid`="' . $this->result[$key]['id'] . '" ORDER BY `timestamp` DESC')) {
                         foreach ($this->result2 as $key2 => $val2) {
                             $this->result2[$key2]['time'] = gmdate('G:i:s D jS F Y', $this->result2[$key2]['timestamp'] + 3600 * $GLOBALS['conf']['offset']);
                         }
                         $this->transcripts = array_merge($this->transcripts, array(array('name' => $GLOBALS['department']->name($this->result[$key]['id']), 'transcript' => $this->result2)));
                     }
                 }
             }
         } else {
             if ($this->result = $GLOBALS['db']->query('SELECT * FROM `assigns` WHERE `operatorid`="' . $GLOBALS['operator']->id() . '"')) {
                 foreach ($this->result as $key => $val) {
                     if ($this->result2 = $GLOBALS['db']->query('SELECT * FROM `transcripts` WHERE `departmentid`="' . $this->result[$key]['departmentid'] . '" AND `operatorid`="' . $GLOBALS['operator']->id() . '" ORDER BY `timestamp` DESC')) {
                         foreach ($this->result2 as $key2 => $val2) {
                             $this->result2[$key2]['time'] = gmdate('G:i:s D jS F Y', $this->result2[$key2]['timestamp'] + 3600 * $GLOBALS['conf']['offset']);
                         }
                         $this->transcripts = array_merge($this->transcripts, array(array('name' => $GLOBALS['department']->name($this->result[$key]['departmentid']), 'transcript' => $this->result2)));
                     }
                 }
             }
         }
         return $this->transcripts;
     } elseif ($id !== '') {
         $this->transcripts = array();
         if ($this->result = $GLOBALS['db']->query('SELECT * FROM `transcripts` WHERE `id`="' . $id . '"')) {
             if ($GLOBALS['auth']->admin() && $admin == 'admin') {
                 $this->transcripts['id'] = $this->result[0]['id'];
                 $this->transcripts['nick'] = $this->result[0]['guest'];
                 $this->transcripts['operator'] = $GLOBALS['operator']->name($this->result[0]['operatorid']);
                 $this->transcripts['department'] = $GLOBALS['department']->name($this->result[0]['departmentid']);
                 $this->transcripts['email'] = $GLOBALS['department']->email($this->result[0]['departmentid']);
                 $this->transcripts['time'] = gmdate('G:i:s D jS F Y', $this->result[0]['timestamp'] + 3600 * $GLOBALS['conf']['offset']);
                 $this->transcripts['chat'] = rawurldecode($this->result[0]['transcript']);
                 return $this->transcripts;
             } elseif ($this->result2 = $GLOBALS['db']->query('SELECT * FROM `assigns` WHERE `operatorid`="' . $GLOBALS['operator']->id() . '"')) {
                 foreach ($this->result2 as $key => $val) {
                     if ($this->result2[$key]['departmentid'] == $this->result[0]['departmentid']) {
                         $this->transcripts['id'] = $this->result[0]['id'];
                         $this->transcripts['nick'] = $this->result[0]['guest'];
                         $this->transcripts['operator'] = $GLOBALS['operator']->name($this->result[0]['operatorid']);
                         $this->transcripts['department'] = $GLOBALS['department']->name($this->result[0]['departmentid']);
                         $this->transcripts['email'] = $GLOBALS['department']->email($this->result[0]['departmentid']);
                         $this->transcripts['time'] = gmdate('G:i:s D jS F Y', $this->result[0]['timestamp'] + 3600 * $GLOBALS['conf']['offset']);
                         $this->transcripts['chat'] = rawurldecode($this->result[0]['transcript']);
                         return $this->transcripts;
                     }
                 }
             }
         } else {
             return false;
         }
     } else {
         $this->chat = '';
         $this->result = $GLOBALS['db']->query('SELECT * FROM `traffic` WHERE `id`="' . $chatid . '"');
         if ($this->result2 = $GLOBALS['db']->query('SELECT * FROM `chat` WHERE `chatid`="' . $chatid . '" ORDER BY `timestamp` ASC')) {
             foreach ($this->result2 as $key => $val) {
                 $this->timestamp = gmdate('G:i:s', $this->result2[$key]['timestamp'] + 3600 * $GLOBALS['conf']['offset']);
                 if ($this->result2[$key]['x'] == 'o') {
                     $this->text = html_to_char(rawurldecode($this->result2[$key]['message'])) . ' ';
                     $this->text = preg_replace("/%%user%%/i", $_SESSION['hcl_' . $chatid]['guest'], $this->text);
                     $this->text = preg_replace("/url:(.*?) /i", "<a href=\"\\1\" target=\"_blank\">\\1</a> ", $this->text);
                     $this->text = preg_replace("/image:(.*?) /i", "<img src=\"\\1\" alt=\"image\" /> ", $this->text);
                     $this->text = preg_replace("/email:(.*?) /i", "<a href=\"\\1\">\\1</a> ", $this->text);
                     $this->text = preg_replace("/push:(.*?) /i", "<i>Pushed Page: \\1</i> ", $this->text);
                     $this->text = substr($this->text, 0, -1);
                     $this->text = '<span class="operator"><i>(' . $this->timestamp . ')</i> <b>' . $_SESSION['hcl_' . $chatid]['operator'] . ':</b> ' . char_to_html($this->text) . '</span><br />';
                 } else {
                     $this->text = '<span class="guest"><i>(' . $this->timestamp . ')</i> <b>' . $_SESSION['hcl_' . $chatid]['guest'] . ':</b> ' . rawurldecode($this->result2[$key]['message']) . '</span><br />';
                 }
                 $this->chat = $this->chat . $this->text;
             }
             return $this->chat;
         } else {
             return 'Error';
         }
     }
 }