Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/revert_changes/revert_changes.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 revert_changes 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             'confirmrevertchanges' => '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 
00072         $confirmed = optional_param('confirmed', false, PARAM_BOOL);
00073 
00074         // If  not confirmed, show confirmation box
00075         if (!$confirmed) {
00076             $o = '<table width="60" class="generalbox boxaligncenter" border="0" cellpadding="5" cellspacing="0" id="notice">';
00077             $o.= '  <tr><td class="generalboxcontent">';
00078             $o.= '    <p class="centerpara">' . $this->str['confirmrevertchanges'] . '<br /><br />' . $dirpath . '</p>';
00079             $o.= '    <table class="boxaligncenter" cellpadding="20"><tr><td>';
00080             $o.= '      <div class="singlebutton">';
00081             $o.= '        <form action="index.php?action=revert_changes&amp;sesskey=' . sesskey() . '&amp;confirmed=yes&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;postaction=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
00082             $o.= '          <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>';
00083             $o.= '      </td><td>';
00084             $o.= '      <div class="singlebutton">';
00085             $o.= '        <form action="index.php?action=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
00086             $o.= '          <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>';
00087             $o.= '      </td></tr>';
00088             $o.= '    </table>';
00089             $o.= '  </td></tr>';
00090             $o.= '</table>';
00091 
00092             $this->output = $o;
00093         } else {
00094             // Get the original dir and delete some elements
00095             if (!empty($XMLDB->dbdirs)) {
00096                 if (isset($XMLDB->dbdirs[$dirpath])) {
00097                     $dbdir =& $XMLDB->dbdirs[$dirpath];
00098                     if ($dbdir) {
00099                         unset($dbdir->xml_changed);
00100                     }
00101                 }
00102             }
00103             // Get the edited dir and delete it completely
00104             if (!empty($XMLDB->editeddirs)) {
00105                 if (isset($XMLDB->editeddirs[$dirpath])) {
00106                     unset($XMLDB->editeddirs[$dirpath]);
00107                 }
00108             }
00109         }
00110 
00111         // Launch postaction if exists (leave this here!)
00112         if ($this->getPostAction() && $result) {
00113             return $this->launch($this->getPostAction());
00114         }
00115 
00116         // Return ok if arrived here
00117         return $result;
00118     }
00119 }
00120 
 All Data Structures Namespaces Files Functions Variables Enumerations