|
Moodle
2.2.1
http://www.collinsharper.com
|
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 delete_key extends XMLDBAction { 00033 00037 function init() { 00038 parent::init(); 00039 00040 // Set own custom attributes 00041 00042 // Get needed strings 00043 $this->loadStrings(array( 00044 'confirmdeletekey' => 'tool_xmldb', 00045 'yes' => '', 00046 'no' => '' 00047 )); 00048 } 00049 00055 function invoke() { 00056 parent::invoke(); 00057 00058 $result = true; 00059 00060 // Set own core attributes 00061 $this->does_generate = ACTION_GENERATE_HTML; 00062 00063 // These are always here 00064 global $CFG, $XMLDB; 00065 00066 // Do the job, setting result as needed 00067 00068 // Get the dir containing the file 00069 $dirpath = required_param('dir', PARAM_PATH); 00070 $dirpath = $CFG->dirroot . $dirpath; 00071 $tableparam = required_param('table', PARAM_PATH); 00072 $keyparam = required_param('key', PARAM_PATH); 00073 00074 $confirmed = optional_param('confirmed', false, PARAM_BOOL); 00075 00076 // If not confirmed, show confirmation box 00077 if (!$confirmed) { 00078 $o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">'; 00079 $o.= ' <tr><td class="generalboxcontent">'; 00080 $o.= ' <p class="centerpara">' . $this->str['confirmdeletekey'] . '<br /><br />' . $keyparam . '</p>'; 00081 $o.= ' <table class="boxaligncenter" cellpadding="20"><tr><td>'; 00082 $o.= ' <div class="singlebutton">'; 00083 $o.= ' <form action="index.php?action=delete_key&sesskey=' . sesskey() . '&confirmed=yes&postaction=edit_table&key=' . $keyparam . '&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">'; 00084 $o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>'; 00085 $o.= ' </td><td>'; 00086 $o.= ' <div class="singlebutton">'; 00087 $o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">'; 00088 $o.= ' <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>'; 00089 $o.= ' </td></tr>'; 00090 $o.= ' </table>'; 00091 $o.= ' </td></tr>'; 00092 $o.= '</table>'; 00093 00094 $this->output = $o; 00095 } else { 00096 // Get the edited dir 00097 if (!empty($XMLDB->editeddirs)) { 00098 if (isset($XMLDB->editeddirs[$dirpath])) { 00099 $dbdir =& $XMLDB->dbdirs[$dirpath]; 00100 $editeddir =& $XMLDB->editeddirs[$dirpath]; 00101 if ($editeddir) { 00102 $structure =& $editeddir->xml_file->getStructure(); 00103 // Move adjacent keys prev and next attributes 00104 $tables =& $structure->getTables(); 00105 $table =& $structure->getTable($tableparam); 00106 $keys =& $table->getKeys(); 00107 $key =& $table->getKey($keyparam); 00108 if ($key->getPrevious()) { 00109 $prev =& $table->getKey($key->getPrevious()); 00110 $prev->setNext($key->getNext()); 00111 } 00112 if ($key->getNext()) { 00113 $next =& $table->getKey($key->getNext()); 00114 $next->setPrevious($key->getPrevious()); 00115 } 00116 // Remove the key 00117 $table->deleteKey($keyparam); 00118 00119 // Recalculate the hash 00120 $structure->calculateHash(true); 00121 00122 // If the hash has changed from the original one, change the version 00123 // and mark the structure as changed 00124 $origstructure =& $dbdir->xml_file->getStructure(); 00125 if ($structure->getHash() != $origstructure->getHash()) { 00126 $structure->setVersion(userdate(time(), '%Y%m%d', 99, false)); 00127 $structure->setChanged(true); 00128 } 00129 } 00130 } 00131 } 00132 } 00133 00134 // Launch postaction if exists (leave this here!) 00135 if ($this->getPostAction() && $result) { 00136 return $this->launch($this->getPostAction()); 00137 } 00138 00139 // Return ok if arrived here 00140 return $result; 00141 } 00142 } 00143