--- inc/util.php 2001/09/19 12:23:57 1.2 +++ inc/util.php 2001/09/25 15:38:04 1.3 @@ -21,13 +21,80 @@ global $syspicdir; $dir = $syspicdir; } - @$size = GetImageSize($dir."/".$pic); + @$size = GetImageSize("$dir/$pic"); $ret = array($size[0], $size[1]); } return $ret; } - $isEdit = stristr($PHP_SELF, "/edit/") ? true : false; - $isMed = stristr($PHP_SELF, "/med/") ? true : false; -header("Content-Type: text/html; charset=ISO-8859-2"); + function PicResize($w, $h, $maxsize = 80) { + if ($w && $h && $w > $maxsize) { + $ratio = ($w / $h); + $w = intval($maxsize); + $h = intval($w / $ratio); + } + return array($w, $h); + } + + function GetLinks($read, $more, $more_title, $id, $cat, $name, $edit, $updown = false, $up = false, $down = false) { + $t = new Smarty(); + global $section, $section_menu, $spec; + $t->assign("section", $section); + $t->assign("section_menu", $section_menu); + $t->assign("spec", $spec); + $t->assign("id", $id); + $t->assign("cat", $cat); + $t->assign("name", $name); + $t->assign("read", $read && !strstr($more, "?")); + $t->assign("more", /* $more */ strstr($more, "?") ? $more : ""); + $t->assign("more_new", strstr($more, "://") ? true : false); + $t->assign("more_title", $more_title); + $t->assign("edit", $edit); + $t->assign("updown", $updown); + $t->assign("up", $up); + $t->assign("down", $down); + return $t->fetch("links.tpl"); + } + + function GetHighlight($hl) { + $tp = new Smarty(); + $tp->assign("hl", $hl); + return $tp->fetch("highlight.tpl"); + } + + function Auth($user = "", $pwd = "") { + 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"); + $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) { + if ($PHP_AUTH_USER != "test" && $PHP_AUTH_PW != "test") { + 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; ?>