--- inc/util.php 2001/09/19 12:23:57 1.2 +++ inc/util.php 2001/10/31 10:12:28 1.12 @@ -1,4 +1,6 @@ $maxsize) { + $ratio = ($w / $h); + $w = intval($maxsize); + $h = intval($w / $ratio); + } + return array($w, $h); + } + + function GetLinks($read, $more, $more_title, $id, $cat, $name, $updown = false, $up = false, $down = false, $prikazi = true, $related = false) { + $t = new Smarty(); + global $section, $section_menu, $section_menu2, $spec, $isMed, $isEdit, $offset; + $t->assign("section", $section); + $t->assign("section_menu", $section_menu); + $t->assign("section_menu2", $section_menu2); + $t->assign("spec", $spec); + $t->assign("offset", $offset); + $t->assign("id", $id); + $t->assign("cat", $cat); + $t->assign("med", $isMed); + $m = "tmore"; + if ($cat == "t" || $cat == "3") $m = "tmore"; + if ($cat == "w") $m = "wmore"; + if ($cat == "p") $m = "pmore"; + $t->assign("m", $m); + $t->assign("name", $name); + $t->assign("read", ($read || $related) ? $read : ""); + $t->assign("more", /* $more */ strstr($more, "?") ? $more : ""); + $t->assign("more_new", strstr($more, "://") ? true : false); + $t->assign("more_title", $more_title); + $t->assign("edit", $isEdit); + $t->assign("updown", $updown); + $t->assign("up", $up); + $t->assign("down", $down); + $t->assign("prikazi", $prikazi); + $t->assign("related", $related); + return $t->fetch("links.tpl"); + } + + function GetRead($id, $ct = "") { + global $section, $section_menu, $section_menu2, $spec, $offset, $cat, $acat, $acat2; + $tmp = array(); + if ($section) array_push($tmp, "section=$section"); + if ($section_menu) array_push($tmp, "section_menu=$section_menu"); + if ($section_menu2) array_push($tmp, "section_menu=$section_menu2"); + if ($spec) array_push($tmp, "spec=$spec"); + if ($offset) array_push($tmp, "offset=$offset"); + if ($acat) array_push($tmp, "acat=$acat"); + if ($acat2) array_push($tmp, "acat2=$acat2"); + if (!$ct) $ct = $cat; + if ($ct) array_push($tmp, "cat=$ct"); + array_push($tmp, "id=$id"); + array_push($tmp, "show=1"); + return "?".HTMLSpecialChars(implode("&", $tmp)); + } + + function GetHighlight($hl) { + $tp = new Smarty(); + $tp->assign("hl", $hl); + return $tp->fetch("highlight.tpl"); + } + + function GetAuthor($pic = "", $alt = "", $info = "", $width = 0, $height = 0, $cv = 0) { + $t = new Smarty(); + global $aupicdir; + $t->assign("aupicdir", "$aupicdir/"); + $t->assign("url", $pic); + $t->assign("alt", $alt); + $info = nl2br($info); + if ($cv) { + $info = str_replace("{", "", $info); + $info = str_replace("}", "", $info); + } else { + $info = str_replace("{", "", $info); + $info = str_replace("}", "", $info); + } + $t->assign("info", $info); + $t->assign("width", $width); + $t->assign("height", $hight); + return $t->fetch("author.tpl"); + } + + function GetSemafor() { + global $dbh; + $conn = $dbh ? true : false; + if (!$conn) include("inc/conn.php"); + $sql = "SELECT stanje, trave, korov, stabla, date, prikazi_date FROM semafor ORDER BY date DESC LIMIT 1"; + $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 (!$conn) $dbh->disconnect(); + $t = new Smarty(); + if ($row) { + list($stanje, $trave, $korov, $stabla, $date, $prik) = $row; + if ($prik[0] == "f" || $prik[0] == "F") unset($prik); + $t->assign("stabla", $stabla); + $t->assign("trave", $trave); + $t->assign("korov", $korov); + $t->assign("msg", $stanje); + $t->assign("date", $prik && $date ? strftime("%d.%m.%y.", strtotime($date)) : ""); + } + return $t->fetch("semafor-table.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; + } + + $isEdit = stristr($ME, "/edit/") ? true : false; + # $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false; + include_once("_site.php"); // This should define $isMed. + + function Auth($user = "", $pwd = "") { + global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR; + global $isEdit; + if ($isEdit) return 0; + // 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; + if (!$user) return 1; + global $dbh; + $connected = $dbh ? true : false; + if (!$connected) include("inc/conn.php"); + $sql = "SELECT username, password FROM users WHERE (username = '$user')"; + $sth = $dbh->prepare($sql); + if (!$sth) return 4; + if (!$sth->execute()) return 5; + $row = $sth->fetchrow_array(); + $sth->finish(); + if (!$connected) $dbh->disconnect(); + list($u, $p) = $row; + if ($u != $user) return 2; + if ($p != $pwd) return 3; + return 0; + } + + Header("Content-Type: text/html; charset=ISO-8859-2"); +/* + if ($isEdit) { + if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") { + Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "Sorry, you are not allowed to edit the site.\n"; + exit; + } + } +*/ + $isReg = $isMed ? false : true; + if (!$isReg) $isReg = (Auth() == 0) ? true : false; ?>