From 51f3aa149103486e857fd0e0989efc39042847e3 Mon Sep 17 00:00:00 2001 From: Phyks Date: Fri, 30 Aug 2013 20:07:52 +0200 Subject: [PATCH] Design improvements --- TODO | 17 ++++---- inc/Invoices.class.php | 34 ++++++++++------ inc/Payback.class.php | 90 ++++++++++++++++++++++++++++++++++++++++++ inc/Storage.class.php | 18 ++++++++- inc/functions.php | 14 +++++++ index.php | 57 ++++++++++++++------------ tpl/css/style.css | 30 ++++++++++++-- tpl/edit_users.html | 4 +- tpl/footer.html | 2 +- tpl/index.html | 6 +-- tpl/js/main.js | 20 ++++++++++ tpl/new_invoice.html | 67 +++++++++++++++++-------------- tpl/settings.html | 2 +- 13 files changed, 274 insertions(+), 87 deletions(-) diff --git a/TODO b/TODO index 88f1b47..a79070a 100755 --- a/TODO +++ b/TODO @@ -3,9 +3,10 @@ inc/Invoices.class.php : ======================== -* Better way to store users in ? => reprendre cette partie +* Modify store() method to handle storage +* Modify load() method to handle JOIN * Modify load() method to handle complex queries (such as WHERE date < DATE_1 AND date > DATE_2) -* Buyer as user object ? +* Cache Manage paybacks : ================= @@ -13,16 +14,14 @@ Manage paybacks : TODO : ====== +* Colgroups + CSS hover * Add / Edit a bill -* Bug in connection form +* JSON output -Tests : -======= -* Remember me ? - -Tests passed (quick tests) : -============================ +To test : +========= * Connection form +* Remember me ? * Edit notice * Add / Edit user * Change password diff --git a/inc/Invoices.class.php b/inc/Invoices.class.php index 2c55d54..665f902 100644 --- a/inc/Invoices.class.php +++ b/inc/Invoices.class.php @@ -1,36 +1,45 @@ 'key', 'date'=>'date', - 'users_in'=>'string', + 'users_in'=>'string', // TODO 'buyer'=>'int', 'amount'=>'float', 'what'=>'text' ); + public function __construct() { + parent::__construct(); + } + // Getters // ======= public function getId() { return $this->id; } - public function getDate() { - return $this->date; + public function getDate($format = "d-m-Y H:i") { + return $this->date->format($format); } public function getUsersIn() { return $this->users_in; } + public function getGuests() { + return $this->guests; + } + public function getBuyer() { return $this->buyer; } @@ -49,17 +58,20 @@ $this->id = (int) $id; } - public function setDate($date_day, $date_month, $date_year) { - if((int) $date_day < 10) $date_day = "0".(int) $date_day; - if((int) $date_month < 10) $date_month = "0".(int) $date_month; + public function setDate($minute, $hour, $day, $month, $year) { + if((int) $minute < 10) $minute = '0'.$minute; - $this->date = $date_year.$date_month.$date_day; + $this->date = DateTime::createFromFormat('Y-n-j G:i', $year.'-'.(int) $month.'-'.(int) $day.' '.(int) $hour.':'.$minute); } public function setUsersIn($users_in) { $this->users_in = $users_in; } + public function setGuests($guests) { + $this->guests = $guests; + } + public function setBuyer($buyer) { $this->buyer = (int) $buyer; } diff --git a/inc/Payback.class.php b/inc/Payback.class.php index e69de29..f1e7f6f 100644 --- a/inc/Payback.class.php +++ b/inc/Payback.class.php @@ -0,0 +1,90 @@ +'key', + 'invoice_id'=>'int', + 'amount'=>'float', + 'from'=>'int', + 'to'=>'int' + ); + + public function __construct() { + parent::__construct(); + } + + // Getters + // ======= + + public function getId() { + return (int) $this->id; + } + + public function getInvoice() { + return (int) $this->invoice_id; + } + + public function getAmount() { + return (float) $this->amount; + } + + public function getFrom() { + return (int) $this->from; + } + + public function getTo() { + return (int) $this->to; + } + + // Setters + // ======= + + public function setId($id) { + $this->id = (int) $id; + } + + public function setInvoice($invoice_id) { + $this->invoice_id = (int) $invoice_id; + } + + public function setAmount($amount) { + $this->amount = (float) $amount; + } + + public function setFrom($from) { + $this->from = (int) $from; + } + + public function setTo($to) { + $this->to = (int) $to; + } + + // Restores object from array + // ========================== + + public function sessionRestore($data, $serialized = false) { + if($serialized) + $data = unserialize($data); + + $this->setId($data['id']); + $this->setInvoice($data['invoice_id']); + $this->setAmount($data['amount']); + $this->setFrom($data['from']); + $this->setTo($data['to']); + } + + // Maps htmlspecialchars on the class before display + // ================================================= + + public function secureDisplay() { + $this->id = (int) $this->id; + $this->invoice_id = (int) $this->invoice_id; + $this->amount = (float) $this->amount; + $this->from = (int) $this->from; + $this->to = (int) $this->to; + } + } diff --git a/inc/Storage.class.php b/inc/Storage.class.php index c9b5bd7..1dbd5f4 100644 --- a/inc/Storage.class.php +++ b/inc/Storage.class.php @@ -64,11 +64,18 @@ class Storage { public function typeToSQL($type) { $return = false; switch($type) { - case 'key': case 'int': + $return = 'INT(11)'; + break; + + case 'key': $return = 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'; break; + case 'float': + $return = 'FLOAT'; + break; + case 'string': $return = 'VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci'; break; @@ -117,6 +124,9 @@ class Storage { if(!empty($fields) && is_array($fields)) { foreach($fields as $field=>$value) { + if($fields[$field] == 'date') + $value = $value->format('Y-m-d H:i:s'); + $query->bindParam(':'.$field, $value); } } @@ -191,6 +201,9 @@ class Storage { foreach($this->fields as $field=>$type) { if(isset($this->$field)) { + if($fields[$field] == 'date') + $value = $value->format('Y-m-d H:i:s'); + $query->bindParam(':'.$field, $this->$field); } } @@ -218,6 +231,9 @@ class Storage { foreach($this->fields as $field=>$type) { if(!empty($this->$field)) { + if($fields[$field] == 'date') + $value = $value->format('Y-m-d H:i:s'); + $query->bindParam(':'.$field, $this->$field); } } diff --git a/inc/functions.php b/inc/functions.php index 390f3f4..f028f37 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -37,3 +37,17 @@ return $return; } + + function ampm2int($date) { + if($date == 'am') + return 0; + else + return 1; + } + + function int2ampm($hour) { + if($hour == 0) + return 6; + else + return 18; + } diff --git a/index.php b/index.php index e039b0f..390540e 100644 --- a/index.php +++ b/index.php @@ -278,11 +278,12 @@ case 'edit_invoice': if(!empty($_GET['id'])) { $invoice = new Invoice(); - $invoice->load(array('id'=>(int) $_GET['id']), true); + $invoice = $invoice->load(array('id'=>(int) $_GET['id']), true); - $date_day = ''; - $date_month = ''; - $date_year = ''; + $date_hour = $invoice->getDate('a'); + $date_day = $invoice->getDate('d'); + $date_month = $invoice->getDate('m'); + $date_year = $invoice->getDate('Y'); $amount = $invoice->getAmount(); $what = $invoice->getWhat(); $users_in = explode(',', $invoice->getUsersIn()); @@ -296,30 +297,35 @@ if(!empty($_POST['date_year'])) $date_year = $_POST['date_year']; if(!empty($_POST['users_in'])) $users_in = $_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'])) { + if(!empty($_POST['what']) && !empty($_POST['amount']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_hour']) && !empty($_POST['date_day']) && !empty($_POST['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) { if(check_token(600, 'new_invoice')) { - $invoice = new Invoice(); - - if(!empty($_POST['id'])) - $invoice->setId($_POST['id']); - - $invoice->setWhat($_POST['what']); - $invoice->setAmount($_POST['amount']); - $invoice->setBuyer($current_user->getId()); - $invoice->setDate($date_day, $date_month, $date_year); - - $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]; + if($_POST['amount'] <= 0) { + $tpl->assign('error', 'Negative amount.'); } - $invoice->setUsersIn($users_in); + else { + $invoice = new Invoice(); - $invoice->save(); - header('location: index.php'); - exit(); + if(!empty($_POST['id'])) + $invoice->setId($_POST['id']); + + $invoice->setWhat($_POST['what']); + $invoice->setAmount($_POST['amount']); + $invoice->setBuyer($current_user); + $invoice->setDate(0, int2ampm($_POST['date_hour']), $_POST['date_day'], $_POST['date_month'], $_POST['date_year']); + + $users_in = array(); + $guests = array(); + foreach($_POST['users_in'] as $user) { + $users_in[] = (int) $user; + $guests[] = (int) $_POST['guest_user_'.$user]; + } + $invoice->setUsersIn($users_in); + $invoice->setGuests($guests); + + $invoice->save(); + header('location: index.php'); + exit(); + } } else { $tpl->assign('error', 'Token error. Please resubmit the form.'); @@ -333,6 +339,7 @@ $tpl->assign('months', range(1, 12)); $tpl->assign('years', range(date('Y') - 1, date('Y') + 1)); + $tpl->assign('hour_post', (!empty($date_hour) ? (int) ampm2int($date_hour) : (int) ampm2int(date('a')))); $tpl->assign('day_post', (!empty($date_day) ? (int) $date_day : (int) date('d'))); $tpl->assign('month_post', (!empty($date_month) ? (int) $date_month : (int) date('m'))); $tpl->assign('year_post', (!empty($date_year) ? (int) $date_year : (int) date('Y'))); diff --git a/tpl/css/style.css b/tpl/css/style.css index 819edef..1ec66bb 100644 --- a/tpl/css/style.css +++ b/tpl/css/style.css @@ -12,10 +12,16 @@ table { margin: auto; text-align: center; max-width: 100%; + border-collapse: collapse; } table td, table th { padding: 0.5em; + border: 1px solid black; +} + +table th { + background-color: #DDD; } h2 { @@ -88,9 +94,13 @@ input[type=submit] { text-align: center } -#edit_password_form, #edit_user_form, #invoice_form { - width: 50%; - margin-left: 15%; +#edit_password_form, #edit_user_form, #invoice_form, #notice_form { + width: 67%; + margin: auto; +} + +#edit_password_form p, #edit_user_form p, #notice_form p { + text-align: center; } #edit_user_admin_rights { @@ -98,13 +108,25 @@ input[type=submit] { } #textarea_notice { - width: 50%; + width: 75%; } textarea#what { width: 75%; } +#list_expenses tr:hover { + background-color: #00bd00; +} + +#balance_table tr:not(:first-child):hover * { + background-color: #00bd00; +} + +.highlight_td { + background-color: #00bd00; +} + #install { margin: 0; } diff --git a/tpl/edit_users.html b/tpl/edit_users.html index ee5c805..0093843 100644 --- a/tpl/edit_users.html +++ b/tpl/edit_users.html @@ -6,8 +6,8 @@ {if condition="$view == 'list_users'"}

List of users

-

You can also add a user.

- +

You can also add a user.

+
diff --git a/tpl/footer.html b/tpl/footer.html index 888f9f4..994bdd1 100755 --- a/tpl/footer.html +++ b/tpl/footer.html @@ -1,4 +1,4 @@ - + diff --git a/tpl/index.html b/tpl/index.html index 729b936..5c525c2 100755 --- a/tpl/index.html +++ b/tpl/index.html @@ -7,7 +7,7 @@

Balance

Read line owes case {$currency} to column. You can click on links to confirm the payback. -

Id Login
+
{loop="users"} @@ -27,7 +27,7 @@

Detailed list of bills for last month

-
Owes\To
+
@@ -40,7 +40,7 @@ {loop="invoices"} - + diff --git a/tpl/js/main.js b/tpl/js/main.js index 84b8e9a..4d5723c 100644 --- a/tpl/js/main.js +++ b/tpl/js/main.js @@ -38,3 +38,23 @@ function toggle_password(id) { else document.getElementById(id).type = 'password'; } + +$(document).ready(function() { + $('#balance_table td').hover(function() { + $(this).closest('tr').find('td,th').addClass('highlight_td'); + var col = $(this).index()+1; + $(this).closest('table').find('tr :nth-child('+col+')').addClass('highlight_td'); + }, function() { + $(this).closest('tr').find('td,th').removeClass('highlight_td'); + var col = $(this).index()+1; + $(this).closest('table').find('tr :nth-child('+col+')').removeClass('highlight_td'); + }); + + $('#balance_table tr:first-child th:not(:first-child)').hover(function() { + var col = $(this).index()+1; + $(this).closest('table').find('tr :nth-child('+col+')').addClass('highlight_td'); + }, function() { + var col = $(this).index()+1; + $(this).closest('table').find('tr :nth-child('+col+')').removeClass('highlight_td'); + }); +}); diff --git a/tpl/new_invoice.html b/tpl/new_invoice.html index 3c974f5..92856dc 100755 --- a/tpl/new_invoice.html +++ b/tpl/new_invoice.html @@ -7,39 +7,46 @@

Add a bill

-

- -

- -

- - {$currency} -

-

- - / - / - -

-

- Users in ? +

+ Expense +

+ +

+ +

+ + {$currency} +

+

+ + / + / + + +

+
+
+ Users in ? {loop="users"}
and . {/loop} -

-

+

+

{if condition="$id != 0"}{/if} diff --git a/tpl/settings.html b/tpl/settings.html index cfbd41f..471f42c 100644 --- a/tpl/settings.html +++ b/tpl/settings.html @@ -9,7 +9,7 @@

Note : You can use HTML formatting in this form.

-

+

Date Paid by
{$value->getDate()}{$value->getBuyer()}{$value->getBuyer()->getDisplayName()} {$value->getUsersIn()} {$value->getAmount()} {$value->getWhat()}