Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/edit_index/edit_index.class.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00031 class edit_index extends XMLDBAction {
00032 
00036     function init() {
00037         parent::init();
00038 
00039         // Set own custom attributes
00040         $this->sesskey_protected = false; // This action doesn't need sesskey protection
00041 
00042         // Get needed strings
00043         $this->loadStrings(array(
00044             'change' => 'tool_xmldb',
00045             'vieworiginal' => 'tool_xmldb',
00046             'viewedited' => 'tool_xmldb',
00047             'yes' => '',
00048             'no' => '',
00049             'back' => 'tool_xmldb'
00050         ));
00051     }
00052 
00058     function invoke() {
00059         parent::invoke();
00060 
00061         $result = true;
00062 
00063         // Set own core attributes
00064         $this->does_generate = ACTION_GENERATE_HTML;
00065 
00066         // These are always here
00067         global $CFG, $XMLDB, $OUTPUT;
00068 
00069         // Do the job, setting result as needed
00070         // Get the dir containing the file
00071         $dirpath = required_param('dir', PARAM_PATH);
00072         $dirpath = $CFG->dirroot . $dirpath;
00073 
00074         // Get the correct dirs
00075         if (!empty($XMLDB->dbdirs)) {
00076             $dbdir =& $XMLDB->dbdirs[$dirpath];
00077         } else {
00078             return false;
00079         }
00080         if (!empty($XMLDB->editeddirs)) {
00081             $editeddir =& $XMLDB->editeddirs[$dirpath];
00082             $structure =& $editeddir->xml_file->getStructure();
00083         }
00084 
00085         // Fetch request data
00086         $tableparam = required_param('table', PARAM_CLEAN);
00087         if (!$table =& $structure->getTable($tableparam)) {
00088             $this->errormsg = 'Wrong table specified: ' . $tableparam;
00089             return false;
00090         }
00091         $indexparam = required_param('index', PARAM_CLEAN);
00092         if (!$index =& $table->getIndex($indexparam)) {
00093             // Arriving here from a name change, looking for the new key name
00094             $indexparam = required_param('name', PARAM_CLEAN);
00095             $index =& $table->getIndex($indexparam);
00096         }
00097 
00098         $dbdir =& $XMLDB->dbdirs[$dirpath];
00099         $origstructure =& $dbdir->xml_file->getStructure();
00100 
00101         // Add the main form
00102         $o = '<form id="form" action="index.php" method="post">';
00103         $o.= '<div>';
00104         $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
00105         $o.= '    <input type="hidden" name ="table" value="' . $tableparam .'" />';
00106         $o.= '    <input type="hidden" name ="index" value="' . $indexparam .'" />';
00107         $o.= '    <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
00108         $o.= '    <input type="hidden" name ="action" value="edit_index_save" />';
00109         $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
00110         $o.= '    <table id="formelements" class="boxaligncenter">';
00111         // XMLDB index name
00112         // If the index has dependencies, we cannot change its name
00113         $disabled = '';
00114         if ($structure->getIndexUses($table->getName(), $index->getName())) {
00115             $disabled = ' disabled="disabled " ';
00116         }
00117         $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>';
00118         // XMLDB key comment
00119         $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>';
00120         // xmldb_index Type
00121         $typeoptions = array (0 => 'not unique',
00122                               1 => 'unique');
00123         $o.= '      <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
00124         $select = html_writer::select($typeoptions, 'unique', $index->getUnique(), false);
00125         $o.= '        <td colspan="2">' . $select . '</td></tr>';
00126         // xmldb_index Fields
00127         $o.= '      <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
00128         $o.= '        <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
00129         // Change button
00130         $o.= '      <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
00131         $o.= '    </table>';
00132         $o.= '</div></form>';
00133         // Calculate the buttons
00134         $b = ' <p class="centerpara buttons">';
00135         // The view original XML button
00136         if ($table->getIndex($indexparam)) {
00137             $b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['vieworiginal'] . ']</a>';
00138         } else {
00139             $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
00140         }
00141         // The view edited XML button
00142         if ($index->hasChanged()) {
00143             $b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['viewedited'] . ']</a>';
00144         } else {
00145             $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
00146         }
00147         // The back to edit table button
00148         $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
00149         $b .= '</p>';
00150         $o .= $b;
00151 
00152         $this->output = $o;
00153 
00154         // Launch postaction if exists (leave this here!)
00155         if ($this->getPostAction() && $result) {
00156             return $this->launch($this->getPostAction());
00157         }
00158 
00159         // Return ok if arrived here
00160         return $result;
00161     }
00162 }
00163 
 All Data Structures Namespaces Files Functions Variables Enumerations