gest366/api/lib/modutil.php

44 lines
1.0 KiB
PHP

<?php
/**
* Controlla se la chiave indicata è esistente per un determinato utente.
*
* @param string $key Chiave da controllare
*/
function user_check($key){
global $dbo;
$results = $dbo->fetchArray("SELECT idutente FROM zz_utenti WHERE MD5( CONCAT(username,password) )=\"" . $key . "\"");
if (sizeof($results) != 0) {
return $results[0]['idutente'];
}
return false;
}
/**
* Esegue una ricerca binaria dell'elemento $elemento nel campo $where dell'array
* Necessita un'array ordinato!!!
*
* @param mixed[] $array
* @param mixed $elemento
* @param string $where Campo di ricerca
* @return int Posizione dell'elemento
*/
function ricerca($array, $elemento, $end = null, $where = 'id') {
$start = 0;
if(!isset($end)) $end = count($array) - 1;
$centro = 0;
while ($start <= $end) {
$centro = intval(($start + $end) / 2);
if ($elemento < $array[$centro][$where]) {
$end = $centro - 1;
}
else {
if ($elemento > $array[$centro][$where]) $start = $centro + 1;
else return $centro;
}
}
return -1;
}
?>