1<?php
2
3include('includes/session.php');
4$Title = _('QA Tests Maintenance');
5$ViewTopic= 'QualityAssurance';// Filename in ManualContents.php's TOC.
6$BookMark = 'QA_Tests';// Anchor's id in the manual's html document.
7include('includes/header.php');
8
9if (isset($_GET['SelectedQATest'])){
10	$SelectedQATest =mb_strtoupper($_GET['SelectedQATest']);
11} elseif(isset($_POST['SelectedQATest'])){
12	$SelectedQATest =mb_strtoupper($_POST['SelectedQATest']);
13}
14
15if (isset($Errors)) {
16	unset($Errors);
17}
18
19$Errors = array();
20
21echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $Title . '</p>';
22
23if (isset($_POST['submit'])) {
24
25	//initialise no input errors assumed initially before we test
26	$InputError = 0;
27
28	/* actions to take once the user has clicked the submit button
29	ie the page has called itself with some user input */
30	$i=1;
31
32	//first off validate inputs sensible
33
34	if (mb_strlen($_POST['QATestName']) > 50) {
35		$InputError = 1;
36		prnMsg(_('The QA Test name must be fifty characters or less long'),'error');
37		$Errors[$i] = 'QATestName';
38		$i++;
39	}
40
41	if (mb_strlen($_POST['Type']) =='') {
42		$InputError = 1;
43		prnMsg(_('The Type must not be blank'),'error');
44		$Errors[$i] = 'Type';
45		$i++;
46	}
47	$sql= "SELECT COUNT(*) FROM qatests WHERE qatests.name='".$_POST['QATestName']."'
48										AND qatests.testid <> '" .$SelectedQATest. "'";
49	$result = DB_query($sql);
50	$myrow = DB_fetch_row($result);
51	if ($myrow[0]>0) {
52		$InputError = 1;
53		prnMsg(_('The QA Test name already exists'),'error');
54		$Errors[$i] = 'QATestName';
55		$i++;
56	}
57
58	if (isset($SelectedQATest) AND $InputError !=1) {
59
60		/*SelectedQATest 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*/
61
62		$sql = "UPDATE qatests SET name='" . $_POST['QATestName'] . "',
63									method='" . $_POST['Method'] . "',
64									groupby='" . $_POST['GroupBy'] . "',
65									units='" . $_POST['Units'] . "',
66									type='" . $_POST['Type'] . "',
67									defaultvalue='" . $_POST['DefaultValue'] . "',
68									numericvalue='" . $_POST['NumericValue'] . "',
69									showoncert='" . $_POST['ShowOnCert'] . "',
70									showonspec='" . $_POST['ShowOnSpec'] . "',
71									showontestplan='" . $_POST['ShowOnTestPlan'] . "',
72									active='" . $_POST['Active'] . "'
73				WHERE qatests.testid = '".$SelectedQATest."'";
74
75		$msg = _('QA Test record for') . ' ' . $_POST['QATestName'] . ' ' . _('has been updated');
76	} elseif ($InputError !=1) {
77
78	/*Selected group is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new QA Test form */
79
80		$sql = "INSERT INTO qatests (name,
81						method,
82						groupby,
83						units,
84						type,
85						defaultvalue,
86						numericvalue,
87						showoncert,
88						showonspec,
89						showontestplan,
90						active)
91				VALUES ('" . $_POST['QATestName'] . "',
92					'" . $_POST['Method'] . "',
93					'" . $_POST['GroupBy'] . "',
94					'" . $_POST['Units'] . "',
95					'" .$_POST['Type'] . "',
96					'" . $_POST['DefaultValue'] . "',
97					'" . $_POST['NumericValue'] . "',
98					'" . $_POST['ShowOnCert'] . "',
99					'" . $_POST['ShowOnSpec'] . "',
100					'" . $_POST['ShowOnTestPlan'] . "',
101					'" . $_POST['Active'] . "'
102					)";
103
104		$msg = _('A new QA Test record has been added for') . ' ' . $_POST['QATestName'];
105	}
106	if ($InputError !=1) {
107		//run the SQL from either of the above possibilites
108		$ErrMsg = _('The insert or update of the QA Test failed because');
109		$DbgMsg = _('The SQL that was used and failed was');
110		$result = DB_query($sql,$ErrMsg, $DbgMsg);
111
112		prnMsg($msg , 'success');
113
114		unset($SelectedQATest);
115		unset($_POST['QATestName']);
116		//unset($_POST['Method']);
117		//unset($_POST['GroupBy']);
118		//unset($_POST['Units']);
119		//unset($_POST['Type']);
120		unset($_POST['DefaultValue']);
121		unset($_POST['NumericValue']);
122		//unset($_POST['ShowOnCert']);
123		//unset($_POST['ShowOnSpec']);
124		//unset($_POST['ShowOnTestPlan']);
125		//unset($_POST['Active']);
126	}
127
128} elseif (isset($_GET['delete'])) {
129//the link to delete a selected record was clicked instead of the submit button
130
131// PREVENT DELETES IF DEPENDENT RECORDS
132
133	$sql= "SELECT COUNT(*) FROM prodspec WHERE  prodspec.testid='".$SelectedQATest."'";
134	//$result = DB_query($sql);
135	//$myrow = DB_fetch_row($result);
136	if ($myrow[0]>0) {
137		prnMsg(_('Cannot delete this QA Test because Product Specs are using it'),'error');
138	} else {
139		$sql="DELETE FROM qatests WHERE testid='". $SelectedQATest."'";
140		$ErrMsg = _('The QA Test could not be deleted because');
141		$result = DB_query($sql,$ErrMsg);
142
143		prnMsg(_('QA Test') . ' ' . $SelectedQATest . ' ' . _('has been deleted from the database'),'success');
144		unset ($SelectedQATest);
145		unset($delete);
146		unset ($_GET['delete']);
147	}
148}
149
150if (isset($SelectedQATest)) {
151	echo '<div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Show All QA Tests') . '</a></div>';
152}
153
154if (! isset($_GET['delete'])) {
155
156	echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
157    echo '<div>';
158	echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
159
160	if (isset($SelectedQATest)) {
161		//editing an existing Sales-person
162
163		$sql = "SELECT testid,
164				name,
165				method,
166				groupby,
167				units,
168				type,
169				defaultvalue,
170				numericvalue,
171				showoncert,
172				showonspec,
173				showontestplan,
174				active
175				FROM qatests
176				WHERE testid='".$SelectedQATest."'";
177
178		$result = DB_query($sql);
179		$myrow = DB_fetch_array($result);
180
181		$_POST['SelectedQATest'] = $myrow['testid'];
182		$_POST['QATestName'] = $myrow['name'];
183		$_POST['Method'] = $myrow['method'];
184		$_POST['GroupBy'] = $myrow['groupby'];
185		$_POST['Type'] = $myrow['type'];
186		$_POST['Units'] = $myrow['units'];
187		$_POST['DefaultValue'] = $myrow['defaultvalue'];
188		$_POST['NumericValue'] = $myrow['numericvalue'];
189		$_POST['ShowOnCert'] = $myrow['showoncert'];
190		$_POST['ShowOnSpec'] = $myrow['showonspec'];
191		$_POST['ShowOnTestPlan'] = $myrow['showontestplan'];
192		$_POST['Active'] = $myrow['active'];
193
194
195		echo '<input type="hidden" name="SelectedQATest" value="' . $SelectedQATest . '" />';
196		echo '<input type="hidden" name="TestID" value="' . $_POST['SelectedQATest'] . '" />';
197		echo '<table class="selection">
198				<tr>
199					<td>' . _('QA Test ID') . ':</td>
200					<td>' . $_POST['SelectedQATest'] . '</td>
201				</tr>';
202
203	} else { //end of if $SelectedQATest only do the else when a new record is being entered
204
205		echo '<table class="selection">';
206
207	}
208	if (!isset($_POST['QATestName'])){
209	  $_POST['QATestName']='';
210	}
211	if (!isset($_POST['Method'])){
212	  $_POST['Method']='';
213	}
214	if (!isset($_POST['GroupBy'])){
215	  $_POST['GroupBy']='';
216	}
217	if (!isset($_POST['Units'])){
218	  $_POST['Units']='';
219	}
220	if (!isset($_POST['Type'])) {
221		$_POST['Type']=4;
222	}
223	if (!isset($_POST['Active'])) {
224		$_POST['Active']=1;
225	}
226	if (!isset($_POST['NumericValue'])) {
227		$_POST['NumericValue']=1;
228	}
229	if (!isset($_POST['ShowOnCert'])) {
230		$_POST['ShowOnCert']=1;
231	}
232	if (!isset($_POST['ShowOnSpec'])) {
233		$_POST['ShowOnSpec']=1;
234	}
235	if (!isset($_POST['ShowOnTestPlan'])) {
236		$_POST['ShowOnTestPlan']=1;
237	}
238	echo '<tr>
239			<td>' . _('QA Test Name') . ':</td>
240			<td><input type="text" '. (in_array('QATestName',$Errors) ? 'class="inputerror"' : '' ) .' name="QATestName"  required="required" title="' . _('The name of the Test you are setting up') . '" size="30" maxlength="50" value="' . $_POST['QATestName'] . '" /></td>
241		</tr>';
242	echo '<tr>
243			<td>' . _('Method') . ':</td>
244			<td><input type="text" name="Method" title="' . _('ASTM, ISO, UL or other') . '" size="20" maxlength="20" value="' . $_POST['Method'] . '" /></td>
245		</tr>';
246	echo '<tr>
247			<td>' . _('Group By') . ':</td>
248			<td><input type="text" name="GroupBy" title="' . _('Can be used to group certain Tests on the Product Specification or Certificate of
249Analysis or left blank') . '" size="20" maxlength="20" value="' . $_POST['GroupBy'] . '" /></td>
250		</tr>';
251	echo '<tr>
252			<td>' . _('Units') . ':</td>
253			<td><input type="text" name="Units" title="' . _('How this is measured. PSI, Fahrenheit, Celsius etc.') . '" size="20" maxlength="20" value="' . $_POST['Units'] . '" /></td>
254		</tr>';
255	echo '<tr>
256			<td>' . _('Type') . ':</td>
257			<td><select title="' . _('What sort of data field is required to record the results for this test') . '" name="Type">';
258	if ($_POST['Type']==0){
259		echo '<option selected="selected" value="0">' . _('Text Box') . '</option>';
260	} else {
261		echo '<option value="0">' . _('Text Box') . '</option>';
262	}
263	if ($_POST['Type']==1){
264		echo '<option selected="selected" value="1">' . _('Select Box') . '</option>';
265	} else {
266		echo '<option value="1">' . _('Select Box') . '</option>';
267	}
268	if ($_POST['Type']==2){
269		echo '<option selected="selected" value="2">' . _('Check Box') . '</option>';
270	} else {
271		echo '<option value="2">' . _('Check Box') . '</option>';
272	}
273	if ($_POST['Type']==3){
274		echo '<option selected="selected" value="3">' . _('Date Box') . '</option>';
275	} else {
276		echo '<option value="3">' . _('Date Box') . '</option>';
277	}
278	if ($_POST['Type']==4){
279		echo '<option selected="selected" value="4">' . _('Range') . '</option>';
280	} else {
281		echo '<option value="4">' . _('Range') . '</option>';
282	}
283	echo '</select></td></tr><tr>
284			<td>' . _('Possible Values') . ':</td>
285			<td><input type="text" name="DefaultValue" size="50" maxlength="150" value="' . $_POST['DefaultValue']. '" /></td>
286		</tr>';
287
288	echo '<tr>
289			<td>' . _('Numeric Value?') . ':</td>
290			<td><select name="NumericValue">';
291	if ($_POST['NumericValue']==1){
292		echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
293	} else {
294		echo '<option value="1">' . _('Yes') . '</option>';
295	}
296	if ($_POST['NumericValue']==0){
297		echo '<option selected="selected" value="0">' . _('No') . '</option>';
298	} else {
299		echo '<option value="0">' . _('No') . '</option>';
300	}
301	echo '</select></td></tr><tr>
302			<td>' . _('Show On Cert?') . ':</td>
303			<td><select name="ShowOnCert">';
304	if ($_POST['ShowOnCert']==1){
305		echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
306	} else {
307		echo '<option value="1">' . _('Yes') . '</option>';
308	}
309	if ($_POST['ShowOnCert']==0){
310		echo '<option selected="selected" value="0">' . _('No') . '</option>';
311	} else {
312		echo '<option value="0">' . _('No') . '</option>';
313	}
314	echo '</select></td></tr><tr>
315			<td>' . _('Show On Spec?') . ':</td>
316			<td><select name="ShowOnSpec">';
317	if ($_POST['ShowOnSpec']==1){
318		echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
319	} else {
320		echo '<option value="1">' . _('Yes') . '</option>';
321	}
322	if ($_POST['ShowOnSpec']==0){
323		echo '<option selected="selected" value="0">' . _('No') . '</option>';
324	} else {
325		echo '<option value="0">' . _('No') . '</option>';
326	}
327	echo '</select></td></tr><tr>
328			<td>' . _('Show On Test Plan?') . ':</td>
329			<td><select name="ShowOnTestPlan">';
330	if ($_POST['ShowOnTestPlan']==1){
331		echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
332	} else {
333		echo '<option value="1">' . _('Yes') . '</option>';
334	}
335	if ($_POST['ShowOnTestPlan']==0){
336		echo '<option selected="selected" value="0">' . _('No') . '</option>';
337	} else {
338		echo '<option value="0">' . _('No') . '</option>';
339	}
340	echo '</select></td></tr><tr>
341			<td>' . _('Active?') . ':</td>
342			<td><select name="Active">';
343	if ($_POST['Active']==1){
344		echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
345	} else {
346		echo '<option value="1">' . _('Yes') . '</option>';
347	}
348	if ($_POST['Active']==0){
349		echo '<option selected="selected" value="0">' . _('No') . '</option>';
350	} else {
351		echo '<option value="0">' . _('No') . '</option>';
352	}
353	echo '</select></td>
354		</tr>
355		</table>
356		<br />
357		<div class="centre">
358			<input type="submit" name="submit" value="' . _('Enter Information') . '" />
359		</div>
360        </div>
361		</form>';
362
363} //end if record deleted no point displaying form to add record
364if (!isset($SelectedQATest)) {
365
366/* It could still be the second time the page has been run and a record has been selected for modification - SelectedQATest will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters
367then none of the above are true and the list of QA Test will be displayed with
368links to delete or edit each. These will call the same page again and allow update/input
369or deletion of the records*/
370
371	$sql = "SELECT testid,
372				name,
373				method,
374				groupby,
375				units,
376				type,
377				defaultvalue,
378				numericvalue,
379				showoncert,
380				showonspec,
381				showontestplan,
382				active
383			FROM qatests
384			ORDER BY name";
385	$result = DB_query($sql);
386
387	echo '<table class="selection">
388		<thead>
389			<tr>
390			<th class="ascending">' . _('Test ID') . '</th>
391			<th class="ascending">' . _('Name') . '</th>
392			<th class="ascending">' . _('Method') . '</th>
393			<th class="ascending">' . _('Group By') . '</th>
394			<th class="ascending">' . _('Units') . '</th>
395			<th class="ascending">' . _('Type') . '</th>
396			<th>' . _('Possible Values') . '</th>
397			<th class="ascending">' . _('Numeric Value') . '</th>
398			<th class="ascending">' . _('Show on Cert') . '</th>
399			<th class="ascending">' . _('Show on Spec') . '</th>
400			<th class="ascending">' . _('Show on Test Plan') . '</th>
401			<th class="ascending">' . _('Active') . '</th>
402			</tr>
403		</thead>
404		<tbody>';
405
406	while ($myrow=DB_fetch_array($result)) {
407
408	if ($myrow['active'] == 1) {
409		$ActiveText = _('Yes');
410	} else {
411		$ActiveText = _('No');
412	}
413	if ($myrow['numericvalue'] == 1) {
414		$IsNumeric = _('Yes');
415	} else {
416		$IsNumeric = _('No');
417	}
418	if ($myrow['showoncert'] == 1) {
419		$ShowOnCertText = _('Yes');
420	} else {
421		$ShowOnCertText = _('No');
422	}
423	if ($myrow['showonspec'] == 1) {
424		$ShowOnSpecText = _('Yes');
425	} else {
426		$ShowOnSpecText = _('No');
427	}
428	if ($myrow['showontestplan'] == 1) {
429		$ShowOnTestPlanText = _('Yes');
430	} else {
431		$ShowOnTestPlanText = _('No');
432	}
433
434	switch ($myrow['type']) {
435	 	case 0; //textbox
436	 		$TypeDisp='Text Box';
437	 		break;
438	 	case 1; //select box
439	 		$TypeDisp='Select Box';
440			break;
441		case 2; //checkbox
442			$TypeDisp='Check Box';
443			break;
444		case 3; //datebox
445			$TypeDisp='Date Box';
446			break;
447		case 4; //range
448			$TypeDisp='Range';
449			break;
450	} //end switch
451
452	printf('<tr class="striped_row">
453			<td class="number">%s</td>
454			<td>%s</td>
455			<td>%s</td>
456			<td>%s</td>
457			<td>%s</td>
458			<td>%s</td>
459			<td>%s</td>
460			<td>%s</td>
461			<td>%s</td>
462			<td>%s</td>
463			<td>%s</td>
464			<td>%s</td>
465			<td><a href="%sSelectedQATest=%s">' .  _('Edit') . '</a></td>
466			<td><a href="%sSelectedQATest=%s&amp;delete=1" onclick="return confirm(\'' . _('Are you sure you wish to delete this QA Test ?') . '\');">' . _('Delete') . '</a></td>
467			</tr>',
468			$myrow['testid'],
469			$myrow['name'],
470			$myrow['method'],
471			$myrow['groupby'],
472			$myrow['units'],
473			$TypeDisp,
474			$myrow['defaultvalue'],
475			$IsNumeric,
476			$ShowOnCertText,
477			$ShowOnSpecText,
478			$ShowOnTestPlanText,
479			$ActiveText,
480			htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?',
481			$myrow['testid'],
482			htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?',
483			$myrow['testid']);
484
485	} //END WHILE LIST LOOP
486	echo '</tbody></table><br />';
487} //end of ifs and buts!
488include('includes/footer.php');
489?>