<?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['promo_code'])){
	$cartAdminMain->add_edit_coupon_details($userinfo['USERNAME'],$page_name,$TOKEN_ID,$COMPANY_ID);	
	exit;
}
?>

<script type="text/javascript">
function getCOUPON(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>
<!-- bootstrap-daterangepicker -->
    <link href="../vendors/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">
    <!-- bootstrap-datetimepicker -->
    <link href="../vendors/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css" rel="stylesheet">
        <!-- 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'] != "")
				{
					echo $cartCore->md5_base64_decode($_GET['pagename']);
				}
				else
				{
					echo $cartCore->getPageHeading($page_name);
				}
				?></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['promo_code']) && $_GET['promo_code'] != "")
		{	
				$encryptid=$_GET['promo_code'];	
				$rid=$cartCore->md5_base64_decode($encryptid);
				$rid = $cartCore->ClearInput($rid);
				$get_promo_info=$cartCore->fetch_cart_promo_by_promo_code_global_id($rid,$COMPANY_ID);
				$submit_status=true;		
		}
		else
		{		
				$encryptid=NULL;
				$get_promo_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_coupon.php?token_id=<?=$TOKEN_ID?>" method="post">
                     <input type="hidden" name="submit_status" value="<?=$submit_status?>" />
                     <input type="hidden" name="promo_code" value="<?=$encryptid?>" />
                     <input type="hidden" name="pagename" value="<?=$_GET['pagename']?>" />
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Coupon Code <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <?php if($submit_status==TRUE) { ?>
                          <input id="name" class="form-control col-md-7 col-xs-12" name="PROMO_CODE" required type="text" value="<?=$get_promo_info['PROMO_CODE']?>" readonly="readonly">
                          <?php
						}else
						{?>
                        <input id="name" class="form-control col-md-7 col-xs-12" name="PROMO_CODE" required type="text" value="<?=$get_promo_info['PROMO_CODE']?>" readonly="readonly">
                        <?php } ?>
                            
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Start date <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         <div class="form-group">
                        <div class='input-group date' id='myDatepicker1'>
                            <input type='text' class="form-control" name="DATE_FROM" readonly value="<?=$get_promo_info['DATE_FROM']?>" required="required"/>
                            <span class="input-group-addon">
                               <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                        </div>
                      </div>
                      
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">End date <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         <div class="form-group">
                        <div class='input-group date' id='myDatepicker2'>
                            <input type='text' class="form-control" name="DATE_TO" readonly required="required" value="<?=$get_promo_info['DATE_TO']?>"/>
                            <span class="input-group-addon">
                               <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Discount 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="getCOUPON(this.value);">
                          <?=$cartAdminMain->get_coupon_type_by_selected_option($get_promo_info['PRECENTAGE']);?>
                          </select>
                        </div>
                      </div>
                     
                       <div class="item form-group" id="test">
                        <label class="control-label col-md-3">Discount </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        
                        <?php
						if($get_promo_info['PROMO_DEDUCTION']==NULL)
						{
							echo '<input id="name" class="form-control col-md-7 col-xs-12 has-feedback-left" name="PROMO_DEDUCTION" required type="text" value="'.$get_promo_info['PROMO_DEDUCTION'].'">
                          <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_promo_info['PRECENTAGE']==1)
						{
							echo '<input id="name" class="form-control col-md-7 col-xs-12 has-feedback-left" name="PROMO_DEDUCTION" required type="text" value="'.$get_promo_info['PROMO_DEDUCTION'].'">
                          <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" name="PROMO_DEDUCTION" required type="text" value="'.$get_promo_info['PROMO_DEDUCTION'].'">
                          <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="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="occupation">Minimum Order Amount
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                      <input id="name" class="form-control col-md-7 col-xs-12 has-feedback-left" name="MINIMUM_ORDER_AMOUNT" required type="text" value="<?=$get_promo_info['MINIMUM_ORDER_AMOUNT']?>" required="required">
                          <span class="fa fa-money form-control-feedback left" aria-hidden="true"></span>
                          </div>
                  </div>
                      
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="occupation">Coupon 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="PROMO_DESCRIPTION" type="text" value="<?=$get_promo_info['PROMO_DESCRIPTION']?>"> 
                        </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>
                  
                  
                </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>
     <!-- bootstrap-daterangepicker -->
    <script src="../vendors/moment/min/moment.min.js"></script>
    <script src="../vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap-datetimepicker -->    
    <script src="../vendors/bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.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>
    
    <!-- Initialize datetimepicker -->
<script>
    
    $('#myDatepicker1').datetimepicker({
        ignoreReadonly: true,
        allowInputToggle: true,
		format: 'YYYY-MM-DD HH:mm:ss'
    });
	 $('#myDatepicker2').datetimepicker({
        ignoreReadonly: true,
        allowInputToggle: true,
		format: 'YYYY-MM-DD HH:mm:ss'
    });
</script>
	
  </body>
</html>