89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
$prodinstname = $prodinsts[0]['prodinstname'];
|
|
$qi = 0;
|
|
?>
|
|
|
|
<input type='hidden' name='instid' value='<?=$prodinstid;?>' />
|
|
<input type='hidden' id='prodinsttestid_del' name='prodinsttestid_del' value='' />
|
|
<div class="modal-header">
|
|
<small><?=$prodinstname;?></small>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<button type="button" class="btn btn-success mb-3" onclick='row_add()'> <i class='bi bi-plus-circle'></i>Add Row </button>
|
|
<table class='table table-bordered table-hover table-sm'>
|
|
<thead>
|
|
<tr> <td class='text-center'>Testcode</td> <td class='text-center'>Inst-Testcode</td> </tr>
|
|
</thead>
|
|
<tbody id='insttest_body'>
|
|
<?php
|
|
$cnt = count($prodinsttests);
|
|
if($cnt < 5){ $cnt = 5; }
|
|
for($i=$qi; $i < $cnt+1; $i++) {
|
|
$testid = '';
|
|
$insttestcode = '';
|
|
if( isset($prodinsttests[$i]['testid']) ) {
|
|
$testid = $prodinsttests[$i]['testid'];
|
|
$insttestcode = $prodinsttests[$i]['insttestcode'];
|
|
}
|
|
?>
|
|
<tr>
|
|
<td>
|
|
<select class='form-control' name='testid[]'>
|
|
<option value=''>-</option>
|
|
<?php
|
|
foreach($tests as $test) {
|
|
$qtestid = $test['testid'];
|
|
$qtestcode = $test['testcode'];
|
|
$qtestname = $test['testname'];
|
|
if($testid==$qtestid) { echo "<option value='$qtestid' selected>$qtestcode - $qtestname</option>"; }
|
|
else { echo "<option value='$qtestid'>$qtestcode - $qtestname</option>"; }
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
<td><input class='form-control' type='text' name='prodinsttestcode[]' value='<?=$prodinsttestcode;?>' /></td>
|
|
<?php
|
|
if($i==0) {echo "<td></td>";}
|
|
else {echo "<td><button type='button' class='btn btn-danger' onclick='row_del(this)'>X</button></td>";}
|
|
?>
|
|
</tr>
|
|
<?php
|
|
$qi++;
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" class="btn btn-primary">Save changes</button>
|
|
</div>
|
|
|
|
<script>
|
|
// del row
|
|
function row_del(e) {
|
|
if(confirm('Are you sure?')) {
|
|
const table = document.getElementById('insttest_body');
|
|
if(table.rows.length >2) { e.parentNode.parentNode.remove(); }
|
|
}
|
|
}
|
|
|
|
// add row
|
|
function row_add() {
|
|
const table = document.getElementById('insttest_body');
|
|
const lastRow = table.rows[table.rows.length - 1];
|
|
const newRow = lastRow.cloneNode(true);
|
|
|
|
// Clear select and input elements in the cloned row
|
|
newRow.querySelectorAll('select, input').forEach(element => {
|
|
if (element.tagName === 'SELECT') {
|
|
element.selectedIndex = 0;
|
|
} else {
|
|
element.value = ''; // Clear input value
|
|
}
|
|
});
|
|
|
|
table.appendChild(newRow);
|
|
}
|
|
</script>
|