<?php

session_start();
include "includes/functions.php";
//this function writes the header for the html document and takes the title for the page as a parameter
docheader("Cupcake Country - Cupcake");
include "includes/header.php";
include "includes/navbar.php";
include "includes/passwords.php";
//The content of this page will be kept in the database and called through mysqli query in PHP
print "<div id=\"browseform\">\n";
print "<h3>Specialty Cupcakes</h3>\n<p>";
$mysqli = new PDO("mysql:host=localhost; dbname=info230_SP12FP_Cupcake_Warriors", $dbname, $dbpassword);
$query = "SELECT sc_name FROM Spec_Cupcakes";
$result = $mysqli->query($query);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
    foreach ($row as $index => $data) {
        print $data . "<br/>\n";
    }
}
print "</p>";
print "<h3>Flavors</h3>\n<p>";
$mysqli3 = new PDO("mysql:host=localhost; dbname=info230_SP12FP_Cupcake_Warriors", $dbname, $dbpassword);
$query = "SELECT fl_name FROM Flavors";
$result = $mysqli3->query($query);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
    foreach ($row as $index => $data) {
        print $data . "<br/>\n";
    }
}
print "</p>";
<?php

session_start();
include "includes/functions.php";
//this function writes the header for the html document and takes the title for the page as a parameter
docheader("Cupcake Country - About Us");
include "includes/header.php";
include "includes/navbar.php";
$file1 = fopen("textfiles/contact_info.txt", 'a');
$file2 = fopen("textfiles/about_baker.txt", 'a');
?>
    <div id='aboutbakermain'>
    <h2>Information about the baker.</h2>
    <p id="bakingpar"><img id="bakingpic" src="images/hands.PNG" height="345" width="300" alt="main cupcake" /></p>

    <div id="bakerbody">
    <?php 
$file1array = file("textfiles/contact_info.txt");
if (!$file1array) {
    print "<p>Could not load file1 (contact_info)</p>\n";
}
$file2array = file("textfiles/about_baker.txt");
if (!$file2array) {
    print "<p>Could not load file2 (about_baker)</p>\n";
}
print "<p>";
foreach ($file2array as $info2) {
    print $info2 . "<br/>";
}
?>
    </div>
<?php

session_start();
include "includes/functions.php";
//this function writes the header for the html document and takes the title for the page as a parameter
docheader("Cupcake Country - User Login");
include "includes/header.php";
include "includes/navbar.php";
include "includes/passwords.php";
print "<div id=\"user_login_body\">";
//connection to database
$mysqli = new PDO("mysql:host=localhost; dbname=info230_SP12FP_Cupcake_Warriors", $dbname, $dbpassword);
$mysqli2 = new PDO("mysql:host=localhost; dbname=info230_SP12FP_Cupcake_Warriors", $dbname, $dbpassword);
$mysqli4 = new PDO("mysql:host=localhost; dbname=info230_SP12FP_Cupcake_Warriors", $dbname, $dbpassword);
//case that logs out user
if (isset($_GET['logout']) && $_GET['logout'] == 'yes') {
    unset($_SESSION['logged_user']);
    session_destroy();
}
/* if no one is logged in and no one has tried to log in */
if (!isset($_POST['submit1']) && !isset($_POST['newsubmit']) && !isset($_SESSION['logged_user'])) {
    ?>
    <div id="login">
	<div class="formheader">
	    <h1>Log In</h1>
	</div>
    
	<div class="form">
	    <form action="user_login.php" method="post">
	        <p>Username:</p><input type="text" name="username" /><br /></p>
	        <p>Password:</p><input type="password" name="password" /><br /></p>
<?php

session_start();
include "includes/functions.php";
//this function writes the header for the html document and takes the title for the page as a parameter
docheader("Cupcake Country - Admin account");
include "includes/header.php";
include "includes/navbar.php";
include "includes/passwords.php";
$file1 = fopen("textfiles/contact_info.txt", 'r+');
$file2 = fopen("textfiles/about_baker.txt", 'r+');
if (isset($_POST['updatefiles'])) {
    file_put_contents("textfiles/contact_info.txt", "");
    file_put_contents("textfiles/about_baker.txt", "");
    fwrite($file1, $_POST['contactinfo']);
    fwrite($file2, $_POST['aboutbaker']);
}
?>
    <div id="adminbody">    
        <h1>Administrator</h1>
        <p><a href="index.php">Back to home</a><br/><a href="user_login.php?logout=yes">Sign out</a></p>
    <div id="addspecial">
<?php 
/* if the admin tried to upload a new cupcake */
if (isset($_POST['Uploadphoto'])) {
    /* check that all the forms were filled out
       INPUT STILL NEEDS TO BE CHECKED!!!! */
    if ($_FILES['newphoto']['error'] == 0 && trim($_POST['sc_name']) != "" && trim($_POST['description']) != "" && ($_POST['oldfl_name'] != "nothing" || trim($_POST['newfl_name']) != "" && trim($_POST['ic_price']) != "") && ($_POST['oldic_name'] != "nothing" || trim($_POST['newic_name']) != "" && trim($_POST['ic_price']) != "")) {
        move_uploaded_file($_FILES['newphoto']['tmp_name'], "images/" . $_FILES['newphoto']['name']);
        /* checks whether or not they invented a new flavor, or used an old one. */
        if (!($_POST['oldfl_name'] == 'nothing')) {
<?php

session_start();
include "includes/functions.php";
//this function writes the header for the html document and takes the title for the page as a parameter
docheader("Cupcake Country - Place An Order");
include "includes/header.php";
include "includes/navbar.php";
?>
<div id="creator">
<h1>Design Your Cupcake</h1>

	<div id="display"></div>
	<div class="form" id="flavor">
		<p>Choose a flavor</p>
		<form>
			<input class="flavortarget" type="radio" name="flavor" value="chocolate" />Chocolate<br />
			<input class="flavortarget" type="radio" name="flavor" value="vanilla" />Vanilla<br />
		</form>
	</div>
</div>

<?php 
/*When the form is done and checked through javascript,
 PHP will use mysqli to connect with the database and enter tuples for the orders
 and an e-mail will be sent to the administrator to inform them that an order has been placed and the client is awaiting correspondence
*/
include "includes/footer.php";
?>
</body>
</html>
<?php

session_start();
include "includes/functions.php";
//this function writes the header for the html document and takes the title for the page as a parameter
docheader("Cupcake Country - Home");
include "includes/header.php";
include "includes/navbar.php";
?>
<div id="mainbody">
	<div id="maincontent">
			<h3>Welcome to Cupcake Country!</h3>
			<p>
			We are a made-to-order cupcake company dedicated to unique,
			decadent flavors and beautiful decoration. With a Wilton-trained head chef,
			there are cupcakes that appeal to both the eyes and taste buds. 
			Order pre-made specialty cupcakes, or create your own from our choice flavors.
			Country Cupcakes are sure to add to any  occasion. 
			</p>
	</div>
	<p id="mainpar"><img id="mainpic" src="images/pink.PNG" height="375" width="500" alt="main cupcake" /></p>
</div>
    <?php 
include "includes/footer.php";
?>
</body>
</html>