<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->load->view('includes/head'); ?>
</head>
<body> 
  <div id="app">
    <div class="main-wrapper">
      <?php $this->load->view('includes/navbar'); ?>
      <!-- Main Content -->
      <div class="main-content">
        <section class="section">
          <div class="section-header">
            <div class="section-header-back">
              <a href="<?=base_url('projects')?>" class="btn btn-icon"><i class="fas fa-arrow-left"></i></a>
            </div>
            <h1>
            <?=$this->lang->line('projects_detail')?$this->lang->line('projects_detail'):'Projects Detail'?>
            </h1>
            <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="<?=base_url()?>"><?=$this->lang->line('dashboard')?$this->lang->line('dashboard'):'Dashboard'?></a></div>
              <div class="breadcrumb-item active"><a href="<?=base_url('projects')?>"><?=$this->lang->line('projects')?$this->lang->line('projects'):'Projects'?></a></div>
              <div class="breadcrumb-item"><?=$this->lang->line('details')?$this->lang->line('details'):'Details'?></div>
            </div>
          </div>
          <div class="section-body">
          <?php 
            if(isset($project[0]) && !empty($project[0])){
              $project = $project[0];
            }
          ?>

            <?php if ($this->ion_auth->is_admin() || permissions('task_view')){ ?>
              <a href="<?=base_url("projects/tasks/".htmlspecialchars($project['id']))?>" class="btn btn-icon icon-left btn-primary"><i class="fas fa-tasks"></i> <?=$this->lang->line('tasks')?$this->lang->line('tasks'):'Tasks'?></a>
            <?php } ?>
            
            
            <?php if ($this->ion_auth->is_admin() || permissions('calendar_view')){ ?>
              <a href="<?=base_url("projects/calendar/".htmlspecialchars($project['id']))?>" class="btn btn-icon icon-left btn-primary"><i class="fas fa-calendar-alt"></i> <?=$this->lang->line('calendar')?$this->lang->line('calendar'):'Calendar'?></a>
            <?php } ?>

            <?php if ($this->ion_auth->is_admin() || permissions('gantt_view')){ ?>
              <a href="<?=base_url("projects/gantt/".htmlspecialchars($project['id']))?>" class="btn btn-icon icon-left btn-primary"><i class="fas fa-layer-group"></i> <?=$this->lang->line('gantt')?$this->lang->line('gantt'):'Gantt'?></a>
            <?php } ?>
            
            <?php if(!$this->ion_auth->in_group(3)){ ?>  
              <a href="<?=base_url("projects/timesheet/".htmlspecialchars($project['id']))?>" class="btn btn-icon icon-left btn-primary"><i class="fas fa-stopwatch"></i> <?=$this->lang->line('timesheet')?$this->lang->line('timesheet'):'Timesheet'?></a>
            <?php } ?>

            <?php if ($this->ion_auth->is_admin() || permissions('project_edit')){ ?>
              <a href="#" data-edit="<?=htmlspecialchars($project['id'])?>" class="btn btn-icon icon-left btn-info modal-edit-project"><i class="fas fa-edit"></i> <?=$this->lang->line('edit')?$this->lang->line('edit'):'Edit'?></a>
            <?php } ?>
            
            <?php if ($this->ion_auth->is_admin() || permissions('project_delete')){ ?>
              <a href="#" class="btn btn-icon icon-left btn-danger delete_project" data-id="<?=htmlspecialchars($project['id'])?>"><i class="fas fa-times"></i> <?=$this->lang->line('delete')?$this->lang->line('delete'):'Delete'?></a>
            <?php } ?>

              <div class="row mt-3">
              <div class="col-md-7">
                <div class="card author-box card-<?=htmlspecialchars($project['project_class'])?>">
                  <div class="card-body">
                    <div class="author-box-name">
                    
                      <?php if($this->ion_auth->is_admin() || permissions('project_budget')){ ?>
                        <div class="float-right">
                          <?=get_currency('currency_symbol')?><?=htmlspecialchars($project['budget'])?>
                        </div>
                      <?php } ?>

                      <a><?=htmlspecialchars($project['title'])?></a>
                    </div>
                    <div class="author-box-job text-<?=htmlspecialchars($project['project_class'])?>"><?=htmlspecialchars($project['project_status'])?></div>
                    <div class="author-box-description">
                      <p class="description-wrapper"><?=htmlspecialchars($project['description'])?></p>
                    </div>
                  </div>
                </div>
              </div>
              
              <?php if(!empty($project['project_client'])){ ?>
              
              <div class="col-md-5">
                <div class="card card-<?=htmlspecialchars($project['project_class'])?>">
                  <div class="card-header">
                    <h4><?=$this->lang->line('client_detail')?$this->lang->line('client_detail'):'Client Detail'?></h4>
                  </div>
                  <div class="card-body pb-0">
                    <div class="profile-widget mt-0">
                    <div class="profile-widget-header">
                      <div class="profile-widget-items">
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('name')?$this->lang->line('name'):'Name'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['project_client']->first_name)?> <?=htmlspecialchars($project['project_client']->last_name)?></div>
                        </div>
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('company_name')?$this->lang->line('company_name'):'Company Name'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['project_client']->company)?></div>
                        </div>
                      </div>
                    </div>
                    <div class="profile-widget-header">
                      <div class="profile-widget-items">
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('email')?$this->lang->line('email'):'Email'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['project_client']->email)?></div>
                        </div>
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('mobile')?$this->lang->line('mobile'):'Mobile'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['project_client']->phone)?></div>
                        </div>
                      </div>
                    </div>
                    </div>
                  </div>
                </div>
              </div>
              <?php } ?>


              <div class="col-md-<?=!empty($project['project_client'])?12:5?>">
                <div class="card card-primary">
                  <div class="card-header">
                    <h4><?=$this->lang->line('task_overview')?$this->lang->line('task_overview'):'Task Overview'?></h4>
                  </div>
                  <div class="card-body pb-0">
                    <div class="profile-widget mt-0">
                    <div class="profile-widget-header">
                      <div class="profile-widget-items">
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('days')?$this->lang->line('days'):'Days'?> <?=htmlspecialchars($project['days_status'])?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['days_count'])?></div>
                        </div>
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('starting_date')?$this->lang->line('starting_date'):'Starting Date'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['starting_date'])?></div>
                        </div>
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('ending_date')?$this->lang->line('ending_date'):'Ending Date'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['ending_date'])?></div>
                        </div>
                      </div>
                    </div>
                    <div class="profile-widget-header">
                      <div class="profile-widget-items">
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('total_tasks')?$this->lang->line('total_tasks'):'Total Tasks'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['total_tasks'])?></div>
                        </div>
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('completed_tasks')?$this->lang->line('completed_tasks'):'Completed Tasks'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['completed_tasks'])?></div>
                        </div>
                        <div class="profile-widget-item">
                          <div class="profile-widget-item-label"><?=$this->lang->line('pending_tasks')?$this->lang->line('pending_tasks'):'Pending Tasks'?></div>
                          <div class="profile-widget-item-value"><?=htmlspecialchars($project['total_tasks'])-htmlspecialchars($project['completed_tasks'])?></div>
                        </div>
                      </div>
                    </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="card card-primary">
                  <div class="card-header">
                    <h4><?=$this->lang->line('task_status')?$this->lang->line('task_status'):'Task Status'?></h4>
                  </div>
                  <div class="card-body">
                    <canvas id="project_statistics" height="auto"></canvas>
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="card card-primary">
                  <div class="card-header">
                    <h4><?=$this->lang->line('project_users')?$this->lang->line('project_users'):'Project Users'?></h4>
                  </div>
                  <div class="card-body"> 
                    <table class='table-striped' id='users_list'
                      data-toggle="table"
                      data-url="<?=base_url('projects/get_project_users/'.$project['id'])?>"
                      data-click-to-select="true"
                      data-side-pagination="server"
                      data-pagination="false"
                      data-page-list="[5, 10, 20, 50, 100, 200]"
                      data-search="false" data-show-columns="false"
                      data-show-refresh="false" data-trim-on-search="false"
                      data-sort-name="first_name" data-sort-order="asc"
                      data-mobile-responsive="true"
                      data-toolbar="" data-show-export="false"
                      data-maintain-selected="true"
                      data-export-types='["txt","excel"]'
                      data-export-options='{
                        "fileName": "users-list",
                        "ignoreColumn": ["state"] 
                      }'
                      data-query-params="queryParams">
                      <thead>
                        <tr>
                          <th data-field="full_name" data-sortable="true"><?=$this->lang->line('name')?$this->lang->line('name'):'Name'?></th>
                          <th data-field="email" data-sortable="true"><?=$this->lang->line('email')?$this->lang->line('email'):'Email'?></th>
                        </tr>
                      </thead>
                    </table>
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="card card-primary">
                  <div class="card-header">
                    <h4><?=$this->lang->line('upload_project_files')?$this->lang->line('upload_project_files'):'Upload Project Files'?></h4>
                  </div>
                  <div class="card-body">
                    <form action="<?=base_url('projects/upload-files/'.htmlspecialchars($project['id']))?>" class="dropzone" id="mydropzone">
                      <div class="fallback">
                        <input name="file" type="file" multiple />
                      </div>
                    </form>
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="card card-primary">
                  <div class="card-header">
                    <h4><?=$this->lang->line('project_files')?$this->lang->line('project_files'):'Project Files'?></h4>
                  </div>
                  <div class="card-body"> 
                    <table class='table-striped' id='file_list'
                      data-toggle="table"
                      data-url="<?=base_url('projects/get_project_files/'.htmlspecialchars($project['id']))?>"
                      data-click-to-select="true"
                      data-side-pagination="server"
                      data-pagination="false"
                      data-page-list="[5, 10, 20, 50, 100, 200]"
                      data-search="false" data-show-columns="false"
                      data-show-refresh="false" data-trim-on-search="false"
                      data-sort-name="first_name" data-sort-order="asc"
                      data-mobile-responsive="true"
                      data-toolbar="" data-show-export="false"
                      data-maintain-selected="true"
                      data-export-types='["txt","excel"]'
                      data-export-options='{
                        "fileName": "users-list",
                        "ignoreColumn": ["state"] 
                      }'
                      data-query-params="queryParams">
                      <thead>
                        <tr>
                          <th data-field="file_name" data-sortable="true"><?=$this->lang->line('file')?$this->lang->line('file'):'File'?></th>
                          <th data-field="file_type" data-sortable="true"><?=$this->lang->line('file_type')?$this->lang->line('file_type'):'File Type'?></th>
                          <th data-field="file_size" data-sortable="true"><?=$this->lang->line('size')?$this->lang->line('size'):'Size'?></th>
                          <th data-field="action" data-sortable="false"><?=$this->lang->line('action')?$this->lang->line('action'):'Action'?></th>
                        </tr>
                      </thead>
                    </table>
                  </div>
                </div>
              </div>



            </div>   
          </div>
        </section>
      </div>
    
    <?php $this->load->view('includes/footer'); ?>
    </div>
  </div>

<form action="<?=base_url('projects/edit-project')?>" method="POST"  class="modal-part" id="modal-edit-project-part" data-title="<?=$this->lang->line('edit_project')?$this->lang->line('edit_project'):'Edit Project'?>" data-btn="<?=$this->lang->line('update')?$this->lang->line('update'):'Update'?>">
  <input type="hidden" name="update_id" id="update_id">

  <div class="form-group">
    <label><?=$this->lang->line('project_title')?$this->lang->line('project_title'):'Project Title'?><span class="text-danger">*</span></label>
    <input type="text" name="title" id="title" class="form-control" required="">
  </div>
  <div class="form-group">
    <label><?=$this->lang->line('description')?$this->lang->line('description'):'Description'?><span class="text-danger">*</span></label>
    <textarea type="text" name="description" id="description" class="form-control"></textarea>
  </div>

  <span class="row">
    <div class="form-group col-md-6">
      <label><?=$this->lang->line('starting_date')?$this->lang->line('starting_date'):'Starting Date'?><span class="text-danger">*</span></label>
      <input type="text" name="starting_date" id="starting_date" class="form-control datepicker">
    </div>

    <div class="form-group col-md-6">
      <label><?=$this->lang->line('ending_date')?$this->lang->line('ending_date'):'Ending Date'?><span class="text-danger">*</span></label>
      <input type="text" name="ending_date" id="ending_date" class="form-control datepicker">
    </div>
  </span>

  <span class="row">
    <div class="form-group col-md-6">
      <label><?=$this->lang->line('budget')?$this->lang->line('budget'):'Budget'?> - <?=get_currency('currency_code')?></label>
      <input type="number" pattern="[0-9]" name="budget" id="budget" class="form-control">
    </div>
    <div class="form-group col-md-6">
      <label><?=$this->lang->line('status')?$this->lang->line('status'):'Status'?><span class="text-danger">*</span></label>
      <select name="status" id="status" class="form-control select2">
        <?php foreach($project_status as $status){ ?>
        <option value="<?=htmlspecialchars($status['id'])?>"><?=htmlspecialchars($status['title'])?></option>
        <?php } ?>
      </select>
    </div>
  </span>

  <div class="form-group">
    <label><?=$this->lang->line('project_users')?$this->lang->line('project_users'):'Project Users'?> <i class="fas fa-question-circle" data-toggle="tooltip" data-placement="right" title="<?=$this->lang->line('add_users_who_will_work_on_this_project_only_this_users_are_able_to_see_this_project')?$this->lang->line('add_users_who_will_work_on_this_project_only_this_users_are_able_to_see_this_project'):"Add users who will work on this project. Only this users are able to see this project."?>"></i></label>
    <select name="users[]" id="users" class="form-control select2" multiple="">
      <?php foreach($system_users as $system_user){ ?>
      <option value="<?=htmlspecialchars($system_user->id)?>"><?=htmlspecialchars($system_user->first_name)?> <?=htmlspecialchars($system_user->last_name)?></option>
      <?php } ?>
    </select>
  </div>

  <div class="form-group">
    <label><?=$this->lang->line('project_client')?$this->lang->line('project_client'):'Project Client'?></label>
    <select name="client" id="client" class="form-control select2">
      <option value=""><?=$this->lang->line('select_clients')?$this->lang->line('select_clients'):'Select Clients'?></option>
      <?php foreach($system_clients as $system_client){ ?>
      <option value="<?=htmlspecialchars($system_client->id)?>"><?=htmlspecialchars($system_client->first_name)?> <?=htmlspecialchars($system_client->last_name)?></option>
      <?php } ?>
    </select>
  </div>
</form>

<div id="modal-edit-project"></div>

<?php
  foreach($task_status as $task_title){
    $tmpT[] =  htmlspecialchars($task_title['title']);
    if($this->ion_auth->is_admin()){
      $tmpTV[] =  get_count('id','tasks','status='.htmlspecialchars($task_title['id']).' AND project_id='.htmlspecialchars($project['id']));
    }elseif($this->ion_auth->in_group(3)){
      $tmpTV[] =  get_count('t.id','tasks t LEFT JOIN projects p on t.project_id = p.id','p.client_id = '.htmlspecialchars($this->session->userdata('user_id')).' AND t.status = '.htmlspecialchars($task_title['id']).' AND t.project_id='.htmlspecialchars($project['id']));
    }else{
      $tmpTV[] =  get_count('t.id','tasks t LEFT JOIN task_users tu ON t.id=tu.task_id','status='.$task_title['id'].' AND tu.user_id='.htmlspecialchars($this->session->userdata('user_id')).' AND project_id='.htmlspecialchars($project['id']));
    }
  }

?>

<?php $this->load->view('includes/js'); ?>
<script>
  project_id = "<?=htmlspecialchars($project['id'])?>";
  task_status = '<?=json_encode($tmpT)?>';
  task_status_values = '<?=json_encode($tmpTV)?>';
</script>
<script src="<?=base_url('assets/js/page/projects-details.js')?>"></script>
</body>
</html>
