MDL-29611 xmldb editor - comments and whitespace cleanup
This commit is contained in:
@@ -126,14 +126,14 @@ class XMLDBAction {
|
||||
* array parameter
|
||||
*/
|
||||
function loadStrings($strings) {
|
||||
/// Load some commonly used strings
|
||||
// Load some commonly used strings
|
||||
if (get_string_manager()->string_exists($this->title, 'tool_xmldb')) {
|
||||
$this->str['title'] = get_string($this->title, 'tool_xmldb');
|
||||
} else {
|
||||
$this->str['title'] = $this->title;
|
||||
}
|
||||
|
||||
/// Now process the $strings array loading it in the $str atribute
|
||||
// Now process the $strings array loading it in the $str atribute
|
||||
if ($strings) {
|
||||
foreach ($strings as $key => $module) {
|
||||
$this->str[$key] = get_string($key, $module);
|
||||
@@ -149,19 +149,19 @@ class XMLDBAction {
|
||||
|
||||
global $SESSION;
|
||||
|
||||
/// Sesskey protection
|
||||
// Sesskey protection
|
||||
if ($this->sesskey_protected) {
|
||||
require_sesskey();
|
||||
}
|
||||
|
||||
/// If we are used any dir, save it in the lastused session object
|
||||
/// Some actions can use it to perform positioning
|
||||
// If we are used any dir, save it in the lastused session object
|
||||
// Some actions can use it to perform positioning
|
||||
if ($lastused = optional_param ('dir', NULL, PARAM_PATH)) {
|
||||
$SESSION->lastused = $lastused;
|
||||
}
|
||||
|
||||
$this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT);
|
||||
/// Avoid being recursive
|
||||
// Avoid being recursive
|
||||
if ($this->title == $this->postaction) {
|
||||
$this->postaction = NULL;
|
||||
}
|
||||
@@ -174,12 +174,12 @@ class XMLDBAction {
|
||||
|
||||
global $CFG;
|
||||
|
||||
/// Get the action path and invoke it
|
||||
// Get the action path and invoke it
|
||||
$actionsroot = "$CFG->dirroot/$CFG->admin/tool/xmldb/actions";
|
||||
$actionclass = $action . '.class.php';
|
||||
$actionpath = "$actionsroot/$action/$actionclass";
|
||||
|
||||
/// Load and invoke the proper action
|
||||
// Load and invoke the proper action
|
||||
$result = false;
|
||||
if (file_exists($actionpath) && is_readable($actionpath)) {
|
||||
require_once($actionpath);
|
||||
@@ -218,16 +218,16 @@ class XMLDBAction {
|
||||
|
||||
$path = $structure->getPath();
|
||||
|
||||
/// Trim "db" from path
|
||||
// Trim "db" from path
|
||||
$path = dirname($path);
|
||||
|
||||
/// Get pluginname, plugindir and plugintype
|
||||
// Get pluginname, plugindir and plugintype
|
||||
$pluginname = basename($path);
|
||||
if ($path == 'lib') { /// exception for lib (not proper plugin)
|
||||
if ($path == 'lib') { // exception for lib (not proper plugin)
|
||||
$plugindir = 'lib';
|
||||
$plugintype = 'lib';
|
||||
} else { /// rest of plugins
|
||||
//TODO: this is not nice and may fail, plugintype should be passed around somehow instead
|
||||
} else { // rest of plugins
|
||||
// TODO: this is not nice and may fail, plugintype should be passed around somehow instead
|
||||
$plugintypes = get_plugin_types(false);
|
||||
$plugindir = dirname($path);
|
||||
$plugindir = str_replace('\\', '/', $plugindir);
|
||||
@@ -237,22 +237,22 @@ class XMLDBAction {
|
||||
$result = '';
|
||||
|
||||
switch ($plugintype ) {
|
||||
case 'lib': /// has own savepoint function
|
||||
case 'lib': // has own savepoint function
|
||||
$result = XMLDB_LINEFEED .
|
||||
' // Main savepoint reached' . XMLDB_LINEFEED .
|
||||
' upgrade_main_savepoint(true, XXXXXXXXXX);' . XMLDB_LINEFEED;
|
||||
break;
|
||||
case 'mod': /// has own savepoint function
|
||||
case 'mod': // has own savepoint function
|
||||
$result = XMLDB_LINEFEED .
|
||||
' // ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED .
|
||||
' upgrade_mod_savepoint(true, XXXXXXXXXX, ' . "'$pluginname'" . ');' . XMLDB_LINEFEED;
|
||||
break;
|
||||
case 'block': /// has own savepoint function
|
||||
case 'block': // has own savepoint function
|
||||
$result = XMLDB_LINEFEED .
|
||||
' // ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED .
|
||||
' upgrade_block_savepoint(true, XXXXXXXXXX, ' . "'$pluginname'" . ');' . XMLDB_LINEFEED;
|
||||
break;
|
||||
default: /// rest of plugins
|
||||
default: // rest of plugins
|
||||
$result = XMLDB_LINEFEED .
|
||||
' // ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED .
|
||||
' upgrade_plugin_savepoint(true, XXXXXXXXXX, ' . "'$plugintype'" . ', ' . "'$pluginname'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
@@ -43,11 +43,11 @@ abstract class XMLDBCheckAction extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
$this->introstr => 'tool_xmldb',
|
||||
'ok' => '',
|
||||
@@ -73,24 +73,24 @@ abstract class XMLDBCheckAction extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $DB, $OUTPUT;
|
||||
|
||||
/// And we nedd some ddl suff
|
||||
// And we nedd some ddl suff
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
/// Here we'll acummulate all the wrong fields found
|
||||
// Here we'll acummulate all the wrong fields found
|
||||
$problemsfound = array();
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// Do the job, setting $result as needed
|
||||
|
||||
/// Get the confirmed to decide what to do
|
||||
// Get the confirmed to decide what to do
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -110,59 +110,59 @@ abstract class XMLDBCheckAction extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
$b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
|
||||
/// Iterate over $XMLDB->dbdirs, loading their XML data to memory
|
||||
// Iterate over $XMLDB->dbdirs, loading their XML data to memory
|
||||
if ($XMLDB->dbdirs) {
|
||||
$dbdirs =& $XMLDB->dbdirs;
|
||||
$o='<ul>';
|
||||
foreach ($dbdirs as $dbdir) {
|
||||
/// Only if the directory exists
|
||||
// Only if the directory exists
|
||||
if (!$dbdir->path_exists) {
|
||||
continue;
|
||||
}
|
||||
/// Load the XML file
|
||||
// Load the XML file
|
||||
$xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
|
||||
|
||||
/// Only if the file exists
|
||||
// Only if the file exists
|
||||
if (!$xmldb_file->fileExists()) {
|
||||
continue;
|
||||
}
|
||||
/// Load the XML contents to structure
|
||||
// Load the XML contents to structure
|
||||
$loaded = $xmldb_file->loadXMLStructure();
|
||||
if (!$loaded || !$xmldb_file->isLoaded()) {
|
||||
echo $OUTPUT->notification('Errors found in XMLDB file: '. $dbdir->path . '/install.xml');
|
||||
continue;
|
||||
}
|
||||
/// Arriving here, everything is ok, get the XMLDB structure
|
||||
// Arriving here, everything is ok, get the XMLDB structure
|
||||
$structure = $xmldb_file->getStructure();
|
||||
|
||||
$o.=' <li>' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
|
||||
/// Getting tables
|
||||
// Getting tables
|
||||
if ($xmldb_tables = $structure->getTables()) {
|
||||
$o.=' <ul>';
|
||||
/// Foreach table, process its fields
|
||||
// Foreach table, process its fields
|
||||
foreach ($xmldb_tables as $xmldb_table) {
|
||||
/// Skip table if not exists
|
||||
// Skip table if not exists
|
||||
if (!$dbman->table_exists($xmldb_table)) {
|
||||
continue;
|
||||
}
|
||||
/// Fetch metadata from physical DB. All the columns info.
|
||||
// Fetch metadata from physical DB. All the columns info.
|
||||
if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
|
||||
//// Skip table if no metacolumns is available for it
|
||||
// / Skip table if no metacolumns is available for it
|
||||
continue;
|
||||
}
|
||||
/// Table processing starts here
|
||||
// Table processing starts here
|
||||
$o.=' <li>' . $xmldb_table->getName();
|
||||
/// Do the specific check.
|
||||
// Do the specific check.
|
||||
list($output, $newproblems) = $this->check_table($xmldb_table, $metacolumns);
|
||||
$o.=$output;
|
||||
$problemsfound = array_merge($problemsfound, $newproblems);
|
||||
$o.=' </li>';
|
||||
/// Give the script some more time (resetting to current if exists)
|
||||
// Give the script some more time (resetting to current if exists)
|
||||
if ($currenttl = @ini_get('max_execution_time')) {
|
||||
@ini_set('max_execution_time',$currenttl);
|
||||
}
|
||||
@@ -174,19 +174,19 @@ abstract class XMLDBCheckAction extends XMLDBAction {
|
||||
$o.='</ul>';
|
||||
}
|
||||
|
||||
/// Create a report of the problems found.
|
||||
// Create a report of the problems found.
|
||||
$r = $this->display_results($problemsfound);
|
||||
|
||||
/// Combine the various bits of output.
|
||||
// Combine the various bits of output.
|
||||
$this->output = $b . $r . $o;
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,11 @@ class check_bigints extends XMLDBCheckAction {
|
||||
$this->introstr = 'confirmcheckbigints';
|
||||
parent::init();
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'wrongints' => 'tool_xmldb',
|
||||
'nowrongintsfound' => 'tool_xmldb',
|
||||
@@ -56,7 +56,7 @@ class check_bigints extends XMLDBCheckAction {
|
||||
'mysqlextracheckbigints' => 'tool_xmldb',
|
||||
));
|
||||
|
||||
/// Correct fields must be type bigint for MySQL and int8 for PostgreSQL
|
||||
// Correct fields must be type bigint for MySQL and int8 for PostgreSQL
|
||||
$this->dbfamily = $DB->get_dbfamily();
|
||||
switch ($this->dbfamily) {
|
||||
case 'mysql':
|
||||
@@ -74,26 +74,26 @@ class check_bigints extends XMLDBCheckAction {
|
||||
$o = '';
|
||||
$wrong_fields = array();
|
||||
|
||||
/// Get and process XMLDB fields
|
||||
// Get and process XMLDB fields
|
||||
if ($xmldb_fields = $xmldb_table->getFields()) {
|
||||
$o.=' <ul>';
|
||||
foreach ($xmldb_fields as $xmldb_field) {
|
||||
/// If the field isn't integer(10), skip
|
||||
// If the field isn't integer(10), skip
|
||||
if ($xmldb_field->getType() != XMLDB_TYPE_INTEGER || $xmldb_field->getLength() != 10) {
|
||||
continue;
|
||||
}
|
||||
/// If the metadata for that column doesn't exist, skip
|
||||
// If the metadata for that column doesn't exist, skip
|
||||
if (!isset($metacolumns[$xmldb_field->getName()])) {
|
||||
continue;
|
||||
}
|
||||
/// To variable for better handling
|
||||
// To variable for better handling
|
||||
$metacolumn = $metacolumns[$xmldb_field->getName()];
|
||||
/// Going to check this field in DB
|
||||
// Going to check this field in DB
|
||||
$o.=' <li>' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
|
||||
/// Detect if the physical field is wrong and, under mysql, check for incorrect signed fields too
|
||||
// Detect if the physical field is wrong and, under mysql, check for incorrect signed fields too
|
||||
if ($metacolumn->type != $this->correct_type || ($this->dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) {
|
||||
$o.='<font color="red">' . $this->str['wrong'] . '</font>';
|
||||
/// Add the wrong field to the list
|
||||
// Add the wrong field to the list
|
||||
$obj = new stdClass();
|
||||
$obj->table = $xmldb_table;
|
||||
$obj->field = $xmldb_field;
|
||||
@@ -121,41 +121,41 @@ class check_bigints extends XMLDBCheckAction {
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
|
||||
/// If we have found wrong integers inform about them
|
||||
// If we have found wrong integers inform about them
|
||||
if (count($wrong_fields)) {
|
||||
$r.= ' <p class="centerpara">' . $this->str['yeswrongintsfound'] . '</p>';
|
||||
$r.= ' <ul>';
|
||||
foreach ($wrong_fields as $obj) {
|
||||
$xmldb_table = $obj->table;
|
||||
$xmldb_field = $obj->field;
|
||||
/// MySQL directly supports this
|
||||
// MySQL directly supports this
|
||||
|
||||
// TODO: move this hack to generators!!
|
||||
|
||||
if ($this->dbfamily == 'mysql') {
|
||||
$sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field);
|
||||
/// PostgreSQL (XMLDB implementation) is a bit, er... imperfect.
|
||||
// PostgreSQL (XMLDB implementation) is a bit, er... imperfect.
|
||||
} else if ($this->dbfamily == 'postgres') {
|
||||
$sqlarr = array('ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() .
|
||||
' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;');
|
||||
}
|
||||
$r.= ' <li>' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
|
||||
$this->str['field'] . ': ' . $xmldb_field->getName() . '</li>';
|
||||
/// Add to output if we have sentences
|
||||
// Add to output if we have sentences
|
||||
if ($sqlarr) {
|
||||
$sqlarr = $dbman->generator->getEndedStatements($sqlarr);
|
||||
$s.= '<code>' . str_replace("\n", '<br />', implode('<br />', $sqlarr)). '</code><br />';
|
||||
}
|
||||
}
|
||||
$r.= ' </ul>';
|
||||
/// Add the SQL statements (all together)
|
||||
// Add the SQL statements (all together)
|
||||
$r.= '<hr />' . $s;
|
||||
} else {
|
||||
$r.= ' <p class="centerpara">' . $this->str['nowrongintsfound'] . '</p>';
|
||||
}
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
/// Add the complete log message
|
||||
// Add the complete log message
|
||||
$r.= ' <p class="centerpara">' . $this->str['completelogbelow'] . '</p>';
|
||||
$r.= ' </td></tr>';
|
||||
$r.= '</table>';
|
||||
|
||||
@@ -40,11 +40,11 @@ class check_defaults extends XMLDBCheckAction {
|
||||
$this->introstr = 'confirmcheckdefaults';
|
||||
parent::init();
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'wrongdefaults' => 'tool_xmldb',
|
||||
'nowrongdefaultsfound' => 'tool_xmldb',
|
||||
@@ -58,7 +58,7 @@ class check_defaults extends XMLDBCheckAction {
|
||||
$o = '';
|
||||
$wrong_fields = array();
|
||||
|
||||
/// Get and process XMLDB fields
|
||||
// Get and process XMLDB fields
|
||||
if ($xmldb_fields = $xmldb_table->getFields()) {
|
||||
$o.=' <ul>';
|
||||
foreach ($xmldb_fields as $xmldb_field) {
|
||||
@@ -66,15 +66,15 @@ class check_defaults extends XMLDBCheckAction {
|
||||
// Get the default value for the field
|
||||
$xmldbdefault = $xmldb_field->getDefault();
|
||||
|
||||
/// If the metadata for that column doesn't exist or 'id' field found, skip
|
||||
// If the metadata for that column doesn't exist or 'id' field found, skip
|
||||
if (!isset($metacolumns[$xmldb_field->getName()]) or $xmldb_field->getName() == 'id') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/// To variable for better handling
|
||||
// To variable for better handling
|
||||
$metacolumn = $metacolumns[$xmldb_field->getName()];
|
||||
|
||||
/// Going to check this field in DB
|
||||
// Going to check this field in DB
|
||||
$o.=' <li>' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
|
||||
|
||||
// get the value of the physical default (or blank if there isn't one)
|
||||
@@ -90,7 +90,7 @@ class check_defaults extends XMLDBCheckAction {
|
||||
$info = '('.$this->str['expected']." '$xmldbdefault', ".$this->str['actual'].
|
||||
" '$physicaldefault')";
|
||||
$o.='<font color="red">' . $this->str['wrong'] . " $info</font>";
|
||||
/// Add the wrong field to the list
|
||||
// Add the wrong field to the list
|
||||
$obj = new stdClass();
|
||||
$obj->table = $xmldb_table;
|
||||
$obj->field = $xmldb_field;
|
||||
@@ -120,7 +120,7 @@ class check_defaults extends XMLDBCheckAction {
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
|
||||
/// If we have found wrong defaults inform about them
|
||||
// If we have found wrong defaults inform about them
|
||||
if (count($wrong_fields)) {
|
||||
$r.= ' <p class="centerpara">' . $this->str['yeswrongdefaultsfound'] . '</p>';
|
||||
$r.= ' <ul>';
|
||||
@@ -137,21 +137,21 @@ class check_defaults extends XMLDBCheckAction {
|
||||
$this->str['field'] . ': ' . $xmldb_field->getName() . ', ' .
|
||||
$this->str['expected'] . ' ' . "'$xmldbdefault'" . ' ' .
|
||||
$this->str['actual'] . ' ' . "'$physicaldefault'" . '</li>';
|
||||
/// Add to output if we have sentences
|
||||
// Add to output if we have sentences
|
||||
if ($sqlarr) {
|
||||
$sqlarr = $dbman->generator->getEndedStatements($sqlarr);
|
||||
$s.= '<code>' . str_replace("\n", '<br />', implode('<br />', $sqlarr)) . '</code><br />';
|
||||
}
|
||||
}
|
||||
$r.= ' </ul>';
|
||||
/// Add the SQL statements (all together)
|
||||
// Add the SQL statements (all together)
|
||||
$r.= '<hr />' . $s;
|
||||
} else {
|
||||
$r.= ' <p class="centerpara">' . $this->str['nowrongdefaultsfound'] . '</p>';
|
||||
}
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
/// Add the complete log message
|
||||
// Add the complete log message
|
||||
$r.= ' <p class="centerpara">' . $this->str['completelogbelow'] . '</p>';
|
||||
$r.= ' </td></tr>';
|
||||
$r.= '</table>';
|
||||
|
||||
@@ -44,11 +44,11 @@ class check_foreign_keys extends XMLDBCheckAction {
|
||||
$this->introstr = 'confirmcheckforeignkeys';
|
||||
parent::init();
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'key' => 'tool_xmldb',
|
||||
'violatedforeignkeys' => 'tool_xmldb',
|
||||
@@ -67,17 +67,17 @@ class check_foreign_keys extends XMLDBCheckAction {
|
||||
$o = '';
|
||||
$violatedkeys = array();
|
||||
|
||||
/// Keys
|
||||
// Keys
|
||||
if ($xmldb_keys = $xmldb_table->getKeys()) {
|
||||
$o.=' <ul>';
|
||||
foreach ($xmldb_keys as $xmldb_key) {
|
||||
/// We are only interested in foreign keys.
|
||||
// We are only interested in foreign keys.
|
||||
if (!in_array($xmldb_key->getType(), array(XMLDB_KEY_FOREIGN, XMLDB_KEY_FOREIGN_UNIQUE))) {
|
||||
continue;
|
||||
}
|
||||
$o.=' <li>' . $this->str['key'] . ': ' . $xmldb_key->readableInfo() . ' ';
|
||||
|
||||
/// Work out the SQL to find key violations.
|
||||
// Work out the SQL to find key violations.
|
||||
$keyfields = $xmldb_key->getFields();
|
||||
$reffields = $xmldb_key->getRefFields();
|
||||
$joinconditions = array();
|
||||
@@ -103,13 +103,13 @@ class check_foreign_keys extends XMLDBCheckAction {
|
||||
implode(' AND ', $joinconditions) . ' WHERE ' .
|
||||
implode(' AND ', $nullnessconditions);
|
||||
|
||||
/// Check there are any problems in the database.
|
||||
// Check there are any problems in the database.
|
||||
$violations = $DB->count_records_sql($sql, $params);
|
||||
if ($violations == 0) {
|
||||
$o.='<font color="green">' . $this->str['ok'] . '</font>';
|
||||
} else {
|
||||
$o.='<font color="red">' . $this->str['violations'] . '</font>';
|
||||
/// Add the missing index to the list
|
||||
// Add the missing index to the list
|
||||
$violation = new stdClass;
|
||||
$violation->table = $xmldb_table;
|
||||
$violation->key = $xmldb_key;
|
||||
@@ -139,7 +139,7 @@ class check_foreign_keys extends XMLDBCheckAction {
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
|
||||
/// If we have found wrong integers inform about them
|
||||
// If we have found wrong integers inform about them
|
||||
if (count($violatedkeys)) {
|
||||
$r.= ' <p class="centerpara">' . $this->str['violatedforeignkeysfound'] . '</p>';
|
||||
$r.= ' <ul>';
|
||||
@@ -156,7 +156,7 @@ class check_foreign_keys extends XMLDBCheckAction {
|
||||
}
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
/// Add the complete log message
|
||||
// Add the complete log message
|
||||
$r.= ' <p class="centerpara">' . $this->str['completelogbelow'] . '</p>';
|
||||
$r.= ' </td></tr>';
|
||||
$r.= '</table>';
|
||||
|
||||
@@ -40,11 +40,11 @@ class check_indexes extends XMLDBCheckAction {
|
||||
$this->introstr = 'confirmcheckindexes';
|
||||
parent::init();
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'missing' => 'tool_xmldb',
|
||||
'key' => 'tool_xmldb',
|
||||
@@ -62,20 +62,20 @@ class check_indexes extends XMLDBCheckAction {
|
||||
$o = '';
|
||||
$missing_indexes = array();
|
||||
|
||||
/// Keys
|
||||
// Keys
|
||||
if ($xmldb_keys = $xmldb_table->getKeys()) {
|
||||
$o.=' <ul>';
|
||||
foreach ($xmldb_keys as $xmldb_key) {
|
||||
$o.=' <li>' . $this->str['key'] . ': ' . $xmldb_key->readableInfo() . ' ';
|
||||
/// Primaries are skipped
|
||||
// Primaries are skipped
|
||||
if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
|
||||
$o.='<font color="green">' . $this->str['ok'] . '</font></li>';
|
||||
continue;
|
||||
}
|
||||
/// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
|
||||
/// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
|
||||
// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
|
||||
// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
|
||||
if (!$dbman->generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
|
||||
/// Create the interim index
|
||||
// Create the interim index
|
||||
$xmldb_index = new xmldb_index('anyname');
|
||||
$xmldb_index->setFields($xmldb_key->getFields());
|
||||
switch ($xmldb_key->getType()) {
|
||||
@@ -87,12 +87,12 @@ class check_indexes extends XMLDBCheckAction {
|
||||
$xmldb_index->setUnique(false);
|
||||
break;
|
||||
}
|
||||
/// Check if the index exists in DB
|
||||
// Check if the index exists in DB
|
||||
if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
|
||||
$o.='<font color="green">' . $this->str['ok'] . '</font>';
|
||||
} else {
|
||||
$o.='<font color="red">' . $this->str['missing'] . '</font>';
|
||||
/// Add the missing index to the list
|
||||
// Add the missing index to the list
|
||||
$obj = new stdClass();
|
||||
$obj->table = $xmldb_table;
|
||||
$obj->index = $xmldb_index;
|
||||
@@ -103,17 +103,17 @@ class check_indexes extends XMLDBCheckAction {
|
||||
}
|
||||
$o.=' </ul>';
|
||||
}
|
||||
/// Indexes
|
||||
// Indexes
|
||||
if ($xmldb_indexes = $xmldb_table->getIndexes()) {
|
||||
$o.=' <ul>';
|
||||
foreach ($xmldb_indexes as $xmldb_index) {
|
||||
$o.=' <li>' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' ';
|
||||
/// Check if the index exists in DB
|
||||
// Check if the index exists in DB
|
||||
if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
|
||||
$o.='<font color="green">' . $this->str['ok'] . '</font>';
|
||||
} else {
|
||||
$o.='<font color="red">' . $this->str['missing'] . '</font>';
|
||||
/// Add the missing index to the list
|
||||
// Add the missing index to the list
|
||||
$obj = new stdClass();
|
||||
$obj->table = $xmldb_table;
|
||||
$obj->index = $xmldb_index;
|
||||
@@ -139,7 +139,7 @@ class check_indexes extends XMLDBCheckAction {
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
|
||||
/// If we have found missing indexes inform about them
|
||||
// If we have found missing indexes inform about them
|
||||
if (count($missing_indexes)) {
|
||||
$r.= ' <p class="centerpara">' . $this->str['yesmissingindexesfound'] . '</p>';
|
||||
$r.= ' <ul>';
|
||||
@@ -154,14 +154,14 @@ class check_indexes extends XMLDBCheckAction {
|
||||
|
||||
}
|
||||
$r.= ' </ul>';
|
||||
/// Add the SQL statements (all together)
|
||||
// Add the SQL statements (all together)
|
||||
$r.= '<hr />' . $s;
|
||||
} else {
|
||||
$r.= ' <p class="centerpara">' . $this->str['nomissingindexesfound'] . '</p>';
|
||||
}
|
||||
$r.= ' </td></tr>';
|
||||
$r.= ' <tr><td class="generalboxcontent">';
|
||||
/// Add the complete log message
|
||||
// Add the complete log message
|
||||
$r.= ' <p class="centerpara">' . $this->str['completelogbelow'] . '</p>';
|
||||
$r.= ' </td></tr>';
|
||||
$r.= '</table>';
|
||||
|
||||
@@ -35,15 +35,15 @@ class create_xml_file extends XMLDBAction {
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->can_subaction = ACTION_NONE;
|
||||
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -57,28 +57,28 @@ class create_xml_file extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
$file = $dirpath . '/install.xml';
|
||||
|
||||
/// Some variables
|
||||
// Some variables
|
||||
$xmlpath = dirname(str_replace($CFG->dirroot . '/', '', $file));
|
||||
$xmlversion = userdate(time(), '%Y%m%d', 99, false);
|
||||
$xmlcomment = 'XMLDB file for Moodle ' . dirname($xmlpath);
|
||||
|
||||
$xmltable = strtolower(basename(dirname($xmlpath)));
|
||||
|
||||
/// Initial contents
|
||||
// Initial contents
|
||||
$c = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
|
||||
$c.= ' <XMLDB PATH="' . $xmlpath . '" VERSION="' . $xmlversion .'" COMMENT="' . $xmlcomment .'">' . "\n";
|
||||
$c.= ' <TABLES>' . "\n";
|
||||
@@ -98,12 +98,12 @@ class create_xml_file extends XMLDBAction {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
/// Launch postaction if exists
|
||||
// Launch postaction if exists
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class delete_field extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletefield' => 'tool_xmldb',
|
||||
'yes' => '',
|
||||
@@ -57,15 +57,15 @@ class delete_field extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
@@ -73,7 +73,7 @@ class delete_field extends XMLDBAction {
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -93,14 +93,14 @@ class delete_field extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Move adjacent fields prev and next attributes
|
||||
// Move adjacent fields prev and next attributes
|
||||
$tables =& $structure->getTables();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$fields =& $table->getFields();
|
||||
@@ -113,14 +113,14 @@ class delete_field extends XMLDBAction {
|
||||
$next =& $table->getField($field->getNext());
|
||||
$next->setPrevious($field->getPrevious());
|
||||
}
|
||||
/// Remove the field
|
||||
// Remove the field
|
||||
$table->deleteField($fieldparam);
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
@@ -131,12 +131,12 @@ class delete_field extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class delete_index extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeleteindex' => 'tool_xmldb',
|
||||
'yes' => '',
|
||||
@@ -57,15 +57,15 @@ class delete_index extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
$tableparam = required_param('table', PARAM_PATH);
|
||||
@@ -73,7 +73,7 @@ class delete_index extends XMLDBAction {
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -93,14 +93,14 @@ class delete_index extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Move adjacent indexes prev and next attributes
|
||||
// Move adjacent indexes prev and next attributes
|
||||
$tables =& $structure->getTables();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$indexes =& $table->getIndexes();
|
||||
@@ -113,14 +113,14 @@ class delete_index extends XMLDBAction {
|
||||
$next =& $table->getIndex($index->getNext());
|
||||
$next->setPrevious($index->getPrevious());
|
||||
}
|
||||
/// Remove the index
|
||||
// Remove the index
|
||||
$table->deleteIndex($indexparam);
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
@@ -131,12 +131,12 @@ class delete_index extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class delete_key extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletekey' => 'tool_xmldb',
|
||||
'yes' => '',
|
||||
@@ -57,15 +57,15 @@ class delete_key extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
$tableparam = required_param('table', PARAM_PATH);
|
||||
@@ -73,7 +73,7 @@ class delete_key extends XMLDBAction {
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -93,14 +93,14 @@ class delete_key extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Move adjacent keys prev and next attributes
|
||||
// Move adjacent keys prev and next attributes
|
||||
$tables =& $structure->getTables();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$keys =& $table->getKeys();
|
||||
@@ -113,14 +113,14 @@ class delete_key extends XMLDBAction {
|
||||
$next =& $table->getKey($key->getNext());
|
||||
$next->setPrevious($key->getPrevious());
|
||||
}
|
||||
/// Remove the key
|
||||
// Remove the key
|
||||
$table->deleteKey($keyparam);
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
@@ -131,12 +131,12 @@ class delete_key extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class delete_table extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletetable' => 'tool_xmldb',
|
||||
'yes' => '',
|
||||
@@ -57,22 +57,22 @@ class delete_table extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -92,26 +92,26 @@ class delete_table extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Remove the table
|
||||
// Remove the table
|
||||
$structure->deleteTable($tableparam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class delete_xml_file extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletexmlfile' => 'tool_xmldb',
|
||||
'yes' => '',
|
||||
@@ -57,21 +57,21 @@ class delete_xml_file extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -91,7 +91,7 @@ class delete_xml_file extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the original dir and delete the xml file
|
||||
// Get the original dir and delete the xml file
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -102,12 +102,12 @@ class delete_xml_file extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ class edit_field extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'tool_xmldb',
|
||||
'float2numbernote' => 'tool_xmldb',
|
||||
@@ -62,18 +62,18 @@ class edit_field extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $OUTPUT;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -84,9 +84,7 @@ class edit_field extends XMLDBAction {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
// Fetch request data
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparam;
|
||||
@@ -94,7 +92,7 @@ class edit_field extends XMLDBAction {
|
||||
}
|
||||
$fieldparam = required_param('field', PARAM_CLEAN);
|
||||
if (!$field =& $table->getField($fieldparam)) {
|
||||
/// Arriving here from a name change, looking for the new field name
|
||||
// Arriving here from a name change, looking for the new field name
|
||||
$fieldparam = required_param('name', PARAM_CLEAN);
|
||||
$field =& $table->getField($fieldparam);
|
||||
}
|
||||
@@ -102,14 +100,14 @@ class edit_field extends XMLDBAction {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
$o = ''; /// Output starts
|
||||
$o = ''; // Output starts
|
||||
|
||||
/// If field is XMLDB_TYPE_FLOAT, comment about to migrate it to XMLDB_TYPE_NUMBER
|
||||
// If field is XMLDB_TYPE_FLOAT, comment about to migrate it to XMLDB_TYPE_NUMBER
|
||||
if ($field->getType() == XMLDB_TYPE_FLOAT) {
|
||||
$o .= '<p>' . $this->str['float2numbernote'] . '</p>';
|
||||
}
|
||||
|
||||
/// Add the main form
|
||||
// Add the main form
|
||||
$o.= '<form id="form" action="index.php" method="post">';
|
||||
$o.= ' <div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -119,8 +117,8 @@ class edit_field extends XMLDBAction {
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_field_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter">';
|
||||
/// XMLDB field name
|
||||
/// If the field has dependencies, we cannot change its name
|
||||
// XMLDB field name
|
||||
// If the field has dependencies, we cannot change its name
|
||||
$disabled = '';
|
||||
if ($structure->getFieldUses($table->getName(), $field->getName())) {
|
||||
$o.= ' <input type="hidden" name ="name" value="' . s($field->getName()) .'" />';
|
||||
@@ -128,9 +126,9 @@ class edit_field extends XMLDBAction {
|
||||
} else {
|
||||
$o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" maxlength="30" id="name" value="' . s($field->getName()) . '" /></td></tr>';
|
||||
}
|
||||
/// XMLDB field comment
|
||||
// XMLDB field comment
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($field->getComment()) . '</textarea></td></tr>';
|
||||
/// xmldb_field Type
|
||||
// xmldb_field Type
|
||||
$typeoptions = array (XMLDB_TYPE_INTEGER => $field->getXMLDBTypeName(XMLDB_TYPE_INTEGER),
|
||||
XMLDB_TYPE_NUMBER => $field->getXMLDBTypeName(XMLDB_TYPE_NUMBER),
|
||||
XMLDB_TYPE_FLOAT => $field->getXMLDBTypeName(XMLDB_TYPE_FLOAT),
|
||||
@@ -138,74 +136,74 @@ class edit_field extends XMLDBAction {
|
||||
XMLDB_TYPE_CHAR => $field->getXMLDBTypeName(XMLDB_TYPE_CHAR),
|
||||
XMLDB_TYPE_TEXT => $field->getXMLDBTypeName(XMLDB_TYPE_TEXT),
|
||||
XMLDB_TYPE_BINARY => $field->getXMLDBTypeName(XMLDB_TYPE_BINARY));
|
||||
/// If current field isnt float, delete such column type to avoid its creation from the interface
|
||||
/// Note that float fields are supported completely but it's possible than in a next future
|
||||
/// we delete them completely from Moodle DB, using, exlusively, number(x,y) types
|
||||
// If current field isnt float, delete such column type to avoid its creation from the interface
|
||||
// Note that float fields are supported completely but it's possible than in a next future
|
||||
// we delete them completely from Moodle DB, using, exlusively, number(x,y) types
|
||||
if ($field->getType() != XMLDB_TYPE_FLOAT) {
|
||||
unset ($typeoptions[XMLDB_TYPE_FLOAT]);
|
||||
}
|
||||
/// Also we hide datetimes. Only edition of them is allowed (and retrofit) but not new creation
|
||||
// Also we hide datetimes. Only edition of them is allowed (and retrofit) but not new creation
|
||||
if ($field->getType() != XMLDB_TYPE_DATETIME) {
|
||||
unset ($typeoptions[XMLDB_TYPE_DATETIME]);
|
||||
}
|
||||
$select = html_writer::select($typeoptions, 'type', $field->getType(), false);
|
||||
$o.= ' <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
|
||||
$o.= ' <td colspan="2">' . $select . '</td></tr>';
|
||||
/// xmldb_field Length
|
||||
// xmldb_field Length
|
||||
$o.= ' <tr valign="top"><td><label for="length" accesskey="l">Length:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="length" type="text" size="6" maxlength="6" id="length" value="' . s($field->getLength()) . '" /><span id="lengthtip"></span></td></tr>';
|
||||
/// xmldb_field Decimals
|
||||
// xmldb_field Decimals
|
||||
$o.= ' <tr valign="top"><td><label for="decimals" accesskey="d">Decimals:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="decimals" type="text" size="6" maxlength="6" id="decimals" value="' . s($field->getDecimals()) . '" /><span id="decimalstip"></span></td></tr>';
|
||||
/// xmldb_field Unsigned
|
||||
// xmldb_field Unsigned
|
||||
$unsignedoptions = array (0 => 'signed', 1 => 'unsigned');
|
||||
$select = html_writer::select($unsignedoptions, 'unsigned', $field->getUnsigned(), false);
|
||||
$o.= ' <tr valign="top"><td><label for="menuunsigned" accesskey="u">Unsigned:</label></td>';
|
||||
$o.= ' <td colspan="2">' . $select . '</td></tr>';
|
||||
/// xmldb_field NotNull
|
||||
// xmldb_field NotNull
|
||||
$notnulloptions = array (0 => 'null', 'not null');
|
||||
$select = html_writer::select($notnulloptions, 'notnull', $field->getNotNull(), false);
|
||||
$o.= ' <tr valign="top"><td><label for="menunotnull" accesskey="n">Not Null:</label></td>';
|
||||
$o.= ' <td colspan="2">' . $select . '</td></tr>';
|
||||
/// xmldb_field Sequence
|
||||
// xmldb_field Sequence
|
||||
$sequenceoptions = array (0 => $this->str['no'], 1 => 'auto-numbered');
|
||||
$select = html_writer::select($sequenceoptions, 'sequence', $field->getSequence(), false);
|
||||
$o.= ' <tr valign="top"><td><label for="menusequence" accesskey="s">Sequence:</label></td>';
|
||||
$o.= ' <td colspan="2">' . $select . '</td></tr>';
|
||||
/// xmldb_field Default
|
||||
// xmldb_field Default
|
||||
$o.= ' <tr valign="top"><td><label for="default" accesskey="d">Default:</label></td>';
|
||||
$o.= ' <td colspan="2"><input type="text" name="default" size="30" maxlength="80" id="default" value="' . s($field->getDefault()) . '" /></td></tr>';
|
||||
/// Change button
|
||||
// Change button
|
||||
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The view original XML button
|
||||
// The view original XML button
|
||||
if ($table->getField($fieldparam)) {
|
||||
$b .= ' <a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '&field=' . $fieldparam . '">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
// The view edited XML button
|
||||
if ($field->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&field=' . $fieldparam . '">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +1,52 @@
|
||||
/// $Id $
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @package tool
|
||||
* @subpackage xmldb
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// Register the needed events
|
||||
onload=function() {
|
||||
// Adjust the form on load
|
||||
transformForm();
|
||||
|
||||
/// Register the needed events
|
||||
// Get the required fields
|
||||
var typeField = document.getElementById('menutype');
|
||||
var sequenceField = document.getElementById('menusequence');
|
||||
|
||||
onload=function() {
|
||||
/// Adjust the form on load
|
||||
transformForm();
|
||||
|
||||
/// Get the required fields
|
||||
var typeField = document.getElementById('menutype');
|
||||
var sequenceField = document.getElementById('menusequence');
|
||||
|
||||
/// Register the rest of events
|
||||
if (typeField.addEventListener) {
|
||||
/// Standard
|
||||
typeField.addEventListener('change', transformForm, false);
|
||||
sequenceField.addEventListener('change', transformForm, false);
|
||||
} else {
|
||||
/// IE 5.5
|
||||
typeField.attachEvent('onchange', transformForm);
|
||||
sequenceField.attachEvent('onchange', transformForm);
|
||||
}
|
||||
// Register the rest of events
|
||||
if (typeField.addEventListener) {
|
||||
// Standard
|
||||
typeField.addEventListener('change', transformForm, false);
|
||||
sequenceField.addEventListener('change', transformForm, false);
|
||||
} else {
|
||||
// IE 5.5
|
||||
typeField.attachEvent('onchange', transformForm);
|
||||
sequenceField.attachEvent('onchange', transformForm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function controls all modifications to perform when any field changes
|
||||
*/
|
||||
function transformForm(event) {
|
||||
|
||||
/// Initialize all the needed variables
|
||||
// Initialize all the needed variables
|
||||
var typeField = document.getElementById('menutype');
|
||||
var lengthField = document.getElementById('length');
|
||||
var decimalsField = document.getElementById('decimals');
|
||||
@@ -64,14 +58,14 @@ function transformForm(event) {
|
||||
var lengthTip = document.getElementById('lengthtip');
|
||||
var decimalsTip = document.getElementById('decimalstip');
|
||||
|
||||
/// Initially, enable everything
|
||||
// Initially, enable everything
|
||||
decimalsField.disabled = false;
|
||||
unsignedField.disabled = false;
|
||||
notnullField.disabled = false;
|
||||
sequenceField.disabled = false;
|
||||
defaultField.disabled = false;
|
||||
|
||||
/// Based on sequence, disable some items
|
||||
// Based on sequence, disable some items
|
||||
if (sequenceField.value == '1') {
|
||||
unsignedField.disabled = true;
|
||||
unsignedField.value = '1';
|
||||
@@ -81,8 +75,7 @@ function transformForm(event) {
|
||||
defaultField.value = '';
|
||||
}
|
||||
|
||||
|
||||
/// Based on type, disable some items
|
||||
// Based on type, disable some items
|
||||
switch (typeField.value) {
|
||||
case '1': // XMLDB_TYPE_INTEGER
|
||||
lengthTip.innerHTML = ' 1...20';
|
||||
|
||||
@@ -38,9 +38,9 @@ class edit_field_save extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'fieldnameempty' => 'tool_xmldb',
|
||||
'incorrectfieldname' => 'tool_xmldb',
|
||||
@@ -69,20 +69,20 @@ class edit_field_save extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
//$this->does_generate = ACTION_NONE;
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted()) { ///Basic prevention
|
||||
if (!data_submitted()) { // Basic prevention
|
||||
print_error('wrongcall', 'error');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
@@ -108,9 +108,9 @@ class edit_field_save extends XMLDBAction {
|
||||
$field =& $table->getField($fieldparam);
|
||||
$oldhash = $field->getHash();
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
$errors = array(); // To store all the errors found
|
||||
|
||||
/// Perform some automatic assumptions
|
||||
// Perform some automatic assumptions
|
||||
if ($sequence) {
|
||||
$unsigned = true;
|
||||
$notnull = true;
|
||||
@@ -126,20 +126,20 @@ class edit_field_save extends XMLDBAction {
|
||||
$default = NULL;
|
||||
}
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
// Perform some checks
|
||||
// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['fieldnameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrectfieldname'];
|
||||
}
|
||||
/// Check duplicate name
|
||||
// Check duplicate name
|
||||
if ($fieldparam != $name && $table->getField($name)) {
|
||||
$errors[] = $this->str['duplicatefieldname'];
|
||||
}
|
||||
/// Integer checks
|
||||
// Integer checks
|
||||
if ($type == XMLDB_TYPE_INTEGER) {
|
||||
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||
$length > 0 && $length <= 20)) {
|
||||
@@ -151,7 +151,7 @@ class edit_field_save extends XMLDBAction {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
/// Number checks
|
||||
// Number checks
|
||||
if ($type == XMLDB_TYPE_NUMBER) {
|
||||
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||
$length > 0 && $length <= 20)) {
|
||||
@@ -169,7 +169,7 @@ class edit_field_save extends XMLDBAction {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
/// Float checks
|
||||
// Float checks
|
||||
if ($type == XMLDB_TYPE_FLOAT) {
|
||||
if (!(empty($length) || (is_numeric($length) &&
|
||||
!empty($length) &&
|
||||
@@ -190,7 +190,7 @@ class edit_field_save extends XMLDBAction {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
/// Char checks
|
||||
// Char checks
|
||||
if ($type == XMLDB_TYPE_CHAR) {
|
||||
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||
$length > 0 && $length <= xmldb_field::CHAR_MAX_LENGTH)) {
|
||||
@@ -203,7 +203,7 @@ class edit_field_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Text checks
|
||||
// Text checks
|
||||
if ($type == XMLDB_TYPE_TEXT) {
|
||||
if ($length != 'small' &&
|
||||
$length != 'medium' &&
|
||||
@@ -217,7 +217,7 @@ class edit_field_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Binary checks
|
||||
// Binary checks
|
||||
if ($type == XMLDB_TYPE_BINARY) {
|
||||
if ($length != 'small' &&
|
||||
$length != 'medium' &&
|
||||
@@ -235,7 +235,7 @@ class edit_field_save extends XMLDBAction {
|
||||
$tempfield->setNotNull($notnull);
|
||||
$tempfield->setSequence($sequence);
|
||||
$tempfield->setDefault($default);
|
||||
/// Prepare the output
|
||||
// Prepare the output
|
||||
$o = '<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $name . ': ' . $tempfield->readableInfo() . '</p>';
|
||||
$o.= '<a href="index.php?action=edit_field&field=' . $field->getName() . '&table=' . $table->getName() .
|
||||
@@ -243,10 +243,10 @@ class edit_field_save extends XMLDBAction {
|
||||
$this->output = $o;
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// atributes of the adjacent fields
|
||||
// If there is one name change, do it, changing the prev and next
|
||||
// atributes of the adjacent fields
|
||||
if ($fieldparam != $name) {
|
||||
$field->setName($name);
|
||||
if ($field->getPrevious()) {
|
||||
@@ -261,10 +261,10 @@ class edit_field_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
// Set comment
|
||||
$field->setComment($comment);
|
||||
|
||||
/// Set the rest of fields
|
||||
// Set the rest of fields
|
||||
$field->setType($type);
|
||||
$field->setLength($length);
|
||||
$field->setDecimals($decimals);
|
||||
@@ -273,26 +273,26 @@ class edit_field_save extends XMLDBAction {
|
||||
$field->setSequence($sequence);
|
||||
$field->setDefault($default);
|
||||
|
||||
/// If the hash has changed from the old one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the old one, change the version
|
||||
// and mark the structure as changed
|
||||
$field->calculateHash(true);
|
||||
if ($oldhash != $field->getHash()) {
|
||||
$field->setChanged(true);
|
||||
$table->setChanged(true);
|
||||
/// Recalculate the structure hash
|
||||
// Recalculate the structure hash
|
||||
$structure->calculateHash(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ class edit_index extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'tool_xmldb',
|
||||
'vieworiginal' => 'tool_xmldb',
|
||||
@@ -60,18 +60,18 @@ class edit_index extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $OUTPUT;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -82,9 +82,7 @@ class edit_index extends XMLDBAction {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
// Fetch request data
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparam;
|
||||
@@ -92,7 +90,7 @@ class edit_index extends XMLDBAction {
|
||||
}
|
||||
$indexparam = required_param('index', PARAM_CLEAN);
|
||||
if (!$index =& $table->getIndex($indexparam)) {
|
||||
/// Arriving here from a name change, looking for the new key name
|
||||
// Arriving here from a name change, looking for the new key name
|
||||
$indexparam = required_param('name', PARAM_CLEAN);
|
||||
$index =& $table->getIndex($indexparam);
|
||||
}
|
||||
@@ -100,7 +98,7 @@ class edit_index extends XMLDBAction {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
// Add the main form
|
||||
$o = '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -110,55 +108,55 @@ class edit_index extends XMLDBAction {
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_index_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter">';
|
||||
/// XMLDB index name
|
||||
/// If the index has dependencies, we cannot change its name
|
||||
// XMLDB index name
|
||||
// If the index has dependencies, we cannot change its name
|
||||
$disabled = '';
|
||||
if ($structure->getIndexUses($table->getName(), $index->getName())) {
|
||||
$disabled = ' disabled="disabled " ';
|
||||
}
|
||||
$o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" id="name"' . $disabled . ' value="' . s($index->getName()) . '" /></td></tr>';
|
||||
/// XMLDB key comment
|
||||
// XMLDB key comment
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($index->getComment()) . '</textarea></td></tr>';
|
||||
/// xmldb_index Type
|
||||
// xmldb_index Type
|
||||
$typeoptions = array (0 => 'not unique',
|
||||
1 => 'unique');
|
||||
$o.= ' <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
|
||||
$select = html_writer::select($typeoptions, 'unique', $index->getUnique(), false);
|
||||
$o.= ' <td colspan="2">' . $select . '</td></tr>';
|
||||
/// xmldb_index Fields
|
||||
// xmldb_index Fields
|
||||
$o.= ' <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
|
||||
/// Change button
|
||||
// Change button
|
||||
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The view original XML button
|
||||
// The view original XML button
|
||||
if ($table->getIndex($indexparam)) {
|
||||
$b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '&index=' . $indexparam . '">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
// The view edited XML button
|
||||
if ($index->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&index=' . $indexparam . '">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ class edit_index_save extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'indexnameempty' => 'tool_xmldb',
|
||||
'incorrectindexname' => 'tool_xmldb',
|
||||
@@ -65,20 +65,20 @@ class edit_index_save extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
//$this->does_generate = ACTION_NONE;
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted()) { ///Basic prevention
|
||||
if (!data_submitted()) { // Basic prevention
|
||||
print_error('wrongcall', 'error');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
@@ -99,44 +99,44 @@ class edit_index_save extends XMLDBAction {
|
||||
$index =& $table->getIndex($indexparam);
|
||||
$oldhash = $index->getHash();
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
$errors = array(); // To store all the errors found
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
// Perform some checks
|
||||
// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['indexnameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrectindexname'];
|
||||
}
|
||||
/// Check duplicate name
|
||||
// Check duplicate name
|
||||
if ($indexparam != $name && $table->getIndex($name)) {
|
||||
$errors[] = $this->str['duplicateindexname'];
|
||||
}
|
||||
$fieldsarr = explode(',', $fields);
|
||||
/// Check the fields isn't empty
|
||||
// Check the fields isn't empty
|
||||
if (empty($fieldsarr[0])) {
|
||||
$errors[] = $this->str['nofieldsspecified'];
|
||||
} else {
|
||||
/// Check that there aren't duplicate column names
|
||||
// Check that there aren't duplicate column names
|
||||
$uniquearr = array_unique($fieldsarr);
|
||||
if (count($fieldsarr) != count($uniquearr)) {
|
||||
$errors[] = $this->str['duplicatefieldsused'];
|
||||
}
|
||||
/// Check that all the fields in belong to the table
|
||||
// Check that all the fields in belong to the table
|
||||
foreach ($fieldsarr as $field) {
|
||||
if (!$table->getField($field)) {
|
||||
$errors[] = $this->str['fieldsnotintable'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any key using exactly the same fields
|
||||
// Check that there isn't any key using exactly the same fields
|
||||
$tablekeys = $table->getKeys();
|
||||
if ($tablekeys) {
|
||||
foreach ($tablekeys as $tablekey) {
|
||||
$keyfieldsarr = $tablekey->getFields();
|
||||
/// Compare both arrays, looking for differences
|
||||
// Compare both arrays, looking for differences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinkey'];
|
||||
@@ -144,16 +144,16 @@ class edit_index_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any index using exactly the same fields
|
||||
// Check that there isn't any index using exactly the same fields
|
||||
$tableindexes = $table->getIndexes();
|
||||
if ($tableindexes) {
|
||||
foreach ($tableindexes as $tableindex) {
|
||||
/// Skip checking against itself
|
||||
// Skip checking against itself
|
||||
if ($indexparam == $tableindex->getName()) {
|
||||
continue;
|
||||
}
|
||||
$indexfieldsarr = $tableindex->getFields();
|
||||
/// Compare both arrays, looking for differences
|
||||
// Compare both arrays, looking for differences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinindex'];
|
||||
@@ -167,7 +167,7 @@ class edit_index_save extends XMLDBAction {
|
||||
$tempindex = new xmldb_index($name);
|
||||
$tempindex->setUnique($unique);
|
||||
$tempindex->setFields($fieldsarr);
|
||||
/// Prepare the output
|
||||
// Prepare the output
|
||||
$o = '<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $tempindex->readableInfo() . '</p>';
|
||||
$o.= '<a href="index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() .
|
||||
@@ -175,10 +175,10 @@ class edit_index_save extends XMLDBAction {
|
||||
$this->output = $o;
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// attributes of the adjacent fields
|
||||
// If there is one name change, do it, changing the prev and next
|
||||
// attributes of the adjacent fields
|
||||
if ($indexparam != $name) {
|
||||
$index->setName($name);
|
||||
if ($index->getPrevious()) {
|
||||
@@ -193,33 +193,33 @@ class edit_index_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
// Set comment
|
||||
$index->setComment($comment);
|
||||
|
||||
/// Set the rest of fields
|
||||
// Set the rest of fields
|
||||
$index->setUnique($unique);
|
||||
$index->setFields($fieldsarr);
|
||||
|
||||
/// If the hash has changed from the old one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the old one, change the version
|
||||
// and mark the structure as changed
|
||||
$index->calculateHash(true);
|
||||
if ($oldhash != $index->getHash()) {
|
||||
$index->setChanged(true);
|
||||
$table->setChanged(true);
|
||||
/// Recalculate the structure hash
|
||||
// Recalculate the structure hash
|
||||
$structure->calculateHash(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ class edit_key extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'tool_xmldb',
|
||||
'vieworiginal' => 'tool_xmldb',
|
||||
@@ -61,18 +61,18 @@ class edit_key extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $OUTPUT;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -83,9 +83,7 @@ class edit_key extends XMLDBAction {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
// Fetch request data
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparam;
|
||||
@@ -93,7 +91,7 @@ class edit_key extends XMLDBAction {
|
||||
}
|
||||
$keyparam = required_param('key', PARAM_CLEAN);
|
||||
if (!$key =& $table->getKey($keyparam)) {
|
||||
/// Arriving here from a name change, looking for the new key name
|
||||
// Arriving here from a name change, looking for the new key name
|
||||
$keyparam = required_param('name', PARAM_CLEAN);
|
||||
$key =& $table->getKey($keyparam);
|
||||
}
|
||||
@@ -101,7 +99,7 @@ class edit_key extends XMLDBAction {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
// Add the main form
|
||||
$o = '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -111,68 +109,68 @@ class edit_key extends XMLDBAction {
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_key_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter">';
|
||||
/// XMLDB key name
|
||||
/// If the key has dependencies, we cannot change its name
|
||||
// XMLDB key name
|
||||
// If the key has dependencies, we cannot change its name
|
||||
$disabled = '';
|
||||
if ($structure->getKeyUses($table->getName(), $key->getName())) {
|
||||
$disabled = ' disabled="disabled " ';
|
||||
}
|
||||
$o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" id="name"' . $disabled . ' value="' . s($key->getName()) . '" /></td></tr>';
|
||||
/// XMLDB key comment
|
||||
// XMLDB key comment
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($key->getComment()) . '</textarea></td></tr>';
|
||||
/// xmldb_key Type
|
||||
// xmldb_key Type
|
||||
$typeoptions = array (XMLDB_KEY_PRIMARY => $key->getXMLDBKeyName(XMLDB_KEY_PRIMARY),
|
||||
XMLDB_KEY_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_UNIQUE),
|
||||
XMLDB_KEY_FOREIGN => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN),
|
||||
XMLDB_KEY_FOREIGN_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN_UNIQUE));
|
||||
/// Only show the XMLDB_KEY_FOREIGN_UNIQUE if the Key has that type
|
||||
/// if ($key->getType() != XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
/// unset ($typeoptions[XMLDB_KEY_FOREIGN_UNIQUE);
|
||||
/// }
|
||||
// Only show the XMLDB_KEY_FOREIGN_UNIQUE if the Key has that type
|
||||
// if ($key->getType() != XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
// unset ($typeoptions[XMLDB_KEY_FOREIGN_UNIQUE);
|
||||
// }
|
||||
$select = html_writer::select($typeoptions, 'type', $key->getType(), false);
|
||||
|
||||
$o.= ' <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
|
||||
$o.= ' <td colspan="2">' . $select . '</td></tr>';
|
||||
/// xmldb_key Fields
|
||||
// xmldb_key Fields
|
||||
$o.= ' <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $key->getFields())) . '" /></td></tr>';
|
||||
/// xmldb_key Reftable
|
||||
// xmldb_key Reftable
|
||||
$o.= ' <tr valign="top"><td><label for="reftable" accesskey="t">Reftable:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="reftable" type="text" size="20" maxlength="40" id="reftable" value="' . s($key->getReftable()) . '" /></td></tr>';
|
||||
/// xmldb_key Reffields
|
||||
// xmldb_key Reffields
|
||||
$o.= ' <tr valign="top"><td><label for="reffields" accesskey="t">Reffields:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="reffields" type="text" size="40" maxlength="80" id="reffields" value="' . s(implode(', ', $key->getRefFields())) . '" /></td></tr>';
|
||||
/// Change button
|
||||
// Change button
|
||||
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The view original XML button
|
||||
// The view original XML button
|
||||
if ($table->getKey($keyparam)) {
|
||||
$b .= ' <a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '&key=' . $keyparam . '">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
// The view edited XML button
|
||||
if ($key->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&key=' . $keyparam . '">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,61 @@
|
||||
/// $Id $
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @package tool
|
||||
* @subpackage xmldb
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// Register the needed events
|
||||
onload=function() {
|
||||
// Adjust the form on load
|
||||
transformForm();
|
||||
|
||||
/// Register the needed events
|
||||
// Get the required fields
|
||||
var typeField = document.getElementById('menutype');
|
||||
|
||||
onload=function() {
|
||||
/// Adjust the form on load
|
||||
transformForm();
|
||||
|
||||
/// Get the required fields
|
||||
var typeField = document.getElementById('menutype');
|
||||
|
||||
/// Register the rest of events
|
||||
if (typeField.addEventListener) {
|
||||
/// Standard
|
||||
typeField.addEventListener('change', transformForm, false);
|
||||
} else {
|
||||
/// IE 5.5
|
||||
typeField.attachEvent('onchange', transformForm);
|
||||
}
|
||||
// Register the rest of events
|
||||
if (typeField.addEventListener) {
|
||||
// Standard
|
||||
typeField.addEventListener('change', transformForm, false);
|
||||
} else {
|
||||
// IE 5.5
|
||||
typeField.attachEvent('onchange', transformForm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function controls all modifications to perform when any field changes
|
||||
*/
|
||||
function transformForm(event) {
|
||||
|
||||
/// Initialize all the needed variables
|
||||
// Initialize all the needed variables
|
||||
var typeField = document.getElementById('menutype');
|
||||
var fieldsField = document.getElementById('fields');
|
||||
var reftableField = document.getElementById('reftable');
|
||||
var reffieldsField = document.getElementById('reffields');
|
||||
|
||||
/// Initially, enable everything
|
||||
// Initially, enable everything
|
||||
typeField.disabled = false;
|
||||
fieldsField.disabled = false;
|
||||
reftableField.disabled = false;
|
||||
reffieldsField.disabled = false;
|
||||
|
||||
/// Based on type, disable some items
|
||||
// Based on type, disable some items
|
||||
switch (typeField.value) {
|
||||
case '1': // XMLDB_KEY_PRIMARY
|
||||
case '2': // XMLDB_KEY_UNIQUE
|
||||
|
||||
@@ -38,9 +38,9 @@ class edit_key_save extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'keynameempty' => 'tool_xmldb',
|
||||
'incorrectkeyname' => 'tool_xmldb',
|
||||
@@ -71,20 +71,20 @@ class edit_key_save extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
//$this->does_generate = ACTION_NONE;
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted()) { ///Basic prevention
|
||||
if (!data_submitted()) { // Basic prevention
|
||||
print_error('wrongcall', 'error');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
@@ -112,39 +112,39 @@ class edit_key_save extends XMLDBAction {
|
||||
$key =& $table->getKey($keyparam);
|
||||
$oldhash = $key->getHash();
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
$errors = array(); // To store all the errors found
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
// Perform some checks
|
||||
// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['keynameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrectkeyname'];
|
||||
}
|
||||
/// Check duplicate name
|
||||
// Check duplicate name
|
||||
if ($keyparam != $name && $table->getKey($name)) {
|
||||
$errors[] = $this->str['duplicatekeyname'];
|
||||
}
|
||||
$fieldsarr = explode(',', $fields);
|
||||
/// Check the fields isn't empty
|
||||
// Check the fields isn't empty
|
||||
if (empty($fieldsarr[0])) {
|
||||
$errors[] = $this->str['nofieldsspecified'];
|
||||
} else {
|
||||
/// Check that there aren't duplicate column names
|
||||
// Check that there aren't duplicate column names
|
||||
$uniquearr = array_unique($fieldsarr);
|
||||
if (count($fieldsarr) != count($uniquearr)) {
|
||||
$errors[] = $this->str['duplicatefieldsused'];
|
||||
}
|
||||
/// Check that all the fields in belong to the table
|
||||
// Check that all the fields in belong to the table
|
||||
foreach ($fieldsarr as $field) {
|
||||
if (!$table->getField($field)) {
|
||||
$errors[] = $this->str['fieldsnotintable'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// If primary, check that all the fields are not null
|
||||
// If primary, check that all the fields are not null
|
||||
if ($type == XMLDB_KEY_PRIMARY) {
|
||||
foreach ($fieldsarr as $field) {
|
||||
if ($fi = $table->getField($field)) {
|
||||
@@ -155,16 +155,16 @@ class edit_key_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any key using exactly the same fields
|
||||
// Check that there isn't any key using exactly the same fields
|
||||
$tablekeys = $table->getKeys();
|
||||
if ($tablekeys) {
|
||||
foreach ($tablekeys as $tablekey) {
|
||||
/// Skip checking against itself
|
||||
// Skip checking against itself
|
||||
if ($keyparam == $tablekey->getName()) {
|
||||
continue;
|
||||
}
|
||||
$keyfieldsarr = $tablekey->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinkey'];
|
||||
@@ -172,12 +172,12 @@ class edit_key_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any index using exactlt the same fields
|
||||
// Check that there isn't any index using exactlt the same fields
|
||||
$tableindexes = $table->getIndexes();
|
||||
if ($tableindexes) {
|
||||
foreach ($tableindexes as $tableindex) {
|
||||
$indexfieldsarr = $tableindex->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinindex'];
|
||||
@@ -185,34 +185,34 @@ class edit_key_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// If foreign key
|
||||
// If foreign key
|
||||
if ($type == XMLDB_KEY_FOREIGN ||
|
||||
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
$reffieldsarr = explode(',', $reffields);
|
||||
/// Check reftable is not empty
|
||||
// Check reftable is not empty
|
||||
if (empty($reftable)) {
|
||||
$errors[] = $this->str['noreftablespecified'];
|
||||
} else
|
||||
/// Check reffields are not empty
|
||||
// Check reffields are not empty
|
||||
if (empty($reffieldsarr[0])) {
|
||||
$errors[] = $this->str['noreffieldsspecified'];
|
||||
} else
|
||||
/// Check the number of fields is correct
|
||||
// Check the number of fields is correct
|
||||
if (count($fieldsarr) != count($reffieldsarr)) {
|
||||
$errors[] = $this->str['wrongnumberofreffields'];
|
||||
} else {
|
||||
/// Check, if pointing to one structure table, that there is one master key for this key
|
||||
// Check, if pointing to one structure table, that there is one master key for this key
|
||||
if ($rt = $structure->getTable($reftable)) {
|
||||
$masterfound = false;
|
||||
$reftablekeys = $rt->getKeys();
|
||||
if ($reftablekeys) {
|
||||
foreach ($reftablekeys as $reftablekey) {
|
||||
/// Only compare with primary and unique keys
|
||||
// Only compare with primary and unique keys
|
||||
if ($reftablekey->getType() != XMLDB_KEY_PRIMARY && $reftablekey->getType() != XMLDB_KEY_UNIQUE) {
|
||||
continue;
|
||||
}
|
||||
$keyfieldsarr = $reftablekey->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($reffieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $reffieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$masterfound = true;
|
||||
@@ -222,7 +222,7 @@ class edit_key_save extends XMLDBAction {
|
||||
if (!$masterfound) {
|
||||
$errors[] = $this->str['nomasterprimaryuniquefound'];
|
||||
} else {
|
||||
/// Quick test of the order
|
||||
// Quick test of the order
|
||||
if (implode(',', $reffieldsarr) != implode(',', $keyfieldsarr)) {
|
||||
$errors[] = $this->str['masterprimaryuniqueordernomatch'];
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class edit_key_save extends XMLDBAction {
|
||||
$tempkey->setRefTable($reftable);
|
||||
$tempkey->setRefFields($reffieldsarr);
|
||||
}
|
||||
/// Prepare the output
|
||||
// Prepare the output
|
||||
$o = '<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $name . ': ' . $tempkey->readableInfo() . '</p>';
|
||||
$o.= '<a href="index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() .
|
||||
@@ -251,10 +251,10 @@ class edit_key_save extends XMLDBAction {
|
||||
$this->output = $o;
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// atributes of the adjacent fields
|
||||
// If there is one name change, do it, changing the prev and next
|
||||
// atributes of the adjacent fields
|
||||
if ($keyparam != $name) {
|
||||
$key->setName($name);
|
||||
if ($key->getPrevious()) {
|
||||
@@ -269,10 +269,10 @@ class edit_key_save extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
// Set comment
|
||||
$key->setComment($comment);
|
||||
|
||||
/// Set the rest of fields
|
||||
// Set the rest of fields
|
||||
$key->setType($type);
|
||||
$key->setFields($fieldsarr);
|
||||
if ($type == XMLDB_KEY_FOREIGN ||
|
||||
@@ -281,26 +281,26 @@ class edit_key_save extends XMLDBAction {
|
||||
$key->setRefFields($reffieldsarr);
|
||||
}
|
||||
|
||||
/// If the hash has changed from the old one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the old one, change the version
|
||||
// and mark the structure as changed
|
||||
$key->calculateHash(true);
|
||||
if ($oldhash != $key->getHash()) {
|
||||
$key->setChanged(true);
|
||||
$table->setChanged(true);
|
||||
/// Recalculate the structure hash
|
||||
// Recalculate the structure hash
|
||||
$structure->calculateHash(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ class edit_table extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'tool_xmldb',
|
||||
'vieworiginal' => 'tool_xmldb',
|
||||
@@ -80,25 +80,25 @@ class edit_table extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
/// Check if the dir exists and copy it from dbdirs
|
||||
/// (because we need straight load in case of saving from here)
|
||||
// Check if the dir exists and copy it from dbdirs
|
||||
// (because we need straight load in case of saving from here)
|
||||
if (!isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$XMLDB->editeddirs[$dirpath] = unserialize(serialize($dbdir));
|
||||
}
|
||||
@@ -108,10 +108,9 @@ class edit_table extends XMLDBAction {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
/// Arriving here from a name change, looking for the new table name
|
||||
// Arriving here from a name change, looking for the new table name
|
||||
$tableparam = required_param('name', PARAM_CLEAN);
|
||||
$table =& $structure->getTable($tableparam);
|
||||
}
|
||||
@@ -119,7 +118,7 @@ class edit_table extends XMLDBAction {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
// Add the main form
|
||||
$o = '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -128,7 +127,7 @@ class edit_table extends XMLDBAction {
|
||||
$o.= ' <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter">';
|
||||
/// If the table is being used, we cannot rename it
|
||||
// If the table is being used, we cannot rename it
|
||||
if ($structure->getTableUses($table->getName())) {
|
||||
$o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($table->getName()) . '" />' . s($table->getName()) .'</td></tr>';
|
||||
} else {
|
||||
@@ -138,7 +137,7 @@ class edit_table extends XMLDBAction {
|
||||
$o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the pending changes / save message
|
||||
// Calculate the pending changes / save message
|
||||
$e = '';
|
||||
$cansavenow = false;
|
||||
if ($structure->hasChanged()) {
|
||||
@@ -149,38 +148,38 @@ class edit_table extends XMLDBAction {
|
||||
$cansavenow = true;
|
||||
}
|
||||
}
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The view original XML button
|
||||
// The view original XML button
|
||||
if ($origstructure->getTable($tableparam)) {
|
||||
$b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
// The view edited XML button
|
||||
if ($table->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The new field button
|
||||
// The new field button
|
||||
$b .= ' <a href="index.php?action=new_field&sesskey=' . sesskey() . '&postaction=edit_field&table=' . $tableparam . '&field=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newfield'] . ']</a>';
|
||||
/// The new key button
|
||||
// The new key button
|
||||
$b .= ' <a href="index.php?action=new_key&sesskey=' . sesskey() . '&postaction=edit_key&table=' . $tableparam . '&key=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newkey'] . ']</a>';
|
||||
/// The new index button
|
||||
// The new index button
|
||||
$b .= ' <a href="index.php?action=new_index&sesskey=' . sesskey() . '&postaction=edit_index&table=' . $tableparam . '&index=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newindex'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
|
||||
$b .= ' <p class="centerpara buttons">';
|
||||
/// The view sql code button
|
||||
// The view sql code button
|
||||
$b .= '<a href="index.php?action=view_table_sql&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>';
|
||||
/// The view php code button
|
||||
// The view php code button
|
||||
$b .= ' <a href="index.php?action=view_table_php&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>';
|
||||
/// The save button (if possible)
|
||||
// The save button (if possible)
|
||||
if ($cansavenow) {
|
||||
$b .= ' <a href="index.php?action=save_xml_file&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&time=' . time() . '&unload=false&postaction=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['save'] . ']</a>';
|
||||
}
|
||||
/// The back to edit xml file button
|
||||
// The back to edit xml file button
|
||||
$b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $e . $b;
|
||||
@@ -188,48 +187,48 @@ class edit_table extends XMLDBAction {
|
||||
require_once("$CFG->libdir/ddl/sql_generator.php");
|
||||
$reserved_words = sql_generator::getAllReservedWords();
|
||||
|
||||
/// Delete any 'changeme' field/key/index
|
||||
// Delete any 'changeme' field/key/index
|
||||
$table->deleteField('changeme');
|
||||
$table->deleteKey('changeme');
|
||||
$table->deleteIndex('changeme');
|
||||
|
||||
/// Add the fields list
|
||||
// Add the fields list
|
||||
$fields =& $table->getFields();
|
||||
if (!empty($fields)) {
|
||||
$o .= '<h3 class="main">' . $this->str['fields'] . '</h3>';
|
||||
$o .= '<table id="listfields" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$row = 0;
|
||||
foreach ($fields as $field) {
|
||||
/// The field name (link to edit - if the field has no uses)
|
||||
// The field name (link to edit - if the field has no uses)
|
||||
if (!$structure->getFieldUses($table->getName(), $field->getName())) {
|
||||
$f = '<a href="index.php?action=edit_field&field=' .$field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">' . $field->getName() . '</a>';
|
||||
} else {
|
||||
$f = $field->getName();
|
||||
}
|
||||
/// Calculate buttons
|
||||
// Calculate buttons
|
||||
$b = '</td><td class="button cell">';
|
||||
/// The edit button (if the field has no uses)
|
||||
// The edit button (if the field has no uses)
|
||||
if (!$structure->getFieldUses($table->getName(), $field->getName())) {
|
||||
$b .= '<a href="index.php?action=edit_field&field=' .$field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['edit'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The up button
|
||||
// The up button
|
||||
if ($field->getPrevious()) {
|
||||
$b .= '<a href="index.php?action=move_updown_field&direction=up&sesskey=' . sesskey() . '&field=' . $field->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['up'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The down button
|
||||
// The down button
|
||||
if ($field->getNext()) {
|
||||
$b .= '<a href="index.php?action=move_updown_field&direction=down&sesskey=' . sesskey() . '&field=' . $field->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['down'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button (if we have more than one and it isn't used
|
||||
// The delete button (if we have more than one and it isn't used
|
||||
if (count($fields) > 1 &&
|
||||
!$structure->getFieldUses($table->getName(), $field->getName())) {
|
||||
$b .= '<a href="index.php?action=delete_field&sesskey=' . sesskey() . '&field=' . $field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
@@ -237,109 +236,109 @@ class edit_table extends XMLDBAction {
|
||||
$b .= '[' . $this->str['delete'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The view xml button
|
||||
// The view xml button
|
||||
$b .= '<a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&field=' . $field->getName() . '&table=' . $table->getName() . '&select=edited">[' . $this->str['viewxml'] . ']</a>';
|
||||
/// Detect if the table name is a reserved word
|
||||
// Detect if the table name is a reserved word
|
||||
if (array_key_exists($field->getName(), $reserved_words)) {
|
||||
$b .= ' <a href="index.php?action=view_reserved_words"><span class="error">' . $this->str['reserved'] . '</span></a>';
|
||||
}
|
||||
/// The readable info
|
||||
// The readable info
|
||||
$r = '</td><td class="readableinfo cell">' . $field->readableInfo() . '</td>';
|
||||
/// Print table row
|
||||
// Print table row
|
||||
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $f . $b . $r . '</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
/// Add the keys list
|
||||
// Add the keys list
|
||||
$keys =& $table->getKeys();
|
||||
if (!empty($keys)) {
|
||||
$o .= '<h3 class="main">' . $this->str['keys'] . '</h3>';
|
||||
$o .= '<table id="listkeys" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$row = 0;
|
||||
foreach ($keys as $key) {
|
||||
/// The key name (link to edit - if the key has no uses)
|
||||
// The key name (link to edit - if the key has no uses)
|
||||
if (!$structure->getKeyUses($table->getName(), $key->getName())) {
|
||||
$k = '<a href="index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">' . $key->getName() . '</a>';
|
||||
} else {
|
||||
$k = $key->getName();
|
||||
}
|
||||
/// Calculate buttons
|
||||
// Calculate buttons
|
||||
$b = '</td><td class="button cell">';
|
||||
/// The edit button (if the key hasn't uses)
|
||||
// The edit button (if the key hasn't uses)
|
||||
if (!$structure->getKeyUses($table->getName(), $key->getName())) {
|
||||
$b .= '<a href="index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['edit'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The up button
|
||||
// The up button
|
||||
if ($key->getPrevious()) {
|
||||
$b .= '<a href="index.php?action=move_updown_key&direction=up&sesskey=' . sesskey() . '&key=' . $key->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['up'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The down button
|
||||
// The down button
|
||||
if ($key->getNext()) {
|
||||
$b .= '<a href="index.php?action=move_updown_key&direction=down&sesskey=' . sesskey() . '&key=' . $key->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['down'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button (if the key hasn't uses)
|
||||
// The delete button (if the key hasn't uses)
|
||||
if (!$structure->getKeyUses($table->getName(), $key->getName())) {
|
||||
$b .= '<a href="index.php?action=delete_key&sesskey=' . sesskey() . '&key=' . $key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['delete'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The view xml button
|
||||
// The view xml button
|
||||
$b .= '<a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&key=' . $key->getName() . '&table=' . $table->getName() . '&select=edited">[' . $this->str['viewxml'] . ']</a>';
|
||||
/// The readable info
|
||||
// The readable info
|
||||
$r = '</td><td class="readableinfo cell">' . $key->readableInfo() . '</td>';
|
||||
/// Print table row
|
||||
// Print table row
|
||||
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $k . $b . $r .'</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
/// Add the indexes list
|
||||
// Add the indexes list
|
||||
$indexes =& $table->getIndexes();
|
||||
if (!empty($indexes)) {
|
||||
$o .= '<h3 class="main">' . $this->str['indexes'] . '</h3>';
|
||||
$o .= '<table id="listindexes" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$row = 0;
|
||||
foreach ($indexes as $index) {
|
||||
/// The index name (link to edit)
|
||||
// The index name (link to edit)
|
||||
$i = '<a href="index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">' . $index->getName() . '</a>';
|
||||
/// Calculate buttons
|
||||
// Calculate buttons
|
||||
$b = '</td><td class="button cell">';
|
||||
/// The edit button
|
||||
// The edit button
|
||||
$b .= '<a href="index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The up button
|
||||
// The up button
|
||||
if ($index->getPrevious()) {
|
||||
$b .= '<a href="index.php?action=move_updown_index&direction=up&sesskey=' . sesskey() . '&index=' . $index->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['up'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The down button
|
||||
// The down button
|
||||
if ($index->getNext()) {
|
||||
$b .= '<a href="index.php?action=move_updown_index&direction=down&sesskey=' . sesskey() . '&index=' . $index->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['down'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button
|
||||
// The delete button
|
||||
$b .= '<a href="index.php?action=delete_index&sesskey=' . sesskey() . '&index=' . $index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The view xml button
|
||||
// The view xml button
|
||||
$b .= '<a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&index=' . $index->getName() . '&table=' . $table->getName() . '&select=edited">[' . $this->str['viewxml'] . ']</a>';
|
||||
/// The readable info
|
||||
// The readable info
|
||||
$r = '</td><td class="readableinfo cell">' . $index->readableInfo() . '</td>';
|
||||
/// Print table row
|
||||
// Print table row
|
||||
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $i . $b . $r .'</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
@@ -348,12 +347,12 @@ class edit_table extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class edit_table_save extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'tablenameempty' => 'tool_xmldb',
|
||||
'incorrecttablename' => 'tool_xmldb',
|
||||
@@ -59,20 +59,20 @@ class edit_table_save extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
//$this->does_generate = ACTION_NONE;
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted()) { ///Basic prevention
|
||||
if (!data_submitted()) { // Basic prevention
|
||||
print_error('wrongcall', 'error');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
@@ -87,25 +87,25 @@ class edit_table_save extends XMLDBAction {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
$errors = array(); // To store all the errors found
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
// Perform some checks
|
||||
// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['tablenameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrecttablename'];
|
||||
}
|
||||
/// Check duplicatename
|
||||
// Check duplicatename
|
||||
if ($tableparam != $name && $structure->getTable($name)) {
|
||||
$errors[] = $this->str['duplicatetablename'];
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$temptable = new xmldb_table($name);
|
||||
/// Prepare the output
|
||||
// Prepare the output
|
||||
$o = '<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $temptable->getName() . '</p>';
|
||||
$o.= '<a href="index.php?action=edit_table&table=' . $tableparam .
|
||||
@@ -113,10 +113,10 @@ class edit_table_save extends XMLDBAction {
|
||||
$this->output = $o;
|
||||
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
// Continue if we aren't under errors
|
||||
} else if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// atributes of the adjacent tables
|
||||
// If there is one name change, do it, changing the prev and next
|
||||
// atributes of the adjacent tables
|
||||
if ($tableparam != $name) {
|
||||
$table->setName($name);
|
||||
if ($table->getPrevious()) {
|
||||
@@ -129,35 +129,35 @@ class edit_table_save extends XMLDBAction {
|
||||
$next->setPrevious($name);
|
||||
$next->setChanged(true);
|
||||
}
|
||||
/// Table has changed
|
||||
// Table has changed
|
||||
$table->setChanged(true);
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
// Set comment
|
||||
if ($table->getComment() != $comment) {
|
||||
$table->setComment($comment);
|
||||
/// Table has changed
|
||||
// Table has changed
|
||||
$table->setChanged(true);
|
||||
}
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ class edit_xml_file extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'tool_xmldb',
|
||||
'edit' => 'tool_xmldb',
|
||||
@@ -76,40 +76,39 @@ class edit_xml_file extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
//$this->does_generate = ACTION_NONE;
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $DB;
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// Do the job, setting $result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
if ($dbdir) {
|
||||
/// Only if the directory exists and it has been loaded
|
||||
// Only if the directory exists and it has been loaded
|
||||
if (!$dbdir->path_exists || !$dbdir->xml_loaded) {
|
||||
return false;
|
||||
}
|
||||
/// Check if the in-memory object exists and create it
|
||||
// Check if the in-memory object exists and create it
|
||||
if (empty($XMLDB->editeddirs)) {
|
||||
$XMLDB->editeddirs = array();
|
||||
}
|
||||
/// Check if the dir exists and copy it from dbdirs
|
||||
// Check if the dir exists and copy it from dbdirs
|
||||
if (!isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$XMLDB->editeddirs[$dirpath] = unserialize(serialize($dbdir));
|
||||
}
|
||||
/// Get it
|
||||
// Get it
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
// Add the main form
|
||||
$o = '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -125,7 +124,7 @@ class edit_xml_file extends XMLDBAction {
|
||||
$o.= ' <tr><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the pending changes / save message
|
||||
// Calculate the pending changes / save message
|
||||
$e = '';
|
||||
$cansavenow = false;
|
||||
if ($structure->hasChanged()) {
|
||||
@@ -136,100 +135,100 @@ class edit_xml_file extends XMLDBAction {
|
||||
$cansavenow = true;
|
||||
}
|
||||
}
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The view original XML button
|
||||
// The view original XML button
|
||||
$b .= ' <a href="index.php?action=view_structure_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
/// The view edited XML button
|
||||
// The view edited XML button
|
||||
if ($structure->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_structure_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The new table button
|
||||
// The new table button
|
||||
$b .= ' <a href="index.php?action=new_table&sesskey=' . sesskey() . '&postaction=edit_table&table=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newtable'] . ']</a>';
|
||||
/// The new from MySQL button
|
||||
// The new from MySQL button
|
||||
if ($DB->get_dbfamily() == 'mysql') {
|
||||
$b .= ' <a href="index.php?action=new_table_from_mysql&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newtablefrommysql'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['newtablefrommysql'] . ']';
|
||||
}
|
||||
|
||||
/// The view sql code button
|
||||
// The view sql code button
|
||||
$b .= '<a href="index.php?action=view_structure_sql&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>';
|
||||
/// The view php code button
|
||||
// The view php code button
|
||||
$b .= ' <a href="index.php?action=view_structure_php&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>';
|
||||
/// The save button (if possible)
|
||||
// The save button (if possible)
|
||||
if ($cansavenow) {
|
||||
$b .= ' <a href="index.php?action=save_xml_file&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&time=' . time() . '&unload=false&postaction=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['save'] . ']</a>';
|
||||
}
|
||||
|
||||
/// The back to main menu button
|
||||
// The back to main menu button
|
||||
$b .= ' <a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $e . $b;
|
||||
|
||||
/// Join all the reserved words into one big array
|
||||
/// Calculate list of available SQL generators
|
||||
// Join all the reserved words into one big array
|
||||
// Calculate list of available SQL generators
|
||||
require_once("$CFG->libdir/ddl/sql_generator.php");
|
||||
$reserved_words = sql_generator::getAllReservedWords();
|
||||
|
||||
/// Add the tables list
|
||||
// Add the tables list
|
||||
$tables = $structure->getTables();
|
||||
if ($tables) {
|
||||
$o .= '<h3 class="main">' . $this->str['tables'] . '</h3>';
|
||||
$o .= '<table id="listtables" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$row = 0;
|
||||
foreach ($tables as $table) {
|
||||
/// The table name (link to edit table)
|
||||
// The table name (link to edit table)
|
||||
$t = '<a href="index.php?action=edit_table&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">' . $table->getName() . '</a>';
|
||||
/// Calculate buttons
|
||||
// Calculate buttons
|
||||
$b = '</td><td class="button cell">';
|
||||
/// The edit button
|
||||
// The edit button
|
||||
$b .= '<a href="index.php?action=edit_table&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The up button
|
||||
// The up button
|
||||
if ($table->getPrevious()) {
|
||||
$b .= '<a href="index.php?action=move_updown_table&direction=up&sesskey=' . sesskey() . '&table=' . $table->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['up'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The down button
|
||||
// The down button
|
||||
if ($table->getNext()) {
|
||||
$b .= '<a href="index.php?action=move_updown_table&direction=down&sesskey=' . sesskey() . '&table=' . $table->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['down'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button (if we have more than one and it isn't used)
|
||||
// The delete button (if we have more than one and it isn't used)
|
||||
if (count($tables) > 1 &&
|
||||
!$structure->getTableUses($table->getName())) {
|
||||
///!$structure->getTableUses($table->getName())) {
|
||||
// !$structure->getTableUses($table->getName())) {
|
||||
$b .= '<a href="index.php?action=delete_table&sesskey=' . sesskey() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['delete'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The view xml button
|
||||
// The view xml button
|
||||
$b .= '<a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&table=' . $table->getName() . '&select=edited">[' . $this->str['viewxml'] . ']</a>';
|
||||
/// Detect if the table name is a reserved word
|
||||
// Detect if the table name is a reserved word
|
||||
if (array_key_exists($table->getName(), $reserved_words)) {
|
||||
$b .= ' <a href="index.php?action=view_reserved_words"><span class="error">' . $this->str['reserved'] . '</span></a>';
|
||||
}
|
||||
$b .= '</td>';
|
||||
/// Print table row
|
||||
// Print table row
|
||||
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $t . $b . '</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
///Add the back to main
|
||||
// Add the back to main
|
||||
$this->output = $o;
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this unmodified)
|
||||
// Launch postaction if exists (leave this unmodified)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class edit_xml_file_save extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,35 +55,35 @@ class edit_xml_file_save extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted()) { ///Basic prevention
|
||||
if (!data_submitted()) { // Basic prevention
|
||||
print_error('wrongcall', 'error');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
$comment = required_param('comment', PARAM_CLEAN);
|
||||
$comment = $comment;
|
||||
|
||||
/// Set comment and recalculate hash
|
||||
// Set comment and recalculate hash
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$structure->setComment($comment);
|
||||
$structure->calculateHash(true);
|
||||
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $origdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
@@ -91,12 +91,12 @@ class edit_xml_file_save extends XMLDBAction {
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -38,10 +38,10 @@ class generate_all_documentation extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'backtomainview' => 'tool_xmldb',
|
||||
'documentationintro' => 'tool_xmldb',
|
||||
@@ -59,15 +59,15 @@ class generate_all_documentation extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// Do the job, setting $result as needed
|
||||
|
||||
/// Add link back to home
|
||||
// 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>';
|
||||
@@ -115,7 +115,7 @@ class generate_all_documentation extends XMLDBAction {
|
||||
$this->output.=get_string('extensionrequired','tool_xmldb','xsl');
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this unmodified)
|
||||
// Launch postaction if exists (leave this unmodified)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ class generate_documentation extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'backtomainview' => 'tool_xmldb',
|
||||
'documentationintro' => 'tool_xmldb'
|
||||
@@ -57,15 +57,15 @@ class generate_documentation extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// Do the job, setting $result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
$path = $dirpath.'/install.xml';
|
||||
@@ -73,7 +73,7 @@ class generate_documentation extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add link back to home
|
||||
// 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>';
|
||||
@@ -85,7 +85,7 @@ class generate_documentation extends XMLDBAction {
|
||||
$this->output.=$c;
|
||||
|
||||
if(class_exists('XSLTProcessor')) {
|
||||
/// Transform XML file and display it
|
||||
// Transform XML file and display it
|
||||
$doc = new DOMDocument();
|
||||
$xsl = new XSLTProcessor();
|
||||
|
||||
@@ -99,7 +99,7 @@ class generate_documentation extends XMLDBAction {
|
||||
$this->output.=get_string('extensionrequired','tool_xmldb','xsl');
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this unmodified)
|
||||
// Launch postaction if exists (leave this unmodified)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
@@ -37,16 +37,16 @@ class get_db_directories extends XMLDBAction {
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->can_subaction = ACTION_NONE;
|
||||
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -60,22 +60,22 @@ class get_db_directories extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// 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
|
||||
// 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
|
||||
// get list of all dirs and create objects with status
|
||||
$db_directories = get_db_directories();
|
||||
foreach ($db_directories as $path) {
|
||||
$dbdir = new stdClass;
|
||||
@@ -86,10 +86,10 @@ class get_db_directories extends XMLDBAction {
|
||||
$XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
|
||||
}
|
||||
|
||||
/// Sort by key
|
||||
// Sort by key
|
||||
ksort($XMLDB->dbdirs);
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,16 +36,16 @@ class load_xml_file extends XMLDBAction {
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->can_subaction = ACTION_NONE;
|
||||
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -59,43 +59,43 @@ class load_xml_file extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// Do the job, setting $result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
if ($dbdir) {
|
||||
/// Set some defaults
|
||||
// Set some defaults
|
||||
$dbdir->xml_exists = false;
|
||||
$dbdir->xml_writeable = false;
|
||||
$dbdir->xml_loaded = false;
|
||||
///Only if the directory exists
|
||||
// Only if the directory exists
|
||||
if (!$dbdir->path_exists) {
|
||||
return false;
|
||||
}
|
||||
$xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
|
||||
///Set the XML DTD and schema
|
||||
// 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
|
||||
// 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
|
||||
// Load the XML contents to structure
|
||||
$loaded = $xmldb_file->loadXMLStructure();
|
||||
if ($loaded && $xmldb_file->isLoaded()) {
|
||||
$dbdir->xml_loaded = true;
|
||||
@@ -110,7 +110,7 @@ class load_xml_file extends XMLDBAction {
|
||||
$this->errormsg = 'XMLDB structure not found';
|
||||
$result = false;
|
||||
}
|
||||
/// Launch postaction if exists
|
||||
// Launch postaction if exists
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
@@ -36,15 +36,15 @@ class load_xml_files extends XMLDBAction {
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->can_subaction = ACTION_NONE;
|
||||
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -58,36 +58,36 @@ class load_xml_files extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting $result as needed
|
||||
// Do the job, setting $result as needed
|
||||
|
||||
/// Iterate over $XMLDB->dbdirs, loading their XML data to memory
|
||||
// Iterate over $XMLDB->dbdirs, loading their XML data to memory
|
||||
if ($XMLDB->dbdirs) {
|
||||
$dbdirs =& $XMLDB->dbdirs;
|
||||
foreach ($dbdirs as $dbdir) {
|
||||
/// Set some defaults
|
||||
// Set some defaults
|
||||
$dbdir->xml_exists = false;
|
||||
$dbdir->xml_writeable = false;
|
||||
$dbdir->xml_loaded = false;
|
||||
///Only if the directory exists
|
||||
// Only if the directory exists
|
||||
if (!$dbdir->path_exists) {
|
||||
continue;
|
||||
}
|
||||
$xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
|
||||
/// Set dbdir as necessary
|
||||
// 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
|
||||
// Load the XML contents to structure
|
||||
$loaded = $xmldb_file->loadXMLStructure();
|
||||
if ($loaded && $xmldb_file->isLoaded()) {
|
||||
$dbdir->xml_loaded = true;
|
||||
|
||||
@@ -40,10 +40,10 @@ class main_view extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'load' => 'tool_xmldb',
|
||||
'create' => 'tool_xmldb',
|
||||
@@ -75,62 +75,62 @@ class main_view extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $SESSION, $DB;
|
||||
|
||||
/// Get lastused
|
||||
// Get lastused
|
||||
$o = '';
|
||||
if (isset($SESSION->lastused)) {
|
||||
if ($lastused = $SESSION->lastused) {
|
||||
/// Print link
|
||||
// Print link
|
||||
$o .= '<p class="centerpara"><a href="#lastused">' . $this->str['gotolastused'] . '</a></p>';
|
||||
}
|
||||
} else {
|
||||
$lastused = NULL;
|
||||
}
|
||||
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = '<p class="centerpara buttons">';
|
||||
/// The reserved_words button
|
||||
// The reserved_words button
|
||||
$b .= ' <a href="index.php?action=view_reserved_words">[' . $this->str['reservedwords'] . ']</a>';
|
||||
/// The docs button
|
||||
// The docs button
|
||||
$b .= ' <a href="index.php?action=generate_all_documentation">[' . $this->str['doc'] . ']</a>';
|
||||
/// The check indexes button
|
||||
// The check indexes button
|
||||
$b .= ' <a href="index.php?action=check_indexes&sesskey=' . sesskey() . '">[' . $this->str['checkindexes'] . ']</a>';
|
||||
/// The check defaults button
|
||||
// The check defaults button
|
||||
$b .= ' <a href="index.php?action=check_defaults&sesskey=' . sesskey() . '">[' . $this->str['checkdefaults'] . ']</a>';
|
||||
/// The check bigints button (only for MySQL and PostgreSQL) MDL-11038a
|
||||
// The check bigints button (only for MySQL and PostgreSQL) MDL-11038a
|
||||
if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') {
|
||||
$b .= ' <a href="index.php?action=check_bigints&sesskey=' . sesskey() . '">[' . $this->str['checkbigints'] . ']</a>';
|
||||
}
|
||||
/// The check semantics button (only for Oracle) MDL-29416
|
||||
// The check semantics button (only for Oracle) MDL-29416
|
||||
if ($DB->get_dbfamily() == 'oracle') {
|
||||
$b .= ' <a href="index.php?action=check_oracle_semantics&sesskey=' . sesskey() . '">[' . $this->str['checkoraclesemantics'] . ']</a>';
|
||||
}
|
||||
$b .= ' <a href="index.php?action=check_foreign_keys&sesskey=' . sesskey() . '">[' . $this->str['checkforeignkeys'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
/// Send buttons to output
|
||||
// Send buttons to output
|
||||
$o .= $b;
|
||||
|
||||
/// Do the job
|
||||
// Do the job
|
||||
|
||||
/// Get the list of DB directories
|
||||
// Get the list of DB directories
|
||||
$result = $this->launch('get_db_directories');
|
||||
/// Display list of DB directories if everything is ok
|
||||
// Display list of DB directories if everything is ok
|
||||
if ($result && !empty($XMLDB->dbdirs)) {
|
||||
$o .= '<table id="listdirectories" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$row = 0;
|
||||
foreach ($XMLDB->dbdirs as $key => $dbdir) {
|
||||
/// Detect if this is the lastused dir
|
||||
// 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
|
||||
// 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])) {
|
||||
@@ -144,7 +144,7 @@ class main_view extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The file name (link to edit if the file is loaded)
|
||||
// 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') &&
|
||||
@@ -154,9 +154,9 @@ class main_view extends XMLDBAction {
|
||||
} else {
|
||||
$f = $elementtext;
|
||||
}
|
||||
/// Calculate the buttons
|
||||
// Calculate the buttons
|
||||
$b = ' <td class="button cell">';
|
||||
/// The create button
|
||||
// The create button
|
||||
if ($dbdir->path_exists &&
|
||||
!file_exists($key . '/install.xml') &&
|
||||
is_writeable($key)) {
|
||||
@@ -165,7 +165,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['create'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The load button
|
||||
// The load button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml') &&
|
||||
@@ -175,7 +175,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['load'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The edit button
|
||||
// The edit button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml') &&
|
||||
@@ -186,7 +186,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['edit'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The save button
|
||||
// The save button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_writeable($key . '/install.xml') &&
|
||||
@@ -194,9 +194,9 @@ class main_view extends XMLDBAction {
|
||||
!empty($dbdir->xml_loaded) &&
|
||||
!empty($dbdir->xml_changed)) {
|
||||
$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>';
|
||||
/// Check if the file has been manually edited while being modified in the editor
|
||||
// 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 errors.
|
||||
// File manually modified. Add to errors.
|
||||
if ($structure =& $dbdir->xml_file->getStructure()) {
|
||||
$structure->errormsg = 'Warning: File locally modified while using the XMLDB Editor. Saving will overwrite local changes';
|
||||
}
|
||||
@@ -205,7 +205,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['save'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The document button
|
||||
// The document button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml') &&
|
||||
@@ -215,7 +215,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['doc'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The view xml button
|
||||
// The view xml button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml')) {
|
||||
@@ -224,7 +224,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['viewxml'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The revert button
|
||||
// The revert button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml') &&
|
||||
@@ -236,7 +236,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['revert'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The unload button
|
||||
// The unload button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml') &&
|
||||
@@ -247,7 +247,7 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['unload'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button
|
||||
// The delete button
|
||||
if ($dbdir->path_exists &&
|
||||
file_exists($key . '/install.xml') &&
|
||||
is_readable($key . '/install.xml') &&
|
||||
@@ -258,14 +258,14 @@ class main_view extends XMLDBAction {
|
||||
$b .= '[' . $this->str['delete'] . ']';
|
||||
}
|
||||
$b .= '</td>';
|
||||
/// include the higlight
|
||||
// include the higlight
|
||||
if ($hithis) {
|
||||
$o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $f . '</td>' . $b . '</tr>';
|
||||
} else {
|
||||
$o .= '<tr class="r' . $row . '"><td class="directory cell">' . $f . '</td>' . $b . '</tr>';
|
||||
}
|
||||
$row = ($row + 1) % 2;
|
||||
/// show errors if they exist
|
||||
// show errors if they exist
|
||||
if (isset($dbdir->xml_file)) {
|
||||
if ($structure =& $dbdir->xml_file->getStructure()) {
|
||||
if ($errors = $structure->getAllErrors()) {
|
||||
@@ -277,8 +277,8 @@ class main_view extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// TODO: Drop this check in Moodle 2.1
|
||||
/// Intercept loaded structure here and look for ENUM fields
|
||||
// TODO: Drop this check in Moodle 2.1
|
||||
// Intercept loaded structure here and look for ENUM fields
|
||||
if (isset($dbdir->xml_file)) {
|
||||
if ($structure =& $dbdir->xml_file->getStructure()) {
|
||||
if ($tables = $structure->getTables()) {
|
||||
@@ -311,7 +311,7 @@ class main_view extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// If there are changes pending to be saved, but the file cannot be written... inform here
|
||||
// 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) &&
|
||||
@@ -329,11 +329,11 @@ class main_view extends XMLDBAction {
|
||||
}
|
||||
$o .= '</table>';
|
||||
|
||||
/// Set the output
|
||||
// Set the output
|
||||
$this->output = $o;
|
||||
}
|
||||
|
||||
/// Finally, return result
|
||||
// Finally, return result
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class move_updown_field extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class move_updown_field extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,7 +77,7 @@ class move_updown_field extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$prev = NULL;
|
||||
$next = NULL;
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
@@ -94,7 +94,7 @@ class move_updown_field extends XMLDBAction {
|
||||
$field =& $table->getField($swap->getPrevious());
|
||||
}
|
||||
|
||||
/// Change the field before the pair
|
||||
// Change the field before the pair
|
||||
if ($field->getPrevious()) {
|
||||
$prev =& $table->getField($field->getPrevious());
|
||||
$prev->setNext($swap->getName());
|
||||
@@ -103,7 +103,7 @@ class move_updown_field extends XMLDBAction {
|
||||
} else {
|
||||
$swap->setPrevious(NULL);
|
||||
}
|
||||
/// Change the field after the pair
|
||||
// Change the field after the pair
|
||||
if ($swap->getNext()) {
|
||||
$next =& $table->getField($swap->getNext());
|
||||
$next->setPrevious($field->getName());
|
||||
@@ -112,37 +112,37 @@ class move_updown_field extends XMLDBAction {
|
||||
} else {
|
||||
$field->setNext(NULL);
|
||||
}
|
||||
/// Swap the fields
|
||||
// Swap the fields
|
||||
$field->setPrevious($swap->getName());
|
||||
$swap->setNext($field->getName());
|
||||
|
||||
/// Mark fields as changed
|
||||
// Mark fields as changed
|
||||
$field->setChanged(true);
|
||||
$swap->setChanged(true);
|
||||
|
||||
/// Table has changed
|
||||
// Table has changed
|
||||
$table->setChanged(true);
|
||||
|
||||
/// Reorder the fields
|
||||
// Reorder the fields
|
||||
$table->orderFields($fields);
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class move_updown_index extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class move_updown_index extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,7 +77,7 @@ class move_updown_index extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$prev = NULL;
|
||||
$next = NULL;
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
@@ -94,7 +94,7 @@ class move_updown_index extends XMLDBAction {
|
||||
$index =& $table->getIndex($swap->getPrevious());
|
||||
}
|
||||
|
||||
/// Change the index before the pair
|
||||
// Change the index before the pair
|
||||
if ($index->getPrevious()) {
|
||||
$prev =& $table->getIndex($index->getPrevious());
|
||||
$prev->setNext($swap->getName());
|
||||
@@ -103,7 +103,7 @@ class move_updown_index extends XMLDBAction {
|
||||
} else {
|
||||
$swap->setPrevious(NULL);
|
||||
}
|
||||
/// Change the field after the pair
|
||||
// Change the field after the pair
|
||||
if ($swap->getNext()) {
|
||||
$next =& $table->getIndex($swap->getNext());
|
||||
$next->setPrevious($index->getName());
|
||||
@@ -112,37 +112,37 @@ class move_updown_index extends XMLDBAction {
|
||||
} else {
|
||||
$index->setNext(NULL);
|
||||
}
|
||||
/// Swap the indexes
|
||||
// Swap the indexes
|
||||
$index->setPrevious($swap->getName());
|
||||
$swap->setNext($index->getName());
|
||||
|
||||
/// Mark indexes as changed
|
||||
// Mark indexes as changed
|
||||
$index->setChanged(true);
|
||||
$swap->setChanged(true);
|
||||
|
||||
/// Table has changed
|
||||
// Table has changed
|
||||
$table->setChanged(true);
|
||||
|
||||
/// Reorder the indexes
|
||||
// Reorder the indexes
|
||||
$table->orderIndexes($indexes);
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class move_updown_key extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class move_updown_key extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,7 +77,7 @@ class move_updown_key extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$prev = NULL;
|
||||
$next = NULL;
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
@@ -94,7 +94,7 @@ class move_updown_key extends XMLDBAction {
|
||||
$key =& $table->getKey($swap->getPrevious());
|
||||
}
|
||||
|
||||
/// Change the key before the pair
|
||||
// Change the key before the pair
|
||||
if ($key->getPrevious()) {
|
||||
$prev =& $table->getKey($key->getPrevious());
|
||||
$prev->setNext($swap->getName());
|
||||
@@ -103,7 +103,7 @@ class move_updown_key extends XMLDBAction {
|
||||
} else {
|
||||
$swap->setPrevious(NULL);
|
||||
}
|
||||
/// Change the key after the pair
|
||||
// Change the key after the pair
|
||||
if ($swap->getNext()) {
|
||||
$next =& $table->getKey($swap->getNext());
|
||||
$next->setPrevious($key->getName());
|
||||
@@ -112,37 +112,37 @@ class move_updown_key extends XMLDBAction {
|
||||
} else {
|
||||
$key->setNext(NULL);
|
||||
}
|
||||
/// Swap the keys
|
||||
// Swap the keys
|
||||
$key->setPrevious($swap->getName());
|
||||
$swap->setNext($key->getName());
|
||||
|
||||
/// Mark keys as changed
|
||||
// Mark keys as changed
|
||||
$key->setChanged(true);
|
||||
$swap->setChanged(true);
|
||||
|
||||
/// Table has changed
|
||||
// Table has changed
|
||||
$table->setChanged(true);
|
||||
|
||||
/// Reorder the keys
|
||||
// Reorder the keys
|
||||
$table->orderKeys($keys);
|
||||
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class move_updown_table extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class move_updown_table extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,7 +77,7 @@ class move_updown_table extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$prev = NULL;
|
||||
$next = NULL;
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
@@ -91,7 +91,7 @@ class move_updown_table extends XMLDBAction {
|
||||
$table =& $structure->getTable($swap->getPrevious());
|
||||
}
|
||||
|
||||
/// Change the table before the pair
|
||||
// Change the table before the pair
|
||||
if ($table->getPrevious()) {
|
||||
$prev =& $structure->getTable($table->getPrevious());
|
||||
$prev->setNext($swap->getName());
|
||||
@@ -100,7 +100,7 @@ class move_updown_table extends XMLDBAction {
|
||||
} else {
|
||||
$swap->setPrevious(NULL);
|
||||
}
|
||||
/// Change the table after the pair
|
||||
// Change the table after the pair
|
||||
if ($swap->getNext()) {
|
||||
$next =& $structure->getTable($swap->getNext());
|
||||
$next->setPrevious($table->getName());
|
||||
@@ -109,34 +109,34 @@ class move_updown_table extends XMLDBAction {
|
||||
} else {
|
||||
$table->setNext(NULL);
|
||||
}
|
||||
/// Swap the tables
|
||||
// Swap the tables
|
||||
$table->setPrevious($swap->getName());
|
||||
$swap->setNext($table->getName());
|
||||
|
||||
/// Table has changed
|
||||
// Table has changed
|
||||
$table->setChanged(true);
|
||||
|
||||
/// Reorder the structure
|
||||
// Reorder the structure
|
||||
$structure->orderTables($tables);
|
||||
/// Send tables back to structure (the order above break refs)
|
||||
// Send tables back to structure (the order above break refs)
|
||||
$structure->setTables($tables);
|
||||
/// Recalculate the hash
|
||||
// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
// If the hash has changed from the original one, change the version
|
||||
// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class new_field extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class new_field extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,34 +77,33 @@ class new_field extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$table =& $structure->getTable($tableparam);
|
||||
|
||||
/// If the changeme field exists, just get it and continue
|
||||
// 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
|
||||
if (!$changeme_exists) { // Lets create the field
|
||||
$field = new xmldb_field('changeme');
|
||||
$table->addField($field);
|
||||
|
||||
/// We have one new field, so the structure has changed
|
||||
// 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!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class new_index extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class new_index extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,33 +77,32 @@ class new_index extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$table =& $structure->getTable($tableparam);
|
||||
|
||||
/// If the changeme index exists, just get it and continue
|
||||
// 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
|
||||
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
|
||||
// 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!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class new_key extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class new_key extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,33 +77,32 @@ class new_key extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$table =& $structure->getTable($tableparam);
|
||||
|
||||
/// If the changeme key exists, just get it and continue
|
||||
// If the changeme key exists, just get it and continue
|
||||
$changeme_exists = false;
|
||||
if ($keys =& $table->getKeys()) {
|
||||
if ($key =& $table->getKey('changeme')) {
|
||||
$changeme_exists = true;
|
||||
}
|
||||
}
|
||||
if (!$changeme_exists) { /// Lets create the Key
|
||||
if (!$changeme_exists) { // Lets create the Key
|
||||
$key = new xmldb_key('changeme');
|
||||
$table->addKey($key);
|
||||
|
||||
/// We have one new key, so the structure has changed
|
||||
// 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!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class new_table extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ class new_table extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -77,16 +77,15 @@ class new_table extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// If the changeme table exists, just get it and continue
|
||||
// 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
|
||||
if (!$changeme_exists) { // Lets create the table
|
||||
$field = new xmldb_field('id');
|
||||
$field->setType(XMLDB_TYPE_INTEGER);
|
||||
$field->setLength(10);
|
||||
@@ -107,16 +106,16 @@ class new_table extends XMLDBAction {
|
||||
$table->addField($field);
|
||||
$table->addKey($key);
|
||||
|
||||
/// Finally, add the whole retrofitted table to the structure
|
||||
/// in the place specified
|
||||
// Finally, add the whole retrofitted table to the structure
|
||||
// in the place specified
|
||||
$structure->addTable($table);
|
||||
}
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ class new_table_from_mysql extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'createtable' => 'tool_xmldb',
|
||||
'aftertable' => 'tool_xmldb',
|
||||
@@ -59,18 +59,18 @@ class new_table_from_mysql extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $DB, $OUTPUT;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -80,14 +80,14 @@ class new_table_from_mysql extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$tableparam = optional_param('table', NULL, PARAM_CLEAN);
|
||||
|
||||
/// If no table, show form
|
||||
// If no table, show form
|
||||
if (!$tableparam) {
|
||||
/// No postaction here
|
||||
// No postaction here
|
||||
$this->postaction = NULL;
|
||||
/// Get list of tables
|
||||
// Get list of tables
|
||||
$dbtables = $DB->get_tables();
|
||||
$selecttables = array();
|
||||
foreach ($dbtables as $dbtable) {
|
||||
@@ -96,7 +96,7 @@ class new_table_from_mysql extends XMLDBAction {
|
||||
$selecttables[$dbtable] = $dbtable;
|
||||
}
|
||||
}
|
||||
/// Get list of after tables
|
||||
// Get list of after tables
|
||||
$aftertables = array();
|
||||
if ($tables =& $structure->getTables()) {
|
||||
foreach ($tables as $aftertable) {
|
||||
@@ -107,7 +107,7 @@ class new_table_from_mysql extends XMLDBAction {
|
||||
$this->errormsg = 'No tables available to be retrofitted';
|
||||
return false;
|
||||
}
|
||||
/// Now build the form
|
||||
// Now build the form
|
||||
$o = '<form id="form" action="index.php" method="post">';
|
||||
$o .= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -124,67 +124,67 @@ class new_table_from_mysql extends XMLDBAction {
|
||||
$this->output = $o;
|
||||
|
||||
|
||||
/// If table, retrofit information and, if everything works,
|
||||
/// go to the table edit action
|
||||
// If table, retrofit information and, if everything works,
|
||||
// go to the table edit action
|
||||
} else {
|
||||
/// Get some params (table is mandatory here)
|
||||
// Get some params (table is mandatory here)
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
$afterparam = required_param('after', PARAM_CLEAN);
|
||||
|
||||
/// Create one new xmldb_table
|
||||
// Create one new xmldb_table
|
||||
$table = new xmldb_table(strtolower(trim($tableparam)));
|
||||
$table->setComment($table->getName() . ' table retrofitted from MySQL');
|
||||
/// Get fields info from ADODb
|
||||
// Get fields info from ADODb
|
||||
$dbfields = $DB->get_columns($tableparam);
|
||||
if ($dbfields) {
|
||||
foreach ($dbfields as $dbfield) {
|
||||
/// Create new XMLDB field
|
||||
// Create new XMLDB field
|
||||
$field = new xmldb_field($dbfield->name);
|
||||
/// Set field with info retrofitted
|
||||
// Set field with info retrofitted
|
||||
$field->setFromADOField($dbfield);
|
||||
/// Add field to the table
|
||||
// Add field to the table
|
||||
$table->addField($field);
|
||||
}
|
||||
}
|
||||
/// Get PK, UK and indexes info from ADODb
|
||||
// Get PK, UK and indexes info from ADODb
|
||||
$dbindexes = $DB->get_indexes($tableparam);
|
||||
if ($dbindexes) {
|
||||
$lastkey = NULL; //To temp store the last key processed
|
||||
foreach ($dbindexes as $indexname => $dbindex) {
|
||||
/// Add the indexname to the array
|
||||
// Add the indexname to the array
|
||||
$dbindex['name'] = $indexname;
|
||||
/// We are handling one xmldb_key (primaries + uniques)
|
||||
// We are handling one xmldb_key (primaries + uniques)
|
||||
if ($dbindex['unique']) {
|
||||
$key = new xmldb_key(strtolower($dbindex['name']));
|
||||
/// Set key with info retrofitted
|
||||
// Set key with info retrofitted
|
||||
$key->setFromADOKey($dbindex);
|
||||
/// Set default comment to PKs
|
||||
// Set default comment to PKs
|
||||
if ($key->getType() == XMLDB_KEY_PRIMARY) {
|
||||
}
|
||||
/// Add key to the table
|
||||
// Add key to the table
|
||||
$table->addKey($key);
|
||||
|
||||
/// We are handling one xmldb_index (non-uniques)
|
||||
// We are handling one xmldb_index (non-uniques)
|
||||
} else {
|
||||
$index = new xmldb_index(strtolower($dbindex['name']));
|
||||
/// Set index with info retrofitted
|
||||
// Set index with info retrofitted
|
||||
$index->setFromADOIndex($dbindex);
|
||||
/// Add index to the table
|
||||
// Add index to the table
|
||||
$table->addIndex($index);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Finally, add the whole retroffited table to the structure
|
||||
/// in the place specified
|
||||
// Finally, add the whole retroffited table to the structure
|
||||
// in the place specified
|
||||
$structure->addTable($table, $afterparam);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class revert_changes extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmrevertchanges' => 'tool_xmldb',
|
||||
'yes' => '',
|
||||
@@ -57,21 +57,21 @@ class revert_changes extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table width="60" class="generalbox boxaligncenter" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
@@ -91,7 +91,7 @@ class revert_changes extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the original dir and delete some elements
|
||||
// Get the original dir and delete some elements
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -100,7 +100,7 @@ class revert_changes extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Get the edited dir and delete it completely
|
||||
// Get the edited dir and delete it completely
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
unset($XMLDB->editeddirs[$dirpath]);
|
||||
@@ -108,12 +108,12 @@ class revert_changes extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ class save_xml_file extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'filenotwriteable' => 'tool_xmldb'
|
||||
));
|
||||
@@ -60,26 +60,26 @@ class save_xml_file extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// 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
|
||||
// Copy the edited dir over the original one
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||
$XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir));
|
||||
@@ -87,19 +87,19 @@ class save_xml_file extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Chech for perms
|
||||
// Chech for perms
|
||||
if (!is_writeable($dirpath . '/install.xml')) {
|
||||
$this->errormsg = $this->str['filenotwriteable'] . '(' . $dirpath . '/install.xml)';
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Save the original dir
|
||||
// Save the original dir
|
||||
$result = $dbdir->xml_file->saveXMLFile();
|
||||
|
||||
if ($result) {
|
||||
/// Delete the edited dir
|
||||
// Delete the edited dir
|
||||
unset ($XMLDB->editeddirs[$dirpath]);
|
||||
/// Unload de originaldir
|
||||
// Unload de originaldir
|
||||
unset($XMLDB->dbdirs[$dirpath]->xml_file);
|
||||
unset($XMLDB->dbdirs[$dirpath]->xml_loaded);
|
||||
unset($XMLDB->dbdirs[$dirpath]->xml_changed);
|
||||
@@ -110,17 +110,17 @@ class save_xml_file extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// If unload has been disabled, simulate it by reloading the file now
|
||||
// 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!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ class template extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -54,19 +54,19 @@ class template extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -76,17 +76,15 @@ class template extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
// ADD YOUR CODE HERE
|
||||
|
||||
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ class unload_xml_file extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,20 +56,19 @@ class unload_xml_file extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the original dir and delete some elements
|
||||
// Get the original dir and delete some elements
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -82,19 +81,19 @@ class unload_xml_file extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Get the edited dir and delete it completely
|
||||
// Get the edited dir and delete it completely
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
unset($XMLDB->editeddirs[$dirpath]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ class view_field_xml extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,23 +56,23 @@ class view_field_xml extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_XML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the file parameter
|
||||
// Get the file parameter
|
||||
$field = required_param('field', PARAM_PATH);
|
||||
$table = required_param('table', PARAM_PATH);
|
||||
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if ($select == 'original') {
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$base =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -86,7 +86,7 @@ class view_field_xml extends XMLDBAction {
|
||||
$result = false;
|
||||
}
|
||||
if ($base) {
|
||||
/// Only if the directory exists and it has been loaded
|
||||
// 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;
|
||||
@@ -96,47 +96,47 @@ class view_field_xml extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Get the structure
|
||||
// Get the structure
|
||||
if ($result) {
|
||||
if (!$structure =& $base->xml_file->getStructure()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the tables
|
||||
// Get the tables
|
||||
if ($result) {
|
||||
if (!$tables =& $structure->getTables()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the table
|
||||
// Get the table
|
||||
if ($result && !$t = $structure->getTable($table)) {
|
||||
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||
$result = false;
|
||||
}
|
||||
/// Get the fields
|
||||
// Get the fields
|
||||
if ($result) {
|
||||
if (!$fields =& $t->getFields()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' fields';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the field
|
||||
// Get the field
|
||||
if ($result && !$f = $t->getField($field)) {
|
||||
$this->errormsg = 'Error retrieving ' . $field . ' field';
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
/// Everything is ok. Generate the XML output
|
||||
// Everything is ok. Generate the XML output
|
||||
$this->output = $f->xmlOutput();
|
||||
} else {
|
||||
/// Switch to HTML and error
|
||||
// Switch to HTML and error
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ class view_index_xml extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,23 +56,23 @@ class view_index_xml extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_XML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the file parameter
|
||||
// Get the file parameter
|
||||
$index = required_param('index', PARAM_PATH);
|
||||
$table = required_param('table', PARAM_PATH);
|
||||
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if ($select == 'original') {
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$base =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -86,7 +86,7 @@ class view_index_xml extends XMLDBAction {
|
||||
$result = false;
|
||||
}
|
||||
if ($base) {
|
||||
/// Only if the directory exists and it has been loaded
|
||||
// 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;
|
||||
@@ -96,47 +96,47 @@ class view_index_xml extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Get the structure
|
||||
// Get the structure
|
||||
if ($result) {
|
||||
if (!$structure =& $base->xml_file->getStructure()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the tables
|
||||
// Get the tables
|
||||
if ($result) {
|
||||
if (!$tables =& $structure->getTables()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the table
|
||||
// Get the table
|
||||
if ($result && !$t =& $structure->getTable($table)) {
|
||||
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||
$result = false;
|
||||
}
|
||||
/// Get the indexes
|
||||
// Get the indexes
|
||||
if ($result) {
|
||||
if (!$indexes =& $t->getIndexes()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' indexes';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the index
|
||||
// Get the index
|
||||
if ($result && !$i = $t->getIndex($index)) {
|
||||
$this->errormsg = 'Error retrieving ' . $index . ' index';
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
/// Everything is ok. Generate the XML output
|
||||
// Everything is ok. Generate the XML output
|
||||
$this->output = $i->xmlOutput();
|
||||
} else {
|
||||
/// Switch to HTML and error
|
||||
// Switch to HTML and error
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ class view_key_xml extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,23 +56,23 @@ class view_key_xml extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_XML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the file parameter
|
||||
// Get the file parameter
|
||||
$key = required_param('key', PARAM_PATH);
|
||||
$table = required_param('table', PARAM_PATH);
|
||||
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if ($select == 'original') {
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$base =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -86,7 +86,7 @@ class view_key_xml extends XMLDBAction {
|
||||
$result = false;
|
||||
}
|
||||
if ($base) {
|
||||
/// Only if the directory exists and it has been loaded
|
||||
// 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;
|
||||
@@ -96,47 +96,47 @@ class view_key_xml extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Get the structure
|
||||
// Get the structure
|
||||
if ($result) {
|
||||
if (!$structure =& $base->xml_file->getStructure()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the tables
|
||||
// Get the tables
|
||||
if ($result) {
|
||||
if (!$tables =& $structure->getTables()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the table
|
||||
// Get the table
|
||||
if ($result && !$t =& $structure->getTable($table)) {
|
||||
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||
$result = false;
|
||||
}
|
||||
/// Get the keys
|
||||
// Get the keys
|
||||
if ($result) {
|
||||
if (!$keys =& $t->getKeys()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' keys';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the key
|
||||
// Get the key
|
||||
if ($result && !$k = $t->getKey($key)) {
|
||||
$this->errormsg = 'Error retrieving ' . $key . ' key';
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
/// Everything is ok. Generate the XML output
|
||||
// Everything is ok. Generate the XML output
|
||||
$this->output = $k->xmlOutput();
|
||||
} else {
|
||||
/// Switch to HTML and error
|
||||
// Switch to HTML and error
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ class view_reserved_words extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'listreservedwords' => 'tool_xmldb',
|
||||
'wrongreservedwords' => 'tool_xmldb',
|
||||
@@ -63,18 +63,18 @@ class view_reserved_words extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $DB;
|
||||
|
||||
/// Calculate list of available SQL generators
|
||||
// Calculate list of available SQL generators
|
||||
require_once("$CFG->libdir/ddl/sql_generator.php");
|
||||
$reserved_words = sql_generator::getAllReservedWords();
|
||||
|
||||
/// Now, calculate, looking into current DB (with AdoDB Metadata), which fields are
|
||||
/// in the list of reserved words
|
||||
// Now, calculate, looking into current DB (with AdoDB Metadata), which fields are
|
||||
// in the list of reserved words
|
||||
$wronguses = array();
|
||||
$dbtables = $DB->get_tables();
|
||||
if ($dbtables) {
|
||||
@@ -94,16 +94,16 @@ class view_reserved_words extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sort the wrong uses
|
||||
// Sort the wrong uses
|
||||
sort($wronguses);
|
||||
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
$b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o = $b;
|
||||
|
||||
/// The list of currently wrong field names
|
||||
// The list of currently wrong field names
|
||||
if ($wronguses) {
|
||||
$o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td align="center"><font color="red">' . $this->str['wrongreservedwords'] . '</font></td></tr>';
|
||||
@@ -113,7 +113,7 @@ class view_reserved_words extends XMLDBAction {
|
||||
$o.= ' </table>';
|
||||
}
|
||||
|
||||
/// The textarea showing all the reserved words
|
||||
// The textarea showing all the reserved words
|
||||
$o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td align="center">' . $this->str['listreservedwords'].'</td></tr>';
|
||||
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||
@@ -123,12 +123,12 @@ class view_reserved_words extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ class view_structure_php extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'selectaction' => 'tool_xmldb',
|
||||
'selecttable' => 'tool_xmldb',
|
||||
@@ -60,18 +60,18 @@ class view_structure_php extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $OUTPUT;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -81,7 +81,6 @@ class view_structure_php extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$tables =& $structure->getTables();
|
||||
$table = reset($tables);
|
||||
@@ -90,28 +89,28 @@ class view_structure_php extends XMLDBAction {
|
||||
$defaulttable = $table->getName();
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$commandparam = optional_param('command', 'create_table', PARAM_PATH);
|
||||
$tableparam = optional_param('table', $defaulttable, PARAM_PATH);
|
||||
|
||||
/// The back to edit xml button
|
||||
// The back to edit xml button
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
$b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o = $b;
|
||||
|
||||
/// Calculate the popup of commands
|
||||
// Calculate the popup of commands
|
||||
$commands = array('create_table',
|
||||
'drop_table',
|
||||
'rename_table');
|
||||
foreach ($commands as $command) {
|
||||
$popcommands[$command] = str_replace('_', ' ', $command);
|
||||
}
|
||||
/// Calculate the popup of tables
|
||||
// Calculate the popup of tables
|
||||
foreach ($tables as $table) {
|
||||
$poptables[$table->getName()] = $table->getName();
|
||||
}
|
||||
/// Now build the form
|
||||
// Now build the form
|
||||
$o.= '<form id="form" action="index.php" method="post">';
|
||||
$o.='<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -123,7 +122,7 @@ class view_structure_php extends XMLDBAction {
|
||||
$o.= '</div></form>';
|
||||
$o.= ' <table id="phpcode" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||
/// Based on current params, call the needed function
|
||||
// Based on current params, call the needed function
|
||||
switch ($commandparam) {
|
||||
case 'create_table':
|
||||
$o.= s($this->create_table_php($structure, $tableparam));
|
||||
@@ -140,12 +139,12 @@ class view_structure_php extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ class view_structure_php extends XMLDBAction {
|
||||
function create_table_php($structure, $table) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -168,62 +167,62 @@ class view_structure_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define table ' . $table->getName() . ' to be created' . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Adding fields to table ' . $table->getName() . XMLDB_LINEFEED;
|
||||
/// Iterate over each field
|
||||
// Iterate over each field
|
||||
foreach ($table->getFields() as $field) {
|
||||
/// The field header, with name
|
||||
// The field header, with name
|
||||
$result .= ' $table->add_field(' . "'" . $field->getName() . "', ";
|
||||
/// The field PHP specs
|
||||
// The field PHP specs
|
||||
$result .= $field->getPHP(false);
|
||||
/// The end of the line
|
||||
// The end of the line
|
||||
$result .= ');' . XMLDB_LINEFEED;
|
||||
}
|
||||
/// Iterate over each key
|
||||
// Iterate over each key
|
||||
if ($keys = $table->getKeys()) {
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Adding keys to table ' . $table->getName() . XMLDB_LINEFEED;
|
||||
foreach ($keys as $key) {
|
||||
/// The key header, with name
|
||||
// The key header, with name
|
||||
$result .= ' $table->add_key(' . "'" . $key->getName() . "', ";
|
||||
/// The key PHP specs
|
||||
// The key PHP specs
|
||||
$result .= $key->getPHP();
|
||||
/// The end of the line
|
||||
// The end of the line
|
||||
$result .= ');' . XMLDB_LINEFEED;
|
||||
}
|
||||
}
|
||||
/// Iterate over each index
|
||||
// Iterate over each index
|
||||
if ($indexes = $table->getIndexes()) {
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Adding indexes to table ' . $table->getName() . XMLDB_LINEFEED;
|
||||
foreach ($indexes as $index) {
|
||||
/// The index header, with name
|
||||
// The index header, with name
|
||||
$result .= ' $table->add_index(' . "'" . $index->getName() . "', ";
|
||||
/// The index PHP specs
|
||||
// The index PHP specs
|
||||
$result .= $index->getPHP();
|
||||
/// The end of the line
|
||||
// The end of the line
|
||||
$result .= ');' . XMLDB_LINEFEED;
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Conditionally launch create table for ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' if (!$dbman->table_exists($table)) {' . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->create_table($table);' . XMLDB_LINEFEED;
|
||||
$result .= ' }' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -240,7 +239,7 @@ class view_structure_php extends XMLDBAction {
|
||||
function drop_table_php($structure, $table) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -248,25 +247,25 @@ class view_structure_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define table ' . $table->getName() . ' to be dropped' . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Conditionally launch drop table for ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' if ($dbman->table_exists($table)) {' . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->drop_table($table);' . XMLDB_LINEFEED;
|
||||
$result .= ' }' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -283,7 +282,7 @@ class view_structure_php extends XMLDBAction {
|
||||
function rename_table_php($structure, $table) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -291,23 +290,23 @@ class view_structure_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define table ' . $table->getName() . ' to be renamed to NEWNAMEGOESHERE' . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch rename table for ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->rename_table($table, ' . "'NEWNAMEGOESHERE'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -38,10 +38,10 @@ class view_structure_sql extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'selectdb' => 'tool_xmldb',
|
||||
'back' => 'tool_xmldb'
|
||||
@@ -58,19 +58,19 @@ class view_structure_sql extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $DB;
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -80,9 +80,8 @@ class view_structure_sql extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
$b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
@@ -90,7 +89,7 @@ class view_structure_sql extends XMLDBAction {
|
||||
|
||||
$o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||
/// Get an array of statements
|
||||
// Get an array of statements
|
||||
if ($starr = $DB->get_manager()->generator->getCreateStructureSQL($structure)) {
|
||||
$starr = $dbman->generator->getEndedStatements($starr);
|
||||
$sqltext = '';
|
||||
@@ -105,12 +104,12 @@ class view_structure_sql extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ class view_structure_xml extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,21 +56,21 @@ class view_structure_xml extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_XML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the file parameter
|
||||
// Get the file parameter
|
||||
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if ($select == 'original') {
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$base =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -84,7 +84,7 @@ class view_structure_xml extends XMLDBAction {
|
||||
$result = false;
|
||||
}
|
||||
if ($base) {
|
||||
/// Only if the directory exists and it has been loaded
|
||||
// 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;
|
||||
@@ -94,7 +94,7 @@ class view_structure_xml extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Get the structure
|
||||
// Get the structure
|
||||
if ($result) {
|
||||
if (!$structure =& $base->xml_file->getStructure()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||
@@ -103,14 +103,14 @@ class view_structure_xml extends XMLDBAction {
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
/// Everything is ok. Generate the XML output
|
||||
// Everything is ok. Generate the XML output
|
||||
$this->output = $structure->xmlOutput();
|
||||
} else {
|
||||
/// Switch to HTML and error
|
||||
// Switch to HTML and error
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ class view_table_php extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'selectaction' => 'tool_xmldb',
|
||||
'selectfieldkeyindex' => 'tool_xmldb',
|
||||
@@ -66,18 +66,18 @@ class view_table_php extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $OUTPUT;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -87,7 +87,6 @@ class view_table_php extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
$tableparam = required_param('table', PARAM_PATH);
|
||||
|
||||
@@ -101,25 +100,25 @@ class view_table_php extends XMLDBAction {
|
||||
$keys = $table->getKeys();
|
||||
$indexes = $table->getIndexes();
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$commandparam = optional_param('command', 'add_field', PARAM_PATH);
|
||||
$origfieldkeyindexparam = optional_param('fieldkeyindex', $defaultfieldkeyindex, PARAM_PATH);
|
||||
$fieldkeyindexparam = preg_replace('/[fki]#/i', '', $origfieldkeyindexparam); ///Strip the initials
|
||||
$fieldkeyindexparam = preg_replace('/[fki]#/i', '', $origfieldkeyindexparam); // Strip the initials
|
||||
$fieldkeyindexinitial = substr($origfieldkeyindexparam, 0, 1); //To know what we have selected
|
||||
|
||||
/// The back to edit xml button
|
||||
// The back to edit xml button
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
$b .= '<a href="index.php?action=edit_table&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&table=' . $tableparam . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o = $b;
|
||||
|
||||
/// The table currently being edited
|
||||
// The table currently being edited
|
||||
$o .= '<h3 class="main">' . $this->str['table'] . ': ' . s($tableparam) . '</h3>';
|
||||
|
||||
/// To indent the menu selections
|
||||
// To indent the menu selections
|
||||
$optionspacer = ' ';
|
||||
|
||||
/// Calculate the popup of commands
|
||||
// Calculate the popup of commands
|
||||
$commands = array('Fields',
|
||||
$optionspacer . 'add_field',
|
||||
$optionspacer . 'drop_field',
|
||||
@@ -129,7 +128,7 @@ class view_table_php extends XMLDBAction {
|
||||
$optionspacer . 'change_field_unsigned',
|
||||
$optionspacer . 'change_field_notnull',
|
||||
$optionspacer . 'change_field_default',
|
||||
$optionspacer . 'drop_enum_from_field', /// TODO: Moodle 2.1 - Drop drop_enum_from_field
|
||||
$optionspacer . 'drop_enum_from_field', // TODO: Moodle 2.1 - Drop drop_enum_from_field
|
||||
'Keys',
|
||||
$optionspacer . 'add_key',
|
||||
$optionspacer . 'drop_key',
|
||||
@@ -141,7 +140,7 @@ class view_table_php extends XMLDBAction {
|
||||
foreach ($commands as $command) {
|
||||
$popcommands[str_replace($optionspacer, '', $command)] = str_replace('_', ' ', $command);
|
||||
}
|
||||
/// Calculate the popup of fields/keys/indexes
|
||||
// Calculate the popup of fields/keys/indexes
|
||||
if ($fields) {
|
||||
$popfields['fieldshead'] = 'Fields';
|
||||
foreach ($fields as $field) {
|
||||
@@ -161,7 +160,7 @@ class view_table_php extends XMLDBAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Now build the form
|
||||
// Now build the form
|
||||
$o.= '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
@@ -175,14 +174,14 @@ class view_table_php extends XMLDBAction {
|
||||
|
||||
$o.= ' <table id="phpcode" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||
/// Check we have selected some field/key/index from the popup
|
||||
// Check we have selected some field/key/index from the popup
|
||||
if ($fieldkeyindexparam == 'fieldshead' || $fieldkeyindexparam == 'keyshead' || $fieldkeyindexparam == 'indexeshead') {
|
||||
$o.= s($this->str['selectonefieldkeyindex']);
|
||||
/// Check we have selected some command from the popup
|
||||
// Check we have selected some command from the popup
|
||||
} else if ($commandparam == 'Fields' || $commandparam == 'Keys' || $commandparam == 'Indexes') {
|
||||
$o.= s($this->str['selectonecommand']);
|
||||
} else {
|
||||
/// Based on current params, call the needed function
|
||||
// Based on current params, call the needed function
|
||||
switch ($commandparam) {
|
||||
case 'add_field':
|
||||
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
|
||||
@@ -227,63 +226,63 @@ class view_table_php extends XMLDBAction {
|
||||
}
|
||||
break;
|
||||
case 'change_field_notnull':
|
||||
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
|
||||
if ($fieldkeyindexinitial == 'f') { // Only if we have got one field
|
||||
$o.= s($this->change_field_notnull_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectonefield'];
|
||||
}
|
||||
break;
|
||||
case 'drop_enum_from_field': /// TODO: Moodle 2.1 - Drop drop_enum_from_field
|
||||
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
|
||||
case 'drop_enum_from_field': // TODO: Moodle 2.1 - Drop drop_enum_from_field
|
||||
if ($fieldkeyindexinitial == 'f') { // Only if we have got one field
|
||||
$o.= s($this->drop_enum_from_field_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectonefield'];
|
||||
}
|
||||
break;
|
||||
case 'change_field_default':
|
||||
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
|
||||
if ($fieldkeyindexinitial == 'f') { // Only if we have got one field
|
||||
$o.= s($this->change_field_default_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectonefield'];
|
||||
}
|
||||
break;
|
||||
case 'add_key':
|
||||
if ($fieldkeyindexinitial == 'k') { //Only if we have got one key
|
||||
if ($fieldkeyindexinitial == 'k') { // Only if we have got one key
|
||||
$o.= s($this->add_key_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectonekey'];
|
||||
}
|
||||
break;
|
||||
case 'drop_key':
|
||||
if ($fieldkeyindexinitial == 'k') { //Only if we have got one key
|
||||
if ($fieldkeyindexinitial == 'k') { // Only if we have got one key
|
||||
$o.= s($this->drop_key_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectonekey'];
|
||||
}
|
||||
break;
|
||||
case 'rename_key':
|
||||
if ($fieldkeyindexinitial == 'k') { //Only if we have got one key
|
||||
if ($fieldkeyindexinitial == 'k') { // Only if we have got one key
|
||||
$o.= s($this->rename_key_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectonekey'];
|
||||
}
|
||||
break;
|
||||
case 'add_index':
|
||||
if ($fieldkeyindexinitial == 'i') { //Only if we have got one index
|
||||
if ($fieldkeyindexinitial == 'i') { // Only if we have got one index
|
||||
$o.= s($this->add_index_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectoneindex'];
|
||||
}
|
||||
break;
|
||||
case 'drop_index':
|
||||
if ($fieldkeyindexinitial == 'i') { //Only if we have got one index
|
||||
if ($fieldkeyindexinitial == 'i') { // Only if we have got one index
|
||||
$o.= s($this->drop_index_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectoneindex'];
|
||||
}
|
||||
break;
|
||||
case 'rename_index':
|
||||
if ($fieldkeyindexinitial == 'i') { //Only if we have got one index
|
||||
if ($fieldkeyindexinitial == 'i') { // Only if we have got one index
|
||||
$o.= s($this->rename_index_php($structure, $tableparam, $fieldkeyindexparam));
|
||||
} else {
|
||||
$o.= $this->str['mustselectoneindex'];
|
||||
@@ -296,12 +295,12 @@ class view_table_php extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -317,7 +316,7 @@ class view_table_php extends XMLDBAction {
|
||||
function add_field_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -328,26 +327,26 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define field ' . $field->getName() . ' to be added to ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Conditionally launch add field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' if (!$dbman->field_exists($table, $field)) {'. XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->add_field($table, $field);' . XMLDB_LINEFEED;
|
||||
$result .= ' }'. XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -365,7 +364,7 @@ class view_table_php extends XMLDBAction {
|
||||
function drop_field_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -376,26 +375,26 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define field ' . $field->getName() . ' to be dropped from ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Conditionally launch drop field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' if ($dbman->field_exists($table, $field)) {' . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->drop_field($table, $field);' . XMLDB_LINEFEED;
|
||||
$result .= ' }' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -413,7 +412,7 @@ class view_table_php extends XMLDBAction {
|
||||
function rename_field_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -424,24 +423,24 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Rename field ' . $field->getName() . ' on table ' . $table->getName() . ' to NEWNAMEGOESHERE'. XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch rename field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->rename_field($table, $field, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -465,7 +464,7 @@ class view_table_php extends XMLDBAction {
|
||||
function change_field_type_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -476,27 +475,27 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Calculate the type tip text
|
||||
// Calculate the type tip text
|
||||
$type = $field->getXMLDBTypeName($field->getType());
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Changing type of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $type . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch change of type for field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->change_field_type($table, $field);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -513,7 +512,7 @@ class view_table_php extends XMLDBAction {
|
||||
function change_field_precision_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -524,31 +523,31 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Calculate the precision tip text
|
||||
// Calculate the precision tip text
|
||||
$precision = '(' . $field->getLength();
|
||||
if ($field->getDecimals()) {
|
||||
$precision .= ', ' . $field->getDecimals();
|
||||
}
|
||||
$precision .= ')';
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Changing precision of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $precision . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " .$field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch change of precision for field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->change_field_precision($table, $field);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -565,7 +564,7 @@ class view_table_php extends XMLDBAction {
|
||||
function change_field_unsigned_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -576,27 +575,27 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Calculate the unsigned tip text
|
||||
// Calculate the unsigned tip text
|
||||
$unsigned = $field->getUnsigned() ? 'unsigned' : 'signed';
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Changing sign of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $unsigned . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch change of sign for field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->change_field_unsigned($table, $field);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -613,7 +612,7 @@ class view_table_php extends XMLDBAction {
|
||||
function change_field_notnull_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -624,27 +623,27 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Calculate the notnull tip text
|
||||
// Calculate the notnull tip text
|
||||
$notnull = $field->getNotnull() ? 'not null' : 'null';
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Changing nullability of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $notnull . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch change of nullability for field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->change_field_notnull($table, $field);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -667,7 +666,7 @@ class view_table_php extends XMLDBAction {
|
||||
function drop_enum_from_field_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -678,24 +677,24 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Drop list of values (enum) from field ' . $field->getName() . ' on table ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch drop of list of values from field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->drop_enum_from_field($table, $field);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -712,7 +711,7 @@ class view_table_php extends XMLDBAction {
|
||||
function change_field_default_php($structure, $table, $field) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -723,27 +722,27 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Calculate the default tip text
|
||||
// Calculate the default tip text
|
||||
$default = $field->getDefault() === null ? 'drop it' : $field->getDefault();
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Changing the default of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $default . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $field = new xmldb_field(' . "'" . $field->getName() . "', " . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch change of default for field ' . $field->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->change_field_default($table, $field);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -761,7 +760,7 @@ class view_table_php extends XMLDBAction {
|
||||
function add_key_php($structure, $table, $key) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -772,24 +771,24 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define key ' . $key->getName() . ' ('. $key->getXMLDBKeyName($key->getType()) . ') to be added to ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $key = new xmldb_key(' . "'" . $key->getName() . "', " . $key->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch add key ' . $key->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->add_key($table, $key);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -807,7 +806,7 @@ class view_table_php extends XMLDBAction {
|
||||
function drop_key_php($structure, $table, $key) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -818,24 +817,24 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define key ' . $key->getName() . ' ('. $key->getXMLDBKeyName($key->getType()) . ') to be dropped form ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $key = new xmldb_key(' . "'" . $key->getName() . "', " . $key->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch drop key ' . $key->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->drop_key($table, $key);' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -853,7 +852,7 @@ class view_table_php extends XMLDBAction {
|
||||
function rename_key_php($structure, $table, $key) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -864,27 +863,27 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Prepend warning. This function isn't usable!
|
||||
// Prepend warning. This function isn't usable!
|
||||
$result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define key ' . $key->getName() . ' ('. $key->getXMLDBKeyName($key->getType()) . ') to be renamed to NEWNAMEGOESHERE' . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $key = new xmldb_key(' . "'" . $key->getName() . "', " . $key->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch rename key ' . $key->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->rename_key($table, $key, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -902,7 +901,7 @@ class view_table_php extends XMLDBAction {
|
||||
function add_index_php($structure, $table, $index) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -913,26 +912,26 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define index ' . $index->getName() . ' ('. ($index->getUnique() ? 'unique' : 'not unique') . ') to be added to ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $index = new xmldb_index(' . "'" . $index->getName() . "', " . $index->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Conditionally launch add index ' . $index->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' if (!$dbman->index_exists($table, $index)) {' . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->add_index($table, $index);' . XMLDB_LINEFEED;
|
||||
$result .= ' }' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -950,7 +949,7 @@ class view_table_php extends XMLDBAction {
|
||||
function drop_index_php($structure, $table, $index) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -961,26 +960,26 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define index ' . $index->getName() . ' ('. ($index->getUnique() ? 'unique' : 'not unique') . ') to be dropped form ' . $table->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $index = new xmldb_index(' . "'" . $index->getName() . "', " . $index->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Conditionally launch drop index ' . $index->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' if ($dbman->index_exists($table, $index)) {' . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->drop_index($table, $index);' . XMLDB_LINEFEED;
|
||||
$result .= ' }' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
@@ -998,7 +997,7 @@ class view_table_php extends XMLDBAction {
|
||||
function rename_index_php($structure, $table, $index) {
|
||||
|
||||
$result = '';
|
||||
/// Validate if we can do it
|
||||
// Validate if we can do it
|
||||
if (!$table = $structure->getTable($table)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1009,27 +1008,27 @@ class view_table_php extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Prepend warning. This function isn't usable!
|
||||
// Prepend warning. This function isn't usable!
|
||||
$result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the standard PHP header
|
||||
// Add the standard PHP header
|
||||
$result .= XMLDB_PHP_HEADER;
|
||||
|
||||
/// Add contents
|
||||
// Add contents
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Define index ' . $index->getName() . ' ('. ($index->getUnique() ? 'unique' : 'not unique') . ') to be renamed to NEWNAMEGOESHERE' . XMLDB_LINEFEED;
|
||||
$result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
|
||||
$result .= ' $index = new xmldb_index(' . "'" . $index->getName() . "', " . $index->getPHP(true) . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Launch the proper DDL
|
||||
// Launch the proper DDL
|
||||
$result .= XMLDB_LINEFEED;
|
||||
$result .= ' // Launch rename index ' . $index->getName() . XMLDB_LINEFEED;
|
||||
$result .= ' $dbman->rename_index($table, $index, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;
|
||||
|
||||
/// Add the proper upgrade_xxxx_savepoint call
|
||||
// Add the proper upgrade_xxxx_savepoint call
|
||||
$result .= $this->upgrade_savepoint_php ($structure);
|
||||
|
||||
/// Add standard PHP footer
|
||||
// Add standard PHP footer
|
||||
$result .= XMLDB_PHP_FOOTER;
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -1,34 +1,30 @@
|
||||
/// $Id $
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @package tool
|
||||
* @subpackage xmldb
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/// Register the needed events
|
||||
onload=function() {
|
||||
/// Adjust the form on load
|
||||
disablePopupHeads();
|
||||
}
|
||||
// Register the needed events
|
||||
onload=function() {
|
||||
// Adjust the form on load
|
||||
disablePopupHeads();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function disables some elements from the command and from the fields/keys/indexes drop downs
|
||||
|
||||
@@ -38,10 +38,10 @@ class view_table_sql extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'selectdb' => 'tool_xmldb',
|
||||
'back' => 'tool_xmldb'
|
||||
@@ -58,19 +58,19 @@ class view_table_sql extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB, $DB;
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
// 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
|
||||
// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
@@ -80,16 +80,15 @@ class view_table_sql extends XMLDBAction {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Get parameters
|
||||
// Get parameters
|
||||
$tableparam = required_param('table', PARAM_PATH);
|
||||
if (!$table = $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparam;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// The back to edit table button
|
||||
// The back to edit table button
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
$b .= '<a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
@@ -98,7 +97,7 @@ class view_table_sql extends XMLDBAction {
|
||||
$o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||
|
||||
/// Get an array of statements
|
||||
// Get an array of statements
|
||||
if ($starr = $DB->get_manager()->generator->getCreateTableSQL($table)) {
|
||||
$starr = $dbman->generator->getEndedStatements($starr);
|
||||
$sqltext = '';
|
||||
@@ -113,12 +112,12 @@ class view_table_sql extends XMLDBAction {
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ class view_table_xml extends XMLDBAction {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,22 +56,22 @@ class view_table_xml extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_XML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the file parameter
|
||||
// Get the file parameter
|
||||
$table = required_param('table', PARAM_CLEAN);
|
||||
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||
/// Get the dir containing the file
|
||||
// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . $dirpath;
|
||||
|
||||
/// Get the correct dir
|
||||
// Get the correct dir
|
||||
if ($select == 'original') {
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$base =& $XMLDB->dbdirs[$dirpath];
|
||||
@@ -85,7 +85,7 @@ class view_table_xml extends XMLDBAction {
|
||||
$result = false;
|
||||
}
|
||||
if ($base) {
|
||||
/// Only if the directory exists and it has been loaded
|
||||
// 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;
|
||||
@@ -95,35 +95,35 @@ class view_table_xml extends XMLDBAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Get the structure
|
||||
// Get the structure
|
||||
if ($result) {
|
||||
if (!$structure =& $base->xml_file->getStructure()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the tables
|
||||
// Get the tables
|
||||
if ($result) {
|
||||
if (!$tables =& $structure->getTables()) {
|
||||
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
/// Get the table
|
||||
// Get the table
|
||||
if ($result && !$t =& $structure->getTable($table)) {
|
||||
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
/// Everything is ok. Generate the XML output
|
||||
// Everything is ok. Generate the XML output
|
||||
$this->output = $t->xmlOutput();
|
||||
} else {
|
||||
/// Switch to HTML and error
|
||||
// Switch to HTML and error
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,16 +36,16 @@ class view_xml extends XMLDBAction {
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->can_subaction = ACTION_NONE;
|
||||
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||
|
||||
/// Set own custom attributes
|
||||
// Set own custom attributes
|
||||
$this->sesskey_protected = false; // This action doesn't need sesskey protection
|
||||
|
||||
/// Get needed strings
|
||||
// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -59,31 +59,31 @@ class view_xml extends XMLDBAction {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_XML;
|
||||
|
||||
/// These are always here
|
||||
// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
// Do the job, setting result as needed
|
||||
|
||||
/// Get the file parameter
|
||||
// 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)
|
||||
// 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
|
||||
// Everything is ok. Load the file to memory
|
||||
$this->output = file_get_contents($file);
|
||||
} else {
|
||||
/// Switch to HTML and error
|
||||
// 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 ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -28,64 +28,64 @@
|
||||
require('../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/ddllib.php');
|
||||
/// Add required XMLDB action classes
|
||||
// Add required XMLDB action classes
|
||||
require_once('actions/XMLDBAction.class.php');
|
||||
require_once('actions/XMLDBCheckAction.class.php');
|
||||
|
||||
|
||||
admin_externalpage_setup('toolxmld');
|
||||
|
||||
/// Add other used libraries
|
||||
// Add other used libraries
|
||||
require_once($CFG->libdir . '/xmlize.php');
|
||||
|
||||
/// Handle session data
|
||||
// Handle session data
|
||||
global $XMLDB;
|
||||
|
||||
/// State is stored in session - we have to serialise it because the classes are not loaded when creating session
|
||||
// State is stored in session - we have to serialise it because the classes are not loaded when creating session
|
||||
if (!isset($SESSION->xmldb)) {
|
||||
$XMLDB = new stdClass;
|
||||
} else {
|
||||
$XMLDB = unserialize($SESSION->xmldb);
|
||||
}
|
||||
|
||||
/// Some previous checks
|
||||
// Some previous checks
|
||||
$site = get_site();
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
|
||||
/// Body of the script, based on action, we delegate the work
|
||||
// Body of the script, based on action, we delegate the work
|
||||
$action = optional_param ('action', 'main_view', PARAM_ALPHAEXT);
|
||||
|
||||
/// Get the action path and invoke it
|
||||
// Get the action path and invoke it
|
||||
$actionsroot = "$CFG->dirroot/$CFG->admin/tool/xmldb/actions";
|
||||
$actionclass = $action . '.class.php';
|
||||
$actionpath = "$actionsroot/$action/$actionclass";
|
||||
|
||||
/// Load and invoke the proper action
|
||||
// Load and invoke the proper action
|
||||
if (file_exists($actionpath) && is_readable($actionpath)) {
|
||||
require_once($actionpath);
|
||||
if ($xmldb_action = new $action) {
|
||||
//Invoke it
|
||||
// Invoke it
|
||||
$result = $xmldb_action->invoke();
|
||||
// store the result in session
|
||||
$SESSION->xmldb = serialize($XMLDB);
|
||||
|
||||
if ($result) {
|
||||
/// Based on getDoesGenerate()
|
||||
// Based on getDoesGenerate()
|
||||
switch ($xmldb_action->getDoesGenerate()) {
|
||||
case ACTION_GENERATE_HTML:
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHAEXT);
|
||||
$postaction = optional_param('postaction', '', PARAM_ALPHAEXT);
|
||||
/// If the js exists, load it
|
||||
// If the js exists, load it
|
||||
if ($action) {
|
||||
$script = $CFG->admin . '/tool/xmldb/actions/' . $action . '/' . $action . '.js';
|
||||
$file = $CFG->dirroot . '/' . $script;
|
||||
if (file_exists($file) && is_readable($file)) {
|
||||
$PAGE->requires->js('/'.$script);
|
||||
} else if ($postaction) {
|
||||
/// Try to load the postaction javascript if exists
|
||||
// Try to load the postaction javascript if exists
|
||||
$script = $CFG->admin . '/tool/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
|
||||
$file = $CFG->dirroot . '/' . $script;
|
||||
if (file_exists($file) && is_readable($file)) {
|
||||
@@ -94,7 +94,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// Go with standard admin header
|
||||
// Go with standard admin header
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($xmldb_action->getTitle());
|
||||
echo $xmldb_action->getOutput();
|
||||
@@ -106,7 +106,7 @@
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
//TODO: need more detailed error info
|
||||
// TODO: need more detailed error info
|
||||
print_error('xmldberror');
|
||||
}
|
||||
} else {
|
||||
@@ -121,6 +121,6 @@
|
||||
|
||||
if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) {
|
||||
if (debugging()) {
|
||||
///print_object($XMLDB);
|
||||
// print_object($XMLDB);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user