--- inc/util.php 2001/09/25 15:38:04 1.3 +++ inc/util.php 2001/10/10 12:40:58 1.7 @@ -1,4 +1,6 @@ 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 = "more"; + if ($cat == "t") $m = "tmore"; + if ($cat == "w") $m = "wmore"; + if ($cat == "p") $m = "pmore"; + $t->assign("m", $m); $t->assign("name", $name); - $t->assign("read", $read && !strstr($more, "?")); + $t->assign("read", $read || ($more && !strstr($more, "?")) ? $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", $edit); + $t->assign("edit", $isEdit); $t->assign("updown", $updown); $t->assign("up", $up); $t->assign("down", $down); + $t->assign("prikazi", $prikazi); 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) { + $t = new Smarty(); + global $aupicdir; + $t->assign("aupicdir", "$aupicdir/"); + $t->assign("url", $pic); + $t->assign("alt", $alt); + $t->assign("info", nl2br($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 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) = $row; + $t->assign("stabla", $stabla); + $t->assign("trave", $trave); + $t->assign("korov", $korov); + $t->assign("msg", $stanje); + $t->assign("date", $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; + } + 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,11 +198,10 @@ } 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") { + 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";