3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
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. //
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: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This class will provide the interface for all the edit sentence actions
29 class edit_sentence
extends XMLDBAction
{
32 * Init method, every subclass will have its own
37 /// Set own custom attributes
39 /// Get needed strings
40 $this->loadStrings(array(
42 'vieworiginal' => 'xmldb',
43 'viewedited' => 'xmldb',
49 * Invoke method, every class will have its own
50 * returns true/false on completion, setting both
51 * errormsg and output as necessary
58 /// Set own core attributes
59 $this->does_generate
= ACTION_GENERATE_HTML
;
61 /// These are always here
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);
69 /// Get the correct dirs
70 if (!empty($XMLDB->dbdirs
)) {
71 $dbdir =& $XMLDB->dbdirs
[$dirpath];
75 if (!empty($XMLDB->editeddirs
)) {
76 $editeddir =& $XMLDB->editeddirs
[$dirpath];
77 $structure =& $editeddir->xml_file
->getStructure();
80 /// ADD YOUR CODE HERE
82 /// Fetch request data
83 $statementparam = required_param('statement', PARAM_CLEAN
);
84 $sentenceparam = optional_param('sentence', NULL, PARAM_CLEAN
);
86 if (!$statement =& $structure->getStatement($statementparam)) {
87 $this->errormsg
= 'Wrong statement specified: ' . $statementparam;
90 $sentences =& $statement->getSentences();
92 /// If no sentence has been specified, edit the last one
93 if ($sentenceparam === NULL) {
95 $sentenceparam = key($sentences);
98 if (!$sentence =& $sentences[$sentenceparam]) {
99 $this->errormsg
= 'Wrong Sentence: ' . $sentenceparam;
103 $dbdir =& $XMLDB->dbdirs
[$dirpath];
104 $origstructure =& $dbdir->xml_file
->getStructure();
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';
112 /// Prepare INSERT sentence
113 $fields = $statement->getFieldsFromInsertSentence($sentence);
114 $values = $statement->getValuesFromInsertSentence($sentence);
116 /// Add the main form
117 $o = '<form id="form" action="index.php" method="post">';
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">';
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>';
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>';
134 $o.= '</div></form>';
135 /// Calculate the buttons
136 $b = ' <p class="centerpara buttons">';
137 /// The back to edit statement button
138 $b .= ' <a href="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['back'] . ']</a>';
145 /// Launch postaction if exists (leave this here!)
146 if ($this->getPostAction() && $result) {
147 return $this->launch($this->getPostAction());
150 /// Return ok if arrived here