@extends('layouts.app')
@section('title')
Book - {{$ebook->title}}
@parent
@stop
@section('content')
<!----Banner Section Starts----> 
@php $banner_list = GetBanner($ebook_volume_details[0]->ebook_volume_id,"eBook_volume"); @endphp
@section('metatags')
@php
$image_file_name=$ebook_volume_details[0]->image_file_name;
if(empty($image_file_name)) $image_file_name= 'no_image.jpg';
if(!(file_exists('images/bentham/'.$image_file_name))){
			$image_file_name = 'no_image.jpg';
}
	$image_url= 'http://'.$_SERVER['HTTP_HOST'].'/images/bentham/'.$image_file_name;
	$url='http://'.$_SERVER['HTTP_HOST'].'/ebook_volume/'.$ebook_volume_details[0]->ebook_volume_id;
	$ebook_title = $ebook->title;
	$subtitle = $ebook->subtitle;
	$isbn = $ebook_volume_details[0]->isbn;
	if($CountMultipleVolumeExist > 0){
		$volumeLabel = 'Volume: '.$ebook_volume_details[0]->volume_name;
	}
	else{
		$volumeLabel = '';
	}

	$checkLoginFlag=false;
@endphp
<meta property="og:type"   content="website" />
<meta property="og:title" content="{{strip_tags($ebook_title)}}" />
<meta property="og:url" content="{{$url}}"/>
<meta property="og:image" content="{{$image_url}}" />
<meta property="og:description" content="{{$subtitle}}" />
<meta property="og:site_name" content="http://{{$_SERVER['HTTP_HOST']}}" />
@endsection


<section id="ebook-banner" class="ebook_volume">

      <div class="container" >
        <div class="row">
          <div class="col-md-2">
          	<div class="position-relative">
          		@if($ebook_volume_details[0]->image_file_name != '')
				  <img
				  src="{{'/images/bentham/'.$ebook_volume_details[0]->image_file_name}}"
				  width="160" height="211"
				  class="img-fluid" alt="">
				@else
					<img src="https://via.placeholder.com/200x200" alt="profile pic" width="160" height="211">
				@endif

			</div>

			@if($ebook_volume_details[0]->flyer_link != "")
			<a class="btn btn-outline-light btn-sm mt-3 btn-block" href="/images/ebook-flyer/{{$ebook_volume_details[0]->flyer_link}}" name="language_btn">Download PDF Flyer</a>

			@endif
			@if(\Route::current()->getName() != 'pre_order_form' && \Route::current()->getName() != 'preview_pre_order')
			@endif
		  </div>
          <div class="col-md-5">

            <h1 class="h4">{!! $ebook->title !!}</h1>
			<h5 class="h5">{!! $ebook_volume_details[0]->ebook_subtitle !!}</h5>
			<h3 class="h5">{{$volumeLabel}}</h3>
			<!-- ebook volume authors -->
			@if (isset($ebook_volume_details) && $ebook_volume_details[0]->ebook_volume_id)

				@php ($author_name = null) @endphp
				@php ($co_author_name = null) @endphp
				@php ($editor_name = null) @endphp
				@php ($co_editor_name = null) @endphp
				@php ($guest_name = null) @endphp

				@foreach ($authors as $author)
					@if($author->iseditorcoeditor == 'a')
						@php $author_name .= ucfirst($author->first_name).' '.ucfirst($author->initials).' '.ucfirst($author->last_name).', '; @endphp
					@elseif($author->iseditorcoeditor == 'ca')
						@php $co_author_name .= ucfirst($author->first_name).' '.ucfirst($author->initials).' '.ucfirst($author->last_name).', '; @endphp
					@elseif($author->iseditorcoeditor == 'e')
						@php $editor_name .= ucfirst($author->first_name).' '.ucfirst($author->initials).' '.ucfirst($author->last_name).', '; @endphp
					@elseif($author->iseditorcoeditor == 'ce')
						@php $co_editor_name .= ucfirst($author->first_name).' '.ucfirst($author->initials).' '.ucfirst($author->last_name).', '; @endphp
					@elseif($author->iseditorcoeditor == 'ge')
						@php $guest_name .= ucfirst($author->first_name).' '.ucfirst($author->initials).' '.ucfirst($author->last_name).', '; @endphp
					@endif
				@endforeach
				<h6>
				@if($author_name) Authors(s) : {!! rtrim($author_name,', ') !!}<br> @endif
				@if($co_author_name) Co-Author(s) : {!! rtrim($co_author_name,', ') !!}<br> @endif
				@if($editor_name) Editor(s) : {!! rtrim($editor_name,', ') !!}<br> @endif
				@if($co_editor_name) Co-Editor(s) : {!! rtrim($co_editor_name,', ') !!}<br> @endif
				@if($guest_name) Guest-Editor(s) : {!! rtrim($guest_name,', ') !!}<br> @endif
				</h6>


			<p>
				@if($ebook_volume_details[0]->doi != "")
				DOI: <a href="https://doi.org/{{ $ebook_volume_details[0]->doi }}" target=
                    "_blank" class="text-white">{{ $ebook_volume_details[0]->doi }}</a>
				@endif

				@if($ebook_volume_details[0]->eisbn != "")
				<br />eISBN: {{ $ebook_volume_details[0]->eisbn }},
				@endif

				{{ $ebook_volume_details[0]->year }}

				@if($ebook_volume_details[0]->isbn != "")
				<br />ISBN: {{ $ebook_volume_details[0]->isbn }}
				@endif

				@if($ebook_volume_details[0]->issn != "")
				<br />ISSN: {{ $ebook_volume_details[0]->issn }} <strong>(Print)</strong>
				@endif

				@if($ebook_volume_details[0]->eissn != "")
				<br />ISSN: {{ $ebook_volume_details[0]->eissn }} <strong>(Online)</strong>
				@endif


			</p>



			@endif
        </div>

				</div>
			</div>
    </section>

<!-- Restricted Access Panel Window Start-->





    			        <!-- Cite Window Start-->
		        <div class="modal fade" id="CiteWindow" role="dialog">
		        <div class="modal-dialog">
		          <div class="modal-content">
		            <div class="modal-header">
		              <h4 class="modal-title">About this Book</h4>
		              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		            </div>
		            <div class="modal-body ">
		              <p><strong>Cite this Book as:</strong></p>
		              <p>
		              	<b><u>For Books</u></b><br>


						@if($author_name){!! rtrim($author_name,', ') !!} @endif
						@if($editor_name){!! rtrim($editor_name,', ') !!} @endif
						, " {!! $ebook->title !!}  {!! $ebook->subtitle !!} ", Bentham Science Publishers ({{ $ebook_volume_details[0]->year }}). <a href="http://dx.doi.org/{{$ebook_volume_details[0]->doi}}" class="btn-link">https://doi.org/{{$ebook_volume_details[0]->doi}}</a> </p>
		              <table class="table">
		                <tr>
			                <td>
			                	<b>DOI</b><br><a href="http://dx.doi.org/{{$ebook_volume_details[0]->doi}}" class="btn-link">https://doi.org/{{$ebook_volume_details[0]->doi}}</a><br />
			                	<b>Publisher Name</b><br />
			                	Bentham Science Publisher
			                </td>

			                <td>
			                	@if($ebook_volume_details[0]->isbn != "")
			                		<p><b>Print ISBN</b><br>{{$ebook_volume_details[0]->isbn}}</p>
			                	@endif
			                	@if($ebook_volume_details[0]->eisbn != "")
			                		<p><b>Online ISBN</b><br>{{$ebook_volume_details[0]->eisbn}} </p>
								@endif
			                </td>
		                </tr>
		              </table>
		            </div>
		            <div class="modal-footer">
		              <button type="button" class="btn btn-outline-dark" data-dismiss="modal">Close</button>
		              <a class="btn btn-outline-primary" href="{{route('ebook_volume', ['id' => $ebook_volume_details[0]->ebook_volume_id])}}" target="_blank">About this Book </a>
		            </div>
		          </div>
		        </div>
		        </div>
<!----Banner Section Starts----> 

<!----Main Section Starts (where all content bodies exist)----> 
<main>
  
  <section>
    <div class="container">
      <div class="row">
        <div class="col-md-12 listing" id="printtopscroll">
		
          <h2 class="h4">Pre-Order Purchase Form</h2>
		  	<hr>
          	 <div class="card bigbox-hvr-slow">
				  <div class="card-body px-5 mt-3">
				  
				  
				   @if ($errors->any())
					
						<div class="form-row">
						<div class="form-group col-md-12 p-0 m-0">				
				   
							<div class="alert alert-danger m-0">	
							  <strong>Whoops!</strong> There were some problems with your input.
							  <ul>
									@foreach ($errors->all() as $error)
										<li>{{ $error }}</li>
									@endforeach
								</ul>
							</div>
							
						</div>
						</div>	
					
					@endif
				  
	  
         @if (isset($message))
            @if($message[0] == true)
            <div class="alert alert-success mb-2">
              <strong>Success!</strong> {{$message[1]}}
            </div>      
            @else
            <div class="alert alert-danger mb-2">
              <strong>Failed!</strong> {{$message[1]}}
            </div>   
            @endif
         @endif   
  
   
   @if (isset($preview))
	
	<form method="POST" action="{{ url('submit_pre_order_payment/'.$ebook_volume_details[0]->ebook_volume_id) }}">
		@csrf
   
<table border="1" cellpading="10" cellspacing="10" width="100%" class="table">

<tbody>
	<tr><td width="300" class="oddrowcolor border-none"><b>First Name:</b></td><td class="oddrowcolor border-none">{{$preview['first_name']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Last Name:</b></td><td class="oddrowcolor border-none">{{$preview['last_name']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Email:</b></td><td class="oddrowcolor border-none">{{$preview['email']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Title:</b></td><td class="oddrowcolor border-none">{{$preview['title']}}</td></tr>

	@if(!empty($preview['user_category']))
	<tr><td width="300" class="oddrowcolor border-none"><b>User Category:</b></td><td class="oddrowcolor border-none">{{$preview['user_category']}}</td></tr>
	@endif
	<tr><td width="300" class="oddrowcolor border-none"><b>Order Type:</b></td><td class="oddrowcolor border-none">{{$preview['order_type']}}</td></tr>
	
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Country:</b></td><td class="oddrowcolor border-none">{{$preview['country']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>City:</b></td><td class="oddrowcolor border-none">{{$preview['city']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>State/Province:</b></td><td class="oddrowcolor border-none">{{$preview['state']}}</td></tr>
	
	@if(!empty($preview['phone']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Phone:</b></td><td class="oddrowcolor border-none">{{$preview['phone']}}</td></tr>
	@endif

	@if(!empty($preview['fax']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Fax: </b></td><td class="oddrowcolor border-none">{{$preview['fax']}}</td></tr>
	@endif
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Zip/Postal Code:</b></td><td class="oddrowcolor border-none">{{$preview['zip']}}</td></tr>

	@if(!empty($preview['org_name']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Organization Name:</b></td><td class="oddrowcolor border-none">{{$preview['org_name']}}</td></tr>
	@endif
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Location/Address:</b></td><td class="oddrowcolor border-none">{{$preview['address']}}</td></tr>
	
	@if($preview['order_type'] != "Electronic Version")
		<tr><td width="300" class="oddrowcolor border-none"><b>No. of Print Copies:</b></td><td class="oddrowcolor border-none">@if($preview['no_of_copies'] == 0) More than 5 @else {{$preview['no_of_copies']}} @endif</td></tr>
	@endif	

	@if(!empty($preview['comments']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Comments: </b></td><td class="oddrowcolor border-none">{{$preview['comments']}}</td></tr>
	@endif

	@if(!empty($preview['no_of_copies']) && isset($preview['shipment_price']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Price: </b></td><td class="oddrowcolor border-none">${{$preview['price']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>No. of Copies: </b></td><td class="oddrowcolor border-none">{{$preview['no_of_copies']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Shipment Charges: </b></td><td class="oddrowcolor border-none">${{$preview['shipment_price']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Total Price: </b></td><td class="oddrowcolor border-none">${{$preview['total_amount']}}</td></tr>

	@else
	<tr><td width="300" class="oddrowcolor border-none"><b>Price: </b></td><td class="oddrowcolor border-none">${{$preview['total_amount']}}</td></tr>
	@endif

	
</tbody>

</table>			

<br>


<input type="hidden" name="first_name" value="{{$preview['first_name']}}" />
<input type="hidden" name="last_name" value="{{$preview['last_name']}}" />
<input type="hidden" name="email" value="{{$preview['email']}}" />

<input type="hidden" name="title" value="{{$preview['title']}}" />
<input type="hidden" name="user_category" value="{{$preview['user_category']}}" />
<input type="hidden" name="order_type" value="{{$preview['order_type']}}" />

<input type="hidden" name="country" value="{{$preview['country']}}" />
<input type="hidden" name="city" value="{{$preview['city']}}" />
<input type="hidden" name="state" value="{{$preview['state']}}" />

<input type="hidden" name="phone" value="{{$preview['phone']}}" />
<input type="hidden" name="fax" value="{{$preview['fax']}}" />
<input type="hidden" name="zip" value="{{$preview['zip']}}" />

<input type="hidden" name="org_name" value="{{$preview['org_name']}}" />
<input type="hidden" name="address" value="{{$preview['address']}}" />
<input type="hidden" name="comments" value="{{$preview['comments']}}" />
<input type="hidden" name="no_of_copies" value="{{$preview['no_of_copies']}}" />
<input type="hidden" name="price" value="{{$preview['price']}}" />
<input type="hidden" name="total_amount" value="{{$preview['total_amount']}}" />


<button type="submit" class="btn btn-primary">Submit</button>

							</form>		
   @else
	   
   
   <form method="POST" action="{{ url('preview_pre_order_payment/'.$ebook_volume_details[0]->ebook_volume_id) }}">
								@csrf


	<div class="form-row">
		<div class="form-group col-md-4">
			<label class="control-label">First Name: *</label>
			<input type="text" maxlength="50" name="first_name" size="60" value="{{ old('first_name') }}" class="form-control" required = 'required'>
		</div>
		<div class="form-group col-md-4" >
			<label class="control-label">Last Name: *</label>
			<input type="text" maxlength="50" name="last_name" size="60" value="{{ old('last_name') }}" class="form-control" required = 'required'>
		</div>
		<div class="form-group col-md-4" >
			<label class="control-label">Email: *</label>
			<input type="email" maxlength="50" name="email" size="60" value="{{ old('email') }}" class="form-control" required = 'required'>
		</div>
	</div>
   
   
	<div class="form-row">
		<div class="form-group col-md-4">
			<label class="control-label">Title: *</label>
			<select name="title" class="form-select form-control" required = 'required'>
				<option title="Select Title" value="">Select Category</option>
				<option value="Mr." {{ (Request::old("title") == "Mr." ? "selected":"") }}>Mr.</option>
				<option value="Mrs." {{ (Request::old("title") == "Mrs." ? "selected":"") }}>Mrs.</option>
				<option value="Ms." {{ (Request::old("title") == "Ms." ? "selected":"") }}>Ms.</option>
				<option value="Prof."  {{ (Request::old("title") == "Prof." ? "selected":"") }}>Prof.</option>
				<option value="Dr."  {{ (Request::old("title") == "Dr." ? "selected":"") }}>Dr.</option>
			</select>	
		</div>
		
		<div class="form-group col-md-4">
		
			<label class="control-label">User Category:</label>
			<select name="user_category" class="form-select form-control">
				<option title="Select Category" value="">Select Category</option>
				<option title="Professor" value="Professor" {{ (Request::old("user_category") == "Professor" ? "selected":"") }}>Professor</option>
				<option title="Student" value="Student" {{ (Request::old("user_category") == "Student" ? "selected":"") }}>Student</option>
				<option title="Researcher" value="Researcher" {{ (Request::old("user_category") == "Researcher" ? "selected":"") }}>Researcher</option>
				<option title="Medical Professional/Practitiionar" value="Medical Professional/Practitiionar" {{ (Request::old("user_category") == "Medical Professional/Practitiionar" ? "selected":"") }}>Medical Professional/Practitiionar</option>
			</select>
			
			
		</div>
		
		<div class="form-group col-md-4">
		
			<label class="control-label">Order Type: *</label>
			<select name="order_type" id="order_type" class="form-select required form-control" required = 'required' onchange="reprintNum()">
				<option title="Select Order Type" value="">Select Order Type</option>
				<option title="Print Version" value="Print Version" {{ (Request::old("order_type") == "Print Version" ? "selected":"") }}>Print Version</option>
				<option title="Electronic Version" value="Electronic Version" {{ (Request::old("order_type") == "Electronic Version" ? "selected":"") }}>Electronic Version</option>
			</select>
		</div>
	 
	</div>
		
	<div class="form-row">
		<div class="form-group col-md-4">
			<label class="control-label">Country: *</label>
			<select class="form-control" id="country" name="country"  required = 'required'>
				<option value="">Country</option>
				@foreach ($country as $countries)
				<option value="{{$countries->printable_name}}" {{ old("country") == $countries->printable_name ? "selected" : "" }}> {{$countries->printable_name}}</option>
				@endforeach
			</select>
		</div>
		<div class="form-group col-md-4" >         
			<label for="edit-city">City: *</label>
			<input type="text" maxlength="50" name="city" id="edit-city" size="60" value="{{ old('city') }}" class="form-control" required = 'required'>
		</div>
		
		<div class="form-group col-md-4" >         
			<label for="edit-city">State/Province:</label>
			<input type="text" maxlength="50" name="state" id="edit-state" size="60" value="{{ old('state') }}" class="form-control">
		</div>
		
	</div>

	<div class="form-row">
		<div class="form-group col-md-4">
			<label for="edit-phone">Phone:</label>
			<input type="text" maxlength="50" name="phone" id="edit-phone" size="60" value="{{ old('phone') }}" class="form-control">
		</div>
		<div class="form-group col-md-4">
			<label for="edit-phone">Fax:</label>
			<input type="text" maxlength="50" name="fax" id="edit-fax" size="60" value="{{ old('fax') }}" class="form-control">
		</div>
	<div class="form-group col-md-4" >
			<label for="edit-zip">Zip/Postal Code: </label>
			<input type="text" maxlength="50" name="zip" id="edit-zip" size="60" value="{{ old('zip') }}" class="form-control">
		</div>
	</div>

	<div class="form-row">
		<div class="form-group col-md-4" id="org_name-wrapper">         
			<label for="org_name">Name of Institution/Organization:</label>
			<input type="text" maxlength="200" name="org_name" id="org_name" size="60" value="{{ old('org_name') }}" class="form-control">
		</div>
			<div class="form-group col-md-4" id="org_location-wrapper">
			<label for="org_location">Location/Address:  *</label>
			<input type="text" maxlength="200" name="address" id="org_location" size="60" value="{{ old('address') }}" class="form-control" required="required">
		</div>
		<div class="form-group col-md-4" id="reprintNum"  @if (old('order_type') != "Print Version") style="display:none;" @endif>
			<label for="edit-math_question">No. of Print Copies: *</label>
			 <input type="number" name="no_of_copies" class="form-control" id="no_of_copies" value="{{ old('no_of_copies') }}" min="1" step="1">
		</div>
		
	</div>

		<!-- 
		<form method="POST" action="{{ url('validate_promo_code/'.$ebook_volume_details[0]->ebook_volume_id) }}">
					@csrf
		-->
    <div class="form-row">
		<div class="form-group col-md-12" id="edit-comments-wrapper">
			<label for="edit-comments">Comment: </label>
			<div class="resizable-textarea">
			<span>
			<textarea cols="60" rows="3" name="comments" id="edit-comments" onkeypress="javascript:return LimitVerifyOrderForm();" class="form-control">{{ old('comments') }}</textarea>
			<div  style="margin-right: 351px;"></div>
			</span>
			</div>
		</div>
	</div>

	<div class="form-group text-center">                
                
          <div class="form-group row mt-3 w-100"> 
                
                  <div class="col-auto mx-auto w-100 d-flex ">
                      <div class="col-md-6 text-right">
                          <div class="captcha">                                       
                              <span>{!! captcha_img() !!}</span>             
                          </div>
                      </div>
                      <div class="col-md-6">                                        
                          <button type="button" class="btn btn-danger" class="refresh-captcha" id="refresh-captcha">
                              &#x21bb;
                          </button> 
                      </div>
                  </div>
                  <div class="form-group my-2 mx-auto">
                      <input id="captcha" type="text" class="form-control" placeholder="Enter Captcha" name="captcha">
                      @if ($errors->has('captcha'))

                        <span class="invalid-feedback" style="display: block;">

                            <strong>{{ $errors->first('captcha') }}</strong>

                        </span>

                    @endif
                  </div>
          </div>
                
          </div>
	<div class="form-group text-center border-top pt-3">
	    <input class="btn btn-dark col-md-2" type="submit" name="Preview" value="Preview" />
	  </div>    

   <!-- 
		</form>		
		-->
		
		</form>
   
   @endif
   
</div>

	  </div>
	  
	</div>
				
        </div>
    
      </div>
    </div>
  </section>
  
<script>
 	
$(document).ready(function()
{
	$("html, body").animate({scrollTop: $("#printtopscroll").offset().top}, 200);
});	

$( "#promo_code" ).keyup(function(e) 
{
	setTimeout( function(){response = validate_promo_code();}, 2000);
});

function validate_promo_code()
{
	var promo_code = $( "#promo_code" ).val();
	var response = 0;
	
	$.ajax({
        type: "POST",
		data: 
		{
			"_token": "{{ csrf_token() }}",
			"promo_code": promo_code,
			ajax: true
		},
        success: function (data)
		{
			console.log(data[0]);
			
			$( "#promo_code_message" ).html(data[1]);
			
			if (data[0])
			{
				$( "#validate_promocode" ).removeClass('alert alert-danger');
				$( "#validate_promocode" ).removeClass('alert alert-warning');
				$( "#validate_promocode" ).addClass('alert alert-success');
				
			}
			else
			{
				$( "#validate_promocode" ).removeClass('alert alert-success');
				$( "#validate_promocode" ).removeClass('alert alert-warning');
				$( "#validate_promocode" ).addClass('alert alert-danger');
			}
			
        },
		error: function () 
		{
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-warning');
			$( "#validate_promocode" ).addClass('alert alert-danger');
			
		},
		beforeSend: function () 
		{
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-danger');
			$( "#validate_promocode" ).addClass('alert alert-warning');
		}
    });    
}


	function reprintNum()
	{
		var reprint_copies = $('#order_type').val();
		
		
		if(reprint_copies == 'Print Version')
		{
			$('#reprintNum').show();
			$('#no_of_copies').attr('required', 'required');
			$('#no_of_copies').val('');
		}
		else
		{
			$('#reprintNum').hide();
			$('#no_of_copies').removeAttr('required');
			$('#no_of_copies').val('');
		}
	}

	
</script>

  
</main>
@endsection
<script src="https://www.recaptcha.net/recaptcha/api.js" async defer></script>