Skip to content

Commit 5df12bd

Browse files
committed
Merge branch 'master' of https://github.com/Program-O/Program-O
2 parents a8dc8a7 + 6560ca1 commit 5df12bd

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

chatbot/core/aiml/parse_aiml_as_XML.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,24 @@ function parse_get_tag($convoArr, $element, $parentName, $level)
277277
$response = 'undefined';
278278
if (empty ($response))
279279
{
280-
$sql = "select `value` from `$dbn`.`client_properties` where `user_id` = $user_id and `bot_id` = $bot_id and `name` = '$var_name';";
281-
runDebug(__FILE__, __FUNCTION__, __LINE__, "Checking the DB for $var_name - sql:\n$sql", 3);
282-
$result = db_query($sql, $con);
283-
if (($result) and (mysql_num_rows($result) > 0))
280+
281+
if((isset($convoArr['client_properties'][(string)$var_name])) && ($convoArr['client_properties'][(string)$var_name]!=""))
284282
{
285-
$row = mysql_fetch_assoc($result);
286-
$response = $row['value'];
287-
}
288-
else $response = 'undefined';
289-
mysql_free_result($result);
283+
$response = $convoArr['client_properties'][(string)$var_name];
284+
} else {
285+
286+
$sql = "select `value` from `$dbn`.`client_properties` where `user_id` = $user_id and `bot_id` = $bot_id and `name` = '$var_name';";
287+
runDebug(__FILE__, __FUNCTION__, __LINE__, "Checking the DB for $var_name - sql:\n$sql", 3);
288+
$result = db_query($sql, $con);
289+
if (($result) and (mysql_num_rows($result) > 0)) {
290+
$row = mysql_fetch_assoc($result);
291+
$response = $row['value'];
292+
}
293+
else {
294+
$response = 'undefined';
295+
}
296+
mysql_free_result($result);
297+
}
290298
}
291299
runDebug(__FILE__, __FUNCTION__, __LINE__, "The value for $var_name is $response.", 4);
292300
return $response;

chatbot/core/conversation/intialise_conversation.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,19 @@ function log_conversation_state($convoArr)
422422
**/
423423
function get_conversation_state($convoArr)
424424
{
425-
global $con, $dbn;
425+
global $con, $dbn,$unknown_user;
426426
runDebug(__FILE__, __FUNCTION__, __LINE__, "getting state", 4);
427427
$user_id = $convoArr['conversation']['user_id'];
428428
$sql = "SELECT * FROM `$dbn`.`users` WHERE `id` = '$user_id' LIMIT 1";
429429
runDebug(__FILE__, __FUNCTION__, __LINE__, "Getting conversation state SQL: $sql", 3);
430430
$result = db_query($sql, $con);
431431
if (($result) && (mysql_num_rows($result) > 0))
432432
{
433-
$row = mysql_fetch_assoc($result);
434-
$convoArr = unserialize($row['state']);
435-
$convoArr['conversation']['user_name'] = $row['user_name'];
436-
$convoArr['client_properties']['name'] = $row['user_name'];
433+
$row = mysql_fetch_assoc($result);
434+
$convoArr = unserialize($row['state']);
435+
$user_name = (!empty ($row['user_name'])) ? $row['user_name'] : $unknown_user;
436+
$convoArr['conversation']['user_name'] = $user_name;
437+
$convoArr['client_properties']['name'] = $user_name;
437438
}
438439
mysql_free_result($result);
439440
return $convoArr;
@@ -450,7 +451,7 @@ function check_set_bot($convoArr)
450451
{
451452
global $form_vars;
452453
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Checking and/or setting the current bot.', 2);
453-
global $con, $dbn, $bot_id, $error_response, $format;
454+
global $con, $dbn, $bot_id, $error_response, $format,$unknown_user;
454455
//check to see if bot_id has been passed if not load default
455456
if ((isset ($form_vars['bot_id'])) && (trim($form_vars['bot_id']) != ""))
456457
{
@@ -473,9 +474,11 @@ function check_set_bot($convoArr)
473474
$row = mysql_fetch_assoc($result);
474475
$bot_name = $row['bot_name'];
475476
$error_response = $row['error_response'];
477+
$unknown_user = $row['unknown_user'];
476478
$convoArr['conversation']['bot_name'] = $bot_name;
477479
$convoArr['conversation']['bot_id'] = $bot_id;
478480
$convoArr['conversation']['format'] = $row['format'];
481+
$convoArr['conversation']['unknown_user'] = $unknown_user;
479482
runDebug(__FILE__, __FUNCTION__, __LINE__, "BOT ID: $bot_id", 2);
480483
}
481484
else

0 commit comments

Comments
 (0)