[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * @package tool_xmldb 19 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 */ 22 23 /** 24 * This class will show all the actions available under the XMLDB editor interface 25 * 26 * From here, files can be created, edited, saved and deleted, plus some 27 * extra utilities like displaying docs, xml info and performing various consistency tests 28 * 29 * @package tool_xmldb 30 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class main_view extends XMLDBAction { 34 35 /** 36 * Init method, every subclass will have its own 37 */ 38 function init() { 39 parent::init(); 40 41 // Set own custom attributes 42 $this->sesskey_protected = false; // This action doesn't need sesskey protection 43 44 // Get needed strings 45 $this->loadStrings(array( 46 'load' => 'tool_xmldb', 47 'create' => 'tool_xmldb', 48 'edit' => 'tool_xmldb', 49 'save' => 'tool_xmldb', 50 'revert' => 'tool_xmldb', 51 'unload' => 'tool_xmldb', 52 'delete' => 'tool_xmldb', 53 'reservedwords' => 'tool_xmldb', 54 'gotolastused' => 'tool_xmldb', 55 'checkindexes' => 'tool_xmldb', 56 'checkdefaults' => 'tool_xmldb', 57 'checkforeignkeys' => 'tool_xmldb', 58 'checkbigints' => 'tool_xmldb', 59 'checkoraclesemantics' => 'tool_xmldb', 60 'doc' => 'tool_xmldb', 61 'filemodifiedoutfromeditor' => 'tool_xmldb', 62 'viewxml' => 'tool_xmldb', 63 'pendingchangescannotbesavedreload' => 'tool_xmldb' 64 )); 65 } 66 67 /** 68 * Invoke method, every class will have its own 69 * returns true/false on completion, setting both 70 * errormsg and output as necessary 71 */ 72 function invoke() { 73 parent::invoke(); 74 75 $result = true; 76 77 // Set own core attributes 78 $this->does_generate = ACTION_GENERATE_HTML; 79 80 // These are always here 81 global $CFG, $XMLDB, $SESSION, $DB; 82 83 // Get lastused 84 $o = ''; 85 if (isset($SESSION->lastused)) { 86 if ($lastused = $SESSION->lastused) { 87 // Print link 88 $o .= '<p class="centerpara"><a href="#lastused">' . $this->str['gotolastused'] . '</a></p>'; 89 } 90 } else { 91 $lastused = NULL; 92 } 93 94 // Calculate the buttons 95 $b = '<p class="centerpara buttons">'; 96 // The reserved_words button 97 $b .= ' <a href="index.php?action=view_reserved_words">[' . $this->str['reservedwords'] . ']</a>'; 98 // The docs button 99 $b .= ' <a href="index.php?action=generate_all_documentation">[' . $this->str['doc'] . ']</a>'; 100 // The check indexes button 101 $b .= ' <a href="index.php?action=check_indexes&sesskey=' . sesskey() . '">[' . $this->str['checkindexes'] . ']</a>'; 102 // The check defaults button 103 $b .= ' <a href="index.php?action=check_defaults&sesskey=' . sesskey() . '">[' . $this->str['checkdefaults'] . ']</a>'; 104 // The check bigints button (only for MySQL and PostgreSQL) MDL-11038a 105 if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') { 106 $b .= ' <a href="index.php?action=check_bigints&sesskey=' . sesskey() . '">[' . $this->str['checkbigints'] . ']</a>'; 107 } 108 // The check semantics button (only for Oracle) MDL-29416 109 if ($DB->get_dbfamily() == 'oracle') { 110 $b .= ' <a href="index.php?action=check_oracle_semantics&sesskey=' . sesskey() . '">[' . $this->str['checkoraclesemantics'] . ']</a>'; 111 } 112 $b .= ' <a href="index.php?action=check_foreign_keys&sesskey=' . sesskey() . '">[' . $this->str['checkforeignkeys'] . ']</a>'; 113 $b .= '</p>'; 114 // Send buttons to output 115 $o .= $b; 116 117 // Do the job 118 119 // Get the list of DB directories 120 $result = $this->launch('get_db_directories'); 121 // Display list of DB directories if everything is ok 122 if ($result && !empty($XMLDB->dbdirs)) { 123 $o .= '<table id="listdirectories" border="0" cellpadding="5" cellspacing="1" class="admintable generaltable">'; 124 $row = 0; 125 foreach ($XMLDB->dbdirs as $key => $dbdir) { 126 // Detect if this is the lastused dir 127 $hithis = false; 128 if (str_replace($CFG->dirroot, '', $key) == $lastused) { 129 $hithis = true; 130 } 131 $elementtext = str_replace($CFG->dirroot . '/', '', $key); 132 // Calculate the dbdir has_changed field if needed 133 if (!isset($dbdir->has_changed) && isset($dbdir->xml_loaded)) { 134 $dbdir->xml_changed = false; 135 if (isset($XMLDB->editeddirs[$key])) { 136 $editeddir = $XMLDB->editeddirs[$key]; 137 if (isset($editeddir->xml_file)) { 138 $structure = $editeddir->xml_file->getStructure(); 139 if ($structure->hasChanged()) { 140 $dbdir->xml_changed = true; 141 $editeddir->xml_changed = true; 142 } 143 } 144 } 145 } 146 // The file name (link to edit if the file is loaded) 147 if ($dbdir->path_exists && 148 file_exists($key . '/install.xml') && 149 is_readable($key . '/install.xml') && 150 is_readable($key) && 151 !empty($dbdir->xml_loaded)) { 152 $f = '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">' . $elementtext . '</a>'; 153 } else { 154 $f = $elementtext; 155 } 156 // Calculate the buttons 157 $b = ' <td class="button cell">'; 158 // The create button 159 if ($dbdir->path_exists && 160 !file_exists($key . '/install.xml') && 161 is_writeable($key)) { 162 $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>'; 163 } else { 164 $b .= '[' . $this->str['create'] . ']'; 165 } 166 $b .= '</td><td class="button cell">'; 167 // The load button 168 if ($dbdir->path_exists && 169 file_exists($key . '/install.xml') && 170 is_readable($key . '/install.xml') && 171 empty($dbdir->xml_loaded)) { 172 $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>'; 173 } else { 174 $b .= '[' . $this->str['load'] . ']'; 175 } 176 $b .= '</td><td class="button cell">'; 177 // The edit button 178 if ($dbdir->path_exists && 179 file_exists($key . '/install.xml') && 180 is_readable($key . '/install.xml') && 181 is_readable($key) && 182 !empty($dbdir->xml_loaded)) { 183 $b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['edit'] . ']</a>'; 184 } else { 185 $b .= '[' . $this->str['edit'] . ']'; 186 } 187 $b .= '</td><td class="button cell">'; 188 // The save button 189 if ($dbdir->path_exists && 190 file_exists($key . '/install.xml') && 191 is_writeable($key . '/install.xml') && 192 is_writeable($key) && 193 !empty($dbdir->xml_loaded) && 194 !empty($dbdir->xml_changed)) { 195 $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>'; 196 // Check if the file has been manually edited while being modified in the editor 197 if ($dbdir->filemtime != filemtime($key . '/install.xml')) { 198 // File manually modified. Add to action error, will be displayed inline. 199 $this->errormsg = $this->str['filemodifiedoutfromeditor']; 200 } 201 } else { 202 $b .= '[' . $this->str['save'] . ']'; 203 } 204 $b .= '</td><td class="button cell">'; 205 // The document button 206 if ($dbdir->path_exists && 207 file_exists($key . '/install.xml') && 208 is_readable($key . '/install.xml') && 209 is_readable($key)) { 210 $b .= '<a href="index.php?action=generate_documentation&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['doc'] . ']</a>'; 211 } else { 212 $b .= '[' . $this->str['doc'] . ']'; 213 } 214 $b .= '</td><td class="button cell">'; 215 // The view xml button 216 if ($dbdir->path_exists && 217 file_exists($key . '/install.xml') && 218 is_readable($key . '/install.xml')) { 219 $b .= '<a href="index.php?action=view_xml&file=' . urlencode(str_replace($CFG->dirroot, '', $key) . '/install.xml') . '">[' . $this->str['viewxml'] . ']</a>'; 220 } else { 221 $b .= '[' . $this->str['viewxml'] . ']'; 222 } 223 $b .= '</td><td class="button cell">'; 224 // The revert button 225 if ($dbdir->path_exists && 226 file_exists($key . '/install.xml') && 227 is_readable($key . '/install.xml') && 228 is_writeable($key) && 229 !empty($dbdir->xml_loaded) && 230 !empty($dbdir->xml_changed)) { 231 $b .= '<a href="index.php?action=revert_changes&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['revert'] . ']</a>'; 232 } else { 233 $b .= '[' . $this->str['revert'] . ']'; 234 } 235 $b .= '</td><td class="button cell">'; 236 // The unload button 237 if ($dbdir->path_exists && 238 file_exists($key . '/install.xml') && 239 is_readable($key . '/install.xml') && 240 !empty($dbdir->xml_loaded) && 241 empty($dbdir->xml_changed)) { 242 $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>'; 243 } else { 244 $b .= '[' . $this->str['unload'] . ']'; 245 } 246 $b .= '</td><td class="button cell">'; 247 // The delete button 248 if ($dbdir->path_exists && 249 file_exists($key . '/install.xml') && 250 is_readable($key . '/install.xml') && 251 is_writeable($key) && 252 empty($dbdir->xml_loaded)) { 253 $b .= '<a href="index.php?action=delete_xml_file&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['delete'] . ']</a>'; 254 } else { 255 $b .= '[' . $this->str['delete'] . ']'; 256 } 257 $b .= '</td>'; 258 // include the higlight 259 if ($hithis) { 260 $o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $f . '</td>' . $b . '</tr>'; 261 } else { 262 $o .= '<tr class="r' . $row . '"><td class="directory cell">' . $f . '</td>' . $b . '</tr>'; 263 } 264 $row = ($row + 1) % 2; 265 // show errors if they exist 266 if (isset($dbdir->xml_file)) { 267 if ($structure = $dbdir->xml_file->getStructure()) { 268 $errors = !empty($this->errormsg) ? array($this->errormsg) : array(); 269 $structureerrors = $structure->getAllErrors(); 270 if ($structureerrors) { 271 $errors = array_merge($errors, $structureerrors); 272 } 273 if (!empty($errors)) { 274 if ($hithis) { 275 $o .= '<tr class="highlight"><td class="error cell" colspan="10">' . implode (', ', $errors) . '</td></tr>'; 276 } else { 277 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="10">' . implode (', ', $errors) . '</td></tr>'; 278 } 279 } 280 } 281 } 282 // If there are changes pending to be saved, but the file cannot be written... inform here 283 if ($dbdir->path_exists && 284 file_exists($key . '/install.xml') && 285 !empty($dbdir->xml_loaded) && 286 !empty($dbdir->xml_changed) && 287 (!is_writeable($key . '/install.xml') || !is_writeable($key))) { 288 289 if ($hithis) { 290 $o .= '<tr class="highlight"><td class="error cell" colspan="10">'; 291 } else { 292 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="10">'; 293 } 294 $o .= $this->str['pendingchangescannotbesavedreload']; 295 $o .= '</td></tr>'; 296 } 297 } 298 $o .= '</table>'; 299 300 // Set the output 301 $this->output = $o; 302 } 303 304 // Finally, return result 305 return $result; 306 } 307 } 308
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |