Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

My Money Tracker

  • Loading branch information...
commit 87f64bac36204ab8478b9128248b41149953500d 0 parents
@kumar-abhishek authored
2  README
@@ -0,0 +1,2 @@
+This is an online money tracker.
+Now forget all the complicated math and trust MMT.
194 aakash@storm.cise.ufl.edu
@@ -0,0 +1,194 @@
+#!/usr/local/bin/php
+<?php
+ $connection = oci_connect($username = 'aakash',
+ $password = 'password',
+ $connection_string = '//oracle.cise.ufl.edu/orcl');
+
+ if (!$connection)
+ {
+ die("Connection Failed");
+ }
+
+ //USERS
+ $statement = oci_parse($connection, 'select 1 from users');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table users(
+ email_add varchar(32),
+ password varchar(32),
+ bank_balance int,
+ ph_no int,
+ monthly_budget int,
+ constraint user_pk primary key (email_add))');
+ if (!oci_execute($statement))
+ {
+ die("USERS table creation failed!");
+ }
+ echo "\nUSERS table created!\n";
+ }
+ else
+ {
+ echo "\nUSERS table already present!\n";
+ }
+
+ //CATEGORY
+ $statement = oci_parse($connection, 'select 1 from category');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table category(
+ cat_id int,
+ cat_desc varchar(64),
+ constraint category_pk primary key (cat_id))');
+ if (!oci_execute($statement))
+ {
+ die("CATEGORY table creation failed!");
+ }
+ echo "\nCATEGORY table created!\n";
+ }
+ else
+ {
+ echo "\nCATEGORY table already present!\n";
+ }
+
+ //TRANSACTION
+ $statement = oci_parse($connection, 'select 1 from transaction');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table transaction(
+ trans_id int,
+ cat_id int,
+ type char(2),
+ txn_desc varchar(64),
+ tot_amt int,
+ txn_date date,
+ constraint transaction_pk primary key (trans_id, cat_id),
+ constraint transaction_fk foreign key (cat_id) references category(cat_id))');
+ if (!oci_execute($statement))
+ {
+ die("TRANSACTION table creation failed!");
+ }
+ echo "\nTRANSACTION table created!\n";
+ }
+ else
+ {
+ echo "\nTRANSACTION table already present!\n";
+ }
+
+ //USERGROUP
+ $statement = oci_parse($connection, 'select 1 from usergroup');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table usergroup(
+ group_id int,
+ group_name varchar(64),
+ constraint group_pk primary key (group_id))');
+ if (!oci_execute($statement))
+ {
+ die("USERGROUP table creation failed!");
+ }
+ echo "\nUSERGROUP table created!\n";
+ }
+ else
+ {
+ echo "\nUSERGROUP table already present!\n";
+ }
+
+ //HAS_FRIENDS
+ $statement = oci_parse($connection, 'select 1 from has_friends');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table has_friends(
+ email_add varchar(32),
+ friend_email_add varchar(32),
+ dues int,
+ constraint has_friends_pk primary key (email_add, friend_email_add),
+ constraint has_friends_fk1 foreign key (friend_email_add) references users(email_add),
+ constraint has_friends_fk2 foreign key (email_add) references users(email_add))');
+ if (!oci_execute($statement))
+ {
+ die("HAS_FRIENDS table creation failed!");
+ }
+ echo "\nHAS_FRIENDS table created!\n";
+ }
+ else
+ {
+ echo "\nHAS_FRIENDS table already present!\n";
+ }
+
+ //BELONGS_TO
+ $statement = oci_parse($connection, 'select 1 from belongs_to');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table belongs_to(
+ email_add varchar(32),
+ group_id int,
+ constraint belongs_to_pk primary key (email_add, group_id),
+ constraint belongs_to_fk1 foreign key (email_add) references users(email_add),
+ constraint belongs_to_fk2 foreign key (group_id) references usergroup(group_id))');
+ if (!oci_execute($statement))
+ {
+ die("BELONGS_TO table creation failed!");
+ }
+ echo "\nBELONGS_TO table created!\n";
+ }
+ else
+ {
+ echo "\nBELONGS_TO table already present!\n";
+ }
+
+ //PARTICIPATES
+ $statement = oci_parse($connection, 'select 1 from participates');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table participates(
+ email_add varchar(32),
+ with_username varchar(32),
+ trans_id int,
+ with_amt int,
+ constraint participates_pk primary key (email_add, with_username, trans_id),
+ constraint participates_fk1 foreign key (email_add) references users(email_add))');
+ if (!oci_execute($statement))
+ {
+ die("PARTICIPATES table creation failed!");
+ }
+ echo "\nPARTICIPATES table created!\n";
+ }
+ else
+ {
+ echo "\nPARTICIPATES table already present!\n";
+ }
+
+ //SHARES
+ $statement = oci_parse($connection, 'select 1 from shares');
+
+ if (false == oci_execute($statement))
+ {
+ $statement = oci_parse($connection, 'create table shares(
+ email_add varchar(32),
+ trans_id int,
+ shared_amt int,
+ constraint shares_pk primary key (email_add, trans_id),
+ constraint shares_fk1 foreign key (email_add) references users(email_add),
+ constraint shares_fk2 foreign key (trans_id) references transaction(trans_id))');
+ if (!oci_execute($statement))
+ {
+ die("SHARES table creation failed!");
+ }
+ echo "\nSHARES table created!\n";
+ }
+ else
+ {
+ echo "\nSHARES table already present!\n";
+ }
+
+
+ oci_free_statement($statement);
+ oci_close($connection);
+?>
64 aakash@thunder.cise.ufl.edu
@@ -0,0 +1,64 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+
+ if(isset($_POST['add_email']))
+ {
+ $query = "insert into has_friends values ('".$_SESSION['email']."', '".$_POST['adding_email']."', 0)";
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("Friend not added!");
+ }
+ header("Location:home.php");
+ }
+ else if (isset($_POST['delete_email']))
+ {
+ $query = "delete from has_friends where email_add = '".$_SESSION['email']."' and friend_email_add = '".$_POST['deleting_email']."' and dues = 0";
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("Friend cannot be deleted! Check that you have no dues with this friend");
+ }
+ header("Location:home.php");
+ }
+?>
+
+<html>
+
+<body>
+
+<form name="input" action="modFriends.php" method="post">
+
+Add a friend (Enter his/her email-address): <input type="text" name="adding_email" />
+
+<input name="add_email" type="submit" value="add" />
+<br />
+Delete a friend (Enter his/her email-address): <input type="text" name="deleting_email" />
+
+<select>
+<?php
+ echo hello;
+?>
+<select>
+<input name="delete_email" type="submit" value="delete" />
+
+</form>
+</body>
+
+</html>
464 addTransaction.php
@@ -0,0 +1,464 @@
+#!/usr/local/bin/php
+
+<script language ="JavaScript" name=emailId>//src = "trackPay.js">
+var sharedarray = new Array();
+var count=0;
+var paidarray = new Array();
+var count1=0;
+function whoPaidFunction(emailId,divName)
+{
+ if(emailId == '----')
+ return;
+ if(arraySearch(paidarray,emailId)==-1)
+ {
+ paidarray[count1]=emailId;
+ count1++;
+ var newdiv = document.createElement('div');
+ newdiv.innerHTML = emailId +"&nbsp; &nbsp; <input type = 'text' name = 'paidAmt[]' value = 0></input> <input type='hidden' name = 'paidEmailIds[]' value = " + emailId + "> </input> " ;
+ document.getElementById(divName).appendChild(newdiv);
+ }
+}
+
+function arraySearch(arr,val)
+{
+ //document.write(arr);
+ for (var i=0; i<arr.length; i++)
+ {
+ //document.write(arr[i]);
+ //alert(arr[i]+" "+val+i);
+ if (arr[i].toString() == val.toString())
+ {
+ //alert('Already Selected!!!');
+ return 1;
+ }
+ //document.write("Not Found");
+ }
+ return -1;
+}
+function form_input_is_numeric(input)
+{
+ return !isNaN(input);
+}
+function whoParticipatedFunction(emailId,divName)
+{
+ if(emailId == '----')
+ return;
+ var newdiv = document.createElement('div');
+ if(emailId.substring(0,5)=="Group")
+ {
+ var ajax;
+ ajax = new XMLHttpRequest();
+ ajax.onreadystatechange=function()
+ {
+ if (ajax.readyState==4 && ajax.status==200)
+ {
+ var test = ajax.responseText.split(',', 1);
+ var i=0;
+ var tempResponse=ajax.responseText.slice(ajax.responseText.indexOf(",")+1,ajax.responseText.length);
+ var groupMembers=parseInt(test);
+ while(i!=groupMembers)
+ {
+ var newdiv = document.createElement('div');
+ var member = tempResponse.split(',', 1);
+ var member1=tempResponse.slice(tempResponse.indexOf(",")+1,tempResponse.length);
+ tempResponse=member1;
+ i++;
+ //document.write(shareEmailIds);
+ if(arraySearch(sharedarray,member)==-1)
+ {
+ sharedarray[count]=member;
+ count++;
+ //document.write(sharedarray[count]);
+ newdiv.innerHTML = member+"&nbsp; \
+ Share: <input type = 'text' name = 'sharedAmt[]' value = 0 ></input> <input type='hidden' name = 'shareEmailIds[]' value = " + member + "> </input> " ;
+ document.getElementById(divName).appendChild(newdiv);
+ }
+ }
+ }
+ }
+ ajax.open("GET","groupinfo.php?groupName="+emailId,true);
+ ajax.send();
+ }
+ else
+ {
+ if(arraySearch(sharedarray,emailId)==-1)
+ {
+ sharedarray[count]=emailId;
+ count++;
+ newdiv.innerHTML = emailId +"&nbsp; \
+ Share: <input type = 'text' name = 'sharedAmt[]' value = 0 ></input> <input type='hidden' name = 'shareEmailIds[]' value = " + emailId + "> </input>" ;
+ document.getElementById(divName).appendChild(newdiv);
+ }
+ }
+}
+function validateCheck()
+{
+ var jVar = document.forms["Report_Expense"]["trans_amt"].value;
+ if (null == jVar || "" == jVar)
+ {
+ alert("Amount cannot be blank!");
+ //return false;
+ }
+ else if(0== jVar)
+ {
+ alert("Amount cannot be Zero!");
+ }
+ else if(!form_input_is_numeric(jVar))
+ {
+ alert("Amount needs to be Numeric");
+ }
+}
+</script>
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+
+ $query = "select cat_id,cat_desc from category where cat_id >0";
+ $statementCategory = oci_parse($connection, $query);
+ if (!oci_execute($statementCategory))
+ {
+ echo $query;
+ die("Failed to execute query!");
+ }
+ $query1 = "select friend_email_add from has_friends where email_add = '".$_SESSION['email']."'";
+ $statement1 = oci_parse($connection, $query1);
+ if (!oci_execute($statement1))
+ {
+ echo $query1;
+ die("Failed to execute query!");
+ }
+ if(isset($_POST['submit']))
+ {
+ //find trans_id and cat_id
+ $queryMaxTxnId = "select MAX(trans_id) as m from transaction";
+ $statement = oci_parse($connection, $queryMaxTxnId);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die ("Failed to execute query!");
+ }
+
+ $row = oci_fetch_object($statement);
+ if (!$row)
+ {
+ $txnId = 1;
+ }
+ else
+ {
+ $txnId = ($row->M) + 1;
+ }
+
+
+ //$catRow = oci_fetch_object($statementCategory);
+ //$catId = $catRow->CAT_ID;
+
+ //update transaction table
+ // trans_id, cat_id, type, txn_desc, tot_amt, date
+ $type = "EX"; //hard-coded to EX: expense type
+ $txn_desc = $_POST['trans_desc'];
+ $txn_amt = $_POST['trans_amt'];
+ //if(!preg_match('/^[0-9]{1,}$/', $txn_amt))
+ // echo "<script>alert('Wrong Amount Entered.Please enter correct Amount!!!');</script>";
+ //else
+ {
+ $txn_amt = (int)$_POST['trans_amt'];
+ $txn_date = $_POST['trans_date'];
+ $catId = $_POST['category'];//category id corrected, should be feteched from option selected
+ if(strlen($txn_desc)==0)
+ {
+ $queryMaxTxnId = "select cat_desc as m from category where cat_id = '".$catId."'";
+ $statement = oci_parse($connection, $queryMaxTxnId);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die ("Failed to execute query!");
+ }
+
+ $row = oci_fetch_object($statement);
+ $txn_desc=$row->M;
+ }
+// $query = "insert into transaction values ($txnId, $catId,'".$type ."','". $txn_desc."' ,$txn_amt,to_date('".$txn_date ."','yyyy-mm-dd'))";
+ if(strlen($txn_date)==0)
+ {
+ $query = "insert into transaction values ($txnId, $catId,'".$type ."','". $txn_desc."' ,$txn_amt,sysdate)";
+ }
+ else{
+ $query = "insert into transaction values ($txnId, $catId,'".$type ."','". $txn_desc."' ,$txn_amt,to_date('".$txn_date ."','yyyy-mm-dd'))";
+ }
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("TRANSACTION NOT added!");
+ }
+
+
+ $paidAmt = $_POST['paidAmt'];
+ $paidEmailIds = $_POST['paidEmailIds'];
+/*
+ echo "paid:";
+ print_r( $paidEmailIds);
+ echo "<br>";
+ print_r($paidAmt);
+ echo "<br>";
+*/
+ $sharedAmt = $_POST['sharedAmt'];
+ $shareEmailIds = $_POST['shareEmailIds'];
+/*
+ echo "shared";
+ print_r($sharedAmt);
+ echo "<br>";
+ print_r($shareEmailIds);
+*/
+ $k = 0;//index for final array
+ $whoPaidAmt = 0;
+ //find what paidEmailIds are there in shareEmailIds and calculate finalEmailIds which are there or not there in shareEmailIds
+ for($i = 0 ; $i<count($paidEmailIds); $i++)
+ {
+ $key = array_search($paidEmailIds[$i], $shareEmailIds);
+ //echo "<br>".$key.$paidEmailIds[$i]."<br>";
+ if($key === false) //not found
+ {
+ $finalEmailIds[$k] = $paidEmailIds[$i];
+ $finalAmt[$k] = -($paidAmt[$i]);
+ }
+ else //found
+ {
+ $finalEmailIds[$k] = $paidEmailIds[$k];
+ $finalAmt[$k] = $sharedAmt[$key] - $paidAmt[$i];
+
+ }
+ $k = $k + 1;
+ $whoPaidAmt=$whoPaidAmt+$paidAmt[$i];
+ }
+/*
+ echo "<br>";
+ print_r($finalAmt);
+ echo "<br>";
+ print_r($finalEmailIds);
+ echo "<br>";
+*/
+ $whosharedAmt=0;
+ //find which shareEmailIds are not there in paidEmailIds and calculate finalEmailIds for them.
+ for($i = 0 ; $i<count($shareEmailIds); $i++)
+ {
+ $key = array_search($shareEmailIds[$i], $paidEmailIds);
+ if($key === false) //not found
+ {
+ $finalEmailIds[$k] = $shareEmailIds[$i];
+ $finalAmt[$k] = $sharedAmt[$i];
+ }
+ $whosharedAmt=$whosharedAmt+$sharedAmt[$i];
+ $k = $k + 1;
+ }
+ if($txn_amt!=$whoPaidAmt)
+ echo "<script>alert('Please check Amount in Who Paid and Who Particiapted fields!!!');</script>";
+ else if($whosharedAmt!=$whoPaidAmt)
+ echo "<script>alert('Paid and Contribution Amount not Matching. Please enter correct Amount!!!');</script>";
+ else
+ {
+ //sort finalAmt[] along with finalEmailIds
+ array_multisort($finalAmt,$finalEmailIds);
+/*
+ echo "<br>After sorting:<br>";
+ print_r($finalAmt);
+ echo "<br>";
+ print_r($finalEmailIds);
+ echo "<br>";
+*/
+ //cache amounts to be paid and insert into participates table
+ $i = 0;
+ $j = count($finalAmt)-1;
+ while($i <= $j)
+ {
+ if($finalAmt[$i] ==0 || $finalAmt[$j] ==0 ) break;
+
+ if( -($finalAmt[$i]) <= $finalAmt[$j])
+ {
+ //email_id,with_username,trans_id,cat_id,with_amt
+ $query = "insert into participates values ('".$finalEmailIds[$i]."','".$finalEmailIds[$j]."',$txnId ,$catId , -($finalAmt[$i]))";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("insertion into participates table failed!");
+ }
+ $finalAmt[$j] += $finalAmt[$i];
+ $finalAmt[$i] = 0;
+ ++$i;
+ }
+ else
+ {
+ $query = "insert into participates values ('".$finalEmailIds[$i]."','".$finalEmailIds[$j]."',$txnId, $catId, $finalAmt[$j])";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("insertion into participates table failed!");
+ }
+ $finalAmt[$i] += $finalAmt[$j];
+ $finalAmt[$j] = 0;
+ --$j;
+ }
+ }
+
+
+
+ //update SHARES table
+ //email_add, trans_id, cat_id , shared_amt
+ for($i=0; $i < count($sharedAmt); $i++)
+ {
+ $query = "insert into shares values ('$shareEmailIds[$i]', $txnId, $catId,$sharedAmt[$i] )";
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("TRANSACTION NOT added!");
+ }
+ }
+ header("Location:home.php");
+ }
+ }
+ }
+?>
+
+<html><head><title>Report Expense</title></head>
+<body>
+<form name = 'Report_Expense' action = 'addTransaction.php' onsubmit = 'return validateCheck() 'method = 'post'>
+
+ Date:<input name = 'trans_date' type = 'date' />
+ <br>Total Amount:<input name = 'trans_amt' type = 'integer' />
+ <br>Description:<input name = 'trans_desc' type = 'text' />
+ <br>Category:<select name = 'category' />
+ <?php
+ while(1)
+ {
+ $row = oci_fetch_object($statementCategory);
+ if (!$row)
+ {
+ print "$row not set";
+ break;
+ }
+
+ echo "<option value = '".$row->CAT_ID."'> ".$row->CAT_DESC." </option>";
+
+ }
+ ?>
+ </select>
+
+ <br><br><b>Who Paid:</b><br>
+ <?php
+ echo "<div id = 'whoPaid'></div>";
+ echo "Add Someone: ";
+ echo '<select name = "nameWhoPaid" onChange="whoPaidFunction(this.value,\'whoPaid\')" />';
+ echo '<option selected>----</option>';
+ ?>
+ <br>
+
+ <?php
+ echo "<option value = '".$_SESSION['email']."'> ".$_SESSION['email']."</option>";
+ $count=0;
+ while(1)
+ {
+ $row = oci_fetch_object($statement1);
+ if (!$row)
+ {
+ break;
+ }
+ $subQuery = "select name from users where email_add = '".$row->FRIEND_EMAIL_ADD."'";
+ $subStatement = oci_parse($connection, $subQuery);
+ if (!oci_execute($subStatement))
+ {
+ echo $subQuery;
+ die("Failed to execute subquery!");
+ }
+
+ $friendName = oci_fetch_object($subStatement);
+ $paidlist[$count]=$row->FRIEND_EMAIL_ADD;
+ $count=$count+1;
+ }
+ for($i=0;$i<$count;$i++)
+ echo "<option value = '".$paidlist[$i]."'>".$friendName->NAME." (".$paidlist[$i].")</option>";
+
+ ?>
+ </select>
+
+ <br><br><b>Who participated:</b><br>
+ <div id = 'whoParticipated'></div>
+ Add Someone:<select name = "who_participated" onChange="whoParticipatedFunction(this.value,'whoParticipated')" />
+ echo '<option selected>----</option>';
+ <?php
+ $query1 = "select friend_email_add from has_friends where email_add = '".$_SESSION['email']."'";
+ $statement1 = oci_parse($connection, $query1);
+ if (!oci_execute($statement1))
+ {
+ echo $query1;
+ die("Failed to execute query!");
+ }
+
+ print $statement1;
+ //$query2 = "select group_name from UserGroup where group_id in (select group_id from belongs_to where email_add = '".$_SESSION['email']."')";
+ echo "<option value = '".$_SESSION['email']."'> ".$_SESSION['email']."</option>";
+ $query2 = "select group_name from UserGroup where GROUP_OWNER = '".$_SESSION['email']."'";
+ $statement2 = oci_parse($connection, $query2);
+ if (!oci_execute($statement2))
+ {
+ echo $query2;
+ die("Failed to execute query!");
+ }
+ while(1)
+ {
+ $row1 = oci_fetch_object($statement2);
+ if (!$row1)
+ {
+ print "breaking";
+ break;
+ }
+ echo "<option value = '".$row1->GROUP_NAME."'>GROUP:".$row1->GROUP_NAME."</option>";
+ }
+ while(1)
+ {
+ $row = oci_fetch_object($statement1);
+ if (!$row)
+ {
+ print "breaking";
+ break;
+ }
+ $subQuery = "select name from users where email_add = '".$row->FRIEND_EMAIL_ADD."'";
+
+ $subStatement = oci_parse($connection, $subQuery);
+ if (!oci_execute($subStatement))
+ {
+ echo $subStatement;
+ die("Failed to execute subquery!");
+ }
+
+ $friendName = oci_fetch_object($subStatement);
+
+ echo "<option value = '".$row->FRIEND_EMAIL_ADD."'>".$friendName->NAME." (".$row->FRIEND_EMAIL_ADD.")</option>";
+ }
+ ?>
+ <br><br>
+ </select>
+ <br><br> <input name = 'submit' type = 'submit' value = 'Submit' />
+ <input name = 'Back' type = 'submit' value = 'Cancel' />
+
+</form>
+</body></html>
24 budget.php
@@ -0,0 +1,24 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+?>
+
+<html>
+<head><title>Budget Split - MMT</title>
+</head>
+
+<body>
+ <br /></br >
+ <img src="http://chart.apis.google.com/chart?chxr=0,-10,100&chxs=0,676767,13.5,0,l,676767&chxt=x&chbh=a&chs=300x225&cht=bvg&chco=A2C180&chds=0,130&chd=t:10,50,60,80,40,60,30,120&chtt=Vertical+bar+chart" width="300" height="225" alt="Vertical bar chart" />
+</body>
+</html>
85 collect.php
@@ -0,0 +1,85 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+?>
+
+<html>
+<head><title>Collect Details - MMT</title>
+</head>
+
+<body>
+ <br /></br >
+ <!-- A table with 2 columns, one figure and the other as details -->
+ <table align = "center" width = "100%">
+ <tr>
+ <td align = "center" valign = "top">
+ <table class = "transactions" align = "center">
+ <tr>
+ <?php
+ $firstRow = 1;
+ $query = "select friend, sum(total) as amt from ((select with_username as friend, with_amt as total from participates where email_add = '".$_SESSION['email']."') union (select email_add as friend, (-with_amt) as total from participates where with_username = '".$_SESSION['email']."')) group by friend";
+ $amtSet = "";
+ $amtLabelSet = "";
+ $nameSet = "";
+
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ die($query);
+ }
+
+ while ($row = oci_fetch_object($statement))
+ {
+ /* If the amount is 0 or negative, it should not be displayed */
+ if ($row->AMT <= 0)
+ {
+ continue;
+ }
+
+ if ($firstRow == 1)
+ {
+ echo "<tr><td class = 'transactions'>Friend</td><td class = 'transactions'>Amount</td></tr>";
+ $firstRow = 0;
+
+ $amtSet = "".$row->AMT;
+ $amtLabelSet = $row->FRIEND." (".$row->AMT.")";
+ $nameSet = "".$row->FRIEND;
+ }
+ else
+ {
+ $amtSet = $amtSet.",".$row->AMT;
+ $amtLabelSet = $amtLabelSet."|".$row->FRIEND." (".$row->AMT.")";
+ $nameSet = $nameSet."|".$row->FRIEND;
+ }
+ echo "<tr><td class = 'transactions'>".$row->FRIEND."</td><td class = 'transactions'>".$row->AMT."</td></tr>";
+ }
+ ?>
+ </tr>
+ </table>
+ </td>
+ <td align = "center" valign = "top">
+ <?php
+ if (0 == $firstRow)
+ {
+ echo "<img src='http://chart.apis.google.com/chart?chs=700x300&cht=p3&chd=t:".$amtSet."&chl=".$amtLabelSet."&chdl=".$nameSet."&chdlp=b&chtt=Amount Breakup' alt='Amount Breakup' />";
+ }
+ else
+ {
+ echo "<center>No transactions found!</center>";
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+</body>
+</html>
11 connection.php
@@ -0,0 +1,11 @@
+<?php
+ $connection = oci_connect($username = 'aakash',
+ $password = 'password',
+ $connection_string = '//oracle.cise.ufl.edu/orcl');
+
+ if (!$connection)
+ {
+ die("Connection to database ".$connection_string." failed!");
+ }
+
+?>
76 delGroups.php
@@ -0,0 +1,76 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+
+ if (isset($_POST['delete_group']))
+ {
+ /* First delete from belongs_to without commiting to database */
+ $query = "delete from belongs_to where group_id = ".$_POST['deleting_group'];
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement, OCI_NO_AUTO_COMMIT))
+ {
+ die($query);
+ }
+
+ /* If this deletion is success, it will commit both belongs_to and the current delete query */
+ $query = "delete from usergroup where group_id = ".$_POST['deleting_group'];
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement))
+ {
+ die($query);
+ }
+ header("Location:home.php");
+ }
+?>
+
+<html>
+<head><title>Delete Groups - MMT</title></head>
+<body>
+
+<br />
+<br />
+<form name="input" action="delGroups.php" method="post">
+
+Delete a group:
+
+<select name="deleting_group">
+ <option selected>----</option>
+<?php
+ $query = "select group_id, group_name from usergroup";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("Failed to execute query!");
+ }
+
+ while ($row = oci_fetch_object($statement))
+ {
+ echo "<option name= 'delete_group' value = '".$row->GROUP_ID."'>(".$row->GROUP_ID.") ".$row->GROUP_NAME."</option>";
+ }
+?>
+</select>
+<input name="delete_group" type="submit" value="delete" />
+
+</form>
+</body>
+
+</html>
162 delTransactions.php
@@ -0,0 +1,162 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+
+ /* Admin Case */
+ $whereClause = " and u.email_add = '".$_SESSION['email']."'";
+ if ($_SESSION['email'] == 'admin@mmt.com')
+ {
+ $whereClause = "";
+ }
+
+ if (isset($_POST['date']))
+ {
+ $query = "select name, t.trans_id, txn_date, txn_desc, tot_amt, shared_amt from shares s, transaction t, users u where u.email_add = s.email_add and t.txn_date between '".$_POST['start_date']."' and '".$_POST['end_date']."' and s.trans_id = t.trans_id".$whereClause." order by txn_date desc, trans_id desc";
+ }
+ /* Delete values as given by the form */
+ else if (isset($_POST['delTxns']))
+ {
+ $selectedTxns = $_POST['checkedtransid'];
+ if (!empty($selectedTxns))
+ {
+ $count = count($selectedTxns);
+ $whereClause = "where";
+ for ($i = 0; $i < $count; $i++)
+ {
+ if ($i != 0)
+ {
+ $whereClause = $whereClause." or";
+ }
+ $whereClause = $whereClause." trans_id = ".$selectedTxns[$i];
+ }
+
+ $query = "delete from shares ".$whereClause;
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement, OCI_NO_AUTO_COMMIT))
+ {
+ die($query);
+ }
+ $query = "delete from participates ".$whereClause;
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement, OCI_NO_AUTO_COMMIT))
+ {
+ die($query);
+ }
+ $query = "delete from transaction ".$whereClause;
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ die($query);
+ }
+ }
+
+ header("Location:delTransactions.php");
+ }
+ else
+ {
+ $query = "select name, t.trans_id, txn_date, txn_desc, tot_amt, shared_amt from shares s, transaction t, users u where u.email_add = s.email_add and s.trans_id = t.trans_id".$whereClause." order by txn_date desc, trans_id desc";
+ }
+
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ die($query);
+ }
+
+ $firstRow = 1;
+
+?>
+ <br /><br />
+ <table class = "transactions" align = "center">
+ <tr>
+ <?php
+ if ($_SESSION['email'] == 'admin@mmt.com')
+ {
+ echo "<td colspan = '7' align = 'center'>";
+ }
+ else
+ {
+ echo "<td colspan = '4' align = 'center'>";
+ }
+ ?>
+ <form name = 'filtertransactions' action='delTransactions.php' method='post'>
+ Start Date: <input type="text" name="start_date" />
+ End Date: <input type="text" name="end_date" /><br />
+ <input name="date" type="submit" value="Filter" />
+ <input name="reset" type="submit" value="View All" />
+ </form>
+ </td>
+ </tr>
+ <!-- If the user is admin, start a new form -->
+ <form name = 'deltxns' action = 'delTransactions.php' method = 'post'>
+<?php
+ $myTotal = 0; $overallTotal = 0;
+ while($row = oci_fetch_object($statement))
+ {
+ $displayCheckColumn = "";
+ $displayCheckBox = "";
+ $displayName = "";
+ $displayNameColumn = "";
+ $colspan = 2;
+ if ($_SESSION['email'] == 'admin@mmt.com')
+ {
+ $displayCheckColumn = "<td class = 'transactions'>Select</td><td class = 'transactions'>Txn Id</td>";
+ $displayCheckBox = "<td class = 'transactions'><input type = 'checkbox' name = 'checkedtransid[]' value = '".$row->TRANS_ID."'></td><td class = 'transactions'>".$row->TRANS_ID."</td>";
+ $displayNameColumn = "<td class = 'transactions'>Name</td>";
+ $displayName = "<td class = 'transactions'>".$row->NAME."</td>";
+ $colspan = 5;
+ }
+
+ if (1 == $firstRow)
+ {
+ echo "<tr>";
+
+ echo $displayCheckColumn.$displayNameColumn."<td class = 'transactions'>Date</td><td class = 'transactions'>Description</td><td class = 'transactions'>Your Share</td><td class = 'transactions'>Total Amount</td>";
+
+ echo "</tr>";
+ $firstRow = 0;
+ }
+
+ echo "<tr>";
+ echo $displayCheckBox.$displayName."<td class = 'transactions'>".$row->TXN_DATE."</td><td class = 'transactions'>".$row->TXN_DESC."</td><td class = 'transactions'>".$row->SHARED_AMT."</td><td class = 'transactions'>".$row->TOT_AMT."</td>";
+ echo "</tr>";
+ $myTotal = $myTotal + $row->SHARED_AMT;
+ $overallTotal = $overallTotal + $row->TOT_AMT;
+ }
+
+ /* Display totals only if there were rows */
+ if (0 == $firstRow)
+ {
+ echo "<tr><td class = 'transactions' colspan = '".$colspan."' align = 'center'>Totals</td><td class = 'transactions'>".$myTotal."</td><td class = 'transactions'>".$overallTotal."</td></tr>";
+
+ if ($_SESSION['email'] == 'admin@mmt.com')
+ {
+ echo "<tr><td colspan = '7' align = 'center'><input name = 'delTxns' type = 'submit' value = 'Delete' /></td></tr>";
+ echo "</form>";
+ }
+ }
+ else
+ {
+ echo "<center>No transactions found!</center>";
+ }
+?>
+ </table>
+
+<html>
+<head><title>Delete Transactions - MMT</title>
+</head>
+
+<body>
+
+</body>
+</html>
78 delUsers.php
@@ -0,0 +1,78 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+
+ if (isset($_POST['delete_email']))
+ {
+ $query = "update users set monthly_budget = -1 where email_add = '".$_POST['deleting_email']."'";
+ $statement = oci_parse($connection, $query);
+
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("user cannot be deactivated!");
+ }
+ header("Location:home.php");
+ }
+?>
+
+<html>
+<head><title>Modify users - MMT</title></head>
+<body>
+
+<form name="input" action="delUsers.php" method="post">
+<br />
+<br />
+Select a user to deactivate:
+
+<select name="deleting_email">
+ <option selected>----</option>
+<?php
+ $query = "select email_add, name, monthly_budget from users";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("Failed to execute query!");
+ }
+
+ while (1)
+ {
+ $row = oci_fetch_object($statement);
+
+ if (!$row)
+ {
+ break;
+ }
+
+ if (($row->EMAIL_ADD == 'admin@mmt.com') || (($row->MONTHLY_BUDGET == (-1))))
+ {
+ continue;
+ }
+
+ echo "<option name= 'delete_user' value = '".$row->EMAIL_ADD."'>".$row->NAME." (".$row->EMAIL_ADD.")</option>";
+ }
+?>
+</select>
+<input name="delete_email" type="submit" value="Deactivate" />
+
+</form>
+</body>
+
+</html>
44 dropall.php
@@ -0,0 +1,44 @@
+#!/usr/local/bin/php
+
+<?php
+ $connection = oci_connect($username = 'aakash',
+ $password = 'password',
+ $connection_string = '//oracle.cise.ufl.edu/orcl');
+
+ if (!$connection)
+ {
+ die("Connection Failed");
+ }
+
+ echo "\nBegin to drop tables...\n";
+
+ $statement = oci_parse($connection, 'drop table shares');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table participates');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table belongs_to');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table has_friends');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table usergroup');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table transaction');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table category');
+ oci_execute($statement);
+
+ $statement = oci_parse($connection, 'drop table users');
+ oci_execute($statement);
+
+ echo "\nAll tables dropped...\n";
+
+ oci_free_statement($statement);
+ oci_close($connection);
+
+?>
85 give.php
@@ -0,0 +1,85 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+?>
+
+<html>
+<head><title>Give Details - MMT</title>
+</head>
+
+<body>
+ <br /></br >
+ <!-- A table with 2 columns, one figure and the other as details -->
+ <table align = "center" width = "100%">
+ <tr>
+ <td align = "center" valign = "top">
+ <table class = "transactions">
+ <?php
+ /* First check for the actual 'give' type (right column summation) */
+ $firstRow = 1;
+ $query = "select friend, sum(total) as amt from ((select with_username as friend, with_amt as total from participates where email_add = '".$_SESSION['email']."') union (select email_add as friend, (-with_amt) as total from participates where with_username = '".$_SESSION['email']."')) group by friend";
+ $amtSet = "";
+ $amtLabelSet = "";
+ $nameSet = "";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ die($query);
+ }
+
+ while ($row = oci_fetch_object($statement))
+ {
+ /* If the amount is 0 or negative, it should not be displayed */
+ if ($row->AMT >= 0)
+ {
+ continue;
+ }
+
+ $row->AMT = (-$row->AMT);
+
+ if ($firstRow == 1)
+ {
+ echo "<tr><td class = 'transactions'>Friend</td><td class = 'transactions'>Amount</td></tr>";
+ $firstRow = 0;
+ $amtSet = "".$row->AMT;
+ $amtLabelSet = $row->FRIEND." (".$row->AMT.")";
+ $nameSet = "".$row->FRIEND;
+ }
+ else
+ {
+ $amtSet = $amtSet.",".$row->AMT;
+ $amtLabelSet = $amtLabelSet."|".$row->FRIEND." (".$row->AMT.")";
+ $nameSet = $nameSet."|".$row->FRIEND;
+ }
+ echo "<tr><td class = 'transactions'>".$row->FRIEND."</td><td class = 'transactions'>".$row->AMT."</td></tr>";
+ }
+ ?>
+ </table>
+ </td>
+ <td align = "center" valign = "top">
+ <?php
+ /* If there is nothing to display, skip displaying the chart */
+ if (0 == $firstRow)
+ {
+ echo "<img src='http://chart.apis.google.com/chart?chs=700x300&cht=p3&chd=t:".$amtSet."&chl=".$amtLabelSet."&chdl=".$nameSet."&chdlp=b&chtt=Amount Breakup' alt='Amount Breakup' />";
+ }
+ else
+ {
+ echo "<center>No transactions found!</center>";
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+</body>
+</html>
244 group.php
@@ -0,0 +1,244 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+
+ if(isset($_POST['group_name']))
+ {
+ $query = "select MAX(group_id) as m from usergroup";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die ("Failed to execute query!");
+ }
+
+ $row = oci_fetch_object($statement);
+ if (!$row)
+ {
+ $groupId = 1;
+ }
+ else
+ {
+ echo $row->M;
+ $groupId = ($row->M) + 1;
+ }
+
+ $finalquery = "insert into usergroup values (".$groupId.", '".$_SESSION['email']."','".$_POST['my_group_name']."')";
+
+ $finalStatement = oci_parse($connection, $finalquery);
+
+ if (!oci_execute($finalStatement, OCI_NO_AUTO_COMMIT))
+ {
+ echo $finalquery;
+ die("User group could not be added!");
+ }
+
+ $query = "insert into belongs_to values ('".$_POST['my_friend_name']."', $groupId)";
+
+ $Statement = oci_parse($connection, $query);
+
+ if (!oci_execute($Statement))
+ {
+ echo $query;
+ die("User could not be added!");
+ }
+
+
+ header("Location:home.php");
+ }
+ /*************** Adding a friend to a group *************************/
+ else if (isset($_POST['group_friend']))
+ {
+ $id = $_POST['to_group'];
+
+ $finalQuery = "insert into belongs_to values ('".$_POST['add_friend_email']."',".$id.")";
+ $finalStatement = oci_parse($connection, $finalQuery);
+ if (!oci_execute($finalStatement))
+ {
+ echo("<br /><br />The user is already present in the selected group. Try again!");
+ }
+ else
+ {
+ header("Location:home.php");
+ }
+ }
+ /*************** Deleting a friend from a group *************************/
+ else if (isset($_POST['delete_friend']))
+ {
+ $id = $_POST['gname'];
+
+ $finalQuery = "delete from belongs_to where email_add = '".$_POST['friend_delete_group']."' and group_id = ".$id;
+ $finalStatement = oci_parse($connection, $finalQuery);
+ if (!oci_execute($finalStatement))
+ {
+ echo $finalQuery;
+ die("Friend cannot be deleted!");
+ }
+
+ $newQuery = "select * from belongs_to where group_id = ".$id;
+ $newStatement = oci_parse($connection, $newQuery);
+ if (!oci_execute($newStatement))
+ {
+ echo $newQuery;
+ die("Query failed!");
+ }
+
+ $row = oci_fetch_object($newStatement);
+ if (!$row)
+ {
+ $deleteQuery = "delete from usergroup where group_id = ".$id;
+ $delStatement = oci_parse($connection, $deleteQuery);
+
+ if (!oci_execute($delStatement))
+ {
+ echo $deleteQuery;
+ die("Group cannot be deleted!");
+ }
+ }
+
+ header("Location:home.php");
+ }
+?>
+
+<html>
+<head><title>Modify Groups - MMT</title></head>
+<script type = "text/javascript" src = "js/validations.js"></script>
+<body>
+
+<form name = 'groupform' action = 'group.php' onsubmit = 'return validateGroup()' method = 'post' >
+ <br />
+ <br />
+ <table class = "transactions" border = "0" align = "center">
+ <tr>
+ <td class = "transactions">Choose one of the options below:</td>
+ </tr>
+ <tr><td bgcolor = '#A4C639'>Create a new group</td></tr>
+ <tr>
+ <td>
+ Group Name: <input type="text" name="my_group_name" />
+ <br />
+ <br />
+ Friend Name: <input type="text" name="my_friend_name" />
+ <input class = "mainButton" name="group_name" type="submit" value="Create" />
+ </td>
+ </tr>
+ <tr>
+ <td bgcolor = '#A4C639'>
+ Add a friend to a group
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <!--Friend <input type="text" name="add_friend_email" /> to -->
+ Friend
+ <select name="add_friend_email">
+ <option selected>----</option>
+ <?php
+ $query = "select friend_email_add from has_friends where email_add = '".$_SESSION['email']."'";
+ $statement = oci_parse($connection, $query);
+ if (!oci_execute($statement))
+ {
+ echo $query;
+ die("Failed to execute query!");
+ }
+
+ while (1)
+ {
+ $row = oci_fetch_object($statement);
+
+ if (!$row)
+ {
+ break;
+ }
+
+ $subQuery = "select name from users where email_add = '".$row->FRIEND_EMAIL_ADD."'";
+ $subStatement = oci_parse($connection, $subQuery);
+ if (!oci_execute($subStatement))
+ {
+ echo $subQuery;
+ die("Failed to execute subquery!");
+ }
+
+ $friendName = oci_fetch_object($subStatement);
+
+ echo "<option name= 'delete_email' value = '".$row->FRIEND_EMAIL_ADD."'>".$friendName->NAME." (".$row->FRIEND_EMAIL_ADD.")</option>";
+ }
+ ?>
+ </select>
+ to
+ <!-- Show all groups to the user of which he is the owner -->
+ <select name = "to_group">
+ <?php
+ $grpQuery = "select group_id, group_name from usergroup where group_owner = '".$_SESSION['email']."'";
+ $statement = oci_parse($connection, $grpQuery);
+ if (!oci_execute($statement))
+ {
+ echo $grpQuery;
+ die ("Failed to execute query!");
+ }
+ while (1)
+ {
+ $row = oci_fetch_object($statement);
+ if (!$row)
+ {
+ break;
+ }
+
+ echo "<option value=".$row->GROUP_ID.">".$row->GROUP_NAME."</option>";
+ }
+ ?>
+ </select>
+ <input class="mainButton" name="group_friend" type="submit" value="Add" />
+ </td>
+ </tr>
+ <tr>
+ <td bgcolor = '#A4C639'>Delete a friend from a group</td>
+ </tr>
+ <tr>
+ <td>
+ Friend <input type="text" name="friend_delete_group" /> from
+ <select name = "gname">
+ <?php
+ if (!oci_execute($statement))
+ {
+ echo $grpQuery;
+ die ("Failed to execute query!");
+ }
+
+ while (1)
+ {
+ $row = oci_fetch_object($statement);
+ if (!$row)
+ {
+ break;
+ }
+
+ /* group names do not allow */
+ echo "<option value=".$row->GROUP_ID.">".$row->GROUP_NAME."</option>";
+ }
+ ?>
+ </select>
+ <input class = "mainButton" name = "delete_friend" type="submit" value="Delete" />
+ </td>
+ </tr>
+ </table>
+</form>
+
+</body>
+</html>
30 groupinfo.php
@@ -0,0 +1,30 @@
+#!/usr/local/bin/php
+<?php
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ echo "Connection lost";
+ exit(1);
+ }
+ $groupid=$_GET['groupName'];
+ $query3 = "select email_add from belongs_to where group_id in (select group_id from usergroup where GROUP_NAME = '".$groupid."')";
+ $statement3 = oci_parse($connection, $query3);
+ if (!oci_execute($statement3))
+ {
+ echo $groupid;
+ }
+ $response="";
+ $i=0;
+ while(1)
+ {
+ $row = oci_fetch_object($statement3);
+ if (!$row)
+ {
+ break;
+ }
+ $response=$response.$row->EMAIL_ADD.",";
+ $i++;
+ }
+ $response=$i.",".$response;
+ echo $response;
+?>
85 home.php
@@ -0,0 +1,85 @@
+#!/usr/local/bin/php
+
+<?php session_start();
+
+ if (!isset($_SESSION['email']))
+ {
+ header("Location:index.php");
+ }
+
+ if (!require("mainBar.php"))
+ {
+ die("Failed to include mainbar!");
+ }
+?>
+
+<html>
+<head><title>Home - MMT</title>
+</head>
+
+<body>
+ <br /></br >
+ <?php
+ if ('admin@mmt.com' != $_SESSION['email'])
+ {
+ ?>
+ <table class = "transactions" align = "center" border = "1" width = "50%">
+ <?php
+ }
+ else
+ {
+ ?>
+ <table class = "transactions" align = "center" border = "1" width = "30%">
+ <?php
+ }
+ ?>
+ <tr>
+ <?php
+ if ('admin@mmt.com' != $_SESSION['email'])
+ {
+ ?>
+ <td bgcolor = "#A4C639">Transactions</td>
+ <td bgcolor = "#A4C639">Other</td>
+ <?php
+ }
+ else
+ {
+ ?>
+ <td>Perform database modifications</td>
+ <?php
+ }
+ ?>
+ </tr>
+ <tr>
+ <?php
+ if ('admin@mmt.com' != $_SESSION['email'])
+ {
+ ?>
+ <td valign = "top">
+ <a href = "addTransaction.php">Add Transaction</a> <br />
+ <a href = "viewTransactions.php">View Transactions</a> <br />
+ <a href = "reportPayment.php">Report Payment</a> <br />
+ <a href = "reportLoanDebt.php">Report Loan/Debt</a> <br />
+ </td>
+ <td valign = "top">
+ <a href = "modFriends.php">Modify Friends</a> <br />
+ <a href = "group.php">Modify Groups</a> <br />
+ </td>
+ <?php
+ }
+ else
+ {
+ ?>
+ <td valign = "top">
+ <a href = "delUsers.php">Deactivate Users</a> <br />
+ <a href = "delTransactions.php">Delete Transactions</a> <br />
+ <a href = "delGroups.php">Delete Groups</a> <br />
+ <a href = "modCategories.php">Modify Categories</a> <br />
+ </td>
+ <?php
+ }
+ ?>
+ </tr>
+ </table>
+</body>
+</html>
BIN  images/logo.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  images/one.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  images/two.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 index.php
@@ -0,0 +1,97 @@
+#!/usr/local/bin/php
+
+<?php session_start(); ?>
+
+<html>
+<head>
+<title>Welcome to MMT</title>
+<link rel = "stylesheet" href = "mmt.css">
+<script type = "text/javascript" src = "js/validations.js"></script>
+</head>
+<body>
+
+<table>
+<tr>
+<td>
+<img src = "images/logo.jpg" />
+</td>
+<td width = "100%">
+<?php
+ if (isset($_SESSION['email']))
+ {
+ header("Location:home.php");
+ }
+ // process only if the login button is clicked
+ if(isset($_POST['login']))
+ {
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+
+ $pwd = md5($_POST['password']);
+ $usrname = $_POST['username'];
+
+ /* For a valid user, the monthly_budget should always be >= 0. if it is < 0, it means that the users has not joined MMT yet */
+ $query = "select name, monthly_budget from users where email_add = '".$usrname."' and password = '".$pwd."' and monthly_budget >= 0";
+ //echo $query;
+
+ // check for a valid username and password combination
+ $stmt = oci_parse($connection, $query);
+ if (!oci_execute($stmt))
+ {
+ die("Failed to execute query");
+ }
+
+ // there will be no rows if the combination is not true
+ $row = oci_fetch_object($stmt);
+ if (!$row)
+ {
+ echo "Invalid username / password!";
+ }
+ else
+ {
+ $_SESSION['email'] = $usrname;
+ $_SESSION['alias'] = $row->NAME;
+ $_SESSION['mbudget'] = $row->MONTHLY_BUDGET;
+ header("Location:home.php");
+ }
+ }
+ else if(isset($_POST['signup'])) // if the signup button is clicked, redirect to signup.php page
+ {
+ header("Location:signUp.php");
+ }
+?>
+
+<form name = 'loginform' action = 'index.php' onsubmit = 'return validateSignIn()' method = 'post'>
+ <table align = 'center'>
+ <tr>
+ <td>Username:</td><td><input name = 'username' type = 'text' /></td>
+ </tr>
+ <tr>
+ <td>Password:</td><td><input name = 'password' type = 'password' /></td>
+ </tr>
+ <tr>
+ <td align = 'center' colspan = '2'>
+ <input class = 'mainButton' name = 'login' type = 'submit' value = 'Sign In' />
+ </td>
+ </tr>
+</form>
+<form name = 'signUpform' action = 'index.php' method = 'post'>
+ <tr>
+ <td align = 'center' colspan = '2'>Do not have any account yet?</td>
+ </tr>
+ <tr>
+ <td align = 'center' colspan = '2'>
+ <input class = 'mainButton' name = 'signup' type = 'submit' value = 'Sign Up Now!' />
+ </td>
+ </tr>
+ </table>
+</form>
+</td>
+</tr>
+<table>
+
+</body>
+</html>
152 js/validations.js
@@ -0,0 +1,152 @@
+function validateSignIn()
+{
+ var jUserName = document.forms["loginform"]["username"].value;
+ if (null == jUserName || "" == jUserName)
+ {
+ alert("Username cannot be blank!");
+ return false;
+ }
+
+ var jUserName = document.forms["loginform"]["password"].value;
+ if (null == jUserName || "" == jUserName)
+ {
+ alert("Password cannot be blank!");
+ return false;
+ }
+
+ return true;
+}
+
+function validateSignUp()
+{
+ var jVar = document.forms["signupform"]["username"].value;
+ if (null == jVar || "" == jVar)
+ {
+ alert("Username cannot be blank!");
+ return false;
+ }
+
+ var jVar = document.forms["signupform"]["password"].value;
+ if (null == jVar || "" == jVar)
+ {
+ alert("Password cannot be blank!");
+ return false;
+ }
+
+ var jVar2 = document.forms["signupform"]["repassword"].value;
+ if (null == jVar2 || "" == jVar2)
+ {
+ alert("You must re-enter the password!");
+ return false;
+ }
+
+ if (jVar != jVar2)
+ {
+ alert("Passwords must match!");
+ return false;
+ }
+
+ var jVar = document.forms["signupform"]["name"].value;
+ if (null == jVar || "" == jVar)
+ {
+ alert("Alias cannot be blank!");
+ return false;
+ }
+
+ return true;
+}
+
+function validateProfileSettings()
+{
+ var jVar = document.forms["changeSettings"]["password"].value;
+ if (null == jVar || "" == jVar)
+ {
+ alert("Password cannot be blank!");
+ return false;
+ }
+
+ var jVar2 = document.forms["changeSettings"]["repassword"].value;
+ if (null == jVar2 || "" == jVar2)
+ {
+ alert("You must re-enter the password!");
+ return false;
+ }
+
+ if (jVar != jVar2)
+ {
+ alert("Passwords must match!");
+ return false;
+ }
+
+ var jVar = document.forms["changeSettings"]["alias"].value;
+ if (null == jVar || "" == jVar)
+ {
+ alert("Alias cannot be blank!");
+ return false;
+ }
+
+ return true;
+}
+
+
+function validateReportPayment()
+{
+ var jVar = document.forms["reportPayment"]["paymentAmt"].value;
+ if (null == jVar || "" == jVar )
+ {
+ alert("Payment amount cannot be blank!");
+ return false;
+ }
+ if(0 == jVar)
+ {
+ alert("Payment amount cannot be zero!");
+ return false;
+ }
+
+ var jVar2 = document.forms["reportPayment"]["paymentDate"].value;
+ if (null == jVar2 || "" == jVar2)
+ {
+ alert("You must enter the Payment Date!");
+ return false;
+ }
+
+ return true;
+}
+
+function validateReportLoanDebt()
+{
+ var jVar = document.forms["reportPayment"]["paymentAmt"].value;
+ if (null == jVar || "" == jVar )
+ {
+ alert("Payment amount cannot be blank!");
+ return false;
+ }
+ if(0 == jVar)
+ {
+ alert("Payment amount cannot be zero!");
+ return false;
+ }
+
+ var jVar2 = document.forms["reportPayment"]["paymentDate"].value;
+ if (null == jVar2 || "" == jVar2)
+ {
+ alert("You must enter the Payment Date!");
+ return false;
+ }
+
+ return true;
+
+}
+function validateGroup()
+{
+ var jVar1 = document.forms["groupform"]["my_group_name"].value;
+ var jVar2 = document.forms["groupform"]["my_friend_name"].value;
+ if (null == jVar1 || "" == jVar1 || null == jVar2 || "" == jVar2)
+ {
+ alert("Group Name or Friend Name cannot be blank!");
+ return false;
+ }
+
+ return true;
+
+}
8 logout.php
@@ -0,0 +1,8 @@
+#!/usr/local/bin/php
+
+<?php
+ session_start();
+ session_unset();
+ session_destroy();
+ header("Location:index.php");
+?>
144 mainBar.php
@@ -0,0 +1,144 @@
+<link rel="stylesheet" href="mmt.css">
+
+<table width="100%" border="0" cellspacing="0" bgcolor="#2D2D2D">
+ <tr>
+ <td>
+ <a class = "bar" href = "home.php">Home</a>
+ </td>
+ <td>
+ <?php
+ if (!require("connection.php"))
+ {
+ // connection failure return error code 1
+ exit(1);
+ }
+ $give = 0;
+ $collect = 0;
+
+ $query = "select friend, sum(total) as amt from ((select with_username as friend, with_amt as total from participates where email_add = '".$_SESSION['email']."') union (select email_add as friend, (-with_amt) as total from participates where with_username = '".$_SESSION['email']."')) group by friend";
+
+ $stmt = oci_parse($connection, $query);
+ if (!oci_execute($stmt))
+ {
+ echo $queryCollect;
+ die("Failed to execute query");
+ }
+
+ while ($row = oci_fetch_object($stmt))
+ {
+ if ($row->AMT > 0)
+ {
+ $collect = $collect + $row->AMT;
+ }
+ else if ($row->AMT < 0)
+ {
+ $give = $give + (-$row->AMT);
+ }
+ /* We do not want to calculate 0 sums */
+ }
+ ?>
+ <a class = "bar" href='give.php'>Give&nbsp;$<?php echo $give; ?></a>
+ </td>
+ <td>
+ <a class = "bar" href='collect.php'>Collect&nbsp;$<?php echo $collect; ?></a>
+ </td>
+ <td width="100%">
+ <form name = "searchform" action = "search.php" method = "get">
+ <input class = "searchBar" name = "searchString" type = "text" value = "Search..." onfocus="this.value = '';"/>
+ <input type = "submit" style="visibility:hidden" />
+ </form>
+ </td>
+ <td>
+ <a class = "bar" href='profileSettings.php'>Monthly&nbsp;Budget:&nbsp$<?=$_SESSION['mbudget'];?></a>
+ </td>
+ <td>
+ <a class = "bar" href = "profileSettings.php" title = "<?php echo $_SESSION['email'] ?>">
+ <?php session_start();
+ echo ucfirst($_SESSION['alias']);
+ ?></a>
+ </td>
+ <td>
+ <a class = "bar" href = "logout.php" onclick = "if (!confirm('Are you sure?')) return false;">Logout</a>
+ </td>
+ </tr>
+</table>
+<!-- This is to implement the monthly budget bar -->
+<table border = "0" cellpadding = "0" cellspacing = "0" width = "100%">
+ <tr>
+ <?php
+ $budgetQuery = "select sum(shared_amt) as amt from shares s, transaction t where t.trans_id = s.trans_id and s.email_add = '".$_SESSION['email']."' and t.txn_date like '%".strtoupper(date('M-y'))."'";
+
+ /* If the query fails to execute, the expense is taken to be 0. from
+ database it will be updated later */
+ $monthExp = 0;
+
+ $stmt = oci_parse($connection, $budgetQuery);
+ if (!oci_execute($stmt))
+ {
+ echo $budgetQuery;
+ die("Failed to execute query");
+ }
+ $row = oci_fetch_object($stmt);
+ if ($row->AMT)
+ {
+ $monthExp = $row->AMT;
+ }
+
+ //echo $monthExp;
+ /* If the monthly budget is not defined */
+ if ($_SESSION['mbudget'] == 0)
+ {
+ echo "<td bgcolor='#A4C639' width='100%'><font color='#000000' size='3'><a href='profileSettings.php'>Keep track of your expenses! Click here to define monthly budget now!</a></font></td>";
+ }
+ else // the monthly budget is defined
+ {
+ if ($monthExp > $_SESSION['mbudget'])
+ {
+ echo "<td bgcolor='#A4C639' width='100%'><font color='#000000' size='3'>Budget overdue by $".($monthExp - $_SESSION['mbudget'])."!</font></td>";
+ }
+ else
+ {
+ /* Calculate Percentage */
+ $monthPercentage = ($monthExp / $_SESSION['mbudget']) * 100;
+ $monthPercentage = round($monthPercentage);
+
+ /* Display in used td */
+ if ($monthPercentage < 50)
+ {
+ $unUsedString = "<font color='#000000' size='2'>$".$monthExp." of $".$_SESSION['mbudget']." used</font>";
+ $usedString = "";
+ }
+ else // disply in unused td
+ {
+ $usedString = "<font color='#000000' size='2'>$".$monthExp." of $".$_SESSION['mbudget']." used</font>";
+ $unUsedString = "";
+ }
+
+ /* Colour used as blue */
+ echo "<td bgcolor='#99CCFF' width='".$monthPercentage."%' align='right'>".$usedString."</td>";
+ echo "<td bgcolor='#A4C639' width='".(100 - $monthPercentage)."%'>".$unUsedString."</td>";
+
+ /* Check if mail needs to be sent to the user */
+ if ($monthPercentage > 90)
+ {
+ if (!isset($_SESSION['notification'])
+ || ($_SESSION['notification'] == 'notsent'))
+ {
+ $to = $_SESSION['email'];
+ $headers = "From: admin@mmt.com";
+ $subject = "Budget Overdue Notification";
+ $message = "Greetings ".ucfirst($_SESSION['alias']).",\n\nThis is to notify that your monthly expense is nearing your budget limit or has already exceeded!\nYour current monthly expense: $".$monthExp.".\nYour defined monthly budget is: $".$_SESSION['mbudget'].".\n\nYours truly,\nAdminstrator\nMMT.com\n";
+ mail($to, $subject, $message, $headers);
+ }
+
+ $_SESSION['notification'] = 'sent';
+ }
+ else
+ {
+ $_SESSION['notification'] = 'notsent';
+ }
+ }
+ }
+ ?>
+ </tr>
+</table>
71 mmt.css
@@ -0,0 +1,71 @@
+a:link {
+ color: #DD4B39 }
+a:visited {
+ color: #DD4B39 }
+a:hover {
+ color: #000000 }
+a {
+ text-decoration: none }
+
+.bar:link {
+ color: #FFFFFF }
+.bar:visited {
+ color: #FFFFFF }
+.bar:hover {
+ color: #BDBDBD }
+.bar {
+ text-decoration: none;
+ color: #FFFFFF; }
+
+.searchBar {
+ background-color: #BDBDBD;
+ border: 1px none;
+ height: 35px;
+ width: 300px;
+}
+
+html, body {
+ margin:10;
+ padding:0;
+ height:80%;
+ border:none
+}
+
+td {
+ padding: 10px;
+}
+
+.transactions {
+ border:1px solid black;
+ border-collapse: collapse;
+ padding: 5px;
+}
+
+.mainButton {
+ color: #FFFFFF;
+ font-weight: bold;
+ background-color: #DD4B39;
+ border-style: solid;
+ border-width: 1px;
+ border-color: #BDBDBD;
+ width: 120px;
+ height: 35px;
+}