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

	$crud = new crud('cms');  // table
    $crud->inserir("page,title,content,menu,status", "'$page','$title','$content','1','S'");

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

      $("#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>
        Content Management System
            <small>CMS</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">CMS</h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form role="form" method="POST" id="CMS" name="CMS">

					
                  <div class="box-body">
					  
					 
                    <div class="form-group">
                      <label for="Input">Name Page</label>
                      <input type="text" class="form-control" name="page" id="page" value="<?php echo @$result['page']; ?>" required>
                    </div>
                    
                    <div class="form-group">
                      <label for="Input">Title Page</label>
                      <input type="text" class="form-control" name="title" id="title" value="<?php echo @$result['title']; ?>" required>
                    </div>
                    
                    <div class="form-group">
                    <textarea id="editor1" name="content" class="form-control" style="height: 300px" placeholder="CMS" required><?php echo @$result['content']; ?></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 -->
   
   
   
   
