<?php
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();
$updated = false;
$OK = false;
// if confirm deletion button has been clicked, delete record
if (isset($_POST['update'])) {
$sql = 'UPDATE resources SET section = :section, category = :category, topic = :topic, title = :title, link = :link, phone = :phone, description = :description, organization = :organization, "document one link" = :docOneLink, "document one title" = :docOneTitle, "document two link" = :docTwoLink, "document two title" = :docTwoTitle, "document three link" = :docThreeLink, "document three title" = :docThreeTitle, modified = :datemodified WHERE ID =:id';
$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(':datemodified', $datemodified);
$stmt->bindParam(':id', $id);
//setup parameters
$id = $_POST['id'];
$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'];
$datemodified = time();
$stmt->execute();
if ($db->changes() > 0) {
$updated = true;
}else {
$error = 'There was a problem updating the record. '. $updated;
}
}
if ($updated || isset($_POST['cancel_update']) || !isset($_GET['id'])) {
$db->close();
header("Location: http://".$_SERVER['HTTP_HOST']."/admin/links/#".$_POST['id']);
exit;
}
// if any SQL query fails, display error message
if (isset($stmt) && !$OK && !$updated) {
$error .= $stmt->error;
//echo $error;
}
?>
<!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>
<?php
$sql = "SELECT * from resources WHERE ID = :id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':id', $id_edit);
$id_edit = $_GET['id'];
$ret = $stmt->execute();
$row = $ret->fetchArray(SQLITE3_ASSOC);
$id = $row['ID'];
$section = $row['section'];
$category = $row['category'];
$topic = $row['topic'];
$title = $row['title'];
$link = $row['link'];
$phone = $row['phone'];
$description = $row['description'];
$organization = $row['organization'];
$docOneLink = $row['document one link'];
$docOneTitle = $row['document one title'];
$docTwoLink = $row['document two link'];
$docTwoTitle = $row['document two title'];
$docThreeLink = $row['document three link'];
$docThreeTitle = $row['document three title'];
$datecreated = $row['created'];
$lastmodified = $row['modified'];
?>
<div style="clear:both;"></div>
<form id="form" method="post" action="edit.php" role="form" style="clear:both;">
<input name="id" id="id" type="hidden" value="<?php echo $id?>">
<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" value="<?php echo $section ?>">
</div>
<div class="form-group">
<label for="category">Category:</label>
<input name="category" type="text" id="category" placeholder="Category" class="form-control" value="<?php echo $category ?>">
</div>
<div class="form-group">
<label for="topic">Topic:</label>
<input name="topic" type="text" id="topic" placeholder="Topic" class="form-control" value="<?php echo $topic ?>">
</div>
<div class="form-group">
<label for="title">Title:</label>
<input name="title" type="text" id="title" placeholder="Title" class="form-control" value="<?php echo $title ?>">
</div>
<div class="form-group">
<label for="organization">Organization:</label>
<input name="organization" type="text" id="organization" placeholder="Organization" class="form-control" value="<?php echo $organization ?>">
</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"><?php echo $description ?></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" value="<?php echo $phone ?>">
</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" value="<?php echo $link ?>">
</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" value="<?php echo $docOneTitle ?>">
</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" value="<?php echo $docOneLink ?>">
</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" value="<?php echo $docTwoTitle ?>">
</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" value="<?php echo $docTwoLink ?>">
</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" value="<?php echo $docThreeTitle ?>">
</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" value="<?php echo $docThreeLink ?>">
</div>
</div>
<div id="buttons">
<input type="submit" name="update" id="update" class="btn btn-success" value="Update Link">
<input type="submit" name="cancel_update" 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';?>