3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This class will save the changes performed to the name and comment of
30 class edit_table_save
extends XMLDBAction
{
33 * Init method, every subclass will have its own
38 /// Set own custom attributes
40 /// Get needed strings
41 $this->loadStrings(array(
42 'tablenameempty' => 'xmldb',
43 'incorrecttablename' => 'xmldb',
44 'duplicatetablename' => 'xmldb',
45 'administration' => ''
50 * Invoke method, every class will have its own
51 * returns true/false on completion, setting both
52 * errormsg and output as necessary
59 /// Set own core attributes
60 $this->does_generate
= ACTION_NONE
;
61 //$this->does_generate = ACTION_GENERATE_HTML;
63 /// These are always here
66 /// Do the job, setting result as needed
68 if (!data_submitted('nomatch')) { ///Basic prevention
69 error('Wrong action call');
73 $dirpath = required_param('dir', PARAM_PATH
);
74 $dirpath = $CFG->dirroot
. stripslashes_safe($dirpath);
76 $tableparam = strtolower(required_param('table', PARAM_PATH
));
77 $name = substr(trim(strtolower(required_param('name', PARAM_PATH
))),0,28);
78 $comment = required_param('comment', PARAM_CLEAN
);
79 $comment = stripslashes_safe($comment);
81 $editeddir =& $XMLDB->editeddirs
[$dirpath];
82 $structure =& $editeddir->xml_file
->getStructure();
83 $table =& $structure->getTable($tableparam);
85 $errors = array(); /// To store all the errors found
87 /// Perform some checks
90 $errors[] = $this->str
['tablenameempty'];
92 /// Check incorrect name
93 if ($name == 'changeme') {
94 $errors[] = $this->str
['incorrecttablename'];
96 /// Check duplicatename
97 if ($tableparam != $name && $structure->getTable($name)) {
98 $errors[] = $this->str
['duplicatetablename'];
101 if (!empty($errors)) {
102 $temptable = new XMLDBTable($name);
103 /// Prepare the output
105 print_header("$site->shortname: XMLDB",
107 "<a href=\"../index.php\">" . $this->str
['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
108 notice ('<p>' .implode(', ', $errors) . '</p>
109 <p>' . $temptable->readableInfo(),
110 'index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)));
114 /// If there is one name change, do it, changing the prev and next
115 /// atributes of the adjacent tables
116 if ($tableparam != $name) {
117 $table->setName($name);
118 if ($table->getPrevious()) {
119 $prev =& $structure->getTable($table->getPrevious());
120 $prev->setNext($name);
121 $prev->setChanged(true);
123 if ($table->getNext()) {
124 $next =& $structure->getTable($table->getNext());
125 $next->setPrevious($name);
126 $next->setChanged(true);
131 $table->setComment($comment);
133 /// Launch postaction if exists (leave this here!)
134 if ($this->getPostAction() && $result) {
135 return $this->launch($this->getPostAction());
138 /// Return ok if arrived here