/**
 * function make_conversation()
 * A controller function to run the instructions to make the conversation
 *
 * @link http://blog.program-o.com/?p=1209
 * @param  array $convoArr - the current state of the conversation array
 * @return array $convoArr (updated)
 */
function make_conversation($convoArr)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Making conversation", 4);
    //get the user input and clean it
    $convoArr['aiml']['lookingfor'] = normalize_text($convoArr['user_say'][1]);
    //find an aiml match in the db
    $convoArr = get_aiml_to_parse($convoArr);
    $convoArr = parse_matched_aiml($convoArr, 'normal');
    //parse the aiml to build a response
    //store the conversation
    $convoArr = push_on_front_convoArr('parsed_template', $convoArr['aiml']['parsed_template'], $convoArr);
    $convoArr = push_on_front_convoArr('template', $convoArr['aiml']['template'], $convoArr);
    //display conversation vars to user.
    $convoArr['conversation']['totallines']++;
    return $convoArr;
}
Example #2
0
/**
 * function make_learn()
 * This function builds the sql insert a learnt aiml cateogry in to the db
 * @param array $convoArr - conversation array
 * @param string $pattern - the pattern we will insert
 * @param string $template - the template to insert
 **/
function make_learn($convoArr, $pattern, $template)
{
    global $dbConn, $dbn;
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Making learn", 2);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Pattern:  {$pattern}", 2);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Template: {$template}", 2);
    $pattern = normalize_text($pattern);
    $aiml = "<learn> <category> <pattern> <eval>{$pattern}</eval> </pattern> <template> <eval>{$template}</eval> </template> </category> </learn>";
    /** @noinspection PhpSillyAssignmentInspection */
    $aiml = $aiml;
    $pattern = $pattern . " ";
    $template = $template . " ";
    $u_id = $convoArr['conversation']['user_id'];
    $bot_id = $convoArr['conversation']['bot_id'];
    $sql = "INSERT INTO `{$dbn}`.`aiml_userdefined`\n        VALUES\n        (NULL, '{$aiml}','{$pattern}','{$template}','{$u_id}','{$bot_id}',NOW())";
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Make learn SQL: {$sql}", 3);
    $sth = $dbConn->prepare($sql);
    $sth->execute();
    $numRows = $sth->rowCount();
}
     $sql = "select `id` from `{$dbn}`.`users` where `session_id` = '{$new_convo_id}' limit 1;";
     $row = db_fetch($sql, null, __FILE__, __FUNCTION__, __LINE__);
     if ($row !== false) {
         $user_id = $row['id'];
         $convoArr['conversation']['user_id'] = $user_id;
         $convoArr['conversation']['convo_id'] = $new_convo_id;
         runDebug(__FILE__, __FUNCTION__, __LINE__, "User ID = {$user_id}.", 4);
         $sql = "delete from `{$dbn}`.`client_properties` where `user_id` = {$user_id};";
         runDebug(__FILE__, __FUNCTION__, __LINE__, "Clear client properties from the DB - SQL:\n{$sql}", 4);
     }
     $say = "Hello";
 }
 //add any pre-processing addons
 $rawSay = $say;
 $say = run_pre_input_addons($convoArr, $say);
 $say = normalize_text($say);
 /** @noinspection PhpUndefinedVariableInspection */
 $bot_id = isset($form_vars['bot_id']) ? $form_vars['bot_id'] : $bot_id;
 runDebug(__FILE__, __FUNCTION__, __LINE__, "Details:\nUser say: " . $say . "\nConvo id: " . $convo_id . "\nBot id: " . $bot_id . "\nFormat: " . $form_vars['format'], 2);
 //get the stored vars
 $convoArr = read_from_session();
 $convoArr = load_default_bot_values($convoArr);
 //now overwrite with the recieved data
 $convoArr = check_set_convo_id($convoArr);
 $convoArr = check_set_bot($convoArr);
 $convoArr = check_set_user($convoArr);
 if (!isset($convoArr['conversation']['user_id']) and isset($user_id)) {
     $convoArr['conversation']['user_id'] = $user_id;
 }
 $convoArr = check_set_format($convoArr);
 $convoArr = load_that($convoArr);
Example #4
0
/**
 * function check_and_add_unknown_inputs()
 * READY FOR v2.5
 * This function adds inputs without a response to the unknown_inputs table
 * @param array $allrows - the highest scoring return rows
 * @param array $convoArr - conversation array
 * @return void
 **/
function check_and_add_unknown_inputs($allrows, $convoArr)
{
    if ($allrows['pattern'] == $convoArr['conversation']['default_aiml_pattern']) {
        global $dbConn, $dbn;
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Adding unknown input", 2);
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Pattern: " . $convoArr['aiml']['lookingfor'], 2);
        $pattern = trim(normalize_text($convoArr['aiml']['lookingfor']));
        $pattern = $pattern . " ";
        $u_id = $convoArr['conversation']['user_id'];
        $bot_id = $convoArr['conversation']['bot_id'];
        $sql = "INSERT INTO `{$dbn}`.`unknown_inputs`\n            VALUES\n            (NULL, '" . $pattern . "','{$bot_id}','{$u_id}',NOW())";
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Unknown Input SQL: {$sql}", 3);
        $sth = $dbConn->prepare($sql);
        $sth->execute();
    }
}
Example #5
0
				<p class="system-login-info">
				<b>Logado como:</b> <?php 
echo $_SESSION["login_data"]["full_name"];
?>
 - <b>Data:</b> <?php 
echo date("d/m/Y H:i");
?>
 
				<input type="button" class="btn-form" id="logout" name="logout" value="Sair com Segurança" />
				</p>
				<?php 
$menu = '<ul>';
$menu .= '<li ' . (preg_match("/(index)/", $_SERVER["REQUEST_URI"]) ? 'class = "selected"' : "") . '><a href="index.php">Home</a></li>';
$uri = false;
$user = new user();
$modules = $user->build_menu();
foreach ($modules as $k => $v) {
    $menu .= '<li ' . (preg_match("/(" . normalize_text($v["nm_menu"]) . ")/", !$uri ? $_SERVER["REQUEST_URI"] : $uri) ? 'class = "selected"' : "") . '><a href="' . normalize_text($v["nm_menu"]) . '.php">' . $v["nm_menu"] . '</a></li>';
}
$menu .= '</ul>';
echo $menu;
?>
		</div>
		
		<!-- main -->
		<div id="main-adm">
		<?php 
if (isset($_SESSION["form_message"]) && $_SESSION["form_message"] != "") {
    print $_SESSION["form_message"];
}
unset($_SESSION["form_message"]);
 public function destino_system($data)
 {
     // carregar variaveis globais
     require ROOT_WEBSITE . "scripts/load_globals.php";
     $authenticated = false;
     $authentication = new cadastro_controller();
     $this->authenticated = $authentication->authenticate($uri);
     if (get_vars("back")) {
         header("Location: " . $base_url_site . "destino");
         exit;
     }
     $ponto = $this->model->get_ponto_turistico($data["id_ponto"]);
     if ($ponto) {
         $title = normalize_text($ponto[0]["nm_ponto_turistico"], true);
         $short_url = $base_url_site . "pontos-turisticos/" . $data["id_ponto"] . "-" . $title;
         if ($data["slug"]) {
             if ($title != $data["slug"]) {
                 header("Location: " . $base_url_site . "pontos-turisticos/" . $data["id_ponto"] . "-" . $title);
                 exit;
             }
         }
         if (get_vars("destino")) {
             header("Location: " . $base_url_site . "destino/" . $data["id_ponto"] . "-" . $title);
             exit;
         }
         $complement_title = htmlspecialchars("Meu Destino - " . $ponto[0]["nm_ponto_turistico"]);
         $meta_description = htmlspecialchars($ponto[0]["nm_ponto_turistico"]);
         $css_files = write_css_header(array("marks"));
         $js_files = write_js_header(array("marks"));
         $google_api = true;
         include $template_directory . "header.inc.php";
         include $template_directory . "marks.inc.php";
         include $template_directory . "footer.inc.php";
     } else {
         header("Location: " . $base_url_site . "destino");
         exit;
     }
 }
Example #7
0
/**
 * Parses the AIML <condition> tag
 *
 * @param array $convoArr
 * @param SimpleXMLElement $element
 * @param string $parentName
 * @param int $level
 * @return array|string
 */
function parse_condition_tag($convoArr, $element, $parentName, $level)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag.', 2);
    global $error_response;
    $response = array();
    $attributes = (array) $element->attributes();
    $attributesArray = isset($attributes['@attributes']) ? $attributes['@attributes'] : array();
    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Element attributes:' . print_r($attributesArray, true), 4);
    $attribute_count = count($attributesArray);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Element attribute count = {$attribute_count}", 4);
    if ($attribute_count == 0) {
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag with no attributes. XML = ' . $element->asXML(), 4);
        $liNamePath = 'li[@name]';
        $condition_xPath = '';
        $exclude = array();
        $choices = $element->xpath($liNamePath);
        foreach ($choices as $choice) {
            $choice_name = (string) $choice['name'];
            if (in_array($choice_name, $exclude)) {
                continue;
            }
            $exclude[] = $choice_name;
            runDebug(__FILE__, __FUNCTION__, __LINE__, 'Client properties = ' . print_r($convoArr['client_properties'], true), 4);
            $choice_value = trim(get_client_property($convoArr, $choice_name));
            $condition_xPath .= "li[@name=\"{$choice_name}\"][@value=\"{$choice_value}\"]|";
        }
        $condition_xPath .= 'li[not(@*)]';
        runDebug(__FILE__, __FUNCTION__, __LINE__, "xpath search = {$condition_xPath}", 4);
        $pick_search = $element->xpath($condition_xPath);
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Pick array = ' . print_r($pick_search, true), 4);
        $pick_count = count($pick_search);
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Pick count = {$pick_count}.", 4);
        $pick = $pick_search[0];
    } elseif (array_key_exists('value', $attributesArray) or array_key_exists('contains', $attributesArray) or array_key_exists('exists', $attributesArray)) {
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag with 2 attributes.', 4);
        $condition_name = (string) $element['name'];
        $test_value = trim(get_client_property($convoArr, $condition_name));
        switch (true) {
            case isset($element['value']):
                $condition_value = (string) $element['value'];
                break;
            case isset($element['contains']):
                $condition_value = (string) $element['contains'];
                break;
            case isset($element['exists']):
                $condition_value = (string) $element['exists'];
                break;
            default:
                runDebug(__FILE__, __FUNCTION__, __LINE__, 'Something went wrong with parsing the CONDITION tag. Returning the error response.', 1);
                return $error_response;
        }
        $pick = normalize_text($condition_value) == normalize_text($test_value) ? $element : '';
    } elseif (array_key_exists('name', $attributesArray)) {
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag with only the NAME attribute', 4);
        $condition_name = (string) $element['name'];
        $test_value = trim(get_client_property($convoArr, $condition_name));
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Looking for test value '{$test_value}'", 4);
        $path = "li[@value]|li[not(@*)]";
        runDebug(__FILE__, __FUNCTION__, __LINE__, "search string = {$path}", 4);
        $choice = $element->xpath($path);
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'element = ' . print_r($element, true), 4);
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Choices = ' . print_r($choice, true), 4);
        if (count($choice) != 0) {
            $test_value = rtrim($test_value);
            runDebug(__FILE__, __FUNCTION__, __LINE__, 'parent XML = ' . $element->asXML(), 4);
            foreach ($choice as $pick) {
                runDebug(__FILE__, __FUNCTION__, __LINE__, 'Current pick = ' . print_r($pick, true), 4);
                $attr = $pick->attributes();
                runDebug(__FILE__, __FUNCTION__, __LINE__, 'Current pick attributes = ' . print_r($attr, true), 4);
                $testVarValue = isset($attr['value']) ? (string) $attr['value'] : '';
                runDebug(__FILE__, __FUNCTION__, __LINE__, "Pick Value = '{$testVarValue}'", 4);
                runDebug(__FILE__, __FUNCTION__, __LINE__, "Checking to see if {$test_value} (Client Property) matches {$testVarValue} (condition value).", 4);
                if (aiml_pattern_match($testVarValue, $test_value)) {
                    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Pick XML = ' . $pick->asXML(), 4);
                    break;
                }
            }
            runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($pick, true), 4);
        } else {
            $path = "li[@value=\"{$test_value}\"]|li[not(@*)]";
            runDebug(__FILE__, __FUNCTION__, __LINE__, "search string = {$path}", 4);
            $choice = $element->xpath($path);
            $pick = $choice[0];
            runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($pick, true), 4);
        }
    } else {
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'No matches found. Returning default error response. this is probably because of poorly written AIML code.', 1);
        return $error_response;
    }
    $children = is_object($pick) ? $pick->children() : null;
    if (!empty($children)) {
        foreach ($children as $child) {
            $response[] = parseTemplateRecursive($convoArr, $child, $level + 1);
        }
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Response = " . print_r($response, true), 4);
    } else {
        $response[] = (string) $pick;
    }
    $response_string = implode_recursive(' ', $response, __FILE__, __FUNCTION__, __LINE__);
    return $response_string;
}
<div id='main-pontos'>
	<p class='welcome'>Escolha um ponto turístico </p>
	<br /><br />
	<?php 
if ($pontos) {
    ?>
	<ul id='pontos-list'>
		<?php 
    foreach ($pontos as $item) {
        ?>
		<li>
			<a href="pontos-turisticos/<?php 
        echo $item["id_ponto_turistico"] . '-' . normalize_text(htmlspecialchars($item["nm_ponto_turistico"]), true);
        ?>
">
				<img src="<?php 
        echo $furniture_directory;
        ?>
files/<?php 
        echo $item["imagem"];
        ?>
" />
				<br />
				<?php 
        echo $item["nm_ponto_turistico"];
        ?>
			</a>
		</li>
		<?php 
    }
    ?>