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 provide the interface for all the edit index actions
29 class edit_index
extends XMLDBAction
{
32 * Init method, every subclass will have its own
37 /// Set own custom attributes
39 /// Get needed strings
40 $this->loadStrings(array(
42 'vieworiginal' => 'xmldb',
43 'viewedited' => 'xmldb',
51 * Invoke method, every class will have its own
52 * returns true/false on completion, setting both
53 * errormsg and output as necessary
60 /// Set own core attributes
61 $this->does_generate
= ACTION_GENERATE_HTML
;
63 /// These are always here
66 /// Do the job, setting result as needed
67 /// Get the dir containing the file
68 $dirpath = required_param('dir', PARAM_PATH
);
69 $dirpath = $CFG->dirroot
. stripslashes_safe($dirpath);
71 /// Get the correct dirs
72 if (!empty($XMLDB->dbdirs
)) {
73 $dbdir =& $XMLDB->dbdirs
[$dirpath];
77 if (!empty($XMLDB->editeddirs
)) {
78 $editeddir =& $XMLDB->editeddirs
[$dirpath];
79 $structure =& $editeddir->xml_file
->getStructure();
82 /// ADD YOUR CODE HERE
84 /// Fetch request data
85 $tableparam = required_param('table', PARAM_CLEAN
);
86 if (!$table =& $structure->getTable($tableparam)) {
87 $this->errormsg
= 'Wrong table specified: ' . $tableparm;
90 $indexparam = required_param('index', PARAM_CLEAN
);
91 if (!$index =& $table->getIndex($indexparam)) {
92 /// Arriving here from a name change, looking for the new key name
93 $indexparam = required_param('name', PARAM_CLEAN
);
94 $index =& $table->getIndex($indexparam);
97 $dbdir =& $XMLDB->dbdirs
[$dirpath];
98 $origstructure =& $dbdir->xml_file
->getStructure();
100 /// Add the main form
101 $o = '<form id="form" action="index.php" method="post">';
103 $o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot
, '', $dirpath) . '" />';
104 $o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
105 $o.= ' <input type="hidden" name ="index" value="' . $indexparam .'" />';
106 $o.= ' <input type="hidden" name ="action" value="edit_index_save" />';
107 $o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
108 $o.= ' <table id="formelements" class="boxaligncenter">';
110 /// If the index has dependencies, we cannot change its name
112 if ($structure->getIndexUses($table->getName(), $index->getName())) {
113 $disabled = ' disabled="disabled " ';
115 $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>';
116 /// XMLDB key comment
117 $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>';
119 $typeoptions = array (0 => 'not unique',
121 $o.= ' <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
122 $o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'unique', $index->getUnique(), '', '', '', true) . '</td></tr>';
123 /// XMLDBIndex Fields
124 $o.= ' <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
125 $o.= ' <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
127 $o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str
['change'] . '" /></td></tr>';
129 $o.= '</div></form>';
130 /// Calculate the buttons
131 $b = ' <p class="centerpara buttons">';
132 /// The view original XML button
133 if ($table->getIndex($indexparam)) {
134 $b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '&select=original&table=' . $tableparam . '&index=' . $indexparam . '">[' . $this->str
['vieworiginal'] . ']</a>';
136 $b .= ' [' . $this->str
['vieworiginal'] . ']';
138 /// The view edited XML button
139 if ($index->hasChanged()) {
140 $b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&index=' . $indexparam . '">[' . $this->str
['viewedited'] . ']</a>';
142 $b .= ' [' . $this->str
['viewedited'] . ']';
144 /// The back to edit table button
145 $b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['back'] . ']</a>';
151 /// Launch postaction if exists (leave this here!)
152 if ($this->getPostAction() && $result) {
153 return $this->launch($this->getPostAction());
156 /// Return ok if arrived here