I put only the relevant parts of the code, so I do not saturate them with a code with more than 3,000 lines, ok?
Next ... I have some error (s) in the code below:
activate_pabxvirtual.php file:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scripttype="text/javascript">
function alterar_div_seleciona_grupo() {
$.ajax({
type: "POST",
url: "vinculagrupo.php",
data: {
ramal: $('#ramal').val(),
grupo: $('#grupo').val()
},
success: function(data) {
$('#seleciona_grupo').html(data);
}
});
window.location.reload();
}
</script>
<table id="tabela" width="100%" border="0" cellpadding="2" cellspacing="5" >
<tr>
<td width="100%" align="center" colspan="2" style="color:#EFEEF0;background-color:#584C95;border-style:inset;border-color:skyblue">
Fila de Atendimento
</td>
</tr>
</table>
<div id="ramal_sel" class="diva" style="display:block">
<table id="tabela" width="100%" border="0" cellpadding="2" cellspacing="5" >
<tr>
<td width="100%" align="center" colspan="2" style="color:#EFEEF0;background-color:#6699FF;border-style:inset;border-color:skyblue">
<b>Organização de Ramais</b>
</td>
</tr>
<tr>
<td width="100%" align="center" colspan="2" align="justify" style="color:#999999;background-color:#F5F5F5;border-style:none;padding-left:2%;padding-right:2%">
<br><b>Vincule os ramais a cada grupo ou opção de atendimento</b><br><br>
</td>
</tr>
<tr>
<td width="100%" align="center" colspan="2" style="color:#EFEEF0;background-color:#6699FF;border-style:inset;border-color:skyblue">Ramais de Atendimento</td>
</tr>
<?php
# Selecionando os ramais de atendimento registrados no BD (tabela ramais)
# Só ramais de atendimento:
$raq = $_SESSION['aplogado']."0";
$qramaisatendimento = mysql_query("SELECT * FROM ramais WHERE usuario='".$_SESSION['aplogado']."' AND ramal LIKE '%".$raq."%'");
if(mysql_num_rows($qramaisatendimento)==0){ ?> <tr><td width="100%" align="center" style="color:#6699FF;background-color:#F5F5F5;border-style:none;padding-left:2%;padding-right:2%"><br>Não há Ramais de Atendimento configurados. <br>Favor contactar nosso suporte: [email protected]<br><br></td></tr><?php }
else { ?>
<tr>
<td width="50%" align="center" style="color:#ffffff;background-color:#cccccc;border-style:none;padding-left:2%;padding-right:2%">Grupo<br></td>
<td width="50%" align="center" style="color:#ffffff;background-color:#cccccc;border-style:none;padding-left:1%;padding-right:1%">Adicione / Vincule ramais</td>
</tr>
</table>
<div id="seleciona_grupo">
<?php
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
// Ramais para o Select
$rasel = $_POST['ramal'];
$rasels .= "<select name=\"ramal\" id=\"ramal\" onchange=\"alterar_div_seleciona_grupo();\" >\r";
$rasels .= "<option value=\"\">Selecione</option>\r";
$qrasel = mysql_query("SELECT * FROM ramais WHERE usuario='".$_SESSION['aplogado']."' AND ramal LIKE '%".$raq."%' AND grupo='' ORDER BY ramal");
while ($rowrasel = mysql_fetch_array($qrasel))
{
$rasels .= "<option value=\"".$rowrasel['ramal']."\" ".iif($ramal=="".$rowrasel['ramal'].""," selected")."> Ramal ".substr($rowrasel['ramal'],-3)." </option>\r";
}
$rasels .= "</select>\r";
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
?>
<table id="tabela" width="100%" border="0" cellpadding="2" cellspacing="5" >
<?php
$qnga = mysql_query("SELECT grupos_de_atendimento,ramais_de_atendimento FROM ilh_usuario WHERE usuario='".$_SESSION['aplogado']."' ");
$rownga = mysql_fetch_array($qnga);
for($gra=1;$gra<=$rownga['grupos_de_atendimento'];$gra++)
{
$grupo_gra = "0".$gra;
?>
<tr>
<td width="50%" align="center" style="color:#6699FF;background-color:#F5F5F5;border-style:none;padding-left:2%;padding-right:2%">
<br><?php if($rownga['grupos_de_atendimento']>=2){echo "Opção ".$grupo_gra;}elseif($rownga['grupos_de_atendimento']==1){echo "Grupo ".$grupo_gra;} ?><br><br>
<?php $gruposelecionado = $_SESSION['aplogado'].$grupo_gra; ?>
<input type="hidden" name="grupo" id="grupo" value="<?php echo $gruposelecionado; ?>" /></td>
<td width="50%" align="center" style="color:#000000;background-color:#F5F5F5;border-style:none;padding-left:1%;padding-right:1%">
<?php
$q2691 = mysql_query("SELECT * FROM ramais WHERE usuario='".$_SESSION['aplogado']."' AND ramal LIKE '%".$raq."%' AND grupo='".$gruposelecionado."' ORDER BY ramal");
while ($row2691 = mysql_fetch_array($q2691))
{
echo "<br>Ramal ".substr($row2691['ramal'],-3)."<br>";
}
echo "<br>".$rasels."<br>";
?>
<br>
</td>
</tr>
<?php
}
} ?>
</table>
</div>
<table id="tabela" width="100%" border="0" cellpadding="2" cellspacing="5" >
<tr>
<td width="100%" align="center" colspan="2" style="color:#EFEEF0;background-color:#6699FF;border-style:inset;border-color:skyblue">
</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center" style="color:#6699FF;background-color:#F5F5F5;border-style:none;padding-left:10%;padding-right:10%">
<br>
<form name="acao_organizado" action="ativar_pabxvirtual.php?acao=distribuir" method="post" >
<input type="submit" name="acaodistribuir" id="acaodistribuir" value="Prosseguir" class="graybutton">
</form><br>
</td>
</tr>
<tr>
<td colspan="2" style="color:#EFEEF0;background-color:#6699FF;border-style:inset;border-color:skyblue"><br></td>
</tr>
</table>
</div>
<?php
}
file linkgroup.php:
<?php
echo "POST-grupo:". $_POST['grupo']."<br>";
echo "POST-ramal:". $_POST['ramal']."<br><br><br>";
$q1 = mysql_query("UPDATE ramais SET grupo='".$_POST['grupo']."' WHERE ramal='".$_POST['ramal']."' AND status='ativo' ");
?>
ERRORS: When I select an extension in the 1st row of the group (1st of the "for" loop), it saves in mysql normally. However, when I select an extension on the other lines, in addition to not capturing the selected extension, the code is capturing the 1st group still (from the 1st of the for).
Could someone give me a light?