PCCS MySQLDatabase Admin Tool version 1.3.4


/incs/ -> global.vars.php

1  <?
2  //////////////////////////////////////////////////////////////////////////
3  // coder: cthorn
4  // Filename: global.vars.php
5  // Function: provide core functions to application
6  //
7  // updated 10-07-2000
8  // -- added changelog to this file
9  // -- added some comments
10  //
11  // updated 10-22-2000
12  // -- added dumpdb() function
13  // -- added getTables() function
14  // Passwd of mysql root user
15  // No need to modify these vars
16 
17  // looking at this I ask myself what where you thinking..
18  // because I can't remenber where these are being called...
19  // will grep mysqldbuser * later... (+:
20  // don't edit them. if you do send me an email if you get an error...
21 
22  $mysqldbuser = "$db_user";
23  $mysqldbpasswd = "$db_passwd";
24 
25  // You can edit these
26  $app_dir = "/home/www/htdocs/pccsmysqladm/";
27  $server_host = gethostbyname($SERVER_ADDR);
28  $app_url = "http://" . gethostbyaddr($SERVER_ADDR) . "/pccsmysqladm/";
29  $bugs_email="cthorn";
30  $appversion="1.3.4"; // version
31  $whichlang = "en"; // current options en
32  $_title ="PCCS MysqlDatabase Admin Tool";
33  $MySQLManual = "http://www.mysql.com/documentation/mysql/bychapter/";
34 
35 
36 
37 
38  // List Display colors //
39 
40  $c1 = "#CCCCCC";
41  $c2 = "#FFFFFF";
42 
43  // BODY Colors //
44 
45  $bgcolor = "006666";
46  $bgtext = "000066";
47  $tcolor = "000077";
48  $ttext = "ffffff";
49  $fcolor = "bbbbbb";
50  $ftext = "000000";
51  $link = "000099";
52 
53 
54 
55  // The need to edit ... really no need unless you just like coding
56 
57  // Images //
58          function displayImage($imgname) {
59                  print "<IMG SRC=\"images/$imgname\" BORDER=0>";
60                  }
61 
62  // Header Function //
63 
64  function common_header($_title)
65  {
66    global $bgcolor,$bgtext,$link;
67 
68                  print "
69                  <STYLE>
70                  .link {text-decoration: none;
71           color: #000000;
72           font-size: 14pt;
73           font-family: sans-serif;
74           }
75                  .title {text-decoration: underline;
76           color: BLUE;
77           font-size: 16pt;
78           font-family: sans-serif;
79           }
80                  
81                  .noul {text-decoration: none;}
82                  .uline {text-decoration: underline;}
83                  
84                  TR,TD,P,BODY
85                   {font-size: 12pt;
86           font-family: sans-serif;
87           }
88          
89                  H2
90                  {font-size: 14pt;
91           font-family: sans-serif;
92           }
93          
94                  B
95                   {font-weight: bold; font-family: sans-serif;
96                   }
97          </STYLE>
98  ";
99 
100          print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
101          print "<HTML>\n";
102          print "<HEAD>\n";
103          print "<TITLE>$_title</TITLE>\n";
104          print "</HEAD>\n";
105 
106          print "<BODY BGCOLOR= \"#$bgcolor\"
107                  TEXT=\"#$bgtext\"
108                  LINK=\"#$link\"
109                  VLINK=\"#$link\"
110                  ALINK=\"#ffffff\">";
111 
112  }
113 
114  // Heading //
115          function heading() {
116          global $str_mainTitle;
117          print "<h3 align=left CLASS=title><font color=blue>
118          $str_mainTitle </font></h3>";
119          }
120 
121 
122  /*
123  ** Function: pageTop()
124  ** Input: Text String, links, pageurl width
125  ** Output: Std HTML
126  ** Description: Top table of web site
127  **
128  **
129  */
130  function pageTop($text_str, $width="500")
131  {
132   global $fcolor, $tcolor, $ttext, $ftext;
133 
134  print "
135      <center>
136 
137 
138        <table border=0 cellpadding=10 cellspacing=0 width=$width>
139 
140          <tr bgcolor=#$tcolor>
141            <td>
142              <font color=#$ttext size=4><center><b>
143               $text_str
144               <br>
145              </b></font>
146            </td>
147          </tr>
148 
149          <tr bgcolor=#$fcolor>
150            <td>
151              <font color=#$ftext>
152 
153      <P>
154 
155      <CENTER>
156      <TABLE CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER
157       BORDER=0 VALIGN=MIDDLE ><TR><TD>
158 
159      <TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER
160       VALIGN=CENTER ><TR><TD>
161 
162        <TABLE CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER
163         VALIGN=TOP BORDER=0><TR>
164        <TD>
165 
166 
167  ";
168 
169  }
170 
171  /*
172  ** Function: pageBottom()
173  ** Input:
174  ** Output: Std HTML
175  ** Description: bottom table of web site
176  **
177  **
178  */
179  function pageBottom()
180  {
181 
182          print "
183             </TD>
184             </TR>
185             </TABLE>
186             </TD></TR></TABLE>
187             </TD></TR></TABLE>
188             </CENTER>
189 
190              </font>
191            </td>
192          </tr>
193 
194        </table>
195 
196      </center>
197    ";
198  }
199 
200 
201  /*
202  ** Function: navBar()
203  ** Input: an array of links
204  ** Output: Std HTML
205  ** Description: display navigational links
206  ** e.g $link_array = array (
207  ** "About" => "about.php",
208  ** "Who We Are" =>"whoweare.php",
209  ** "What We Do" =>"whatwedo.php");
210  **
211  */
212  function navBar($link_array,$page_dir="")
213  {
214     reset($link_array);
215     echo "<TABLE BORDER='0' CELLSPACING=1 CELLPADDING=2><TR>\n";
216     while (list($key, $val) = each($link_array)) {
217        $label = ucfirst($key);
218        $link = $page_dir . "$val";
219           echo "<TD align='CENTER'>\n<FONT SIZE=-1><A HREF=$link CLASS=noul
220  onMouseOver=\"window.status='$label'; return
221  true;\" onMouseOut=\"window.status=' '; return true;\">$label</A></FONT>\n</TD>\n";
222 
223 
224 
225     }
226     echo "</TR></TABLE>\n";
227  }
228 
229 
230 
231  // Footer //
232 
233          function footer() {
234                  print"</BODY></HTML>";
235          }
236 
237  function refresh_meta($param)
238  {
239     global $PHP_SELF;
240     print "<META CONTENT=\"0; URL=$PHP_SELF?$param\" HTTP-EQUIV=\"REFRESH\">";
241  }
242 
243 
244  // Display Table Field //
245 
246     Function displayFields() {
247       global $dbname, $tblname;
248      $result = mysql_list_fields ("$dbname", "$tblname")
249                  or die ("Query failed");
250          for ($i = 0; $i < mysql_num_fields ($result); $i++)
251          {
252                  $val = mysql_field_name ($result, $i);
253                  print "<OPTION NAME=where2 VALUE=\"$val\">$val</OPTION>\n";
254          }
255    }
256    
257  // Display Equate for QueryTool //
258    
259     Function displayEquate() {
260     
261      print"
262      <option><>
263                  <option>=
264                  <option><
265                  <option>>
266                  <option>>=
267                  <option><=
268                  <option>LIKE
269          ";
270          }
271 
272  // Font Color //
273 
274     Function fontcolor($txt,$color)
275           {
276                  print "<FONT COLOR=$color>$txt</FONT>";
277           }
278 
279  // Mouse Over //
280 
281     Function mouseover($txt)
282          {
283                 print("onMouseOver=\"window.status='$txt'; return true;\" onMouseOut=\"window.status=' '; return true;\"");
284          }
285 
286 
287  /////////////////////////////////////////////////////////////////////////////
288  // Function getTables()
289  // Display Tables for database
290 
291  function getTables() {
292   global $dbname, $_isbeta;
293 
294  $result = mysql_list_tables($dbname);
295 
296        $c = "#CCCCCC";
297 
298 
299  print "
300        <CENTER>
301        <TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>
302              <TR>
303              <TH ALIGN=left>Tables</TH>
304           <TH>View Fields</TH>
305           <TH>View Data</TH>
306          
307           <TH>View Indexes</TH>
308  ";
309  if($_isbeta == "yes") {
310 
311          print "
312          <TH>Analyze</TH>
313          <TH>Check/Repair</TH>";
314  }
315          print "
316          <TH>PHP Framework</TH>
317          <TH>Records</TD>
318          </TR>";
319 
320  while($row = mysql_fetch_row($result)) {
321  $table = $row[0];
322  print"
323  <TR BGCOLOR=$c>
324  <TD ALIGN=left>$table</TD>
325  <TD ALIGN=center><A HREF=\"mysqldb_info.php?action=tbldetails&dbname=$dbname&tblname=$table\" CLASS=noul>View Fields</A></TD>
326  <TD ALIGN=center><A HREF=\"mysqldb_displayqry.php?action=get_results&dbname=$dbname&table=$table\" CLASS=noul>View Data</A></TD>
327  <TD ALIGN=center><A HREF=\"mysqldb_runcmd.php?action=showindexes&dbname=$dbname&tblname=$table\" CLASS=noul>View Indexes</A></TD>
328  ";
329 
330  if($_isbeta == "yes") {
331  print "
332  <TD ALIGN=center><A HREF=\"mysqldb_runcmd.php?action=analyzetbl&dbname=$dbname&tblname=$table\" CLASS=noul>Analyze</A></TD>
333  <TD ALIGN=center><A HREF=\"mysqldb_runcmd.php?action=check_repair&dbname=$dbname&tblname=$table\" CLASS=noul>Check/Repair</A></TD>
334  ";
335  }
336 
337  print "
338  <TD ALIGN=center><A HREF=\"mysqldb_info.php?action=begin_genapp&dbname=$dbname&tblname=$table\" CLASS=noul>PHP Framework</A></TD>
339  ";
340  $qry = "SELECT * from $table";
341  $res = mysql($dbname,$qry);
342  $records = mysql_numrows($res);
343 
344  print "<TD ALIGN=right>$records</TD> ";
345  print "</tr>";
346 
347 
348  }
349  print "</table>";
350 
351  print "<P><A HREF=mysqldb_admin.php>BACK to Databases</A>";
352  print "</CENTER>";
353  print "<P>";
354 
355  }
356  /////////////////////////////////////////////////////////////////////////////
357 
358  /////////////////////////////////////////////////////////////////////////////
359  // Function dumpdb($dbname,$dumptype)
360  // $dbname = db to list tables for
361  // $dumptype = 3.23 version beta
362 
363           function dumpdb($dbname,$dumptype) {
364           global $mysqldbuser, $mysqldbpasswd;
365           $_time = date("H:i:s");
366                  $_date = date("Y-m-d");
367                  $_admtool = "/usr/local/bin/mysqldump";
368                  $dumpdir = "." . "/dbdumps/";
369                  if($dumptype == "with") {
370                  $par = "--opt -u$mysqldbuser -p$mysqldbpasswd $dbname";
371                  } else {
372                  $par = "--opt -d -u$mysqldbuser -p$mysqldbpasswd $dbname";
373                  }
374                  $command = "$_admtool $par";
375                  echo "Database dump for $dbname";
376                  echo "<BR>";
377                  echo "$_date :: $_time";
378                  echo "<P>";
379                  exec ($command, $dd, $result);
380                  $indexLimit = count($dd);
381                  $csvfile="db_" . $dbname . date("Ymd") . ".dump";
382                  $myfile = fopen($dumpdir . $csvfile,"w");
383                  for($index=0; $index < $indexLimit; $index++) {
384                  $_dumpdata = (" $dd[$index]\n ");
385                  
386                  // echo (" $_dumpdata<BR>\n ");
387                  fputs($myfile,$_dumpdata);
388 
389                  }
390                  fclose($myfile);
391                  echo "<a href=dbdumps/$csvfile>DUMP</a> File Created\n";
392                  echo "<br><a href=mysqldb_admin.php>BACK to Main</a>\n";
393          }
394 
395 
396  /////////////////////////////////////////////////////////////////////////////
397  // Functions from the phpgen 1.x //
398 
399    Function print_sp($val) {
400          $val = chop($val);
401          if($val != "")
402           print $val;
403          else
404           print "&nbsp;";
405    }
406          
407    Function print_html($val) {
408          $val = htmlspecialchars($val);
409          print $val;
410    }
411 
412    Function array2select($arr,$sel = "") {
413          while ( list( $key, $val ) = each($arr)) {
414           if($sel && $key == $sel) {
415           $select_v=" selected";
416           } else {
417           $select_v="";
418              }
419           echo "<option value=\"$key\" $select_v>$val</option>\n";
420          }
421    }
422 
423    Function array2radio($arr,$name,$sel = "") {
424          while ( list( $key, $val ) = each($arr)) {
425           if($sel && $key == $sel) {
426           $select_v=" checked";
427           } else {
428           $select_v="";
429              }
430           echo "<input type=radio name=\"$name\" value=\"$key\" $select_v> $val\n";
431          }
432    }
433 
434    Function mk_array($from,$to,$form="%d") {
435          $res=array();
436          for($n=$from,$i=0;$n<=$to;$n++,$i++) {
437           $res[$n]=sprintf($form,$n);
438          }
439          return $res;
440    }
441 
442    Function mk_checkbox($name,$value,$cb_val=1) {
443          echo "<input valign=\"top\" type=\"checkbox\" name=\"$name\" value=\"$cb_val\"".($value==$cb_val?" checked>":">");
444    }
445 
446    Function callback_meta($param) {
447          global $PHP_SELF;
448          echo "<META CONTENT=\"0; URL=$PHP_SELF?$param\" HTTP-EQUIV=\"REFRESH\">";
449    }
450    
451    Function callback_js($param) {
452          global $PHP_SELF;
453          echo "<script language=\"JavaScript\">\n";
454     echo "<!--\n";
455     echo "parent.location=\"$PHP_SELF?$param\";\n";
456     echo "// -->\n";
457     echo "</script>\n";
458    }
459    
460   
461    
462  //
463  //////////////////////////////////////////////////////////////////////////
464  ?>


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