<!DOCTYPE html>
<html lang="en">
<head>
	<!-- header -->
		<?php
		helper('form');
        $session = session();
		$validation = \Config\Services::validation();

		 echo view('admin/common_header'); ?>
	<!-- /header -->
	
	<!-- 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>
	

	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/select2.min.js');?>"></script>

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

	
	
	<!-- 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>

    <!--<script src="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/js/msdropdown/jquery.dd.min.js"></script>
	<link rel="stylesheet" type="text/css" href="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/css/msdropdown/flags.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/assets/boots/css/select.css" />-->

	<!-- select box JS files 
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/pages/form_bootstrap_select.js"></script>-->
	<!-- /select box JS files -->
	<script src="<?php echo base_url('assets/boots/js/select_min.js');?>"></script>
	<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/boots/css/select2.css');?>"/>
	
</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.lang_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($lang_data->language_id)) { 
								echo lang('language_lang.lang_edit_page_title');
							} else {
								echo lang('language_lang.lang_create_page_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 languagesetting" action="<?= site_url($action);?>" method="post" enctype="multipart/form-data">
							<?php 
								if($validation->listErrors()) { 
									$form_err_data = str_replace('<p>', '', $validation->listErrors());
									$form_err_data = str_replace('</p>', '', $form_err_data);
									$form_err_data = str_replace('.', '', $form_err_data);
							?>
									
									<script type="text/javascript">
									
									(function( $ ) {
										$.jGrowl.defaults.closer = false;
								        var from_daa = '<?php $form_err_data;?>';
										$.jGrowl(from_daa, {
								            header: '<?php echo lang("language_lang.error");?>',
								            theme: 'bg-danger'
								        });
								    
									})(jQuery);


									</script>
							<?php
								}
							?>
							<div class="form-group  <?php if($validation->getError('name')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_lang_name'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-4">
									<div class="input-group">
										<span class="input-group-addon"><i class="icon-graduation"></i></span>
										<input type="text" name="name" id="name" class="form-control" placeholder="<?php echo lang('language_lang.place_lang_name'); ?>" value="<?php echo set_value('name',isset($lang_data->language_name) ? $lang_data->language_name : ''); ?>">
									</div>
									<?php echo $validation->getError('name', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>

							<div class="form-group  <?php if($validation->getError('code')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_lang_code'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-4">
							   <select name="code" id="simg" class="select form-control">
											<?php 
												if(isset($lang_data->language_code)) {
													$selected_lang = $lang_data->language_code;
												} else {
													$selected_lang = '';
												}
												foreach ($countries as $row) { 
											?>
												<option <?php if($selected_lang===$row->iso_2) { echo 'selected';} ?> value='<?php echo strtolower($row->iso_2);?>' data-image="images/msdropdown/icons/blank.gif" data-imagecss="flag <?php echo strtolower($row->iso_2);?>" data-title="<?php echo $row->Country;?>"><?php echo $row->Country;?></option>	
											<?php	
												}
											?>
										</select>
									
									<?php echo $validation->getError('code', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>



							<!-- <div class="form-group   <?php if($validation->getError('code')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_lang_code'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon"><i class="icon-hyperlink"></i></span>
										<input type="text" name="code" class="form-control"  placeholder="<?php echo lang('language_lang.place_lang_code'); ?>" value="<?php echo set_value('code',isset($lang_data->language_code) ? $lang_data->language_code : ''); ?>">
									</div>
									<?php echo $validation->getError('code', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div> -->

							<!-- <div class="form-group  <?php if($validation->getError('flag')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_country_flag'); ?> <span class="text-danger">*</span></label>
								
								<div class="col-lg-6">
									<div>
										<input type="file" name="flag" class="file-input-extensions" value="<?php echo set_value('flag', isset($lang_data->language_flag) ? $lang_data->language_flag : '' ); ?>">
									</div>
									<span class="help-block">Allow only specific file extensions. In this example only <code>jpg</code>, <code>gif</code>, <code>png</code> and <code>jpeg</code> extensions are allowed.</span>
									<?php echo $validation->getError('flag', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div> -->

							<?php 
								if(isset($lang_data->language_id)) { 
									$lang_default = $lang_data->language_default;
								} else {
									$lang_default = '';
								}
							?>
							<!-- Switch single -->
							<div class="form-group <?php if($validation->getError('default')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_lang_default'); ?> </label>
								<div class="col-lg-4">
									<div class="checkbox checkbox-switch">
										<label>
											<input type="checkbox" <?php if($lang_default){ echo 'checked="checked"'; }   ?> name="default" 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('default', '<label class="validation-error-label">', '</label>'); ?>
								</div>
							</div>
							<!-- /switch single -->


							<?php 
								if(isset($lang_data->language_id)) { 
									$lang_status = $lang_data->language_status;
								} else {
									$lang_status = '';
								}
							?>
							<!-- Switch single -->
							<div class="form-group <?php if($validation->getError('status')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_lang_status'); ?> </label>
								<div class="col-lg-6">
									<div class="checkbox checkbox-switch">
										<label>
											<input type="checkbox" <?php if(!isset($lang_data->language_id)) { echo 'checked'; } ?> <?php if($lang_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>
							<!-- /switch single -->

							<?php 
								if(isset($lang_data->language_id)) { 
							?>
							<input type="hidden" name="language_id" value="<?php echo $lang_data->language_id;?>"/>
							<?php } ?>

							<div class="text-right col-lg-7">
								<button type="submit" class="btn btn-primary"><?php if(isset($lang_data->language_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($session->getFlashData('error_message')) { ?>
				$.jGrowl("<?php echo $session->getFlashData('error_message');?>", {
		            header: '<?php echo lang("language_lang.error");?>',
		            theme: 'bg-danger'
		        });
            <?php } ?>
                    
            <?php if($session->getFlashData('success_message')) { ?>
                $.jGrowl("<?php echo $session->getFlashData('success_message');?>", {
		            header: '<?php echo lang("language_lang.success");?>',
		            theme: 'bg-success'
		        });
            <?php } ?>

            if ($("#simg").length > 0) {
		        function formatFlags(state) {
		            if (!state.id) return state.text;
		            return "<img style='padding-right:10px;' src='<?php echo base_url('assets/images/flags/');?>" +'/'+ state.id.toLowerCase() + ".png'/>" + state.text;
		        }
		        $("#simg").select2({
		            formatResult: formatFlags,
		            formatSelection: formatFlags,
		            escapeMarkup: function(m) {
		                return m;
		            }
		        });
		    }

		    $('.languagesetting').formValidation({
		    	framework: 'bootstrap',
		    	excluded: [':disabled'],
		        icon: {
		            valid: 'glyphicon glyphicon-ok',
		            invalid: 'glyphicon glyphicon-remove',
		            validating: 'glyphicon glyphicon-refresh'
		        },
		        fields: {
		            name: {
		                message: '<?php echo lang("language_lang.lang_name_valid");?>',
		                validators: {
		                    notEmpty: {
		                        message: '<?php echo lang("language_lang.lang_name_required");?>'
		                    },
		                    stringLength: {
		                        min: 4,
		                        message: '<?php echo lang("language_lang.lang_name_long");?>'
		                    },
		                    regexp: {
		                        regexp: /^[a-z]+$/i,
		                        message: '<?php echo lang("language_lang.lang_name_must");?>'
		                    }
		                }
		            },
		            code: {
		                message: '<?php echo lang("language_lang.lang_code_valid");?>',
		                validators: {
		                    notEmpty: {
		                        message: '<?php echo lang("language_lang.lang_code_required");?>'
		                    },
		                    stringLength: {
		                        min: 2,
		                        max: 2,
		                        message: '<?php echo lang("language_lang.lang_code_long");?>'
		                    },
		                    regexp: {
		                        regexp: /^[a-z]+$/i,
		                        message: '<?php echo lang("language_lang.lang_code_must");?>'
		                    }
		                }
		            }
		            
		        }
		    })

		});
	    
	 //    $(".file-input-extensions").fileinput({
		//     uploadAsync: false,
		//     minFileCount: 1,
		//     maxFileCount: 1,
		//     overwriteInitial: true,
		//     showUpload: false,
		//     <?php if(isset($lang_data->language_flag)) { ?>
		//     	initialPreview: ["<?php echo base_url();?>uploads/site/<?php echo ($lang_data->language_flag) ? $lang_data->language_flag : 'placeholder.jpg';  ?>"],
		//     	initialPreviewAsData: true, 
		//     	initialPreviewFileType: 'image',
		//     <?php } else {?>
		//     	initialPreview: ["<?php echo base_url().'uploads/site/placeholder.jpg';?>"],
		//     	initialPreviewAsData: true, 
		//     	initialPreviewFileType: 'image',
		    	
		//     <?php } ?>
		//     allowedFileExtensions: ["jpg", "gif", "png", "jpeg"],
		//     uploadExtraData: {
		//         img_key: "1000"
		//     }
		// });
		$('#icon-bck').on('click',function() {
			window.history.back();
		});
		// $("#countries").msDropdown();
	    $(".switchery").bootstrapSwitch();
	   

	});
	})(jQuery);

	
	</script>

</body>
</html>
