<!DOCTYPE html>
<html lang="en">
<head>
	<!-- header -->
		<?php 

		$this->session = session();
		$validation = \Config\Services::validation();


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

	<!-- Theme 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/plugins/forms/selects/select2.min.js');?>"></script>
	<!-- /theme JS files -->

	<!-- Theme JS files -->

	<!-- /theme JS files -->

    <!-- notify JS files -->
	    <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>
	<!-- /select box JS files -->
	
	<style type="text/css">
	    .has-error span.select2-container
	    {
	    	border:1px solid #d84315;
	    }

	    .has-success span.select2-container
	    {
	    	border:1px solid #43a047;
	    }

	     .multiselect-container {
	    	width:100% !important;
	    }

	    div.form-group  div.btn-group ul.multiselect-container.dropdown-menu {
	    	padding: 0px !important;
	    }	 
	    .form-horizontal .checkbox .checker, .form-horizontal .checkbox-inline .checker
	    {
 			top:0; 
		}   

		.multiselect-container > li > a .checker, .multiselect-container > li > a .choice {
  left: 12px;
  margin-top: 10px;
  top: 50%;
}

	</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">

				<!-- Horizontal form -->
				<div class="panel panel-flat">
					<div class="panel-heading">
						<h5 class="panel-title"><? echo lang('language_lang.menu_currency_pair'); ?></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();?>
					<div class="panel-body">
						<form class="form-horizontal fundtransfer" action="<?=site_url($action);?>" method="post" enctype="multipart/form-data">
						<input type="hidden" name="ijd" id="ijd" value="<?php echo $id;?>">
							<?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 error_data = '< ?php echo lang("language_lang.fund_transfer_amount_bet"); ?>'
											$.jGrowl(error_data, {
									            header: '< ?php echo lang("language_lang.error");?>',
									            theme: 'bg-danger'
									        });
										})(jQuery);
									</script>-->
							<?php
								}
							?>

							<div class="form-group  <?php if(!$validation->getError('select_payer')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.menu_currency_market'); ?> <span class="text-danger">*</span></label>
								<div class="col-lg-4">
									<select name="select_payer" id="select_payer_id" class="select-search form-control" >
										<option value=""><?php echo lang('language_lang.none_selected'); ?></option>
					               		<?php foreach ($market_currency as $users) { ?>
										<option value="<?php echo $users->coid; ?>" <?php if(isset($getpair)){if($getpair->mark_curr==$users->coid){echo 'selected=selected';}else{ echo '';}}?>><?php echo ucfirst($users->coin_name); ?></option>
										<?php } ?>	
									</select>
									
								</div>
							</div>



							<div class="form-group  <?php if($validation->getError('select_pair')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.menu_currency_unmarket'); ?> <span class="text-danger">*</span></label>
								<div id="bg_color" class="col-lg-4">
									<select name="select_receiver[]" class="<?php if(!isset($id)){ echo  'multiselect-full-featured1';}else{ echo 'select-search';}?> bootstrap form-control" <?php if(!isset($id)){ echo 'multiple="multiple"';}else{ echo 'disabled'; }?> style="width:100%;">
					               		<?php foreach ($unmarket_currency as $receiver) { ?>
										<option value="<?php echo $receiver->coid;?>" <?php if(isset($getpair)){if($getpair->curid==$receiver->coid){echo 'selected=selected';}else{ echo '';}}?> ><?php echo ucfirst($receiver->coin_name); ?></option>
										<?php } ?>
									</select>
									<?php echo $validation->getError('select_pair', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>

							 <?php

                          $condition = "cid ='".$cid."' ";
                          $checkcointype =$this->common_model->GetRow('currency_pair',$condition);

                          
                          $coin = $checkcointype->curid;
                          $condition = "coid ='".$coin."'";
                          $checkcointypes =$this->common_model->GetRow('coin_info',$condition);
                         

                          $coin1 = $checkcointype->curid;
                          $condition1 = "curid ='".$coin1."'";
                          $chk =$this->common_model->GetRow('currency_market',$condition1);
                         


                          if($checkcointypes->coin_type == '0')
                          { ?>
                            

                            <div class="form-group <?php if($validation->getError('curprice')) echo "has-error";?>">
                                <label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.price'); ?>  </label>
                                  <div class="col-lg-3">
                                        <input type="text" value="<?php if(isset($chk)){ echo $chk->price;}else{ echo set_value('price');}?>" name="price" class="form-control" />
                                      <div class="messageContainer"></div>
                                      <?php echo $validation->getError('curprice', '<span class="help-block">', '</span>'); ?>
                                  </div>
                              </div>


                              <div class="form-group <?php if($validation->getError('price_usd')) echo "has-error";?>">
                                <label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.price_usd'); ?>   </label>
                                  <div class="col-lg-3">
                                        <input type="text" value="<?php if(isset($chk)){ echo $chk->price_usd;}else{ echo set_value('price_usd');}?>" name="price_usd" class="form-control" />
                                      <div class="messageContainer"></div>
                                      <?php echo $validation->getError('price_usd', '<span class="help-block">', '</span>'); ?>
                                  </div>
                              </div>

                          <?php } ?>
                          	<input type="hidden" name="recid" value="<?php echo $coin; ?>" >

							<div class="clearfix"><br></div>

							<div class="text-right col-lg-7">
	                            <button id="btn" 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() {

			$('.select-search').select2();


			$('#transfer_amount').change(function(){

                $.ajax({
                    type: 'post',
                    url : '<?php echo base_url('admin/finance/transationfee');?>',
                    data : {'amount':$('#transfer_amount').val()},
                    success : function(msg)
                    {
                        if(msg) {
                            $('#transfee').html(msg);
                        }
                    }
                });

            })

            $('#select_payer_id').change(function(){

      			// var id = $('#payment_check').val();
      			var user_id = $('#select_payer_id').val();
      			var amount = $('#balanceVal').html();

      			if($('#transfer_amount').val()) {
                    $('.fundtransfer').formValidation('revalidateField', 'amount');
                }

      			// if($('#transfer_amount').val() > amount){
      			// 	console.log('invalid');
      			// 	$('#transfer_amount').trigger('change');
      			// } else {
      			// 	console.log('valid');
      			// 	$('#transfer_amount').trigger('change');
      			// }

      			if(user_id) {
		        	$.ajax({
		                type: 'post',
		                url : '<?php echo base_url('admin/finance/checkbalance');?>',
		                data : {'sender_id':user_id},
		                success : function(msg)
		                {
		                    if(msg) {
		                    	$('#balanceVal').html(msg);
	                        
	                        	if(msg=='<?php echo number_format('0',$currency_info->deimal_point, '.', ''); ?>' || msg < '0') {
		                    
			                    	$('#ip-exist').css('display','block');
			                    	$('#balanceVal').css('color','#d84315');
			                    	$('#deduct').css('color','#d84315');
			                    	$('.error_msg').parent().parent().addClass('has-error');
			                    	$('#btn').addClass('disabled');

		                    	} else {

			                    	$('#ip-exist').css('display','none');
			                    	$('#balanceVal').css('color','#333333');
			                    	$('#deduct').css('color','#333333');
			                    	$('.error_msg').parent().parent().removeClass('has-error');
			                    }
		                    }
		                }
		            });
				}
      
             });

			$('#payment_check').change(function(){

      			var id = $('#payment_check').val();
      			var user_id = $('#select_payer_id').val();

      			if($('#transfer_amount').val()) {
                    $('.fundtransfer').formValidation('revalidateField', 'amount');
                }

      			if(user_id) {
		        	$.ajax({
		                type: 'post',
		                url : '<?php echo base_url('admin/finance/checkbalance');?>',
		                data : {'id':id,'sender_id':user_id},
		                success : function(msg)
		                {
		                    if(msg) {
		                    	$('#balanceVal').html(msg);
	                        
	                        	if(msg=='<?php echo number_format('0',$currency_info->deimal_point, '.', ''); ?>' || msg < '0') {
		                    
			                    	$('#ip-exist').css('display','block');
			                    	$('#balanceVal').css('color','#d84315');
			                    	$('#deduct').css('color','#d84315');
			                    	$('.error_msg').parent().parent().addClass('has-error');
			                    	$('#btn').addClass('disabled');

		                    	} else {

			                    	$('#ip-exist').css('display','none');
			                    	$('#balanceVal').css('color','#333333');
			                    	$('#deduct').css('color','#333333');
			                    	$('.error_msg').parent().parent().removeClass('has-error');
			                    }
		                    }
		                }
		            });
				}
      
             });

			// $('#transfer_amount').change(function(){

   //    			var id = $('#transfer_amount').val();
   //    			var balance_val = $('#balanceVal').html();
   //    			var user_id = $('#select_payer_id').val();
   //    			if(user_id) {
	  //     			if(id!=<?php echo number_format('0'); ?>){
			// 	        $.ajax({
			// 	            type: 'post',
			// 	            url : '<?php echo base_url();?>admin/finance/checkfee/',
			// 	            // data : {'id':id,'user':user_id},
			// 	            data : {'id':id,'user':user_id,'balance':balance_val},
			// 	            success : function(msg)
			// 	            {
			//                     if(msg) {
			//                     	if(msg=='Insufficient') {

			//                             $('#blan').css('display','block');
			//                             $('.error_msg1').parent().parent().addClass('has-error');
			//                             $('#btn').addClass('disabled');

			//                     	} else {
			// 		                    $('#trans_fee').html('<?php echo $currency_info->currency_symbol;?>'+msg);
			// 		                    $('#transfee').val(msg);
			// 		                    $('#blan').css('display','none');
			//                         }
			//                     }
			// 	            }
			// 	        });

		 //         	} else{

		 //         		$('#blan').css('display','block');
	  //               	$('.error_msg1').parent().parent().addClass('has-error');
	  //               	$('#btn').addClass('disabled');
		 //         	}
		 //        }
      
   //          });

			$.jGrowl.defaults.closer = false;

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

		    $('.fundtransfer').formValidation({
		    	framework: 'bootstrap',
		    	excluded: [':disabled'],
		        icon: {
		            validating: 'glyphicon glyphicon-refresh'
		        },
		        fields: {
		            select_payer: {
		                message: '<?php echo lang("language_lang.market_currency_required");?>',
		                validators: {
		                    notEmpty: {
		                        message: '<?php echo lang("language_lang.market_currency_required");?>'
		                    }
		                }
		            },
		            'select_receiver[]': {
		                message: '<?php echo lang("language_lang.fund_transfer_receiver_valid");?>',
		                validators: {
		                    notEmpty: {
		                        message: '<?php echo lang("language_lang.fund_transfer_receiver_required");?>'
		                    }
		                }
		            }
		        }
		    })

		});
	 
		$('#icon-bck').on('click',function() {
			window.history.back();
		});

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

</body>
</html>
