[ Index ]

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

title

Body

[close]

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

   1  <?php // $Id: edit_table_save.class.php,v 1.7 2007/10/10 05:25:23 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 save the changes performed to the name and comment of
  28  /// one table
  29  
  30  class edit_table_save 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              'tablenameempty' => 'xmldb',
  43              'incorrecttablename' => 'xmldb',
  44              'duplicatetablename' => 'xmldb',
  45              'administration' => ''
  46          ));
  47      }
  48  
  49      /**
  50       * Invoke method, every class will have its own
  51       * returns true/false on completion, setting both
  52       * errormsg and output as necessary
  53       */
  54      function invoke() {
  55          parent::invoke();
  56  
  57          $result = true;
  58  
  59      /// Set own core attributes
  60          $this->does_generate = ACTION_NONE;
  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  
  68          if (!data_submitted('nomatch')) { ///Basic prevention
  69              error('Wrong action call');
  70          }
  71  
  72      /// Get parameters
  73          $dirpath = required_param('dir', PARAM_PATH);
  74          $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
  75  
  76          $tableparam = strtolower(required_param('table', PARAM_PATH));
  77          $name = substr(trim(strtolower(required_param('name', PARAM_PATH))),0,28);
  78          $comment = required_param('comment', PARAM_CLEAN);
  79          $comment = stripslashes_safe($comment);
  80  
  81          $editeddir =& $XMLDB->editeddirs[$dirpath];
  82          $structure =& $editeddir->xml_file->getStructure();
  83          $table =& $structure->getTable($tableparam);
  84  
  85          $errors = array();    /// To store all the errors found
  86  
  87      /// Perform some checks
  88      /// Check empty name
  89          if (empty($name)) {
  90              $errors[] = $this->str['tablenameempty'];
  91          }
  92      /// Check incorrect name
  93          if ($name == 'changeme') {
  94              $errors[] = $this->str['incorrecttablename'];
  95          }
  96      /// Check duplicatename
  97          if ($tableparam != $name && $structure->getTable($name)) {
  98              $errors[] = $this->str['duplicatetablename'];
  99          }
 100  
 101          if (!empty($errors)) {
 102              $temptable = new XMLDBTable($name);
 103                                                                                                                                        /// Prepare the output
 104              $site = get_site();
 105              $navlinks = array();
 106              $navlinks[] = array('name' => $this->str['administration'], 'link' => '../index.php', 'type' => 'misc');
 107              $navlinks[] = array('name' => 'XMLDB', 'link' => 'index.php', 'type' => 'misc');
 108              $navigation = build_navigation($navlinks);
 109              print_header("$site->shortname: XMLDB", "$site->fullname", $navigation);
 110              notice ('<p>' .implode(', ', $errors) . '</p>
 111                       <p>' . $temptable->readableInfo(),
 112                       'index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
 113              die; /// re-die :-P
 114          }
 115  
 116      /// If there is one name change, do it, changing the prev and next
 117      /// atributes of the adjacent tables
 118          if ($tableparam != $name) {
 119              $table->setName($name);
 120              if ($table->getPrevious()) {
 121                  $prev =& $structure->getTable($table->getPrevious());
 122                  $prev->setNext($name);
 123                  $prev->setChanged(true);
 124              }
 125              if ($table->getNext()) {
 126                  $next =& $structure->getTable($table->getNext());
 127                  $next->setPrevious($name);
 128                  $next->setChanged(true);
 129              }
 130          }
 131  
 132      /// Set comment
 133          $table->setComment($comment);
 134  
 135      /// Launch postaction if exists (leave this here!)
 136          if ($this->getPostAction() && $result) {
 137              return $this->launch($this->getPostAction());
 138          }
 139  
 140      /// Return ok if arrived here
 141          return $result;
 142      }
 143  }
 144  ?>


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