/[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.2 by ravilov, Wed Sep 19 12:23:57 2001 UTC revision 1.6 by ravilov, Thu Oct 4 14:59:35 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 21  Line 23 
23                                  global $syspicdir;                                  global $syspicdir;
24                                  $dir = $syspicdir;                                  $dir = $syspicdir;
25                          }                          }
26                          @$size = GetImageSize($dir."/".$pic);                          @$size = GetImageSize("$dir/$pic");
27                          $ret = array($size[0], $size[1]);                          $ret = array($size[0], $size[1]);
28                  }                  }
29                  return $ret;                  return $ret;
30          }          }
31    
32          $isEdit = stristr($PHP_SELF, "/edit/") ? true : false;          function PicResize($w, $h, $maxsize = 80) {
33          $isMed = stristr($PHP_SELF, "/med/") ? true : false;                  if ($w && $h && $w > $maxsize) {
34  header("Content-Type: text/html; charset=ISO-8859-2");                          $ratio = ($w / $h);
35                            $w = intval($maxsize);
36                            $h = intval($w / $ratio);
37                    }
38                    return array($w, $h);
39            }
40    
41            function GetLinks($read, $more, $more_title, $id, $cat, $name, $edit, $updown = false, $up = false, $down = false) {
42                    $t = new Smarty();
43                    global $section, $section_menu, $section_menu2, $spec, $isMed, $offset;
44                    $t->assign("section", $section);
45                    $t->assign("section_menu", $section_menu);
46                    $t->assign("section_menu2", $section_menu2);
47                    $t->assign("spec", $spec);
48                    $t->assign("offset", $offset);
49                    $t->assign("id", $id);
50                    $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);
58                    $t->assign("read", $read || ($more && !strstr($more, "?")) ? $read : "");
59                    $t->assign("more", /* $more */ strstr($more, "?") ? $more : "");
60                    $t->assign("more_new", strstr($more, "://") ? true : false);
61                    $t->assign("more_title", $more_title);
62                    $t->assign("edit", $edit);
63                    $t->assign("updown", $updown);
64                    $t->assign("up", $up);
65                    $t->assign("down", $down);
66                    return $t->fetch("links.tpl");
67            }
68    
69            function GetRead($id, $ct = "") {
70                    global $section, $section_menu, $section_menu2, $spec, $offset, $cat, $acat, $acat2;
71                    $tmp = array();
72                    if ($section) array_push($tmp, "section=$section");
73                    if ($section_menu) array_push($tmp, "section_menu=$section_menu");
74                    if ($section_menu2) array_push($tmp, "section_menu=$section_menu2");
75                    if ($spec) array_push($tmp, "spec=$spec");
76                    if ($offset) array_push($tmp, "offset=$offset");
77                    if ($acat) array_push($tmp, "acat=$acat");
78                    if ($acat2) array_push($tmp, "acat2=$acat2");
79                    if (!$ct) $ct = $cat;
80                    if ($ct) array_push($tmp, "cat=$ct");
81                    array_push($tmp, "id=$id");
82                    array_push($tmp, "show=1");
83                    return "?".HTMLSpecialChars(implode("&", $tmp));
84            }
85    
86            function GetHighlight($hl) {
87                    $tp = new Smarty();
88                    $tp->assign("hl", $hl);
89                    return $tp->fetch("highlight.tpl");
90            }
91    
92            function GenerateUsername($ime, $prezime) {
93                    global $dbh;
94                    $replace_from = "¹šðè澞©ŠÐÈÆ®Ž ";
95                    $replace_to = "ssdcczzSSDCCZZ_";
96                    $ime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
97                            strtr($ime, $replace_from, $replace_to)));
98                    $prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
99                            strtr($prezime, $replace_from, $replace_to)));
100                    $cnt = 1;
101                    while ($cnt <= strlen($ime)) {
102                            $username = substr($ime, 0, $cnt++).$prezime;
103                            $sql = "SELECT username FROM users WHERE username = '$username'";
104                            $sth = $dbh->prepare($sql);
105                            if (!$sth) error("Cannot prepare query: \"$sql\"");
106                            if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
107                            $row = $sth->fetchrow_array();
108                            $sth->finish();
109                            if (!$row) break;
110                    }
111                    if ($cnt > strlen($ime)) {
112                            $username2 = $username;
113                            $cnt = 1;
114                            while (true) {
115                                    $username = $username.($cnt++);
116                                    $sql = "SELECT username FROM users WHERE username = '$username'";
117                                    $sth = $dbh->prepare($sql);
118                                    if (!$sth) error("Cannot prepare query: \"$sql\"");
119                                    if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
120                                    $row = $sth->fetchrow_array();
121                                    $sth->finish();
122                                    if (!$row) break;
123                            }
124                    }
125                    return $username;
126            }
127    
128            function GeneratePassword($length = 8) {
129                    $chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
130                    array_shift($chars);
131                    array_pop($chars);
132                    $password = "";
133                    for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))];
134                    return $password;
135            }
136    
137            function Auth($user = "", $pwd = "") {
138                    global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR;
139                    // DEBUG:
140                    #if (stristr($ME, "test.plivamed.net")) return 0;
141                    // User-Agent: should be mnoGoSearch, but in version 3.1.19
142                    // it's UdmSearch so we match just search
143                    if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0;
144                    global $PMusername, $PMpassword;
145                    if (!$user) $user = $PMusername;
146                    if (!$pwd) $pwd = $PMpassword;
147                    if (!$user) return 1;
148                    global $dbh;
149                    $connected = $dbh ? true : false;
150                    if (!$connected) include("inc/conn.php");
151                    $sql = "SELECT username, password FROM users WHERE (username = '$user')";
152                    $sth = $dbh->prepare($sql);
153                    if (!$sth) return 4;
154                    if (!$sth->execute()) return 5;
155                    $row = $sth->fetchrow_array();
156                    $sth->finish();
157                    if (!$connected) $dbh->disconnect();
158                    list($u, $p) = $row;
159                    if ($u != $user) return 2;
160                    if ($p != $pwd) return 3;
161                    return 0;
162            }
163    
164            Header("Content-Type: text/html; charset=ISO-8859-2");
165            $isEdit = stristr($ME, "/edit/") ? true : false;
166            $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;
167            if ($isEdit) {
168                    if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") {
169                            Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\"");
170                            Header("HTTP/1.0 401 Unauthorized");
171                            echo "Sorry, you are not allowed to edit the site.\n";
172                            exit;
173                    }
174            }
175            $isReg = $isMed ? false : true;
176            if (!$isReg) $isReg = (Auth() == 0) ? true : false;
177  ?>  ?>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.26