/[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.4 by ravilov, Wed Sep 26 13:04:28 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 62  Line 64 
64                  return $tp->fetch("highlight.tpl");                  return $tp->fetch("highlight.tpl");
65          }          }
66    
67            function GenerateUsername($ime, $prezime) {
68                    global $dbh;
69                    $replace_from = "¹šðè澞©ŠÐÈÆ®Ž ";
70                    $replace_to = "ssdcczzSSDCCZZ_";
71                    $ime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
72                            strtr($ime, $replace_from, $replace_to)));
73                    $prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
74                            strtr($prezime, $replace_from, $replace_to)));
75                    $cnt = 1;
76                    while ($cnt <= strlen($ime)) {
77                            $username = substr($ime, 0, $cnt++).$prezime;
78                            $sql = "SELECT username FROM users WHERE username = '$username'";
79                            $sth = $dbh->prepare($sql);
80                            if (!$sth) error("Cannot prepare query: \"$sql\"");
81                            if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
82                            $row = $sth->fetchrow_array();
83                            $sth->finish();
84                            if (!$row) break;
85                    }
86                    if ($cnt > strlen($ime)) {
87                            $username2 = $username;
88                            $cnt = 1;
89                            while (true) {
90                                    $username = $username.($cnt++);
91                                    $sql = "SELECT username FROM users WHERE username = '$username'";
92                                    $sth = $dbh->prepare($sql);
93                                    if (!$sth) error("Cannot prepare query: \"$sql\"");
94                                    if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
95                                    $row = $sth->fetchrow_array();
96                                    $sth->finish();
97                                    if (!$row) break;
98                            }
99                    }
100                    return $username;
101            }
102    
103            function GeneratePassword($length = 8) {
104                    $chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
105                    array_shift($chars);
106                    array_pop($chars);
107                    $password = "";
108                    for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))];
109                    return $password;
110            }
111    
112          function Auth($user = "", $pwd = "") {          function Auth($user = "", $pwd = "") {
113                    global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR;
114                    // DEBUG:
115                    if (stristr($ME, "test.plivamed.net")) return 0;
116                    // User-Agent: should be mnoGoSearch, but in version 3.1.19
117                    // it's UdmSearch so we match just search
118                    if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0;
119                  global $PMusername, $PMpassword;                  global $PMusername, $PMpassword;
120                  if (!$user) $user = $PMusername;                  if (!$user) $user = $PMusername;
121                  if (!$pwd) $pwd = $PMpassword;                  if (!$pwd) $pwd = $PMpassword;
# Line 84  Line 137 
137          }          }
138    
139          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;  
140          $isEdit = stristr($ME, "/edit/") ? true : false;          $isEdit = stristr($ME, "/edit/") ? true : false;
141          $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;          $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;
142          if ($isEdit) {          if ($isEdit) {

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

  ViewVC Help
Powered by ViewVC 1.1.26