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',
52 'checkbigints' => 'xmldb'
57 * Invoke method, every class will have its own
58 * returns true/false on completion, setting both
59 * errormsg and output as necessary
66 /// Set own core attributes
67 $this->does_generate
= ACTION_GENERATE_HTML
;
69 /// These are always here
70 global $CFG, $XMLDB, $SESSION;
74 if (isset($SESSION->lastused
)) {
75 if ($lastused = $SESSION->lastused
) {
77 $o .= '<p class="centerpara"><a href="#lastused">' . $this->str
['gotolastused'] . '</a></p>';
83 /// Calculate the buttons
84 $b = '<p class="centerpara buttons">';
85 /// The reserved_words button
86 $b .= ' <a href="index.php?action=view_reserved_words">[' . $this->str
['reservedwords'] . ']</a>';
88 $b .= ' <a href="index.php?action=test">[' . $this->str
['test'] . ']</a>';
89 /// The check indexes button
90 $b .= ' <a href="index.php?action=check_indexes">[' . $this->str
['checkindexes'] . ']</a>';
91 /// The check bigints button (only for MySQL and PostgreSQL) MDL-11038a
92 if ($CFG->dbfamily
== 'mysql' ||
$CFG->dbfamily
== 'postgres') {
93 $b .= ' <a href="index.php?action=check_bigints">[' . $this->str
['checkbigints'] . ']</a>';
96 /// Send buttons to output
101 /// Get the list of DB directories
102 $result = $this->launch('get_db_directories');
103 /// Display list of DB directories if everything is ok
104 if ($result && !empty($XMLDB->dbdirs
)) {
105 $o .= '<table id="listdirectories" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
107 foreach ($XMLDB->dbdirs
as $key => $dbdir) {
108 /// Detect if this is the lastused dir
110 if (str_replace($CFG->dirroot
, '', $key) == $lastused) {
113 $elementtext = str_replace($CFG->dirroot
. '/', '', $key);
114 /// Calculate the dbdir has_changed field if needed
115 if (!isset($dbdir->has_changed
) && isset($dbdir->xml_loaded
)) {
116 $dbdir->xml_changed
= false;
117 if (isset($XMLDB->editeddirs
[$key])) {
118 $editeddir =& $XMLDB->editeddirs
[$key];
119 if (isset($editeddir->xml_file
)) {
120 $structure =& $editeddir->xml_file
->getStructure();
121 if ($structure->hasChanged()) {
122 $dbdir->xml_changed
= true;
123 $editeddir->xml_changed
= true;
128 /// Calculate the buttons
129 $b = ' <td class="button cell">';
130 /// The create button
131 if ($dbdir->path_exists
&&
132 !file_exists($key . '/install.xml') &&
133 is_writeable($key)) {
134 $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>';
136 $b .= '[' . $this->str
['create'] . ']';
138 $b .= '</td><td class="button cell">';
140 if ($dbdir->path_exists
&&
141 file_exists($key . '/install.xml') &&
142 is_readable($key . '/install.xml') &&
143 empty($dbdir->xml_loaded
)) {
144 $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>';
146 $b .= '[' . $this->str
['load'] . ']';
148 $b .= '</td><td class="button cell">';
150 if ($dbdir->path_exists
&&
151 file_exists($key . '/install.xml') &&
152 is_readable($key . '/install.xml') &&
154 !empty($dbdir->xml_loaded
)) {
155 $b .= '<a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '">[' . $this->str
['edit'] . ']</a>';
157 $b .= '[' . $this->str
['edit'] . ']';
159 $b .= '</td><td class="button cell">';
161 if ($dbdir->path_exists
&&
162 file_exists($key . '/install.xml') &&
163 is_writeable($key . '/install.xml') &&
164 is_writeable($key) &&
165 !empty($dbdir->xml_loaded
) &&
166 !empty($dbdir->xml_changed
)) {
167 $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>';
168 /// Check if the file has been manually edited while being modified in the editor
169 if ($dbdir->filemtime
!= filemtime($key . '/install.xml')) {
170 /// File manually modified. Add to errors.
171 if ($structure =& $dbdir->xml_file
->getStructure()) {
172 $structure->errormsg
= 'Warning: File locally modified while using the XMLDB Editor. Saving will overwrite local changes';
176 $b .= '[' . $this->str
['save'] . ']';
178 $b .= '</td><td class="button cell">';
179 /// The revert button
180 if ($dbdir->path_exists
&&
181 file_exists($key . '/install.xml') &&
182 is_readable($key . '/install.xml') &&
183 is_writeable($key) &&
184 !empty($dbdir->xml_loaded
) &&
185 !empty($dbdir->xml_changed
)) {
186 $b .= '<a href="index.php?action=revert_changes&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '">[' . $this->str
['revert'] . ']</a>';
188 $b .= '[' . $this->str
['revert'] . ']';
190 $b .= '</td><td class="button cell">';
191 /// The unload button
192 if ($dbdir->path_exists
&&
193 file_exists($key . '/install.xml') &&
194 is_readable($key . '/install.xml') &&
195 !empty($dbdir->xml_loaded
) &&
196 empty($dbdir->xml_changed
)) {
197 $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>';
199 $b .= '[' . $this->str
['unload'] . ']';
201 $b .= '</td><td class="button cell">';
202 /// The delete button
203 if ($dbdir->path_exists
&&
204 file_exists($key . '/install.xml') &&
205 is_readable($key . '/install.xml') &&
206 is_writeable($key) &&
207 empty($dbdir->xml_loaded
)) {
208 $b .= '<a href="index.php?action=delete_xml_file&dir=' . urlencode(str_replace($CFG->dirroot
, '', $key)) . '">[' . $this->str
['delete'] . ']</a>';
210 $b .= '[' . $this->str
['delete'] . ']';
213 /// if the file, exist, XML is viewable
214 if ($dbdir->path_exists
&&
215 file_exists($key . '/install.xml') &&
216 is_readable($key . '/install.xml')) {
217 $elementtext = '<a href="index.php?action=view_xml&file=' . urlencode(str_replace($CFG->dirroot
, '', $key) . '/install.xml') . '">' . $elementtext . '</a></td>';
219 $elementtext = $elementtext . '</td>';
221 /// include the higlight
223 $o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $elementtext . $b . '</tr>';
225 $o .= '<tr class="r' . $row . '"><td class="directory cell">' . $elementtext . $b . '</tr>';
227 $row = ($row +
1) %
2;
228 /// show errors if they exist
229 if (isset($dbdir->xml_file
)) {
230 if ($structure =& $dbdir->xml_file
->getStructure()) {
231 if ($errors = $structure->getAllErrors()) {
233 $o .= '<tr class="highlight"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
235 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
247 /// Finally, return result