diff --git a/TODO b/TODO index d218364..5987e27 100755 --- a/TODO +++ b/TODO @@ -4,8 +4,6 @@ * cf TODO in files * French template * Favicon -* Take account of paybacks in balance table -* Confirm all paybacks Improvements : ============== diff --git a/index.php b/index.php index 50cfd10..9b39519 100644 --- a/index.php +++ b/index.php @@ -602,14 +602,81 @@ exit(); } else { - $tpl->assign('error', $errors['unauthorized']); - $tpl->draw('index'); + header('location: index.php'); + exit(); } } else { header('location: index.php'); exit(); } + break; + + case 'payall': + if(!empty($_GET['from']) && !empty($_GET['to'])) { + if($_GET['to'] == $current_user->getId() || $current_user->getAdmin()) { + // Confirm all paybacks when to is buyer + $invoices = new Invoice(); + $invoices = $invoices->load(array('buyer'=>(int) $_GET['to'])); + + if($invoices !== false) { + foreach($invoices as $invoice) { + $paybacks = new Payback(); + $paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>(int) $_GET['to'], 'from_user'=>(int) $_GET['from'])); + + if($paybacks === false) { + $payback = new Payback(); + $payback->setTo($_GET['to']); + $payback->setFrom($_GET['from']); + $payback->setAmount($invoice->getAmountPerPerson($_GET['from'])); + $payback->setInvoice($invoice->getId()); + $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); + $payback->save(); + } + } + } + + // Confirm all paybacks when from is buyer + $invoices = new Invoice(); + $invoices = $invoices->load(array('buyer'=>(int) $_GET['from'])); + + if($invoices !== false) { + foreach($invoices as $invoice) { + $paybacks = new Payback(); + $paybacks = $paybacks->load(array('invoice_id'=>$invoice->getId(), 'to_user'=>(int) $_GET['from'], 'from_user'=>(int) $_GET['to'])); + + if($paybacks === false) { + $payback = new Payback(); + $payback->setTo($_GET['from']); + $payback->setFrom($_GET['to']); + $payback->setAmount($invoice->getAmountPerPerson($_GET['to'])); + $payback->setInvoice($invoice->getId()); + $payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); + $payback->save(); + } + } + } + + // Clear the cache + $tmp_files = glob(raintpl::$cache_dir."*.rtpl.php"); + if(is_array($tmp_files)) { + array_map("unlink", $tmp_files); + } + + header('location: index.php'); + exit(); + } + else { + header('location: index.php'); + exit(); + } + + } + else { + header('location: index.php'); + exit(); + } + break; default: diff --git a/tpl/default_en/index.html b/tpl/default_en/index.html index 91ad492..8789883 100755 --- a/tpl/default_en/index.html +++ b/tpl/default_en/index.html @@ -20,8 +20,10 @@ {loop="users"} {if condition="$balances[$value1->getId()][$value2->getId()] === 'X'"} - {else} + {elseif condition="$balances[$value1->getId()][$value2->getId()] === '-' || ($value2->getId() != $current_user->getId() && !$current_user->getAdmin())"} {$balances[$value1->getId()][$value2->getId()]} + {else} + {$balances[$value1->getId()][$value2->getId()]} {/if} {/loop}