0){ return true; } else { return false; } } function idsql($sql){ $rx = mysqli_query($GLOBALS['db'],$sql); if(mysqli_num_rows($rx)){ $f = mysqli_fetch_array($rx); $a = $f["id"]; mysqli_free_result($rx); } else { $a = 0; } return $a; } function countsql($sql){ $rx = mysqli_query($GLOBALS['db'],$sql); return mysqli_num_rows($rx); } function addsql($sql){ $rx = mysqli_query($GLOBALS['db'],$sql); $rx = mysqli_insert_id($GLOBALS['db']); if($rx == "") $rx = 0; return $rx; } function RowID(){ return date("YmdHis",time())."_".md5(uniqid(rand())); } function getval($tabla,$fld,$val,$x = "id"){ $sql = "select * from $tabla where $x='".addslashes($val)."'"; $rsa = mysqli_query($GLOBALS['db'],$sql); $f = mysqli_fetch_array($rsa); $dat = StripSlashes($f[$fld]); mysqli_free_result($rsa); return ($dat); } function dbtoar($sql){ $rs = mysqli_query($GLOBALS['db'],$sql); $rc = mysqli_num_rows($rs); if($rc){ /* if(mysqli_num_rows($rs)==1){ $i = mysqli_fetch_array($rs); mysqli_free_result($rs); return $i; } else { */ $x = 0; $data = array(); while($i=mysqli_fetch_assoc($rs)){ $data[$x]=$i; $x++; } mysqli_free_result($rs); return $data; // } } else { return false; } } function getextradat($inmueble,$extra,$campo){ $sql = "select $campo from inmuebles_extras_datos where extra=$extra and inmueble=$inmueble limit 1"; //echo $sql."
"; $rsa = mysqli_query($GLOBALS['db'],$sql); $f = mysqli_fetch_array($rsa); $dat = StripSlashes($f[$campo]); mysqli_free_result($rsa); return ($dat); } function extension_get($a){ $a = strtolower($a); if($a){ if(!strpos(" ".$a,".")){ return false; } else { $a = explode(".",$a); return $a[count($a)-1]; } } else { return false; } } function deletefile($file) { $delete = @unlink($file); if (@file_exists($file)) { $filesys = eregi_replace("/","\\",$file); $delete = @system("del $filesys"); if (@file_exists($file)) { $delete = @chmod ($file, 0775); $delete = @unlink($file); $delete = @system("del $filesys"); } } } function fch2dt($d){ $d = explode("/",$d,3); return $d[2].$d[1].$d[0]; } function dt2fch($d){ if(strlen($d) > 8) $d = substr($d,0,8); if($d){ return substr($d,6,2)."/".substr($d,4,2)."/".substr($d,0,4); } else { return ""; } } function dt2ts($a,$opc=0){ if(strlen($a) > 8) $a = substr($a,0,8); $y = intval(substr($a,0,4)); $m = intval(substr($a,4,2)); $d = intval(substr($a,6,2)); if($opc){ return mktime(0,0,0,$m,$d,$y); }else{ return mktime(23,59,59,$m,$d,$y); } } function dttime($a){ return date("Ymd",$a); } function lim($a,$largo = 200){ $a = trim(stripslashes($a)); $a = strip_tags($a); $a = html_entity_decode($a); if(strlen($a) > $largo){ $a = substr($a,0,($largo - 3))."..."; } return $a; } function tohour($a){ if(strlen($a) != 6){ return ""; }else{ return substr($a,0,2).":".substr($a,2,2).":".substr($a,4,2); } } function getstr($fld,$db="tareas"){ $sql = "select * from $db limit 1"; $rsa = mysqli_query($GLOBALS['db'],$sql); $f = mysqli_fetch_array($rsa); $dat = trim(StripSlashes($f[$fld])); mysqli_free_result($rsa); return $dat; } function humandate($a){ //recibo solo timestamp if(!is_numeric($a)){ return ""; } else { $d = explode(",",dias); $m = explode(",",meses); return $d[date("w",$a)].", ".date("j",$a)." de ".$m[date("n",$a)]." de ".date("Y",$a); } } function getstr2($db,$fld){ $sql = "select * from $db limit 1"; $rsa = mysqli_query($GLOBALS['db'],$sql); $f = mysqli_fetch_array($rsa); $dat = trim(StripSlashes($f[$fld])); mysqli_free_result($rsa); return $dat; } Function Right($orig,$ini){ $right=strrev($orig); $right=substr(" ".$right,1,$ini); return strrev($right); } function fmtnum($a){ // v 20110221 if(strpos($a,",")>0){ $aux = explode(",",$a); if(count($aux) > 2){ $dec = $aux[count($aux)-1]; $ent = ""; for($n=0;$n < count($aux)-1;$n++){ $ent.= $aux[$n]; } $a = $ent.",".$dec; } $a = str_replace(".","" ,$a); $a = str_replace(",",".",$a); } else { $p = strpos(" ".strrev($a),"."); if($p==4){ $a = str_replace(".","",$a); } else { $b = substr($a,0,strlen($a)-$p); $b = str_replace(".","",$b); $a = $b.right($a,$p); } } if(!is_numeric($a)) $a = 0; return $a; } function fmt($a){ return number_format($a,2,",","."); } function getvalue($tabla,$fld,$val,$x = "id"){ $sql = "select * from $tabla where $x='".addslashes($val)."' limit 1"; $rsa = mysqli_query($GLOBALS['db'],$sql); $f = mysqli_fetch_array($rsa); $dat = StripSlashes($f[$fld]); mysqli_free_result($rsa); return $dat; } function generatePassword() { $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand((double)microtime()*1000000); $i = 0; while ($i < 8) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass.$tmp; $i++; } return $pass; } function sumsql($sql){ $rx = mysqli_query($GLOBALS['db'],$sql); $g = mysqli_fetch_row($rx); $aux= $g[0]; mysqli_free_result($rx); return $aux; } function isfch($fecha){ //v2 if(strpos($fecha,"/")){ if(strlen($fecha) != 10) return false; $aux = explode("/",$fecha,3); $d = $aux[0]; $m = $aux[1]; $y = $aux[2]; }else{ if(strlen($fecha) != 8) return false; $m = substr($fecha,2,2); $d = substr($fecha,0,2); $y = substr($fecha,4,4); } if($m < 1 || $m > 12) return false; if($d <1 || $d > 31) return false; if($y < 1900) return false; if(!is_date($m,$d,$y)) return false; return true; } function is_date($m,$d,$y){ $a = str_pad($d,2,"0",STR_PAD_LEFT)."/". str_pad($m,2,"0",STR_PAD_LEFT)."/".$y; $b = date("d/m/Y",dt2ts(intval($y."".$m."".$d))); if($a==$b){ return true; } else { return false; } } function titulos($session){ $aux = ""; $sql = "select producto,(select titulo from productos where id=pe.producto) as pname from pedidos pe where session='$session' order by pname "; $rsa = mysqli_query($GLOBALS['db'],$sql); while($f=mysqli_fetch_array($rsa)){ if($aux) $aux.= " | "; $aux.= "".utf8_encode(getdb($f["pname"])).""; } mysqli_free_result($rsa); return trim($aux); } //contramedidas sql inject function sql_armor(){ foreach($_REQUEST as $key => $data){ $data = strtolower($data); if (strpos($data, "base64_") !== false) exit; if (strpos($data, "union") !== false && strpos($data, "select") !== false) exit; } } sql_armor(); //---------------------- //if(!$_SESSION["actua"]){ /* mysqli_query($db,"update productos set stock=case when (select sum(stock) from productosxtalle where producto=productos.id) > 0 then 1 else 0 end "); mysqli_query($db,"update productos set soldout=case when (select sum(stock) from productosxtalle where producto=productos.id) > 0 then 0 else 1 end "); mysqli_query($db,"update productos set stock=1,soldout=0 where stockfijo > 0 and (select talles from productos_categorias where id=productos.categoria) = 0 "); mysqli_query($db,"update productos set stock=0, soldout=1 where stockfijo = 0 and (select talles from productos_categorias where id=productos.categoria) = 0 "); $_SESSION["actua"]=true; */ //} ?>