forked from sitracker/sitracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract_new.php
More file actions
348 lines (295 loc) · 14.5 KB
/
contract_new.php
File metadata and controls
348 lines (295 loc) · 14.5 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
// contract_new.php - Add a new maintenance contract
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010-2014 The Support Incident Tracker Project
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
// This Page Is Valid XHTML 1.0 Transitional! 24May2009
require ('core.php');
$permission = PERM_CONTRACT_ADD; // Add Maintenance Contract
require (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');
$title = $strNewContract;
// External variables
$action = clean_fixed_list($_REQUEST['action'], array('','showform','new'));
$siteid = clean_int($_REQUEST['siteid']);
// Show add maintenance form
if ($action == "showform" OR $action == '')
{
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo show_form_errors('new_contract');
clear_form_errors('new_contract');
echo "<h2>".icon('contract', 32)." ";
echo "{$strNewContract}</h2>";
plugin_do('contract_new');
echo "<form id='new_contract' name='new_contract' action='{$_SERVER['PHP_SELF']}?action=new' method='post' onsubmit='return confirm_action(\"{$strAreYouSureAdd}\");'>";
echo "<table class='maintable vertical'>";
echo "<tr><th>{$strSite}</th><td>";
echo site_drop_down("site", show_form_value('new_contract', 'site', $siteid), TRUE);
echo " <span class='required'>{$strRequired}</span></td></tr>\n";
echo "<tr><th>{$strContacts}</th><td>";
$amountChecked = $allChecked = '';
if ($_SESSION['formdata']['new_contract']['contacts'] == 'all') $allChecked = "checked='checked'";
else $amountChecked = "checked='checked'";
echo "<input value='amount' type='radio' name='contacts' {$amountChecked} />";
echo "{$strLimitTo} <input size='2' name='numcontacts' value='".show_form_value('new_contract', 'numcontacts', '0')."' /> {$strSupportedContacts} ({$str0MeansUnlimited})<br />";
echo "<input type='radio' value='all' name='contacts' {$allChecked} />";
echo "{$strAllSiteContactsSupported}";
echo "</td></tr>\n";
echo "<tr><th>{$strProduct}</th><td>";
echo product_drop_down("product", show_form_value('new_contract', 'product', 0), TRUE)." <span class='required'>{$strRequired}</span></td></tr>\n";
echo "<tr><th>{$strServiceLevel}</th><td>";
echo servicelevel_drop_down('servicelevel', show_form_value('new_contract', 'servicelevel', $CONFIG['default_service_level']), TRUE, "onchange=\"addcontract_sltimed(\$F('servicelevel'));\"")."</td></tr>\n";
// check the initially selected service level to decide whether to show the extra hiddentimed section
$timed = servicelevel_timed($_SESSION['formdata']['new_contract']['servicelevel']);
echo "<tr><th colspan='2' style='text-align: left;'><br />{$strServicePeriod}</th></tr>\n";
echo "<tr><th>{$strStartDate}</th>";
echo "<td><input type='text' name='startdate' id='startdate' size='10' value='".date('Y-m-d', $now)."' /> ";
echo date_picker('new_contract.startdate');
echo "</td></tr>\n";
echo "<tr><th>{$strExpiryDate}</th>";
echo "<td><input class='required' name='expiry' size='10' ";
if ($_SESSION['formdata']['new_contract']['expiry'] != '')
{
echo "value='{$_SESSION['formdata']['new_contract']['expiry']}'";
}
echo "/> ".date_picker('new_contract.expiry');
echo "<label><input type='checkbox' name='noexpiry' ";
if ($_SESSION['formdata']['new_contract']['noexpiry'] == "on")
{
echo "checked='checked' ";
}
echo "onclick=\"this.form.expiry.value=''\" /> {$strUnlimited}</label>";
echo " <span class='required'>{$strRequired}</span></td></tr>\n";
echo "<tr><th>{$strAdminContact}</th>";
echo "<td>".contact_drop_down("admincontact", show_form_value('new_contract', 'admincontact', 0), TRUE, TRUE);
echo " <span class='required'>{$strRequired}</span></td></tr>\n";
echo "<tr><th>{$strNotes}</th><td><textarea cols='40' name='notes' rows='5'>{$_SESSION['formdata']['new_contract']['notes']}</textarea></td></tr>\n";
plugin_do('contract_new_form');
echo "<tbody id='hiddentimed'";
if (!$timed) echo " style='display:none'";
echo ">";
echo "<tr><th>{$strBilling}</th>";
echo "<td>";
echo "<label>";
echo "<input type='radio' name='billtype' value='UnitBillable' onchange=\"addcontract_display_billing_matrix('new_contract', '{$_SESSION['formdata']['new_contract']['billing_matrix']}');\" checked='checked' /> ";
echo "{$strPerUnit}</label>";
echo "<label>";
echo "<input type='radio' name='billtype' value='IncidentBillable' onchange=\"addcontract_display_billing_matrix('new_contract', '{$_SESSION['formdata']['new_contract']['billing_matrix']}');\" /> ";
echo "{$strPerIncident}</label>";
echo "<label>";
echo "<input type='radio' name='billtype' value='PointsBillable' onchange=\"addcontract_display_billing_matrix('new_contract', '{$_SESSION['formdata']['new_contract']['billing_matrix']}');\" /> ";
echo "{$strPointsBased}</label>";
echo "</td></tr>\n";
echo "<tr><th>{$strCreditAmount}</th><td>{$CONFIG['currency_symbol']}";
echo "<input maxlength='7' name='amount' size='5' class='required' value='".show_form_value('new_contract', 'amount', '0')."' /> ";
echo "<span class='required'>{$strRequired}</span>".help_link("BillingCreditAmount")."</td></tr>\n";
echo "<tr id='unitratesection'><th>{$strUnitRate}</th>";
echo "<td>{$CONFIG['currency_symbol']} ";
echo "<input class='required' type='text' name='unitrate' size='5' value='".show_form_value('new_contract', 'unitrate', '')."' />";
echo " <span class='required'>{$strRequired}</span>".help_link("BillingUnitRate")."</td></tr>\n";
echo "<tr><th>{$strBillingMatrix}</th>";
echo "<td><div id='billingmatrix_cell'></div></td>";
echo "</tr>";
echo "<tr>";
echo "<th>{$strFreeOfCharge}</th>";
echo "<td><input type='checkbox' id='foc' name='foc' value='yes' ";
if ($_SESSION['formdata']['new_contract']['foc'] == 'yes')
{
echo "checked='checked'' ";
}
echo "/> ".help_link("BillingFreeOfCharge")."{$strAboveMustBeCompletedToAllowDeductions}</td></tr>\n";
echo "</tbody>\n";
echo "<tr><th></th><td><a href=\"javascript:void(0);\" onclick=\"$('hidden').toggle();\">{$strMore}</a></td></tr>\n";
echo "<tbody id='hidden' style='display:none'>";
echo "<tr><th>{$strReseller}</th><td>";
reseller_drop_down("reseller", show_form_value('new_contract', 'reseller', 1));
echo "</td></tr>\n";
echo "<tr><th>{$strLicenseQuantity}</th><td><input maxlength='7' name='licence_quantity' size='5' value='".show_form_value('new_contract', 'licence_quantity', 0)."' />";
echo " ({$str0MeansUnlimited})</td></tr>\n";
echo "<tr><th>{$strLicenseType}</th><td>";
licence_type_drop_down("licence_type", show_form_value('new_contract', 'licence_type', LICENCE_SITE));
echo "</td></tr>\n";
echo "<tr><th>{$strIncidentPool}</th>";
$incident_pools = explode(',', "{$strUnlimited},{$CONFIG['incident_pools']}");
echo "<td>".array_drop_down($incident_pools, 'incident_poolid', show_form_value('new_contract', 'incident_poolid', $maint['incident_quantity']))."</td></tr>\n";
plugin_do('contract_new_form_more');
echo "</tbody>\n";
echo "</table>\n";
if ($timed) $timed = 'yes';
else $timed = 'no';
echo "<input type='hidden' id='timed' name='timed' value='{$timed}' />";
echo "<p class='formbuttons'><input name='reset' type='reset' value='{$strReset}' /> ";
echo "<input name='submit' type='submit' value=\"{$strSave}\" /></p>";
echo "</form>";
echo "<p class='return'><a href=\"contracts.php\">{$strReturnWithoutSaving}</a></p>";
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
clear_form_data('new_contract');
}
elseif ($action == 'new')
{
// External Variables
$site = clean_int($_REQUEST['site']);
$product = clean_int($_REQUEST['product']);
$reseller = clean_int($_REQUEST['reseller']);
$licence_quantity = clean_int($_REQUEST['licence_quantity']);
$licence_type = clean_int($_REQUEST['licence_type']);
$admincontact = clean_int($_REQUEST['admincontact']);
$notes = clean_dbstring($_REQUEST['notes']);
$servicelevel = clean_dbstring($_REQUEST['servicelevel']);
$incidentpoolid = clean_int($_REQUEST['incidentpoolid']);
$term = clean_fixed_list($_REQUEST['term'], array('no','yes'));
$contacts = cleanvar($_REQUEST['contacts']);
$timed = cleanvar($_REQUEST['timed']);
$startdate = strtotime($_REQUEST['startdate']);
if ($startdate > 0) $startdate = date('Y-m-d', $startdate);
else $startdate = date('Y-m-d',$now);
$enddate = strtotime($_REQUEST['expiry']);
if ($enddate > 0) $enddate = date('Y-m-d', $enddate);
else $enddate = date('Y-m-d', $now);
if ($_REQUEST['noexpiry'] == 'on')
{
$expirydate = '-1';
}
else
{
$expirydate = strtotime($_REQUEST['expiry']);
}
$amount = clean_float($_POST['amount']);
if ($amount == '') $amount = 0;
$unitrate = clean_float($_POST['unitrate']);
$billtype = cleanvar($_REQUEST['billtype']);
$foc = cleanvar($_REQUEST['foc']);
if (empty($foc)) $foc = 'no';
$billingmatrix = clean_dbstring($_REQUEST['billing_matrix']);
$allcontacts = 'no';
if ($contacts == 'amount') $numcontacts = clean_int($_REQUEST['numcontacts']);
elseif ($contacts == 'all') $allcontacts = 'yes';
$incident_pools = explode(',', "0,{$CONFIG['incident_pools']}");
$incident_quantity = clean_int($incident_pools[$_POST['incident_poolid']]);
$_SESSION['formdata']['new_contract'] = cleanvar($_POST, TRUE, FALSE, FALSE,
array("@"), array("'" => '"'));
// Add maintenance to database
$errors = 0;
// check for blank site
if ($site == 0)
{
$errors++;
$_SESSION['formerrors']['new_contract']['site'] = sprintf($strFieldMustNotBeBlank, $strSite);
}
// check for blank product
if ($product == 0)
{
$errors++;
$_SESSION['formerrors']['new_contract']['product'] = sprintf($strFieldMustNotBeBlank, $strProduct);
}
// check for blank expiry day
if (empty($_REQUEST['expiry']) AND $expirydate != -1)
{
$errors++;
$_SESSION['formerrors']['new_contract']['expirydate'] = sprintf($strFieldMustNotBeBlank, $strExpiryDate);
}
elseif ($expirydate < $now AND $expirydate != -1)
{
$errors++;
$_SESSION['formerrors']['new_contract']['expirydate2'] = "{$strExpiryDateCannotBeInThePast}\n";
}
// check for blank admin contact
if ($admincontact == 0)
{
$errors++;
$_SESSION['formerrors']['new_contract']['admincontact'] = sprintf($strFieldMustNotBeBlank, $strAdminContact);
}
if ($timed == 'yes' AND $amount == 0)
{
$errors++;
$_SESSION['formerrors']['new_contract']['amount'] = sprintf($strFieldMustNotBeBlank, $strCreditAmount);
}
$billingObj = new $billtype();
if ($timed == 'yes' AND empty($unitrate) AND $billingObj->uses_unit_rate())
{
$errors++;
$_SESSION['formerrors']['new_contract']['unitrate'] = sprintf($strFieldMustNotBeBlank, $strUnitRate);
}
if ($timed == 'yes' AND $billingObj->uses_billing_matrix AND empty($billingmatrix))
{
$errors++;
$_SESSION['formerrors']['new_contract']['billing_matrix'] = sprintf($strFieldMustNotBeBlank, $strNoBillingMatrixDefined);
}
plugin_do('contract_new_submitted');
// add maintenance if no errors
if ($errors == 0)
{
$addition_errors = 0;
if (empty($reseller) OR $reseller == 0)
{
$reseller = "NULL";
}
else
{
$reseller = "'{$reseller}'";
}
if (empty($licence_type) OR $licence_type == 0)
{
$licence_type = "NULL";
}
else
{
$licence_type = "'{$licence_type}'";
}
if ($timed != 'yes')
{
$billingmatrix = '';
$billtype = '';
}
$billingmatrix = convert_string_null_safe($billingmatrix);
$billtype = convert_string_null_safe($billtype);
// NOTE above is so we can insert null so browse_contacts etc can see the contract rather than inserting 0
$sql = "INSERT INTO `{$dbMaintenance}` (site, product, reseller, expirydate, licence_quantity, licence_type, notes, ";
$sql .= "admincontact, servicelevel, incidentpoolid, incident_quantity, term, supportedcontacts, allcontactssupported, billingmatrix, billingtype) ";
$sql .= "VALUES ('{$site}', '{$product}', {$reseller}, '{$expirydate}', '{$licence_quantity}', {$licence_type}, '{$notes}', ";
$sql .= "'{$admincontact}', '{$servicelevel}', '{$incidentpoolid}', '{$incident_quantity}', '{$term}', '{$numcontacts}', '{$allcontacts}', {$billingmatrix}, {$billtype})";
$result = mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_ERROR);
$maintid = mysqli_insert_id($db);
if (!$result)
{
$addition_errors = 1;
$addition_errors_string .= user_alert($strAdditionFail, E_USER_WARNING);
}
// Add service
$sql = "INSERT INTO `{$dbService}` (contractid, startdate, enddate, creditamount, rate, foc) ";
$sql .= "VALUES ('{$maintid}', '{$startdate}', '{$enddate}', '{$amount}', '{$unitrate}', '{$foc}')";
mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error(mysqli_error($db), E_USER_ERROR);
if (mysqli_affected_rows($db) < 1) trigger_error("Insert failed", E_USER_ERROR);
$serviceid = mysqli_insert_id($db);
update_contract_balance($maintid, $strNewContract, $amount, $serviceid);
if ($addition_errors == 1)
{
// show addition error message
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo $addition_errors_string;
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
else
{
plugin_do('contract_new_saved');
// show success message
$t = new TriggerEvent('TRIGGER_NEW_CONTRACT', array('contractid' => $maintid, 'userid' => $sit[2]));
html_redirect("contract_details.php?id={$maintid}");
}
clear_form_data('new_contract');
}
else
{
// show error message if errors
html_redirect($_SERVER['PHP_SELF'], FALSE);
}
}
?>