/**
 * function log_conversation_state(()
 * A function to log the conversation state
 *
 * @link http://blog.program-o.com/?p=1264
 * @param  array $convoArr - the current state of the conversation array
 * @return array $convoArr (updated)
 */
function log_conversation_state($convoArr)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Logging the state of the conversation.', 2);
    global $dbConn, $dbn, $user_name;
    //get undefined defaults from the db
    runDebug(__FILE__, __FUNCTION__, __LINE__, "logging state", 4);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "user name = {$user_name}. Stored user name = " . $convoArr['conversation']['user_name'], 4);
    $serialise_convo = serialize(reduceConvoArr($convoArr));
    $user_id = $convoArr['conversation']['user_id'];
    $sql_addon = !empty($user_name) ? "`user_name` = '" . $user_name . "', " : '';
    $sql = "UPDATE `{$dbn}`.`users`\n                SET\n                `state` = '{$serialise_convo}',\n                `last_update` = NOW(),\n                {$sql_addon}\n                `chatlines` = `chatlines`+1\n                WHERE `id` = '{$user_id}' LIMIT 1";
    runDebug(__FILE__, __FUNCTION__, __LINE__, "updating conversation state SQL: {$sql}", 3);
    $sth = $dbConn->prepare($sql);
    $sth->execute();
    return $convoArr;
}
Example #2
0
/**
 * function handleDebug()
 * Handle the debug array at the end of the process
 * @param  array $convoArr - conversation arrau
 * @return array $convoArr;
 **/
function handleDebug($convoArr, $et)
{
    global $debugArr, $debug_level, $debug_mode;
    $debug_level = isset($convoArr['conversation']['debug_level']) ? $convoArr['conversation']['debug_level'] : $debug_level;
    $debug_mode = isset($convoArr['conversation']['debugmode']) ? $convoArr['conversation']['debugmode'] : $debug_mode;
    $convoArr['debug'] = $debugArr;
    $log = '';
    foreach ($debugArr as $time => $subArray) {
        $log .= $time . '[NEWLINE]';
        foreach ($subArray as $index => $value) {
            if ($index == 'fileName' || $index == 'functionName' || $index == 'line') {
                $log .= "[{$value}]";
            } elseif ($index == 'info') {
                $log .= "[NEWLINE]{$value} [NEWLINE]-----------------------[NEWLINE]";
            }
        }
    }
    $log = rtrim($log);
    if ($debug_level == 4) {
        //show the full array
        $showArr = $convoArr;
        unset($showArr['debug']);
    } else {
        //show a reduced array
        $showArr = reduceConvoArr($convoArr);
    }
    if ($debug_level != 0) {
        //$log .= '[NEWLINE]-----------------------[NEWLINE]';
        $log .= "Debug Level: {$debug_level}";
        $log .= '[NEWLINE]-----------------------[NEWLINE]';
        $log .= "Debug Mode: {$debug_mode}";
        $log .= '[NEWLINE]-----------------------[NEWLINE]';
        $log .= 'CONVERSATION ARRAY';
        $log .= '[NEWLINE]-----------------------[NEWLINE]';
        $log .= str_replace("\n", PHP_EOL, print_r($showArr, true));
        $log .= '[NEWLINE]-----------------------[NEWLINE]';
        $log .= "Total execution time: {$et} Milliseconds. Goodbye.";
    }
    switch ($debug_mode) {
        case 0:
            //show in source code
            $log = str_replace('[NEWLINE]', "\n", $log);
            display_on_page(0, $log);
            break;
        case 1:
            //write to log file
            $log = str_replace('[NEWLINE]', PHP_EOL, $log);
            writefile_debug($log, $convoArr);
            break;
        case 2:
            //show in webpage
            $log = str_replace('[NEWLINE]', '<br/>', $log);
            display_on_page(1, $log);
            break;
        case 3:
            //email to user
            $log = str_replace('[NEWLINE]', "\r\n", $log);
            email_debug($convoArr['conversation']['debugemail'], $log);
            break;
    }
    return $convoArr;
}
Example #3
0
/**
 * function handleDebug()
 * Handle the debug array at the end of the process
 * @param  array $convoArr - conversation arrau
 * @return array $convoArr;
 * TODO THIS MUST BE IMPLMENTED
**/
function handleDebug($convoArr)
{
    global $debugArr;
    $convoArr['debug'] = $debugArr;
    $log = '';
    foreach ($debugArr as $time => $subArray) {
        $log .= $time . "[NEWLINE]";
        foreach ($subArray as $index => $value) {
            if ($index == "fileName" || $index == "functionName" || $index == "line") {
                $log .= "[" . $value . "]";
            } elseif ($index == "info") {
                $log .= "[NEWLINE]" . $value . "[NEWLINE]-----------------------[NEWLINE]";
            }
        }
    }
    $log .= "[NEWLINE]-----------------------[NEWLINE]";
    $log .= "CONVERSATION ARRAY";
    $log .= "[NEWLINE]-----------------------[NEWLINE]";
    $debuglevel = get_convo_var($convoArr, 'conversation', 'debugshow', '', '');
    if ($debuglevel == 4) {
        //show the full array
        $showArr = $convoArr;
        unset($showArr['debug']);
    } else {
        //show a reduced array
        $showArr = reduceConvoArr($convoArr);
    }
    $log .= print_r($showArr, true);
    switch ($convoArr['conversation']['debugmode']) {
        case 0:
            //show in source code
            $log = str_replace("[NEWLINE]", "\r\n", $log);
            display_on_page(0, $log);
            break;
        case 1:
            //write to log file
            $log = str_replace("[NEWLINE]", "\r\n", $log);
            writefile_debug($log);
            break;
        case 2:
            //show in webpage
            $log = str_replace("[NEWLINE]", "<br/>", $log);
            display_on_page(1, $log);
            break;
        case 3:
            //email to user
            $log = str_replace("[NEWLINE]", "\r\n", $log);
            email_debug($convoArr['conversation']['debugemail'], $log);
            break;
    }
    return $convoArr;
}