@extends('main')
@section('css')
<link href="{{ asset('/css/bootstrapValidator.min.css')}}" rel="stylesheet">
<link href="{{ asset('plugins/datatables/css/jquery.dataTables.css')}}" rel="stylesheet">
@endsection
@section('content')
<section class="main_content">
    <div class="container">
     <ol class="breadcrumb cust-breadcrumb">
              <li><a href="{{url('/')}}">Home</a></li>
              <li class="active">Mentor/Mentee</li>
            </ol>  
              <div class="row">

  <div class="clearfix"></div>
             @if (Session::get('error_msg'))
              <div class="col-md-12">
                <div class="alert alert-danger">
                   <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                   </button>
                    <?php echo Session::get('error_msg') ?>
                </div>
              </div>
            @endif
            @if (Session::get('succ_msg'))
              <div class="col-md-12">
                <div class="alert alert-success">
                   <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                   </button>
                    <?php echo Session::get('succ_msg')?>
                </div>
              </div>  
            @endif
          </div>
      <div class="row talent_home">
        @include("left_menu")
        <div class="col-md-9 col-sm-8">
            <div class="rt-panel-block">  
           <div class="my-profiles-block"> 
            <div id="render-this">
            <h1 class="heading pull-left">Mentor/Mentee</h1> 
           
            <div class="row">
         
              <div class="col-md-12">
                  <div id="connectionmsg" >
                      @if(isset($_GET['data']))
                      <p class='alert alert-success clearfix'>                
                          {{$_GET['data']}}                
                      </p>
                      @endif
                  </div>
                  <div class="clearfix"><br></div>
                  
                  <ul id="myTab" class="nav nav-tabs mentor-tabs">
                  <li class="active"><a href="#Mentor" data-toggle="tab">My Mentors</a></li>
                  <li class=""><a href="#Mentee" data-toggle="tab">My Mentees</a></li>
                  </ul>
                   <div id="myTabContent" class="tab-content">
                  <div class="tab-pane fade active in" id="Mentor">
                    <table id="userstable" class="display responsive nowrap table table-bordered">
                  <thead>
                    <tr>
                      <th style="display:none">Name</th>
                      <th style="display:none">Subject</th>
                      <th style="display:none">Date</th>
                    </tr>
                    @if(count($res_act)==0)
                    <tr>
                        <td colspan="3" align="center">No New Message</td>                      
                    </tr>
                    @endif                    
                    @foreach($res_act as $rows)                  
                    <tr>
                       @if($rows['status']=="1")
                        <td class="menter-pic-block">@if($rows['profile_type']=='O')<a href="{{url('profiles/'.$rows['receiver_profile_id'])}}">@else<a href="{{url('profiles/'.$rows['receiver_profile_id'])}}">@endif<img src="<?php if($rows['profile_image'] && is_file('uploads/profile_images/'.$rows['profile_image'])) {echo 'uploads/profile_images/'.$rows['profile_image']; }else  {echo 'uploads/profile_images/default-profile.png';} ?>" class="img-circle menter-profil-pic"> <p class="menter-name-p"><?php if($rows['is_readed']=='N') echo "<strong> ". ucfirst($rows['name']). "</strong>"; else echo ucfirst($rows['name']); ?></p></a></td>
                        @endif
                         @if($rows['status']=="1")
                        <td><a href="{{url('mentor/details/'.$rows['id'])}}" class="mentor-msg-txt"><?php if($rows['is_readed']=='N') echo "<strong title='New Message'> ".ucfirst($rows['subject'])." </strong>"; else echo ucfirst($rows['subject']); ?></strong></a><p class="mentor-msg-date">{{date('d-m-Y',strtotime($rows['created_at']))}}</p></td>
                         @endif
                    </tr>                  
                    @endforeach
                  </thead>
              </table>
                  </div>
                  <div class="tab-pane fade" id="Mentee">
                      <table id="userstable" class="display responsive nowrap table table-bordered">
                  <thead>
                    <tr>
                      <th style="display:none">Name</th>
                      <th style="display:none">Subject</th>
                      <?php $i=0;?>
                      @if(count($res_inact)>0)
                      @foreach($res_inact as $rows)
                      @if($rows['status']=="0")
                     <?php  $i++;?>
                      @endif
                      @endforeach
                      @endif  
                      
                    </tr>
                    @if(count($res_inact)==0)
                    <tr>
                        <td colspan="3" align="center">No New Message</td>                      
                    </tr>
                    @endif
                    @foreach($res_inact as $rows)                  
                    <tr>
                        <?php if($rows['status']=="0"){ ?> 
                            <td class="menter-pic-block">@if($rows['profile_type']=='O')<a href="{{url('profiles/'.$rows['sender_profile_id'])}}">@else<a href="{{url('profiles/'.$rows['sender_profile_id'])}}">@endif<img src="<?php if($rows['profile_image'] && is_file('uploads/profile_images/'.$rows['profile_image'])) {echo 'uploads/profile_images/'.$rows['profile_image']; }else  {echo 'uploads/profile_images/default-profile.png';} ?>" class="img-circle menter-profil-pic" > &nbsp;<?php if($rows['is_readed']=='N') echo "<p class='menter-name-p'><strong> ". ucfirst($rows['name']). "</strong></p>"; else echo ucfirst($rows['name']); ?></a></td>
                        <?php } else if($rows['status']=="1") { ?>
                            <td class="menter-pic-block">@if($rows['profile_type']=='O')<a href="{{url('profiles/'.$rows['sender_profile_id'])}}">@else<a href="{{url('profiles/'.$rows['sender_profile_id'])}}">@endif<img src="<?php if($rows['profile_image'] && is_file('uploads/profile_images/'.$rows['profile_image'])) {echo 'uploads/profile_images/'.$rows['profile_image']; }else  {echo 'uploads/profile_images/default-profile.png';} ?>" class="img-circle menter-profil-pic"><p class="menter-name-p"><?php if($rows['is_readed']=='N') echo "<strong> ". ucfirst($rows['name']). "</strong>"; else echo ucfirst($rows['name']); ?></p></a></td>
                        <?php } ?>
                         <?php if($rows['status']=="0"){ ?> 
                            <td><a href="{{url('mentor/details/'.$rows['id'])}}" class="mentor-msg-txt"><?php if($rows['is_readed']=='N') echo "<strong title='New Message'> ".ucfirst($rows['subject'])." </strong>"; else echo ucfirst($rows['subject']); ?></strong></a></td>
                           <td> <a class="btn btn-success ment-acc-btn"  href="{{url('mentorstatus/yes/'.$rows['sender_profile_id'])}}">Accept</a>&nbsp;<a class="btn btn-success ment-decl-btn" href="{{url('mentorstatus/no/'.$rows['sender_profile_id'])}}" >Decline</a>&nbsp;<a class="btn btn-success ment-decl-btn" id="mentor_request" data-id="{{$rows['sender_profile_id']}}" href="javascript:void(0)" >Delete</a><p class="mentor-msg-date">{{date('d-m-Y',strtotime($rows['created_at']))}}</p></td>
                         <?php } else if($rows['status']=="1") { ?>
                        <td><a href="{{url('mentor/details/'.$rows['id'])}}"><?php if($rows['is_readed']=='N') echo "<strong title='New Message'> ".ucfirst($rows['subject'])." </strong>"; else echo ucfirst($rows['subject']); ?></a></td><td><p class="mentor-msg-date">{{date('d-m-Y',strtotime($rows['created_at']))}}</p></td>
                       
                         <?php } ?>  
                       
                       
                    </tr>                  
                    @endforeach
                  </thead>
              </table>
                      
                   
                  </div>
                  </div>
              </div>
            </div> 
          </div>  
          </div>
          </div>       
        </div>  
       </div>
       </div>  
  </section>
@endsection
@section('js')
<script src="{{ asset('js/bootstrapValidator.min.js')}}"></script>
<script src="{{ asset('plugins/datatables/js/jquery.dataTables.js')}}"></script>
<script src="{{ asset('js/typeahead_0.11.js')}}"></script>
<script src="{{ asset('js/handlebars.js')}}"></script>
<script src="{{ asset('js/validation.js')}}"></script>
<script src="{{ asset('js/bootbox.js')}}"></script>
<script>
$(document).on('click','#mentor_request',function(){
    var msg = 'Are you sure want to Delete ';
    var pic_id = $(this).attr("data-id");
    bootbox.confirm("Are you sure, you want to Decline Connection", function(result){   
     if(result)

   location.href = '{{url("mentorstatus/delete")}}/'+pic_id;
         return true;
//       $.ajax({
//              url: "{{url('statusdelete')}}",
//              type: 'get',
//              data: { 'pid':$pid,'_token': $('input[name=_token]').val() },
//              success:function(data){
//                         //$("#connectionmsg").append(data);
//                        window.location='connectionview?data='+data;
//                        }
//              });
    });
  });
        
 if($('#send_invitation').length)
{
  $(document).on('click','#send_invitation',function(){
    $('#send_invitation_modal').modal('show');
  });
}
if($('#sendInvitationForm').length)
{
  /*Compose To Address Profile Typeahead*/
  var bestPictures = new Bloodhound({
      datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
      queryTokenizer: Bloodhound.tokenizers.whitespace,
      //prefetch: '../data/films/post_1960.json',
      remote: {
        url: '{{url("profile_typeahead")}}?profile_name=%QUERY',
        wildcard: '%QUERY'
      }
    });

  $('#to').typeahead(null, {
      name: 'best-pictures',
      display: 'value',
      source: bestPictures,
      templates: {
        empty: [
          '<div class="empty-message">',
            'unable to find any prfofile name that match the current query',
          '</div>'
        ].join('\n'),
        suggestion: Handlebars.compile('<p><img src="{{url("uploads/profile_images/")}}/@{{#if profile_image}}@{{profile_image}}@{{else}}default-profile.png@{{/if}}" class="img-circle" width="50px" height="50px">&nbsp;<strong>@{{value}}</strong> – @{{username}}</p>')
      }

    }).on('typeahead:selected', function($e, datum){
        $("#sel_to_prof_id").val(datum['id']);
    });
  /* End To Address Profile Typeahead*/
  $(document).on('click','.clear_form',function(){
    window.location=window.location;
  });

  $("#composeMessageForm").bootstrapValidator({        
      message: 'This value is not valid',
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        'to': {
              validators: {
                  notEmpty: {
                      message: 'The To should not be empty'
                  },
                  remote: {
                      message : 'invalid to address',
                      url: "/invitation/check_username",
                      type: "get",
                      data: {
                      username: function() {
                                      return $("#username").val();
                                  }
                      }
                  }
              },
          },
        'subject': {
              validators: {
                  notEmpty: {
                      message: 'The Subject should not be empty'
                  },
              }
          },
        'message': {
              validators: {
                  notEmpty: {
                      message: 'The Message should not be empty'
                  },
              }
          },
      }
  });
}
/*if($('#users-table').length)
{
  $('#users-table').DataTable({
    //processing: true,
    serverSide: true,
    ajax: 'connectedlist?msg_type=I',
    columns: [
      {data: 'profile_image', name: 'profile_image', width:'25%', orderable: false, searchable: false},
      {data: 'name', name: 'name', width:'60%', orderable: false, searchable: false},
      {data: 'created_at', name: 'created_at', width:'15%'},
      {data: 'status', name: 'status', width:'60%', orderable: false, searchable: false},
      {data: 'sender_profile_id', name: 'sender_profile_id', width:'15%'}
    ],
  });
}*/
function statuschange($pid)
{
    $.ajax({
          url: "{{url('statuschange')}}",
          type: 'get',
          data: { 'pid':$pid,'_token': $('input[name=_token]').val() },
          success:function(data){
                //alert(data);
               window.location='connectionview?data='+data;
                    }
                });
}
function statusdelete($pid)
{  var msg = 'Are you sure want to Delete ';
    bootbox.confirm("Are you sure, you want to Decline Connection", function(result){   
     if(result)
       $.ajax({
              url: "{{url('statusdelete')}}",
              type: 'get',
              data: { 'pid':$pid,'_token': $('input[name=_token]').val() },
              success:function(data){
                         //$("#connectionmsg").append(data);
                        window.location='connectionview?data='+data;
                        }
              });
    });
}
$(document).ready(function(){
    
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  var target = $(e.target).attr("href") // activated tab
  //alert(target);
});
});
</script>
@endsection
