<?php
$page_title = "Add Resource | CES Admin";
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/common_functions.php"); //common functions in the course registartion system
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/config.php"); //holds global config variables
check_if_authenticated('admin');//check if user is logged in
if(isset($_POST['submit'])){
//form has been submitted, don't prompt for info; add form data to database and show what has been added
$db = mysqli_connect($mysql_server, $user, $pass, $database);
$title = htmlentities($_POST['title'], ENT_QUOTES);
$url = htmlentities($_POST['url'], ENT_QUOTES);
$tel = htmlentities($_POST['tel'], ENT_QUOTES);
$description = htmlentities($_POST['description'], ENT_QUOTES);
$organization = htmlentities($_POST['organization'], ENT_QUOTES);
$sql = "INSERT INTO ces_resources (title, url, phone, description, organization, created) VALUES (\"$title\", \"$url\", \"$tel\", \"$description\", \"$organization\", NOW())";
if(mysqli_query($db, $sql)){ //if the update is successful show the new entry
$last_id = mysqli_insert_id($db);
header("location:index.php#".$last_id);
exit;
} //end if
else {//else the update did not happen so output an error
$msg = return_sql_error('Error - resources submission failed when doing:', $sql);
}//else
}
include_once($_SERVER['DOCUMENT_ROOT'] . "/admin/php/top-admin.php"); //get the HTML heading common to all pages in the CES admin module
?>
<article class="ces-admin">
<h2>CES Admin - Add Resource</h2>
<?php
include_once($_SERVER['DOCUMENT_ROOT'] . "/admin/php/nav-admin.php");
if (isset($msg)){
echo "<p>".$msg."</p>";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<div class="form-group">
<label for="title">Title:</label>
<input class="form-control" type='text' id='title' name='title' placeholder="Resource Title" autofocus required>
</div>
<div class="form-group">
<label for="url">Link:</label>
<input class="form-control" type='url' id='url' name='url' placeholder="http://..." required>
</div>
<div class="form-group">
<label for="tel">Phone Number:</label>
<input class="form-control" type='tel' id='tel' name='tel' placeholder="403-955-1234" >
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea class="form-control" rows='8' style="height:auto; resize:none;" name='description' wrap='soft' required placeholder="Resource Description"></textarea>
</div>
<div class="form-group">
<label for="organization">Organization:</label>
<input class="form-control" type='text' id='organization' name='organization' placeholder="Organization" >
</div>
<input type='submit' name='submit' value="Add Resource" class="btn ces-green-btn">
<input type='reset' name='reset' value="Reset Form" class="btn ces-grey-btn">
<a class="btn ces-orange-btn" href="/admin/resources/">Cancel</a>
</form>
</article>
</section><!-- #middle-->
</div><!-- #wrapper -->
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/require/footer.php';?>