Show sourcecode
The following files exists in this folder. Click to view.
add-article.php
aside.php
blokket-default.php
data/
initiate.php
remove-article.php
show-all-articles.php
show-article.php
update-article.php
update-article_backup.php
initiate.php
1 lines ASCII Unix (LF)
<h1>Initiate the Blokk</h1>
<?php
if (substr(sprintf('%o', fileperms("incl/blokket2/data")), -4) == 777)
echo "<p>The directory is writable.</p>";
else
echo "<p>The directory is NOT writable.</p>";
$filenames = readDirectory("incl/blokket2/data");
echo "<p><strong>The directory contains the following database files:</strong></p><ul>";
$files = "";
foreach($filenames as $filename)
$files .= "<li>" . $filename . "</li>";
echo $files . "</ul>";
if(isset($_POST["doArticleReset"]))
{
// Creating the database, if it doesn't exist, and initiating it with default ads.
$db = new PDO("sqlite:incl/blokket2/data/ads");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); // Display errors, but continue script
// Create a table if it doesn't already exist.
$stmt = $db->prepare('
CREATE TABLE IF NOT EXISTS Ads
(
id INTEGER PRIMARY KEY NOT NULL UNIQUE,
title TEXT,
description TEXT,
image TEXT
);
');
$stmt->execute();
// If the table already exists, delete all ad from it.
$stmt = $db->prepare('DELETE FROM Ads;');
$stmt->execute();
// Prepared statement for repeatedly inserting default ads.
$stmt = $db->prepare("INSERT INTO Ads(title,description,image) VALUES(?,?,?)");
$defaultAdsList = "<ul>";
// Insert the default ads:
$ad = null;
$ad[] = "Chewing gum";
$ad[] = 'Only slightly used. Most of the flavor still left (raspberry). Easy to blow bubbles with.';
$ad[] = "incl/blokket2/data/img/chewinggum.jpg";
$stmt->execute($ad);
$defaultAdsList .= "<li>" . $ad[0] . "</li>";
$ad = null;
$ad[] = "Parachute";
$ad[] = 'Parachute with extra holes in it, for those who like parachuting but think it takes too long to reach the ground.';
$ad[] = "incl/blokket2/data/img/parachute.jpg";
$stmt->execute($ad);
$defaultAdsList .= "<li>" . $ad[0] . "</li>";
$ad = null;
$ad[] = "Pistol";
$ad[] = 'Good to have in case you get tired of someone (maybe yourself).';
$ad[] = "incl/blokket2/data/img/pistol.jpg";
$stmt->execute($ad);
$defaultAdsList .= "<li>" . $ad[0] . "</li>";
$defaultAdsList .= "</ul>";
echo "<p><strong>Default ads inserted:</strong>" . $defaultAdsList;
}
?>
<form method="post">
<input type="submit" name="doArticleReset" value="Reset to default articles">
</form>