<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: classes/admin/ranks.php
| Author: Chan (<NAME>)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
namespace PHPFusion\Forums\Admin;

use PHPFusion\Forums\ForumServer;

class ForumAdminRanks extends ForumAdminInterface {

    protected $data = array(
        'rank_id' => 0,
        'rank_title' => '',
        'rank_image' => '',
        'rank_posts' => 0,
        'rank_type' => 2,
        'rank_apply_normal' => '',
        'rank_apply_special' => '',
        'rank_apply' => '',
    );

    public function viewRanksAdmin() {
        $aidlink = fusion_get_aidlink();
        pageAccess('F');
        \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb([
                           'link' => INFUSIONS.'forum/admin/forums.php'.$aidlink.'&section=fr',
                           'title' => self::$locale['404']
                       ]);

        $forum_settings = $this->get_forum_settings();

        echo "<div class='well'>".self::$locale['forum_rank_0100']."</div>\n";

        if ($forum_settings['forum_ranks']) {

            $tab['title'][] = self::$locale['402'];
            $tab['id'][] = "rank_list";
            $tab['icon'][] = "";

            $tab['title'][] = isset($_GET['rank_id']) && isnum($_GET['rank_id']) ? self::$locale['401'] : self::$locale['400'];
            $tab['id'][] = "rank_form";
            $tab['icon'][] = "";

            $_GET['ref'] = isset($_GET['ref']) && in_array($_GET['ref'], $tab['id']) ? $_GET['ref'] : "rank_list";

            echo opentab($tab, $_GET['ref'], "rank_admin", TRUE, "nav-tabs m-t-10", "ref");

            switch ($_GET['ref']) {
                case "rank_form" :
                    // @todo: improvise rank from ui
                    echo $this->displayRanksForm();
                    break;
                case "rank_list":
                    echo $this->displayRankList();

            }

            echo closetab();

        } else {
            opentable(self::$locale['403']);
            ?>
            <div class="well text-center">
                <?php
                echo sprintf(self::$locale['450'], "<a href='".FUSION_SELF.$aidlink."&section=fs'>".self::$locale['451']."</a>");
                ?>
            </div>
            <?php
            closetable();
        }


    }

    protected function displayRanksForm() {
        global $aidlink;

        if (isset($_POST['cancel_rank'])) {
            redirect(clean_request("", array("rank_id", "ref"), FALSE));
        }

        add_to_footer("<script src='".FORUM."admin/admin_rank.js'></script>");

        $this->data['rank_language'] = LANGUAGE;

        $array_apply_normal_opts = array(
            USER_LEVEL_MEMBER => self::$locale['424'],
            '104' => self::$locale['425'],
            USER_LEVEL_ADMIN => self::$locale['426'],
            USER_LEVEL_SUPER_ADMIN => self::$locale['427']
        );

        // Special Select
        $groups_arr = getusergroups();
        $groups_except = array(USER_LEVEL_PUBLIC, USER_LEVEL_MEMBER, USER_LEVEL_ADMIN, USER_LEVEL_SUPER_ADMIN);
        $group_opts = array();
        foreach ($groups_arr as $group) {
            if (!in_array($group[0], $groups_except)) {
                $group_opts[$group[0]] = $group[1];
            }
        }

        $language_opts = fusion_get_enabled_languages();

        $this->post_forum_ranks();

        $form_action = FUSION_SELF.$aidlink.'&section=fr&ref=rank_form';

        if (isset($_GET['rank_id']) && isnum($_GET['rank_id'])) {

            $result = dbquery("SELECT * FROM ".DB_FORUM_RANKS." WHERE rank_id='".intval($_GET['rank_id'])."'");

            if (dbrows($result) > 0) {

                $this->data = dbarray($result);

                $form_action = FUSION_SELF.$aidlink."&section=fr&ref=rank_form&rank_id=".$_GET['rank_id']."";

            } else {
                redirect(clean_request("", array("rank_id", "ref"), FALSE));
            }

        }

        $html =
            openform('rank_form', 'post', $form_action, array('class' => 'm-t-20')).

            form_text('rank_title', self::$locale['420'], $this->data['rank_title'],
                      array('required' => 1, 'error_text' => self::$locale['414'], "inline" => TRUE)).

            form_select('rank_image', self::$locale['421'], $this->data['rank_image'],
                        array(
                            'options' => $this->get_rank_images(),
                            'placeholder' => self::$locale['choose'],
                            "inline" => TRUE
                        )
            );

        if (multilang_table("FR")) {
            $html .=
                form_select('rank_language', self::$locale['global_ML100'], $this->data['rank_language'], array(
                    'options' => $language_opts,
                    'placeholder' => self::$locale['choose'], "inline" => TRUE
                ));

        } else {
            $html .= form_hidden('rank_language', '', $this->data['rank_language']);
        }

        $html .= form_checkbox('rank_type', self::$locale['429'], $this->data['rank_type'],
                               array(
                                   "options" => array(
                                       2 => self::$locale['429a'],
                                       1 => self::$locale['429b'],
                                       0 => self::$locale['429c'],
                                   ),
                                   "type" => "radio",
                                   "inline" => TRUE,
                               )
            ).

            form_text('rank_posts', self::$locale['422'], $this->data['rank_posts'],
                      array(
                          'inline' => TRUE,
                          'type' => 'number',<commit_msg>Update ranks.php<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: classes/admin/ranks.php
| Author: Chan (<NAME>)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
namespace PHPFusion\Forums\Admin;

use PHPFusion\Forums\ForumServer;

class ForumAdminRanks extends ForumAdminInterface {

    protected $data = array(
        'rank_id' => 0,
        'rank_title' => '',
        'rank_image' => '',
        'rank_posts' => 0,
        'rank_type' => 2,
        'rank_apply_normal' => '',
        'rank_apply_special' => '',
        'rank_apply' => '',
    );

    public function viewRanksAdmin() {
        $aidlink = fusion_get_aidlink();
        pageAccess('F');
        \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb([
                           'link' => INFUSIONS.'forum/admin/forums.php'.$aidlink.'&section=fr',
                           'title' => self::$locale['404']
                       ]);

        $forum_settings = $this->get_forum_settings();

        echo "<div class='well'>".self::$locale['forum_rank_0100']."</div>\n";

        if ($forum_settings['forum_ranks']) {

            $tab['title'][] = self::$locale['402'];
            $tab['id'][] = "rank_list";
            $tab['icon'][] = "";

            $tab['title'][] = isset($_GET['rank_id']) && isnum($_GET['rank_id']) ? self::$locale['401'] : self::$locale['400'];
            $tab['id'][] = "rank_form";
            $tab['icon'][] = "";

            $_GET['ref'] = isset($_GET['ref']) && in_array($_GET['ref'], $tab['id']) ? $_GET['ref'] : "rank_list";

            echo opentab($tab, $_GET['ref'], "rank_admin", TRUE, "nav-tabs m-t-10", "ref");

            switch ($_GET['ref']) {
                case "rank_form" :
                    // @todo: improvise rank from ui
                    echo $this->displayRanksForm();
                    break;
                case "rank_list":
                    echo $this->displayRankList();

            }

            echo closetab();

        } else {
            opentable(self::$locale['403']);
            ?>
            <div class="well text-center">
                <?php
                echo sprintf(self::$locale['450'], "<a href='".FUSION_SELF.$aidlink."&section=fs'>".self::$locale['451']."</a>");
                ?>
            </div>
            <?php
            closetable();
        }


    }

    protected function displayRanksForm() {
        global $aidlink;

        if (isset($_POST['cancel_rank'])) {
            redirect(clean_request("", array("rank_id", "ref"), FALSE));
        }

        add_to_footer("<script src='".FORUM."admin/admin_rank.js'></script>");

        $this->data['rank_language'] = LANGUAGE;

        $array_apply_normal_opts = array(
            USER_LEVEL_MEMBER => self::$locale['424'],
            '-104' => self::$locale['425'],
            USER_LEVEL_ADMIN => self::$locale['426'],
            USER_LEVEL_SUPER_ADMIN => self::$locale['427']
        );

        // Special Select
        $groups_arr = getusergroups();
        $groups_except = array(USER_LEVEL_PUBLIC, USER_LEVEL_MEMBER, USER_LEVEL_ADMIN, USER_LEVEL_SUPER_ADMIN);
        $group_opts = array();
        foreach ($groups_arr as $group) {
            if (in_array($group[0], $groups_except)) {
                $group_opts[$group[0]] = $group[1];
            }
        }

        $language_opts = fusion_get_enabled_languages();

        $this->post_forum_ranks();

        $form_action = FUSION_SELF.$aidlink.'&section=fr&ref=rank_form';

        if (isset($_GET['rank_id']) && isnum($_GET['rank_id'])) {

            $result = dbquery("SELECT * FROM ".DB_FORUM_RANKS." WHERE rank_id='".intval($_GET['rank_id'])."'");

            if (dbrows($result) > 0) {

                $this->data = dbarray($result);

                $form_action = FUSION_SELF.$aidlink."&section=fr&ref=rank_form&rank_id=".$_GET['rank_id']."";

            } else {
                redirect(clean_request("", array("rank_id", "ref"), FALSE));
            }

        }

        $html =
            openform('rank_form', 'post', $form_action, array('class' => 'm-t-20')).

            form_text('rank_title', self::$locale['420'], $this->data['rank_title'],
                      array('required' => 1, 'error_text' => self::$locale['414'], "inline" => TRUE)).

            form_select('rank_image', self::$locale['421'], $this->data['rank_image'],
                        array(
                            'options' => $this->get_rank_images(),
                            'placeholder' => self::$locale['choose'],
                            "inline" => TRUE
                        )
            );

        if (multilang_table("FR")) {
            $html .=
                form_select('rank_language', self::$locale['global_ML100'], $this->data['rank_language'], array(
                    'options' => $language_opts,
                    'placeholder' => self::$locale['choose'], "inline" => TRUE
                ));

        } else {
            $html .= form_hidden('rank_language', '', $this->data['rank_language']);
        }

        $html .= form_checkbox('rank_type', self::$locale['429'], $this->data['rank_type'],
                               array(
                                   "options" => array(
                                       self::$locale['429c'],
                                       self::$locale['429b'],
                                       self::$locale['429a'],
                                   ),
                                   "type" => "radio",
                                   "inline" => TRUE,
                               )
            ).

            form_text('rank_posts', self::$locale['422'], $this->data['rank_posts'],
                      array(
                          'inline' => TRUE,
                          'type' => 'number',
{'fraction_non_alphanumeric': 0.20020120724346077, 'fraction_numerical': 0.012459371614301192, 'mean_word_length': 1.6149332254148119, 'pattern_counts': {'":': 2, '<': 27, '<?xml version=': 0, '>': 116, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1068827', 'n_tokens_mistral': 3740, 'n_tokens_neox': 3521, 'n_words': 605}