added some development tools
[windows-sources.git] / developer / Samples / Bot / admin / clear.php
blobc88fb80870f6d91adbe050cbf64d22eb55de05ea
1 <?PHP
3 /***************************************
4 * http://www.program-o.com
5 * PROGRAM O
6 * Version: 2.5.3
7 * FILE: clear.php
8 * AUTHOR: Elizabeth Perreau and Dave Morton
9 * DATE: 12-12-2014
10 * DETAILS: Clears out AIML categories from the DB for the currently selected chatbot
11 ***************************************/
12 $content = "";
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"))
17 $msg = clearAIML();
19 elseif ((isset ($post_vars['clearFile'])) && ($post_vars['clearFile'] != "null"))
21 $msg = clearAIMLByFileName($post_vars['clearFile']);
23 else
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);
34 $noLeftNav = '';
35 $noTopNav = '';
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);
46 /**
47 * Function clearAIML
50 * @return string
52 function clearAIML()
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 />";
58 return $msg;
61 /**
62 * Function clearAIMLByFileName
64 * * @param $filename
65 * @return string
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 />";
73 return $msg;
76 /**
77 * Function buildSelOpts
80 * @return string
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.";
90 return false;
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";
100 else
101 $curOption = str_replace('[val]', $row['filename'], $optionTemplate);
102 $out .= $curOption;
104 $out .= " <!-- End Selectbox Options -->\n";
105 return $out;
109 * Function buildMain
112 * @return string
114 function buildMain()
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);
122 return $content;