',$LogTxt)), $Cabeceras );
}else if( $_ErrReportTo!='' ){
$Cabeceras = "MIME-Version: 1.0\r\n";
$Cabeceras .= "Content-type: text/html; charset=iso-8859-1\r\n";
$Cabeceras .= "From: ".$_ErrReportFrom."\r\n";
if( $_ErrReportFrom!='' ) $Cabeceras .= "Reply-To: ".$_ErrReportFrom."\r\n";
if( $_ErrReportCc !='' ) $Cabeceras .= "Cc: ".$_ErrReportCc."\r\n";
if( $_ErrReportBCc !='' ) $Cabeceras .= "Bcc: ".$_ErrReportBCc."\r\n";
$Cabeceras .= "X-Mailer: PHP/" . phpversion();
$cd = zend_get_id();
if( is_array($cd) ) list($cd) = $cd;
mail( $_ErrReportTo, $_ErrReportMessage.' '.$cd, stripslashes(str_replace("\n",'
',$LogTxt)), $Cabeceras );
}
eInit();
echo '';
if( $_Development || $GLOBALS['_D_']!='' ){
eTrace('[SCRIPT]'); eTrace( $GLOBALS['OriFichero'] );
echo '
'; eTrace('[SQL]'); eTrace($sql); eTrace('[ERROR]'); eTrace( $SQLError );
echo '
'; eTrace('[_GET]' ); foreach( $_GET as $k=>$v ) eTrace( $k.' = '.$v );
echo '
'; eTrace('[_POST]'); foreach( $_POST as $k=>$v ) eTrace( $k.' = '.$v );
echo '
';
if( $GLOBALS['_D_']=='~' ){
echo ''; debug_print_backtrace(); echo '
'; print_r(debug_backtrace()); echo '
';
}
if( function_exists('KeyEditFile') ) KeyEditFile( $GLOBALS['OriFichero'] );
}else{
eTrace( '[ ERROR SQL ]' );
echo '';
}
if( $NumSqlError_ ) eEnd();
$NumSqlError_ = true;
if( substr_count( $_SERVER['REQUEST_URI'],'edes.gs?' ) == 1 ){
$tmp = explode('edes.gs?',$_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = 'edes.gs?'.trim($tmp[1]);
}
$_SERVER['REQUEST_URI'] = str_replace( "'", '"' , $_SERVER['REQUEST_URI'] );
$_SERVER['REQUEST_URI'] = str_replace( chr(92), '' , $_SERVER['REQUEST_URI'] );
$sql = trim(str_replace("'",'"',$sql));
$TxtError = trim(str_replace("'",'"',$TxtError));
$sqlError = 'insert into gs_error ( cdi ,cd_gs_user,tipo, desde, fichero , linea, texto, trace ) values '.
"( '{$Cdi}', {$_User} , 'S', 'PHP','{$_SERVER['REQUEST_URI']}', '' , '' , '{$TxtError}\n\n{$sql}' )";
mysql_query( $sqlError );
if( mysql_errno() ) eTrace('ERROR: gs_error');
eEnd();
}
function sql_Result( $i ){
return mysql_result( $GLOBALS['_Result'], $i );
}
function sql_Query( $sql, &$Puntero, $Continuar=false ){
global $_Result, $_TReg, $_DEBUG, $_HndDB, $_SQL_;
$sql = trim($sql);
if( $_DEBUG==4 ) eLogDebug($sql);
if( $_DEBUG==1 ) eTrace("[{$sql}]");
$_TReg = -1;
if( func_num_args() == 1 ){
$_Result = mysql_query( $sql );
if( mysql_errno() ){
if( !$Continuar ){
if( $_DEBUG==30 ) return -1;
sql_Error( $sql );
}
}else{
$_TReg = mysql_affected_rows( $_Result );
}
}else{
$Puntero = mysql_query( $sql );
if( mysql_errno() ){
if( !$Continuar ){
if( $_DEBUG==30 ) return -1;
sql_Error( $sql );
}
}else{
$_TReg = mysql_affected_rows( $Puntero );
}
}
if( substr($sql,0,6)=='insert' ){
$tmp = str_replace(' ',' ',str_replace("\t",' ',str_replace("\n",' ',str_replace("\r",' ',$sql))));
$tmp = explode(' ',$tmp );
$Tabla = $tmp[2];
global $_IdInsert, $_IdRegistro;
array_push( $_IdInsert, array( trim($Tabla), mysql_insert_id() ) );
$_IdRegistro[trim($Tabla)] = mysql_insert_id();
}else if( substr($sql,0,6)=='select' ) $_SQL_ = $sql;
if( $_DEBUG==1 ) eTrace( "[Reg.Query: {$_TReg}]" );
return $_TReg;
}
function sql_Cuenta( $Tabla, $Condicion, &$Puntero ){
global $_Result, $_TReg, $_DEBUG;
if( trim($Condicion)!='' ){
$Condicion = 'where '.$Condicion;
}else{
}
$sql = "select count(*) from {$Tabla} {$Condicion}";
if( $_DEBUG==4 ) eLogDebug($sql);
if( $_DEBUG==1 ) eTrace("[{$sql}]");
if( func_num_args() < 3 ){
$_Result = mysql_query( $sql );
if( mysql_errno() ){
if( $_DEBUG==30 ) return -1;
sql_Error( $sql );
}
$_TReg = mysql_result( $_Result, 0 );
}else{
$Puntero = mysql_query( $sql );
if( mysql_errno() ){
if( $_DEBUG==30 ) return -1;
sql_Error( $sql );
}
$_TReg = mysql_result( $Puntero, 0 );
}
if( $_DEBUG==1 ) eTrace( "[Total Reg: {$_TReg}]" );
return $_TReg;
}
function sql_Fila( $Puntero ){
if( func_num_args() == 0 ){
return mysql_fetch_row( $GLOBALS['_Result'] );
}else{
return mysql_fetch_row( $Puntero );
}
}
function sql_Array( $Puntero ){
if( func_num_args() == 0 ){
return mysql_fetch_array( $GLOBALS['_Result'] );
}else{
return mysql_fetch_array( $Puntero );
}
}
function sql_Id(){
return mysql_insert_id();
}
function sql_Seek( $i ){
return mysql_data_seek( $GLOBALS['_Result'], $i);
}
function sql_NombreCampo( $i ){
return mysql_field_name( $GLOBALS['_Result'], $i );
}
function sql_TipoCampo( $i ){
return mysql_field_type( $GLOBALS['_Result'], $i );
}
function sql_LongitudCampo( $i ){
return mysql_field_len( $GLOBALS['_Result'], $i );
}
function sql_FlagsCampo( $i ){
return mysql_field_flags( $GLOBALS['_Result'], $i );
}
function sql_TotalCampos(){
return mysql_num_fields( $GLOBALS['_Result'] );
}
function sql_Bloquea(){
}
function sql_Desbloquea(){
}
function sql_TranOn(){
global $_DEBUG, $_SqlTransaction;
if( !$_SqlTransaction ) return;
if( $_DEBUG==4 ) eLogDebug("START TRANSACTION");
if( $_DEBUG==1 ) eTrace('[START TRANSACTION]');
$_Result = mysql_query( 'START TRANSACTION' );
if( mysql_errno( $_Result ) ){
if( $_DEBUG==30 ) return -1;
sql_Error('START TRANSACTION');
}
}
function sql_TranOff(){
global $_DEBUG, $_SqlTransaction;
if( !$_SqlTransaction ) return;
if( $_DEBUG==4 ) eLogDebug("COMMIT");
if( $_DEBUG==1 ) eTrace('[COMMIT]');
$_Result = mysql_query( 'COMMIT' );
if( mysql_errno( $_Result ) ){
if( $_DEBUG==30 ) return -1;
sql_Error('COMMIT');
}
}
function sql_TranBack(){
global $_DEBUG;
if( $_DEBUG==4 ) eLogDebug("ROLLBACK");
if( $_DEBUG==1 ) eTrace('[ROLLBACK]');
$_Result = mysql_query( 'ROLLBACK' );
if( mysql_errno( $_Result ) ){
if( $_DEBUG==30 ) return -1;
sql_Error('ROLLBACK');
}
}
function sql_Log( $Log, $sOpe, $sTabla, $sSql ){
global $_DEBUG, $_HndDB, $_Result, $_TReg, $_User, $_DBSERIAL;
$sClave = '';
for( $n=0; $n$v ) $$k = $v;
unset($_SERIALIZE);
$sql = $_SQL_;
}
}
if( trim($sql)=='' ){
global $_SQL_;
$sql = $_SQL_;
}
if( $Depurar ) eTrace( '|'.$sql.'|' );
$DimCampoCondi = array();
$DimCondicion = array();
$TxtOrdenacion = '';
$sql = trim($sql);
if( strtoupper(substr($sql,0,6)) == 'WHERE ' ){
$sql = ' '.$sql;
}
$Cambio = array( ' from ', ' where ',' order by ', ' group by ',' like ', ' and ', ' or ', ' extend(', ' matches' );
for( $i=0; $i 0 ){
$sql = explode( ' FROM ', $sql );
$sql = $sql[1];
}
if( $Depurar ) eTrace( 'FROM|'.$sql.'|' );
if( substr_count( $sql, ' WHERE ' ) > 0 ){
$sql = explode( ' WHERE ', $sql );
$sql = $sql[1];
}
if( $Depurar ) eTrace( 'WHERE|'.$sql.'|' );
if( isset($PDF_TxtOrderBy) ){
$TxtOrdenacion = $PDF_TxtOrderBy;
}else if( substr_count( $sql, ' ORDER BY ') > 0 ){
$sql = explode( ' ORDER BY ', $sql );
$TxtOrdenacion = $sql[1];
$sql = $sql[0];
if( substr_count( $TxtOrdenacion, ' GROUP BY ' ) > 0 ){
$TxtOrdenacion = explode( ' GROUP BY ', $TxtOrdenacion );
$TxtOrdenacion = $TxtOrdenacion[0];
}
$tmp = explode( ',',$TxtOrdenacion );
$TxtOrdenacion = '';
for( $i=0; $i 0 ){
$campo = $DimCampos[$campo*1-1];
list( $campo, $atributo ) = explode( ' ',$campo );
$campo = trim($campo);
}
if( substr_count( $campo, '.' ) > 0 ) list(,$campo) = explode('.',$campo);
$campo = trim($campo);
if( $TxtOrdenacion != '' ) $TxtOrdenacion .= ', ';
$puntero = null;
if( sql_Cuenta( 'gs_campo', "tabla='{$_DBTABLE}' and campo='{$campo}'", $puntero ) > 0 ){
sql_Query( "select etiqueta, label_tab from gs_campo where tabla='{$_DBTABLE}' and campo='{$campo}'", $puntero );
$row = sql_Fila( $puntero );
if( trim($row[1])!='' ){
$TxtOrdenacion .= trim($row[1]);
}else{
$TxtOrdenacion .= trim($row[0]);
}
}else{
$sEti='';
if( $_PDFLABELHIDDEN[$campo] != '' ) $sEti = $_PDFLABELHIDDEN[$campo];
if( $sEti == '' ){
for($c=0;$c',' ',$sEti);
$sEti = str_replace('
',' ',$sEti);
$sEti = str_replace('
',' ',$sEti);
$sEti = str_replace('
',' ',$sEti);
$TxtOrdenacion .= $sEti;
}
}
}
$TxtOrdenacion = trim($TxtOrdenacion);
if( substr($TxtOrdenacion,-1)==',') $TxtOrdenacion = substr($TxtOrdenacion,0,-1);
}
if( $Depurar ) eTrace( 'WHERE (sin order by)|'.$sql.'|' );
if( substr_count( $sql, ' GROUP BY ' ) > 0 ){
$sql = explode( ' GROUP BY ', $sql );
$sql = $sql[0];
}
if( $Depurar ) eTrace( 'GROUP BY|'.$sql.'|' );
while( substr_count( $sql, ' EXTEND(' ) > 0 ){
$ei = strpos( $sql, ' EXTEND(' );
$ci = $ei+8;
$cf = strpos( $sql, ',', $ei+1 );
$ef = strpos( $sql, ')', $ei+1 );
$sql = substr( $sql, 0, $ei+1 ).
substr( $sql, $ei+8, $cf-$ei-8 ).
substr( $sql, $ef+1 );
}
if( $Depurar ) eTrace( 'CALCULA CONDICIONES|'.$sql.'|' );
$tmp = explode( ' AND ', trim($sql) );
for($i=0; $i=! '.chr(9), $c ) > 0 ){
$sp = $p;
break;
}else{
$campo .= $c;
}
}
$campo = trim($campo);
if( substr_count( $campo, '.' ) > 0 ){
list(,$campo ) = explode('.',$campo);
$campo = trim($campo);
}
if( substr_count($campo,' ')>0 ) list($campo) = explode(' ',$campo);
if( $FuncSql!='' ){
list($campo) = explode(',',$campo);
$campo = trim($campo);
for( $p=$sp; $p0 ) $campo = trim(substr($campo,0,strpos($campo,'[')));
if( $Depurar ) eTrace( $i.'.CAMPO |'.$campo.'| '.$FuncSql );
$tmp2 = strtoupper(trim(substr($dato,$sp)));
if( substr($tmp2,0,7)=='NOT IN ' ){
$condi = '<>'; $sCondi = 'NOT IN';
$sp += 7;
}else if( substr($tmp2,0,3)=='IN ' ){
$condi = '='; $sCondi = 'IN';
$sp += 3;
}else if( substr($tmp2,0,5)=='LIKE ' ){
$condi = '='; $sCondi = 'LIKE';
$sp += 5;
}else if( substr($tmp2,0,8)=='IS NULL ' ){
$condi = '='; $sCondi = 'IS NULL';
$sp += 8;
}else if( substr($tmp2,0,12)=='IS NOT NULL ' ){
$condi = '='; $sCondi = 'IS NOT NULL';
$sp += 12;
}else{
$Ini = false;
for( $p=$sp; $p=!', $c ) > 0 ){
$condi .= $c;
}else{
$sp = $p;
break;
}
}
if( $c == ' ' ) {
for( $p=$sp; $p NewCampo |'.$tmp2);
}
}
break;
}
}
}
if( $Depurar ){
eTrace($i.'.VALOR |'.$valor.'|');
eTrace($i.' ['.$campo.']['.$condi.']['.$valor.']
' );
}
if( $valor!='' && $valor[0]!='"' && $valor[0]!="'" && !is_numeric($valor) ){
if( $Depurar ) eTrace($i.' ---> Condicion anulada
');
continue;
}
$puntero = null;
$etiqueta = '';
if( $_PDFLABELHIDDEN[$campo] != '' ) $etiqueta = $_PDFLABELHIDDEN[$campo];
if( $etiqueta == '' ){
for($p=0;$p 0 ){
sql_Query( "select etiqueta, label_tab from gs_campo where tabla='{$_DBTABLE}' and campo='{$campo}'", $puntero );
$row = sql_Fila( $puntero );
if( trim($row[1])!='' ){
$etiqueta .= trim($row[1]);
}else{
$etiqueta .= trim($row[0]);
}
}
}
if( $etiqueta == '' && substr($campo,0,3)=='cd_' ){
for($p=0;$p |'.$campo.'|'.$dato.'|' );
$etiqueta = str_replace(' ',' ',$etiqueta);
$etiqueta = str_replace('&NBSP;',' ',$etiqueta);
$etiqueta = str_replace('
',' ',$etiqueta);
$etiqueta = str_replace('
',' ',$etiqueta);
$etiqueta = str_replace('
',' ',$etiqueta);
$etiqueta = str_replace('
',' ',$etiqueta);
$etiqueta = trim($etiqueta);
if( $etiqueta!='' ){
$valor = trim($valor);
$ExisteTabla = false;
if( substr($campo,0,3)=='cd_' ){
$sDEBUG = $_DEBUG;
$_DEBUG = 30;
if( substr($campo,0,3)=='cd_' ) $SeekTabla = substr($campo,3);
if( sql_Query( 'show columns from '.$SeekTabla, $p ) != -1 ){
$row = sql_Fila($p);
$ExisteTabla = ($row[0]!='');
}
$_DEBUG = $sDEBUG;
}
if( substr($campo,0,3)=='cd_' && $ExisteTabla ){
$MasWhere = '';
for( $p=0; $p0 ){
$tmpCondi = explode(',',substr($_RELATIONFIELDS[$p],1,$pi-1));
for( $p2=0; $p2 0 ){
if( $DimCampoCondi[count($DimCampoCondi)-1][0] == $etiqueta ){
if( $condi=='=' ){
$DimCondicion[count($DimCondicion)-1] .= ' o '.$valor;
}else{
$DimCondicion[count($DimCondicion)-1] .= ' y '.$condi.' '.$valor;
}
$Sumar = false;
}
}
if( $Sumar ){
array_push( $DimCondicion, $etiqueta.' '.$condi.' '.$valor );
array_push( $DimCampoCondi, array($etiqueta,$campo) );
}
}
}
global $_LISTCOMPARE;
if( $_LISTCOMPARE[1]!='' ){
list( $oCmp, $dCmp ) = explode(',',$_LISTCOMPARE[1]);
$oCmp = trim($oCmp);
global $$oCmp, $$dCmp;
if( $_gs_formato_!='P' ){
for( $p=0; $p') == 0 ) $tmp = '='.$tmp;
}
$DimCondicion[$p] = $etiqueta.' '.$tmp;
array_push( $DimCondicion, $ss );
}
}
}else{
for( $p=0; $p') == 0 ) $tmp = '='.$tmp;
}
$etiqueta = strtoupper($_PDFLABELHIDDEN[$dCmp]);
array_push( $DimCondicion, $etiqueta.' '.$tmp );
}
}
}
}
mysql_data_seek( $GLOBALS['_Result'], 0 );
$_TReg = $sTReg;
if( $_ClearShowFilter ) $DimCondicion = array();
if( function_exists('eChangeListCondition') ) $DimCondicion = eChangeListCondition( $DimCondicion );
}
function TransformaFecha( $tmp ){
for( $c=0; $c 0 ){
$sql = substr($sql,0,strpos(strtoupper($sql), ' FROM ') );
}
$Expresion = false;
$NomCampo = '';
for( $c=0; $c 0 ){
list( , $txt ) = explode(' as ',$DimCampo[$c]);
$DimCampo[$c] = trim($txt);
}else if( substr_count($DimCampo[$c],'(') > 0 ){
list( $comando, $txt ) = explode('(',$DimCampo[$c]);
if( $comando != 'COUNT' ){
list( $txt ) = explode(',',$txt);
$DimCampo[$c] = trim($txt);
}
}
}
return $DimCampo;
}
function _MicroSg(){
return date('H:i:').str_pad( sprintf( "%2.6f", (date('s')+substr(microtime(),0,8)) ), 9 ,'0',STR_PAD_LEFT );
}
sql_Conecta();
?>