function Main() { $cod = $_POST["c"]; $des = urldecode($_POST["d"]); $pai = $_POST["p"]; header('Content-Type: text/html; charset=iso-8859-1'); try { $n = new AreaConhecimento(); if ($cod != "") { $n->setCodigo($cod); } if ($des != "") { $n->setDescricao($des); } if ($pai != "") { $n->setAreaPai($pai); } if ($n->VerificaCodigo() == false) { if ($n->AdicionaAreaConhecimento()) { echo "GRAVADO"; } else { echo $n->msg_erro; } } else { if ($n->AtualizaAreaConhecimento()) { echo "GRAVADO"; } else { echo $n->msg_erro; } } } catch (Exception $ex) { echo $ex->getMessage(); } }
public static function RetornaArea($p_codigo) { $sql = "SELECT Codigo, Descricao, CodAreaPai FROM mesarea WHERE Codigo = :pCodigo;"; $cnn = Conexao2::getInstance(); $cmd = $cnn->prepare($sql); $cmd->bindParam(":pCodigo", $p_codigo, PDO::PARAM_INT); $cmd->execute(); $rs = $cmd->fetch(PDO::FETCH_OBJ); $ar = new AreaConhecimento(); $ar->setCodigo($rs->Codigo); $ar->setDescricao($rs->Descricao); if (!is_null($rs->CodAreaPai)) { if ($rs->CodAreaPai > 0) { $ar->setAreaPai(self::RetornaArea($rs->CodAreaPai)); } } return $ar; }