<?php
include("access.php");
include("include/admin.class.php");
include("include/conf.class.php");
$userinfo=$cartCore->get_user_info($CARTUSERNAME);
$cartAdminMain->check_grant($userinfo['USER_ID'],$page_name);
$cartCore->get_headder();
$cartCore->view_welcome($userinfo['USERNAME'],$userinfo['IMAGE']);
$cartCore->view_sidebar($userinfo['USER_ID'],$TOKEN_ID);
$cartCore->view_credit($COMPANY_ID,$bk);
if(isset($_POST['shippingid'])){
	$cartAdminMain->add_edit_shipping_details($userinfo['USERNAME'],$page_name,$TOKEN_ID,$COMPANY_ID);	
	exit;
}
if(isset($_POST['contactFrmSubmit'])){
	 $cartAdminMain->update_any_country_shipping_details($userinfo['USERNAME'],$page_name,$TOKEN_ID,$COMPANY_ID);	
	 exit;
}
?>

<script type="text/javascript">
function getSHIPPING(id) {
	if(id==1)
	{ 
		  $("#precentage").show(); 
		  $("#flat").hide();
	}
	else
	{
		 $("#precentage").hide(); 
		 $("#flat").show();
	}
	
}
getTAX(1);
</script>

<script type="text/javascript">
function getSHIPPINGANY(id) {
	if(id==1)
	{ 
		  $("#precentageany").show(); 
		  $("#flatany").hide();
	}
	else
	{
		 $("#precentageany").hide(); 
		 $("#flatany").show();
	}
	
}
getTAX(1);
</script>
        <!-- top navigation -->
        <div class="top_nav">
          <div class="nav_menu">
            <nav>
              <div class="nav toggle">
                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
              </div>

              <ul class="nav navbar-nav navbar-right">
              
              
              <?=$cartCore->view_userprofile($userinfo['USER_ID'],$userinfo['USERNAME'],$userinfo['IMAGE'],$TOKEN_ID,$COMPANY_ID,$bk)?>

                <li role="presentation" class="dropdown">
                  <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                    <i class="fa fa-envelope-o"></i>
                    <span class="badge bg-green"><?=$cartAdminMain->getMessageCount($userinfo['USERNAME'])?></span>
                  </a>
                  <ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu">
                  <?=$cartAdminMain->getUserMessage($userinfo['USERNAME'])?>
                    <li>
                      <div class="text-center">
                        <a href="message.php?token_id=<?=$TOKEN_ID?>&pid=<?=$cartCore->md5_base64_encode($userinfo['USERNAME'])?>">
                          <strong>See All Alerts</strong>
                          <i class="fa fa-angle-right"></i>
                        </a>
                      </div>
                    </li>
                  </ul>
                </li>
              </ul>
            </nav>
          </div>
        </div>
        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>
				<?php
                if(isset($_GET['pagename']) && $_GET['pagename'] != "")
				{
					echo $cartCore->md5_base64_decode($_GET['pagename']);
				}
				else
				{
					echo $cartCore->getPageHeading($page_name);
				}
				?>
			</h3>
              </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2><?=$cartCore->getMainPageHeading($page_name)?> 
                    <small><?php
                 if(isset($_GET['pagename']) && $_GET['pagename'] != "")
				{
					$pagename=$cartCore->md5_base64_decode($_GET['pagename']);
					echo $pagename;
				}
				else
				{
					$pagename=$cartCore->getPageHeading($page_name);
					echo $pagename;
				}
				?></small></h2>
                
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li> 
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">

<?php
	if(isset($_GET['shippingid']) && $_GET['shippingid'] != "")
		{	
				$encryptid=$_GET['shippingid'];	
				$rid=$cartCore->md5_base64_decode($encryptid);
				$rid = $cartCore->ClearInput($rid);
				$get_shipping_info=$cartCore->fetch_shipping_info_by_shipping_id($rid);
				$submit_status=true;		
		}
		else
		{		
				$encryptid=NULL;
				$get_shipping_info = NULL;
				$submit_status=false;
		}


		if(isset($_GET['success_msg']) && $_GET['success_msg']!="")
		{	
			echo $cartCore->display_sucess_msg($cartCore->md5_base64_decode($_GET['success_msg']));		  
		}
		if(isset($_GET['warning_msg']) && $_GET['warning_msg']!="")
		{	
			echo $cartCore->display_warning_msg($cartCore->md5_base64_decode($_GET['warning_msg']));		  
		}
		
?>


                    <form class="form-horizontal form-label-left" novalidate action="add_shipping_setting.php?token_id=<?=$TOKEN_ID?>" method="post">
                     <input type="hidden" name="submit_status" value="<?=$submit_status?>" />
                     <input type="hidden" name="shippingid" value="<?=$encryptid?>" />
                     <input type="hidden" name="pagename" value="<?=$pagename?>" />
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Shipping Label <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="6" name="SHIPPING_NAME" required type="text" value="<?=$get_shipping_info['SHIPPING_NAME']?>">
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Country <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <?php
						if($get_shipping_info['SHIPPING_COUNTRY']==NULL){
						echo '<select name="SHIPPING_COUNTRY" class="form-control col-md-7 col-xs-12">'.
                          $cartAdminMain->get_country_by_selected_option($get_shipping_info["SHIPPING_COUNTRY"]).'
                          </select>';
						}
						else
						{
							$shipping_country=$cartCore->fetch_country_by_iso($get_shipping_info['SHIPPING_COUNTRY']);
							echo $shipping_country['NAME'].'<input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="6" name="SHIPPING_COUNTRY" required type="HIDDEN" value="'.$get_shipping_info['SHIPPING_COUNTRY'].'" readonly="readonly">';
						}
						?>
                        </div>
                      </div>
   
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="occupation">Shipping Description 
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                       <input id="name" class="form-control col-md-7 col-xs-12" name="SHIPPING_DESCRIPTION" type="text" value="<?=$get_shipping_info['SHIPPING_DESCRIPTION']?>"> 
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Type
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <select name="PRECENTAGE" class="form-control col-md-7 col-xs-12" onchange="getSHIPPING(this.value);">
                          <?=$cartAdminMain->get_shipping_type_by_selected_option($get_shipping_info['PRECENTAGE']);?>
                          </select>
                        </div>
                      </div>
                     
                       <div class="item form-group" id="test">
                        <label class="control-label col-md-3">Amount </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        
                        <?php
						if($get_shipping_info['AMOUNT']==NULL)
						{
							echo '<input id="name" class="form-control col-md-7 col-xs-12 has-feedback-left" data-validate-length-range="6" name="AMOUNT" required type="text" value="'.$get_shipping_info['AMOUNT'].'">
                          <span id="flat" class="fa fa-money form-control-feedback left" aria-hidden="true"></span>
                          <span id="precentage" style="display:none;" class="fa fa-percent form-control-feedback right" aria-hidden="true"></span>';
						}
						else if($get_shipping_info['PRECENTAGE']==1)
						{
							echo '<input id="name" class="form-control col-md-7 col-xs-12 has-feedback-left" data-validate-length-range="6" name="AMOUNT" required type="text" value="'.$get_shipping_info['AMOUNT'].'">
                          <span id="flat" style="display:none;" class="fa fa-money form-control-feedback left" aria-hidden="true"></span>
                          <span id="precentage" class="fa fa-percent form-control-feedback right" aria-hidden="true"></span>';
						}
						else
						{
							echo '<input id="name" class="form-control col-md-7 col-xs-12 has-feedback-left" data-validate-length-range="6" name="AMOUNT" required type="text" value="'.$get_shipping_info['AMOUNT'].'">
                          <span id="flat"  class="fa fa-money form-control-feedback left" aria-hidden="true"></span>
                          <span id="precentage" style="display:none;" class="fa fa-percent form-control-feedback right" aria-hidden="true"></span>';
						}
						?>
                          
                        </div>
                      </div>
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="send" type="submit" class="btn btn-success">Submit</button>
                        </div>
                      </div>
                    </form>
                     <div class="ln_solid"></div>
                  </div>
                  
                <!-- Button to trigger modal -->
<button class="btn btn-info btn-lg" data-toggle="modal" data-target="#modalForm">
    All Other Countries Shipping
</button>

<!-- Modal -->
<div class="modal fade" id="modalForm" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">All Other Countries Shipping rule</h4>
            </div>
            
            <!-- Modal Body -->
            <div class="modal-body">
                <p class="statusMsg"></p>
                <form role="form">
                <?php
                $fetch_any_country_shipping=$cartCore->fetch_cart_shipping_by_country_code_global_id('ANY',$COMPANY_ID);
				?>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Type
                        </label>
                        <select id="PRECENTAGE" name="PRECENTAGE" class="form-control col-md-7 col-xs-12" onchange="getSHIPPINGANY(this.value);">
                         <?=$cartAdminMain->get_shipping_type_by_selected_option($fetch_any_country_shipping['PRECENTAGE']);?>
                          </select>
                          
 
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Amount
                        </label>
                          <?php
						 	if($fetch_any_country_shipping['PRECENTAGE']==1)
							{
								echo '<input id="AMOUNT" class="form-control col-md-7 col-xs-12 has-feedback-left" data-validate-length-range="6" name="AMOUNT" required type="text" value="'.$fetch_any_country_shipping['AMOUNT'].'">
                          <span id="flatany" style="display:none;" class="fa fa-money form-control-feedback right" aria-hidden="true"></span>
                          <span id="precentageany" class="fa fa-percent form-control-feedback right" aria-hidden="true"></span>';
							}
							else
							{
								echo '<input id="AMOUNT" class="form-control col-md-7 col-xs-12 has-feedback-left" data-validate-length-range="6" name="AMOUNT" required type="text" value="'.$fetch_any_country_shipping['AMOUNT'].'">
                          <span id="flatany"  class="fa fa-money form-control-feedback right" aria-hidden="true"></span>
                          <span id="precentageany" style="display:none;" class="fa fa-percent form-control-feedback right" aria-hidden="true"></span>';
							}
							?>
                        </div>
                </form>
            </div>
            
            <!-- Modal Footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary submitBtn" onclick="submitContactForm()">SUBMIT</button>
            </div>
            
        </div>
    </div>
</div>
                  
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content --><?=$cartCore->get_footer();?>
        <!-- /footer content -->
      </div>
    </div>
    
        <script>
function submitContactForm(){
    var PRECENTAGE = $('#PRECENTAGE').val();
	var AMOUNT = $('#AMOUNT').val();
	
	 if(PRECENTAGE.trim() == '' ){
        alert('Please enter Type.');
        $('#PRECENTAGE').focus();
        return false;
    }else if(AMOUNT.trim()== ''){
        alert('Please enter valid Amount.');
        $('#AMOUNT').focus();
        return false;
    }else{
        $.ajax({
            type:'POST',
            url:'add_shipping_setting.php?token_id=<?=$TOKEN_ID?>',
            data:'contactFrmSubmit=1&PRECENTAGE='+PRECENTAGE+'&AMOUNT='+AMOUNT,
            beforeSend: function () {
                $('.submitBtn').attr("disabled","disabled");
                $('.modal-body').css('opacity', '.5');
            },
            success:function(msg){
                if(msg == 'ok'){
                    $('.statusMsg').html('<span style="color:green;">All Other Countries Shipping rule has been updated</span>');
                }else{
                   $('.statusMsg').html('<span style="color:green;">All Other Countries Shipping rule has been updated.</span>');
                }
                $('.submitBtn').removeAttr("disabled");
                $('.modal-body').css('opacity', '');
            }
        });
    }
}
</script>

    <!-- jQuery -->
    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="../vendors/nprogress/nprogress.js"></script>
    <!-- validator -->
    <script src="../vendors/validator/validator.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
  </body>
</html>