1 |
<?php |
<?php |
2 |
|
$ME = "http".($HTTPS?"s":"")."://".$HTTP_HOST.$PHP_SELF; |
3 |
|
|
4 |
function MyQuote($str) { |
function MyQuote($str) { |
5 |
global $dbh; |
global $dbh; |
6 |
if (!$dbh) return "'$str'"; |
if (!$dbh) return "'$str'"; |
13 |
} |
} |
14 |
|
|
15 |
function MyDelete($src) { |
function MyDelete($src) { |
16 |
@unlink($src); |
#@unlink($src); |
17 |
} |
} |
18 |
|
|
19 |
function PicSize($pic, $dir = "") { |
function PicSize($pic, $dir = "") { |
40 |
|
|
41 |
function GetLinks($read, $more, $more_title, $id, $cat, $name, $edit, $updown = false, $up = false, $down = false) { |
function GetLinks($read, $more, $more_title, $id, $cat, $name, $edit, $updown = false, $up = false, $down = false) { |
42 |
$t = new Smarty(); |
$t = new Smarty(); |
43 |
global $section, $section_menu, $spec; |
global $section, $section_menu, $section_menu2, $spec, $isMed; |
44 |
$t->assign("section", $section); |
$t->assign("section", $section); |
45 |
$t->assign("section_menu", $section_menu); |
$t->assign("section_menu", $section_menu); |
46 |
|
$t->assign("section_menu2", $section_menu2); |
47 |
$t->assign("spec", $spec); |
$t->assign("spec", $spec); |
48 |
$t->assign("id", $id); |
$t->assign("id", $id); |
49 |
$t->assign("cat", $cat); |
$t->assign("cat", $cat); |
50 |
|
$t->assign("med", $isMed); |
51 |
|
$m = "more"; |
52 |
|
if ($cat == "t") $m = "tmore"; |
53 |
|
if ($cat == "w") $m = "wmore"; |
54 |
|
if ($cat == "p") $m = "pmore"; |
55 |
|
$t->assign("m", $m); |
56 |
$t->assign("name", $name); |
$t->assign("name", $name); |
57 |
$t->assign("read", $read && !strstr($more, "?")); |
$t->assign("read", $read || ($more && !strstr($more, "?"))); |
58 |
$t->assign("more", /* $more */ strstr($more, "?") ? $more : ""); |
$t->assign("more", /* $more */ strstr($more, "?") ? $more : ""); |
59 |
$t->assign("more_new", strstr($more, "://") ? true : false); |
$t->assign("more_new", strstr($more, "://") ? true : false); |
60 |
$t->assign("more_title", $more_title); |
$t->assign("more_title", $more_title); |
71 |
return $tp->fetch("highlight.tpl"); |
return $tp->fetch("highlight.tpl"); |
72 |
} |
} |
73 |
|
|
74 |
|
function GenerateUsername($ime, $prezime) { |
75 |
|
global $dbh; |
76 |
|
$replace_from = "¹šðè澞©ŠÐÈÆ®Ž "; |
77 |
|
$replace_to = "ssdcczzSSDCCZZ_"; |
78 |
|
$ime = strtolower(ereg_replace('[^A-Za-z0-9]', "", |
79 |
|
strtr($ime, $replace_from, $replace_to))); |
80 |
|
$prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "", |
81 |
|
strtr($prezime, $replace_from, $replace_to))); |
82 |
|
$cnt = 1; |
83 |
|
while ($cnt <= strlen($ime)) { |
84 |
|
$username = substr($ime, 0, $cnt++).$prezime; |
85 |
|
$sql = "SELECT username FROM users WHERE username = '$username'"; |
86 |
|
$sth = $dbh->prepare($sql); |
87 |
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
88 |
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
89 |
|
$row = $sth->fetchrow_array(); |
90 |
|
$sth->finish(); |
91 |
|
if (!$row) break; |
92 |
|
} |
93 |
|
if ($cnt > strlen($ime)) { |
94 |
|
$username2 = $username; |
95 |
|
$cnt = 1; |
96 |
|
while (true) { |
97 |
|
$username = $username.($cnt++); |
98 |
|
$sql = "SELECT username FROM users WHERE username = '$username'"; |
99 |
|
$sth = $dbh->prepare($sql); |
100 |
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
101 |
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
102 |
|
$row = $sth->fetchrow_array(); |
103 |
|
$sth->finish(); |
104 |
|
if (!$row) break; |
105 |
|
} |
106 |
|
} |
107 |
|
return $username; |
108 |
|
} |
109 |
|
|
110 |
|
function GeneratePassword($length = 8) { |
111 |
|
$chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); |
112 |
|
array_shift($chars); |
113 |
|
array_pop($chars); |
114 |
|
$password = ""; |
115 |
|
for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))]; |
116 |
|
return $password; |
117 |
|
} |
118 |
|
|
119 |
function Auth($user = "", $pwd = "") { |
function Auth($user = "", $pwd = "") { |
120 |
|
global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR; |
121 |
|
// DEBUG: |
122 |
|
#if (stristr($ME, "test.plivamed.net")) return 0; |
123 |
|
// User-Agent: should be mnoGoSearch, but in version 3.1.19 |
124 |
|
// it's UdmSearch so we match just search |
125 |
|
if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0; |
126 |
global $PMusername, $PMpassword; |
global $PMusername, $PMpassword; |
127 |
if (!$user) $user = $PMusername; |
if (!$user) $user = $PMusername; |
128 |
if (!$pwd) $pwd = $PMpassword; |
if (!$pwd) $pwd = $PMpassword; |
144 |
} |
} |
145 |
|
|
146 |
Header("Content-Type: text/html; charset=ISO-8859-2"); |
Header("Content-Type: text/html; charset=ISO-8859-2"); |
|
$ME = "http".($HTTPS?"s":"")."://".$HTTP_HOST."/".$PHP_SELF; |
|
147 |
$isEdit = stristr($ME, "/edit/") ? true : false; |
$isEdit = stristr($ME, "/edit/") ? true : false; |
148 |
$isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false; |
$isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false; |
149 |
if ($isEdit) { |
if ($isEdit) { |
150 |
if ($PHP_AUTH_USER != "test" && $PHP_AUTH_PW != "test") { |
if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") { |
151 |
Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\""); |
Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\""); |
152 |
Header("HTTP/1.0 401 Unauthorized"); |
Header("HTTP/1.0 401 Unauthorized"); |
153 |
echo "Sorry, you are not allowed to edit the site.\n"; |
echo "Sorry, you are not allowed to edit the site.\n"; |