<?php
$sNomeIdJConsulta = 'iJan_LstCadFun';
$sNomeIdJEdt_Cad = 'iJan_EdtCadFun';
$nTmpFrmEnv = 300;
$bDir_Consult = CondPrivilegio(@$s_DireitosLst, $sNomeAcesso, 'C');
$bDir_Alterar = CondPrivilegio(@$s_DireitosLst, $sNomeAcesso, 'A');
$bDir_Incluir = CondPrivilegio(@$s_DireitosLst, $sNomeAcesso, 'I');
//
//  ** CADASTRO (NOVO/EDITA) **
If ( $sSubModulo=="EDT" ) {
    // Criar objeto Janela
    $oJanelaPrinc = New R_Janela();
    $oJanelaPrinc->sIdObj  = $sNomeIdJEdt_Cad; 
    $oJanelaPrinc->nTop    = 40;
    $oJanelaPrinc->nLeft   = 20;
    $oJanelaPrinc->nWidth  = 860;   // Largura
    $oJanelaPrinc->nHeight = 0;     // Altura
	$oJanelaPrinc->nLeft  += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
    $oJanelaPrinc->sTitulo = 'Cadastro funcionário';
	//
	$oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso."2.Teclas_F(this,event);";
    $sJavaTravarJ = "document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
	$oJanelaPrinc->sJavOnClickF =
	      $sJavaTravarJ.
		  "document.forms.fmECadFun.acao.value='FECHAR'; ".
		  "document.forms.fmECadFun.submit();".
		  "";
	//
	$bMontarJanela = true;
    $sFun_Codigo = @$_REQUEST['Fun_Codigo'];
	//
	// SALVAR
    If ( $sAcao=="SALVAR" ) {
	   $nFun_Codigo = 0;
	   $bGravarReg = False;
	   If ($bDir_Alterar) {
          $bGravarReg = True;
	   } Else {
          $sRet_Javs .=
            Info_Evento('ALERTA: Você não tem previlégio para alterar este funcionário.').
            "";
	   }
	   If ($bGravarReg) {
	      If ( STRLEN(@$_REQUEST['Fun_Apelid'])<2 ) {
	         $sRet_Javs .= Info_Evento('Alguns campos estão incompletos.');
	         $bGravarReg = False;
	      }
	   }
	   If ($bGravarReg) {
	      If ( $sFun_Codigo=="NOVO" ) {
	         $nFun_Codigo = SQLVarConfig(STRTOUPPER($sModulo)."_SEQCOD")+0;
	         $Row_CadFun = MYSQL_QUERY("SELECT * FROM cad_funcionario WHERE FUN_CODIGO=".($nFun_Codigo)." ;") or die(MYSQL_ERROR());
             If ($Row_CadFun = MYSQL_FETCH_ARRAY($Row_CadFun)) {
	            $sRet_Javs .= Info_Evento('Não posso gravar, codigo sequencial já existe ('.Str_Zero($nFun_Codigo,6).') .',1);
				$bGravarReg = False;
			 }
		  }
	   }
	   If ($bGravarReg) {
          $Row_CadFun = MYSQL_QUERY("SELECT * FROM cad_funcionario WHERE UPPER(FUN_APELID) = UPPER('".$_REQUEST['Fun_Apelid']."')".($sFun_Codigo<>"NOVO" ? " AND FUN_CODIGO<>'".$sFun_Codigo."'" : "")." ;") or die(MYSQL_ERROR());
          If ($Row_CadFun = MYSQL_FETCH_ARRAY($Row_CadFun)) {
             $sRet_Javs .= Info_Evento('Não posso gravar, este apelido já existe.',1);
             $bGravarReg = False;
          }
	   }
	   If ($bGravarReg && STRLEN(@$_REQUEST['Fun_SenGar'])>0) {
          $Row_CadFun = MYSQL_QUERY("SELECT * FROM cad_funcionario WHERE FUN_SENGAR = '".$_REQUEST['Fun_SenGar']."'".($sFun_Codigo<>"NOVO" ? " AND FUN_CODIGO<>'".$sFun_Codigo."'" : "")." ;") or die(MYSQL_ERROR());
          If ($Row_CadFun = MYSQL_FETCH_ARRAY($Row_CadFun)) {
             $sRet_Javs .= Info_Evento('Não posso gravar, senha do Garçom Express inválida.',1);
             $bGravarReg = False;
          }
	   }
	   If ($bGravarReg) {
	      If ( $sFun_Codigo=="NOVO" ) {
	         $nFun_Codigo = SQLVarConfig(STRTOUPPER($sModulo)."_SEQCOD")+0;
             SQLVarConfigG(STRTOUPPER($sModulo)."_SEQCOD", $nFun_Codigo+1 );
             MYSQL_QUERY(   // Cria um novo registro
               "INSERT INTO cad_funcionario(FUN_CODIGO,FUN_ATIVO_) VALUES (".$nFun_Codigo.",1); ") or die(MYSQL_ERROR());
	      } Else {
	         $nFun_Codigo = $sFun_Codigo+0;
	      }
	      $Row_CadFun = MYSQL_QUERY("SELECT * FROM cad_funcionario WHERE FUN_CODIGO=".($nFun_Codigo)." ;") or die(MYSQL_ERROR());
          If ($Row_CadFun = MYSQL_FETCH_ARRAY($Row_CadFun)) {
		     If ( (@$_REQUEST['Fun_EntPad']+0) ) {
                MYSQL_QUERY("UPDATE cad_funcionario SET FUN_ENTPAD=0;");
			 }
             MYSQL_QUERY(   // Atualiza o registro
               "UPDATE cad_funcionario SET ".
                 'FUN_NOMECP=0x'.BIN2HEX(UTF8_DECODE(@$_REQUEST['Fun_NomeCP'])).','.
                 'FUN_APELID="'.RemoveAcentos(@$_REQUEST['Fun_Apelid']).'",'.
                 'FUN_NUMCPF="'.@$_REQUEST['Fun_NumCPF'].'",'.
				 (STRLEN(@$_REQUEST['Fun_SenhaN'])>0 ? 'FUN_SENHA_="'.@$_REQUEST['Fun_SenhaN'].'",' : '').
				 'FUN_ENTPAD="'.(@$_REQUEST['Fun_EntPad']+0).'",'.
				 'FUN_SENGAR="'.@$_REQUEST['Fun_SenGar'].'",'.
                 'FUN_CODDIR="'.@$_REQUEST['Fun_CodDir'].'",'.
                 'FUN_TELEF1="'.@$_REQUEST['Fun_Telef1'].'",'.
                 'FUN_PERCOM="'.@$_REQUEST['Fun_PerCom'].'",'.
				 'FUN_ENTMOT="'.(@$_REQUEST['Fun_EntMot']+0).'",'.
				 'FUN_GARFUN="'.(@$_REQUEST['Fun_GarFun']+0).'",'.
                 'FUN_VALSAL=' .(STR_REPLACE(",",".",@$_REQUEST['Fun_ValSal'])+0).','.
                 'FUN_DATAAD="'.ConvertDataBRUS(@$_REQUEST['Fun_DataAd']).'",'.
                 'FUN_OBSPET='.SQL_Bin(UTF8_DECODE(@$_REQUEST['Fun_ObsPeT'])).','.
                 'FUN_OBSLIV='.SQL_Bin(UTF8_DECODE(@$_REQUEST['Fun_ObsLiv'])).' '.
               "WHERE FUN_CODIGO=".($nFun_Codigo)."; ") or die(MYSQL_ERROR());
	         // atualizar registro
	      } Else {
             // Erro: registro não existe
			 $sRet_Javs .= Info_Evento('Registro não existe.',1);
	      }
          $sRet_Javs .= "document.location.href = './car_js.php?mod=".$sModulo."&submod=".$sSubModulo."&acao=FECHAR&nomeacs=".$sNomeAcesso."&acaoAnt=".$sAcao."';";
       }
	   $bMontarJanela = false;
    //
    // FECHAR
    } ElseIf ( $sAcao=="FECHAR" ) {
       $sRet_Javs .= 
	      "parent.RmElem('".$oJanelaPrinc->sIdObj."'); ".
		  "parent.Disabled_In_Elems('".$sNomeIdJConsulta."',false);".
		  "parent.document.getElementById('".$sNomeIdJConsulta."_Travar').style.visibility='hidden';".
    	  'parent.document.getElementById("iCadFun_PChave").focus();'.
		  (@$_REQUEST['acaoAnt']=='SALVAR' ? "parent.Car_".$sNomeAcesso."1.P_Atu();" : '').
		  "";
	   $bMontarJanela = false;
	//
	// NOVO REGISTRO
	} ElseIf ( $sAcao=="NV" ) {
	   $sFun_Codigo = 'NOVO';
	//
	// PUXAR REGISTRO
	} Else {
	   If (STRLEN($sFun_Codigo)==0) {
	      $bMontarJanela = False;
	      $sAcao = 'FECHAR';
          $sRet_Javs .=
		     "parent.document.getElementById('".$sNomeIdJConsulta."_Travar').style.visibility='hidden';".
	         Info_Evento('Selecione um funcionario.');
	   } Else {
          $Row_CadFun = MYSQL_QUERY("SELECT * FROM cad_funcionario WHERE FUN_CODIGO=".($sFun_Codigo+0)." ;") or die(MYSQL_ERROR());
          If (! $Row_CadFun = MYSQL_FETCH_ARRAY($Row_CadFun)) {
	         $Row_CadFun = ARRAY();
	      }
	   }
       //
	}
	If ($bMontarJanela) {
	   //
	   $oJanelaPrinc->aIdsObjList =
	      ARRAY(
		    'iCadEFun_Apelido','iCadEFun_NomeCP','iCadEFun_NomeCP','iCadEFun_NumCPF','iCadEFun_Telef1','iCadEFun_PerCom',
			'iCadEFun_SenhaN' ,'iCadEFun_SenhaC','iCadEFun_SenGar','iCadEFun_EntPad','iCadEFun_EntMot' ,'iCadEFun_CodDir','iCadEFun_GarFun',
			'iCadEFun_ValSal' ,'iCadEFun_DataAd','iCadEFun_ObsPeT','iCadEFun_ObsLiv'
		  );
	   //
       // Tela HTML
	   //
       $sHTML_ComboDir = '<option value="0">- Nenhum grupo selecionado -</option>';
       $RowsT_CadDir = MYSQL_QUERY( "SELECT * FROM cad_direitos WHERE DIR_CODIGO>0 ORDER BY DIR_DESCRI ASC" ) Or Die(MYSQL_ERROR());
       While ($RowT_CadDir = MYSQL_FETCH_OBJECT($RowsT_CadDir)) {
           $sHTML_ComboDir .= '<option value="'.$RowT_CadDir->DIR_CODIGO.'" '.($RowT_CadDir->DIR_CODIGO==(@$Row_CadFun['FUN_CODDIR']+0) ? 'selected' : '').'>'.$RowT_CadDir->DIR_CODIGO.' - '.$RowT_CadDir->DIR_DESCRI.($RowT_CadDir->DIR_ATIVO_ ? '' : ' (INATIVO)').'</option>';
       }
	   
	   $sLinha_Risco = 
	      //'<div style="height:10px"></div>'.
	      '<div style="width:100%; height:4px; background-color:#91D8F8;"></div>'.
	      '<div style="height:10px"></div>';

	   //
	   $sFun_Codigo = Str_Zero($sFun_Codigo, 4);
       $sRet_TelaJ_HTML =
    	  $oJanelaPrinc->MontaJanHTML(True).
          '<form name="fmECadFun" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.'3">'.
           '<input name="mod" type="hidden" value="'.$sModulo.'">'.
           '<input name="submod" type="hidden" value="'.$sSubModulo.'">'.
           '<input name="acao" type="hidden" value="">'.
    	   '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
       	   '<table width="100%" border="0">'.
		     '<tr>'.
			    '<td width="4px" height="24px">&nbsp;</td>'.
       	        //'<td width="4px" height="24px">&nbsp;</td>'.
       	        '<td align="right" width="90px">'.
		          'Código:'.
		   	    '</td>'.
			    '<td align="left">'.
				   '<input id="iCadEFun_Codigo" name="Fun_Codigo" type="text" value="'.$sFun_Codigo.'" readonly="readonly" style="width:40px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
				'<td width="74px" height="24px">&nbsp;</td>'.
       	        '<td align="right" width="60px">'.
		           'Apelido:'.
			    '</td>'.
				'<td align="left">'.
				   '<input id="iCadEFun_Apelido" name="Fun_Apelid" type="text" value="'.@$Row_CadFun['FUN_APELID'].'" maxlength="12" style="width:60px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
				'<td width="74px" height="24px">&nbsp;</td>'.
			    '<td align="right" width="90px">'.
			       'Nome Completo:'.
			    '</td>'.
				'<td align="right">'.
			       '<input id="iCadEFun_NomeCP" name="Fun_NomeCP" type="text" value="'.@$Row_CadFun['FUN_NOMECP'].'" maxlength="60" style="width:320px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
		        '</td>'.
       	        '<td width="4px" height="24px">&nbsp;</td>'.
		     '</tr>'.
		  '</table>'.
		  '<table width="100%" border="0">'.
		     '<tr>'.
			 '<td width="4px" height="24px">&nbsp;</td>'.
       	        //'<td>&nbsp;</td>'.
       	        '<td align="right" width="90px">'.
		        //'<span style="display:inline-block; width:14px;">&nbsp;</span>'.
		            'CPF:'.
			    '</td>'.
			    '<td align="left" width="116px">'.
				   '<input id="iCadEFun_NumCPF" name="Fun_NumCPF" type="text" value="'.@$Row_CadFun['FUN_NUMCPF'].'" maxlength="11" style="width:90px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
       	        '<td align="right" width="60px">'.
		           'Telefone:'.
			    '</td>'.
				'<td align="left">'.
			       '<input id="iCadEFun_Telef1" name="Fun_Telef1" type="text" value="'.@$Row_CadFun['FUN_TELEF1'].'" maxlength="12" style="width:90px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
			    '</td>'.
			//'<span style="display:inline-block; width:27px;"></span>'.
		        '<td align="right" width="160px">'.
			       'Comissão como garçom:'.
			    '</td>'.
				'<td width="70px" align="right">'.
			       '<input id="iCadEFun_PerCom" name="Fun_PerCom" type="text" value="'.@$Row_CadFun['FUN_PERCOM'].'" maxlength="7" style="width:50px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
			       '&nbsp;%'.
       	        '</td>'.
		        '<td width="4px" height="24px">&nbsp;</td>'.
       	     '</tr>'.
		  '</table>'.
       	  '<table width="100%" border="0">'.
		     '<tr>'.
			    '<td width="4px" height="24px">&nbsp;</td>'.
       	        '<td align="right" width="90px">'.
		           'Senha:'.
				'</td>'.
				'<td align="left">'.
			       '<input id="iCadEFun_SenhaN" type="password" name="Fun_SenhaN" value="'.($bDir_Alterar ? @$Row_CadFun['FUN_SENHA_'] : '').'" maxlength="15" style="width:90px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
				'<td width="74px" height="24px">&nbsp;</td>'.
       	        //'<td align="right" width="202px">'.
		        //   'Confirmar senha:&nbsp;&nbsp;'.
			    //'</td>'.	
				//'<td align="left">'.
			    //   '<input id="iCadEFun_SenhaC" type="password" name="Fun_SenhaC" value="'.($bDir_Alterar ? @$Row_CadFun['FUN_SENHA_'] : '').'" maxlength="15" style="width:90px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        //'</td>'.
       	        '<td align="right" width="192px">'.
		           'Senha no Garcom Express:&nbsp;&nbsp;'.
			    '</td>'.
			    '<td align="right" width="90px">'.
			       '<input id="iCadEFun_SenGar" type="password" name="Fun_SenGar" value="'.($bDir_Alterar ? @$Row_CadFun['FUN_SENGAR'] : '').'" maxlength="15" style="width:90px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
       	        '<td width="4px" height="24px">&nbsp;</td>'.
       	     '</tr>'.
			 '<tr>'.
			    '<td width="4px" height="24px">&nbsp;</td>'.
			    '<td align="right" width="90px">'.
		           'Confirmar senha:&nbsp;&nbsp;'.
			    '</td>'.	
				'<td align="left">'.
			       '<input id="iCadEFun_SenhaC" type="password" name="Fun_SenhaC" value="'.($bDir_Alterar ? @$Row_CadFun['FUN_SENHA_'] : '').'" maxlength="15" style="width:90px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
       	     '</tr>'.
		  '</table>'.
		  //
		  $sLinha_Risco.
       	  '<table width="100%" border="0">'.
		     '<tr>'.
       	        '<td width="2px" height="24px">&nbsp;</td>'.
       	        '<td align="left" width="180px">'.
		           'Entregador padrão&nbsp;'.
			    //'</td>'.
				//'<td align="left">'.
				   '<select id="iCadEFun_EntPad" name="Fun_EntPad">'.
			          '<option value="0"'.(@$Row_CadFun['FUN_ENTPAD'] ? '' : ' selected').'>Não</option>'.
			          '<option value="1"'.(@$Row_CadFun['FUN_ENTPAD'] ? ' selected' : '').'>Sim</option>'.
			       '</select>'.
       	        '</td>'.
       	        '<td align="left" width="380px">'.
		           'Motoqueiro/Entregador&nbsp;'.
			    //'</td>'.
				//'<td align="left">'.
				   '<select id="iCadEFun_EntMot" name="Fun_EntMot">'.
			          '<option value="0"'.(@$Row_CadFun['FUN_ENTMOT'] ? '' : ' selected').'>Não</option>'.
			          '<option value="1"'.(@$Row_CadFun['FUN_ENTMOT'] ? ' selected' : '').'>Sim</option>'.
			       '</select>'.
       	           '<span style="color:#FF0000;">'.
				      '&nbsp;&nbsp;'.
	  			      '* Usado na tela de expedição ecook plus'.
				   '</span>'.
				'</td>'.
			    '<td align="right">'.  
				   'Grupo de acesso:&nbsp;&nbsp;'.
				   '<select id="iCadEFun_CodDir" name="Fun_CodDir">'.
			          $sHTML_ComboDir.
			       '</select>'.
       	        '</td>'.
       	        //'<td width="166px">&nbsp;</td>'.
       	        //'<td width="4px" height="24px">&nbsp;</td>'.
		     '</tr>'.
		  '</table>'.
		  '<table width="100%" border="0">'.
		     '<tr>'.
       	        //'<td width="2px" height="24px">&nbsp;</td>'.
       	        '<td align="left" width="140px">'.
		           'Garcom/Funcionário&nbsp;'.
			      '<select id="iCadEFun_EntMot" name="Fun_GarFun">'.
			          '<option value="0"'.(@$Row_CadFun['FUN_GARFUN'] ? '' : ' selected').'>Não</option>'.
			          '<option value="1"'.(@$Row_CadFun['FUN_GARFUN'] ? ' selected' : '').'>Sim</option>'.
			       '</select>'.
       	           '<span style="color:#FF0000;">'.
				      '&nbsp;&nbsp;'.
	  			      '* Somente plus'.
				   '</span>'.
				'</td>'.
			 '</tr>'.  
		  '</table>'.
		  $sLinha_Risco.
		  '<table width="100%" border="0">'.
		     '<tr>'.
       	        '<td width="2px" height="24px">&nbsp;</td>'.
       	        '<td align="left" width="250px">'.
		           'Salário R$ :&nbsp;'.
			       '<input id="iCadEFun_ValSal" type="text" name="Fun_ValSal" value="'.FormatoMoeda(@$Row_CadFun['FUN_VALSAL']).'" maxlength="16" style="width:90px; height:22px; text-align:right; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
				'</td>'.
       	        '<td align="left" width="250px">'.
		           'Data de admissão :&nbsp;'.
			       '<input id="iCadEFun_DataAd" type="text" name="Fun_DataAd" value="'.ConvertDataUSBR(@$Row_CadFun['FUN_DATAAD']).'" maxlength="10" style="width:77px; height:22px; text-align:center; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
				'</td>'.
				'<td>'.
				'</td>'.
			 '</tr>'.  
		  '</table>'.
		  //
		  '<table width="100%" border="0">'.
		     '<tr>'.
       	        '<td width="4px" height="24px">&nbsp;</td>'.
       	        '<td align="left">'.
		           'Período de trabalho:'.
				   '<br>'.
				   '<textarea id="iCadEFun_ObsPeT" name="Fun_ObsPeT" style="width:99.5%; height:70px; resize:none; text-align:left; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
				   '</textarea>'.
				'</td>'.
			 '</tr>'.  
		  '</table>'.
		  //
		  '<table width="100%" border="0">'.
		     '<tr>'.
       	        '<td width="4px" height="24px">&nbsp;</td>'.
       	        '<td align="left">'.
		           'Digitação livre de observações:'.
				   '<br>'.
				   '<textarea id="iCadEFun_ObsLiv" name="Fun_ObsLiv" style="width:99.5%; height:70px; resize:none; text-align:left; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
				   '</textarea>'.
				'</td>'.
			 '</tr>'.  
		  '</table>'.
		  //
          '</form>'.
       	  '<table width="100%"></tr>'.
       	   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
       	   '</td>'.
       	   '<td>'.
       	    HTML_Botao( 3, 'CadEFun_BT_Svl', "document.forms.fmECadFun.acao.value='SALVAR'; ".
    	                                     "document.forms.fmECadFun.submit();"
			             , 'Salvar (F10)','images/btimg_salvar.png').'&nbsp;&nbsp;'.
       	   '</td>'.
       	   '<td width="114px" align="left">'.
       	    HTML_Botao( 3, 'CadEFun_BT_Fec', $oJanelaPrinc->sJavOnClickF
                         , 'Sair (ESC)' ,'images/btimg_fechar.png').
       	   '</td>'.
		   '<td width="4px" height="24px">&nbsp;</td>'.
       	  '</tr></table>'.
    	  $oJanelaPrinc->MontaJanHTML(False);
       //
       $sRet_JavsPos .=
    	  'parent.document.getElementById("iCadEFun_ObsPeT").value = '.JAVA_CharCode(@$Row_CadFun['FUN_OBSPET']).';'.
    	  'parent.document.getElementById("iCadEFun_ObsLiv").value = '.JAVA_CharCode(@$Row_CadFun['FUN_OBSLIV']).';'.
    	  'parent.document.getElementById("iCadEFun_Apelido").focus();'.
		  ($bDir_Alterar ? '' :
		    "parent.document.getElementById('CadEFun_BT_Svl').style.display='none';"
		  ).
		  //
		  "function Teclas_F( Objeto, Evento ) {".
             "vNumTecla = parent.Tecla_Apertada(Evento);".
             "if ( vNumTecla==121) { ".        //  ** [F10] **         // (Gravar)
			     "if ( parent.document.getElementById('CadEFun_BT_Svl').style.display != 'none' ) {".
                     "setTimeout( parent.document.getElementById('CadEFun_BT_Svl').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==116) { ".  // ** [F5] **         Não atualizar
                 //
		     "} else if ( vNumTecla==27) { ".   // ** [ESC] **         // (SAIR)
                 "setTimeout( parent.document.getElementById('CadEFun_BT_Fec').onclick , 100);".
		     "} else if ( vNumTecla==13) { ".   // ** [ENTER] **
				 "sTempId = parent.Proximo_TabObj(parent.document.getElementById('".$oJanelaPrinc->sIdObj."'),parent.sIdHasFocus);".
				 "if ( sTempId.length>0 ) {".
				     "parent.document.getElementById(sTempId).focus();".
				 "} else {".
    	             'parent.document.getElementById("iCadEFun_Apelido").focus();'.
				 "}".
			     //
			 "} else {".
			     "return true;".
			 "}".
			 "return false;".
		  '}'.
		  //
    	 "";
       //
	}
//
//  ** CONSULTA **
} Else {
    // Criar objeto Janela
    $oJanelaPrinc = New R_Janela();
    $oJanelaPrinc->sIdObj  = $sNomeIdJConsulta; 
    $oJanelaPrinc->nTop    = 5;
    $oJanelaPrinc->nLeft   = 20;
    $oJanelaPrinc->nWidth  = 860;   // Largura
    $oJanelaPrinc->nHeight = 0;     // Altura
  	$oJanelaPrinc->nLeft  += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
    $oJanelaPrinc->sTitulo = 'Funcionários';
	//$oJanelaPrinc->sJavOnClick = "document.getElementById('iCadFun_PChave').focus();";
	$oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso."1.Teclas_F(this,event);";
    //
	$sJavaTravarJ = "document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
	$oJanelaPrinc->sJavOnClickF = 
	    $sJavaTravarJ.
		"document.forms.fmPCadFun.acao.value='FECHAR'; ".
		"document.forms.fmPCadFun.submod.value=''; ".
		"document.forms.fmPCadFun.Fun_PChave.value=''; ".
		"document.forms.fmPCadFun.Fun_NumCam.value=''; ".
		"document.forms.fmPCadFun.submit();".
		"";
	//
	//
    // Criar objeto GRID
    $oTabelaRegs = New Pad_GridPesq();
    $oTabelaRegs->sNomeTabela  = 'cad_funcionario';
    $oTabelaRegs->sIdObjTabela = 'iQdr_ListaFun';
    $oTabelaRegs->GLstCampos( 'FUN_APELID,Apelido,100px;'.
                              'FUN_NOMECP,Nome Completo;'.
    			              'FUN_NUMCPF,CPF,100px,PFJ;'.
    			              'FUN_TELEF1,Telefone,100px,TEL;' );
    $oTabelaRegs->sCampoIndice = 'FUN_CODIGO';
    $oTabelaRegs->nWidth  = $oJanelaPrinc->nWidth;
    $oTabelaRegs->nHeight = 340;    // Altura
    $oTabelaRegs->sCampoOnClick  = "Car_".$sNomeAcesso."1.P_Sel(<NUMCAM>); Car_".$sNomeAcesso."1.P_Atu();";
    $oTabelaRegs->sLinhaOnClick  = "Car_".$sNomeAcesso."1.PRow_Sel(<QTDCOL>,<SELLIN>);";
    $oTabelaRegs->sLinhaOnDblClk = $sJavaTravarJ.
	                               "Car_".$sNomeAcesso."1.Pesq_Editar();";
    $oTabelaRegs->sJavSelectReg = "sSelIndice = S_Indice;".
	                              "if (parseInt(sSelIndice)>0) {".
								      "if (parent.document.forms.fmPCadFun.Fun_Ativos.value=='0') {".
									      ($bDir_Alterar ?
				                             "parent.document.getElementById('CadCFun_BT_Itv').style.display='inline-block';"
										  : '').
				                          "parent.document.getElementById('CadCFun_BT_Atv').style.display='none';".
									   "} else if (parent.document.forms.fmPCadFun.Fun_Ativos.value=='1') {".
									      "parent.document.getElementById('CadCFun_BT_Itv').style.display='none';".
									      ($bDir_Alterar ?
                                             "parent.document.getElementById('CadCFun_BT_Atv').style.display='inline-block';"
										  : '').
								       "}".
		                               "parent.document.getElementById('CadCFun_BT_Edt').style.display='inline-block';".
								   "} ".
	                              'parent.document.getElementById("iCadFun_PChave").focus();';
    //
    // MONTAR LISTA DE CADASTROS
    If ( $sAcao=="LISTAR" ) {
	   If ($bDir_Consult) {
          $sP_PChave = @$_REQUEST['Fun_PChave'];
          $nP_NumCam = @$_REQUEST['Fun_NumCam']+0;
	      //$bP_Ativos = (@$_REQUEST['Fun_Ativos']+0)>0;
		  $nP_Ativos  = @$_REQUEST['Fun_Ativos']+0; //0-ativos 1-inativos 2 -todos
          $nIniReg = 0;
          $nQtdReg = 80;
          // Montar condição para a pesquisa
	      $sParamSQL = '';
		  $sWhereSQL = '';
		  If ($nP_Ativos == 0) { // ativos
		     $sWhereSQL =' FUN_ATIVO_';
		  } ElseIf ($nP_Ativos == 1) { //inativos
		     $sWhereSQL =' FUN_ATIVO_=0';
		  } 
		  
		  
		  //$sWhereSQL = 'FUN_ATIVO_='.($bP_Ativos+0).' ';
          If ( $nP_NumCam==0 ) { $nP_NumCam=2; }
    	  $aLstCampo = EXPLODE(',',@$oTabelaRegs->aLstCampos[$nP_NumCam-1]);
   	      If ( STRLEN(@$aLstCampo[0])>0 ) {
             If ( STRLEN($sP_PChave)>0 ) {
			    If (STRLEN($sWhereSQL)>0) { $sWhereSQL .= ' AND ';}
    	        //$sWhereSQL .= 'AND '.$aLstCampo[0].' LIKE "%'.$sP_PChave.'%" ';
				$sWhereSQL .= $aLstCampo[0].' LIKE "%'.$sP_PChave.'%" ';
    	     }
			 $sParamSQL .= ' ORDER BY '.$aLstCampo[0].' ASC ';
          }
		  If (STRLEN($sWhereSQL)>0) { $sWhereSQL = ' WHERE '.$sWhereSQL; }  
          $oTabelaRegs->sBDParametros = $sWhereSQL.$sParamSQL.'LIMIT '.$nIniReg.','.$nQtdReg;
          // Tabela
          $sRet_TelaJ_HTML = $oTabelaRegs->MontaTabelaHTML();
          // Java
          $sRet_Javs .=
             "var iQdr_ListaCli = parent.document.getElementById('".$oTabelaRegs->sIdObjTabela."');".
    	     'iQdr_ListaCli.innerHTML = '.JAVA_CharCode($sRet_TelaJ_HTML).';'.
    	     '';
          // Java posterior
          $sRet_JavsPos .=
             'parent.Car_'.$sNomeAcesso.'1.'.$oTabelaRegs->sNomeTabela.'_Rowsel = 1;'.
             'parent.Car_'.$sNomeAcesso.'1.P_Sel('.$nP_NumCam.');'.
    	     '';
          $sRet_TelaJ_HTML = '';
	   }
    //
    // FECHAR
    } ElseIf ( $sAcao=="FECHAR" ) {
       $sRet_Javs .=
		  'parent.document.getElementById("dv_MenuL_Barra").style.visibility="visible";'.
	      "parent.RmElem('".$oJanelaPrinc->sIdObj."');";
    //
    // ATIVAR REGISTRO
    } ElseIf ( $sAcao=="ATIVAR" ) {
	   $sRet_Javs .=
	      'parent.JanEspera(false);'.
		  '';
	   If ($bDir_Alterar) {
	      If ((@$_REQUEST['Fun_Codigo']+0)>0) {
             MYSQL_QUERY("UPDATE cad_funcionario SET FUN_ATIVO_=1 WHERE FUN_CODIGO=".(@$_REQUEST['Fun_Codigo']+0)." ;") or die(MYSQL_ERROR());
	         $sRet_Javs .=
		        'parent.Car_'.$sNomeAcesso.'1.PRow_Sel('.($oTabelaRegs->nQtdCampos-1).',1);'.
		   	    'parent.Car_'.$sNomeAcesso.'1.P_Atu();';
	      }
	   } Else {
	      $sRet_Javs .= Info_Evento('ALERTA: Sem previlégio de alteração para ativar.');
	   }
    //
    // INATIVAR REGISTRO
    } ElseIf ( $sAcao=="INATIVAR" ) {
	   $sRet_Javs .=
	      'parent.JanEspera(false);'.
		  '';
	   If ($bDir_Alterar) {
	      If ((@$_REQUEST['Fun_Codigo']+0)>0) {
             MYSQL_QUERY("UPDATE cad_funcionario SET FUN_ATIVO_=0 WHERE FUN_CODIGO=".(@$_REQUEST['Fun_Codigo']+0)." ;") or die(MYSQL_ERROR());
	         $sRet_Javs .= 
		        'parent.Car_'.$sNomeAcesso.'1.PRow_Sel('.($oTabelaRegs->nQtdCampos-1).',1);'.
		        'parent.Car_'.$sNomeAcesso.'1.P_Atu();'.
                '';
	      }
	   } Else {
	      $sRet_Javs .= Info_Evento('ALERTA: Sem previlégio de alteração para inativar.');
	   }
    //
    // JANELA TELA PRINCIPAL
    } Else {
	   //
	   $sJavClkAtiv =
          "JanEspera(true, 'Ativando registro... Aguarde...');".
          "setTimeout( function() { ".
             "document.forms.fmPCadFun.acao.value='ATIVAR'; ".
			 "document.forms.fmPCadFun.submod.value=''; ".
             "document.forms.fmPCadFun.Fun_Codigo.value=Car_".$sNomeAcesso."1.sSelIndice;".
    	     "document.forms.fmPCadFun.submit();".
          "}, ".$nTmpFrmEnv.");".
		  "";
	   //
	   // Confirma a inativação do registro
	   $sJavClkInat =
		  JAVA_CharCode(
		     "if (_NUM_BOT_==1) { ".
                 "JanEspera(true, 'Inativando registro... Aguarde...');".
                 "setTimeout( function() { ".
                    "document.forms.fmPCadFun.acao.value='INATIVAR'; ".
                    "document.forms.fmPCadFun.submod.value=''; ".
                    "document.forms.fmPCadFun.Fun_Codigo.value=Car_".$sNomeAcesso."1.sSelIndice;".
                    "document.forms.fmPCadFun.submit();".
                 "}, ".$nTmpFrmEnv.");".
		  	 "}"
		   );
	   $sJavClkInat =
		  "sIdHasFocus='iCadFun_PChave';".
	      "Qdr_Prompt_H(true,'Tem certeza que deseja INATIVAR este funcionário?',".$sJavClkInat.",['Sim','Não']); ";
	   //
       // Tela HTML
       $sRet_TelaJ_HTML =
    	  $oJanelaPrinc->MontaJanHTML(True).
          '<form name="fmPCadFun" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.'2">'.
           '<input name="mod" type="hidden" value="'.$sModulo.'">'.
           '<input name="submod" type="hidden" value="">'.
           '<input name="acao" type="hidden" value="">'.
    	   '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
    	   '<input name="Fun_PChave" type="hidden" value="">'.
           '<input name="Fun_Ativos" type="hidden" value="0">'.
    	   '<input name="Fun_NumCam" type="hidden" value="">'.
    	   '<input name="Fun_Codigo" type="hidden" value="">'.
          '</form>'.
       	  '<table width="100%">'.
		     '<tr>'.
       	        '<td width="4px" height="10px" align="left">'.
				   '&nbsp;'.
				'</td>'.
       	        '<td align="left" width="70px" style="font-size:14px;">'.
       	           'Procurar por: '.
       	        '</td>'.
       	        '<td align="left" style="font-size:14px;">'.
		           'Mostrar'.
			    '</td>'.
		     '</tr>'.
			 '<tr>'.
			    '<td width="4px" height="10px" align="left">'.
				   '&nbsp;'.
			    '</td>'.
			    '<td align="left" width="300px">'.
       	           '<input id="iCadFun_PChave" type="text" maxlength="30" style="width:98%; height:24px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	        '</td>'.
				'<td align="left">'.
			       '<select id="sl_CadFun_Ativos" onchange="Car_'.$sNomeAcesso.'1.P_Atu();" style="font-size:14px;border-width: 1px; border-style: solid; border-color: #0099FF;margin-top:-1px;height:20px;">'.			
				      '<option value="0">Ativos&nbsp;&nbsp;&nbsp;</option>'.
				      '<option value="1">Inativos&nbsp;&nbsp;&nbsp;</option>'.
					  '<option value="2">Todos&nbsp;&nbsp;&nbsp;</option>'.				  
			       '</select>'.	
				'</td>'.
			    '<td align="right" width="70px">'.
       	           HTML_Botao( 3, 'CadFun_BT_Pro', 'Car_'.$sNomeAcesso.'1.P_Atu();'
		                        , 'Procurar'     ,'images/btimg_lupa.png').
       	        '</td>'.
       	 	 '</tr>'.
		  '</table>'.
		  //'<table width="100%"></tr>'.
       	  // '<td width="4px" height="10px" align="left">&nbsp;</td>'.
       	  // '<td align="left" width="70px">'.
       	  //  'Procurar por: '.
       	  // '</td>'.
       	  // '<td align="left" width="300px">'.
       	  //  '<input id="iCadFun_PChave" type="text" maxlength="30" style="width:98%; height:24px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	  // '</td>'.
       	  // '<td align="center">'.
		  //  '<span onclick="Car_'.$sNomeAcesso.'1.P_Ativos();" style="cursor:pointer; font-weight:bold; font-size:13px; text-decoration:underline;">'.
		  //  'Mostrar somente os <span id="PCadFun_Ativos">inativos</span>'.
		  //	'</span>'.
       	  //  '</td>'.
       	  //  '<td align="right" width="70px">'.
       	  //  HTML_Botao( 3, 'CadFun_BT_Pro', 'Car_'.$sNomeAcesso.'1.P_Atu();'
		  //              , 'Procurar'     ,'images/btimg_lupa.png').
       	  // '</td>'.
       	  //'</tr></table>'.
    	  $oTabelaRegs->MontaDivHtml().
       	  '<table width="100%"></tr>'.
       	   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
       	   '</td>'.
       	   '<td>'.
       	    HTML_Botao( 3, 'CadCFun_BT_Nov', $sJavaTravarJ.
			                                 "document.forms.fmPCadFun.acao.value='NV'; ".
			                                 "document.forms.fmPCadFun.submod.value='EDT'; ".
    	                                     "document.forms.fmPCadFun.submit();"
			             , 'Novo (F6)'   ,'images/btimg_novo.png').'&nbsp;&nbsp;'.
       	    HTML_Botao( 3, 'CadCFun_BT_Edt', $sJavaTravarJ.
			                                 "Car_".$sNomeAcesso."1.Pesq_Editar();"
			             , ($bDir_Alterar ? 'Editar' : 'Visualizar').' (F7)' ,'images/btimg_editar.png',130).'&nbsp;&nbsp;'.
       	    HTML_Botao( 3, 'CadCFun_BT_Itv', $sJavClkInat
			             , 'Inativar (F8)','images/btimg_remover.png',110).
       	    HTML_Botao( 3, 'CadCFun_BT_Atv', $sJavClkAtiv
			             , 'Ativar (F8)','images/btimg_ativar.png').'&nbsp;&nbsp;'.
       	   '</td>'.
       	   '<td width="120px" align="left">'.
       	    HTML_Botao( 3, 'CadCFun_BT_Fch', $oJanelaPrinc->sJavOnClickF
                         , 'Sair (ESC)' ,'images/btimg_fechar.png').
       	   '</td>'.
       	  '</tr></table>'.
    	  $oJanelaPrinc->MontaJanHTML(False);
       //
       $sRet_Javs .=
		  'parent.document.getElementById("dv_MenuL_Barra").style.visibility="hidden";'.
	      "var sSelIndice='';".
          "function P_Atu() {".
            "sSelIndice='0';".
		    $oTabelaRegs->MontaJavaAgu().
		    "parent.document.getElementById('CadCFun_BT_Edt').style.display='none';".
		    "parent.document.getElementById('CadCFun_BT_Itv').style.display='none';".
		    "parent.document.getElementById('CadCFun_BT_Atv').style.display='none';".
         	"parent.document.forms.fmPCadFun.acao.value='LISTAR'; ".
            "parent.document.forms.fmPCadFun.submod.value=''; ".
         	"parent.document.forms.fmPCadFun.Fun_PChave.value=parent.document.getElementById('iCadFun_PChave').value; ".
         	"parent.document.forms.fmPCadFun.Fun_Ativos.value=parent.document.getElementById('sl_CadFun_Ativos').value;".
			"parent.document.forms.fmPCadFun.Fun_NumCam.value=nPesq_CampoSel+''; ".
         	"setTimeout( function() { parent.document.forms.fmPCadFun.submit(); }, 100);".
          '}'.
		  'function Pesq_Editar() {'.
            "parent.document.forms.fmPCadFun.acao.value='';".
            "parent.document.forms.fmPCadFun.submod.value='EDT';".
            "parent.document.forms.fmPCadFun.Fun_Codigo.value=sSelIndice;".
            "parent.document.forms.fmPCadFun.submit();".
		  '}'.
		  "var bExbAtivos=true;".
		  //'function P_Ativos() {'.
		  //  "var obj = parent.document.getElementById('PCadFun_Ativos');".
		  //	"if (bExbAtivos) {".
          //       "parent.document.forms.fmPCadFun.Fun_Ativos.value='0'; ".
		  //	    "obj.innerHTML = 'ativos';".
		  //		"bExbAtivos = false;".
		  //	"} else {".
          //       "parent.document.forms.fmPCadFun.Fun_Ativos.value='1'; ".
		  //	    "obj.innerHTML = 'inativos';".
		  //		"bExbAtivos = true;".
		  //	"}".
		  //	"P_Atu();".
		  // '}'.
          $oTabelaRegs->MontaJavaPri().
          '';
       // Java posterior
       $sRet_JavsPos .=
		  "parent.document.getElementById('CadCFun_BT_Atv').style.display='none';".
          ($bDir_Incluir ? '' :
		     "parent.document.getElementById('CadCFun_BT_Nov').style.display='none';"
		  ).
		  ($bDir_Consult ?
		    "P_Atu();"
		  :
		    Info_Evento('ALERTA: Sem previlégio para consulta neste modulo.').
         	"parent.document.forms.fmPCadFun.acao.value='FECHAR'; ".
            "parent.document.forms.fmPCadFun.submod.value=''; ".
         	"parent.document.forms.fmPCadFun.submit();"
		  ).
    	  'parent.document.getElementById("iCadFun_PChave").focus();'.
		  //
		  "function Teclas_F( Objeto, Evento ) {".
             "vNumTecla = parent.Tecla_Apertada(Evento);".
             "if ( vNumTecla==117) { ".        //  ** [F6] **          // (Novo)
                 "if ( parent.document.getElementById('CadCFun_BT_Nov').style.display != 'none') {".
                     "setTimeout( parent.document.getElementById('CadCFun_BT_Nov').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==116) { ".  // ** [F5] **         Não atualizar
                 //
		     "} else if ( vNumTecla==118) { ". //  ** [F7] **          // (Editar)
                 "if ( parent.document.getElementById('CadCFun_BT_Edt').style.display != 'none') {".
                      "setTimeout( parent.document.getElementById('CadCFun_BT_Edt').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==119) { ". //  ** [F8] **          // (Inativar)
                 "if ( parent.document.getElementById('CadCFun_BT_Itv').style.display != 'none') {".
                      "setTimeout( parent.document.getElementById('CadCFun_BT_Itv').onclick , 100);".
					                                                   // (Ativar)
                 "} else if ( parent.document.getElementById('CadCFun_BT_Atv').style.display != 'none') {".
                      "setTimeout( parent.document.getElementById('CadCFun_BT_Atv').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==27) { ".  //  ** [ESC] **         // (SAIR)
                  "setTimeout( parent.document.getElementById('CadCFun_BT_Fch').onclick , 100);".
			 "} else {".
		          "P_TeclasPress_fm(Evento);".
			      "return true;".
			 "}".
			 "return false;".
		  '}'.
		  //
    	  "";
    }
}
?>