function Main() { $codigo = base64_decode($_POST['txtCodigo']); $txt = urldecode($_POST['txtDescricao']); $clsAtual = $_POST['selClasse']; $nivAtual = $_POST['selNivel']; $tipAtual = $_POST['selTipo']; $ativo = $_POST['selAtivo']; $expGeral = urldecode($_POST['txtExplicacaoGeral']); if (trim($codigo) == "") { $codigo = null; } else { if (!is_numeric($codigo)) { echo Comuns::Idioma("@lng[Código informado não é válido]"); } } $p = new Pergunta(); if (!is_null($codigo)) { $p->setCodigo($codigo); } $p->setTexto($txt); $p->setClasse($clsAtual); $p->setNivel($nivAtual); $p->setTipo(TipoPergunta::RetornaTipo($tipAtual)); $p->setAtivo($ativo); if ($expGeral != "") { $p->setTextoExplicacaoGeral($expGeral); } if ($p->getCodigo() === 0) { if ($p->AdicionaPergunta() === true) { $_SESSION['perg'] = $p->getCodigo(); echo "OK"; } else { $_SESSION['perg'] = 0; echo Comuns::Idioma("@lng[Erro ao adicionar a pergunta:]"); } } else { if ($p->AtualizaPergunta() === true) { $_SESSION['perg'] = $p->getCodigo(); echo "OK"; } else { $erros = "@lng[Erros ocorreram.]"; foreach ($p->msg_erro as $err) { $erros .= "<br />" . $err; } echo Comuns::Idioma($erros); } } }
function Main() { $p = $_SESSION['perg']; $codalt = isset($_GET['a']) && !is_null($_GET['a']) ? base64_decode($_GET['a']) : null; if (is_numeric($codalt)) { //$codperg = $p->getCodigo(); $pergunta = new Pergunta(); $pergunta->setCodigo($p); $alt = new Alternativa(); $alt->Carrega($codalt); if ($pergunta->DeletaAlternativa($alt)) { //$pergunta->RecarregarAlternativas(); //$_SESSION['perg'] = serialize($p); header("Location:vwalternativas.php?p=" . base64_encode($p)); } else { $erros = "Erros ocorreram."; foreach ($p->msg_erro as $err) { $erros .= "<br />" . $err; } echo $erros; } } }
public function BuscaSaltosConteudo($strChaveAtual) { $sql = "select "; $sql .= "\t concat(dest.Organizador, '_', dest.TipoConteudo, '_', dest.ContReferencia, '_', salt.ChaveDestino) as ChaveDestino "; $sql .= "\t,salt.ChaveCond "; $sql .= "\t,cond.TipoConteudo as TipoContCond "; $sql .= "\t,salt.CodPergunta "; $sql .= "\t,salt.RespostaCond "; $sql .= "from mescasomontagemsaltos salt "; $sql .= "inner join mescasomontagem mont "; $sql .= "\t\ton mont.CodCaso = salt.CodCaso "; $sql .= "\t and mont.CodMontagem = salt.CodMontagem "; $sql .= "\t and mont.Chave = salt.ChaveAtual "; $sql .= "inner join mescasomontagem dest "; $sql .= "\t\ton dest.CodCaso = salt.CodCaso "; $sql .= "\t and dest.CodMontagem = salt.CodMontagem "; $sql .= "\t and dest.Chave = salt.ChaveDestino "; $sql .= "left outer join mescasomontagem cond "; $sql .= "\t\t\t on cond.CodCaso = salt.CodCaso "; $sql .= "\t\t\tand cond.CodMontagem = salt.CodMontagem "; $sql .= "\t\t\tand cond.Chave = salt.ChaveCond "; $sql .= "where salt.CodCaso = :pCodCaso "; $sql .= " and salt.CodMontagem = 1 "; $sql .= " and salt.ChaveAtual = :pChaveAtual;"; $cnn = Conexao2::getInstance(); $cmd = $cnn->prepare($sql); $cmd->bindParam(":pCodCaso", $this->codcaso, PDO::PARAM_INT); $cmd->bindParam(":pChaveAtual", $strChaveAtual, PDO::PARAM_STR); $cmd->execute(); if ($cmd->errorCode() == Comuns::QUERY_OK) { if ($cmd->rowCount() > 0) { $strProximoItem = ""; $sair = false; while ($salto = $cmd->fetch(PDO::FETCH_OBJ)) { if (is_null($salto->ChaveCond)) { $strProximoItem = $salto->ChaveDestino; break; } else { if ($salto->TipoContCond != 'perg' && $salto->TipoContCond != 'grupo-perg') { $respostas = $this->BuscaRespostas($salto->ChaveCond); $itens = $this->BuscaConteudosAgrupador($salto->ChaveCond, $salto->RespostaCond); foreach ($itens as $opcao) { if ((intval($opcao->ValorOpt, 10) & intval($respostas, 10)) > 0) { $strProximoItem = $salto->ChaveDestino; $sair = true; break; } } } else { $respostas = $this->BuscaRespostas($salto->ChaveCond, $salto->CodPergunta); $p = new Pergunta(); $p->setCodigo($salto->CodPergunta); $itens = $p->BuscaAlternativasFiltradas($salto->RespostaCond); if (count($itens) > 0) { foreach ($itens as $opcao) { if ((intval($opcao->getCodBinario(), 10) & intval($respostas, 10)) > 0) { $strProximoItem = $salto->ChaveDestino; $sair = true; break; } } } else { return 0; } } if ($sair) { break; } } } if ($strProximoItem != "") { return $strProximoItem; } else { return 0; } } else { return 0; } } else { $msg = $cmd->errorInfo(); $this->msg_erro = $msg[2]; return false; } }
function Main() { $codigo = isset($_POST['txtCodigo']) ? base64_decode($_POST['txtCodigo']) : null; $txt = urldecode($_POST['txtDescricao']); $clsAtual = $_POST['selClasse']; $nivAtual = $_POST['selNivel']; $tipAtual = $_POST['selTipo']; $ativo = $_POST['selAtivo']; $act = isset($_POST['act']) ? base64_decode($_POST['act']) : null; $expGeral = $_POST['txtExplicacaoGeral']; $u = unserialize($_SESSION['usu']); // Ação veio vazio. Sendo assim monta o formulário. if (!$act) { // Busca o template $tpl = file_get_contents('tpl/perguntas-E1.html'); $tpl = str_replace("<!--telatopo-->", Comuns::GeraTopoPagina($u), $tpl); $botoes = Botao::BotaoSalvar("fntGravaE1();", "@lng[Salvar pergunta e cadastrar/editar alternativas]"); $botoes .= Botao::BotaoCancelar("fntNavega('listagem.php?t=8');", "@lng[Cancelar edição]"); $tpl = str_replace("<!--itens-toolbar-->", $botoes, $tpl); $tpl = str_replace("<!--Mensagem-->", isset($mensagem) && $mensagem != "" ? base64_decode($mensagem) : "", $tpl); // Verifica se veio um registro informado via GET if (is_null($codigo)) { $codigo = isset($_GET['r']) ? base64_decode($_GET['r']) : null; } // Instancia classe $p = new Pergunta(); // Se veio um código via GET, entende-se que o mesmo deva ser editado. if (!is_null($codigo)) { $p->Carregar($codigo); } $tipos = $p->tipos->ListaRecordSet(); $classes = $p->classes->ListaRecordSet(); $niveis = $p->niveis->ListaRecordSet(); $strtipos = ""; $strclasses = ""; $strniveis = ""; foreach ($tipos as $linhat) { $strtipos .= '<option ' . ($linhat->Codigo == ($p->getTipo() != null ? $p->getTipo()->getCodigo() : 0) ? 'selected="selected"' : '') . ' value="' . $linhat->Codigo . '">' . $linhat->Descricao . '</option>'; } foreach ($classes as $linhac) { $strclasses .= '<option ' . ($linhac->Codigo == $p->getClasse() ? 'selected="selected"' : '') . ' value="' . $linhac->Codigo . '">' . $linhac->Descricao . '</option>'; } foreach ($niveis as $linhan) { $strniveis .= '<option ' . ($linhan->Codigo == $p->getNivel() ? 'selected="selected"' : '') . ' value="' . $linhan->Codigo . '">' . $linhan->Descricao . '</option>'; } $strAtivo = '<option ' . ($p->getAtivo() == 1 ? 'selected="selected"' : "") . ' value="1">@lng[Sim]</option><option ' . ($p->getAtivo() == 0 ? 'selected="selected"' : "") . ' value="0">@lng[Não]</option>'; $tpl = str_replace("<!--txtCodigo-->", $p->getCodigo() == 0 ? "" : base64_encode($p->getCodigo()), $tpl); $tpl = str_replace("<!--TextoPergunta-->", $p->getTexto(), $tpl); $tpl = str_replace("<!--txtExplicacaoGeral-->", is_null($p->getTextoExplicacaoGeral()) ? "" : $p->getTextoExplicacaoGeral(), $tpl); $tpl = str_replace("<!--ListaClasses-->", $strclasses, $tpl); $tpl = str_replace("<!--ListaNiveis-->", $strniveis, $tpl); $tpl = str_replace("<!--ListaAtivo-->", $strAtivo, $tpl); $tpl = str_replace("<!--ListaTipos-->", $strtipos, $tpl); } else { if ($act == "ins") { $p = new Pergunta(); if (!is_null($codigo)) { $p->setCodigo($codigo); } $p->setTexto($txt); $p->setClasse($clsAtual); $p->setNivel($nivAtual); $p->setTipo($tipAtual); $p->setAtivo($ativo); if ($expGeral != "") { $p->setTextoExplicacaoGeral($expGeral); } if ($p->getCodigo() === 0) { if ($p->AdicionaPergunta() === true) { $_SESSION['perg'] = serialize($p); header("Location:alternativas.php"); } else { $_SESSION['perg'] = ""; echo "@lng[Erro ao adicionar a pergunta:]"; } } else { if ($p->AtualizaPergunta() === true) { $_SESSION['perg'] = serialize($p); } } } } echo Comuns::Idioma($tpl); }