Professional Documents
Culture Documents
Name: Alres C. Arena Prenciss Ann P. Juni 1) Website: Index - PHP
Name: Alres C. Arena Prenciss Ann P. Juni 1) Website: Index - PHP
Name: Alres C. Arena Prenciss Ann P. Juni 1) Website: Index - PHP
ARENA
PRENCISS ANN P. JUNI
1) WEBSITE
index.php
<?php
require_once 'app/init.php';
$itemsQuery = $db->prepare("SELECT id, name, done FROM items WHERE user =:user");
]);
foreach($items as $item) {
print_r($item);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>To do</title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans"
rel="stylesheet">
<link href="http://fonts.googleapis.com/css?
family=Shadows+Into+Light+Two" rel="stylesheet">
</head>
<body>
<div class="list">
<h1 class="header">To do.</h1>
<ul>
<?php foreach($items as $item): ?>
<li><span class="item<?php echo $item['done'] ? ' done' : '' ?
>"><?php echo $item['name']; ?></span>
<?php if($item['done']): ?>
<a href="mark.php?as=done&item=<?php echo
$item['id']; ?>" class="done-button">Mark as done</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
mark.php
<?php
require_once 'app/init.php'
if(isset($_GET['as'], $_GET['item'])) {
$as = $_GET['as'];
$item = $_GET['item'];
switch($as) {
case 'done':
$doneQuery = $db->prepare("
UPDATE items
SET done = 1
WHERE id = :item
AND user = :user
");
$doneQuery->execute([
'item' => $item,
'user' => $_SESSION['user_id']
]);
break;
}
}
header('Location: index.php');
add.php
<?php
require_once 'app/init.php';
if(isset($_POST['name'])) {
$name = trim($_POST['name']);
if(!empty($name)) {
$addedQuery = $db->prepare("
INSERT INTO items (name, user, done, created)
VALUES (:name, :user, 0, NOW())
");
$addedQuery->execute([
'name' => $name,
'user' => $_SESSION['user_id']
]);
}
}
header('Location: index.php');
app/init.php
<?php
session_start();
$_SESSION['user_id'] = 1;
if (!isset($_SESSION['user_id'])) {
die('You are not signed in.');
}
css/main.css
body {
background-color:#eceff0;
body, input {
font: 1em "Open Sans", sans-serif;
color: #363639;
a{
text-decoration: none;
border-bottom: 1px dashed #363639;
}
/* List */
.list {
background-color: #fff;
margin: 20px auto;
width: 100%;
max-width:500px;
padding: 20px;
border-radius: 2px;
box-shadow: 3px 3px 0 rgba(0, 0, 0, .1);
box-sizing: border-box;
}
.list .header {
font-family: "Shadows Into Light Two", cursive;
margin: 0 0 10px 0;
/* Items */
.items {
margin: 0;
padding: 0;
list-style-type: none;
.items .item.done {
text-decoration: line-through;
}
.items li,
.item-add .input {
border: 0;
border-botom: 1px dashed #ccc;
padding: 15px 0;
}
.input {
width: 100%;
}
.input:focus {
outline: none;
}
/* Done button */
.done-button {
display: inline-block;
font-size: 0.8em;
background-color: #d9dfe1;
color: #363639;
padding: 3px 6px;
border: 0;
opacity: 0.4;
/* Submit button */
.submit {
background-color: #fff;
padding: 5px 10px;
border: 1px solid #ddd;
width: 100%
margin-top: 10px;
box-shadow: 3px 3px 0 #ddd;
}
QUESTIONS :