0
Hello the question is this:
I have a Controller called dinChamado.class.php, with the following methods::
public function comentario()
{
$obj_chamado = new daoChamado();
$this->setVar('sch_codigo',$obj_chamado->recuperaChamado(self::$v_get[0]));
$this->setVar("acao","adicionar");
$this->setTPL("form/insuporte/form_comentario.php");
$this->gerarTemplate();
}
public function addComentario(){
print_r($_REQUEST);
$_REQUEST['sco_codigo'] = $this->obj_comentario->geraCodigo();
daoComentario::$ajax = 'T';
$obj_entComentario = new entComentario();
$obj_entComentario->setSchCodigo($_POST['sco_sch_codigo']);
$resposta = array("resultado"=>"sucesso");
$resultado = $this->obj_comentario->Inserir();
if(!$resultado)
{
$resposta = array("resultado"=>"erro","motivo"=>"Ocorreu um erro no processamento");
}
echo json_encode($resposta);
}
In Call.class.php is the following method:
function recuperaChamado($sch_codigo){
$rs = $this->especialQuery("SELECT a.sch_codigo,a.sch_descricao,a.sch_contato,a.sch_ramal,a.sch_tecnico,b.sar_codigo,b.sar_titulo,b.sar_id,b.sar_data_ini,b.sar_data_update,b.sar_data_fim,b.sar_resp_id,b.sar_habilitado,c.spr_codigo,c.spr_problema,c.spr_descricao,c.spr_sla,c.spr_sar_codigo,c.spr_id,c.spr_data_ini,c.spr_data_update,c.spr_data_fim,c.spr_resp_id,c.spr_habilitado,d.sri_codigo,d.sri_prioridade,d.sri_id,d.sri_data_ini,d.sri_data_update,d.sri_data_fim,d.sri_resp_id,d.sri_habilitado,e.sun_codigo,e.sun_unidade,e.sun_id,e.sun_data_ini,e.sun_data_update,e.sun_data_fim,e.sun_resp_id,e.sun_habilitado,f.sts_codigo,f.sts_status,f.sts_id,f.sts_data_ini,f.sts_data_update,f.sts_data_fim,f.sts_resp_id,f.sts_habilitado,a.sch_id,DATE_FORMAT(a.sch_data_ini,'%d/%m/%Y %H:%i:%s') AS sch_data_ini ,DATE_FORMAT(a.sch_data_update,'%d/%m/%Y %H:%i:%s') AS sch_data_update ,DATE_FORMAT(a.sch_data_fim,'%d/%m/%Y %H:%i:%s') AS sch_data_fim ,g.usu_nome,g.usu_login,g.usu_senha,g.usu_cpf,g.usu_flag_adm,g.usu_per_id,g.usu_email,g.usu_telefone,g.usu_celular,g.usu_id,g.usu_data_ini,g.usu_data_update,g.usu_data_fim,g.usu_resp_id,g.usu_habilitado,a.sch_habilitado FROM insuporte_chamado as a LEFT JOIN insuporte_area AS b ON a.sch_sar_codigo = b.sar_codigo LEFT JOIN insuporte_problema AS c ON a.sch_spr_codigo = c.spr_codigo LEFT JOIN insuporte_prioridade AS d ON a.sch_sri_codigo = d.sri_codigo LEFT JOIN insuporte_unidade AS e ON a.sch_sun_codigo = e.sun_codigo LEFT JOIN insuporte_status AS f ON a.sch_sts_codigo = f.sts_codigo LEFT JOIN sistema_usuario AS g ON a.sch_resp_id = g.usu_id WHERE 1= 1 AND sch_st_id = 1 AND sch_codigo = '".$sch_codigo."' ");
return $rs;
}
In the Controller comment method I am generating the TPL (template) and the variable to be sent to the TPL form_comentario.php.
In the addComentario method it is inserting the fields but not the sco_sch_codigo field that is the foreign key (FK that connects the two entities Called and Comment. I tried several ways giving $_REQUEST with $_POST and variable but could not, if you can help me thank.
I did not inform that in form_comentario.php I have a form with sender and comment, only that I need to capture the code of the call to which the comment is being sent, again thank you for the help of all.
– user53616
I got it here in the internship, my supervisor helped me and showed me what I wasn’t doing: public Function comentario(){ $obj_chamado = new daoChamado(); $this->setVar('chamado',$obj_chamado->recuperaChamado(self::$v_get[0]));
 $this->setVar("acao","adicionar");
 $this->setTPL("form/insuporte/form_comentario.php");
 $this->gerarTemplate();
 
 }
– user53616
public Function addComentario(){ $reply = array("result"=>"success"); $_REQUEST['sco_codigo'] = $this->obj_comentario->geraCodigo(); daComentario::$ajax = ’T'; $result = $this->obj_comentario->Insert(); if(!$result){ $answer = array("result"=>"error","reason"=>"Parse error"); } echo json_encode($reply); }
– user53616
and in form_comentario.php : <input type="Hidden" name="sco_sch_codigo" id="sco_sch_codigo" value="<?= $chamado[0]['sch_codigo']?>">
– user53616