@extends('layouts.admin')    
@section('content')
 
                  <div class="card-header">
                    <h4> Institute Faculty Profile</h4>
                  </div>
                  <div class="card-body">
                  @if (Session::has('sucmessage')) 
                        <div class="alert alert-success alert-dismissible show fade">
                          <div class="alert-body">
                            <button class="close" data-dismiss="alert">
                              <span>&times;</span>
                            </button>
                            {{ Session::get('sucmessage') }}
                          </div>
                        </div> 
                        @endif
                        
                        
                        @if (Session::has('message')) 
                          <div class="alert alert-danger alert-dismissible show fade">
                            <div class="alert-body">
                              <button class="close" data-dismiss="alert">
                                <span>&times;</span>
                              </button>
                              {{ Session::get('message') }}
                            </div>
                          </div>
                        @endif

                        <?php // echo  Auth::user()->id ;  echo '<pre>'; print_r($userdetails); echo '</pre>'; exit;
                         $statename  = '';  $cityname  ='' ; 
                          if($userdetails) {
                           $statename  = $userdetails->statename;   $cityname  = $userdetails->cityname; 
                           }
                        ?>
                  <form action="{{ SITEURL }}admin/teacherupdatefaculty" method="post">
                    <div class="form-row"> 
                            <div class="form-group col-md-6">
                                <label for="inputEmail4">Faculty Name</label>
                                <input type="text" class="form-control" id="institutename" name="institutename" value="{{ $userdata->name }}" maxlength="200" placeholder="Institute Name" required>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="inputEmail4">Faculty Name</label>
                                <input type="text" class="form-control" id="institutenamelast" name="institutenamelast" value="{{ $userdata->lastname }}" maxlength="200" placeholder="Institute Name" required>
                            </div>
                            
                            <div class="form-group  col-md-6">
                            <label for="inputAddress2">Email Address </label>
                            <input type="email" class="form-control" id="emailid" name="emailid" disabled  value="{{ $userdata->email }}" placeholder="Email ID" required maxlength="200">
                            </div>
                            <div class="form-group col-md-6">
                                <label for="searchlsit">Faculty Subject</label>
                          
                                <div id="myUL" class="subjectlsishow custdropdwnn">
                               
                                  <?php 
                                    $teacherclasses = DB::table('teacherclasses')->select('subjectid')->distinct()->where('teacherid', $userdata->id)->get();
                                    foreach($teacherclasses as $teacherclassesdata) {
                                      $teacherdetailssection = DB::table('teacherdetails')->where('subjectid', $teacherclassesdata->subjectid)->where('teacherid', $userdata->id)->first();
                                      if(!$teacherdetailssection ){
                                        $subjectdetails = DB::table('subjectdetails')->where('id', $teacherclassesdata->subjectid)->first();
                                        $insertdatausers = array(                             
                                              'teacherid'=>$userdata->id,
                                              'subjectid'=>$subjectdetails->id,  
                                              'subjectname'=>$subjectdetails->subjectname,                                               
                                              'createdtime'=>date("Y-m-d H:i:s"), 
                                              );
                                  
                                      DB::table('teacherdetails')->insert($insertdatausers); 
                                      }
                                    }

                                  foreach($subjectdetails as $subject) { 
                                      $teacherdetails = DB::table('teacherdetails')->where('subjectid', $subject->id)->where('teacherid', $userdata->id)->first();
                                      if($teacherdetails ){
                                    ?>
                                      <p> <span> <input type="checkbox" disabled name="subjectlist[]" <?php if( $teacherdetails) { echo 'checked'; }?> id="subjectlist{{ $subject->id }}" class="checboxsubject" value="{{ $subject->id }}<=>{{ $subject->subjectname }}"> {{ $subject->subjectname }}  </span> </p>
                                   <?php } }  ?> 
                                   <div class="clearsection"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-6">
                                <label for="searchlsit">Faculty Class</label>
                               
                                <div id="myUL" class="subjectlsishow custdropdwnn">
                                
                                  <?php    
                                            $teacherclasses = DB::table('teacherclasses')->select('classid')->distinct()->where('teacherid',Auth::user()->id )->get();
                                            $classsidarray = array();
                                            foreach($teacherclasses as $teacherclas) { $classsidarray[] = $teacherclas->classid; }
                                  ///  echo '<pre>'; print_r($teacherclasses); echo '</pre>';
                                  $institutegroups = DB::table('institutegroups')->whereIn('id',$classsidarray )->where('createdby',Auth::user()->createdby )->get();
                                    foreach($institutegroups  as $instituteg ) {
                                       ?>
                                      <p> <span> <input type="checkbox" disabled name="classid[]" <?php if(in_array($instituteg->id,$classsidarray)) { echo 'checked'; }?>  id="subjectlist{{ $instituteg->id }}" class="checboxsubject" value="{{ $instituteg->id }}<=>{{ $instituteg->groupname }}"> {{ $instituteg->groupname }}-{{ $instituteg->grouposection }}  </span> </p>
                                   <?php   } ?> 
                                </div>
                            </div>


                        </div>
                        
                    <div class="form-group">
                        <label for="inputPassword4">Mobile Number</label>
                        <input type="text" class="form-control"  onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" id="mobilenumber" name="mobilenumber" placeholder="Mobile Numbere" disabled value="{{ $userdata->mobileno }}" required maxlength="10" minlength="10">
                    </div>

                    <div class="form-group">
                      <label for="inputAddress2">Address </label>
                      <input type="text" class="form-control" id="addressname" value="{{ $userdata->address }}" name="addressname" placeholder="Apartment, studio, or floor" required maxlength="500">
                    </div>
                        <div class="form-group ">
                            <label for="inputPassword4">State</label>
                            <input type="text" class="form-control" id="statename" value="{{ $statename }}" name="statename" placeholder="State Name" required maxlength="200">
                        </div> 
                        <div class="form-group">
                            <label for="inputAddress">City</label>
                            <input type="text" class="form-control" id="cityname"  value="{{ $cityname }}" name="cityname" placeholder="City Name" required maxlength="200">
                        </div> 
                                       
					     <div class="form-group">
                              <label  for="userinput5">Upload Profile Picture</label> 
                              	 <div id="targetLayer" style="width:300px; height:200px;"> 
                                    <?php $urldata = SITEURL.'public/newlogo.jpg';
                                     if($userdata->profileimh > 0) { 
                                        $attachements = DB::table('attachements')->where('id', $userdata->profileimh)->first();
                                        if($attachements) { $urldata = SITEURL.'files/'.$attachements->att_url; }
                                     }
                                    ?>
                                        <img src="{{ $urldata }}" style="max-width:200px; max-height:200px;" alt="" />  
                                        <input type="hidden" name="photoid" id="photoid" value="{{ $userdata->profileimh }}">
                                    </div>
                                  <div class="loading" style="display:none; text-align:center;">
                                        	<img src="{{ SITEURL }}public/admin/loadspinner.gif" style="width:80px;" alt="Loading.." />
                                        </div>
                                <a id="newuploadphoto" href="#" class="btn btn-primary margin-botom-btm">New Upload</a>
                                
                           </div> 
                        </div>
                      
                        <div class="card-footer">
                            <input type="hidden" name="editid" id="editid" value="{{ $userdata->id }}">
                            <button type="submit" class="btn btn-primary">Update</button>
                        </div>
                        {!! csrf_field() !!}
                    </form>
                  </div>
                 
                  </div> 
                  <div style="display:none;">
                  			 <form id="uploadForm" action="#" method="post"> 
                                 <div id="uploadFormLayer">
                                    <input name="userImage"  id="newuploaed" type="file" class="inputFile" /><br/>
                                       <input type="submit" id="sunmitrphot" value="Submit" class="btnSubmit" />
                                      <input type="hidden" name="userid" value="{{ Auth::user()->id  }}" />
                                    <input type="hidden" name="action" value="cat_img" />
                                   </div>
                              </form>
                          </div>   
<script type="text/javascript">
$(document).ready(function (e) {
	$( "#newuploadphoto" ).click(function() { 
	  $('#newuploaed').trigger('click');
	  return false;
	});
	
	$( "#newuploaed" ).change(function() { 
	  $('#sunmitrphot').trigger('click');
	  return false;
	}); 
	
	
	$("#uploadForm").on('submit',(function(e) {
		e.preventDefault();
		$('.loading').fadeIn();
        var data = new FormData(this); 
       //  console.log(data);
		$.ajax({
        	url: "{{ route('admin.upload.attachment') }}",
			type: "POST",
			data:  new FormData(this),
			contentType: false,
    	    cache: false,
			processData:false,
			success: function(data)
		    {
             // console.log(data);
			$('.loading').fadeOut();
			$("#targetLayer").html(data);
			
		    },
		  	error: function() 
	    	{
	    	} 	        
	   });
	}));
});
</script>     
@endsection
