@extends('adminlte::page')
@section('content_header')
    @notifyCss
    @notifyJs
@stop
@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card card-primary">
                <div class="card-header">
                    <h3 class="card-title">View Schedule</h3>
                </div>
                @include('notify::messages')
                <!-- /.card-header -->
                <!-- form start -->
                <form id="userregform" class="form-horizontal" action="#" method="post" autocomplete="off" enctype="multipart/form-data">
                  {{ csrf_field() }}
                  <div class="card-body">
                      <div class="col-12">
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Organisation</label><br>
                                  {{$schedules->organisation->organisation_name}}
                                  <input type="hidden" name="schedule_id" id="schedule_id" value="{{$schedules->id}}">
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Department</label><br>
                                  @if(isset($schedules->department_id))
                                    {{$schedules->department->department_name}}
                                  @endif
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Section</label><br>
                                  @if(isset($schedules->section_id))
                                    {{$schedules->section->section_name}}
                                  @endif
                              </div>
                              <div class="col-3">
                                <label for="exampleInputEmail1">Material Type</label><br>
                                  {{$schedules->material_type->material_type_name}}
                              </div>
                          </div>
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Training Title</label><br>
                                  {{$schedules->training_title}}
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Venue</label><br>
                                  {{$schedules->venue}}
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Training Period</label><br>
                                  @php
                                    $period_from = $schedules->period_from;
                                    $period_to = $schedules->period_to;
                                    if($period_from)
                                    {
                                        $period_from = date("d-M-Y", strtotime($period_from));
                                    }
                                    if($period_to)
                                    {
                                        $period_to = date("d-M-Y", strtotime($period_to));
                                    }
                                    echo $period_from." to ".$period_to;
                                  @endphp 
                                  
                              </div>
                              <div class="col-3">
                                <label for="exampleInputEmail1">Min & Max seats for training</label><br>
                                  @php
                                    $min_seat_training = $schedules->min_seat_training;
                                    $max_seat_training = $schedules->max_seat_training;
                                    
                                    echo $min_seat_training." & ".$max_seat_training;
                                  @endphp 
                              </div>
                          </div>
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Roles</label><br>
                                  {{$schedules->training_title}}
                              </div>
                          </div>
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Whether Registration is Needed?</label><br>
                                  @if($schedules->registration_status==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Question and Answers for Training</label><br>
                                  @if($schedules->question_answer_status==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Reviews and Feedback Needed?</label><br>
                                  @if($schedules->review_status==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif                                  
                              </div>
                              <div class="col-3">
                                <label for="exampleInputEmail1">Training Certificates Needed?</label><br>
                                  @if($schedules->training_certificates==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif   
                              </div>
                          </div>
                          <div id="listroledata" style="padding: 10px;">
                              <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                                  <thead>
                                      <tr class="success">
                                        <th width="10%">Slno</th>
                                        <th>Participant Name</th>
                                        <th>
                                          <button data-toggle="modal" data-target='#ParticipantModal' class="btn btn-warning btn-sm pull-right" type="button" onclick=getModalParticipant({{$schedules->id}});>Add New Participant</button>
                                        </th>
                                      </tr>
                                  </thead>
                                  <tbody>
                                    @php
                                      $n= 0;
                                    @endphp
                                    @if(isset($schedules->schedule_participants))
                                      @foreach($schedules->schedule_participants as $schedule_participant)
                                        @php
                                          $n++;
                                        @endphp
                                        <tr>
                                          <td>{{$n}}</td>
                                          <td>{{$schedule_participant->users->name}}</td>
                                          <td>
                                            @if($schedule_participant->mail_send_flag==1)
                                              @php
                                                echo "Mail Send."
                                              @endphp
                                            @else
                                              @php
                                                echo "Mail Not Send."
                                              @endphp
                                            @endif
                                          </td>
                                        </tr>
                                      @endforeach
                                    @else
                                      <tr>
                                        <td colspan="3" style=" text-align: center;">
                                            <span style="color: red;">No Participants are assigned yet !!!</span>
                                        </td>
                                      </tr>
                                    @endif
                                  </tbody>
                              </table>
                          </div>                        
                      </div>
                  </div>
                  <!-- /.card-body -->
                </form>
            </div>
        </div>        
    </div>
    <div class="modal fade" id="ParticipantModal" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document" style="max-width: 750px !important;" >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="card-body">
              <h4 class="modal-title" id="myModalLabel">Add New Participant</h4>
              <form action="{{ url('/participant_add_training') }}" method="post" enctype="multipart/form-data" id="tapal_forward">
                <div class="modal-body">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input type="hidden" name="schedule_id_new" id="schedule_id_new" class="form-control" value="">
                    <div id="modal_particiapant_div">
                      <div class="form-group row">
                        <div class="col-6">
                            <label for="exampleInputEmail1">Organisation</label>
                            <select name="organisation_id" id="organisation_id" class="form-control" required onchange="load_department(this.value);load_user();">
                                <option value="">Select Organisation</option>
                                @foreach($organisations as $organisation)
                                    <option value="{{$organisation->id}}">{{$organisation->organisation_name}}</option>
                                @endforeach
                            </select>
                        </div>
                      </div>
                      <div class="form-group row">
                        <div class="col-6">
                            <label for="exampleInputEmail1">Department</label>
                            <select name="department_id" id="department_id" class="form-control" onchange="load_section(this.value);load_user();">
                                <option value="">Select Department</option>
                            </select>
                        </div>
                      </div>
                      <div class="form-group row">
                        <div class="col-6">
                            <label for="exampleInputEmail1">Section</label>
                            <select name="section_id" id="section_id" class="form-control" onchange="load_user();">
                                <option value="">Select Section</option>
                            </select>
                        </div>
                      </div>
                      <div class="form-group row">
                        <div class="col-6">
                            <label for="exampleInputEmail1">Participants</label>
                            <select name="user_id" id="user_id" class="form-control" required class="form-control">
                              <option value="">Select Participants</option>
                            </select>
                        </div>
                      </div>
                    </div>
                  <!--modal body close-->
                </div>
                <div class="modal-footer">
                  <div class="row">
                    <div class="col-md-3">
                      <button id="add_participant" type="submit" class="btn btn-info"  >Add</button>
                    </div>
                  </div>
                </div>
              </form>
            </div>
        </div>
      </div>
      <!--panel body close-->
    </div>
    <script type="text/javascript">
      function getModalParticipant(id)
      {
        document.getElementById("schedule_id_new").value=id;
      }
      function load_department(organisation_id)
      {
          $.ajax({
             type:'GET',
             url: "{!! url('get_department/"+organisation_id+"') !!}",
             success:function(data)
             {
                $('#department_id').empty();
                $('#department_id').append("<option value=''>Select Department</option>");
                $.each(data, function(key, element) {
                    $('#department_id').append("<option value='" + key +"'>" + element + "</option>");
                }); 
             }
          });
      }
      function load_section(department_id)
      {
          $.ajax({
             type:'GET',
             url: "{!! url('get_section/"+department_id+"') !!}",
             success:function(data)
             {
                $('#section_id').empty();
                $('#section_id').append("<option value=''>Select Section</option>");
                $.each(data, function(key, element) {
                    $('#section_id').append("<option value='" + key +"'>" + element + "</option>");
                }); 
             }
          });
      }
      function load_user()
      {
        var department_id= "";
        var section_id = "";
        var organisation_id ="";
        var schedule_id = document.getElementById("schedule_id").value;
        organisation_id = document.getElementById("organisation_id").value;
        department_id = document.getElementById("department_id").value;
        section_id = document.getElementById("section_id").value;
        var id = organisation_id+"~"+department_id+"~"+section_id+"~"+schedule_id;
        //alert(id);
          $.ajax({
             type:'GET',
             url: "{!! url('get_participants/"+id+"') !!}",
             success:function(data)
             {
                $('#user_id').empty();
                $('#user_id').append("<option value=''>Select Participants</option>");
                $.each(data, function(key, element) {
                    $('#user_id').append("<option value='" + key +"'>" + element + "</option>");
                }); 
             }
          });
      }
    </script>
@stop
