[ PHPXref.com ] [ Generated: Sun Jul 20 19:45:58 2008 ] [ phpMSAdmin 0.14 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> table_export.php (source)

   1  <?php
   2       /*
   3       Copyright (C)
   4  
   5       This program is free software; you can redistribute it and/or modify it
   6       under the terms of the GNU General Public License as published by the Free
   7       Software Foundation; either version 2 of the License, or (at your option)
   8       any later version.
   9  
  10       This program is distributed in the hope that it will be useful, but WITHOUT
  11       ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12       FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13       more details.
  14  
  15       You should have received a copy of the GNU General Public License along
  16       with this program; if not, write to the Free Software Foundation, Inc.,
  17       59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18       */
  19  ?>
  20  <?php
  21  
  22  include ('inc/header.php');
  23  
  24  if($_POST['delimiter'] == '')
  25  {
  26      echo '<form name="form1" method="post" action="table_export.php">';
  27  
  28      foreach($_POST['tables'] AS $row)
  29      {
  30          echo('<input type="hidden" name="tables[]" value="' . $row . '">');
  31      }
  32  ?>
  33  
  34  <table cellpadding="3" cellspacing="3" style="border: 1px solid">
  35      <tr>
  36          <td align="center" colspan="2" style="background: #D0DCE0">
  37              <b>Export Table Data</b>
  38          </td>
  39      </tr>
  40      <tr>
  41          <td align="right" nowrap>
  42              <b>Field Delimiter:</b>
  43          </td>
  44          <td>
  45              <input name="delimiter" size="5" maxlength="10" value=",">
  46          </td>
  47      </tr>
  48      <tr>
  49          <td align="right" nowrap>
  50              <b>Field Quoted With:</b>
  51          </td>
  52          <td>
  53              <select name="fieldquote">
  54                  <option value="single" selected>'</option>
  55                  <option value="double">"</option>
  56              </select>
  57          </td>
  58      </tr>
  59      <tr>
  60          <td align="right" valign="top" nowrap>
  61              <b>Export Type:</b>
  62          <td nowrap>
  63              <input type="radio" name="exporttype" value="sql" checked>SQL Based<br>
  64              <input type="radio" name="exporttype" value="csv">CSV Based
  65          </td>
  66      </tr>
  67      <tr>
  68          <td align="center" colspan="2">
  69              <input type="submit" value="Export">
  70          </td>
  71      </tr>
  72  </table>
  73  </form>
  74  
  75  <script language="javascript">
  76  document.form1.delimiter.focus();
  77  </script>
  78  
  79  <?php
  80  
  81  }
  82  else
  83  {
  84      @mssql_select_db($_SESSION['database']) or die(throwSQLError('unable to select database'));
  85  
  86       if($_POST['fieldquote'] == 'single')
  87            $quote = '\'';
  88       else
  89            $quote = '"';
  90  
  91       echo '<form name="form1" method="post" action="table_export_download.php">';
  92       echo('<input type="hidden" name="exporttype" value="' . $_POST['exporttype'] . '">');
  93       echo '<textarea name="data" rows="30" cols="75">';
  94  
  95      $tablecount = count($_POST['tables']);
  96      for($counter = 0; $counter < $tablecount; $counter++)
  97      {
  98          $table_query = @mssql_query('SELECT * FROM ' . $_POST['tables'][$counter] . ';') or die(throwSQLError('unable to retrieve table data'));
  99          while($row = mssql_fetch_array($table_query))
 100          {
 101              if(!isset($schema))
 102              {
 103                  $schema = array();
 104  
 105                  foreach($row AS $key => $value)
 106                      if(!is_int($key))
 107                          $schema[] = $key;
 108              }
 109  
 110              $values = array();
 111              foreach($schema AS $col)
 112                      if($quote == '\'')
 113                           $values[] = '\'' . str_replace('\'','\'\'',$row[$col]) . '\'';
 114                      else
 115                           $values[] = '"' . $row[$col] . '"';
 116  
 117                 if($_POST['exporttype'] == 'sql')
 118                      echo('INSERT INTO ' . $_POST['tables'][$counter] . ' (' . implode(',',$schema) . ') VALUES (' . implode(',',$values) . ");\n");
 119                 else
 120                      echo(implode(',',$values) . "\n");
 121  
 122              unset($values);
 123          }
 124  
 125          unset($table_query,$row,$schema);
 126      }
 127  
 128      echo '</textarea>';
 129      echo '<br><br><input type="submit" value="Save to File">';
 130      echo '</form>';
 131  }
 132  
 133  include ('inc/footer.php');
 134  
 135  ?>


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