Beispiel #1
0
/**
 * function get_user_id()
 * A function to get the user id
 * @param  array $convoArr - the current state of the conversation array
 * @return array $convoArr
**/
function get_user_id($convoArr)
{
    //db globals
    global $dbConn, $dbn, $unknown_user;
    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Getting user ID.', 2);
    //get undefined defaults from the db
    $sql = "SELECT * FROM `{$dbn}`.`users` WHERE `session_id` = '" . $convoArr['conversation']['convo_id'] . "' limit 1";
    $sth = $dbConn->prepare($sql);
    $sth->execute();
    $result = $sth->fetchAll();
    $count = count($result);
    if ($count > 0) {
        $sth = $dbConn->prepare($sql);
        $sth->execute();
        $row = $sth->fetch();
        $convoArr['conversation']['user_id'] = $row['id'];
        // add user name, if set
        $convoArr['conversation']['user_name'] = !empty($convoArr['client_properties']['name']) ? $convoArr['client_properties']['name'] : !empty($row['user_name']) ? $row['user_name'] : $unknown_user;
        $convoArr['client_properties']['name'] = $convoArr['conversation']['user_name'];
        $msg = "existing";
    } else {
        $convoArr = intisaliseUser($convoArr);
        $msg = "new";
    }
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Getting {$msg} user id:" . $convoArr['conversation']['user_id'], 4);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "get_user_id SQL: {$sql}", 3);
    return $convoArr;
}
Beispiel #2
0
/**
 * function get_user_id()
 * A function to get the user id
 * @param  array $convoArr - the current state of the conversation array
 * @return the update $convoArr
**/
function get_user_id($convoArr)
{
    //db globals
    global $con, $dbn, $unknown_user;
    //get undefined defaults from the db
    $sql = "SELECT * FROM `{$dbn}`.`users` WHERE `session_id` = '" . $convoArr['conversation']['convo_id'] . "' limit 1";
    $result = mysql_query($sql, $con);
    $count = mysql_num_rows($result);
    if ($count > 0) {
        $row = mysql_fetch_array($result);
        $convoArr['conversation']['user_id'] = $row['id'];
        // add user name, if set
        $convoArr['conversation']['user_name'] = !empty($row['name']) ? $row['name'] : !empty($convoArr['client_properties']['name']) ? $convoArr['client_properties']['name'] : $unknown_user;
        $msg = "existing";
    } else {
        $convoArr['conversation']['user_id'] = intisaliseUser($convoArr['conversation']['convo_id']);
        $msg = "new";
    }
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Getting {$msg} user id:" . $convoArr['conversation']['user_id'], 4);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "get_user_id SQL: {$sql}", 3);
    return $convoArr;
}
/**
 * function check_set_convo_id(()
 * A function to check and set the convo id
 * @param  array $convoArr - the current state of the conversation array
 * @return $convoArr (updated)
**/
function check_set_user($convoArr)
{
    global $default_convo_id, $con, $dbn, $unknown_user;
    //check to see if user_name has been set if not set as default
    $convo_id = isset($convoArr['conversation']['convo_id']) ? $convoArr['conversation']['convo_id'] : session_id();
    $bot_id = $convoArr['conversation']['bot_id'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $convoArr['client_properties']['ip_address'] = $ip;
    $sql = "select `name`, `id` from `users` where `session_id` = '{$convo_id}' limit 1;";
    $result = mysql_query($sql, $con) or $msg = SQL_error(mysql_errno(), __FILE__, __FUNCTION__, __LINE__);
    $numRows = mysql_num_rows($result);
    if ($numRows == 0) {
        $user_id = intisaliseUser($convo_id);
    } else {
        $row = mysql_fetch_assoc($result);
        $user_id = !empty($row['id']) ? $row['id'] : 0;
        $user_name = !empty($row['name']) ? $row['name'] : 'User';
    }
    $convoArr['conversation']['user_name'] = !empty($user_name) ? $user_name : $unknown_user;
    #die("User name = $user_name<br />\n");
    return $convoArr;
}
/**
 * function check_set_user(()
 * A function to check and set the user's information
 *
 * @link http://blog.program-o.com/?p=1278
 * @param  array $convoArr - the current state of the conversation array
 * @return array|int $convoArr (updated)
 */
function check_set_user($convoArr)
{
    global $dbConn, $dbn, $unknown_user;
    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Checking and setting the user info, as needed.', 2);
    //check to see if user_name has been set if not set as default
    $convo_id = isset($convoArr['conversation']['convo_id']) ? $convoArr['conversation']['convo_id'] : session_id();
    if (!isset($convoArr['conversation']['convo_id'])) {
        $convoArr['conversation']['convo_id'] = $convo_id;
    }
    $ip = $_SERVER['REMOTE_ADDR'];
    $convoArr['client_properties']['ip_address'] = $ip;
    $sql = "select `user_name`, `id`, `chatlines` from `{$dbn}`.`users` where `session_id` = :convo_id limit 1;";
    $row = db_fetch($sql, array(':convo_id' => $convo_id), __FILE__, __FUNCTION__, __LINE__);
    if ($row === false) {
        $convoArr = intisaliseUser($convoArr);
        $user_id = $convoArr['conversation']['user_id'];
        $user_name = $unknown_user;
    } else {
        $user_id = $row['id'];
        $user_name = !empty($row['user_name']) ? $row['user_name'] : $unknown_user;
    }
    $chatlines = !empty($row['chatlines']) ? $row['chatlines'] : 0;
    $user_name = !empty($user_name) ? $user_name : $unknown_user;
    $convoArr['conversation']['user_name'] = $user_name;
    $convoArr['conversation']['user_id'] = $user_id;
    $convoArr['client_properties']['name'] = $user_name;
    $convoArr['conversation']['totallines'] = $chatlines;
    return $convoArr;
}