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
|
<?php
// billing_matrix_edit.php - Page to edit a Unit Based billing matrix
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010 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.
//
// Author: Paul Heaney Paul Heaney <paul[at]sitracker.org>
require ('core.php');
$permission = PERM_BILLING_DURATION_EDIT; // TODO we need a permission to administer billing matrixes
require_once (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
require_once (APPLICATION_LIBPATH . 'auth.inc.php');
$tag = clean_dbstring($_REQUEST['tag']);
$action = cleanvar($_REQUEST['action']);
$title = $strEditBillingMatrix;
if (!empty($tag) AND empty($action))
{
$sql = "SELECT * FROM `{$dbBillingMatrixUnit}` WHERE tag='{$tag}' ORDER BY hour";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
if (mysql_num_rows($result) > 0)
{
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo "<h2>".icon('billing', 32)." {$title}</h2>";
plugin_do('billing_matrix_edit');
echo "<p align='center'>{$tag}</p>";
echo "<form name='billing_matrix_edit' action='{$_SERVER['PHP_SELF']}' method='post'>";
echo "<table class='maintable'>";
echo "<tr><th>{$strHour}</th><th>{$strMonday}</th><th>{$strTuesday}</th>";
echo "<th>{$strWednesday}</th><th>{$strThursday}</th><th>{$strFriday}</th>";
echo "<th>{$strSaturday}</th><th>{$strSunday}</th><th>{$strPublicHoliday}</th></tr>\n";
$days = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun', 'holiday');
while ($obj = mysql_fetch_object($result))
{
echo "<tr>";
echo "<th>{$obj->hour}</th>";
foreach ($days AS $day)
{
$id = "{$day}_{$obj->hour}";
echo "<td>".billing_multiplier_dropdown($id, $obj->$day)."</td>";
}
echo "</tr>";
}
plugin_do('billing_matrix_edit_form');
echo "</table>";
echo "<input type='hidden' name='tag' value='{$tag}' />";
echo "<input type='hidden' name='action' value='edit' />";
echo "<p class='formbuttons'><input name='reset' type='reset' value='{$strReset}' /> ";
echo "<input type='submit' value='{$strSave}' /></p>";
echo "<p class='return'><a href=\"billing_matrix.php\">{$strReturnWithoutSaving}</a></p>";
echo "</form>";
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
else
{
html_redirect("billing_matrix.php", FALSE, $strNoBillingMatrixFound);
}
}
else if(!empty($tag) AND $action == "edit")
{
$tag = clean_dbstring($_REQUEST['tag']);
$values = array();
$days = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun', 'holiday');
$hour = 0;
plugin_do('billing_matrix_edit_submitted');
while ($hour < 24)
{
$values[$hour] = array();
$mon = clean_float($_REQUEST["mon_{$hour}"]);
$tue = clean_float($_REQUEST["tue_{$hour}"]);
$wed = clean_float($_REQUEST["wed_{$hour}"]);
$thu = clean_float($_REQUEST["thu_{$hour}"]);
$fri = clean_float($_REQUEST["fri_{$hour}"]);
$sat = clean_float($_REQUEST["sat_{$hour}"]);
$sun = clean_float($_REQUEST["sun_{$hour}"]);
$holiday = clean_float($_REQUEST["holiday_{$hour}"]);
$sql = "UPDATE `{$dbBillingMatrixUnit}` SET mon = {$mon}, tue = {$tue}, wed = {$wed}, thu = {$thu}, ";
$sql .= "fri = {$fri}, sat = {$sat}, sun = {$sun}, holiday = {$holiday} WHERE tag = '{$tag}' AND hour = {$hour}";
$result = mysql_query($sql);
if (mysql_error())
{
$errors++;
trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
break; // Dont try and add any more
}
$hour++;
}
if ($errors >= 1)
{
html_redirect("billing_matrix.php", FALSE, $strBillingMatrixEditFailed);
}
else
{
plugin_do('billing_matrix_edit_saved');
html_redirect("billing_matrix.php", TRUE);
}
}
else
{
html_redirect("billing_matrix.php", FALSE, $strRequiredDataMissing);
}
|