 <?php
    $edited = can_action('55', 'edited');
    $deleted = can_action('55', 'deleted');
  
 ?>
 <div class="nav-tabs-custom">
     <!-- Tabs within a box -->
     <ul class="nav nav-tabs">
         <li class="active"><a href="#reminder_manage" data-toggle="tab"><?= lang('reminder') . ' ' . lang('list') ?></a>
         </li>
         <?php if (!empty($edited)) { ?>
             <li class=""><a href="#reminder_create" data-toggle="tab"><?= lang('set') . ' ' . lang('reminder') ?></a>
             </li>
         <?php } ?>
     </ul>
     <div class="tab-content bg-white">
         <!-- ************** general *************-->
         <div class="tab-pane active" id="reminder_manage">
             <div class="table-responsive">
                 <table class="table table-striped">
                     <thead>
                         <tr>
                             <th><?= lang('description') ?></th>
                             <th><?= lang('date') ?></th>
                             <th><?= lang('remind') ?></th>
                             <th><?= lang('notified') ?></th>
                             <th class="col-options no-sort text-right"><?= lang('action') ?></th>
                         </tr>
                     </thead>
                     <tbody>
                         <?php
                            // $all_reminder = $this->db->where(array('module' => 'leads', 'module_id' => $leads_details->leads_id))->get('tbl_reminders')->result();
                            $all_reminder = get_result('tbl_reminders', array('module_id' => $leads_details->leads_id));
                            
                            if (!empty($all_reminder)) {
                                foreach ($all_reminder as $v_reminder) :
                                    $remind_user_info = $this->db->where('user_id', $v_reminder->user_id)->get('tbl_account_details')->row();
                            ?>
                                 <tr id="leads_reminder_<?= $v_reminder->reminder_id ?>">
                                     <td><?= $v_reminder->description ?></td>
                                     <td><?= display_date($v_reminder->date) . ' ' . display_time($v_reminder->date) ?>
                                     </td>
                                     <td>
                                         <a href="<?= base_url() ?>admin/user/user_details/<?= $v_reminder->user_id ?>">
                                             <?= $remind_user_info->fullname ?></a>
                                     </td>
                                     <td><?= $v_reminder->notified ?></td>
                                     <td>
                                         <?php echo ajax_anchor(base_url("admin/invoice/delete_reminder/" . $v_reminder->module . '/' . $v_reminder->module_id . '/' . $v_reminder->reminder_id), lang('delete'), array("class" => "", "title" => lang('delete'), "data-fade-out-on-success" => "#leads_reminder_" . $v_reminder->reminder_id)); ?>
                                     </td>
                                 </tr>
                             <?php
                                endforeach;
                            } else {
                                ?>
                             <tr>
                                 <td colspan="5"><?= lang('nothing_to_display') ?></td>
                             </tr>
                         <?php }
                            ?>
                     </tbody>
                 </table>
             </div>
         </div>
         <div class="tab-pane" id="reminder_create">
             <form role="form" data-parsley-validate="" novalidate="" enctype="multipart/form-data" id="form" action="<?php echo base_url(); ?>admin/invoice/reminder/leads/<?= $leads_details->leads_id ?>/<?php
                                                                                                                                                                                                            if (!empty($reminder_info)) {
                                                                                                                                                                                                                echo $reminder_info->reminder_id;
                                                                                                                                                                                                            }
                                                                                                                                                                                                            ?>" method="post" class="form-horizontal  ">
                 <div class="form-group">
                     <label class="col-lg-3 control-label"><?= lang('date_to_notified') ?> <span class="text-danger">*</span></label>
                     <div class="col-lg-5">
                        <input type="text" name="date" class="form-control ts-datepicker" value="<?php
                                                                                                   if (!empty($reminder_info->date)) {
                                                                                                       echo $reminder_info->date;
                                                                                                   } else {
                                                                                                       echo date('Y-m-d H:i');
                                                                                                   }
                                                                                                   ?>" data-type="datetime" data-format="Y-m-d H:i" data-min-date="<?= date('Y-m-d'); ?>">
                    </div>

                 </div>
                 <!-- End discount Fields -->
                 <div class="form-group terms">
                     <label class="col-lg-3 control-label"><?= lang('description') ?> </label>
                     <div class="col-lg-5">
                         <textarea name="description" class="form-control"><?php
                                                                            if (!empty($reminder_info)) {
                                                                                echo $reminder_info->description;
                                                                            }
                                                                            ?></textarea>
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="col-lg-3 control-label"><?= lang('set_reminder_to') ?> <span class="text-danger">*</span></label>
                     <div class="col-lg-5">
                         <select class="form-control select_box" name="user_id" style="width: 100%">
                             <?php
                                $permission_user = $this->items_model->all_permission_user('55');
                                if (!empty($permission_user)) {
                                    foreach ($permission_user as $key => $v_users) {
                                ?>
                                     <option <?php
                                                if (!empty($reminder_info)) {
                                                    echo $reminder_info->user_id == $v_users->user_id ? 'selected' : null;
                                                }
                                                ?> value="<?= $v_users->user_id ?>">
                                         <?= $v_users->fullname ?></option>
                             <?php }
                                }
                                ?>
                         </select>
                     </div>
                 </div>
                 <div class="form-group terms">
                     <label class="col-lg-3 control-label"></label>
                     <div class="col-lg-5">
                         <div class="checkbox c-checkbox">
                             <label class="needsclick">
                                 <input type="checkbox" value="Yes" <?php if (!empty($reminder_info) && $reminder_info->notify_by_email == 'Yes') {
                                                                        echo 'checked';
                                                                    } ?> name="notify_by_email">
                                 <span data-lucide="check"></span>
                                 <?= lang('send_also_email_this_reminder') ?>
                             </label>
                         </div>
                     </div>
                 </div>

                 <div class="form-group">
                     <label class="col-lg-3 control-label"></label>
                     <div class="col-lg-5">
                         <button type="submit" class="btn btn-purple"><?= lang('update') ?></button>
                     </div>
                 </div>
             </form>
         </div>
     </div>
 </div>
