Commit 989c66a2 by mhasan

added edit page.

parent cb91c82f
<?php
session_start();
require "db_conn.php";
$e = NULL;
// $dateTime = $_POST['date']. " ". $_POST['time']. ":00";
if( isset($_POST['submit']))
{
try
{
/* This will insert Time and to do into a pre existing table called $_POST['user] */
$querry_prep = sprintf("INSERT INTO %s (t_date,t_time, task, task_completion) VALUES (:date , :time , :task , 0);",$_SESSION['userName'] );
/* The sprintf part is necessary because there cannot be "quotes" before the table name.*/
/* Be default execute statement adds quotes before and after the bound parameters, so userName couldn't be bound, rather added by sprintf*/
$pdo_st = $pdo -> prepare($querry_prep);
$param = [ ':date' => $_POST['date'] ,':time' => $_POST['time'], ':task' => $_POST['todo'] ];
$pdo_st -> execute($param);
header("location: view.php");
}
catch(PDOException $e)
{
echo("querry error ". $e -> getMessage(). " ". $e -> getLine(). " ");
}
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href= "css/create_style.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> Create List</title>
</head>
<body>
<nav class="nav">
<a href="index.php"> Index </a> &nbsp; &nbsp;
<a href="register.php"> Register </a>&nbsp; &nbsp;
<a href="create.php"> Create List </a>&nbsp; &nbsp;
<a href="view.php"> View List</a>&nbsp; &nbsp;
<a href="delete.php"> DELETE Tasks </a>&nbsp; &nbsp;
<a href="faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> Create List</h2>
<form action = "#" method="POST">
<!-- User Name: <input type="text" name = "user"> <br> <br> unecessary, session variables will hold the username (and table name)-->
<!-- Task ID: <input type ="number" name="taskID" required> <br> <br> -->
Date : <input type="text" name="date" placeholder="YYYY-MM-DD" required
pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))"
title="Enter a date in this format YYYY-MM-DD"/> <br> <br>
Time : <input type = "time" name ="time" required> <br> <br>
Task (upto 300 characters) : <textarea rows = "6" cols= "40" name = "todo" maxlength="300" required></textarea> <br> <br>
<input type="submit" name = "submit" value="submit"> <br>
</form>
</body>
</html>
<?php
/*
* This file contains the "common" instructions for connecting to a database.
* Meaning, by including this file a connection to the database has already been made (or a PDO exception, in the event of failiure)
*/
$dsn = "mysql:host=localhost;dbname=project";
$database_user = 'root';
$database_pass = "root";
try
{
$pdo = new PDO($dsn, "root", "root");
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Sets exception parameters
}
catch( PDOException $e)
{
echo(" Connection failed. " . $e -> getMessage() . " ". $e -> getLine() );
}
<?php
require "db_conn.php";
session_start();
$e = null;
if (isset($_POST['submit'])) {
try {
$query_st = sprintf("DELETE FROM %s WHERE taskID ='%d';", $_SESSION['userName'], $_POST['taskID']);
$pdo->exec($query_st);
} catch (PDOException $e) {
echo ($e->getMessage() . " " . $e->getLine());
}
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css/view.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> View Tasks</title>
</head>
<body>
<nav class="nav">
<a href="index.php"> Index </a> &nbsp; &nbsp;
<a href="register.php"> Register </a>&nbsp; &nbsp;
<a href="create.php"> Create List </a>&nbsp; &nbsp;
<a href="view.php"> View List</a>&nbsp; &nbsp;
<a href="delete.php"> DELETE Tasks </a>&nbsp; &nbsp;
<a href="faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> DELETE tasks </h2>
<form method="POST">
Enter Task ID :<input type="number" name="taskID">
Submit :<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
\ No newline at end of file
<?php
session_start();
require "db_conn.php";
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css/create_style.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> Edit Tasks</title>
</head>
<body>
<?php
echo "<h2>", $_POST['edit'], "</h2>";
if (isset($_SESSION['userName'])) {
try {
if ( isset($_POST['edit']) ){
$_SESSION['id'] = $_POST['edit'];
}
$querry = sprintf('SELECT * FROM %s WHERE taskID = %d', $_SESSION['userName'], $_SESSION['id']);
$pdo_st = $pdo->query($querry);
$pdo_st->setFetchMode(PDO::FETCH_ASSOC);
$row = $pdo_st->fetch();
} catch (PDOException $ex) {
echo ($ex->getMessage() . " " . $ex->getLine());
}
}
?>
<form method="POST" action = "#">
Date: <input type = 'text' name="date" placeholder="YYYY-MM-DD"
pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))"
title="Enter a date in this format YYYY-MM-DD"> <?php echo ($row['t_date']); ?> <br> <br>
Time: <input type = 'time' name = 'time' value = 'time'> <?php echo($row['t_time']) ?> <br> <br>
Task: <textarea rows = "6" cols= "40" name = "todo" maxlength="300" > <?php echo ($row['task']); ?> </textarea> <br> <br>
Task status: <input type='number' name='task_completion' value='set'> <br> <br>
<input type = 'submit' name = 'save' value = 'save'>
</form>
<?php
// echo("querry script started! <br>");
if (isset($_POST['save'])) {
// echo("Save is not null, trying querry <br>");
// echo($_SESSION['userName']. $_POST['date']. $_POST['time']. $_POST['todo'].$_POST['task_completion'] .$_SESSION['id']);
try {
$querry = sprintf("UPDATE %s SET t_date = '%s' , t_time = '%s' , task = '%s' , task_completion = %d WHERE taskID = %d;", $_SESSION['userName'], $_POST['date'], $_POST['time'], $_POST['todo'],$_POST['task_completion'], $_SESSION['id']);
// echo ("<h2>".$querry."</h2>");
$pdo->exec($querry);
header("location: view.php");
} catch (PDOException $e) {
echo ($e->getMessage() . " " . $e->getLine());
}
}
?>
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href= "css/view.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> FAQ</title>
</head>
<body>
<nav class="nav">
<a href = "index.php"> Index </a> &nbsp; &nbsp;
<a href = "register.php"> Register </a>&nbsp; &nbsp;
<a href = "create.php"> Create List </a>&nbsp; &nbsp;
<a href = "view.php"> View List</a>&nbsp; &nbsp;
<a href = "faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> Frequently Asked QUestions</h2>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/index_style.css">
<meta charset="utf-8">
<title>Personal Assistence</title>
<?php
require "db_conn.php";
$e = null;
if (isset($_POST['submit'])) {
try {
$querry = sprintf("SELECT passHash FROM login WHERE userName = '%s' ;", $_POST['userName']);
$pdo_st = $pdo->query($querry);
$pdo_st->setFetchMode(PDO::FETCH_ASSOC);
$array = $pdo_st->fetch();
$isMatch = password_verify($_POST['pass'], $array['passHash']);
if ($isMatch == true) {
session_start();
$_SESSION['userName'] = $_POST['userName'];
header("location: create.php"); //redirects user to a certain page upon successful login!
}
} catch (PDOException $e) {
echo ($e->getMessage() . " " . $e->getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href="index.php"> Index </a> &nbsp; &nbsp;
<a href="register.php"> Register </a>&nbsp; &nbsp;
<a href="create.php"> Create List </a>&nbsp; &nbsp;
<a href="view.php"> View List</a>&nbsp; &nbsp;
<a href="delete.php"> DELETE Tasks </a>&nbsp; &nbsp;
<a href="faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> WELCOME TO YOUR VERY OWN PERSONAL ASSISTENT</h2>
<p> In modern lifestyle we have to do lot of things, be at different places and communicate with lot of people.
It gets complicated to manage all this. You have to plan your day, week even a month at a time.
<br><b> So join us , manage your day with ease.</b></p>
<form method="POST">
<label id="user"> Username:</label>
<input type="text" name="userName" id="user">
<br><br>
<label id="pass"> Password: </label>
<input type="password" name="pass" id="pass">
<br><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
\ No newline at end of file
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Tallinn University of Technology – Web Technologies - Learning CSS">
<meta name="keywords" content="ICD0007, LAB5, CSS">
<title>Form Validation</title>
<?php
//$form_values = $_POST['salutation'] + '.' + $_POST['f_name'] + ',' + $_POST['mid_name'] + ',' + $_POST['l_name'] + ',' + $_POST['age'] + ',' + $_POST['email'] + ',' + $_POST['tel'] + ',' + $_POST['date'] + ';' ;
//file_put_contents("form.txt", $form_values, FILE_APPEND);
if(is_writable("form.txt"))
{
echo "writeable";
}
else
{
echo "unwriteable";
}
$fptr = fopen('form.txt', 'a+') or die("failure");
$form_values = 'salutations \n';
fwrite($fptr, $form_values);
fclose($fptr);
die("done!");
?>
</head>
<body>
<h2> HTML FORM VALIDATION </h2>
<form method="POST" action=" ">
<select name = "salutation">
<option value = "Mr"> Mr </option>
<option value = "Mrs"> Mrs </option>
<option value = "Dr"> Dr </option>
<option value = "Prof"> Prof </option>
<option value = "Sir"> Sir </option>
</select>
<label for = "first"> First Name </label>
<input type="text" name = "f_name" id = "first" required> <br>
<label for = "middle"> Middle Name </label>
<input type="text" name = "mid_name" id = "middle"> <br>
<label for = "last"> Last Name </label>
<input type="text" name = "l_name" id = "lirst" required> <br>
<label for = "age"> Age </label>
<input type="number" name = "age" label = "age" min = "17" max = "200" required> <br>
<label for = "e"> Email </label>
<input type="email" name = "email" label = "e" required> <br>
<label for = "phone"> Phone </label>
<input type = "tel" name = "tel" label = "phone"> <br>
<label for = "Date"> Date of Arrival </label>
<input type="date" name = "date" label = "Date" required> <br>
<input type="submit" name = "submit"> <br>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css/register_css.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> Registration</title>
<?php
require "db_conn.php";
$e = null;
$pass_hash = password_hash($_POST['pass'], PASSWORD_DEFAULT);
if (isset($_POST['submit'])) {
try {
/* This INSERTS users credentials into the (pre existing)data table called login( userName VARCHAR(20), email VARCHAR(320), passHash CHAR(255));*/
$pdo_stmnt = $pdo->prepare("INSERT IGNORE INTO login (userName, email, passHash) VALUES( :userName, :email, :passHash);");
$paramBind = [':userName' => $_POST['u_name'], ':email' => $_POST['email'], ':passHash' => $pass_hash]; //array for the parameters to be bound before execution.
$pdo_stmnt->execute($paramBind);
/* Creates The data table for the user under the project database. Each time user creats a task, the task will be inserted into the data_table of the user name*/
$querry = sprintf("CREATE TABLE IF NOT EXISTS %s (taskID INT AUTO_INCREMENT PRIMARY KEY, t_date ,t_time TIME, task VARCHAR(300), task_completion TINYINT(1) DEFAULT 0);", $_POST['u_name']);
$pdo->exec($querry);
header("location: view.php");
} catch (PDOException $e) {
echo ("querry failiure " . $e->getMessage() . " " . $e->getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href="index.php"> Index </a> &nbsp; &nbsp;
<a href="register.php"> Register </a>&nbsp; &nbsp;
<a href="create.php"> Create List </a>&nbsp; &nbsp;
<a href="view.php"> View List</a>&nbsp; &nbsp;
<a href="delete.php"> DELETE Tasks </a>&nbsp; &nbsp;
<a href="faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> Registration</h2>
<form action="#" method="post">
User Name &emsp;: <input type="text" name="u_name"> <br>
Email &emsp;&emsp; &nbsp;&nbsp;&nbsp; : <input type="email" name="email"> <br>
Password &emsp; &nbsp;&nbsp;: <input type="password" name="pass"> <br>
Confirm Password : <input type="password"> <br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css/view.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> View Tasks</title>
<?php
session_start();
require "db_conn.php";
if (isset($_SESSION['userName'])) {
try {
$querry = sprintf("SELECT * FROM %s", $_SESSION['userName']);
$pdo_st = $pdo->query($querry);
$pdo_st->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $p) {
echo ($p->getMessage() . " " . $p->getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href="index.php"> Index </a> &nbsp; &nbsp;
<a href="register.php"> Register </a>&nbsp; &nbsp;
<a href="create.php"> Create List </a>&nbsp; &nbsp;
<a href="view.php"> View List</a>&nbsp; &nbsp;
<a href="delete.php"> DELETE Tasks </a>&nbsp; &nbsp;
<a href="faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> View Tasks for today</h2>
<table>
<tr>
<th> STATUS </th>
<th> TASK ID </th>
<th> DATE </th>
<th> TIME</th>
<th> TASKS</th>
<th> </th>
<th> EDIT Task </th>
</tr>
<form method="POST" action="#" id = 'check'> </form>
<form method="POST" action="edit.php" id = 'edit'> </form>
<?php
$completed_task_list = [];
while ($row = $pdo_st->fetch()) // Takes 1 row of the data table, stores into an assoc array called row, elements of each row can be called by column name.
{
$_SESSION['edit'] = $row['taskID'];
if (isset($_POST[$row['taskID']])) {
$completed_task_list = [$row['taskID'] => true];
}
if ($row['task_completion'] == true) {
echo "<tr class = 'strike'> <td> DONE </td>";
} else {
echo "<tr> <td> TO DO </td>";
}
echo ("<td>" . $row['taskID'] . "</td>" ."<td>" . $row['t_date'] . "</td>" . "<td>" . $row['t_time'] . "</td>" . "<td>" . $row['task'] . "</td>");
echo "<td> <input form = 'check' type='checkbox' name = '", $row['taskID'], "' value = 'done' onChange='this.form.submit()'> </input> </td>";
echo "<td> <input type = 'submit' form = 'edit' name = 'edit', value ='", $row['taskID'],"'> </td>";
echo "</tr>";
}
foreach ($completed_task_list as $key => $value) {
if ($value == true) {
$query = sprintf("UPDATE %s SET task_completion = 1 WHERE taskID = %d", $_SESSION['userName'], $key);
try {
$pdo->exec($query);
header("location: view.php");
} catch (PDOException $e) {
echo ($e->getMessage() . " " . $e->getcode());
}
}
}
?>
</table>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment