<?php
session_start();
include_once("connect.php");
class AjaxPage
{
static function checkData()
{
$DB = new Connection();
$DB = $DB-> connectToDB();
if(isset($_POST["username"]))
{
$sqlCheckUser="select * from users where user_name = :uname";
$stmt = $DB->prepare($sqlCheckUser);
$stmt->bindParam(':uname',$_POST["username"]);
$stmt->execute();
if($stmt->rowCount() == 1 )
{
echo "<span style=\"color:red;\"> This name is already taken! </span>";
}
else
{
echo "<span style=\"color:green;\"> ... </span ";
}
}// if(isset($_POST["username"]))
else if(isset($_POST["currentVal"]))
{
$increment = $_POST["currentVal"] +1;
$stmt = $DB->prepare("UPDATE work_list SET done_before = :incr where note_id = :ntid ");
$stmt->bindParam(':ntid',$_POST["noteId"]);
$stmt->bindParam(':incr',$increment);
if( $stmt->execute())
{
$stmt->execute();
$num = $increment;
echo <<< c1
<input type="hidden" name="current_done_times" id="{$_POST["noteId"]}_times" value="{$num}" >
<input type="hidden" name="note_id" id="note_id" value="{$_POST["noteId"]}" >
{$num}
c1;
}
}// if(isset($_POST["increment"]))
else if (isset($_POST["for_now"]))
{
$stmt = $DB->prepare("UPDATE work_list SET for_now = :fnow where note_id = :ntid ");
$stmt->bindParam(':ntid',$_POST["noteId"]);
$stmt->bindParam(':fnow',$_POST["for_now"]);
if( $stmt->execute())
{
$stmt->execute();
}
}//if (isset($_POST["for_now"]))
else if (isset($_POST["for_now_show_all"]))
{
$stmt = $DB->prepare("UPDATE work_list SET for_now = :fnow where user_name = :uname AND
for_now = 'hide' ");
$stmt->bindParam(':uname',$_SESSION["todo_user_name"]);
$stmt->bindParam(':fnow',$_POST["for_now_show_all"]);
if( $stmt->execute())
{
$stmt->execute();
}
}
else if(isset($_POST["deleteNoteId"]))
{
$stmt = $DB->prepare("DELETE FROM work_list where note_id = :ntid ");
$stmt->bindParam(':ntid',$_POST["deleteNoteId"]);
if( $stmt->execute())
{
$stmt->execute();
}
}// if(isset($_POST["increment"]))
}//function checkData()
}//AjaxPage
AjaxPage::checkData();
?>