| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/usa_sites/usafundingapplications.ai/vsa/ |
Upload File : |
<?php
/*
Copyright (c) 2007-present InnAnTech Industries
Author: Dave Guindon
Web: www.VirtualSmartAgent.com
Support: www.DaveGuindonSupport.com
Please send bug reports, suggestions and/or feedback to the support
website given above.
Virtual Smart Agent is a commercial software. Any distribution is strictly prohibited
unless a resale rights license was delivered along with this software.
This script contains several functions used throughout the agent system
*/
/*==================================================================*/
function ReplaceTags($s,$a,$cid,$aid,$cli,$pid,$testmode='0'){
/*
this function is used to replace tags in the agent response messages
*/
global $systemcodes, $linksTable, $settingsTable, $userdataTable, $usernameTable, $aweber_nametext, $conn;
//check for tags in message
if (strpos($s, '%%')!==false){
//replace all system codes here (this is a little weird because of the agent name)
foreach($systemcodes as $key=>$value){
//check if this code is contained in the message string
if (strpos($s, $value[0]) !== false){
//check for date codes
if (strpos($key,'date') !== false){
$s = str_replace($value[0], date($value[1]), $s);
}else if ($key == 'agentname'){ //or simply replace code
$s = str_replace($value[0], $a, $s);
}else if ($key == 'visitorname'){
$user_name = '';
//check if visitor name was given
$sql = "SELECT * FROM $usernameTable WHERE cid='$cid' AND chatlogid='$cli'";
$myres = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$nc = mysql_num_rows($myres);
if ($nc > 0){
$userdata = mysql_fetch_assoc($myres);
$user_name = $userdata['name'];
$user_name = stripslashes($user_name);
$user_name = trim($user_name);
}else{
$sql = "SELECT * FROM $userdataTable WHERE cid='$cid' AND chatlogid='$cli'";
$myres = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$nc = mysql_num_rows($myres);
if ($nc > 0){
$userdata = mysql_fetch_assoc($myres);
$user_name = $userdata['name'];
$user_name = stripslashes($user_name);
$user_name = trim($user_name);
}
}
if ($user_name != ''){
$s = str_replace($value[0], $user_name, $s);
}else{
$s = str_replace($value[0], '', $s);
}
}//end if
}//end if
}//end foreach
//build the tracking link url
$sql = "SELECT * FROM $settingsTable";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$sdata = mysql_fetch_assoc($result);
$installfolder = $sdata['installfolder'];
$installsite = $sdata['installsite'];
$linkurl = $installsite.$installfolder.'links.php?cid='.$cid.'&aid='.$aid.'&cli='.$cli.'&pid='.$pid.'&tmd='.$testmode;
//replace any tags with predefeined links in the links table
$sql = "SELECT * FROM $linksTable WHERE cid='$cid'"; //get all preset links
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
if ($result){
$nc = mysql_num_rows($result);
if ($nc > 0){
$t = ''; //tmp array
while(list($id,$cid,$code,$content,$link,$style)=@mysql_fetch_row($result)){
//create link to replace the code
$thelink = $linkurl.'&lid='.$id;
if ($style){ //check for styling
#$insert = '<a href="'.$thelink.'" target="_blank"><span style="'.$style.'">'.$content.'</span></a>';
$insert = '<a href="'.$thelink.'" target="_top"><span style="'.$style.'">'.$content.'</span></a>';
}else{
#$insert = '<a href="'.$thelink.'" target="_blank">'.$content.'</a>';
$insert = '<a href="'.$thelink.'" target="_top">'.$content.'</a>';
}
$s = str_replace($code, $insert, $s);
}//end while
}//end if $nc
}//end if $result
}//end if strpos
return $s;
}
/*==================================================================*/
function SetStats($cid,$agentid,$picid,$chatlogid,$linksid,$ip,$type,$testmode='0'){
/*
this function simply logs statistics: pageview, initiation, interation, click, or sale
*/
global $campaignTable, $statsTable, $conn;
//check for testmode
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')){
//get todays date
$dtoday = time();
//insert this stat into the stats table
$sql = "INSERT INTO $statsTable VALUES(null,'$cid','$agentid','$picid','$chatlogid','$linksid','$ip','$type','$dtoday')";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}//end testmode
}
/*==================================================================*/
function SetChatlog($n,$cid,$chatlogid,$ip,$agentid,$testmode='0'){
/*
this function records the start and end time for the given chat id
*/
global $campaignTable, $chatlogTable, $conn, $doselfclean, $selfcleanperiod;
//check for testmode
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')){
if($n == 1){
//get todays date
$dtoday = time();
//check old chat logs for chatend=0 and delete if they are 7 days old ... self cleaning!
if ($doselfclean == '1'){
$sql = "DELETE FROM $chatlogTable WHERE cid='$cid' AND chatend='0' AND action='start' AND $dtoday - chatstart >= '$selfcleanperiod'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}
//start new chat log
$sql = "INSERT INTO $chatlogTable VALUES(null,'$cid','$agentid','$dtoday','0','$ip','start')";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
//get the last id
$thisres = mysql_query("SELECT LAST_INSERT_ID()",$conn);mysql_error()?(print(mysql_error())):'';
$tmprec = mysql_fetch_row($thisres);
$lastid = $tmprec[0];
return $lastid;
}else{
//stop given chat log
//get the current datestamp
$dtoday = time();
//first check the action type
$sql = "SELECT * FROM $chatlogTable WHERE id='$chatlogid'";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$cdata = mysql_fetch_assoc($result);
$action = $cdata['action'];
if ($action == 'start'){
//if there was no action performed during the chat, then set action to closed meaning nothing happened
$sql = "UPDATE $chatlogTable SET chatend='$dtoday', action='closed' WHERE id='$chatlogid' AND cid='$cid'";
}else{
//otherwise do not set the action field because it is already set from somewhere else ... like an interaction or followed link
$sql = "UPDATE $chatlogTable SET chatend='$dtoday' WHERE id='$chatlogid' AND cid='$cid'";
}
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
//send the auto thank you email advertisment here
SendAutoEmail($cid,$chatlogid,$ip,$agentid,$testmode);
}
}//end testmode
}
/*==================================================================*/
function SetUserData($cid,$cli,$ip,$aid,$name,$email,$testmode='0'){
/*
this function enters the user input data into the user data table
*/
global $campaignTable, $userdataTable, $chatlogTable, $conn;
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')){
//check if this record already exists
//$sql = "SELECT * FROM $userdataTable WHERE email='$email' AND chatlogid='$cli' AND cid='$cid'";
$sql = "SELECT * FROM $userdataTable WHERE agentid='$aid' AND chatlogid='$cli' AND cid='$cid'";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$nc = mysql_num_rows($result);
if ($nc == 0){
//enter this record
$dtoday = time();
$sql = "INSERT INTO $userdataTable VALUES(null,'$cid','$cli','$aid','$name','$email','0','$ip',$dtoday)";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
//NEW update the chatend for all interactions for the case when closing doesn't work
$sql = "UPDATE $chatlogTable SET action='operation', chatend='$dtoday' WHERE id='$cli' AND cid='$cid'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}else if ($nc == 1){
$userdata = mysql_fetch_assoc($result);
$id = $userdata['id'];
$sql = "UPDATE $userdataTable SET name='$name', email='$email' WHERE id='$id'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}
}//end testmode
}
/*==================================================================*/
function SetUserDataName($cid,$cli,$ip,$aid,$name,$testmode='0'){
/*
this function enters the user input name to a user name data table
*/
global $campaignTable, $usernameTable, $chatlogTable, $conn;
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')){
//check if this record already exists
$sql = "SELECT * FROM $usernameTable WHERE agentid='$aid' AND chatlogid='$cli' AND cid='$cid'";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$nc = mysql_num_rows($result);
if ($nc == 0){
//enter this record
$dtoday = time();
$sql = "INSERT INTO $usernameTable VALUES(null,'$cid','$cli','$aid','$name','$ip',$dtoday)";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
//NEW update the chatend for all interactions for the case when closing doesn't work
$sql = "UPDATE $chatlogTable SET action='operation', chatend='$dtoday' WHERE id='$cli' AND cid='$cid'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}else if ($nc == 1){
$userdata = mysql_fetch_assoc($result);
$id = $userdata['id'];
$sql = "UPDATE $usernameTable SET name='$name' WHERE id='$id'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}
}//end testmode
}
/*==================================================================*/
function SetChatData($cid,$chatlogid,$agentid,$sender,$message,$testmode='0'){
/*
this function enters a chat data record into the chat data table
*/
global $campaignTable, $chatdataTable, $chatlogTable, $conn;
//check for testmode
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')){
//get todays date
$dtoday = time();
$message = addslashes($message);
$sql = "INSERT INTO $chatdataTable VALUES(null,'$cid','$chatlogid','$agentid','$sender','$message','$dtoday')";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
//check if this chat is interactive and update the chatlog table
//NEW update the chatend for all interactions for the case when closing doesn't work
if ($sender == 'user'){
$sql = "UPDATE $chatlogTable SET action='operation', chatend='$dtoday' WHERE id='$chatlogid' AND cid='$cid'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}
}//end testmode
}
/*==================================================================*/
function SetNoCommentChatData($cid,$chatlogid,$agentid,$message,$testmode='0'){
/*
this function enters a message that was not answered by the agent
*/
global $campaignTable, $nocommentTable, $settingsTable, $userdataTable, $conn;
//check for testmode
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')){
//get todays date
$dtoday = time();
$message = addslashes($message);
$sql = "INSERT INTO $nocommentTable VALUES(null,'$cid','$chatlogid','$agentid','$message','$dtoday')";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
//send email notification to administrator
if ($camp['sendnocomment'] == '1'){
$sql = "SELECT * FROM $settingsTable";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$data = mysql_fetch_assoc($result);
//check if name and email was given
$sql = "SELECT * FROM $userdataTable WHERE cid='$cid' AND chatlogid='$chatlogid'";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$nc = mysql_num_rows($result);
if ($nc > 0){
$userdata = mysql_fetch_assoc($result);
$user_name = $userdata['name'];
$user_email = $userdata['email'];
}else{
$user_email = '';
}
$message = stripslashes($message);
$fromemail = $camp['nocommentemail'];
$fromemail = stripslashes($fromemail);
$subject = '[Virtual Smart Agent] '.$camp['label'].' - Unanswered Question';
$mm = '{Automated Message}'."\n\r";
$mm .= 'There was an unanswered question from your Virtual Smart Agent with the following details:'."\n\r";
$mm .= 'Campaign Label: '.$camp['label']."\n\r";
$mm .= 'Campaign Description: '.$camp['description']."\n\r";
$mm .= 'Unanswered Question: '.$message."\n\r";
if ($user_email != ''){
$mm .= 'User Name: '.$user_name."\n\r";
$mm .= 'User Email: '.$user_email."\n\r";
}
$mm .= 'Login: '.$data['installsite'].$data['installfolder'].'login.php';
SendEmail($fromemail,$fromemail,$subject,$mm);
}
}//end testmode
}
/*==================================================================*/
function SendEmail($fromemail,$sendemail,$subject,$message){
$headers = "From: $fromemail\n";
$headers .= "Reply-To: $fromemail\n";
$headers .= "Return-Path: $fromemail\n";
$headers .= "X-Mailer: PHP/".phpversion();
mail($sendemail, $subject, $message, $headers);
}
/*==================================================================*/
function hex2rgb($color){
$color_array = array();
$hex_color = strtoupper($color);
for($i = 0; $i < 6; $i++){
$hex = substr($hex_color,$i,1);
switch($hex){
case "A": $num = 10; break;
case "B": $num = 11; break;
case "C": $num = 12; break;
case "D": $num = 13; break;
case "E": $num = 14; break;
case "F": $num = 15; break;
default: $num = $hex; break;
}
array_push($color_array,$num);
}
$R = (($color_array[0] * 16) + $color_array[1]);
$G = (($color_array[2] * 16) + $color_array[3]);
$B = (($color_array[4] * 16) + $color_array[5]);
return array($R,$G,$B);
unset($color_array,$hex,$R,$G,$B);
}
/*==================================================================*/
function rgb2hsv($rgb){
$var_r = ($rgb[0] / 255);
$var_g = ($rgb[1] / 255);
$var_b = ($rgb[2] / 255);
// Min. value of RGB
$var_min = min($var_r, $var_g, $var_b);
// Max. value of RGB
$var_max = max($var_r, $var_g, $var_b);
// Delta RGB value.
$del_max = $var_max - $var_min;
$v = $var_max;
if($del_max == 0) {
// This is a gray, no chroma
// HSV results = 0 � 1
$h = 0;
$s = 0;
} else {
// Chromatic data
$s = $del_max / $var_max;
$del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
$del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
$del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
if($var_r == $var_max) {
$h = $del_b - $del_g;
} elseif($var_g == $var_max) {
$h = (1 / 3) + $del_r - $del_b;
} elseif($var_b == $var_max) {
$h = (2 / 3) + $del_g - $del_r;
}
if($h < 0) {
$h += 1;
}
if($h > 1) {
$h -= 1;
}
}
if($h != 0){ $h = round($h*100); }
if($s != 0){ $s = round($s*100); }
if($v != 0){ $v = round($v*100); }
return array($h, $s, $v);
}
/*==================================================================*/
function MakeVisibleColor($c){
$dd = rgb2hsv(hex2rgb($c));
if ($dd[2] <= 58){
$cc = 'FFFFFF';
}else{
$cc = '000000';
}
return $cc;
}
/*==================================================================*/
function checkEmail($email){
//this is a great function for validating an email address
//if php version < 5.2
if ( version_compare( phpversion(), "5.2","<" ) ){
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)){
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++){
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])){
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])){ // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", trim($email_array[1]));
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++){
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])){
return false;
}
}
}else{
//regular expression verifies that each component is a number from 1 to 3 characters in length
if (!ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $email_array[1])){
return false;
}
}
}else if ( filter_var( $email, FILTER_VALIDATE_EMAIL ) === false ){
return false;
}
return true;
}
/*==================================================================*/
function SendAutoEmail($cid,$cli,$ip,$aid,$testmode=0){
//this function sends the auto thank you email advertisment to the web visitor
//this feature only works if the web visitors email was given during the chat
global $campaignTable, $agentsTable, $aweber_nametext, $vsacbnick, $settingsTable, $userdataTable, $linksTable, $conn;
//check for testmode
$result = mysql_query("SELECT * FROM $campaignTable WHERE id='$cid'",$conn);mysql_error()?(print(mysql_error())):'';
$camp = mysql_fetch_assoc($result);
if (($camp['testmode'] == '0')&&($testmode == '0')&&($camp['useautoemail'] == '1')){
//check if name and email was given
$sql = "SELECT * FROM $userdataTable WHERE cid='$cid' AND chatlogid='$cli'";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$nc = mysql_num_rows($result);
if ($nc > 0){
$userdata = mysql_fetch_assoc($result);
$user_name = $userdata['name'];
$user_email = $userdata['email'];
if (($user_name == $aweber_nametext)||($user_name == '')){ $user_name = 'Friend'; }
$fromemail = $camp['autoemailfrom'];
$subject = $camp['autoemailsubject'];
$message = $camp['autoemailmessage'];
$subject = stripslashes($subject);
$tmp = explode('\n',$message);
$message = '';
foreach($tmp as $key=>$value){
if($key < count($tmp)-1){
$value = trim($value);
$message .= $value."\n";
}
}
$message = trim($message);
$trackid = $camp['trackid'];
$trackid = trim($trackid);
if ($trackid == ''){
$vsalink = 'http://www.virtualsmartagent.com';
}else{
$vsalink = $trackid;
}
$sql = "SELECT * FROM $agentsTable WHERE id='$aid'";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$agentdata = mysql_fetch_assoc($result);
$agentname = $agentdata['name'];
$sql = "SELECT * FROM $settingsTable";
$result = mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
$settings = mysql_fetch_assoc($result);
$sitename = $settings['installsite'];
$installfolder = $settings['installfolder'];
//replace the codes in the email message. See globals.php for pre-defined codes
$message = str_replace('%%AGENTNAME%%', $agentname, $message);
$message = str_replace('%%VISITORNAME%%', $user_name, $message);
$message = str_replace('%%VISITOREMAIL%%', $user_email, $message);
$message = str_replace('%%AFFILIATELINK%%', $vsalink, $message);
$message = str_replace('%%SITENAME%%', $sitename, $message);
$message = str_replace('%%IPADDRESS%%', $ip, $message);
//insert the powered by text
$message = $message."\n\n\n".'Powered by VSA: '.$vsalink;
//send email
SendEmail($fromemail,$user_email,$subject,$message);
//update this user data record
$sql = "UPDATE $userdataTable SET sent='1' WHERE cid='$cid' AND chatlogid='$cli'";
mysql_query($sql,$conn);mysql_error()?(print(mysql_error())):'';
}
}//end if testmode
}
/*==================================================================*/
?>