[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

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

   1  <?php // $Id: edit_index.class.php,v 1.8 2007/10/10 05:25:17 nicolasconnault Exp $
   2  
   3  ///////////////////////////////////////////////////////////////////////////
   4  //                                                                       //
   5  // NOTICE OF COPYRIGHT                                                   //
   6  //                                                                       //
   7  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   8  //          http://moodle.com                                            //
   9  //                                                                       //
  10  // Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
  11  //           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
  12  //                                                                       //
  13  // This program is free software; you can redistribute it and/or modify  //
  14  // it under the terms of the GNU General Public License as published by  //
  15  // the Free Software Foundation; either version 2 of the License, or     //
  16  // (at your option) any later version.                                   //
  17  //                                                                       //
  18  // This program is distributed in the hope that it will be useful,       //
  19  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  20  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  21  // GNU General Public License for more details:                          //
  22  //                                                                       //
  23  //          http://www.gnu.org/copyleft/gpl.html                         //
  24  //                                                                       //
  25  ///////////////////////////////////////////////////////////////////////////
  26  
  27  /// This class will provide the interface for all the edit index actions
  28  
  29  class edit_index extends XMLDBAction {
  30  
  31      /**
  32       * Init method, every subclass will have its own
  33       */
  34      function init() {
  35          parent::init();
  36  
  37      /// Set own custom attributes
  38  
  39      /// Get needed strings
  40          $this->loadStrings(array(
  41              'change' => 'xmldb',
  42              'vieworiginal' => 'xmldb',
  43              'viewedited' => 'xmldb',
  44              'yes' => '',
  45              'no' => '',
  46              'back' => 'xmldb'
  47          ));
  48      }
  49  
  50      /**
  51       * Invoke method, every class will have its own
  52       * returns true/false on completion, setting both
  53       * errormsg and output as necessary
  54       */
  55      function invoke() {
  56          parent::invoke();
  57  
  58          $result = true;
  59  
  60      /// Set own core attributes
  61          $this->does_generate = ACTION_GENERATE_HTML;
  62  
  63      /// These are always here
  64          global $CFG, $XMLDB;
  65  
  66      /// Do the job, setting result as needed
  67      /// Get the dir containing the file
  68          $dirpath = required_param('dir', PARAM_PATH);
  69          $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
  70  
  71      /// Get the correct dirs
  72          if (!empty($XMLDB->dbdirs)) {
  73              $dbdir =& $XMLDB->dbdirs[$dirpath];
  74          } else {
  75              return false;
  76          }
  77          if (!empty($XMLDB->editeddirs)) {
  78              $editeddir =& $XMLDB->editeddirs[$dirpath];
  79              $structure =& $editeddir->xml_file->getStructure();
  80          }
  81  
  82      /// ADD YOUR CODE HERE
  83  
  84      /// Fetch request data
  85          $tableparam = required_param('table', PARAM_CLEAN);
  86          if (!$table =& $structure->getTable($tableparam)) {
  87              $this->errormsg = 'Wrong table specified: ' . $tableparm;
  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 ="action" value="edit_index_save" />';
 107          $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
 108          $o.= '    <table id="formelements" class="boxaligncenter">';
 109      /// XMLDB index name
 110      /// If the index has dependencies, we cannot change its name
 111          $disabled = '';
 112          if ($structure->getIndexUses($table->getName(), $index->getName())) {
 113              $disabled = ' disabled="disabled " ';
 114          }
 115          $o.= '      <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" id="name"' . $disabled . ' value="' . s($index->getName()) . '" /></td></tr>';
 116      /// XMLDB key comment
 117          $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>';
 118      /// XMLDBIndex Type
 119          $typeoptions = array (0 => 'not unique',
 120                                1 => 'unique');
 121          $o.= '      <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
 122          $o.= '        <td colspan="2">' . choose_from_menu($typeoptions, 'unique', $index->getUnique(), '', '', '', true) . '</td></tr>';
 123      /// XMLDBIndex Fields
 124          $o.= '      <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
 125          $o.= '        <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
 126      /// Change button
 127          $o.= '      <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
 128          $o.= '    </table>';
 129          $o.= '</div></form>';
 130      /// Calculate the buttons
 131          $b = ' <p class="centerpara buttons">';
 132      /// The view original XML button
 133          if ($table->getIndex($indexparam)) {
 134              $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>';
 135          } else {
 136              $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
 137          }
 138      /// The view edited XML button
 139          if ($index->hasChanged()) {
 140              $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>';
 141          } else {
 142              $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
 143          }
 144      /// The back to edit table button
 145          $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
 146          $b .= '</p>';
 147          $o .= $b;
 148  
 149          $this->output = $o;
 150  
 151      /// Launch postaction if exists (leave this here!)
 152          if ($this->getPostAction() && $result) {
 153              return $this->launch($this->getPostAction());
 154          }
 155  
 156      /// Return ok if arrived here
 157          return $result;
 158      }
 159  }
 160  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7