<!DOCTYPE html>
<html lang="en">
<head>
	<!-- Main navbar -->
		<?php
		$session = session();
		$this->common_model = model('CommonModel');
		$validation = \Config\Services::validation();
		helper('form');

		 echo view('admin/common_header'); ?>
	<!-- /main navbar -->
	
	<!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/uploaders/fileinput.min.js');?>"></script>
	
	<!-- Bootsrap swith and validation css files -->	
	<link href="<?php echo base_url('assets/boots/css/bootstrap-switch.css');?>" rel="stylesheet" type="text/css">
	<link href="<?php echo base_url('assets/boots/css/formValidation.min.css');?>" rel="stylesheet" type="text/css">
	
	<!-- Bootsrap form validation JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/formValidation.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.js');?>"></script>
	

	<!-- Theme JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>
	<!-- /theme JS files -->


	<!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/boots/js/fileinput.min.js');?>"></script>
	
	<!-- bootsrap switch checkbox JS files -->
    <script src="<?php echo base_url('assets/boots/js/bootstrap-switch.js');?>"></script>

    <!-- notify JS files -->
    <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>

	
<style>    
    div.checker {
    	top: 18px !important;
    }
    .kv-file-content img.file-preview-image {
    	width: 150px !important;
    }

</style>
</head>

<body class="navbar-top-md-md">
	<!-- <div class="pre_loader"></div> -->
	<!-- Fixed navbars wrapper -->
	<div class="navbar-fixed-top">

		<!-- Main navbar -->
		<?php echo view('admin/mainnav'); ?>
		<!-- /main navbar -->


		<!-- Second navbar -->
		<?php echo view('admin/secondnav'); ?>
		<!-- /second navbar -->

	</div>
	<!-- /fixed navbars wrapper -->


	<!-- Page header -->
	<div class="page-header">
		<div class="page-header-content">
			<div class="page-title">
				<h4><i id="icon-bck" class="icon-arrow-left52 position-left"></i> <span class="text-semibold"><?php echo lang('language_lang.slider_page_title'); ?></span></h4>

				<ul class="breadcrumb breadcrumb-caret position-right">
					<?php foreach ($breadcrumbs as $breadcrumb) { if(isset($breadcrumb['href'])){?>
					    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
					<?php } else { ?> <li><?php echo $breadcrumb['text']; ?></li><?php } } ?>
				</ul>
			</div>
			<?php echo view('admin/'.$module_name.'_header'); ?>
			
		</div>
	</div>
	<!-- /page header -->


	<!-- Page container -->
	<div class="page-container">

		<!-- Page content -->
		<div class="page-content">

			<!-- Main content -->
			<div class="content-wrapper">

				<!-- Horizontal form -->
				<div class="panel panel-flat">
					<div class="panel-heading">
						<h5 class="panel-title">
						<?php 




						if(isset($slider_data->slider_id)) { 
                           echo lang('language_lang.slider_edit_title');
                        }
                        else{
                           echo lang('language_lang.slider_add_title');

                        }



                        ?>
						</h5>
						<div class="heading-elements">
							<ul class="icons-list">
		                		<li><a data-action="collapse"></a></li>
		                		<li><a data-action="close"></a></li>
		                	</ul>
	                	</div>
                	</div>
                	
					<div class="panel-body">
						<form class="form-horizontal slider" action="<?=site_url($action);?>" method="post" enctype="multipart/form-data">
							<?php 
								if($validation->listErrors()) { 
									$form_err_data = str_ireplace('<p>', '', $validation->listErrors());
									$form_err_data = str_ireplace('</p>', '', $form_err_data);
									$form_err_data = str_ireplace('.', '', $form_err_data);
								}
							?>

							<div class="form-group  <?php if($validation->getError('image')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_slider_image'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-6">
									<div>
										<input type="file" name="image" class="file-input-extensions" value="<?php echo set_value('image', isset($slider_data->image) ? $slider_data->image : '' ); ?>">
									</div>
									<span class="help-block"><?php echo lang('language_lang.slider_image_extension');?></span>
									<?php echo $validation->getError('image', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>
							<?php

							foreach ($languages as $row)
							{
								$condition = "slider_id = '".$slider_data->slider_id."' and language_id = '".$row->language_id."'";
								$slid = 	$this->common_model->GetRow('slider_controls', $condition);								
								?>							

							<div class="form-group  <?php if($validation->getError('title')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo  ucfirst($row->language_name).' '.lang('language_lang.lbl_slider_title'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-6">
									<div class="">
										<input type="text" name="title_<?php echo $row->language_id;?>" id="title" class="form-control" placeholder="<?php echo lang('language_lang.place_slider_title'); ?>" value="<?php echo set_value('title',isset($slider_data->title) ? $slider_data->title : ''); ?>">
									</div>
									<?php echo $validation->getError('title', '<div class="form-control-feedback"></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>
                            
							<div class="form-group <?php if($validation->getError('description')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo $row->language_name.' '.lang('language_lang.lbl_slider_description'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-6">
									<div style="width:100%" class="input-group">
							       		<textarea class="form-control elastic" name="description_<?php echo $row->language_id; ?>" rows="5" cols="4" placeholder="<?php echo lang('language_lang.place_slider_content'); ?>"><?php echo set_value('description',isset($slider_data->description) ? $slider_data->description : ''); ?></textarea>
									</div>
									<?php echo $validation->getError('description', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>
							<?php 
						}
								if(isset($slider_data->slider_id)) { 
									$slider_status = $slider_data->status;
								} else {
									$slider_status = '';
								}
							?>
							<!-- Switch single -->
							<div class="form-group <?php if($validation->getError('status')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_slider_status'); ?> </label>
								<div class="col-lg-6">
									<div class="checkbox checkbox-switch">
										<label>
											<input type="checkbox" <?php if($slider_status==='1' || $slider_status===''){ echo 'checked="checked"'; }   ?> name="status" data-on-color="success" data-off-color="danger" data-on-text="<?php echo lang('language_lang.On');?>" data-off-text="<?php echo lang('language_lang.Off');?>" class="switchery">
										</label>
									</div>
									<?php echo $validation->getError('status', '<label class="validation-error-label">', '</label>'); ?>
								</div>
							</div>
							
							<?php 
								if(isset($slider_data->slider_id)) { 
							?>
							<input type="hidden" name="slider_id" value="<?php echo $slider_data->slider_id;?>"/>
							<?php } ?>

							<div class="text-right col-lg-8">
								<button type="submit" class="btn btn-primary"><?php if(isset($slider_data->slider_id)) {  echo lang('language_lang.button_update'); } else { echo lang('language_lang.button_save'); } ?> <i class="icon-arrow-right14 position-right"></i></button>
							</div>
						</form>
					</div>
				</div>
				<!-- /horizotal form -->

			</div>
			<!-- /main content -->

		</div>
		<!-- /page content -->
		

		<!-- Footer -->
		<div class="footer text-muted">
			<?php echo site_footer();?>
		</div>
		<!-- /footer -->

	</div>
	<!-- /page container -->

	<script type="text/javascript">
		jQuery.noConflict();
		(function( $ ) {
		$(function() {

			$(document).ready(function() {

				$.jGrowl.defaults.closer = false;

				<?php if(isset($form_err_data)) { ?>
					$.jGrowl('<?php echo trim($form_err_data);?>', {
			            header: '<?php echo lang("language_lang.error");?>',
			            theme: 'bg-danger'
			        });
				<?php } ?>


				<?php if($session->getFlashData('error_slider')) { ?>
					$.jGrowl("<?php echo $session->getFlashData('error_slider');?>", {
			            header: '<?php echo lang("language_lang.error");?>',
			            theme: 'bg-danger'
			        });
	            <?php } ?>
	                    
	            <?php if($session->getFlashData('success_slider')) { ?>
	                $.jGrowl("<?php echo $session->getFlashData('success_slider');?>", {
			            header: '<?php echo lang("language_lang.success");?>',
			            theme: 'bg-success'
			        });
	            <?php } ?>

			    $('.slider').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        fields: {
			        	title: {
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.slider_title_required");?>'
			                    },
			                    stringLength: {
			                        min: 10,
			                        message: '<?php echo lang("language_lang.slider_title_min");?>'
			                    },
			                    regexp: {
			                        regexp: /^[a-z\d\-\s]+$/i,
			                        message: '<?php echo lang("language_lang.slider_title_must");?>'
			                    }
			                }
			            },
			            <?php  if(isset($slider_data->slider_id)) { ?>
			            image: {
				            validators: {
				                file: {
				                    extension: 'jpg,jpeg,png,gif',
				                    type: 'image/gif,image/jpg,image/jpeg,image/png, image/png',
				                    message: '<?php echo lang("language_lang.slider_image_must");?>'
				                }
				            }
				        },
				        <?php } else { ?>

				        	image: {
				            validators: {
				            	notEmpty: {
			                        message: '<?php echo lang("language_lang.slider_image_required");?>'
			                    },
				                file: {
				                    extension: 'jpg,jpeg,png,gif',
				                    type: 'image/gif,image/jpg,image/jpeg,image/png, image/png',
				                    message: '<?php echo lang("language_lang.slider_image_must");?>'
				                }
				            }
				        },
				        <?php } ?>
			            description: {
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.slider_description_required");?>'
			                    },
			                    stringLength: {
			                        min: 20,
			                        message: '<?php echo lang("language_lang.slider_description_min");?>'
			                    },
			                }
			            }
			            
			        }
			    })
				

			});

			$(".file-input-extensions").fileinput({
			    uploadUrl: "http://localhost/file-upload-single/1", // server upload action
			    uploadAsync: false,
			    minFileCount: 1,
			    maxFileCount: 1,
			    overwriteInitial: true,
			    showUpload: false,
			    <?php if(isset($slider_data->image)) { ?>
			    	initialPreview: ["<?php echo base_url('content/slider/'.$slider_data->image)?>"],
			    	initialPreviewAsData: true, 
			    	initialPreviewFileType: 'image',
			    <?php } ?>
			    allowedFileExtensions: ["jpg", "gif", "png", "jpeg"],
			    uploadExtraData: {
			        img_key: "1000"
			    }
			});
		    
		 	$('#icon-bck').on('click',function() {
				window.history.back();
			});
			
		    $(".switchery").bootstrapSwitch();
		    // $("#countries").msDropdown();

		});
		})(jQuery);
	
	</script>

</body>
</html>
