@php $banner_list = GetBanner($ebook_volume_details[0]->ebook_volume_id,"eBook_volume") @endphp

@extends('layouts.app')
@section('title')
Book - {!!strip_tags($ebook->title)!!}
@parent

@stop

@section('header_styles')
  
<script type="text/javascript" src="https://platform-api.sharethis.com/js/sharethis.js#property=5f2d6cad2e6de20011ec6cd1&product=inline-share-buttons" async="async"></script>

@stop

@section('content')
<!----Banner Section Starts----> 

@if (isset($page) && $page == 'chapter')
<!-- Chapter Section Header-->
	@include('layouts.chapter_header_section')
@endif	

@if (isset($page) && $page == 'ebook_volume')
<!-- Ebook Volume Section Header-->
	@include('layouts.ebook_volume_header_section')
@endif	

<!----Banner Section Ends----> 

<!----Main Section Starts (where all content bodies exist)----> 
<style>
	.agencies {
		width: 100%;
		display: inline-flex;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.agencies a {
		border-bottom: 1px dashed #333;
		padding: 0;
		font-size: 14px;
		text-align: left;
		color: #333;
		margin-bottom: 2px;
		display: inline-flex;
		flex: 32%;
		margin-right: 1%;
		align-items: center;
		padding: 5px 0px !important;
	}

	.agencies a:hover,
	.agencies a:focus {
		background-color: var(--siteblue);
		color: #fff !important;
	}
</style>
<!-- End Page Level CSS -->


	
<main id="ebook_volume_details">
	
	@if(strtolower($ebook_volume_details[0]->select_ebook_type) == 'video')
	<section id="chapter-list">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <nav id="about-toc">
                    <div class="nav nav-tabs" id="nav-tab" role="tablist">
                    	@if(!empty($ebook_volume_details[0]->introduction))
                        <a aria-controls="nav-profile" aria-selected="false" class="nav-item nav-link active" data-toggle="tab" href="#nav-profile" id="nav-profile-tab" role="tab">
                            About Book
                        </a>
                        @endif
                    </div>
                </nav>
                <div aria-labelledby="nav-profile-tab" class="tab-pane fade show bg-white active" id="nav-profile" role="tabpanel">
                    <div class="col-md-12 p-4">
                        <h2 class="h4">
                            Introduction
                        </h2>
                        <hr>
                            <p class="text-justify">
									{!! strip_tags(html_entity_decode($ebook_volume_details[0]->introduction, ENT_NOQUOTES, 'UTF-8')) !!}									
                            </p>
							@if($ebook_volume_indexing_details)
							<h2 class="h4">Indexed In</h2>
                            <hr>
							<div class="agencies">
								@foreach ($ebook_volume_indexing_details as $indexing)
								<a type="button" class="btn btn-link p-0" data-toggle="modal" id="indexingButton" data-target="#indexingModal" data-attr="{{ route('indexing_agencies_bookslist',[$indexing->index_id,$indexing->ebook_volume_id])}}">
									<i class="fas fa-angle-right mr-2"></i>{{$indexing->title}}
								</a>
								@endforeach
							</div>
                            @endif
                            
	                    </div>
	                </div>
	            </div>
	        </div>
	    </div>
	</section>
	
	@elseif($vol_type === 888)
	
	
	
	{{-- If Type 888 Sample User Access Donot Show Chapter List --}}
		@if(!empty($ebook_volume_details[0]->introduction))
			<section id="chapter-list">
				<div class="container">
					<div class="row">
					<div class="col-md-12 p-4">
						<div class="card card-body">						
						
							<h2 class="h4">Introduction</h2>
							<hr>
							<p class="text-justify">

							{!! strip_tags(html_entity_decode($ebook_volume_details[0]->introduction, ENT_NOQUOTES, 'UTF-8')) !!}									
							</p>

							@if($ebook_volume_details[0]->index_on)
							<h2 class="h4">Index In</h2>
							<hr>
							<p>{{  $ebook_volume_details[0]->index_on }}</p>
							@endif
						</div>
					</div>
				</div>
			</div>
			</section>
		@endif
	
	@else
		
	<section id="chapter-list">
    <div class="container">

	
      <div class="row">
        <div class="col-md-8">
          
                <nav id="about-toc">
  <div class="nav nav-tabs" id="nav-tab" role="tablist">
  
    <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Table of Contents</a>
	
    @if(!empty($ebook_volume_details[0]->introduction))
    <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">About Book</a>
    @endif
  </div>
</nav>
<div class="tab-content" id="nav-tabContent">
  <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
    
    <div class="col-md-12 listing">
								@if ($ebook_volume_details[0]->ebook_type != 1)
	      <h2 class="h4">Book Volume {{ $ebook_volume_details[0]->volume_name }}</h2>
          <hr>
								@endif

								@if (count($chapter_details) > 0)
								@foreach($chapter_details as $chapter)
								<div class="card bigbox-hvr-slow">
									<div class="card-body">
										@if($chapter->access_base_text!="")
										<span class="badge badge-pill badge-danger float-right">{{$chapter->access_base_text}}</span>
										@endif
										<h4 class="card-title"><a href="{{ URL::to('chapter/'.$chapter->chapter_id)  }}">{!!$chapter->title!!}</a> </h4>
										<p>Page: {{$chapter->first_page}}-{{$chapter->last_page}} ({{$chapter->page_count}})<br>
											Author: {!!$chapter->authors!!}<br>
											<a href="https://doi.org/{{ $chapter->doi }}" target=
                    						"_blank">DOI: {{$chapter->doi}}</a><br>
											@if(!$chapter->download_access)
											PDF Price: ${{ $ebook_volume_details[0]->chapter_price }}
											@endif
										</p>
										<p><?php echo DisplaySocialNetworkLink($chapter->title, 'http://' . $_SERVER['HTTP_HOST'] . '/chapter/' . $chapter->chapter_id . ''); ?></p>
									</div>
									<div class="card-footer text-muted">

										@if (!empty($chapter->abstract))
										<button href="#" class="card-link text-dark" data-toggle="modal" data-target="#abstract_{{ $chapter->chapter_id }}">View Abstract</button>

										<!--View Abstract -->
										<!---------------------------------------------------------------------->
										<!---------------------------------------------------------------------->
										<div class="modal fade" id="abstract_{{$chapter->chapter_id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
											<div class="modal-dialog modal-lg" role="document">
												<div class="modal-content">
													<div class="modal-header">
														<h5 class="modal-title" id="exampleModalLongTitle"> Abstract</h5>
														<button type="button" class="close" data-dismiss="modal" aria-label="Close">
															<span aria-hidden="true">&times;</span>
														</button>
													</div>
													<div class="modal-body text-justify">

														<p>{!! html_entity_decode($chapter->abstract) !!}</p>

						      </div>
						      <div class="modal-footer">
						        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
						      </div>
						    </div>
						  </div>
						</div>

					<!---------------------------------------------------------------------->
					<!---------------------------------------------------------------------->
					
					@endif
					
					@if(isset($chapter->download_access) && $chapter->download_access > 0)  

		                @php 
		                    $rparam=encrypt(array('readchapterpdf',$chapter->chapter_id,config('constants.admin.token'),$content_download_type));
		                @endphp

						@if($chapter->terms_popup)
		                  @php
		                    $checklicense = 'javascript:return CheckLicense(this.id)';
		                  @endphp
		                @else
		                  @php

							  $checklicense ='';
							  $D_key = false;
								
								if ($chapter->type == 444 || $chapter->type == 555)
								{
									$D_key = true;
									
								}
								
			                  if($chapter->access_base_text==='Token Based Access' && $D_key == true)
							  {
								$checklicense ="javascript:return LoginToDownload('download_hide_".$chapter->chapter_id."')";
			                  }      
					  
		                  @endphp
		              	@endif 
					
						@if($chapter->view_option==0)	

					
			              {{ Form::open(array('method' => 'POST','route' => 'ebook_download_chapter','id' => 'download-form-'.$chapter->chapter_id)) }}
			              <input type="hidden" value="{{csrf_token()}}" name="_token">
			              <input type="hidden" name="agree-flag" id="agree-flag" value="1">
			              <input type="hidden" name="param" value="{{Crypt::encrypt($chapter->chapter_id.'||'.'pdf'.'||'.$chapter->content_download_type.'||'.$chapter->restricted_user_access_key.'||'.$chapter->user_access_id)}}">



					<!-- if User Access Info View Option is zero than allow to download-->

						   <button type="submit" id="{{$chapter->chapter_id}}" name="download{{$chapter->chapter_id}}" class="card-link " onclick="{{$checklicense}}">Download PDF File</button>
		                {{ Form::close() }}

		                  {{ Form::open(array('method' => 'POST','route' => 'ebook_download_chapter','id' => 'download-form-pdf')) }}
						  <input type="hidden" name="agree-flag" id="agree-flag" value="1">
						  <input type="hidden" name="param" value="{{Crypt::encrypt($chapter->chapter_id.'||'.'pdf'.'||'.$chapter->content_download_type.'||'.$chapter->restricted_user_access_key.'||'.$chapter->user_access_id)}}">  
						  <div class="modal fade" id='download_hide_{{$chapter->chapter_id}}' tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
						    <div class="modal-dialog">
						      <div class="modal-content">
						        <div class='modal-header bg-primary'>
						          <h4 class="modal-title text-white" id="modalLabelprimary">Restricted Access Panel</h4>
						          <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
						         
						        </div>
						        <div class='modal-body'>
						          <label class="control-label">Content Access Key</label>
						          <input type="text" name="user_name" class="form-control" >
						          <label class="control-label">Password</label>
						          <input type="password" name="password" class="form-control">
						        </div> <!-- /.modal-body -->   
						        <div class="modal-footer">
						           <button type="submit" class="btn btn-primary" onclick="javascript: $('#download_hide_{{$chapter->chapter_id}}').modal('hide');" ><span class="glyphicon glyphicon-remove-circle"></span> Login to Download</button>
						          <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Close</button>
						        
						        </div> 
						      </div> <!-- /.modal-content -->
						    </div> <!-- /.modal-dialog -->
						  </div>
						{{ Form::close() }}

					@elseif($chapter->view_option==1)	

						   <a type="button" id="readpdf_{{$chapter->chapter_id}}" name="download{{$chapter->chapter_id}}" class="card-link " href="{{route('chapter', ['id' => $chapter->chapter_id,'param' => $rparam])}}" onclick="{{$checklicense}}">Read Chapter</a>

					@else

						@if(empty($bundle_content) || $bundle_content->chapter==0)
							@if($chapter->checkIfMarked)          
					          {{ Form::open([ 'method'  => 'delete', 'route' => [ 'marklist.destroy', $chapter->nid] ]) }}
					            <input type="hidden" name="param" value="{{Crypt::encrypt($chapter->nid)}}">          
					            <button type="submit" id="unmarkitembtn" class="card-link text-dark ">Unwish</button>
					          {{ Form::close() }}
					        @else
					          {{ Form::open(array('method' => 'POST','route' => 'marklist.store')) }}
					            <input type="hidden" name="param" value="{{Crypt::encrypt($chapter->nid)}}">
					            <input type="hidden" name="itemtype" value="2">          
					            <button type="submit" id="markitembtn" class="card-link text-dark ">Add to Wish List</button>
					          {{ Form::close() }}	
					         @endif	
							
							{{ Form::open(array('id'=>"addtocartForm",'method' => 'POST','route' => 'cart.store')) }}					
							<input type="hidden" name="param" value="{{Crypt::encrypt($chapter->nid)}}">  
							<button type="submit" id="{{$chapter->chapter_id}}" name="download{{$chapter->chapter_id}}" class="card-link text-dark ">Purchase PDF</button>	
							{{ Form::close() }}	
					    @else

			              {{ Form::open(array('method' => 'POST','route' => 'chapter_download_bundle_file','id' => 'download-form-'.$chapter->chapter_id)) }}
			              <input type="hidden" value="{{csrf_token()}}" name="_token">
			              <input type="hidden" name="agree-flag" id="agree-flag" value="1">
					      <input type="hidden" name="bundle_offer_order_id" id="bundle_offer_order_id" value="{{$bundle_content->bundle_offer_order_id}}"> 
			              <input type="hidden" name="param" value="{{Crypt::encrypt($chapter->chapter_id.'||'.'pdf'.'||'.$bundle_content->content_download_type.'||'.$chapter->restricted_user_access_key.'||'.$chapter->user_access_id)}}">

						   <button type="submit" id="{{$chapter->chapter_id}}" name="download{{$chapter->chapter_id}}" class="card-link ">Download PDF File</button>
		                {{ Form::close() }}

						@endif	

					@endif
				@endif
				  </div>
			</div>
<!-- --------------Trial Trial Terms Condition------------------------- -->
  @if (isset($chapter->type) && $chapter->type == 111)
			    <a id="license{{$chapter->chapter_id}}" href="{{route('termstrial', ['access_type' => $chapter->type,'content_id' => $chapter->chapter_id,'param' => $rparam])}}"  ></a>
  @else
			    <a id="license{{$chapter->chapter_id}}" href="{{route('terms', ['content_id' => $chapter->chapter_id,'param' => $rparam])}}"  ></a>
  @endif  
			
			@endforeach

		<!-- --------------Trial Trial Terms Condition ebook volume------------------------- -->
		  @if (isset($vol_type) && $vol_type == 111)
		    <a id="license" href="{{route('termstrial', ['access_type' => $vol_type,'content_id' => $ebook_volume_details[0]->ebook_volume_id,'param' => $rparam])}}"  ></a>
		  @else
		    <a id="license" href="{{route('terms', ['access_type' => $vol_type,'content_id' => $ebook_volume_details[0]->ebook_volume_id,'param' => $rparam])}}"  ></a>
		  @endif  

  
  <div style="text-align:left;" class="modal fade" id="TnCModal" tabindex="-1" role="dialog" aria-labelledby="TnCModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
      </div> <!-- /.modal-content -->
    </div> <!-- /.modal-dialog -->
  </div>

			     
			      <input type="hidden" name="license_downloadid" id="license_downloadid" value="0">


		@endif

	@if (count($chapter_details) > 0)
		<span class="col-md-12 d-inline-flex list-pagination">{{ $chapter_details->appends(request()->input())->links() }}</span>
	@endif	
            
        </div>

  </div>
  <div class="tab-pane fade bg-white" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
    <div class="col-md-12 p-4">
    <h2 class="h4">Introduction</h2>
    <hr>
    <p class="text-justify">
									{!! strip_tags(html_entity_decode($ebook_volume_details[0]->introduction, ENT_NOQUOTES, 'UTF-8')) !!}									
    </p>
								@if($ebook_volume_indexing_details)
    <h2 class="h4">Indexed In</h2>
    <hr>
								<div class="agencies">
									@foreach ($ebook_volume_indexing_details as $indexing)
									<a type="button" class="btn btn-link p-0" data-toggle="modal" id="indexingButton" data-target="#indexingModal" data-attr="{{ route('indexing_agencies_bookslist',[$indexing->index_id,$indexing->ebook_volume_id])}}">
										<i class="fas fa-angle-right mr-2"></i>{{$indexing->title}}
									</a>
									@endforeach
								</div>
@endif
</div>

  </div>

						<!-- Indexing book modal -->
						<div class="modal fade" id="indexingModal" tabindex="-1" role="dialog" aria-labelledby="indexingModalLabel" aria-hidden="true">
							<div class="modal-dialog modal-lg" role="document">
								<div class="modal-content">
									<div class="modal-body" id="indexingBody">
										<!-- the result to be displayed here -->
									</div>
								</div>
							</div>
						</div>

  </div>

        </div>


        <div class="col-md-4">
          
      <!----Banner Section Starts----> 
          @include('ebook.ebook_right_banner')
      <!----Banner Section Ends---->
          
          
        
          @include('includes.inc_related_journals')
          @include('includes.inc_related_ebooks')

	      	@if(!empty($ebook_volume_details[0]->trendmd_id))
          <div class="card card-body mt-3">
          	<h5 class="card-title">Recommended Chapters</h5>
          		<div id="trendmd-suggestions" class="col-md-12"></div>
	        		<script defer src='//js.trendmd.com/trendmd.min.js' data-trendmdconfig='{"journal_id":"{{$ebook_volume_details[0]->trendmd_id}}","element":"#trendmd-suggestions"}'></script>
          </div>	
	     		@endif
        </div>
      </div>


        @endif

    </div>

      {{ Form::open(array('method' => 'POST','route' => 'download_volume_file','id' => 'download-form-pdf')) }}
  <input type="hidden" name="agree-flag" id="agree-flag" value="1">
  <input type="hidden" name="param" value="{{Crypt::encrypt($ebook_volume_details[0]->ebook_volume_id.'||'.'pdf'.'||'.$content_download_type.'||'.$restricted_user_access_key)}}">  
  <div class="modal fade" id='downloadv_hide_{{$ebook_volume_details[0]->ebook_volume_id}}' tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class='modal-header bg-primary'>
          <h4 class="modal-title text-white" id="modalLabelprimary">Restricted Access Panel</h4>
          <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
         
        </div>
        <div class='modal-body'>
          <label class="control-label">Content Access Key</label>
          <input type="text" name="user_name" class="form-control" >
          <label class="control-label">Password</label>
          <input type="password" name="password" class="form-control">
        </div> <!-- /.modal-body -->   
        <div class="modal-footer">
           <button type="submit" class="btn btn-primary" ><span class="glyphicon glyphicon-remove-circle"></span> Login to Download</button>
          <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Close</button>
        
        </div> 
      </div> <!-- /.modal-content -->
    </div> <!-- /.modal-dialog -->
  </div>
{{ Form::close() }}
  </section>

</main>



<!----Main Section Starts----> 
@endsection
@section('footer_scripts')

<script>
$(function () {

   $('.alert[data-auto-dismiss]').each(function (index, element) {
        var $element = $(element),
            timeout  = $element.data('auto-dismiss') || 5000;

        setTimeout(function () {
            $element.alert('close');
        }, timeout);
    });
  
});

	function CheckEbookLicense(id) { 
	  $('#license_downloadid').val(id);
	  
	  var file_type = '';
	  
	  id=id;
	  
	  if($("#agree-flag").val() == "" || $("#agree-flag").val() != "Y"){
	    
	    var target = $("#license").attr("href");
	    $("#TnCModal .modal-content").load(target+'/eBook_volume/'+file_type, function() {                      
	      $("#TnCModal").modal("show"); 
	    });                     
	      return false;
	    }
	  
} 


function CheckLicense(id) {

	$('#license_downloadid').val(id);

  var array = id.split('_');
  var file_type = '';
  if(array[0] != "readpdf")
  {
    id=id;
  }
  else
  {
    id=array[1];
    file_type="readpdf";
  }
	if($("#agree-flag").val() == "" || $("#agree-flag").val() != "Y"){
    
	  var target = $("#license"+id).attr("href");
    $("#TnCModal .modal-content").load(target+'/chapter/'+file_type, function() {                      
	    $("#TnCModal").modal("show"); 
	  });                     
	    return false;
  	}
  
}   

function LoginToDownload(id) {  
                            
   $("#"+id).modal("show"); 
   return false;
}            
</script>
<script>
	// display a indexing book modal
	$(document).on('click', '#indexingButton', function(event) {
		event.preventDefault();
		let href = $(this).attr('data-attr');
		$.ajax({
			url: href,
			beforeSend: function() {
				$('#loader').show();
			},
			// return the result
			success: function(result) {
				$('#indexingModal').modal("show");
				$('#indexingBody').html(result).show();
			},
		})
	});
</script>

@endsection