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

		 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>
	

	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/styling/uniform.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/pnotify.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/bootstrap_multiselect.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>
    <!-- Theme JS files -->
	
	
    <!-- Theme JS files -->
	
	
	<script type="text/javascript" src="<?php echo base_url('assets/js/pages/form_multiselect.js');?>"></script>
	<!-- /theme JS files -->

	
<style>    
    div.checker {
    	top: 18px !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.message_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($message_data->message_id)) { 
                           echo lang('language_lang.message_edit_title');
                        }
                        else{
                           echo lang('language_lang.message_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 message" 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);
								}
							?>
							
                            <div class="form-group  <?php if($validation->getError('start_date')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.message_startdate'); ?> <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_message_date'); ?>" name="start_date" value="<?php echo set_value('start_date',isset($message_data->start_date) ? date('m-d-Y', strtotime($message_data->start_date)) : ''); ?>">
									</div>
								</div>
								<?php echo $validation->getError('start_date', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
							</div>
                            <div class="form-group  has-feedback <?php if($validation->getError('expire_days')) echo "has-error";?>">
							    <label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.message_expiredays'); ?>  <span class="text-danger">*</span></label>
						        <div class="col-lg-4">
							        <div style="width:100%;" class="input-group">
								        <input type="text" name="expire_days" class="form-control"  placeholder="<?php echo lang('language_lang.plac_message_expire'); ?>" value="<?php echo set_value('expire_days',isset($message_data->expire_days) ? ucfirst($message_data->expire_days) : ''); ?>">
								        <span class="input-group-addon"><?php echo lang('language_lang.day');?></span>
							        </div>
							        <?php echo $validation->getError('expire_days', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
						        </div>
						    </div>
                              
						    <!-- Select All option selected -->
								<div class="form-group has-feedback <?php if($validation->getError('user_id[]')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.message_users');?></label>
									<div class="col-lg-4">
									<div class="multi-select-full">
										<select name="user_id[]" class="form-control multiselect-select-all" multiple="multiple">

										<?php 
                                         if (isset($message_data->user)) {
                                           $display = json_decode($message_data->user);						     
                           
										      foreach ($user_list as $list_data) {
											      ?><option <?php if(in_array($list_data->uusersid, $display)) { echo 'selected="selected"'; } ?> value="<?php echo $list_data->uusersid; ?>"><?php echo $list_data->username;?></option>
									    <?php } } else {?>
									
	                                        <?php foreach ($user_list as $list_data) {
												?><option value="<?php echo $list_data->uusersid; ?>"><?php echo $list_data->username;?></option>
										<?php } } ?>
										</select>
										<?php echo $validation->getError('user_id[]', '<div class="form-control-feedback"></div><span class="help-block">', '</span>'); ?>
									</div>

									</div>
								</div>
								<!-- /select All option selected -->
							<div class="form-group   <?php if($validation->getError('message_content')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.message_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="message_content" rows="8" cols="4" placeholder="<?php echo lang('language_lang.plac_message_content'); ?>"><?php echo set_value('message_content',isset($message_data->message_content) ? ucfirst($message_data->message_content) : ''); ?></textarea>
									</div>
									<?php echo $validation->getError('message_content', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>

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

							<div class="text-right col-lg-8">
								<button type="submit" class="btn btn-primary"><?php if(isset($message_data->message_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_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) {
	            	$('.message').formValidation('revalidateField','start_date');
	            });

			    $('.message').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        fields: {
			            message_content: {
			                message: '<?php echo lang("language_lang.message_content_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.message_content_required");?>'
			                    }
			                }
			            },
			            start_date: {
			                message: '<?php echo lang("language_lang.message_date_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.message_date_required");?>'
			                    }
			                }
			            },
			            expire_days: {
			                message: '<?php echo lang("language_lang.message_expire_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.message_expire_required");?>'
			                    },
			                    digits: {
			                    	message: '<?php echo lang("language_lang.message_expire_num");?>'
			                    }
			                }
		                },
		                user_id: {
			                message: '<?php echo lang("language_lang.message_userlist_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.message_userlist_required");?>'
			                    }
			                }
			            }

			            
			        }
			    })
				

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

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

</body>
</html>
