/ieducar/intranet/include/otopic/clsPessoaAuxiliarTelefone.inc.php

https://github.com/gtinfo/ieducar · PHP · 273 lines · 185 code · 20 blank · 68 comment · 16 complexity · 7c464113b36226976c157e61e4557e09 MD5 · raw file

  1. <?php
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. * *
  4. * @author Prefeitura Municipal de Itajaí *
  5. * @updated 29/03/2007 *
  6. * Pacote: i-PLB Software Público Livre e Brasileiro *
  7. * *
  8. * Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí *
  9. * ctima@itajai.sc.gov.br *
  10. * *
  11. * Este programa é software livre, você pode redistribuí-lo e/ou *
  12. * modificá-lo sob os termos da Licença Pública Geral GNU, conforme *
  13. * publicada pela Free Software Foundation, tanto a versão 2 da *
  14. * Licença como (a seu critério) qualquer versão mais nova. *
  15. * *
  16. * Este programa é distribuído na expectativa de ser útil, mas SEM *
  17. * QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI- *
  18. * ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con- *
  19. * sulte a Licença Pública Geral GNU para obter mais detalhes. *
  20. * *
  21. * Você deve ter recebido uma cópia da Licença Pública Geral GNU *
  22. * junto com este programa. Se não, escreva para a Free Software *
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *
  24. * 02111-1307, USA. *
  25. * *
  26. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  27. require_once ("include/clsBanco.inc.php");
  28. require_once ("include/otopic/otopicGeral.inc.php");
  29. class clsPessoaAuxiliarTelefone
  30. {
  31. var $ref_cod_pessoa_auxiliar;
  32. var $ddd;
  33. var $fone;
  34. var $campos_lista;
  35. var $todos_campos;
  36. var $tabela;
  37. /**
  38. * Construtor
  39. *
  40. * @return Object
  41. */
  42. function clsPessoaAuxiliarTelefone( $int_ref_cod_pessoa_auxiliar = null, $int_ddd = null, $int_fone = null)
  43. {
  44. if(is_numeric($int_ref_cod_pessoa_auxiliar))
  45. {
  46. $obj_pessoa_auxiliar = new clsPessoaAuxiliar($int_ref_cod_pessoa_auxiliar);
  47. if($obj_pessoa_auxiliar->detalhe())
  48. {
  49. $this->ref_cod_pessoa_auxiliar = $int_ref_cod_pessoa_auxiliar;
  50. }
  51. }
  52. if(is_numeric($int_ddd))
  53. {
  54. $this->ddd = $int_ddd;
  55. }
  56. if(is_numeric($int_fone))
  57. {
  58. $this->fone = $int_fone;
  59. }
  60. $this->campos_lista = $this->todos_campos = "ref_cod_pessoa_auxiliar, ddd, fone";
  61. $this->tabela = "pmiotopic.pessoa_auxiliar_telefone";
  62. }
  63. /**
  64. * Função que cadastra um novo registro com os valores atuais
  65. *
  66. * @return bool
  67. */
  68. function cadastra()
  69. {
  70. $campos = "";
  71. $valoes = "";
  72. if($this->ref_cod_pessoa_auxiliar && $this->ddd && $this->fone)
  73. {
  74. if(!$this->detalhe())
  75. {
  76. $campos = "ref_cod_pessoa_auxiliar, ddd, fone";
  77. $valoes = "'{$this->ref_cod_pessoa_auxiliar}', '{$this->ddd}', '{$this->fone}'";
  78. $db = new clsBanco();
  79. $db->Consulta("INSERT INTO {$this->tabela} ( $campos ) VALUES ( $valoes )");
  80. return true;
  81. }
  82. }
  83. return false;
  84. }
  85. /**
  86. * Edita o registro atual
  87. *
  88. * @return bool
  89. */
  90. function edita()
  91. {
  92. if($this->ref_cod_pessoa_auxiliar && $this->ddd && $this->fone)
  93. {
  94. $set = "ddd = '{$this->ddd}', fone = '{$this->fone}'";
  95. $db = new clsBanco();
  96. $db->Consulta( "UPDATE {$this->tabela} SET $set WHERE ref_cod_pessoa_auxiliar = '{$this->ref_cod_pessoa_auxiliar}' AND ddd = '{$this->ddd}' AND fone = '{$this->fone}'");
  97. return true;
  98. }
  99. return false;
  100. }
  101. /**
  102. * Remove todos os registros pertencentes a uma pessoa
  103. *
  104. * @return bool
  105. */
  106. function excluiTodos( )
  107. {
  108. // verifica se existe um ID definido para delecao
  109. if($this->ref_cod_pessoa_auxiliar)
  110. {
  111. $db = new clsBanco();
  112. $db->Consulta("DELETE FROM {$this->tabela} WHERE ref_cod_pessoa_auxiliar = '{$this->ref_cod_pessoa_auxiliar}'");
  113. return true;
  114. }
  115. return false;
  116. }
  117. /**
  118. * Remove o registro atual
  119. *
  120. * @return bool
  121. */
  122. function exclui( )
  123. {
  124. // verifica se existe um ID definido para delecao
  125. if($this->ref_cod_pessoa_auxiliar && $this->ddd && $this->fone)
  126. {
  127. $db = new clsBanco();
  128. $db->Consulta("DELETE FROM {$this->tabela} WHERE ref_cod_pessoa_auxiliar = '{$this->ref_cod_pessoa_auxiliar}' AND ddd = '{$this->ddd}' AND fone = '{$this->fone}'");
  129. return true;
  130. }
  131. return false;
  132. }
  133. /**
  134. * Indica quais os campos da tabela serão selecionados
  135. *
  136. * @return Array
  137. */
  138. function setcampos_lista($str_campos)
  139. {
  140. $this->campos_lista = $str_campos;
  141. }
  142. /**
  143. * Indica todos os campos da tabela para busca
  144. *
  145. * @return void
  146. */
  147. function resetcampos_lista()
  148. {
  149. $this->campos_lista = $this->todos_campos;
  150. }
  151. /**
  152. * Exibe uma lista baseada nos parametros de filtragem passados
  153. *
  154. * @return Array
  155. */
  156. function lista( $int_ref_cod_pessoa_auxiliar = false, $int_ddd = false, $int_fone = false, $int_limite_ini = false, $int_limite_qtd = false, $str_order_by = false )
  157. {
  158. // verificacoes de filtros a serem usados
  159. $where = "";
  160. $and = "";
  161. if(is_numeric($int_ref_cod_pessoa_auxiliar))
  162. {
  163. $where .= " $and ref_cod_pessoa_auxiliar = '$int_ref_cod_pessoa_auxiliar'";
  164. $and = " AND ";
  165. }
  166. elseif (is_string($int_ref_cod_pessoa_auxiliar))
  167. {
  168. $where .= " $and ref_cod_pessoa_auxiliar IN ({$int_ref_cod_pessoa_auxiliar})'";
  169. $and = " AND ";
  170. }
  171. if(is_numeric($int_ddd))
  172. {
  173. $where .= " $and ddd = '$int_ddd'";
  174. $and = " AND ";
  175. }
  176. if(is_numeric($int_fone))
  177. {
  178. $where .= " $and fone = '$int_fone'";
  179. $and = " AND ";
  180. }
  181. $orderBy = "";
  182. if( is_string( $str_order_by))
  183. {
  184. $orderBy = "ORDER BY $str_order_by";
  185. }
  186. if($where)
  187. {
  188. $where = " WHERE $where";
  189. }
  190. if($int_limite_ini !== false && $int_limite_qtd)
  191. {
  192. $limit = " LIMIT $int_limite_ini,$int_limite_qtd";
  193. }
  194. $db = new clsBanco();
  195. $total = $db->UnicoCampo( "SELECT COUNT(0) AS total FROM {$this->tabela} $where" );
  196. //echo "SELECT ".$this->campos_lista." FROM {$this->tabela} $where $orderBy $limit"; die();
  197. $db->Consulta( "SELECT ".$this->campos_lista." FROM {$this->tabela} $where $orderBy $limit" );
  198. $resultado = array();
  199. $countCampos = count( explode( ",", $this->campos_lista ) );
  200. while ( $db->ProximoRegistro() )
  201. {
  202. $tupla = $db->Tupla();
  203. if($countCampos > 1 )
  204. {
  205. $tupla["total"] = $total;
  206. $resultado[] = $tupla;
  207. }
  208. else
  209. {
  210. $resultado[] = $tupla["$this->campos_lista"];
  211. }
  212. }
  213. if( count( $resultado ) )
  214. {
  215. return $resultado;
  216. }
  217. return false;
  218. }
  219. /**
  220. * Retorna um array com os detalhes do objeto
  221. *
  222. * @return Array
  223. */
  224. function detalhe()
  225. {
  226. if($this->ref_cod_pessoa_auxiliar && $this->ddd && $this->fone)
  227. {
  228. $db = new clsBanco();
  229. $db->Consulta( "SELECT {$this->todos_campos} FROM {$this->tabela} WHERE ref_cod_pessoa_auxiliar = '{$this->ref_cod_pessoa_auxiliar}' AND ddd = '{$this->ddd}' AND fone = '{$this->fone}'" );
  230. if( $db->ProximoRegistro() )
  231. {
  232. $tupla = $db->Tupla();
  233. $this->ativo = $tupla['ativo'];
  234. return $tupla;
  235. }
  236. }
  237. return false;
  238. }
  239. }
  240. ?>