[ PHPXref.com ] [ Generated: Sun Jul 20 19:55:59 2008 ] [ phpSQLDiff 2.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> index.php (source)

   1  <?php
   2  /*#################################################################
   3  #
   4  # Name:    index.php
   5  #
   6  # Description:
   7  #   Start of sqldiff. Get the details of the databases to open.
   8  #   Save connection details as cookies.
   9  #
  10  # Parameters:
  11  #   project - optional project to be used, allows overrides of 
  12  #           local_config values so we can work with alternate databases.
  13  #   cid - optional cookie id number. Allows multiple instances of SQLView
  14  #   state - controls which session variables we use
  15  #       'startover' - use existing session
  16  #       else create a new session, discard old one
  17  #
  18  # Copyright (C) 2001-2006 Dmitriy Katsman, Terry Gliedt, University of Michigan
  19  # This is free software; you can redistribute it and/or modify it under the
  20  # terms of the GNU General Public License as published by the Free Software
  21  # Foundation; See http://www.gnu.org/copyleft/gpl.html
  22  #################################################################*/
  23  include_once "common.php";
  24  global $cid;
  25  include_once "session.php";             // Set up session variables
  26  ob_start();
  27  eval('include_once "local_config.php";');       // Maybe local_config not done
  28  $value = ob_get_contents();
  29  ob_end_clean();
  30  if ($value) {                           // This failed, try setup
  31      local_config_failed($value);
  32      exit;
  33  }
  34  
  35  $allfields = array(
  36      'type'  => 'Database Type',
  37      'host'  => 'Database Host',
  38      'db'    => 'Database Name',
  39      'user'  => 'User Name',
  40      'pass'  => 'Password',
  41      'table' => 'Table Name',
  42      'comp'  => 'Compare Column',
  43  );
  44  
  45  //print "<!-- _GET=\n"; print_r($_GET); print " -->\n";
  46  //print "<!-- _SESSION=\n"; print_r($_SESSION); print "-->\n";
  47  
  48  //  Get parameters passed in via normal invocation
  49  extract(isolate_parms( 'state', 'project'));
  50  $_SESSION['cid'] = $cid;
  51  
  52  //  Reset all session variables except a very minimal set
  53  reset ($_SESSION);
  54  while (list ($key, $val) = each($_SESSION)) {
  55      if ($key == 'session') { continue; }
  56      if (preg_match('/^row/',$key)) { continue; }
  57      if (preg_match('/^sql_/',$key)) { continue; }
  58      unset($_SESSION[$key]);
  59  }
  60  
  61  //  Override any project related variables
  62  get_project($project);
  63  
  64  //-------------------------------------------------------------------
  65  //  We only do one thing, prompt to connect to the database
  66  //-------------------------------------------------------------------
  67  doheader(0);
  68  
  69  //  See if the user is allowed to use this project
  70  verify_access($project);
  71  
  72  //  Maybe the project code provided a little extra HTML to replace the header
  73  if (isset($LOCALOPT['text']) && $LOCALOPT['text']) { print $LOCALOPT['text']; }
  74  else {
  75      $t = "SQLDiff - Compare Two Tables";
  76      if ($LOCALOPT['title'] != '') { $t = $LOCALOPT['title']; }
  77      print "<h2 align=\"center\">" . $LOCALOPT['title'] . "</h2>\n";
  78  }
  79  
  80  //  Generate the form on the first page 
  81  print <<<END
  82  <form action="diff.php" method="post" name="tables">
  83  <input type="hidden" name="cid" value="$cid"/>
  84  
  85  END;
  86  
  87  reset ($allfields);
  88  //  Generate hidden fields (i.e. those not in $LOCALOPT['promptfor']
  89  while (list ($key, $val) = each($allfields)) {
  90      if (! in_array ($key, $LOCALOPT['promptfor'])) {
  91          $t = "diff${key}1";
  92          print "<input type=\"hidden\" name=\"sql_$key\" value=\"$LDB[$t]\"/>\n" .
  93              "<input type=\"hidden\" name=\"sql_${key}2\" value=\"$LDB[$t]\"/>\n";
  94      }
  95  }
  96  print "  <table align=\"center\">\n<tr><td>\n";     
  97  
  98  //  Generate master table prompt
  99  print "  <table summary=\"summary\" border=\"0\" cellspacing=\"15\" class=\"master\">\n" .
 100      "  <tr>\n     <td colspan=\"2\" align=\"center\"><b><u>Master Table</u></b></td>\n  </tr>\n";
 101  
 102  reset ($allfields);
 103  $compwarning = '';
 104  while (list ($key, $val) = each($allfields)) {
 105      if (! in_array ($key, $LOCALOPT['promptfor'])) { continue; }
 106      if ($key == 'comp') { $compwarning = 1; }
 107      $t = "sql_$key";
 108      if (isset($_SESSION[$t])) { $defval = $_SESSION[$t]; }
 109      else {
 110          $t = "diff${key}1";
 111          $defval = $LDB[$t];
 112      }
 113      $typ = 'text';
 114      if ($key == 'pass') { $typ = 'password'; }
 115      print <<<END
 116    <tr>
 117      <td><b>$val:</b></td>
 118      <td><input type="$typ" name="sql_$key" value="$defval" onchange="set${key}2()"/>
 119      </td>
 120    </tr>
 121  
 122  END;
 123  }
 124  print "  </table>\n</td>\n<td>\n";
 125  
 126  //  Generate modified table prompt
 127  print "  <table summary=\"summary2\" border=\"0\" cellspacing=\"15\" class=\"modified\">\n" .
 128      "  <tr>\n     <td colspan=\"2\" align=\"center\"><b><u>Modified Table</u></b></td>\n  </tr>\n";
 129  
 130  reset ($allfields);
 131  while (list ($key, $val) = each($allfields)) {
 132      if (! in_array ($key, $LOCALOPT['promptfor'])) { continue; }
 133      $t = "sql_${key}2";
 134      if (isset($_SESSION[$t])) { $defval = $_SESSION[$t]; }
 135      else {
 136          $t = "diff${key}2";
 137          $defval = $LDB[$t];
 138      }
 139      $typ = 'text';
 140      if ($key == 'pass') { $typ = 'password'; }
 141      print <<<END
 142    <tr>
 143      <td><b>$val:</b></td>
 144      <td><input type="$typ" name="sql_${key}2" value="$defval"/>
 145      </td>
 146    </tr>
 147  
 148  END;
 149  }
 150  print "  </table>\n</td>\n</tr>\n";
 151  
 152  //  Here's the button to start us off and the footer
 153  print "<tr>\n";
 154  if ($LOCALOPT['showdetails']) {
 155      print "  <td align=\"left\"><input type=\"checkbox\" value=\"1\" name=\"showdetails\"/> " .
 156          " Show Details</td>\n";
 157      print "  <td align=\"center\"><b><input type=\"submit\" value=" .
 158          "\" Compare Tables \"/></b></td>\n";
 159  }
 160  else {
 161      print "  <td align=\"center\" colspan=\"2\"><b><input type=\"submit\" value=" .
 162          "\" Compare Tables \"/></b></td>\n";
 163  }
 164  
 165  //  Provide warning if comp column possible
 166  if ($compwarning) {
 167      $compwarning = <<<END
 168  <p><b>WARNING:</b> Specifing a Compare Column which is not the primary
 169  key can result in surprising grouping of data.
 170  Making changes to tables when the primary key is not used
 171  will almost always result in more rows being changed than 
 172  you expect.
 173  Be exceedingly careful if you attempt to make SQL changes based
 174  on comparisons not based on the primary key.
 175  </p>
 176  
 177  END;
 178  }
 179  
 180  //  Footer
 181  print <<<END
 182  </tr>
 183  </table>
 184  </form>
 185  $compwarning
 186  <hr/>
 187  <table><tr>
 188    <td><a href="doc.html"><b>Documentation</b></a></td>
 189    <td width="100">&nbsp;</td>
 190  
 191  END;
 192  
 193  //  Add local links at the bottom of the page
 194  while (list ($key, $val) = each($LOCALOPT['bottomlinks'])) {
 195    print "<td><a href=\"$val\"><b>$key</b></a></td>\n";
 196  }
 197  
 198  print <<<END
 199    <td width="100">&nbsp;</td>
 200    <td><b>Not Connected</b></td>
 201  </tr></table>
 202  
 203  </body>
 204  </html>
 205  
 206  END;
 207                             
 208  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]