/[health_html]/inc/util.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /inc/util.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by ravilov, Tue Sep 25 15:38:04 2001 UTC revision 1.7 by ravilov, Wed Oct 10 12:40:58 2001 UTC
# Line 1  Line 1 
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'";
# Line 11  Line 13 
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 = "") {
# Line 36  Line 38 
38                  return array($w, $h);                  return array($w, $h);
39          }          }
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, $updown = false, $up = false, $down = false, $prikazi = true) {
42                  $t = new Smarty();                  $t = new Smarty();
43                  global $section, $section_menu, $spec;                  global $section, $section_menu, $section_menu2, $spec, $isMed, $isEdit, $offset;
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("offset", $offset);
49                  $t->assign("id", $id);                  $t->assign("id", $id);
50                  $t->assign("cat", $cat);                  $t->assign("cat", $cat);
51                    $t->assign("med", $isMed);
52                    $m = "more";
53                    if ($cat == "t") $m = "tmore";
54                    if ($cat == "w") $m = "wmore";
55                    if ($cat == "p") $m = "pmore";
56                    $t->assign("m", $m);
57                  $t->assign("name", $name);                  $t->assign("name", $name);
58                  $t->assign("read", $read && !strstr($more, "?"));                  $t->assign("read", $read || ($more && !strstr($more, "?")) ? $read : "");
59                  $t->assign("more", /* $more */ strstr($more, "?") ? $more : "");                  $t->assign("more", /* $more */ strstr($more, "?") ? $more : "");
60                  $t->assign("more_new", strstr($more, "://") ? true : false);                  $t->assign("more_new", strstr($more, "://") ? true : false);
61                  $t->assign("more_title", $more_title);                  $t->assign("more_title", $more_title);
62                  $t->assign("edit", $edit);                  $t->assign("edit", $isEdit);
63                  $t->assign("updown", $updown);                  $t->assign("updown", $updown);
64                  $t->assign("up", $up);                  $t->assign("up", $up);
65                  $t->assign("down", $down);                  $t->assign("down", $down);
66                    $t->assign("prikazi", $prikazi);
67                  return $t->fetch("links.tpl");                  return $t->fetch("links.tpl");
68          }          }
69    
70            function GetRead($id, $ct = "") {
71                    global $section, $section_menu, $section_menu2, $spec, $offset, $cat, $acat, $acat2;
72                    $tmp = array();
73                    if ($section) array_push($tmp, "section=$section");
74                    if ($section_menu) array_push($tmp, "section_menu=$section_menu");
75                    if ($section_menu2) array_push($tmp, "section_menu=$section_menu2");
76                    if ($spec) array_push($tmp, "spec=$spec");
77                    if ($offset) array_push($tmp, "offset=$offset");
78                    if ($acat) array_push($tmp, "acat=$acat");
79                    if ($acat2) array_push($tmp, "acat2=$acat2");
80                    if (!$ct) $ct = $cat;
81                    if ($ct) array_push($tmp, "cat=$ct");
82                    array_push($tmp, "id=$id");
83                    array_push($tmp, "show=1");
84                    return "?".HTMLSpecialChars(implode("&", $tmp));
85            }
86    
87          function GetHighlight($hl) {          function GetHighlight($hl) {
88                  $tp = new Smarty();                  $tp = new Smarty();
89                  $tp->assign("hl", $hl);                  $tp->assign("hl", $hl);
90                  return $tp->fetch("highlight.tpl");                  return $tp->fetch("highlight.tpl");
91          }          }
92    
93            function GetAuthor($pic = "", $alt = "", $info = "", $width = 0, $height = 0) {
94                    $t = new Smarty();
95                    global $aupicdir;
96                    $t->assign("aupicdir", "$aupicdir/");
97                    $t->assign("url", $pic);
98                    $t->assign("alt", $alt);
99                    $t->assign("info", nl2br($info));
100                    $t->assign("width", $width);
101                    $t->assign("height", $hight);
102                    return $t->fetch("author.tpl");
103            }
104    
105            function GetSemafor() {
106                    global $dbh;
107                    $conn = $dbh ? true : false;
108                    if (!$conn) include("inc/conn.php");
109                    $sql = "SELECT stanje, trave, korov, stabla, date FROM semafor ORDER BY date DESC LIMIT 1";
110                    $sth = $dbh->prepare($sql);
111                    if (!$sth) error("Cannot prepare query: \"$sql\"");
112                    if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
113                    $row = $sth->fetchrow_array();
114                    $sth->finish();
115                    if (!$conn) $dbh->disconnect();
116                    $t = new Smarty();
117                    if ($row) {
118                            list($stanje, $trave, $korov, $stabla, $date) = $row;
119                            $t->assign("stabla", $stabla);
120                            $t->assign("trave", $trave);
121                            $t->assign("korov", $korov);
122                            $t->assign("msg", $stanje);
123                            $t->assign("date", $date ? strftime("%d.%m.%y.", strtotime($date)) : "");
124                    }
125                    return $t->fetch("semafor-table.tpl");
126            }
127    
128            function GenerateUsername($ime, $prezime) {
129                    global $dbh;
130                    $replace_from = "¹šðè澞©ŠÐÈÆ®Ž ";
131                    $replace_to = "ssdcczzSSDCCZZ_";
132                    $ime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
133                            strtr($ime, $replace_from, $replace_to)));
134                    $prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
135                            strtr($prezime, $replace_from, $replace_to)));
136                    $cnt = 1;
137                    while ($cnt <= strlen($ime)) {
138                            $username = substr($ime, 0, $cnt++).$prezime;
139                            $sql = "SELECT username FROM users WHERE username = '$username'";
140                            $sth = $dbh->prepare($sql);
141                            if (!$sth) error("Cannot prepare query: \"$sql\"");
142                            if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
143                            $row = $sth->fetchrow_array();
144                            $sth->finish();
145                            if (!$row) break;
146                    }
147                    if ($cnt > strlen($ime)) {
148                            $username2 = $username;
149                            $cnt = 1;
150                            while (true) {
151                                    $username = $username.($cnt++);
152                                    $sql = "SELECT username FROM users WHERE username = '$username'";
153                                    $sth = $dbh->prepare($sql);
154                                    if (!$sth) error("Cannot prepare query: \"$sql\"");
155                                    if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
156                                    $row = $sth->fetchrow_array();
157                                    $sth->finish();
158                                    if (!$row) break;
159                            }
160                    }
161                    return $username;
162            }
163    
164            function GeneratePassword($length = 8) {
165                    $chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
166                    array_shift($chars);
167                    array_pop($chars);
168                    $password = "";
169                    for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))];
170                    return $password;
171            }
172    
173          function Auth($user = "", $pwd = "") {          function Auth($user = "", $pwd = "") {
174                    global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR;
175                    // DEBUG:
176                    #if (stristr($ME, "test.plivamed.net")) return 0;
177                    // User-Agent: should be mnoGoSearch, but in version 3.1.19
178                    // it's UdmSearch so we match just search
179                    if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0;
180                  global $PMusername, $PMpassword;                  global $PMusername, $PMpassword;
181                  if (!$user) $user = $PMusername;                  if (!$user) $user = $PMusername;
182                  if (!$pwd) $pwd = $PMpassword;                  if (!$pwd) $pwd = $PMpassword;
# Line 84  Line 198 
198          }          }
199    
200          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;  
201          $isEdit = stristr($ME, "/edit/") ? true : false;          $isEdit = stristr($ME, "/edit/") ? true : false;
202          $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;          $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;
203          if ($isEdit) {          if ($isEdit) {
204                  if ($PHP_AUTH_USER != "test" && $PHP_AUTH_PW != "test") {                  if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") {
205                          Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\"");                          Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\"");
206                          Header("HTTP/1.0 401 Unauthorized");                          Header("HTTP/1.0 401 Unauthorized");
207                          echo "Sorry, you are not allowed to edit the site.\n";                          echo "Sorry, you are not allowed to edit the site.\n";

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26