diff --git a/TODO b/TODO index 8c0a114..c350cd0 100755 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ * tokens + ban system * remember me * htmlspecialchars => on users objects -* Associate a guest with someone install.php : ============= @@ -15,10 +14,12 @@ inc/Invoices.class.php : * Better way to store date ? (use specific date types) * Better way to store users in ? * Modify load() method to handle complex queries (such as WHERE date < DATE_1 AND date > DATE_2) +* Buyer as user object ? index.php?do=new_invoice : ========================== * Improve date handling for form display +* Onchange not working as wanted index.php?do=settings : ======================= diff --git a/inc/Invoices.class.php b/inc/Invoices.class.php index 45e9eb5..808edfd 100644 --- a/inc/Invoices.class.php +++ b/inc/Invoices.class.php @@ -2,7 +2,7 @@ require_once('data/config.php'); require_once('Storage.class.php'); - class Invoices extends Storage { + class Invoice extends Storage { protected $id, $date, $users_in, $buyer, $amount, $what; protected $TABLE_NAME = "Invoices"; protected $fields = array( @@ -54,7 +54,7 @@ $this->buyer = (int) $buyer; } - public function setAmount ($admount) { + public function setAmount ($amount) { $this->amount = (float) $amount; } diff --git a/index.php b/index.php index 175bf28..67e9d3c 100644 --- a/index.php +++ b/index.php @@ -203,18 +203,25 @@ break; case 'new_invoice': - if(!empty($_POST['what']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_day']) && !empty($_POT['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) { + if(!empty($_POST['what']) && !empty($_POST['amount']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_day']) && !empty($_POST['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) { $invoice = new Invoice(); $invoice->setWhat($_POST['what']); $invoice->setAmount($_POST['amount']); $invoice->setBuyer($current_user->getId()); - $invoice->setDate(); + $invoice->setDate(time()); - //TODO : Handle users_in + guests + $users_in = ''; + $guests = array(); + foreach($_POST['users_in'] as $user) { + $users_in .= ($users_in != '') ? ', ' : ''; + $users_in .= $user.'('.(!empty($_POST['guest_user_'.$user]) ? (int) $_POST['guest_user_'.$user] : '0').')'; + $guests[$user] = (int) $_POST['guest_user_'.$user]; + } + $invoice->setUsersIn($users_in); - $invoice->save(); - header('location: index.php'); - exit(); + //$invoice->save(); +// header('location: index.php'); + // exit(); } $users_list = new User(); @@ -227,10 +234,11 @@ $tpl->assign('day_post', (!empty($_POST['date_day']) ? (int) $_POST['date_day'] : (int) date('d'))); $tpl->assign('month_post', (!empty($_POST['date_month']) ? (int) $_POST['date_month'] : (int) date('m'))); $tpl->assign('year_post', (!empty($_POST['date_year']) ? (int) $_POST['date_year'] : (int) date('Y'))); - $tpl->assign('amount_post', (!empty($_POST['amount']) ? (float) $_POST['amount'] : 0)); $tpl->assign('what_post', (!empty($_POST['what']) ? htmlspecialchars($_POST['what']) : '')); $tpl->assign('users', $users_list); + $tpl->assign('users_in', (!empty($_POST['users_in']) ? $_POST['users_in'] : array())); + $tpl->assign('guests', (!empty($guests) ? $guests : array())); $tpl->draw('new_invoice'); break; diff --git a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php index b8af817..09b56ae 100755 --- a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php @@ -9,7 +9,7 @@
Read line owes case to column. You can click on links to confirm the payback. +
Read line owes case to column. You can click on links to confirm the payback.
Owes\To | @@ -23,6 +23,11 @@|
---|---|
getDisplayName();?> | + $value2 ){ $counter2++; ?> + +getDisplayName();?> | + +
Owes\To | @@ -17,6 +17,9 @@ {loop="users"}|
---|---|
{$value->getDisplayName()} | + {loop="users"} +{$value->getDisplayName()} | + {/loop}
- {$currency} + {$currency}
@@ -32,7 +32,7 @@
Users in ?
{loop="users"}
-
and .
+
and getId(), $users_in)"} {$guests[$value->getId()]} {else} 0 {/if}" onchange="guest_user_label({$value->getId()});"/>.
{/loop}