Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / xmldb / actions / view_structure_sql / view_structure_sql.class.php
blob9c9e3aba67b2f5e88be75f67e0ac8996b29b3af7
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 /// the entire XMLDB file
30 class view_structure_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 $generatorparam = optional_param('generator', null, PARAM_ALPHANUM);
82 if (empty($generatorparam)) {
83 $generatorparam = $CFG->dbtype;
86 /// Calculate list of available SQL generators
87 $plugins = get_list_of_plugins('lib/xmldb/classes/generators');
88 $generators = array();
89 foreach($plugins as $plugin) {
90 $generators[$plugin] = $plugin;
92 /// Check we have the selected generator
93 if (!in_array($generatorparam, $generators)) {
94 $generatorparam = reset($generators);
97 /// The back to edit table button
98 $b = ' <p class="centerpara buttons">';
99 $b .= '<a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
100 $b .= '</p>';
101 $o = $b;
103 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
104 $o.= ' <tr><td align="center">' . $this->str['selectdb'];
106 /// Show the popup of generators
107 $url = 'index.php?action=view_structure_sql&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;generator=';
108 $o.= popup_form($url, $generators, 'selectgenerator', $generatorparam, '', '', '' , true);
109 $o.= ' </td></tr>';
110 $o.= ' <tr><td><textarea cols="80" rows="32">';
111 /// Get an array of statements
112 if ($starr = $structure->getCreateStructureSQL($generatorparam, $CFG->prefix)) {
113 $sqltext = '';
114 foreach ($starr as $st) {
115 $sqltext .= s($st) . "\n\n";
117 $sqltext = trim($sqltext);
118 $o.= $sqltext;
120 $o.= '</textarea></td></tr>';
121 $o.= ' </table>';
123 $this->output = $o;
125 /// Launch postaction if exists (leave this here!)
126 if ($this->getPostAction() && $result) {
127 return $this->launch($this->getPostAction());
130 /// Return ok if arrived here
131 return $result;