<?php
/**
 * VFM - veno file manager: admin-panel/view/dashboard/registration.php
 * administration registration block
 *
 * @package VenoFileManager
 */
if (!defined('VFM_APP')) {
    return;
}
/**
* ROLE PERMISSIONS
**/
$regdirs = $setUp->getConfig('registration_user_folders');
$regdirsarray = $regdirs ? json_decode($regdirs, true) : array();
?>
<div class="row mb-3">
    <div class="col-sm-12">
        <div class="card" id="view-registration">
            <div class="card-header d-flex justify-content-center align-items-center">
                <h4 class="m-0"><i class="bi bi-person-plus"></i> <?php echo $setUp->getString('registration'); ?></h4>
                <button type="button" class="btn ms-auto" data-bs-toggle="collapse" data-bs-target="#card-registration" aria-expanded="false">
                    <i class="bi bi-dash-lg"></i>
                </button>
            </div>
            <div class="collapse show" id="card-registration">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <div class="checkbox mb-3">
                            <?php $formchecked = $setUp->getConfig('registration_enable') ? ' checked' : ''; ?>
                            <div class="form-check form-switch">
                                <input class="form-check-input" role="switch" type="checkbox" name="registration_enable" id="registration_enable" <?php echo $formchecked; ?>>
                                <label class="form-check-label" for="registration_enable"><?php echo $setUp->getString("enabled"); ?></label>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-4">
                        <label class="form-label"><?php echo $setUp->getString("role"); ?></label>
                        <div class="input-group mb-3">
                            <select class="form-select" name="registration_role">
                            <?php
                            foreach ($allroles_nosuperadmin as $key => $rolename) {
                                $rolekey = $key == 'admin' ? '' : '_'.$key;
                                $formselected = $setUp->getConfig('registration_role') === $key ? ' selected' : '';
                                ?>
                                <option value="<?php echo $key; ?>"<?php echo $formselected; ?>><?php echo $rolename; ?></option>
                                <?php
                            } ?>
                            </select>
                        </div>

                        <div class="form-group mb-3">
                            <label class="form-label"><?php echo $setUp->getString("keep_links"); ?></label>
                            <select class="form-select" name="registration_lifetime">
                            <?php
                            $default_registration_lifetime = $setUp->getConfig('registration_lifetime', '-1 day');
                            foreach ($registration_lifetime as $key => $value) {
                                $formselected = $default_registration_lifetime === $key ? ' selected' : '';
                                ?>
                                <option value="<?php echo $key; ?>"<?php echo $formselected; ?>><?php echo $value; ?></option>
                                <?php
                            } ?>
                            </select>
                        </div>

                        <div class="form-group mb-3">
                            <label class="label" for="password_length"><?php echo $setUp->getString("password"); ?>: <?php echo $setUp->getString("minimum_length"); ?></label>
                            <input class="form-control" type="number" name="password_length" id="password_length" value="<?php echo $setUp->getConfig("password_length", 4); ?>">
                        </div>
                    </div>

                    <div class="col-md-4 togglequota">

                        <div class="row">

                            <div class="col-12 form-group mb-3">
                                <label class="form-label"><?php echo $setUp->getString("user_folder"); ?></label>
                                <div class="foldertree-btn">
                                    <div class="input-group mb-3">
                                        <span class="input-group-text"><i class="bi bi-folder-check"></i></span>
                                        <span class="input-group-text flex-grow-1">(<span class="getfolder-count">0</span>)</span>
                                        <button type="button" class="btn btn-primary" data-target="archive-map">
                                          <i class="bi bi-diagram-3-fill"></i>
                                        </button>
                                    </div>
                                    <input type="hidden" readonly class="form-control getfolder" name="reguserfolders" value='<?php echo json_encode($regdirsarray); ?>'>
                                </div>
                                <?php
                                $formchecked = $setUp->getConfig('registration_user_folder') ? ' checked' : '';
                                ?>
                                <div class="form-check form-switch">
                                  <input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" name="registration_user_folder"<?php echo $formchecked; ?>>
                                  <label class="form-check-label" for="flexSwitchCheckDefault"><i class="bi bi-folder-plus"></i> <?php echo $setUp->getString("new_username_folder"); ?></label>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-12">
                                <div class="form-group userquota mb-3">
                                    <label class="form-label"><?php echo $setUp->getString("available_space"); ?></label>
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-segmented-nav"></i></span>
                                        <select class="form-select" name="regquota">
                                            <option value=""><?php echo $setUp->getString("unlimited"); ?></option>
                                            <?php
                                            foreach ($_QUOTA as $value) {
                                                $formatsize = $setUp->formatSize(($value*1024*1024));
                                                echo '<option value="'.$value.'"';
                                                if ($setUp->getConfig('registration_user_quota') == $value) {
                                                    echo ' selected';
                                                }
                                                echo '>'.$formatsize.'</option>';
                                            } ?>
                                        </select>
                                    </div> <!-- input-group -->
                                </div> <!-- userquota -->
                            </div> <!-- col-sm-12 -->
                        </div> <!-- row -->

                        <div class="form-group mb-3">
                            <label class="form-label" for="password_length"><?php echo $setUp->getString("request_approvation"); ?></label>
                            <input class="form-control" type="email" name="request_approvation" value="<?php echo $setUp->getConfig("request_approvation", ""); ?>" placeholder="admin@mail.ext">
                            <div class="form-text"><?php echo $setUp->getString("send_approvation_link_to"); ?></div>
                        </div>

                    </div> <!-- col-md-4 -->

                </div> <!-- row -->
            </div> <!-- box-body -->
            </div>
        </div> <!-- box -->
    </div>
</div>