-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
73 lines (59 loc) · 2.13 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php require('core/init.php');
//Create Invoice Object
$invoice = new Invoice;
if(isset($_POST['do_delete'])) {
$updated = array();
$updated['id'] = $_SESSION['singleId'];
$updated['invoice_number'] = $_POST['invoice_number'];
$updated['user_id'] = getUser()['user_id'];
$updated['create_date'] = $_POST['create_date'];
$updated['due'] = $_POST['due'];
$updated['payee'] = $_POST['payee'];
$updated['amount'] = $_POST['amount'];
$updated['description'] = $_POST['description'];
$invoice->delete($updated);
redirect('index.php', 'Your invoice has been deleted', 'Success');
}
if(isset($_POST['do_update'])) {
//Create validator object
$validate = new Validator;
//create data array
$updated = array();
$updated['id'] = $_SESSION['singleId'];
$updated['invoice_number'] = $_POST['invoice_number'];
$updated['user_id'] = getUser()['user_id'];
$updated['create_date'] = $_POST['create_date'];
$updated['due'] = $_POST['due'];
$updated['payee'] = $_POST['payee'];
$updated['amount'] = $_POST['amount'];
$updated['description'] = $_POST['description'];
//Required Fields
$field_array = array('invoice_number', 'create_date', 'due', 'payee', 'amount');
if($validate->isRequired($field_array)) {
if($invoice->update($updated)) {
redirect('index.php', 'Your invoice has been updated', 'Success');
} else {
redirect('invoice.php?id='.$invoice_id, 'Something has gone wrong', 'error');
}
} else {
redirect('create.php', 'Please fill in the required fields', 'error');
}
}
if(isset($_POST['do_pdf']))
{
$content = "<h1>Invoice ID: " . $_POST['invoice_number'] . "</h1>" . "<h2>Payee: " . $_POST['payee'] . "</h2>"
. "<h2>Due Date: " . $_POST['due'] . "</h2>" . "<h2>Amount: $" . $_POST['amount'] . "</h2>" . "</h2>" . "<h2>Description: " . $_POST['description'] . "</h2>" . "<h2>Date: " . $_POST['create_date'] . "</h2>"
;
if($content)
{
include_once('dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream('invoice.pdf');
}
}
//Get Template & Assign Vars
$template = new Template('templates/invoices.php');
//Display template
echo $template;