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

	$crud = new crud('category');  // table
    $crud->inserir("name,description", "'$name','$description'");

	header("Location: index.php?mod=Categories&y=1"); // redirect send mail ok
    
	
	}
	
	if(isset($_POST['update'])) {
	$name = $_POST['name'];
	$description = $_POST['description'];

	$registerID = $_POST['registerID'];
	
	$crud = new crud('category'); // Table
    $crud->atualizar("name='$name',description='$description'", "id='$registerID'");
	
	header("Location: index.php?mod=Categories&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('category'); // Table
    $crud->excluir("id = $id"); // ID
    
    header("Location: index.php?mod=Categories&y=3");
    }
    
    
    ?>
    <!-- JAVASCRIPT -->
     <script>
     $().ready(function() {

		$("#Department").validate({
			rules: {
				
				name: "required"
				
			},
			messages: {
				name: "<?php echo $lang['VALIDATE_CATEGORY']; ?>"
			}
		});

	});
     
	</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_CATEGORY']; ?>
            <small><?php echo $lang['SLOGAN_NEW_CATEGORY']; ?></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['CATEGORIES']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form role="form" method="POST" id="Department" name="Department">

					
                  <div class="box-body">
					  
				
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['CATEGORY_NAME']; ?></label>
                      <input type="text" class="form-control" name="name" id="name" value="<?php echo @$result['name']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['CATEGORY_DESCRIPTION']; ?></label>
                    <textarea name="description" class="form-control" id="msg"><?php echo @$result['description']; ?></textarea>
                    </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 -->
   
   
   
   
