[ Index ]

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

title

Body

[close]

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

   1  <?php // $Id: edit_sentence.class.php,v 1.7 2007/10/10 05:25:16 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 sentence actions
  28  
  29  class edit_sentence 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              'back' => 'xmldb'
  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      /// Get the dir containing the file
  66          $dirpath = required_param('dir', PARAM_PATH);
  67          $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
  68  
  69      /// Get the correct dirs
  70          if (!empty($XMLDB->dbdirs)) {
  71              $dbdir =& $XMLDB->dbdirs[$dirpath];
  72          } else {
  73              return false;
  74          }
  75          if (!empty($XMLDB->editeddirs)) {
  76              $editeddir =& $XMLDB->editeddirs[$dirpath];
  77              $structure =& $editeddir->xml_file->getStructure();
  78          }
  79  
  80      /// ADD YOUR CODE HERE
  81  
  82      /// Fetch request data
  83          $statementparam = required_param('statement', PARAM_CLEAN);
  84          $sentenceparam  = optional_param('sentence', NULL, PARAM_CLEAN);
  85  
  86          if (!$statement =& $structure->getStatement($statementparam)) {
  87              $this->errormsg = 'Wrong statement specified: ' . $statementparam;
  88              return false;
  89          }
  90          $sentences =& $statement->getSentences();
  91  
  92      /// If no sentence has been specified, edit the last one
  93          if ($sentenceparam === NULL) {
  94              end($sentences);
  95              $sentenceparam = key($sentences);
  96          }
  97  
  98          if (!$sentence =& $sentences[$sentenceparam]) {
  99              $this->errormsg = 'Wrong Sentence: ' . $sentenceparam;
 100              return false;
 101          }
 102  
 103          $dbdir =& $XMLDB->dbdirs[$dirpath];
 104          $origstructure =& $dbdir->xml_file->getStructure();
 105  
 106      /// Based in the type of statement, print different forms
 107          if ($statement->getType() != XMLDB_STATEMENT_INSERT) {
 108          /// Only INSERT is allowed!!
 109              $this->errormsg = 'Wrong Statement Type. Only INSERT allowed';
 110              return false;
 111          } else {
 112          /// Prepare INSERT sentence
 113              $fields = $statement->getFieldsFromInsertSentence($sentence);
 114              $values = $statement->getValuesFromInsertSentence($sentence);
 115  
 116          /// Add the main form
 117              $o = '<form id="form" action="index.php" method="post">';
 118              $o.= '<div>';
 119              $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
 120              $o.= '    <input type="hidden" name ="statement" value="' . $statementparam .'" />';
 121              $o.= '    <input type="hidden" name ="sentence" value="' . $sentenceparam .'" />';
 122              $o.= '    <input type="hidden" name ="action" value="edit_sentence_save" />';
 123              $o.= '    <input type="hidden" name ="postaction" value="edit_statement" />';
 124              $o.= '    <table id="formelements" class="boxaligncenter">';
 125          /// The fields box
 126              $o.= '    <tr><td>INSERT INTO ' . s($statement->getTable()) . '</td></tr>';
 127              $o.= '    <tr><td><textarea name="fields" rows="2" cols="70" id="fields">' . s(implode(', ', $fields)) . '</textarea></td></tr>';
 128          /// The values box
 129              $o.= '    <tr><td>VALUES</td></tr>';
 130              $o.= '    <tr><td><textarea name="values" rows="2" cols="70" id="values">' . s(implode(', ', $values)) . '</textarea></td></tr>';
 131          /// The submit button
 132              $o.= '      <tr valign="top"><td><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 back to edit statement button
 138              $b .= '&nbsp;<a href="index.php?action=edit_statement&amp;statement=' . urlencode($statementparam) . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
 139              $b .= '</p>';
 140              $o .= $b;
 141  
 142              $this->output = $o;
 143          }
 144  
 145      /// Launch postaction if exists (leave this here!)
 146          if ($this->getPostAction() && $result) {
 147              return $this->launch($this->getPostAction());
 148          }
 149  
 150      /// Return ok if arrived here
 151          return $result;
 152      }
 153  }
 154  ?>


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