forked from KwaMoja/KwaMoja
/
KCMCAssignmentTypes.php
226 lines (187 loc) · 6.94 KB
/
KCMCAssignmentTypes.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
<?php
include ('includes/session.php');
$Title = _('Assignment Types') . ' / ' . _('Maintenance');
include ('includes/header.php');
if (isset($_POST['SelectedType'])) {
$SelectedType = mb_strtoupper($_POST['SelectedType']);
} elseif (isset($_GET['SelectedType'])) {
$SelectedType = mb_strtoupper($_GET['SelectedType']);
}
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/maintenance.png" title="', _('Assignment Types'), '" alt="" />', _('Assignment Type Setup'), '
</p>';
echo '<div class="page_help_text">', _('Add/edit/delete Assignment Types'), '</div>';
if (isset($_POST['Insert']) or isset($_POST['Update'])) {
//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['TypeName']) > 100) {
$InputError = 1;
prnMsg(_('The assignment type name description must be 100 characters or less long'), 'error');
}
if (mb_strlen($_POST['TypeName']) == 0) {
$InputError = 1;
prnMsg(_('The assignment type name description must contain at least one character'), 'error');
}
if (isset($_POST['Update']) and $InputError != 1) {
$SQL = "UPDATE care_type_assignment
SET type = '" . $_POST['Type'] . "',
name = '" . $_POST['TypeName'] . "',
status= '" . $_POST['Status'] . "',
modify_id='" . $_SESSION['UserID'] . "'
WHERE type_nr = '" . $SelectedType . "'";
$Msg = _('The assignment type') . ' ' . $SelectedType . ' ' . _('has been updated');
} elseif ($InputError != 1) {
$CheckSql = "SELECT count(type)
FROM care_type_assignment
WHERE name = '" . $_POST['TypeName'] . "'";
$CheckResult = DB_query($CheckSql);
$CheckRow = DB_fetch_row($CheckResult);
if ($CheckRow[0] > 0 and !isset($SelectedType)) {
$InputError = 1;
echo '<br />';
prnMsg(_('You already have an assignment type called') . ' ' . $_POST['TypeName'], 'error');
} else {
// Add new record on submit
$SQL = "INSERT INTO care_type_assignment (type_nr,
type,
name,
status,
history,
create_id,
create_time,
modify_id,
LD_var
) VALUES (
NULL,
'" . $_POST['Type'] . "',
'" . $_POST['TypeName'] . "',
'" . $_POST['Status'] . "',
'',
'" . $_SESSION['UserID'] . "',
CURRENT_DATE,
'" . $_SESSION['UserID'] . "',
''
)";
$Msg = _('Assignment type') . ' ' . $_POST['TypeName'] . ' ' . _('has been created');
}
}
if ($InputError != 1) {
//run the SQL from either of the above possibilites
$Result = DB_query($SQL);
prnMsg($Msg, 'success');
unset($SelectedType);
unset($_POST['typeid']);
unset($_POST['TypeName']);
}
} elseif (isset($_GET['delete'])) {
// PREVENT DELETES IF DEPENDENT RECORDS IN 'DebtorTrans'
// Prevent delete if saletype exist in customer transactions
$SQL = "DELETE FROM care_type_assignment WHERE type_nr='" . $SelectedType . "'";
$ErrMsg = _('The Type record could not be deleted because');
$Result = DB_query($SQL, $ErrMsg);
echo '<br />';
prnMsg(_('The assignment type has been deleted'), 'success');
unset($SelectedType);
unset($_GET['delete']);
}
if (!isset($SelectedType)) {
$SQL = "SELECT type_nr,
type,
name,
status
FROM care_type_assignment";
$Result = DB_query($SQL);
if (DB_num_rows($Result) > 0) {
echo '<table class="selection">
<thead>
<tr>
<th class="SortedColumn">', _('Type'), '</th>
<th class="SortedColumn">', _('Type Name'), '</th>
<th class="SortedColumn">', _('Status'), '</th>
<th></th>
<th></th>
</tr>
</thead>';
$k = 0; //row colour counter
echo '<tbody>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<tr class="striped_row">
<td>', $MyRow['type'], '</td>
<td>', $MyRow['name'], '</td>
<td>', _($MyRow['status']), '</td>
<td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?SelectedType=', urlencode($MyRow['type_nr']), '">' . _('Edit') . '</a></td>
<td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?SelectedType=', urlencode($MyRow['type_nr']), '&delete=yes" onclick="return MakeConfirm(\'' . _('Are you sure you wish to delete this Assignment Type?') . '\', \'Confirm Delete\', this);">' . _('Delete') . '</a></td>
</tr>';
}
//END WHILE LIST LOOP
echo '</tbody>';
echo '</table>';
}
}
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'], '" />';
// The user wish to EDIT an existing type
if (isset($SelectedType) and $SelectedType != '') {
$SQL = "SELECT type_nr,
type,
name,
status
FROM care_type_assignment
WHERE type_nr='" . $SelectedType . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['Type'] = $MyRow['type'];
$_POST['TypeName'] = $MyRow['name'];
$_POST['Status'] = $MyRow['status'];
echo '<input type="hidden" name="SelectedType" value="', $SelectedType, '" />';
echo '<fieldset>
<legend>', _('Edit Assignment Type'), ' - ', $MyRow['name'], '</legend>';
echo '<field>
<label for="TypeID">', _('Type ID'), ':</label>
<div class="fieldtext">', $SelectedType, '</div>
</field>';
} else {
$_POST['Type'] = '';
$_POST['TypeName'] = '';
$_POST['Status'] = _('Active');
echo '<fieldset>
<legend>', _('Create New Assignment Type'), '</legend>';
}
echo '<field>
<label for="Type">', _('Type'), ':</label>
<input type="text" name="Type" required="required" maxlength="60" size="50" value="', $_POST['Type'], '" />
</field>';
echo '<field>
<label for="TypeName">', _('Type Name'), ':</label>
<input type="text" name="TypeName" required="required" maxlength="60" size="50" value="', $_POST['TypeName'], '" />
</field>';
echo '<field>
<label for="Status">', _('Status'), '</label>
<select name="Status">';
if ($_POST['Status'] == 'Active') {
echo '<option value="Active" selected="selected">', _('Active'), '</option>';
echo '<option value="InActive">', _('Inactive'), '</option>';
} else {
echo '<option value="Active">', _('Active'), '</option>';
echo '<option value="InActive" selected="selected">', _('Inactive'), '</option>';
}
echo '</select>
</field>';
echo '</fieldset>'; // close main table
if (isset($SelectedType) and $SelectedType != '') {
echo '<div class="centre">
<input type="submit" name="Update" value="', _('Update Assignment Type'), '" />
</div>';
} else {
echo '<div class="centre">
<input type="submit" name="Insert" value="', _('Create Assignment Type'), '" />
</div>';
}
echo '</form>';
} // end if user wish to delete
include ('includes/footer.php');
?>