@extends('main')
@section('css')
<link href="{{ asset('/css/bootstrapValidator.min.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">Search Result</li>
            </ol>
      <div class="row talent_home">
        
        <form name="hiddenSearchForm" id="hiddenSearchForm">
          @foreach($search_data as $key => $value)
            <input type="hidden" name="{{$key}}" value="{{$value}}">
          @endforeach
            <input type="hidden" id="limit" name="limit" value="{{Config::get('constants.PROFILE_SEARCH_LIMIT')}}">
            <input type="hidden" id="offset" name="offset" value="{{Config::get('constants.PROFILE_SEARCH_LIMIT')}}">
        </form>
        <div class="col-md-12 col-sm-12"> 
             
             
            <div id="connectionmsg" >
                
            </div>
             
             <div class="col-xs-6">
          <h1 class="heading mtop-0 search-result-head">Search</h1>
          </div>
          
          <div class="clearfix"></div>
        <form name="searchProfileForm" id="searchProfileForm" method="post">
         <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <div class="row talent_data search_result search-result-right-br" id="search_result_data">
            @if(count($search_result))
            <?php $i=1;?>
              @foreach($search_result as $pro)
             <?php if($i%2==0){?> <div class="row search-page-br"><?php } ?>
              <div class="col-md-6">
                <div class="row">
                  <div class="emty-div-row">
                   <div class="row profile-search-top-actions">
                        
						<div class="col-md-8 col-xs-8">
                      <a href="{{url('searchprofiles/'.$pro->id)}}">
                       <h4>{{$pro->name}}</h4>
                      </a>
                    </div>
					</div>
					<div class="row profile-search-middle-actions ">
					<div class="col-xs-4 col-md-4 searchpg-profile-pic">
                       <a href="{{url('searchprofiles/'.$pro->id)}}">
  					         @if($pro->profile_image && is_file('uploads/profile_images/'.$pro->profile_image))
                        <img class="img-responsive img-circle" src="{{url('uploads/profile_images/'.$pro->profile_image)}}" alt=""/>
                      @else                    
                        <img class="img-responsive img-circle" src="{{url('uploads/profile_images/default-profile.png')}}" alt=""/>
                      @endif
                      </a>
                   </div>
				 
                    <div class="col-xs-4 col-md-4">
                    <div class="profile-addpic-search"><a href="{{url('searchprofiles/'.$pro->id)}}"><img class="img-responsive" src="../images/add_pic.png" alt=""/></a></div></div>
                  
                  </div>
                  </div>
                    
                </div>
                   <div class="clearfix">     <div id="LoadingImage" style="display: none;">
                 <img class="img-responsive" src="../images/spin.gif" width="120" height="120" alt=""/>
        </div></div>
              </div>
             <?php if($i%2==0){?></div><?php }?>
              <?php $i++;?>
              @endforeach
            @else
              <div class="col-md-6 txt-red">
                Required profiles not found
              </div>  
            @endif  
            </div>          
          </form>
          <div class="clearfix"></div>
          <!--<input type="hidden" name="_token" value="{{{ Session::getToken() }}}">-->


 <div class="modal" id="mentor_model" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
&times;</button>
<h4 class="modal-title" align="center">Mentor Subject Information</h4>
</div>
    <div class="modal-body">
        <form role="form" action="mentor" method="POST"id="mentor_subject">
        <div class="form-group">
             <input type="hidden" name="_token" value="{{ csrf_token() }}">
             <input type="hidden" name="checbox_val" id="checkbox_val" value="">
           <label for="name">Title<span class="reqired-val">*</span>:</label>
           <input type="text" class="form-control" id="mentor_sub" name="mentor_sub" 
              placeholder="Enter subject">
        </div> 
    <div class="modal-footer">
<button type="submit" class="btn btn-primary">Submit</button>

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

</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>         
 
          <div class="modal" id="connection_model" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
&times;</button>
<h4 class="modal-title" align="center">Connection Subject Information</h4>
</div>
    <div class="modal-body">
        <form role="form" action="{{url('send_connection')}}" method="GET" id="connection_subject" name="connection_subject">
        
             <input type="hidden" name="_token" value="{{ csrf_token() }}">
             <input type="hidden" name="ids" id="ids">
             <input type="hidden" name="checbox_val" id="checkbox_val" value="">
        <div class="form-group">
           <label for="name">Title :</label>
           <input type="text" class="form-control" id="conneciton_sub" name="conneciton_sub" 
                  placeholder="Enter subject" value="I would like to Connect" readonly="true">
        </div>
        <div class="form-group">
            <label for="name">Message :</label>
            <textarea id="connection_message" name="connection_message" class="form-control" ></textarea>
        </div> 
    <div class="modal-footer">
<!--<button type="button" class="btn btn-primary" id="connection_ajax">Submit</button>-->
<button type="submit" class="btn btn-primary"> Submit</button>

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

</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div> 
          
          
         
          @if($total_records>$default_limit)
            <div class="search_load_more text-center">
              <button type="button" class="btn btn-success load-m-profile-btn" id="load_more_profiles">  Load More Profiles</button>
            </div>
          @endif
      </div>
    </div>
    <div id="profile_search_save_modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
        <div class="modal-content">
     
        <div class="modal-body">
            <form class="form-horizontal" method="post" action="" id="saveSearchform" name="saveSearchform" enctype="multipart/form-data" onsubmit="return check_save_search()">
            @foreach($search_data as $key => $value)
              <input type="hidden" name="{{$key}}" value="{{$value}}">
            @endforeach
           <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <div id="save_search_error" class="txt-red"></div>
                       
            <div class="form-group">
                <div class="col-md-6 pull-right">OR</div>
            </div>            
            <div class="form-group">
              <label class="col-sm-4 control-label">New Name</label>
              <div class="col-sm-8">
              <input type="text" class="form-control" id="save_name" name="save_name" placeholder="New Name">
              </div>
            </div>            
            <div class="form-group">
                <div class="col-sm-12">
                    <button type="submit" name="search" value="search_save" class="btn btn-primary pull-right">Save Search</button>
                </div>
            </div>
          </form>          
        </div><!-- End of Modal body -->
        </div><!-- End of Modal content -->
        </div><!-- End of Modal dialog -->
    </div><!-- End of Profile Image Modal -->


  </section> 
@endsection
@section('js')
<script src="{{ asset('js/bootstrapValidator.min.js')}}"></script>
<script src="{{ asset('js/maskedinput/jquery.maskedinput.min.js')}}"></script>
<script src="{{ asset('js/validation.js')}}"></script>
<script src="{{ asset('js/bootbox.js')}}"></script>
<script type="text/javascript">
  /*var search_data = JSON.stringify('<?php echo json_encode($search_data)?>');
  alert(search_data);*/
 $(function(){
  var checked_values = '';  
 
  var k=1;
 if($("#load_more_profiles").length) 
  {
    var total_profiles = {{$total_records}};
    $(document).on('click','#load_more_profiles',function(){
     
      $(this).html('<i class="fa fa-spinner fa-pulse"></i> Loading Profiles');

      next = parseInt($("#offset").val())+{{Config::get('constants.PROFILE_SEARCH_LIMIT')}};

      $.ajax({
       type: "GET",
       data: $("#hiddenSearchForm").serialize(),
       dataType: "json",
       url: "{{url('home_search_ajax')}}",
       success: function(ajax_data){
       

        total_rec = ajax_data.total;
        prof_data = ajax_data.data;
        append_data = '';
        default_image = '{{url('uploads/profile_images/default-profile.png')}}';
        //$.each(ajax_data,function(k,v))
        $.each(prof_data,function(i,v){
          if(prof_data[i].profile_image)
            image_path = "{{url('uploads/profile_images')}}/default-profile.png";
          else
            image_path = "{{url('uploads/profile_images/default-profile.png')}}";
          
          var dd="";var dd1="";
          if(k%2==0) dd='<div class="row search-page-br">';
          if(k%2==0) dd1='</div>';
          append_data = append_data+dd+'<div class="col-md-6"><div class="row"><div class="emty-div-row"><div class="row profile-search-top-actions"><div class="col-xs-4 col-md-4"><input type="checkbox" id="profileList" name="profileList[]" value="'+prof_data[i].id+'"></div><div class="col-md-8 col-xs-8"><a href="{{url("searchprofiles")}}/'+prof_data[i].id+'"><h4>'+prof_data[i].name+'</h4></a></div></div><div class="row profile-search-middle-actions "><div class="col-xs-4 col-md-4 searchpg-profile-pic"><a href="{{url("searchprofiles")}}/'+prof_data[i].id+'"><img class="img-responsive img-circle" src="'+image_path+'" alt=""/></a></div><div class="col-xs-4 col-md-4"><div class="profile-addpic-search"><a href="{{url("searchprofiles")}}/'+prof_data[i].id+'"><img class="img-responsive" src="../images/add_pic.png" alt=""/></a></div></div></div></div></div></div></div></div>'+dd1;
         /* alert(prof_data[i].id);
          alert(prof_data[i].profile_image);
          alert(prof_data[i].name);*/
       k++; });
          $("#search_result_data").append(append_data);
          $("#offset").val(next);
          if(next>total_profiles)
              $("#load_more_profiles").hide();
          else
              $("#load_more_profiles").show();

          $("#load_more_profiles").html('Load More Profiles');
      
     
       }
      });
    });
  }

    
    });
</script>
@endsection
