コード例 #1
0
 /**
  * Sobrescrita do método clsCadastro::Novo.
  *
  * Insere novo registro nas tabelas pmieducar.cliente e pmieducar.cliente_tipo_cliente.
  */
 public function Novo()
 {
     session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     $senha = md5($this->senha . 'asnk@#*&(23');
     $obj_permissoes = new clsPermissoes();
     $obj_permissoes->permissao_cadastra(603, $this->pessoa_logada, 11, 'educar_cliente_lst.php');
     $obj = new clsPmieducarCliente(NULL, NULL, NULL, $this->ref_idpes);
     $detalhe = $obj->detalhe();
     if (!$detalhe) {
         $obj_cliente = new clsPmieducarCliente();
         $lst_cliente = $obj_cliente->lista(NULL, NULL, NULL, NULL, $this->login);
         if ($lst_cliente && $this->login != '') {
             $this->mensagem = "Este login já está sendo utilizado por outra pessoa!<br>";
         } else {
             $obj = new clsPmieducarCliente($this->cod_cliente, NULL, $this->pessoa_logada, $this->ref_idpes, $this->login, $senha, $this->data_cadastro, $this->data_exclusao, 1);
             $cadastrou = $obj->cadastra();
             if ($cadastrou) {
                 $this->cod_cliente = $cadastrou;
                 $obj_cliente_tipo = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo, $this->cod_cliente, NULL, NULL, $this->pessoa_logada, $this->pessoa_logada, 1);
                 if ($obj_cliente_tipo->existeCliente()) {
                     if ($obj_cliente_tipo->trocaTipo()) {
                         $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
                         header('Location: educar_definir_cliente_tipo_lst.php');
                         die;
                     }
                 } else {
                     $obj_cliente_tipo = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo, $this->cod_cliente, NULL, NULL, $this->pessoa_logada, NULL, 1, $this->ref_cod_biblioteca);
                     if ($obj_cliente_tipo->cadastra()) {
                         $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
                         header('Location: educar_cliente_lst.php');
                         die;
                     }
                 }
             }
             $this->mensagem = "Cadastro n&atilde;o realizado.<br>";
             return FALSE;
         }
     } else {
         $obj = new clsPmieducarCliente(NULL, NULL, NULL, $this->ref_idpes);
         $registro = $obj->detalhe();
         if ($registro) {
             $this->cod_cliente = $registro['cod_cliente'];
         }
         $this->ativo = 1;
         $sql = "SELECT COUNT(0) FROM pmieducar.cliente_tipo_cliente WHERE ref_cod_cliente = {$this->cod_cliente}\n        AND ref_cod_biblioteca = {$this->ref_cod_biblioteca} AND ativo = 1";
         $db = new clsBanco();
         $possui_biblio = $db->CampoUnico($sql);
         if ($possui_biblio == 0) {
             $obj_cliente_tipo_cliente = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo, $this->cod_cliente, NULL, NULL, $this->pessoa_logada, NULL, NULL, $this->ref_cod_biblioteca);
             if (!$obj_cliente_tipo_cliente->cadastra()) {
                 $this->mensagem = "Não cadastrou";
                 return FALSE;
             } else {
                 header('Location: educar_cliente_lst.php');
                 return TRUE;
                 die;
             }
         } else {
             $this->mensagem = "O cliente já está cadastrado!<br>";
         }
     }
 }