<?php
session_start();
include_once("connect.php");
include_once("user.php");
User :: checkUserSession();
class HandlerPage
{
static function insertData()
{
if(isset($_POST["in_importance"]))
{
$DB = new Connection();
$DB = $DB-> connectToDB();
$st = $DB->prepare("select * FROM work_list where user_name =:uname ");
$st->bindParam(":uname",$_SESSION["todo_user_name"]);
$st->execute();
$arr = array();
$j=0;
if($st->rowCount() >= 1)
{
while($row = $st->fetch())
{
$arr[$j] = $row["note_id"];
$j++;
}
}
$noteID = $_SESSION["todo_user_name"]."_1";
$k = 1;
while(in_array($noteID,$arr))
{
$noteID = $_SESSION["todo_user_name"]."_".$k;
$k++;
}
$stmt = $DB->prepare("INSERT INTO work_list(title,description,category,date_end,done_before,importance,for_now, note_id,user_name, note_rank)
VALUES(:titl,:desc,:cate,:dend,:dnbfr,:impo,:now , :ntid,:uname, :ntrnk ) ");
$stmt->bindParam(':titl',$_POST["in_title"]);
$stmt->bindParam(':desc',$_POST["in_description"]);
$stmt->bindParam(':cate',$_POST["in_category"]);
$stmt->bindParam(':dend',$_POST["in_date_end"]);
$stmt->bindParam(':dnbfr',$_POST["in_done_before"]);
$stmt->bindParam(':impo',$_POST["in_importance"]);
$stmt->bindParam(':now',$_POST["in_for_now"]);
$stmt->bindParam(':ntid',$noteID);
$stmt->bindParam(':uname',$_SESSION["todo_user_name"]);
$stmt->bindParam(':ntrnk',$_POST["in_rank"]);
if( $stmt->execute())
{
$stmt->execute();
echo <<< P1
<button onclick="location.href='add_item.php'"> Add New Item</button>
<button onclick="location.href='index.php'"> GO TO HOMEPAGE</button>
P1;
}
}//isset($_POST)
}
//insertData()
}
//class Index
HandlerPage:: InsertData();
?>