mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Moving all the XMLDB stuff from contrib to head. Go, go, go...
This commit is contained in:
parent
f0a7247d0e
commit
8c15ae9958
60 changed files with 8720 additions and 0 deletions
78
admin/xmldb/README.txt
Normal file
78
admin/xmldb/README.txt
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
XMLDB - Base classes and edition interface.
|
||||||
|
|
||||||
|
Complete Documentation:
|
||||||
|
|
||||||
|
http://docs.moodle.org/en/XMLDB_Defining_one_XML_structure
|
||||||
|
|
||||||
|
Ciao, Eloy Lafuente (stronk7)
|
||||||
|
|
||||||
|
========== ========== ========== ========== ==========
|
||||||
|
========== ========== HISTORY ========== ==========
|
||||||
|
========== ========== ========== ========== ==========
|
||||||
|
|
||||||
|
2006-08-07 - Editor working on production
|
||||||
|
|
||||||
|
The editor has been used succesfully to build
|
||||||
|
a bunch of install.xml files and everything
|
||||||
|
seems to be working properly.
|
||||||
|
|
||||||
|
========== ========== ========== ========== ==========
|
||||||
|
|
||||||
|
2006-07-11 - PHP4 compatible release
|
||||||
|
|
||||||
|
Now everything seems to be working under PHP 4. What
|
||||||
|
a horrible OOP implementation!
|
||||||
|
|
||||||
|
Note that write permissions to */db dirs are required.
|
||||||
|
|
||||||
|
Now working in the 3 missing forms, to manually edit
|
||||||
|
fields, keys and indexes.
|
||||||
|
|
||||||
|
Ciao, Eloy Lafuente (stronk7)
|
||||||
|
|
||||||
|
========== ========== ========== ========== ==========
|
||||||
|
|
||||||
|
2006-07-11 - Important notes
|
||||||
|
|
||||||
|
I've just discovered this some seconds ago, in order
|
||||||
|
to test properly the XMLDB classes and editor:
|
||||||
|
|
||||||
|
1.- PHP 5 required for now. Will change this soon.
|
||||||
|
2.- Perms to "apache" user needed in */db
|
||||||
|
dirs in order to allow the XMDBD interface
|
||||||
|
to write files.
|
||||||
|
|
||||||
|
Ciao, Eloy Lafuente (stronk7)
|
||||||
|
|
||||||
|
========== ========== ========== ========== ==========
|
||||||
|
|
||||||
|
2006-07-11 - Initial commit
|
||||||
|
|
||||||
|
This directory contains the XMLDB classes to be used
|
||||||
|
under Moodle > 1.7 to store all the DB info in a
|
||||||
|
neutral form (classes dir). Also it contains one simple
|
||||||
|
interface to edit all those structures.
|
||||||
|
|
||||||
|
To install and test it, simply copy the whole xmldb directory
|
||||||
|
under your moodle/admin dir and point your browser (as admin)
|
||||||
|
to http://your.server/moodle/admin/xmldb
|
||||||
|
|
||||||
|
The edition interface isn't completed yet (it laks 3 more forms
|
||||||
|
to edit fields, keys and indexes) and there isn't any lang file
|
||||||
|
(although I hope everything is really clear).
|
||||||
|
|
||||||
|
The edition interface includes one reverse-engineering tool that
|
||||||
|
provides an easy way to retroffit and to generate any table from
|
||||||
|
MySQL to the new XMLDB format.
|
||||||
|
|
||||||
|
Once the XMLDB format was approved, we'll be able to build all the
|
||||||
|
"generators" needed in order to use it to create Moodle DB structures
|
||||||
|
for each RDBMS flavour.
|
||||||
|
|
||||||
|
Once the interface was finished (2-3 days from now) related documentation
|
||||||
|
will be sent to http://docs.moodle.org/en/XML_database_schema in order
|
||||||
|
to comment/modify/approve the final XML format.
|
||||||
|
|
||||||
|
All the code is, obviously GPL, with its copyrights and so on...
|
||||||
|
|
||||||
|
Ciao, Eloy Lafuente (stronk7) :-)
|
191
admin/xmldb/actions/XMLDBAction.class.php
Normal file
191
admin/xmldb/actions/XMLDBAction.class.php
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This is the main action class. It implements all the basic
|
||||||
|
/// functionalities to be shared by each action.
|
||||||
|
|
||||||
|
class XMLDBAction {
|
||||||
|
|
||||||
|
var $does_generate; //Type of value returned by the invoke method
|
||||||
|
//ACTION_GENERATE_HTML have contents to show
|
||||||
|
//set by each specialized invoke
|
||||||
|
|
||||||
|
var $title; //Title of the Action (class name, by default)
|
||||||
|
//set by parent init automatically
|
||||||
|
|
||||||
|
var $str; //Strings used by the action
|
||||||
|
//set by each specialized init, calling loadStrings
|
||||||
|
|
||||||
|
var $output; //Output of the action
|
||||||
|
//set by each specialized invoke, get with getOutput
|
||||||
|
|
||||||
|
var $errormsg; //Last Error produced. Check when any invoke returns false
|
||||||
|
//get with getError
|
||||||
|
|
||||||
|
var $postaction; //Action to execute at the end of the invoke script
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
function XMLDBAction() {
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to keep PHP5 happy
|
||||||
|
*/
|
||||||
|
function __construct() {
|
||||||
|
$this->XMLDBAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own,
|
||||||
|
* always calling the parent one
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
$this->title = strtolower(get_class($this));
|
||||||
|
$this->str = array();
|
||||||
|
$this->output = NULL;
|
||||||
|
$this->errormsg = NULL;
|
||||||
|
$this->subaction = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the type of output of the file
|
||||||
|
*/
|
||||||
|
function getDoesGenerate() {
|
||||||
|
return $this->does_generate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getError method, returns the last error string.
|
||||||
|
* Used if the invoke() methods returns false
|
||||||
|
*/
|
||||||
|
function getError() {
|
||||||
|
return $this->errormsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getOutput method, returns the output generated by the action.
|
||||||
|
* Used after execution of the invoke() methods if they return true
|
||||||
|
*/
|
||||||
|
function getOutput() {
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPostAtion method, returns the action to launch after executing
|
||||||
|
* another one
|
||||||
|
*/
|
||||||
|
function getPostAction() {
|
||||||
|
return $this->postaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTitle method returns the title of the action (that is part
|
||||||
|
* of the $str array attribute
|
||||||
|
*/
|
||||||
|
function getTitle() {
|
||||||
|
return $this->str['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loadStrings method, loads the required strings specified in the
|
||||||
|
* array parameter
|
||||||
|
*/
|
||||||
|
function loadStrings($strings) {
|
||||||
|
/// Load some commonly used strings
|
||||||
|
$this->str['title'] = get_string($this->title, 'xmldb');
|
||||||
|
|
||||||
|
/// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main invoke method, it simply sets the postaction attribute
|
||||||
|
* if possible
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
|
||||||
|
global $SESSION;
|
||||||
|
|
||||||
|
/// 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_CLEAN)) {
|
||||||
|
$SESSION->lastused = stripslashes_safe($lastused);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT);
|
||||||
|
/// Avoid being recursive
|
||||||
|
if ($this->title == $this->postaction) {
|
||||||
|
$this->postaction = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* launch method, used to easily call invoke methods between actions
|
||||||
|
*/
|
||||||
|
function launch($action) {
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
/// Get the action path and invoke it
|
||||||
|
$actionsroot = "$CFG->dirroot/$CFG->admin/xmldb/actions";
|
||||||
|
$actionclass = $action . '.class.php';
|
||||||
|
$actionpath = "$actionsroot/$action/$actionclass";
|
||||||
|
|
||||||
|
/// Load and invoke the proper action
|
||||||
|
$result = false;
|
||||||
|
if (file_exists($actionpath) && is_readable($actionpath)) {
|
||||||
|
require_once($actionpath);
|
||||||
|
if ($xmldb_action = new $action) {
|
||||||
|
$result = $xmldb_action->invoke();
|
||||||
|
if ($result) {
|
||||||
|
if ($xmldb_action->does_generate != ACTION_NONE &&
|
||||||
|
$xmldb_action->getOutput()) {
|
||||||
|
$this->does_generate = $xmldb_action->does_generate;
|
||||||
|
$this->title = $xmldb_action->title;
|
||||||
|
$this->str = $xmldb_action->str;
|
||||||
|
$this->output .= $xmldb_action->getOutput();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = $xmldb_action->getError();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = "Error: cannot instantiate class (actions/$action/$actionclass)";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = "Error: wrong action specified ($action)";
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
108
admin/xmldb/actions/create_xml_file/create_xml_file.class.php
Normal file
108
admin/xmldb/actions/create_xml_file/create_xml_file.class.php
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will
|
||||||
|
|
||||||
|
class create_xml_file extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->can_subaction = ACTION_NONE;
|
||||||
|
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$file = $dirpath . '/install.xml';
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
$c = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
|
||||||
|
$c.= ' <XMLDB PATH="' . $xmlpath . '" VERSION="' . $xmlversion .'" COMMENT="' . $xmlcomment .'">' . "\n";
|
||||||
|
$c.= ' <TABLES>' . "\n";
|
||||||
|
$c.= ' <TABLE NAME="' . $xmltable . '" COMMENT="Default comment for ' . $xmltable .', please edit me">' . "\n";
|
||||||
|
$c.= ' <FIELDS>' . "\n";
|
||||||
|
$c.= ' <FIELD NAME="id" TYPE="int" LENGTH="10" UNSIGNED="true" NOTNULL="true" SEQUENCE="true" COMMENT="id of the table, please edit me" />' . "\n";
|
||||||
|
$c.= ' </FIELDS>' . "\n";
|
||||||
|
$c.= ' <KEYS>' . "\n";
|
||||||
|
$c.= ' <KEY NAME="primary" COMMENT="Primary key for ' . $xmltable . '" TYPE="primary" FIELDS="id" />' . "\n";
|
||||||
|
$c.= ' </KEYS>' . "\n";
|
||||||
|
$c.= ' </TABLE>' . "\n";
|
||||||
|
$c.= ' </TABLES>' . "\n";
|
||||||
|
$c.= ' </XMLDB>';
|
||||||
|
|
||||||
|
if (!file_put_contents($file, $c)) {
|
||||||
|
$errormsg = 'Error creando fichero ' . $file;
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
140
admin/xmldb/actions/delete_field/delete_field.class.php
Normal file
140
admin/xmldb/actions/delete_field/delete_field.class.php
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one field
|
||||||
|
|
||||||
|
class delete_field extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeletefield' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$fieldparam = required_param('field', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeletefield'] . '<br /><br />' . $fieldparam . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_field&confirmed=yes&postaction=edit_table&field=' . $fieldparam . '&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$fields =& $table->getFields();
|
||||||
|
$field =& $table->getField($fieldparam);
|
||||||
|
if ($field->getPrevious()) {
|
||||||
|
$prev =& $table->getField($field->getPrevious());
|
||||||
|
$prev->setNext($field->getNext());
|
||||||
|
}
|
||||||
|
if ($field->getNext()) {
|
||||||
|
$next =& $table->getField($field->getNext());
|
||||||
|
$next->setPrevious($field->getPrevious());
|
||||||
|
}
|
||||||
|
/// Remove the field
|
||||||
|
$table->deleteField($fieldparam);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
140
admin/xmldb/actions/delete_index/delete_index.class.php
Normal file
140
admin/xmldb/actions/delete_index/delete_index.class.php
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one index
|
||||||
|
|
||||||
|
class delete_index extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeleteindex' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$indexparam = required_param('index', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeleteindex'] . '<br /><br />' . $indexparam . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_index&confirmed=yes&postaction=edit_table&index=' . $indexparam . '&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$indexes =& $table->getIndexes();
|
||||||
|
$index =& $table->getIndex($indexparam);
|
||||||
|
if ($index->getPrevious()) {
|
||||||
|
$prev =& $table->getIndex($index->getPrevious());
|
||||||
|
$prev->setNext($index->getNext());
|
||||||
|
}
|
||||||
|
if ($index->getNext()) {
|
||||||
|
$next =& $table->getIndex($index->getNext());
|
||||||
|
$next->setPrevious($index->getPrevious());
|
||||||
|
}
|
||||||
|
/// Remove the index
|
||||||
|
$table->deleteIndex($indexparam);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
140
admin/xmldb/actions/delete_key/delete_key.class.php
Normal file
140
admin/xmldb/actions/delete_key/delete_key.class.php
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one key
|
||||||
|
|
||||||
|
class delete_key extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeletekey' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$keyparam = required_param('key', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeletekey'] . '<br /><br />' . $keyparam . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_key&confirmed=yes&postaction=edit_table&key=' . $keyparam . '&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$keys =& $table->getKeys();
|
||||||
|
$key =& $table->getKey($keyparam);
|
||||||
|
if ($key->getPrevious()) {
|
||||||
|
$prev =& $table->getKey($key->getPrevious());
|
||||||
|
$prev->setNext($key->getNext());
|
||||||
|
}
|
||||||
|
if ($key->getNext()) {
|
||||||
|
$next =& $table->getKey($key->getNext());
|
||||||
|
$next->setPrevious($key->getPrevious());
|
||||||
|
}
|
||||||
|
/// Remove the key
|
||||||
|
$table->deleteKey($keyparam);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
133
admin/xmldb/actions/delete_sentence/delete_sentence.class.php
Normal file
133
admin/xmldb/actions/delete_sentence/delete_sentence.class.php
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one sentence
|
||||||
|
|
||||||
|
class delete_sentence extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeletesentence' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||||
|
$sentenceparam = required_param('sentence', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeletesentence'] . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_sentence&confirmed=yes&postaction=edit_statement&sentence=' . $sentenceparam . '&statement=' . urlencode($statementparam) . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// 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();
|
||||||
|
$statements =& $structure->getStatements();
|
||||||
|
$statement =& $structure->getStatement($statementparam);
|
||||||
|
$sentences =& $statement->getSentences();
|
||||||
|
/// Remove the sentence
|
||||||
|
unset ($sentences[$sentenceparam]);
|
||||||
|
|
||||||
|
/// The statement has changed
|
||||||
|
$statement->setChanged(true);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
115
admin/xmldb/actions/delete_statement/delete_statement.class.php
Normal file
115
admin/xmldb/actions/delete_statement/delete_statement.class.php
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one statement
|
||||||
|
|
||||||
|
class delete_statement extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeletestatement' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeletestatement'] . '<br /><br />' . $statementparam . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_statement&confirmed=yes&postaction=edit_xml_file&statement=' . $statementparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
$structure->deleteStatement($statementparam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
115
admin/xmldb/actions/delete_table/delete_table.class.php
Normal file
115
admin/xmldb/actions/delete_table/delete_table.class.php
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one table
|
||||||
|
|
||||||
|
class delete_table extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeletetable' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeletetable'] . '<br /><br />' . $tableparam . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_table&confirmed=yes&postaction=edit_xml_file&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
$structure->deleteTable($tableparam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
111
admin/xmldb/actions/delete_xml_file/delete_xml_file.class.php
Normal file
111
admin/xmldb/actions/delete_xml_file/delete_xml_file.class.php
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will delete completely one XML file
|
||||||
|
|
||||||
|
class delete_xml_file extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmdeletexmlfile' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmdeletexmlfile'] . '<br /><br />' . $dirpath . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=delete_xml_file&confirmed=yes&dir=' . urlencode($dirpath) . '&postaction=main_view#lastused" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=main_view#lastused" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// Get the original dir and delete the xml file
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
if ($dbdir) {
|
||||||
|
@unlink($dirpath . '/install.xml');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
204
admin/xmldb/actions/edit_field/edit_field.class.php
Normal file
204
admin/xmldb/actions/edit_field/edit_field.class.php
Normal file
|
@ -0,0 +1,204 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will provide the interface for all the edit field actions
|
||||||
|
|
||||||
|
class edit_field extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => '',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// Fetch request data
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
if (!$table =& $structure->getTable($tableparam)) {
|
||||||
|
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$fieldparam = required_param('field', PARAM_CLEAN);
|
||||||
|
if (!$field =& $table->getField($fieldparam)) {
|
||||||
|
/// Arriving here from a name change, looking for the new field name
|
||||||
|
$fieldparam = required_param('name', PARAM_CLEAN);
|
||||||
|
$field =& $table->getField($fieldparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $dbdir->xml_file->getStructure();
|
||||||
|
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="field" value="' . $fieldparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_field_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
/// 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()) .'" />';
|
||||||
|
$o.= ' <tr valign="top"><td>Name:</td><td colspan="2">' . s($field->getName()) . '</td></tr>';
|
||||||
|
} 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
|
||||||
|
$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>';
|
||||||
|
/// XMLDBField 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),
|
||||||
|
XMLDB_TYPE_DATETIME=> $field->getXMLDBTypeName(XMLDB_TYPE_DATETIME),
|
||||||
|
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 ($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
|
||||||
|
if ($field->getType() != XMLDB_TYPE_DATETIME) {
|
||||||
|
unset ($typeoptions[XMLDB_TYPE_DATETIME]);
|
||||||
|
}
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
|
||||||
|
$o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'type', $field->getType(), '', '', '', true) . '</td></tr>';
|
||||||
|
/// XMLDBField 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>';
|
||||||
|
/// XMLDBField 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>';
|
||||||
|
/// XMLDBField Unsigned
|
||||||
|
$unsignedoptions = array (0 => 'signed', 1 => 'unsigned');
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menuunsigned" accesskey="u">Unsigned:</label></td>';
|
||||||
|
$o.= ' <td colspan="2">' . choose_from_menu($unsignedoptions, 'unsigned', $field->getUnsigned(), '', '', '', true) . '</td></tr>';
|
||||||
|
/// XMLDBField NotNull
|
||||||
|
$notnulloptions = array (0 => 'null', 'not null');
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menunotnull" accesskey="n">Not Null:</label></td>';
|
||||||
|
$o.= ' <td colspan="2">' . choose_from_menu($notnulloptions, 'notnull', $field->getNotNull(), '', '', '', true) . '</td></tr>';
|
||||||
|
/// XMLDBField Sequence
|
||||||
|
$sequenceoptions = array (0 => $this->str['no'], 1 => 'auto-numbered');
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menusequence" accesskey="s">Sequence:</label></td>';
|
||||||
|
$o.= ' <td colspan="2">' . choose_from_menu($sequenceoptions, 'sequence', $field->getSequence(), '', '', '', true) . '</td></tr>';
|
||||||
|
/// XMLDBField Enum and enumvalues
|
||||||
|
$enumoptions = array (0 => $this->str['no'], 1 => $this->str['yes']);
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menuenum" accesskey="s">Enum:</label></td>';
|
||||||
|
$o.= ' <td>' . choose_from_menu($enumoptions, 'enum', $field->getEnum(), '', '', '', true) . '</td>';
|
||||||
|
if (is_array($field->getEnumValues())) {
|
||||||
|
$enumvalues = implode(', ', $field->getEnumValues());
|
||||||
|
} else {
|
||||||
|
$enumvalues = '';
|
||||||
|
}
|
||||||
|
$o.= ' <td><textarea name="enumvalues" rows="3" cols="70" id="enumvalues">' . s($enumvalues) . '</textarea></td></tr>';
|
||||||
|
/// XMLDBField 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
|
||||||
|
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The view original XML button
|
||||||
|
if ($table->getField($fieldparam)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_field_xml&dir=' . urlencode($dirpath) . '&select=original&table=' . $tableparam . '&field=' . $fieldparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||||
|
}
|
||||||
|
/// The view edited XML button
|
||||||
|
if ($field->hasChanged()) {
|
||||||
|
$b .= ' <a href="index.php?action=view_field_xml&dir=' . urlencode($dirpath) . '&select=edited&table=' . $tableparam . '&field=' . $fieldparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||||
|
}
|
||||||
|
/// The back to edit table button
|
||||||
|
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
187
admin/xmldb/actions/edit_field/edit_field.js
Normal file
187
admin/xmldb/actions/edit_field/edit_field.js
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
/// $Id $
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/// Register the needed events
|
||||||
|
|
||||||
|
onload=function() {
|
||||||
|
/// Adjust the form on load
|
||||||
|
transformForm();
|
||||||
|
|
||||||
|
/// Get the required fields
|
||||||
|
var typeField = document.getElementById('menutype');
|
||||||
|
var sequenceField = document.getElementById('menusequence');
|
||||||
|
var enumField = document.getElementById('menuenum');
|
||||||
|
|
||||||
|
/// Register the rest of events
|
||||||
|
if (typeField.addEventListener) {
|
||||||
|
/// Standard
|
||||||
|
typeField.addEventListener('change', transformForm, false);
|
||||||
|
sequenceField.addEventListener('change', transformForm, false);
|
||||||
|
enumField.addEventListener('change', transformForm, false);
|
||||||
|
} else {
|
||||||
|
/// IE 5.5
|
||||||
|
typeField.attachEvent('onchange', transformForm);
|
||||||
|
sequenceField.attachEvent('onchange', transformForm);
|
||||||
|
enumField.attachEvent('onchange', transformForm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function controls all modifications to perform when any field changes
|
||||||
|
*/
|
||||||
|
function transformForm(event) {
|
||||||
|
|
||||||
|
/// Initialize all the needed variables
|
||||||
|
var typeField = document.getElementById('menutype');
|
||||||
|
var lengthField = document.getElementById('length');
|
||||||
|
var decimalsField = document.getElementById('decimals');
|
||||||
|
var unsignedField = document.getElementById('menuunsigned');
|
||||||
|
var notnullField = document.getElementById('menunotnull');
|
||||||
|
var sequenceField = document.getElementById('menusequence');
|
||||||
|
var enumField = document.getElementById('menuenum');
|
||||||
|
var enumvaluesField = document.getElementById('enumvalues');
|
||||||
|
var defaultField = document.getElementById('default');
|
||||||
|
|
||||||
|
var lengthTip = document.getElementById('lengthtip');
|
||||||
|
var decimalsTip = document.getElementById('decimalstip');
|
||||||
|
|
||||||
|
/// Initially, enable everything
|
||||||
|
decimalsField.disabled = false;
|
||||||
|
unsignedField.disabled = false;
|
||||||
|
notnullField.disabled = false;
|
||||||
|
sequenceField.disabled = false;
|
||||||
|
enumField.disabled = false;
|
||||||
|
enumvaluesField.disabled = false;
|
||||||
|
defaultField.disabled = false;
|
||||||
|
|
||||||
|
/// Based on enum, disable some items
|
||||||
|
if (enumField.value == '0') {
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Based on sequence, disable some items
|
||||||
|
if (sequenceField.value == '1') {
|
||||||
|
unsignedField.disabled = true;
|
||||||
|
unsignedField.value = '1';
|
||||||
|
notnullField.disabled = true;
|
||||||
|
notnullField.value = '1';
|
||||||
|
defaultField.disabled = true;
|
||||||
|
defaultField.value = '';
|
||||||
|
enumField.disabled = true;
|
||||||
|
enumField.value = '0';
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Based on type, disable some items
|
||||||
|
switch (typeField.value) {
|
||||||
|
case '1': // XMLDB_TYPE_INTEGER
|
||||||
|
lengthTip.innerHTML = ' 1...20';
|
||||||
|
decimalsTip.innerHTML = '';
|
||||||
|
decimalsField.disabled = true;
|
||||||
|
decimalsField.value = '';
|
||||||
|
enumField.disabled = true;
|
||||||
|
enumField.value = '0';
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
break;
|
||||||
|
case '2': // XMLDB_TYPE_NUMBER
|
||||||
|
lengthTip.innerHTML = ' 1...20';
|
||||||
|
decimalsTip.innerHTML = ' 0...length or empty';
|
||||||
|
enumField.disabled = true;
|
||||||
|
enumField.value = '0';
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
break;
|
||||||
|
case '3': // XMLDB_TYPE_FLOAT
|
||||||
|
lengthTip.innerHTML = ' 1...20 or empty';
|
||||||
|
decimalsTip.innerHTML = ' 0...length or empty';
|
||||||
|
enumField.disabled = true;
|
||||||
|
enumField.value = '0';
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
break;
|
||||||
|
case '4': // XMLDB_TYPE_CHAR
|
||||||
|
lengthTip.innerHTML = ' 1...255';
|
||||||
|
decimalsTip.innerHTML = '';
|
||||||
|
decimalsField.disabled = true;
|
||||||
|
decimalsField.value = '';
|
||||||
|
unsignedField.disabled = true;
|
||||||
|
unsignedField.value = '0';
|
||||||
|
sequenceField.disabled = true;
|
||||||
|
sequenceField.value = '0';
|
||||||
|
break;
|
||||||
|
case '5': // XMLDB_TYPE_TEXT
|
||||||
|
lengthTip.innerHTML = ' small, medium, big';
|
||||||
|
decimalsTip.innerHTML = '';
|
||||||
|
decimalsField.disabled = true;
|
||||||
|
decimalsField.value = '';
|
||||||
|
unsignedField.disabled = true;
|
||||||
|
unsignedField.value = '0';
|
||||||
|
sequenceField.disabled = true;
|
||||||
|
sequenceField.value = '0';
|
||||||
|
defaultField.disabled = true;
|
||||||
|
defaultField.value = '';
|
||||||
|
break;
|
||||||
|
case '6': // XMLDB_TYPE_BINARY
|
||||||
|
lengthTip.innerHTML = ' small, medium, big';
|
||||||
|
decimalsTip.innerHTML = '';
|
||||||
|
decimalsField.disabled = true;
|
||||||
|
decimalsField.value = '';
|
||||||
|
unsignedField.disabled = true;
|
||||||
|
unsignedField.value = '0';
|
||||||
|
sequenceField.disabled = true;
|
||||||
|
sequenceField.value = '0';
|
||||||
|
enumField.disabled = true;
|
||||||
|
enumField.value = '0';
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
defaultField.disabled = true;
|
||||||
|
defaultField.value = '';
|
||||||
|
break;
|
||||||
|
case '7': // XMLDB_TYPE_DATETIME
|
||||||
|
lengthTip.innerHTML = '';
|
||||||
|
lengthField.disabled = true;
|
||||||
|
lengthField.value = '';
|
||||||
|
decimalsTip.innerHTML = '';
|
||||||
|
decimalsField.disabled = true;
|
||||||
|
decimalsField.value = '';
|
||||||
|
unsignedField.disabled = true;
|
||||||
|
unsignedField.value = '0';
|
||||||
|
sequenceField.disabled = true;
|
||||||
|
sequenceField.value = '0';
|
||||||
|
enumField.disabled = true;
|
||||||
|
enumField.value = '0';
|
||||||
|
enumvaluesField.disabled = true;
|
||||||
|
enumvaluesField.value = '';
|
||||||
|
defaultField.disabled = true;
|
||||||
|
defaultField.value = '';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
346
admin/xmldb/actions/edit_field_save/edit_field_save.class.php
Normal file
346
admin/xmldb/actions/edit_field_save/edit_field_save.class.php
Normal file
|
@ -0,0 +1,346 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to one field
|
||||||
|
|
||||||
|
class edit_field_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'fieldnameempty' => 'xmldb',
|
||||||
|
'incorrectfieldname' => 'xmldb',
|
||||||
|
'duplicatefieldname' => 'xmldb',
|
||||||
|
'integerincorrectlength' => 'xmldb',
|
||||||
|
'numberincorrectlength' => 'xmldb',
|
||||||
|
'floatincorrectlength' => 'xmldb',
|
||||||
|
'charincorrectlength' => 'xmldb',
|
||||||
|
'textincorrectlength' => 'xmldb',
|
||||||
|
'binaryincorrectlength' => 'xmldb',
|
||||||
|
'numberincorrectdecimals' => 'xmldb',
|
||||||
|
'floatincorrectdecimals' => 'xmldb',
|
||||||
|
'enumvaluesincorrect' => 'xmldb',
|
||||||
|
'wronglengthforenum' => 'xmldb',
|
||||||
|
'defaultincorrect' => 'xmldb',
|
||||||
|
'administration' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$tableparam = strtolower(required_param('table', PARAM_CLEAN));
|
||||||
|
$fieldparam = strtolower(required_param('field', PARAM_CLEAN));
|
||||||
|
$name = substr(trim(strtolower(optional_param('name', $fieldparam, PARAM_CLEAN))),0,30);
|
||||||
|
|
||||||
|
$comment = required_param('comment', PARAM_CLEAN);
|
||||||
|
$comment = trim(stripslashes_safe($comment));
|
||||||
|
|
||||||
|
$type = required_param('type', PARAM_INT);
|
||||||
|
$length = strtolower(optional_param('length', NULL, PARAM_CLEAN));
|
||||||
|
$decimals = optional_param('decimals', NULL, PARAM_CLEAN);
|
||||||
|
$unsigned = optional_param('unsigned', false, PARAM_BOOL);
|
||||||
|
$notnull = optional_param('notnull', false, PARAM_BOOL);
|
||||||
|
$sequence = optional_param('sequence', false, PARAM_BOOL);
|
||||||
|
$enum = optional_param('enum', false, PARAM_BOOL);
|
||||||
|
$enumvalues = optional_param('enumvalues', 0, PARAM_CLEAN);
|
||||||
|
$enumvalues = trim(stripslashes_safe($enumvalues));
|
||||||
|
$default = optional_param('default', NULL, PARAM_CLEAN);
|
||||||
|
$default = trim(stripslashes_safe($default));
|
||||||
|
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$field =& $table->getField($fieldparam);
|
||||||
|
$oldhash = $field->getHash();
|
||||||
|
|
||||||
|
$errors = array(); /// To store all the errors found
|
||||||
|
|
||||||
|
/// Perform some automatic asumptions
|
||||||
|
if ($sequence) {
|
||||||
|
$unsigned = true;
|
||||||
|
$notnull = true;
|
||||||
|
$enum = false;
|
||||||
|
$default = NULL;
|
||||||
|
}
|
||||||
|
if ($type != XMLDB_TYPE_NUMBER && $type != XMLDB_TYPE_FLOAT) {
|
||||||
|
$decimals = NULL;
|
||||||
|
}
|
||||||
|
if ($type != XMLDB_TYPE_CHAR && $type != XMLDB_TYPE_TEXT) {
|
||||||
|
$enum = false;
|
||||||
|
}
|
||||||
|
if ($type == XMLDB_TYPE_BINARY) {
|
||||||
|
$default = NULL;
|
||||||
|
}
|
||||||
|
if (!$enum) {
|
||||||
|
$enumvalues = NULL;
|
||||||
|
}
|
||||||
|
if ($default === '') {
|
||||||
|
$default = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform some checks
|
||||||
|
/// Check empty name
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = $this->str['fieldnameempty'];
|
||||||
|
}
|
||||||
|
/// Check incorrect name
|
||||||
|
if ($name == 'changeme') {
|
||||||
|
$errors[] = $this->str['incorrectfieldname'];
|
||||||
|
}
|
||||||
|
/// Check duplicate name
|
||||||
|
if ($fieldparam != $name && $table->getField($name)) {
|
||||||
|
$errors[] = $this->str['duplicatefieldname'];
|
||||||
|
}
|
||||||
|
/// Integer checks
|
||||||
|
if ($type == XMLDB_TYPE_INTEGER) {
|
||||||
|
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||||
|
$length > 0 && $length <= 20)) {
|
||||||
|
$errors[] = $this->str['integerincorrectlength'];
|
||||||
|
}
|
||||||
|
if (!(empty($default) || (is_numeric($default) &&
|
||||||
|
!empty($default) &&
|
||||||
|
intval($default)==floatval($default)))) {
|
||||||
|
$errors[] = $this->str['defaultincorrect'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Number checks
|
||||||
|
if ($type == XMLDB_TYPE_NUMBER) {
|
||||||
|
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||||
|
$length > 0 && $length <= 20)) {
|
||||||
|
$errors[] = $this->str['numberincorrectlength'];
|
||||||
|
}
|
||||||
|
if (!(empty($decimals) || (is_numeric($decimals) &&
|
||||||
|
!empty($decimals) &&
|
||||||
|
intval($decimals)==floatval($decimals) &&
|
||||||
|
$decimals >= 0 &&
|
||||||
|
$decimals < $length))) {
|
||||||
|
$errors[] = $this->str['numberincorrectdecimals'];
|
||||||
|
}
|
||||||
|
if (!(empty($default) || (is_numeric($default) &&
|
||||||
|
!empty($default)))) {
|
||||||
|
$errors[] = $this->str['defaultincorrect'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Float checks
|
||||||
|
if ($type == XMLDB_TYPE_FLOAT) {
|
||||||
|
if (!(empty($length) || (is_numeric($length) &&
|
||||||
|
!empty($length) &&
|
||||||
|
intval($length)==floatval($length) &&
|
||||||
|
$length > 0 &&
|
||||||
|
$length <= 20))) {
|
||||||
|
$errors[] = $this->str['floatincorrectlength'];
|
||||||
|
}
|
||||||
|
if (!(empty($decimals) || (is_numeric($decimals) &&
|
||||||
|
!empty($decimals) &&
|
||||||
|
intval($decimals)==floatval($decimals) &&
|
||||||
|
$decimals >= 0 &&
|
||||||
|
$decimals < $length))) {
|
||||||
|
$errors[] = $this->str['floatincorrectdecimals'];
|
||||||
|
}
|
||||||
|
if (!(empty($default) || (is_numeric($default) &&
|
||||||
|
!empty($default)))) {
|
||||||
|
$errors[] = $this->str['defaultincorrect'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Char checks
|
||||||
|
if ($type == XMLDB_TYPE_CHAR) {
|
||||||
|
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||||
|
$length > 0 && $length <= 255)) {
|
||||||
|
$errors[] = $this->str['charincorrectlength'];
|
||||||
|
}
|
||||||
|
if ($default !== NULL && $default !== '') {
|
||||||
|
if (substr($default, 0, 1) == "'" ||
|
||||||
|
substr($default, -1, 1) == "'") {
|
||||||
|
$errors[] = $this->str['defaultincorrect'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Text checks
|
||||||
|
if ($type == XMLDB_TYPE_TEXT) {
|
||||||
|
if ($length != 'small' &&
|
||||||
|
$length != 'medium' &&
|
||||||
|
$length != 'big') {
|
||||||
|
$errors[] = $this->str['textincorrectlength'];
|
||||||
|
}
|
||||||
|
if ($default !== NULL && $default !== '') {
|
||||||
|
if (substr($default, 0, 1) == "'" ||
|
||||||
|
substr($default, -1, 1) == "'") {
|
||||||
|
$errors[] = $this->str['defaultincorrect'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Binary checks
|
||||||
|
if ($type == XMLDB_TYPE_BINARY) {
|
||||||
|
if ($length != 'small' &&
|
||||||
|
$length != 'medium' &&
|
||||||
|
$length != 'big') {
|
||||||
|
$errors[] = $this->str['binaryincorrectlength'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Enum checks
|
||||||
|
if ($enum) {
|
||||||
|
$enumerr = false;
|
||||||
|
$enumarr = explode(',',$enumvalues);
|
||||||
|
$maxlength = 0;
|
||||||
|
if ($enumarr) {
|
||||||
|
foreach ($enumarr as $key => $enumelement) {
|
||||||
|
/// Clear some spaces
|
||||||
|
$enumarr[$key] = trim($enumelement);
|
||||||
|
$enumelement = trim($enumelement);
|
||||||
|
/// Calculate needed length
|
||||||
|
$le = strlen(str_replace("'", '', $enumelement));
|
||||||
|
if ($le > $maxlength) {
|
||||||
|
$maxlength = $le;
|
||||||
|
}
|
||||||
|
/// Skip if under error
|
||||||
|
if ($enumerr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/// Look for quoted strings
|
||||||
|
if (substr($enumelement, 0, 1) != "'" ||
|
||||||
|
substr($enumelement, -1, 1) != "'") {
|
||||||
|
$enumerr = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$enumerr = true;
|
||||||
|
}
|
||||||
|
if ($enumerr) {
|
||||||
|
$errors[] = $this->str['enumvaluesincorrect'];
|
||||||
|
} else {
|
||||||
|
$enumvalues = $enumarr;
|
||||||
|
}
|
||||||
|
if ($length < $maxlength) {
|
||||||
|
$errors[] = $this->str['wronglengthforenum'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$tempfield = new XMLDBField($name);
|
||||||
|
$tempfield->setType($type);
|
||||||
|
$tempfield->setLength($length);
|
||||||
|
$tempfield->setDecimals($decimals);
|
||||||
|
$tempfield->setUnsigned($unsigned);
|
||||||
|
$tempfield->setNotNull($notnull);
|
||||||
|
$tempfield->setSequence($sequence);
|
||||||
|
$tempfield->setEnum($enum);
|
||||||
|
$tempfield->setEnumValues($enumvalues);
|
||||||
|
$tempfield->setDefault($default);
|
||||||
|
/// Prepare the output
|
||||||
|
$site = get_site();
|
||||||
|
print_header("$site->shortname: XMLDB",
|
||||||
|
"$site->fullname",
|
||||||
|
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||||
|
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||||
|
<p>' . $tempfield->readableInfo(),
|
||||||
|
'index.php?action=edit_field&field=' .$field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath));
|
||||||
|
die; /// re-die :-P
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 ($fieldparam != $name) {
|
||||||
|
$field->setName($name);
|
||||||
|
if ($field->getPrevious()) {
|
||||||
|
$prev =& $table->getField($field->getPrevious());
|
||||||
|
$prev->setNext($name);
|
||||||
|
$prev->setChanged(true);
|
||||||
|
}
|
||||||
|
if ($field->getNext()) {
|
||||||
|
$next =& $table->getField($field->getNext());
|
||||||
|
$next->setPrevious($name);
|
||||||
|
$next->setChanged(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set comment
|
||||||
|
$field->setComment($comment);
|
||||||
|
|
||||||
|
/// Set the rest of fields
|
||||||
|
$field->setType($type);
|
||||||
|
$field->setLength($length);
|
||||||
|
$field->setDecimals($decimals);
|
||||||
|
$field->setUnsigned($unsigned);
|
||||||
|
$field->setNotNull($notnull);
|
||||||
|
$field->setSequence($sequence);
|
||||||
|
$field->setEnum($enum);
|
||||||
|
$field->setEnumValues($enumvalues);
|
||||||
|
$field->setDefault($default);
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
/// Mark as changed
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
159
admin/xmldb/actions/edit_index/edit_index.class.php
Normal file
159
admin/xmldb/actions/edit_index/edit_index.class.php
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will provide the interface for all the edit index actions
|
||||||
|
|
||||||
|
class edit_index extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => '',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// Fetch request data
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
if (!$table =& $structure->getTable($tableparam)) {
|
||||||
|
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$indexparam = required_param('index', PARAM_CLEAN);
|
||||||
|
if (!$index =& $table->getIndex($indexparam)) {
|
||||||
|
/// Arriving here from a name change, looking for the new key name
|
||||||
|
$indexparam = required_param('name', PARAM_CLEAN);
|
||||||
|
$index =& $table->getIndex($indexparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $dbdir->xml_file->getStructure();
|
||||||
|
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="index" value="' . $indexparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_index_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
/// 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
|
||||||
|
$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>';
|
||||||
|
/// XMLDBIndex Type
|
||||||
|
$typeoptions = array (0 => 'not unique',
|
||||||
|
1 => 'unique');
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
|
||||||
|
$o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'unique', $index->getUnique(), '', '', '', true) . '</td></tr>';
|
||||||
|
/// XMLDBIndex 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
|
||||||
|
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The view original XML button
|
||||||
|
if ($table->getIndex($indexparam)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode($dirpath) . '&select=original&table=' . $tableparam . '&index=' . $indexparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||||
|
}
|
||||||
|
/// The view edited XML button
|
||||||
|
if ($index->hasChanged()) {
|
||||||
|
$b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode($dirpath) . '&select=edited&table=' . $tableparam . '&index=' . $indexparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||||
|
}
|
||||||
|
/// The back to edit table button
|
||||||
|
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
220
admin/xmldb/actions/edit_index_save/edit_index_save.class.php
Normal file
220
admin/xmldb/actions/edit_index_save/edit_index_save.class.php
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to one index
|
||||||
|
|
||||||
|
class edit_index_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'indexnameempty' => 'xmldb',
|
||||||
|
'incorrectindexname' => 'xmldb',
|
||||||
|
'duplicateindexname' => 'xmldb',
|
||||||
|
'nofieldsspecified' => 'xmldb',
|
||||||
|
'duplicatefieldsused' => 'xmldb',
|
||||||
|
'fieldsnotintable' => 'xmldb',
|
||||||
|
'fieldsusedinkey' => 'xmldb',
|
||||||
|
'fieldsusedinindex' => 'xmldb',
|
||||||
|
'administration' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$tableparam = strtolower(required_param('table', PARAM_CLEAN));
|
||||||
|
$indexparam = strtolower(required_param('index', PARAM_CLEAN));
|
||||||
|
$name = trim(strtolower(optional_param('name', $indexparam, PARAM_CLEAN)));
|
||||||
|
|
||||||
|
$comment = required_param('comment', PARAM_CLEAN);
|
||||||
|
$comment = trim(stripslashes_safe($comment));
|
||||||
|
|
||||||
|
$unique = required_param('unique', PARAM_INT);
|
||||||
|
$fields = required_param('fields', PARAM_CLEAN);
|
||||||
|
$fields = str_replace(' ', '', trim(strtolower(stripslashes_safe($fields))));
|
||||||
|
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$index =& $table->getIndex($indexparam);
|
||||||
|
$oldhash = $index->getHash();
|
||||||
|
|
||||||
|
$errors = array(); /// To store all the errors found
|
||||||
|
|
||||||
|
/// Perform some checks
|
||||||
|
/// Check empty name
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = $this->str['indexnameempty'];
|
||||||
|
}
|
||||||
|
/// Check incorrect name
|
||||||
|
if ($name == 'changeme') {
|
||||||
|
$errors[] = $this->str['incorrectindexname'];
|
||||||
|
}
|
||||||
|
/// Check duplicate name
|
||||||
|
if ($indexparam != $name && $table->getIndex($name)) {
|
||||||
|
$errors[] = $this->str['duplicateindexname'];
|
||||||
|
}
|
||||||
|
$fieldsarr = explode(',', $fields);
|
||||||
|
/// Check the fields isn't empty
|
||||||
|
if (empty($fieldsarr[0])) {
|
||||||
|
$errors[] = $this->str['nofieldsspecified'];
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
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
|
||||||
|
$tablekeys = $table->getKeys();
|
||||||
|
if ($tablekeys) {
|
||||||
|
foreach ($tablekeys as $tablekey) {
|
||||||
|
$keyfieldsarr = $tablekey->getFields();
|
||||||
|
/// Compare both arrays, looking for diferences
|
||||||
|
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
|
||||||
|
if (empty($diferences)) {
|
||||||
|
$errors[] = $this->str['fieldsusedinkey'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Check that there isn't any index using exactlt the same fields
|
||||||
|
$tableindexes = $table->getIndexes();
|
||||||
|
if ($tableindexes) {
|
||||||
|
foreach ($tableindexes as $tableindex) {
|
||||||
|
/// Skip checking against itself
|
||||||
|
if ($indexparam == $tableindex->getName()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$indexfieldsarr = $tableindex->getFields();
|
||||||
|
/// Compare both arrays, looking for diferences
|
||||||
|
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
|
||||||
|
if (empty($diferences)) {
|
||||||
|
$errors[] = $this->str['fieldsusedinindex'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$tempindex = new XMLDBIndex($name);
|
||||||
|
$tempindex->setUnique($unique);
|
||||||
|
$tempindex->setFields($fieldsarr);
|
||||||
|
/// Prepare the output
|
||||||
|
$site = get_site();
|
||||||
|
print_header("$site->shortname: XMLDB",
|
||||||
|
"$site->fullname",
|
||||||
|
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||||
|
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||||
|
<p>' . $tempindex->readableInfo(),
|
||||||
|
'index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath));
|
||||||
|
die; /// re-die :-P
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 ($indexparam != $name) {
|
||||||
|
$index->setName($name);
|
||||||
|
if ($index->getPrevious()) {
|
||||||
|
$prev =& $table->getIndex($index->getPrevious());
|
||||||
|
$prev->setNext($name);
|
||||||
|
$prev->setChanged(true);
|
||||||
|
}
|
||||||
|
if ($index->getNext()) {
|
||||||
|
$next =& $table->getIndex($index->getNext());
|
||||||
|
$next->setPrevious($name);
|
||||||
|
$next->setChanged(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set comment
|
||||||
|
$index->setComment($comment);
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
$index->calculateHash(true);
|
||||||
|
if ($oldhash != $index->getHash()) {
|
||||||
|
$index->setChanged(true);
|
||||||
|
$table->setChanged(true);
|
||||||
|
/// Recalculate the structure hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
/// Mark as changed
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
171
admin/xmldb/actions/edit_key/edit_key.class.php
Normal file
171
admin/xmldb/actions/edit_key/edit_key.class.php
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will provide the interface for all the edit key actions
|
||||||
|
|
||||||
|
class edit_key extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => '',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// Fetch request data
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
if (!$table =& $structure->getTable($tableparam)) {
|
||||||
|
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$keyparam = required_param('key', PARAM_CLEAN);
|
||||||
|
if (!$key =& $table->getKey($keyparam)) {
|
||||||
|
/// Arriving here from a name change, looking for the new key name
|
||||||
|
$keyparam = required_param('name', PARAM_CLEAN);
|
||||||
|
$key =& $table->getKey($keyparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $dbdir->xml_file->getStructure();
|
||||||
|
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="key" value="' . $keyparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_key_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
/// 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
|
||||||
|
$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>';
|
||||||
|
/// XMLDBKey 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);
|
||||||
|
/// }
|
||||||
|
$o.= ' <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
|
||||||
|
$o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'type', $key->getType(), '', '', '', true) . '</td></tr>';
|
||||||
|
/// XMLDBKey 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>';
|
||||||
|
/// XMLDBKey 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>';
|
||||||
|
/// XMLDBKey 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
|
||||||
|
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The view original XML button
|
||||||
|
if ($table->getKey($keyparam)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_key_xml&dir=' . urlencode($dirpath) . '&select=original&table=' . $tableparam . '&key=' . $keyparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||||
|
}
|
||||||
|
/// The view edited XML button
|
||||||
|
if ($key->hasChanged()) {
|
||||||
|
$b .= ' <a href="index.php?action=view_key_xml&dir=' . urlencode($dirpath) . '&select=edited&table=' . $tableparam . '&key=' . $keyparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||||
|
}
|
||||||
|
/// The back to edit table button
|
||||||
|
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
77
admin/xmldb/actions/edit_key/edit_key.js
Normal file
77
admin/xmldb/actions/edit_key/edit_key.js
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/// $Id $
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/// Register the needed events
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function controls all modifications to perform when any field changes
|
||||||
|
*/
|
||||||
|
function transformForm(event) {
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
typeField.disabled = false;
|
||||||
|
fieldsField.disabled = false;
|
||||||
|
reftableField.disabled = false;
|
||||||
|
reffieldsField.disabled = false;
|
||||||
|
|
||||||
|
/// Based on type, disable some items
|
||||||
|
switch (typeField.value) {
|
||||||
|
case '1': // XMLDB_KEY_PRIMARY
|
||||||
|
case '2': // XMLDB_KEY_UNIQUE
|
||||||
|
reftableField.disabled = true;
|
||||||
|
reftableField.value = '';
|
||||||
|
reffieldsField.disabled = true;
|
||||||
|
reffieldsField.value = '';
|
||||||
|
break;
|
||||||
|
case '3': // XMLDB_KEY_FOREIGN
|
||||||
|
case '5': // XMLDB_KEY_FOREIGN_UNIQUE
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
301
admin/xmldb/actions/edit_key_save/edit_key_save.class.php
Normal file
301
admin/xmldb/actions/edit_key_save/edit_key_save.class.php
Normal file
|
@ -0,0 +1,301 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to one key
|
||||||
|
|
||||||
|
class edit_key_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'keynameempty' => 'xmldb',
|
||||||
|
'incorrectkeyname' => 'xmldb',
|
||||||
|
'duplicatekeyname' => 'xmldb',
|
||||||
|
'nofieldsspecified' => 'xmldb',
|
||||||
|
'duplicatefieldsused' => 'xmldb',
|
||||||
|
'fieldsnotintable' => 'xmldb',
|
||||||
|
'fieldsusedinkey' => 'xmldb',
|
||||||
|
'fieldsusedinindex' => 'xmldb',
|
||||||
|
'noreftablespecified' => 'xmldb',
|
||||||
|
'wrongnumberofreffields' => 'xmldb',
|
||||||
|
'noreffieldsspecified' => 'xmldb',
|
||||||
|
'nomasterprimaryuniquefound' => 'xmldb',
|
||||||
|
'masterprimaryuniqueordernomatch' => 'xmldb',
|
||||||
|
'primarykeyonlyallownotnullfields' => 'xmldb',
|
||||||
|
'administration' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$tableparam = strtolower(required_param('table', PARAM_CLEAN));
|
||||||
|
$keyparam = strtolower(required_param('key', PARAM_CLEAN));
|
||||||
|
$name = trim(strtolower(optional_param('name', $keyparam, PARAM_CLEAN)));
|
||||||
|
|
||||||
|
$comment = required_param('comment', PARAM_CLEAN);
|
||||||
|
$comment = trim(stripslashes_safe($comment));
|
||||||
|
|
||||||
|
$type = required_param('type', PARAM_INT);
|
||||||
|
$fields = required_param('fields', PARAM_CLEAN);
|
||||||
|
$fields = str_replace(' ', '', trim(strtolower(stripslashes_safe($fields))));
|
||||||
|
|
||||||
|
if ($type == XMLDB_KEY_FOREIGN ||
|
||||||
|
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||||
|
$reftable = trim(strtolower(required_param('reftable', PARAM_CLEAN)));
|
||||||
|
$reffields= required_param('reffields', PARAM_CLEAN);
|
||||||
|
$reffields = str_replace(' ', '', trim(strtolower(stripslashes_safe($reffields))));
|
||||||
|
}
|
||||||
|
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$key =& $table->getKey($keyparam);
|
||||||
|
$oldhash = $key->getHash();
|
||||||
|
|
||||||
|
$errors = array(); /// To store all the errors found
|
||||||
|
|
||||||
|
/// Perform some checks
|
||||||
|
/// Check empty name
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = $this->str['keynameempty'];
|
||||||
|
}
|
||||||
|
/// Check incorrect name
|
||||||
|
if ($name == 'changeme') {
|
||||||
|
$errors[] = $this->str['incorrectkeyname'];
|
||||||
|
}
|
||||||
|
/// Check duplicate name
|
||||||
|
if ($keyparam != $name && $table->getKey($name)) {
|
||||||
|
$errors[] = $this->str['duplicatekeyname'];
|
||||||
|
}
|
||||||
|
$fieldsarr = explode(',', $fields);
|
||||||
|
/// Check the fields isn't empty
|
||||||
|
if (empty($fieldsarr[0])) {
|
||||||
|
$errors[] = $this->str['nofieldsspecified'];
|
||||||
|
} else {
|
||||||
|
/// 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
|
||||||
|
foreach ($fieldsarr as $field) {
|
||||||
|
if (!$table->getField($field)) {
|
||||||
|
$errors[] = $this->str['fieldsnotintable'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// If primary, check that all the fields are not null
|
||||||
|
if ($type == XMLDB_KEY_PRIMARY) {
|
||||||
|
foreach ($fieldsarr as $field) {
|
||||||
|
if ($fi = $table->getField($field)) {
|
||||||
|
if (!$fi->getNotNull()) {
|
||||||
|
$errors[] = $this->str['primarykeyonlyallownotnullfields'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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
|
||||||
|
if ($keyparam == $tablekey->getName()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$keyfieldsarr = $tablekey->getFields();
|
||||||
|
/// Compare both arrays, looking for diferences
|
||||||
|
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
|
||||||
|
if (empty($diferences)) {
|
||||||
|
$errors[] = $this->str['fieldsusedinkey'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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
|
||||||
|
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
|
||||||
|
if (empty($diferences)) {
|
||||||
|
$errors[] = $this->str['fieldsusedinindex'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// If foreign key
|
||||||
|
if ($type == XMLDB_KEY_FOREIGN ||
|
||||||
|
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||||
|
$reffieldsarr = explode(',', $reffields);
|
||||||
|
/// Check reftable is not empty
|
||||||
|
if (empty($reftable)) {
|
||||||
|
$errors[] = $this->str['noreftablespecified'];
|
||||||
|
} else
|
||||||
|
/// Check reffields are not empty
|
||||||
|
if (empty($reffieldsarr[0])) {
|
||||||
|
$errors[] = $this->str['noreffieldsspecified'];
|
||||||
|
} else
|
||||||
|
/// 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
|
||||||
|
if ($rt = $structure->getTable($reftable)) {
|
||||||
|
$masterfound = false;
|
||||||
|
$reftablekeys = $rt->getKeys();
|
||||||
|
if ($reftablekeys) {
|
||||||
|
foreach ($reftablekeys as $reftablekey) {
|
||||||
|
/// 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
|
||||||
|
$diferences = array_merge(array_diff($reffieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $reffieldsarr));
|
||||||
|
if (empty($diferences)) {
|
||||||
|
$masterfound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$masterfound) {
|
||||||
|
$errors[] = $this->str['nomasterprimaryuniquefound'];
|
||||||
|
} else {
|
||||||
|
/// Quick test of the order
|
||||||
|
if (implode(',', $reffieldsarr) != implode(',', $keyfieldsarr)) {
|
||||||
|
$errors[] = $this->str['masterprimaryuniqueordernomatch'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$tempkey = new XMLDBKey($name);
|
||||||
|
$tempkey->setType($type);
|
||||||
|
$tempkey->setFields($fieldsarr);
|
||||||
|
if ($type == XMLDB_KEY_FOREIGN ||
|
||||||
|
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||||
|
$tempkey->setRefTable($reftable);
|
||||||
|
$tempkey->setRefFields($reffieldsarr);
|
||||||
|
}
|
||||||
|
/// Prepare the output
|
||||||
|
$site = get_site();
|
||||||
|
print_header("$site->shortname: XMLDB",
|
||||||
|
"$site->fullname",
|
||||||
|
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||||
|
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||||
|
<p>' . $tempkey->readableInfo(),
|
||||||
|
'index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath));
|
||||||
|
die; /// re-die :-P
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 ($keyparam != $name) {
|
||||||
|
$key->setName($name);
|
||||||
|
if ($key->getPrevious()) {
|
||||||
|
$prev =& $table->getKey($key->getPrevious());
|
||||||
|
$prev->setNext($name);
|
||||||
|
$prev->setChanged(true);
|
||||||
|
}
|
||||||
|
if ($key->getNext()) {
|
||||||
|
$next =& $table->getKey($key->getNext());
|
||||||
|
$next->setPrevious($name);
|
||||||
|
$next->setChanged(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set comment
|
||||||
|
$key->setComment($comment);
|
||||||
|
|
||||||
|
/// Set the rest of fields
|
||||||
|
$key->setType($type);
|
||||||
|
$key->setFields($fieldsarr);
|
||||||
|
if ($type == XMLDB_KEY_FOREIGN ||
|
||||||
|
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||||
|
$key->setRefTable($reftable);
|
||||||
|
$key->setRefFields($reffieldsarr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
/// Mark as changed
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
153
admin/xmldb/actions/edit_sentence/edit_sentence.class.php
Normal file
153
admin/xmldb/actions/edit_sentence/edit_sentence.class.php
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will provide the interface for all the edit sentence actions
|
||||||
|
|
||||||
|
class edit_sentence extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// Fetch request data
|
||||||
|
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||||
|
$sentenceparam = optional_param('sentence', NULL, PARAM_CLEAN);
|
||||||
|
|
||||||
|
if (!$statement =& $structure->getStatement($statementparam)) {
|
||||||
|
$this->errormsg = 'Wrong statement specified: ' . $statementparam;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$sentences =& $statement->getSentences();
|
||||||
|
|
||||||
|
/// If no sentence has been specified, edit the last one
|
||||||
|
if ($sentenceparam === NULL) {
|
||||||
|
end($sentences);
|
||||||
|
$sentenceparam = key($sentences);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$sentence =& $sentences[$sentenceparam]) {
|
||||||
|
$this->errormsg = 'Wrong Sentence: ' . $sentenceparam;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $dbdir->xml_file->getStructure();
|
||||||
|
|
||||||
|
/// Based in the type of statement, print different forms
|
||||||
|
if ($statement->getType() != XMLDB_STATEMENT_INSERT) {
|
||||||
|
/// Only INSERT is allowed!!
|
||||||
|
$this->errormsg = 'Wrong Statement Type. Only INSERT allowed';
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
/// Prepare INSERT sentence
|
||||||
|
$fields = $statement->getFieldsFromInsertSentence($sentence);
|
||||||
|
$values = $statement->getValuesFromInsertSentence($sentence);
|
||||||
|
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="sentence" value="' . $sentenceparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_sentence_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
/// The fields box
|
||||||
|
$o.= ' <tr><td>INSERT INTO ' . s($statement->getTable()) . '</td></tr>';
|
||||||
|
$o.= ' <tr><td><textarea name="fields" rows="2" cols="70" id="fields">' . s(implode(', ', $fields)) . '</textarea></td></tr>';
|
||||||
|
/// The values box
|
||||||
|
$o.= ' <tr><td>VALUES</td></tr>';
|
||||||
|
$o.= ' <tr><td><textarea name="values" rows="2" cols="70" id="values">' . s(implode(', ', $values)) . '</textarea></td></tr>';
|
||||||
|
/// The submit button
|
||||||
|
$o.= ' <tr valign="top"><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The back to edit statement button
|
||||||
|
$b .= ' <a href="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,155 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to one sentence
|
||||||
|
|
||||||
|
class edit_sentence_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'cannotuseidfield' => 'xmldb',
|
||||||
|
'missingfieldsinsentence' => 'xmldb',
|
||||||
|
'missingvaluesinsentence' => 'xmldb',
|
||||||
|
'wrongnumberoffieldsorvalues' => 'xmldb',
|
||||||
|
'administration' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$statementparam = strtolower(required_param('statement', PARAM_CLEAN));
|
||||||
|
$sentenceparam = strtolower(required_param('sentence', PARAM_CLEAN));
|
||||||
|
|
||||||
|
$fields = required_param('fields', PARAM_CLEAN);
|
||||||
|
$fields = trim(stripslashes_safe($fields));
|
||||||
|
$values = required_param('values', PARAM_CLEAN);
|
||||||
|
$values = trim(stripslashes_safe($values));
|
||||||
|
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
$statement =& $structure->getStatement($statementparam);
|
||||||
|
$sentences =& $statement->getSentences();
|
||||||
|
|
||||||
|
$oldsentence = $sentences[$sentenceparam];
|
||||||
|
|
||||||
|
if (!$statement) {
|
||||||
|
$this->errormsg = 'Wrong statement specified: ' . $statementparam;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// For now, only insert sentences are allowed
|
||||||
|
if ($statement->getType() != XMLDB_STATEMENT_INSERT) {
|
||||||
|
$this->errormsg = 'Wrong Statement Type. Only INSERT allowed';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors = array(); /// To store all the errors found
|
||||||
|
|
||||||
|
/// Build the whole sentence
|
||||||
|
$sentence = '(' . $fields . ') VALUES (' . $values . ')';
|
||||||
|
|
||||||
|
/// Perform some checks
|
||||||
|
$fields = $statement->getFieldsFromInsertSentence($sentence);
|
||||||
|
$values = $statement->getValuesFromInsertSentence($sentence);
|
||||||
|
|
||||||
|
if (in_array('id', $fields)) {
|
||||||
|
$errors[] = $this->str['cannotuseidfield'];
|
||||||
|
}
|
||||||
|
if ($result && count($fields) == 0) {
|
||||||
|
$errors[] = $this->str['missingfieldsinsentence'];
|
||||||
|
}
|
||||||
|
if ($result && count($values) == 0) {
|
||||||
|
$errors[] = $this->str['missingvaluesinsentence'];
|
||||||
|
}
|
||||||
|
if ($result && count($fields) != count($values)) {
|
||||||
|
$errors[] = $this->str['wrongnumberoffieldsorvalues'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
/// Prepare the output
|
||||||
|
$site = get_site();
|
||||||
|
print_header("$site->shortname: XMLDB",
|
||||||
|
"$site->fullname",
|
||||||
|
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||||
|
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||||
|
<p>' . s($sentence),
|
||||||
|
'index.php?action=edit_sentence&sentence=' .$sentenceparam . '&statement=' . urlencode($statementparam) . '&dir=' . urlencode($dirpath));
|
||||||
|
die; /// re-die :-P
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Continue if we aren't under errors
|
||||||
|
if (empty($errors)) {
|
||||||
|
$sentences[$sentenceparam] = $sentence;
|
||||||
|
|
||||||
|
/// If the sentence has changed from the old one, change the version
|
||||||
|
/// and mark the statement and structure as changed
|
||||||
|
if ($oldsentence != $sentence) {
|
||||||
|
$statement->setChanged(true);
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
/// Mark as changed
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
182
admin/xmldb/actions/edit_statement/edit_statement.class.php
Normal file
182
admin/xmldb/actions/edit_statement/edit_statement.class.php
Normal file
|
@ -0,0 +1,182 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will provide the interface for all the edit statement actions
|
||||||
|
|
||||||
|
class edit_statement extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'newsentence' => 'xmldb',
|
||||||
|
'sentences' => 'xmldb',
|
||||||
|
'edit' => 'xmldb',
|
||||||
|
'delete' => 'xmldb',
|
||||||
|
'duplicate' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$statementparam = optional_param('statement', NULL, PARAM_CLEAN);
|
||||||
|
/// If no statement, then we are coming for a new one. Look for
|
||||||
|
/// type and table and build the correct statementparam
|
||||||
|
if (!$statementparam) {
|
||||||
|
$typeparam = optional_param('type', NULL, PARAM_CLEAN);
|
||||||
|
$tableparam = optional_param('table', NULL, PARAM_CLEAN);
|
||||||
|
$typename = XMLDBStatement::getXMLDBStatementName($typeparam);
|
||||||
|
$statementparam = trim(strtolower($typename . ' ' . $tableparam));
|
||||||
|
}
|
||||||
|
if (!$statement =& $structure->getStatement($statementparam)) {
|
||||||
|
/// Arriving here from a name change, looking for the new statement name
|
||||||
|
$statementname = required_param('name', PARAM_CLEAN);
|
||||||
|
$statement =& $structure->getStatement($statementparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $dbdir->xml_file->getStructure();
|
||||||
|
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_statement_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
$o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($statement->getName()) . '" />' . s($statement->getName()) .'</td></tr>';
|
||||||
|
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . s($statement->getComment()) . '</textarea></td></tr>';
|
||||||
|
$o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The view original XML button
|
||||||
|
if ($origstructure->getStatement($statementparam)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode($dirpath) . '&select=original&statement=' . $statementparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||||
|
}
|
||||||
|
/// The view edited XML button
|
||||||
|
if ($statement->hasChanged()) {
|
||||||
|
$b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode($dirpath) . '&select=edited&statement=' . $statementparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||||
|
}
|
||||||
|
/// The new sentence button
|
||||||
|
$b .= ' <a href="index.php?action=new_sentence&postaction=edit_sentence&statement=' . $statementparam . '&dir=' . urlencode($dirpath) . '">[' . $this->str['newsentence'] . ']</a>';
|
||||||
|
/// The back to edit xml file button
|
||||||
|
$b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
/// Delete any 'changeme' sentence
|
||||||
|
///$statement->deleteSentence('changeme');
|
||||||
|
|
||||||
|
/// Add the fields list
|
||||||
|
$sentences =& $statement->getSentences();
|
||||||
|
if (!empty($sentences)) {
|
||||||
|
$o .= '<h3 class="main">' . $this->str['sentences'] . '</h3>';
|
||||||
|
$o .= '<table id="listfields" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($sentences as $key => $sentence) {
|
||||||
|
/// Prepend some SQL
|
||||||
|
if ($statement->getType() == XMLDB_STATEMENT_INSERT) {
|
||||||
|
$p = 'INSERT INTO ' . $statement->getTable() . ' ';
|
||||||
|
} else {
|
||||||
|
$p = 'UNSUPPORTED SENTENCE TYPE ';
|
||||||
|
}
|
||||||
|
/// Calculate buttons
|
||||||
|
$b = '</td><td class="button cell">';
|
||||||
|
/// The edit button
|
||||||
|
$b .= '<a href="index.php?action=edit_sentence&sentence=' .$key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode($dirpath) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The duplicate button
|
||||||
|
$b .= '<a href="index.php?action=new_sentence&postaction=edit_sentence&basesentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode($dirpath) . '">[' . $this->str['duplicate'] . ']</a>';
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The delete button
|
||||||
|
$b .= '<a href="index.php?action=delete_sentence&sentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode($dirpath) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
$b .= '</td>';
|
||||||
|
/// Print table row
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,108 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to the name and comment of
|
||||||
|
/// one statement
|
||||||
|
|
||||||
|
class edit_statement_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'administration' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$statementparam = strtolower(required_param('statement', PARAM_CLEAN));
|
||||||
|
$name = trim(strtolower(required_param('name', PARAM_CLEAN)));
|
||||||
|
$comment = required_param('comment', PARAM_CLEAN);
|
||||||
|
$comment = stripslashes_safe($comment);
|
||||||
|
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
$statement =& $structure->getStatement($statementparam);
|
||||||
|
|
||||||
|
$errors = array(); /// To store all the errors found
|
||||||
|
|
||||||
|
/// If there is one name change, do it, changing the prev and next
|
||||||
|
/// atributes of the adjacent tables
|
||||||
|
if ($statementparam != $name) {
|
||||||
|
$statement->setName($name);
|
||||||
|
if ($statement->getPrevious()) {
|
||||||
|
$prev =& $structure->getStatement($statement->getPrevious());
|
||||||
|
$prev->setNext($name);
|
||||||
|
$prev->setChanged(true);
|
||||||
|
}
|
||||||
|
if ($statement->getNext()) {
|
||||||
|
$next =& $structure->getStatement($statement->getNext());
|
||||||
|
$next->setPrevious($name);
|
||||||
|
$next->setChanged(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set comment
|
||||||
|
$statement->setComment($comment);
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
310
admin/xmldb/actions/edit_table/edit_table.class.php
Normal file
310
admin/xmldb/actions/edit_table/edit_table.class.php
Normal file
|
@ -0,0 +1,310 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will provide the interface for all the edit table actions
|
||||||
|
|
||||||
|
class edit_table extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'viewsqlcode' => 'xmldb',
|
||||||
|
'viewphpcode' => 'xmldb',
|
||||||
|
'newfield' => 'xmldb',
|
||||||
|
'newkey' => 'xmldb',
|
||||||
|
'newindex' => 'xmldb',
|
||||||
|
'fields' => 'xmldb',
|
||||||
|
'keys' => 'xmldb',
|
||||||
|
'indexes' => 'xmldb',
|
||||||
|
'edit' => 'xmldb',
|
||||||
|
'up' => 'xmldb',
|
||||||
|
'down' => 'xmldb',
|
||||||
|
'delete' => 'xmldb',
|
||||||
|
'reserved' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
if (!$table =& $structure->getTable($tableparam)) {
|
||||||
|
/// Arriving here from a name change, looking for the new table name
|
||||||
|
$tableparam = required_param('name', PARAM_CLEAN);
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $dbdir->xml_file->getStructure();
|
||||||
|
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_table_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
/// 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 {
|
||||||
|
$o.= ' <tr valign="top"><td><label for="name" accesskey="p">Name:</label></td><td><input name="name" type="text" size="28" maxlength="28" id="name" value="' . s($table->getName()) . '" /></td></tr>';
|
||||||
|
}
|
||||||
|
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . s($table->getComment()) . '</textarea></td></tr>';
|
||||||
|
$o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The view original XML button
|
||||||
|
if ($origstructure->getTable($tableparam)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode($dirpath) . '&select=original&table=' . $tableparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||||
|
}
|
||||||
|
/// The view edited XML button
|
||||||
|
if ($table->hasChanged()) {
|
||||||
|
$b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode($dirpath) . '&select=edited&table=' . $tableparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||||
|
}
|
||||||
|
/// The new field button
|
||||||
|
$b .= ' <a href="index.php?action=new_field&postaction=edit_field&table=' . $tableparam . '&field=changeme&dir=' . urlencode($dirpath) . '">[' . $this->str['newfield'] . ']</a>';
|
||||||
|
/// The new key button
|
||||||
|
$b .= ' <a href="index.php?action=new_key&postaction=edit_key&table=' . $tableparam . '&key=changeme&dir=' . urlencode($dirpath) . '">[' . $this->str['newkey'] . ']</a>';
|
||||||
|
/// The new index button
|
||||||
|
$b .= ' <a href="index.php?action=new_index&postaction=edit_index&table=' . $tableparam . '&index=changeme&dir=' . urlencode($dirpath) . '">[' . $this->str['newindex'] . ']</a>';
|
||||||
|
/// The back to edit xml file button
|
||||||
|
$b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$b .= ' <p align="center" class="buttons">';
|
||||||
|
/// The view sql code button
|
||||||
|
$b .= '<a href="index.php?action=view_table_sql&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '">[' .$this->str['viewsqlcode'] . ']</a>';
|
||||||
|
/// The view php code button
|
||||||
|
$b .= ' <a href="index.php?action=view_table_php&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '">[' . $this->str['viewphpcode'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
/// Join all the reserved words into one big array
|
||||||
|
/// Calculate list of available SQL generators
|
||||||
|
$plugins = get_list_of_plugins('lib/xmldb/classes/generators');
|
||||||
|
$reserved_words = array();
|
||||||
|
foreach($plugins as $plugin) {
|
||||||
|
$classname = 'XMLDB' . $plugin;
|
||||||
|
$generator = new $classname();
|
||||||
|
$reserved_words = array_merge($reserved_words, $generator->getReservedWords());
|
||||||
|
}
|
||||||
|
sort($reserved_words);
|
||||||
|
$reserved_words = array_unique($reserved_words);
|
||||||
|
|
||||||
|
/// Delete any 'changeme' field/key/index
|
||||||
|
$table->deleteField('changeme');
|
||||||
|
$table->deleteKey('changeme');
|
||||||
|
$table->deleteIndex('changeme');
|
||||||
|
|
||||||
|
/// Add the fields list
|
||||||
|
$fields =& $table->getFields();
|
||||||
|
if (!empty($fields)) {
|
||||||
|
$o .= '<h3 class="main">' . $this->str['fields'] . '</h3>';
|
||||||
|
$o .= '<table id="listfields" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
/// Calculate buttons
|
||||||
|
$b = '</td><td class="button cell">';
|
||||||
|
/// The edit button (if the field has no uses)
|
||||||
|
if (!$structure->getFieldUses($table->getName(), $field->getName())) {
|
||||||
|
$b .= '<a href="index.php?action=edit_field&field=' .$field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['edit'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The up button
|
||||||
|
if ($field->getPrevious()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_field&direction=up&field=' . $field->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['up'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['up'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The down button
|
||||||
|
if ($field->getNext()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_field&direction=down&field=' . $field->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode($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
|
||||||
|
if (count($fields) > 1 &&
|
||||||
|
!$structure->getFieldUses($table->getName(), $field->getName())) {
|
||||||
|
$b .= '<a href="index.php?action=delete_field&field=' . $field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['delete'] . ']';
|
||||||
|
}
|
||||||
|
/// Detect if the table name is a reserved word
|
||||||
|
if (in_array($field->getName(), $reserved_words)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_reserved_words"><span class="error">' . $this->str['reserved'] . '</span></a>';
|
||||||
|
}
|
||||||
|
/// The readable info
|
||||||
|
$r = '</td><td class="readableinfo cell">' . $field->readableInfo() . '</td>';
|
||||||
|
/// Print table row
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_field_xml&dir=' . urlencode($dirpath) . '&field=' . $field->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $field->getName() . '</a>' . $b . $r . '</tr>';
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
}
|
||||||
|
/// Add the keys list
|
||||||
|
$keys =& $table->getKeys();
|
||||||
|
if (!empty($keys)) {
|
||||||
|
$o .= '<h3 class="main">' . $this->str['keys'] . '</h3>';
|
||||||
|
$o .= '<table id="listkeys" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
/// Calculate buttons
|
||||||
|
$b = '</td><td class="button cell">';
|
||||||
|
/// The edit button (if the key hasn't uses)
|
||||||
|
if (!$structure->getKeyUses($table->getName(), $key->getName())) {
|
||||||
|
$b .= '<a href="index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['edit'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The up button
|
||||||
|
if ($key->getPrevious()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_key&direction=up&key=' . $key->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['up'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['up'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The down button
|
||||||
|
if ($key->getNext()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_key&direction=down&key=' . $key->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode($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)
|
||||||
|
if (!$structure->getKeyUses($table->getName(), $key->getName())) {
|
||||||
|
$b .= '<a href="index.php?action=delete_key&key=' . $key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['delete'] . ']';
|
||||||
|
}
|
||||||
|
/// The readable info
|
||||||
|
$r = '</td><td class="readableinfo cell">' . $key->readableInfo() . '</td>';
|
||||||
|
/// Print table row
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_key_xml&dir=' . urlencode($dirpath) . '&key=' . $key->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $key->getName() . '</a>' . $b . $r .'</tr>';
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
}
|
||||||
|
/// Add the indexes list
|
||||||
|
$indexes =& $table->getIndexes();
|
||||||
|
if (!empty($indexes)) {
|
||||||
|
$o .= '<h3 class="main">' . $this->str['indexes'] . '</h3>';
|
||||||
|
$o .= '<table id="listindexes" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($indexes as $index) {
|
||||||
|
/// Calculate buttons
|
||||||
|
$b = '</td><td class="button cell">';
|
||||||
|
/// The edit button
|
||||||
|
$b .= '<a href="index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The up button
|
||||||
|
if ($index->getPrevious()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_index&direction=up&index=' . $index->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['up'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['up'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The down button
|
||||||
|
if ($index->getNext()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_index&direction=down&index=' . $index->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['down'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['down'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The delete button
|
||||||
|
$b .= '<a href="index.php?action=delete_index&index=' . $index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
/// The readable info
|
||||||
|
$r = '</td><td class="readableinfo cell">' . $index->readableInfo() . '</td>';
|
||||||
|
/// Print table row
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_index_xml&dir=' . urlencode($dirpath) . '&index=' . $index->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $index->getName() . '</a>' . $b . $r .'</tr>';
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
138
admin/xmldb/actions/edit_table_save/edit_table_save.class.php
Normal file
138
admin/xmldb/actions/edit_table_save/edit_table_save.class.php
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to the name and comment of
|
||||||
|
/// one table
|
||||||
|
|
||||||
|
class edit_table_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'tablenameempty' => 'xmldb',
|
||||||
|
'incorrecttablename' => 'xmldb',
|
||||||
|
'duplicatetablename' => 'xmldb',
|
||||||
|
'administration' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$tableparam = strtolower(required_param('table', PARAM_CLEAN));
|
||||||
|
$name = substr(trim(strtolower(required_param('name', PARAM_CLEAN))),0,28);
|
||||||
|
$comment = required_param('comment', PARAM_CLEAN);
|
||||||
|
$comment = stripslashes_safe($comment);
|
||||||
|
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
|
||||||
|
$errors = array(); /// To store all the errors found
|
||||||
|
|
||||||
|
/// Perform some checks
|
||||||
|
/// Check empty name
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = $this->str['tablenameempty'];
|
||||||
|
}
|
||||||
|
/// Check incorrect name
|
||||||
|
if ($name == 'changeme') {
|
||||||
|
$errors[] = $this->str['incorrecttablename'];
|
||||||
|
}
|
||||||
|
/// Check duplicatename
|
||||||
|
if ($tableparam != $name && $structure->getTable($name)) {
|
||||||
|
$errors[] = $this->str['duplicatetablename'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$temptable = new XMLDBTable($name);
|
||||||
|
/// Prepare the output
|
||||||
|
$site = get_site();
|
||||||
|
print_header("$site->shortname: XMLDB",
|
||||||
|
"$site->fullname",
|
||||||
|
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||||
|
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||||
|
<p>' . $temptable->readableInfo(),
|
||||||
|
'index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath));
|
||||||
|
die; /// re-die :-P
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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()) {
|
||||||
|
$prev =& $structure->getTable($table->getPrevious());
|
||||||
|
$prev->setNext($name);
|
||||||
|
$prev->setChanged(true);
|
||||||
|
}
|
||||||
|
if ($table->getNext()) {
|
||||||
|
$next =& $structure->getTable($table->getNext());
|
||||||
|
$next->setPrevious($name);
|
||||||
|
$next->setChanged(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set comment
|
||||||
|
$table->setComment($comment);
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
252
admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php
Normal file
252
admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php
Normal file
|
@ -0,0 +1,252 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will edit one loaded XML file
|
||||||
|
|
||||||
|
class edit_xml_file extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'change' => 'xmldb',
|
||||||
|
'edit' => 'xmldb',
|
||||||
|
'up' => 'xmldb',
|
||||||
|
'down' => 'xmldb',
|
||||||
|
'delete' => 'xmldb',
|
||||||
|
'vieworiginal' => 'xmldb',
|
||||||
|
'viewedited' => 'xmldb',
|
||||||
|
'tables' => 'xmldb',
|
||||||
|
'statements' => 'xmldb',
|
||||||
|
'newtable' => 'xmldb',
|
||||||
|
'newtablefrommysql' => 'xmldb',
|
||||||
|
'newstatement' => 'xmldb',
|
||||||
|
'viewsqlcode' => 'xmldb',
|
||||||
|
'viewphpcode' => 'xmldb',
|
||||||
|
'reserved' => 'xmldb',
|
||||||
|
'backtomainview' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
//$this->does_generate = ACTION_NONE;
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting $result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
if ($dbdir) {
|
||||||
|
/// 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
|
||||||
|
if (empty($XMLDB->editeddirs)) {
|
||||||
|
$XMLDB->editeddirs = array();
|
||||||
|
}
|
||||||
|
/// Check if the dir exists and copy it from dbdirs
|
||||||
|
if (!isset($XMLDB->editeddirs[$dirpath])) {
|
||||||
|
$XMLDB->editeddirs[$dirpath] = unserialize(serialize($dbdir));
|
||||||
|
}
|
||||||
|
/// Get it
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
/// Add the main form
|
||||||
|
$o = '<form id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="edit_xml_file_save" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_xml_file" />';
|
||||||
|
$o.= ' <input type="hidden" name ="path" value="' . s($structure->getPath()) .'" />';
|
||||||
|
$o.= ' <input type="hidden" name ="version" value="' . s($structure->getVersion()) .'" />';
|
||||||
|
$o.= ' <table id="formelements" align="center">';
|
||||||
|
$o.= ' <tr valign="top"><td>Path:</td><td>' . s($structure->getPath()) . '</td></tr>';
|
||||||
|
$o.= ' <tr valign="top"><td>Version:</td><td>' . s($structure->getVersion()) . '</td></tr>';
|
||||||
|
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . $structure->getComment() . '</textarea></td></tr>';
|
||||||
|
$o.= ' <tr><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
/// The view original XML button
|
||||||
|
$b .= ' <a href="index.php?action=view_structure_xml&dir=' . urlencode($dirpath) . '&select=original" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||||
|
/// The view edited XML button
|
||||||
|
if ($structure->hasChanged()) {
|
||||||
|
$b .= ' <a href="index.php?action=view_structure_xml&dir=' . urlencode($dirpath) . '&select=edited" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||||
|
}
|
||||||
|
/// The new table button
|
||||||
|
$b .= ' <a href="index.php?action=new_table&postaction=edit_table&table=changeme&dir=' . urlencode($dirpath) . '">[' . $this->str['newtable'] . ']</a>';
|
||||||
|
/// The new from MySQL button
|
||||||
|
if ($CFG->dbtype == 'mysql') {
|
||||||
|
$b .= ' <a href="index.php?action=new_table_from_mysql&dir=' . urlencode($dirpath) . '">[' . $this->str['newtablefrommysql'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= ' [' . $this->str['newtablefrommysql'] . ']';
|
||||||
|
}
|
||||||
|
/// The new statement button
|
||||||
|
$b .= ' <a href="index.php?action=new_statement&dir=' . urlencode($dirpath) . '">[' . $this->str['newstatement'] . ']</a>';
|
||||||
|
/// The back to main menu button
|
||||||
|
$b .= ' <a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$b .= ' <p align="center" class="buttons">';
|
||||||
|
/// The view sql code button
|
||||||
|
$b .= '<a href="index.php?action=view_structure_sql&dir=' . urlencode($dirpath) . '">[' .$this->str['viewsqlcode'] . ']</a>';
|
||||||
|
/// The view php code button
|
||||||
|
$b .= ' <a href="index.php?action=view_structure_php&dir=' . urlencode($dirpath) . '">[' . $this->str['viewphpcode'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o .= $b;
|
||||||
|
/// Join all the reserved words into one big array
|
||||||
|
/// Calculate list of available SQL generators
|
||||||
|
$plugins = get_list_of_plugins('lib/xmldb/classes/generators');
|
||||||
|
$reserved_words = array();
|
||||||
|
foreach($plugins as $plugin) {
|
||||||
|
$classname = 'XMLDB' . $plugin;
|
||||||
|
$generator = new $classname();
|
||||||
|
$reserved_words = array_merge($reserved_words, $generator->getReservedWords());
|
||||||
|
}
|
||||||
|
sort($reserved_words);
|
||||||
|
$reserved_words = array_unique($reserved_words);
|
||||||
|
/// Add the tables list
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
if ($tables) {
|
||||||
|
$o .= '<h3 class="main">' . $this->str['tables'] . '</h3>';
|
||||||
|
$o .= '<table id="listtables" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($tables as $table) {
|
||||||
|
/// Calculate buttons
|
||||||
|
$b = '</td><td class="button cell">';
|
||||||
|
/// The edit button
|
||||||
|
$b .= '<a href="index.php?action=edit_table&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The up button
|
||||||
|
if ($table->getPrevious()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_table&direction=up&table=' . $table->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['up'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['up'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The down button
|
||||||
|
if ($table->getNext()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_table&direction=down&table=' . $table->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode($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)
|
||||||
|
if (count($tables) > 1 &&
|
||||||
|
!$structure->getTableUses($table->getName())) {
|
||||||
|
///!$structure->getTableUses($table->getName())) {
|
||||||
|
$b .= '<a href="index.php?action=delete_table&table=' . $table->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['delete'] . ']';
|
||||||
|
}
|
||||||
|
/// Detect if the table name is a reserved word
|
||||||
|
if (in_array($table->getName(), $reserved_words)) {
|
||||||
|
$b .= ' <a href="index.php?action=view_reserved_words"><span class="error">' . $this->str['reserved'] . '</span></a>';
|
||||||
|
}
|
||||||
|
$b .= '</td>';
|
||||||
|
/// Print table row
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_table_xml&dir=' . urlencode($dirpath) . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $table->getName() . '</a>' . $b . '</tr>';
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
}
|
||||||
|
///Add the statements list
|
||||||
|
$statements =& $structure->getStatements();
|
||||||
|
if ($statements) {
|
||||||
|
$o .= '<h3 class="main">' . $this->str['statements'] . '</h3>';
|
||||||
|
$o .= '<table id="liststatements" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($statements as $statement) {
|
||||||
|
/// Calculate buttons
|
||||||
|
$b = '</td><td class="button cell">';
|
||||||
|
/// The edit button
|
||||||
|
$b .= '<a href="index.php?action=edit_statement&statement=' . $statement->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The up button
|
||||||
|
if ($statement->getPrevious()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_statement&direction=up&statement=' . $statement->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['up'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['up'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The down button
|
||||||
|
if ($statement->getNext()) {
|
||||||
|
$b .= '<a href="index.php?action=move_updown_statement&direction=down&statement=' . $statement->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode($dirpath) . '">[' . $this->str['down'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['down'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The delete button
|
||||||
|
$b .= '<a href="index.php?action=delete_statement&statement=' . $statement->getName() . '&dir=' . urlencode($dirpath) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
$b .= '</td>';
|
||||||
|
/// Print statement row
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="statement cell"><a href="index.php?action=view_statement_xml&dir=' . urlencode($dirpath) . '&statement=' . $statement->getName() . '&select=edited" target="_blank">' . $statement->getName() . '</a>' . $b . '</tr>';
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
}
|
||||||
|
///Add the back to main
|
||||||
|
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this unmodified)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save the changes performed to the comment of one file
|
||||||
|
|
||||||
|
class edit_xml_file_save extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$comment = required_param('comment', PARAM_CLEAN);
|
||||||
|
$comment = stripslashes_safe($comment);
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
$origdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
$origstructure =& $origdir->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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,151 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will check all the db directories existing under the
|
||||||
|
/// current Moodle installation, sending them to the SESSION->dbdirs array
|
||||||
|
|
||||||
|
class get_db_directories extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->can_subaction = ACTION_NONE;
|
||||||
|
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting $result as needed
|
||||||
|
|
||||||
|
/// Lets go to add all the db directories available inside Moodle
|
||||||
|
/// Create the array if it doesn't exists
|
||||||
|
if (!isset($XMLDB->dbdirs)) {
|
||||||
|
$XMLDB->dbdirs = array();
|
||||||
|
}
|
||||||
|
/// First, the main one (lib/db)
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->libdir . '/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, activity modules (mod/xxx/db)
|
||||||
|
if ($plugins = get_list_of_plugins('mod')) {
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->dirroot . '/mod/' . $plugin . '/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, question types (question/type/xxx/db)
|
||||||
|
if ($plugins = get_list_of_plugins('question/type')) {
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->dirroot . '/question/type/' . $plugin . '/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, backup/restore stuff (backup/db)
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->dirroot . '/backup/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, block system stuff (blocks/db)
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->dirroot . '/blocks/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, blocks (blocks/xxx/db)
|
||||||
|
if ($plugins = get_list_of_plugins('blocks', 'db')) {
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->dirroot . '/blocks/' . $plugin . '/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Now, enrolment plugins (enrol/xxx/db)
|
||||||
|
if ($plugins = get_list_of_plugins('enrol', 'db')) {
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
$dbdir = new stdClass;
|
||||||
|
$dbdir->path = $CFG->dirroot . '/enrol/' . $plugin . '/db';
|
||||||
|
$dbdir->path_exists = file_exists($dbdir->path);
|
||||||
|
if (!isset($XMLDB->dbdirs[$dbdir->path])) {
|
||||||
|
$XMLDB->dbdirs[$dbdir->path] = $dbdir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Sort by key
|
||||||
|
ksort($XMLDB->dbdirs);
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
113
admin/xmldb/actions/load_xml_file/load_xml_file.class.php
Normal file
113
admin/xmldb/actions/load_xml_file/load_xml_file.class.php
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will load one XML file to memory if necessary
|
||||||
|
|
||||||
|
class load_xml_file extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->can_subaction = ACTION_NONE;
|
||||||
|
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting $result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
if ($dbdir) {
|
||||||
|
/// Set some defaults
|
||||||
|
$dbdir->xml_exists = false;
|
||||||
|
$dbdir->xml_writeable = false;
|
||||||
|
$dbdir->xml_loaded = false;
|
||||||
|
///Only if the directory exists
|
||||||
|
if (!$dbdir->path_exists) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
|
||||||
|
/// Set dbdir as necessary
|
||||||
|
if ($xmldb_file->fileExists()) {
|
||||||
|
$dbdir->xml_exists = true;
|
||||||
|
}
|
||||||
|
if ($xmldb_file->fileWriteable()) {
|
||||||
|
$dbdir->xml_writeable = true;
|
||||||
|
}
|
||||||
|
/// Load the XML contents to structure
|
||||||
|
$loaded = $xmldb_file->loadXMLStructure();
|
||||||
|
if ($loaded && $xmldb_file->isLoaded()) {
|
||||||
|
$dbdir->xml_loaded = true;
|
||||||
|
}
|
||||||
|
$dbdir->xml_file = $xmldb_file;
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Wrong directory (' . $dirpath . ')';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'XMLDB structure not found';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
/// Launch postaction if exists
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
98
admin/xmldb/actions/load_xml_files/load_xml_files.class.php
Normal file
98
admin/xmldb/actions/load_xml_files/load_xml_files.class.php
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will load every XML file to memory if necessary
|
||||||
|
|
||||||
|
class load_xml_files extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->can_subaction = ACTION_NONE;
|
||||||
|
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting $result as needed
|
||||||
|
|
||||||
|
/// Iterate over $XMLDB->dbdirs, loading their XML data to memory
|
||||||
|
if ($XMLDB->dbdirs) {
|
||||||
|
$dbdirs =& $XMLDB->dbdirs;
|
||||||
|
foreach ($dbdirs as $dbdir) {
|
||||||
|
/// Set some defaults
|
||||||
|
$dbdir->xml_exists = false;
|
||||||
|
$dbdir->xml_writeable = false;
|
||||||
|
$dbdir->xml_loaded = false;
|
||||||
|
///Only if the directory exists
|
||||||
|
if (!$dbdir->path_exists) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
|
||||||
|
/// Set dbdir as necessary
|
||||||
|
if ($xmldb_file->fileExists()) {
|
||||||
|
$dbdir->xml_exists = true;
|
||||||
|
}
|
||||||
|
if ($xmldb_file->fileWriteable()) {
|
||||||
|
$dbdir->xml_writeable = true;
|
||||||
|
}
|
||||||
|
/// Load the XML contents to structure
|
||||||
|
$loaded = $xmldb_file->loadXMLStructure();
|
||||||
|
if ($loaded && $xmldb_file->isLoaded()) {
|
||||||
|
$dbdir->xml_loaded = true;
|
||||||
|
}
|
||||||
|
$dbdir->xml_file = $xmldb_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
233
admin/xmldb/actions/main_view/main_view.class.php
Normal file
233
admin/xmldb/actions/main_view/main_view.class.php
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will show all the actions available under the XMLDB interface
|
||||||
|
|
||||||
|
class main_view extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'load' => 'xmldb',
|
||||||
|
'create' => 'xmldb',
|
||||||
|
'edit' => 'xmldb',
|
||||||
|
'save' => 'xmldb',
|
||||||
|
'revert' => 'xmldb',
|
||||||
|
'unload' => 'xmldb',
|
||||||
|
'delete' => 'xmldb',
|
||||||
|
'reservedwords' => 'xmldb',
|
||||||
|
'gotolastused' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB, $SESSION;
|
||||||
|
|
||||||
|
/// Get lastused
|
||||||
|
$o = '';
|
||||||
|
if (isset($SESSION->lastused)) {
|
||||||
|
if ($lastused = $SESSION->lastused) {
|
||||||
|
/// Print link
|
||||||
|
$o .= '<p align="center"><a href="#lastused">' . $this->str['gotolastused'] . '</a></p>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$lastused = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = '<p align="center" class="buttons">';
|
||||||
|
/// The reserved_words button
|
||||||
|
$b .= ' <a href="index.php?action=view_reserved_words">[' . $this->str['reservedwords'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
/// Send buttons to output
|
||||||
|
$o .= $b;
|
||||||
|
|
||||||
|
/// Do the job
|
||||||
|
|
||||||
|
/// Get the list of DB directories
|
||||||
|
$result = $this->launch('get_db_directories');
|
||||||
|
/// Display list of DB directories if everything is ok
|
||||||
|
if ($result && !empty($XMLDB->dbdirs)) {
|
||||||
|
$o .= '<table id="listdirectories" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||||
|
$row = 0;
|
||||||
|
foreach ($XMLDB->dbdirs as $key => $dbdir) {
|
||||||
|
/// Detect if this is the lastused dir
|
||||||
|
$hithis = false;
|
||||||
|
if ($key == $lastused) {
|
||||||
|
$hithis = true;
|
||||||
|
}
|
||||||
|
$elementtext = str_replace($CFG->dirroot . '/', '', $key);
|
||||||
|
/// Calculate the dbdir has_changed field if needed
|
||||||
|
if (!isset($dbdir->has_changed) && isset($dbdir->xml_loaded)) {
|
||||||
|
$dbdir->xml_changed = false;
|
||||||
|
if (isset($XMLDB->editeddirs[$key])) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$key];
|
||||||
|
if (isset($editeddir->xml_file)) {
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
if ($structure->hasChanged()) {
|
||||||
|
$dbdir->xml_changed = true;
|
||||||
|
$editeddir->xml_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Calculate the buttons
|
||||||
|
$b = ' <td class="button cell">';
|
||||||
|
/// The create button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
!file_exists($key . '/install.xml') &&
|
||||||
|
is_writeable($key)) {
|
||||||
|
$b .= '<a href="index.php?action=create_xml_file&dir=' . urlencode($key) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['create'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['create'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The load button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml') &&
|
||||||
|
empty($dbdir->xml_loaded)) {
|
||||||
|
$b .= '<a href="index.php?action=load_xml_file&dir=' . urlencode($key) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['load'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['load'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The edit button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml') &&
|
||||||
|
is_readable($key) &&
|
||||||
|
!empty($dbdir->xml_loaded)) {
|
||||||
|
$b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode($key) . '">[' . $this->str['edit'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['edit'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The save button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml') &&
|
||||||
|
is_writeable($key) &&
|
||||||
|
!empty($dbdir->xml_loaded) &&
|
||||||
|
!empty($dbdir->xml_changed)) {
|
||||||
|
$b .= '<a href="index.php?action=save_xml_file&dir=' . urlencode($key) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['save'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['save'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The revert button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml') &&
|
||||||
|
is_writeable($key) &&
|
||||||
|
!empty($dbdir->xml_loaded) &&
|
||||||
|
!empty($dbdir->xml_changed)) {
|
||||||
|
$b .= '<a href="index.php?action=revert_changes&dir=' . urlencode($key) . '">[' . $this->str['revert'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['revert'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The unload button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml') &&
|
||||||
|
!empty($dbdir->xml_loaded) &&
|
||||||
|
empty($dbdir->xml_changed)) {
|
||||||
|
$b .= '<a href="index.php?action=unload_xml_file&dir=' . urlencode($key) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str['unload'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['unload'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td><td class="button cell">';
|
||||||
|
/// The delete button
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml') &&
|
||||||
|
is_writeable($key) &&
|
||||||
|
empty($dbdir->xml_loaded)) {
|
||||||
|
$b .= '<a href="index.php?action=delete_xml_file&dir=' . urlencode($key) . '">[' . $this->str['delete'] . ']</a>';
|
||||||
|
} else {
|
||||||
|
$b .= '[' . $this->str['delete'] . ']';
|
||||||
|
}
|
||||||
|
$b .= '</td>';
|
||||||
|
/// if the file, exist, XML is viewable
|
||||||
|
if ($dbdir->path_exists &&
|
||||||
|
file_exists($key . '/install.xml') &&
|
||||||
|
is_readable($key . '/install.xml')) {
|
||||||
|
$elementtext = '<a href="index.php?action=view_xml&file=' . urlencode($key . '/install.xml') . '" target="_blank">' . $elementtext . '</a></td>';
|
||||||
|
} else {
|
||||||
|
$elementtext = $elementtext . '</td>';
|
||||||
|
}
|
||||||
|
/// include the higlight
|
||||||
|
if ($hithis) {
|
||||||
|
$o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $elementtext . $b . '</tr>';
|
||||||
|
} else {
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="directory cell">' . $elementtext . $b . '</tr>';
|
||||||
|
}
|
||||||
|
$row = ($row + 1) % 2;
|
||||||
|
/// show errors if they exist
|
||||||
|
if (isset($dbdir->xml_file)) {
|
||||||
|
if ($structure =& $dbdir->xml_file->getStructure()) {
|
||||||
|
if ($errors = $structure->getAllErrors()) {
|
||||||
|
if ($hithis) {
|
||||||
|
$o .= '<tr class="highlight"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
|
||||||
|
} else {
|
||||||
|
$o .= '<tr class="r' . $row . '"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$o .= '</table>';
|
||||||
|
|
||||||
|
/// Set the output
|
||||||
|
$this->output = $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Finally, return result
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,146 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will will move one field up/down
|
||||||
|
|
||||||
|
class move_updown_field extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$prev = NULL;
|
||||||
|
$next = NULL;
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$fieldparam = required_param('field', PARAM_CLEAN);
|
||||||
|
$direction = required_param('direction', PARAM_ALPHA);
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$fields =& $table->getFields();
|
||||||
|
if ($direction == 'down') {
|
||||||
|
$field =& $table->getField($fieldparam);
|
||||||
|
$swap =& $table->getField($field->getNext());
|
||||||
|
} else {
|
||||||
|
$swap =& $table->getField($fieldparam);
|
||||||
|
$field =& $table->getField($swap->getPrevious());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the field before the pair
|
||||||
|
if ($field->getPrevious()) {
|
||||||
|
$prev =& $table->getField($field->getPrevious());
|
||||||
|
$prev->setNext($swap->getName());
|
||||||
|
$swap->setPrevious($prev->getName());
|
||||||
|
$prev->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$swap->setPrevious(NULL);
|
||||||
|
}
|
||||||
|
/// Change the field after the pair
|
||||||
|
if ($swap->getNext()) {
|
||||||
|
$next =& $table->getField($swap->getNext());
|
||||||
|
$next->setPrevious($field->getName());
|
||||||
|
$field->setNext($next->getName());
|
||||||
|
$next->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$field->setNext(NULL);
|
||||||
|
}
|
||||||
|
/// Swap the fields
|
||||||
|
$field->setPrevious($swap->getName());
|
||||||
|
$swap->setNext($field->getName());
|
||||||
|
|
||||||
|
/// Mark fields as changed
|
||||||
|
$field->setChanged(true);
|
||||||
|
$swap->setChanged(true);
|
||||||
|
|
||||||
|
/// Table has changed
|
||||||
|
$table->setChanged(true);
|
||||||
|
|
||||||
|
/// Reorder the fields
|
||||||
|
$table->orderFields($fields);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,146 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will will move one index up/down
|
||||||
|
|
||||||
|
class move_updown_index extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$prev = NULL;
|
||||||
|
$next = NULL;
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$indexparam = required_param('index', PARAM_CLEAN);
|
||||||
|
$direction = required_param('direction', PARAM_ALPHA);
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$indexes =& $table->getIndexes();
|
||||||
|
if ($direction == 'down') {
|
||||||
|
$index =& $table->getIndex($indexparam);
|
||||||
|
$swap =& $table->getIndex($index->getNext());
|
||||||
|
} else {
|
||||||
|
$swap =& $table->getIndex($indexparam);
|
||||||
|
$index =& $table->getIndex($swap->getPrevious());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the index before the pair
|
||||||
|
if ($index->getPrevious()) {
|
||||||
|
$prev =& $table->getIndex($index->getPrevious());
|
||||||
|
$prev->setNext($swap->getName());
|
||||||
|
$swap->setPrevious($prev->getName());
|
||||||
|
$prev->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$swap->setPrevious(NULL);
|
||||||
|
}
|
||||||
|
/// Change the field after the pair
|
||||||
|
if ($swap->getNext()) {
|
||||||
|
$next =& $table->getIndex($swap->getNext());
|
||||||
|
$next->setPrevious($index->getName());
|
||||||
|
$index->setNext($next->getName());
|
||||||
|
$next->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$index->setNext(NULL);
|
||||||
|
}
|
||||||
|
/// Swap the indexes
|
||||||
|
$index->setPrevious($swap->getName());
|
||||||
|
$swap->setNext($index->getName());
|
||||||
|
|
||||||
|
/// Mark indexes as changed
|
||||||
|
$index->setChanged(true);
|
||||||
|
$swap->setChanged(true);
|
||||||
|
|
||||||
|
/// Table has changed
|
||||||
|
$table->setChanged(true);
|
||||||
|
|
||||||
|
/// Reorder the indexes
|
||||||
|
$table->orderIndexes($indexes);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
146
admin/xmldb/actions/move_updown_key/move_updown_key.class.php
Normal file
146
admin/xmldb/actions/move_updown_key/move_updown_key.class.php
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will will move one key up/down
|
||||||
|
|
||||||
|
class move_updown_key extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$prev = NULL;
|
||||||
|
$next = NULL;
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$keyparam = required_param('key', PARAM_CLEAN);
|
||||||
|
$direction = required_param('direction', PARAM_ALPHA);
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$keys =& $table->getKeys();
|
||||||
|
if ($direction == 'down') {
|
||||||
|
$key =& $table->getKey($keyparam);
|
||||||
|
$swap =& $table->getKey($key->getNext());
|
||||||
|
} else {
|
||||||
|
$swap =& $table->getKey($keyparam);
|
||||||
|
$key =& $table->getKey($swap->getPrevious());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the key before the pair
|
||||||
|
if ($key->getPrevious()) {
|
||||||
|
$prev =& $table->getKey($key->getPrevious());
|
||||||
|
$prev->setNext($swap->getName());
|
||||||
|
$swap->setPrevious($prev->getName());
|
||||||
|
$prev->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$swap->setPrevious(NULL);
|
||||||
|
}
|
||||||
|
/// Change the key after the pair
|
||||||
|
if ($swap->getNext()) {
|
||||||
|
$next =& $table->getKey($swap->getNext());
|
||||||
|
$next->setPrevious($key->getName());
|
||||||
|
$key->setNext($next->getName());
|
||||||
|
$next->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$key->setNext(NULL);
|
||||||
|
}
|
||||||
|
/// Swap the keys
|
||||||
|
$key->setPrevious($swap->getName());
|
||||||
|
$swap->setNext($key->getName());
|
||||||
|
|
||||||
|
/// Mark keys as changed
|
||||||
|
$key->setChanged(true);
|
||||||
|
$swap->setChanged(true);
|
||||||
|
|
||||||
|
/// Table has changed
|
||||||
|
$table->setChanged(true);
|
||||||
|
|
||||||
|
/// Reorder the keys
|
||||||
|
$table->orderKeys($keys);
|
||||||
|
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,140 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will will move one statement down
|
||||||
|
|
||||||
|
class move_updown_statement extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$prev = NULL;
|
||||||
|
$next = NULL;
|
||||||
|
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||||
|
$direction = required_param('direction', PARAM_ALPHA);
|
||||||
|
$statements =& $structure->getStatements();
|
||||||
|
if ($direction == 'down') {
|
||||||
|
$statement =& $structure->getStatement($statementparam);
|
||||||
|
$swap =& $structure->getStatement($statement->getNext());
|
||||||
|
} else {
|
||||||
|
$swap =& $structure->getStatement($statementparam);
|
||||||
|
$statement =& $structure->getStatement($swap->getPrevious());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the statement before the pair
|
||||||
|
if ($statement->getPrevious()) {
|
||||||
|
$prev =& $structure->getStatement($statement->getPrevious());
|
||||||
|
$prev->setNext($swap->getName());
|
||||||
|
$swap->setPrevious($prev->getName());
|
||||||
|
$prev->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$swap->setPrevious(NULL);
|
||||||
|
}
|
||||||
|
/// Change the statement after the pair
|
||||||
|
if ($swap->getNext()) {
|
||||||
|
$next =& $structure->getStatement($swap->getNext());
|
||||||
|
$next->setPrevious($statement->getName());
|
||||||
|
$statement->setNext($next->getName());
|
||||||
|
$next->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$statement->setNext(NULL);
|
||||||
|
}
|
||||||
|
/// Swap the statements
|
||||||
|
$statement->setPrevious($swap->getName());
|
||||||
|
$swap->setNext($statement->getName());
|
||||||
|
|
||||||
|
/// Statement has changed
|
||||||
|
$statement->setChanged(true);
|
||||||
|
|
||||||
|
/// Reorder the structure
|
||||||
|
$structure->orderStatements($statements);
|
||||||
|
/// Send statements back to structure (the order above break refs)
|
||||||
|
$structure->setStatements($statements);
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,140 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will will move one table down
|
||||||
|
|
||||||
|
class move_updown_table extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$prev = NULL;
|
||||||
|
$next = NULL;
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$direction = required_param('direction', PARAM_ALPHA);
|
||||||
|
$tables =& $structure->getTables();
|
||||||
|
if ($direction == 'down') {
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
$swap =& $structure->getTable($table->getNext());
|
||||||
|
} else {
|
||||||
|
$swap =& $structure->getTable($tableparam);
|
||||||
|
$table =& $structure->getTable($swap->getPrevious());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the table before the pair
|
||||||
|
if ($table->getPrevious()) {
|
||||||
|
$prev =& $structure->getTable($table->getPrevious());
|
||||||
|
$prev->setNext($swap->getName());
|
||||||
|
$swap->setPrevious($prev->getName());
|
||||||
|
$prev->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$swap->setPrevious(NULL);
|
||||||
|
}
|
||||||
|
/// Change the table after the pair
|
||||||
|
if ($swap->getNext()) {
|
||||||
|
$next =& $structure->getTable($swap->getNext());
|
||||||
|
$next->setPrevious($table->getName());
|
||||||
|
$table->setNext($next->getName());
|
||||||
|
$next->setChanged(true);
|
||||||
|
} else {
|
||||||
|
$table->setNext(NULL);
|
||||||
|
}
|
||||||
|
/// Swap the tables
|
||||||
|
$table->setPrevious($swap->getName());
|
||||||
|
$swap->setNext($table->getName());
|
||||||
|
|
||||||
|
/// Table has changed
|
||||||
|
$table->setChanged(true);
|
||||||
|
|
||||||
|
/// Reorder the structure
|
||||||
|
$structure->orderTables($tables);
|
||||||
|
/// Send tables back to structure (the order above break refs)
|
||||||
|
$structure->setTables($tables);
|
||||||
|
/// Recalculate the hash
|
||||||
|
$structure->calculateHash(true);
|
||||||
|
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
109
admin/xmldb/actions/new_field/new_field.class.php
Normal file
109
admin/xmldb/actions/new_field/new_field.class.php
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will create a new default field to be edited
|
||||||
|
|
||||||
|
class new_field extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
|
||||||
|
/// If the changeme field exists, just get it and continue
|
||||||
|
$changeme_exists = false;
|
||||||
|
if ($fields =& $table->getFields()) {
|
||||||
|
if ($field =& $table->getField('changeme')) {
|
||||||
|
$changeme_exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$changeme_exists) { /// Lets create the field
|
||||||
|
$field = new XMLDBField('changeme');
|
||||||
|
$field->setComment('Default comment for the field, please edit me');
|
||||||
|
$table->addField($field);
|
||||||
|
|
||||||
|
/// We have one new field, so the structure has changed
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
108
admin/xmldb/actions/new_index/new_index.class.php
Normal file
108
admin/xmldb/actions/new_index/new_index.class.php
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will create a new default index to be edited
|
||||||
|
|
||||||
|
class new_index extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
|
||||||
|
/// If the changeme index exists, just get it and continue
|
||||||
|
$changeme_exists = false;
|
||||||
|
if ($indexes =& $table->getIndexes()) {
|
||||||
|
if ($index =& $table->getIndex('changeme')) {
|
||||||
|
$changeme_exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$changeme_exists) { /// Lets create the Index
|
||||||
|
$index = new XMLDBIndex('changeme');
|
||||||
|
$index->setComment('Default comment for the index, please edit me');
|
||||||
|
$table->addIndex($index);
|
||||||
|
|
||||||
|
/// We have one new key, so the structure has changed
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
108
admin/xmldb/actions/new_key/new_key.class.php
Normal file
108
admin/xmldb/actions/new_key/new_key.class.php
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will create a new default key to be edited
|
||||||
|
|
||||||
|
class new_key extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
|
||||||
|
$table =& $structure->getTable($tableparam);
|
||||||
|
|
||||||
|
/// If the changeme 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
|
||||||
|
$key = new XMLDBKey('changeme');
|
||||||
|
$key->setComment('Default comment for the key, please edit me');
|
||||||
|
$table->addKey($key);
|
||||||
|
|
||||||
|
/// We have one new key, so the structure has changed
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
$structure->setChanged(true);
|
||||||
|
}
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
120
admin/xmldb/actions/new_sentence/new_sentence.class.php
Normal file
120
admin/xmldb/actions/new_sentence/new_sentence.class.php
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will create a new default sentence to be edited.
|
||||||
|
/// If one previous sentence key is specified, it's used as
|
||||||
|
/// base to build the new setence, else a blank one is used
|
||||||
|
|
||||||
|
class new_sentence extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||||
|
$basesentenceparam = optional_param('basesentence', NULL, PARAM_CLEAN);
|
||||||
|
|
||||||
|
$statement =& $structure->getStatement($statementparam);
|
||||||
|
$sentences =& $statement->getSentences();
|
||||||
|
|
||||||
|
$sentence = NULL;
|
||||||
|
|
||||||
|
/// If some sentence has been specified, create the new one
|
||||||
|
/// based on it
|
||||||
|
if (!empty($basesentenceparam)) {
|
||||||
|
$sentence = $sentences[$basesentenceparam];
|
||||||
|
}
|
||||||
|
/// Else, try to create the new one based in the last
|
||||||
|
if (empty($sentence) && !empty($sentences)) {
|
||||||
|
$sentence = end($sentences);
|
||||||
|
}
|
||||||
|
/// Else, create one sentence by hand
|
||||||
|
if (empty($sentence)) {
|
||||||
|
$sentence = "(list, of, fields) VALUES ('list', 'of', 'values')";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add the sentence to the statement
|
||||||
|
$statement->addSentence($sentence);
|
||||||
|
|
||||||
|
/// We have one new sentence, so the statement and the structure has changed
|
||||||
|
$statement->setChanged(true);
|
||||||
|
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||||
|
$structure->setChanged(true);
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
161
admin/xmldb/actions/new_statement/new_statement.class.php
Normal file
161
admin/xmldb/actions/new_statement/new_statement.class.php
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will ask for one statement type and table
|
||||||
|
/// to be able to add sentences of that type
|
||||||
|
|
||||||
|
class new_statement extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'statementtype' => 'xmldb',
|
||||||
|
'statementtable' => 'xmldb',
|
||||||
|
'create' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB, $db;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$tableparam = optional_param('table', NULL, PARAM_CLEAN);
|
||||||
|
$typeparam = optional_param('type', NULL, PARAM_CLEAN);
|
||||||
|
|
||||||
|
/// If no table or type, show form
|
||||||
|
if (!$tableparam || !$typeparam) {
|
||||||
|
/// No postaction here
|
||||||
|
$this->postaction = NULL;
|
||||||
|
/// Get list of tables
|
||||||
|
$dbtables = $db->MetaTables('TABLES');
|
||||||
|
$selecttables = array();
|
||||||
|
foreach ($dbtables as $dbtable) {
|
||||||
|
$dbtable = str_replace($CFG->prefix, '', $dbtable);
|
||||||
|
$selecttables[$dbtable] = $dbtable;
|
||||||
|
}
|
||||||
|
/// Get list of statement types
|
||||||
|
$typeoptions = array (XMLDB_STATEMENT_INSERT => XMLDBStatement::getXMLDBStatementName(XMLDB_STATEMENT_INSERT),
|
||||||
|
XMLDB_STATEMENT_UPDATE => XMLDBStatement::getXMLDBStatementName(XMLDB_STATEMENT_UPDATE),
|
||||||
|
XMLDB_STATEMENT_DELETE => XMLDBStatement::getXMLDBStatementName(XMLDB_STATEMENT_DELETE),
|
||||||
|
XMLDB_STATEMENT_CUSTOM => XMLDBStatement::getXMLDBStatementName(XMLDB_STATEMENT_CUSTOM));
|
||||||
|
if (!$selecttables) {
|
||||||
|
$this->errormsg = 'No tables available to create statements';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// Now build the form
|
||||||
|
$o = '<form id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="new_statement" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||||
|
$o.= ' <table id="formelements" align="center" cellpadding="5">';
|
||||||
|
$o.= ' <tr><td><label for="type" accesskey="t">' . $this->str['statementtype'] .' </label>' . choose_from_menu($typeoptions, 'type', '', 'choose', '', 0, true) . '<label for="table" accesskey="a">' . $this->str['statementtable'] . ' </label>' .choose_from_menu($selecttables, 'table', '', 'choose', '', 0, true) . '</td></tr>';
|
||||||
|
$o.= ' <tr><td colspan="2" align="center"><input type="submit" value="' .$this->str['create'] . '" /></td></tr>';
|
||||||
|
$o.= ' <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
|
||||||
|
/// If table, retrofit information and, if everything works,
|
||||||
|
/// go to the table edit action
|
||||||
|
} else {
|
||||||
|
/// Get some params (table is mandatory here)
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$typeparam = required_param('type', PARAM_CLEAN);
|
||||||
|
|
||||||
|
/// Only insert is allowed :-/
|
||||||
|
if ($typeparam != XMLDB_STATEMENT_INSERT) {
|
||||||
|
$this->errormsg = 'Only insert of records is supported';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate the name of the statement
|
||||||
|
$typename = XMLDBStatement::getXMLDBStatementName($typeparam);
|
||||||
|
$name = trim(strtolower($typename . ' ' . $tableparam));
|
||||||
|
|
||||||
|
/// Check that this Statement hasn't been created before
|
||||||
|
if ($structure->getStatement($name)) {
|
||||||
|
$this->errormsg = 'The statement "' . $name . '" already exists, please use it to add more sentences';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create one new XMLDBStatement
|
||||||
|
$statement = new XMLDBStatement($name);
|
||||||
|
$statement->setType($typeparam);
|
||||||
|
$statement->setTable($tableparam);
|
||||||
|
$statement->setComment('Initial ' . $typename . ' of records on table ' . $tableparam);
|
||||||
|
/// Finally, add the whole retroffited table to the structure
|
||||||
|
/// in the place specified
|
||||||
|
$structure->addStatement($statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
121
admin/xmldb/actions/new_table/new_table.class.php
Normal file
121
admin/xmldb/actions/new_table/new_table.class.php
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will create a new default table to be edited
|
||||||
|
|
||||||
|
class new_table extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// If the changeme table exists, just get it and continue
|
||||||
|
$changeme_exists = false;
|
||||||
|
if ($tables =& $structure->getTables()) {
|
||||||
|
if ($table =& $structure->getTable('changeme')) {
|
||||||
|
$changeme_exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$changeme_exists) { /// Lets create the table
|
||||||
|
$field = new XMLDBField('id');
|
||||||
|
$field->setType(XMLDB_TYPE_INTEGER);
|
||||||
|
$field->setLength(10);
|
||||||
|
$field->setNotNull(true);
|
||||||
|
$field->setSequence(true);
|
||||||
|
$field->setComment('id of the table, please edit me');
|
||||||
|
$field->setLoaded(true);
|
||||||
|
$field->setChanged(true);
|
||||||
|
|
||||||
|
$key = new XMLDBKey('primary');
|
||||||
|
$key->setType(XMLDB_KEY_PRIMARY);
|
||||||
|
$key->setFields(array('id'));
|
||||||
|
$key->setComment('primary key of the table, please edit me');
|
||||||
|
$key->setLoaded(true);
|
||||||
|
$key->setChanged(true);
|
||||||
|
|
||||||
|
$table = new XMLDBTable('changeme');
|
||||||
|
$table->setComment('Default comment for the table, please edit me');
|
||||||
|
$table->addField($field);
|
||||||
|
$table->addKey($key);
|
||||||
|
|
||||||
|
/// Finally, add the whole retroffited table to the structure
|
||||||
|
/// in the place specified
|
||||||
|
$structure->addTable($table);
|
||||||
|
}
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,188 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will ask and retrofit all the information from one
|
||||||
|
/// mysql table present in the Moodle DB to one XMLDBTable structure
|
||||||
|
|
||||||
|
class new_table_from_mysql extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'createtable' => 'xmldb',
|
||||||
|
'aftertable' => 'xmldb',
|
||||||
|
'create' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB, $db;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
$tableparam = optional_param('table', NULL, PARAM_CLEAN);
|
||||||
|
|
||||||
|
/// If no table, show form
|
||||||
|
if (!$tableparam) {
|
||||||
|
/// No postaction here
|
||||||
|
$this->postaction = NULL;
|
||||||
|
/// Get list of tables
|
||||||
|
$dbtables = $db->MetaTables('TABLES');
|
||||||
|
$selecttables = array();
|
||||||
|
foreach ($dbtables as $dbtable) {
|
||||||
|
$dbtable = str_replace($CFG->prefix, '', $dbtable);
|
||||||
|
$i = $structure->findTableInArray($dbtable);
|
||||||
|
if ($i === NULL) {
|
||||||
|
$selecttables[$dbtable] = $dbtable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get list of after tables
|
||||||
|
$aftertables = array();
|
||||||
|
if ($tables =& $structure->getTables()) {
|
||||||
|
foreach ($tables as $aftertable) {
|
||||||
|
$aftertables[$aftertable->getName()] = $aftertable->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$selecttables) {
|
||||||
|
$this->errormsg = 'No tables available to be retrofitted';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// Now build the form
|
||||||
|
$o = '<form id="form" action="index.php" method="post">';
|
||||||
|
$o.= ' <input type="hidden" name ="dir" value="' . $dirpath . '" />';
|
||||||
|
$o.= ' <input type="hidden" name ="action" value="new_table_from_mysql" />';
|
||||||
|
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||||
|
$o.= ' <table id="formelements" align="center" cellpadding="5">';
|
||||||
|
$o.= ' <tr><td><label for="table" accesskey="t">' . $this->str['createtable'] .' </label>' . choose_from_menu($selecttables, 'table', '', 'choose', '', 0, true) . '<label for="after" accesskey="a">' . $this->str['aftertable'] . ' </label>' .choose_from_menu($aftertables, 'after', '', 'choose', '', 0, true) . '</td></tr>';
|
||||||
|
$o.= ' <tr><td colspan="2" align="center"><input type="submit" value="' .$this->str['create'] . '" /></td></tr>';
|
||||||
|
$o.= ' <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= '</form>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
|
||||||
|
/// If table, retrofit information and, if everything works,
|
||||||
|
/// go to the table edit action
|
||||||
|
} else {
|
||||||
|
/// Get some params (table is mandatory here)
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
$afterparam = required_param('after', PARAM_CLEAN);
|
||||||
|
|
||||||
|
/// Create one new XMLDBTable
|
||||||
|
$table = new XMLDBTable(strtolower(trim($tableparam)));
|
||||||
|
$table->setComment($table->getName() . ' table retrofitted from MySQL');
|
||||||
|
/// Get fields info from ADODb
|
||||||
|
$dbfields = $db->MetaColumns($CFG->prefix . $tableparam);
|
||||||
|
if ($dbfields) {
|
||||||
|
foreach ($dbfields as $dbfield) {
|
||||||
|
/// Create new XMLDB field
|
||||||
|
$field = new XMLDBField(strtolower($dbfield->name));
|
||||||
|
/// Set field with info retrofitted
|
||||||
|
$field->setFromADOField($dbfield);
|
||||||
|
/// Add field to the table
|
||||||
|
$table->addField($field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get PK, UK and indexes info from ADODb
|
||||||
|
$dbindexes = $db->MetaIndexes($CFG->prefix . $tableparam, true);
|
||||||
|
if ($dbindexes) {
|
||||||
|
$lastkey = NULL; //To temp store the last key processed
|
||||||
|
foreach ($dbindexes as $indexname => $dbindex) {
|
||||||
|
/// Add the indexname to the array
|
||||||
|
$dbindex['name'] = $indexname;
|
||||||
|
/// We are handling one XMLDBKey (primaries + uniques)
|
||||||
|
if ($dbindex['unique']) {
|
||||||
|
$key = new XMLDBKey(strtolower($dbindex['name']));
|
||||||
|
/// Set key with info retrofitted
|
||||||
|
$key->setFromADOKey($dbindex);
|
||||||
|
/// Set default comment to PKs
|
||||||
|
if ($key->getType() == XMLDB_KEY_PRIMARY) {
|
||||||
|
$key->setComment('Primary key for ' . $table->getName());
|
||||||
|
}
|
||||||
|
/// Add key to the table
|
||||||
|
$table->addKey($key);
|
||||||
|
|
||||||
|
/// We are handling one XMLDBIndex (non-uniques)
|
||||||
|
} else {
|
||||||
|
$index = new XMLDBIndex(strtolower($dbindex['name']));
|
||||||
|
/// Set index with info retrofitted
|
||||||
|
$index->setFromADOIndex($dbindex);
|
||||||
|
/// Add index to the table
|
||||||
|
$table->addIndex($index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Finally, add the whole retroffited table to the structure
|
||||||
|
/// in the place specified
|
||||||
|
$structure->addTable($table, $afterparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
117
admin/xmldb/actions/revert_changes/revert_changes.class.php
Normal file
117
admin/xmldb/actions/revert_changes/revert_changes.class.php
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will revert changes (delete the editeddb)
|
||||||
|
|
||||||
|
class revert_changes extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'confirmrevertchanges' => 'xmldb',
|
||||||
|
'yes' => '',
|
||||||
|
'no' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||||
|
|
||||||
|
/// If not confirmed, show confirmation box
|
||||||
|
if (!$confirmed) {
|
||||||
|
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||||
|
$o.= ' <tr><td class="generalboxcontent">';
|
||||||
|
$o.= ' <p align="center">' . $this->str['confirmrevertchanges'] . '<br /><br />' . $dirpath . '</p>';
|
||||||
|
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=revert_changes&confirmed=yes&dir=' . urlencode($dirpath) . '&postaction=main_view#lastused" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||||
|
$o.= ' </td><td>';
|
||||||
|
$o.= ' <div class="singlebutton">';
|
||||||
|
$o.= ' <form action="index.php?action=main_view#lastused" method="post">';
|
||||||
|
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= '</table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
} else {
|
||||||
|
/// Get the original dir and delete some elements
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
if ($dbdir) {
|
||||||
|
unset($dbdir->xml_changed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
106
admin/xmldb/actions/save_xml_file/save_xml_file.class.php
Normal file
106
admin/xmldb/actions/save_xml_file/save_xml_file.class.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will save one edited xml file
|
||||||
|
|
||||||
|
class save_xml_file extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the edited dir
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Copy the edited dir over the original one
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||||
|
$XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir));
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save the original dir
|
||||||
|
$result = $dbdir->xml_file->saveXMLFile();
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
/// Delete the edited dir
|
||||||
|
unset ($XMLDB->editeddirs[$dirpath]);
|
||||||
|
/// Unload de originaldir
|
||||||
|
unset($XMLDB->dbdirs[$dirpath]->xml_file);
|
||||||
|
unset($XMLDB->dbdirs[$dirpath]->xml_loaded);
|
||||||
|
unset($XMLDB->dbdirs[$dirpath]->xml_changed);
|
||||||
|
unset($XMLDB->dbdirs[$dirpath]->xml_exists);
|
||||||
|
unset($XMLDB->dbdirs[$dirpath]->xml_writeable);
|
||||||
|
} else {
|
||||||
|
$errormsg = 'Error saving XML file (' . $dirpath . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
91
admin/xmldb/actions/template/template.class.php
Normal file
91
admin/xmldb/actions/template/template.class.php
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will
|
||||||
|
|
||||||
|
class template extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will unload one loaded file completely
|
||||||
|
|
||||||
|
class unload_xml_file extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_NONE;
|
||||||
|
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the original dir and delete some elements
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
if ($dbdir) {
|
||||||
|
unset($dbdir->xml_file);
|
||||||
|
unset($dbdir->xml_loaded);
|
||||||
|
unset($dbdir->xml_changed);
|
||||||
|
unset($dbdir->xml_exists);
|
||||||
|
unset($dbdir->xml_writeable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
139
admin/xmldb/actions/view_field_xml/view_field_xml.class.php
Normal file
139
admin/xmldb/actions/view_field_xml/view_field_xml.class.php
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display the XML for one field being edited
|
||||||
|
|
||||||
|
class view_field_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$field = required_param('field', PARAM_CLEAN);
|
||||||
|
$table = required_param('table', PARAM_CLEAN);
|
||||||
|
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if ($select == 'original') {
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$base =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else if ($select == 'edited') {
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$base =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Cannot access to ' . $select . ' info';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
if ($base) {
|
||||||
|
/// Only if the directory exists and it has been loaded
|
||||||
|
if (!$base->path_exists || !$base->xml_loaded) {
|
||||||
|
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Problem handling ' . $select . ' files';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the structure
|
||||||
|
if ($result) {
|
||||||
|
if (!$structure =& $base->xml_file->getStructure()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the tables
|
||||||
|
if ($result) {
|
||||||
|
if (!$tables =& $structure->getTables()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the table
|
||||||
|
if ($result && !$t = $structure->getTable($table)) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
/// Get the fields
|
||||||
|
if ($result) {
|
||||||
|
if (!$fields =& $t->getFields()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' fields';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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
|
||||||
|
$this->output = $f->xmlOutput();
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
139
admin/xmldb/actions/view_index_xml/view_index_xml.class.php
Normal file
139
admin/xmldb/actions/view_index_xml/view_index_xml.class.php
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display the XML for one index being edited
|
||||||
|
|
||||||
|
class view_index_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$index = required_param('index', PARAM_CLEAN);
|
||||||
|
$table = required_param('table', PARAM_CLEAN);
|
||||||
|
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if ($select == 'original') {
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$base =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else if ($select == 'edited') {
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$base =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Cannot access to ' . $select . ' info';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
if ($base) {
|
||||||
|
/// Only if the directory exists and it has been loaded
|
||||||
|
if (!$base->path_exists || !$base->xml_loaded) {
|
||||||
|
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Problem handling ' . $select . ' files';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the structure
|
||||||
|
if ($result) {
|
||||||
|
if (!$structure =& $base->xml_file->getStructure()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the tables
|
||||||
|
if ($result) {
|
||||||
|
if (!$tables =& $structure->getTables()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the table
|
||||||
|
if ($result && !$t =& $structure->getTable($table)) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
/// Get the indexes
|
||||||
|
if ($result) {
|
||||||
|
if (!$indexes =& $t->getIndexes()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' indexes';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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
|
||||||
|
$this->output = $i->xmlOutput();
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
139
admin/xmldb/actions/view_key_xml/view_key_xml.class.php
Normal file
139
admin/xmldb/actions/view_key_xml/view_key_xml.class.php
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display the XML for one key being edited
|
||||||
|
|
||||||
|
class view_key_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$key = required_param('key', PARAM_CLEAN);
|
||||||
|
$table = required_param('table', PARAM_CLEAN);
|
||||||
|
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if ($select == 'original') {
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$base =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else if ($select == 'edited') {
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$base =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Cannot access to ' . $select . ' info';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
if ($base) {
|
||||||
|
/// Only if the directory exists and it has been loaded
|
||||||
|
if (!$base->path_exists || !$base->xml_loaded) {
|
||||||
|
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Problem handling ' . $select . ' files';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the structure
|
||||||
|
if ($result) {
|
||||||
|
if (!$structure =& $base->xml_file->getStructure()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the tables
|
||||||
|
if ($result) {
|
||||||
|
if (!$tables =& $structure->getTables()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the table
|
||||||
|
if ($result && !$t =& $structure->getTable($table)) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $table . ' table';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
/// Get the keys
|
||||||
|
if ($result) {
|
||||||
|
if (!$keys =& $t->getKeys()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' keys';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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
|
||||||
|
$this->output = $k->xmlOutput();
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,153 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will show all the reserved words in a format suitable to
|
||||||
|
/// be pasted to: http://docs.moodle.org/en/XMLDB_reserved_words and
|
||||||
|
/// http://docs.moodle.org/en/Database_reserved_words
|
||||||
|
/// Also, it introspects te DB looking for such words and informing about
|
||||||
|
|
||||||
|
class view_reserved_words extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'listreservedwords' => 'xmldb',
|
||||||
|
'wrongreservedwords' => 'xmldb',
|
||||||
|
'table' => 'xmldb',
|
||||||
|
'field' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB, $db;
|
||||||
|
|
||||||
|
/// Calculate list of available SQL generators
|
||||||
|
$plugins = get_list_of_plugins('lib/xmldb/classes/generators');
|
||||||
|
$reserved_words = array();
|
||||||
|
$reserved_words_bydb = array();
|
||||||
|
foreach($plugins as $plugin) {
|
||||||
|
$classname = 'XMLDB' . $plugin;
|
||||||
|
$generator = new $classname();
|
||||||
|
$reserved_words = array_merge($reserved_words, $generator->getReservedWords());
|
||||||
|
$reserved_words_bydb[$plugin] = $generator->getReservedWords();
|
||||||
|
}
|
||||||
|
sort($reserved_words);
|
||||||
|
$reserved_words = array_unique($reserved_words);
|
||||||
|
|
||||||
|
/// Now, calculate, looking into current DB (with AdoDB Metadata), which fields are
|
||||||
|
/// in the list of reserved words
|
||||||
|
$wronguses = array();
|
||||||
|
$dbtables = $db->MetaTables('TABLES');
|
||||||
|
if ($dbtables) {
|
||||||
|
foreach ($dbtables as $dbtable) {
|
||||||
|
$table = str_replace($CFG->prefix, '', $dbtable);
|
||||||
|
if (in_array($table, $reserved_words)) {
|
||||||
|
$list_of_db = array();
|
||||||
|
foreach ($reserved_words_bydb as $key=>$words) {
|
||||||
|
if (in_array($table, $words)) {
|
||||||
|
$list_of_db[] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$list_of_db) . ')';
|
||||||
|
|
||||||
|
}
|
||||||
|
$dbfields = $db->MetaColumns($dbtable);
|
||||||
|
if ($dbfields) {
|
||||||
|
foreach ($dbfields as $dbfield) {
|
||||||
|
if (in_array($dbfield->name, $reserved_words)) {
|
||||||
|
$list_of_db = array();
|
||||||
|
foreach ($reserved_words_bydb as $key=>$words) {
|
||||||
|
if (in_array($dbfield->name, $words)) {
|
||||||
|
$list_of_db[] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$wronguses[] = $this->str['field'] . ' - ' . $table . '->' . $dbfield->name . ' (' . implode(', ',$list_of_db) . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sort the wrong uses
|
||||||
|
sort($wronguses);
|
||||||
|
|
||||||
|
/// The back to edit table button
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
$b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o = $b;
|
||||||
|
|
||||||
|
/// The list of currently wrong field names
|
||||||
|
if ($wronguses) {
|
||||||
|
$o.= ' <table id="formelements" align="center" cellpadding="5">';
|
||||||
|
$o.= ' <tr><td align="center"><font color="red">' . $this->str['wrongreservedwords'] . '</font></td></tr>';
|
||||||
|
$o.= ' <tr><td>';
|
||||||
|
$o.= ' <ul><li>' . implode('</li><li>', $wronguses) . '</li></ul>';
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The textarea showing all the reserved words
|
||||||
|
$o.= ' <table id="formelements" align="center" cellpadding="5">';
|
||||||
|
$o.= ' <tr><td align="center">' . $this->str['listreservedwords'];
|
||||||
|
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||||
|
$o.= s(implode(', ', $reserved_words));
|
||||||
|
$o.= '</textarea></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,126 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display the XML for one statement being edited
|
||||||
|
|
||||||
|
class view_statement_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$statement = required_param('statement', PARAM_CLEAN);
|
||||||
|
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if ($select == 'original') {
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$base =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else if ($select == 'edited') {
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$base =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Cannot access to ' . $select . ' info';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
if ($base) {
|
||||||
|
/// Only if the directory exists and it has been loaded
|
||||||
|
if (!$base->path_exists || !$base->xml_loaded) {
|
||||||
|
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Problem handling ' . $select . ' files';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the structure
|
||||||
|
if ($result) {
|
||||||
|
if (!$structure =& $base->xml_file->getStructure()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the statements
|
||||||
|
if ($result) {
|
||||||
|
if (!$statements =& $structure->getStatements()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' statements';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the statement
|
||||||
|
if ($result && !$t =& $structure->getStatement($statement)) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $statement . ' statement';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
/// Everything is ok. Generate the XML output
|
||||||
|
$this->output = $t->xmlOutput();
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,134 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will show the SQL generated for the selected RDBMS for
|
||||||
|
/// the entire XMLDB file
|
||||||
|
|
||||||
|
class view_structure_sql extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'selectdb' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$generatorparam = optional_param('generator', null, PARAM_CLEAN);
|
||||||
|
if (empty($generatorparam)) {
|
||||||
|
$generatorparam = $CFG->dbtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate list of available SQL generators
|
||||||
|
$plugins = get_list_of_plugins('lib/xmldb/classes/generators');
|
||||||
|
$generators = array();
|
||||||
|
foreach($plugins as $plugin) {
|
||||||
|
$generators[$plugin] = $plugin;
|
||||||
|
}
|
||||||
|
/// Check we have the selected generator
|
||||||
|
if (!in_array($generatorparam, $generators)) {
|
||||||
|
$generatorparam = reset($generators);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The back to edit table button
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
$b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o = $b;
|
||||||
|
|
||||||
|
$o.= ' <table id="formelements" align="center" cellpadding="5">';
|
||||||
|
$o.= ' <tr><td align="center">' . $this->str['selectdb'];
|
||||||
|
|
||||||
|
/// Show the popup of generators
|
||||||
|
$url = 'index.php?action=view_structure_sql&dir=' . urlencode($dirpath) . '&generator=';
|
||||||
|
$o.= popup_form($url, $generators, 'selectgenerator', $generatorparam, '', '', '' , true);
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||||
|
/// Get an array of statements
|
||||||
|
if ($starr = $structure->getCreateStructureSQL($generatorparam, $CFG->prefix)) {
|
||||||
|
$sqltext = '';
|
||||||
|
foreach ($starr as $st) {
|
||||||
|
$sqltext .= s($st) . "\n\n";
|
||||||
|
}
|
||||||
|
$sqltext = trim($sqltext);
|
||||||
|
$o.= $sqltext;
|
||||||
|
}
|
||||||
|
$o.= '</textarea></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display the XML for one structure
|
||||||
|
|
||||||
|
class view_structure_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$select = required_param('select', PARAM_ALPHAEXT); //original/edited
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if ($select == 'original') {
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$base =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else if ($select == 'edited') {
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$base =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Cannot access to ' . $select . ' info';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
if ($base) {
|
||||||
|
/// Only if the directory exists and it has been loaded
|
||||||
|
if (!$base->path_exists || !$base->xml_loaded) {
|
||||||
|
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Problem handling ' . $select . ' files';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the structure
|
||||||
|
if ($result) {
|
||||||
|
if (!$structure =& $base->xml_file->getStructure()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
/// Everything is ok. Generate the XML output
|
||||||
|
$this->output = $structure->xmlOutput();
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
139
admin/xmldb/actions/view_table_sql/view_table_sql.class.php
Normal file
139
admin/xmldb/actions/view_table_sql/view_table_sql.class.php
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will show the SQL generated for the selected RDBMS for
|
||||||
|
/// one table
|
||||||
|
|
||||||
|
class view_table_sql extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
'selectdb' => 'xmldb',
|
||||||
|
'back' => 'xmldb'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dirs
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
$structure =& $editeddir->xml_file->getStructure();
|
||||||
|
}
|
||||||
|
/// ADD YOUR CODE HERE
|
||||||
|
|
||||||
|
/// Get parameters
|
||||||
|
$tableparam = required_param('table', PARAM_CLEAN);
|
||||||
|
if (!$table =& $structure->getTable($tableparam)) {
|
||||||
|
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$generatorparam = optional_param('generator', null, PARAM_CLEAN);
|
||||||
|
if (empty($generatorparam)) {
|
||||||
|
$generatorparam = $CFG->dbtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate list of available SQL generators
|
||||||
|
$plugins = get_list_of_plugins('lib/xmldb/classes/generators');
|
||||||
|
$generators = array();
|
||||||
|
foreach($plugins as $plugin) {
|
||||||
|
$generators[$plugin] = $plugin;
|
||||||
|
}
|
||||||
|
/// Check we have the selected generator
|
||||||
|
if (!in_array($generatorparam, $generators)) {
|
||||||
|
$generatorparam = reset($generators);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The back to edit table button
|
||||||
|
$b = ' <p align="center" class="buttons">';
|
||||||
|
$b .= '<a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '">[' . $this->str['back'] . ']</a>';
|
||||||
|
$b .= '</p>';
|
||||||
|
$o = $b;
|
||||||
|
|
||||||
|
$o.= ' <table id="formelements" align="center" cellpadding="5">';
|
||||||
|
$o.= ' <tr><td align="center">' . $this->str['selectdb'];
|
||||||
|
|
||||||
|
/// Show the popup of generators
|
||||||
|
$url = 'index.php?action=view_table_sql&table=' . $tableparam . '&dir=' . urlencode($dirpath) . '&generator=';
|
||||||
|
$o.= popup_form($url, $generators, 'selectgenerator', $generatorparam, '', '', '' , true);
|
||||||
|
$o.= ' </td></tr>';
|
||||||
|
$o.= ' <tr><td><textarea cols="80" rows="32">';
|
||||||
|
/// Get an array of statements
|
||||||
|
if ($starr = $table->getCreateTableSQL($generatorparam, $CFG->prefix)) {
|
||||||
|
$sqltext = '';
|
||||||
|
foreach ($starr as $st) {
|
||||||
|
$sqltext .= s($st) . "\n\n";
|
||||||
|
}
|
||||||
|
$sqltext = trim($sqltext);
|
||||||
|
$o.= $sqltext;
|
||||||
|
}
|
||||||
|
$o.= '</textarea></td></tr>';
|
||||||
|
$o.= ' </table>';
|
||||||
|
|
||||||
|
$this->output = $o;
|
||||||
|
|
||||||
|
/// Launch postaction if exists (leave this here!)
|
||||||
|
if ($this->getPostAction() && $result) {
|
||||||
|
return $this->launch($this->getPostAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
126
admin/xmldb/actions/view_table_xml/view_table_xml.class.php
Normal file
126
admin/xmldb/actions/view_table_xml/view_table_xml.class.php
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display the XML for one table bein edited
|
||||||
|
|
||||||
|
class view_table_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$table = required_param('table', PARAM_CLEAN);
|
||||||
|
$select = required_param('select', PARAM_ALPHA); //original/edited
|
||||||
|
/// Get the dir containing the file
|
||||||
|
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||||
|
$dirpath = stripslashes_safe($dirpath);
|
||||||
|
|
||||||
|
/// Get the correct dir
|
||||||
|
if ($select == 'original') {
|
||||||
|
if (!empty($XMLDB->dbdirs)) {
|
||||||
|
$base =& $XMLDB->dbdirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else if ($select == 'edited') {
|
||||||
|
if (!empty($XMLDB->editeddirs)) {
|
||||||
|
$base =& $XMLDB->editeddirs[$dirpath];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Cannot access to ' . $select . ' info';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
if ($base) {
|
||||||
|
/// Only if the directory exists and it has been loaded
|
||||||
|
if (!$base->path_exists || !$base->xml_loaded) {
|
||||||
|
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->errormsg = 'Problem handling ' . $select . ' files';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the structure
|
||||||
|
if ($result) {
|
||||||
|
if (!$structure =& $base->xml_file->getStructure()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' structure';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Get the tables
|
||||||
|
if ($result) {
|
||||||
|
if (!$tables =& $structure->getTables()) {
|
||||||
|
$this->errormsg = 'Error retrieving ' . $select . ' tables';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 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
|
||||||
|
$this->output = $t->xmlOutput();
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
86
admin/xmldb/actions/view_xml/view_xml.class.php
Normal file
86
admin/xmldb/actions/view_xml/view_xml.class.php
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This class will display one XML file
|
||||||
|
|
||||||
|
class view_xml extends XMLDBAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method, every subclass will have its own
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->can_subaction = ACTION_NONE;
|
||||||
|
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||||
|
|
||||||
|
/// Set own custom attributes
|
||||||
|
|
||||||
|
/// Get needed strings
|
||||||
|
$this->loadStrings(array(
|
||||||
|
/// 'key' => 'module',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke method, every class will have its own
|
||||||
|
* returns true/false on completion, setting both
|
||||||
|
* errormsg and output as necessary
|
||||||
|
*/
|
||||||
|
function invoke() {
|
||||||
|
parent::invoke();
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
/// Set own core attributes
|
||||||
|
$this->does_generate = ACTION_GENERATE_XML;
|
||||||
|
|
||||||
|
/// These are always here
|
||||||
|
global $CFG, $XMLDB;
|
||||||
|
|
||||||
|
/// Do the job, setting result as needed
|
||||||
|
|
||||||
|
/// Get the file parameter
|
||||||
|
$file = required_param('file', PARAM_CLEAN);
|
||||||
|
$file = stripslashes_safe($file);
|
||||||
|
/// File must be under $CFG->wwwroot and
|
||||||
|
/// under one db directory (simple protection)
|
||||||
|
if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot &&
|
||||||
|
substr(dirname($file), -2, 2) == 'db') {
|
||||||
|
/// Everything is ok. Load the file to memory
|
||||||
|
$this->output = file_get_contents($file);
|
||||||
|
} else {
|
||||||
|
/// Switch to HTML and error
|
||||||
|
$this->does_generate = ACTION_GENERATE_HTML;
|
||||||
|
$this->errormsg = 'File not viewable (' . $file .')';
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return ok if arrived here
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
138
admin/xmldb/index.php
Normal file
138
admin/xmldb/index.php
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
<?php // $Id$
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This is the main script for the complete XMLDB interface. From here
|
||||||
|
/// all the actions supported will be launched.
|
||||||
|
|
||||||
|
/// Add required XMLDB constants
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBConstants.php');
|
||||||
|
|
||||||
|
/// Add required XMLDB action classes
|
||||||
|
require_once('actions/XMLDBAction.class.php');
|
||||||
|
|
||||||
|
/// Add main XMLDB Generator
|
||||||
|
require_once('../../lib/xmldb/classes/generators/XMLDBGenerator.class.php');
|
||||||
|
|
||||||
|
/// Add required XMLDB DB classes
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBObject.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBFile.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBStructure.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBTable.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBField.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBKey.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBIndex.class.php');
|
||||||
|
require_once('../../lib/xmldb/classes/XMLDBStatement.class.php');
|
||||||
|
|
||||||
|
/// Add Moodle config script (this is loaded AFTER all the rest
|
||||||
|
/// of classes because it starts the SESSION and classes to be
|
||||||
|
/// stored there MUST be declared before in order to avoid
|
||||||
|
/// getting "incomplete" objects
|
||||||
|
require_once('../../config.php');
|
||||||
|
|
||||||
|
/// Add other used libraries
|
||||||
|
require_once($CFG->libdir . '/xmlize.php');
|
||||||
|
|
||||||
|
/// Add all the available SQL generators
|
||||||
|
$generators = get_list_of_plugins('lib/xmldb/classes/generators');
|
||||||
|
foreach($generators as $generator) {
|
||||||
|
require_once ('../../lib/xmldb/classes/generators/' . $generator . '/' . $generator . '.class.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle session data
|
||||||
|
global $XMLDB;
|
||||||
|
/// The global SESSION object where everything will happen
|
||||||
|
if (!isset($SESSION->xmldb)) {
|
||||||
|
$SESSION->xmldb = new stdClass;
|
||||||
|
}
|
||||||
|
$XMLDB =& $SESSION->xmldb;
|
||||||
|
|
||||||
|
/// Some previous checks
|
||||||
|
if (! $site = get_site()) {
|
||||||
|
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
require_login();
|
||||||
|
|
||||||
|
if (!isadmin()) {
|
||||||
|
error('You must be an administrator to use this page.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch all the needed strings
|
||||||
|
$stradministration = get_string('administration');
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
$actionsroot = "$CFG->dirroot/$CFG->admin/xmldb/actions";
|
||||||
|
$actionclass = $action . '.class.php';
|
||||||
|
$actionpath = "$actionsroot/$action/$actionclass";
|
||||||
|
|
||||||
|
/// Load and invoke the proper action
|
||||||
|
if (file_exists($actionpath) && is_readable($actionpath)) {
|
||||||
|
require_once($actionpath);
|
||||||
|
if ($xmldb_action = new $action) {
|
||||||
|
//Invoke it
|
||||||
|
$result = $xmldb_action->invoke();
|
||||||
|
if ($result) {
|
||||||
|
/// Based on getDoesGenerate()
|
||||||
|
switch ($xmldb_action->getDoesGenerate()) {
|
||||||
|
case ACTION_GENERATE_HTML:
|
||||||
|
/// Define $CFG->javascript to use our custom javascripts.
|
||||||
|
/// Save the original one to add it from ours. Global too! :-(
|
||||||
|
global $standard_javascript;
|
||||||
|
$standard_javascript = $CFG->javascript; // Save original javascript file
|
||||||
|
$CFG->javascript = $CFG->dirroot.'/admin/xmldb/javascript.php'; //Use our custom javascript code
|
||||||
|
/// Go with standard header
|
||||||
|
print_header("$site->shortname: XMLDB",
|
||||||
|
"$site->fullname",
|
||||||
|
"<a href=\"../index.php\">$stradministration</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||||
|
print_heading($xmldb_action->getTitle());
|
||||||
|
echo $xmldb_action->getOutput();
|
||||||
|
print_footer();
|
||||||
|
break;
|
||||||
|
case ACTION_GENERATE_XML:
|
||||||
|
header('Content-type: application/xhtml+xml');
|
||||||
|
echo $xmldb_action->getOutput();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error($xmldb_action->getError());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error ("Error: cannot instantiate class (actions/$action/$actionclass)");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error ("Error: wrong action specified ($action)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) {
|
||||||
|
if ($CFG->debug > 7) {
|
||||||
|
///print_object($XMLDB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
60
admin/xmldb/javascript.php
Normal file
60
admin/xmldb/javascript.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php /// $Id $
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// NOTICE OF COPYRIGHT //
|
||||||
|
// //
|
||||||
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||||
|
// http://moodle.com //
|
||||||
|
// //
|
||||||
|
// Copyright (C) 2001-3001 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 //
|
||||||
|
// //
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// Load XMLDB required Javascript libraries, adding them
|
||||||
|
/// before the standard one ($standard_javascript)
|
||||||
|
|
||||||
|
if (!defined('MOODLE_INTERNAL')) {
|
||||||
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||||
|
}
|
||||||
|
|
||||||
|
/// We use this globals to be able to generate the proper JavaScripts
|
||||||
|
global $standard_javascript;
|
||||||
|
|
||||||
|
/// Load XMLDB javascript needed to handle some forms
|
||||||
|
$action = optional_param('action', '', PARAM_ALPHAEXT);
|
||||||
|
$postaction = optional_param('postaction', '', PARAM_ALPHAEXT);
|
||||||
|
/// If the js exists, load it
|
||||||
|
if ($action) {
|
||||||
|
$file = $CFG->dirroot . '/admin/xmldb/actions/' . $action . '/' . $action . '.js';
|
||||||
|
$wwwfile = $CFG->wwwroot . '/admin/xmldb/actions/' . $action . '/' . $action . '.js';
|
||||||
|
if (file_exists($file) && is_readable($file)) {
|
||||||
|
echo '<script language="JavaScript" type="text/javascript" src="' . $wwwfile . '"></script>' . "\n";
|
||||||
|
} else {
|
||||||
|
/// Try to load the postaction javascript if exists
|
||||||
|
if ($postaction) {
|
||||||
|
$file = $CFG->dirroot . '/admin/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
|
||||||
|
$wwwfile = $CFG->wwwroot . '/admin/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
|
||||||
|
if (file_exists($file) && is_readable($file)) {
|
||||||
|
echo '<script language="JavaScript" type="text/javascript" src="' . $wwwfile . '"></script>' . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load standard JavaScript
|
||||||
|
include($standard_javascript);
|
||||||
|
?>
|
62
admin/xmldb/xmldb.dtd
Normal file
62
admin/xmldb/xmldb.dtd
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<!ELEMENT FIELD EMPTY >
|
||||||
|
<!ATTLIST FIELD DECIMALS NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST FIELD DEFAULT NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST FIELD ENUM ( false | true ) #REQUIRED >
|
||||||
|
<!ATTLIST FIELD ENUMVALUES CDATA #IMPLIED >
|
||||||
|
<!ATTLIST FIELD LENGTH NMTOKEN #REQUIRED >
|
||||||
|
<!ATTLIST FIELD NAME NMTOKEN #REQUIRED >
|
||||||
|
<!ATTLIST FIELD NEXT NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST FIELD NOTNULL ( false | true ) #REQUIRED >
|
||||||
|
<!ATTLIST FIELD PREVIOUS NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST FIELD SEQUENCE ( false | true ) #REQUIRED >
|
||||||
|
<!ATTLIST FIELD TYPE ( binary | char | float | int | number | text ) #REQUIRED >
|
||||||
|
<!ATTLIST FIELD UNSIGNED ( false | true ) #IMPLIED >
|
||||||
|
|
||||||
|
<!ELEMENT FIELDS ( FIELD+ ) >
|
||||||
|
|
||||||
|
<!ELEMENT INDEX EMPTY >
|
||||||
|
<!ATTLIST INDEX COMMENT CDATA #IMPLIED >
|
||||||
|
<!ATTLIST INDEX FIELDS CDATA #REQUIRED >
|
||||||
|
<!ATTLIST INDEX NAME NMTOKEN #REQUIRED >
|
||||||
|
<!ATTLIST INDEX NEXT NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST INDEX PREVIOUS NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST INDEX UNIQUE ( false | true ) #REQUIRED >
|
||||||
|
|
||||||
|
<!ELEMENT INDEXES ( INDEX+ ) >
|
||||||
|
|
||||||
|
<!ELEMENT KEY EMPTY >
|
||||||
|
<!ATTLIST KEY COMMENT CDATA #IMPLIED >
|
||||||
|
<!ATTLIST KEY FIELDS CDATA #REQUIRED >
|
||||||
|
<!ATTLIST KEY NAME NMTOKEN #REQUIRED >
|
||||||
|
<!ATTLIST KEY NEXT NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST KEY PREVIOUS NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST KEY TYPE ( primary | unique | foreign ) #REQUIRED >
|
||||||
|
|
||||||
|
<!ELEMENT KEYS ( KEY+ ) >
|
||||||
|
|
||||||
|
<!ELEMENT SENTENCE EMPTY >
|
||||||
|
<!ATTLIST SENTENCE TEXT CDATA #REQUIRED >
|
||||||
|
|
||||||
|
<!ELEMENT SENTENCES ( SENTENCE+ ) >
|
||||||
|
|
||||||
|
<!ELEMENT STATEMENT ( SENTENCES ) >
|
||||||
|
<!ATTLIST STATEMENT COMMENT CDATA #REQUIRED >
|
||||||
|
<!ATTLIST STATEMENT NAME CDATA #REQUIRED >
|
||||||
|
<!ATTLIST STATEMENT TABLE NMTOKEN #REQUIRED >
|
||||||
|
<!ATTLIST STATEMENT TYPE NMTOKEN #REQUIRED >
|
||||||
|
|
||||||
|
<!ELEMENT STATEMENTS ( STATEMENT ) >
|
||||||
|
|
||||||
|
<!ELEMENT TABLE ( FIELDS, KEYS, INDEXES? ) >
|
||||||
|
<!ATTLIST TABLE COMMENT CDATA #REQUIRED >
|
||||||
|
<!ATTLIST TABLE NAME ID #REQUIRED >
|
||||||
|
<!ATTLIST TABLE NEXT NMTOKEN #IMPLIED >
|
||||||
|
<!ATTLIST TABLE PREVIOUS NMTOKEN #IMPLIED >
|
||||||
|
|
||||||
|
<!ELEMENT TABLES ( TABLE+ ) >
|
||||||
|
|
||||||
|
<!ELEMENT XMLDB ( TABLES, STATEMENTS ) >
|
||||||
|
<!ATTLIST XMLDB COMMENT CDATA #REQUIRED >
|
||||||
|
<!ATTLIST XMLDB PATH CDATA #REQUIRED >
|
||||||
|
<!ATTLIST XMLDB VERSION NMTOKEN #REQUIRED >
|
||||||
|
|
197
admin/xmldb/xmldb.xsd
Normal file
197
admin/xmldb/xmldb.xsd
Normal file
|
@ -0,0 +1,197 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="FIELD">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="ENUM" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="false" />
|
||||||
|
<xs:enumeration value="true" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="LENGTH" type="xs:NMTOKEN" use="required" />
|
||||||
|
<xs:attribute name="DECIMALS" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="NEXT" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="SEQUENCE" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="false" />
|
||||||
|
<xs:enumeration value="true" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="ENUMVALUES" type="xs:string" use="optional" />
|
||||||
|
<xs:attribute name="DEFAULT" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="TYPE" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="binary" />
|
||||||
|
<xs:enumeration value="char" />
|
||||||
|
<xs:enumeration value="float" />
|
||||||
|
<xs:enumeration value="int" />
|
||||||
|
<xs:enumeration value="number" />
|
||||||
|
<xs:enumeration value="text" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="UNSIGNED" use="optional">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="false" />
|
||||||
|
<xs:enumeration value="true" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="PREVIOUS" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="NOTNULL" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="false" />
|
||||||
|
<xs:enumeration value="true" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="NAME" type="xs:NMTOKEN" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="FIELDS">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="FIELD" maxOccurs="unbounded" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="INDEX">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="PREVIOUS" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="COMMENT" type="xs:string" use="optional" />
|
||||||
|
<xs:attribute name="UNIQUE" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="false" />
|
||||||
|
<xs:enumeration value="true" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="NAME" type="xs:NMTOKEN" use="required" />
|
||||||
|
<xs:attribute name="FIELDS" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="NEXT" type="xs:NMTOKEN" use="optional" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="INDEXES">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="INDEX" maxOccurs="unbounded" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="KEY">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="PREVIOUS" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="COMMENT" type="xs:string" use="optional" />
|
||||||
|
<xs:attribute name="NAME" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="name" />
|
||||||
|
<xs:enumeration value="plugin_name" />
|
||||||
|
<xs:enumeration value="primary" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="FIELDS" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="TYPE" use="required">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="primary" />
|
||||||
|
<xs:enumeration value="unique" />
|
||||||
|
<xs:enumeration value="foreign" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="NEXT" type="xs:NMTOKEN" use="optional" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="KEYS">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="KEY" maxOccurs="unbounded" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="SENTENCE">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="TEXT" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="SENTENCES">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="SENTENCE" maxOccurs="unbounded" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="STATEMENT">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="SENTENCES" />
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="COMMENT" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="TABLE" type="xs:NMTOKEN" use="required" />
|
||||||
|
<xs:attribute name="NAME" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="TYPE" type="xs:NMTOKEN" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="STATEMENTS">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="STATEMENT" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="TABLE">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="FIELDS" />
|
||||||
|
<xs:element ref="KEYS" />
|
||||||
|
<xs:element ref="INDEXES" minOccurs="0" />
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="PREVIOUS" type="xs:NMTOKEN" use="optional" />
|
||||||
|
<xs:attribute name="COMMENT" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="NAME" type="xs:ID" use="required" />
|
||||||
|
<xs:attribute name="NEXT" type="xs:NMTOKEN" use="optional" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="TABLES">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="TABLE" maxOccurs="unbounded" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="XMLDB">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element ref="TABLES" />
|
||||||
|
<xs:element ref="STATEMENTS" />
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="PATH" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="COMMENT" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="VERSION" type="xs:NMTOKEN" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
</xs:schema>
|
Loading…
Add table
Add a link
Reference in a new issue