[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/xmldb/actions/edit_index/ -> edit_index.class.php (source)

   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 provide the interface for all the edit index actions
  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 edit_index 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          $this->sesskey_protected = false; // This action doesn't need sesskey protection
  40  
  41          // Get needed strings
  42          $this->loadStrings(array(
  43              'change' => 'tool_xmldb',
  44              'vieworiginal' => 'tool_xmldb',
  45              'viewedited' => 'tool_xmldb',
  46              'yes' => '',
  47              'no' => '',
  48              'back' => 'tool_xmldb'
  49          ));
  50      }
  51  
  52      /**
  53       * Invoke method, every class will have its own
  54       * returns true/false on completion, setting both
  55       * errormsg and output as necessary
  56       */
  57      function invoke() {
  58          parent::invoke();
  59  
  60          $result = true;
  61  
  62          // Set own core attributes
  63          $this->does_generate = ACTION_GENERATE_HTML;
  64  
  65          // These are always here
  66          global $CFG, $XMLDB, $OUTPUT;
  67  
  68          // Do the job, setting result as needed
  69          // Get the dir containing the file
  70          $dirpath = required_param('dir', PARAM_PATH);
  71          $dirpath = $CFG->dirroot . $dirpath;
  72  
  73          // Get the correct dirs
  74          if (!empty($XMLDB->dbdirs)) {
  75              $dbdir = $XMLDB->dbdirs[$dirpath];
  76          } else {
  77              return false;
  78          }
  79          if (!empty($XMLDB->editeddirs)) {
  80              $editeddir = $XMLDB->editeddirs[$dirpath];
  81              $structure = $editeddir->xml_file->getStructure();
  82          }
  83  
  84          // Fetch request data
  85          $tableparam = required_param('table', PARAM_CLEAN);
  86          if (!$table = $structure->getTable($tableparam)) {
  87              $this->errormsg = 'Wrong table specified: ' . $tableparam;
  88              return false;
  89          }
  90          $indexparam = required_param('index', PARAM_CLEAN);
  91          if (!$index = $table->getIndex($indexparam)) {
  92              // Arriving here from a name change, looking for the new key name
  93              $indexparam = required_param('name', PARAM_CLEAN);
  94              $index = $table->getIndex($indexparam);
  95          }
  96  
  97          $dbdir = $XMLDB->dbdirs[$dirpath];
  98          $origstructure = $dbdir->xml_file->getStructure();
  99  
 100          // Add the main form
 101          $o = '<form id="form" action="index.php" method="post">';
 102          $o.= '<div>';
 103          $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
 104          $o.= '    <input type="hidden" name ="table" value="' . $tableparam .'" />';
 105          $o.= '    <input type="hidden" name ="index" value="' . $indexparam .'" />';
 106          $o.= '    <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
 107          $o.= '    <input type="hidden" name ="action" value="edit_index_save" />';
 108          $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
 109          $o.= '    <table id="formelements" class="boxaligncenter">';
 110          // XMLDB index name
 111          // If the index has dependencies, we cannot change its name
 112          $disabled = '';
 113          if ($structure->getIndexUses($table->getName(), $index->getName())) {
 114              $disabled = ' disabled="disabled " ';
 115          }
 116          $o.= '      <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="'.xmldb_field::NAME_MAX_LENGTH.'" id="name"' . $disabled . ' value="' . s($index->getName()) . '" /></td></tr>';
 117          // XMLDB key comment
 118          $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($index->getComment()) . '</textarea></td></tr>';
 119          // xmldb_index Type
 120          $typeoptions = array (0 => 'not unique',
 121                                1 => 'unique');
 122          $o.= '      <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
 123          $select = html_writer::select($typeoptions, 'unique', $index->getUnique(), false);
 124          $o.= '        <td colspan="2">' . $select . '</td></tr>';
 125          // xmldb_index Fields
 126          $o.= '      <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
 127          $o.= '        <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
 128          // xmldb_index hints
 129          $o.= '      <tr valign="top"><td><label for="hints" accesskey="h">Hints:</label></td>';
 130          $o.= '        <td colspan="2"><input name="hints" type="text" size="40" maxlength="80" id="hints" value="' . s(implode(', ', $index->getHints())) . '" /></td></tr>';
 131          // Change button
 132          $o.= '      <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
 133          $o.= '    </table>';
 134          $o.= '</div></form>';
 135          // Calculate the buttons
 136          $b = ' <p class="centerpara buttons">';
 137          // The view original XML button
 138          if ($table->getIndex($indexparam)) {
 139              $b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['vieworiginal'] . ']</a>';
 140          } else {
 141              $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
 142          }
 143          // The view edited XML button
 144          if ($index->hasChanged()) {
 145              $b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['viewedited'] . ']</a>';
 146          } else {
 147              $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
 148          }
 149          // The back to edit table button
 150          $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
 151          $b .= '</p>';
 152          $o .= $b;
 153  
 154          $this->output = $o;
 155  
 156          // Launch postaction if exists (leave this here!)
 157          if ($this->getPostAction() && $result) {
 158              return $this->launch($this->getPostAction());
 159          }
 160  
 161          // Return ok if arrived here
 162          return $result;
 163      }
 164  }
 165  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1