/**
* 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_XML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the file parameter
$file = required_param('file', PARAM_PATH);
$file = $CFG->dirroot . $file;
/// File must be under $CFG->wwwroot and
/// under one db directory (simple protection)
if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot && substr(dirname($file), -2, 2) == 'db') {
/// Everything is ok. Load the file to memory
$this->output = file_get_contents($file);
} else {
/// Switch to HTML and error
$this->does_generate = ACTION_GENERATE_HTML;
$this->errormsg = 'File not viewable (' . $file . ')';
$result = false;
}
/// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
// These are always here
global $CFG, $XMLDB;
// Do the job, setting result as needed
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
// If the changeme table exists, just get it and continue
$changeme_exists = false;
if ($tables =& $structure->getTables()) {
if ($table =& $structure->getTable('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
// Lets create the table
$field = new xmldb_field('id');
$field->setType(XMLDB_TYPE_INTEGER);
$field->setLength(10);
$field->setNotNull(true);
$field->setUnsigned(true);
$field->setSequence(true);
$field->setLoaded(true);
$field->setChanged(true);
$key = new xmldb_key('primary');
$key->setType(XMLDB_KEY_PRIMARY);
$key->setFields(array('id'));
$key->setLoaded(true);
$key->setChanged(true);
$table = new xmldb_table('changeme');
$table->setComment('Default comment for the table, please edit me');
$table->addField($field);
$table->addKey($key);
// Finally, add the whole retrofitted table to the structure
// in the place specified
$structure->addTable($table);
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting $result as needed
/// Lets go to add all the db directories available inside Moodle
/// Create the array if it doesn't exists
if (!isset($XMLDB->dbdirs)) {
$XMLDB->dbdirs = array();
}
/// get list of all dirs and create objects with status
$db_direcotries = get_db_directories();
foreach ($db_direcotries as $path) {
$dbdir = new stdClass();
$dbdir->path = $path;
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
}
$XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path);
//Update status
}
/// Sort by key
ksort($XMLDB->dbdirs);
/// Return ok if arrived here
return true;
}
/**
* 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_XML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the file parameter
$select = required_param('select', PARAM_ALPHA);
//original/edited
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dir
if ($select == 'original') {
if (!empty($XMLDB->dbdirs)) {
$base =& $XMLDB->dbdirs[$dirpath];
}
} else {
if ($select == 'edited') {
if (!empty($XMLDB->editeddirs)) {
$base =& $XMLDB->editeddirs[$dirpath];
}
} else {
$this->errormsg = 'Cannot access to ' . $select . ' info';
$result = false;
}
}
if ($base) {
/// Only if the directory exists and it has been loaded
if (!$base->path_exists || !$base->xml_loaded) {
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
return false;
}
} else {
$this->errormsg = 'Problem handling ' . $select . ' files';
return false;
}
/// Get the structure
if ($result) {
if (!($structure =& $base->xml_file->getStructure())) {
$this->errormsg = 'Error retrieving ' . $select . ' structure';
$result = false;
}
}
if ($result) {
/// Everything is ok. Generate the XML output
$this->output = $structure->xmlOutput();
} else {
/// Switch to HTML and error
$this->does_generate = ACTION_GENERATE_HTML;
}
/// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting $result as needed
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dir
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
if ($dbdir) {
/// Set some defaults
$dbdir->xml_exists = false;
$dbdir->xml_writeable = false;
$dbdir->xml_loaded = false;
///Only if the directory exists
if (!$dbdir->path_exists) {
return false;
}
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
///Set the XML DTD and schema
$xmldb_file->setDTD($CFG->dirroot . '/lib/xmldb/xmldb.dtd');
$xmldb_file->setSchema($CFG->dirroot . '/lib/xmldb/xmldb.xsd');
/// Set dbdir as necessary
if ($xmldb_file->fileExists()) {
$dbdir->xml_exists = true;
}
if ($xmldb_file->fileWriteable()) {
$dbdir->xml_writeable = true;
}
/// Load the XML contents to structure
$loaded = $xmldb_file->loadXMLStructure();
if ($loaded && $xmldb_file->isLoaded()) {
$dbdir->xml_loaded = true;
$dbdir->filemtime = filemtime($dbdir->path . '/install.xml');
}
$dbdir->xml_file = $xmldb_file;
} else {
$this->errormsg = 'Wrong directory (' . $dirpath . ')';
$result = false;
}
} else {
$this->errormsg = 'XMLDB structure not found';
$result = false;
}
/// Launch postaction if exists
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
return $result;
}
/**
* 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_NONE;
// These are always here
global $CFG, $XMLDB;
// Do the job, setting result as needed
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
$unload = optional_param('unload', true, PARAM_BOOL);
// Get the edited dir
if (!empty($XMLDB->editeddirs)) {
if (isset($XMLDB->editeddirs[$dirpath])) {
$editeddir = $XMLDB->editeddirs[$dirpath];
}
}
// Copy the edited dir over the original one
if (!empty($XMLDB->dbdirs)) {
if (isset($XMLDB->dbdirs[$dirpath])) {
$XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir));
$dbdir = $XMLDB->dbdirs[$dirpath];
}
}
// Check for perms
if (!is_writeable($dirpath . '/install.xml')) {
$this->errormsg = $this->str['filenotwriteable'] . '(' . $dirpath . '/install.xml)';
return false;
}
// Save the original dir
$result = $dbdir->xml_file->saveXMLFile();
if ($result) {
// Delete the edited dir
unset($XMLDB->editeddirs[$dirpath]);
// Unload de originaldir
unset($XMLDB->dbdirs[$dirpath]->xml_file);
unset($XMLDB->dbdirs[$dirpath]->xml_loaded);
unset($XMLDB->dbdirs[$dirpath]->xml_changed);
unset($XMLDB->dbdirs[$dirpath]->xml_exists);
unset($XMLDB->dbdirs[$dirpath]->xml_writeable);
} else {
$this->errormsg = 'Error saving XML file (' . $dirpath . ')';
return false;
}
// If unload has been disabled, simulate it by reloading the file now
if (!$unload) {
return $this->launch('load_xml_file');
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
$statementparam = required_param('statement', PARAM_CLEAN);
$basesentenceparam = optional_param('basesentence', NULL, PARAM_CLEAN);
$statement =& $structure->getStatement($statementparam);
$sentences =& $statement->getSentences();
$sentence = NULL;
/// If some sentence has been specified, create the new one
/// based on it
if (!empty($basesentenceparam)) {
$sentence = $sentences[$basesentenceparam];
}
/// Else, try to create the new one based in the last
if (empty($sentence) && !empty($sentences)) {
$sentence = end($sentences);
}
/// Else, create one sentence by hand
if (empty($sentence)) {
$sentence = "(list, of, fields) VALUES ('list', 'of', 'values')";
}
/// Add the sentence to the statement
$statement->addSentence($sentence);
/// We have one new sentence, so the statement and the structure has changed
$statement->setChanged(true);
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
$tableparam = required_param('table', PARAM_CLEAN);
$table =& $structure->getTable($tableparam);
/// If the changeme field exists, just get it and continue
$changeme_exists = false;
if ($fields =& $table->getFields()) {
if ($field =& $table->getField('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
/// Lets create the field
$field = new XMLDBField('changeme');
$field->setComment('Default comment for the field, please edit me');
$table->addField($field);
/// We have one new field, so the structure has changed
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
// These are always here
global $CFG, $XMLDB;
// Do the job, setting result as needed
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir = $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir = $XMLDB->editeddirs[$dirpath];
$structure = $editeddir->xml_file->getStructure();
}
$tableparam = required_param('table', PARAM_CLEAN);
$table = $structure->getTable($tableparam);
// If the changeme index exists, just get it and continue
$changeme_exists = false;
if ($indexes = $table->getIndexes()) {
if ($index = $table->getIndex('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
// Lets create the Index
$index = new xmldb_index('changeme');
$table->addIndex($index);
// We have one new key, so the structure has changed
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get parameters
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
$statementparam = strtolower(required_param('statement', PARAM_CLEAN));
$name = trim(strtolower(required_param('name', PARAM_CLEAN)));
$comment = required_param('comment', PARAM_CLEAN);
$comment = stripslashes_safe($comment);
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
$statement =& $structure->getStatement($statementparam);
$errors = array();
/// To store all the errors found
/// If there is one name change, do it, changing the prev and next
/// atributes of the adjacent tables
if ($statementparam != $name) {
$statement->setName($name);
if ($statement->getPrevious()) {
$prev =& $structure->getStatement($statement->getPrevious());
$prev->setNext($name);
$prev->setChanged(true);
}
if ($statement->getNext()) {
$next =& $structure->getStatement($statement->getNext());
$next->setPrevious($name);
$next->setChanged(true);
}
}
/// Set comment
$statement->setComment($comment);
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
/**
* 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;
// Do the job, setting $result as needed
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
$path = $dirpath . '/install.xml';
if (!file_exists($path) || !is_readable($path)) {
return false;
}
// Add link back to home
$b = ' <p class="centerpara buttons">';
$b .= ' <a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>';
$b .= '</p>';
$this->output = $b;
$c = ' <p class="centerpara">';
$c .= $this->str['documentationintro'];
$c .= '</p>';
$this->output .= $c;
if (class_exists('XSLTProcessor')) {
// Transform XML file and display it
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load(__DIR__ . '/xmldb.xsl');
$xsl->importStyleSheet($doc);
$doc->load($path);
$this->output .= $xsl->transformToXML($doc);
$this->output .= $b;
} else {
$this->output .= get_string('extensionrequired', 'tool_xmldb', 'xsl');
}
// Launch postaction if exists (leave this unmodified)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
return $result;
}
/**
* 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_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting $result as needed
/// Iterate over $XMLDB->dbdirs, loading their XML data to memory
if ($XMLDB->dbdirs) {
$dbdirs =& $XMLDB->dbdirs;
foreach ($dbdirs as $dbdir) {
/// Set some defaults
$dbdir->xml_exists = false;
$dbdir->xml_writeable = false;
$dbdir->xml_loaded = false;
///Only if the directory exists
if (!$dbdir->path_exists) {
continue;
}
$xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
/// Set dbdir as necessary
if ($xmldb_file->fileExists()) {
$dbdir->xml_exists = true;
}
if ($xmldb_file->fileWriteable()) {
$dbdir->xml_writeable = true;
}
/// Load the XML contents to structure
$loaded = $xmldb_file->loadXMLStructure();
if ($loaded && $xmldb_file->isLoaded()) {
$dbdir->xml_loaded = true;
}
$dbdir->xml_file = $xmldb_file;
}
}
return $result;
}
请发表评论