<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
		<?php
		use App\Libraries\MyEncrypt;
        $validation = \Config\Services::validation();
        $this->session = \Config\Services::session();
		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/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>
   
	<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 {
	    	
	    }*/
	    .dropdown-menu.inner {
    		max-height: 200px !important;
		}
	</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 -->
	<?php echo view('admin/'.$module_name.'_header'); ?>
	<!-- /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.bonus_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>
                	<?php       
	    	            $currency_info = defaultcurrency();
	        			// $this->load->library('MyEncrypt');
						$myencrypt = new MyEncrypt;
						$session = \Config\Services::session();
						$admin_login=$session->get('userid');
						$get_admin=$this->db->query("select * from admin where id='".$admin_login."'")->getRow();
						$user_group = $get_admin->user_group;
						


                	?>
                	 
					<div class="panel-body">
						<form class="form-horizontal form-bonus" action="<?=site_url($action);?>" method="post">
                          
                            <?php if($flag==0) { ?>


							
								<div class="form-group  has-feedback <?php if($validation->getError('select_group')) echo "has-error";?>">   
				                <label class="control-label col-lg-3 text-semibold">Select User Group</label>
				                <div class="col-lg-4">
					               <select class="bootstrap-select form-control"  name="select_group" id="select_group">
				                        <option value="all" >All</option>
										<?php 
                                  		if($user_group=='0')
                                  		{	 
                                		 ?>
										<option value="0">Group A</option>
										<option value="1">Group B</option>
										<?php
										}
										?>
										<?php 
                                  		if($user_group=='1')
                                  		{	 
                                		 ?>
										<option value="0">Group A</option>
										<?php
										}
										?>
										<?php 
                                  		if($user_group=='2')
                                  		{	 
                                		 ?>
										<option value="1">Group B</option>
										<?php
										}
										?>
									</select> 
					       			
							    </div>
							</div>

							<div class="form-group  has-feedback <?php if($validation->getError('select_user')) echo "has-error";?>">   
				                <label class="control-label col-lg-3 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="0"><?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-3 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('select_coin')) echo "has-error";?>">   
				                <label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.lbl_select_coin'); ?></label>
				                <div class="col-lg-4">
					               <select class="bootstrap-select form-control" style="max-height: 200px;"  name="select_coin" id="select_coin">
					               <option value=""><?php echo lang('language_lang.none_selected'); ?></option>
					               <?php foreach ($all_active_coin as $list) { ?>
											<option value="<?php echo $list->coid; ?>"><?php echo ucfirst($list->coin_name); ?></option>
											<?php } ?>
				                        
									</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('amount')) echo "has-error";?>">
							    <label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.bonus_amount'); ?>  <span class="text-danger">*</span></label>
						        <div class="col-lg-4">
							        <div style="width:100%;" class="input-group">
								    									
                                     <input type="text" id="amount" name="amount" class="form-control"  placeholder="<?php echo lang('language_lang.plac_amount'); ?>" value="">
							        
							        </div>
							        <?php echo $validation->getError('amount', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
						        <div id="blan" style="display:none;color:#d84315;" class="error_msg1"><?php echo lang('language_lang.fund_balance'); ?></div>
						        </div>
						    </div>
							<div class="form-group  has-feedback <?php if($validation->getError('description')) echo "has-error";?>">
							    <label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.bonus_description'); ?>  <span class="text-danger">*</span></label>
						        <div class="col-lg-4">
							        <div style="width:100%;" class="input-group">
								        <input type="text" name="description" class="form-control"  placeholder="<?php echo lang('language_lang.plac_memo_value'); ?>" value="">
							        </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>
													
	                       <div class="text-right col-lg-7"> 
	                            <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() {


				$('#amount').change(function(){
				 	var amountVal = $('#amount').val();
				 	if(amountVal==<?php echo number_format('0'); ?>)
				 	{
	                	$('#blan').css('display','block');
	                 	$('.error_msg1').parent().parent().addClass('has-error');
	                 	$('#btn').addClass('disabled');
				 	}
				 	else
				 	{
				 		$('#blan').css('display','none');
	                    $('.error_msg1').parent().parent().removeClass('has-error');
				 	}
				})

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

				$.jGrowl.defaults.closer = false;

				<?php if($this->session->getFlashData('error_message')) { ?>
					var error_data = <?php echo $this->session->getFlashData('error_message');?>
					$.jGrowl(error_data, {
			            header: '<?php echo lang("language_lang.error");?>',
			            theme: 'bg-danger'
			        });
	            <?php } ?>
	                    
	            <?php if($this->session->getFlashData('success_message')) { ?>
	                
	                var succ_data = '<?php echo $this->session->getFlashData('success_message');?>';
	                $.jGrowl(succ_data, {
			            header: '<?php echo lang("language_lang.success");?>',
			            theme: 'bg-success'
			        });
	            <?php } ?>

			    $('.form-bonus').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        row: {
					    valid: 'has-success1',
					    invalid: 'has-error'
					},
			        fields: {
			            description: {
			                message: '<?php echo lang("language_lang.bonus_descrip_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.bonus_descrip_required"); ?>'
			                    }
			                }
			            },
			             amount: {
			                message: '<?php echo lang("language_lang.bonus_amount_valid"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.bonus_amount_required"); ?>'
			                    },
			                    regexp: {
			                        regexp: /^[0-9.]+$/,
			                        message: '<?php echo lang("language_lang.bonus_amount_invalid"); ?>'
			                    }
			                }
			            },
			            select_user: {
			            	message: '<?php echo lang("language_lang.bonus_userstype_valid"); ?>',
			            	 validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.bonus_usertype_required"); ?>'
			                    }
			                }
			            },
			            select_coin: {
			            	message: '<?php echo lang("language_lang.lbl_select_coin_cannot_empty"); ?>',
			            	 validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.lbl_select_coin_cannot_empty"); ?>'
			                    }
			                }
			            },
			            // payment: {
			            // 	message: '<?php echo lang("language_lang.bonus_paymentgateway_valid"); ?>',
			            // 	 validators: {
			            //         notEmpty: {
			            //             message: '<?php echo lang("language_lang.bonus_paymentgateway_required"); ?>'
			            //         }
			            //     }
			            // },
			            'userlist[]': {
			            	message: '<?php echo lang("language_lang.bonus_selectuser_valid"); ?>',
			            	 validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.bonus_selectuser_required"); ?>'
			                    }
			                }
			            }
			        }
			    })
			});

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

	        	$.ajax({
	                type: 'post',
	                url : '<?php echo base_url('admin/finance/list_user/');?>'+'/'+id,
	                data : {'id':id,'group':group},
	                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');
	    	});


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

	        	$.ajax({
	                type: 'post',
	                url : '<?php echo base_url('admin/finance/list_user/');?>'+'/'+id,
	                data : {'id':id,'group':group},
	                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>
