   <?php
   // CRUD 
   @$getId = base64_decode(anti_injection($_GET['id']));  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM promotions WHERE id = + $getId");
        $result = mysql_fetch_array($query);
    }
    
    if(isset ($_POST['save'])){
	$code = $_POST['code'];
	$valor = $_POST['valor'];
	$date = date('Y-m-d');

	$crud = new crud('promotions');  // table
    $crud->inserir("code,valor,date,status", "'$code','$valor','$date','S'");

	header("Location: index.php?mod=Promotions&y=1"); // redirect send mail ok
    
	
	}
	
	if(isset($_POST['update'])) {
	$name = $_POST['name'];
	$valor = $_POST['valor'];
	$date = date('Y-m-d');

	$registerID = $_POST['registerID'];
	
	$crud = new crud('promotions'); // Table
    $crud->atualizar("valor='$valor',date='$date'", "id='$registerID'");
	
	header("Location: index.php?mod=Promotions&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('promotions'); // Table
    $crud->excluir("id = $id"); // ID
    
    header("Location: index.php?mod=Promotions&y=3");
    }
    
    
    ?>
    
      
    <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <?php echo $lang['TITLE_NEW_PROMOTION']; ?>
          </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['PROMOTIONS']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form role="form" method="POST" id="Promotion" name="Promotion">

					
                  <div class="box-body">
					  
				
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PROMOTION_CODE']; ?></label>
                      <input type="text" class="form-control" name="code" id="code" value="<?php if (@$result['id'] <> '') { ?><?php echo @$result['code']; ?><? } else { ?>OFF<?php echo rand(111111,999999); ?><?php } ?>" required>
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PROMOTION_VALOR']; ?></label>
                    <input type="number" min="0" max="100" class="form-control" name="valor" id="valor" value="<?php echo @$result['valor']; ?>" required>
                    </div>
                    
                  
                  
                  <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-body -->

                 
                
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
           
         
           
          </div><!-- /.row -->
        </section><!-- /.content -->
       
        
      </div><!-- /.content-wrapper -->
   
   
   
   
