

		 {!! Form::open(array('url'=>'couponstemp/savepublic', 'class'=>'form-horizontal','files' => true , 'parsley-validate'=>'','novalidate'=>' ')) !!}

	@if(Session::has('messagetext'))
	  
		   {!! Session::get('messagetext') !!}
	   
	@endif
	<ul class="parsley-error-list">
		@foreach($errors->all() as $error)
			<li>{{ $error }}</li>
		@endforeach
	</ul>		


<div class="sbox1"><div class="col-md-12">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> Coupons Temp</legend>
				<?php if( !isset($row['id']))  $row['id'] = null;   ?>
		<input  type='hidden' name='id' id='id' value='{{$row['id']}}' />
									
									  <div class="form-group depen- wrap-title  " >
										<label for="Title" class=" control-label col-md-3 text-left"> Title <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['title']))  $row['title'] = null;   ?>
		 <?php $val = json_decode($row['title']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#title_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='title_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="title[{{$ilang}}]" id='title' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						required  placeholder='Title - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-store_id  " >
										<label for="Store Id" class=" control-label col-md-3 text-left"> Store Id <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['store_id']))  $row['store_id'] = null;   ?>
		 
					<?php $row['store_id'] = trim($row['store_id'],'[]'); ?>

					 <select name='store_id' rows='5' id='store_id' class='select2 '  data-placeholder='Select Store Id'   placeholder='Select Store Id' required     ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-description  " >
										<label for="Description" class=" control-label col-md-3 text-left"> Description </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['description']))  $row['description'] = null;   ?>
		 <?php $val = json_decode($row['description']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#description_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='description_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="description[{{$ilang}}]" id='description' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						  placeholder='Description - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-promo_text  " >
										<label for="Promo Text" class=" control-label col-md-3 text-left"> Promo Text </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['promo_text']))  $row['promo_text'] = null;   ?>
		 <?php $val = json_decode($row['promo_text']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#promo_text_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='promo_text_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="promo_text[{{$ilang}}]" id='promo_text' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						  placeholder='Promo Text - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-type  " >
										<label for="Type" class=" control-label col-md-3 text-left"> Type <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( strlen($row['type']) < 1 )  $row['type']  = 'offer'; 	  ?>
		<?php $type = (isset($row['type'])) ? $row['type'] : null ; ?>
					
					<input type='radio' name='type' value ='offer' required    @if( $type == 'offer') checked="checked" @endif class='minimal-red' > Offer 
					
					<input type='radio' name='type' value ='coupon' required    @if( $type == 'coupon') checked="checked" @endif class='minimal-red' > Coupon  
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-code  " >
										<label for="Code" class=" control-label col-md-3 text-left"> Code </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['code']))  $row['code'] = null;   ?>
		<input  type='text' name='code' id='code' value='{{ $row['code'] }}' 
						   data-parsley-maxlength="50"    class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-link  " >
										<label for="Link" class=" control-label col-md-3 text-left"> Link <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['link']))  $row['link'] = null;   ?>
		<input  type='text' name='link' id='link' value='{{ $row['link'] }}' 
						required   data-parsley-maxlength="500"    class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-brands  " >
										<label for="Brands" class=" control-label col-md-3 text-left"> Brands </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['brands']))  $row['brands'] = null;   ?>
		 
					<?php $row['brands'] = trim($row['brands'],'[]'); ?>

					 <select name='brands[]' multiple rows='5' id='brands' class='select2 '  data-placeholder='Select Brands'   placeholder='Select Brands'      ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-tags  " >
										<label for="Tags" class=" control-label col-md-3 text-left"> Tags </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['tags']))  $row['tags'] = null;   ?>
		 
					<?php $row['tags'] = trim($row['tags'],'[]'); ?>

					 <select name='tags[]' multiple rows='5' id='tags' class='select2 '  data-placeholder='Select Tags'   placeholder='Select Tags'      ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-cats  " >
										<label for="Cats" class=" control-label col-md-3 text-left"> Cats </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['cats']))  $row['cats'] = null;   ?>
		 
					<?php $row['cats'] = trim($row['cats'],'[]'); ?>

					 <select name='cats[]' multiple rows='5' id='cats' class='select2 '  data-placeholder='Select Cats'   placeholder='Select Cats'      ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-is_featured  " >
										<label for="Is Featured" class=" control-label col-md-3 text-left"> Is Featured <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( strlen($row['is_featured']) < 1 )  $row['is_featured']  = '0'; 	  ?>
		<div class='switch-wrap'> <label class='switch'>
				    <input type='hidden' name='is_featured' value ='0' />
					<input type='checkbox' name='is_featured' value ='1' 
					@if($row['is_featured']) checked @endif 
					 />   <span class="slider round"></span></label></div> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-created_mode  " >
										<label for="Created Mode" class=" control-label col-md-3 text-left"> Created Mode </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['created_mode']))  $row['created_mode'] = null;   ?>
		<input  type='text' name='created_mode' id='created_mode' value='{{ $row['created_mode'] }}' 
						   data-parsley-maxlength="50"    class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-network_id  " >
										<label for="Network Id" class=" control-label col-md-3 text-left"> Network Id </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['network_id']))  $row['network_id'] = null;   ?>
		<input  type='number' name='network_id' id='network_id' value='{{ $row['network_id'] }}' 
						   data-parsley-maxlength="11"    class='form-control is_number'  /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-network_coupon_id  " >
										<label for="Network Coupon Id" class=" control-label col-md-3 text-left"> Network Coupon Id </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['network_coupon_id']))  $row['network_coupon_id'] = null;   ?>
		<input  type='text' name='network_coupon_id' id='network_coupon_id' value='{{ $row['network_coupon_id'] }}' 
						   data-parsley-maxlength="20"    class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-expiry_date  " >
										<label for="Expiry Date" class=" control-label col-md-3 text-left"> Expiry Date </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['expiry_date']))  $row['expiry_date'] = null;   ?>
		<input  type='text' name='expiry_date' id='expiry_date' value='{{ $row['expiry_date'] }}' 
						       class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-status  " >
										<label for="Status" class=" control-label col-md-3 text-left"> Status <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( strlen($row['status']) < 1 )  $row['status']  = 'draft'; 	  ?>
		<?php $status = (isset($row['status'])) ? $row['status'] : null ; ?>
					
					<input type='radio' name='status' value ='publish' required    @if( $status == 'publish') checked="checked" @endif class='minimal-red' > Publish 
					
					<input type='radio' name='status' value ='draft' required    @if( $status == 'draft') checked="checked" @endif class='minimal-red' > Draft 
					
					<input type='radio' name='status' value ='trash' required    @if( $status == 'trash') checked="checked" @endif class='minimal-red' > Trash  
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-clicks  " >
										<label for="Clicks" class=" control-label col-md-3 text-left"> Clicks <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( strlen($row['clicks']) < 1 )  $row['clicks']  = '0'; 	  ?>
		<input  type='number' name='clicks' id='clicks' value='{{ $row['clicks'] }}' 
						required   data-parsley-maxlength="11"    class='form-control is_number'  /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div></fieldset>
			</div>
			
			
		</div>
		
		

			<div style="clear:both"></div>	
				
					
				  <div class="form-group">
					<label class="col-sm-4 text-right">&nbsp;</label>
					<div class="col-sm-8">	
					<button type="submit" name="apply" class="btn btn-info btn-sm" ><i class="fa  fa-check-circle"></i> {{ Lang::get('core.sb_apply') }}</button>
					<button type="submit" name="submit" class="btn btn-primary btn-sm" ><i class="fa  fa-save "></i> {{ Lang::get('core.sb_save') }}</button>
				  </div>	  
			
		</div> 
		 <input type="hidden" name="action_task" value="public" />
		 {!! Form::close() !!}
		 
   <script type="text/javascript">
	$(document).ready(function() { 
		
		
		$("#store_id").select2({
			ajax: {
				url: "{{url('/manage/couponstemp/ajaxselect?filter=stores:id:name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.id,
								text: selctToJson(item,'name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

		@if( strlen($row["store_id"]) > 0  )
		// Fetch the preselected item, and add to the control
			var store_idSelect = $('#store_id');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/couponstemp/ajaxselect?filter=stores:id:name&values='.urlencode($row["store_id"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'name'), item.id, true, true);
											store_idSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				store_idSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			store_idSelect.select2_sortable();
			@endif

		
		$("#brands").select2({
			ajax: {
				url: "{{url('/manage/couponstemp/ajaxselect?filter=brands:id:name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.id,
								text: selctToJson(item,'name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 1,
			width:'100%'
		});
		

		@if( strlen($row["brands"]) > 0  )
		// Fetch the preselected item, and add to the control
			var brandsSelect = $('#brands');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/couponstemp/ajaxselect?filter=brands:id:name&values='.urlencode($row["brands"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'name'), item.id, true, true);
											brandsSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				brandsSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			brandsSelect.select2_sortable();
			@endif

		
		$("#tags").select2({
			ajax: {
				url: "{{url('/manage/couponstemp/ajaxselect?filter=tags:id:name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.id,
								text: selctToJson(item,'name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 1,
			width:'100%'
		});
		

		@if( strlen($row["tags"]) > 0  )
		// Fetch the preselected item, and add to the control
			var tagsSelect = $('#tags');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/couponstemp/ajaxselect?filter=tags:id:name&values='.urlencode($row["tags"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'name'), item.id, true, true);
											tagsSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				tagsSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			tagsSelect.select2_sortable();
			@endif

		
		$("#cats").select2({
			ajax: {
				url: "{{url('/manage/couponstemp/ajaxselect?filter=categories_coupon:id:name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.id,
								text: selctToJson(item,'name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 1,
			width:'100%'
		});
		

		@if( strlen($row["cats"]) > 0  )
		// Fetch the preselected item, and add to the control
			var catsSelect = $('#cats');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/couponstemp/ajaxselect?filter=categories_coupon:id:name&values='.urlencode($row["cats"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'name'), item.id, true, true);
											catsSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				catsSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			catsSelect.select2_sortable();
			@endif

		 

		$('.removeCurrentFiles').on('click',function(){
			var removeUrl = $(this).attr('href');
			$.get(removeUrl,function(response){});
			$(this).parent('div').empty();	
			return false;
		});		
		
	});
	</script>		 
