<?php 
include ("connection/conn.php");


if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $course_category = mysqli_real_escape_string($link, $_POST['course_category']);
    $subject = mysqli_real_escape_string($link, $_POST['subject']);

    if (!empty($course_category) && !empty($subject)) {
        $insertQuery = "INSERT INTO subjects (course_id, subject_name) VALUES ('$course_category', '$subject')";
        
        if (mysqli_query($link, $insertQuery)) {
            header("Location: manage-subjects.php?success=Subject has been added successfully.");
            exit();
        } else {
            echo "Error: " . mysqli_error($link);
        }
    } else {
        echo "Please select category and enter a subject name.";
    }
}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Administrator</title>
		<link href="css/bootstrap.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
		
	<script src="vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
	</head>
	
	<body>
		<div id="wrapper">
			<?php
				include("top-header.php");
				include("right-sec.php");
			?>
			<div id="page-wrapper" >
				<div id="page-inner">
					<div class="row">
						<div class="col-md-12">
							<h3 class="page-header">
								Add Course  <small></small>
							</h3>
							<div class="table-sec">
								<div class="srch_box">
									<form name="pnews" id="pnews" method="post" action="" enctype="multipart/form-data">
    <div class="row">
        <div class="col-md-12 col-xs-12">
            <div class="pnl_box"> 
                <div class="col-md-12 col-xs-6">    
                    <div class="form-group form-select">
                        <label>Category <span>*</span></label>
                        <select name="course_category" id="course_category" class="form-control">
                            <option value="">Select Category</option>
                            <?php
                            $sqlcourse="SELECT * FROM course_category ORDER BY id ASC";
                            $resultcourse=mysqli_query($link,$sqlcourse);
                            while($findcourse=mysqli_fetch_array($resultcourse)){ ?>
                                <option value="<?php echo $findcourse['id']; ?>"><?php echo $findcourse['course']; ?></option>
                            <?php } ?>
                        </select>
                    </div>        
                </div>
                <div class="col-md-12 col-xs-6">    
                    <div class="form-group">
                        <label>Course Name <span>*</span></label>
                        <input type="text" name="subject" id="subject" class="form-control" placeholder="Enter Course Name" required>
                    </div>        
                </div>
            </div>    
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 col-xs-4">    
            <div class="btn_sec">
                <input type="submit" name="submit" value="Submit" />
            </div>
        </div>
    </div>
</form>

								</div>
							</div>
						</div>
					</div> 
				</div>
			</div>
			<div style="height:70px; clear:both">&nbsp;</div>
			<footer class="footer-sec">
				<div class="container">
					<div class="row">
						<div class="col-md-12">
							<p class="text-center">All right reserved. Template Design by: <a href="">aryansinstitute</a></p>
						</div>
					</div>
				</div>
			</footer>
		</div>
<!-- jQuery Js -->
		<script src="js/jquery-1.10.2.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/jquery.metisMenu.js"></script>
		<script src="js/custom-scripts.js"></script>
		<script src="vendors/jquery.validate.js" type="text/javascript"></script>
<script src="vendors/cms.js" type="text/javascript"></script>
<!--/.fluid-container-->
<link href="vendors/datepicker.css" rel="stylesheet" media="screen">
<link href="vendors/uniform.default.css" rel="stylesheet" media="screen">
<link href="vendors/chosen.min.css" rel="stylesheet" media="screen">
<link href="vendors/wysiwyg/bootstrap-wysihtml5.css" rel="stylesheet" media="screen">
<s<script src="vendors/wysiwyg/wysihtml5-0.3.0.js"></script>
<script src="vendors/wysiwyg/bootstrap-wysihtml5.js"></script>
<script src="vendors/wizard/jquery.bootstrap.wizard.min.js"></script>
<script src="assets/scripts.js"></script>
<script src="vendors/ckeditor/ckeditor.js"></script>
<script src="vendors/ckeditor/adapters/jquery.js"></script>
<script>
$(function() {
	// Bootstrap
	$('#bootstrap-editor').wysihtml5();

	// Ckeditor standard
	$( 'textarea#ckeditor_standard' ).ckeditor({width:'98%', height: '150px', toolbar: [
		{ name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] },	// Defines toolbar group with name (used to create voice label) and items in 3 subgroups.
		[ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ],			// Defines toolbar group without name.
		{ name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
	]});
	$( 'textarea#ckeditor_full' ).ckeditor({width:'98%', height: '150px'});
});
</script>
	</body>
</html>
