You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
18 KiB

<?php
define("QUANTIDADE_QUESTOES", 10);
define("QUANTIDADE_OPCOES", 10);
$tpLayout = 1;
$ppId = $_FORMS["pp_id"];
$idOper = !$ppId ? session_id() : $ppId;
$valuesForm = array();
$mostraIncluiQuetoes = MostraInclusaoQuestoes($ppId);
$msgErro = "";
$fieldsTable = array("pp_nome", "pp_audio_saudacao", "pp_audio_encerramento", "pp_status");
$quantidadeQuestoes = !isset($_FORMS["quantidadeQuestoes"]) ? QUANTIDADE_QUESTOES : $_FORMS["quantidadeQuestoes"];
$quantidadeOpcoes = !isset($_FORMS["quantidadeOpcoes"]) ? QUANTIDADE_OPCOES : $_FORMS["quantidadeOpcoes"];
$upload = 1;
if (!IsPostBack()) {
/*
* Quando $ppId <EFBFBD> passado a opere<EFBFBD><EFBFBD>o <EFBFBD> de edi<EFBFBD><EFBFBD>o
*/
if ($ppId) {
$table = GetPesquisa($idOper);
} else {
$valuesForm["pp_status"] = 1;
$table = GetTable($quantidadeQuestoes, $quantidadeOpcoes);
}
} else {
$aform = $_FORMS["qst_descricao"];
$arTecla = $_FORMS["qst_tecla"];
$arAudio = $_FILES["pp_audio"]["tmp_name"];
$arAudioName = $_FILES["pp_audio"]["name"];
$arQuetoes = array();
$arOpcoes = array();
$arTipo = $_FORMS["pq_tipo"];
foreach ($aform as $key => $value) {
$opcForm = array();
foreach ($value as $kQuest => $vQuest) {
if (!$kQuest)
$arQuetoes[$key] = $vQuest;
else
$opcForm[] = $vQuest;
}
$arOpcoes[$key] = $opcForm;
}
$table = GetTable($quantidadeQuestoes, $quantidadeOpcoes, 0, $arQuetoes, $arOpcoes, $arAudio, $arTipo, $arTecla);
if (!isset($_FORMS["pp_status"])) {
$_FORMS["pp_status"] = 1;
}
foreach ($fieldsTable as $key)
$valuesForm[$key] = $_FORMS[$key];
/*
* Valida<EFBFBD><EFBFBD>o do form pp_nome, pp_data_inicio, pp_data_fim, pp_audio_saudacao,
pp_audio_encerramento, pp_status
*/
$pp_nome = trim($_FORMS["pp_nome"]);
$pp_audio_saudacao = trim($_FILES["pp_audio_saudacao"]["name"]);
$pp_audio_encerramento = trim($_FILES["pp_audio_encerramento"]["name"]);
$pp_status = isset($_FORMS["pp_status"]);
if (empty($pp_nome)) {
$msgErro = "Informe um nome para pesquisa!";
} else if (!$pp_audio_saudacao || (GetFileExt($pp_audio_saudacao) <> "mp3")) {
$msgErro = "Informe um arquivo mp3 para o <EFBFBD>udio de Sauda<EFBFBD><EFBFBD>o!";
} else if (!$pp_audio_encerramento || (GetFileExt($pp_audio_encerramento) <> "mp3")) {
$msgErro = "Informe um arquivo mp3 para o <EFBFBD>udio de Encerramento!";
}
if (empty($msgErro)) {
$valuesForm["pp_audio_saudacao"] = trim($_FILES["pp_audio_saudacao"]["name"]);
$valuesForm["pp_audio_encerramento"] = trim($_FILES["pp_audio_encerramento"]["name"]);
$where = " where pp_id = '$ppId'";
if ($ppId) {
//$result = UpdateDb ($dbcon, 'pbx_pesquisa', $valuesForm, $where);
$msgErro = "Recurso n<EFBFBD>o implementado. Se necess<EFBFBD>rio altera<EFBFBD><EFBFBD>es dever<EFBFBD> recria-la!";
// $jsStartup[] = "alert('$msgErro'); ";
} else {
$query = "begin";
$result = pg_query($dbcon, $query);
if ($result) {
$result = InsertDb($dbcon, 'pbx_pesquisa', $valuesForm, "pbx_pesquisa_pp_id_seq");
$pp_id = $result;
}
$tmpName = $_FILES['pp_audio_saudacao']['tmp_name'];
$nameFile = $_FILES['pp_audio_saudacao']['name'];
$nameFileNew = RemoveEspaco("pesquisa_audio_sauda_$pp_id.mp3");
if ($result)
$result = MoveFile($tmpName, $nameFile, $nameFileNew, true, $msgErro);
$tmpName = $_FILES['pp_audio_encerramento']['tmp_name'];
$nameFile = $_FILES['pp_audio_encerramento']['name'];
$nameFileNew = RemoveEspaco("pesquisa_audio_encerra_$pp_id.mp3");
if ($result) {
MoveFile($tmpName, $nameFile, $nameFileNew, true, $msgErro);
$result = ($msgErro == '');
}
if ($result)
$result = InsertQuestoes($dbcon, $pp_id, $arQuetoes, $arOpcoes, $arAudio, $arAudioName, $arTipo, $arTecla);
if ($result) {
$mesRet = explode(":", $result);
$result = $mesRet[0] == "[OK]";
if (!$result) {
$msgErro = $mesRet[1];
}
}
if ($result) {
$query = "commit";
$result = pg_query($dbcon, $query);
$table = GetPesquisa($pp_id);
$jsStartup[] = "alert('Pesquisa inserida com sucesso!'); ";
} else {
$pp_id = 0;
$query = "rollback";
$result = pg_query($dbcon, $query);
}
}
if ($result == -1) {
$msgErro = "N<EFBFBD>o foi poss<EFBFBD>vel atualizar o banco de dados!";
}
}
// // if(!empty($_FILES['logoRelatorio']['name']))
}
if ($msgErro)
$jsStartup[] = "alert('$msgErro'); ";
//$jsJQuery[] = "\$('#penalidade').keyup(function(){somenteNumeros(this);}) ";
//$jsJQuery[] = "\$('#pp_data_inicio').keypress(function(){formataDataHora(this);}) ";
//$jsJQuery[] = "\$('#pp_data_fim').keypress(function(){formataDataHora(this);}) ";
$jsJQuery[] = sprintf("\$('#insereQuestoes').css(\"visibility\", \"%s\");", $mostraIncluiQuetoes ? "visible" : "hidden");
// $jsJQuery[] = "\$(document).ready(function(){var \$box = $('.box'); \$box.toggle();});";
$valuesForm['acaoUser'] = "Gravar";
$valuesForm['pp_id'] = $ppId;
if (!$numQuest)
$table = "N<EFBFBD>o h<EFBFBD> quest<EFBFBD>es incluidas!";
foreach ($valuesForm as $key => $value)
$smarty->assign($key, $value);
$smarty->assign("msg", $msgErro);
$smarty->assign("questoes", $table);
GetTemplate($smarty, 'pesquisa/pesquisaCad.htm');
function MostraInclusaoQuestoes($ppId) {
return !$ppId;
}
function GetTable($quantidadeQuestoes, $quantidadeOpcoes, $ppId = 0, $arQuetoes = [], $arOpcoes = [], $arAudio = [], $arTipo = [], $arTecla = [], $arQuetoesId = []) {
$table = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">
<tr>
<td colspan=\"2\">Informe em sequ<EFBFBD>ncia Quest<EFBFBD>es com seus respctivos <EFBFBD>udios e Op<EFBFBD><EFBFBD>es!</td>
</tr> ";
$linhaQuest = "";
$linhaOpc = "";
$qst_descricao = "";
$criaQuestoes = 0;
$criaOpcoes = 0;
$pq_display = 0;
$po_display = 0;
$existeQuet = count($arQuetoes);
while ($criaQuestoes <= $quantidadeQuestoes) {
$qst_descricao = $existeQuet ? $arQuetoes[$criaQuestoes] : ""; // "Questao " . ($criaQuestoes+1);
$idQuestao = "ppQuestao_$criaQuestoes";
$idAudio = "ppAudio_$criaQuestoes";
$tipoQuestao = ''; //!$arTipo ? GetTipoQuestao($criaQuestoes, 0) : GetTipoQuestao($criaQuestoes, $arTipo[$criaQuestoes]);
$audio = $arAudio[$criaQuestoes];
$imgAudio = !$audio ? '' : "<img src=\"imgSite/sound22.png\" width=\"22\" height=\"22\" border=\"0\" title=\"$audio!\" align=\"absmiddle\">";
$pqId = !$arQuetoesId ? 0 : $arQuetoesId[$criaQuestoes];
//$imgAudio = $imgAudio ? "<a href=\"index.php?idProg=184&pp_id=$ppId&pq_id=$pqId\" target=\"_new\">$imgAudio</a>" : "";
$imgAudio = $imgAudio ? "<a href=\"javaScript:NovaJanela('index.php?idProg=184&pp_id=$ppId&pq_id=$pqId', '$audio', '300', '200', 'resizable=NO,scrollbars=YES');\">$imgAudio</a>" : "";
$imgDel = ""; //!$ppId ? "" : " <img src=\"imgSite/fecha16.png\" width=\"16\" height=\"16\" align=\"absmiddle\" title=\"Exclui a quest<EFBFBD>o: $qst_descricao\" />";
$pq_display++;
$linhaQuest .= "<tr>
<td>$pq_display)</td>
<td><input name=\"qst_descricao[$criaQuestoes][0]\" type=\"text\" id=\"$idQuestao\" value=\"$qst_descricao\" title=\"Informe aqui a quest<EFBFBD>o " . ($criaQuestoes + 1) . ".\" size=\"107\" maxlength=\"120\">$imgDel</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type=\"file\" name=\"pp_audio[$criaQuestoes]\" id=\"$idAudio\" title=\"Informe um audio para quest<EFBFBD>o " . ($criaQuestoes + 1) . ".\" size=\"40\" style=\"width:415px\" />$imgAudio $tipoQuestao</td>
</tr>";
$linhaOpc = "<tr><td colspan=\"5\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
$criaOpcoes = 0;
$po_display = 0;
$arOpc = $arOpcoes[$criaQuestoes];
while ($criaOpcoes <= $quantidadeOpcoes) {
$idx = $criaOpcoes + 1;
$idOpcao = "opcDescricao_" . $criaQuestoes . "_" . $criaOpcoes;
$idTecla = "opcTecla_" . $criaQuestoes . "_" . $criaOpcoes;
$opc_descricao = $existeQuet ? $arOpc[$criaOpcoes] : ""; // "Op<EFBFBD><EFBFBD>o " . ($idx);
$opc_tecla = $arTecla ? $arTecla[$criaQuestoes][$criaOpcoes] : "";
$po_display++;
$linhaOpc .= "<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>$po_display)</td>
<td>
<input name=\"qst_tecla[$criaQuestoes][$criaOpcoes]\" type=\"text\" id=\"$idTecla\" value=\"$opc_tecla\" title=\"Informe a op<EFBFBD><EFBFBD>o a ser digitada!\" size=\"4\" maxlength=\"2\" style=\"width:40px\">
<input name=\"qst_descricao[$criaQuestoes][$idx]\" type=\"text\" id=\"$idOpcao\" value=\"$opc_descricao\" title=\"Descreva aqui a op<EFBFBD><EFBFBD>o " . ($criaOpcoes + 1) . ".\" size=\"50\" style=\"width:360px\" maxlength=\"60\">
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>";
$criaOpcoes++;
}
$linhaQuest .= $linhaOpc . "</table></td></tr>";
$criaQuestoes++;
}
$GLOBALS["numQuest"] = $criaQuestoes;
return $table . $linhaQuest . "</table>";
}
function InsertQuestoes($db, $pp_id, $arQuetoes, $arOpcoes, $arAudio, $arAudioName, $arTipo, $arTecla) {
/*
* Peqga o id da Pesquisa Inserida
*/
if (!$pp_id)
return "[ERRO]: N<EFBFBD>o foi poss<EFBFBD>vel gerar o identificador da pesquisa!";
$numQuest = 0;
foreach ($arQuetoes as $kQuest => $vQuest) {
/*
* Quest<EFBFBD>es em branco
*/
$vQuest = trim($vQuest);
if (empty($vQuest) && ($vQuest != '0'))
break;
$audio = trim($arAudioName[$kQuest]);
if (empty($audio))
return "[ERRO]: <EFBFBD> necess<EFBFBD>rio informar um <EFBFBD>udio para cada quest<EFBFBD>o!";
if (strtoupper(GetFileExt($audio)) != 'MP3')
return "[ERRO]: <EFBFBD> necess<EFBFBD>rio informar um <EFBFBD>udio para cada quest<EFBFBD>o!";
//$tipo = $arTipo[$kQuest];
//if(!$tipo) return "[ERRO]: <EFBFBD> necess<EFBFBD>rio informar um tipo para cada quest<EFBFBD>o!";
$queryQuest = "insert into pbx_pesquisa_questoes(pp_id, pq_display, pq_questao, pq_tipo, pq_audio, user_reg)values(%s,%s,%s,%s,%s,%s)";
$queryQuest = sprintf($queryQuest, NullDb($pp_id), NullDb(($kQuest + 1)), NullDb($vQuest), '1', NullDb($audio), NullDb(GetLogin()));
$result = pg_query($db, $queryQuest);
if (!$result)
"[ERRO]: N<EFBFBD>o foi poss<EFBFBD>vel inserir a quest<EFBFBD>o!";
/*
* Id da Quest<EFBFBD>o
*/
$pq_id = GetSequenciaDb($db, "pbx_pesquisa_questoes_pq_id_seq");
if (!$pq_id)
return "[ERRO]: N<EFBFBD>o foi poss<EFBFBD>vel gerar o identificador da quest<EFBFBD>o!";
/*
* Tenta Inserir o audio
*/
$audioTmp = trim($arAudio[$kQuest]);
$nameFileNew = Sprintf("pesquisa_questao_%s_%s.mp3", $pp_id, $pq_id);
$msgErro = '';
MoveFile($audioTmp, $audio, $nameFileNew, true, $msgErro);
if ($msgErro)
return "[ERRO]: N<EFBFBD>o foi poss<EFBFBD>vel gravar o arquivo de <EFBFBD>udio: $audio!";
$numOpc = 0;
$confTcl = array();
foreach ($arOpcoes[$kQuest] as $keyOpc => $valueOpc) {
$po_display = $keyOpc + 1;
$opc = trim($valueOpc);
$tcl = trim($arTecla[$kQuest][$keyOpc]);
if ($numOpc && (array_search($tcl, $confTcl) !== false)) {
return "[ERRO]: A op<EFBFBD><EFBFBD>o a ser digitada n<EFBFBD>o pode repetir por quest<EFBFBD>o!";
}
$confTcl[] = $tcl;
if ($tcl && !is_numeric($tcl)) {
return "[ERRO]: A op<EFBFBD><EFBFBD>o a ser digitada tem que ser um n<EFBFBD>mero!";
}
if (trim($opc) == '') {
break;
}
$queryOpc = "insert into pbx_pesquisa_opcoes(pp_id, pq_id, po_display, po_tecla, po_opcao, user_reg)values(%s,%s,%s,%s,%s,%s)";
$queryOpc = sprintf($queryOpc, $pp_id, $pq_id, $po_display, NullDb($tcl), NullDb($opc), NullDb(GetLogin()));
$result = pg_query($db, $queryOpc);
if (!$result)
return "[ERRO]: N<EFBFBD>o foi poss<EFBFBD>vel inserir a op<EFBFBD><EFBFBD>o!";
$numOpc++;
}
if ($numOpc < 2)
return "[ERRO]: <EFBFBD> necess<EFBFBD>rio informar pelo menos duas op<EFBFBD><EFBFBD>es por quest<EFBFBD>o!";
//N<EFBFBD>o foi poss<EFBFBD>vel inserir a op<EFBFBD><EFBFBD>o! insert into pbx_pesquisa_opcoes(pp_id, pq_id, po_display, po_tecla, po_opcao, user_reg)values(35,27,1,null,'Sim','admin')
$numQuest++;
}
if (!$numQuest)
return "[ERRO]: Para inserir uma pesquisa <EFBFBD> necess<EFBFBD>rio pelo menos uma quest<EFBFBD>o!";
echo "<script>opener.location.reload();</script>";
return "[OK]: Pesquisa inserida com sucesso!";
}
function GetTipoQuestao($questId, $tipo = 0) {
$db = $GLOBALS["dbcon"];
$select = !$tipo ? 'selected="selected"' : '';
$ret = sprintf('<select name="pq_tipo[%s]" id="pq_tipo_%s" style="width: 250px" title="Selecione o tipo da questao">\n', $questId, $questId);
$ret .= "<option value=\"0\" $select>----------------</option>\n";
$query = "select pqt_id, pqt_descricao from pbx_pesquisa_questao_tipo where pqt_status = 1";
$result = pg_query($db, $query);
while ($dados = pg_fetch_array($result)) {
$pqtId = $dados["pqt_id"];
$pqtDescricao = $dados["pqt_descricao"];
$select = $tipo == $pqtId ? 'selected="selected"' : '';
$ret .= "<option value=\"$pqtId\" $select>$pqtDescricao</option>\n";
}
$ret .= "</select>\n";
return $ret;
}
function GetPesquisa($idOper) {
$valuesForm = &$GLOBALS["valuesForm"];
$fieldsTable = &$GLOBALS["fieldsTable"];
$quantidadeQuestoes = $GLOBALS["quantidadeQuestoes"];
$quantidadeOpcoes = $GLOBALS["quantidadeOpcoes"];
$dbcon = $GLOBALS["dbcon"];
$query = "select pp_id, pp_nome, pp_audio_saudacao,
pp_audio_encerramento, pp_status, pp_data
from pbx_pesquisa where pp_id = $idOper";
$result = pg_query($dbcon, $query);
while ($dados = pg_fetch_array($result)) {
foreach ($fieldsTable as $key)
$valuesForm[$key] = $dados[$key];
$audio = $dados["pp_audio_saudacao"];
$imgAudio = "<img src=\"imgSite/sound22.png\" width=\"22\" height=\"22\" border=\"0\" title=\"$audio!\" align=\"absmiddle\">";
$imgAudio = "<a href=\"javaScript:NovaJanela('index.php?idProg=184&pp_id=$idOper&sauda=1', '$audio', '300', '200', 'resizable=NO,scrollbars=YES');\">$imgAudio</a>";
//$imgAudio = "<a href=\"index.php?idProg=184&pp_id=$idOper&sauda=1\">$imgAudio</a>";
$valuesForm["audioSauda"] = $imgAudio;
$audio = $dados["pp_audio_encerramento"];
$imgAudio = "<img src=\"imgSite/sound22.png\" width=\"22\" height=\"22\" border=\"0\" title=\"$audio!\" align=\"absmiddle\">";
//$imgAudio = "<a href=\"index.php?idProg=184&pp_id=$idOper\">$imgAudio</a>";
$imgAudio = "<a href=\"javaScript:NovaJanela('index.php?idProg=184&pp_id=$idOper', '$audio', '300', '200', 'resizable=NO,scrollbars=YES');\">$imgAudio</a>";
$valuesForm["audioEncerra"] = $imgAudio;
}
$arQuetoes = array();
$arQuetoesId = array();
$arOpcoes = array();
$arAudio = array();
$arTipo = array();
$arTecla = array();
GetQuestoesDb($dbcon, $idOper, $arQuetoes, $arOpcoes, $arAudio, $arTipo, $arTecla, $arQuetoesId);
return GetTable($quantidadeQuestoes, $quantidadeOpcoes, $idOper, $arQuetoes, $arOpcoes, $arAudio, $arTipo, $arTecla, $arQuetoesId);
}
function GetQuestoesDb($dbcon, $idOper, &$arQuetoes, &$arOpcoes, &$arAudio, &$arTipo, &$arTecla, &$arQuetoesId) {
$queryQuest = "select pp_id, pq_id, pq_display, pq_questao, pq_tipo, pq_audio, pq_status
from pbx_pesquisa_questoes
where pp_id = '$idOper'
order by pq_id";
$resultQuest = pg_query($dbcon, $queryQuest);
$numQuest = 0;
$numOpc = 0;
while ($dadosQuest = pg_fetch_array($resultQuest)) {
$pqId = $dadosQuest["pq_id"];
$pqQuestao = $dadosQuest["pq_questao"];
$pqAudio = $dadosQuest["pq_audio"];
$pqTipo = $dadosQuest["pq_tipo"];
$arQuetoes[] = $pqQuestao;
$arAudio[] = $pqAudio;
$arTipo[] = $pqTipo;
$arQuetoesId[] = $pqId;
$queryOpcao = "select pp_id, pq_id, po_id, po_display, po_tecla, po_opcao, po_status
from pbx_pesquisa_opcoes
where pp_id = '$idOper'
and pq_id = '$pqId'
order by po_id";
$resultOpcao = pg_query($dbcon, $queryOpcao);
$arOpc = array();
$arTcl = array();
while ($dadosOpc = pg_fetch_array($resultOpcao)) {
$poOpc = $dadosOpc["po_opcao"];
$arOpc[] = $poOpc;
$arTcl[] = $dadosOpc["po_tecla"];
}
$arOpcoes[] = $arOpc;
$arTecla[] = $arTcl;
}
}
$jsJQuery[] = "\$(document).ready(function(){
$('.animate').click(function(){
var \$box = \$('.box');
if(\$box.is(':visible')){
\$box.slideToggle('slow');
$('#animate').attr(\"src\", \"imgSite/expand.jpg\");
$('#labelRotas').text(\" Exibir Quest<EFBFBD>es\");
}
else{
$('#animate').attr(\"src\", \"imgSite/collapse.jpg\");
$('#labelRotas').text(\" Ocultar Quest<EFBFBD>es\");
\$box.slideToggle('slow');
}
});
});
";
$cssBlock = '<style type="text/css">
div.scrollableContainer {
position: relative;
padding-top: 1.4em;
}
div.scrollingArea {
height: 320px;
overflow: scroll;
border:0;
}
.tipFocus { color: #fff; font-style: italic; }
</style>';
?>