PCCS MySQLDatabase Admin Tool version 1.3.4


/ -> mysqldb_qrytool.php

1  <?php
2   // Hacked by: Chauncey Thorn
3   // code reuse
4  /************************************************************************
5  PCCS MySQLDatabase Admin Tool
6  Copyright (C) 1999 Chauncey Thorn
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
21  **************************************************************************/
22    
23  // updated 10-23-2000
24  // -- moving to a single file for global include files
25    
26  require('mysqldb_app_includes.php');
27     
28     common_header($_title);
29     
30    pageTop("PCCS MySQLAdmin Tool: QUERY TOOL","600");
31 
32  $link_array = array(
33  "$str_mainMenu" => "./",
34  "$str_installscriptlink" => "installscript/mysqldb_installscript.php",
35  "$str_createwebacct" => "mysqldb_create_webuser.php",
36  "LOGOUT" => "logout.php"
37  );
38     
39   print "<BR>";
40   print "<CENTER>";
41   navBar($link_array);
42   print "</CENTER>";
43   print "<BR>";
44 
45 
46  $across = "6";
47  function displayDatabases() {
48          global $across, $start_script;
49          
50          $content .="<table width=100% border=0 cellpadding=3><tr>";
51          $result_1 = mysql_query("SHOW DATABASES");
52          
53                  while ($info = mysql_fetch_array($result_1))
54                  {
55                  
56                  $a++;
57                  
58                  $content .="<td><small><a
59          
60  href=\"mysqldb_qrytool.php?action=listtbls&dbname=$info[Database]\" CLASS=noul><b>$info[Database]
61                  </b></a>";
62                  $content .= "$info[User]</small></td>\n";
63                  if ($a == $across) {$content .="</tr>"; $a=0;}
64          }
65          
66          $content .= "</tr></table>";
67          
68          echo $content;
69          }
70 
71  if($argv[0] == ""):
72          // heading();
73 
74  print "
75  <font face=\"arial, heveltica\" size=\"2\" color=\"Red\" style=\"font-size: 12;
76  font-weight: normal;\">";
77  $cur_date = date("l M d, Y H:i:s");
78  print " $cur_date";
79  print "<p>";
80  print "<center>Click on the Database you wish to run query
81  against</center>";
82  print "</font>";
83  print "<HR>";
84          displayDatabases();
85  print "<P>";
86  print "<HR>";
87  print "<P>";
88  print "<<<<A HREF=./>back ...</A>";
89 
90  endif;
91 
92 
93  if($action == "listtbls"):
94          print "<FORM ACTION=$PHP_SELF?action=searchform METHOD=POST>";
95          print "<CENTER>\n";
96          print "<BIG>Select a table from " .$dbname. " to run a query from... </BIG><P>\n";
97          print "<BIG><B>\n";
98          print "<SELECT NAME=tblname>\n";
99                  $db = mysql_listtables($dbname);
100                  for ($i = 0; $i < mysql_numrows($db); $i++):
101                          echo "\t\t\t\t\t\t\t<OPTION VALUE=\"",
102                                  mysql_tablename($db, $i);
103                          if ($tablename == mysql_tablename($db, $i))
104                                  echo " SELECTED";
105                          echo "\">\n ", mysql_tablename($db, $i), "\n";
106                  endfor;
107          print "</SELECT>\n";
108          print "</B></BIG>\n";
109  /*
110          print "<SELECT multiple NAME=tblname[]>";
111                  for ($i = 0; $i < mysql_numrows($db); $i++):
112                          echo "\t\t\t\t\t\t\t<OPTION VALUE=\"",
113                                  mysql_tablename($db, $i);
114                          if ($tablename == mysql_tablename($db, $i))
115                                  echo " SELECTED";
116                          echo "\"> ", mysql_tablename($db, $i), "\n";
117                  endfor;
118          print "</SELECT>\n";
119  */
120          print "<INPUT TYPE=\"HIDDEN\" NAME=\"dbname\" VALUE=\"$dbname\">\n";
121          print "<INPUT TYPE=\"SUBMIT\" VALUE=\"Run Query against table\">\n";
122          print "</FORM>";
123          
124          // Modifed code
125          // Chauncey Thorn
126          // - changed free form link to submit button
127          // - added display tables and fields checkbox
128          
129          print "OR use the ";
130          print "<FORM ACTION=$PHP_SELF?action=freeform&dbname=$dbname
131          METHOD=post>";
132          print "<INPUT TYPE=submit value=\"Form Query\"></A><br>\n";
133          
134          print "Display Tables and Fields ? <INPUT TYPE=checkbox NAME=\"displayfields\" VALUE=\"yes\"><P>";
135          print "e.g. <I>SELECT user.User, user.Password FROM tablename WHERE lastname = 'value' AND userid = 'value'</I>";
136          print "<P><A HREF=$PHP_SELF>back to databases</A>\n";
137          // print "</CENTER>\n";
138          
139  endif;
140 
141  if($action == "freeform"):
142          $today = Date("mdy");
143          print "
144          <CENTER>
145          <H3>Enter Query against <FONT COLOR=red> $dbname </FONT></H3>
146          <FORM ACTION=$PHP_SELF?action=freeform_res METHOD=POST>
147          <BR>
148          <TEXTAREA NAME=qry COLS=70 ROWS=10 WRAP=virtual></TEXTAREA><BR>
149          HTML File <INPUT TYPE=radio NAME=mode VALUE=\"htmlfile\">
150          <INPUT TYPE=\"text\" NAME=\"filename\" SIZE=\"25\" VALUE=\"$dbname-$tblname$today.html\">
151          XML File <INPUT TYPE=radio NAME=mode VALUE=\"writexml\">
152          <INPUT TYPE=\"text\" NAME=\"xml_filename\" SIZE=\"25\" VALUE=\"$dbname-$tblname$today.xml\">
153          <font color=red>Display</font> <INPUT TYPE=radio NAME=mode VALUE=\"display\">
154          <INPUT TYPE=hidden NAME=dbname VALUE=$dbname>
155          <P>
156          <INPUT TYPE=SUBMIT VALUE=\"Run Query\">
157          </FORM>
158          
159          </CENTER>";
160          
161          // Code added
162          // Chauncey Thorn
163          // - option to display table and fields
164          
165          if($displayfields == "yes"):
166          print "<P>
167          <HR NOSHADE>
168          <H2>Tables and fields in : $dbname </H2>
169          <P>
170          ";
171                  
172          $res = mysql_list_tables($dbname);
173          $fields=mysql_num_rows($res);
174          while($row=mysql_fetch_row($res)) {
175           print "<center>\n<font size=+1><b>Table : " .$row[0] . "</b></font><br>\n";
176           $result=mysql_query("DESCRIBE $row[0]");
177           print "<table width=340>\n";
178           while($field=mysql_fetch_array($result)) {
179           print "<tr>";
180           for($i=0; $i<mysql_num_fields($result); $i++)
181           { print "<td>" . $field[$i] . "</td>"; }
182           print "</tr>\n";
183           }
184           print "</table></center>\n";
185           print "<P>\n";
186          }
187          endif;
188 
189  endif;
190 
191  if($action == "freeform_res"):
192  // include('incs/mysqldb_functions.php');
193 
194  if($mode == "display") {
195          show_results($qry);
196          print "<<<<A HREF=$PHP_SELF>back ...</A>" ;
197  } elseif ($mode == "htmlfile") {
198   echo "Creating HTML File";
199                  write_htmlfile($qry,$filename);
200                  print "\n<br>HTML File created as a result of your query: <a
201                  href=tmp/$filename> $filename</a>";
202                  print " <br> You may<a
203                  href=sqledit.php?directory=tmp/&filename=$filename>Edit</a> the
204                  file";
205                  print " <br><a href=webadmin_fm.php>Goto</a> The WebAdmin
206                  FileManager >>>
207                  <P><<<<A HREF=./>back ...</A>
208                  ";
209 
210  } elseif ($mode == "writexml") {
211  require('xml/createxml.php');
212          createxmlFile($qry,$xml_filename);
213 
214 
215 
216  }
217 
218  endif;
219 
220 
221  if($action == "searchform"):
222          print "
223          <CENTER>
224 
225          <FORM ACTION=$PHP_SELF?action=dbsearch METHOD=POST>
226          <TABLE CELLPADING=5>
227          <TR>
228          <TD COLSPAN=\"3\" ALIGN=center SIZE=5><FONT SIZE=\"+3\" COLOR=blue>
229          <B>SQL Query Tool</B></FONT>
230          </TR>
231 
232          <TR>
233          <TD VALIGN=TOP ><BIG><B> SELECT </B></BIG>
234          <TD COLSPAN=\"2\">
235          <INPUT TYPE=text NAME=_sel
236          SIZE=35 VALUE=\"*\">
237          &nbsp; FROM $tblname
238          </TD>
239 
240          <TD></TD>
241 
242          <TR><TD> WHERE </TD>
243          </TR>
244          <TR>
245          <TD VALIGN=TOP>
246          <SELECT NAME=\"where1\">
247  ";
248          displayFields();
249          
250  print "</SELECT>";
251  print "
252          <TD>
253          <SELECT NAME=\"equate1\">";
254   
255          displayEquate();
256   
257  print "
258          </SELECT>
259          </TD>
260          
261  ";
262 
263  print "
264  </TR>
265 
266  <TR>
267  <TD><INPUT TYPE=\"text\" NAME=\"searchvalue1\">
268  </TR>
269  <TR>
270  <TD> <INPUT TYPE=\"radio\" VALUE=\"AND\" NAME=\"andor\" checked>AND<BR>
271  <INPUT TYPE=\"radio\" VALUE=\"OR\" NAME=\"andor\">OR<TD VALIGN=TOP>";
272  print "<SELECT NAME=\"where2\">";
273 
274          displayFields();
275 
276 
277  print "</SELECT>";
278  print "
279          <TD>
280          <SELECT NAME=\"equate2\">" ;
281          
282          displayEquate();
283  print "
284          </SELECT>
285          </TD>
286  </TR>
287 
288  <TR>
289          <TD><INPUT TYPE=\"text\" NAME=\"searchvalue2\"><P>
290  </TR>
291  <TR>
292  <TD>ORDER BY: </TD>
293  </TR>
294 
295  <TR>
296  <TD>
297          <SELECT NAME=\"order_by\">
298  ";
299 
300          displayFields();
301 
302 
303          
304  print "</SELECT>";
305  print "
306  </TD>
307  </TR>
308 
309  <TR>
310  <TD>
311  HTML File <INPUT TYPE=radio NAME=mode VALUE=\"htmlfile\">";
312  $today = Date("mdy");
313  print "
314  <INPUT TYPE=\"text\" NAME=\"filename\" SIZE=\"25\" VALUE=\"$dbname-$tblname$today.html\">
315  </TD>
316  </TR>
317  <TR>
318  <TD>
319  XML File <INPUT TYPE=radio NAME=mode VALUE=\"writexml\">
320  <INPUT TYPE=\"text\" NAME=\"xml_filename\" SIZE=\"25\" VALUE=\"$dbname-$tblname$today.xml\">
321  </TD>
322  </TR>
323 
324  <TR>
325  <TD>
326  <font color=red>Display</font> <INPUT TYPE=radio NAME=mode VALUE=\"showresults\">
327  </TD>
328  </TR>
329  <TR>
330  <TD COLSPAN=3 ALIGN=CENTER >
331  <INPUT TYPE=\"hidden\" NAME=\"tblname\" VALUE=\"$tblname\">
332  <INPUT TYPE=\"hidden\" NAME=\"dbname\" VALUE=\"$dbname\">
333  <INPUT TYPE=\"submit\" VALUE=\"Submit Search\">
334  </TR>
335 
336  <TR>
337  <TD COLSPAN=\"4\">$str_querytool<P>
338  <<<<A HREF=./>back ...</A>
339  </TR>
340 
341  </TABLE>
342  </FORM>
343  </CENTER>
344  ";
345  endif;
346 
347 
348 
349  if($action == "dbsearch"):
350          print "<p>";
351 
352          $qry = "SELECT $_sel
353          FROM $tblname
354          WHERE ($where1 $equate1 '" . $searchvalue1 . "' $andor $where2 $equate2 '" . $searchvalue2 . "' )
355          ORDER BY $order_by ";
356                          
357 
358   // echo "$qry";
359 
360 
361 
362  ///////////////////////////////////////////////////////////////////////////////
363 
364 
365  // print "<table><tr>";
366  // include('incs/mysqldb_functions.php');
367 
368          if($mode == "htmlfile"):
369 
370                  write_htmlfile($qry,$filename);
371                  // fixed path issue added tmp/ to URL
372                  print "\n<br>HTML File created as a result of your query: <a href=tmp/$filename>
373  $filename</a>";
374                  print " <br> You may<a
375                  href=sqledit.php?directory=./&filename=$filename>Edit</a> the
376                  file";
377                  print " <br><a href=webadmin_fm.php>Goto</a> The WebAdmin
378                  FileManager >>>";
379                  print " <br><a href=mysqldb_admin.php>Goto</a> DB Admin >>>";
380                  elseif($mode == "showresults"):
381                          show_results($qry);
382                  elseif($mode == "writexml"):
383  require('xml/createxml.php');
384           createxmlFile($qry,$xml_filename);
385 
386 
387          endif;
388          
389  endif;
390 
391 
392  pageBottom();
393  footer();
394  ?>


Generated: Sat Jan 27 15:40:36 2001 Generated by PHPXref 0.1.2
PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002