|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00035 class main_view extends XMLDBAction { 00036 00040 function init() { 00041 parent::init(); 00042 00043 // Set own custom attributes 00044 $this->sesskey_protected = false; // This action doesn't need sesskey protection 00045 00046 // Get needed strings 00047 $this->loadStrings(array( 00048 'load' => 'tool_xmldb', 00049 'create' => 'tool_xmldb', 00050 'edit' => 'tool_xmldb', 00051 'save' => 'tool_xmldb', 00052 'revert' => 'tool_xmldb', 00053 'unload' => 'tool_xmldb', 00054 'delete' => 'tool_xmldb', 00055 'reservedwords' => 'tool_xmldb', 00056 'gotolastused' => 'tool_xmldb', 00057 'checkindexes' => 'tool_xmldb', 00058 'checkdefaults' => 'tool_xmldb', 00059 'checkforeignkeys' => 'tool_xmldb', 00060 'checkbigints' => 'tool_xmldb', 00061 'checkoraclesemantics' => 'tool_xmldb', 00062 'doc' => 'tool_xmldb', 00063 'viewxml' => 'tool_xmldb', 00064 'pendingchangescannotbesavedreload' => 'tool_xmldb' 00065 )); 00066 } 00067 00073 function invoke() { 00074 parent::invoke(); 00075 00076 $result = true; 00077 00078 // Set own core attributes 00079 $this->does_generate = ACTION_GENERATE_HTML; 00080 00081 // These are always here 00082 global $CFG, $XMLDB, $SESSION, $DB; 00083 00084 // Get lastused 00085 $o = ''; 00086 if (isset($SESSION->lastused)) { 00087 if ($lastused = $SESSION->lastused) { 00088 // Print link 00089 $o .= '<p class="centerpara"><a href="#lastused">' . $this->str['gotolastused'] . '</a></p>'; 00090 } 00091 } else { 00092 $lastused = NULL; 00093 } 00094 00095 // Calculate the buttons 00096 $b = '<p class="centerpara buttons">'; 00097 // The reserved_words button 00098 $b .= ' <a href="index.php?action=view_reserved_words">[' . $this->str['reservedwords'] . ']</a>'; 00099 // The docs button 00100 $b .= ' <a href="index.php?action=generate_all_documentation">[' . $this->str['doc'] . ']</a>'; 00101 // The check indexes button 00102 $b .= ' <a href="index.php?action=check_indexes&sesskey=' . sesskey() . '">[' . $this->str['checkindexes'] . ']</a>'; 00103 // The check defaults button 00104 $b .= ' <a href="index.php?action=check_defaults&sesskey=' . sesskey() . '">[' . $this->str['checkdefaults'] . ']</a>'; 00105 // The check bigints button (only for MySQL and PostgreSQL) MDL-11038a 00106 if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') { 00107 $b .= ' <a href="index.php?action=check_bigints&sesskey=' . sesskey() . '">[' . $this->str['checkbigints'] . ']</a>'; 00108 } 00109 // The check semantics button (only for Oracle) MDL-29416 00110 if ($DB->get_dbfamily() == 'oracle') { 00111 $b .= ' <a href="index.php?action=check_oracle_semantics&sesskey=' . sesskey() . '">[' . $this->str['checkoraclesemantics'] . ']</a>'; 00112 } 00113 $b .= ' <a href="index.php?action=check_foreign_keys&sesskey=' . sesskey() . '">[' . $this->str['checkforeignkeys'] . ']</a>'; 00114 $b .= '</p>'; 00115 // Send buttons to output 00116 $o .= $b; 00117 00118 // Do the job 00119 00120 // Get the list of DB directories 00121 $result = $this->launch('get_db_directories'); 00122 // Display list of DB directories if everything is ok 00123 if ($result && !empty($XMLDB->dbdirs)) { 00124 $o .= '<table id="listdirectories" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">'; 00125 $row = 0; 00126 foreach ($XMLDB->dbdirs as $key => $dbdir) { 00127 // Detect if this is the lastused dir 00128 $hithis = false; 00129 if (str_replace($CFG->dirroot, '', $key) == $lastused) { 00130 $hithis = true; 00131 } 00132 $elementtext = str_replace($CFG->dirroot . '/', '', $key); 00133 // Calculate the dbdir has_changed field if needed 00134 if (!isset($dbdir->has_changed) && isset($dbdir->xml_loaded)) { 00135 $dbdir->xml_changed = false; 00136 if (isset($XMLDB->editeddirs[$key])) { 00137 $editeddir =& $XMLDB->editeddirs[$key]; 00138 if (isset($editeddir->xml_file)) { 00139 $structure =& $editeddir->xml_file->getStructure(); 00140 if ($structure->hasChanged()) { 00141 $dbdir->xml_changed = true; 00142 $editeddir->xml_changed = true; 00143 } 00144 } 00145 } 00146 } 00147 // The file name (link to edit if the file is loaded) 00148 if ($dbdir->path_exists && 00149 file_exists($key . '/install.xml') && 00150 is_readable($key . '/install.xml') && 00151 is_readable($key) && 00152 !empty($dbdir->xml_loaded)) { 00153 $f = '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">' . $elementtext . '</a>'; 00154 } else { 00155 $f = $elementtext; 00156 } 00157 // Calculate the buttons 00158 $b = ' <td class="button cell">'; 00159 // The create button 00160 if ($dbdir->path_exists && 00161 !file_exists($key . '/install.xml') && 00162 is_writeable($key)) { 00163 $b .= '<a href="index.php?action=create_xml_file&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['create'] . ']</a>'; 00164 } else { 00165 $b .= '[' . $this->str['create'] . ']'; 00166 } 00167 $b .= '</td><td class="button cell">'; 00168 // The load button 00169 if ($dbdir->path_exists && 00170 file_exists($key . '/install.xml') && 00171 is_readable($key . '/install.xml') && 00172 empty($dbdir->xml_loaded)) { 00173 $b .= '<a href="index.php?action=load_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['load'] . ']</a>'; 00174 } else { 00175 $b .= '[' . $this->str['load'] . ']'; 00176 } 00177 $b .= '</td><td class="button cell">'; 00178 // The edit button 00179 if ($dbdir->path_exists && 00180 file_exists($key . '/install.xml') && 00181 is_readable($key . '/install.xml') && 00182 is_readable($key) && 00183 !empty($dbdir->xml_loaded)) { 00184 $b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['edit'] . ']</a>'; 00185 } else { 00186 $b .= '[' . $this->str['edit'] . ']'; 00187 } 00188 $b .= '</td><td class="button cell">'; 00189 // The save button 00190 if ($dbdir->path_exists && 00191 file_exists($key . '/install.xml') && 00192 is_writeable($key . '/install.xml') && 00193 is_writeable($key) && 00194 !empty($dbdir->xml_loaded) && 00195 !empty($dbdir->xml_changed)) { 00196 $b .= '<a href="index.php?action=save_xml_file&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['save'] . ']</a>'; 00197 // Check if the file has been manually edited while being modified in the editor 00198 if ($dbdir->filemtime != filemtime($key . '/install.xml')) { 00199 // File manually modified. Add to errors. 00200 if ($structure =& $dbdir->xml_file->getStructure()) { 00201 $structure->errormsg = 'Warning: File locally modified while using the XMLDB Editor. Saving will overwrite local changes'; 00202 } 00203 } 00204 } else { 00205 $b .= '[' . $this->str['save'] . ']'; 00206 } 00207 $b .= '</td><td class="button cell">'; 00208 // The document button 00209 if ($dbdir->path_exists && 00210 file_exists($key . '/install.xml') && 00211 is_readable($key . '/install.xml') && 00212 is_readable($key)) { 00213 $b .= '<a href="index.php?action=generate_documentation&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['doc'] . ']</a>'; 00214 } else { 00215 $b .= '[' . $this->str['doc'] . ']'; 00216 } 00217 $b .= '</td><td class="button cell">'; 00218 // The view xml button 00219 if ($dbdir->path_exists && 00220 file_exists($key . '/install.xml') && 00221 is_readable($key . '/install.xml')) { 00222 $b .= '<a href="index.php?action=view_xml&file=' . urlencode(str_replace($CFG->dirroot, '', $key) . '/install.xml') . '">[' . $this->str['viewxml'] . ']</a>'; 00223 } else { 00224 $b .= '[' . $this->str['viewxml'] . ']'; 00225 } 00226 $b .= '</td><td class="button cell">'; 00227 // The revert button 00228 if ($dbdir->path_exists && 00229 file_exists($key . '/install.xml') && 00230 is_readable($key . '/install.xml') && 00231 is_writeable($key) && 00232 !empty($dbdir->xml_loaded) && 00233 !empty($dbdir->xml_changed)) { 00234 $b .= '<a href="index.php?action=revert_changes&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['revert'] . ']</a>'; 00235 } else { 00236 $b .= '[' . $this->str['revert'] . ']'; 00237 } 00238 $b .= '</td><td class="button cell">'; 00239 // The unload button 00240 if ($dbdir->path_exists && 00241 file_exists($key . '/install.xml') && 00242 is_readable($key . '/install.xml') && 00243 !empty($dbdir->xml_loaded) && 00244 empty($dbdir->xml_changed)) { 00245 $b .= '<a href="index.php?action=unload_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['unload'] . ']</a>'; 00246 } else { 00247 $b .= '[' . $this->str['unload'] . ']'; 00248 } 00249 $b .= '</td><td class="button cell">'; 00250 // The delete button 00251 if ($dbdir->path_exists && 00252 file_exists($key . '/install.xml') && 00253 is_readable($key . '/install.xml') && 00254 is_writeable($key) && 00255 empty($dbdir->xml_loaded)) { 00256 $b .= '<a href="index.php?action=delete_xml_file&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['delete'] . ']</a>'; 00257 } else { 00258 $b .= '[' . $this->str['delete'] . ']'; 00259 } 00260 $b .= '</td>'; 00261 // include the higlight 00262 if ($hithis) { 00263 $o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $f . '</td>' . $b . '</tr>'; 00264 } else { 00265 $o .= '<tr class="r' . $row . '"><td class="directory cell">' . $f . '</td>' . $b . '</tr>'; 00266 } 00267 $row = ($row + 1) % 2; 00268 // show errors if they exist 00269 if (isset($dbdir->xml_file)) { 00270 if ($structure =& $dbdir->xml_file->getStructure()) { 00271 if ($errors = $structure->getAllErrors()) { 00272 if ($hithis) { 00273 $o .= '<tr class="highlight"><td class="error cell" colspan="10">' . implode (', ', $errors) . '</td></tr>'; 00274 } else { 00275 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="10">' . implode (', ', $errors) . '</td></tr>'; 00276 } 00277 } 00278 } 00279 } 00280 // TODO: Drop this check in Moodle 2.1 00281 // Intercept loaded structure here and look for ENUM fields 00282 if (isset($dbdir->xml_file)) { 00283 if ($structure =& $dbdir->xml_file->getStructure()) { 00284 if ($tables = $structure->getTables()) { 00285 foreach ($tables as $table) { 00286 if ($fields = $table->getFields()) { 00287 foreach ($fields as $field) { 00288 if (!empty($field->hasenums)) { 00289 if ($hithis) { 00290 $o .= '<tr class="highlight"><td class="error cell" colspan="10">'; 00291 } else { 00292 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="10">'; 00293 } 00294 $o .= 'Table ' . $table->getName() . ', field ' . $field->getName() . ' has ENUM info'; 00295 if (!empty($field->hasenumsenabled)) { 00296 $o .= ' that seems to be active (true). ENUMs support has been dropped in Moodle 2.0, ' . 00297 ' the XMLDB Editor will delete any ENUM reference next time you save this file' . 00298 ' and you MUST provide one upgrade block in your code to drop them from DB. See' . 00299 ' <a href="http://docs.moodle.org/dev/DB_layer_2.0_migration_docs#The_changes">' . 00300 ' Moodle Docs</a> for more info and examples.'; 00301 } else { 00302 $o .= ' that seem to be inactive (false). ENUMs support has been dropped in Moodle 2.0,' . 00303 ' the XMLDB Editor will, simply, delete any ENUM reference next time you save this file.' . 00304 ' No further action is necessary.'; 00305 } 00306 $o .= '</td></tr>'; 00307 } 00308 } 00309 } 00310 } 00311 } 00312 } 00313 } 00314 // If there are changes pending to be saved, but the file cannot be written... inform here 00315 if ($dbdir->path_exists && 00316 file_exists($key . '/install.xml') && 00317 !empty($dbdir->xml_loaded) && 00318 !empty($dbdir->xml_changed) && 00319 (!is_writeable($key . '/install.xml') || !is_writeable($key))) { 00320 00321 if ($hithis) { 00322 $o .= '<tr class="highlight"><td class="error cell" colspan="10">'; 00323 } else { 00324 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="10">'; 00325 } 00326 $o .= $this->str['pendingchangescannotbesavedreload']; 00327 $o .= '</td></tr>'; 00328 } 00329 } 00330 $o .= '</table>'; 00331 00332 // Set the output 00333 $this->output = $o; 00334 } 00335 00336 // Finally, return result 00337 return $result; 00338 } 00339 } 00340