<!DOCTYPE html>
<html lang="en">
<head>
	<!-- Main navbar -->
		<?php
        helper('form');
		$session = session();
		$validation = \Config\Services::validation();
		echo view('admin/common_header'); ?>
	<!-- /main navbar -->
	



	<!-- date picker JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/interactions.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/widgets.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/effects.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/extensions/mousewheel.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/globalize/globalize.js');?>"></script>

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

	<!-- date picker JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/pages/jqueryui_forms.js');?>"></script>

	<!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/uploaders/fileinput.min.js');?>"></script>
	<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>
    <!-- Theme JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/ckeditor/ckeditor.js');?>"></script>
	<!-- select box theme JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/bootstrap_select.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/select2.min.js');?>"></script>

	<script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>

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

</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.news_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($news_data->news_id)) { 
                           echo lang('language_lang.news_edit_data');
                        }
                        else{
                           echo lang('language_lang.news_add_data');

                        }


                        ?>
						</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 news" 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('news_header')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.news_title'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-6">
									<div style="width:100%" class="input-group">
									<textarea name="news_header" class="form-control elastic" cols="4" rows="3" placeholder="<?php echo lang('language_lang.plac_news_title'); ?>"><?php echo set_value('news_header',isset($news_data->news_header) ? ucfirst($news_data->news_header) : ''); ?></textarea>
									</div>
									<?php echo $validation->getError('news_header', '<div class="form-control-feedback"></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>

							<div class="form-group   <?php if($validation->getError('news_content')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.news_content'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-6">
									<div style="width:100%" class="input-group">
							        <textarea class="form-control elastic" name="news_content" rows="8" cols="4" placeholder="<?php echo lang('language_lang.plac_news_content'); ?>"><?php echo set_value('news_content',isset($news_data->news_content) ? ucfirst($news_data->news_content) : ''); ?></textarea>
									</div>
									<?php echo $validation->getError('news_content', '<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('news_image')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"> Upload Image <span class="text-danger">*</span></label>
								
								<div class="col-lg-6">
									<div>
										<input type="file" name="news_image" class="file-input-extensions" value="<?php echo set_value('news_image', isset($news_data->news_image) ? "/..".$news_data->news_image : '' ); ?>">
									</div>
									<span class="help-block"><?php echo lang('language_lang.site_logo_extension');?></span>
									<?php echo $validation->getError('news_image', '<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('news_date')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.news_date'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-4">
									<div class="input-group">
										<span class="input-group-addon"><i class="icon-calendar22"></i></span>
										<input type="text" class="form-control datepicker" placeholder="<?php echo lang('language_lang.plac_news_date'); ?>" name="news_date" value="<?php echo set_value('news_date',isset($news_data->news_date) ? date('Y-m-d', strtotime($news_data->news_date)) : ''); ?>">
									</div>
								</div>
								<?php echo $validation->getError('news_date', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
							</div>
                            <div class="form-group  <?php if($validation->getError('language_id')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lab_language'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-4">
									
										<select class="bootstrap-select form-control" name="language_id">
											<?php 
												if(isset($news_data->language_id)) {
													$selected_lang = $news_data->language_id;
												} else {
													$selected_lang = '';
												}
												foreach ($languages as $row) { 
											?>
												<option <?php if($selected_lang==strtolower($row->language_id)) { echo 'selected';} ?> value='<?php echo strtolower($row->language_id);?>' ><?php echo ucfirst($row->language_name);?></option>	
											<?php	
												}
											?>
										</select>
									
									<?php echo $validation->getError('language_id', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div> 

							

							<?php 
								if(isset($news_data->news_id)) { 
									$news_status = $news_data->news_status;
								} else {
									$news_status = '';
								}
							?>
							<!-- Switch single -->
							<div class="form-group <?php if($validation->getError('news_status')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.faq_status'); ?> </label>
								<div class="col-lg-6">
									<div class="checkbox checkbox-switch">
										<label>
											<input type="checkbox" <?php if($news_status==='1' || $news_status===''){ echo 'checked="checked"'; }   ?> name="news_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('news_status', '<label class="validation-error-label">', '</label>'); ?>
								</div>
							</div>
							<!-- /switch single -->

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

							<div class="text-right col-lg-8">
								<button type="submit" class="btn btn-primary"><?php if(isset($news_data->news_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 } ?>

	            $(".datepicker").datepicker({
	            	format: 'mm-dd-yyyy',
	            	minDate:0
	            }).on('change', function(e) {
	            	$('.news').formValidation('revalidateField','news_date');
	            });

			    $('.news').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        fields: {
			            news_header: {
			                message: '<?php echo lang("language_lang.news_title_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.news_title_required");?>'
			                    }
			                }
			            },
			            news_content: {
			                message: '<?php echo lang("language_lang.news_content_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.news_content_required");?>'
			                    }
			                }
			            },
			            news_date: {
			                message: '<?php echo lang("language_lang.news_date_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.news_date_required");?>'
			                    }
			                }
		                },
						<?php if(isset($news_data->news_id)) { ?>

						news_image: {
							validators: {
							file: {
							extension: 'jpg,jpeg,png,gif',
							type: 'image/jpg,image/jpeg,image/png, image/png',
							message: '<?php echo "File must be the follwing extensions";?>'
							}
							}
						},

						<?php } else { ?>
						news_image: {
							validators: {
							notEmpty: {
							message: '<?php echo "News Image field is required";?>'
							},
							file: {
							extension: 'jpg,jpeg,png,gif',
							type: 'image/jpg,image/jpeg,image/png, image/png',
							message: '<?php echo "File must be the follwing extensions";?>'
							}
							}
						},
						<?php } ?>
			            
			        }
			    })
				

			});


			$(".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($news_data->news_image)) { ?>
		    	initialPreview: ["<?php echo base_url('assets/images/news/'.$news_data->news_image);?>"],
		    	initialPreviewAsData: true, // identify if you are sending preview data only and not the raw markup
		    	initialPreviewFileType: 'image', // image is the default and can be overridden in config below
		    <?php } ?>
		    allowedFileExtensions: ["jpg", "gif", "png", "jpeg"],
		    uploadExtraData: {
		        img_key: "1000"
		    }
		});

		    // $('[name="page_content"]').ckeditor();
		 	$('#icon-bck').on('click',function() {
				window.history.back();
			});
			
		    $(".switchery").bootstrapSwitch();
		    // $("#countries").msDropdown();

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

</body>
</html>
