| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: view_structure_sql.class.php,v 1.5 2007/10/10 05:25:31 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 /// the entire XMLDB file 29 30 class view_structure_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 $generatorparam = optional_param('generator', null, PARAM_ALPHANUM); 82 if (empty($generatorparam)) { 83 $generatorparam = $CFG->dbtype; 84 } 85 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; 91 } 92 /// Check we have the selected generator 93 if (!in_array($generatorparam, $generators)) { 94 $generatorparam = reset($generators); 95 } 96 97 /// The back to edit table button 98 $b = ' <p class="centerpara buttons">'; 99 $b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>'; 100 $b .= '</p>'; 101 $o = $b; 102 103 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">'; 104 $o.= ' <tr><td align="center">' . $this->str['selectdb']; 105 106 /// Show the popup of generators 107 $url = 'index.php?action=view_structure_sql&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&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"; 116 } 117 $sqltext = trim($sqltext); 118 $o.= $sqltext; 119 } 120 $o.= '</textarea></td></tr>'; 121 $o.= ' </table>'; 122 123 $this->output = $o; 124 125 /// Launch postaction if exists (leave this here!) 126 if ($this->getPostAction() && $result) { 127 return $this->launch($this->getPostAction()); 128 } 129 130 /// Return ok if arrived here 131 return $result; 132 } 133 } 134 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |