Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package    tool_xmldb
  19   * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  20   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  
  23  /**
  24   * This class will delete completely one table
  25   *
  26   * @package    tool_xmldb
  27   * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class delete_table extends XMLDBAction {
  31  
  32      /**
  33       * Init method, every subclass will have its own
  34       */
  35      function init() {
  36          parent::init();
  37  
  38          // Set own custom attributes
  39  
  40          // Get needed strings
  41          $this->loadStrings(array(
  42              'confirmdeletetable' => 'tool_xmldb',
  43              'yes' => '',
  44              'no' => ''
  45          ));
  46      }
  47  
  48      /**
  49       * Invoke method, every class will have its own
  50       * returns true/false on completion, setting both
  51       * errormsg and output as necessary
  52       */
  53      function invoke() {
  54          parent::invoke();
  55  
  56          $result = true;
  57  
  58          // Set own core attributes
  59          $this->does_generate = ACTION_GENERATE_HTML;
  60  
  61          // These are always here
  62          global $CFG, $XMLDB;
  63  
  64          // Do the job, setting result as needed
  65  
  66          // Get the dir containing the file
  67          $dirpath = required_param('dir', PARAM_PATH);
  68          $dirpath = $CFG->dirroot . $dirpath;
  69          $tableparam = required_param('table', PARAM_CLEAN);
  70  
  71          $confirmed = optional_param('confirmed', false, PARAM_BOOL);
  72  
  73          // If  not confirmed, show confirmation box
  74          if (!$confirmed) {
  75              $o = '<table width="60" class="generaltable" border="0" cellpadding="5" cellspacing="0" id="notice">';
  76              $o.= '  <tr><td class="generalboxcontent">';
  77              $o.= '    <p class="centerpara">' . $this->str['confirmdeletetable'] . '<br /><br />' . $tableparam . '</p>';
  78              $o.= '    <table class="boxaligncenter" cellpadding="20"><tr><td>';
  79              $o.= '      <div class="singlebutton">';
  80              $o.= '        <form action="index.php?action=delete_table&amp;sesskey=' . sesskey() . '&amp;confirmed=yes&amp;postaction=edit_xml_file&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
  81              $o.= '          <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>';
  82              $o.= '      </td><td>';
  83              $o.= '      <div class="singlebutton">';
  84              $o.= '        <form action="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
  85              $o.= '          <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>';
  86              $o.= '      </td></tr>';
  87              $o.= '    </table>';
  88              $o.= '  </td></tr>';
  89              $o.= '</table>';
  90  
  91              $this->output = $o;
  92          } else {
  93              // Get the edited dir
  94              if (!empty($XMLDB->editeddirs)) {
  95                  if (isset($XMLDB->editeddirs[$dirpath])) {
  96                      $dbdir = $XMLDB->dbdirs[$dirpath];
  97                      $editeddir = $XMLDB->editeddirs[$dirpath];
  98                      if ($editeddir) {
  99                          $structure = $editeddir->xml_file->getStructure();
 100                          // Remove the table
 101                          $structure->deleteTable($tableparam);
 102                      }
 103                  }
 104              }
 105          }
 106  
 107          // Launch postaction if exists (leave this here!)
 108          if ($this->getPostAction() && $result) {
 109              return $this->launch($this->getPostAction());
 110          }
 111  
 112          // Return ok if arrived here
 113          return $result;
 114      }
 115  }
 116