/[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.1 by ravilov, Thu Aug 30 16:35:36 2001 UTC revision 1.10 by ravilov, Tue Oct 23 16:13:59 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) {          function PicSize($pic, $dir = "") {
                 global $syspicdir;  
20                  $ret = array(0, 0);                  $ret = array(0, 0);
21                  if ($pic) {                  if ($pic) {
22                          @$size = GetImageSize($syspicdir."/".$pic);                          if (!$dir) {
23                                    global $syspicdir;
24                                    $dir = $syspicdir;
25                            }
26                            @$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 = 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, $updown = false, $up = false, $down = false, $prikazi = true, $related = false) {
42                    $t = new Smarty();
43                    global $section, $section_menu, $section_menu2, $spec, $isMed, $isEdit, $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" || $cat == "3") $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 || ($more && !strpos($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", $isEdit);
63                    $t->assign("updown", $updown);
64                    $t->assign("up", $up);
65                    $t->assign("down", $down);
66                    $t->assign("prikazi", $prikazi);
67                    $t->assign("related", $related);
68                    return $t->fetch("links.tpl");
69            }
70    
71            function GetRead($id, $ct = "") {
72                    global $section, $section_menu, $section_menu2, $spec, $offset, $cat, $acat, $acat2;
73                    $tmp = array();
74                    if ($section) array_push($tmp, "section=$section");
75                    if ($section_menu) array_push($tmp, "section_menu=$section_menu");
76                    if ($section_menu2) array_push($tmp, "section_menu=$section_menu2");
77                    if ($spec) array_push($tmp, "spec=$spec");
78                    if ($offset) array_push($tmp, "offset=$offset");
79                    if ($acat) array_push($tmp, "acat=$acat");
80                    if ($acat2) array_push($tmp, "acat2=$acat2");
81                    if (!$ct) $ct = $cat;
82                    if ($ct) array_push($tmp, "cat=$ct");
83                    array_push($tmp, "id=$id");
84                    array_push($tmp, "show=1");
85                    return "?".HTMLSpecialChars(implode("&", $tmp));
86            }
87    
88            function GetHighlight($hl) {
89                    $tp = new Smarty();
90                    $tp->assign("hl", $hl);
91                    return $tp->fetch("highlight.tpl");
92            }
93    
94            function GetAuthor($pic = "", $alt = "", $info = "", $width = 0, $height = 0, $cv = 0) {
95                    $t = new Smarty();
96                    global $aupicdir;
97                    $t->assign("aupicdir", "$aupicdir/");
98                    $t->assign("url", $pic);
99                    $t->assign("alt", $alt);
100                    $info = nl2br($info);
101                    if ($cv) {
102                            $info = str_replace("{", "<a href=\"autor.php?id=$cv\" target=\"_blank\" class=\"underlined\" onclick=\"window.open(this.href, this.target, 'width=450,height=600,toolbar=no,menu=no'); return false;\">", $info);
103                            $info = str_replace("}", "</a>", $info);
104                    } else {
105                            $info = str_replace("{", "", $info);
106                            $info = str_replace("}", "", $info);
107                    }
108                    $t->assign("info", $info);
109                    $t->assign("width", $width);
110                    $t->assign("height", $hight);
111                    return $t->fetch("author.tpl");
112            }
113    
114            function GetSemafor() {
115                    global $dbh;
116                    $conn = $dbh ? true : false;
117                    if (!$conn) include("inc/conn.php");
118                    $sql = "SELECT stanje, trave, korov, stabla, date, prikazi_date FROM semafor ORDER BY date DESC LIMIT 1";
119                    $sth = $dbh->prepare($sql);
120                    if (!$sth) error("Cannot prepare query: \"$sql\"");
121                    if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
122                    $row = $sth->fetchrow_array();
123                    $sth->finish();
124                    if (!$conn) $dbh->disconnect();
125                    $t = new Smarty();
126                    if ($row) {
127                            list($stanje, $trave, $korov, $stabla, $date, $prik) = $row;
128                            if ($prik[0] == "f" || $prik[0] == "F") unset($prik);
129                            $t->assign("stabla", $stabla);
130                            $t->assign("trave", $trave);
131                            $t->assign("korov", $korov);
132                            $t->assign("msg", $stanje);
133                            $t->assign("date", $prik && $date ? strftime("%d.%m.%y.", strtotime($date)) : "");
134                    }
135                    return $t->fetch("semafor-table.tpl");
136            }
137    
138            function GenerateUsername($ime, $prezime) {
139                    global $dbh;
140                    $replace_from = "¹šðè澞©ŠÐÈÆ®Ž ";
141                    $replace_to = "ssdcczzSSDCCZZ_";
142                    $ime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
143                            strtr($ime, $replace_from, $replace_to)));
144                    $prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
145                            strtr($prezime, $replace_from, $replace_to)));
146                    $cnt = 1;
147                    while ($cnt <= strlen($ime)) {
148                            $username = substr($ime, 0, $cnt++).$prezime;
149                            $sql = "SELECT username FROM users WHERE username = '$username'";
150                            $sth = $dbh->prepare($sql);
151                            if (!$sth) error("Cannot prepare query: \"$sql\"");
152                            if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
153                            $row = $sth->fetchrow_array();
154                            $sth->finish();
155                            if (!$row) break;
156                    }
157                    if ($cnt > strlen($ime)) {
158                            $username2 = $username;
159                            $cnt = 1;
160                            while (true) {
161                                    $username = $username.($cnt++);
162                                    $sql = "SELECT username FROM users WHERE username = '$username'";
163                                    $sth = $dbh->prepare($sql);
164                                    if (!$sth) error("Cannot prepare query: \"$sql\"");
165                                    if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
166                                    $row = $sth->fetchrow_array();
167                                    $sth->finish();
168                                    if (!$row) break;
169                            }
170                    }
171                    return $username;
172            }
173    
174            function GeneratePassword($length = 8) {
175                    $chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
176                    array_shift($chars);
177                    array_pop($chars);
178                    $password = "";
179                    for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))];
180                    return $password;
181            }
182    
183            $isEdit = stristr($ME, "/edit/") ? true : false;
184            # $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;
185            include_once("_site.php");      // This should define $isMed.
186    
187            function Auth($user = "", $pwd = "") {
188                    global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR;
189                    global $isEdit;
190                    if ($isEdit) return 0;
191                    // DEBUG:
192                    #if (stristr($ME, "test.plivamed.net")) return 0;
193                    // User-Agent: should be mnoGoSearch, but in version 3.1.19
194                    // it's UdmSearch so we match just search
195                    if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0;
196                    global $PMusername, $PMpassword;
197                    if (!$user) $user = $PMusername;
198                    if (!$pwd) $pwd = $PMpassword;
199                    if (!$user) return 1;
200                    global $dbh;
201                    $connected = $dbh ? true : false;
202                    if (!$connected) include("inc/conn.php");
203                    $sql = "SELECT username, password FROM users WHERE (username = '$user')";
204                    $sth = $dbh->prepare($sql);
205                    if (!$sth) return 4;
206                    if (!$sth->execute()) return 5;
207                    $row = $sth->fetchrow_array();
208                    $sth->finish();
209                    if (!$connected) $dbh->disconnect();
210                    list($u, $p) = $row;
211                    if ($u != $user) return 2;
212                    if ($p != $pwd) return 3;
213                    return 0;
214            }
215    
216            Header("Content-Type: text/html; charset=ISO-8859-2");
217    /*
218            if ($isEdit) {
219                    if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") {
220                            Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\"");
221                            Header("HTTP/1.0 401 Unauthorized");
222                            echo "Sorry, you are not allowed to edit the site.\n";
223                            exit;
224                    }
225            }
226    */
227            $isReg = $isMed ? false : true;
228            if (!$isReg) $isReg = (Auth() == 0) ? true : false;
229  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.26