<?php $this->load->view('site/layout'); ?>
<link href="<?php echo base_url() ?>public/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css" />

<?php $this->load->view('site/navbar'); ?>

<style>
    .privacy {
        display: none;
    }
    .select2{
        width: 100% !important;
    }
</style>

<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">

    <!-- begin:: Content Head -->
    <div class="kt-subheader  kt-grid__item" id="kt_subheader">
        <div class="kt-container  kt-container--fluid ">
            <div class="kt-subheader__main">
                <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                <span class="kt-subheader__desc"><?php echo $this->lang->line('guides'); ?></span>
            </div>

        </div>
    </div>
</div>

<div class="kt-portlet kt-portlet--mobile">
    <?php if ($this->session->flashdata('success')) { ?>
        <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
            <?= $this->session->flashdata('success') ?>
        </div>
    <?php } ?>

    <div class="kt-portlet__head kt-portlet__head--lg">
        <div class="kt-portlet__head-label">
            <span class="kt-portlet__head-icon">
                <i class="kt-font-brand flaticon2-line-chart"></i>
            </span>
            <h3 class="kt-portlet__head-title">
                <?php echo $this->lang->line('add-a-guide'); ?>
            </h3>
        </div>
    </div>
    <div class="kt-portlet__body">

        <?php if (validation_errors()) { ?>
            <div class="alert alert-danger">
                <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                <?php echo validation_errors(); ?>
            </div>
        <?php } ?>

        <?php echo form_open('knowledge_base/postadddalel'); ?>	

        <form method="post" id="edit-profile" class="form-horizontal">

                <div class="form-group row">
                    <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('link_title') ?></label>
                    <div class="col-10">
                        <input type="text" required class="form-control" id="mail" name="name" value="">
                    </div> <!-- /controls -->				
                </div> <!-- /control-group -->


                <div class="form-group row">
                    <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('guide_title') ?></label>
                    <div class="col-10">
                        <input type="text" required class="form-control" id="firstname" name="title" value="">
                    </div> <!-- /controls -->				
                </div> <!-- /control-group -->


                <div class="form-group row">
                    <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('protection_type') ?></label>
                    <div class="col-10">
                        <select name="privacy_type" class="form-control" id="privacy_type">
                            <option value="عام">عام</option>
                            <option value="كلمة مرور">كلمة مرور</option>
                            <option value="مستخدمين">مستخدمين</option>
                            <option value="مجموعات">مجموعات</option>
                        </select>
                    </div> <!-- /controls -->				
                </div> <!-- /control-group -->
                <br />
                <br />
                <!--For Password Privacy-->
                <div class="form-group row privacy" id="password">
                    <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('password') ?></label>
                    <div class="col-10">
                        <input type="password" class="form-control" id="firstname" name="password" value="">
                    </div> <!-- /controls -->				
                </div> <!-- /control-group -->
                <!--end password privacy-->

                <!--For Users Privacy -->
                <?php $allusers = $this->db->get('user')->result(); ?>

                <div class="form-group row privacy" id="users">
                    <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('users') ?></label>
                    <div class="col-10">
                        <div class="row">
                            <div class="col-sm-5">
                                <select name="usersfrom[]" id="search1" class="form-control select2" multiple >
                                    <?php
                                    if (isset($allusers) && $allusers != null) {
                                        for ($k = 0; $k < count($allusers); ++$k) {
                                            //if (in_array($permissions[$k]->id, $group_per) == false) {
                                            ?>
                                            <option value="<?php echo $allusers[$k]->id; ?>" data-position="1"><?php echo $allusers[$k]->name; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    </div> <!-- /controls -->				

                </div> <!-- /control-group -->
                <!--end users privacy-->

                <!--For Groups Privacy -->
                <?php $allgroups = $this->db->get('groups')->result(); ?>
                <div class="form-group row privacy" id="groups">
                    <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('groups') ?></label>
                    <div class="col-10">
                        <div class="row">
                            <div class="col-sm-5">
                                <p><?= $this->lang->line('all') . ' ' . $this->lang->line('groups') ?></p>
                                <select name="groupsfrom[]" id="search" class="form-control select2" size="8" multiple="multiple">
                                    <?php
                                    if (isset($allgroups) && $allgroups != null) {
                                        for ($k = 0; $k < count($allgroups); ++$k) {
                                            //if (in_array($permissions[$k]->id, $group_per) == false) {
                                            ?>
                                            <option value="<?php echo $allgroups[$k]->id; ?>" data-position="1"><?php echo $allgroups[$k]->groups; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    </div> <!-- /controls -->				

                </div> <!-- /control-group -->
                <!--end group privacy-->

                <br>   

                <div class="form-actions">
                    <button type="submit" class="btn btn-primary"><?= $this->lang->line('save') ?></button> 
                    <a href="<?php echo base_url('knowledge_base/dalel'); ?>" class="btn"><?= $this->lang->line('cancel') ?></a>
                </div> <!-- /form-actions -->
        </form>
    </div>
</div>


<?php $this->load->view('site/footer_2'); ?>

<script type="text/javascript">
    $(document).ready(function () {
        $(".select2").select2();

        $("#privacy_type").change(function () {
            var privacy = $(this).children("option:selected").val();
            if (privacy == 'كلمة مرور') {
                $('.privacy').fadeOut(300);
                $('#password').delay(100).fadeIn(500);
            }
            if (privacy == 'مستخدمين') {
                $('.privacy').fadeOut(300);
                $('#users').delay(100).fadeIn(500);
            }
            if (privacy == 'مجموعات') {
                $('.privacy').fadeOut(300);
                $('#groups').delay(100).fadeIn(500);
            }
            if (privacy == 'عام') {
                $('.privacy').fadeOut(500);
            }
        });
    });

</script>