1 |
<?php |
2 |
function MyQuote($str) { |
3 |
global $dbh; |
4 |
if (!$dbh) return "'$str'"; |
5 |
return $dbh->quote($str); |
6 |
} |
7 |
|
8 |
function MyMove($src, $dest) { |
9 |
$cmd = "mv -f '".EscapeShellCmd($src)."' '".EscapeShellCmd($dest)."'"; |
10 |
return exec($cmd); |
11 |
} |
12 |
|
13 |
function MyDelete($src) { |
14 |
@unlink($src); |
15 |
} |
16 |
|
17 |
function PicSize($pic, $dir = "") { |
18 |
$ret = array(0, 0); |
19 |
if ($pic) { |
20 |
if (!$dir) { |
21 |
global $syspicdir; |
22 |
$dir = $syspicdir; |
23 |
} |
24 |
@$size = GetImageSize("$dir/$pic"); |
25 |
$ret = array($size[0], $size[1]); |
26 |
} |
27 |
return $ret; |
28 |
} |
29 |
|
30 |
function PicResize($w, $h, $maxsize = 80) { |
31 |
if ($w && $h && $w > $maxsize) { |
32 |
$ratio = ($w / $h); |
33 |
$w = intval($maxsize); |
34 |
$h = intval($w / $ratio); |
35 |
} |
36 |
return array($w, $h); |
37 |
} |
38 |
|
39 |
function GetLinks($read, $more, $more_title, $id, $cat, $name, $edit, $updown = false, $up = false, $down = false) { |
40 |
$t = new Smarty(); |
41 |
global $section, $section_menu, $spec; |
42 |
$t->assign("section", $section); |
43 |
$t->assign("section_menu", $section_menu); |
44 |
$t->assign("spec", $spec); |
45 |
$t->assign("id", $id); |
46 |
$t->assign("cat", $cat); |
47 |
$t->assign("name", $name); |
48 |
$t->assign("read", $read && !strstr($more, "?")); |
49 |
$t->assign("more", /* $more */ strstr($more, "?") ? $more : ""); |
50 |
$t->assign("more_new", strstr($more, "://") ? true : false); |
51 |
$t->assign("more_title", $more_title); |
52 |
$t->assign("edit", $edit); |
53 |
$t->assign("updown", $updown); |
54 |
$t->assign("up", $up); |
55 |
$t->assign("down", $down); |
56 |
return $t->fetch("links.tpl"); |
57 |
} |
58 |
|
59 |
function GetHighlight($hl) { |
60 |
$tp = new Smarty(); |
61 |
$tp->assign("hl", $hl); |
62 |
return $tp->fetch("highlight.tpl"); |
63 |
} |
64 |
|
65 |
function Auth($user = "", $pwd = "") { |
66 |
global $PMusername, $PMpassword; |
67 |
if (!$user) $user = $PMusername; |
68 |
if (!$pwd) $pwd = $PMpassword; |
69 |
if (!$user) return 1; |
70 |
global $dbh; |
71 |
$connected = $dbh ? true : false; |
72 |
if (!$connected) include("inc/conn.php"); |
73 |
$sql = "SELECT username, password FROM users WHERE (username = '$user')"; |
74 |
$sth = $dbh->prepare($sql); |
75 |
if (!$sth) return 4; |
76 |
if (!$sth->execute()) return 5; |
77 |
$row = $sth->fetchrow_array(); |
78 |
$sth->finish(); |
79 |
if (!$connected) $dbh->disconnect(); |
80 |
list($u, $p) = $row; |
81 |
if ($u != $user) return 2; |
82 |
if ($p != $pwd) return 3; |
83 |
return 0; |
84 |
} |
85 |
|
86 |
Header("Content-Type: text/html; charset=ISO-8859-2"); |
87 |
$ME = "http".($HTTPS?"s":"")."://".$HTTP_HOST."/".$PHP_SELF; |
88 |
$isEdit = stristr($ME, "/edit/") ? true : false; |
89 |
$isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false; |
90 |
if ($isEdit) { |
91 |
if ($PHP_AUTH_USER != "test" && $PHP_AUTH_PW != "test") { |
92 |
Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\""); |
93 |
Header("HTTP/1.0 401 Unauthorized"); |
94 |
echo "Sorry, you are not allowed to edit the site.\n"; |
95 |
exit; |
96 |
} |
97 |
} |
98 |
$isReg = $isMed ? false : true; |
99 |
if (!$isReg) $isReg = (Auth() == 0) ? true : false; |
100 |
?> |