Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/edit_key/edit_key.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 
00032 class edit_key extends XMLDBAction {
00033 
00037     function init() {
00038         parent::init();
00039 
00040         // Set own custom attributes
00041         $this->sesskey_protected = false; // This action doesn't need sesskey protection
00042 
00043         // Get needed strings
00044         $this->loadStrings(array(
00045             'change' => 'tool_xmldb',
00046             'vieworiginal' => 'tool_xmldb',
00047             'viewedited' => 'tool_xmldb',
00048             'yes' => '',
00049             'no' => '',
00050             'back' => 'tool_xmldb'
00051         ));
00052     }
00053 
00059     function invoke() {
00060         parent::invoke();
00061 
00062         $result = true;
00063 
00064         // Set own core attributes
00065         $this->does_generate = ACTION_GENERATE_HTML;
00066 
00067         // These are always here
00068         global $CFG, $XMLDB, $OUTPUT;
00069 
00070         // Do the job, setting result as needed
00071         // Get the dir containing the file
00072         $dirpath = required_param('dir', PARAM_PATH);
00073         $dirpath = $CFG->dirroot . $dirpath;
00074 
00075         // Get the correct dirs
00076         if (!empty($XMLDB->dbdirs)) {
00077             $dbdir =& $XMLDB->dbdirs[$dirpath];
00078         } else {
00079             return false;
00080         }
00081         if (!empty($XMLDB->editeddirs)) {
00082             $editeddir =& $XMLDB->editeddirs[$dirpath];
00083             $structure =& $editeddir->xml_file->getStructure();
00084         }
00085 
00086         // Fetch request data
00087         $tableparam = required_param('table', PARAM_CLEAN);
00088         if (!$table =& $structure->getTable($tableparam)) {
00089             $this->errormsg = 'Wrong table specified: ' . $tableparam;
00090             return false;
00091         }
00092         $keyparam = required_param('key', PARAM_CLEAN);
00093         if (!$key =& $table->getKey($keyparam)) {
00094             // Arriving here from a name change, looking for the new key name
00095             $keyparam = required_param('name', PARAM_CLEAN);
00096             $key =& $table->getKey($keyparam);
00097         }
00098 
00099         $dbdir =& $XMLDB->dbdirs[$dirpath];
00100         $origstructure =& $dbdir->xml_file->getStructure();
00101 
00102         // Add the main form
00103         $o = '<form id="form" action="index.php" method="post">';
00104         $o.= '<div>';
00105         $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
00106         $o.= '    <input type="hidden" name ="table" value="' . $tableparam .'" />';
00107         $o.= '    <input type="hidden" name ="key" value="' . $keyparam .'" />';
00108         $o.= '    <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
00109         $o.= '    <input type="hidden" name ="action" value="edit_key_save" />';
00110         $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
00111         $o.= '    <table id="formelements" class="boxaligncenter">';
00112         // XMLDB key name
00113         // If the key has dependencies, we cannot change its name
00114         $disabled = '';
00115         if ($structure->getKeyUses($table->getName(), $key->getName())) {
00116             $disabled = ' disabled="disabled " ';
00117         }
00118         $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>';
00119         // XMLDB key comment
00120         $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>';
00121         // xmldb_key Type
00122         $typeoptions = array (XMLDB_KEY_PRIMARY => $key->getXMLDBKeyName(XMLDB_KEY_PRIMARY),
00123                               XMLDB_KEY_UNIQUE  => $key->getXMLDBKeyName(XMLDB_KEY_UNIQUE),
00124                               XMLDB_KEY_FOREIGN   => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN),
00125                               XMLDB_KEY_FOREIGN_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN_UNIQUE));
00126         // Only show the XMLDB_KEY_FOREIGN_UNIQUE if the Key has that type
00127         // if ($key->getType() != XMLDB_KEY_FOREIGN_UNIQUE) {
00128         // unset ($typeoptions[XMLDB_KEY_FOREIGN_UNIQUE);
00129         // }
00130         $select = html_writer::select($typeoptions, 'type', $key->getType(), false);
00131 
00132         $o.= '      <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
00133         $o.= '        <td colspan="2">' . $select . '</td></tr>';
00134         // xmldb_key Fields
00135         $o.= '      <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
00136         $o.= '        <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $key->getFields())) . '" /></td></tr>';
00137         // xmldb_key Reftable
00138         $o.= '      <tr valign="top"><td><label for="reftable" accesskey="t">Reftable:</label></td>';
00139         $o.= '        <td colspan="2"><input name="reftable" type="text" size="20" maxlength="40" id="reftable" value="' . s($key->getReftable()) . '" /></td></tr>';
00140         // xmldb_key Reffields
00141         $o.= '      <tr valign="top"><td><label for="reffields" accesskey="t">Reffields:</label></td>';
00142         $o.= '        <td colspan="2"><input name="reffields" type="text" size="40" maxlength="80" id="reffields" value="' . s(implode(', ', $key->getRefFields())) . '" /></td></tr>';
00143         // Change button
00144         $o.= '      <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
00145         $o.= '    </table>';
00146         $o.= '</div></form>';
00147         // Calculate the buttons
00148         $b = ' <p class="centerpara buttons">';
00149         // The view original XML button
00150         if ($table->getKey($keyparam)) {
00151             $b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['vieworiginal'] . ']</a>';
00152         } else {
00153             $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
00154         }
00155         // The view edited XML button
00156         if ($key->hasChanged()) {
00157             $b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['viewedited'] . ']</a>';
00158         } else {
00159             $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
00160         }
00161         // The back to edit table button
00162         $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
00163         $b .= '</p>';
00164         $o .= $b;
00165 
00166         $this->output = $o;
00167 
00168         // Launch postaction if exists (leave this here!)
00169         if ($this->getPostAction() && $result) {
00170             return $this->launch($this->getPostAction());
00171         }
00172 
00173         // Return ok if arrived here
00174         return $result;
00175     }
00176 }
00177 
 All Data Structures Namespaces Files Functions Variables Enumerations