@extends('admin/layouts/default')

{{-- Page title --}}
@section('title')
Add Issue
@parent
@stop

{{-- page level styles --}}
@section('header_styles')
	@include('admin.layouts.css')
@stop

{{-- Page content --}}
@section('content')


<script type="text/javascript" src="{!! asset('js/jquery.min.js') !!}"></script>
<link href="{{ asset('assets/vendors/select2/css/select2.min.css') }}" type="text/css" rel="stylesheet">
<link href="{{ asset('assets/vendors/select2/css/select2-bootstrap.css') }}" rel="stylesheet">

<link href="{{ asset('assets/vendors/daterangepicker/css/daterangepicker.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('assets/vendors/datetimepicker/css/bootstrap-datetimepicker.min.css') }}" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="{{ asset('assets/vendors/bootstrap-tagsinput/css/bootstrap-tagsinput.css') }}" />
<link rel="stylesheet" href="{{ asset('assets/vendors/bootstrap-tagsinput/css/app.css') }}" />
<script>
$(function () {
		
		$("#journal_id").change(function(){
		
			var journal_id = $('#journal_id').val();

			  $.ajax({
					type: "GET",
					url: '',
					data: {journal_id: journal_id,ajx_search:true},
					success: function( msg ) 
					{
						var data = msg['volume_search'];
						$('#volume_id').empty();						
							$("#volume_id").append('<option value="">Select Volume</option>');
						$.each(data, function(key,value) 
						{							
							$("#volume_id").append('<option value="'+value['volume_id']+'" >'+value['volume_name']+'</option>');
						});					
					}
				});						
		});

		 /* $("form").each(function()
		{
		
			$(this).find(':input');
				
			var fields = $( ":input" ).serializeArray();
			
			for ( var i = 0, l = fields.length; i < l; i++ ) 
			{
				var input = $('input[name="' + fields[i]['name'] + '"]').val();
				
				if (input == '')
				{
					$('input[name="' + fields[i]['name'] + '"]').val(Math.random().toString(36).substring(7));
					
				}
				
				var input = $('textarea[name="' + fields[i]['name'] + '"]').val();
				
				if (input == '')
				{					
					$('textarea[name="' + fields[i]['name'] + '"]').val(Math.random().toString(36).substring(7));
				}
			}
			
		}); */

	
});
  
</script>
            <section class="content-header">
                <!--section starts-->
                <h1>
                    Add Issue
                </h1>
                <ol class="breadcrumb">
                    <li>
                        <a href="{{ route('admin.dashboard') }}">
                            <i class="livicon" data-loop="true" data-name="home" data-size="14">
                            </i>
                            Dashboard
                        </a>
                    </li>
                    <li class="active">
                        Add Issue
                    </li>
                </ol>
            </section>
            <!--section ends-->
            <section class="content paddingleft_right15">
                <!--main content-->
                <div class="row">
                    <div class="panel panel-primary ">
                        <div class="panel-heading">
                            <h3 class="panel-title">
                                <i class="livicon" data-c="#fff" data-hc="white" data-loop="true" data-name="gear" data-size="16">
                                </i>
                                Add Volume Issue
                            </h3>
                            <span class="pull-right clickable">
                                <i class="glyphicon glyphicon-chevron-up">
                                </i>
                            </span>
                        </div>
						
                        <div class="panel-body">
				
                            <div class="row acc-wizard">
							@isset($issue)
								<form method="POST" action="{{ url('admin/issue/' . $issue->issue_id) }}">								@method('PUT')
							@else
								<form method="POST" action="/admin/issue">
							@endisset 							@csrf
							
                                <div class="col-md-3 pd-2">
                                    <p class="mar-2">
                                        Follow the steps below to add new Issue.
                                    </p>
                                    <ol class="acc-wizard-sidebar">
                                        <li class="acc-wizard-todo">
                                            <a href="#Issue">
                                                Issue
                                            </a>
                                        </li>
                                        <li class="acc-wizard-todo">
                                            <a href="#meta">
                                                Meta Tags
                                            </a>
                                        </li>
                                    </ol>
                                </div>
                                <div class="col-md-9 pd-r">
                                    <div class="panel-group" id="accordion-demo">
										
                                        <!-- /.panel.panel-default -->
                                        <div class="panel panel-default">
                                            <div class="panel-heading">
                                                <h4 class="panel-title">
                                                    <a data-parent="#accordion-demo" data-toggle="collapse" href="#Issue">
                                                       Issue
                                                    </a>
                                                </h4>
                                            </div>
                                            <div class="panel-collapse collapse" id="Issue">
                                                <div class="panel-body">
                                                       
                                                        <div class="my-3" id="e-book">
														
                                                            <div class="form-group @if ($errors->has('journal_id')) has-error @endif ">
                                                                <label class="control-label" for="select21">Journal: *</label>
																<select class="form-control select2" id="journal_id" name="journal_id">
                                                                <option selected="true" disabled="disabled" hidden >Select Journal</option>
                                                                    @foreach($journal as $key => $value)
																		<option value="{{$key}}" 
																		@isset($issue) @if($issue->journal_id == $key) selected @endif @endisset
																		@if(old('journal_id') == $key ) selected @endif
																		>{{$value}}</option>
                                                                    @endforeach
                                                                </select>
                                                            </div>
															
			
															
															<div class="form-group @if ($errors->has('volume_id')) has-error @endif ">
                                                                <label class="control-label" for="select21">
                                                                   Volume: *
                                                                </label>
																
																
															
																
                                                                <select class="form-control"  name="volume_id" id="volume_id">
																<option selected="true" disabled="disabled" hidden>Select Volume</option>
																	@if (session('volume_search'))
																		@foreach(session('volume_search') as $volume)
																			<option value="{{$volume->volume_id}}" 
																			@if(old('volume_id') == $volume->volume_id ) selected @endif
																			>{{$volume->volume_name}}</option>
																		@endforeach
																	@elseif($volume_search)
																		@foreach($volume_search as $volume)
																			<option value="{{$volume->volume_id}}"
																			@if($issue->volume_id == $volume->volume_id ) selected @endif
																			>{{$volume->volume_name}}</option>
																		@endforeach
																	@endif
                                                               </select>
																
                                                            </div>
		
															<div class="form-group">
                                                                <label class="control-label" >Issue Type: *</label>																
                                                                <select name="type" class="form-control select2" >
                                                                   <option title="Normal" value="0"  
																	@isset($issue) @if($issue->type == 0) selected @endif @endisset 
																	
																		@if(old('type') == 0 ) selected @endif 
																	
																   >Normal</option>
																	<option title="Thematic" value="1" 
																	@isset($issue) @if($issue->type == 1) selected @endif @endisset 
																	
																		@if(old('type') == 1 ) selected @endif 
																	
																	>Thematic</option>
																	<option title="In Process" value="2" 
																	@isset($issue) @if($issue->type == 2) selected @endif @endisset 
																	
																		@if(old('type') == 2 ) selected @endif 
																	
																	>In Process</option>
                                                                </select>
                                                            </div>
															
															
															 <div class="form-group">
															 <label class="control-label" for="select21">Title Thematic Issue:</label>
                                                            <input type="text" name="issue_title"  class="form-control input-md" placeholder="Sub Title"
															
											value=" {{ old("issue_title", isset($issue->issue_title) ? $issue->issue_title : '') }} ">
															</div>
															
														<div class="form-group">
                                                            <label  class="control-label">About Thematic Issue:</label>
															{{ $about_issue = old("about_issue", isset($issue->about_issue) ? $issue->about_issue : '') }}
                                                            <textarea class="form-control resize_vertical" name="about_issue" 
															placeholder="Please enter text here..." rows="5">{{$about_issue}}</textarea>
															
															
                                                        </div>
															
															 <div class="form-group @if ($errors->has('month_id')) has-error @endif ">
                                                                <label class="control-label">Month:</label>
																
                                                                    <select class="form-control select2"  name="month_id">																		
																	
																		<option selected="true" disabled="disabled" hidden>Select Month</option>
																		<option value='1' 
																		@isset($issue) @if($issue->month_id == 1) selected @endif @endisset 
																		@if( old('month_id') == 1 ) selected @endif
																		>January</option>
																		<option value='2' 
																		@isset($issue) @if($issue->month_id == 2) selected @endif @endisset 
																		@if( old('month_id') == 2 ) selected @endif
																		>February</option>
																		<option value='3' 
																		@isset($issue) @if($issue->month_id == 3) selected @endif @endisset 
																		@if( old('month_id') == 3 ) selected @endif
																		>March</option>
																		<option value='4' 
																		@isset($issue) @if($issue->month_id == 4) selected @endif @endisset 
																		@if( old('month_id') == 4 ) selected @endif
																		>April</option>
																		<option value='5' 
																		@isset($issue) @if($issue->month_id == 5) selected @endif @endisset 
																		@if( old('month_id') == 5 ) selected @endif
																		>May</option>
																		<option value='6' 
																		@isset($issue) @if($issue->month_id == 6) selected @endif @endisset
																		@if( old('month_id') == 6 ) selected @endif
																		>June</option>
																		<option value='7' 
																		@isset($issue) @if($issue->month_id == 7) selected @endif @endisset 
																		@if( old('month_id') == 7 ) selected @endif
																		>July</option>
																		<option value='8' 
																		@isset($issue) @if($issue->month_id == 8) selected @endif @endisset 
																		@if( old('month_id') == 8 ) selected @endif
																		>August</option>
																		<option value='9' 
																		@isset($issue) @if($issue->month_id == 9) selected @endif @endisset 
																		@if( old('month_id') == 9 ) selected @endif
																		>September</option>
																		<option value='10' 
																		@isset($issue) @if($issue->month_id == 10) selected @endif @endisset 
																		@if( old('month_id') == 10 ) selected @endif
																		>October</option>
																		<option value='11' 
																		@isset($issue) @if($issue->month_id == 11) selected @endif @endisset 
																		@if( old('month_id') == 11 ) selected @endif
																		>November</option>
																		<option value='12' 
																		@isset($issue) @if($issue->month_id == 12) selected @endif @endisset 
																		@if( old('month_id') == 12 ) selected @endif
																		>December</option>
                                                                    </select>
                                                                
																<label for="e1" class="control-label"> @if ($errors->has('month_id')) {{ $errors->first('month_id') }} @endif </label>
																
                                                            </div>
															
															<div class="form-group @if ($errors->has('title')) has-error @endif @isset($issue_exist) has-error @endisset">
																<label  class="control-label">Title / Issue No.: *</label>
																
																<input  name="title" type="text" class="form-control " id="title" 
																value=" {{ old('title', isset($issue->title) ? $issue->title : '') }} ">
																<label for="e1" class="control-label">
																@if ($errors->has('title')) {{ $errors->first('title') }} @endif																
																
																</label>
															</div>
															
															<div class="form-group @if ($errors->has('publication_date')) has-error @endif ">
																<label>Issue Publication Date : *</label>
																<div class="input-group">
																	<div class="input-group-addon">
																		<i class="livicon" data-name="laptop" data-size="16" data-c="#555555"
																		   data-hc="#555555" data-loop="true"></i>
																	</div>
																	<input  name="publication_date" type="text" class="form-control " id="publication_date"  
																	
																	value="@if(isset($issue->publication_date) && $issue->publication_date <> 0)
																	{{date('Y-m-d',$issue->publication_date)}}
																	@else
																	{{date('Y-m-d')}}
																	@endif" />
																</div>
																<!-- /.input group -->
															</div>
															
															
															<div class="form-group @if ($errors->has('price')) has-error @endif ">
																<label class="control-label" for="price">Issue Price:</label>
	                                                            <input type="text" name="price"  class="form-control input-md" placeholder="Issue Price" 
																
																value=" {{ old("price", isset($issue->price) ? $issue->price : '') }} "
																
																>
															</div>
															
															<div class="form-group @if ($errors->has('is_uploaded')) has-error @endif ">
                                                                <label class="control-label" >Issue Uploaded: *</label>
                                                                <select class="form-control select2" name="is_uploaded">		
																	<option title="NO" value="0" 
																	@isset($issue) @if($issue->is_uploaded) == 0) selected @endif @endisset 
																	
																	@if(old('is_uploaded') == 0 ) selected @endif 
																	
																	>NO</option>
																	<option title="YES" value="1" 
																	@isset($issue) @if($issue->is_uploaded) == 1) selected @endif @endisset 
																	
																	@if(old('is_uploaded') == 1 ) selected @endif 
																	
																	>YES</option>
                                                                </select>
                                                            </div>
															
                                              
                                                </div>
                                                <!--/.panel-body -->
                                            </div>
                                        </div>
                                            <!-- /#adjusthtml -->
                                        </div>
                                        <!-- /.panel.panel-default -->
                                        @include('admin.meta_tag.meta_tag')
                                        <!-- /.panel.panel-default -->
                                    </div>
                                    <br><br>
									
									@isset($issue)
									
										<input type="submit" class="btn btn-primary" value="Update" name="submit">
									@else
										<input type="submit" class="btn btn-primary" value="Save" name="submit">
									@endisset 
									
									</form>
                                </div>
                                
								
                            </div>
                        </div>
                    </div>
                </div>
                <!--main content ends-->
            </section>
            <!-- content -->
            @stop

{{-- page level scripts --}}
@section('footer_scripts')
@include('admin.layouts.js')
<script src="{{ asset('assets/vendors/select2/js/select2.js') }}" type="text/javascript"></script>    		
<script>
$(function () {

	$("#journal_id").select2({
		theme:"bootstrap",
		placeholder:"",
		width: '100%'
	});
	
	
	$("#publication_date").daterangepicker({
		 locale: {
            format: 'YYYY-MM-DD'
        },
        singleDatePicker: true,
        showDropdowns: true,
		
    });
    
});
</script>

<script src="{{ asset('assets/vendors/daterangepicker/js/daterangepicker.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/vendors/datetimepicker/js/bootstrap-datetimepicker.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/js/pages/datepicker.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/vendors/bootstrap-tagsinput/js/bootstrap-tagsinput.js') }}"  type="text/javascript"></script>


@stop