3 /***************************************
4 * http://www.program-o.com
8 * AUTHOR: Elizabeth Perreau and Dave Morton
10 * DETAILS: Clears out AIML categories from the DB for the currently selected chatbot
11 ***************************************/
13 $upperScripts = $template->getSection('UpperScripts');
14 $post_vars = filter_input_array(INPUT_POST
, FILTER_SANITIZE_STRING
);
15 if ((isset ($post_vars['action'])) && ($post_vars['action'] == "clear"))
19 elseif ((isset ($post_vars['clearFile'])) && ($post_vars['clearFile'] != "null"))
21 $msg = clearAIMLByFileName($post_vars['clearFile']);
26 $content .= buildMain();
27 $topNav = $template->getSection('TopNav');
28 $leftNav = $template->getSection('LeftNav');
29 $main = $template->getSection('Main');
30 $navHeader = $template->getSection('NavHeader');
31 $FooterInfo = getFooter();
32 $errMsgClass = (!empty ($msg)) ?
"ShowError" : "HideError";
33 $errMsgStyle = $template->getSection($errMsgClass);
36 $noRightNav = $template->getSection('NoRightNav');
37 $headerTitle = 'Actions:';
38 $pageTitle = "My-Program O - Clear AIML Categories";
39 $mainContent = $content;
40 $mainTitle = "Clear AIML Categories for the bot named $bot_name [helpLink]";
41 $showHelp = $template->getSection('ClearShowHelp');
42 $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle);
43 $mainContent = str_replace('[showHelp]', $showHelp, $mainContent);
44 $mainContent = str_replace('[upperScripts]', $upperScripts, $mainContent);
54 global $dbn, $bot_id, $bot_name, $dbConn;
55 $sql = "DELETE FROM `aiml` WHERE `bot_id` = $bot_id;";
56 $affectedRows = db_write($sql, null, false, __FILE__
, __FUNCTION__
, __LINE__
);
57 $msg = "<strong>All AIML categories cleared for $bot_name!</strong><br />";
62 * Function clearAIMLByFileName
67 function clearAIMLByFileName($filename)
69 global $dbn, $bot_id, $dbConn;
70 $sql = "delete from `aiml` where `filename` like '$filename' and `bot_id` = $bot_id;";
71 $affectedRows = db_write($sql, null, false, __FILE__
, __FUNCTION__
, __LINE__
);
72 $msg = "<br/><strong>AIML categories cleared for file $filename!</strong><br />";
77 * Function buildSelOpts
82 function buildSelOpts()
84 global $bot_id, $bot_name, $msg;
85 $sql = "SELECT DISTINCT filename FROM `aiml` where `bot_id` = $bot_id order by `filename`;";
86 $result = db_fetchAll($sql, null, __FILE__
, __FUNCTION__
, __LINE__
);
87 if (count($result) == 0)
89 $msg = "The chatbot '$bot_name' has no AIML categories to clear.";
92 $out = " <!-- Start Selectbox Options -->\n";
93 $optionTemplate = " <option value=\"[val]\">[val]</option>\n";
94 foreach ($result as $row)
96 if (empty ($row['filename']))
98 $curOption = " <option value=\"\">{No Filename entry}</option>\n";
101 $curOption = str_replace('[val]', $row['filename'], $optionTemplate);
104 $out .= " <!-- End Selectbox Options -->\n";
116 global $msg, $template;
117 $selectOptions = buildSelOpts();
118 if ($selectOptions === false) return "<div class=\"bold red center\">$msg</div><br>\n";
119 $content = $template->getSection('ClearAIML');
120 $content = str_replace('[selectOptions]', $selectOptions, $content);
121 $content = str_replace('[blank]', '', $content);