--- inc/util.php 2001/09/25 15:38:04 1.3 +++ inc/util.php 2001/09/26 13:04:28 1.4 @@ -1,4 +1,6 @@ fetch("highlight.tpl"); } + function GenerateUsername($ime, $prezime) { + global $dbh; + $replace_from = "¹šðè澞©ŠÐÈÆ®Ž "; + $replace_to = "ssdcczzSSDCCZZ_"; + $ime = strtolower(ereg_replace('[^A-Za-z0-9]', "", + strtr($ime, $replace_from, $replace_to))); + $prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "", + strtr($prezime, $replace_from, $replace_to))); + $cnt = 1; + while ($cnt <= strlen($ime)) { + $username = substr($ime, 0, $cnt++).$prezime; + $sql = "SELECT username FROM users WHERE username = '$username'"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $row = $sth->fetchrow_array(); + $sth->finish(); + if (!$row) break; + } + if ($cnt > strlen($ime)) { + $username2 = $username; + $cnt = 1; + while (true) { + $username = $username.($cnt++); + $sql = "SELECT username FROM users WHERE username = '$username'"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $row = $sth->fetchrow_array(); + $sth->finish(); + if (!$row) break; + } + } + return $username; + } + + function GeneratePassword($length = 8) { + $chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); + array_shift($chars); + array_pop($chars); + $password = ""; + for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))]; + return $password; + } + function Auth($user = "", $pwd = "") { + global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR; + // DEBUG: + if (stristr($ME, "test.plivamed.net")) return 0; + // User-Agent: should be mnoGoSearch, but in version 3.1.19 + // it's UdmSearch so we match just search + if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0; global $PMusername, $PMpassword; if (!$user) $user = $PMusername; if (!$pwd) $pwd = $PMpassword; @@ -84,7 +137,6 @@ } Header("Content-Type: text/html; charset=ISO-8859-2"); - $ME = "http".($HTTPS?"s":"")."://".$HTTP_HOST."/".$PHP_SELF; $isEdit = stristr($ME, "/edit/") ? true : false; $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false; if ($isEdit) {