// ------------------------------------------------------------------------- // gersincro. Permite el sincronismo de servidores. // ------------------------------------------------------------------------- function gersincro () { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $cfg_java_exe, $stemp, $cursor1, $cursor2, $cursor3, $cursor4; global $cfg_gersinhtm; if ($io_test>=1) { echo "Revisa gersincro ........................................................ \n"; } $ti=array(); $rcl=''; $buffer="select * from XW_SINCRO where ESTADO='P' order by IDSINCRO"; $conn->ger_exec ($cursor1, $buffer); $rcl= gerdb_fetch ($cursor1, $ti); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } while ($rcl=='') { if ($io_test>=2) { echo "Trata sincronismo: "; foreach ($ti as $i => $valor) { echo $valor . "|"; } echo "\n"; } procesa_sincro($ti); $rcl= gerdb_fetch ($cursor1, $ti); } } // ------------------------------------------------------------------------- // procesa_sincro. Permite procesar un sincronismo. // Codigos retorno: // C - Correcto, gerrc=0 y gertxt='' // I - Incorrecto, gerrc!=0 con gertxt informado // U - No hubo confirmacion de envio // ------------------------------------------------------------------------- function procesa_sincro ($ti) { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $cfg_java_exe, $stemp, $cursor1, $cursor2, $cursor3, $cursor4; global $cfg_gersinhtm; $ti['AREA']=str_replace(' ', '%20', $ti['AREA']); $respuesta=''; $url=$cfg_gersinhtm."?sql=".$ti['AREA']; $fp=fopen($url, "rb"); if ($fp!=NULL) { while (!feof($fp)) { $c=fgetc($fp); $nconta++; echo $c; $respuesta.=$c; } fclose($fp); } // Analizar $respuesta C si tiene gerrc:0b es correcto. // $respuesta E con gerrc:n es erroneo // $respuesta U sin gerrc: No se proceso $procesado = date("Y/m/d H:i:s"); $c=substr($respuesta,0,1); $resto=substr($respuesta,1); if (($c=='C') || ($c=='E')) { $resto=str_replace('\'', '\'\'', $resto); $resto=str_replace("[Microsoft]","", $resto); $resto=str_replace("[SQL Server Native Client 10.0]","", $resto); $resto=str_replace("[SQL Server Native Client 11.0]","", $resto); $resto=str_replace("[SQL Server]","", $resto); $resto=str_replace("SQLExecDirect","", $resto); $buffer="update XW_SINCRO set ESTADO='$c', PROCESADO='$procesado', RESPUESTA='$resto' where IDENTI=" . $ti['IDENTI']; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "sql: [" . $buffer . "]\n"; } // echo "url: [$url]
"; // echo "respuesta: $respuesta
"; } else { echo "U"; // Sin confirmaci¢n envio $buffer="update XW_SINCRO set ESTADO='U', PROCESADO='$procesado', RESPUESTA='Sin respuesta' where IDENTI=" . $ti['IDENTI']; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "sql: [" . $buffer . "]\n"; } } } // ------------------------------------------------------------------------- // obtenLIQ. Permite obtener una liquidacion // ------------------------------------------------------------------------- function obtenliq () { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $cfg_java_exe, $stemp, $cursor1, $cursor2, $cursor3, $cursor4; global $mail, $cfg_mail_host, $cfg_mail_port, $cfg_mail_user, $cfg_mail_pass, $cfg_mail_ssl; global $cfg_tic_ftp; if ($io_test>=1) { echo "Revisa Obten liquida ........................................................ \n"; } $ti=array(); $rcl=''; $buffer="select * from XW_SINCRO (NOLOCK) where (ESTADO='L' or ESTADO='U')"; $conn->ger_exec ($cursor3, $buffer); $rcl= gerdb_fetch ($cursor3, $ti); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } while ($rcl=='') { $idliq=$ti['TIDENTI']+0; if ($idliq>0) { $xesta=$ti['ESTADO']; if ($io_test>=2) { echo "Trata liquidacion: "; foreach ($ti as $i => $valor) { echo $valor . "|"; } echo "\n"; } if ($xesta=='L') { obtener_liquida ($ti['TIDENTI'],$ti['WEB']); // } else { // envia_liquida ($ti['TIDENTI']); } } $buffer="update XW_SINCRO set ESTADO='C' where IDENTI=" . $ti['IDENTI']; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "sql: [" . $buffer . "]\n"; } $rcl= gerdb_fetch ($cursor3, $ti); } } // ------------------------------------------------------------------------- // obtener_liquida. Permite obtener una liquidaci¢n concreta // ------------------------------------------------------------------------- function obtener_liquida ($idliq, $cweb) { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $cfg_java_exe, $stemp, $cursor1, $cursor2, $cursor3, $cursor4; global $cfg_obtenhtm, $cfg_obtenhtmbo, $c, $sdire, $xweb, $fp, $nconta, $nfiche, $nficheros, $nbytes, $idlog; if ($io_test>=2) { echo "Solicita liquidacion $idliq ............\n"; } $respuesta=''; if ($cweb=='BOBOLI') { $xweb=$cweb; $url=$cfg_obtenhtmbo."?liq=".$idliq; } else { $url=$cfg_obtenhtm."?liq=".$idliq; } if ($io_test>=2) { echo "url: [$url]\n"; } $sdire=$sroot."\\tmp\\$xweb\\"; if ($io_test>=2) { echo "sdire=$sdire\n"; } $nconta=0; $gerror=0; $tiempo_inicio=microtime(true); ftp_Graba_xf_envia_logcabe (); $nfiche=0; $fp=fopen($url, "rb"); if ($fp!=NULL) { $stipo=''; while (!feof($fp)) { $c=fgetc($fp); $nconta++; if (strlen($stipo)<2) { $stipo.=$c; } else { if ($stipo=='01') { ftp_trata_fichero(); $nfiche++; } if ($stipo=='05') { ftp_trata_mensaje(); } if ($stipo=='07') { ftp_cargar_img(); } if ($stipo=='08') { ftp_trata_sql(); } $stipo=''; } } fclose($fp); } $tiempo_final=microtime(true); $duracion=date("i:s", $tiempo_final - $tiempo_inicio); $duration = (int) ($tiempo_final - $tiempo_inicio); $hours = (int)($duration/60/60); $minutes = (int)($duration/60)-$hours*60; $seconds = (int)$duration-$hours*60*60-$minutes*60; $kb=(int) (($nconta/$seconds)/1024); $nsz=number_format($nconta,0,',','.'); if ($io_test>=2) { echo "total $nsz bytes en $duracion segundos ($seconds) velocidad bajada $kb kb\n"; echo "finaliza ...\n"; } $sfecha=date("Y/m/d"); $shora=date("H:i:s"); $detalle=''; if ($nfiche==0) { $detalle=", DETALLE='Sin ficheros recibidos' "; } if ($nfiche==1) { $detalle=", DETALLE='$nfiche fichero recibido' "; } if ($nfiche>1) { $detalle=", DETALLE='$nfiche ficheros recibidos' "; } $buffer="update XF_ENVIA_LOGCABE set IPORIGEN='". $xfr['NOMBRE'] . "',ESTADO='OK', TIEMPO='$duration', NFICHEROS='$nficheros', NBYTES='$nbytes', NN43='$nn43', NPDF='$npdf' $detalle where IDLOG='" . $idlog . "'"; $conn->ger_exec($cursor1, $buffer); if ($io_test>=2) { echo "rc=" . $rc . " sql: " . $buffer . "
"; } if ($xfr['TIPOEJECUCION']=='I') { $xfr['TIPOEJECUCION']='P'; } // Si es interactiva se deja parada $buffer="update XF_REMOTO_RECIBE set TIPOEJECUCION='" . $xfr['TIPOEJECUCION']. "', FECHA_ULTIMO='$sfecha', HORA_ULTIMO='$shora' where IDENTI=" . $xfr['IDENTI']; $conn->ger_exec($cursor1, $buffer); if ($io_test>=2) { echo "\nrc=" . $rc . " sql: " . $buffer . "
"; } actualiza_liquida($idliq); } // ------------------------------------------------------------------------- // actualiza_liquida. Permite actualizar una liquidacion // ------------------------------------------------------------------------- function actualiza_liquida ($idliq,$xcir) { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $stemp, $cursor1, $cursor2, $cursor3, $cursor4, $cursor5; global $mail, $cfg_mail_host, $cfg_mail_port, $cfg_mail_user, $cfg_mail_pass, $cfg_mail_ssl, $xweb, $xempresa; global $cfg_tic_ftp; $ti=array(); $rcl=''; $xcompanyia=''; $buffer="select * from M_TICKETS_LIQ (nolock) where web='$xweb' and IDLIQUIDA=$idliq"; $conn->ger_exec ($cursor1, $buffer); $rcl= gerdb_fetch ($cursor1, $ti); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $xempresa=$ti['EMPRESA']; if ($rcl=='') { if ($io_test>=2) { foreach ($ti as $i => $valor) { echo $valor . "|"; } echo "\n"; } $xusu=$ti['USUARIO']; if ($xusu!='') { $tuser=array(); $rcu=''; $buffer="select * from XW_USUARIOS (nolock) where web='$xweb' and USUARIO='$xusu'"; $conn->ger_exec ($cursor1, $buffer); $rcu= gerdb_fetch ($cursor1, $tuser); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } if ($rcu=='') { if ($io_test>=2) { foreach ($tuser as $i => $valor) { echo $valor . "|"; } echo "\n"; } if ($xcir==''){ $xcir=$tuser['CIRCUITO_GASTOS']; } $xestado='RECIBIDA'; if ($io_test>=2) { echo "circuito: $xcir estado: $xestado \n"; } $tele=array(); $rc=''; $buffer='select USUARIOS,ACCION from M_GASTOS_APROBACION_EST (NOLOCK) where WEB=\''.$xweb.'\' and EMPRESA=\''.$xempresa.'\' and CIRCUITO=\''.$xcir.'\' and ESTADO_INICIO=\''.$xestado.'\''; $conn->ger_exec ($cursor1, $buffer); $rc= gerdb_fetch ($cursor1, $tele); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } if ($io_test>=2) { foreach ($tele as $i => $valor) { echo $valor . "|"; } echo "\n\n\n"; } $xusuarios =$tele['USUARIOS']; $xaccion =$tele['ACCION']; $xsiguiente_validacion=''; $xcorreos=''; $fecha_estado= date ("Y/m/d"); $tu=array(); $tu=explode ('',$xusuarios); foreach ($tu as $nombre_campo => $valor) { $p=strstr($tratado, $valor . "#"); if (($valor<>'') && ($p==NULL)) { if ($valor=='@SU_JEFE'){ $tele=array(); if($conn->entorno[GI_PERSONAL]=="XW_USUARIOS") { $buffer='select SU_JEFE from XW_USUARIOS (NOLOCK) where WEB=\''.$_POST['GERWEB'].'\' and EMPRESA=\''.$_POST['GEREMPRESA'].'\' and USUARIO=\''.$conn->usu['USUARIO'].'\''; } else { if ($_POST['GERWEB']=='COMPUT' || $_POST['GERWEB']=='LABOREX'){ $buffer='select SU_JEFE from GI_PERSONAL (NOLOCK) where EMPLEADO=\''.$conn->usu['USUARIO'].'\''; } else { $buffer='select SU_JEFE from GI_PERSONAL (NOLOCK) where WEB=\''.$xweb.'\' and EMPRESA=\''.$xempresa.'\' and EMPLEADO=\''.$conn->usu['USUARIO'].'\''; } } $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $rc= gerdb_fetch ($cursor1, $tele); $valor=$tele['SU_JEFE']; } if ($valor!=''){ $xsiguiente_validacion.='#'.$valor.'#'; } } } $sql_aux=''; if (strtoupper($nuevo_estado)=='RECHAZADA' || strtoupper($nuevo_estado)=='APROBADA') { $xsiguiente_validacion=''; $sql_aux=',ESTADO=\''.$nuevo_estado.'\''; } $xmen=''; $sinicio=", FINICIO_APROBACION='" . date("Y/m/d"). "' "; $buffer="update M_TICKETS_LIQ SET FECHA_CONTA='', FECHA_ESTADO='$fecha_estado', ESTADO_APROBACION='RECIBIDA', CODIGO_APROBACION='$xcir', NAVISION='N', USUPENDIENTE_APROBACION='$xsiguiente_validacion'" . $xmen . $sinicio . " where web='$xweb' and IDLIQUIDA=$idliq"; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } if ($gerini=='LVMH') { $tcc=array(); $rcc=''; $buffer="select TIPLMG from GLM01 where CCIAMG='$xcompanyia'"; $conn->ger_exec ($cursor1, $buffer); $rcc = gerdb_fetch ($cursor1, $tcc); if ($rcc=='') { $pcta=$tcc['TIPLMG']; } } if ($pcta=='') { $pcta='T'; } // --------------------------------------------------------------------------- // Grabar entrada en log de la validacion del circuito // --------------------------------------------------------------------------- $sfecha=date("Y/m/d"); $shora=date("H:i:s"); $buffer ="insert into M_GASTOS_APROBACION_LOG (WEB,EMPRESA,IDLIQUIDA,FECHA,HORA,CIRCUITO,ESTADO_INICIO,ESTADO_FINAL,USUARIO,DESCRIPCION) VALUES ("; $buffer.="'$xweb','$xempresa',$idliq,'$sfecha','$shora','$xcir','@NINGUNO','RECIBIDA','UGESTOR','Recepcion liquidación en ". $xweb ."')"; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $tapli=array(); $rcc=''; $buffer ="select GASTOS_DATOSFINALES_UGESTOR from GLC_APLICA (nolock)"; $buffer.=" where WEB='" . $ti[WEB] . "' and EMPRESA='" . $ti[EMPRESA] . "'"; $conn->ger_exec($cursor1, $buffer); $rcc= gerdb_fetch ($cursor1, $tapli); // $xw=$xweb; $xe=$xempresa; $xweb=$ti['WEB']; $xempresa=$ti['EMPRESA']; //if($tapli[GASTOS_DATOSFINALES_UGESTOR]!="N") { // --------------------------------------------------------------------------- // Enviar avisos de gastos // --------------------------------------------------------------------------- $xaccion='MSOLICITUD'; Enviar_avisos_gastos($xusuarios,$xaccion,$idliq); //if (($tuser['INSTALA']=='S') && ($tuser['APPNOTI']=='S')) { // --------------------------------------------------------------------------- // Enviar Notifiacion si tiene activo // --------------------------------------------------------------------------- Enviar_notificacion ($tuser, $ti, "NotaSolicitada"); //} //} // --------------------------------------------------------------------------- // Grabar el reparto de gastos del ticket // --------------------------------------------------------------------------- $buffer="delete from M_TICKETS_REPAR where WEB='$xweb' and EMPRESA='$xempresa' and IDLIQUIDA=$idliq"; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $tcon=array(); $rc=''; $buffer="select CONCEPTO, SUM(IMPORTE) AS SUMA, COUNT(*) AS NCONTA from M_TICKETS where WEB='$xweb' and IDLIQUIDA=$idliq GROUP BY CONCEPTO order by CONCEPTO"; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $rc= gerdb_fetch ($cursor1, $tcon); while ($rc=='') { $tc=array(); $rcc=''; $buffer="select * from M_GASTOS_CON where WEB='$xweb' and CONCEPTO='" . $tcon['CONCEPTO'] . "'"; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $rcc= gerdb_fetch ($cursor2, $tc); if ($gerini=='LVMH' || $gerini=='LOEWEXXXX') { $buffer="insert into M_TICKETS_REPAR (WEB,EMPRESA,IDLIQUIDA,CONCEPTO,IMPORTE,CTACONTABLE,CAUX1,CAUX2,CAUX3,PCTA) values ("; $buffer.="'$xweb','$xempresa',$idliq,'" . $tcon['CONCEPTO']. "'," . $tcon['SUMA'] . ",'" . $tc['CTACONTABLE']; $buffer.="', '" . $tc['CAUX1'] . "','" . $tc['CAUX2'] . "','" . $tc['CAUX3'] . "','" . $pcta . "')"; } else { $buffer="insert into M_TICKETS_REPAR (WEB,EMPRESA,IDLIQUIDA,CONCEPTO,IMPORTE,CTACONTABLE) values ("; $buffer.="'$xweb','$xweb',$idliq,'" . $tcon['CONCEPTO']. "'," . $tcon['SUMA'] . ",'" . $tc['CTACONTABLE'] . "')"; } $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $rc= gerdb_fetch ($cursor1, $tcon); } } } } // if ($gerini!='LVMH') { echo "finaliza "; exit; } //rafa6 } // -------------------------------------------------------------------------------------- // Enviar_notificacion. Permite enviar una notificaci¢n // -------------------------------------------------------------------------------------- function Enviar_notificacion($tuser, $ti, $tipo) { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $stemp, $cursor1, $cursor2, $cursor3, $cursor4, $cursor5; global $mail, $cfg_mail_host, $cfg_mail_port, $cfg_mail_user, $cfg_mail_pass, $cfg_mail_ssl, $xweb, $xempresa; global $cfg_tic_ftp; echo "dentro de enviar_notifiaci¢n\n"; if ($io_test>=2) { foreach ($tuser as $i => $valor) { echo $valor . "|"; } echo "\n"; } if ($io_test>=2) { foreach ($ti as $i => $valor) { echo $valor . "|"; } echo "\n"; } // ----------------------------------------------------------------------------------- // Comprobar que se tiene parametrizada mensaje de notificacion // $mensaje="Su Nota de gastos #ANYO#/#IDLIQUIDAUSU#, de importe #IMPORTE# ha sido solicitada correctamente. Recibira un nuevo mensaje cuando haya sido Aprobada"; // ----------------------------------------------------------------------------------- $taccio=array(); $rca=''; $buffer="select * from M_APPCODI (NOLOCK) where WEB='$xweb' and EMPRESA='$xempresa' "; $buffer.="and ACCION='$tipo'"; $conn->ger_exec ($cursor4, $buffer); $rca= gerdb_fetch ($cursor4, $taccio); if ($io_test>=2) { echo "rca: $rca sql: " . $buffer . "\n"; } //if ($rca!='') { return; } // Mutidioma //$sidioma=$tuser['IDIOMA']; //$gidioma='ES,IN,FR,PT,CA,AL,IT,RU'; //$pdest=(strpos($gidioma, $sidioma)/3)+1; //$taccio['TITULO']=$taccio['TITULO'.$pdest]; //if ($taccio['TITULO']=='') { $taccio['TITULO']=$taccio['TITULO1']; } //$taccio['TEXTO']=$taccio['TEXTO'.$pdest]; //if ($taccio['TEXTO']=='') { $taccio['TEXTO']=$taccio['TEXTO1']; } $titulo=$taccio['TITULO']; $mensaje=$taccio['TEXTO']; //if ($taccio['TEXTO']=='') { return; } $fichero_size=$taccio['FICHERO_SIZE']; $fichero_tipo=$taccio['FICHERO_TIPO']; $respuesta=$taccio['RESPUESTA']; $grafico=$taccio['GRAFICO']; if (($ti['WEB']=='FERROMEX') || ($ti['WEB']=='TEXMODAS')) { foreach ($ti as $i => $valor) { if ($i=='IMPORTE') { $ti['IMPORTE']="$".number_format(round($ti['IMPORTE'], 2), 2, '.', ','); } } } foreach ($ti as $i => $valor) { $mensaje=str_replace("#".$i. "#", $valor, $mensaje); } $anyo=substr($ti['FECHA_INICIO'],0,4); $mensaje=str_replace("#ANYO#", $anyo, $mensaje); if ($io_test>=2) { echo "Mensaje: $mensaje \n\n"; } $buffer="begin transaction"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $tlog=array(); $rc=''; $buffer="select max(IDNOTI) as IDNOTI from M_GASTOS_NOTI (updlock) where web = '" . $xweb . "' and empresa = '" . $xempresa . "'"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $rc= gerdb_fetch ($cursor4, $tlog); if ($rc=='') { $idnoti=$tlog['IDNOTI']+1; } else { $idnoti=1; } if ($io_test>=2) { echo "idnoti: " . $idnoti . "\n"; } $sfecha=date("Y/m/d"); $shora=date("H:i:s"); $empleado=$tuser['USUARIO']; $buffer="insert into M_GASTOS_NOTI (WEB,EMPRESA,IDNOTI,EMPLEADO,IDLIQ,"; $buffer.="TIPO,TITULO,TEXTO, FICHERO,FICHERO_SIZE,FICHERO_TIPO,FECHA,"; $buffer.="FECHA_RECEPCION, ESTADO, TIPORESPU, RESPUESTA,FECHA_RESPUESTA) values ('"; $buffer.=$xweb . "','" . $xempresa . "',".$idnoti . ",'".$empleado . "',0,'Notas de Gastos','"; $buffer.=$titulo . "','" . $mensaje . "','0x00',"; $buffer.=$fichero_size. ",'". $fichero_tipo . "','', '', 'Pendiente','$respuesta','','')"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } if ($fichero_size>0) { $buffer="update M_GASTOS_NOTI set FICHERO=(select FICHERO from M_APPCODI where IDENTI=" . $taccio['IDENTI'] . ") "; $buffer.="where WEB='" . $xweb . "' and IDNOTI=" . $idnoti; if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $conn->ger_exec ($cursor4, $buffer); } if (($grafico!='') && ($grafico!='@NINGUNO')) { $buffer="update M_GASTOS_NOTI set FICHERO=(select GRAFICO from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico'), "; $buffer.="FICHERO_SIZE=(select GRAFICO_SIZE from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico'), "; $buffer.="FICHERO_TIPO=(select GRAFICO_TIPO from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico') "; $buffer.="where WEB='" . $xweb . "' and IDNOTI=" . $idnoti; if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $conn->ger_exec ($cursor4, $buffer); } $idnoti++; $buffer="commit transaction"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } } // -------------------------------------------------------------------------------------- // Enviar_avisos_gastos. Permite enviar maila los siguientes a validar notas de gastos // -------------------------------------------------------------------------------------- function Enviar_avisos_gastos($xusuarios,$xaccion,$idliq){ global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $stemp, $cursor1, $cursor2, $cursor3, $cursor4, $cursor5; global $mail, $cfg_mail_host, $cfg_mail_port, $cfg_mail_user, $cfg_mail_pass, $cfg_mail_ssl, $xweb, $xempresa; global $cfg_tic_ftp; if ($xaccion!='' && $xaccion!='@NINGUNO'){ $tele=array(); $buffer='select ACCION,DESCRIPCION,ASUNTO_MAIL,LISTA_USUARIOS,CUERPO_MAIL,ADJUNTAR_DOCUMENTO from'; $buffer.=' M_GASTOS_ACCION'; $buffer.=' where WEB=\''.$xweb.'\' and EMPRESA=\''.$xempresa.'\' and ACCION=\''.str_replace("'","''",$xaccion).'\''; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $rc= gerdb_fetch ($cursor1, $tele); $maccion =$tele['ACCION']; $mdescripcion =$tele['DESCRIPCION']; $masunto_mail =$tele['ASUNTO_MAIL']; $mlista_usuarios =$tele['LISTA_USUARIOS']; $cuerpo =$tele['CUERPO_MAIL']; $madjuntar_documento =$tele['ADJUNTAR_DOCUMENTO']; $correo=''; if(strlen($mlista_usuarios)==0) { $saux=$xusuarios; } else { if(strlen($xusuarios)==0) { $saux=$mlista_usuarios; } else { $saux=$xusuarios.''.$mlista_usuarios; } } $tu=explode ('',$saux); foreach ($tu as $nombre_campo => $valor) { $p=strstr($tratado, $valor . "#"); if (($valor<>'') && ($p==NULL)) { if ($valor=='@ACTUAL'){$valor=$conn->usu['USUARIO'];} if ($valor=='@SU_JEFE'){ $tele=array(); if($conn->entorno[GI_PERSONAL]=="XW_USUARIOS") { $buffer='select SU_JEFE from XW_USUARIOS (NOLOCK) where WEB=\''.$xweb.'\' and EMPRESA=\''.$xempresa.'\' and USUARIO=\''.str_replace("'","''",$conn->usu['USUARIO']).'\''; } else { $buffer='select SU_JEFE from GI_PERSONAL (NOLOCK) where WEB=\''.$xweb.'\' and EMPRESA=\''.$xempresa.'\' and EMPLEADO=\''.str_replace("'","''",$conn->usu['USUARIO']).'\''; } $conn->ger_exec ($cursor1, $buffer); $rc= gerdb_fetch ($cursor1, $tele); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $valor=$tele['SU_JEFE']; } if ($valor=='@SOLICITANTE'){ if ($xvalidacion_permisos=='S'){ $tele=array(); $buffer="select EMPLEADO from GI_PERSONAL_PER where IDENTI=" . $permisos_id; $conn->ger_exec ($cursor1, $buffer); $rc= gerdb_fetch ($cursor1, $tele); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $valor=$tele['EMPLEADO']; } } if ($valor!=''){ $tratado.=$valor ."#"; $tusu=array(); $rcu=''; $buffer="SELECT EMAIL from XW_USUARIOS WHERE WEB='".$xweb."' and EMPRESA='".$xempresa."' and USUARIO='" . str_replace("'","''",$valor) . "'"; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "
"; } $rcu = gerdb_fetch ($cursor2, $tusu); if (($rcu=='') && ($tusu['EMAIL']<>'')) { if ($correo<>'') { $correo.=','; } $correo.=$tusu['EMAIL']; } } } } if ($correo<>'') { $tele=array(); $buffer="select IDLIQUIDA,IDLIQUIDAUSU, USUARIO,FECHA_INICIO,FECHA_FINAL,ADELANTO,OBS,IMPORTE,ESTADO,FECHA_ESTADO,CODIGO_APROBACION,ESTADO_APROBACION,USUPENDIENTE_APROBACION,FECHA_ALTA,HORA_ALTA,COMPANYIA,IMAGEN_SIZE,IMAGEN_TIPO from M_TICKETS_LIQ where WEB='$xweb' and idliquida=$idliq"; $conn->ger_exec ($cursor1, $buffer); $rc= gerdb_fetch ($cursor1, $tele); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } if ($io_test>=2) { foreach ($tele as $i => $valor) { echo $valor . "|"; } echo "\n\n"; } $sidliquida =$tele['IDLIQUIDA']; $sidliquidausu =substr($tele['FECHA_INICIO'],0,4)."/".$tele['IDLIQUIDAUSU']; $susuario =$tele['USUARIO']; $sfecha_inicio =substr($tele['FECHA_INICIO'],8,2)."/".substr($tele['FECHA_INICIO'],5,2)."/".substr($tele['FECHA_INICIO'],0,4); $sfecha_final =$tele['FECHA_FINAL']; $sadelanto =$tele['ADELANTO']; $sestado_validacion= $tele['ESTADO_APROBACION']; $scodigo_aprobacion =$tele['CODIGO_APROBACION']; $sobs =$tele['OBS']; $simporte =$tele['IMPORTE']; $sfecha_alta =$tele['FECHA_ALTA']; $shora_alta =$tele['HORA_ALTA']; $scompanyia =$tele['COMPANYIA']; $ssiguiente_validacion=$tele['USUPENDIENTE_APROBACION']; $sfestado_validacion =$tele['FECHA_ESTADO']; $simagen_size =$tele['IMAGEN_SIZE']+0; $simagen_tipo =$tele['IMAGEN_TIPO']; $tcom=array(); $rco=''; $buffer="SELECT RSOCIAL from M_EMPRESA (nolock) WHERE CODIGO='$scompanyia'"; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "
"; } $rco = gerdb_fetch ($cursor2, $tcom); $scompanyia=$tcom['RSOCIAL']; $tusu=array(); $rcu=''; $buffer="SELECT * from XW_USUARIOS (nolock) WHERE WEB='".$xweb."' and EMPRESA='".$xempresa."' and USUARIO='$susuario'"; $conn->ger_exec ($cursor2, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "
"; } $rcu = gerdb_fetch ($cursor2, $tusu); $tipomail='XM_MAIL'; $idocu='FACPROVE'; $fecha_alta = date("Y/m/d"); $hora_alta = date("H:i:s"); if ($cuerpo==''){ $cuerpo = $conn->entorno['M_TICKETS_LIQ_VAL_CUERPO']; } $mail_from = $conn->entorno['M_TICKETS_LIQ_VAL_FROM']; $cuerpo='LIQCIRINI'; $mail_to = $correo; $mail_cco = ''; $mail_asunto =$masunto_mail; // if ($mail_asunto==''){ $mail_asunto = 'Nota de gastos '.$sidliquida.' de '.$susuario.' en estado ' . $sestado_validacion . ' requiere validación'; // } foreach($tele as $campo => $valor){ $mail_asunto=str_ireplace('#'.$campo.'#',$valor,$mail_asunto); } $mail_fiche1 = ''; $mail_fiche2 = ''; $mail_fiche3 = ''; $pdfmerge = ''; $campos=$valores=''; $campos ='IDLIQUIDA~IDLIQUIDAUSU~USUARIO~FECHA_INICIO~FECHA_FINAL~ADELANTO~OBS~IMPORTE~ESTADO~FECHA_ESTADO~CODIGO_APROBACION~ESTADO_APROBACION~USUPENDIENTE_APROBACION~FECHA_ALTA~HORA_ALTA~COMPANYIA'; $valores="$sidliquida~$sidliquidausu~$susuario~$sfecha_inicio~$sfecha_final~$sadelanto~$sobs~$simporte~$sestado~$sfestado_validacion~$scodigo_aprobacion~$sestado_validacion~$ssiguiente_validacion~$sfecha_alta~$shora_alta~$scompanyia"; if ($tusu['CCC']!='') { $campos.="~CCC"; $valores.="~".$tusu['CCC']; } if ($tusu['CCONTA']!='') { $campos.="~CCONTA"; $valores.="~".$tusu['CCONTA']; } if ($tusu['CDNI']!='') { $campos.="~CDNI"; $valores.="~".$tusu['CDNI']; } if ($tusu['CARGO']!='') { $campos.="~CCARGO"; $valores.="~".$tusu['CCARGO']; } $estado = 'PENDIENTE'; $fecha = ''; $hora = ''; $tipo='NOTAS GASTOS'; // Aprobaci¢n gastos $valores=str_replace("'", "''", $valores); //20130108 $buffer = "insert into XM_MAIL (WEB,EMPRESA, FECHA_ALTA, HORA_ALTA, TIPO, MAIL_DE, MAIL_PARA, MAIL_CCO, ASUNTO, CUERPO, "; $buffer.= "CUERPO_WEB, CUERPO_EMPRESA, ADJUNTO1, ADJUNTO2, ADJUNTO3, CAMPOS, VALORES, ESTADO, FECHA, HORA, DOCU_TIPO, "; $buffer.= "DOCU_SIZE, DOCU, ACUSE, NOTIFICA) VALUES ('" . $xweb . "','" . $xempresa . "','" . str_replace("'","''",$fecha_alta) . "','"; $buffer.= str_replace("'","''",$hora_alta) . "','".str_replace("'","''",$tipo)."','" .str_replace("'","''",$mail_from) . "','" . str_replace("'","''",$mail_to) . "','" . str_replace("'","''",$mail_cco) . "','" . str_replace("'","''",$mail_asunto); $buffer.= "','".str_replace("'","''",$cuerpo)."','" . $xweb . "','" . $xempresa . "','" . str_replace("'","''",$mail_fiche1) . "','" . str_replace("'","''",$mail_fiche2). "','"; $buffer.= str_replace("'","''",$mail_fiche3). "','" . str_replace("'","''",$campos). "','" . str_replace("'","''",$valores) ."','" . str_replace("'","''",$estado). "','" . str_replace("'","''",$fecha) . "','" . str_replace("'","''",$hora) . "','"; $buffer.= "',0, '0x1', 'N', 'N')"; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "
"; } if ($simagen_size>0){ $tele=array(); $buffer="select IDENTI from XM_MAIL (NOLOCK) where WEB='" . $xweb . "' and EMPRESA='" . $xempresa . "' and FECHA_ALTA='" . str_replace("'","''",$fecha_alta) . "' and HORA_ALTA='".str_replace("'","''",$hora_alta)."' and TIPO='".str_replace("'","''",$tipo)."' and MAIL_DE='" .str_replace("'","''",$mail_from) . "' and MAIL_PARA='" . str_replace("'","''",$mail_to) . "' and MAIL_CCO='" . str_replace("'","''",$mail_cco) . "' and ASUNTO='" . str_replace("'","''",$mail_asunto)."' and CUERPO='".str_replace("'","''",$cuerpo)."'"; $conn->ger_exec ($cursor1, $buffer); $rc= gerdb_fetch ($cursor1, $tele); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } $xm_mail_identi=$tele['IDENTI']; if ($xm_mail_identi>0){ $buffer="update XM_MAIL set DOCU_SIZE=".$simagen_size.", DOCU_TIPO='".$simagen_tipo."', DOCU=(SELECT IMAGEN from M_TICKETS_LIQ WHERE WEB='$xweb' and IDLIQUIDA=".$idliq.") where IDENTI=".$xm_mail_identi; $conn->ger_exec ($cursor1, $buffer); if ($io_test>=2) { echo "rcl: $rcl sql: [" . $buffer . "]\n"; } } } } } } // ------------------------------------------------------------------------- // gerappnoti - Permite planificar notificaciones. // ------------------------------------------------------------------------- function gerappnoti () { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $cfg_java_exe, $stemp, $cursor1, $cursor2, $cursor3, $cursor4; global $mail, $cfg_mail_host, $cfg_mail_port, $cfg_mail_user, $cfg_mail_pass, $cfg_mail_ssl; global $cfg_tic_ftp, $xweb, $xempresa; $tnoti=array(); $rcn=''; $buffer="select * from M_APPNOTI (nolock) where EJECUCION='I'"; $conn->ger_exec($cursor1, $buffer); $rcn= gerdb_fetch ($cursor1, $tnoti); if ($io_test>=2) { echo "rcn=" . $rce . " sql: " . $buffer . "\n"; } while ($rcn=='') { $xweb=$tnoti['WEB']; $xempresa=$tnoti['EMPRESA']; $grafico=$tnoti['GRAFICO']; if ($io_test>=2) { echo "m_appnoti: "; foreach ($tnoti as $i => $valor) { echo $valor . "|"; } echo "\n"; } $buffer="begin transaction"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $tlog=array(); $rc=''; $buffer="select max(IDNOTI) as IDNOTI from M_GASTOS_NOTI (updlock) where web = '" . $xweb . "' and empresa = '" . $xempresa . "'"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $rc= gerdb_fetch ($cursor4, $tlog); if ($rc=='') { $idnoti=$tlog['IDNOTI']+1; } else { $idnoti=1; } if ($io_test>=2) { echo "idnoti: " . $idnoti . "\n"; } $usu=$tnoti['DESTIUSU']; if ($usu!='@TODOS') { $tusu=explode('', $tnoti['DESTIUSU']); for ($ii=0; $iiger_exec ($cursor4, $buffer); //flog2("gerappnoti. *a* gerrc(" . $gerrc . "), buffer(" . $buffer . ")\n"); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } if ($tnoti['FICHERO_SIZE']>0) { $buffer="update M_GASTOS_NOTI set FICHERO=(select FICHERO from M_APPNOTI where IDENTI=" . $tnoti['IDENTI'] . ") "; $buffer.="where WEB='" . $xweb . "' and IDNOTI=" . $idnoti; if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $conn->ger_exec ($cursor4, $buffer); } if (($grafico!='') && ($grafico!='@NINGUNO')) { $buffer="update M_GASTOS_NOTI set FICHERO=(select GRAFICO from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico'), "; $buffer.="FICHERO_SIZE=(select GRAFICO_SIZE from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico'), "; $buffer.="FICHERO_TIPO=(select GRAFICO_TIPO from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico') "; $buffer.="where WEB='" . $xweb . "' and IDNOTI=" . $idnoti; if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $conn->ger_exec ($cursor4, $buffer); } $idnoti++; } else { if ($tusu[$ii]=='@TODOS') { $tuser=array(); $rcu=''; $buffer="select USUARIO from XW_USUARIOS where BLOQUEADO='N' and APP='S'"; $buffer.=" and APPNOTI='S' and WEB='" . $xweb . "' order by USUARIO"; $conn->ger_exec($cursor2, $buffer); $rcu= gerdb_fetch ($cursor2, $tuser); if ($io_test>=2) { echo "rcu=" . $rce . " sql: " . $buffer . "\n"; } while ($rcu=='') { echo "trata usuario: ". $tuser['USUARIO'] . "\n"; $sfecha=date("Y/m/d"); $shora=date("H:i:s"); $empleado=$tuser['USUARIO']; $buffer="insert into M_GASTOS_NOTI (WEB,EMPRESA,IDNOTI,EMPLEADO,IDLIQ,"; $buffer.="TIPO,TITULO,TEXTO, FICHERO,FICHERO_SIZE,FICHERO_TIPO,FECHA,"; $buffer.="FECHA_RECEPCION, ESTADO, TIPORESPU, RESPUESTA, FECHA_RESPUESTA) values ('"; $buffer.=$xweb . "','" . $xempresa . "',".$idnoti . ",'".$empleado . "',0,'"; $buffer.=$tnoti['CLAVE']. "','" . $tnoti['TITULO'] . "','" . $tnoti['TEXTO'] . "','0x00',"; $buffer.=$tnoti['FICHERO_SIZE']. ",'". $tnoti['FICHERO_TIPO'] . "','', '', 'Pendiente','"; $buffer.=$tnoti['RESPUESTA'] . "','','')"; $conn->ger_exec ($cursor4, $buffer); //flog2("gerappnoti. *b* gerrc(" . $gerrc . "), buffer(" . $buffer . ")\n"); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } if ($tnoti['FICHERO_SIZE']>0) { $buffer="update M_GASTOS_NOTI set FICHERO=(select FICHERO from M_APPNOTI where IDENTI=" . $tnoti['IDENTI'] . ") "; $buffer.="where WEB='" . $xweb . "' and IDNOTI=" . $idnoti; if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $conn->ger_exec ($cursor4, $buffer); } if (($grafico!='') && ($grafico!='@NINGUNO')) { $buffer="update M_GASTOS_NOTI set FICHERO=(select GRAFICO from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico'), "; $buffer.="FICHERO_SIZE=(select GRAFICO_SIZE from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico'), "; $buffer.="FICHERO_TIPO=(select GRAFICO_TIPO from XW_CONTENIDO_GRA where web='$xweb' and TIPO='NOTAS' and NOMBRE='$grafico') "; $buffer.="where WEB='" . $xweb . "' and IDNOTI=" . $idnoti; if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $conn->ger_exec ($cursor4, $buffer); } $idnoti++; $rcu= gerdb_fetch ($cursor2, $tusu); } } } } } $buffer="update M_APPNOTI set EJECUCION='N' where identi=" . $tnoti['IDENTI']; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $buffer="commit transaction"; $conn->ger_exec ($cursor4, $buffer); if ($io_test>=2) { echo "sql: " . $buffer . "\n"; } $rcn= gerdb_fetch ($cursor1, $tnoti); } } // ------------------------------------------------------------------------- // ticket_noti. Revisar el fichero de incidencias y obrar en consecuencia // ------------------------------------------------------------------------- function ticket_noti () { global $conn, $io_test, $conn, $sphx, $sroot, $gerperfil, $gerini, $xtipobd, $xnolock, $npid, $cfg_java_exe, $stemp, $cursor1, $cursor2, $cursor3, $cursor4; global $mail, $cfg_mail_host, $cfg_mail_port, $cfg_mail_user, $cfg_mail_pass, $cfg_mail_ssl; global $cfg_tic_ftp, $cfg_ftp, $xweb, $xempresa, $cfg_noti, $cfg_noti_url_idfirebase; $tnoti=array(); $rcn=''; // $buffer="select * from M_GASTOS_NOTI where WEB='$xweb' and EMPRESA='$xempresa' and ESTADO='Pendiente'"; $buffer="select * from M_GASTOS_NOTI where ESTADO='Pendiente'"; $conn->ger_exec($cursor1, $buffer); $rcn= gerdb_fetch ($cursor1, $tnoti); if ($io_test>=2) { echo "rcn=" . $rce . " sql: " . $buffer . "\n"; } while ($rcn=='') { $xweb=$tnoti['WEB']; $xempresa=$tnoti['EMPRESA']; if ($io_test>=2) { echo "Notificacion: "; foreach ($tnoti as $i => $valor) { echo $valor . "|"; } echo "\n"; } $xidenti=$tnoti['IDENTI']; $nomgra=''; $tnoti['FICHERO_SIZE']=$tnoti['FICHERO_SIZE']+0; $xexten=$tnoti['FICHERO_TIPO']; if ($tnoti['FICHERO_SIZE']>0) { $tiempo=microtime(true); $tiempo=str_replace('.', '', $tiempo); $sfichero=$cfg_ftp. "\\out\\noti_" . $xidenti . "_" . $tiempo . "." . $xexten; $nomgra="noti_" . $xidenti . "_" . $tiempo . "." . $xexten; $conn->ger_lee_grafico("M_GASTOS_NOTI", "FICHERO", $xidenti, $sfichero, ""); if ($io_test>=2) { echo "obtiene grafico: " . $sfichero . "\n"; } } $MESSAGE=$tnoti['TEXTO']; $TITULO=$tnoti['TITULO']; $TITULO=utf8_encode($TITULO); $MESSAGE=utf8_encode($MESSAGE); if ($io_test>=2) { echo "titulo: [" . $tnoti['TITULO'] . "]\ntexto: [" . $tnoti['TEXTO'] . "]\n"; } if ($io_test>=2) { echo "titulo: [" . $TITULO . "]\ntexto: [" . $MESSAGE . "]\n"; } $channel=""; $saction='notificaciones.uGastos'; if ($cfg_noti=='parse') { $APPLICATION_ID= "6WH57aQQdXhXZbUFGBr5pnU2PFdANKm9MUUER7kd"; $REST_API_KEY = "NBG7nxiCo1GB6gqNhwDqdMViccdphUwOnVCVpAp8"; $channel=$xweb."_".$tnoti['EMPLEADO']; } if ($cfg_noti=='fire') { if (strlen($cfg_noti_url_idfirebase)!=0) { $respuesta=''; $url=$cfg_noti_url_idfirebase . $tnoti['EMPLEADO']; if ($io_test>=2) { echo "url: [" . $url . "]\n"; } $fp=fopen($url, "rb"); if ($fp!=NULL) { while (!feof($fp)) { $c=fgetc($fp); $nconta++; echo $c; $respuesta.=$c; } fclose($fp); } if (($respuesta!='Error') && ($respuesta!='')) { // $idfirebase='fj2qkoFf8h4:APA91bFfxUxGGeIfc7YbD0UjAs25co1a05E00AOp1nbvTBwJKxJS1heq2v8TotijRCWvtDYsFmAvMMk6jY4xu6LE2pFOfl33u_UKpNEGIyrR38MwrOgTRdKey736kz9H7G4n2STMLwEm'; $channel=$respuesta; } } else { $tuu=array(); $rcu=''; $buffer ="select IDFIREBASE from XW_USUARIOS (nolock) where WEB='"; $buffer.=$xweb."' and EMPRESA='" . $xempresa . "' and USUARIO='"; $buffer.=$tnoti['EMPLEADO']. "'"; if ($io_test>=2) { echo "buffer= [" . $buffer . "]\n"; } $conn->ger_exec($cursor1, $buffer); $rcn= gerdb_fetch ($cursor1, $tuu); $channel=$tuu['IDFIREBASE']; // if ($channel=='') { $channel='deIv3cnhXVY:APA91bHHaBxdIfJWf7leqTtP1gi4WS0A-q4rNfDOGWZ60TO2am9h7OioRc4emC2tcBjwbgGVJd4b-F2RhC8u_Rx2jnAhbOspafJvi5dST3986nWug_vthC-jMRxg8HacAGp359CNOswG'; } if ($channel=='') { $channel='fp9e9odkB5g:APA91bHUmJSUEm0JNwBRZM0iUKkfPvqkzYO46bvBUYRVuRpOsXiRq8HczG8x2Kjx46xd_RLzWPJBIzru0zeKomGtmEee6YHq_UlpdoevKoJu_JKjurZ7Po_gX_coHqSVe4y9aCY86pRV'; } } } if(strlen($channel)!=0) { $idnoti=$tnoti['IDNOTI']; $tiporespu=$tnoti['TIPORESPU']; $srespuesta=''; if ($io_test>=2) { echo "tiporespu: $tiporespu \n"; } if (($tiporespu!='') && ($tiporespu!='@NINGUNA')) { $tres=array(); $rct=''; $buffer="select * from M_APPRESPU (nolock) where WEB='" . $xweb . "' and ACTIVO='S'"; $buffer.=" and RESPUESTA='" . $tiporespu . "'"; $conn->ger_exec($cursor2, $buffer); $rcn= gerdb_fetch ($cursor2, $tres); if ($io_test>=2) { echo "rcn=" . $rce . " sql: " . $buffer . "\n"; } if ($rcn=='') { $sresputras=$tres['DESPUES']; $tval=array(); $rcv=''; $buffer="select * from M_APPRESPUVAL (nolock) where WEB='" . $xweb . "' and RESPUESTA='"; $buffer.=$tiporespu . "' order by ORDEN"; $conn->ger_exec($cursor2, $buffer); $rcv= gerdb_fetch ($cursor2, $tval); while ($rcv=='') { if ($tval['RESPONDER']=='') { $tval['RESPONDER']=$tval['MOSTRAR']; } $srespuesta.=$tval['MOSTRAR']."|".$tval['RESPONDER'].";"; foreach ($tval as $i => $valor) { echo $valor . "|"; } echo "\n"; $rcv= gerdb_fetch ($cursor2, $tval); } if ($srespuesta!='') { $ii=strlen($srespuesta); $srespuesta=substr($srespuesta, 0, $ii-1); } } if ($srespuesta=='') { $tiporespu=$resputras=''; } } $srespuesta=utf8_encode($srespuesta); if ($cfg_noti=='fire') { $version = curl_version(); $ssl_supported = ( $version['features'] & CURL_VERSION_SSL ); if (!$ssl_supported) { echo 'CURL ssl support not found'; exit; } $url = 'https://fcm.googleapis.com/fcm/send'; if ($nomgra!='') { $data = array( // 'to' => 'deIv3cnhXVY:APA91bHHaBxdIfJWf7leqTtP1gi4WS0A-q4rNfDOGWZ60TO2am9h7OioRc4emC2tcBjwbgGVJd4b-F2RhC8u_Rx2jnAhbOspafJvi5dST3986nWug_vthC-jMRxg8HacAGp359CNOswG', 'to' => $channel, 'data' => array( 'tipo' => $MESSAGE, 'title' => $TITULO, // 'action' => 'notificaciones.uGastos', 'action' => $saction, 'idnotilog' => $idnoti, 'nomgrafico' => $nomgra, 'localizacion' => $localiza, 'tiporespu' => $tiporespu, // 'Encuesta1', 'respuesta' => $srespuesta, // 'Aceptar|A;Rechazar|R', 'resputras' => $sresputras, // Tras responder ), 'priority' => "high", ); } else { $data = array( 'to' => $channel, 'data' => array( 'tipo' => $MESSAGE, 'title' => $TITULO, // 'action' => 'notificaciones.uGastos', 'action' => $saction, 'idnotilog' => $idnoti, 'nomgrafico' => 'null', 'localizacion' => $localiza, 'tiporespu' => $tiporespu, // 'Encuesta1', 'respuesta' => $srespuesta, // 'Aceptar|A;Rechazar|R', 'resputras' => $sresputras, // Tras responder ), 'priority' => "high", ); } $_data = json_encode($data); if ($io_test>=2) { echo "data: (" . $_data . ") \n\n"; } $headers = array( 'Authorization: key=AAAAY29DPBo:APA91bHeca09BoFMDMreO0hWpr4dRIrGrGPpSWY2FqR6Ff4RudaeaOwq4Gg028McnW65IfDsnILPJN-SRXZGBExGWu8kZUkWbOfY53ltSNSDn0BWRr208QFd3L0oTXGMp0UN4n4h7p-Y', 'Content-Type: application/json', 'Content-Length: ' . strlen($_data), ); if ($io_test>=2) { $h=json_encode($headers); echo "headers: (" . $h . ") \n"; } $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $_data); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); //flog2("***1*** curl_exec\n"); exit; echo "repuesta: $response \n"; echo "enviado $url ...\n"; // -------------------------------------------------------------------------------------------------- // envio 2 notificacion asociada a la primera // -------------------------------------------------------------------------------------------------- $data = array( 'to'=> $channel, 'priority'=> "high", 'notification'=> array( "title"=> "Aviso de notas", "body"=> $MESSAGE ) ); $_data = json_encode($data); if ($io_test>=2) { echo "data: (" . $_data . ") \n\n"; } $headers = array( 'Authorization: key=AAAAY29DPBo:APA91bHeca09BoFMDMreO0hWpr4dRIrGrGPpSWY2FqR6Ff4RudaeaOwq4Gg028McnW65IfDsnILPJN-SRXZGBExGWu8kZUkWbOfY53ltSNSDn0BWRr208QFd3L0oTXGMp0UN4n4h7p-Y', 'Content-Type: application/json', 'Content-Length: ' . strlen($_data), ); if ($io_test>=2) { $h=json_encode($headers); echo "headers: (" . $h . ") \n"; } $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $_data); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); //flog2("***2*** curl_exec\n"); echo "\n\n\nrepuesta2: ($response) \n"; // echo "final ...\n"; } if ($cfg_noti=='parse') { $version = curl_version(); $ssl_supported = ( $version['features'] & CURL_VERSION_SSL ); if (!$ssl_supported) { echo 'CURL ssl support not found'; exit; } $url = 'https://api.parse.com/1/push'; if ($nomgra!='') { $data = array( 'channel' => $channel, 'data' => array( 'alert' => $MESSAGE, 'title' => $TITULO, // 'action' => 'notificaciones.uGastos', 'action' => $saction, 'idnotilog' => $idnoti, 'nomgrafico' => $nomgra, 'localizacion' => $localiza, 'tiporespu' => $tiporespu, // 'Encuesta1', 'respuesta' => $srespuesta, // 'Aceptar|A;Rechazar|R', 'resputras' => $sresputras, // Tras responder ), ); } else { $data = array( 'channel' => $channel, 'data' => array( 'alert' => $MESSAGE, 'title' => $TITULO, // 'action' => 'notificaciones.uGastos', 'action' => $saction, 'idnotilog' => $idnoti, 'nomgrafico' => 'null', 'localizacion' => $localiza, 'tiporespu' => $tiporespu, // 'Encuesta1', 'respuesta' => $srespuesta, // 'Aceptar|A;Rechazar|R', 'resputras' => $sresputras, // Tras responder ), ); } if ($io_test>=2) { echo "MESSAGE: (" . $MESSAGE . ") \n\n"; } $_data = json_encode($data); if ($io_test>=2) { echo "data: (" . $_data . ") \n\n"; } $headers = array( 'X-Parse-Application-Id: ' . $APPLICATION_ID, 'X-Parse-REST-API-Key: ' . $REST_API_KEY, 'Content-Type: application/json', 'Content-Length: ' . strlen($_data), ); if ($io_test>=2) { // $h=json_encode($headers); // echo "headers: (" . $h . ")

"; } $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $_data); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); //flog2("***3*** curl_exec\n"); } // $sfecha=date("Y/m/d")." ".date("H:i:s"); $buffer="update M_GASTOS_NOTI set ESTADO='Ok', FECHA='$sfecha', FECHA_RECEPCION='' where IDENTI=" . $xidenti; $conn->ger_exec($cursor2, $buffer); if ($io_test>=2) { echo "rcn=" . $rce . " sql: " . $buffer . "\n"; } } else { $sfecha=date("Y/m/d")." ".date("H:i:s"); $buffer="update M_GASTOS_NOTI set ESTADO='Error', FECHA='$sfecha', FECHA_RECEPCION='' where IDENTI=" . $xidenti; $conn->ger_exec($cursor2, $buffer); if ($io_test>=2) { echo "rcn=" . $rce . " sql: " . $buffer . "\n"; } } $rcn= gerdb_fetch ($cursor1, $tnoti); } }