function Novo()
 {
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     $this->ref_cod_cliente = $_SESSION['emprestimo']['cod_cliente'];
     @session_write_close();
     $obj_permissoes = new clsPermissoes();
     $obj_permissoes->permissao_cadastra(610, $this->pessoa_logada, 11, "educar_exemplar_emprestimo_lst.php");
     $this->exemplar_emprestimo = unserialize(urldecode($this->exemplar_emprestimo));
     if ($this->exemplar_emprestimo) {
         $this->exemplar_emprestimo = $this->exemplar_emprestimo['ref_cod_exemplar_'];
         foreach ($this->exemplar_emprestimo as $campo) {
             $obj = new clsPmieducarExemplarEmprestimo(null, null, $this->pessoa_logada, $this->ref_cod_cliente, $campo);
             $cadastrou = $obj->cadastra();
             if ($cadastrou) {
                 $obj_situacao = new clsPmieducarSituacao();
                 $lst_situacao = $obj_situacao->lista(null, null, null, null, 1, null, 0, 1, null, null, null, null, 1, $this->ref_cod_biblioteca);
                 if (is_array($lst_situacao) && count($lst_situacao)) {
                     $det_situacao = array_shift($lst_situacao);
                     $cod_situacao = $det_situacao["cod_situacao"];
                     $obj = new clsPmieducarExemplar($campo, null, null, null, $cod_situacao, $this->pessoa_logada, null, null, null, null, null, 1);
                     $editou = $obj->edita();
                     if (!$editou) {
                         $this->mensagem = "Cadastro n&atilde;o realizado.<br>";
                         echo "<!--\nErro ao cadastrar clsPmieducarSituacao\nvalores obrigatorios\nis_numeric( {$this->pessoa_logada} ) && is_numeric( {$campo} ) && is_numeric( {$cod_situacao} )\n-->";
                         return false;
                     }
                 } else {
                     echo "<script> alert('ERRO - Não foi possível encontrar a situação EMPRESTADO da biblioteca utilizada!'); </script>";
                 }
             } else {
                 $this->mensagem = "Cadastro n&atilde;o realizado.<br>";
                 echo "<!--\nErro ao cadastrar clsPmieducarExemplarEmprestimo\nvalores obrigatorios\nis_numeric( {$this->pessoa_logada} ) && is_numeric( {$this->ref_cod_cliente} )\n-->";
                 return false;
             }
         }
         $this->mensagem .= "Cadastro efetuado com sucesso.<br>";
         header("Location: educar_exemplar_emprestimo_lst.php");
         die;
         return true;
     }
     echo "<script> alert('É necessário adicionar pelo menos 1 Tombo!') </script>";
     $this->mensagem = "Cadastro n&atilde;o realizado.<br>";
     return false;
 }
 protected function postEmprestimo()
 {
     if ($this->canPostEmprestimo()) {
         // altera situacao exemplar para emprestado
         $situacaoEmprestimo = $this->loadSituacaoExemplar($permiteEmprestimo = false, $padrao = null, $emprestada = true);
         if ($situacaoEmprestimo && !$this->updateSituacaoExemplar($situacaoEmprestimo)) {
             $this->messenger->append("Aparentemente a situação do exemplar não foi alterada para emprestado.", 'error');
         } elseif (!$situacaoEmprestimo) {
             $this->messenger->append("Não foi encontrado uma situação cadastrada para emprestimo.", 'error');
         }
         // grava emprestimo
         if (!$this->messenger->hasMsgWithType('error')) {
             $emprestimo = new clsPmieducarExemplarEmprestimo();
             $emprestimo->ref_usuario_cad = $this->getSession()->id_pessoa;
             $emprestimo->ref_cod_cliente = $this->getRequest()->cliente_id;
             $emprestimo->ref_cod_exemplar = $this->getRequest()->exemplar_id;
             if ($emprestimo->cadastra()) {
                 $this->messenger->append("Emprestimo realizado com sucesso.", 'success');
             } else {
                 $this->messenger->append("Aparentemente o realizado não foi cadastrado, por favor, tente novamente.", 'error');
             }
         }
     }
     $this->appendResponse('exemplar', $this->loadExemplar($reload = true));
 }