Commit 1d5a441b7f63f53d507edf764e54acfc7d337abd

Authored by Eriksen Costa Paixão
1 parent eb755d0a
Exists in master

Refactoring para coding standards

ieducar/intranet/educar_servidor_alocacao_cad.php
1 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   - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2 +
27 3 /**
28   - * @author Adriano Erik Weiguert Nagasava
29   - * Haissam Yebahi
  4 + * i-Educar - Sistema de gestão escolar
  5 + *
  6 + * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  7 + * <ctima@itajai.sc.gov.br>
  8 + *
  9 + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  10 + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  11 + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  12 + * qualquer versão posterior.
  13 + *
  14 + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  15 + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  16 + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  17 + * do GNU para mais detalhes.
  18 + *
  19 + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  20 + * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  21 + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  22 + *
  23 + * @author Adriano Erik Weiguert Nagasava <ctima@itajai.sc.gov.br>
  24 + * @author Haissam Yebahi <ctima@itajai.sc.gov.br>
  25 + * @category i-Educar
  26 + * @license @@license@@
  27 + * @package iEd_Pmieducar
  28 + * @since Arquivo disponível desde a versão 1.0.0
  29 + * @version $Id$
30 30 */
31 31  
32   -require_once ("include/clsBase.inc.php");
33   -require_once ("include/clsCadastro.inc.php");
34   -require_once ("include/clsBanco.inc.php");
35   -require_once( "include/pmieducar/geral.inc.php" );
  32 +require_once 'include/clsBase.inc.php';
  33 +require_once 'include/clsCadastro.inc.php';
  34 +require_once 'include/clsBanco.inc.php';
  35 +require_once 'include/pmieducar/geral.inc.php';
36 36  
  37 +/**
  38 + * clsIndexBase class.
  39 + *
  40 + * @author Adriano Erik Weiguert Nagasava <ctima@itajai.sc.gov.br>
  41 + * @author Haissam Yebahi <ctima@itajai.sc.gov.br>
  42 + * @category i-Educar
  43 + * @license @@license@@
  44 + * @package iEd_Pmieducar
  45 + * @since Classe disponível desde a versão 1.0.0
  46 + * @version @@package_version@@
  47 + */
37 48 class clsIndexBase extends clsBase
38 49 {
39   - function Formular()
40   - {
41   - $this->SetTitulo( "{$this->_instituicao} i-Educar - Servidor Alocação" );
42   - $this->processoAp = "635";
43   - }
  50 + function Formular()
  51 + {
  52 + $this->SetTitulo($this->_instituicao . ' i-Educar - Servidor Alocação');
  53 + $this->processoAp = 635;
  54 + }
44 55 }
45 56  
  57 +/**
  58 + * indice class.
  59 + *
  60 + * @author Adriano Erik Weiguert Nagasava <ctima@itajai.sc.gov.br>
  61 + * @author Haissam Yebahi <ctima@itajai.sc.gov.br>
  62 + * @category i-Educar
  63 + * @license @@license@@
  64 + * @package iEd_Pmieducar
  65 + * @since Classe disponível desde a versão 1.0.0
  66 + * @version @@package_version@@
  67 + */
46 68 class indice extends clsCadastro
47 69 {
48   - /**
49   - * Referencia pega da session para o idpes do usuario atual
50   - *
51   - * @var int
52   - */
53   - var $pessoa_logada;
54   - var $cod_servidor_alocacao;
55   - var $ref_ref_cod_instituicao;
56   - var $ref_usuario_exc;
57   - var $ref_usuario_cad;
58   - var $ref_cod_escola;
59   - var $ref_cod_servidor;
60   - var $data_cadastro;
61   - var $data_exclusao;
62   - var $ativo;
63   - var $carga_horaria_alocada;
64   - var $carga_horaria_disponivel;
65   - var $periodo;
66   -
67   - var $alocacao_array = array();
68   - var $alocacao_excluida_array = array();
69   -
70   - function Inicializar()
71   - {
72   - $retorno = "Novo";
73   - @session_start();
74   - $this->pessoa_logada = $_SESSION['id_pessoa'];
75   - @session_write_close();
76   -
77   - $this->ref_cod_servidor = $_GET["ref_cod_servidor"];
78   - $this->ref_ref_cod_instituicao = $_GET["ref_cod_instituicao"];
79   -
80   - $obj_permissoes = new clsPermissoes();
81   - $obj_permissoes->permissao_cadastra( 635, $this->pessoa_logada, 3, "educar_servidor_alocacao_lst.php" );
82   -
83   - if ( is_numeric( $this->ref_cod_servidor ) && is_numeric( $this->ref_ref_cod_instituicao ) )
84   - {
85   -
86   - $obj = new clsPmieducarServidorAlocacao( );
87   - $lista = $obj->lista( null, $this->ref_ref_cod_instituicao, null, null, null, $this->ref_cod_servidor, null, null, null, null, 1, null, null );
88   -
89   - if ( $lista )
90   - {
91   - foreach ( $lista AS $campo => $val )
92   - {
93   - $temp = array();
94   - $temp['carga_horaria_alocada'] = $val['carga_horaria'];
95   - $temp['periodo'] = $val['periodo'];
96   - $temp['ref_cod_escola'] = $val['ref_cod_escola'];
97   - $temp['novo'] = 0;
98   -
99   - $this->alocacao_array[] = $temp;
100   - }
101   - $retorno = "Novo";
102   - }
103   -
104   - $obj_servidor = new clsPmieducarServidor( $this->ref_cod_servidor, null, null, null, null, null, 1, $this->ref_ref_cod_instituicao );
105   - $det_servidor = $obj_servidor->detalhe();
106   - $this->carga_horaria_disponivel = $det_servidor['carga_horaria'];
107   - }
108   - else
109   - {
110   - header( "location: educar_servidor_lst.php" );
111   - die;
112   - }
113   -
114   - $this->url_cancelar = "educar_servidor_det.php?cod_servidor={$this->ref_cod_servidor}&ref_cod_instituicao={$this->ref_ref_cod_instituicao}";
115   - $this->nome_url_cancelar = "Cancelar";
116   - return $retorno;
117   - }
118   -
119   - function Gerar()
120   - {
121   - if ( $_POST )
122   - {
123   - foreach ( $_POST AS $campo => $val )
124   - {
125   - if ( is_string( $val ) )
126   - {
127   - $val = urldecode( $val );
128   - }
129   - $this->$campo = ( $this->$campo ) ? $this->$campo : $val;
130   - }
131   - }
132   -
133   - $obj_inst = new clsPmieducarInstituicao( $this->ref_ref_cod_instituicao );
134   - $inst_det = $obj_inst->detalhe();
135   -
136   - $this->campoRotulo( "nm_instituicao", "Institui&ccedil;&atilde;o", $inst_det['nm_instituicao'] );
137   - $this->campoOculto( "ref_ref_cod_instituicao", $this->ref_ref_cod_instituicao );
138   -
139   - if ( class_exists( "clsPmieducarServidor" ) )
140   - {
141   - $objTemp = new clsPmieducarServidor( $this->ref_cod_servidor );
142   - $det = $objTemp->detalhe();
143   - if ( $det )
144   - {
145   - foreach ( $det as $key => $registro )
146   - {
147   - $this->$key = $registro;
148   - }
149   - }
150   -
151   - if ( $this->ref_cod_servidor )
152   - {
153   - $objTemp = new clsFuncionario( $this->ref_cod_servidor );
154   - $detalhe = $objTemp->detalhe();
155   - $detalhe = $detalhe["idpes"]->detalhe();
156   - $nm_servidor = $detalhe["nome"];
157   - }
158   - }
159   - else
160   - {
161   - echo "<!--\nErro\nClasse clsPmieducarServidor nao encontrada\n-->";
162   - $opcoes = array( "" => "Erro na geracao" );
163   - }
164   -
165   - $this->campoRotulo( "nm_servidor", "Servidor", $nm_servidor );
166   -
167   - $this->campoOculto( "ref_cod_servidor", $this->ref_cod_servidor );
168   -
169   - if ( $_POST["alocacao_array"] )
170   - {
171   - $this->alocacao_array = unserialize( urldecode( $_POST["alocacao_array"] ) );
172   - }
173   -
174   - if ( $_POST["alocacao_excluida_array"] )
175   - {
176   - $this->alocacao_excluida_array = unserialize( urldecode( $_POST["alocacao_excluida_array"] ) );
177   - }
178   -
179   - if ( $_POST["carga_horaria_alocada"] && $_POST["periodo"] )
180   - {
181   - $aux = array();
182   - $aux["carga_horaria_alocada"] = $_POST["carga_horaria_alocada"];
183   - $aux["periodo"] = $_POST["periodo"];
184   - $aux["ref_cod_escola"] = $_POST["ref_cod_escola"];
185   - $aux['novo'] = 1;
186   - /*$achou = false;
187   -
188   - foreach ( $this->alocacao_array as $alocacao )
189   - {
190   - if ( $alocacao['periodo'] == $aux["periodo"] )
191   - {
192   - $achou = true;
193   - echo "<script>alert('Horário já utilizado!\\nPeriodo: {$this->periodo[$aux["periodo"]]}\\n');</script>";
194   - }
195   - }
196   -
197   - if ( !$achou )
198   - {
199   - $this->alocacao_array[] = $aux;
200   - }
201   - */
202   - $this->alocacao_array[] = $aux;
203   -
204   - unset( $this->periodo );
205   - unset( $this->carga_horaria_alocada );
206   - unset( $this->ref_cod_escola );
207   - }
208   -
209   - /**
210   - * Exclusão
211   - */
212   - if ( $this->alocacao_array )
213   - {
214   - foreach ( $this->alocacao_array as $key => $alocacao )
215   - {
216   - if ( is_numeric( $_POST['excluir_periodo'] ) )
217   - {
218   - if ( $_POST['excluir_periodo'] == $key )
219   - {
220   - $this->alocacao_excluida_array[] = $alocacao;
221   - unset( $this->alocacao_array[$key] );
222   - unset( $this->excluir_periodo );
223   - }
224   - }
225   - }
226   - }
227   -
228   - /**
229   - * Carga Horaria
230   - */
231   - $total_horas = sprintf( "%02d", ( int ) ( floor( $this->carga_horaria_disponivel ) ) );
232   - $total_horas = sprintf( "%02d", ( int ) ( floor( $this->carga_horaria_disponivel ) ) );
233   - $total_minutos = sprintf( "%02d", ( int ) ( ( floatval( $this->carga_horaria_disponivel ) - floatval( $total_horas ) ) * 60 ) );
234   -
235   - $horas_utilizadas = 0;
236   - $minutos_utilizados = 0;
237   -
238   - if ( $this->alocacao_array )
239   - {
240   - foreach ( $this->alocacao_array as $alocacao )
241   - {
242   - $carga_horaria_ = explode( ":", $alocacao['carga_horaria_alocada'] );
243   -
244   - $horas_utilizadas += ( $carga_horaria_[0] );
245   - $minutos_utilizados += ( $carga_horaria_[1] );
246   - }
247   - }
248   -
249   - $horas = sprintf( "%02d", ( int ) $horas_utilizadas );
250   - $minutos = sprintf( "%02d", ( int ) $minutos_utilizados );
251   - $str_horas_utilizadas = "{$horas}:{$minutos}";
252   -
253   - $this->campoRotulo( "carga_horaria_disponivel", "Carga Hor&aacute;ria", "{$total_horas}:{$total_minutos}" );
254   - $this->campoRotulo( "horas_utilizadas", "Horas Utilizadas", $str_horas_utilizadas );
255   -
256   - $horas = sprintf( "%02d", ( int ) $total_horas - $horas_utilizadas );
257   - $minutos = sprintf( "%02d", ( int ) $total_minutos - $minutos_utilizados );
258   - $str_horas_restantes = "{$horas}:{$minutos}";
259   -
260   - $this->campoRotulo( "horas_restantes", "Horas Restantes", $str_horas_restantes );
261   - $this->campoOculto( "horas_restantes_", $str_horas_restantes );
262   -
263   - $this->campoQuebra();
264   -
265   - $this->campoOculto( "excluir_periodo", "" );
266   - unset( $aux );
267   -
268   -// array_multisort( $this->alocacao_array );
269   -
270   - if ( class_exists( "clsPmieducarEscola" ) )
271   - {
272   - $obj_escola = new clsPmieducarEscola();
273   - $lista_escola = $obj_escola->lista( null, null, null, $this->ref_ref_cod_instituicao, null, null, null, null, null, null, 1 );
274   -
275   - if ( $lista_escola )
276   - {
277   - $opcoes = array( '' => "Selecione" );
278   - foreach ( $lista_escola as $escola )
279   - {
280   - $opcoes[$escola['cod_escola']] = $escola['nome'];
281   - }
282   - }
283   - }
284   - else
285   - {
286   - $registro["ref_cod_escola"] = "Erro na geracao";
287   - echo "<!--\nErro\nClasse nao existente: clsPmieducarEscola\n-->";
288   - }
289   -
290   - $this->campoLista( "ref_cod_escola", "Escola", $opcoes, $this->ref_cod_escola, "", false, "", "", false, false );
291   - $this->campoLista( "periodo", "Período", array( "" => "Selecione", "1" => "Matutino", "2" => "Vespertino", "3" => "Noturno" ), $this->periodo, null, false, "", "", false, false );
292   - $this->campoHora( "carga_horaria_alocada", "Carga Horária", $this->carga_horaria_alocada, false );
293   - $this->campoOculto( "alocacao_array", serialize( $this->alocacao_array ) );
294   - $this->campoOculto( "alocacao_excluida_array", serialize( $this->alocacao_excluida_array ) );
295   - $this->campoRotulo( "bt_incluir_periodo", "Período", "<a href='#' onclick=\"if(validaHora()){document.getElementById('incluir_periodo').value = 'S'; document.getElementById('tipoacao').value = ''; document.{$this->__nome}.submit();}\"><img src='imagens/nvp_bot_adiciona.gif' title='Incluir' border=0></a>" );
296   -
297   - if ( $this->alocacao_array )
298   - {
299   - $excluir_ok = false;
300   -
301   - if ( $_POST['excluir_periodo'] || $_POST['excluir_periodo'] == "0" )
302   - {
303   - $excluir_ok = true;
304   - }
305   -
306   - foreach ( $this->alocacao_array as $key => $alocacao )
307   - {
308   - $obj_permissoes = new clsPermissoes();
309   - $link_excluir = "";
310   -
311   - if ( $obj_permissoes->permissao_excluir( 635, $this->pessoa_logada, 3 ) )
312   - {
313   - $link_excluir = "<a href='#' onclick=\"getElementById( 'excluir_periodo' ).value = '{$key}'; getElementById( 'tipoacao' ).value = ''; {$this->__nome}.submit();\"><img src='imagens/nvp_bola_xis.gif' title='Excluir' border=0></a>";
314   - }
315   -
316   - $obj_escola = new clsPmieducarEscola( $alocacao['ref_cod_escola'] );
317   - $det_escola = $obj_escola->detalhe();
318   - $det_escola = $det_escola["nome"];
319   -
320   - switch( $alocacao["periodo"] )
321   - {
322   - case 1:
323   - $nm_periodo = "Matutino";
324   - break;
325   - case 2:
326   - $nm_periodo = "Vespertino";
327   - break;
328   - case 3:
329   - $nm_periodo = "Noturno";
330   - break;
331   - }
332   -
333   - $this->campoTextoInv( "periodo_{$key}", "", $nm_periodo, 10, 10, false, false, true, "", "", "", "", "periodo" );
334   - $this->campoTextoInv( "carga_horaria_alocada_{$key}", "", $alocacao['carga_horaria_alocada'], 5, 5, false, false, true, "", "", "", "", "ds_carga_horaria_" );
335   - $this->campoTextoInv( "ref_cod_escola_{$key}", "", $det_escola, 30, 255, false, false, false, "", "{$link_excluir}", "", "", "ref_cod_escola_" );
336   - }
337   - }
338   - $this->campoOculto( "incluir_periodo", "" );
339   - $this->campoQuebra();
340   - }
341   -
342   - function Novo()
343   - {
344   - @session_start();
345   - $this->pessoa_logada = $_SESSION['id_pessoa'];
346   - @session_write_close();
347   -
348   - $obj_permissoes = new clsPermissoes();
349   - $obj_permissoes->permissao_cadastra( 635, $this->pessoa_logada, 3, "educar_servidor_alocacao_lst.php" );
350   -
351   - if ( $_POST["alocacao_array"] )
352   - {
353   - $this->alocacao_array = unserialize( urldecode( $_POST["alocacao_array"] ) );
354   - }
355   -
356   - if ( $_POST["alocacao_excluida_array"] )
357   - {
358   - $this->alocacao_excluida_array = unserialize( urldecode( $_POST["alocacao_excluida_array"] ) );
359   - }
360   -
361   - if ( $this->alocacao_excluida_array )
362   - {
363   - foreach ( $this->alocacao_excluida_array as $excluida )
364   - {
365   - $obj = new clsPmieducarServidorAlocacao( null, $this->ref_ref_cod_instituicao, $this->pessoa_logada, $this->pessoa_logada, $excluida['ref_cod_escola'], $this->ref_cod_servidor, null, null, $this->ativo, $excluida['carga_horaria_alocada'], $excluida['periodo'] );
366   - $cadastrou = $obj->excluir_horario();
367   - }
368   - }
369   -
370   - if ( $_POST["carga_horaria_alocada"] && $_POST["periodo"] )
371   - {
372   -
373   - $aux = array();
374   - $aux["periodo"] = $_POST["periodo"];
375   - $aux["carga_horaria_alocada"] = $_POST["carga_horaria_alocada"];
376   - $aux["ref_cod_escola"] = $_POST["ref_cod_escola"];
377   - $aux["novo"] = 1;
378   - $achou = false;
379   -
380   - foreach ( $this->alocacao_array as $alocacao )
381   - {
382   - if ( $alocacao['periodo'] == $aux["periodo"] )
383   - {
384   - $achou = true;
385   - }
386   - }
387   - if ( !$achou )
388   - {
389   - $this->alocacao_array[] = $aux;
390   - }
391   - unset( $this->periodo );
392   - unset( $this->carga_horaria_alocada );
393   - }
394   -
395   - if ( $this->alocacao_array )
396   - {
397   - foreach ( $this->alocacao_array as $alocacao )
398   - {
399   - if ( $alocacao['novo'] )
400   - {
401   - $obj = new clsPmieducarServidorAlocacao( null, $this->ref_ref_cod_instituicao, null, $this->pessoa_logada, $alocacao['ref_cod_escola'], $this->ref_cod_servidor, null, null, $this->ativo, $alocacao['carga_horaria_alocada'], $alocacao['periodo'] );
402   - $cadastrou = $obj->cadastra();
403   -
404   - if ( !$cadastrou )
405   - {
406   - $this->mensagem = "Cadastro n&atilde;o realizado.<br>";
407   - echo "<!--\nErro ao cadastrar clsPmieducarServidorAlocacao\nvalores obrigatorios\nis_numeric( $this->ref_ref_cod_instituicao ) && is_numeric( $this->ref_usuario_cad ) && is_numeric( $this->ref_cod_escola ) && is_numeric( $this->ref_cod_servidor ) && is_numeric( $this->periodo ) && ( $this->carga_horaria_alocada )\n-->";
408   - return false;
409   - }
410   - }
411   - }
412   - }
413   -
414   - $this->mensagem .= "Cadastro efetuado com sucesso.<br>";
415   - header( "Location: educar_servidor_det.php?cod_servidor={$this->ref_cod_servidor}&ref_cod_instituicao={$this->ref_ref_cod_instituicao} ");
416   - die();
417   - return true;
418   - }
419   -
420   - function Editar()
421   - {
422   - return false;
423   - }
424   -
425   - function Excluir()
426   - {
427   - return false;
428   -
429   - }
  70 + var $pessoa_logada;
  71 + var $cod_servidor_alocacao;
  72 + var $ref_ref_cod_instituicao;
  73 + var $ref_usuario_exc;
  74 + var $ref_usuario_cad;
  75 + var $ref_cod_escola;
  76 + var $ref_cod_servidor;
  77 + var $data_cadastro;
  78 + var $data_exclusao;
  79 + var $ativo;
  80 + var $carga_horaria_alocada;
  81 + var $carga_horaria_disponivel;
  82 + var $periodo;
  83 +
  84 + var $alocacao_array = array();
  85 + var $alocacao_excluida_array = array();
  86 +
  87 + function Inicializar()
  88 + {
  89 + $retorno = 'Novo';
  90 + @session_start();
  91 + $this->pessoa_logada = $_SESSION['id_pessoa'];
  92 + @session_write_close();
  93 +
  94 + $this->ref_cod_servidor = $_GET['ref_cod_servidor'];
  95 + $this->ref_ref_cod_instituicao = $_GET['ref_cod_instituicao'];
  96 +
  97 + $obj_permissoes = new clsPermissoes();
  98 + $obj_permissoes->permissao_cadastra(635, $this->pessoa_logada, 3,
  99 + 'educar_servidor_alocacao_lst.php');
  100 +
  101 + if (is_numeric($this->ref_cod_servidor) && is_numeric($this->ref_ref_cod_instituicao)) {
  102 + $obj = new clsPmieducarServidorAlocacao();
  103 + $lista = $obj->lista(NULL, $this->ref_ref_cod_instituicao, NULL, NULL,
  104 + NULL, $this->ref_cod_servidor, NULL, NULL, NULL, NULL, 1, NULL, NULL);
  105 +
  106 + if ($lista) {
  107 + foreach ($lista as $campo => $val) {
  108 + $temp = array();
  109 + $temp['carga_horaria_alocada'] = $val['carga_horaria'];
  110 + $temp['periodo'] = $val['periodo'];
  111 + $temp['ref_cod_escola'] = $val['ref_cod_escola'];
  112 + $temp['novo'] = 0;
  113 +
  114 + $this->alocacao_array[] = $temp;
  115 + }
  116 +
  117 + $retorno = 'Novo';
  118 + }
  119 +
  120 + $obj_servidor = new clsPmieducarServidor($this->ref_cod_servidor, NULL,
  121 + NULL, NULL, NULL, NULL, 1, $this->ref_ref_cod_instituicao);
  122 + $det_servidor = $obj_servidor->detalhe();
  123 +
  124 + $this->carga_horaria_disponivel = $det_servidor['carga_horaria'];
  125 + }
  126 + else {
  127 + header('Location: educar_servidor_lst.php');
  128 + die();
  129 + }
  130 +
  131 + $this->url_cancelar = sprintf(
  132 + 'educar_servidor_det.php?cod_servidor=%d&ref_cod_instituicao=%d',
  133 + $this->ref_cod_servidor, $this->ref_ref_cod_instituicao
  134 + );
  135 + $this->nome_url_cancelar = 'Cancelar';
  136 + return $retorno;
  137 + }
  138 +
  139 + function Gerar()
  140 + {
  141 + if ($_POST) {
  142 + foreach ($_POST as $campo => $val) {
  143 + if (is_string($val)) {
  144 + $val = urldecode($val);
  145 + }
  146 +
  147 + $this->$campo = ($this->$campo) ? $this->$campo : $val;
  148 + }
  149 + }
  150 +
  151 + $obj_inst = new clsPmieducarInstituicao($this->ref_ref_cod_instituicao);
  152 + $inst_det = $obj_inst->detalhe();
  153 +
  154 + $this->campoRotulo('nm_instituicao', 'Instituição', $inst_det['nm_instituicao']);
  155 + $this->campoOculto('ref_ref_cod_instituicao', $this->ref_ref_cod_instituicao);
  156 +
  157 + if (class_exists('clsPmieducarServidor')) {
  158 + $objTemp = new clsPmieducarServidor($this->ref_cod_servidor);
  159 + $det = $objTemp->detalhe();
  160 +
  161 + if ($det) {
  162 + foreach ($det as $key => $registro) {
  163 + $this->$key = $registro;
  164 + }
  165 + }
  166 +
  167 + if ($this->ref_cod_servidor) {
  168 + $objTemp = new clsFuncionario($this->ref_cod_servidor);
  169 + $detalhe = $objTemp->detalhe();
  170 + $detalhe = $detalhe['idpes']->detalhe();
  171 + $nm_servidor = $detalhe['nome'];
  172 + }
  173 + }
  174 + else {
  175 + echo '<!--\nErro\nClasse clsPmieducarServidor não encontrada\n-->';
  176 + $opcoes = array('' => 'Erro na geração');
  177 + }
  178 +
  179 + $this->campoRotulo('nm_servidor', 'Servidor', $nm_servidor);
  180 +
  181 + $this->campoOculto('ref_cod_servidor', $this->ref_cod_servidor);
  182 +
  183 + if ($_POST['alocacao_array']) {
  184 + $this->alocacao_array = unserialize(urldecode($_POST['alocacao_array']));
  185 + }
  186 +
  187 + if ($_POST['alocacao_excluida_array']) {
  188 + $this->alocacao_excluida_array = unserialize(urldecode($_POST['alocacao_excluida_array']));
  189 + }
  190 +
  191 + if ($_POST['carga_horaria_alocada'] && $_POST['periodo']) {
  192 + $aux = array();
  193 + $aux['carga_horaria_alocada'] = $_POST['carga_horaria_alocada'];
  194 + $aux['periodo'] = $_POST['periodo'];
  195 + $aux['ref_cod_escola'] = $_POST['ref_cod_escola'];
  196 + $aux['novo'] = 1;
  197 +
  198 + $this->alocacao_array[] = $aux;
  199 +
  200 + unset($this->periodo);
  201 + unset($this->carga_horaria_alocada);
  202 + unset($this->ref_cod_escola);
  203 + }
  204 +
  205 + /**
  206 + * Exclusão
  207 + */
  208 + if ($this->alocacao_array) {
  209 + foreach ($this->alocacao_array as $key => $alocacao) {
  210 + if (is_numeric($_POST['excluir_periodo'])) {
  211 + if ($_POST['excluir_periodo'] == $key) {
  212 + $this->alocacao_excluida_array[] = $alocacao;
  213 + unset($this->alocacao_array[$key]);
  214 + unset($this->excluir_periodo);
  215 + }
  216 + }
  217 + }
  218 + }
  219 +
  220 + /**
  221 + * Carga Horária
  222 + */
  223 + $total_horas = sprintf('%02d', (int) (floor($this->carga_horaria_disponivel)));
  224 + $total_horas = sprintf('%02d', (int) (floor($this->carga_horaria_disponivel)));
  225 + $total_minutos = sprintf('%02d', (int) ((floatval($this->carga_horaria_disponivel) - floatval($total_horas)) * 60));
  226 +
  227 + $horas_utilizadas = 0;
  228 + $minutos_utilizados = 0;
  229 +
  230 + if ($this->alocacao_array) {
  231 + foreach ($this->alocacao_array as $alocacao) {
  232 + $carga_horaria_ = explode(':', $alocacao['carga_horaria_alocada']);
  233 +
  234 + $horas_utilizadas += ($carga_horaria_[0]);
  235 + $minutos_utilizados += ($carga_horaria_[1]);
  236 + }
  237 + }
  238 +
  239 + $horas = sprintf('%02d', (int) $horas_utilizadas);
  240 + $minutos = sprintf('%02d', (int) $minutos_utilizados);
  241 + $str_horas_utilizadas = sprintf('%s:%s', $horas, $minutos);
  242 +
  243 + $this->campoRotulo('carga_horaria_disponivel', 'Carga Horária',
  244 + sprintf('%s:%s', $total_horas, $total_minutos));
  245 +
  246 + $this->campoRotulo('horas_utilizadas', 'Horas Utilizadas', $str_horas_utilizadas);
  247 +
  248 + $horas = sprintf('%02d', (int) $total_horas - $horas_utilizadas);
  249 + $minutos = sprintf('%02d', (int) $total_minutos - $minutos_utilizados);
  250 + $str_horas_restantes = sprintf('%s:%s', $horas, $minutos);
  251 +
  252 + $this->campoRotulo('horas_restantes', 'Horas Restantes', $str_horas_restantes);
  253 + $this->campoOculto('horas_restantes_', $str_horas_restantes);
  254 +
  255 + $this->campoQuebra();
  256 +
  257 + $this->campoOculto('excluir_periodo', '');
  258 + unset($aux);
  259 +
  260 + if (class_exists('clsPmieducarEscola')) {
  261 + $obj_escola = new clsPmieducarEscola();
  262 + $lista_escola = $obj_escola->lista(null, null, null,
  263 + $this->ref_ref_cod_instituicao, null, null, null, null, null, null, 1);
  264 +
  265 + if ($lista_escola) {
  266 + $opcoes = array('' => 'Selecione');
  267 + foreach ($lista_escola as $escola) {
  268 + $opcoes[$escola['cod_escola']] = $escola['nome'];
  269 + }
  270 + }
  271 + }
  272 + else {
  273 + $registro['ref_cod_escola'] = 'Erro na geração';
  274 + echo "<!--\nErro\nClasse não existente: clsPmieducarEscola\n-->";
  275 + }
  276 +
  277 + $periodo = array(
  278 + '' => 'Selecione',
  279 + 1 => 'Matutino',
  280 + 2 => 'Vespertino',
  281 + 3 => 'Noturno'
  282 + );
  283 +
  284 + $this->campoLista('ref_cod_escola', 'Escola', $opcoes, $this->ref_cod_escola,
  285 + '', FALSE, '', '', FALSE, FALSE);
  286 +
  287 + $this->campoLista('periodo', 'Período', $periodo, $this->periodo, NULL, FALSE,
  288 + '', '', FALSE, FALSE);
  289 +
  290 + $this->campoHora('carga_horaria_alocada', 'Carga Horária',
  291 + $this->carga_horaria_alocada, FALSE);
  292 +
  293 + $this->campoOculto('alocacao_array', serialize($this->alocacao_array));
  294 +
  295 + $this->campoOculto('alocacao_excluida_array', serialize($this->alocacao_excluida_array));
  296 +
  297 + $this->campoRotulo('bt_incluir_periodo', 'Período', "<a href='#' onclick=\"if(validaHora()) { document.getElementById('incluir_periodo').value = 'S'; document.getElementById('tipoacao').value = ''; document.{$this->__nome}.submit();}\"><img src='imagens/nvp_bot_adiciona.gif' title='Incluir' border=0></a>");
  298 +
  299 + if ($this->alocacao_array) {
  300 + $excluir_ok = FALSE;
  301 +
  302 + if ($_POST['excluir_periodo'] || $_POST['excluir_periodo'] == '0') {
  303 + $excluir_ok = TRUE;
  304 + }
  305 +
  306 + foreach ($this->alocacao_array as $key => $alocacao) {
  307 + $obj_permissoes = new clsPermissoes();
  308 + $link_excluir = '';
  309 +
  310 + if ($obj_permissoes->permissao_excluir(635, $this->pessoa_logada, 3)) {
  311 + $link_excluir = "<a href='#' onclick=\"getElementById('excluir_periodo').value = '{$key}'; getElementById( 'tipoacao' ).value = ''; {$this->__nome}.submit();\"><img src='imagens/nvp_bola_xis.gif' title='Excluir' border=0></a>";
  312 + }
  313 +
  314 + $obj_escola = new clsPmieducarEscola( $alocacao['ref_cod_escola'] );
  315 + $det_escola = $obj_escola->detalhe();
  316 + $det_escola = $det_escola['nome'];
  317 +
  318 + // @todo CoreExt_Enum
  319 + switch ($alocacao['periodo']) {
  320 + case 1:
  321 + $nm_periodo = 'Matutino';
  322 + break;
  323 + case 2:
  324 + $nm_periodo = 'Vespertino';
  325 + break;
  326 + case 3:
  327 + $nm_periodo = 'Noturno';
  328 + break;
  329 + }
  330 +
  331 + $this->campoTextoInv('periodo_' . $key, '', $nm_periodo, 10, 10, FALSE,
  332 + FALSE, TRUE, '', '', '', '', 'periodo');
  333 +
  334 + $this->campoTextoInv('carga_horaria_alocada_' . $key, '',
  335 + $alocacao['carga_horaria_alocada'], 5, 5, FALSE, FALSE, TRUE, '', '',
  336 + '', '', 'ds_carga_horaria_');
  337 +
  338 + $this->campoTextoInv('ref_cod_escola_' . $key, '', $det_escola, 30, 255,
  339 + FALSE, FALSE, FALSE, '', $link_excluir, '', '', 'ref_cod_escola_');
  340 + }
  341 + }
  342 +
  343 + $this->campoOculto('incluir_periodo', '');
  344 + $this->campoQuebra();
  345 + }
  346 +
  347 + function Novo()
  348 + {
  349 + @session_start();
  350 + $this->pessoa_logada = $_SESSION['id_pessoa'];
  351 + @session_write_close();
  352 +
  353 + $obj_permissoes = new clsPermissoes();
  354 + $obj_permissoes->permissao_cadastra(635, $this->pessoa_logada, 3,
  355 + 'educar_servidor_alocacao_lst.php');
  356 +
  357 + if ($_POST['alocacao_array']) {
  358 + $this->alocacao_array = unserialize(urldecode($_POST['alocacao_array']));
  359 + }
  360 +
  361 + if ($_POST['alocacao_excluida_array']) {
  362 + $this->alocacao_excluida_array = unserialize(urldecode($_POST['alocacao_excluida_array']));
  363 + }
  364 +
  365 + if ($this->alocacao_excluida_array) {
  366 + foreach ($this->alocacao_excluida_array as $excluida) {
  367 + $obj = new clsPmieducarServidorAlocacao(NULL, $this->ref_ref_cod_instituicao,
  368 + $this->pessoa_logada, $this->pessoa_logada, $excluida['ref_cod_escola'],
  369 + $this->ref_cod_servidor, NULL, NULL, $this->ativo,
  370 + $excluida['carga_horaria_alocada'], $excluida['periodo']);
  371 +
  372 + $cadastrou = $obj->excluir_horario();
  373 + }
  374 + }
  375 +
  376 + if ($_POST['carga_horaria_alocada'] && $_POST['periodo']) {
  377 + $aux = array();
  378 + $aux['periodo'] = $_POST['periodo'];
  379 + $aux['carga_horaria_alocada'] = $_POST['carga_horaria_alocada'];
  380 + $aux['ref_cod_escola'] = $_POST['ref_cod_escola'];
  381 + $aux['novo'] = 1;
  382 + $achou = FALSE;
  383 +
  384 + foreach ($this->alocacao_array as $alocacao) {
  385 + if ($alocacao['periodo'] == $aux["periodo"]) {
  386 + $achou = TRUE;
  387 + }
  388 + }
  389 +
  390 + if (!$achou) {
  391 + $this->alocacao_array[] = $aux;
  392 + }
  393 +
  394 + unset($this->periodo);
  395 + unset($this->carga_horaria_alocada);
  396 + }
  397 +
  398 + if ($this->alocacao_array) {
  399 + foreach ($this->alocacao_array as $alocacao) {
  400 + if ($alocacao['novo']) {
  401 + $obj = new clsPmieducarServidorAlocacao(NULL, $this->ref_ref_cod_instituicao,
  402 + NULL, $this->pessoa_logada, $alocacao['ref_cod_escola'],
  403 + $this->ref_cod_servidor, NULL, NULL, $this->ativo,
  404 + $alocacao['carga_horaria_alocada'], $alocacao['periodo']);
  405 +
  406 + $cadastrou = $obj->cadastra();
  407 +
  408 + if (!$cadastrou) {
  409 + $this->mensagem = 'Cadastro não realizado.<br />';
  410 + echo "<!--\nErro ao cadastrar clsPmieducarServidorAlocacao\nvalores obrigatorios\nis_numeric($this->ref_ref_cod_instituicao) && is_numeric($this->ref_usuario_cad) && is_numeric($this->ref_cod_escola) && is_numeric($this->ref_cod_servidor) && is_numeric($this->periodo) && ($this->carga_horaria_alocada)\n-->";
  411 + return FALSE;
  412 + }
  413 + }
  414 + }
  415 + }
  416 +
  417 + $this->mensagem .= 'Cadastro efetuado com sucesso.<br />';
  418 + header('Location: ' . sprintf('educar_servidor_det.php?cod_servidor=%d&ref_cod_instituicao=%d',
  419 + $this->ref_cod_servidor, $this->ref_ref_cod_instituicao));
  420 + die();
  421 + }
  422 +
  423 + function Editar()
  424 + {
  425 + return FALSE;
  426 + }
  427 +
  428 + function Excluir()
  429 + {
  430 + return FALSE;
  431 +
  432 + }
430 433 }
431 434  
432   -// cria uma extensao da classe base
  435 +// Instancia objeto de página
433 436 $pagina = new clsIndexBase();
434   -// cria o conteudo
  437 +
  438 +// Instancia objeto de conteúdo
435 439 $miolo = new indice();
436   -// adiciona o conteudo na clsBase
437   -$pagina->addForm( $miolo );
438   -// gera o html
  440 +
  441 +// Atribui o conteúdo à página
  442 +$pagina->addForm($miolo);
  443 +
  444 +// Gera o código HTML
439 445 $pagina->MakeAll();
440 446 ?>
441   -<script>
442   -
  447 +<script type="text/javascript">
443 448 function validaHora()
444 449 {
445   - var carga_horaria = document.getElementById('carga_horaria_alocada').value;
446   - var periodo = document.getElementById('periodo').value;
447   - var ref_cod_escola = document.getElementById('ref_cod_escola').value;
448   - var horas_restantes = document.getElementById('horas_restantes_').value;
449   -
450   - if ( !ref_cod_escola )
451   - {
452   - alert( 'Preencha o campo \'Escola\' corretamente!' );
453   - return false;
454   - }
455   -
456   - if ( !( ( /[0-9]{2}:[0-9]{2}/ ).test( document.formcadastro.carga_horaria_alocada.value ) ) )
457   - {
458   - alert( "Preencha o campo 'Carga Horária' corretamente!" );
459   - return false;
460   - }
461   -
462   - if ( !periodo )
463   - {
464   - alert( "Preencha o campo 'Período' corretamente!" );
465   - return false;
466   - }
467   -
468   - horas_restantes = unescape( horas_restantes );
469   - horas_restantes = unescape( horas_restantes ).split( ":" );
470   -
471   - var carga_horaria_alocada_ = document.getElementById('carga_horaria_alocada').value.split( ":" );
472   -
473   - hora_ = Date.UTC( 1970, 01, 01, carga_horaria_alocada_[0], carga_horaria_alocada_[1], 0 );
474   - hora_restantes_ = Date.UTC( 1970, 01, 01, horas_restantes[0], horas_restantes[1], 0 );
475   -
476   - if ( hora_ > hora_restantes_ )
477   - {
478   - alert( "Atenção número de horas excedem o número de horas disponíveis ,\nPor favor corriga!!!" );
479   - document.getElementById( 'ref_cod_escola' ).value = '';
480   - document.getElementById( 'periodo' ).value = '';
481   - document.getElementById( 'carga_horaria_alocada' ).value = '';
482   - return false;
483   - }
484   -
485   - return true;
  450 + var carga_horaria = document.getElementById('carga_horaria_alocada').value;
  451 + var periodo = document.getElementById('periodo').value;
  452 + var ref_cod_escola = document.getElementById('ref_cod_escola').value;
  453 + var horas_restantes = document.getElementById('horas_restantes_').value;
  454 +
  455 + if (!ref_cod_escola) {
  456 + alert('Preencha o campo "Escola" corretamente!');
  457 + return false;
  458 + }
  459 +
  460 + if (!((/[0-9]{2}:[0-9]{2}/).test(document.formcadastro.carga_horaria_alocada.value))) {
  461 + alert('Preencha o campo "Carga Horária" corretamente!');
  462 + return false;
  463 + }
  464 +
  465 + if (!periodo) {
  466 + alert('Preencha o campo "Período" corretamente!');
  467 + return false;
  468 + }
  469 +
  470 + horas_restantes = unescape(horas_restantes);
  471 + horas_restantes = unescape(horas_restantes).split(':');
  472 +
  473 + var carga_horaria_alocada_ = document.getElementById('carga_horaria_alocada').value.split(":");
  474 +
  475 + hora_ = Date.UTC(1970, 01, 01, carga_horaria_alocada_[0], carga_horaria_alocada_[1], 0);
  476 + hora_restantes_ = Date.UTC(1970, 01, 01, horas_restantes[0], horas_restantes[1], 0);
  477 +
  478 + if (hora_ > hora_restantes_) {
  479 + alert("Atenção número de horas excedem o número de horas disponíveis! Por favor, corrija.");
  480 + document.getElementById('ref_cod_escola').value = '';
  481 + document.getElementById('periodo').value = '';
  482 + document.getElementById('carga_horaria_alocada').value = '';
  483 + return false;
  484 + }
  485 +
  486 + return true;
486 487 }
487 488 </script>
488 489 \ No newline at end of file
... ...
ieducar/intranet/include/pmieducar/clsPmieducarServidorAlocacao.inc.php
1 1 <?php
2 2  
3   -/*
  3 +/**
4 4 * i-Educar - Sistema de gestão escolar
5 5 *
6 6 * Copyright (C) 2006 Prefeitura Municipal de Itajaí
... ... @@ -19,642 +19,574 @@
19 19 * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
20 20 * com este programa; se não, escreva para a Free Software Foundation, Inc., no
21 21 * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  22 + *
  23 + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
  24 + * @category i-Educar
  25 + * @license @@license@@
  26 + * @package iEd_Pmieducar
  27 + * @since Arquivo disponível desde a versão 1.0.0
  28 + * @version $Id$
22 29 */
23 30  
  31 +require_once 'include/pmieducar/geral.inc.php';
  32 +
24 33 /**
25   - * ClsPmieducarServidorAlocacaoTest class
  34 + * clsPmieducarServidorAlocacao class.
26 35 *
27   - * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
28   - * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL
29   - * @package Core
30   - * @subpackage Servidor
31   - * @since Classe disponível desde a versão 1.0.0
32   - * @version $Id$
  36 + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
  37 + * @category i-Educar
  38 + * @license @@license@@
  39 + * @package iEd_Pmieducar
  40 + * @since Classe disponível desde a versão 1.0.0
  41 + * @version @@package_version@@
33 42 */
34   -
35   -require_once( "include/pmieducar/geral.inc.php" );
36   -
37 43 class clsPmieducarServidorAlocacao
38 44 {
39   - var $cod_servidor_alocacao;
40   - var $ref_ref_cod_instituicao;
41   - var $ref_usuario_exc;
42   - var $ref_usuario_cad;
43   - var $ref_cod_escola;
44   - var $ref_cod_servidor;
45   - var $data_cadastro;
46   - var $data_exclusao;
47   - var $ativo;
48   - var $carga_horaria;
49   - var $periodo;
50   -
51   - // propriedades padrao
52   -
53   - /**
54   - * Armazena o total de resultados obtidos na ultima chamada ao metodo lista
55   - *
56   - * @var int
57   - */
58   - var $_total;
59   -
60   - /**
61   - * Nome do schema
62   - *
63   - * @var string
64   - */
65   - var $_schema;
66   -
67   - /**
68   - * Nome da tabela
69   - *
70   - * @var string
71   - */
72   - var $_tabela;
73   -
74   - /**
75   - * Lista separada por virgula, com os campos que devem ser selecionados na proxima chamado ao metodo lista
76   - *
77   - * @var string
78   - */
79   - var $_campos_lista;
80   -
81   - /**
82   - * Lista com todos os campos da tabela separados por virgula, padrao para selecao no metodo lista
83   - *
84   - * @var string
85   - */
86   - var $_todos_campos;
87   -
88   - /**
89   - * Valor que define a quantidade de registros a ser retornada pelo metodo lista
90   - *
91   - * @var int
92   - */
93   - var $_limite_quantidade;
94   -
95   - /**
96   - * Define o valor de offset no retorno dos registros no metodo lista
97   - *
98   - * @var int
99   - */
100   - var $_limite_offset;
101   -
102   - /**
103   - * Define o campo padrao para ser usado como padrao de ordenacao no metodo lista
104   - *
105   - * @var string
106   - */
107   - var $_campo_order_by;
108   - /**
109   - * Define o campo padrao para ser usado como padrao de ordenacao no metodo lista
110   - *
111   - * @var string
112   - */
113   - var $_campo_group_by;
114   -
115   -
116   - /**
117   - * Construtor (PHP 4)
118   - *
119   - * @return object
120   - */
121   - function clsPmieducarServidorAlocacao( $cod_servidor_alocacao = null, $ref_ref_cod_instituicao = null, $ref_usuario_exc = null, $ref_usuario_cad = null, $ref_cod_escola = null, $ref_cod_servidor = null, $data_cadastro = null, $data_exclusao = null, $ativo = null, $carga_horaria = null, $periodo = null )
122   - {
123   - $db = new clsBanco();
124   - $this->_schema = "pmieducar.";
125   - $this->_tabela = "{$this->_schema}servidor_alocacao";
126   -
127   - $this->_campos_lista = $this->_todos_campos = "cod_servidor_alocacao, ref_ref_cod_instituicao, ref_usuario_exc, ref_usuario_cad, ref_cod_escola, ref_cod_servidor, data_cadastro, data_exclusao, ativo, carga_horaria, periodo";
128   -
129   - if( is_numeric( $ref_usuario_cad ) )
130   - {
131   - if( class_exists( "clsPmieducarUsuario" ) )
132   - {
133   - $tmp_obj = new clsPmieducarUsuario( $ref_usuario_cad );
134   - if( method_exists( $tmp_obj, "existe") )
135   - {
136   - if( $tmp_obj->existe() )
137   - {
138   - $this->ref_usuario_cad = $ref_usuario_cad;
139   - }
140   - }
141   - else if( method_exists( $tmp_obj, "detalhe") )
142   - {
143   - if( $tmp_obj->detalhe() )
144   - {
145   - $this->ref_usuario_cad = $ref_usuario_cad;
146   - }
147   - }
148   - }
149   - else
150   - {
151   - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_cad}'" ) )
152   - {
153   - $this->ref_usuario_cad = $ref_usuario_cad;
154   - }
155   - }
156   - }
157   - if( is_numeric( $ref_usuario_exc ) )
158   - {
159   - if( class_exists( "clsPmieducarUsuario" ) )
160   - {
161   - $tmp_obj = new clsPmieducarUsuario( $ref_usuario_exc );
162   - if( method_exists( $tmp_obj, "existe") )
163   - {
164   - if( $tmp_obj->existe() )
165   - {
166   - $this->ref_usuario_exc = $ref_usuario_exc;
167   - }
168   - }
169   - else if( method_exists( $tmp_obj, "detalhe") )
170   - {
171   - if( $tmp_obj->detalhe() )
172   - {
173   - $this->ref_usuario_exc = $ref_usuario_exc;
174   - }
175   - }
176   - }
177   - else
178   - {
179   - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_exc}'" ) )
180   - {
181   - $this->ref_usuario_exc = $ref_usuario_exc;
182   - }
183   - }
184   - }
185   - if( is_numeric( $ref_cod_escola ) )
186   - {
187   - if( class_exists( "clsPmieducarEscola" ) )
188   - {
189   - $tmp_obj = new clsPmieducarEscola( $ref_cod_escola );
190   - if( method_exists( $tmp_obj, "existe") )
191   - {
192   - if( $tmp_obj->existe() )
193   - {
194   - $this->ref_cod_escola = $ref_cod_escola;
195   - }
196   - }
197   - else if( method_exists( $tmp_obj, "detalhe") )
198   - {
199   - if( $tmp_obj->detalhe() )
200   - {
201   - $this->ref_cod_escola = $ref_cod_escola;
202   - }
203   - }
204   - }
205   - else
206   - {
207   - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.escola WHERE cod_escola = '{$ref_cod_escola}'" ) )
208   - {
209   - $this->ref_cod_escola = $ref_cod_escola;
210   - }
211   - }
212   - }
213   -
214   - if( is_numeric( $ref_cod_servidor ) && is_numeric( $ref_ref_cod_instituicao ) )
215   - {
216   - if( class_exists( "clsPmieducarServidor" ) )
217   - {
218   - $tmp_obj = new clsPmieducarServidor( $ref_cod_servidor,null,null,null,null,null,null, $ref_ref_cod_instituicao );
219   - if( method_exists( $tmp_obj, "existe") )
220   - {
221   - if( $tmp_obj->existe() )
222   - {
223   - $this->ref_cod_servidor = $ref_cod_servidor;
224   - $this->ref_ref_cod_instituicao = $ref_ref_cod_instituicao;
225   - }
226   - }
227   - else if( method_exists( $tmp_obj, "detalhe") )
228   - {
229   - if( $tmp_obj->detalhe() )
230   - {
231   - $this->ref_cod_servidor = $ref_cod_servidor;
232   - $this->ref_ref_cod_instituicao = $ref_ref_cod_instituicao;
233   - }
234   - }
235   - }
236   - else
237   - {
238   - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.servidor WHERE cod_servidor = '{$ref_cod_servidor}' AND ref_cod_instituicao = '{$ref_ref_cod_instituicao}'" ) )
239   - {
240   - $this->ref_cod_servidor = $ref_cod_servidor;
241   - $this->ref_ref_cod_instituicao = $ref_ref_cod_instituicao;
242   - }
243   - }
244   - }
245   -
246   -
247   - if ( is_numeric( $cod_servidor_alocacao ) )
248   - {
249   - $this->cod_servidor_alocacao = $cod_servidor_alocacao;
250   - }
251   - if ( is_string( $data_cadastro ) )
252   - {
253   - $this->data_cadastro = $data_cadastro;
254   - }
255   - if ( is_string( $data_exclusao ) )
256   - {
257   - $this->data_exclusao = $data_exclusao;
258   - }
259   - if ( is_numeric( $ativo ) )
260   - {
261   - $this->ativo = $ativo;
262   - }
263   - if ( is_string( $carga_horaria ) )
264   - {
265   - $this->carga_horaria = $carga_horaria;
266   - }
267   - if ( is_numeric( $periodo ) )
268   - {
269   - $this->periodo = $periodo;
270   - }
271   - }
272   -
273   - /**
274   - * Cria um novo registro
275   - *
276   - * @return bool
277   - */
278   - function cadastra()
279   - {
280   - if( is_numeric( $this->ref_ref_cod_instituicao ) && is_numeric( $this->ref_usuario_cad ) && is_numeric( $this->ref_cod_escola ) && is_numeric( $this->ref_cod_servidor ) && is_string( $this->carga_horaria ) && ( $this->periodo ) )
281   - {
282   - $db = new clsBanco();
283   -
284   - $campos = "";
285   - $valores = "";
286   - $gruda = "";
287   -
288   - if( is_numeric( $this->ref_ref_cod_instituicao ) )
289   - {
290   - $campos .= "{$gruda}ref_ref_cod_instituicao";
291   - $valores .= "{$gruda}'{$this->ref_ref_cod_instituicao}'";
292   - $gruda = ", ";
293   - }
294   - if( is_numeric( $this->ref_usuario_cad ) )
295   - {
296   - $campos .= "{$gruda}ref_usuario_cad";
297   - $valores .= "{$gruda}'{$this->ref_usuario_cad}'";
298   - $gruda = ", ";
299   - }
300   - if( is_numeric( $this->ref_cod_escola ) )
301   - {
302   - $campos .= "{$gruda}ref_cod_escola";
303   - $valores .= "{$gruda}'{$this->ref_cod_escola}'";
304   - $gruda = ", ";
305   - }
306   - if( is_numeric( $this->ref_cod_servidor ) )
307   - {
308   - $campos .= "{$gruda}ref_cod_servidor";
309   - $valores .= "{$gruda}'{$this->ref_cod_servidor}'";
310   - $gruda = ", ";
311   - }
312   - if( is_string( $this->carga_horaria ) )
313   - {
314   - $campos .= "{$gruda}carga_horaria";
315   - $valores .= "{$gruda}'{$this->carga_horaria}'";
316   - $gruda = ", ";
317   - }
318   - if( ( $this->periodo ) )
319   - {
320   - $campos .= "{$gruda}periodo";
321   - $valores .= "{$gruda}'{$this->periodo}'";
322   - $gruda = ", ";
323   - }
324   - $campos .= "{$gruda}data_cadastro";
325   - $valores .= "{$gruda}NOW()";
326   - $gruda = ", ";
327   - $campos .= "{$gruda}ativo";
328   - $valores .= "{$gruda}'1'";
329   - $gruda = ", ";
330   -
331   - $db->Consulta( "INSERT INTO {$this->_tabela} ( $campos ) VALUES( $valores )" );
332   - return $db->InsertId( "{$this->_tabela}_cod_servidor_alocacao_seq");
333   - }
334   - return false;
335   - }
336   -
337   - /**
338   - * Edita os dados de um registro
339   - *
340   - * @return bool
341   - */
342   - function edita()
343   - {
344   - if( is_numeric( $this->cod_servidor_alocacao ) && is_numeric( $this->ref_usuario_exc ) )
345   - {
346   -
347   - $db = new clsBanco();
348   - $set = "";
349   -
350   - if( is_numeric( $this->ref_ref_cod_instituicao ) )
351   - {
352   - $set .= "{$gruda}ref_ref_cod_instituicao = '{$this->ref_ref_cod_instituicao}'";
353   - $gruda = ", ";
354   - }
355   - if( is_numeric( $this->ref_usuario_exc ) )
356   - {
357   - $set .= "{$gruda}ref_usuario_exc = '{$this->ref_usuario_exc}'";
358   - $gruda = ", ";
359   - }
360   - if( is_numeric( $this->ref_usuario_cad ) )
361   - {
362   - $set .= "{$gruda}ref_usuario_cad = '{$this->ref_usuario_cad}'";
363   - $gruda = ", ";
364   - }
365   - if( is_numeric( $this->ref_cod_escola ) )
366   - {
367   - $set .= "{$gruda}ref_cod_escola = '{$this->ref_cod_escola}'";
368   - $gruda = ", ";
369   - }
370   - if( is_numeric( $this->ref_cod_servidor ) )
371   - {
372   - $set .= "{$gruda}ref_cod_servidor = '{$this->ref_cod_servidor}'";
373   - $gruda = ", ";
374   - }
375   - if( is_numeric( $this->carga_horaria ) )
376   - {
377   - $set .= "{$gruda}carga_horaria = '{$this->carga_horaria}'";
378   - $gruda = ", ";
379   - }
380   - if( ( $this->periodo ) )
381   - {
382   - $set .= "{$gruda}periodo = '{$this->periodo}'";
383   - $gruda = ", ";
384   - }
385   - if( is_string( $this->data_cadastro ) )
386   - {
387   - $set .= "{$gruda}data_cadastro = '{$this->data_cadastro}'";
388   - $gruda = ", ";
389   - }
390   - $set .= "{$gruda}data_exclusao = NOW()";
391   - $gruda = ", ";
392   - if( is_numeric( $this->ativo ) )
393   - {
394   - $set .= "{$gruda}ativo = '{$this->ativo}'";
395   - $gruda = ", ";
396   - }
397   - if( $set )
398   - {
399   - $db->Consulta( "UPDATE {$this->_tabela} SET $set WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'" );
400   - return true;
401   - }
402   - }
403   - return false;
404   - }
405   -
406   - /**
407   - * Retorna uma lista filtrados de acordo com os parametros
408   - *
409   - * @return array
410   - */
411   - function lista( $int_cod_servidor_alocacao = null, $int_ref_ref_cod_instituicao = null, $int_ref_usuario_exc = null, $int_ref_usuario_cad = null, $int_ref_cod_escola = null, $int_ref_cod_servidor = null, $date_data_cadastro_ini = null, $date_data_cadastro_fim = null, $date_data_exclusao_ini = null, $date_data_exclusao_fim = null, $int_ativo = null, $int_carga_horaria = null, $int_periodo = null,$bool_busca_nome = false, $boo_professor = null )
412   - {
413   -
414   - $filtros = "";
415   - $whereAnd = " WHERE ";
416   -
417   - if(is_bool($bool_busca_nome) && $bool_busca_nome == true)
418   - {
419   - $join = ", cadastro.pessoa p ";
420   - $filtros .= "{$whereAnd} sa.ref_cod_servidor = p.idpes";
421   - $whereAnd = " AND ";
422   - $this->_campos_lista .= ",p.nome";
423   - }
424   -
425   - $sql = "SELECT {$this->_campos_lista} FROM {$this->_tabela} sa{$join}";
426   -
427   - if( is_numeric( $int_cod_servidor_alocacao ) )
428   - {
429   - $filtros .= "{$whereAnd} sa.cod_servidor_alocacao = '{$int_cod_servidor_alocacao}'";
430   - $whereAnd = " AND ";
431   - }
432   - if( is_numeric( $int_ref_ref_cod_instituicao ) )
433   - {
434   - $filtros .= "{$whereAnd} sa.ref_ref_cod_instituicao = '{$int_ref_ref_cod_instituicao}'";
435   - $whereAnd = " AND ";
436   - }
437   - if( is_numeric( $int_ref_usuario_exc ) )
438   - {
439   - $filtros .= "{$whereAnd} sa.ref_usuario_exc = '{$int_ref_usuario_exc}'";
440   - $whereAnd = " AND ";
441   - }
442   - if( is_numeric( $int_ref_usuario_cad ) )
443   - {
444   - $filtros .= "{$whereAnd} sa.ref_usuario_cad = '{$int_ref_usuario_cad}'";
445   - $whereAnd = " AND ";
446   - }
447   - if( is_numeric( $int_ref_cod_escola ) )
448   - {
449   - $filtros .= "{$whereAnd} sa.ref_cod_escola = '{$int_ref_cod_escola}'";
450   - $whereAnd = " AND ";
451   - }
452   - if( is_numeric( $int_ref_cod_servidor ) )
453   - {
454   - $filtros .= "{$whereAnd} sa.ref_cod_servidor = '{$int_ref_cod_servidor}'";
455   - $whereAnd = " AND ";
456   - }
457   - if( is_numeric( $int_carga_horaria ) )
458   - {
459   - $filtros .= "{$whereAnd} sa.carga_horaria = '{$int_carga_horaria}'";
460   - $whereAnd = " AND ";
461   - }
462   - if( ( $int_periodo ) )
463   - {
464   - $filtros .= "{$whereAnd} sa.periodo = '{$int_periodo}'";
465   - $whereAnd = " AND ";
466   - }
467   - if( is_string( $date_data_cadastro_ini ) )
468   - {
469   - $filtros .= "{$whereAnd} sa.data_cadastro >= '{$date_data_cadastro_ini}'";
470   - $whereAnd = " AND ";
471   - }
472   - if( is_string( $date_data_cadastro_fim ) )
473   - {
474   - $filtros .= "{$whereAnd} sa.data_cadastro <= '{$date_data_cadastro_fim}'";
475   - $whereAnd = " AND ";
476   - }
477   - if( is_string( $date_data_exclusao_ini ) )
478   - {
479   - $filtros .= "{$whereAnd} sa.data_exclusao >= '{$date_data_exclusao_ini}'";
480   - $whereAnd = " AND ";
481   - }
482   - if( is_string( $date_data_exclusao_fim ) )
483   - {
484   - $filtros .= "{$whereAnd} sa.data_exclusao <= '{$date_data_exclusao_fim}'";
485   - $whereAnd = " AND ";
486   - }
487   - if( is_null( $int_ativo ) || $int_ativo )
488   - {
489   - $filtros .= "{$whereAnd} sa.ativo = '1'";
490   - $whereAnd = " AND ";
491   - }
492   - else
493   - {
494   - $filtros .= "{$whereAnd} sa.ativo = '0'";
495   - $whereAnd = " AND ";
496   - }
497   -
498   - if(is_bool($boo_professor))
499   - {
500   - $not = $boo_professor? "=" : "!=";
501   - $filtros .= "{$whereAnd} EXISTS( SELECT 1 FROM pmieducar.servidor_funcao,pmieducar.funcao WHERE ref_cod_funcao = cod_funcao AND ref_cod_servidor = sa.ref_cod_servidor AND sa.ref_ref_cod_instituicao = ref_ref_cod_instituicao AND professor $not 1)";
502   - $whereAnd = " AND ";
503   - }
504   -
505   -
506   -
507   - $db = new clsBanco();
508   - $countCampos = count( explode( ",", $this->_campos_lista ) );
509   - $resultado = array();
510   -
511   - $sql .= $filtros . $this->getGroupBy() . $this->getOrderby() . $this->getLimite();
512   -
513   - $this->_total = $db->CampoUnico( "SELECT COUNT(0) FROM {$this->_tabela} sa {$join} {$filtros}" );
514   -
515   - $db->Consulta( $sql );
516   -
517   - if( $countCampos > 1 )
518   - {
519   - while ( $db->ProximoRegistro() )
520   - {
521   - $tupla = $db->Tupla();
522   -
523   - $tupla["_total"] = $this->_total;
524   - $resultado[] = $tupla;
525   - }
526   - }
527   - else
528   - {
529   - while ( $db->ProximoRegistro() )
530   - {
531   - $tupla = $db->Tupla();
532   - $resultado[] = $tupla[$this->_campos_lista];
533   - }
534   - }
535   - if( count( $resultado ) )
536   - {
537   - return $resultado;
538   - }
539   - return false;
540   - }
541   -
542   -
543   - function listaEscolas($int_ref_ref_cod_instituicao = null)
544   - {
545   -
546   - if( is_numeric( $int_ref_ref_cod_instituicao ) )
547   - {
548   -
549   - $sql = "SELECT DISTINCT ref_cod_escola FROM {$this->_tabela} WHERE ref_ref_cod_instituicao = '{$int_ref_ref_cod_instituicao}' AND ativo = '1'";
550   -
551   - $db = new clsBanco();
552   - $resultado = array();
553   -
554   - $db->Consulta( $sql );
555   -
556   - while ( $db->ProximoRegistro() )
557   - {
558   - $tupla = $db->Tupla();
559   - $resultado[] = $tupla;
560   - }
561   -
562   - if( count( $resultado ) )
563   - {
564   - return $resultado;
565   - }
566   -
567   - return false;
568   - }
569   - return false;
570   - }
571   -
572   -
573   - /**
574   - * Retorna um array com os dados de um registro
575   - *
576   - * @return array
577   - */
578   - function detalhe()
579   - {
580   - if( is_numeric( $this->cod_servidor_alocacao ) )
581   - {
582   -
583   - $db = new clsBanco();
584   - $db->Consulta( "SELECT {$this->_todos_campos} FROM {$this->_tabela} WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'" );
585   - $db->ProximoRegistro();
586   - return $db->Tupla();
587   - }
588   - return false;
589   - }
590   -
591   - /**
592   - * Retorna um array com os dados de um registro
593   - *
594   - * @return array
595   - */
596   - function existe()
597   - {
598   - if( is_numeric( $this->cod_servidor_alocacao ) )
599   - {
600   -
601   - $db = new clsBanco();
602   - $db->Consulta( "SELECT 1 FROM {$this->_tabela} WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'" );
603   - $db->ProximoRegistro();
604   - return $db->Tupla();
605   - }
606   - return false;
607   - }
608   -
609   - /**
610   - * Exclui um registro
611   - *
612   - * @return bool
613   - */
614   - function excluir()
615   - {
616   - if( is_numeric( $this->cod_servidor_alocacao ) && is_numeric( $this->ref_usuario_exc ) )
617   - {
618   -
619   - /*
620   - delete
621   - $db = new clsBanco();
622   - $db->Consulta( "DELETE FROM {$this->_tabela} WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'" );
623   - return true;
624   - */
625   -
626   - $this->ativo = 0;
627   - return $this->edita();
628   - }
629   - return false;
630   - }
631   -
632   - /**
633   - * Exclui um registro passando cod_Servidor escola e horario
634   - *
635   - * @return bool
636   - */
637   - function excluir_horario()
638   - {
639   -// echo "if( is_numeric( $this->ref_cod_servidor ) && is_numeric( $this->ref_ref_cod_instituicao ) && is_numeric( $this->ref_cod_escola ) && is_numeric( $this->hora_inicial ) && is_numeric( $this->hora_final ))";die;
640   - if( is_numeric( $this->ref_cod_servidor ) && is_numeric( $this->ref_ref_cod_instituicao ) && is_numeric( $this->ref_cod_escola ) && is_numeric( $this->periodo ) )
641   - {
642   -
643   -
644   - //delete
645   - $db = new clsBanco();
646   - //echo "DELETE FROM {$this->_tabela} WHERE ref_cod_servidor = '{$this->ref_cod_servidor}' AND ref_ref_cod_instituicao = '{$this->ref_ref_cod_instituicao}' AND ref_cod_escola = '{$this->ref_cod_escola}' AND hora_inicial = '{$this->hora_inicial}' AND hora_final = '{$this->hora_final}' " ;
647   - $db->Consulta( "DELETE FROM {$this->_tabela} WHERE ref_cod_servidor = '{$this->ref_cod_servidor}' AND ref_ref_cod_instituicao = '{$this->ref_ref_cod_instituicao}' AND ref_cod_escola = '{$this->ref_cod_escola}' AND periodo = '$this->periodo'" );
648   - return true;
649   -
650   -
651   - //$this->ativo = 0;
652   - // return $this->edita();
653   - }
654   - return false;
655   - }
  45 + var $cod_servidor_alocacao;
  46 + var $ref_ref_cod_instituicao;
  47 + var $ref_usuario_exc;
  48 + var $ref_usuario_cad;
  49 + var $ref_cod_escola;
  50 + var $ref_cod_servidor;
  51 + var $data_cadastro;
  52 + var $data_exclusao;
  53 + var $ativo;
  54 + var $carga_horaria;
  55 + var $periodo;
  56 +
  57 + /**
  58 + * Armazena o total de resultados obtidos na última chamada ao método lista().
  59 + * @var int
  60 + */
  61 + var $_total;
  62 +
  63 + /**
  64 + * Nome do schema.
  65 + * @var string
  66 + */
  67 + var $_schema;
  68 +
  69 + /**
  70 + * Nome da tabela.
  71 + * @var string
  72 + */
  73 + var $_tabela;
  74 +
  75 + /**
  76 + * Lista separada por vírgula, com os campos que devem ser selecionados na
  77 + * próxima chamado ao método lista().
  78 + * @var string
  79 + */
  80 + var $_campos_lista;
  81 +
  82 + /**
  83 + * Lista com todos os campos da tabela separados por vírgula, padrão para
  84 + * seleção no método lista.
  85 + * @var string
  86 + */
  87 + var $_todos_campos;
  88 +
  89 + /**
  90 + * Valor que define a quantidade de registros a ser retornada pelo método lista().
  91 + * @var int
  92 + */
  93 + var $_limite_quantidade;
  94 +
  95 + /**
  96 + * Define o valor de offset no retorno dos registros no método lista().
  97 + * @var int
  98 + */
  99 + var $_limite_offset;
656 100  
  101 + /**
  102 + * Define o campo para ser usado como padrão de ordenação no método lista().
  103 + * @var string
  104 + */
  105 + var $_campo_order_by;
657 106  
  107 + /**
  108 + * Define o campo para ser usado como padrão de agrupamento no método lista().
  109 + * @var string
  110 + */
  111 + var $_campo_group_by;
  112 +
  113 + /**
  114 + * Construtor.
  115 + */
  116 + function clsPmieducarServidorAlocacao($cod_servidor_alocacao = NULL,
  117 + $ref_ref_cod_instituicao = NULL, $ref_usuario_exc = NULL, $ref_usuario_cad = NULL,
  118 + $ref_cod_escola = NULL, $ref_cod_servidor = NULL, $data_cadastro = NULL,
  119 + $data_exclusao = NULL, $ativo = NULL, $carga_horaria = NULL, $periodo = NULL)
  120 + {
  121 + $db = new clsBanco();
  122 + $this->_schema = 'pmieducar.';
  123 + $this->_tabela = $this->_schema . 'servidor_alocacao';
  124 +
  125 + $this->_campos_lista = $this->_todos_campos = 'cod_servidor_alocacao, ref_ref_cod_instituicao, ref_usuario_exc, ref_usuario_cad, ref_cod_escola, ref_cod_servidor, data_cadastro, data_exclusao, ativo, carga_horaria, periodo';
  126 +
  127 + if (is_numeric($ref_usuario_cad)) {
  128 + if (class_exists("clsPmieducarUsuario")) {
  129 + $tmp_obj = new clsPmieducarUsuario($ref_usuario_cad);
  130 + if (method_exists($tmp_obj, "existe")) {
  131 + if ($tmp_obj->existe()) {
  132 + $this->ref_usuario_cad = $ref_usuario_cad;
  133 + }
  134 + }
  135 + elseif (method_exists($tmp_obj, "detalhe")) {
  136 + if ($tmp_obj->detalhe()) {
  137 + $this->ref_usuario_cad = $ref_usuario_cad;
  138 + }
  139 + }
  140 + }
  141 + else {
  142 + if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_cad}'")) {
  143 + $this->ref_usuario_cad = $ref_usuario_cad;
  144 + }
  145 + }
  146 + }
  147 +
  148 + if (is_numeric($ref_usuario_exc)) {
  149 + if (class_exists("clsPmieducarUsuario")) {
  150 + $tmp_obj = new clsPmieducarUsuario($ref_usuario_exc);
  151 + if (method_exists($tmp_obj, "existe")) {
  152 + if ($tmp_obj->existe()) {
  153 + $this->ref_usuario_exc = $ref_usuario_exc;
  154 + }
  155 + }
  156 + elseif (method_exists($tmp_obj, "detalhe")) {
  157 + if ($tmp_obj->detalhe()) {
  158 + $this->ref_usuario_exc = $ref_usuario_exc;
  159 + }
  160 + }
  161 + }
  162 + else {
  163 + if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_exc}'")) {
  164 + $this->ref_usuario_exc = $ref_usuario_exc;
  165 + }
  166 + }
  167 + }
  168 + if (is_numeric($ref_cod_escola)) {
  169 + if (class_exists("clsPmieducarEscola")) {
  170 + $tmp_obj = new clsPmieducarEscola($ref_cod_escola);
  171 + if (method_exists($tmp_obj, "existe")) {
  172 + if ($tmp_obj->existe()) {
  173 + $this->ref_cod_escola = $ref_cod_escola;
  174 + }
  175 + }
  176 + elseif (method_exists($tmp_obj, "detalhe")) {
  177 + if ($tmp_obj->detalhe()) {
  178 + $this->ref_cod_escola = $ref_cod_escola;
  179 + }
  180 + }
  181 + }
  182 + else {
  183 + if ($db->CampoUnico("SELECT 1 FROM pmieducar.escola WHERE cod_escola = '{$ref_cod_escola}'")) {
  184 + $this->ref_cod_escola = $ref_cod_escola;
  185 + }
  186 + }
  187 + }
  188 +
  189 + if (is_numeric($ref_cod_servidor) && is_numeric($ref_ref_cod_instituicao)) {
  190 + if (class_exists("clsPmieducarServidor")) {
  191 + $tmp_obj = new clsPmieducarServidor($ref_cod_servidor, NULL, NULL, NULL,
  192 + NULL, NULL, NULL, $ref_ref_cod_instituicao);
  193 + if (method_exists($tmp_obj, "existe")) {
  194 + if ($tmp_obj->existe()) {
  195 + $this->ref_cod_servidor = $ref_cod_servidor;
  196 + $this->ref_ref_cod_instituicao = $ref_ref_cod_instituicao;
  197 + }
  198 + }
  199 + elseif (method_exists($tmp_obj, "detalhe")) {
  200 + if ($tmp_obj->detalhe()) {
  201 + $this->ref_cod_servidor = $ref_cod_servidor;
  202 + $this->ref_ref_cod_instituicao = $ref_ref_cod_instituicao;
  203 + }
  204 + }
  205 + }
  206 + else {
  207 + if ($db->CampoUnico("SELECT 1 FROM pmieducar.servidor WHERE cod_servidor = '{$ref_cod_servidor}' AND ref_cod_instituicao = '{$ref_ref_cod_instituicao}'")) {
  208 + $this->ref_cod_servidor = $ref_cod_servidor;
  209 + $this->ref_ref_cod_instituicao = $ref_ref_cod_instituicao;
  210 + }
  211 + }
  212 + }
  213 +
  214 + if (is_numeric($cod_servidor_alocacao)) {
  215 + $this->cod_servidor_alocacao = $cod_servidor_alocacao;
  216 + }
  217 +
  218 + if (is_string($data_cadastro)) {
  219 + $this->data_cadastro = $data_cadastro;
  220 + }
  221 +
  222 + if (is_string($data_exclusao)) {
  223 + $this->data_exclusao = $data_exclusao;
  224 + }
  225 +
  226 + if (is_numeric($ativo)) {
  227 + $this->ativo = $ativo;
  228 + }
  229 +
  230 + if (is_string($carga_horaria)) {
  231 + $this->carga_horaria = $carga_horaria;
  232 + }
  233 +
  234 + if (is_numeric($periodo)) {
  235 + $this->periodo = $periodo;
  236 + }
  237 + }
  238 +
  239 + /**
  240 + * Cria um novo registro.
  241 + * @return bool
  242 + */
  243 + function cadastra()
  244 + {
  245 + if (is_numeric($this->ref_ref_cod_instituicao) && is_numeric($this->ref_usuario_cad) &&
  246 + is_numeric($this->ref_cod_escola) && is_numeric($this->ref_cod_servidor) &&
  247 + is_string($this->carga_horaria) && ($this->periodo)
  248 + ) {
  249 + $db = new clsBanco();
  250 +
  251 + $campos = '';
  252 + $valores = '';
  253 + $gruda = '';
  254 +
  255 + if (is_numeric($this->ref_ref_cod_instituicao)) {
  256 + $campos .= "{$gruda}ref_ref_cod_instituicao";
  257 + $valores .= "{$gruda}'{$this->ref_ref_cod_instituicao}'";
  258 + $gruda = ', ';
  259 + }
  260 +
  261 + if (is_numeric($this->ref_usuario_cad)) {
  262 + $campos .= "{$gruda}ref_usuario_cad";
  263 + $valores .= "{$gruda}'{$this->ref_usuario_cad}'";
  264 + $gruda = ', ';
  265 + }
  266 +
  267 + if (is_numeric($this->ref_cod_escola)) {
  268 + $campos .= "{$gruda}ref_cod_escola";
  269 + $valores .= "{$gruda}'{$this->ref_cod_escola}'";
  270 + $gruda = ', ';
  271 + }
  272 +
  273 + if (is_numeric($this->ref_cod_servidor)) {
  274 + $campos .= "{$gruda}ref_cod_servidor";
  275 + $valores .= "{$gruda}'{$this->ref_cod_servidor}'";
  276 + $gruda = ', ';
  277 + }
  278 +
  279 + if (is_string($this->carga_horaria)) {
  280 + $campos .= "{$gruda}carga_horaria";
  281 + $valores .= "{$gruda}'{$this->carga_horaria}'";
  282 + $gruda = ', ';
  283 + }
  284 +
  285 + if (($this->periodo)) {
  286 + $campos .= "{$gruda}periodo";
  287 + $valores .= "{$gruda}'{$this->periodo}'";
  288 + $gruda = ', ';
  289 + }
  290 +
  291 + $campos .= "{$gruda}data_cadastro";
  292 + $valores .= "{$gruda}NOW()";
  293 + $gruda = ", ";
  294 +
  295 + $campos .= "{$gruda}ativo";
  296 + $valores .= "{$gruda}'1'";
  297 + $gruda = ", ";
  298 +
  299 + $db->Consulta("INSERT INTO {$this->_tabela} ($campos) VALUES ($valores)");
  300 + return $db->InsertId("{$this->_tabela}_cod_servidor_alocacao_seq");
  301 + }
  302 +
  303 + return FALSE;
  304 + }
  305 +
  306 + /**
  307 + * Edita os dados de um registro.
  308 + * @return bool
  309 + */
  310 + function edita()
  311 + {
  312 + if (is_numeric($this->cod_servidor_alocacao) && is_numeric($this->ref_usuario_exc)) {
  313 + $db = new clsBanco();
  314 + $set = '';
  315 +
  316 + if (is_numeric($this->ref_ref_cod_instituicao)) {
  317 + $set .= "{$gruda}ref_ref_cod_instituicao = '{$this->ref_ref_cod_instituicao}'";
  318 + $gruda = ', ';
  319 + }
  320 +
  321 + if (is_numeric($this->ref_usuario_exc)) {
  322 + $set .= "{$gruda}ref_usuario_exc = '{$this->ref_usuario_exc}'";
  323 + $gruda = ', ';
  324 + }
  325 +
  326 + if (is_numeric($this->ref_usuario_cad)) {
  327 + $set .= "{$gruda}ref_usuario_cad = '{$this->ref_usuario_cad}'";
  328 + $gruda = ', ';
  329 + }
  330 +
  331 + if (is_numeric($this->ref_cod_escola)) {
  332 + $set .= "{$gruda}ref_cod_escola = '{$this->ref_cod_escola}'";
  333 + $gruda = ', ';
  334 + }
  335 +
  336 + if (is_numeric($this->ref_cod_servidor)) {
  337 + $set .= "{$gruda}ref_cod_servidor = '{$this->ref_cod_servidor}'";
  338 + $gruda = ', ';
  339 + }
  340 +
  341 + if (is_numeric($this->carga_horaria)) {
  342 + $set .= "{$gruda}carga_horaria = '{$this->carga_horaria}'";
  343 + $gruda = ', ';
  344 + }
  345 +
  346 + if (($this->periodo)) {
  347 + $set .= "{$gruda}periodo = '{$this->periodo}'";
  348 + $gruda = ', ';
  349 + }
  350 +
  351 + if (is_string($this->data_cadastro)) {
  352 + $set .= "{$gruda}data_cadastro = '{$this->data_cadastro}'";
  353 + $gruda = ', ';
  354 + }
  355 +
  356 + $set .= "{$gruda}data_exclusao = NOW()";
  357 + $gruda = ', ';
  358 +
  359 + if (is_numeric($this->ativo)) {
  360 + $set .= "{$gruda}ativo = '{$this->ativo}'";
  361 + $gruda = ', ';
  362 + }
  363 +
  364 + if ($set) {
  365 + $db->Consulta("UPDATE {$this->_tabela} SET $set WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'");
  366 + return TRUE;
  367 + }
  368 + }
  369 +
  370 + return FALSE;
  371 + }
  372 +
  373 + /**
  374 + * Retorna uma lista de registros filtrados de acordo com os parâmetros.
  375 + * @return array
  376 + */
  377 + function lista($int_cod_servidor_alocacao = NULL, $int_ref_ref_cod_instituicao = NULL,
  378 + $int_ref_usuario_exc = NULL, $int_ref_usuario_cad = NULL, $int_ref_cod_escola = NULL,
  379 + $int_ref_cod_servidor = NULL, $date_data_cadastro_ini = NULL,
  380 + $date_data_cadastro_fim = NULL, $date_data_exclusao_ini = NULL,
  381 + $date_data_exclusao_fim = NULL, $int_ativo = NULL, $int_carga_horaria = NULL,
  382 + $int_periodo = NULL,$bool_busca_nome = FALSE, $boo_professor = NULL)
  383 + {
  384 + $filtros = '';
  385 + $whereAnd = ' WHERE ';
  386 +
  387 + if (is_bool($bool_busca_nome) && $bool_busca_nome == TRUE) {
  388 + $join = ', cadastro.pessoa p ';
  389 + $filtros .= $whereAnd.' sa.ref_cod_servidor = p.idpes';
  390 + $whereAnd = ' AND ';
  391 + $this->_campos_lista .= ',p.nome';
  392 + }
  393 +
  394 + $sql = "SELECT {$this->_campos_lista} FROM {$this->_tabela} sa{$join}";
  395 +
  396 + if (is_numeric($int_cod_servidor_alocacao)) {
  397 + $filtros .= "{$whereAnd} sa.cod_servidor_alocacao = '{$int_cod_servidor_alocacao}'";
  398 + $whereAnd = ' AND ';
  399 + }
  400 +
  401 + if (is_numeric($int_ref_ref_cod_instituicao)) {
  402 + $filtros .= "{$whereAnd} sa.ref_ref_cod_instituicao = '{$int_ref_ref_cod_instituicao}'";
  403 + $whereAnd = ' AND ';
  404 + }
  405 +
  406 + if (is_numeric($int_ref_usuario_exc)) {
  407 + $filtros .= "{$whereAnd} sa.ref_usuario_exc = '{$int_ref_usuario_exc}'";
  408 + $whereAnd = ' AND ';
  409 + }
  410 + if (is_numeric($int_ref_usuario_cad)) {
  411 + $filtros .= "{$whereAnd} sa.ref_usuario_cad = '{$int_ref_usuario_cad}'";
  412 + $whereAnd = ' AND ';
  413 + }
  414 +
  415 + if (is_numeric($int_ref_cod_escola)) {
  416 + $filtros .= "{$whereAnd} sa.ref_cod_escola = '{$int_ref_cod_escola}'";
  417 + $whereAnd = ' AND ';
  418 + }
  419 +
  420 + if (is_numeric($int_ref_cod_servidor)) {
  421 + $filtros .= "{$whereAnd} sa.ref_cod_servidor = '{$int_ref_cod_servidor}'";
  422 + $whereAnd = ' AND ';
  423 + }
  424 +
  425 + if (is_numeric($int_carga_horaria)) {
  426 + $filtros .= "{$whereAnd} sa.carga_horaria = '{$int_carga_horaria}'";
  427 + $whereAnd = ' AND ';
  428 + }
  429 +
  430 + if (($int_periodo)) {
  431 + $filtros .= "{$whereAnd} sa.periodo = '{$int_periodo}'";
  432 + $whereAnd = ' AND ';
  433 + }
  434 +
  435 + if (is_string($date_data_cadastro_ini)) {
  436 + $filtros .= "{$whereAnd} sa.data_cadastro >= '{$date_data_cadastro_ini}'";
  437 + $whereAnd = ' AND ';
  438 + }
  439 +
  440 + if (is_string($date_data_cadastro_fim)) {
  441 + $filtros .= "{$whereAnd} sa.data_cadastro <= '{$date_data_cadastro_fim}'";
  442 + $whereAnd = ' AND ';
  443 + }
  444 +
  445 + if (is_string($date_data_exclusao_ini)) {
  446 + $filtros .= "{$whereAnd} sa.data_exclusao >= '{$date_data_exclusao_ini}'";
  447 + $whereAnd = ' AND ';
  448 + }
  449 +
  450 + if (is_string($date_data_exclusao_fim)) {
  451 + $filtros .= "{$whereAnd} sa.data_exclusao <= '{$date_data_exclusao_fim}'";
  452 + $whereAnd = ' AND ';
  453 + }
  454 +
  455 + if (is_null($int_ativo) || $int_ativo) {
  456 + $filtros .= "{$whereAnd} sa.ativo = '1'";
  457 + $whereAnd = ' AND ';
  458 + }
  459 + else {
  460 + $filtros .= "{$whereAnd} sa.ativo = '0'";
  461 + $whereAnd = ' AND ';
  462 + }
  463 +
  464 + if (is_bool($boo_professor)) {
  465 + $not = $boo_professor? "=" : "!=";
  466 + $filtros .= "{$whereAnd} EXISTS(SELECT 1 FROM pmieducar.servidor_funcao,pmieducar.funcao WHERE ref_cod_funcao = cod_funcao AND ref_cod_servidor = sa.ref_cod_servidor AND sa.ref_ref_cod_instituicao = ref_ref_cod_instituicao AND professor $not 1)";
  467 + $whereAnd = ' AND ';
  468 + }
  469 +
  470 + $db = new clsBanco();
  471 + $countCampos = count(explode(',', $this->_campos_lista));
  472 + $resultado = array();
  473 +
  474 + $sql .= $filtros . $this->getGroupBy() . $this->getOrderby() . $this->getLimite();
  475 +
  476 + $this->_total = $db->CampoUnico("SELECT COUNT(0) FROM {$this->_tabela} sa {$join} {$filtros}");
  477 +
  478 + $db->Consulta($sql);
  479 +
  480 + if ($countCampos > 1) {
  481 + while ($db->ProximoRegistro()) {
  482 + $tupla = $db->Tupla();
  483 +
  484 + $tupla['_total'] = $this->_total;
  485 + $resultado[] = $tupla;
  486 + }
  487 + }
  488 + else {
  489 + while ($db->ProximoRegistro()) {
  490 + $tupla = $db->Tupla();
  491 + $resultado[] = $tupla[$this->_campos_lista];
  492 + }
  493 + }
  494 +
  495 + if (count($resultado)) {
  496 + return $resultado;
  497 + }
  498 +
  499 + return FALSE;
  500 + }
  501 +
  502 +
  503 + function listaEscolas($int_ref_ref_cod_instituicao = NULL)
  504 + {
  505 + if (is_numeric($int_ref_ref_cod_instituicao)) {
  506 + $sql = "SELECT DISTINCT ref_cod_escola FROM {$this->_tabela} WHERE ref_ref_cod_instituicao = '{$int_ref_ref_cod_instituicao}' AND ativo = '1'";
  507 +
  508 + $db = new clsBanco();
  509 + $resultado = array();
  510 +
  511 + $db->Consulta($sql);
  512 +
  513 + while ($db->ProximoRegistro()) {
  514 + $tupla = $db->Tupla();
  515 + $resultado[] = $tupla;
  516 + }
  517 +
  518 + if (count($resultado)) {
  519 + return $resultado;
  520 + }
  521 +
  522 + return FALSE;
  523 + }
  524 +
  525 + return FALSE;
  526 + }
  527 +
  528 + /**
  529 + * Retorna um array com os dados de um registro.
  530 + * @return array
  531 + */
  532 + function detalhe()
  533 + {
  534 + if (is_numeric($this->cod_servidor_alocacao)) {
  535 + $db = new clsBanco();
  536 + $db->Consulta( "SELECT {$this->_todos_campos} FROM {$this->_tabela} WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'" );
  537 + $db->ProximoRegistro();
  538 + return $db->Tupla();
  539 + }
  540 +
  541 + return FALSE;
  542 + }
  543 +
  544 + /**
  545 + * Retorna um array com os dados de um registro.
  546 + * @return array
  547 + */
  548 + function existe()
  549 + {
  550 + if (is_numeric($this->cod_servidor_alocacao)) {
  551 + $db = new clsBanco();
  552 + $db->Consulta("SELECT 1 FROM {$this->_tabela} WHERE cod_servidor_alocacao = '{$this->cod_servidor_alocacao}'");
  553 + $db->ProximoRegistro();
  554 + return $db->Tupla();
  555 + }
  556 +
  557 + return FALSE;
  558 + }
  559 +
  560 + /**
  561 + * Exclui um registro.
  562 + * @return bool
  563 + */
  564 + function excluir()
  565 + {
  566 + if (is_numeric($this->cod_servidor_alocacao) && is_numeric($this->ref_usuario_exc)) {
  567 + $this->ativo = 0;
  568 + return $this->edita();
  569 + }
  570 +
  571 + return FALSE;
  572 + }
  573 +
  574 + /**
  575 + * Exclui um registro baseado no período da alocação.
  576 + * @return bool
  577 + */
  578 + function excluir_horario()
  579 + {
  580 + if (is_numeric($this->ref_cod_servidor) && is_numeric($this->ref_ref_cod_instituicao) &&
  581 + is_numeric($this->ref_cod_escola) && is_numeric($this->periodo)
  582 + ) {
  583 + $db = new clsBanco();
  584 + $db->Consulta("DELETE FROM {$this->_tabela} WHERE ref_cod_servidor = '{$this->ref_cod_servidor}' AND ref_ref_cod_instituicao = '{$this->ref_ref_cod_instituicao}' AND ref_cod_escola = '{$this->ref_cod_escola}' AND periodo = '$this->periodo'");
  585 + return TRUE;
  586 + }
  587 +
  588 + return FALSE;
  589 + }
658 590  
659 591 /**
660 592 * Substitui a alocação entre servidores
... ... @@ -665,13 +597,14 @@ class clsPmieducarServidorAlocacao
665 597 * método, um objeto desta classe precisa estar instanciado com os atributos
666 598 * do servidor a ser substituido.
667 599 *
668   - * @param int $int_ref_cod_servidor_substituto Código do servidor que substituirá o atual
669   - * @return bool TRUE em caso de sucesso, FALSE caso contrário
  600 + * @param int $int_ref_cod_servidor_substituto Código do servidor que substituirá o atual
  601 + * @return bool TRUE em caso de sucesso, FALSE caso contrário
670 602 */
671   - public function substituir_servidor($int_ref_cod_servidor_substituto) {
  603 + function substituir_servidor($int_ref_cod_servidor_substituto)
  604 + {
672 605 if (is_numeric($int_ref_cod_servidor_substituto) &&
673   - is_numeric($this->ref_ref_cod_instituicao)) {
674   -
  606 + is_numeric($this->ref_ref_cod_instituicao)
  607 + ) {
675 608 $servidor = new clsPmieducarServidor($int_ref_cod_servidor_substituto,
676 609 NULL, NULL, NULL, NULL, NULL, NULL, $this->ref_ref_cod_instituicao);
677 610  
... ... @@ -682,8 +615,8 @@ class clsPmieducarServidorAlocacao
682 615  
683 616 if (is_numeric($this->ref_cod_servidor) && is_numeric($this->ref_ref_cod_instituicao) &&
684 617 is_numeric($this->ref_cod_escola) && is_numeric($this->periodo) &&
685   - is_string($this->carga_horaria)) {
686   -
  618 + is_string($this->carga_horaria)
  619 + ) {
687 620 $sql = "UPDATE %s SET ref_cod_servidor='%d' WHERE ref_cod_servidor = '%d' ";
688 621 $sql .= "AND ref_ref_cod_instituicao = '%d' AND ref_cod_escola = '%d' AND ";
689 622 $sql .= "carga_horaria = '%s' AND periodo = '%d'";
... ... @@ -701,113 +634,94 @@ class clsPmieducarServidorAlocacao
701 634 return FALSE;
702 635 }
703 636  
  637 + /**
  638 + * Define quais campos da tabela serão selecionados no método Lista().
  639 + */
  640 + function setCamposLista($str_campos)
  641 + {
  642 + $this->_campos_lista = $str_campos;
  643 + }
  644 +
  645 + /**
  646 + * Define que o método Lista() deverpa retornar todos os campos da tabela.
  647 + */
  648 + function resetCamposLista()
  649 + {
  650 + $this->_campos_lista = $this->_todos_campos;
  651 + }
  652 +
  653 + /**
  654 + * Define limites de retorno para o método Lista().
  655 + */
  656 + function setLimite($intLimiteQtd, $intLimiteOffset = NULL)
  657 + {
  658 + $this->_limite_quantidade = $intLimiteQtd;
  659 + $this->_limite_offset = $intLimiteOffset;
  660 + }
  661 +
  662 + /**
  663 + * Retorna a string com o trecho da query responsável pelo limite de
  664 + * registros retornados/afetados.
  665 + *
  666 + * @return string
  667 + */
  668 + function getLimite()
  669 + {
  670 + if (is_numeric($this->_limite_quantidade)) {
  671 + $retorno = " LIMIT {$this->_limite_quantidade}";
  672 + if (is_numeric($this->_limite_offset)) {
  673 + $retorno .= " OFFSET {$this->_limite_offset} ";
  674 + }
  675 + return $retorno;
  676 + }
  677 + return '';
  678 + }
704 679  
  680 + /**
  681 + * Define o campo para ser utilizado como ordenação no método Lista().
  682 + */
  683 + function setOrderby($strNomeCampo)
  684 + {
  685 + if (is_string($strNomeCampo) && $strNomeCampo ) {
  686 + $this->_campo_order_by = $strNomeCampo;
  687 + }
  688 + }
705 689  
706   - /**
707   - * Define quais campos da tabela serao selecionados na invocacao do metodo lista
708   - *
709   - * @return null
710   - */
711   - function setCamposLista( $str_campos )
712   - {
713   - $this->_campos_lista = $str_campos;
714   - }
715   -
716   - /**
717   - * Define que o metodo Lista devera retornoar todos os campos da tabela
718   - *
719   - * @return null
720   - */
721   - function resetCamposLista()
722   - {
723   - $this->_campos_lista = $this->_todos_campos;
724   - }
725   -
726   - /**
727   - * Define limites de retorno para o metodo lista
728   - *
729   - * @return null
730   - */
731   - function setLimite( $intLimiteQtd, $intLimiteOffset = null )
732   - {
733   - $this->_limite_quantidade = $intLimiteQtd;
734   - $this->_limite_offset = $intLimiteOffset;
735   - }
736   -
737   - /**
738   - * Retorna a string com o trecho da query resposavel pelo Limite de registros
739   - *
740   - * @return string
741   - */
742   - function getLimite()
743   - {
744   - if( is_numeric( $this->_limite_quantidade ) )
745   - {
746   - $retorno = " LIMIT {$this->_limite_quantidade}";
747   - if( is_numeric( $this->_limite_offset ) )
748   - {
749   - $retorno .= " OFFSET {$this->_limite_offset} ";
750   - }
751   - return $retorno;
752   - }
753   - return "";
754   - }
755   -
756   - /**
757   - * Define campo para ser utilizado como ordenacao no metolo lista
758   - *
759   - * @return null
760   - */
761   - function setOrderby( $strNomeCampo )
762   - {
763   - // limpa a string de possiveis erros (delete, insert, etc)
764   - //$strNomeCampo = eregi_replace();
765   -
766   - if( is_string( $strNomeCampo ) && $strNomeCampo )
767   - {
768   - $this->_campo_order_by = $strNomeCampo;
769   - }
770   - }
771   -
772   - /**
773   - * Retorna a string com o trecho da query resposavel pela Ordenacao dos registros
774   - *
775   - * @return string
776   - */
777   - function getOrderby()
778   - {
779   - if( is_string( $this->_campo_order_by ) )
780   - {
781   - return " ORDER BY {$this->_campo_order_by} ";
782   - }
783   - return "";
784   - }
785   -
786   - /**
787   - * Define campo para ser utilizado na clause group by
788   - *
789   - * @return null
790   - */
791   - function setGroupBy( $strNomeCampo )
792   - {
793   - if( is_string( $strNomeCampo ) && $strNomeCampo )
794   - {
795   - $this->_campo_group_by = $strNomeCampo;
796   - }
797   - }
798   -
799   - /**
800   - * Retorna a string com o trecho da query resposavel pelo group by
801   - *
802   - * @return string
803   - */
804   - function getGroupBy()
805   - {
806   - if( is_string( $this->_campo_group_by ) )
807   - {
808   - return " GROUP BY {$this->_campo_group_by} ";
809   - }
810   - return "";
811   - }
812   -}
813   -?>
814 690 \ No newline at end of file
  691 + /**
  692 + * Retorna a string com o trecho da query responsável pela Ordenação dos
  693 + * registros.
  694 + *
  695 + * @return string
  696 + */
  697 + function getOrderby()
  698 + {
  699 + if (is_string($this->_campo_order_by)) {
  700 + return " ORDER BY {$this->_campo_order_by} ";
  701 + }
  702 + return '';
  703 + }
  704 +
  705 + /**
  706 + * Define o campo para ser utilizado na agrupação no método Lista().
  707 + */
  708 + function setGroupby($strNomeCampo)
  709 + {
  710 + if (is_string($strNomeCampo) && $strNomeCampo ) {
  711 + $this->_campo_group_by = $strNomeCampo;
  712 + }
  713 + }
  714 +
  715 + /**
  716 + * Retorna a string com o trecho da query responsável pelo Agrupamento dos
  717 + * registros.
  718 + *
  719 + * @return string
  720 + */
  721 + function getGroupBy()
  722 + {
  723 + if (is_string($this->_campo_group_by)) {
  724 + return " GROUP BY {$this->_campo_group_by} ";
  725 + }
  726 + return '';
  727 + }
  728 +}
815 729 \ No newline at end of file
... ...