forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSupplierContacts.php
287 lines (238 loc) · 9.87 KB
/
SupplierContacts.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
include('includes/session.php');
$Title = _('Supplier Contacts');
/* webERP manual links before header.php */
$ViewTopic= 'AccountsPayable';
$BookMark = 'SupplierContact';
include('includes/header.php');
if (isset($_GET['SupplierID'])){
$SupplierID = $_GET['SupplierID'];
} elseif (isset($_POST['SupplierID'])){
$SupplierID = $_POST['SupplierID'];
}
echo '<a href="' . $RootPath . '/SelectSupplier.php" class="toplink">' . _('Back to Suppliers') . '</a><br />';
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' .
_('Supplier Allocations') . '" alt="" />' . ' ' . $Title . '</p>';
if (!isset($SupplierID)) {
prnMsg(_('This page must be called with the supplier code of the supplier for whom you wish to edit the contacts') . '<br />' . _('When the page is called from within the system this will always be the case') .
'<br />' . _('Select a supplier first, then select the link to add/edit/delete contacts'),'info');
include('includes/footer.php');
exit;
}
if (isset($_GET['SelectedContact'])){
$SelectedContact = $_GET['SelectedContact'];
} elseif (isset($_POST['SelectedContact'])){
$SelectedContact = $_POST['SelectedContact'];
}
if (isset($_POST['submit'])) {
//initialise no input errors assumed initially before we test
$InputError = 0;
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
//first off validate inputs sensible
if (mb_strlen($_POST['Contact']) == 0) {
$InputError = 1;
prnMsg(_('The contact name must be at least one character long'),'error');
echo '<br />';
}
if (mb_strlen($_POST['Email'])){
if (!IsEmailAddress($_POST['Email'])) {
$InputError = 1;
prnMsg(_('The email address entered does not appear to be a valid email address'),'error');
echo '<br />';
}
}
if (isset($SelectedContact) AND $InputError != 1) {
/*SelectedContact could also exist if submit had not been clicked this code would not run in this case 'cos submit is false of course see the delete code below*/
$SQL = "UPDATE suppliercontacts SET position='" . $_POST['Position'] . "',
tel='" . $_POST['Tel'] . "',
fax='" . $_POST['Fax'] . "',
email='" . $_POST['Email'] . "',
mobile = '". $_POST['Mobile'] . "'
WHERE contact='".$SelectedContact."'
AND supplierid='".$SupplierID."'";
$Msg = _('The supplier contact information has been updated');
} elseif ($InputError != 1) {
/*Selected contact is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new supplier contacts form */
$SQL = "INSERT INTO suppliercontacts (supplierid,
contact,
position,
tel,
fax,
email,
mobile)
VALUES ('" . $SupplierID . "',
'" . $_POST['Contact'] . "',
'" . $_POST['Position'] . "',
'" . $_POST['Tel'] . "',
'" . $_POST['Fax'] . "',
'" . $_POST['Email'] . "',
'" . $_POST['Mobile'] . "')";
$Msg = _('The new supplier contact has been added to the database');
}
//run the SQL from either of the above possibilites
if ($InputError != 1) {
$ErrMsg = _('The supplier contact could not be inserted or updated because');
$DbgMsg = _('The SQL that was used but failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg);
prnMsg($Msg,'success');
unset($SelectedContact);
unset($_POST['Contact']);
unset($_POST['Position']);
unset($_POST['Tel']);
unset($_POST['Fax']);
unset($_POST['Email']);
unset($_POST['Mobile']);
}
} elseif (isset($_GET['delete'])) {
$SQL = "DELETE FROM suppliercontacts
WHERE contact='".$SelectedContact."'
AND supplierid = '".$SupplierID."'";
$ErrMsg = _('The supplier contact could not be deleted because');
$DbgMsg = _('The SQL that was used but failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg);
echo '<br />' . _('Supplier contact has been deleted') . '<p />';
}
if (!isset($SelectedContact)){
$SQL = "SELECT suppliers.suppname,
contact,
position,
tel,
suppliercontacts.fax,
suppliercontacts.email
FROM suppliercontacts,
suppliers
WHERE suppliercontacts.supplierid=suppliers.supplierid
AND suppliercontacts.supplierid = '".$SupplierID."'";
$Result = DB_query($SQL);
if (DB_num_rows($Result)>0){
$MyRow = DB_fetch_array($Result);
echo '<table class="selection">
<thead>
<tr>
<th colspan="7">' . _('Contacts Defined for') . ' - ' . $MyRow['suppname'] . '</th>
</tr>
<tr>
<th class="SortedColumn">' . _('Name') . '</th>
<th class="SortedColumn">' . _('Position') . '</th>
<th class="SortedColumn">' . _('Phone No') . '</th>
<th class="SortedColumn">' . _('Fax No') . '</th>
<th class="SortedColumn">' . _('Email') . '</th>
<th colspan="2"></th>
</tr>
</thead>
<tbody>';
do {
echo '<tr class="striped_row">
<td>', $MyRow['contact'], '</td>
<td>', $MyRow['position'], '</td>
<td>', $MyRow['tel'], '</td>
<td>', $MyRow['fax'], '</td>
<td><a href="mailto:', $MyRow['email'], '">', $MyRow['email'], '</a></td>
<td><a href="', htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?&SupplierID=', $SupplierID, '&SelectedContact=', $MyRow['contact'], '">' . _('Edit') . '</a></td>
<td><a href="', htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?&SupplierID=', $SupplierID, '&SelectedContact=', $MyRow['contact'], '&delete=yes" onclick="return confirm(\'' . _('Are you sure you wish to delete this contact?') . '\');">' . _('Delete') . '</a></td>
</tr>';
} while ($MyRow = DB_fetch_array($Result));
echo '</tbody></table><br />';
} else {
prnMsg(_('There are no contacts defined for this supplier'),'info');
}
//END WHILE LIST LOOP
}
//end of ifs and buts!
if (isset($SelectedContact)) {
echo '<div class="centre">
<a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SupplierID=' . $SupplierID . '">' .
_('Show all the supplier contacts for') . ' ' . $SupplierID . '</a>
</div>';
}
if (! isset($_GET['delete'])) {
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
if (isset($SelectedContact)) {
//editing an existing contact
$SQL = "SELECT contact,
position,
tel,
fax,
mobile,
email
FROM suppliercontacts
WHERE contact='" . $SelectedContact . "'
AND supplierid='" . $SupplierID . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['Contact'] = $MyRow['contact'];
$_POST['Position'] = $MyRow['position'];
$_POST['Tel'] = $MyRow['tel'];
$_POST['Fax'] = $MyRow['fax'];
$_POST['Email'] = $MyRow['email'];
$_POST['Mobile'] = $MyRow['mobile'];
echo '<input type="hidden" name="SelectedContact" value="' . $_POST['Contact'] . '" />';
echo '<input type="hidden" name="Contact" value="' . $_POST['Contact'] . '" />';
echo '<fieldset>
<legend>', _('Edit Supplier Contact'), '</legend>
<field>
<label for="Contact">' . _('Contact') . ':</label>
<fieldtext>' . $_POST['Contact'] . '</fieldtext>
</field>';
} else { //end of if $SelectedContact only do the else when a new record is being entered
if (!isset($_POST['Contact'])) {
$_POST['Contact']='';
}
echo '<fieldset>
<legend>', _('Create Supplier Contact'), '</legend>
<field>
<label for="Contact">' . _('Contact Name') . ':</label>
<input type="text" required="required" pattern="(?!^\s+$).{1,40}" title="" placeholder="'._('More than one characters long').'" name="Contact" size="41" maxlength="40" value="' . $_POST['Contact'] . '" />
<fieldhelp>'._('The contact name must be more than one characters long').'</fieldhelp>
</field>';
}
if (!isset($_POST['Position'])) {
$_POST['Position']='';
}
if (!isset($_POST['Tel'])) {
$_POST['Tel']='';
}
if(!isset($_POST['Fax'])) {
$_POST['Fax']='';
}
if (!isset($_POST['Mobile'])) {
$_POST['Mobile']='';
}
if (!isset($_POST['Email'])) {
$_POST['Email'] = '';
}
echo '<field>
<input type="hidden" name="SupplierID" value="' . $SupplierID . '" />
<label for="Position">' . _('Position') . ':</label>
<input type="text" name="Position" size="31" maxlength="30" value="' . $_POST['Position'] . '" />
</field>
<field>
<label for="Tel">' . _('Telephone No') . ':</label>
<input type="tel" pattern="[\d\s+()-]{1,30}" title="" placeholder="'._('Only digits,space,+,-,(,) allowed').'" name="Tel" size="31" maxlength="30" value="' . $_POST['Tel'] . '" />
<fieldhelp>'._('The input should be phone number').'</fieldhelp>
</field>
<field>
<label for="Fax">' . _('Facsimile No') . ':</label>
<input type="tel" pattern="[\d\s+()-]{1,30}" title="" placeholder="'._('Only digits,space,+,-,(,) allowed').'" name="Fax" size="31" maxlength="30" value="' . $_POST['Fax'] . '" />
<fieldhelp>'._('The input should be phone number').'</fieldhelp>
</field>
<field>
<label for="Mobile">' . _('Mobile No') . ':</label>
<input type="tel" pattern="[\d\s+()-]{1,30}" title="" placeholder="'._('Only digits,space,+,-,(,) allowed').'" name="Mobile" size="31" maxlength="30" value="' . $_POST['Mobile'] . '" />
<fieldhelp>'._('The input should be phone number').'</fieldhelp>
</field>
<field>
<label for="Email"><a href="Mailto:' . $_POST['Email'] . '">' . _('Email') . ':</a></label>
<input type="email" name="Email" title="" placeholder="'._('should be email format such as [email protected]').'" size="51" maxlength="50" value="' . $_POST['Email'] . '" />
<fieldhelp>'._('The input must be email format').'</fieldhelp>
</field>
</fieldset>';
echo '<div class="centre">
<input type="submit" name="submit" value="' . _('Enter Information') . '" />
</div>
</form>';
} //end if record deleted no point displaying form to add record
include('includes/footer.php');
?>