<?php
   // CRUD 
   @$getId = base64_decode($_GET['id']);  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM tdl WHERE id = + $getId");
        $result = mysql_fetch_array($query);
    }
    
    if(isset ($_POST['save'])){
	$tdl = $_POST['tdl'];
	$amount = $_POST['amount'];
	$period = $_POST['period'];

	$crud = new crud('tdl');  // table
    $crud->inserir("tdl,amount,period", "'$tdl','$amount','$period'");

	header("Location: index.php?mod=PriceDomains&y=1"); // redirect send mail ok
    
	
	}
	
	if(isset($_POST['update'])) {
	$tdl = $_POST['tdl'];
	$amount = $_POST['amount'];
	$period = $_POST['period'];
	$registerID = $_POST['registerID'];
	
	$crud = new crud('tdl'); // Table
    $crud->atualizar("tdl='$tdl',amount='$amount',period='$period'", "id='$registerID'");
	
	header("Location: index.php?mod=PriceDomains&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('tdl'); // Table
    $crud->excluir("id = $id"); // ID
    
    header("Location: index.php?mod=PriceDomains&y=3");
    }
    
    
    ?>
    
   
    <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <?php echo $lang['TITLE_LIST_TDL']; ?>
            <small><?php echo $lang['LIST_TDL']; ?></small>
          </h1>
          
        </section>

       
       <section class="content">
          <div class="row">
            <div class="col-xs-12">
				
				<!-- ALERTS -->
				<?php if($_GET['y'] == '1') { ?>
				<div class="callout callout-success">
                    <h4><?php echo $lang['ALERT_DOMAINPRICE_NEW']; ?></h4>
                    <p><?php echo $lang['ALERT_DOMAINPRICE_NEW_TXT']; ?></p>
                  </div>
				<?php } ?>
				<?php if($_GET['y'] == '2') { ?>
				<div class="callout callout-success">
                    <h4><?php echo $lang['ALERT_DOMAINPRICE_UPDATE']; ?></h4>
                    <p><?php echo $lang['ALERT_DOMAINPRICE_UPDATE_TXT']; ?></p>
                  </div>
				<?php } ?>
				<?php if($_GET['y'] == '3') { ?>
				<div class="callout callout-success">
                    <h4><?php echo $lang['ALERT_DOMAINPRICE_DELETE']; ?></h4>
                    <p><?php echo $lang['ALERT_DOMAINPRICE_DELETE_TXT']; ?></p>
                  </div>
				<?php } ?>
				
              <div class="box">
				  
                <div class="box-header">
                
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-hover">
                    <thead>
                      <tr>
                        <th><?php echo $lang['TDL']; ?></th>
                        <th><?php echo $lang['PRICE']; ?></th>
                        <th><?php echo $lang['PERIOD']; ?></th>
                        <th width="120"><?php echo $lang['ACTIONS']; ?></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
 		  			$query = mysql_query("SELECT * FROM tdl order by id ASC");
 		  			while($result = mysql_fetch_array($query)){ 
					?>
					<form method="POST" name="<?php echo $result['id']; ?>">
					<input type="hidden" name="registerID" value="<?php echo $result['id']; ?>">
		            <tr>
		            <td><input type="text" class="form-control" name="tdl" value="<?php echo $result['tdl']; ?>" required></td>
					<td><input type="text" class="form-control" onKeyUp="moeda(this);" name="amount" value="<?php echo number_format($result['amount'],2,'.',''); ?>" required></td>
					<td><input type="number" class="form-control" min="1" max="10" name="period" value="<?php echo $result['period']; ?>" required></td>
					<td><input type="submit" class="btn btn-info" name="update" value="<?php echo $lang['BTN_SAVE_UP']; ?>"> <a href="javascript:void(0);" onclick="javascript: if (confirm('<?php echo $lang['ALERT_BTN_DELETE']; ?>')) { window.location.href='?mod=PriceDomains&id=<?php echo base64_encode($result['id']); ?>&action=delete' } else { void('') };" class="btn btn-danger"><i class="fa fa-remove"></i></a></td>
		            </tr>
		            </form>
					<?php } ?>
					<form method="POST" name="PriceDomain" id="PriceDomain">
		            <tr>
		            <td><input type="text" class="form-control" name="tdl" id="tdl" required></td>
					<td><input type="text" class="form-control" onKeyUp="moeda(this);" name="amount" required></td>
					<td><input type="number" class="form-control" min="1" max="10" name="period" required></td>
					<td></td>
		            </tr>
		            <tr>
		            <td><input type="submit" value="<?php echo $lang['BTN_SAVE']; ?>" class="btn btn-success" name="save"></td>
					<td></td>
					<td></td>
					<td></td>
		            </tr>
		            </form>
                    </tbody>
                    <tfoot>
                      <tr>
                        <th><?php echo $lang['TDL']; ?></th>
                        <th><?php echo $lang['PRICE']; ?></th>
                        <th><?php echo $lang['PERIOD']; ?></th>
                        <th><?php echo $lang['ACTIONS']; ?></th>
                      </tr>
                    </tfoot>
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
       
           </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
       
       
        
        
      </div><!-- /.content-wrapper -->
   
   
   
   
