[ Index ]

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

title

Body

[close]

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

   1  <?php // $Id: edit_key.class.php,v 1.8 2007/10/10 05:25:18 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 key actions
  28  
  29  class edit_key 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          $keyparam = required_param('key', PARAM_CLEAN);
  91          if (!$key =& $table->getKey($keyparam)) {
  92          /// Arriving here from a name change, looking for the new key name
  93              $keyparam = required_param('name', PARAM_CLEAN);
  94              $key =& $table->getKey($keyparam);
  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 ="key" value="' . $keyparam .'" />';
 106          $o.= '    <input type="hidden" name ="action" value="edit_key_save" />';
 107          $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
 108          $o.= '    <table id="formelements" class="boxaligncenter">';
 109      /// XMLDB key name
 110      /// If the key has dependencies, we cannot change its name
 111          $disabled = '';
 112          if ($structure->getKeyUses($table->getName(), $key->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($key->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($key->getComment()) . '</textarea></td></tr>';
 118      /// XMLDBKey Type
 119          $typeoptions = array (XMLDB_KEY_PRIMARY => $key->getXMLDBKeyName(XMLDB_KEY_PRIMARY),
 120                                XMLDB_KEY_UNIQUE  => $key->getXMLDBKeyName(XMLDB_KEY_UNIQUE),
 121                                XMLDB_KEY_FOREIGN   => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN),
 122                                XMLDB_KEY_FOREIGN_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN_UNIQUE));
 123      /// Only show the XMLDB_KEY_FOREIGN_UNIQUE if the Key has that type
 124      /// if ($key->getType() != XMLDB_KEY_FOREIGN_UNIQUE) {
 125      ///     unset ($typeoptions[XMLDB_KEY_FOREIGN_UNIQUE);
 126      /// }
 127          $o.= '      <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
 128          $o.= '        <td colspan="2">' . choose_from_menu($typeoptions, 'type', $key->getType(), '', '', '', true) . '</td></tr>';
 129      /// XMLDBKey Fields
 130          $o.= '      <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
 131          $o.= '        <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $key->getFields())) . '" /></td></tr>';
 132      /// XMLDBKey Reftable
 133          $o.= '      <tr valign="top"><td><label for="reftable" accesskey="t">Reftable:</label></td>';
 134          $o.= '        <td colspan="2"><input name="reftable" type="text" size="20" maxlength="40" id="reftable" value="' . s($key->getReftable()) . '" /></td></tr>';
 135      /// XMLDBKey Reffields
 136          $o.= '      <tr valign="top"><td><label for="reffields" accesskey="t">Reffields:</label></td>';
 137          $o.= '        <td colspan="2"><input name="reffields" type="text" size="40" maxlength="80" id="reffields" value="' . s(implode(', ', $key->getRefFields())) . '" /></td></tr>';
 138      /// Change button
 139          $o.= '      <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
 140          $o.= '    </table>';
 141          $o.= '</div></form>';
 142      /// Calculate the buttons
 143          $b = ' <p class="centerpara buttons">';
 144      /// The view original XML button
 145          if ($table->getKey($keyparam)) {
 146              $b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['vieworiginal'] . ']</a>';
 147          } else {
 148              $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
 149          }
 150      /// The view edited XML button
 151          if ($key->hasChanged()) {
 152              $b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['viewedited'] . ']</a>';
 153          } else {
 154              $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
 155          }
 156      /// The back to edit table button
 157          $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
 158          $b .= '</p>';
 159          $o .= $b;
 160  
 161          $this->output = $o;
 162  
 163      /// Launch postaction if exists (leave this here!)
 164          if ($this->getPostAction() && $result) {
 165              return $this->launch($this->getPostAction());
 166          }
 167  
 168      /// Return ok if arrived here
 169          return $result;
 170      }
 171  }
 172  ?>


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