Added:
/trunk/nikiatti
/trunk/nikiatti/Includes
/trunk/nikiatti/Includes/db.php
/trunk/nikiatti/createNewWisher.php
/trunk/nikiatti/deleteWish.php
/trunk/nikiatti/editWish.php
/trunk/nikiatti/editWishList.php
/trunk/nikiatti/index.php
/trunk/nikiatti/nbproject
/trunk/nikiatti/nbproject/private
/trunk/nikiatti/nbproject/private/config.properties
/trunk/nikiatti/nbproject/private/private.properties
/trunk/nikiatti/nbproject/private/private.xml
/trunk/nikiatti/nbproject/project.properties
/trunk/nikiatti/nbproject/project.xml
/trunk/nikiatti/static
/trunk/nikiatti/static/logo.png
/trunk/nikiatti/static/logo1.jpg
/trunk/nikiatti/static/logo1.png
/trunk/nikiatti/static/logo2.jpg
/trunk/nikiatti/static/logo2.png
/trunk/nikiatti/static/logo3.jpg
/trunk/nikiatti/static/logo3.png
/trunk/nikiatti/static/logo4.png
/trunk/nikiatti/static/logo5.jpg
/trunk/nikiatti/static/logo5.png
/trunk/nikiatti/static/logo6.png
/trunk/nikiatti/wishlist.css
/trunk/nikiatti/wishlist.php
=======================================
--- /dev/null
+++ /trunk/nikiatti/Includes/db.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,99 @@
+<?php
+ class WishDB {
+ // single instance of self shared among all instances
+ private static $instance = null;
+
+ // db connection config vars
+ private $user = "nikiatti";
+ private $pass = "nikiatti1234";
+ private $dbName = "nikiatti";
+ private $dbHost = "hci.cs.sfsu.edu";
+
+ private $con = null;
+
+ //This method must be static, and must return an instance of the
object if the object
+ //does not already exist.
+ public static function getInstance() {
+ if (!self::$instance instanceof self) {
+ self::$instance = new self;
+ }
+ return self::$instance;
+ }
+
+ // The clone and wakeup methods prevents external instantiation of
copies of the Singleton class,
+ // thus eliminating the possibility of duplicate objects.
+ public function __clone() {
+ trigger_error('Clone is not allowed.', E_USER_ERROR);
+ }
+ public function __wakeup() {
+ trigger_error('Deserializing is not allowed.', E_USER_ERROR);
+ }
+
+ // private constructor
+ private function __construct() {
+ $this->con = mysql_connect($this->dbHost, $this->user, $this->pass)
+ or die ("Could not connect to db: " . mysql_error());
+ //SET NAMES sets client, results, and connection character sets
+ mysql_query("SET NAMES 'utf8'");
+ mysql_select_db($this->dbName, $this->con)
+ or die ("Could not select db: " . mysql_error());
+ }
+
+ public function get_wisher_id_by_name ($name) {
+ $name = mysql_real_escape_string($name);
+ $result = mysql_query("SELECT id FROM wishers WHERE name = '"
+ . $name . "'");
+ if (mysql_num_rows($result) > 0)
+ return mysql_result($result, 0);
+ else
+ return null;
+ }
+
+ public function get_wishes_by_wisher_id($id) {
+ return mysql_query("SELECT * FROM wishes WHERE wisher_id=" . $id);
+ }
+
+ public function create_wisher ($name, $password){
+ $name = mysql_real_escape_string($name);
+ $password = mysql_real_escape_string($password);
+ mysql_query("INSERT INTO wishers (name, password) VALUES ('" .
$name
+ . "', '" . $password . "')");
+ }
+
+ public function verify_wisher_credentials ($name, $password){
+ return mysql_num_rows(mysql_query("SELECT * FROM wishers WHERE name
= '"
+ . $name . "' AND password = '" . $password . "'"));
+ }
+
+ public function get_wish_by_wish_id ($wishID) {
+ return mysql_query("SELECT * FROM wishes WHERE id = " . $wishID);
+ }
+
+ public function insert_wish($wisherId, $description, $duedate){
+ $description = mysql_real_escape_string($description);
+ return mysql_query("INSERT INTO wishes (wisher_id, description,
due_date)" .
+ " VALUES (" . $wisherId . ", '" .
$description . "', "
+ . $this->format_date_for_sql($duedate) . ")");
+ }
+
+ public function update_wish($wishID, $description, $duedate){
+ $description = mysql_real_escape_string($description);
+ return mysql_query("UPDATE wishes SET description = '" .
$description .
+ "', due_date = " .
$this->format_date_for_sql($duedate)
+ . " WHERE id =" . $wishID);
+ }
+
+ public function delete_wish ($wishID){
+ return mysql_query("DELETE FROM wishes WHERE id = " . $wishID);
+ }
+
+ public function format_date_for_sql($date){
+ if ($date == "")
+ return "NULL";
+ else {
+ $dateParts = date_parse($date);
+ return $dateParts["year"]*10000 + $dateParts["month"]*100 +
$dateParts["day"];
+ }
+ }
+ }
+?>
=======================================
--- /dev/null
+++ /trunk/nikiatti/createNewWisher.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,92 @@
+<?php
+require_once("Includes/db.php");
+
+/**other variables */
+$userNameIsUnique = true;
+$passwordIsValid = true;
+$userIsEmpty = false;
+$passwordIsEmpty = false;
+$password2IsEmpty = false;
+
+/** Check that the page was requested from itself via the POST method. */
+if ($_SERVER["REQUEST_METHOD"] == "POST"){
+ /** Check whether the user has filled in the wisher's name in the text
field "user" */
+ if ($_POST["user"]==""){
+ $userIsEmpty = true;
+ }
+
+ /** Create database connection */
+ $wisherID =
WishDB::getInstance()->get_wisher_id_by_name($_POST["user"]);
+ if ($wisherID) {
+ $userNameIsUnique = false;
+ }
+
+ /** Check whether a password was entered and confirmed correctly */
+ if ($_POST["password"]=="")
+ $passwordIsEmpty = true;
+ if ($_POST["password2"]=="")
+ $password2IsEmpty = true;
+ if ($_POST["password"]!=$_POST["password2"]) {
+ $passwordIsValid = false;
+ }
+
+ /** Check whether the boolean values show that the input data was
validated successfully.
+ * If the data was validated successfully, add it as a new entry in
the "wishers" database.
+ * After adding the new entry, close the connection and redirect the
application to editWishList.php.
+ */
+ if (!$userIsEmpty && $userNameIsUnique && !$passwordIsEmpty
&& !$password2IsEmpty && $passwordIsValid) {
+ WishDB::getInstance()->create_wisher($_POST["user"],
$_POST["password"]);
+ session_start();
+ $_SESSION["user"] = $_POST["user"];
+ header('Location: editWishList.php' );
+ exit;
+ }
+}
+?>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head><meta charset=UTF-8"></head>
+ <body>
+ Welcome!<br>
+ <form action="createNewWisher.php" method="POST">
+ Your name: <input type="text" name="user"/><br/>
+ <?php
+ /** Display error messages
if "user" field is empty or there is already a user with that name*/
+ if ($userIsEmpty) {
+ echo ("Enter your name, please!");
+ echo ("<br/>");
+ }
+ if (!$userNameIsUnique) {
+ echo ("The person already exists. Please check the
spelling and try again");
+ echo ("<br/>");
+ }
+ ?>
+ Password: <input type="password" name="password"/><br/>
+ <?php
+ /** Display error messages if the "password"
field is empty */
+ if ($passwordIsEmpty) {
+ echo ("Enter the password, please");
+ echo ("<br/>");
+ }
+ ?>
+ Please confirm your password: <input type="password"
name="password2"/><br/>
+ <input type="submit" value="Register"/>
+ <?php
+ /** Display error messages if the "password2"
field is empty
+ * or its contents do not match the "password"
field
+ */
+ if ($password2IsEmpty) {
+ echo ("Confirm your password, please");
+ echo ("<br/>");
+ }
+ if (!$password2IsEmpty && !$passwordIsValid) {
+ echo ("<div>The passwords do not match!</div>");
+ echo ("<br/>");
+ }
+ ?>
+
+ </form>
+
+ </body>
+</html>
=======================================
--- /dev/null
+++ /trunk/nikiatti/deleteWish.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,6 @@
+<?php
+ require_once("Includes/db.php");
+
+ WishDB::getInstance()->delete_wish ($_POST["wishID"]);
+ header('Location: editWishList.php' );
+?>
=======================================
--- /dev/null
+++ /trunk/nikiatti/editWish.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,76 @@
+<?php
+/**Start session */
+session_start();
+if (!array_key_exists("user", $_SESSION)) {
+ header('Location: index.php');
+ exit;
+}
+/** Create a new database object */
+require_once("Includes/db.php");
+
+ /** Retrieve the ID of the wisher who is trying to add a wish */
+$wisherId =
WishDB::getInstance()->get_wisher_id_by_name($_SESSION["user"]);
+ /** Initialize $wishDescriptionIsEmpty */
+$wishDescriptionIsEmpty = false;
+
+/** Checks that the Request method is POST, which means that the data
+ * was submitted from the form for entering the wish data on the
editWish.php
+ * page itself */
+if ($_SERVER["REQUEST_METHOD"] == "POST"){
+ /** Checks whether the $_POST array contains an element with
the "back" key */
+ if (array_key_exists("back", $_POST)) {
+ /** The Back to the List key was pressed.
+ * Code redirects the user to the editWishList.php */
+ header('Location: editWishList.php' );
+ exit;
+ } else
+ /** Checks whether the element with the "wish" key in the $_POST
array is empty,
+ * which means that no description was entered.
+ */
+ if ($_POST["wish"] == "") {
+ $wishDescriptionIsEmpty = true;
+ }
+ /** The "wish" key in the $_POST array is NOT empty, so a description
is entered.
+ * Adds the wish description and the due date to the database via
WishDB.insert_wish
+ */
+ else if ($_POST["wishID"]=="") {
+ WishDB::getInstance()->insert_wish($wisherId, $_POST["wish"],
$_POST["dueDate"]);
+ header('Location: editWishList.php' );
+ exit;
+ }
+ else if ($_POST["wishID"]!="") {
+ WishDB::getInstance()->update_wish($_POST["wishID"],
$_POST["wish"], $_POST["dueDate"]);
+ header('Location: editWishList.php' );
+ exit;
+ }
+}
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <?php
+ if ($_SERVER["REQUEST_METHOD"] == "POST")
+ $wish = array("id" => $_POST["wishID"],
+ "description" =>
$_POST["wish"],
+ "due_date" =>
$_POST["dueDate"]);
+ else
+ if (array_key_exists("wishID", $_GET))
+ $wish =
mysql_fetch_array(WishDB::getInstance()->get_wish_by_wish_id($_GET["wishID"]));
+ else
+ $wish = array("id" => "", "description" => "", "due_date" => "");
+ ?>
+ <form name="editWish" action="editWish.php" method="POST">
+ <input type="hidden" name="wishID" value="<?php echo
$wish["id"];?>" />
+ Describe your wish: <input type="text" name="wish"
value="<?php echo $wish['description'];?>" /><br/>
+ <?php
+ if ($wishDescriptionIsEmpty) echo "Please enter
description<br/>";
+ ?>
+ When do you want to get it? <input type="text" name="dueDate"
value="<?php echo $wish['due_date']; ?>"/><br/>
+ <input type="submit" name="saveWish" value="Save Changes"/>
+ <input type="submit" name="back" value="Back to the List"/>
+ </form>
+ </body>
+</html>
=======================================
--- /dev/null
+++ /trunk/nikiatti/editWishList.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,57 @@
+<?php
+session_start();
+if (array_key_exists("user", $_SESSION)) {
+ echo "Hello " . $_SESSION["user"];
+}
+else {
+ header('Location: index.php');
+ exit;
+}
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <table border="black">
+ <tr><th>Item</th><th>Due Date</th></tr>
+ <?php
+ require_once("Includes/db.php");
+
+ $wisherID =
WishDB::getInstance()->get_wisher_id_by_name($_SESSION["user"]);
+ $result =
WishDB::getInstance()->get_wishes_by_wisher_id($wisherID);
+ while($row = mysql_fetch_array($result)) {
+ strip_tags($row["description"],'<br><p><h1>');
+ echo "<tr><td>" . $row["description"]."</td>";
+ strip_tags($row["due_date"],'<br><p><h1>');
+ echo "<td>".$row["due_date"]."</td>";
+ $wishID = $row["id"];
+ //The loop is left open
+ ?>
+ <td>
+ <form name="editWish" action="editWish.php" method="GET">
+ <input type="hidden" name="wishID" value="<?php echo
$wishID; ?>"/>
+ <input type="submit" name="editWish" value="Edit"/>
+ </form>
+ </td>
+ <td>
+ <form name="deleteWish" action="deleteWish.php"
method="POST">
+ <input type="hidden" name="wishID" value="<?php echo
$wishID; ?>"/>
+ <input type="submit" name="deleteWish" value="Delete"/>
+ </form>
+ </td>
+ <?php
+ echo "</tr>\n";
+ //The loop is now closed
+ }
+ ?>
+ </table>
+ <form name="addNewWish" action="editWish.php">
+ <input type="submit" value="Add Wish"/>
+ </form>
+ <form name="backToMainPage" action="index.php">
+ <input type="submit" value="Back To Main Page"/>
+ </form>
+ </body>
+</html>
=======================================
--- /dev/null
+++ /trunk/nikiatti/index.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,79 @@
+<?php
+require_once("Includes/db.php");
+$logonSuccess = true;
+if ($_SERVER["REQUEST_METHOD"] == "POST"){
+ if (WishDB::getInstance()->verify_wisher_credentials($_POST["user"],
$_POST["userpassword"]) == 1) {
+ session_start();
+ $_SESSION["user"] = $_POST["user"];
+ header('Location: editWishList.php');
+ } else {
+ $logonSuccess = false;
+ }
+}
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Wishlist Application</title>
+ <link href="wishlist.css" type="text/css" rel="stylesheet"
media="all" />
+ </head>
+ <body>
+ <div class="logo">
+ <img src="static/logo1.jpg" alt="logo"/>
+ <img src="static/logo2.jpg" alt="logo"/>
+ <br/>
+ <img src="static/logo3.jpg" alt="logo"/>
+ <img src="static/logo5.jpg" alt="logo"/>
+ </div>
+ <div class="logon">
+ <input type="submit" name="myWishList" value="My Wish List >>"
onclick="javascript:showHideLogonForm()"/>
+ <form name="logon" action="index.php" method="POST"
+ style="visibility:<?php if ($logonSuccess)
echo "hidden"; else echo "visible";?>">
+ Username: <input type="text" name="user"/>
+ Password: <input type="password"
name="userpassword"/><br/>
+ <div class="error">
+ <?php
+ if (!$logonSuccess)
+ echo "Invalid name and/or password";
+ ?>
+ </div>
+ <input type="submit" value="Edit My Wish List"/>
+ </form>
+ </div>
+ <div class="showWishList">
+ <input type="submit" name="showWishList" value="Show Wish List
of >>" onclick="javascript:showHideShowWishListForm()"/>
+
+ <form name="wishList" action="wishlist.php" method="GET"
style="visibility:hidden">
+ <input type="text" name="user"/>
+ <input type="submit" value="Go" />
+ </form>
+ </div>
+ <div class="createWishList">
+ Still don't have a wish list?! <a
href="createNewWisher.php">Create now</a>
+ </div>
+ <script type="text/javascript">
+ function showHideLogonForm() {
+ if (document.all.logon.style.visibility == "visible"){
+ document.all.logon.style.visibility = "hidden";
+ document.all.myWishList.value = "My Wishlist >>";
+ }
+ else {
+ document.all.logon.style.visibility = "visible";
+ document.all.myWishList.value = "<< My Wishlist";
+ }
+ }
+
+ function showHideShowWishListForm() {
+ if (document.all.wishList.style.visibility == "visible") {
+ document.all.wishList.style.visibility = "hidden";
+ document.all.showWishList.value = "Show Wish List of
>>";
+ }
+ else {
+ document.all.wishList.style.visibility = "visible";
+ document.all.showWishList.value = "<< Show Wish List
of";
+ }
+ }
+ </script>
+ </body>
+</html>
=======================================
--- /dev/null
+++ /trunk/nikiatti/nbproject/private/private.properties Thu Feb 3
22:03:24 2011
@@ -0,0 +1,8 @@
+copy.src.files=false
+copy.src.target=
+remote.connection=hci
+remote.directory=/PhpProject1
+remote.permissions=true
+remote.upload=ON_RUN
+run.as=REMOTE
+url=http://hci.cs.sfsu.edu/~nikiatti/PhpProject1/
=======================================
--- /dev/null
+++ /trunk/nikiatti/nbproject/private/private.xml Thu Feb 3 22:03:24 2011
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks
xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
=======================================
--- /dev/null
+++ /trunk/nikiatti/nbproject/project.properties Thu Feb 3 22:03:24 2011
@@ -0,0 +1,13 @@
+ignore.path=
+include.path=\
+ ${php.global.include.path}
+php.version=PHP_5
+phpunit.bootstrap=
+phpunit.bootstrap.create.tests=false
+phpunit.configuration=
+phpunit.suite=
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+web.root=.
=======================================
--- /dev/null
+++ /trunk/nikiatti/nbproject/project.xml Thu Feb 3 22:03:24 2011
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.php.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/php-project/1">
+ <name>PhpProject1</name>
+ </data>
+ </configuration>
+</project>
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo1.jpg Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo1.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo2.jpg Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo2.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo3.jpg Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo3.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo4.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo5.jpg Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo5.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/static/logo6.png Thu Feb 3 22:03:24 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/nikiatti/wishlist.css Thu Feb 3 22:03:24 2011
@@ -0,0 +1,91 @@
+/*
+ Document : wishlist
+ Created on : Sep 17, 2010, 2:49:00 AM
+ Author : Nilay
+ Description:
+ Purpose of the stylesheet follows.
+*/
+
+/*
+ TODO customize this sample style
+ Syntax recommendation http://www.w3.org/TR/REC-CSS2/
+*/
+
+body {
+ font-family: Verdana,Arial,Helvetica,sans-serif;
+ font-size: 18px;
+ background-color: #ccffff;
+}
+
+input {
+ font-family: Verdana,Arial,Helvetica,sans-serif;
+ font-size: 18px;
+ margin-top: 5px;
+ margin-bottom: 5px;
+}
+
+.showWishList {
+ position: absolute;
+ left: 70%;
+ width: 15%;
+ top: 70%;
+}
+
+.createWishList {
+ position: absolute;
+ left: 33%;
+ top: 60%;
+ color: blue;
+ font-size: 30px;
+}
+
+.logon {
+ position: absolute;
+ left: 70%;
+ width: 15%;
+ top: 5%;
+}
+
+.logo {
+ position: fixed;
+ left: 10px;
+ width: 80%;
+ top: 10px;
+}
+
+.error {
+ color:red;
+ font-weight:bold;
+}
+
+.welcome {
+ top: 10%;
+ text-align: center;
+ font-family: Arial,Helvetica,sans-serif;
+ font-size: 24px;
+ color: teal;
+}
+
+.enterData {
+ position: relative;
+ left: 35%;
+ vertical-align: top;
+}
+
+.button {
+ top: 40%;
+ text-align: center;
+}
+
+.table {
+ position: absolute;
+ top: 20%;
+ left: 20%;
+}
+
+.buttonsOnEditWishList {
+ position: absolute;
+ top: 20%;
+ right: 20%;
+}
+
=======================================
--- /dev/null
+++ /trunk/nikiatti/wishlist.php Thu Feb 3 22:03:24 2011
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <body>
+ Wish List of <?php echo $_GET["user"]."<br/>";?>
+ <?php
+ require_once("Includes/db.php");
+
+ $wisherID =
WishDB::getInstance()->get_wisher_id_by_name($_GET["user"]);
+ if (!$wisherID) {
+ die("The person " .$_GET["user"]. " is not found. Please check
the spelling and try again" );
+ }
+ ?>
+ <table border="black">
+ <tr>
+ <th>Item</th>
+ <th>Due Date</th>
+ </tr>
+ <?php
+ $result =
WishDB::getInstance()->get_wishes_by_wisher_id($wisherID);
+ while($row = mysql_fetch_array($result)) {
+ $desc = $row["description"];
+ $dueDate = $row["due_date"];
+ echo "<tr><td>" . strip_tags($desc,'<br><p><h1>')."</td>";
+ echo "<td>". strip_tags($dueDate)."</td></tr>\n";
+ }
+ ?>
+ </table>
+ </body>
+</html>