/*
Ult. Fec. Act. 04 Sep 2008
OBTIENE LOS TOTALES POR CLAVE
RECIBE UNA CONEXION Y UN ARREGLO DONDE GUARDA LOS TOTALES.
*/
function obtenerTotales($conexion, $arr_tot){
$qry_NV = "SELECT lower(lib_cve) as lib_cve, count(lib_cve) as count ";
$qry_NV.= "FROM LIBRO ";
$qry_NV.= "WHERE (lib_cve <> '') GROUP BY lib_cve";
$qry_UNA = "SELECT lower(lib_cve) as lib_cve, max(lib_adq) ";
$qry_UNA.= "FROM LIBRO WHERE (lib_cve <> '') Group by lib_cve";
if( $conexion ){
/* NUMERO DE VOLUMENES */
$rs_NV = pg_query($conexion, $qry_NV) or die("Al obtener el número de volumenes");
$num_rows = pg_num_rows($rs_NV);
aux1_obtenerTotales(&$rs_NV, ($num_rows-1), &$arr_tot);
/*
for($i=0; $i<$num_rows; $i++){
$cve = "b" . strtolower(pg_fetch_result($rs_NV, $i, "lib_cve"));
$num = pg_fetch_result($rs_NV, $i, "count");
$arr_tot[$cve]['NV'] = intval($num);
}
*/
/* ULTIMO NUMERO DE ADQUISICION */
$rs_UNA = pg_query($conexion, $qry_UNA) or die("Al obtener Ultimo numero de adquisicion");
$una_num_rows = pg_num_rows($rs_UNA);
aux2_obtenerTotales(&$rs_UNA, ($una_num_rows-1), &$arr_tot);
/*
for($i=0; $i<$una_num_rows; $i++){
$cve = "b" . strtolower(pg_fetch_result($rs_UNA, $i, "lib_cve"));
$num = pg_fetch_result($rs_UNA, $i, "max");
$arr_tot[$cve]['UNA'] = intval($num);
}
*/
} else {
echo "No existe conexion a la base de datos";
}
}//function
function aux1_obtenerTotales(&$resultSet, $numReg, &$arreglo){
if( $numReg < 0){
return;
} else {
$cve = "b" . strtolower(pg_fetch_result(&$resultSet, $numReg, "lib_cve")) or die();
$num = pg_fetch_result(&$resultSet, $numReg, "count");
$arreglo[$cve]['NV'] = intval($num);
$numReg--;
aux1_obtenerTotales(&$resultSet, $numReg, &$arreglo);
}
}
function aux2_obtenerTotales(&$resultSet, $numReg, &$arreglo){
if( $numReg < 0 ){
return;
} else {
$cve = "b" . strtolower(pg_fetch_result(&$resultSet, $numReg, "lib_cve"));
$num = pg_fetch_result(&$resultSet, $numReg, "max");
$arreglo[$cve]['UNA'] = intval($num);
$numReg--;
aux2_obtenerTotales(&$resultSet, $numReg, &$arreglo);
}
}
/*
query:
Select lower(lib_cve) as lib_cve, count(lib_cve)
From Actividad
Left join libro using(lib_id)
where (lib_cve in ('H','H1','HF','H3','H6','H7','HBM')) and (act_act = 'LIBRO REVISADO')
Group by lib_cve
*/
function resumenPorClave($arr, $conexion){
//$arr = Arreglo donde se guardaran los totales por acervo
$qry = "Select lower(lib_cve) as lib_cve, count(lib_cve) ";
$qry.= "From Rev_sp Left join libro using(lib_id) ";
$qry.= "where (lib_cve in ('H','H1','HF','H3','H6','H7','HBM')) Group by lib_cve ";
$rs = pg_query($conexion, $qry) or die("Al obtener el resumen por clave");
$num_rows = pg_num_rows($rs);
aux_resumenPorClave(&$rs, ($num_rows - 1), &$arr);
/*
for($i=0; $i<$num_rows; $i++){
$cve = "a" . strtolower(pg_fetch_result($rs, $i, "lib_cve"));
$num = pg_fetch_result($rs, $i, "count");
$arr[$cve] = intval($num);
}
*/
}//function
function aux_resumenPorClave(&$resultSet, $numReg, &$arreglo) {
if( $numReg < 0){
return;
} else {
$cve = "a" . strtolower(pg_fetch_result(&$resultSet, $numReg, "lib_cve"));
$num = pg_fetch_result(&$resultSet, $numReg, "count");
$arreglo[$cve] = intval($num);
$numReg--;
aux_resumenPorClave(&$resultSet, $numReg, &$arreglo);
}
}
function sumaClaves($inv, $cve){
$suma = 0;
$suma+= $inv['bh'][$cve];
$suma+= $inv['bhf'][$cve];
$suma+= $inv['bh7'][$cve];
$suma+= $inv['bh3'][$cve];
$suma+= $inv['bh6'][$cve];
$suma+= $inv['bhbm'][$cve];
$suma+= $inv['bh1'][$cve];
return $suma;
}
function sumaVolumenes($tot){
$suma = 0;
$suma+= $tot['bh']['NV'];
$suma+= $tot['bhf']['NV'];
$suma+= $tot['bh7']['NV'];
$suma+= $tot['bh3']['NV'];
$suma+= $tot['bh6']['NV'];
$suma+= $tot['bhbm']['NV'];
$suma+= $tot['bh1']['NV'];
return $suma;
}
function totalInventariados($inv){
$suma = array_sum($inv['bh']);
$suma+= array_sum($inv['bhf']);
$suma+= array_sum($inv['bh7']);
$suma+= array_sum($inv['bh3']);
$suma+= array_sum($inv['bh6']);
$suma+= array_sum($inv['bhbm']);
$suma+= array_sum($inv['bh1']);
return $suma;
}
function totalPertenecientes($inv) {
/*Suma de los libros inventariados
por una biblioteca que si pertenecen a la bibioteca*/
$suma = 0;
$suma += $inv['bh']['ah'];
$suma += $inv['bhf']['ahf'];
$suma += $inv['bh7']['ah7'];
$suma += $inv['bh3']['ah3'];
$suma += $inv['bh6']['ah6'];
$suma += $inv['bhbm']['ahbm'];
$suma += $inv['bh1']['ah1'];
return $suma;
}
/*OBTIENE EL ACERVO DE UNA CLAVE DE BIBLIOTECA Y DE UNA BD ESPECIFICA
EJEMPLO: LOS LIBROS H DE LA BIBLIOTECA HF.
Query:
SELECT lib_id FROM REV_SP
LEFT JOIN LIBRO using(lib_id)
WHERE (lib_cve = '".strtoupper($cve)."') ORDER BY lib_id
*/
function acervo($cve, $bd){
$conexion = pg_connect("dbname=".$bd) or die();
$qry = "SELECT upper(lib_id) ";
$qry.= "FROM REV_SP LEFT JOIN LIBRO using(lib_id) ";
$qry.= "WHERE (upper(lib_cve) = '".strtoupper($cve)."') Order by lib_id";
$rs = pg_query($conexion, $qry) or die($qry . " BASE: " . $bd);
//echo "
$qry ($bd)
";
pg_close($conexion);
$arreglo = array();
$arreglo = pg_fetch_all_columns($rs);
return $arreglo;
}
function registrosUnicos($cve, $bd){
$conexion = pg_connect("dbname=".$bd) or die();
$qry = "SELECT upper(lib_id) ";
$qry.= "FROM REV_SP LEFT JOIN LIBRO using(lib_id) ";
$qry.= "WHERE (upper(lib_cve) = '".strtoupper($cve)."') Order by lib_id";
$rs = pg_query($conexion, $qry) or die($qry . " BASE: " . $bd);
//echo "
$qry ($bd)
";
pg_close($conexion);
$arreglo = array();
$arreglo = pg_fetch_all_columns($rs);
$unicos = array(); $unicos = array_unique($arreglo);
return $unicos;
}
function repetidos($cve_verde, $arr_cve, $deOtras){
//Saca el acervo verde
$verde = array();
$verde = acervo($arr_cve[$cve_verde]['CVE'], $arr_cve[$cve_verde]['BD']);
//Saca los acervos amarillos
//Crea un arreglo con un solo elemento para extraerlo del arreglo de claves
$arr_verde = $arr_cve[$cve_verde];
$arr_verde[$cve_verde] = array();
$arr_verde[$cve_verde]['BD'] = $arr_cve[$cve_verde]['BD'];
$arr_verde[$cve_verde]['CVE'] = $cve_verde;
//En el arreglo con las claves de los acervos amarillos se guardan todos menos el verde
$cves_amarillos = array();
$cves_amarillos = array_diff_assoc($arr_cve, $arr_verde);
//Por cada conjunto amarillo se obtiene el acervo y se junta con todos los demas conjuntos
//amarillos ($amarillos)
$amarillos = array();
foreach($cves_amarillos as $a){
$arr_tmp = array();
$arr_tmp = acervo($cve_verde, $a['BD']);
$amarillos = array_merge($amarillos, $arr_tmp);
}
//junta los acervos amarillos y deja los ID unicos
$amarillos_unicos = array_unique($amarillos);
//echo count($amarillos) - count($amarillos_unicos) . "
";
$deOtras = count($amarillos_unicos);
//intersecta el verde y el amarillo
$interseccion = array_intersect($amarillos_unicos, $verde); //NOS DA AQUELLOS EN AMARILLOS QUE SE ENCUENTREN EN VERDE
//devuelve el tamaño de la interseccion
unset($verde);
unset($amarillos);
unset($amarillos_unicos);
$num = count($interseccion);
unset($interseccion);
return $num;
}
function elementos_repetidos($cve_verde, $arr_cve, $deOtras){
//DEVUELVE UN ARREGLO CON LOS ELEMENTOS REPETIDOS.
//Saca el acervo verde
$verde = array();
$verde = acervo($arr_cve[$cve_verde]['CVE'], $arr_cve[$cve_verde]['BD']);
//Saca los acervos amarillos
//Crea un arreglo con un solo elemento para extraerlo del arreglo de claves
$arr_verde = $arr_cve[$cve_verde];
$arr_verde[$cve_verde] = array();
$arr_verde[$cve_verde]['BD'] = $arr_cve[$cve_verde]['BD'];
$arr_verde[$cve_verde]['CVE'] = $cve_verde;
//En el arreglo con las claves de los acervos amarillos se guardan todos menos el verde
$cves_amarillos = array();
$cves_amarillos = array_diff_assoc($arr_cve, $arr_verde);
//Por cada conjunto amarillo se obtiene el acervo y se junta con todos los demas conjuntos
//amarillos ($amarillos)
$amarillos = array();
foreach($cves_amarillos as $a){
$arr_tmp = array();
$arr_tmp = acervo($cve_verde, $a['BD']);
$amarillos = array_merge($amarillos, $arr_tmp);
}
//junta los acervos amarillos y deja los ID unicos
$amarillos_unicos = array_unique($amarillos);
//echo count($amarillos) - count($amarillos_unicos) . "
";
$deOtras = count($amarillos_unicos);
//intersecta el verde y el amarillo
$interseccion = array_intersect($verde, $amarillos_unicos);
//devuelve el tamaño de la interseccion
unset($verde);
unset($amarillos);
unset($amarillos_unicos);
return $interseccion;
}
?>
No se puede establecer conexion con la base de datos
No se puede establecer conexion con la base de datos H
No se puede establecer conexion con la base de datos HF
No se puede establecer conexion con la base de datos H7
No se puede establecer conexion con la base de datos H3
No se puede establecer conexion con la base de datos H6
No se puede establecer conexion con la base de datos H1
LIBROS INVENTARIADOS DE LA CLAVE HBM
Clave | Registros |
HBM | |
H | |
HF | |
H7 | |
H3 | |
H6 | |
H1 | |
Total | 0 |
Núm |
Bibl. |
Adquisición |
Matriz |
Título |
Autor(es) |
Clasificación |
Clave |
Edición |
Fecha |
Lugar de edición |
Editorial |
ISBN |
Volumen |
Tiene errores |
Observaciones |
Descripción del color |
Entrepaño |
Id |