<?php 
    include("../db.php");
    if($_POST){

        if(isset($_FILES["principal_photo"]["name"]) && !empty($_FILES["principal_photo"]["name"])){
    		$lfilename = basename($_FILES['principal_photo']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		echo "$lnewfile";
    		if(move_uploaded_file($_FILES['principal_photo']['tmp_name'],"../uploads/".$lnewfile)){
    		    echo "hello";
    		    $_POST['principal_photo'] = $lnewfile;
    		}
    	}
    
       if(isset($_FILES["director_photo"]["name"]) && !empty($_FILES["director_photo"]["name"])){
    		$lfilename = basename($_FILES['director_photo']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		echo "$lnewfile";
    		if(move_uploaded_file($_FILES['director_photo']['tmp_name'],"../uploads/".$lnewfile)){
    		    echo "hello";
    		    $_POST['director_photo'] = $lnewfile;
    		}
    	}
    
        if(isset($_FILES["logo"]["name"]) && !empty($_FILES["logo"]["name"])){
    		$lfilename = basename($_FILES['logo']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		if(move_uploaded_file($_FILES['logo']['tmp_name'],"../uploads/".$lnewfile)){
    		    $_POST['logo'] = $lnewfile;
    		}
    	}

   if(isset($_FILES["announcement_photo"]["name"]) && !empty($_FILES["announcement_photo"]["name"])){
    		$lfilename = basename($_FILES['announcement_photo']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		if(move_uploaded_file($_FILES['announcement_photo']['tmp_name'],"../uploads/".$lnewfile)){
    		    $_POST['announcement_photo'] = $lnewfile;
    		}
    	}

   if(isset($_FILES["toppers_photo"]["name"]) && !empty($_FILES["toppers_photo"]["name"])){
    		$lfilename = basename($_FILES['toppers_photo']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		if(move_uploaded_file($_FILES['toppers_photo']['tmp_name'],"../uploads/".$lnewfile)){
    		    $_POST['toppers_photo'] = $lnewfile;
    		}
    	}
 if(isset($_FILES["Popup_image"]["name"]) && !empty($_FILES["Popup_image"]["name"])){
    		$lfilename = basename($_FILES['Popup_image']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		if(move_uploaded_file($_FILES['Popup_image']['tmp_name'],"../uploads/".$lnewfile)){
    		    $_POST['Popup_image'] = $lnewfile;
    		}
    	}

        $db->updateAry("site_setting", $_POST, "where id='1'");
        
        header("Location: site_setting");
    }
?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Dashboard</title>
    <?php include("meta.php"); ?>

</head>
<body> 
 
<?php include("header.php"); ?>

<?php include("sidebar.php"); 

    $data = $db->getRow("select * from site_setting where id='1' ");

?>

<div class="main">
    
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="content-div">
                    <h2>SITE SETTINGS</h2>
                    
                    <form action="" method="post" enctype="multipart/form-data">
                        <div class="form-row row">
                            <div class="col-md-2"><label>School Name</label></div>
                            <div class="col-md-10"><input type="text" name="school_name" class="form-control" value="<?php echo $data["school_name"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>School Address</label></div>
                            <div class="col-md-10"><input type="text" name="address" class="form-control" value="<?php echo $data["address"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>School Email</label></div>
                            <div class="col-md-10"><input type="text" name="email" class="form-control" value="<?php echo $data["email"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Contact No.</label></div>
                            <div class="col-md-10"><input type="text" name="contact" class="form-control" value="<?php echo $data["contact"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Working Hours</label></div>
                            <div class="col-md-10"><input type="text" name="working_hrs" class="form-control" value="<?php echo $data["working_hrs"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Admin uname</label></div>
                            <div class="col-md-10"><input type="text" name="admin_uname" class="form-control" value="<?php echo $data["admin_uname"]; ?>"></div>
                        </div>
                         <div class="form-row row">
                            <div class="col-md-2"><label>Link</label></div>
                            <div class="col-md-10"><input type="text" name="link" class="form-control" value="<?php echo $data["link"]; ?>"></div>
                        </div>
                        
                        <div class="form-row row">
                            <div class="col-md-2"><label>Admin Pwd</label></div>
                            <div class="col-md-10"><input type="text" name="admin_pwd" class="form-control" value="<?php echo $data["admin_pwd"]; ?>"></div>
                        </div>
                         <div class="form-row row">
                            <div class="col-md-2"><label>Director's Message</label></div>
                            <div class="col-md-10"><textarea rows="5" name="director_msg" class="form-control"><?php echo $data["director_msg"]; ?></textarea></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Principal's Message</label></div>
                            <div class="col-md-10"><textarea rows="5" name="principal_msg" class="form-control"><?php echo $data["principal_msg"]; ?></textarea></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Marquee News</label></div>
                            <div class="col-md-10"><input type="text" name="marquee" class="form-control" value="<?php echo $data["marquee"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Theme Color Code</label></div>
                            <div class="col-md-10"><input type="text" name="color_code" class="form-control" value="<?php echo $data["color_code"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Facebook Link</label></div>
                            <div class="col-md-10"><input type="text" name="facebook" class="form-control" value="<?php echo $data["facebook"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>YouTube</label></div>
                            <div class="col-md-10"><input type="text" name="youtube" class="form-control" value="<?php echo $data["youtube"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Twitter</label></div>
                            <div class="col-md-10"><input type="text" name="twitter" class="form-control" value="<?php echo $data["twitter"]; ?>"></div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>LinkedIn</label></div>
                            <div class="col-md-10"><input type="text" name="linkedin" class="form-control" value="<?php echo $data["linkedin"]; ?>"></div>
                        </div>
                         <div class="form-row row">
                            <div class="col-md-2"><label>Director Photo</label></div>
                            <div class="col-md-10"><input type="file" name="director_photo" class="form-control" />
                                <?php if($data["director_photo"]!=""){ ?>
                                    <img src="../uploads/<?php echo $data["director_photo"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Principal Photo</label></div>
                            <div class="col-md-10"><input type="file" name="principal_photo" class="form-control" />
                                <?php if($data["principal_photo"]!=""){ ?>
                                    <img src="../uploads/<?php echo $data["principal_photo"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Announcement Photo</label></div>
                            <div class="col-md-10"><input type="file" name="announcement_photo" class="form-control" />
                                <?php if($data["announcement_photo"]!=""){ ?>
                                    <img src="../uploads/<?php echo $data["announcement_photo"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>Topper's Photo</label></div>
                            <div class="col-md-10"><input type="file" name="toppers_photo" class="form-control" />
                                <?php if($data["toppers_photo"]!=""){ ?>
                                    <img src="../uploads/<?php echo $data["toppers_photo"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                        </div>
                        <div class="form-row row">
                            <div class="col-md-2"><label>School Logo</label></div>
                            <div class="col-md-10"><input type="file" name="logo" class="form-control" />
                                <?php if($data["logo"]!=""){ ?>
                                    <img src="../uploads/<?php echo $data["logo"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                        </div><br>
                                                <div class="form-row row">
                            <div class="col-md-2"><label>Popup Image</label></div>
                            <div class="col-md-10"><input type="file" name="Popup_image" class="form-control" />
                                <?php if($data["Popup_image"]!=""){ ?>
                                    <img src="../uploads/<?php echo $data["Popup_image"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                            </div>
                          <div style="margin-left: 18%;">
                               
                               <label >Show</label>
                               <?php if($data["shows"]==1){ ?>
                                <input type="radio" name="shows" value="1" checked  />
                                <?php } 
                                else{
                                ?>
                                <input type="radio" name="shows" value="1"   />
                                <?php } ?>
                                <label >Hide</label>
                               <?php if($data["shows"]==0){ ?>
                                <input type="radio" name="shows" value="0" checked  />
                                <?php } 
                                else{
                                ?>
                                <input type="radio" name="shows" value="0"   />
                                <?php } ?>
                           </div>
                            
                        <br>
                        <div class="form-row form-check text-center"><input type="submit" class="btn btn-primary" value="Save Changes"></div>
                    </form>
                    
                </div>

            </div>   
        </div>
    </div>
    
</div>
     
</body>
</html> 
