3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards 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
106 $navlinks[] = array('name' => $this->str
['administration'], 'link' => '../index.php', 'type' => 'misc');
107 $navlinks[] = array('name' => 'XMLDB', 'link' => 'index.php', 'type' => 'misc');
108 $navigation = build_navigation($navlinks);
109 print_header("$site->shortname: XMLDB", "$site->fullname", $navigation);
110 notice ('<p>' .implode(', ', $errors) . '</p>
111 <p>' . $temptable->readableInfo(),
112 'index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)));
116 /// If there is one name change, do it, changing the prev and next
117 /// atributes of the adjacent tables
118 if ($tableparam != $name) {
119 $table->setName($name);
120 if ($table->getPrevious()) {
121 $prev =& $structure->getTable($table->getPrevious());
122 $prev->setNext($name);
123 $prev->setChanged(true);
125 if ($table->getNext()) {
126 $next =& $structure->getTable($table->getNext());
127 $next->setPrevious($name);
128 $next->setChanged(true);
133 $table->setComment($comment);
135 /// Launch postaction if exists (leave this here!)
136 if ($this->getPostAction() && $result) {
137 return $this->launch($this->getPostAction());
140 /// Return ok if arrived here