3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-3001 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 statement actions
29 class edit_statement
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',
44 'newsentence' => 'xmldb',
45 'sentences' => 'xmldb',
48 'duplicate' => 'xmldb',
54 * Invoke method, every class will have its own
55 * returns true/false on completion, setting both
56 * errormsg and output as necessary
63 /// Set own core attributes
64 $this->does_generate
= ACTION_GENERATE_HTML
;
66 /// These are always here
69 /// Do the job, setting result as needed
70 /// Get the dir containing the file
71 $dirpath = required_param('dir', PARAM_PATH
);
72 $dirpath = $CFG->dirroot
. stripslashes_safe($dirpath);
74 /// Get the correct dirs
75 if (!empty($XMLDB->dbdirs
)) {
76 $dbdir =& $XMLDB->dbdirs
[$dirpath];
80 if (!empty($XMLDB->editeddirs
)) {
81 $editeddir =& $XMLDB->editeddirs
[$dirpath];
82 $structure =& $editeddir->xml_file
->getStructure();
85 /// ADD YOUR CODE HERE
86 $statementparam = optional_param('statement', NULL, PARAM_CLEAN
);
87 /// If no statement, then we are coming for a new one. Look for
88 /// type and table and build the correct statementparam
89 if (!$statementparam) {
90 $typeparam = optional_param('type', NULL, PARAM_CLEAN
);
91 $tableparam = optional_param('table', NULL, PARAM_CLEAN
);
92 $typename = XMLDBStatement
::getXMLDBStatementName($typeparam);
93 $statementparam = trim(strtolower($typename . ' ' . $tableparam));
95 if (!$statement =& $structure->getStatement($statementparam)) {
96 /// Arriving here from a name change, looking for the new statement name
97 $statementname = required_param('name', PARAM_CLEAN
);
98 $statement =& $structure->getStatement($statementparam);
101 $dbdir =& $XMLDB->dbdirs
[$dirpath];
102 $origstructure =& $dbdir->xml_file
->getStructure();
104 /// Add the main form
105 $o = '<form id="form" action="index.php" method="post">';
107 $o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot
, '', $dirpath) . '" />';
108 $o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
109 $o.= ' <input type="hidden" name ="action" value="edit_statement_save" />';
110 $o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
111 $o.= ' <table id="formelements" class="boxaligncenter">';
112 $o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($statement->getName()) . '" />' . s($statement->getName()) .'</td></tr>';
113 $o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . s($statement->getComment()) . '</textarea></td></tr>';
114 $o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str
['change'] . '" /></td></tr>';
116 $o.= '</div></form>';
117 /// Calculate the buttons
118 $b = ' <p class="centerpara buttons">';
119 /// The view original XML button
120 if ($origstructure->getStatement($statementparam)) {
121 $b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '&select=original&statement=' . $statementparam . '">[' . $this->str
['vieworiginal'] . ']</a>';
123 $b .= ' [' . $this->str
['vieworiginal'] . ']';
125 /// The view edited XML button
126 if ($statement->hasChanged()) {
127 $b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '&select=edited&statement=' . $statementparam . '">[' . $this->str
['viewedited'] . ']</a>';
129 $b .= ' [' . $this->str
['viewedited'] . ']';
131 /// The new sentence button
132 $b .= ' <a href="index.php?action=new_sentence&postaction=edit_sentence&statement=' . $statementparam . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['newsentence'] . ']</a>';
133 /// The back to edit xml file button
134 $b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['back'] . ']</a>';
138 /// Delete any 'changeme' sentence
139 ///$statement->deleteSentence('changeme');
141 /// Add the fields list
142 $sentences =& $statement->getSentences();
143 if (!empty($sentences)) {
144 $o .= '<h3 class="main">' . $this->str
['sentences'] . '</h3>';
145 $o .= '<table id="listfields" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
147 foreach ($sentences as $key => $sentence) {
149 if ($statement->getType() == XMLDB_STATEMENT_INSERT
) {
150 $p = 'INSERT INTO ' . $statement->getTable() . ' ';
152 $p = 'UNSUPPORTED SENTENCE TYPE ';
154 /// Calculate buttons
155 $b = '</td><td class="button cell">';
157 $b .= '<a href="index.php?action=edit_sentence&sentence=' .$key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['edit'] . ']</a>';
158 $b .= '</td><td class="button cell">';
159 /// The duplicate button
160 $b .= '<a href="index.php?action=new_sentence&postaction=edit_sentence&basesentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['duplicate'] . ']</a>';
161 $b .= '</td><td class="button cell">';
162 /// The delete button
163 $b .= '<a href="index.php?action=delete_sentence&sentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot
, '', $dirpath)) . '">[' . $this->str
['delete'] . ']</a>';
166 $o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
167 $row = ($row +
1) %
2;
174 /// Launch postaction if exists (leave this here!)
175 if ($this->getPostAction() && $result) {
176 return $this->launch($this->getPostAction());
179 /// Return ok if arrived here