Skip to content

Commit

Permalink
Multiple fixes
Browse files Browse the repository at this point in the history
Bugs:
1.) Bot select form:
  a.) Fixed debugging issues
  b.) Added ability to configure bot error response on a per-bot basis
  c.) Fixed a bug where the debugging email field was a checkbox, rather than text
2.) Upload form:
  a.) Removed "strict" validation. Now the AIML files only need to be well-formed, rather than fully valid XML
  b.) Revised the error messages to make them more easily understood

Signed-off-by: Dave Morton <[email protected]>
  • Loading branch information
Dave-Morton committed Jun 9, 2012
1 parent 570794e commit 21fca73
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 470 deletions.
58 changes: 32 additions & 26 deletions admin/default.page.htm
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@
<div class="leftHalf noBorder">
<table width="100%">
<tr class="row">
<td><label for="bot_name"><span class="label">Bot Name</span></label></td>
<td><span class="formw"><input type="text" class="fm-req" id="bot_name" name="bot_name" value="[bot_name]"/></span></td>
<td width="50%"><label for="bot_name"><span class="label">Bot Name</span></label></td>
<td width="50%"><span class="formw"><input type="text" class="fm-req" id="bot_name" name="bot_name" value="[bot_name]"/></span></td>
</tr>
<tr class="row">
<td><label for="bot_active"><span class="label">Bot Active</span></label></td>
Expand Down Expand Up @@ -225,27 +225,26 @@
</td>
</tr>
<tr class="row">
<td><label for="remember_up_to"><span class="label">Bot memory lines</span></label></td>
<td><label for="debugemail"><span class="label">Debug Email Address</span></label></td>
<td>
<span class="formw">
<input type="text" class="fm-req" id="remember_up_to" name="remember_up_to" value="[bot_remember_up_to]"/>
<input type="text" name="debugemail" id="debugemail" value="[bot_debugemail]" />
</span>
</td>
</tr>
<tr class="row">
<td><label for="debugemail"><span class="label">Email Debugging Info</span></label></td>
<td><label for="default_aiml_pattern"><span class="label">Default Pickup Line Pattern</span></label></td>
<td>
<span class="formw">
<input type="radio" name="debugemail" id="debugemail_1" [debugemail_1] value="1" />Yes
<input type="radio" name="debugemail" id="debugemail_0" [debugemail_0] value="0" />No
<input type="text" name="default_aiml_pattern" id="default_aiml_pattern" value="[bot_default_aiml_pattern]" />
</span>
</td>
</tr>
<tr class="row">
<td><label for="default_aiml_pattern"><span class="label">Default pickup line pattern</span></label></td>
<td><label for="error_response"><span class="label">Error Response Message</span></label></td>
<td>
<span class="formw">
<input type="text" name="default_aiml_pattern" id="default_aiml_pattern" value="[bot_default_aiml_pattern]" />
<input type="text" name="error_response" id="error_response" value="[bot_error_response]" />
</span>
</td>
</tr>
Expand All @@ -254,13 +253,13 @@
<div class="rightHalf noBorder">
<table width="100%">
<tr class="row">
<td><label for="bot_desc"><span class="label">Bot Desc</span></label></td>
<td><span class="formw">
<textarea rows="4" cols="40" id="bot_desc" name="bot_desc">[bot_desc]</textarea>
<td width="50%"><label for="bot_desc"><span class="label">Bot Description</span></label></td>
<td width="50%"><span class="formw">
<textarea rows="2" cols="40" id="bot_desc" name="bot_desc">[bot_desc]</textarea>
</span></td>
</tr>
<tr class="row">
<td><label for="bot_parent_id"><span class="label">Bot Parent ID</span></label></td>
<td><label for="bot_parent_id"><span class="label">Bot Parent Name</span></label></td>
<td><span class="formw">
<select name="bot_parent_id" id="bot_parent_id">
[parent_options]
Expand All @@ -276,34 +275,41 @@
</select>
</span></td>
</tr>
<tr class="row">
<td><label for="remember_up_to"><span class="label">Bot History Lines</span></label></td>
<td>
<span class="formw">
<input type="text" class="fm-req" id="remember_up_to" name="remember_up_to" value="[bot_remember_up_to]"/>
</span>
</td>
</tr>
<tr class="row">
<td><label for="conversation_lines"><span class="label">Chat Lines To Display</span></label></td>
<td><span class="formw">
<input type="text" class="fm-req" id="conversation_lines" name="conversation_lines" value="[bot_conversation_lines]"/>
</span></td>
</tr>
<tr class="row">
<td><label for="debugshow"><span class="label">Debug Output</span></label></td>
<td><label for="debugmode"><span class="label">Debug Output</span></label></td>
<td>
<span class="formw">
<select name="debugshow" id="debugshow">
<option value="0" [ds_]>source code view - show debugging in source code</option>
<option value="1" [ds_i]>file log - log debugging to a file</option>
<option value="2" [ds_ii]>page view - display debugging on the webpage</option>
<option value="3" [ds_iii]>email each conversation line (not recommended)</option>
<select name="debugmode" id="debugmode">
<option value="0" [dm_]>source code view - show debugging in source code</option>
<option value="1" [dm_i]>file log - log debugging to a file</option>
<option value="2" [dm_ii]>page view - display debugging on the webpage</option>
<option value="3" [dm_iii]>email each conversation line (not recommended)</option>
</select>
</span>
</td>
</tr>
<tr class="row">
<td><label for="debugmode"><span class="label">Debug Mode</span></label></td>
<td><label for="debugshow"><span class="label">Debug Mode</span></label></td>
<td><span class="formw">
<select name="debugmode" id="debugmode">
<option value="0" [dm_]>Show no debugging</option>
<option value="1" [dm_i]>general + errors</option>
<option value="2" [dm_ii]>general + errors + sql</option>
<option value="3" [dm_iii]>show everything</option>
<option value="4" [dm_iv]>Test</option>
<select name="debugshow" id="debugshow">
<option value="0" [ds_]>Show no debugging</option>
<option value="1" [ds_i]>general + errors</option>
<option value="2" [ds_ii]>general + errors + sql</option>
<option value="3" [ds_iii]>show everything</option>
</select>
</span></td>
</tr>
Expand Down
26 changes: 8 additions & 18 deletions admin/select_bots.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ function getSelectedBot() {
elseif($bot_format=="json") {
$sel_json = ' selected="selected"';
}
if($use_aiml_code=="1") {
if($bot_use_aiml_code=="1") {
$sel_fuyes = ' selected="selected"';
}
elseif($use_aiml_code=="0") {
elseif($bot_use_aiml_code=="0") {
$sel_funo = ' selected="selected"';
}
if($update_aiml_code=="1") {
if($bot_update_aiml_code=="1") {
$sel_fyes = ' selected="selected"';
}
elseif($update_aiml_code=="0") {
elseif($bot_update_aiml_code=="0") {
$sel_fno = ' selected="selected"';
}
if($bot_debugshow=="0") {
Expand Down Expand Up @@ -179,14 +179,6 @@ function getSelectedBot() {
}
$action = "update";
}
$debugemail_0 = $debugemail_1 = '';
switch ($bot_debugemail) {
case 0:
$debugemail_0 = 'checked="checked"';
break;
case 1:
$debugemail_1 = 'checked="checked"';
}
mysql_close($dbconn);
}
else {
Expand All @@ -202,8 +194,7 @@ function getSelectedBot() {
$bot_conversation_lines = "";
$bot_remember_up_to = "";
$bot_debugemail = "";
$debugemail_0 = "";
$debugemail_1 = "";
$debugemail = "";
$bot_debugshow = "";
$bot_debugmode = "";
$bot_default_aiml_pattern = '';
Expand All @@ -215,7 +206,7 @@ function getSelectedBot() {
'[sel_html]','[sel_xml]','[sel_json]','[sel_session]','[sel_db]','[sel_fyes]',
'[sel_fno]','[sel_fuyes]','[sel_funo]','[bot_conversation_lines]','[bot_remember_up_to]',
'[bot_debugemail]','[dm_]','[dm_i]','[dm_ii]','[dm_iii]','[ds_]','[ds_i]','[ds_ii]',
'[ds_iii]','[action]','[debugemail_0]','[debugemail_1]', '[bot_default_aiml_pattern]',
'[ds_iii]','[action]', '[bot_default_aiml_pattern]', '[bot_error_response]',
);
foreach ($searches as $search) {
$replace = str_replace('[', '', $search);
Expand All @@ -236,7 +227,6 @@ function updateBotSelection() {
$value = mysql_escape_string(trim(stripslashes($value)));
if(($key != "bot_id")&&($key != "action")&&($value!="")) {
$sql = "UPDATE `bots` SET `$key` ='$value' where `bot_id` = '".$_POST['bot_id']."' limit 1; ";
$x = file_put_contents(_ADMIN_PATH_ . 'updateBotSQL.txt', $sql);
$result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.');
if(!$result) {
$msg = 'Error updating bot details.';
Expand All @@ -263,8 +253,8 @@ function addBot() {
}
$dbconn = db_open();
$sql = <<<endSQL
INSERT INTO `bots`(`bot_id`, `bot_name`, `bot_desc`, `bot_active`, `bot_parent_id`, `format`, `save_state`, `conversation_lines`, `remember_up_to`, `debugemail`, `debugshow`, `debugmode`, `default_aiml_pattern`, `use_aiml_code`, `update_aiml_code`)
VALUES (NULL,'$bot_name','$bot_desc','$bot_active','$bot_parent_id','$format','$save_state','$conversation_lines','$remember_up_to','$debugemail','$debugshow','$debugmode','$default_aiml_pattern','$use_aiml_code','$update_aiml_code');
INSERT INTO `bots`(`bot_id`, `bot_name`, `bot_desc`, `bot_active`, `bot_parent_id`, `format`, `save_state`, `conversation_lines`, `remember_up_to`, `debugemail`, `debugshow`, `debugmode`, `default_aiml_pattern`, `use_aiml_code`, `update_aiml_code`, `error_response`)
VALUES (NULL,'$bot_name','$bot_desc','$bot_active','$bot_parent_id','$format','$save_state','$conversation_lines','$remember_up_to','$debugemail','$debugshow','$debugmode','$default_aiml_pattern','$use_aiml_code','$update_aiml_code', '$error_response');
endSQL;
$result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.');

Expand Down
6 changes: 5 additions & 1 deletion admin/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,8 @@ table td#notes {
clear: none;
}

#helpLink1 {float: left; margin-bottom: 10px;}
#helpLink1 {float: left; margin-bottom: 10px;}
td input, td select {
width: 100%;
margin: 0 auto;
}
21 changes: 15 additions & 6 deletions admin/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,29 @@ function parseAIML ($file) {
$aimlTagStart = stripos($aimlContent,'<aiml',0);
$aimlTagEnd = strpos($aimlContent,'>', $aimlTagStart) + 1;
$aimlFile = $validAIMLHeader . substr($aimlContent,$aimlTagEnd);
/*
#die('<pre>'.htmlentities($aimlFile)."</pre>\n");
$saveFile = str_replace('./uploads',_ADMIN_PATH_.'aiml',$file);
#if (!file_exists($saveFile)) file_put_contents("$saveFile", $aimlFile);
$validate = new DOMDocument();
$validate->loadXML($aimlFile);
#$validate->loadXML($aimlContent);
$validate->preserveWhiteSpace = false;
$validate->formatOutput = true;
if ($validate->validate() === false) {
$msg = "Cannot parse file $file! Please note errors that follow:\n";
$errors = libxml_get_errors();
foreach ($errors as $error) {
$msg .= libxml_display_error($error);
}
libxml_clear_errors();
return $msg;
foreach ($errors as $error) {
$msg .= libxml_display_error($error);
}
libxml_clear_errors();
return $msg;
}
*/
try {
$aiml = new SimpleXMLElement($aimlFile);
#$aiml = new SimpleXMLElement($aimlContent);
$rowCount = 0;
if (!empty($aiml->topic)) {
foreach ($aiml->topic as $topicXML) { # handle any topic tag(s) in the file
Expand Down Expand Up @@ -205,7 +210,11 @@ function parseAIML ($file) {
$sql = rtrim($sql, ",\n") . ';';
$success = (updateDB($sql) >=0) ? true : false;
}
$msg = "There was a problem adding file $fileName to the database.";
}
catch(Exception $e) {
$success = false;
}
$msg = "There was a problem adding file $fileName to the database. Please validate the file and try again.";
if ($success) $msg = "Successfully added $fileName to the database.";
return $msg;
}
Expand Down
2 changes: 1 addition & 1 deletion chatbot/conversation_start.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//chdir( dirname ( __FILE__ ) );
$thisFolder = dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR;
$thisParentFolder = preg_replace('~[/\\\\][^/\\\\]*[/\\\\]$~', DIRECTORY_SEPARATOR, $thisFolder);

require_once ($thisParentFolder.'config'.DIRECTORY_SEPARATOR.'global_config.php');

//load shared files
include_once (_LIB_PATH_ . "db_functions.php");
Expand Down
Loading

0 comments on commit 21fca73

Please sign in to comment.