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 show all the actions available under the XMLDB interface
29 class main_view
extends XMLDBAction
{
32 * Init method, every subclass will have its own
37 /// Set own custom attributes
39 /// Get needed strings
40 $this->loadStrings(array(
48 'reservedwords' => 'xmldb',
50 'gotolastused' => 'xmldb',
51 'checkindexes' => 'xmldb'
56 * Invoke method, every class will have its own
57 * returns true/false on completion, setting both
58 * errormsg and output as necessary
65 /// Set own core attributes
66 $this->does_generate
= ACTION_GENERATE_HTML
;
68 /// These are always here
69 global $CFG, $XMLDB, $SESSION;
73 if (isset($SESSION->lastused
)) {
74 if ($lastused = $SESSION->lastused
) {
76 $o .= '<p class="centerpara"><a href="#lastused">' . $this->str
['gotolastused'] . '</a></p>';
82 /// Calculate the buttons
83 $b = '<p class="centerpara buttons">';
84 /// The reserved_words button
85 $b .= ' <a href="index.php?action=view_reserved_words">[' . $this->str
['reservedwords'] . ']</a>';
87 $b .= ' <a href="index.php?action=test">[' . $this->str
['test'] . ']</a>';
88 /// The check indexes button
89 $b .= ' <a href="index.php?action=check_indexes">[' . $this->str
['checkindexes'] . ']</a>';
91 /// Send buttons to output
96 /// Get the list of DB directories
97 $result = $this->launch('get_db_directories');
98 /// Display list of DB directories if everything is ok
99 if ($result && !empty($XMLDB->dbdirs
)) {
100 $o .= '<table id="listdirectories" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
102 foreach ($XMLDB->dbdirs
as $key => $dbdir) {
103 /// Detect if this is the lastused dir
105 if (str_replace($CFG->dirroot
, '', $key) == $lastused) {
108 $elementtext = str_replace($CFG->dirroot
. '/', '', $key);
109 /// Calculate the dbdir has_changed field if needed
110 if (!isset($dbdir->has_changed
) && isset($dbdir->xml_loaded
)) {
111 $dbdir->xml_changed
= false;
112 if (isset($XMLDB->editeddirs
[$key])) {
113 $editeddir =& $XMLDB->editeddirs
[$key];
114 if (isset($editeddir->xml_file
)) {
115 $structure =& $editeddir->xml_file
->getStructure();
116 if ($structure->hasChanged()) {
117 $dbdir->xml_changed
= true;
118 $editeddir->xml_changed
= true;
123 /// Calculate the buttons
124 $b = ' <td class="button cell">';
125 /// The create button
126 if ($dbdir->path_exists
&&
127 !file_exists($key . '/install.xml') &&
128 is_writeable($key)) {
129 $b .= '<a href="index.php?action=create_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str
['create'] . ']</a>';
131 $b .= '[' . $this->str
['create'] . ']';
133 $b .= '</td><td class="button cell">';
135 if ($dbdir->path_exists
&&
136 file_exists($key . '/install.xml') &&
137 is_readable($key . '/install.xml') &&
138 empty($dbdir->xml_loaded
)) {
139 $b .= '<a href="index.php?action=load_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str
['load'] . ']</a>';
141 $b .= '[' . $this->str
['load'] . ']';
143 $b .= '</td><td class="button cell">';
145 if ($dbdir->path_exists
&&
146 file_exists($key . '/install.xml') &&
147 is_readable($key . '/install.xml') &&
149 !empty($dbdir->xml_loaded
)) {
150 $b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '">[' . $this->str
['edit'] . ']</a>';
152 $b .= '[' . $this->str
['edit'] . ']';
154 $b .= '</td><td class="button cell">';
156 if ($dbdir->path_exists
&&
157 file_exists($key . '/install.xml') &&
158 is_writeable($key . '/install.xml') &&
159 is_writeable($key) &&
160 !empty($dbdir->xml_loaded
) &&
161 !empty($dbdir->xml_changed
)) {
162 $b .= '<a href="index.php?action=save_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str
['save'] . ']</a>';
163 /// Check if the file has been manually edited while being modified in the editor
164 if ($dbdir->filemtime
!= filemtime($key . '/install.xml')) {
165 /// File manually modified. Add to errors.
166 if ($structure =& $dbdir->xml_file
->getStructure()) {
167 $structure->errormsg
= 'Warning: File locally modified while using the XMLDB Editor. Saving will overwrite local changes';
171 $b .= '[' . $this->str
['save'] . ']';
173 $b .= '</td><td class="button cell">';
174 /// The revert button
175 if ($dbdir->path_exists
&&
176 file_exists($key . '/install.xml') &&
177 is_readable($key . '/install.xml') &&
178 is_writeable($key) &&
179 !empty($dbdir->xml_loaded
) &&
180 !empty($dbdir->xml_changed
)) {
181 $b .= '<a href="index.php?action=revert_changes&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '">[' . $this->str
['revert'] . ']</a>';
183 $b .= '[' . $this->str
['revert'] . ']';
185 $b .= '</td><td class="button cell">';
186 /// The unload button
187 if ($dbdir->path_exists
&&
188 file_exists($key . '/install.xml') &&
189 is_readable($key . '/install.xml') &&
190 !empty($dbdir->xml_loaded
) &&
191 empty($dbdir->xml_changed
)) {
192 $b .= '<a href="index.php?action=unload_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '&time=' . time() . '&postaction=main_view#lastused">[' . $this->str
['unload'] . ']</a>';
194 $b .= '[' . $this->str
['unload'] . ']';
196 $b .= '</td><td class="button cell">';
197 /// The delete button
198 if ($dbdir->path_exists
&&
199 file_exists($key . '/install.xml') &&
200 is_readable($key . '/install.xml') &&
201 is_writeable($key) &&
202 empty($dbdir->xml_loaded
)) {
203 $b .= '<a href="index.php?action=delete_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '">[' . $this->str
['delete'] . ']</a>';
205 $b .= '[' . $this->str
['delete'] . ']';
208 /// if the file, exist, XML is viewable
209 if ($dbdir->path_exists
&&
210 file_exists($key . '/install.xml') &&
211 is_readable($key . '/install.xml')) {
212 $elementtext = '<a href="index.php?action=view_xml&file=' . urlencode(str_replace($CFG->dirroot
, '', $key) . '/install.xml') . '">' . $elementtext . '</a></td>';
214 $elementtext = $elementtext . '</td>';
216 /// include the higlight
218 $o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $elementtext . $b . '</tr>';
220 $o .= '<tr class="r' . $row . '"><td class="directory cell">' . $elementtext . $b . '</tr>';
222 $row = ($row +
1) %
2;
223 /// show errors if they exist
224 if (isset($dbdir->xml_file
)) {
225 if ($structure =& $dbdir->xml_file
->getStructure()) {
226 if ($errors = $structure->getAllErrors()) {
228 $o .= '<tr class="highlight"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
230 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
242 /// Finally, return result