   <?php
   // CRUD 
   @$getId = base64_decode(anti_injection($_GET['id']));  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM domains WHERE id = + $getId");
        $result = mysql_fetch_array($query);
    }
    
    if(isset ($_POST['save'])){
	$customer = $_POST['customer'];
	$domain = $_POST['domain'];
	$tdl = $_POST['tdl'];
	$dns1 = $_POST['dns1'];
	$dns2 = $_POST['dns2'];
	$date_register = $_POST['date_register'];
	$date_expire = $_POST['date_expire'];
	$amount = $_POST['amount'];
	$amount_recurrent = $_POST['amount_recurrent'];
	$period = $_POST['period'];
	$epp = $_POST['epp'];
	$obs = $_POST['obs'];
	$status = 'S';
	
	$crud = new crud('domains');  // table
    $crud->inserir("customer,domain,tdl,dns1,dns2,date_register,date_expire,amount,amount_recurrent,period,epp,obs,status", "'$customer','$domain','$tdl','$dns1','$dns2','$date_register','$date_expire','$amount','$amount_recurrent','$period','$epp','$obs','$status'");

	header("Location: index.php?mod=Domains&y=1"); // redirect send mail ok
    
	
	}
	
	if(isset($_POST['update'])) {
	$customer = $_POST['customer'];
	$domain = $_POST['domain'];
	$tdl = $_POST['tdl'];
	$dns1 = $_POST['dns1'];
	$dns2 = $_POST['dns2'];
	$date_register = $_POST['date_register'];
	$date_expire = $_POST['date_expire'];
	$amount = $_POST['amount'];
	$amount_recurrent = $_POST['amount_recurrent'];
	$period = $_POST['period'];
	$epp = $_POST['epp'];
	$obs = $_POST['obs'];
	$registerID = $_POST['registerID'];
	
	$crud = new crud('domains'); // Table
    $crud->atualizar("customer='$customer',domain='$domain',tdl='$tdl',dns1='$dns1',dns2='$dns2',date_register='$date_register',date_expire='$date_expire',amount='$amount',amount_recurrent='$amount_recurrent',period='$period',epp='$epp',obs='$obs'", "id='$registerID'");
	
	$domainTLD = $domain . "" . $tdl;
	
	$above = $config['above'];
	update_dns($domainTLD,$above,$dns1,$dns2);
	
	
	header("Location: index.php?mod=Domains&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('domains'); // Table
    $crud->excluir("id = $id"); // ID
    
    header("Location: index.php?mod=Domains&y=3");
    }
    
    
    ?>
    <!-- JAVASCRIPT -->
      <script type="text/javascript">
     $().ready(function() {

		$("#RegisterDomain").validate({
			rules: {
				
				domain: "required",
				dns1: "required",
				dns2: "required",
				date_register: "required",
				date_expire: "required",
				amount: "required",
				amount_recurrent: "required",
				period: "required"
			},
			messages: {
				domain: "<?php echo $lang['VALIDATE_DOMAIN']; ?>",
				dns1: "<?php echo $lang['VALIDATE_DNS']; ?>",
				dns2: "<?php echo $lang['VALIDATE_DNS']; ?>",
				date_register: "<?php echo $lang['VALIDATE_DATE']; ?>",
				date_expire: "<?php echo $lang['VALIDATE_DATE']; ?>",
				amount: "<?php echo $lang['VALIDATE_AMOUNT']; ?>",
				amount_recurrent: "<?php echo $lang['VALIDATE_AMOUNT']; ?>",
				period: "<?php echo $lang['VALIDATE_PERIOD']; ?>"
			}
		});

	});
      $(function () {
        //Initialize Select2 Elements
        $(".select2").select2();
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "mm/dd/yyyy"});
        
        });
   
	</script>
    <!-- END -->  
      
    <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <?php echo $lang['TITLE_NEW_DOMAIN']; ?>
            <small><?php echo $lang['NEW_DOMAIN']; ?></small>
          </h1>
          
        </section>

       
       <!-- Main content -->
        <section class="content">
          <div class="row">
			  
			  
            <!-- left column -->
            <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['SLOGAN_REGISTER_DOMAIN']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form role="form" method="POST" id="RegisterDomain" name="RegisterDomain">
				<input type="hidden" name="len" id="pass-len" value="8">
					
                  <div class="box-body">
					  
				   <div class="form-group">
                   <label for="Input"><?php echo $lang['DOMAIN']; ?></label>
                   <div class="input-group ">
					
                    <input type="text" class="form-control" name="domain" id="domain" value="<?php echo $result['domain']; ?>">
                    <span class="input-group-btn">
                    <select id="tdl" style="width:110px;" name="tdl" class="form-control">
                    <?php
					$catgn = mysql_query("SELECT * FROM tdl order by tdl ASC");
					while($tdl = mysql_fetch_array($catgn)){ 
					?>
                    <option value="<?php echo $tdl['tdl']; ?>" <?php if (@$result['tdl'] == $tdl['tdl']) { echo "selected"; } ?>><?php echo $tdl['tdl']; ?></option>
				    <?php } ?> 
				    </select>
                    </span>
                   </div>
                   </div>
					  
					  
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['CUSTOMER']; ?></label>
                      <select id="customer" name="customer" class="form-control select2" style="width: 100%;">
						  <option value="">Select</option>
                    <?php
					$catcc = mysql_query("SELECT * FROM customers order by name ASC");
					while($custm = mysql_fetch_array($catcc)){ 
					?>
                    <option value="<?php echo $custm['id']; ?>" <?php if (@$result['customer'] == $custm['id']) { echo "selected"; } ?>><?php echo $custm['name']; ?> - <?php echo $custm['email']; ?></option>
				    <?php } ?> 
				    </select>
                    </div>
                    
                    
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['DNS1']; ?></label>
                      <input type="text" class="form-control" name="dns1" value="<?php echo @$result['dns1']; ?>">
                    </div>
                   
                  
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['DNS2']; ?></label>
                      <input type="text" class="form-control" name="dns2" value="<?php echo @$result['dns2']; ?>">
                    </div>
                    
                    <div class="form-group">
						<label for="Input"><?php echo $lang['DATE_REGISTER']; ?></label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                      </div>
                      <input type="text" class="form-control" id="date_register" name="date_register" value="<?php echo @$result['date_register']; ?>">
                    </div><!-- /.input group -->
                  </div>
                  
                  <div class="form-group">
						<label for="Input"><?php echo $lang['DATE_EXPIRE']; ?></label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                      </div>
                      <input type="text" class="form-control" id="date_expire" name="date_expire" value="<?php echo @$result['date_expire']; ?>">
                    </div><!-- /.input group -->
                  </div>
                  
                  
                  
                    
                   
                  </div><!-- /.box-body -->

                 
                
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
           
           <!-- left column -->
            <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-info">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['SLOGAN_DOMAIN']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
   
                  <div class="box-body">
					 
					<div class="form-group">
                      <label for="Input"><?php echo $lang['AMOUNT_DOMAIN']; ?></label>
                      <input type="text" name="amount" onKeyUp="moeda(this);" id="amount" value="<?php echo $result['amount']; ?>" class="form-control">
                    </div>
                    
					<div class="form-group">
                      <label for="Input"><?php echo $lang['AMOUNT_DOMAIN_RECURRENT']; ?></label>
                      <input type="text" name="amount_recurrent" onKeyUp="moeda(this);" id="amount_recurrent" value="<?php echo $result['amount_recurrent']; ?>" class="form-control">
                    </div>
                 
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['DOMAIN_PERIOD']; ?></label>
                      <input type="number" min="1" max="10" name="period" id="period" value="<?php echo $result['period']; ?>" class="form-control">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['DOMAIN_EPP']; ?></label>
                      <input type="text" name="epp" value="<?php echo $result['epp']; ?>" class="form-control">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['DOMAIN_OBS']; ?></label>
                      <textarea name="obs" class="form-control"><?php echo $result['obs']; ?></textarea>
                    </div>
                 
                   
                  </div><!-- /.box-body -->

                  <div class="box-footer">
					  
		  <?php if (@$result['id'] <> '') { ?>

		  <input type="submit" value="<?php echo $lang['UPDATE']; ?>" name="update" style="text-transform:uppercase" class="btn btn-info btn-lg btn-block">
		  <input type="hidden" name="registerID" value="<?php echo @$result['id']; ?>"> 
		  <? } else { ?>
		  <input type="submit" value="<?php echo $lang['REGISTER']; ?>" name="save" style="text-transform:uppercase" class="btn btn-success btn-lg btn-block">
		  <?php } ?>
					  
                  </div>
                  
                 
                </form>
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
          </div><!-- /.row -->
        </section><!-- /.content -->
       
        
      </div><!-- /.content-wrapper -->
   
   
   
   
