   <?php
   // CRUD 
   @$getId = base64_decode(anti_injection($_GET['id']));  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM departments WHERE id = + $getId");
        $result = mysql_fetch_array($query);
    }
    
    if(isset ($_POST['save'])){
	$name_department = $_POST['name_department'];
	$email_department = $_POST['email'];
	$crud = new crud('departments');  // table
    $crud->inserir("name_department,email_department", "'$name_department','$email_department'");

	header("Location: index.php?mod=Departments&y=1"); // redirect send mail ok
    
	
	}
	
	if(isset($_POST['update'])) {
	$name_department = $_POST['name_department'];
	$email_department = $_POST['email'];
	$registerID = $_POST['registerID'];
	
	$crud = new crud('departments'); // Table
    $crud->atualizar("name_department='$name_department',email_department='$email_department'", "id='$registerID'");
	
	header("Location: index.php?mod=Departments&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('departments'); // Table
    $crud->excluir("id = $id"); // ID
    
    header("Location: index.php?mod=Departments&y=3");
    }
    
    
    ?>
    <!-- JAVASCRIPT -->
     <script>
     $().ready(function() {

		$("#Department").validate({
			rules: {
				
				name_department: "required",
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				name_department: "<?php echo $lang['VALIDATE_DEPARTMENT']; ?>",
				email: "<?php echo $lang['VALIDATE_EMAIL']; ?>"
			}
		});

	});
     
	</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_DEPARTMENT']; ?>
            <small><?php echo $lang['NEW_DEPARTMENT']; ?></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['DEPARTMENT']; ?></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['DEPARTMENT_NAME']; ?></label>
                      <input type="text" class="form-control" name="name_department" id="name_department" value="<?php echo @$result['name_department']; ?>">
                    </div>
                   
                   <div class="form-group">
                      <label for="Input"><?php echo $lang['EMAIL']; ?></label>
                      <input type="email" class="form-control" name="email" value="<?php echo @$result['email_department']; ?>" placeholder="<?php echo $lang['EMAIL_PLACEHOLDER']; ?>">
                    </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 -->
   
   
   
   
