Skip to content

Commit

Permalink
Add Label to payment
Browse files Browse the repository at this point in the history
  • Loading branch information
npfedwards committed Oct 2, 2012
1 parent aa3afa1 commit db7d43f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
22 changes: 22 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ function paymentForm($user){
<option>Yes</option>
</select>
<span id='repeatoptions'></span>
<label for='labelselect'>Label</span>
<select name='labels' id='labelselect'>
<option value='0'>No Label</option>
";
$query="SELECT * FROM labels WHERE UserID='$user'";
$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_assoc($result)){
echo "<option value='".$row['LabelID']."' style='color:".$row['Colour']."'>".stripslashes($row['LabelName'])."</option>";
}
echo "</select>
<button onclick=\"addPayment()\">Add Payment</button></span>
</div>";
}
Expand Down Expand Up @@ -408,6 +419,17 @@ function checkAccount($user, $account, $default=NULL){
return $account;
}

function checklabel($user, $label, $default=0){
if($label!=0){
$query="SELECT * FROM labels WHERE UserID='$user' AND LabelID='$label'";
$result=mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result)!=1){ // Check if the account is not connected to this user
$label=$default;
}
}
return $label;
}

function currencySymbol($user){
$query="SELECT * FROM users WHERE UserID='$user'";
$currencyresult=mysql_query($query) or die(mysql_error());
Expand Down
3 changes: 2 additions & 1 deletion js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function addPayment(){
var offset=escape(document.getElementById("page").value);
var recvalue=escape(document.getElementById("accbal").value);
var perpage=escape(document.getElementById("numperpage").value);
var label=escape(document.getElementById("labelselect").value);

var repeat=document.getElementById("repeat").value;
if(repeat==="Yes"){
Expand All @@ -177,7 +178,7 @@ function addPayment(){
document.getElementById("repeat").value="No";
document.getElementById("repeatoptions").innerHTML="";
}
ajaxRequest("xmlhttp/addpayment.php?o="+otherparty+"&d="+desc+"&a="+amount+"&t="+type+"&day="+day+"&month="+month+"&year="+year+"&account="+account+"&getorgive="+getorgive+"&accsel="+accsel+"&order="+order+"&rf="+rf+"&rt="+rt+"&offset="+offset+"&recvalue="+recvalue+"&perpage="+perpage+"&field="+field, a);
ajaxRequest("xmlhttp/addpayment.php?o="+otherparty+"&d="+desc+"&a="+amount+"&t="+type+"&day="+day+"&month="+month+"&year="+year+"&account="+account+"&getorgive="+getorgive+"&accsel="+accsel+"&order="+order+"&rf="+rf+"&rt="+rt+"&offset="+offset+"&recvalue="+recvalue+"&perpage="+perpage+"&field="+field+"&label="+label, a);
}

function showWithOffset(){
Expand Down
2 changes: 1 addition & 1 deletion xmlhttp/addlabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if($loggedin==1){
$label=sanitise('label');
//Need a long list of colours!
$colourarray=array('#A00', '#0A0', '#565600', '#00A', '#0F7GEE');
$colourarray=array('#A00', '#0A0', '#565600', '#00A', '#0F7DEE');
$query="SELECT * FROM labels WHERE UserID='$user'";
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_assoc($result)){
Expand Down
23 changes: 12 additions & 11 deletions xmlhttp/addpayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
$recvalue=sanitise('recvalue');
$perpage=sanitise('perpage');
$field=sanitise('field');

$label=sanitise('label');
$label=checklabel($user, $label);

$time=strtotime($m."/".$d."/".$y);

Expand All @@ -35,7 +36,7 @@
if($toaccount!=0){
$theotherparty=getaccountname($account);
$toamount=-$amount;
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount) VALUES ('$user', '$toaccount', '$time', '$theotherparty', '$desc', '$toamount', '$type', '$account')";
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, LabelID) VALUES ('$user', '$toaccount', '$time', '$theotherparty', '$desc', '$toamount', '$type', '$account', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#001");
$insertid=mysql_insert_id();
$otherparty=getaccountname($toaccount);
Expand All @@ -46,7 +47,7 @@
$insertid=0;
}

$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID) VALUES ('$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$insertid')";
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, LabelID) VALUES ('$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$insertid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#002");
$paymentid=mysql_insert_id();

Expand All @@ -61,14 +62,14 @@
$expiretime=$time+($rt*31*86400);

if($insertid!=0){ //Repeat Paired Payment
$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount) VALUES ('$rf', '$rt', '$expiretime', '$user', '$toaccount', '$time', '$theotherparty', '$desc', '$amount', '$type', '$account')";
$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, LabelID) VALUES ('$rf', '$rt', '$expiretime', '$user', '$toaccount', '$time', '$theotherparty', '$desc', '$amount', '$type', '$account', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#004-1");
$repeatinsertid=mysql_insert_id();
$query="UPDATE payments SET RepeatID='$repeatinsertid' WHERE PaymentID='$insertid'";
mysql_query($query) or die(mysql_error()." addpayment#004-2");
}

$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID) VALUES ('$rf', '$rt', '$expiretime', '$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$repeatinsertid')";
$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, LabelID) VALUES ('$rf', '$rt', '$expiretime', '$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$repeatinsertid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#004");
$repeatid=mysql_insert_id();
$query="UPDATE payments SET RepeatID='$repeatid' WHERE PaymentID='$paymentid'";
Expand All @@ -92,11 +93,11 @@

while($time<time()+86400 && $i<=$rt){
if($insertid!=0){
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, RepeatID) VALUES ('$user', '$toaccount', '$time', '$theotherparty', '$desc', '$toamount', '$type', '$account', '$repeatinsertid')";
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, RepeatID, LabelID) VALUES ('$user', '$toaccount', '$time', '$theotherparty', '$desc', '$toamount', '$type', '$account', '$repeatinsertid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#005");
$insertid=mysql_insert_id();
}
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, RepeatID) VALUES ('$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$insertid', '$repeatid')";
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, RepeatID, LabelID) VALUES ('$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$insertid', '$repeatid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#006");

if($insertid!=0){
Expand All @@ -119,14 +120,14 @@
$expiretime=$time+($rt*$rf*86400);
if($insertid!=0){ //Repeat Paired Payment

$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount) VALUES ('$rf', '$rt', '$expiretime', '$user', '$toaccount', '$time', '$theotherparty', '$desc', '$amount', '$type', '$account')";
$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, LabelID) VALUES ('$rf', '$rt', '$expiretime', '$user', '$toaccount', '$time', '$theotherparty', '$desc', '$amount', '$type', '$account', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#008-1");
$repeatinsertid=mysql_insert_id();
$query="UPDATE payments SET RepeatID='$repeatinsertid' WHERE PaymentID='$insertid'";
mysql_query($query) or die(mysql_error()." addpayment#008-2");
}

$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID) VALUES ('$rf', '$rt', '$expiretime', '$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$repeatinsertid')";
$query="INSERT INTO repeats (Frequency, Times, ExpireTime, UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, LabelID) VALUES ('$rf', '$rt', '$expiretime', '$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$repeatinsertid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#008");
$repeatid=mysql_insert_id();
$query="UPDATE payments SET RepeatID='$repeatid' WHERE PaymentID='$paymentid'";
Expand All @@ -141,11 +142,11 @@
$i=2;
while($time<time()+604800 && $i<=$rt){
if($insertid!=0){
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, RepeatID) VALUES ('$user', '$toaccount', '$time', '$theotherparty', '$desc', '$toamount', '$type', '$account', '$repeatinsertid')";
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, RepeatID, LabelID) VALUES ('$user', '$toaccount', '$time', '$theotherparty', '$desc', '$toamount', '$type', '$account', '$repeatinsertid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#009");
$insertid=mysql_insert_id();
}
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, RepeatID) VALUES ('$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$insertid', '$repeatid')";
$query="INSERT INTO payments (UserID, AccountID, Timestamp, PaymentName, PaymentDesc, PaymentAmount, PaymentType, ToAccount, PairedID, RepeatID, LabelID) VALUES ('$user', '$account', '$time', '$otherparty', '$desc', '$amount', '$type', '$toaccount', '$insertid', '$repeatid', '$label')";
mysql_query($query) or die(mysql_error()." addpayment#010");

if($insertid!=0){
Expand Down

0 comments on commit db7d43f

Please sign in to comment.