viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Last commit for src/views/elements/BotstoryElement.php: 2addb500315b7393a90fe66431d7832b1e7386c7

Adjust copyrights years

Chris Pollett [2024-01-03 21:Jan:rd]
Adjust copyrights years
<?php
/**
 * SeekQuarry/Yioop --
 * Open Source Pure PHP Search Engine, Crawler, and Indexer
 *
 * Copyright (C) 2009 - 2018  Chris Pollett chris@pollett.org
 *
 * LICENSE:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * END LICENSE
 *
 * @author Chris Pollett chris@pollett.org
 * @license http://www.gnu.org/licenses/ GPL3
 * @link http://www.seekquarry.com/
 * @copyright 2009 - 2018
 * @filesource
 */
namespace seekquarry\yioop\views\elements;

use seekquarry\yioop as B;
use seekquarry\yioop\configs as C;

/**
 * Element responsible for displaying the bot story features
 * that someone can create for their own bot.
 *
 * @author Harika Nukala
 */
class BotstoryElement extends Element
{
    /**
     * Used to draw the Bot Story action forms which are used to configure
     * new Group Chat Bots
     * @param array $data associative array of info from the ChatBotComponent
     *      needed to draw the form
     */
    public function render($data)
    {
        ?>
        <div class="current-activity">
                <ul class='tab-menu-list'>
                    <li><a href="javascript:
                switchTab('createintenttab', 'createentitytab',
                'createexpressionstab');"
                           id='createintenttabitem'
                           class="<?= $data['create_intent_active'] ?>"><?=
                            tl('botstory_element_create_intent')?></a></li>
                    <li><a href="javascript:
                switchTab('createentitytab', 'createintenttab',
                'createexpressionstab');"
                           id='createentitytabitem'
                           class="<?= $data['create_entity_active'] ?>"><?=
                            tl('botstory_element_create_entity')?></a></li>
                    <li><a href="javascript:
                switchTab('createexpressionstab', 'createintenttab',
                'createentitytab');"
                           id='createexpressionstabitem'
                           class="<?= $data['create_expressions_active'] ?>"><?=
                            tl('botstory_element_create_expressions')?></a></li>
                </ul>
                <div class='tab-menu-content'>
                    <div id='createintenttab'>
                        <?php
                        $admin_url = htmlentities(B\controllerUrl('admin',
                             true));
                        $token_string = C\CSRF_TOKEN . "=" .$data[C\CSRF_TOKEN];
                        $pre_base_url = $admin_url . $token_string;
                        $base_url = $pre_base_url ."&amp;a=botStory&amp;
                        option_type=".$data['option_type'];
                        ?>
                        <div>
                            <?php if ($data["INTENT_FORM_TYPE"] == "editintent")
                            {
                                ?>
                                <div class='float-opposite'><a href='<?=
                                    $base_url ?>'><?=
                            tl('botstory_element_addintent_form') ?></a></div>
                               <h2><?= tl('botstory_element_edit_intent')?></h2>
                                <?php
                            }
                            ?>
                            </div>
                        <form id="botIntentForm" method="post">
                            <input type="hidden" name="c" value="admin" />
                            <input type="hidden" id='option-type'
                                   name="option_type" value="<?=
                            $data['option_type'] ?>" />
                            <input type="hidden" name="<?= C\CSRF_TOKEN ?>"
                                   value="<?= $data[C\CSRF_TOKEN] ?>" />
                            <input type="hidden" name="a" value="botStory" />
                            <input type="hidden" name="arg" value="<?=
                            $data['INTENT_FORM_TYPE']?>" />
                            <?php
                            if ($data['INTENT_FORM_TYPE'] == "editintent") {
                            ?>
                            <input type="hidden" name="id" value="<?=
                                $data['id']?>" />
                            <?php
                            }
                            ?>
                            <div class="top-margin"><b><label for="intent"><?=
                                     tl('botstory_element_intent')?></label></b>
                               <input type="text" id="intent" class="wide-field"
                                       name="BOT_INTENT" value="<?=
                                       $data['BOT_INTENT']  ?>" />
                                <button id="bot-intent-save" class="button-box"
                                        type="submit"
                                ><?= tl('bot_intent_save') ?></button>
                            </div>
                            </form>
                        <?php
                        ?>
                        <table class="search-sources-table">
                           <tr><th><?= tl('botstory_element_intentname') ?></th>
                               <th colspan="3"><?=
                                   tl('botstory_element_actions')?></th>
                            </tr><?php
                            foreach ($data['INTENTS'] as $intent) {
                                ?>
                                <tr>
                                    <td><?= $intent['INTENT'] ?></td>
                                    <td><a href="<?=$pre_base_url .
                                    "&amp;a=botStory&amp;option_type=".
                                        $data['option_type']
                                        ."&amp;arg=editintent&amp;id=".
                                         $intent['INTENT_ID']?>"><?=
                                            tl('botstory_element_editintent')
                                            ?></a></td>
                                    <td><a onclick='javascript:return
                                        confirm("<?=
                                        tl('botstory_element_delete_operation')
                                        ?>");' href="<?=$pre_base_url
                                            ."&amp;a=botStory&amp;option_type="
                                        .$data['option_type']
                                        ."&amp;arg=deleteintent&amp;
                                          id=".$intent['INTENT_ID']
                                     ?>"><?= tl('botstory_element_deleteintent')
                                            ?></a></td>
                                </tr>
                                <?php
                            } ?>
                        </table>
                    </div>
                    <div id='createentitytab'>
                        <div>
                          <?php if ($data["ENTITY_FORM_TYPE"] == "editentity") {
                                ?>
                           <div class='float-opposite'><a href='<?=
                          $base_url ?>'><?=tl('botstory_element_addentity_form')
                             ?></a></div>
                               <h2><?= tl('botstory_element_edit_entity')?></h2>
                           <?php
                            }
                            ?>
                        </div>
                        <form id="createEntityForm" method="post">
                            <input type="hidden" name="c" value="admin" />
                            <input type="hidden" id='option-type'
                            name="option_type" value="<?=
                            $data['option_type'] ?>" />
                            <input type="hidden" name="<?= C\CSRF_TOKEN ?>"
                            value="<?=
                            $data[C\CSRF_TOKEN] ?>" />
                            <input type="hidden" name="a" value="botStory" />
                            <input type="hidden" name="arg" value="<?=
                            $data['ENTITY_FORM_TYPE']?>" />
                            <?php
                            if ($data['ENTITY_FORM_TYPE'] == "editentity") {
                                ?>
                                <input type="hidden" name="id"
                                    value="<?= $data['id']?>" />
                                <?php
                            }
                            ?>
                            <div class="top-margin">
                                <table class="name-table">
                                    <tr><th class="table-label">
                                    <label for="new_entity"><?=
                                            tl('botstory_element_new_entity')?>
                                    </label>:</th>
                                        <th> <input type="text" id="entity-name"
                                                     class="wide-field"
                                              name="BOT_ENTITY_NAME" value="<?=
                                            $data['BOT_ENTITY_NAME']  ?>" />
                                            </th>
                                        </tr>
                                <?php
                                if ($data['ENTITY_FORM_TYPE'] == "editentity") {
                                    ?>
                                   <tr><th class="table-label"><label
                                         for="new_entity_value"><?=
                                       tl('botstory_element_new_entity_value')?>
                                       </label>:</th>
                                        <td><div class='light-gray-box'><table>
                                        <?php
                                        foreach ($data['ENTITY_VALUES'] as
                                            $entity) {  ?>
                                            <tr>
                                                <td><?= $entity['ENTITY_VALUE']
                                                ?></td>
                                                <td><a onclick='javascript:
                                                return confirm("<?=
                                  tl('botstory_element_delete_operation') ?>");'
                                                 href="<?=
                                                 $pre_base_url ."&amp;a=botStory
                                                &amp;option_type=create_entity"
                                                    ."&amp;arg=deleteentityvalue
                                                    &amp;id=".$entity['ID']
                                                    ?>"><?=
                                        tl('botstory_element_deleteentityvalue')
                                                        ?></a></td>
                                            </tr>
                                            <?php
                                        } ?>
                                    <tr><td><input type="text" id="entity-value"
                                            name="BOT_ENTITY_VALUE"
                                            value="<?= $data['BOT_ENTITY_VALUE']
                                          ?>" /></td></tr>
                                    </table>
                                           </div>
                                <?php
                                }
                                ?>
                                <tr><td></td></td><td class="center">
                                 <button class="button-box" id="bot-entity-save"
                                    type="submit"><?php
                                    e(tl('bot_entity_save'));
                                    ?></button></td></tr>
                                    </table>
                            </div>
                        </form>
                        <?php
                        ?>
                        <table class="search-sources-table">
                           <tr><th><?= tl('botstory_element_entityname') ?></th>
                                <th colspan="3"><?=
                            tl('botstory_element_actions')?></th>
                            </tr><?php
                            foreach ($data['ENTITIES'] as $entity) {
                                ?>
                                <tr>
                                    <td><?= $entity['ENTITY_NAME'] ?></td>
                                    <td><a href="<?=$pre_base_url
                                    ."&amp;a=botStory&amp;
                                    option_type=create_entity"
                                   ."&amp;arg=editentity&amp;id=".
                                        $entity['ENTITY_ID']?>"><?=
                                            tl('botstory_element_editentity')
                                            ?></a></td>
                                  <td><a onclick='javascript:return confirm("<?=
                                  tl('botstory_element_delete_operation') ?>");'
                                  href="<?=
                                  $pre_base_url ."&amp;a=botStory&amp;
                                    option_type=create_entity"
                                        ."&amp;arg=deleteentity&amp;
                                           id=".$entity['ENTITY_ID']
                                     ?>"><?= tl('botstory_element_deleteentity')
                                            ?></a></td>
                                </tr>
                                <?php
                            } ?>
                        </table>

                    </div>
                    <div id='createexpressionstab'>
                        <div>
                            <?php if ($data["EXPRESSION_FORM_TYPE"] ==
                                     "editexpression") {
                                ?>
                                <div class='float-opposite'><a href='<?=
                                        $base_url ?>'><?=
                                       tl('botstory_element_addexpression_form')
                                         ?></a></div>
                                <h2><?= tl('botstory_element_edit_expression')?>
                                </h2>
                                <?php
                            }
                            ?>
                        </div>
                        <form id="expressionForm" method="post">
                            <input type="hidden" name="c" value="admin" />
                            <input type="hidden" id="option-type"
                                  name="option_type"
                                 value="<?= $data['option_type'] ?>" />
                            <input type="hidden" name="<?= C\CSRF_TOKEN ?>"
                            value="<?= $data[C\CSRF_TOKEN] ?>" />
                            <input type="hidden" name="a" value="botStory" />
                            <input type="hidden" name="arg" value="<?=
                            $data['EXPRESSION_FORM_TYPE']?>" />
                            <?php
                            if ($data['EXPRESSION_FORM_TYPE'] ==
                                   "editexpression") {
                                ?>
                                <input type="hidden" name="id"
                                    value="<?= $data['id']?>" />
                                <?php
                            }
                            ?>
                            <table class="name-table">
                                <tr><td><label for="intent-select"><b><?=
                                             tl('botstory_element_intentselect')
                                        ?></b></label></td><td>
                                        <?php
                                        $this->view->helper("options")->
                                            render("intent-select",
                                            "INTENT_ID", $data['INTENT_LISTS'],
                                           $data['CURRENT_STORY']['INTENT_ID']);
                                         ?></td></tr>
                                <tr><td><b><label for="create_expressions"><?=
                                        tl('botstory_element_new_expressions')?>
                                        </label></b></label></td><td>
                                        <input type="text" id="expression"
                                                class="extra-wide-field"
                                               name="EXPRESSION" value="<?=
                                    $data['CURRENT_STORY']['EXPRESSION']  ?>" />
                                               </td></tr>
                              <tr><td colspan="3"><b><label for="view_entities">
                                        <?= "Bot User has following Entities:"?>
                                                </label></b></label></td></tr>
                                <?php
                                foreach ($data['ENTITIES'] as $entity) {
                                    $value =
                                        (empty($entity['ENTITY_NAME']) ||
                                        empty($data[$entity['ENTITY_NAME']])) ?
                                        "" : $data[$entity['ENTITY_NAME']];
                                ?>
                                <tr>
                                    <td><input type="text" id="exp-entity-name"
                                     class="wide-field" value="<?=
                                     $entity['ENTITY_NAME'] ?>"
                                        style="background: none;
                                        border:none" disabled="disabled"/>
                                        </td>
                                    <td><input type="text" id="exp-entity-value"
                                               class="wide-field"
                                               name="<?=$entity['ENTITY_ID']?>"
                                               value="<?= $value ?>"/>
                                    </td>
                                </tr>
                                <?php
                                } ?>
                                <tr><td></td><td class="center">
                             <button class="button-box" id="bot-expression-save"
                              type="submit"><?= tl('bot_expression_save')
                                            ?></button></td></tr>
                            </table>
                        </form>
                        <table class="search-sources-table">
                           <tr>
                           <th><?= tl('botstory_element_expressionname') ?></th>
                           <th><?= tl('botstory_element_intentname') ?></th>
                          <th colspan="3"><?= tl('botstory_element_actions')?>
                            </th>
                            </tr><?php
                            foreach ($data['EXPRESSIONS'] as $expression) {
                                ?>
                                <tr>
                                    <td><?= $expression['EXPRESSION'] ?></td>
                                    <td><?= $expression['INTENT'] ?></td>
                                    <td><a href="<?=$pre_base_url .
                                        "&amp;a=botStory&amp;" .
                                        "option_type=create_expressions" .
                                        "&amp;arg=editexpression&amp;id=".
                                        $expression['EXPRESSION_ID']?>"><?=
                                           tl('botstory_element_editexpression')
                                            ?></a></td>
                                    <td><a onclick='javascript:return
                                        confirm("<?=
                                        tl('botstory_element_delete_operation')
                                        ?>");' href="<?=
                                        $pre_base_url ."&amp;a=botStory&amp;
                                        option_type=create_expressions"
                                        ."&amp;arg=deleteexpression&amp;
                                        id=".$expression['EXPRESSION_ID']
                                 ?>"><?= tl('botstory_element_deleteexpression')
                                            ?></a></td>
                                </tr>
                                <?php
                            } ?>
                        </table>
                    </div>
                </div>
        </div>
        <script type="text/javascript">
            function switchTab(newtab, oldtab, oldtab2)
            {
                setDisplay(newtab, true);
                setDisplay(oldtab, false);
                setDisplay(oldtab2, false);
                ntab = elt(newtab + "item");
                if (ntab) {
                    ntab.className = 'active';
                }
                otab = elt(oldtab + "item");
                if (otab) {
                    otab.className = '';
                }
                otab2 = elt(oldtab2 + "item");
                if (otab2) {
                    otab2.className = '';
                }
                ctype = elt('option-type');
                if (ctype) {
                    ctype.value = (newtab == 'createintenttab')
                        ? 'create_intent' : ((newtab == 'createentitytab') ?
                        'create_entity' : 'create_expressions' );
                }
                console.log(ctype)
            }
        </script>
        <?php
    }
}
ViewGit