// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program in a file named LICENSE.txt . //=========================================================================== require_once "visitor_common.php"; // get the info of this user.. $query = "SELECT * FROM livehelp_users WHERE sessionid='" . $identity['SESSIONID'] . "'"; $people = $mydatabase->query($query); $people = $people->fetchRow(DB_FETCHMODE_ASSOC); $myid = $people['user_id']; $channel = $people['onchannel']; $isnamed = $people['isnamed']; // get a channel for this user: $onchannel = createchannel($myid); // get department information... $where = ""; if (!isset($UNTRUSTED['department'])) { $UNTRUSTED['department'] = ""; } if (!isset($UNTRUSTED['printit'])) { $UNTRUSTED['printit'] = ""; } if ($UNTRUSTED['department'] != "") { $where = " WHERE recno=" . intval($UNTRUSTED['department']); } $query = "SELECT * FROM livehelp_departments {$where} "; $data_d = $mydatabase->query($query); $department_a = $data_d->fetchRow(DB_FETCHMODE_ASSOC); $department = $department_a['recno'];
// get the info of this user.. $query = "SELECT * \n FROM livehelp_users \n WHERE sessionid='" . $identity['SESSIONID'] . "'"; $people = $mydatabase->query($query); $people = $people->fetchRow(DB_FETCHMODE_ASSOC); $myid = $people['user_id']; $channel = $people['onchannel']; $isadminsetting = $people['isadmin']; $timeof = date("YmdHis"); if (empty($UNTRUSTED['what'])) { $UNTRUSTED['what'] = ""; } if (!empty($UNTRUSTED['selectedwho'])) { $pairs = explode("__", $UNTRUSTED['selectedwho']); for ($i = 0; $i < count($pairs); $i++) { $selected = $pairs[$i]; $whatchannel = createchannel($selected); $query = "DELETE \n FROM livehelp_operator_channels \n WHERE user_id=" . intval($myid) . " \n AND userid=" . intval($selected); $mydatabase->query($query); $timeof = date("YmdHis"); } } // open up layer directory and get list of layer invites: $dir = "layer_invites" . C_DIR; $handle = opendir($dir); $i = 0; $count = 101; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && preg_match("/layer/", $file)) { $imageurl = $file; if (is_file("{$dir}" . C_DIR . "{$file}") && !preg_match("/.txt/", $file)) { $parts = explode(".", $file);
if ($UNTRUSTED['what'] == "send") { $pair = explode(",", $UNTRUSTED['channelsplit']); for ($i = 0; $i < count($pair); $i++) { $split = $pair[$i]; $array = explode("__", $split); $saidto = $array[1]; $channel = $array[0]; if ($saidto == "") { $channel = -1; } $query = "UPDATE livehelp_users set status='request' WHERE user_id=" . intval($saidto); $mydatabase->query($query); $query = "INSERT INTO livehelp_messages (message,channel,timeof,saidfrom,saidto) VALUES ('" . filter_sql($UNTRUSTED['comment']) . "'," . intval($channel) . ",'{$timeof}'," . intval($myid) . "," . intval($saidto) . ")"; $mydatabase->query($query); if (!empty($UNTRUSTED['askquestions'])) { $whatchannel = createchannel(intval($saidto)); $now = date("YmdHis"); $query = "UPDATE livehelp_users set isnamed='Y',askquestions='N',chataction='{$now}' WHERE user_id=" . intval($saidto); $mydatabase->query($query); // add operator answer call. // generate random Hex.. $txtcolor_alt = get_next_color_ordered("clients"); // generate random Hex.. $txtcolor = get_next_color_ordered("operators"); $query = "DELETE FROM livehelp_operator_channels WHERE user_id=" . intval($myid) . " AND userid=" . intval($saidto); $mydatabase->query($query); $channelcolor = get_next_color_ordered("backgrounds"); $query = "INSERT INTO livehelp_operator_channels (user_id,channel,userid,txtcolor,txtcolor_alt,channelcolor) VALUES (" . intval($myid) . "," . intval($whatchannel) . "," . intval($saidto) . ",'{$txtcolor}','{$txtcolor_alt}','{$channelcolor}')"; $mydatabase->query($query); // add to history: $query = "INSERT INTO livehelp_operator_history (opid,action,dateof,channel,totaltime) VALUES ({$myid},'startchat','" . date("YmdHis") . "'," . intval($whatchannel) . ",0)";
$questiondata = $mydatabase->query($sqlquery); $question_row = $questiondata->fetchRow(DB_FETCHMODE_ASSOC); if ($l != 0) { $datamessage .= "<br>"; } $datamessage .= "<b>" . $question_row['headertext'] . "</b><br>" . urldecode($dataset[1]); } } if ($datamessage != "") { $timeof = rightnowtime(); $sqlquery = "INSERT INTO livehelp_messages (saidto,saidfrom,message,channel,timeof) VALUES (" . intval($myid) . "," . intval($UNTRUSTED['who']) . ",'" . filter_sql($datamessage) . "'," . intval($UNTRUSTED['whatchannel']) . ",'{$timeof}')"; $mydatabase->query($sqlquery); } } if (empty($whatchannel) || $whatchannel == 0) { $whatchannel = createchannel($UNTRUSTED['who']); } // generate random Hex.. $txtcolor_alt = get_next_color_ordered("clients"); $txtcolor = get_next_color_ordered("operators"); $sqlquery = "DELETE FROM livehelp_operator_channels WHERE user_id=" . intval($myid) . " AND userid=" . intval($UNTRUSTED['who']); $mydatabase->query($sqlquery); $channelcolor = get_next_color_ordered("backgrounds"); $sqlquery = "INSERT INTO livehelp_operator_channels (user_id,channel,userid,txtcolor,txtcolor_alt,channelcolor) VALUES (" . intval($myid) . "," . intval($whatchannel) . "," . intval($UNTRUSTED['who']) . ",'{$txtcolor}','{$txtcolor_alt}','{$channelcolor}')"; $mydatabase->query($sqlquery); // add to history: $query = "INSERT INTO livehelp_operator_history (opid,action,dateof,channel,totaltime) VALUES ({$myid},'startchat','" . date("YmdHis") . "'," . intval($whatchannel) . ",0)"; $mydatabase->query($query); $timeof = rightnowtime(); if (!empty($UNTRUSTED['conferencein'])) { $channelcolor = get_next_color_ordered("backgrounds");
if (!empty($dataset[1])) { $fieldid = str_replace("field_", "", $dataset[0]); $query = "SELECT * FROM livehelp_questions WHERE id=" . intval($fieldid); $questiondata = $mydatabase->query($query); $question_row = $questiondata->fetchRow(DB_FETCHMODE_ASSOC); $datamessage .= $question_row['headertext'] . "<br><font color=000000><b>" . urldecode($dataset[1]) . "</font></b><br>"; } } if ($datamessage != "") { $timeof = rightnowtime(); $query = "INSERT INTO livehelp_messages (saidto,saidfrom,message,channel,timeof) VALUES (" . intval($myid) . "," . intval($who) . ",'<br>" . filter_sql($datamessage) . "'," . intval($whatchannel) . ",'{$timeof}')"; $mydatabase->query($query); } } if (empty($whatchannel) || $whatchannel == 0) { $whatchannel = createchannel(intval($UNTRUSTED['who'])); } // generate random Hex.. $txtcolor = ""; $lowletters = array("0", "2", "4", "6"); for ($index = 1; $index <= 6; $index++) { $randomindex = rand(0, 3); $txtcolor .= $lowletters[$randomindex]; } // generate random Hex.. $txtcolor_alt = ""; $lowletters = array("2", "4", "6", "8"); for ($index = 1; $index <= 6; $index++) { $randomindex = rand(0, 3); $txtcolor_alt .= $lowletters[$randomindex]; }
$pageurl = $pageurl . "&department=" . intval($UNTRUSTED['department']); } $url = $pageurl . $querystringadd; $urlforchat = str_replace("&&", "&", $url); include "themes/{$theme}/chatwindow_large.php"; } else { // get the info of this user.. $query = "SELECT * FROM livehelp_users WHERE sessionid='" . $identity['SESSIONID'] . "'"; $people = $mydatabase->query($query); $people = $people->fetchRow(DB_FETCHMODE_ASSOC); $myid = $people['user_id']; $channel = $people['onchannel']; $isnamed = $people['isnamed']; $department = $people['department']; // get a channel for this user: $onchannel = createchannel($myid, $department); // get department information... $where = ""; if (!isset($UNTRUSTED['department'])) { $UNTRUSTED['department'] = ""; } if (!isset($UNTRUSTED['printit'])) { $UNTRUSTED['printit'] = ""; } if ($UNTRUSTED['department'] != "") { $where = " WHERE recno=" . intval($UNTRUSTED['department']); } $query = "SELECT * FROM livehelp_departments {$where} "; $data_d = $mydatabase->query($query); $department_a = $data_d->fetchRow(DB_FETCHMODE_ASSOC); $colorscheme = $department_a['colorscheme'];
/** * Auto invite users based on identity of user * * @param array $identity array containing session/user information. * @param string $status current status of the user. * @param int $department that user is on. * * @global object $mydatabase mysql database object. * * @return bool true if invited */ function autoinvite($identity, $status = "", $department = 0) { global $mydatabase, $dbtype, $CSLH_Config, $isavisitor; if ($status == 'invited' or $status == 'wentaway' or $status == 'chat' or $status == 'operator' or $status == 'stopped' or $status == 'request') { return false; } // make list of ignored visitors: $ipadd = explode(",", $CSLH_Config['ignoreips']); $ignoreme = false; for ($i = 0; $i < count($ipadd); $i++) { if (!empty($ipadd[$i])) { if (preg_match("/" . $ipadd[$i] . "/", $identity['IP_ADDR'])) { $ignoreme = true; } } } if ($ignoreme) { return false; } // if this is a Visitor: if ($isavisitor) { // see if any online operator in this department has autoinvite on: $sqlquery = "SELECT isonline \n FROM livehelp_users,livehelp_operator_departments \n WHERE livehelp_users.user_id=livehelp_operator_departments.user_id\n AND livehelp_users.authenticated='Y'\n AND livehelp_users.isoperator='Y'"; if (intval($department) != 0) { $sqlquery .= " AND livehelp_operator_departments.department=" . intval($department); } $sqlquery .= " AND livehelp_users.auto_invite='Y' AND livehelp_users.isonline='Y' LIMIT 1"; $tmpdata = $mydatabase->query($sqlquery); // someone is online invite the user: if ($tmpdata->numrows() != 0) { // get users track record: $sqlquery = "SELECT camefrom,user_id FROM livehelp_users WHERE sessionid='" . $identity['SESSIONID'] . "' LIMIT 1"; $res = $mydatabase->query($sqlquery); $user_info = $res->fetchRow(DB_FETCHMODE_ORDERED); $camefrom = $user_info[0]; $user_id = $user_info[1]; $pathstuff = explode("?", $camefrom); $camefrom = $pathstuff[0]; $camefrom = str_replace("http://", "", $camefrom); $camefrom = str_replace("www.", "", $camefrom); $sqlquery = "SELECT location from livehelp_visit_track WHERE sessionid='" . $identity['SESSIONID'] . "' ORDER BY whendone DESC"; $footprints = $mydatabase->query($sqlquery); $visits = $footprints->numrows(); $foot = $footprints->fetchRow(DB_FETCHMODE_ORDERED); $pathstuff = explode("?", $foot[0]); $pageurl = $pathstuff[0]; $pageurl = str_replace("http://", "", $pageurl); $pageurl = str_replace("www.", "", $pageurl); // time online: $query = "SELECT whendone from livehelp_visit_track WHERE sessionid='" . filter_sql($identity['SESSIONID']) . "' Order by whendone LIMIT 1"; $page_trail = $mydatabase->query($query); $page = $page_trail->fetchRow(DB_FETCHMODE_ASSOC); $later = $page['whendone']; $timeon = timediff($later, date("YmdHis")); $sqlquery = "SELECT * FROM livehelp_autoinvite WHERE "; $sqlquery .= " (department=0 OR department=" . intval($department) . " ) "; $sqlquery .= " AND (visits=0 OR visits<={$visits}) "; $sqlquery .= " AND (seconds=0 OR seconds<={$timeon}) "; $sqlquery .= " AND isactive='Y'"; // print $sqlquery; $data = $mydatabase->query($sqlquery); if (!empty($pageurl) && $data->numrows() != 0) { // look for match for page and camefrom: while ($row = $data->fetchRow(DB_FETCHMODE_ASSOC)) { $comment = $row['message']; $typeof = $row['typeof']; $page = $row['page']; $refpage = $row['referer']; $socialpane = $row['socialpane']; $thisuserid = $row['user_id']; $excludemobile = $row['excludemobile']; $onlymobile = $row['onlymobile']; if (empty($refpage)) { $refpage = "."; } if (empty($camefrom)) { $camefrom = "."; } if (empty($page)) { $page = "."; } if (empty($pageurl)) { $pageurl = "."; } // panel invite: if ($socialpane == "Y") { $sessiondata = "tab=,nvoks,drdwm&nvoks=Eric&openPop=Eric&drdwm=Eric&"; $query = "UPDATE livehelp_users set sessiondata='{$sessiondata}' WHERE user_id=" . intval($user_id); $mydatabase->query($query); } // if match: if (preg_match("/" . $refpage . "/", $camefrom) && preg_match("/" . $page . "/", $pageurl)) { // if we are looking only for a specific user_id if ($thisuserid == 0 || userisonline($thisuserid)) { $whatchannel = createchannel($user_id); $timeof = date("YmdHis"); $channel = $whatchannel; if ($user_id == "") { $channel = -1; } if ($typeof == "layer") { $sqlquery = "UPDATE livehelp_users set status='DHTML',sessiondata='invite=" . filter_sql($comment) . "' WHERE user_id=" . intval($user_id); $mydatabase->query($sqlquery); } else { $sqlquery = "UPDATE livehelp_users set status='request' WHERE user_id=" . intval($user_id); $mydatabase->query($sqlquery); $sqlquery = "INSERT INTO livehelp_messages (message,channel,timeof,saidfrom,saidto) VALUES ('" . filter_sql($comment) . "'," . intval($channel) . ",'{$timeof}',0," . intval($user_id) . ")"; $mydatabase->insert($sqlquery); } return true; } // end user_id match } // end preg match } // end loop of auto results } // end of if auto found. } // end of if someone is online. // this is an operator: } else { // maybe auto invite inactive people .. but that seems like too much work... return false; } return false; }