<?php
session_start();
$added = false;
if (isset($_POST['insert'])) {
class MyDB extends SQLite3{
function __construct(){
$this->open('resources.db');
}
}
//Strip \'s from $_POST, needed because magic_quotes are turned on in php
//$_POST = array_map('stripslashes', $_POST);
$db = new MyDB();
// create SQL
$sql = "INSERT INTO resources
(section, category, topic, title, link, phone, description, organization, 'document one link', 'document one title', 'document two link', 'document two title', 'document three link', 'document three title', created, modified)
VALUES( :section,
:category,
:topic,
:title,
:link,
:phone,
:description,
:organization,
:docOneLink,
:docOneTitle,
:docTwoLink,
:docTwoTitle,
:docThreeLink,
:docThreeTitle,
:datecreated,
:datemodified)";
$stmt = $db->prepare($sql);
//setup parameter bindings
$stmt->bindParam(':section', $section);
$stmt->bindParam(':category', $category);
$stmt->bindParam(':topic', $topic);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':link', $link);
$stmt->bindParam(':phone', $phone);
$stmt->bindParam(':description', $description);
$stmt->bindParam(':organization', $organization);
$stmt->bindParam(':docOneLink', $docOneLink);
$stmt->bindParam(':docOneTitle', $docOneTitle);
$stmt->bindParam(':docTwoLink', $docTwoLink);
$stmt->bindParam(':docTwoTitle', $docTwoTitle);
$stmt->bindParam(':docThreeLink', $docThreeLink);
$stmt->bindParam(':docThreeTitle', $docThreeTitle);
$stmt->bindParam(':datecreated', $datecreated);
$stmt->bindParam(':datemodified', $datemodified);
//setup parameters
$section = $_POST['section'];
$category = $_POST['category'];
$topic = $_POST['topic'];
$title = $_POST['title'];
$link = $_POST['link'];
$phone = $_POST['phone'];
$description = $_POST['description'];
$organization = $_POST['organization'];
$docOneLink = $_POST['docOneLink'];
$docOneTitle = $_POST['docOneTitle'];
$docTwoLink = $_POST['docTwoLink'];
$docTwoTitle = $_POST['docTwoTitle'];
$docThreeLink = $_POST['docThreeLink'];
$docThreeTitle = $_POST['docThreeTitle'];
$datecreated = time();
$datemodified = time();
$stmt->execute();
if ($db->changes() > 0) {
$added = true;
}
$db->close();
}
if ($added || isset($_POST['cancel_add'])) {
//Session Information
if (!empty($_POST) && $added){
if(isset($_POST['section']))
$_SESSION['section'] = $_POST['section'];
if(isset($_POST['category']))
$_SESSION['category'] = $_POST['category'];
if(isset($_POST['topic']))
$_SESSION['topic'] = $_POST['topic'];
if(isset($_POST['items_to_show']))
$_SESSION['items_to_show'] = $_POST['items_to_show'];
}
// redirect back to admin page
header("Location: http://".$_SERVER['HTTP_HOST']."/admin/links/");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add Link | Links | Admin | The Family & Community Resource Centre</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/require/head.php');?>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<style>
th{
text-align: left;
}
h5 {
margin: 0;
padding: 0;
}
span.buttons{
float: right;
}
.pagination li{
margin: 0;
padding: 0;
}
form .btn {
margin-top:24px;
}
</style>
</head>
<body>
<div class="wrapper">
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/require/header.php');?>
<section class="middle">
<article style="width:100%;">
<h2>FCRC Links</h2>
<h3>Add Link</h3>
<hr>
<div style="clear:both;"></div>
<form id="form" method="post" action="add.php" role="form" style="clear:both;" enctype="application/x-www-form-urlencoded">
<h4>Link Information</h4>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="section">Section:</label>
<input name="section" type="text" id="section" placeholder="Section" class="form-control" list="sections" autocomplete="off">
<datalist id="sections">
<option value="Community Links">
<option value="Transition Resources">
</datalist>
</div>
<div class="form-group">
<label for="category">Category:</label>
<input name="category" type="text" id="category" placeholder="Category" class="form-control">
</div>
<div class="form-group">
<label for="topic">Topic:</label>
<input name="topic" type="text" id="topic" placeholder="Topic" class="form-control">
</div>
<div class="form-group">
<label for="title">Title:</label>
<input name="title" type="text" id="title" placeholder="Title" class="form-control">
</div>
<div class="form-group">
<label for="organization">Organization:</label>
<input name="organization" type="text" id="organization" placeholder="Organization" class="form-control">
</div>
</div>
<div class="form-group col-sm-6">
<label for="description">Description:</label>
<textarea name="description" id="description" placeholder="Description" class="form-control" rows="15"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-sm-4">
<label for="phone">Phone Number:</label>
<input name="phone" type="text" id="phone" placeholder="Phone" class="form-control">
</div>
<div class="form-group col-sm-8">
<label for="link">Link Address:</label>
<input name="link" type="url" id="link" placeholder="http://..." class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-sm-4">
<label for="docOneTitle">Document #1 Title:</label>
<input name="docOneTitle" type="text" id="docOneTitle" placeholder="Link Title" class="form-control">
</div>
<div class="form-group col-sm-8">
<label for="docOneLink">Document #1 Link:</label>
<input name="docOneLink" type="url" id="docOneLink" placeholder="http://..." class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-sm-4">
<label for="docTwoTitle">Document #2 Title:</label>
<input name="docTwoTitle" type="text" id="docTwoTitle" placeholder="Link Title" class="form-control">
</div>
<div class="form-group col-sm-8">
<label for="docTwoLink">Document #2 Link:</label>
<input name="docTwoLink" type="url" id="docTwoLink" placeholder="http://..." class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-sm-4">
<label for="docThreeTitle">Document #3 Title:</label>
<input name="docThreeTitle" type="text" id="docThreeTitle" placeholder="Link Title" class="form-control">
</div>
<div class="form-group col-sm-8">
<label for="docThreeLink">Document #3 Link:</label>
<input name="docThreeLink" type="url" id="docThreeLink" placeholder="http://..." class="form-control">
</div>
</div>
<div id="buttons">
<input type="submit" name="insert" id="insert" class="btn btn-success" value="Save New Entry">
<input type="submit" name="cancel_add" id="cancel_add" class="btn btn-danger" formnovalidate value="Cancel">
</div>
</form>
</article>
</section><!-- #middle-->
</div><!-- #wrapper -->
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/require/footer.php';?>