$campo() == $id) return $item; } return null; } function yo(){ $user = $_SESSION["usuario"]; if (!$user) return "NN"; return $user->get_nombre() . " " . $user->get_apellido() ; } function convertirHora_HoraBD($hora){ $hora = explode(":",$hora); return $fecha[2].$fecha[1].$fecha[0]; } function convertirHoraBD_Hora($hora){ $pos = strrpos($hora, ":"); if ($pos === false){ return substr($hora, 0, 2).":".substr($hora, 2, 2); } return $hora; } function validar_tabla_db($table_name){ global $conn; // $table_name = "rrhh_ficha_personal"; $res = $conn->Execute("show tables like '$table_name'"); if(strtoupper($res->fields[0]) != strtoupper($table_name)){ $direccion = "fachada/sql/" . $table_name . ".sql"; $query = file_get_contents($direccion); if ($query) $conn->Execute($query); } } function bg_lista_php(){ return "onMouseOver=\'style.backgroundColor='#FEDFA2';\' onMouseOut=\'style.backgroundColor='';\'"; } function popup_php($text,$width){ $width = ""; return 'onmouseover="return overlib(\''.$text.'\', WIDTH, \''.$width.'\', TIMEOUT, 1500);" onblur="return nd();" onmouseout="return nd();" onclick="return nd();"'; } function retornar_array_week($fecha,$valor){ $hor = substr($fecha,8,2); $min = substr($fecha,10,2); $mes = substr($fecha,4,2); $dia = substr($fecha,6,2); $año = substr($fecha,0,4); $time = mktime ($hor, $minu, 0, $mes , $dia, $año); $dia_semana = date("N", $time); $diferencia = $dia_semana - 1; $lunes = mktime(0,0,0, $mes,$dia,$año) - ($diferencia - $valor) * 24 * 60 * 60; //echo date("d-m-Y",$lunes); for ($i=0;$i<7;$i++){ $nueva = $lunes + $i * 24 * 60 * 60; $array_week[] = date("Ymdhm",$nueva); } return $array_week; } function get_permiso($seguridad){ $usuario = new Usuario(); $usuario = $_SESSION["usuario"]; if ($usuario->get_privilegio() >= $seguridad){ return true; }else{ return false; } } function money_php($val) { $number = $val; $decimals = "0"; $decpoint = "."; $thousandsep = "."; return "$".number_format($number, $decimals, $decpoint, $thousandsep); } function calcular_dias_entre($fecha1,$fecha2) { $fecha1 = convertirFechaBD_fecha($fecha1); $fecha2 = convertirFechaBD_fecha($fecha2); $fecha1 = explode("/",$fecha1); $fecha2 = explode("/",$fecha2); $fecha1 = mktime(1,0,0,$fecha1[1],$fecha1[0],$fecha1[2]); $fecha2 = mktime(1,0,0,$fecha2[1],$fecha2[0],$fecha2[2]); $dia = 24 * 60 * 60; $dif = $fecha1 - $fecha2; $dias = $dif/$dia; $dias = ceil($dias); return $dias; } function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function get_extra_var($tabla){ global $MAPEOS; return $MAPEOS[$tabla]; } function make_query_return_operation($key){ $op = "LIKE"; if (substr($key,0,2) == ">="){ $op = ">="; $key = substr($key,2); } if (substr($key,0,2) == "<="){ $op = "<="; $key = substr($key,2); } if (substr($key,0,1) == "!"){ $op = "!="; $key = substr($key,1); } if (substr($key,0,1) == ">"){ $op = ">"; $key = substr($key,1); } if (substr($key,0,1) == "<"){ $op = "<"; $key = substr($key,1); } if (substr($key,0,1) == "="){ $op = "="; $key = substr($key,1); } $return["op"] = $op; $return["key"] = $key; return $return; } function make_query($tabla, $filtro, $extra, $extra_var, $tipo = null, $tabla_primary_key){ //debug() // ESTA FUNCIONANDO BIEN if (!$filtro){ $where = ""; }else{ $where = "WHERE "; $count = 0; foreach ($filtro as $key => $item) { /* ESTO ES PARA CUANDO SE NECESITE FILTRAR POR UN VALOR QUE ESTA EN UNA TABLA DISTINTA A LA DE DONDE SE SACAN LOS DATOS, COMO SE DEBE MODIFICAR TODOS LOS LUGARES DONDE SE OCUPE FILTRO, POR AHORA SE PASA UN ATRIBUTO MAS AL MAKE_QUERY */ $array = explode(".",$key); $nombre_tabla = $array[0]."|".$array[0]; if ($array[1] && !in_array($nombre_tabla,$tablas_extras)){ $tablas_extras[] = $nombre_tabla; } if (sizeof($array)>1){ $tabla_externa = true; }else $tabla_externa = false; if (is_array($item)){ $count2 = 0; $where .= "("; foreach ($item as $key2 => $x){ $return_op = make_query_return_operation($key2); $op = $return_op["op"]; $key2 = $return_op["key"]; $and_or = substr($key2,-2,2); if (!$tabla_externa){ $where .= "$tabla.$key $op '$x'"; }else $where .= "$key $op '$x'"; $count2++; if ($count2 < sizeof($item)) if ($and_or == "&&") $where .= " AND "; else $where .= " OR "; } $where .= ")"; }else{ $return_op = make_query_return_operation($key); $op = $return_op["op"]; $key = $return_op["key"]; if (!$tabla_externa){ if (is_numeric($item) || (stristr($item,"%"))) $where .= "$tabla.$key $op '$item'"; else{ $verificar_explode = explode(".",$item); if (sizeof($verificar_explode) > 1) $where .= "$tabla.$key $op $item"; else $where .= "$tabla.$key $op '$item'"; } }else{ if (is_numeric($item) || (stristr($item,"%"))){ $where .= "$key $op '$item'"; } else { $where .= "$key $op $item"; } } } if ($count < sizeof($filtro)-1) $where .= " AND "; $count++; } } if ($tabla_primary_key){ $tabla_primary_key = explode("|",$tabla_primary_key); $alias_pk = $tabla_primary_key[2]; if (!$alias_pk) $alias_pk = $tabla_primary_key[0]; $join[$tabla_primary_key[1]] = $tabla_primary_key[1].".".$tabla_primary_key[0]." = ".$tabla.".".$alias_pk." AND "; } foreach ($extra_var as $key => $value){ $arr = explode("|", $value); $nombre_tabla = trim($arr[0]); $nombre_campo = trim($arr[1]); $id_interno = trim($arr[2]); $id_externo = trim($arr[3]); $nombre_tabla_hr= trim($arr[4]); $id_interno_hr = trim($arr[5]); $id_externo_hr = trim($arr[6]); $alias = $nombre_tabla; if (!$id_externo) $id_externo = $id_interno; if ($nombre_tabla_hr) $q_var_extras .= ", $nombre_tabla_hr.$nombre_campo AS $key"; else $q_var_extras .= ", $alias.$nombre_campo AS $key"; if ($nombre_tabla_hr){ if (!$id_externo_hr) $id_externo_hr = $id_interno_hr; if (!stristr($join[$nombre_tabla_hr],"$tabla.$id_interno = $alias.$id_externo")){ $join[$nombre_tabla_hr] .= "$nombre_tabla_hr.$id_interno_hr = $alias.$id_externo_hr AND "; $where_hr = "$tabla.$id_interno = $alias.$id_externo"; $tablas_hr[$nombre_tabla_hr] = $alias; } if (!stristr($q_var_link,"$tabla.$id_interno = $nombre_tabla.$id_externo AND ")) $q_var_link .= "$tabla.$id_interno = $nombre_tabla.$id_externo AND "; }else{ if (!stristr($join[$nombre_tabla],"$tabla.$id_interno = $alias.$id_externo")) $join[$nombre_tabla] .= "$tabla.$id_interno = $alias.$id_externo AND "; } } $q_var_link = substr($q_var_link,0,-4); if (($where) and ($q_var_link)) $q_var_link = " AND " . $q_var_link; $where .= $q_var_link; if (($where) and (substr($where, 0, 5) !== "WHERE")) $where = "WHERE " . $where; if (($where_hr) and (substr($where, 0, 5) !== "WHERE")) $where = "WHERE " . $where_hr; if ($where == "WHERE "){ $where = ""; } //Extras de la Querie if ($extra["sum"]){ $tipo = "sum"; $array = explode("|",$extra["sum"]); if ($array[1]) $alias_sum = $array[1]; else $alias_sum = $array[0]; $sum = $array[0]; } if ($extra["count"]){ $tipo = "count"; $array = explode("|",$extra["count"]); if ($array[1]) $alias_count = $array[1]; else $alias_count = $array[0]; $count = $array[0]; $extra["group"] = $count; } if ($extra["group"]){ $where .= " GROUP BY ".$extra["group"]." "; } if ($extra["order"]){ $where .= " ORDER BY ".$extra["order"]." "; } if ($extra["sort"]){ $where .= " ".$extra["sort"]." "; } if ($extra["limit"]){ if ($extra["desde"]){ $where .= " LIMIT ".$extra["desde"].",".$extra["limit"]; }else{ $where .= " LIMIT ".$extra["limit"]; } }else{ if ($extra["desde"]){ $where .= " LIMIT ".$extra["desde"].",0"; } } if ($extra["sql"]){ $where .= $extra["sql"]; } //debug($tablas_hr); switch ($tipo){ case "cantidad" : $str_tipo = "count(*) as cantidad "; break; case "sum" : $str_tipo = "DISTINCT $tabla.* $q_var_extras, SUM($tabla.$sum) as $alias_sum";break; case "count" : $str_tipo = "DISTINCT $tabla.* $q_var_extras, COUNT($tabla.$count) as $alias_count";break; default: $str_tipo = "DISTINCT $tabla.* $q_var_extras"; break; } $q = " SELECT $str_tipo FROM $tabla"; $qj = ""; $icount = 1; foreach ($join as $tabla=>$on){ $tabla = trim($tabla); $incorporar = true; /* if (array_search($tabla,$tablas_hr)){ $tablas_hr[$tabla] = "($tablas_hr[$tabla], $tabla)"; $incorporar = false; } if ($tablas_hr[$tabla]) $tabla = "($tabla, $tablas_hr[$tabla])";*/ //debug(array_search($tablas_hr[$tabla],$tablas_incluidas)); if (!array_search($tablas_hr[$tabla],$tablas_incluidas) && $tablas_hr[$tabla]){ $tablas_incluidas[$icount++] = $tablas_hr[$tabla]; $tabla_escribir = "($tabla, $tablas_hr[$tabla])"; }else{ $tabla_escribir = $tabla; $tablas_incluidas[$icount++] = $tabla; } $on = substr($on,0,-4); if (!strstr($qj, $tabla) && $incorporar){ $qj.= " LEFT JOIN $tabla_escribir ON $on"; } } $q .= $qj; $q .= " $where "; //debug($q); return $q; } function make_query2($tabla, $filtro, $extra, $extra_var){ if (!$filtro){ $where = ""; }else{ $where = "WHERE "; $count = 0; foreach ($filtro as $key => $item) { $array = explode(".",$key); $nombre_tabla = $array[0]."|".$array[0]; if ($array[1] && !in_array($nombre_tabla,$tablas_extras)){ $tablas_extras[] = $nombre_tabla; } if (sizeof($array)>1){ $tabla_externa = true; }else $tabla_externa = false; if (is_array($item)){ $count2 = 0; $where .= "("; foreach ($item as $key2 => $x){ $op = "LIKE"; if (substr($key2,0,1) == "!"){ $op = "!="; } if (substr($key2,0,1) == ">"){ $op = ">"; } if (substr($key2,0,1) == "<"){ $op = "<"; } if (substr($key2,0,2) == ">="){ $op = ">="; } if (substr($key2,0,2) == "<="){ $op = "<="; } if (!$tabla_externa){ $where .= "$tabla.$key $op '$x'"; }else $where .= "$key $op '$x'"; $count2++; if ($count2 < sizeof($item)) $where .= " OR "; } $where .= ")"; }else{ $op = "LIKE"; if (substr($key,0,1) == "!"){ $op = "!="; $key = substr($key,1); } if (substr($key,0,1) == ">"){ $op = ">"; $key = substr($key,1); } if (substr($key,0,1) == "<"){ $op = "<"; $key = substr($key,1); } if (substr($key,0,2) == ">="){ $op = ">="; $key = substr($key,2); } if (substr($key,0,2) == "<="){ $op = "<="; $key = substr($key,2); } if (!$tabla_externa){ if (is_numeric($item) || (stristr($item,"%"))) $where .= "$tabla.$key $op '$item'"; else $where .= "$tabla.$key $op '$item'"; }else{ if (is_numeric($item) || (stristr($item,"%"))){ $where .= "$key $op '$item'"; } else { $where .= "$key $op $item"; } } } if ($count < sizeof($filtro)-1) $where .= " AND "; $count++; } } //debug($tablas_extras); foreach ($extra_var as $key => $value){ $arr = explode("|", $value); $nombre_tabla = $arr[0]; $nombre_campo = $arr[1]; $id_interno = $arr[2]; $id_externo = $arr[3]; $alias = $arr[4]; if (!$id_externo) $id_externo = $id_interno; if (!$alias) $alias = $nombre_tabla; $q_var_extras .= ", $alias.$nombre_campo AS $key"; if (!stristr($q_var_link,"$tabla.$id_interno = $alias.$id_externo AND ")) $q_var_link .= "$tabla.$id_interno = $alias.$id_externo AND "; // Verifica todas las tablas nuevas a incluir en la query if ($alias) $nombre_tabla = $nombre_tabla."|".$alias; if (!in_array($nombre_tabla, $tablas_extras)){$tablas_extras[] = $nombre_tabla;} } foreach ($tablas_extras as $t){ if(strstr($t, "|")){ $arr = explode("|", $t); if (!stristr($q_tablas_extras, trim($arr[0]))) $q_tablas_extras .= ", " . trim($arr[0]) . " as " . trim($arr[1]); }else{ if (!stristr($q_tablas_extras, $t)) $q_tablas_extras .= ", " . $t; } } $q_var_link = substr($q_var_link,0,-4); if (($where) and ($q_var_link)) $q_var_link = " AND " . $q_var_link; $where .= $q_var_link; if (($where) and (substr($where, 0, 5) !== "WHERE")) $where = "WHERE " . $where; //Extras de la Querie if ($extra["group"]){ $where .= " GROUP BY ".$extra["group"]." "; } if ($extra["order"]){ $where .= " ORDER BY ".$extra["order"]." "; } if ($extra["sort"]){ $where .= " ".$extra["sort"]." "; } if ($extra["limit"]){ if ($extra["desde"]){ $where .= " LIMIT ".$extra["desde"].",".$extra["limit"]; }else{ $where .= " LIMIT ".$extra["limit"]; } }else{ if ($extra["desde"]){ $where .= " LIMIT ".$extra["desde"].",0"; } } if ($extra["sql"]){ $where .= $extra["sql"]; } $q = " SELECT DISTINCT $tabla.* $q_var_extras FROM $tabla $q_tablas_extras $where "; //debug($q); return $q; } function exec_query($query){ global $conn; $conn -> debug = CONN_DEBUG; $RecordSet = &$conn -> Execute($query); if ($RecordSet){ while (!$RecordSet -> EOF) { $listado_campos = $RecordSet->fields; foreach ($listado_campos as $campo => $valor){ if (!is_numeric($campo)){ $temp[$campo] = $valor; } } $vector[] = $temp; $RecordSet -> MoveNext(); } return $vector; } return null; } function convertir_money($nro){ $number = $nro; $decimals = "0"; $decpoint= "."; $thousandsep="."; return "$" . number_format($number, $decimals, $decpoint, $thousandsep); } function to_string($object){ $str = ""; foreach ($object as $key => $value){ $tok = strtok ($key, "_"); $ok = true; switch ($tok) { case "id": $ok = false; break; case "to": $ok = false; break; case "estado": $ok = false; break; } if ($ok){ if ($tok == "fecha") {$value = miniFecha($value);} $nombre = ucfirst(str_replace("_", " ", $key)); $str .= $nombre . ": " . $value . "
"; } } return $str; } function format_array_combobox($arr, $id, $name1, $id_padre, $conector, $name2, $fin){ $id = "get_" . $id; $name1 = "get_" . $name1; $fn_id_padre = "get_" . $id_padre; $array_tmp = null; foreach ($arr as $item){ if ($name2){ $name2_mod = "get_" . $name2; $nombre_2 = $item->$name2_mod(); } $temp["id"] = $item->$id(); $temp["name"] = $item->$name1() . $conector . $nombre_2 . $fin; if ($id_padre) $temp["id_padre"] = $item->$fn_id_padre(); $array_tmp[] = $temp; } return $array_tmp; } function get_id_usuario(){ $user = new Usuario(); $user = $_SESSION["usuario"]; return $user->get_id_usuario(); //return $user["id_usuario"]; } function makebarcode($codigo_barra, $cantidad=8){ $txt = "%0" . $cantidad . "s"; if (is_numeric($codigo_barra)){ $codigo_barra = sprintf($txt,$codigo_barra); }else{ $codigo_barra = sprintf($txt,0); } return $codigo_barra; } function convertirFecha_fechabd($fecha, $comp){ if (substr_count($fecha, "/") != 0){ $fecha = explode("/",$fecha); return $fecha[2].$fecha[1].$fecha[0].$comp; } return $fecha; } function convertirFechaBD_fecha($fecha){ if (substr_count($fecha, "/") == 0){ return substr($fecha, 6, 2)."/".substr($fecha, 4, 2)."/".substr($fecha, 0, 4); } return $fecha; } function miniFecha($val){ $dia = substr($val, 6, 2); $mes = substr($val, 4, 2); $año = substr($val, 0, 4); $hor = substr($val, 8, 2); $min = substr($val, 10, 2); if ($hor){ return $dia."-".$mes."-".$año. " (".$hor.":".$min.")"; } return $dia."-".$mes."-".$año; } function expandirFecha($val){ $dia = substr($val, 6, 2); $mes = substr($val, 4, 2); $año = substr($val, 0, 4); $fecha = getdate(mktime (0,0,0,$mes,$dia,$año)); $wdia = $fecha['wday']; // Día de la Semana switch ($wdia){ case "1": $tdia = "Lunes";break; case "2": $tdia = "Martes";break; case "3": $tdia = "Miércoles";break; case "4": $tdia = "Jueves";break; case "5": $tdia = "Viernes";break; case "6": $tdia = "Sábado";break; case "0": $tdia = "Domingo";break; } // Mes switch ($mes){ case "01": $mes = "Enero";break; case "02": $mes = "Febrero";break; case "03": $mes = "Marzo";break; case "04": $mes = "Abril";break; case "05": $mes = "Mayo";break; case "06": $mes = "Junio";break; case "07": $mes = "Julio";break; case "08": $mes = "Agosto";break; case "09": $mes = "Septiembre";break; case "10": $mes = "Octubre";break; case "11": $mes = "Noviembre";break; case "12": $mes = "Diciembre";break; } return $tdia.", ".$dia." de ".$mes." de ".$año; } /*** Agregado por Macphisto ***/ function enviarMail($to, $subject, $msg){ $headers = "From: ITEK Chile \r\n"; mail($to, $subject, $msg, $headers); } function hoy() { date_default_timezone_set(Chile/Continental); return date("YmdHi", mktime(date("H"),date("i"),0,date("m"),date("d"),date("Y"))); } function & format_money($val) { return number_format($val, 0, ',', '.'); } function & format_rut($val) { $rut = $val; //debug($rut); if (strlen($rut) > 6 ){ $rut = number_format($rut, 0, ',', '.').substr($rut,-2,2); if (strlen($rut) < 12) $rut = "0".$rut; return $rut; }else{ return "- -"; } } function debug($var, $text){ if ($text) {$text .= " : ";} echo "
$text"; var_dump($var); echo "
"; return 1; } function eliminar_pos_arreglo($arreglo,$pos_eliminar){ for ($i=0,$j=0;$ilogHTML("$str: $errstr (on $errfile:$errline)"); } set_error_handler("myErrorHandler"); function detect_pda() { // The set of brosers $browsers = array( "Windows CE", "WebTV", "AvantGo", "Blazer", "PalmOS", "lynx", "Go.Web", "Elaine", "ProxiNet", "ChaiFarer", "Digital Paths", "UP.Browser", "Mazingo", "Mobile", "T68", "Syncalot", "NetFront", "Danger", "Symbian", "Nokia", "Xiino", "AU-MIC", "EPOC"); // The test if(preg_match('/('.implode('|', $browsers).')/i', $_SERVER['HTTP_USER_AGENT'], $match)) { return true; } else if (isset($_SERVER['HTTP_UA_OS'])) { if (strstr($_SERVER['HTTP_UA_OS'],"POCKET PC") !== false) { return true; } } else { return false; } } ?>