-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
140 lines (133 loc) · 2.9 KB
/
add.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* add.php
*
* Creates the form and adds a new contact to the database
*
* @author Angus Vine <[email protected]>
* @version 1.0
* @since 5.5 (The php version used)
*/
require_once 'core/init.php';
include 'includes/head.inc.php';
?>
<div class="sub-headerContainer">
<div class="sub-header">
<h2>Add Contacts</h2>
</div>
<div class="sub-navigation">
<span><span class="bold">Import CSV from:</span>
<a href="importcsv-myob.php">MYOB</a> |
<a href="importcsv-web.php">Web Site</a>
</span>
</div>
</div>
<?php
if (Input::exists()) {
$validate = new Validation();
$validation = $validate->check($_POST, array(
'band' => array(
'max' => 64
),
'first_name' => array(
'max' => 64
),
'last_name' => array(
'max' => 64
),
'email' => array(
'required' => true,
'max' => 1024,
'is_email' => true,
'unique' => 'contacts'
),
'phone' => array(
'max' => 64,
'is_numeric' => true
),
'mobile' => array(
'max' => 64,
'is_numeric' => true,
'unique' => 'contacts'
),
'company' => array(
'max' => 64
),
'add_line_1' => array(
'max' => 128
),
'add_line_2' => array(
'max' => 128
),
'state' => array(
'max' => 128
),
'city' => array(
'max' => 128
),
'post_code' => array(
'max' => 128,
'is_numeric' => true
)
));
if($validation->passed()) {
$contact = new Contact();
try {
$contact->create(array(
'company' => Input::get('company'),
'band' => Input::get('band'),
'first_name' => Input::get('first_name'),
'last_name' => Input::get('last_name'),
'email' => Input::get('email'),
'add_line_1' => Input::get('add_line_1'),
'add_line_2' => Input::get('add_line_2'),
'state' => Input::get('state'),
'city' => Input::get('city'),
'post_code' => Input::get('post_code'),
'phone' => Input::get('phone'),
'mobile' => Input::get('mobile'),
'notes' => Input::get('notes'),
'date_created' => date('d-m-Y'),
'date_modified' => date('d-m-Y')
));
Session::flash('home', 'The <a href="contact.php?id=' . $contact->db()->rtnInstId() . '">contact</a> has been created successfully');
Redirect::to('index.php');
} catch (Exception $e) {
Session::flash('home', $e->getMessage());
Redirect::to('index.php');
exit();
}
} else {
echo '<ul class="error">';
foreach($validation->errors() as $error) {
echo '<li>' . $error . '</li>';
}
echo '</ul>';
}
}
$form = array(
'action' => '',
'method' => 'post',
'id' => '',
'band' => '',
'first_name' => '',
'last_name' => '',
'email' => '',
'phone' => '',
'mobile' => '',
'company' => '',
'add_line_1' => '',
'add_line_2' => '',
'show_state' => true,
'state' => '',
'city' => '',
'post_code' => '',
'show_notes' => true,
'notes' => '',
'show_button' => true,
'button' => 'Add Contact',
'read_only' => false
);
include 'includes/contact-form.php';
include 'includes/foot.inc.php';
?>