<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
		<?php 
		use App\Libraries\MyEncrypt;
		$session = \Config\Services::session();
		$validation = \Config\Services::validation();
		echo view('admin/common_header'); ?>
	<!-- /header -->
	  <!-- multi select -->

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


	
  <!-- notify JS files -->
    <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>
	
	<!-- /theme JS files -->
	<!-- select box theme JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/bootstrap_select.min.js');?>"></script>
    <!-- select box JS files -->
   <!-- ckeditor JS files -->
    <script type="text/javascript" src="<?php echo base_url('assets/ckeditor/ckeditor.js');?>"></script>
	<script src="<?php echo base_url('assets/boots/js/jquery.js');?>"></script>


	<!-- /select box JS files -->
<style>    
		
	    .btn-group {
			display: block;
		}
	    div.checker {
	    	top: 18px !important;
	    }
	    .multiselect-container {
	    	width:100% !important;
	    }
	    /*.checker span {
	    	border: 0 solid #607d8b;
    		color: transparent;
	    }
	    .checker span::after {
	    	content: '' !important;
	    }
	    label.checkbox {
	    	padding-left: 20px !important;
	    }*/
	    div.form-group  div.btn-group ul.multiselect-container.dropdown-menu {
	    	padding: 0px !important;
	    }
	    /*.multiselect ul.dropdown-menu {
	    	
	    }*/

</style>



	
</head>

<body class="navbar-top-md-md">

	<!-- 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.sendnews_newsletter_lbl'); ?></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"><? echo lang('language_lang.sendnews_newsletter_lbl'); ?></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>
                	<?php       
	    	            $currency_info = defaultcurrency();
	        			// $this->load->library('MyEncrypt');
						$myencrypt = new MyEncrypt;
                	?>
                	 
					<div class="panel-body">
						<form class="form-horizontal form-sendnews" action="<?=site_url($action);?>" method="post" enctype="multipart/form-data">
							
							
                          
                          <?php if($flag==0) { ?>
							<div class="form-group  has-feedback <?php if($validation->getError('select_user')) echo "has-error";?>">   
				                <label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.bonus_usertype'); ?></label>
				                <div class="col-lg-4">
					               <select class="bootstrap-select form-control"  name="select_user" id="fetch_user">
					                        <option value="" ><?php echo lang('language_lang.none_selected'); ?></option>
											<option value="4" id="select-all-values"><?php echo lang('language_lang.all_users'); ?></option>
											<option value="1"><?php echo lang('language_lang.active_users'); ?></option>
											<option value="2"><?php echo lang('language_lang.suspended_users'); ?></option>
									</select> 
					       <?php echo $validation->getError('select_user', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>

							    </div>
							</div>


							<div class="form-group has-feedback <?php if($validation->getError('userlist')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.bonus_select_user'); ?></label>
				                <div id="bg_color" class="col-lg-4">
                                 <select id="userlist" class="multiselect-full-featured1 bootstrap form-control" multiple="multiple" name="userlist[]"   style="width:100%;" placeholder="To select users">
                                     <?php echo $validation->getError('userlist', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                                  </select>
						        </div>
						    </div>

						    <?php } else { ?>

                           <input type="hidden" name="user1" value="<?php echo $myencrypt->encode($member_name->uusersid);?>">
							<? } ?>
							
							<div class="form-group  has-feedback <?php if($validation->getError('subject')) echo "has-error";?>">
							    <label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_mail_subject'); ?>  <span class="text-danger">*</span></label>
						        <div class="col-lg-4">
							        <div style="width:100%;" class="input-group">
                                     <input type="text" id="subject" name="subject" class="form-control"  placeholder="<?php echo lang('language_lang.sendnews_subject_plc'); ?>" value="">
							        </div>
							        <?php echo $validation->getError('subject', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
						        
						        </div>
						    </div>
							<div class="form-group  has-feedback <?php if($validation->getError('message')) echo "has-error";?>">
							    <label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_mail_message'); ?>  <span class="text-danger">*</span></label>
						        <div class="col-lg-9">
							        <div style="width:100%;" class="input-group">
								        <textarea rows="5" name="message" cols="5" class="form-control ckeditor" ></textarea>
							        </div>
							        <?php echo $validation->getError('message', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
						        </div>
						    </div>
													
	                       <div class="text-right col-lg-6"> 
	                            <button type="submit" class="btn btn-primary"><?php echo lang('language_lang.bonus_button'); ?> <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() {
        	$('.multiselect-full-featured1').multiselect({
		        includeSelectAllOption: true,
		        enableFiltering: true,
		        enableCaseInsensitiveFiltering: true,
		        templates: {
		            filter: '<li class="multiselect-item multiselect-filter"><i class="icon-search4"></i> <input class="form-control" type="text"></li>'
		        },
		        onSelectAll: function() {
		            $.uniform.update();
		        }
		    });

		    $(".styled, .multiselect-container input").uniform({ radioClass: 'choice'});
			$(document).ready(function() {

				$('.bootstrap-select').selectpicker();
				$('.bootstrap-select1').selectpicker({size: 4});

				$.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 } ?>
	            

			    $('.form-sendnews').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        row: {
					    valid: 'has-success1',
					    invalid: 'has-error'
					},
			        fields: {
			            subject: {
			            	 validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.contact_subject_required"); ?>'
			                    },
	                            regexp: {
	                            	regexp: /^[A-Za-z ]+$/,
	                                message: '<?php echo lang("language_lang.contact_subject_alpha");?>'
	                            }
			                }

			            },
			            select_user: {
			            	message: '<?php echo lang("language_lang.bonus_userstype_valid"); ?>',
			            	 validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.bonus_usertype_required"); ?>'
			                    }
			                }

			            },
			            'userlist[]': {
			            	message: '<?php echo lang("language_lang.bonus_selectuser_valid"); ?>',
			            	 validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.bonus_selectuser_required"); ?>'
			                    }
			                }

			            },
			            message: {
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.contact_message_required"); ?>'
			                    },
			                     stringLength: {
	                                min: 10,
	                                message: '<?php echo lang("language_lang.contact_message_exceed");?>'
	                        	}

			                }
			            }
			            
			        }
			    }).find('[name="message"]')
					.ckeditor()
		            .editor
	                .on('change', function() {
	                    $('.form-sendnews').formValidation('revalidateField', 'message');
	                });

			    $('[name="message"]').ckeditor();
			});

			$('#fetch_user').change(function(){
	      		var id = $('#fetch_user').val();

	        	$.ajax({
	                type: 'post',
	                url : '<?php echo base_url("admin/sendnewsletter/list_user/");?>'+'/'+id,
	                data : {'id':id},
	                success : function(msg) {
	                    if(msg) {
	                     	$('#userlist').html(msg);
			            	$(".multiselect-full-featured1").multiselect('rebuild');
						    $(".styled, .multiselect-container input").uniform({ radioClass: 'choice'});
	                    }
	                }
	            });
	 			$(".multiselect-full-featured1").multiselect('refresh');
	    	});
		    
		    $('#icon-bck').on('click',function() {
				window.history.back();
			});

		});
	})(jQuery);

	
	</script>

</body>
</html>
