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

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

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

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

      $("#msg").wysihtml5();
        CKEDITOR.replace('editor1', {
		allowedContent: true
		});  

	});
     
	</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_TUTORIAL']; ?>
            <small><?php echo $lang['SLOGAN_NEW_TUTORIAL']; ?></small>
          </h1>
          
        </section>

       
       <!-- Main content -->
        <section class="content">
          <div class="row">
			  
			  
            <!-- left column -->
            <div class="col-md-12">
              <!-- general form elements -->
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['TUTORIALS']; ?></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']; ?></label>
                    <select id="category" name="category" class="form-control select2" style="width: 100%;">
                    <option value="">Select</option>
                    <?php
					$cdecc = mysql_query("SELECT * FROM category order by name ASC");
					while($depart = mysql_fetch_array($cdecc)){ 
					?>
                    <option value="<?php echo $depart['id']; ?>" <?php if (@$result['category'] == $depart['id']) { echo "selected"; } ?>><?php echo $depart['name']; ?></option>
				    <?php } ?> 
				    </select>
                    </div>
				
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['TUTORIAL_TITLE']; ?></label>
                      <input type="text" class="form-control" name="title" id="title" value="<?php echo @$result['title']; ?>">
                    </div>
                    
                    <div class="form-group">
                    <textarea id="editor1" name="description" class="form-control" style="height: 300px" placeholder="<?php echo $lang['TUTORIAL_FORM_MSG']; ?>" required><?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 -->
   
   
   
   
