Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / xmldb / actions / view_table_sql / view_table_sql.class.php
blob76cead8255a0d1988e47cd30dd424c1b974e434d
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-3001 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 ///////////////////////////////////////////////////////////////////////////
27 /// This class will show the SQL generated for the selected RDBMS for
28 /// one table
30 class view_table_sql extends XMLDBAction {
32 /**
33 * Init method, every subclass will have its own
35 function init() {
36 parent::init();
38 /// Set own custom attributes
40 /// Get needed strings
41 $this->loadStrings(array(
42 'selectdb' => 'xmldb',
43 'back' => 'xmldb'
44 ));
47 /**
48 * Invoke method, every class will have its own
49 * returns true/false on completion, setting both
50 * errormsg and output as necessary
52 function invoke() {
53 parent::invoke();
55 $result = true;
57 /// Set own core attributes
58 $this->does_generate = ACTION_GENERATE_HTML;
60 /// These are always here
61 global $CFG, $XMLDB;
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);
68 /// Get the correct dirs
69 if (!empty($XMLDB->dbdirs)) {
70 $dbdir =& $XMLDB->dbdirs[$dirpath];
71 } else {
72 return false;
74 if (!empty($XMLDB->editeddirs)) {
75 $editeddir =& $XMLDB->editeddirs[$dirpath];
76 $structure =& $editeddir->xml_file->getStructure();
78 /// ADD YOUR CODE HERE
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;
86 $generatorparam = optional_param('generator', null, PARAM_ALPHANUM);
87 if (empty($generatorparam)) {
88 $generatorparam = $CFG->dbtype;
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;
97 /// Check we have the selected generator
98 if (!in_array($generatorparam, $generators)) {
99 $generatorparam = reset($generators);
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;
108 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
109 $o.= ' <tr><td align="center">' . $this->str['selectdb'];
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";
122 $sqltext = trim($sqltext);
123 $o.= $sqltext;
125 $o.= '</textarea></td></tr>';
126 $o.= ' </table>';
128 $this->output = $o;
130 /// Launch postaction if exists (leave this here!)
131 if ($this->getPostAction() && $result) {
132 return $this->launch($this->getPostAction());
135 /// Return ok if arrived here
136 return $result;