ok

Mini Shell

Direktori : /proc/thread-self/root/home2/selectio/public_html/thedentalpark.com/admin/
Upload File :
Current File : //proc/thread-self/root/home2/selectio/public_html/thedentalpark.com/admin/course-add.php

<?php  include("header.php");
error_reporting(E_ALL);

if(isset($_POST['course_name'])) {
    try {
        
        $course_name = $_POST['course_name'] ?  $_POST['course_name'] : '';
        $college_id = $_POST['college_id'] ?  $_POST['college_id'] : '';
        $status = $_POST['status'] ?  $_POST['status'] : '';
        $update_id = $_POST['update_id'] ?  $_POST['update_id'] : '';
        
        $date = date("Y-m-d H:i:s");

       

        if($update_id){

            
        	$statement = $pdo->prepare("UPDATE tbl_course SET course_name=?, college_id=?, status=?, created_at=? WHERE id=?");
            $statement->execute(array($course_name,$college_id,$status,$date,$update_id));
            
            // Check result of database operation
            if($statement) {
                $_SESSION['course_success_message'] = 'Course Details Updated Successfully' ;
                header("Location: course-list.php");
                exit;
            } else {
                 $_SESSION['course_error_message'] = 'Error Occured Not Added';
                header("Location: course-add.php");
                exit;
            }
         
        }else{
             


          	// Inserting the slider details into the database
    		$statement = $pdo->prepare("INSERT INTO tbl_course (course_name, college_id, status, created_at) VALUES (?,?,?,?)");
    		$statement->execute(array($course_name, $college_id, $status, $date));

            // Check result of database operation
            if($statement) {
                $_SESSION['course_success_message'] = 'Course Details Added Successfully' ;
                 header("Location: course-list.php");
                exit;
            } else {
                 $_SESSION['course_error_message'] = 'Error Occured Not Added';
                  header("Location: course-add.php");
                exit;
            }  
           
        }

    } catch(Exception $e) {
        $_SESSION['course_error_message'] =  $e->getMessage();  
        header("Location: course-add.php");
        exit;
    }
}


if(isset($_GET['id']) && $_GET['id']!=''){
    
    $id = isset($_GET['id']) ? $_GET['id'] : '';
    
    $statement = $pdo->prepare("SELECT * FROM tbl_course WHERE id=?");
	$statement->execute(array($id));
	$edit_result = $statement->fetchAll(PDO::FETCH_ASSOC);
	$edit_count = $statement->rowCount();
	
	
	$course_name = $edit_result[0]['course_name'];
	$college_id = $edit_result[0]['college_id'];
	$status = $edit_result[0]['status'];
}
 
?>

    <div class="content-wrapper" style="background-color: white;">

        <div class="clearfix"></div>
        
        <section class="content">
            
            <div class="row">
                <div class="col-xs-12">
                    <?php if(!empty($_SESSION['course_error_message'])) { ?>
                		<div class="callout callout-danger">
                			<p><?php echo $_SESSION['course_error_message']; ?></p>
                		</div>
            		<?php  unset($_SESSION['course_error_message']); }?>
            
            		<?php if(!empty($_SESSION['course_success_message'])){ ?>
                		<div class="callout callout-success">
                			<p><?php echo $_SESSION['course_success_message']; ?></p>
                		</div>
            		<?php  unset($_SESSION['course_success_message']); } ?>
        		</div>
            </div>
            
            <div class="row">
                <div class="col-xs-12">
                    <div>
                        <div class="box-header">
                            <h3 class="box-title"><b><?php if(isset($_GET['id']) && $_GET['id']!=''){ echo 'Update';}else { echo 'Add';} ?> Course: </b></h3>
                        </div>
                        
                        <div class="box box-info">
                            <div class="box-body" style="box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;">
                                <div class="col-lg-12">
                                    <div id="content-div">
                                        <form action="" enctype="multipart/form-data" method="post" id="course_form" accept-charset="utf-8">
                                            <div class="row">
                                                <input type="hidden" name="update_id" id="update_id" value="<?php echo (isset($_GET['id']) ? $_GET['id'] : '') ?>">
                                        
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="required" for="course_name">Course Name</label>                                    
                                                        <input type="text" name="course_name"  id="course_name" value="<?php echo (isset($course_name) ? $course_name : '') ?>" placeholder="Enter Course Name" class="form-control" />
                                                    </div>
                                                </div>
                                                
                                                
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="required" for="college_id">College Name</label>                                   
                                                        <select name="college_id" class="form-control select2" style="width:100%" id="college_id" required="required">
                                                            <option value="">Select College Name</option>
                                                            <?php $statement = $pdo->prepare("SELECT * FROM `tbl_college` where status=1");
                                                                $statement->execute();
                                                                $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                                foreach ($location_result as $result) { ?>
                                                                    <option value="<?=$result['id']?>"  <?php if(!empty($college_id) && $college_id==$result['id']){ echo "selected";} ?>><?=$result['college_name']?></option>
                                                            <?php  }  ?>
                                                        </select>
                                                    </div>
                                                </div>
                                                
                                               
                                                
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="required" for="status">Status</label>
                                                        <select name="status" class="form-control select2" style="width:100%" id="status">
                                                            <option value="1" <?php if(!empty($status) && $status==1){ echo "selected";} ?>>Active</option>
                                                            <option value="0" <?php if(!empty($status) && $status==0){ echo "selected";} ?>>In-Active</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                
                                            </div>
                                            <div class="row">
                                                <div class="form-group" style="text-align:center;">
                                                    <button type="submit" id="submit_course" name="submit_course" class="btn btn-success"><?php if(isset($_GET['id']) && $_GET['id']!=''){ echo 'Update';}else { echo 'Add';} ?> Course</button>
                                                </div>
                                            </div>
                                        </form>
                                        
                                        <div class="form-group" style="text-align:center;">
                                            <a href="course-add.php"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a>
                                            <a href="course-list.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a>
                                        </div>
                                    </div>
                               
                                    
                                    <div class="clearfix"></div>
                                </div>
                            </div>
                        </div> 
                    </div>
                </div>
            </div>
        </section>


<?php include "footer.php";?>

<script type="text/javascript">

    $(document).ready(function() {

            $.validator.addMethod("large_text_field",function(value,element){
                if(value){
                    return this.optional(element) || (/[\=\<\>]+/.test(value))? false : true;
                }else{
                    return true;
                }
            },"Don't Use '=' Symbol and Tag '<>' Symbol ");

            $('#course_form').validate({
                rules:{
                    'course_name': {
                        required: true,
                        large_text_field:true,
                        maxlength: 200
                    },
                    'college_id': {
                        required: true
                    },
                    'status':{
                       required: true
                    }
                   
                },
                errorPlacement: function(error, element) {
                    var ername = element.attr('name');
                    error.css('color', 'red');
                    element.parents('.form-group').append(error);
                   
                },
                messages:{

                },
                submitHandler: function(form){
                     
                    $('#submit_course').attr('disabled',true).text("Processing...");
                    form.submit();
                    
                }


            });

        });
</script>

Zerion Mini Shell 1.0