[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/admin/xmldb/actions/view_table_sql/ -> view_table_sql.class.php (source)

   1  <?php // $Id: view_table_sql.class.php,v 1.5 2007/10/10 05:25:27 nicolasconnault Exp $
   2  
   3  ///////////////////////////////////////////////////////////////////////////
   4  //                                                                       //
   5  // NOTICE OF COPYRIGHT                                                   //
   6  //                                                                       //
   7  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   8  //          http://moodle.com                                            //
   9  //                                                                       //
  10  // Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
  11  //           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
  12  //                                                                       //
  13  // This program is free software; you can redistribute it and/or modify  //
  14  // it under the terms of the GNU General Public License as published by  //
  15  // the Free Software Foundation; either version 2 of the License, or     //
  16  // (at your option) any later version.                                   //
  17  //                                                                       //
  18  // This program is distributed in the hope that it will be useful,       //
  19  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  20  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  21  // GNU General Public License for more details:                          //
  22  //                                                                       //
  23  //          http://www.gnu.org/copyleft/gpl.html                         //
  24  //                                                                       //
  25  ///////////////////////////////////////////////////////////////////////////
  26  
  27  /// This class will show the SQL generated for the selected RDBMS for
  28  /// one table
  29  
  30  class view_table_sql extends XMLDBAction {
  31  
  32      /**
  33       * Init method, every subclass will have its own
  34       */
  35      function init() {
  36          parent::init();
  37  
  38      /// Set own custom attributes
  39  
  40      /// Get needed strings
  41          $this->loadStrings(array(
  42              'selectdb' => 'xmldb',
  43              'back' => 'xmldb'
  44          ));
  45      }
  46  
  47      /**
  48       * Invoke method, every class will have its own
  49       * returns true/false on completion, setting both
  50       * errormsg and output as necessary
  51       */
  52      function invoke() {
  53          parent::invoke();
  54  
  55          $result = true;
  56  
  57      /// Set own core attributes
  58          $this->does_generate = ACTION_GENERATE_HTML;
  59  
  60      /// These are always here
  61          global $CFG, $XMLDB;
  62  
  63      /// Do the job, setting result as needed
  64      /// Get the dir containing the file
  65          $dirpath = required_param('dir', PARAM_PATH);
  66          $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
  67  
  68      /// Get the correct dirs
  69          if (!empty($XMLDB->dbdirs)) {
  70              $dbdir =& $XMLDB->dbdirs[$dirpath];
  71          } else {
  72              return false;
  73          }
  74          if (!empty($XMLDB->editeddirs)) {
  75              $editeddir =& $XMLDB->editeddirs[$dirpath];
  76              $structure =& $editeddir->xml_file->getStructure();
  77          }
  78      /// ADD YOUR CODE HERE
  79  
  80      /// Get parameters
  81          $tableparam = required_param('table', PARAM_PATH);
  82          if (!$table =& $structure->getTable($tableparam)) {
  83              $this->errormsg = 'Wrong table specified: ' . $tableparm;
  84              return false;
  85          }
  86          $generatorparam = optional_param('generator', null, PARAM_ALPHANUM);
  87          if (empty($generatorparam)) {
  88              $generatorparam = $CFG->dbtype;
  89          }
  90  
  91      /// Calculate list of available SQL generators
  92          $plugins = get_list_of_plugins('lib/xmldb/classes/generators');
  93          $generators = array();
  94          foreach($plugins as $plugin) {
  95              $generators[$plugin] = $plugin;
  96          }
  97      /// Check we have the selected generator
  98          if (!in_array($generatorparam, $generators)) {
  99              $generatorparam = reset($generators);
 100          }
 101  
 102          /// The back to edit table button
 103          $b = ' <p class="centerpara buttons">';
 104          $b .= '<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
 105          $b .= '</p>';
 106          $o = $b;
 107  
 108          $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
 109          $o.= '      <tr><td align="center">' . $this->str['selectdb'];
 110  
 111      /// Show the popup of generators
 112          $url = 'index.php?action=view_table_sql&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;generator=';
 113          $o.= popup_form($url, $generators, 'selectgenerator', $generatorparam, '', '', '' , true);
 114          $o.= '      </td></tr>';
 115          $o.= '      <tr><td><textarea cols="80" rows="32">';
 116      /// Get an array of statements
 117          if ($starr = $table->getCreateTableSQL($generatorparam, $CFG->prefix)) {
 118              $sqltext = '';
 119              foreach ($starr as $st) {
 120                  $sqltext .= s($st) . "\n\n";
 121              }
 122              $sqltext = trim($sqltext);
 123              $o.= $sqltext;
 124          }
 125          $o.= '</textarea></td></tr>';
 126          $o.= '    </table>';
 127  
 128          $this->output = $o;
 129  
 130      /// Launch postaction if exists (leave this here!)
 131          if ($this->getPostAction() && $result) {
 132              return $this->launch($this->getPostAction());
 133          }
 134  
 135      /// Return ok if arrived here
 136          return $result;
 137      }
 138  }
 139  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7