|
PCCS MySQLDatabase Admin Tool version 1.3.4
|
/incs/ -> mysqldb_functions.php
1 <?
2 ///////////////////////////////////////////////////////////////////////////////////////////// 3 // Filename: mysqldb_functions.php 4 // Function: Contains some core functions related to this application 5 // // show_query() and write_htmlfile() 6 // Functions are called from the query tool 7 // 8 // updated 10-07-2000 9 // -- added changelog to this file 10 // 11 // 12
13
14 function write_htmlfile($qry,$filename) {
15 global $dbname;
16
17 $border = "0";
18 $th_bgcolor = "#D3DCE3";
19 $bgcolor_one = "#CCCCCC";
20 $bgcolor_two = "#DDDDDD";
21 $max_rows = "100";
22 $pos = 0;
23
24 $dirname = "tmp/";
25 $htmlfile = "$filename";
26 $f = fopen($dirname . $htmlfile, "w");
27 fputs($f,"<HTML>\n<HEAD>\n");
28 fputs($f,"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=$NLSCharset\">\n");
29 fputs($f,"<TITLE>Web Report</TITLE>\n");
30 $today = Date("Ymd");
31 fputs($f,"<!--\n//** Generated by PCCS MySQLDatabase Admin Tool $today\n -->\n");
32
33
34 fputs($f,"<table><tr>\n");
35
36
37 // $qry = addslashes($qry); 38 $result = mysqlquery("$dbname",$qry) or die("Query Failed");
39 if (!$result)
40 {
41 // mysql_die();
42 }
43 else
44 {
45 $num_rows = @mysql_num_rows($result);
46 if ($num_rows < 1)
47 {
48 if (isset($zero_rows))
49 {
50 echo $zero_rows;
51 }
52 else
53 {
54 echo "Empty Result Set";
55 }
56 }
57 else
58 {
59 if (!isset($pos))
60 {
61 $pos = 0;
62 }
63 $pos_next = $pos + $max_rows;
64 $pos_prev = $pos - $max_rows;
65
66 if (@mysql_num_rows($dt_result)>1)
67 {
68 echo "Showing Records $pos - $pos_next (".mysql_num_rows($result)." Total )";
69 }
70
71 while ($field = mysql_fetch_field($result))
72 {
73 if (@mysql_num_rows($result)>1)
74 {
75 $sql_sort=urlencode("select * from $table order by $field->name $order");
76 fputs($f,"<th><font color=blue>$field->name</font></th>\n");
77 }
78 else
79 {
80 fputs($f,"<th>$field->name</th>");
81
82 }
83 $table = $field->table;
84 }
85 fputs($f,"</tr>\n");
86 $foo = 0;
87
88 while ($row = mysql_fetch_row($result))
89 {
90 if ($foo < $pos_next && $foo >= $pos)
91 {
92 $primary_key = "";
93 $bgcolor = $bgcolor_one;
94 $foo % 2 ? 0: $bgcolor = $bgcolor_two;
95 fputs($f,"<tr bgcolor=$bgcolor>");
96 for ($i=0; $i<mysql_num_fields($result); $i++)
97 {
98 $primary = mysql_fetch_field($result,$i);
99 if ($primary->numeric == 1)
100 {
101 fputs($f,"<td align=right> $row[$i] </td>\n");
102 }
103 else
104 {
105
106 fputs($f,"<td> ".htmlspecialchars($row[$i])." </td>\n");
107 }
108 if ($primary->primary_key > 0)
109 {
110 $primary_key .= " $primary->name = '$row[$i]' AND";
111 }
112 }
113 if ($primary_key)
114 {
115 $primary_key = urlencode(ereg_replace("AND$", "", $primary_key));
116 $query = "&db=$db&table=$table";
117
118 }
119 fputs($f,"</tr>\n");
120 }
121 $foo++;
122 }
123 fputs($f,"</table>\n");
124 fputs($f,"\n");
125 fputs($f,"</BODY>\n");
126 fputs($f,"</HTML>\n");
127 fclose($f);
128 // display_table($result);
129
130 // echo "<BR> $where1 and $where2";
131 }
132 }
133 }
134
135 //////////////////////////////////////////////////////////////////////////////////// 136 //////////////////////////////////////////////////////////////////////////////////// 137
138 function show_results($qry) {
139 global $dbname;
140
141 $border = "0";
142 $th_bgcolor = "#D3DCE3";
143 $bgcolor_one = "#CCCCCC";
144 $bgcolor_two = "#DDDDDD";
145 $max_rows = "100";
146 $pos = 0;
147
148
149 print "<table><tr>";
150
151
152 $qry = stripslashes($qry);
153 $result = mysqlquery("$dbname",$qry);
154 if (!$result)
155 {
156 echo $qry . "<BR>";
157 echo mysql_error();
158 }
159 else
160 {
161 $num_rows = @mysql_num_rows($result);
162 if ($num_rows < 1)
163 {
164 if (isset($zero_rows))
165 {
166 echo $zero_rows;
167 }
168 else
169 {
170 echo "Empty Result Set";
171 }
172 }
173 else
174 {
175 if (!isset($pos))
176 {
177 $pos = 0;
178 }
179 $pos_next = $pos + $max_rows;
180 $pos_prev = $pos - $max_rows;
181
182 if (@mysql_num_rows($dt_result)>1)
183 {
184 echo "Showing Records $pos - $pos_next (".mysql_num_rows($result)." Total )";
185 }
186
187 while ($field = mysql_fetch_field($result))
188 {
189 if (@mysql_num_rows($result)>1)
190 {
191 $sql_sort=urlencode("select * from $table order by $field->name $order");
192 echo "<th><font color=blue>$field->name</font></th>\n";
193 }
194 else
195 {
196 echo "<th>$field->name</th>";
197
198 }
199 $table = $field->table;
200 }
201 echo "</tr>\n";
202 $foo = 0;
203
204 while ($row = mysql_fetch_row($result))
205 {
206 if ($foo < $pos_next && $foo >= $pos)
207 {
208 $primary_key = "";
209 $bgcolor = $bgcolor_one;
210 $foo % 2 ? 0: $bgcolor = $bgcolor_two;
211 echo "<tr bgcolor=$bgcolor>";
212 for ($i=0; $i<mysql_num_fields($result); $i++)
213 {
214 $primary = mysql_fetch_field($result,$i);
215 if ($primary->numeric == 1)
216 {
217 echo "<td align=right> $row[$i] </td>\n";
218 }
219 else
220 {
221 echo "<td> ".htmlspecialchars($row[$i])." </td>\n";
222 }
223 if ($primary->primary_key > 0)
224 {
225 $primary_key .= " $primary->name = '$row[$i]' AND";
226 }
227 }
228 if ($primary_key)
229 {
230 $primary_key = urlencode(ereg_replace("AND$", "", $primary_key));
231 $query = "&db=$db&table=$table";
232
233 }
234 echo "</tr>\n";
235 }
236 $foo++;
237 }
238 echo "</table>\n";
239
240 // display_table($result);
241
242 // echo "<BR> $where1 and $where2";
243 }
244 }
245 }
246
247 ////////////////////////////////////////////////////////////////////////////////////////////////// 248
249
250 ////////////////////////////////////////////////////////////////////////////////////////////////// 251 /*
252 function log_this($action) {
253 $ip = $REMOTE_ADDR;
254 if(file_exist("logs/log.txt")) {
255 $logfile = fopen("logs/dblog.txt","a");
256 fputs($logfile,$ip."\t".date("dS of F Y h:i:s A")."\t" . $db_user ."\t". $action ."\n");
257 fclose($logfile);
258 } else {
259 exec ("touch logs/dblog.txt");
260 $logfile = fopen("logs/dblog.txt","a");
261 fputs($logfile,$ip."\t".date("dS of F Y h:i:s A")."\t" . $db_user ."\t". $action ."\n");
262 fclose($logfile);
263 }
264 }
265 */
266 ///////////////////////////////////////////////////////////////////////////////////////////////// 267 ?>
| |