. /** * @package tool_xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * This class will show all the actions available under the XMLDB editor interface * * From here, files can be created, edited, saved and deleted, plus some * extra utilities like displaying docs, xml info and performing various consistency tests * * @package tool_xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class main_view extends XMLDBAction { /** * Init method, every subclass will have its own */ function init() { parent::init(); // Set own custom attributes $this->sesskey_protected = false; // This action doesn't need sesskey protection // Get needed strings $this->loadStrings(array( 'load' => 'tool_xmldb', 'create' => 'tool_xmldb', 'edit' => 'tool_xmldb', 'save' => 'tool_xmldb', 'revert' => 'tool_xmldb', 'unload' => 'tool_xmldb', 'delete' => 'tool_xmldb', 'reservedwords' => 'tool_xmldb', 'gotolastused' => 'tool_xmldb', 'checkindexes' => 'tool_xmldb', 'checkdefaults' => 'tool_xmldb', 'checkforeignkeys' => 'tool_xmldb', 'checkbigints' => 'tool_xmldb', 'checkoraclesemantics' => 'tool_xmldb', 'doc' => 'tool_xmldb', 'filemodifiedoutfromeditor' => 'tool_xmldb', 'viewxml' => 'tool_xmldb', 'pendingchangescannotbesavedreload' => 'tool_xmldb' )); } /** * Invoke method, every class will have its own * returns true/false on completion, setting both * errormsg and output as necessary */ function invoke() { parent::invoke(); $result = true; // Set own core attributes $this->does_generate = ACTION_GENERATE_HTML; // These are always here global $CFG, $XMLDB, $SESSION, $DB; // Get lastused $o = ''; if (isset($SESSION->lastused)) { if ($lastused = $SESSION->lastused) { // Print link $o .= '

' . $this->str['gotolastused'] . '

'; } } else { $lastused = NULL; } // Calculate the buttons $b = '

'; // The reserved_words button $b .= ' [' . $this->str['reservedwords'] . ']'; // The docs button $b .= ' [' . $this->str['doc'] . ']'; // The check indexes button $b .= ' [' . $this->str['checkindexes'] . ']'; // The check defaults button $b .= ' [' . $this->str['checkdefaults'] . ']'; // The check bigints button (only for MySQL and PostgreSQL) MDL-11038a if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') { $b .= ' [' . $this->str['checkbigints'] . ']'; } // The check semantics button (only for Oracle) MDL-29416 if ($DB->get_dbfamily() == 'oracle') { $b .= ' [' . $this->str['checkoraclesemantics'] . ']'; } $b .= ' [' . $this->str['checkforeignkeys'] . ']'; $b .= '

'; // Send buttons to output $o .= $b; // Do the job // Get the list of DB directories $result = $this->launch('get_db_directories'); // Display list of DB directories if everything is ok if ($result && !empty($XMLDB->dbdirs)) { $o .= ''; $row = 0; foreach ($XMLDB->dbdirs as $key => $dbdir) { // Detect if this is the lastused dir $hithis = false; if (str_replace($CFG->dirroot, '', $key) == $lastused) { $hithis = true; } $elementtext = str_replace($CFG->dirroot . '/', '', $key); // Calculate the dbdir has_changed field if needed if (!isset($dbdir->has_changed) && isset($dbdir->xml_loaded)) { $dbdir->xml_changed = false; if (isset($XMLDB->editeddirs[$key])) { $editeddir = $XMLDB->editeddirs[$key]; if (isset($editeddir->xml_file)) { $structure = $editeddir->xml_file->getStructure(); if ($structure->hasChanged()) { $dbdir->xml_changed = true; $editeddir->xml_changed = true; } } } } // The file name (link to edit if the file is loaded) if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_readable($key) && !empty($dbdir->xml_loaded)) { $f = '' . $elementtext . ''; } else { $f = $elementtext; } // Calculate the buttons $b = ' '; // include the higlight if ($hithis) { $o .= '' . $b . ''; } else { $o .= '' . $b . ''; } $row = ($row + 1) % 2; // show errors if they exist if (isset($dbdir->xml_file)) { if ($structure = $dbdir->xml_file->getStructure()) { $errors = !empty($this->errormsg) ? array($this->errormsg) : array(); $structureerrors = $structure->getAllErrors(); if ($structureerrors) { $errors = array_merge($errors, $structureerrors); } if (!empty($errors)) { if ($hithis) { $o .= ''; } else { $o .= ''; } } } } // If there are changes pending to be saved, but the file cannot be written... inform here if ($dbdir->path_exists && file_exists($key . '/install.xml') && !empty($dbdir->xml_loaded) && !empty($dbdir->xml_changed) && (!is_writeable($key . '/install.xml') || !is_writeable($key))) { if ($hithis) { $o .= ''; } } $o .= '
'; // The create button if ($dbdir->path_exists && !file_exists($key . '/install.xml') && is_writeable($key)) { $b .= '[' . $this->str['create'] . ']'; } else { $b .= '[' . $this->str['create'] . ']'; } $b .= ''; // The load button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && empty($dbdir->xml_loaded)) { $b .= '[' . $this->str['load'] . ']'; } else { $b .= '[' . $this->str['load'] . ']'; } $b .= ''; // The edit button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_readable($key) && !empty($dbdir->xml_loaded)) { $b .= '[' . $this->str['edit'] . ']'; } else { $b .= '[' . $this->str['edit'] . ']'; } $b .= ''; // The save button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_writeable($key . '/install.xml') && is_writeable($key) && !empty($dbdir->xml_loaded) && !empty($dbdir->xml_changed)) { $b .= '[' . $this->str['save'] . ']'; // Check if the file has been manually edited while being modified in the editor if ($dbdir->filemtime != filemtime($key . '/install.xml')) { // File manually modified. Add to action error, will be displayed inline. $this->errormsg = $this->str['filemodifiedoutfromeditor']; } } else { $b .= '[' . $this->str['save'] . ']'; } $b .= ''; // The document button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_readable($key)) { $b .= '[' . $this->str['doc'] . ']'; } else { $b .= '[' . $this->str['doc'] . ']'; } $b .= ''; // The view xml button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml')) { $b .= '[' . $this->str['viewxml'] . ']'; } else { $b .= '[' . $this->str['viewxml'] . ']'; } $b .= ''; // The revert button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_writeable($key) && !empty($dbdir->xml_loaded) && !empty($dbdir->xml_changed)) { $b .= '[' . $this->str['revert'] . ']'; } else { $b .= '[' . $this->str['revert'] . ']'; } $b .= ''; // The unload button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && !empty($dbdir->xml_loaded) && empty($dbdir->xml_changed)) { $b .= '[' . $this->str['unload'] . ']'; } else { $b .= '[' . $this->str['unload'] . ']'; } $b .= ''; // The delete button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_writeable($key) && empty($dbdir->xml_loaded)) { $b .= '[' . $this->str['delete'] . ']'; } else { $b .= '[' . $this->str['delete'] . ']'; } $b .= '
' . $f . '
' . $f . '
' . implode (', ', $errors) . '
' . implode (', ', $errors) . '
'; } else { $o .= '
'; } $o .= $this->str['pendingchangescannotbesavedreload']; $o .= '
'; // Set the output $this->output = $o; } // Finally, return result return $result; } }