Bom dia! Preciso "Pegar os Ids" selecionados e alterar os seus status para opção que escolher no select status. Edição em massa, o mesmo valor no campo status para todos Ids selecionados.
Models: Os_model
public function edit($table, $data, $fieldID, $ID)
{
$this->db->where($fieldID, $ID);
$this->db->update($table, $data);
if ($this->db->affected_rows() >= 0) {
return true;
}
return false;
}
Controllers: Os.php
public function alterarCheckbox(){
$ids = $this->input->post('status');
$numRegs = count($ids);
if($numRegs > 0){
// atualiza status no banco de dados
foreach($this->input->post('status') as $valor){
$dados['status'] = 1;
$this->db->where('idOs', $valor);
if($this->db->update('os', $dados)){
echo $valor." > Atualizado <br>";
}
}
} else {
echo "Nenhum item foi marcado.";
}
}
os.php
<form name="form1" id="form1" method="post" action="<?php echo current_url(); ?>" onSubmit="return valida_campos();">
<?php echo form_hidden('idOs',$result->idOs) ?>
<label for="status" class="control-label"></label>
<div class="controls">
<select class="span2" name="status[<?php echo $res['id'] ?>]" id="status" value="">
<option>status</option>
<option <?php if ($result->status == 'Aguardando') { echo 'selected'; } ?> value="Aguardando">Aguardando</option>
<option <?php if ($result->status == 'Liberado') { echo 'selected'; } ?> value="Liberado">Liberado</option>
</select>
<span>
<button type="submit" class="btn" style="padding-top: px;border-top-width: px;margin-bottom: 9px;"><i class="fas fa-sync-alt"></i></button>
</span>
</div>
/*input para conferir que os IDs foram selecionados*/
<input class="span6" type="text" name="grupo_os" id="grupo_os" />
<table>
<thead>
<tr>
<th><input name="todos" id="todos" type="checkbox" value="todos" onchange="if(this.checked == true){marcacao_generico('form1',1,'os','grupo_os');}else{marcacao_generico('form1',0,'os','grupo_os');}" /> </th>
<th>N° OS</th>
<th>Campo 1</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
foreach ($results as $r) {
echo '<tr>';
echo '<td><input type="checkbox" name="os" value="'. $r->idOs. '" onclick="acao_coleta_generico(\''. $r->idOs. '\', \'grupo_os\' );"></td>';
echo '<td>' . $r->idOs . '</td>';
echo '<td>' . $r->campo1 . '</td>';
echo '<td>' . $r->status . '</td>';
echo '</tr>';
} ?>
</tbody>
</table>
</form>
/*Código para CheckBox*/
<?PHP
if(isset($_POST['grupo_os']))
{
$os = '';
$os = explode(",",str_replace(':','',$_POST['grupo_os']));
?>
<br>
<?PHP
for($i = 0;$i < count($os) - 1; $i++)
{
echo($os[$i]);
echo "<br>";
}
?>
<hr>
<?PHP
}
?>
<script type="text/javascript">
function acao_coleta_generico(valor, campo_alvo) {
if (document.getElementById(campo_alvo).value.indexOf(':' + valor + ':,') == -1) {
document.getElementById(campo_alvo).value += ':' + valor + ':,';
} else {
var grupo = document.getElementById(campo_alvo).value;
grupo = grupo.replace(':' + valor + ':,', '');
document.getElementById(campo_alvo).value = grupo;
}
}
function marcacao_generico(formulario, opcao, campo, campo_alvo) {
for (i = 0; i < document.getElementById(formulario).elements.length; i++) {
if (document.getElementById(formulario).elements[i].name == campo) {
if (document.getElementById(formulario).elements[i].checked != opcao) {
document.getElementById(formulario).elements[i].checked = opcao;
acao_coleta_generico(document.getElementById(formulario).elements[i].value, campo_alvo);
}
}
}
}
function valida_campos() {
if (document.getElementById('grupo_os').value == '') {
alert('Por favor, selecione ao menos um item.');
return false;
}
}
</script>
id
?