<!DOCTYPE html>
<html lang="en">
<head>

	<!-- Main navbar -->
		<?php
		 $this->session = session();
		 $this->uri = service('uri');


		 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>
	
	<!-- 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/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>
	<!--<script type="text/javascript" src="<?php echo base_url();?>assets/js/plugins/ui/moment/moment.min.js"></script>
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/plugins/pickers/daterangepicker.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 type="text/javascript" src="<?php echo base_url();?>assets/js/pages/form_multiselect.js"></script>
	 /theme JS files -->
	
	<style>    
		.btn-group {
			display: block;
		}
	    div.checker {
	    	top: 18px !important;
	    }
	    .multiselect-container {
	    	width:100% !important;
	    }
	    div.form-group  div.btn-group ul.multiselect-container.dropdown-menu {
	    	padding: 0px !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 -->
	<?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">
			<div class="col-lg-12">
				<div class="col-lg-12">
					<!-- Horizontal form -->
					<div class="panel panel-flat">
						<div class="panel-heading">
							<h5 class="panel-title"><?php echo $page_title; ?></h5>
							<div class="heading-elements">
								<ul class="icons-list">
									<!-- <li><a href="<?php echo base_url();?>admin/users/add" class="glyphicon-plus"></a></li> -->
			                		<li><a data-action="collapse"></a></li>
			                		<li><a data-action="reload"></a></li>
			                		<li><a data-action="close"></a></li>
			                	</ul>
		                	</div>
						</div>
						<?php 
						$currency_info = defaultcurrency();
						$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 export validateDontSubmit" name="frmexport" id="frmexport" action="<?=site_url($action);?>" method="post">


							<div class="form-group">   
				                <label class="control-label col-lg-2 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 ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_select_user_type'); ?> </label>
									<div class="col-lg-4">
										<select name="user_type" class="form-control bootstrap-select" id="user-type">
		                                    <option value=""><?php echo ucfirst(lang('language_lang.lbl_select_user_type'));?></option>
		                                    <option value="all"><?php echo ucfirst(lang('language_lang.lbl_all_user'));?></option>
		                                    <option value="1"><?php echo ucfirst(lang('language_lang.lbl_active_user'));?></option>
		                                    <option value="0"><?php echo ucfirst(lang('language_lang.lbl_suspend_user'));?></option>
										</select>
									</div>
								</div>

								<div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_select_users'); ?> </label>
									<div class="col-lg-4">
										<select name="user_list[]" class="form-control multiselect-full-featured1" multiple="multiple" id="user_list">
										</select>
									</div>
								</div>
								
								<?php
									if($this->uri->getSegment(3)=='exchange')
									{?>
										<div class="form-group">
											<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_exchange_type'); ?> </label>
											<div class="col-lg-4">
												<select name="exchange_type[]" id="exchange_type" class="form-control input-group multiselect-full-featured" multiple="multiple">
		                                    		<?php foreach ($exchange_type as $pay_list => $value) {?>
		                                    			<option value="<?php echo $pay_list; ?>"><?php echo ucfirst($value);?></option>
													<?php } ?>
												</select>
											</div>
										</div>	

										<div class="form-group">
											<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_exchange_status'); ?> </label>
											<div class="col-lg-4">
												<select name="exchange_status[]" id="exchange_status" class="form-control input-group multiselect-full-featured" multiple="multiple">
		                                    		<?php foreach ($exchange_status as $pay_list => $value) {?>
		                                    			<option value="<?php echo $pay_list;?>"><?php echo ucfirst($value);?></option>
													<?php } ?>
												</select>
											</div>
										</div>											
									<?}
								?>
								<div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_date_range'); ?> </label>
									<div class="col-lg-2">
										<label class="control-label text-semibold"><?php echo lang('language_lang.lbl_date_from'); ?> </label>
										<div class="input-group">
											<span class="input-group-addon"><i class="icon-calendar22"></i></span>
											<input type="text" class="form-control start_date" placeholder="<?php echo lang('language_lang.place_start_date'); ?>" name="start_date" value="">
										</div>
									</div>
									<div class="col-lg-2">
										<label class="control-label text-semibold"><?php echo lang('language_lang.lbl_date_to'); ?> </label>
										<div class="input-group">
											<span class="input-group-addon"><i class="icon-calendar22"></i></span>
											<input type="text" class="form-control end_date" placeholder="<?php echo lang('language_lang.place_end_date'); ?>" name="end_date" value="">
										</div>
									</div>
								</div>

								<!-- <div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_date_from'); ?> </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 start_date" placeholder="<?php echo lang('language_lang.place_start_date'); ?>" name="start_date" value="">
										</div>
									</div>
								</div>

								<div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_date_to'); ?> </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 end_date" placeholder="<?php echo lang('language_lang.place_end_date'); ?>" name="end_date" value="">
										</div>
									</div>
								</div> -->

								<div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_amount_range'); ?> </label>
									<div class="col-lg-2">
										<label class="control-label text-semibold"><?php echo lang('language_lang.lbl_amount_min'); ?> </label>
										<div class="input-group">
											<input type="text" class="form-control" placeholder="<?php echo lang('language_lang.place_min_amount'); ?>" name="min_amount" value="">
											
										</div>
									</div>
									<div class="col-lg-2">
										<label class="control-label text-semibold"><?php echo lang('language_lang.lbl_amount_max'); ?> </label>
										<div class="input-group">
											
											<input type="text" class="form-control" placeholder="<?php echo lang('language_lang.place_max_amount'); ?>" name="max_amount" value="">
											
										</div>
									</div>
								</div>

								<!-- <div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_amount_min'); ?> </label>
									<div class="col-lg-4">
										<div class="input-group">
											<span class="input-group-addon" style="font-size: 18px;"><strong><?php echo $currency_info->currency_symbol;?></strong></span>
											<input type="text" class="form-control" placeholder="<?php echo lang('language_lang.place_min_amount'); ?>" name="min_amount" value="">
											<span class="input-group-addon"><?php echo strtoupper($currency_info->currency_unit);?></span>
										</div>
									</div>
								</div>

								<div class="form-group ">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.lbl_amount_max'); ?> </label>
									<div class="col-lg-4">
										<div class="input-group">
											<span class="input-group-addon" style="font-size: 18px;"><strong><?php echo $currency_info->currency_symbol;?></strong></span>
											<input type="text" class="form-control" placeholder="<?php echo lang('language_lang.place_max_amount'); ?>" name="max_amount" value="">
											<span class="input-group-addon"><?php echo strtoupper($currency_info->currency_unit);?></span>
										</div>
									</div>
								</div> -->
								
								
								<div class="text-right col-lg-6">
									<input name="format[]" value="<?php echo lang('language_lang.lbl_xml'); ?>" type="button" class="btn exportbtn btn-primary"/>
									<input name="format[]"   value="<?php echo lang('language_lang.lbl_pdf'); ?>" type="button" class="btn exportbtn btn-primary"/>
									<input name="format[]" value="<?php echo lang('language_lang.lbl_csv'); ?>" type="button" class="btn exportbtn btn-primary"/>
								</div>

								<!-- <div class="text-right col-lg-8">
									<button type="submit" class="btn btn-primary"><?php echo lang('language_lang.button_export'); ?> <i class="icon-arrow-right14 position-right"></i></button>
								</div> -->
							</form>
						</div>
					</div>
					<!-- /horizotal form -->
				</div>
			</div>
			<!-- <div class="col-lg-6">
				<div class="panel panel-flat">
					<div class="panel-heading">
						<h5 class="panel-title"><?php echo lang('language_lang.page_title_comming'); ?></h5>
						<div class="heading-elements">
							<ul class="icons-list">
		                		<li><a data-action="collapse"></a></li>
		                		<li><a data-action="reload"></a></li>
		                		<li><a data-action="close"></a></li>
		                	</ul>
	                	</div>
					</div>
					<div class="panel-body">
					</div>
				</div>
			</div> -->

			</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-featured').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();
		        }
		    });

		    $('.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();
		        }
		     //    ,
		     //    buttonText: function (options) {
			    //     if (options.length == 0) {
			    //         return 'Disabled';
			    //     } else {
			    //         var selected = 0;
			    //         options.each(function () {
			    //             selected += 1;
			    //         });
			    //     }
			    // }
		    });

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

			$(document).ready(function() {

				$('.bootstrap-select').selectpicker();

				$.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($this->session->getFlashData('error_message')) { ?>
					$.jGrowl("<?php echo $this->session->getFlashData('error_message');?>", {
			            header: '<?php echo lang("language_lang.error");?>',
			            theme: 'bg-danger'
			        });
	            <?php } ?>
	                    
	            <?php if($this->session->getFlashData('success_message')) { ?>
	                $.jGrowl("<?php echo $this->session->getFlashData('success_message');?>", {
			            header: '<?php echo lang("language_lang.success");?>',
			            theme: 'bg-success'
			        });
	            <?php } ?>

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

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

	            $(".min_amount").on('change', function(e) {
	            	$('.export').formValidation('revalidateField','min_amount');
	            })

	            $(".max_amount").on('change', function(e) {
	            	$('.export').formValidation('revalidateField','max_amount');
	            })

	            

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

			$('#user-type').on('change', function() {
				
				// console.log(this.value);
				var values =  this.value;
				var group = $("#select_group").val();
			
				$.ajax({
		            type: 'post',
		            url:'<?php echo base_url('admin/reports/checkusertypes/');?>'+'/'+values,
					data : {'group':group},
		            success : function(resp)
		            {
		            	$('#user_list').html(resp);
		            	$(".multiselect-full-featured1").multiselect('rebuild');
					    $(".styled, .multiselect-container input").uniform({ radioClass: 'choice'});
					    // $('ul.multiselect-container').removeAttr('style');

		            }
		        });
			})

			$('#select_group').on('change', function() {
				
				// console.log(this.value);
				var values =  $("#user-type").val();
				var group = $("#select_group").val();
				$.ajax({
		            type: 'post',
		            url:'<?php echo base_url('admin/reports/checkusertypes/');?>'+'/'+values,
					data : {'group':group},
		            success : function(resp)
		            {
		            	$('#user_list').html(resp);
		            	$(".multiselect-full-featured1").multiselect('rebuild');
					    $(".styled, .multiselect-container input").uniform({ radioClass: 'choice'});
					    // $('ul.multiselect-container').removeAttr('style');

		            }
		        });
			})

			// $('ul.multiselect-container').find('.checker').children().addClass('checked');
			// $('.exportbtn').on('click', function() {
			// 	document.forms["frmexport"].submit();
			// 	// $('#frmexport form').submit();
			// });

			$('.exportbtn').on('click', function() {
				// alert($(this).val());
				ExportDoc($(this).val());
				// $('.export').formValidation();	
				// $('.export').isValid();
				// var formValidation = $('.export').data('formValidation');
			})

			
			

		    	$('.export')
		    	 // .find('[name="user_id[]"]')
		      //       .selectpicker()
		      //       .change(function(e) {
		      //           $('.export').formValidation('revalidateField', 'user_id');
		      //       })
		      //       .end()

		    	.formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        row: {
					    valid: 'has-success1',
					    invalid: 'has-error'
					},
			        fields: {

			        	user_type: {
			        		message: '<?php echo lang("language_lang.reports_usertype_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_usertype_required"); ?>'
			                    }
			                }
			        	},
			        	'user_list[]': {
			        		message: '<?php echo lang("language_lang.reports_user_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_user_required"); ?>'
			                    }
			                }
			        	},
			        	'payment_name[]': {
			        		message: '<?php echo lang("language_lang.reports_payment_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_payment_required"); ?>'
			                    }
			                }
			        	},
			        	start_date: {
			        		message: '<?php echo lang("language_lang.reports_from_date_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_from_date_required"); ?>'
			                    },
			                    date: {
		                            format: 'MM/DD/YYYY',
		                            max: 'end_date',
		                            message: 'The start date is not a valid'
		                        }
			                }
			        	},
			        	end_date: {
			        		message: '<?php echo lang("language_lang.reports_to_date_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_to_date_required"); ?>'
			                    },
			                    date: {
		                            format: 'MM/DD/YYYY',
		                            min: 'start_date',
		                            message: 'The end date is not a valid'
		                        }
			                }
			        	},
			            min_amount: {
			                message: '<?php echo lang("language_lang.reports_minamount_valid"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_minamount_required"); ?>'
			                    },
			                    regexp: {
			                        regexp: /^[0-9.]+$/,
			                        message: '<?php echo lang("language_lang.reports_minamount_valid"); ?>'
			                    }
			                    
			                }
		                },
		                max_amount: {
			                message: '<?php echo lang("language_lang.reports_maxamount_valid"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_maxamount_required"); ?>'
			                    },
			                    regexp: {
			                        regexp: /^[0-9.]+$/,
			                        message: '<?php echo lang("language_lang.reports_maxamount_valid"); ?>'
			                    },
			                    greaterThan: {
			                        value: 'min_amount',
			                        message: 'The value must be greater than to minimum amount'
			                    }
			                }
		                }
			            
			        }
			    })
				// .on('success.form.fv', function(e) {
		  //           e.preventDefault();
		  //           var $form = $(e.target);
		            
		  //           // Get the FormValidation instance
		  //           var bv = $form.data('formValidation');
		  //           var button = bv.getSubmitButton();
		  //           var button_value = button.attr('value');
		  //           var buttonid = button.attr('class');
		  //           $('.text-right').after('<input type=hidden name=format value=' + button_value + '>');
		  //           $.post($form.attr('action'), $form.serialize(), function(result) {
		  //               console.log(result);
		  //           }, 'json');
		  //       });
		 		
				// .on('success.form.fv', function(e, data) {
		  //           if (data.field === 'min_amount') {
		  //               data.element
		  //                   .on('change', function(evt) {
		  //                       $('.export').formValidation('revalidateField', data.element);
		  //                   });
		  //           }
		  //       })
				
			    // .on('success.form.fv', function(e) {
		     //        // Prevent form submission
		     //        e.preventDefault();

		     //        var $form = $(e.target);
		     //        $form.Submit({
		     //            // You can change the url option to desired target
		     //            url: $form.attr('action'),
		     //            success: function(responseText, statusText, xhr, $form) {
		     //                // $('.export').append('<input type="hidden" name="format" value="'+value+'"/>');
		     //                console.log('valid');
		     //            }
		     //        });
		     //    });

		});
		})(jQuery);

		function ExportDoc(value){
			if(!jQuery('.export').formValidation()) {
				console.log('invalid');
			} else {
				jQuery('.export').append('<input type="hidden" name="format" value="'+value+'"/>');
				document.forms["frmexport"].submit();	
				// console.log('valid');
				// location.reload();
			}
			
		}
	
	</script>

</body>
</html>
