/[webwml]/newmaint/common.inc
ViewVC logotype

Contents of /newmaint/common.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Sat Feb 1 14:25:44 2003 UTC (10 years, 3 months ago) by tbm
Branch: MAIN
Changes since 1.4: +1 -1 lines
Specify the database handle,
1 csmall 1.1 <?
2     #Common functions used everywhere
3     if (!function_exists(pg_connect)) {
4     dl("pgsql.so");
5     }
6    
7     # Opens the Database, returns the database handle if ok and FALSE if there
8     # was a problem.
9     function open_db()
10     {
11     global $DBName, $DBUser, $DBPasswd;
12    
13     $connstr = "dbname=$DBName user=$DBUser";
14     if ($DBPasswd != "") {
15     $connstr .= " password=$DBPasswd";
16     }
17     if (! ($db = pg_Connect($connstr))) {
18     echo "<STRONG>Problem with connecting to database: ", pg_ErrorMessage($db), "</STRONG><BR>";
19     return FALSE;
20     }
21     return $db;
22     }
23    
24 tbm 1.3 function find_applicant($db, $email) {
25     global $row, $query;
26     # start looking at stuff
27     $sql = "SELECT * from applicant WHERE email='$email'";
28     if (! ($query = pg_exec($db, $sql))) {
29     echo "Problem with query", pg_ErrorMessage($db), "<BR>";
30     return FALSE;
31     }
32     if ( pg_numRows($query) < 1) {
33     echo "Could not find $email in the database. You can find a full list of applicants <A href=\"nmlist.php\">here</A>.<BR>";
34     return FALSE;
35     }
36     $row = pg_Fetch_Array($query, 0);
37     return TRUE;
38     }
39    
40 tbm 1.5 function logger($db, $who, $manager, $action, $name, $email) {
41 tbm 1.4 $sql = "INSERT INTO log (who, manager, action, name, email) VALUES ('$who', '$manager', '$action', '$name', '$email')";
42     if (! ($result = pg_exec($db, $sql))) {
43     echo "Problem with interrogating database: ", pg_ErrorMessage($db), "<BR>\n";
44     return FALSE;
45     }
46     if (($tuples = pg_CmdTuples($result)) != 1) {
47     echo "Only one row should be effected but $tuples rows were<BR>\n";
48     return FALSE;
49     }
50     return TRUE;
51     }
52    
53 csmall 1.1 function print_bool($title, $name, $value, $editable)
54     {
55     echo "<TR><TD width=\"200\"><B>$title</B> </TD><TD width=\"200\">";
56     if ($editable) {
57     echo "<INPUT type=\"radio\" name=\"$name\" value=\"t\"";
58     if ($value == 't') { echo " checked"; }
59     echo ">Yes &nbsp;\n<INPUT type=\"radio\" name=\"", $name,
60     "\" value=\"f\"";
61     if ($value == 'f') { echo " checked"; }
62     echo "> No &nbsp;\n<INPUT type=\"radio\" name=\"", $name,
63     "\" value=\"n\"";
64     if ($value != 'f' && $value != 't') { echo " checked"; }
65     echo "> Not checked\n";
66     } else {
67     if ($value == 't') { echo "[ Yes ]"; }
68     if ($value == 'f') { echo "[ No ]"; }
69     if ($value == 'n') { echo "[ Not Checked ]"; }
70     }
71     echo "</TD></TR>\n";
72     }
73     function print_text($title, $name, $value, $editable)
74     {
75     echo "<TR><TD width=\"200\"><B>$title</B> </TD><TD width=\"400\"> ";
76     if ($editable) {
77     echo "<INPUT type=\"text\" name=\"$name\" value=\"$value\">";
78     } else {
79     echo "[ $value ]";
80     }
81     echo "</TD></TR>\n";
82     }
83     function print_checkbox($title, $name, $value, $editable)
84     {
85     echo "<TR><TD width=\"200\"><B>$title</B> </TD><TD width=\"400\"> ";
86     if ($editable) {
87     echo "<INPUT type=\"checkbox\" name=\"$name\" value=\"t\" ";
88     if ($value == 't') { echo "CHECKED"; }
89     echo ">";
90     } else {
91     if ($value == 't') {
92     echo "[ Yes ]";
93     } else {
94     echo "[ No ]";
95     }
96     }
97     echo "</TD></TR>\n";
98     }
99     function print_passwd($title, $name)
100     {
101     echo "<TR><TD width=\"200\"><B>$title</B> </TD><TD width=\"400\"> <INPUT type=\"password\" name=\"$name\"></TD></TR>\n";
102     }
103     function print_flag($value,$trueflag,$falseflag)
104     {
105     if ($value == 't') {
106     echo $trueflag;
107     } else {
108     echo $falseflag;
109     }
110     }
111 weasel 1.2
112     # Those two functions are currently needed in the gpg signing coordination part
113     # I took the liberty to add them here as they might be useful for other parts of
114     # the page too.
115     function passwd_crypt($passwd)
116     {
117     static $initialized = 0;
118    
119     if (! $initialized ) {
120     srand((double)microtime()*1000000);
121     $initialized=1;
122     };
123     $salt = '$1$';
124     $itoa64="./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
125     # FIXME: What kind of characters are allowed in salts? Is there a better way
126     # to create one?
127     # And no, php's crypt() funktion does not work without salt. At least
128     # it didn't for me.
129    
130     $random=rand(); $salt .= substr($itoa64,$random % 64,1).substr($itoa64,($random/64) % 64,1);
131     $random=rand(); $salt .= substr($itoa64,$random % 64,1).substr($itoa64,($random/64) % 64,1);
132     $random=rand(); $salt .= substr($itoa64,$random % 64,1).substr($itoa64,($random/64) % 64,1);
133     $random=rand(); $salt .= substr($itoa64,$random % 64,1).substr($itoa64,($random/64) % 64,1);
134     return crypt($passwd, $salt);
135     }
136     function passwd_verify($stored_passwd, $guess)
137     {
138     $salt = substr($stored_passwd, 0, 12);
139     $crypted_passwd = crypt($guess, $salt);
140     return ($stored_passwd == $crypted_passwd);
141     }
142 csmall 1.1 ?>
143    

  ViewVC Help
Powered by ViewVC 1.1.5