Merge remote branch 'origin/master' into rubric

Conflicts:
	lib/db/install.xml
	lib/db/upgrade.php
	version.php
This commit is contained in:
David Mudrak 2011-10-07 22:01:38 +02:00
commit e8004aadc8
1347 changed files with 6330 additions and 4460 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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>';

View File

@ -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>';

View File

@ -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>';

View File

@ -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>';

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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>&nbsp;</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 .= '&nbsp;<a href="index.php?action=view_field_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;field=' . $fieldparam . '">[' . $this->str['vieworiginal'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
}
/// The view edited XML button
// The view edited XML button
if ($field->hasChanged()) {
$b .= '&nbsp;<a href="index.php?action=view_field_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;field=' . $fieldparam . '">[' . $this->str['viewedited'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['viewedited'] . ']';
}
/// The back to edit table button
// The back to edit table button
$b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;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;
}
}

View File

@ -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';
@ -93,13 +86,17 @@ function transformForm(event) {
case '2': // XMLDB_TYPE_NUMBER
lengthTip.innerHTML = ' 1...20';
decimalsTip.innerHTML = ' 0...length or empty';
unsignedField.disabled = true;
unsignedField.value = '0';
break;
case '3': // XMLDB_TYPE_FLOAT
lengthTip.innerHTML = ' 1...20 or empty';
decimalsTip.innerHTML = ' 0...length or empty';
unsignedField.disabled = true;
unsignedField.value = '0';
break;
case '4': // XMLDB_TYPE_CHAR
lengthTip.innerHTML = ' 1...'.xmldb_field::CHAR_MAX_LENGTH;
lengthTip.innerHTML = ' 1...1333'; // Hardcoded, yes!
decimalsTip.innerHTML = '';
decimalsField.disabled = true;
decimalsField.value = '';

View File

@ -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&amp;field=' . $field->getName() . '&amp;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;
}
}

View File

@ -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>&nbsp;</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 .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['vieworiginal'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
}
/// The view edited XML button
// The view edited XML button
if ($index->hasChanged()) {
$b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['viewedited'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['viewedited'] . ']';
}
/// The back to edit table button
// The back to edit table button
$b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;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;
}
}

View File

@ -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&amp;index=' .$index->getName() . '&amp;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;
}
}

View File

@ -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>&nbsp;</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 .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['vieworiginal'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
}
/// The view edited XML button
// The view edited XML button
if ($key->hasChanged()) {
$b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['viewedited'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['viewedited'] . ']';
}
/// The back to edit table button
// The back to edit table button
$b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;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;
}
}

View File

@ -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

View File

@ -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&amp;key=' .$key->getName() . '&amp;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;
}
}

View File

@ -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>&nbsp;</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 .= '&nbsp;<a href="index.php?action=view_table_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '">[' . $this->str['vieworiginal'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
}
/// The view edited XML button
// The view edited XML button
if ($table->hasChanged()) {
$b .= '&nbsp;<a href="index.php?action=view_table_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '">[' . $this->str['viewedited'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['viewedited'] . ']';
}
/// The new field button
// The new field button
$b .= '&nbsp;<a href="index.php?action=new_field&amp;sesskey=' . sesskey() . '&amp;postaction=edit_field&amp;table=' . $tableparam . '&amp;field=changeme&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newfield'] . ']</a>';
/// The new key button
// The new key button
$b .= '&nbsp;<a href="index.php?action=new_key&amp;sesskey=' . sesskey() . '&amp;postaction=edit_key&amp;table=' . $tableparam . '&amp;key=changeme&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newkey'] . ']</a>';
/// The new index button
// The new index button
$b .= '&nbsp;<a href="index.php?action=new_index&amp;sesskey=' . sesskey() . '&amp;postaction=edit_index&amp;table=' . $tableparam . '&amp;index=changeme&amp;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&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>';
/// The view php code button
// The view php code button
$b .= '&nbsp;<a href="index.php?action=view_table_php&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>';
/// The save button (if possible)
// The save button (if possible)
if ($cansavenow) {
$b .= '&nbsp;<a href="index.php?action=save_xml_file&amp;sesskey=' . sesskey() . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;time=' . time() . '&amp;unload=false&amp;postaction=edit_table&amp;table=' . $tableparam . '&amp;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 .= '&nbsp;<a href="index.php?action=edit_xml_file&amp;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&amp;field=' .$field->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;field=' .$field->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;direction=up&amp;sesskey=' . sesskey() . '&amp;field=' . $field->getName() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_table' . '&amp;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&amp;direction=down&amp;sesskey=' . sesskey() . '&amp;field=' . $field->getName() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_table' . '&amp;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&amp;sesskey=' . sesskey() . '&amp;field=' . $field->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;field=' . $field->getName() . '&amp;table=' . $table->getName() . '&amp;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 .= '&nbsp;<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&amp;key=' .$key->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;key=' .$key->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;direction=up&amp;sesskey=' . sesskey() . '&amp;key=' . $key->getName() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_table' . '&amp;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&amp;direction=down&amp;sesskey=' . sesskey() . '&amp;key=' . $key->getName() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_table' . '&amp;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&amp;sesskey=' . sesskey() . '&amp;key=' . $key->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;key=' . $key->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;index=' .$index->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;index=' .$index->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;direction=up&amp;sesskey=' . sesskey() . '&amp;index=' . $index->getName() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_table' . '&amp;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&amp;direction=down&amp;sesskey=' . sesskey() . '&amp;index=' . $index->getName() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_table' . '&amp;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&amp;sesskey=' . sesskey() . '&amp;index=' . $index->getName() . '&amp;table=' . $table->getName() . '&amp;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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;index=' . $index->getName() . '&amp;table=' . $table->getName() . '&amp;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;
}
}

View File

@ -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&amp;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;
}
}

View File

@ -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>&nbsp;</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 .= '&nbsp;<a href="index.php?action=view_structure_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original">[' . $this->str['vieworiginal'] . ']</a>';
/// The view edited XML button
// The view edited XML button
if ($structure->hasChanged()) {
$b .= '&nbsp;<a href="index.php?action=view_structure_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited">[' . $this->str['viewedited'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['viewedited'] . ']';
}
/// The new table button
// The new table button
$b .= '&nbsp;<a href="index.php?action=new_table&amp;sesskey=' . sesskey() . '&amp;postaction=edit_table&amp;table=changeme&amp;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 .= '&nbsp;<a href="index.php?action=new_table_from_mysql&amp;sesskey=' . sesskey() . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newtablefrommysql'] . ']</a>';
} else {
$b .= '&nbsp;[' . $this->str['newtablefrommysql'] . ']';
}
/// The view sql code button
// The view sql code button
$b .= '<a href="index.php?action=view_structure_sql&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>';
/// The view php code button
// The view php code button
$b .= '&nbsp;<a href="index.php?action=view_structure_php&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>';
/// The save button (if possible)
// The save button (if possible)
if ($cansavenow) {
$b .= '&nbsp;<a href="index.php?action=save_xml_file&amp;sesskey=' . sesskey() . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;time=' . time() . '&amp;unload=false&amp;postaction=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['save'] . ']</a>';
}
/// The back to main menu button
// The back to main menu button
$b .= '&nbsp;<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&amp;table=' . $table->getName() . '&amp;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&amp;table=' . $table->getName() . '&amp;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&amp;direction=up&amp;sesskey=' . sesskey() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_xml_file' . '&amp;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&amp;direction=down&amp;sesskey=' . sesskey() . '&amp;table=' . $table->getName() . '&amp;postaction=edit_xml_file' . '&amp;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&amp;sesskey=' . sesskey() . '&amp;table=' . $table->getName() . '&amp;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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;table=' . $table->getName() . '&amp;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 .= '&nbsp;<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());
}

View File

@ -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;
}
}

View File

@ -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 .= '&nbsp;<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());
}

View File

@ -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 .= '&nbsp;<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());
}

View File

@ -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;
}
}

View File

@ -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());
}

View File

@ -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;

View File

@ -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 .= '&nbsp;<a href="index.php?action=view_reserved_words">[' . $this->str['reservedwords'] . ']</a>';
/// The docs button
// The docs button
$b .= '&nbsp;<a href="index.php?action=generate_all_documentation">[' . $this->str['doc'] . ']</a>';
/// The check indexes button
// The check indexes button
$b .= '&nbsp;<a href="index.php?action=check_indexes&amp;sesskey=' . sesskey() . '">[' . $this->str['checkindexes'] . ']</a>';
/// The check defaults button
// The check defaults button
$b .= '&nbsp;<a href="index.php?action=check_defaults&amp;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 .= '&nbsp;<a href="index.php?action=check_bigints&amp;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 .= '&nbsp;<a href="index.php?action=check_oracle_semantics&amp;sesskey=' . sesskey() . '">[' . $this->str['checkoraclesemantics'] . ']</a>';
}
$b .= '&nbsp;<a href="index.php?action=check_foreign_keys&amp;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&amp;sesskey=' . sesskey() . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&amp;time=' . time() . '&amp;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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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&amp;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;

View File

@ -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&amp;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;
}
}

View File

@ -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;
}
}

View File

@ -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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;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 = '&nbsp;&nbsp;&nbsp;';
/// 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;

View File

@ -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

View File

@ -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&amp;table=' . $tableparam . '&amp;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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -73,7 +73,7 @@ class backup_course_task extends backup_task {
$this->add_step(new backup_course_structure_step('course_info', 'course.xml'));
// Generate the enrolment file (conditionally, prevent it in any IMPORT/HUB operation)
if (!$this->plan->get_mode() == backup::MODE_IMPORT && !$this->plan->get_mode() == backup::MODE_HUB) {
if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) {
$this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
}

View File

@ -70,7 +70,7 @@ class restore_course_task extends restore_task {
$this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml'));
// Restore course enrolments (plugins and membership). Conditionally prevented for any IMPORT/HUB operation
if (!$this->plan->get_mode() == backup::MODE_IMPORT && !$this->plan->get_mode() == backup::MODE_HUB) {
if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) {
$this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
}

View File

@ -123,14 +123,24 @@ abstract class backup_cron_automated_helper {
$backupcourse = $DB->get_record('backup_courses', array('courseid'=>$course->id));
}
// Skip courses that do not yet need backup
$skipped = !(($backupcourse->nextstarttime >= 0 && $backupcourse->nextstarttime < $now) || $rundirective == self::RUN_IMMEDIATELY);
// Skip backup of unavailable courses that have remained unmodified in a month
$skipped = false;
if (empty($course->visible) && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + unmodified last month
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
$DB->update_record('backup_courses', $backupcourse);
mtrace('Skipping unchanged course '.$course->fullname);
$skipped = true;
} else if (($backupcourse->nextstarttime >= 0 && $backupcourse->nextstarttime < $now) || $rundirective == self::RUN_IMMEDIATELY) {
if (!$skipped && empty($course->visible) && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + settings were unmodified last month
//Check log if there were any modifications to the course content
$sqlwhere = "course=:courseid AND time>:time AND ". $DB->sql_like('action', ':action', false, true, true);
$params = array('courseid' => $course->id, 'time' => $now-31*24*60*60, 'action' => '%view%');
$logexists = $DB->record_exists_select('log', $sqlwhere, $params);
if (!$logexists) {
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
$backupcourse->nextstarttime = $nextstarttime;
$DB->update_record('backup_courses', $backupcourse);
mtrace('Skipping unchanged course '.$course->fullname);
$skipped = true;
}
}
//Now we backup every non-skipped course
if (!$skipped) {
mtrace('Backing up '.$course->fullname, '...');
//We have to send a email because we have included at least one backup

View File

@ -46,6 +46,7 @@ class block_search extends block_base {
'<form id="searchquery" method="get" action="'. $CFG->wwwroot .'/search/query.php"><div>'
. '<label for="block_search_q">' . get_string('searchmoodle', 'block_search') . '</label>'
. '<input id="block_search_q" type="text" name="query_string" />'
. '<input id="block_instance_id" type="hidden" name="block_instanceid" value="' . $this->instance->id . '"/>'
. '<input type="submit" value="' . s(get_string('go', 'block_search')) . '" />'
. '</div></form>';

View File

@ -2265,7 +2265,9 @@ function print_category_info($category, $depth=0, $showcourses = false) {
echo '<div class="categorylist">';
$html = '';
$cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss);
$cat .= html_writer::tag('span', ' ('.count($courses).')', array('title'=>get_string('numberofcourses'), 'class'=>'numberofcourse'));
if (count($courses) > 0) {
$cat .= html_writer::tag('span', ' ('.count($courses).')', array('title'=>get_string('numberofcourses'), 'class'=>'numberofcourse'));
}
if ($depth > 0) {
for ($i=0; $i< $depth; $i++) {

View File

@ -32,7 +32,6 @@ class grade_import_form extends moodleform {
$mform->setType('id', PARAM_INT);
$mform->addElement('header', 'general', get_string('importfile', 'grades'));
$mform->disabledIf('url', 'userfile', 'noteq', '');
$mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades'));
$mform->setDefault('feedback', 0);
@ -42,6 +41,7 @@ class grade_import_form extends moodleform {
$mform->disabledIf('userfile', 'url', 'noteq', '');
$mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"');
$mform->disabledIf('url', 'userfile', 'noteq', '');
if (!empty($CFG->gradepublishing)) {
$mform->addElement('header', 'publishing', get_string('publishing', 'grades'));

View File

@ -31,5 +31,6 @@
$string['clianswerno'] = 'Не';
$string['cliansweryes'] = 'Да';
$string['cliincorrectvalueretry'] = 'Неправилна стойност. Моля опитайте отново';
$string['clitypevalue'] = 'Тип стойност';
$string['environmentrequireinstall'] = 'Трябва да бъде инсталиран и разрешен';
$string['environmentrequireversion'] = 'Необходима е версия {$a->needed} а Вие имате {$a->current}';

View File

@ -30,3 +30,4 @@
$string['cannotcreatetempdir'] = 'Не може да създаде временна директория';
$string['cannotfindcomponent'] = 'Не можа да намери компонент';
$string['remotedownloaderror'] = 'Изтеглянето на компонента към вашия сървър пропадна, проверете настройките на proxy, препоръчително е PHP разширението cURL.<br /><br />Вие трябва ръчно да изтеглите файла <a href="{$a->url}">{$a->url}</a>, да го копирате в директория {$a->dest} на вашия сървър и да го разархивирате там.';

View File

@ -38,6 +38,7 @@ $string['dataroot'] = 'Директория за данни';
$string['dbprefix'] = 'Представка на таблиците';
$string['dirroot'] = 'Директория на Moodle';
$string['installation'] = 'Инсталиране';
$string['langdownloaderror'] = 'За съжаление езикът "{$a}" не може да бъде изтеглен. Инсталирането ще продължи на английски.';
$string['paths'] = 'Пътища';
$string['pathshead'] = 'Потвърждаване на пътищата';
$string['pathssubdataroot'] = 'Тази директория е място, където Moodle, записва качваните файлове. Тази директория трябва да е достъпна за четене И ЗА ЗАПИС от потребителя на интернет сървъра (обикновено \'nobody\' или \'apache\'), но не трябва да е достъпна пряко през Интернет. Инталаторът ще се опита да създаде директорията, ако тя не съществува.';

View File

@ -31,7 +31,7 @@
$string['cannotcreatelangdir'] = 'Не удается создать каталог языка';
$string['cannotcreatetempdir'] = 'Не удается создать временный каталог';
$string['cannotdownloadcomponents'] = 'Невозможно загрузить компоненты.';
$string['cannotdownloadzipfile'] = 'Не удалось загрузить ZIP файл';
$string['cannotdownloadzipfile'] = 'Не удалось загрузить ZIP-файл';
$string['cannotfindcomponent'] = 'Не удалось найти компонент';
$string['cannotsavemd5file'] = 'Не удалось сохранить MD5-файл';
$string['cannotsavezipfile'] = 'Не удалось сохранить ZIP-файл';
@ -40,6 +40,7 @@ $string['componentisuptodate'] = 'Компонент не нуждается в
$string['downloadedfilecheckfailed'] = 'Ошибка проверки загруженного файла';
$string['invalidmd5'] = 'Некорректная md5';
$string['missingrequiredfield'] = 'Отсутствуют некоторые обязательные поля';
$string['remotedownloaderror'] = 'Не удалось загрузить компонент на сервер, проверьте настройки прокси-сервера, настоятельно рекомендуется установка расширения cURL языка PHP.<br /> <br />Вам следует вручную загрузить файл по ссылке <a href="{$a->url}">{$a->url}</a>, скопировать его в папку "{$a->dest}" на своём сервере и там его распаковать.';
$string['wrongdestpath'] = 'Ошибочный путь назначения';
$string['wrongsourcebase'] = 'Ошибочный источник базового URL';
$string['wrongzipfilename'] = 'Неверное имя ZIP-файла';

View File

@ -63,6 +63,7 @@ $string['runindexertest'] = 'Run indexer test';
$string['score'] = 'Score';
$string['search'] = 'Search';
$string['searching'] = 'Searching in ...';
$string['searchnotpermitted'] = 'You are not allowed to do a search';
$string['seconds'] = 'seconds';
$string['solutions'] = 'Solutions';
$string['statistics'] = 'Statistics';

View File

@ -1820,7 +1820,8 @@
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The short name or code for this outcome statement" PREVIOUS="courseid" NEXT="fullname"/>
<FIELD NAME="fullname" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" COMMENT="The full description of the outcome (usually 1 sentence)" PREVIOUS="shortname" NEXT="scaleid"/>
<FIELD NAME="scaleid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The recommended scale for this outcome." PREVIOUS="fullname" NEXT="description"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Outcome description" PREVIOUS="scaleid"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Outcome description" PREVIOUS="scaleid" NEXT="descriptionformat"/>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="oldid"/>
@ -1851,7 +1852,8 @@
<FIELD NAME="droplow" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Drop the X lowest items" PREVIOUS="keephigh" NEXT="aggregateonlygraded"/>
<FIELD NAME="aggregateonlygraded" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="aggregate only graded items" PREVIOUS="droplow" NEXT="aggregateoutcomes"/>
<FIELD NAME="aggregateoutcomes" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Aggregate outcomes" PREVIOUS="aggregateonlygraded" NEXT="aggregatesubcats"/>
<FIELD NAME="aggregatesubcats" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="ignore subcategories in aggregation" PREVIOUS="aggregateoutcomes"/>
<FIELD NAME="aggregatesubcats" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="ignore subcategories in aggregation" PREVIOUS="aggregateoutcomes" NEXT="hidden"/>
<FIELD NAME="hidden" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="aggregatesubcats"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="oldid"/>
@ -1895,7 +1897,9 @@
<FIELD NAME="hidden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="1 is hidden, &amp;gt; 1 is a date to hide until (prevents viewing)" PREVIOUS="sortorder" NEXT="locked"/>
<FIELD NAME="locked" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="1 is locked, &amp;gt; 1 is a date to lock until (prevents update)" PREVIOUS="hidden" NEXT="locktime"/>
<FIELD NAME="locktime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="lock all final grades after this date" PREVIOUS="locked" NEXT="needsupdate"/>
<FIELD NAME="needsupdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="If this flag is set, then the whole column will be recalculated" PREVIOUS="locktime"/>
<FIELD NAME="needsupdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="If this flag is set, then the whole column will be recalculated" PREVIOUS="locktime" NEXT="display"/>
<FIELD NAME="display" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="needsupdate" NEXT="decimals"/>
<FIELD NAME="decimals" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="display"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="oldid"/>

View File

@ -6728,6 +6728,56 @@ FROM
upgrade_main_savepoint(true, 2011091600.01);
}
if ($oldversion < 2011092800.01) {
// Check for potential missing columns in the grade_items_history
$table = new xmldb_table('grade_items_history');
$field = new xmldb_field('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'sortorder');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, 'display');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
} else {
//check that the grade_items_history.decimals allows nulls
//Somehow some Moodle databases have this column marked as "not null"
$columns = $DB->get_columns('grade_items_history');
if (array_key_exists('display', $columns) && !empty($columns['display']->not_null)) {
$dbman->change_field_notnull($table, $field);
}
}
// Main savepoint reached
upgrade_main_savepoint(true, 2011092800.01);
}
if ($oldversion < 2011092800.02) {
// Check for potential missing columns in the grade_categories_history
$table = new xmldb_table('grade_categories_history');
$field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timemodified');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2011092800.02);
}
if ($oldversion < 2011092800.03) {
// Check for potential missing columns in the grade_outcomes_history
$table = new xmldb_table('grade_outcomes_history');
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'description');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2011092800.03);
}
if ($oldversion < 2011092900.00) {
// Create new core tables for the advanced grading subsystem
@ -6763,7 +6813,7 @@ FROM
$dbman->create_table($table);
}
$table = new xmldb_table('grading_instances');
$table = new xmldb_table('grading_instances');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('formid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('raterid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
@ -6786,4 +6836,3 @@ FROM
return true;
}

View File

@ -489,7 +489,7 @@ class mysqli_native_moodle_database extends moodle_database {
$info->unique = null;
}
} else if (preg_match('/(decimal|double|float)\((\d+),(\d+)\)/i', $rawcolumn->type, $matches)) {
} else if (preg_match('/(decimal)\((\d+),(\d+)\)/i', $rawcolumn->type, $matches)) {
$info->type = $matches[1];
$info->meta_type = 'N';
$info->max_length = $matches[2];
@ -503,6 +503,20 @@ class mysqli_native_moodle_database extends moodle_database {
$info->auto_increment= false;
$info->unique = null;
} else if (preg_match('/(double|float)(\((\d+),(\d+)\))?/i', $rawcolumn->type, $matches)) {
$info->type = $matches[1];
$info->meta_type = 'N';
$info->max_length = isset($matches[3]) ? $matches[3] : null;
$info->scale = isset($matches[4]) ? $matches[4] : null;
$info->not_null = ($rawcolumn->null === 'NO');
$info->default_value = $rawcolumn->default;
$info->has_default = is_null($info->default_value) ? false : true;
$info->primary_key = ($rawcolumn->key === 'PRI');
$info->binary = false;
$info->unsigned = (stripos($rawcolumn->type, 'unsigned') !== false);
$info->auto_increment= false;
$info->unique = null;
} else if (preg_match('/([a-z]*text)/i', $rawcolumn->type, $matches)) {
$info->type = $matches[1];
$info->meta_type = 'X';

View File

@ -415,7 +415,7 @@ class pgsql_native_moodle_database extends moodle_database {
$info->scale = null;
$info->not_null = ($rawcolumn->attnotnull === 't');
if ($info->has_default) {
$info->default_value = $rawcolumn->adsrc;
$info->default_value = trim($rawcolumn->adsrc, '()');
} else {
$info->default_value = null;
}
@ -433,7 +433,7 @@ class pgsql_native_moodle_database extends moodle_database {
$info->not_null = ($rawcolumn->attnotnull === 't');
$info->has_default = ($rawcolumn->atthasdef === 't');
if ($info->has_default) {
$info->default_value = $rawcolumn->adsrc;
$info->default_value = trim($rawcolumn->adsrc, '()');
} else {
$info->default_value = null;
}
@ -451,7 +451,7 @@ class pgsql_native_moodle_database extends moodle_database {
$info->not_null = ($rawcolumn->attnotnull === 't');
$info->has_default = ($rawcolumn->atthasdef === 't');
if ($info->has_default) {
$info->default_value = $rawcolumn->adsrc;
$info->default_value = trim($rawcolumn->adsrc, '()');
} else {
$info->default_value = null;
}

View File

@ -727,6 +727,11 @@ class dml_test extends UnitTestCase {
$table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('enumfield', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'test2');
$table->add_field('onenum', XMLDB_TYPE_NUMBER, '10,2', null, null, null, 200);
$table->add_field('onefloat', XMLDB_TYPE_FLOAT, '10,2', null, null, null, 300);
$table->add_field('anotherfloat', XMLDB_TYPE_FLOAT, null, null, null, null, 400);
$table->add_field('negativedfltint', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '-1');
$table->add_field('negativedfltnumber', XMLDB_TYPE_NUMBER, '10', null, XMLDB_NOTNULL, null, '-2');
$table->add_field('negativedfltfloat', XMLDB_TYPE_FLOAT, '10', null, XMLDB_NOTNULL, null, '-3');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
@ -772,10 +777,39 @@ class dml_test extends UnitTestCase {
$field = $columns['onenum'];
$this->assertEqual('N', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertEqual(10, $field->max_length);
$this->assertEqual(2, $field->scale);
$this->assertTrue($field->has_default);
$this->assertEqual(200.0, $field->default_value);
$this->assertFalse($field->not_null);
$field = $columns['onefloat'];
$this->assertEqual('N', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertTrue($field->has_default);
$this->assertEqual(300.0, $field->default_value);
$this->assertFalse($field->not_null);
$field = $columns['anotherfloat'];
$this->assertEqual('N', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertTrue($field->has_default);
$this->assertEqual(400.0, $field->default_value);
$this->assertFalse($field->not_null);
// Test negative defaults in numerical columns
$field = $columns['negativedfltint'];
$this->assertTrue($field->has_default);
$this->assertEqual(-1, $field->default_value);
$field = $columns['negativedfltnumber'];
$this->assertTrue($field->has_default);
$this->assertEqual(-2, $field->default_value);
$field = $columns['negativedfltfloat'];
$this->assertTrue($field->has_default);
$this->assertEqual(-3, $field->default_value);
for ($i = 0; $i < count($columns); $i++) {
if ($i == 0) {
$next_column = reset($columns);

View File

@ -228,11 +228,35 @@ function enrol_check_plugins($user) {
* The courses has to be visible and enrolments has to be active,
* timestart and timeend restrictions are ignored.
*
* This function calls {@see enrol_get_shared_courses()} setting checkexistsonly
* to true.
*
* @param stdClass|int $user1
* @param stdClass|int $user2
* @return bool
*/
function enrol_sharing_course($user1, $user2) {
return enrol_get_shared_courses($user1, $user2, false, true);
}
/**
* Returns any courses shared by the two users
*
* The courses has to be visible and enrolments has to be active,
* timestart and timeend restrictions are ignored.
*
* @global moodle_database $DB
* @param stdClass|int $user1
* @param stdClass|int $user2
* @param bool $preloadcontexts If set to true contexts for the returned courses
* will be preloaded.
* @param bool $checkexistsonly If set to true then this function will return true
* if the users share any courses and false if not.
* @return array|bool An array of courses that both users are enrolled in OR if
* $checkexistsonly set returns true if the users share any courses
* and false if not.
*/
function enrol_get_shared_courses($user1, $user2, $preloadcontexts = false, $checkexistsonly = false) {
global $DB, $CFG;
$user1 = !empty($user1->id) ? $user1->id : $user1;
@ -253,14 +277,33 @@ function enrol_sharing_course($user1, $user2) {
$params['user1'] = $user1;
$params['user2'] = $user2;
$sql = "SELECT DISTINCT 'x'
FROM {enrol} e
JOIN {user_enrolments} ue1 ON (ue1.enrolid = e.id AND ue1.status = :active1 AND ue1.userid = :user1)
JOIN {user_enrolments} ue2 ON (ue2.enrolid = e.id AND ue2.status = :active2 AND ue2.userid = :user2)
JOIN {course} c ON (c.id = e.courseid AND c.visible = 1)
WHERE e.status = :enabled AND e.enrol $plugins";
$ctxselect = '';
$ctxjoin = '';
if ($preloadcontexts) {
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
}
return $DB->record_exists_sql($sql, $params);
$sql = "SELECT c.* $ctxselect
FROM {course} c
JOIN (
SELECT DISTINCT c.id
FROM {enrol} e
JOIN {user_enrolments} ue1 ON (ue1.enrolid = e.id AND ue1.status = :active1 AND ue1.userid = :user1)
JOIN {user_enrolments} ue2 ON (ue2.enrolid = e.id AND ue2.status = :active2 AND ue2.userid = :user2)
JOIN {course} c ON (c.id = e.courseid AND c.visible = 1)
WHERE e.status = :enabled AND e.enrol $plugins
) ec ON ec.id = c.id
$ctxjoin";
if ($checkexistsonly) {
return $DB->record_exists_sql($sql, $params);
} else {
$courses = $DB->get_records_sql($sql, $params);
if ($preloadcontexts) {
array_map('context_instance_preload', $courses);
}
return $courses;
}
}
/**
@ -1566,4 +1609,4 @@ abstract class enrol_plugin {
public function get_bulk_operations() {
return array();
}
}
}

View File

@ -230,7 +230,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
//Apply editor validation if required field
$editorrules = '';
if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) {
$editorrules = 'onblur="'.htmlspecialchars($this->getAttribute('onblur')).'" onchange="'.htmlspecialchars($this->getAttribute('onchange')).'"';
$editorrules = ' onblur="'.htmlspecialchars($this->getAttribute('onblur')).'" onchange="'.htmlspecialchars($this->getAttribute('onchange')).'"';
}
$str .= '<div><textarea id="'.$id.'" name="'.$elname.'[text]" rows="'.$rows.'" cols="'.$cols.'"'.$editorrules.'>';
$str .= s($text);

View File

@ -45,6 +45,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
$this->_type = 'filemanager';
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
}

View File

@ -1,19 +1,34 @@
M.form_filepicker = {};
M.form_filepicker.Y = null;
M.form_filepicker.instances = [];
M.form_filepicker.callback = function(params) {
var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
//When file is added then set status of global variable to true
var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
M.form_filepicker.instances[elementname].fileadded = true;
//generate event to indicate changes which will be used by disable if or validation code
M.form_filepicker.Y.one('#id_'+elementname).simulate('change');
};
/**
* This fucntion is called for each file picker on page.
*/
M.form_filepicker.init = function(Y, options) {
//Keep reference of YUI, so that it can be used in callback.
M.form_filepicker.Y = Y;
//For client side validation, initialize file status for this filepicker
M.form_filepicker.instances[options.elementname] = {};
M.form_filepicker.instances[options.elementname].fileadded = false;
//Set filepicker callback
options.formcallback = M.form_filepicker.callback;
if (!M.core_filepicker.instances[options.client_id]) {
M.core_filepicker.init(Y, options);
M.core_filepicker.init(Y, options);
}
Y.on('click', function(e, client_id) {
e.preventDefault();

View File

@ -29,6 +29,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
$this->_type = 'filepicker';
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
}
@ -78,6 +79,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$args->maxbytes = $this->_options['maxbytes'];
$args->context = $PAGE->context;
$args->buttonname = $elname.'choose';
$args->elementname = $elname;
$html = $this->_getTabs();
$fp = new file_picker($args);
@ -86,7 +88,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$html .= $OUTPUT->render($fp);
$html .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" value="'.$draftitemid.'" class="filepickerhidden"/>';
$module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker'));
$module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker', 'node', 'node-event-simulate'));
$PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
$nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array(

View File

@ -277,7 +277,17 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
} else if (this.getAttribute('type').toLowerCase() == 'checkbox' && !Y.Node.getDOMNode(this).checked) {
return;
}
lock = lock || this.get('value') == value;
//check for filepicker status
if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
var elementname = this.getAttribute('name');
if (elementname && M.form_filepicker.instances[elementname].fileadded) {
lock = false;
} else {
lock = true;
}
} else {
lock = lock || this.get('value') == value;
}
});
return {
lock : lock,
@ -298,7 +308,17 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
} else if (this.getAttribute('type').toLowerCase() == 'checkbox' && !Y.Node.getDOMNode(this).checked) {
return;
}
lock = lock || this.get('value') != value;
//check for filepicker status
if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
var elementname = this.getAttribute('name');
if (elementname && M.form_filepicker.instances[elementname].fileadded) {
lock = true;
} else {
lock = false;
}
} else {
lock = lock || this.get('value') != value;
}
});
return {
lock : lock,

View File

@ -339,6 +339,43 @@ abstract class moodleform {
}
}
/**
* Internal method. Validates filepicker and filemanager files if they are
* set as required fields. Also, sets the error message if encountered one.
*
* @return bool/array with errors
*/
protected function validate_draft_files() {
global $USER;
$mform =& $this->_form;
$errors = array();
//Go through all the required elements and make sure you hit filepicker or
//filemanager element.
foreach ($mform->_rules as $elementname => $rules) {
$elementtype = $mform->getElementType($elementname);
//If element is of type filepicker then do validation
if (($elementtype == 'filepicker') || ($elementtype == 'filemanager')){
//Check if rule defined is required rule
foreach ($rules as $rule) {
if ($rule['type'] == 'required') {
$draftid = (int)$mform->getSubmitValue($elementname);
$fs = get_file_storage();
$context = get_context_instance(CONTEXT_USER, $USER->id);
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
$errors[$elementname] = $rule['message'];
}
}
}
}
}
if (empty($errors)) {
return true;
} else {
return $errors;
}
}
/**
* Load in existing data as form defaults. Usually new entry defaults are stored directly in
* form definition (new entry form); this function is used to load in data where values
@ -439,6 +476,16 @@ abstract class moodleform {
$files = array();
$file_val = $this->_validate_files($files);
//check draft files for validation and flag them if required files
//are not in draft area.
$draftfilevalue = $this->validate_draft_files();
if ($file_val !== true && $draftfilevalue !== true) {
$file_val = array_merge($file_val, $draftfilevalue);
} else if ($draftfilevalue !== true) {
$file_val = $draftfilevalue;
} //default is file_val, so no need to assign.
if ($file_val !== true) {
if (!empty($file_val)) {
foreach ($file_val as $element=>$msg) {
@ -2300,7 +2347,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
if (!$form->isFrozen()) {
$args = $form->getLockOptionObject();
if (count($args[1]) > 0) {
$PAGE->requires->js_init_call('M.form.initFormDependencies', $args, false, moodleform::get_js_module());
$PAGE->requires->js_init_call('M.form.initFormDependencies', $args, true, moodleform::get_js_module());
}
}
}

View File

@ -255,7 +255,7 @@ class portfolio_add_button {
*
* @param int $format format to display the button or form or icon or link.
* See constants PORTFOLIO_ADD_XXX for more info.
* optional, defaults to PORTFOLI_ADD_FULL_FORM
* optional, defaults to PORTFOLIO_ADD_FULL_FORM
* @param str $addstr string to use for the button or icon alt text or link text.
* this is whole string, not key. optional, defaults to 'Add to portfolio';
*/

View File

@ -223,7 +223,7 @@ umask(0000);
// exact version of currently used yui2 and 3 library
$CFG->yui2version = '2.9.0';
$CFG->yui3version = '3.4.1pr1';
$CFG->yui3version = '3.4.1';
// special support for highly optimised scripts that do not need libraries and DB connection

View File

@ -228,7 +228,7 @@
<location>yui</location>
<name>YUI</name>
<license>BSD</license>
<version>3.4.1pr1</version>
<version>3.4.1</version>
<licenseversion></licenseversion>
</library>
<library>

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -196,4 +196,4 @@ YUI.add('align-plugin', function(Y) {
}, '3.4.1pr1' ,{requires:['node-pluginhost', 'node-screen']});
}, '3.4.1' ,{requires:['node-pluginhost', 'node-screen']});

View File

@ -1,7 +1,7 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("align-plugin",function(c){var e="offsetWidth",d="offsetHeight",b=b;function a(f){if(f.host){this._host=f.host;}}a.prototype={to:function(j,t,l,o){this._syncArgs=c.Array(arguments);if(j.top===b){j=c.one(j).get("region");}if(j){var s=[j.left,j.top],q=[j.width,j.height],n=a.points,f=this._host,h=null,r=f.getAttrs([d,e]),k=[0-r[e],0-r[d]],p=t?n[t.charAt(0)]:h,m=(t&&t!=="cc")?n[t.charAt(1)]:h,i=l?n[l.charAt(0)]:h,g=(l&&l!=="cc")?n[l.charAt(1)]:h;if(p){s=p(s,q,t);}if(m){s=m(s,q,t);}if(i){s=i(s,k,l);}if(g){s=g(s,k,l);}if(s&&f){f.setXY(s);}this._resize(o);}return this;},sync:function(){this.to.apply(this,this._syncArgs);return this;},_resize:function(g){var f=this._handle;if(g&&!f){this._handle=c.on("resize",this._onresize,window,this);}else{if(!g&&f){f.detach();}}},_onresize:function(){var f=this;setTimeout(function(){f.sync();});},center:function(g,f){this.to(g,"cc","cc",f);return this;},destroy:function(){var f=this._handle;if(f){f.detach();}}};a.points={"t":function(f,g){return f;},"r":function(f,g){return[f[0]+g[0],f[1]];},"b":function(f,g){return[f[0],f[1]+g[1]];},"l":function(f,g){return f;},"c":function(i,k,f){var h=(f[0]==="t"||f[0]==="b")?0:1,g,j;if(f==="cc"){g=[i[0]+k[0]/2,i[1]+k[1]/2];}else{j=i[h]+k[h]/2;g=(h)?[i[0],j]:[j,i[1]];}return g;}};a.NAME="Align";a.NS="align";a.prototype.constructor=a;c.namespace("Plugin");c.Plugin.Align=a;},"3.4.1pr1",{requires:["node-pluginhost","node-screen"]});
YUI.add("align-plugin",function(c){var e="offsetWidth",d="offsetHeight",b=b;function a(f){if(f.host){this._host=f.host;}}a.prototype={to:function(j,t,l,o){this._syncArgs=c.Array(arguments);if(j.top===b){j=c.one(j).get("region");}if(j){var s=[j.left,j.top],q=[j.width,j.height],n=a.points,f=this._host,h=null,r=f.getAttrs([d,e]),k=[0-r[e],0-r[d]],p=t?n[t.charAt(0)]:h,m=(t&&t!=="cc")?n[t.charAt(1)]:h,i=l?n[l.charAt(0)]:h,g=(l&&l!=="cc")?n[l.charAt(1)]:h;if(p){s=p(s,q,t);}if(m){s=m(s,q,t);}if(i){s=i(s,k,l);}if(g){s=g(s,k,l);}if(s&&f){f.setXY(s);}this._resize(o);}return this;},sync:function(){this.to.apply(this,this._syncArgs);return this;},_resize:function(g){var f=this._handle;if(g&&!f){this._handle=c.on("resize",this._onresize,window,this);}else{if(!g&&f){f.detach();}}},_onresize:function(){var f=this;setTimeout(function(){f.sync();});},center:function(g,f){this.to(g,"cc","cc",f);return this;},destroy:function(){var f=this._handle;if(f){f.detach();}}};a.points={"t":function(f,g){return f;},"r":function(f,g){return[f[0]+g[0],f[1]];},"b":function(f,g){return[f[0],f[1]+g[1]];},"l":function(f,g){return f;},"c":function(i,k,f){var h=(f[0]==="t"||f[0]==="b")?0:1,g,j;if(f==="cc"){g=[i[0]+k[0]/2,i[1]+k[1]/2];}else{j=i[h]+k[h]/2;g=(h)?[i[0],j]:[j,i[1]];}return g;}};a.NAME="Align";a.NS="align";a.prototype.constructor=a;c.namespace("Plugin");c.Plugin.Align=a;},"3.4.1",{requires:["node-pluginhost","node-screen"]});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -196,4 +196,4 @@ YUI.add('align-plugin', function(Y) {
}, '3.4.1pr1' ,{requires:['node-pluginhost', 'node-screen']});
}, '3.4.1' ,{requires:['node-pluginhost', 'node-screen']});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -673,4 +673,4 @@ YUI.add('anim-base', function(Y) {
Y.extend(Y.Anim, Y.Base, proto);
}, '3.4.1pr1' ,{requires:['base-base', 'node-style']});
}, '3.4.1' ,{requires:['base-base', 'node-style']});

View File

@ -1,7 +1,7 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("anim-base",function(b){var c="running",n="startTime",l="elapsedTime",j="start",i="tween",m="end",d="node",k="paused",o="reverse",h="iterationCount",a=Number;var f={},e;b.Anim=function(){b.Anim.superclass.constructor.apply(this,arguments);b.Anim._instances[b.stamp(this)]=this;};b.Anim.NAME="anim";b.Anim._instances={};b.Anim.RE_DEFAULT_UNIT=/^width|height|top|right|bottom|left|margin.*|padding.*|border.*$/i;b.Anim.DEFAULT_UNIT="px";b.Anim.DEFAULT_EASING=function(q,p,s,r){return s*q/r+p;};b.Anim._intervalTime=20;b.Anim.behaviors={left:{get:function(q,p){return q._getOffset(p);}}};b.Anim.behaviors.top=b.Anim.behaviors.left;b.Anim.DEFAULT_SETTER=function(s,t,v,w,y,r,u,x){var q=s._node,p=u(y,a(v),a(w)-a(v),r);if(t in q._node.style||t in b.DOM.CUSTOM_STYLES){x=x||"";q.setStyle(t,p+x);}else{if(q._node.attributes[t]){q.setAttribute(t,p);}else{q.set(t,p);}}};b.Anim.DEFAULT_GETTER=function(r,p){var q=r._node,s="";if(p in q._node.style||p in b.DOM.CUSTOM_STYLES){s=q.getComputedStyle(p);}else{if(q._node.attributes[p]){s=q.getAttribute(p);}else{s=q.get(p);}}return s;};b.Anim.ATTRS={node:{setter:function(p){if(p){if(typeof p=="string"||p.nodeType){p=b.one(p);}}this._node=p;if(!p){}return p;}},duration:{value:1},easing:{value:b.Anim.DEFAULT_EASING,setter:function(p){if(typeof p==="string"&&b.Easing){return b.Easing[p];}}},from:{},to:{},startTime:{value:0,readOnly:true},elapsedTime:{value:0,readOnly:true},running:{getter:function(){return !!f[b.stamp(this)];},value:false,readOnly:true},iterations:{value:1},iterationCount:{value:0,readOnly:true},direction:{value:"normal"},paused:{readOnly:true,value:false},reverse:{value:false}};b.Anim.run=function(){var q=b.Anim._instances;for(var p in q){if(q[p].run){q[p].run();}}};b.Anim.pause=function(){for(var p in f){if(f[p].pause){f[p].pause();}}b.Anim._stopTimer();};b.Anim.stop=function(){for(var p in f){if(f[p].stop){f[p].stop();}}b.Anim._stopTimer();};b.Anim._startTimer=function(){if(!e){e=setInterval(b.Anim._runFrame,b.Anim._intervalTime);}};b.Anim._stopTimer=function(){clearInterval(e);e=0;};b.Anim._runFrame=function(){var p=true;for(var q in f){if(f[q]._runFrame){p=false;f[q]._runFrame();}}if(p){b.Anim._stopTimer();}};b.Anim.RE_UNITS=/^(-?\d*\.?\d*){1}(em|ex|px|in|cm|mm|pt|pc|%)*$/;var g={run:function(){if(this.get(k)){this._resume();}else{if(!this.get(c)){this._start();}}return this;},pause:function(){if(this.get(c)){this._pause();}return this;},stop:function(p){if(this.get(c)||this.get(k)){this._end(p);}return this;},_added:false,_start:function(){this._set(n,new Date()-this.get(l));this._actualFrames=0;if(!this.get(k)){this._initAnimAttr();}f[b.stamp(this)]=this;b.Anim._startTimer();this.fire(j);},_pause:function(){this._set(n,null);this._set(k,true);delete f[b.stamp(this)];this.fire("pause");},_resume:function(){this._set(k,false);f[b.stamp(this)]=this;this._set(n,new Date()-this.get(l));b.Anim._startTimer();this.fire("resume");},_end:function(p){var q=this.get("duration")*1000;if(p){this._runAttrs(q,q,this.get(o));}this._set(n,null);this._set(l,0);this._set(k,false);delete f[b.stamp(this)];this.fire(m,{elapsed:this.get(l)});},_runFrame:function(){var u=this._runtimeAttr.duration,r=new Date()-this.get(n),q=this.get(o),p=(r>=u),s,v;this._runAttrs(r,u,q);this._actualFrames+=1;this._set(l,r);this.fire(i);if(p){this._lastFrame();}},_runAttrs:function(A,z,w){var x=this._runtimeAttr,r=b.Anim.behaviors,y=x.easing,p=z,u=false,q,s,v;if(A>=z){u=true;}if(w){A=z-A;p=0;}for(v in x){if(x[v].to){q=x[v];s=(v in r&&"set" in r[v])?r[v].set:b.Anim.DEFAULT_SETTER;if(!u){s(this,v,q.from,q.to,A,z,y,q.unit);}else{s(this,v,q.from,q.to,p,z,y,q.unit);}}}},_lastFrame:function(){var p=this.get("iterations"),q=this.get(h);q+=1;if(p==="infinite"||q<p){if(this.get("direction")==="alternate"){this.set(o,!this.get(o));}this.fire("iteration");}else{q=0;this._end();}this._set(n,new Date());this._set(h,q);},_initAnimAttr:function(){var w=this.get("from")||{},v=this.get("to")||{},p={duration:this.get("duration")*1000,easing:this.get("easing")},r=b.Anim.behaviors,u=this.get(d),t,s,q;b.each(v,function(A,y){if(typeof A==="function"){A=A.call(this,u);}s=w[y];if(s===undefined){s=(y in r&&"get" in r[y])?r[y].get(this,y):b.Anim.DEFAULT_GETTER(this,y);}else{if(typeof s==="function"){s=s.call(this,u);}}var x=b.Anim.RE_UNITS.exec(s);var z=b.Anim.RE_UNITS.exec(A);s=x?x[1]:s;q=z?z[1]:A;t=z?z[2]:x?x[2]:"";if(!t&&b.Anim.RE_DEFAULT_UNIT.test(y)){t=b.Anim.DEFAULT_UNIT;}if(!s||!q){b.error('invalid "from" or "to" for "'+y+'"',"Anim");return;}p[y]={from:s,to:q,unit:t};},this);this._runtimeAttr=p;},_getOffset:function(q){var s=this._node,t=s.getComputedStyle(q),r=(q==="left")?"getX":"getY",u=(q==="left")?"setX":"setY";if(t==="auto"){var p=s.getStyle("position");if(p==="absolute"||p==="fixed"){t=s[r]();s[u](t);}else{t=0;}}return t;},destructor:function(){delete b.Anim._instances[b.stamp(this)];}};b.extend(b.Anim,b.Base,g);},"3.4.1pr1",{requires:["base-base","node-style"]});
YUI.add("anim-base",function(b){var c="running",n="startTime",l="elapsedTime",j="start",i="tween",m="end",d="node",k="paused",o="reverse",h="iterationCount",a=Number;var f={},e;b.Anim=function(){b.Anim.superclass.constructor.apply(this,arguments);b.Anim._instances[b.stamp(this)]=this;};b.Anim.NAME="anim";b.Anim._instances={};b.Anim.RE_DEFAULT_UNIT=/^width|height|top|right|bottom|left|margin.*|padding.*|border.*$/i;b.Anim.DEFAULT_UNIT="px";b.Anim.DEFAULT_EASING=function(q,p,s,r){return s*q/r+p;};b.Anim._intervalTime=20;b.Anim.behaviors={left:{get:function(q,p){return q._getOffset(p);}}};b.Anim.behaviors.top=b.Anim.behaviors.left;b.Anim.DEFAULT_SETTER=function(s,t,v,w,y,r,u,x){var q=s._node,p=u(y,a(v),a(w)-a(v),r);if(t in q._node.style||t in b.DOM.CUSTOM_STYLES){x=x||"";q.setStyle(t,p+x);}else{if(q._node.attributes[t]){q.setAttribute(t,p);}else{q.set(t,p);}}};b.Anim.DEFAULT_GETTER=function(r,p){var q=r._node,s="";if(p in q._node.style||p in b.DOM.CUSTOM_STYLES){s=q.getComputedStyle(p);}else{if(q._node.attributes[p]){s=q.getAttribute(p);}else{s=q.get(p);}}return s;};b.Anim.ATTRS={node:{setter:function(p){if(p){if(typeof p=="string"||p.nodeType){p=b.one(p);}}this._node=p;if(!p){}return p;}},duration:{value:1},easing:{value:b.Anim.DEFAULT_EASING,setter:function(p){if(typeof p==="string"&&b.Easing){return b.Easing[p];}}},from:{},to:{},startTime:{value:0,readOnly:true},elapsedTime:{value:0,readOnly:true},running:{getter:function(){return !!f[b.stamp(this)];},value:false,readOnly:true},iterations:{value:1},iterationCount:{value:0,readOnly:true},direction:{value:"normal"},paused:{readOnly:true,value:false},reverse:{value:false}};b.Anim.run=function(){var q=b.Anim._instances;for(var p in q){if(q[p].run){q[p].run();}}};b.Anim.pause=function(){for(var p in f){if(f[p].pause){f[p].pause();}}b.Anim._stopTimer();};b.Anim.stop=function(){for(var p in f){if(f[p].stop){f[p].stop();}}b.Anim._stopTimer();};b.Anim._startTimer=function(){if(!e){e=setInterval(b.Anim._runFrame,b.Anim._intervalTime);}};b.Anim._stopTimer=function(){clearInterval(e);e=0;};b.Anim._runFrame=function(){var p=true;for(var q in f){if(f[q]._runFrame){p=false;f[q]._runFrame();}}if(p){b.Anim._stopTimer();}};b.Anim.RE_UNITS=/^(-?\d*\.?\d*){1}(em|ex|px|in|cm|mm|pt|pc|%)*$/;var g={run:function(){if(this.get(k)){this._resume();}else{if(!this.get(c)){this._start();}}return this;},pause:function(){if(this.get(c)){this._pause();}return this;},stop:function(p){if(this.get(c)||this.get(k)){this._end(p);}return this;},_added:false,_start:function(){this._set(n,new Date()-this.get(l));this._actualFrames=0;if(!this.get(k)){this._initAnimAttr();}f[b.stamp(this)]=this;b.Anim._startTimer();this.fire(j);},_pause:function(){this._set(n,null);this._set(k,true);delete f[b.stamp(this)];this.fire("pause");},_resume:function(){this._set(k,false);f[b.stamp(this)]=this;this._set(n,new Date()-this.get(l));b.Anim._startTimer();this.fire("resume");},_end:function(p){var q=this.get("duration")*1000;if(p){this._runAttrs(q,q,this.get(o));}this._set(n,null);this._set(l,0);this._set(k,false);delete f[b.stamp(this)];this.fire(m,{elapsed:this.get(l)});},_runFrame:function(){var u=this._runtimeAttr.duration,r=new Date()-this.get(n),q=this.get(o),p=(r>=u),s,v;this._runAttrs(r,u,q);this._actualFrames+=1;this._set(l,r);this.fire(i);if(p){this._lastFrame();}},_runAttrs:function(A,z,w){var x=this._runtimeAttr,r=b.Anim.behaviors,y=x.easing,p=z,u=false,q,s,v;if(A>=z){u=true;}if(w){A=z-A;p=0;}for(v in x){if(x[v].to){q=x[v];s=(v in r&&"set" in r[v])?r[v].set:b.Anim.DEFAULT_SETTER;if(!u){s(this,v,q.from,q.to,A,z,y,q.unit);}else{s(this,v,q.from,q.to,p,z,y,q.unit);}}}},_lastFrame:function(){var p=this.get("iterations"),q=this.get(h);q+=1;if(p==="infinite"||q<p){if(this.get("direction")==="alternate"){this.set(o,!this.get(o));}this.fire("iteration");}else{q=0;this._end();}this._set(n,new Date());this._set(h,q);},_initAnimAttr:function(){var w=this.get("from")||{},v=this.get("to")||{},p={duration:this.get("duration")*1000,easing:this.get("easing")},r=b.Anim.behaviors,u=this.get(d),t,s,q;b.each(v,function(A,y){if(typeof A==="function"){A=A.call(this,u);}s=w[y];if(s===undefined){s=(y in r&&"get" in r[y])?r[y].get(this,y):b.Anim.DEFAULT_GETTER(this,y);}else{if(typeof s==="function"){s=s.call(this,u);}}var x=b.Anim.RE_UNITS.exec(s);var z=b.Anim.RE_UNITS.exec(A);s=x?x[1]:s;q=z?z[1]:A;t=z?z[2]:x?x[2]:"";if(!t&&b.Anim.RE_DEFAULT_UNIT.test(y)){t=b.Anim.DEFAULT_UNIT;}if(!s||!q){b.error('invalid "from" or "to" for "'+y+'"',"Anim");return;}p[y]={from:s,to:q,unit:t};},this);this._runtimeAttr=p;},_getOffset:function(q){var s=this._node,t=s.getComputedStyle(q),r=(q==="left")?"getX":"getY",u=(q==="left")?"setX":"setY";if(t==="auto"){var p=s.getStyle("position");if(p==="absolute"||p==="fixed"){t=s[r]();s[u](t);}else{t=0;}}return t;},destructor:function(){delete b.Anim._instances[b.stamp(this)];}};b.extend(b.Anim,b.Base,g);},"3.4.1",{requires:["base-base","node-style"]});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -672,4 +672,4 @@ YUI.add('anim-base', function(Y) {
Y.extend(Y.Anim, Y.Base, proto);
}, '3.4.1pr1' ,{requires:['base-base', 'node-style']});
}, '3.4.1' ,{requires:['base-base', 'node-style']});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -51,4 +51,4 @@ Y.each(['backgroundColor',
);
}, '3.4.1pr1' ,{requires:['anim-base']});
}, '3.4.1' ,{requires:['anim-base']});

View File

@ -1,7 +1,7 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("anim-color",function(b){var a=Number;b.Anim.behaviors.color={set:function(f,d,i,h,c,g,e){i=b.Color.re_RGB.exec(b.Color.toRGB(i));h=b.Color.re_RGB.exec(b.Color.toRGB(h));if(!i||i.length<3||!h||h.length<3){b.error("invalid from or to passed to color behavior");}f._node.setStyle(d,"rgb("+[Math.floor(e(c,a(i[1]),a(h[1])-a(i[1]),g)),Math.floor(e(c,a(i[2]),a(h[2])-a(i[2]),g)),Math.floor(e(c,a(i[3]),a(h[3])-a(i[3]),g))].join(", ")+")");},get:function(d,c){var e=d._node.getComputedStyle(c);e=(e==="transparent")?"rgb(255, 255, 255)":e;return e;}};b.each(["backgroundColor","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor"],function(c,d){b.Anim.behaviors[c]=b.Anim.behaviors.color;});},"3.4.1pr1",{requires:["anim-base"]});
YUI.add("anim-color",function(b){var a=Number;b.Anim.behaviors.color={set:function(f,d,i,h,c,g,e){i=b.Color.re_RGB.exec(b.Color.toRGB(i));h=b.Color.re_RGB.exec(b.Color.toRGB(h));if(!i||i.length<3||!h||h.length<3){b.error("invalid from or to passed to color behavior");}f._node.setStyle(d,"rgb("+[Math.floor(e(c,a(i[1]),a(h[1])-a(i[1]),g)),Math.floor(e(c,a(i[2]),a(h[2])-a(i[2]),g)),Math.floor(e(c,a(i[3]),a(h[3])-a(i[3]),g))].join(", ")+")");},get:function(d,c){var e=d._node.getComputedStyle(c);e=(e==="transparent")?"rgb(255, 255, 255)":e;return e;}};b.each(["backgroundColor","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor"],function(c,d){b.Anim.behaviors[c]=b.Anim.behaviors.color;});},"3.4.1",{requires:["anim-base"]});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -51,4 +51,4 @@ Y.each(['backgroundColor',
);
}, '3.4.1pr1' ,{requires:['anim-base']});
}, '3.4.1' ,{requires:['anim-base']});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -60,4 +60,4 @@ Y.Anim.getBezier = function(points, t) {
};
}, '3.4.1pr1' ,{requires:['anim-xy']});
}, '3.4.1' ,{requires:['anim-xy']});

View File

@ -1,7 +1,7 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("anim-curve",function(a){a.Anim.behaviors.curve={set:function(f,c,i,h,b,g,e){i=i.slice.call(i);h=h.slice.call(h);var d=e(b,0,100,g)/100;h.unshift(i);f._node.setXY(a.Anim.getBezier(h,d));},get:function(c,b){return c._node.getXY();}};a.Anim.getBezier=function(f,e){var g=f.length;var d=[];for(var c=0;c<g;++c){d[c]=[f[c][0],f[c][1]];}for(var b=1;b<g;++b){for(c=0;c<g-b;++c){d[c][0]=(1-e)*d[c][0]+e*d[parseInt(c+1,10)][0];d[c][1]=(1-e)*d[c][1]+e*d[parseInt(c+1,10)][1];}}return[d[0][0],d[0][1]];};},"3.4.1pr1",{requires:["anim-xy"]});
YUI.add("anim-curve",function(a){a.Anim.behaviors.curve={set:function(f,c,i,h,b,g,e){i=i.slice.call(i);h=h.slice.call(h);var d=e(b,0,100,g)/100;h.unshift(i);f._node.setXY(a.Anim.getBezier(h,d));},get:function(c,b){return c._node.getXY();}};a.Anim.getBezier=function(f,e){var g=f.length;var d=[];for(var c=0;c<g;++c){d[c]=[f[c][0],f[c][1]];}for(var b=1;b<g;++b){for(c=0;c<g-b;++c){d[c][0]=(1-e)*d[c][0]+e*d[parseInt(c+1,10)][0];d[c][1]=(1-e)*d[c][1]+e*d[parseInt(c+1,10)][1];}}return[d[0][0],d[0][1]];};},"3.4.1",{requires:["anim-xy"]});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -60,4 +60,4 @@ Y.Anim.getBezier = function(points, t) {
};
}, '3.4.1pr1' ,{requires:['anim-xy']});
}, '3.4.1' ,{requires:['anim-xy']});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -353,4 +353,4 @@ var Easing = {
Y.Easing = Easing;
}, '3.4.1pr1' ,{requires:['anim-base']});
}, '3.4.1' ,{requires:['anim-base']});

View File

@ -1,7 +1,7 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("anim-easing",function(b){var a={easeNone:function(f,e,h,g){return h*f/g+e;},easeIn:function(f,e,h,g){return h*(f/=g)*f+e;},easeOut:function(f,e,h,g){return -h*(f/=g)*(f-2)+e;},easeBoth:function(f,e,h,g){if((f/=g/2)<1){return h/2*f*f+e;}return -h/2*((--f)*(f-2)-1)+e;},easeInStrong:function(f,e,h,g){return h*(f/=g)*f*f*f+e;},easeOutStrong:function(f,e,h,g){return -h*((f=f/g-1)*f*f*f-1)+e;},easeBothStrong:function(f,e,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+e;}return -h/2*((f-=2)*f*f*f-2)+e;},elasticIn:function(g,e,k,j,f,i){var h;if(g===0){return e;}if((g/=j)===1){return e+k;}if(!i){i=j*0.3;}if(!f||f<Math.abs(k)){f=k;h=i/4;}else{h=i/(2*Math.PI)*Math.asin(k/f);}return -(f*Math.pow(2,10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i))+e;},elasticOut:function(g,e,k,j,f,i){var h;if(g===0){return e;}if((g/=j)===1){return e+k;}if(!i){i=j*0.3;}if(!f||f<Math.abs(k)){f=k;h=i/4;}else{h=i/(2*Math.PI)*Math.asin(k/f);}return f*Math.pow(2,-10*g)*Math.sin((g*j-h)*(2*Math.PI)/i)+k+e;},elasticBoth:function(g,e,k,j,f,i){var h;if(g===0){return e;}if((g/=j/2)===2){return e+k;}if(!i){i=j*(0.3*1.5);}if(!f||f<Math.abs(k)){f=k;h=i/4;}else{h=i/(2*Math.PI)*Math.asin(k/f);}if(g<1){return -0.5*(f*Math.pow(2,10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i))+e;}return f*Math.pow(2,-10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i)*0.5+k+e;},backIn:function(f,e,i,h,g){if(g===undefined){g=1.70158;}if(f===h){f-=0.001;}return i*(f/=h)*f*((g+1)*f-g)+e;},backOut:function(f,e,i,h,g){if(typeof g==="undefined"){g=1.70158;}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+e;},backBoth:function(f,e,i,h,g){if(typeof g==="undefined"){g=1.70158;}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+e;}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+e;},bounceIn:function(f,e,h,g){return h-b.Easing.bounceOut(g-f,0,h,g)+e;},bounceOut:function(f,e,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+e;}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+e;}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+e;}}}return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+e;},bounceBoth:function(f,e,h,g){if(f<g/2){return b.Easing.bounceIn(f*2,0,h,g)*0.5+e;}return b.Easing.bounceOut(f*2-g,0,h,g)*0.5+h*0.5+e;}};b.Easing=a;},"3.4.1pr1",{requires:["anim-base"]});
YUI.add("anim-easing",function(b){var a={easeNone:function(f,e,h,g){return h*f/g+e;},easeIn:function(f,e,h,g){return h*(f/=g)*f+e;},easeOut:function(f,e,h,g){return -h*(f/=g)*(f-2)+e;},easeBoth:function(f,e,h,g){if((f/=g/2)<1){return h/2*f*f+e;}return -h/2*((--f)*(f-2)-1)+e;},easeInStrong:function(f,e,h,g){return h*(f/=g)*f*f*f+e;},easeOutStrong:function(f,e,h,g){return -h*((f=f/g-1)*f*f*f-1)+e;},easeBothStrong:function(f,e,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+e;}return -h/2*((f-=2)*f*f*f-2)+e;},elasticIn:function(g,e,k,j,f,i){var h;if(g===0){return e;}if((g/=j)===1){return e+k;}if(!i){i=j*0.3;}if(!f||f<Math.abs(k)){f=k;h=i/4;}else{h=i/(2*Math.PI)*Math.asin(k/f);}return -(f*Math.pow(2,10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i))+e;},elasticOut:function(g,e,k,j,f,i){var h;if(g===0){return e;}if((g/=j)===1){return e+k;}if(!i){i=j*0.3;}if(!f||f<Math.abs(k)){f=k;h=i/4;}else{h=i/(2*Math.PI)*Math.asin(k/f);}return f*Math.pow(2,-10*g)*Math.sin((g*j-h)*(2*Math.PI)/i)+k+e;},elasticBoth:function(g,e,k,j,f,i){var h;if(g===0){return e;}if((g/=j/2)===2){return e+k;}if(!i){i=j*(0.3*1.5);}if(!f||f<Math.abs(k)){f=k;h=i/4;}else{h=i/(2*Math.PI)*Math.asin(k/f);}if(g<1){return -0.5*(f*Math.pow(2,10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i))+e;}return f*Math.pow(2,-10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i)*0.5+k+e;},backIn:function(f,e,i,h,g){if(g===undefined){g=1.70158;}if(f===h){f-=0.001;}return i*(f/=h)*f*((g+1)*f-g)+e;},backOut:function(f,e,i,h,g){if(typeof g==="undefined"){g=1.70158;}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+e;},backBoth:function(f,e,i,h,g){if(typeof g==="undefined"){g=1.70158;}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+e;}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+e;},bounceIn:function(f,e,h,g){return h-b.Easing.bounceOut(g-f,0,h,g)+e;},bounceOut:function(f,e,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+e;}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+e;}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+e;}}}return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+e;},bounceBoth:function(f,e,h,g){if(f<g/2){return b.Easing.bounceIn(f*2,0,h,g)*0.5+e;}return b.Easing.bounceOut(f*2-g,0,h,g)*0.5+h*0.5+e;}};b.Easing=a;},"3.4.1",{requires:["anim-base"]});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -353,4 +353,4 @@ var Easing = {
Y.Easing = Easing;
}, '3.4.1pr1' ,{requires:['anim-base']});
}, '3.4.1' ,{requires:['anim-base']});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -29,4 +29,4 @@ Y.namespace('Plugin');
Y.Plugin.NodeFX = NodeFX;
}, '3.4.1pr1' ,{requires:['node-pluginhost', 'anim-base']});
}, '3.4.1' ,{requires:['node-pluginhost', 'anim-base']});

View File

@ -1,7 +1,7 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("anim-node-plugin",function(b){var a=function(c){c=(c)?b.merge(c):{};c.node=c.host;a.superclass.constructor.apply(this,arguments);};a.NAME="nodefx";a.NS="fx";b.extend(a,b.Anim);b.namespace("Plugin");b.Plugin.NodeFX=a;},"3.4.1pr1",{requires:["node-pluginhost","anim-base"]});
YUI.add("anim-node-plugin",function(b){var a=function(c){c=(c)?b.merge(c):{};c.node=c.host;a.superclass.constructor.apply(this,arguments);};a.NAME="nodefx";a.NS="fx";b.extend(a,b.Anim);b.namespace("Plugin");b.Plugin.NodeFX=a;},"3.4.1",{requires:["node-pluginhost","anim-base"]});

View File

@ -1,5 +1,5 @@
/*
YUI 3.4.1pr1 (build 4097)
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
@ -29,4 +29,4 @@ Y.namespace('Plugin');
Y.Plugin.NodeFX = NodeFX;
}, '3.4.1pr1' ,{requires:['node-pluginhost', 'anim-base']});
}, '3.4.1' ,{requires:['node-pluginhost', 'anim-base']});

Some files were not shown because too many files have changed in this diff Show More