/[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.5 by ravilov, Fri Sep 28 23:34:37 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;
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("id", $id);
49                    $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);
57                    $t->assign("read", $read || ($more && !strstr($more, "?")));
58                    $t->assign("more", /* $more */ strstr($more, "?") ? $more : "");
59                    $t->assign("more_new", strstr($more, "://") ? true : false);
60                    $t->assign("more_title", $more_title);
61                    $t->assign("edit", $edit);
62                    $t->assign("updown", $updown);
63                    $t->assign("up", $up);
64                    $t->assign("down", $down);
65                    return $t->fetch("links.tpl");
66            }
67    
68            function GetHighlight($hl) {
69                    $tp = new Smarty();
70                    $tp->assign("hl", $hl);
71                    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 = "") {
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;
127                    if (!$user) $user = $PMusername;
128                    if (!$pwd) $pwd = $PMpassword;
129                    if (!$user) return 1;
130                    global $dbh;
131                    $connected = $dbh ? true : false;
132                    if (!$connected) include("inc/conn.php");
133                    $sql = "SELECT username, password FROM users WHERE (username = '$user')";
134                    $sth = $dbh->prepare($sql);
135                    if (!$sth) return 4;
136                    if (!$sth->execute()) return 5;
137                    $row = $sth->fetchrow_array();
138                    $sth->finish();
139                    if (!$connected) $dbh->disconnect();
140                    list($u, $p) = $row;
141                    if ($u != $user) return 2;
142                    if ($p != $pwd) return 3;
143                    return 0;
144            }
145    
146            Header("Content-Type: text/html; charset=ISO-8859-2");
147            $isEdit = stristr($ME, "/edit/") ? true : false;
148            $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;
149            if ($isEdit) {
150                    if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") {
151                            Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\"");
152                            Header("HTTP/1.0 401 Unauthorized");
153                            echo "Sorry, you are not allowed to edit the site.\n";
154                            exit;
155                    }
156            }
157            $isReg = $isMed ? false : true;
158            if (!$isReg) $isReg = (Auth() == 0) ? true : false;
159  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.26