Commit 3f09b60d by mhasan

commented

parent f72c1bcc
...@@ -39,7 +39,7 @@ session_start(); ...@@ -39,7 +39,7 @@ session_start();
<div class='form'> <div class='form'>
<form class = 'form-group' style='text-align:center' action = "./php/createTask.php" method="POST" onsubmit="return dateValid()"> <form class = 'form-group' style='text-align:center' action = "./php/createTask.php" method="POST" onsubmit="return dateValid()">
<label class="form-control-label"> Date : </label> <label class="form-control-label"> Date : </label>
<input type="text" name="date" id = 'date' onchange='dateValid();' required> <!-- <span id = 'dateText'> </span> --> <input type="text" name="date" id = 'date' onchange='dateValid();' required> <!-- <span id = 'dateText'> </span> --> <!-- Datev alidation -->
<br><br><br> <br><br><br>
<label class="form-control-label" > Time : </label> <label class="form-control-label" > Time : </label>
...@@ -48,7 +48,7 @@ session_start(); ...@@ -48,7 +48,7 @@ session_start();
<label class="form-control-label"> Task (upto 300 characters) : </label> <label class="form-control-label"> Task (upto 300 characters) : </label>
<textarea rows = "6" cols= "40" name = "todo" maxlength="300" required></textarea> <br> <br> <textarea rows = "6" cols= "40" name = "todo" maxlength="300" required></textarea> <br> <br>
<input class="btn btn-outline-success" type="submit" name = "submit" value="submit" id='submit'> <br> <input class="btn btn-success" type="submit" name = "submit" value="submit" id='submit'> <br>
</form> </form>
</div> </div>
......
...@@ -39,7 +39,7 @@ require "php/db_conn.php"; ...@@ -39,7 +39,7 @@ require "php/db_conn.php";
</nav> </nav>
<h2 style="text-align: center; margin-top:80px; margin-bottom:30px;"> Edit Task </h2> <h2 style="text-align: center; margin-top:80px; margin-bottom:30px;"> Edit Task </h2>
<!-- Date and time validaion occurs at when submit button is pressed, if on of the is false, submission does not happen. -->
<form class = 'form-group' style='text-align:center' method="POST" onsubmit="return (dateValid() && timeValid());" action="php/updateData.php"> <form class = 'form-group' style='text-align:center' method="POST" onsubmit="return (dateValid() && timeValid());" action="php/updateData.php">
<label class="form-control-label"> Date : </label> <label class="form-control-label"> Date : </label>
<textarea name="date" rows="1" cols="10" id="date" onfocusout="dateValid()"><?php echo($row['t_date']); ?></textarea><br> <br> <textarea name="date" rows="1" cols="10" id="date" onfocusout="dateValid()"><?php echo($row['t_date']); ?></textarea><br> <br>
......
<?php <?php
require 'Twig/lib/Twig/Autoloader.php'; /*
* Index page script.
* loads the twig auto loader. checks if the submit button was pressed or not.
* If submited, then connects to the database and matches the password with the passhash of the user.
* If it matches, session is started and session userName is initialized.
*
* If submitted but failed, the the index html is rendered with login = false, meaning that there was a failed login attempt.
* So on the page is notified to try again.
*
* If not submitted, then index is rendered but no additional info is sent.
*/
require 'Twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register(); Twig_Autoloader::register();
// Load twig templating engine // Loads twig templating engine
$loader = new Twig_Loader_Filesystem('views'); $loader = new Twig_Loader_Filesystem('views'); //Location of the html pages in the filesystem.
$twig = new Twig_Environment($loader); $twig = new Twig_Environment($loader); //twig object.
// Enable debugging so we can dump array // Enable debugging so we can dump array
$twig = new \Twig\Environment($loader, [ $twig = new \Twig\Environment($loader, ['debug' => true,]); //set debugging mode
'debug' => true,
]);
$twig->addExtension(new \Twig\Extension\DebugExtension()); $twig->addExtension(new \Twig\Extension\DebugExtension());
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
......
<?php <?php
require "db_conn.php"; require "db_conn.php";
session_start(); session_start();
$taskArray = array(); $taskArray = array(); //global array used by view.php. array of task objects.
// $amount = $_POST['amount']; // $amount = $_POST['amount'];
class Task class Task
{ {
...@@ -22,6 +22,12 @@ class Task ...@@ -22,6 +22,12 @@ class Task
} }
} }
/*
* functions execute the querries. each function takes a PDO object (in db_conn.php), the reference to $taskArray, and $comp (which is true false or null)
* $comp tell which tasks to display, if null it displays all, if 1 only completed if 0, then the ones need to be done.
*
* One function also takes in a date string for custom date searches.
*/
function all($pdo, &$taskArr, $comp) { function all($pdo, &$taskArr, $comp) {
// $date = date('Y-m-d'); // $date = date('Y-m-d');
...@@ -73,8 +79,14 @@ function custom($pdo, &$taskArr, $inputDate, $comp) { ...@@ -73,8 +79,14 @@ function custom($pdo, &$taskArr, $inputDate, $comp) {
} }
} }
if ($amount == 'all') {
/*
* Depending on the value for amount (which means all tasks, or todays task or task for some arbitrary date), different function is executed.
* also in the view.php script. completion value is set .
* by default tho, when no info is submitted via post, it executes the last script. which means it will display today's todo list.
*
*/
if ($amount == 'all') {
try { try {
all($pdo,$taskArray, $completion); all($pdo,$taskArray, $completion);
} catch (PDOException $p) { } catch (PDOException $p) {
...@@ -92,4 +104,11 @@ if ($amount == 'all') { ...@@ -92,4 +104,11 @@ if ($amount == 'all') {
} catch (PDOException $p) { } catch (PDOException $p) {
echo ($p->getMessage() . " " . $p->getLine()); echo ($p->getMessage() . " " . $p->getLine());
} }
} else {
try {
today($pdo,$taskArray, 0);
} catch (PDOException $p) {
echo ($p->getMessage() . " " . $p->getLine());
}
} }
<?php <?php
/*
* View page.
* Twig is loaded.
*/
session_start(); session_start();
require 'Twig/lib/Twig/Autoloader.php'; require 'Twig/lib/Twig/Autoloader.php';
...@@ -9,9 +13,7 @@ $loader = new Twig_Loader_Filesystem('views'); ...@@ -9,9 +13,7 @@ $loader = new Twig_Loader_Filesystem('views');
$twig = new Twig_Environment($loader); $twig = new Twig_Environment($loader);
// Enable debugging so we can dump array // Enable debugging so we can dump array
$twig = new \Twig\Environment($loader, [ $twig = new \Twig\Environment($loader, ['debug' => true,]);
'debug' => true,
]);
$twig->addExtension(new \Twig\Extension\DebugExtension()); $twig->addExtension(new \Twig\Extension\DebugExtension());
$completion; $completion;
...@@ -26,9 +28,7 @@ $twig = new \Twig\Environment($loader, [ ...@@ -26,9 +28,7 @@ $twig = new \Twig\Environment($loader, [
$amount = $_POST['amount']; $amount = $_POST['amount'];
$custom = $_POST['custom']; $custom = $_POST['custom'];
require "php/serveData.php"; require "php/serveData.php";
echo $twig->render('view.html', array( echo $twig->render('view.html', array('tasks' => $taskArray));
'tasks' => $taskArray,
));
} }
else { else {
......
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