|
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_table 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 'confirmdeletetable' => '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_CLEAN); 00072 00073 $confirmed = optional_param('confirmed', false, PARAM_BOOL); 00074 00075 // If not confirmed, show confirmation box 00076 if (!$confirmed) { 00077 $o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">'; 00078 $o.= ' <tr><td class="generalboxcontent">'; 00079 $o.= ' <p class="centerpara">' . $this->str['confirmdeletetable'] . '<br /><br />' . $tableparam . '</p>'; 00080 $o.= ' <table class="boxaligncenter" cellpadding="20"><tr><td>'; 00081 $o.= ' <div class="singlebutton">'; 00082 $o.= ' <form action="index.php?action=delete_table&sesskey=' . sesskey() . '&confirmed=yes&postaction=edit_xml_file&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">'; 00083 $o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>'; 00084 $o.= ' </td><td>'; 00085 $o.= ' <div class="singlebutton">'; 00086 $o.= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">'; 00087 $o.= ' <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>'; 00088 $o.= ' </td></tr>'; 00089 $o.= ' </table>'; 00090 $o.= ' </td></tr>'; 00091 $o.= '</table>'; 00092 00093 $this->output = $o; 00094 } else { 00095 // Get the edited dir 00096 if (!empty($XMLDB->editeddirs)) { 00097 if (isset($XMLDB->editeddirs[$dirpath])) { 00098 $dbdir =& $XMLDB->dbdirs[$dirpath]; 00099 $editeddir =& $XMLDB->editeddirs[$dirpath]; 00100 if ($editeddir) { 00101 $structure =& $editeddir->xml_file->getStructure(); 00102 // Remove the table 00103 $structure->deleteTable($tableparam); 00104 } 00105 } 00106 } 00107 } 00108 00109 // Launch postaction if exists (leave this here!) 00110 if ($this->getPostAction() && $result) { 00111 return $this->launch($this->getPostAction()); 00112 } 00113 00114 // Return ok if arrived here 00115 return $result; 00116 } 00117 } 00118