viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]
<?php /** * SeekQuarry/Yioop -- * Open Source Pure PHP Search Engine, Crawler, and Indexer * * Copyright (C) 2009 - 2022 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 <https://www.gnu.org/licenses/>. * * END LICENSE * * @author Chris Pollett chris@pollett.org * @license https://www.gnu.org/licenses/ GPL3 * @link https://www.seekquarry.com/ * @copyright 2009 - 2022 * @filesource */ namespace seekquarry\yioop\views\elements; use seekquarry\yioop as B; use seekquarry\yioop\configs as C; /** * Element responsible for displaying the user account features * that someone can modify for their own SeekQuarry/Yioop account. * * @author Chris Pollett */ class ManageaccountElement extends Element { /** * Draws a view with a summary of a user's account together with * a form for updating user info such as password as well as with * useful links for groups, etc * * @param array $data anti-CSRF token */ public function render($data) { $token = C\CSRF_TOKEN . "=" . $data[C\CSRF_TOKEN]; $admin_url = htmlentities(B\controllerUrl('admin', true)); $feed_url = htmlentities(B\feedsUrl("", "", true, "group")). "$token"; $messages_url = htmlentities(B\controllerUrl("user_messages", true)) . $token; $group_url = "{$admin_url}a=manageGroups&$token&". "context=account"; $mix_url = "{$admin_url}a=mixCrawls&$token"; $crawls_url = "{$admin_url}a=manageCrawls&$token"; $machines_url = "{$admin_url}a=manageMachines&$token"; $base_url = "{$admin_url}a=manageAccount&$token"; $querystats_url = $crawls_url . "&arg=querystats&". "context=account"; $edit_or_no_url = $base_url . ( (isset($data['EDIT_USER'])) ? "&edit=false":"&edit=true"); $icon_helper = $this->view->helper('iconlink'); $is_mobile = !empty($_SERVER['MOBILE']); if (isset($data['EDIT_USER'])) { return $this->renderEditUser($data); } $more_groups = (count(($data['RECENT_GROUPS'] ?? [])) < $data['NUM_GROUPS']); ?> <div class="current-activity"> <div class="account-info"> <h2><img class='home-icon' src="<?= $data['USER']['USER_ICON'] ?>" alt="<?= tl('manageaccount_element_icon') ?>" /> <div><?= $data['USERNAME'] ?></div> <?= $icon_helper->renderButton($edit_or_no_url, 'account_settings'); ?> </h2> </div> <?php if (isset($data['CRAWL_MANAGER']) && $data['CRAWL_MANAGER']) { ?> <h2 class="home-groups-container"><?php e(tl('manageaccount_element_search_and_index')); ?> </h2> <?=$icon_helper->renderButton($crawls_url, 'crawls');?> <?=$icon_helper->renderButton($machines_url, 'machines');?> <?php if (in_array("mixCrawls", array_column($data['ACTIVITIES'],"METHOD_NAME"))) { $icon_helper->renderButton($mix_url, 'mixes'); }?> <?=$icon_helper->renderButton($querystats_url, 'query_stats');?> <p><?php e(tl('manageaccount_element_num_crawls', $data["CRAWLS_RUNNING"], $data["NUM_CLOSED_CRAWLS"])); if (in_array("mixCrawls", array_column($data['ACTIVITIES'],"METHOD_NAME"))) { ?> <?php if ($data['NUM_MIXES'] > 1 || $data['NUM_MIXES'] == 0) { e(tl('manageaccount_element_num_mixes', $data['NUM_MIXES'])); } else { e(tl('manageaccount_element_num_mix', $data['NUM_MIXES'])); } ?> <?php } ?> </p> <?php } ?> <h2 class="inline-block"><?= tl('manageaccount_element_groups')?></h2> <?=$icon_helper->renderButton($messages_url, 'messages');?> <?=$icon_helper->renderButton($feed_url ."&v=ungrouped", 'combined_discussions');?> <?=$icon_helper->renderButton($feed_url, 'groups');?> <?=$icon_helper->renderButton($group_url ."&browse=true", 'join_groups');?> <?=$icon_helper->renderButton($group_url, 'create_group');?> <p><?php if ($data['NUM_GROUPS'] > 1 || $data['NUM_GROUPS'] == 0) { e(tl('manageaccount_element_num_groups', $data['NUM_GROUPS'])); } else { e(tl('manageaccount_element_num_group', $data['NUM_GROUPS'])); }?></p> <?php $this->view->helper("grouplist")->render($data['GROUPS'], $token, $icon_helper, "admin", "account"); if ($more_groups) {?> <div class="more-groups"><b><a href="<?=$feed_url?>"><?= tl('manageaccount_element_more_groups')?></a></b></div><?php } if (!empty($data['THREAD_RECOMMENDATIONS']) || !empty($data['GROUP_RECOMMENDATIONS'])) { ?> <h2><?=tl('manageaccount_element_recommendations')?></h2> <div class="access-result"> <?php if (!empty($data['THREAD_RECOMMENDATIONS'])) { ?><b><?=tl('manageaccount_element_rec_threads') ?></b><ul><?php foreach ($data['THREAD_RECOMMENDATIONS'] as $thread => $threadName) { ?> <li><a href="<?=htmlentities(B\feedsUrl("thread", $thread, true, "group")) . $token ?>" ><?= $threadName ?></a></li> <?php }?></ul><?php } ?><br /><?php if (!empty($data['GROUP_RECOMMENDATIONS'])) { ?><b><?=tl('manageaccount_element_rec_groups') ?></b><ul><?php foreach ($data['GROUP_RECOMMENDATIONS'] as $group_id => $group_name) { ?> <li><a href="<?= htmlentities(B\feedsUrl("group", $group_id, true, "group")) . $token ?>" ><?= $group_name ?></a></li> <?php }?></ul><?php } ?></div><?php } ?> </div> <?php } /** * Renders the form used to control account settings such as * icon photo, email, password, etc. for a user * * @param array $data has field with current values for these setting * (except password) so that forms can be pre-populated. */ public function renderEditUser($data) { $token = C\CSRF_TOKEN . "=" . $data[C\CSRF_TOKEN]; $admin_url = htmlentities(B\controllerUrl('admin', true)); $messages_url = htmlentities(B\controllerUrl("user_messages", true)) . $token; $base_url = "{$admin_url}a=manageAccount&$token"; $password_or_no_url = $base_url .( (isset($data['EDIT_PASSWORD'])) ? "&edit_pass=false": "&edit_pass=true"); $edit_or_no_url = $base_url . ( (isset($data['EDIT_USER'])) ? "&edit=false":"&edit=true"); $disabled = (isset($data['EDIT_USER'])) ? "" : "disabled='disabled'"; $is_mobile = !empty($_SERVER['MOBILE']); ?> <div class="current-activity"> <div class="account-info" tabindex="1"> <?= $this->view->helper("close")->render($edit_or_no_url); ?> <form id="changeUserForm" method="post" class="account-details" autocomplete="off" enctype="multipart/form-data"> <h2><?=tl('manageaccount_element_account_details') ?></h2><?php $row_col_span = 'rowspan="7"'; if (isset($data['EDIT_PASSWORD'])) { $row_col_span = 'rowspan="12"'; } if (!empty($data['USER']['IS_BOT_USER'])) { $row_col_span = 'rowspan="17"'; } if ($is_mobile) { $row_col_span = 'class="center" style="width:300px"'; } ?> <input type="hidden" name="c" value="admin" /> <input type="hidden" name="<?= C\CSRF_TOKEN ?>" value="<?= $data[C\CSRF_TOKEN] ?>" /> <input type="hidden" name="a" value="manageAccount" /> <input type="hidden" name="arg" value="updateuser" /> <table class="name-table"> <tr> <td <?=$row_col_span?> class="user-icon-td" ><img class='user-icon' id='current-icon' src="<?= $data['USER']['USER_ICON'] ?>" alt="<?= tl('manageaccount_element_icon') ?>" /><?php $this->view->helper("fileupload")->render('current-icon', 'user_icon', 'user-icon', C\THUMB_SIZE, 'image', ['image/png', 'image/gif', 'image/jpeg']); if ($is_mobile) { ?> </td></tr></table><table class="name-table"> <?php } else { e('</td>'); }?> <th class="table-label"><label for="user-name"><?= tl('manageaccount_element_username') ?>:</label></th> <td><input type="text" id="user-name" name="user_name" maxlength="<?= C\NAME_LEN ?>" value="<?= $data['USER']['USER_NAME'] ?>" class="narrow-field" disabled="disabled" /></td> </tr> <tr><th class="table-label"><label for="first-name"><?php e(tl('manageaccount_element_firstname')); ?>:</label></th> <td><input type="text" id="first-name" name="FIRST_NAME" maxlength="<?= C\NAME_LEN?>" value="<?php e($data['USER']['FIRST_NAME']); ?>" class="narrow-field" <?php e($disabled);?> /></td></tr> <tr><th class="table-label"><label for="last-name"><?php e(tl('manageaccount_element_lastname')); ?>:</label></th> <td><input type="text" id="last-name" name="LAST_NAME" maxlength="<?= C\NAME_LEN ?>" value="<?php e($data['USER']['LAST_NAME']); ?>" class="narrow-field" <?php e($disabled);?> /></td></tr> <tr><th class="table-label"><label for="e-mail"><?php e(tl('manageaccount_element_email')); ?>:</label></th> <td><input type="email" id="e-mail" name="EMAIL" maxlength="<?= C\LONG_NAME_LEN ?>" <?php e($disabled);?> value="<?php e($data['USER']['EMAIL']); ?>" class="narrow-field"/></td></tr> <tr> <th class="table-label"><label for="locale"><b><?= tl('options_element_language_label') ?></b></label></th> <td><?php $this->view->element("language")->render($data); ?></td> </tr><?php if (!empty($data['yioop_bot_configuration'])) { ?> <tr> <th class="table-label"><label for="is_bot"><?php e(tl('manageaccount_element_is_bot')); ?></label></th> <td><input type="checkbox" id="is_bot" name="IS_BOT_USER" value="true" <?php if (!empty($data['USER']['IS_BOT_USER']) && $data['USER']['IS_BOT_USER'] == true) { e("checked='checked'"); } ?> /> </td></tr><?php if ($data['USER']['IS_BOT_USER'] == true) { ?> <tr><th class="table-label"> <label for="bot-unique-token"><?php e(tl('manageaccount_element_bot_unique_token')) ?></label></th> <td><input type="text" id="bot-unique-token" name="BOT_TOKEN" value="<?php e($data['USER']['BOT_TOKEN']); ?>" class="narrow-field" /> </td> </tr> <tr> <th class="table-label"> <label for="bot-callback-url"><?php e(tl('manageaccount_element_bot_callback_url')); ?></label></th> <td><input type="text" id="bot-callback-url" name="BOT_CALLBACK_URL" value="<?php e($data['USER']['CALLBACK_URL']); ?>" class="narrow-field"/> </td> </tr> <?php } }?> <tr><th class="table-label"><label for="password"><a href="<?php e($password_or_no_url);?>"><?php e(tl('manageaccount_element_password'))?></a></label></th> <td><input type="password" id="password" name="password" maxlength="<?= C\LONG_NAME_LEN ?>" class="narrow-field"/> </td></tr> <?php if (isset($data['EDIT_PASSWORD'])) { ?> <tr><th class="table-label"><label for="new-password"><?php e(tl('manageaccount_element_new_password'))?></label></th> <td><input type="password" id="new-password" name="new_password" maxlength="<?= C\LONG_NAME_LEN?>" class="narrow-field"/> </td></tr> <tr><th class="table-label"><label for="retype-password"><?php e(tl('manageaccount_element_retype_password')); ?></label></th> <td><input type="password" id="retype-password" name="retype_password" maxlength="<?= C\LONG_NAME_LEN?>" class="narrow-field" /> </td></tr> <?php $question_sets = []; if (C\RECOVERY_MODE == C\EMAIL_AND_QUESTIONS_RECOVERY) { $question_sets = [ tl('manageaccount_element_new_recovery_qa') => $data['RECOVERY']]; } $i = 0; foreach ($question_sets as $name => $set) { $first = true; $num = count($set); foreach ($set as $question) { if ($first) { ?> <tr><th class="table-label" rowspan='<?= $num ?>' style="max-width:2in;"><?php e($name); ?></th><td class="table-input border-top"> <?php } else { ?> <tr><td class="table-input"> <?php } $this->view->helper("options")->render( "question-$i", "question_$i", $question, $data['RECOVERY_ANSWERS'][$i]); $first = false; e("</td></tr>"); $i++; } } } ?> <tr><td></td> <td class="center"><button class="button-box" type="submit"><?php e(tl('manageaccount_element_save')); ?></button></td></tr> </table> </form> </div> </div><?php } }