Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / xmldb / actions / main_view / main_view.class.php
blob673cb885a0b57f71a576fc5f7d7a13d028b789e1
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-3001 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 ///////////////////////////////////////////////////////////////////////////
27 /// This class will show all the actions available under the XMLDB interface
29 class main_view extends XMLDBAction {
31 /**
32 * Init method, every subclass will have its own
34 function init() {
35 parent::init();
37 /// Set own custom attributes
39 /// Get needed strings
40 $this->loadStrings(array(
41 'load' => 'xmldb',
42 'create' => 'xmldb',
43 'edit' => 'xmldb',
44 'save' => 'xmldb',
45 'revert' => 'xmldb',
46 'unload' => 'xmldb',
47 'delete' => 'xmldb',
48 'reservedwords' => 'xmldb',
49 'test' => 'xmldb',
50 'gotolastused' => 'xmldb',
51 'checkindexes' => 'xmldb'
52 ));
55 /**
56 * Invoke method, every class will have its own
57 * returns true/false on completion, setting both
58 * errormsg and output as necessary
60 function invoke() {
61 parent::invoke();
63 $result = true;
65 /// Set own core attributes
66 $this->does_generate = ACTION_GENERATE_HTML;
68 /// These are always here
69 global $CFG, $XMLDB, $SESSION;
71 /// Get lastused
72 $o = '';
73 if (isset($SESSION->lastused)) {
74 if ($lastused = $SESSION->lastused) {
75 /// Print link
76 $o .= '<p class="centerpara"><a href="#lastused">' . $this->str['gotolastused'] . '</a></p>';
78 } else {
79 $lastused = NULL;
82 /// Calculate the buttons
83 $b = '<p class="centerpara buttons">';
84 /// The reserved_words button
85 $b .= '&nbsp;<a href="index.php?action=view_reserved_words">[' . $this->str['reservedwords'] . ']</a>';
86 /// The test button
87 $b .= '&nbsp;<a href="index.php?action=test">[' . $this->str['test'] . ']</a>';
88 /// The check indexes button
89 $b .= '&nbsp;<a href="index.php?action=check_indexes">[' . $this->str['checkindexes'] . ']</a>';
90 $b .= '</p>';
91 /// Send buttons to output
92 $o .= $b;
94 /// Do the job
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">';
101 $row = 0;
102 foreach ($XMLDB->dbdirs as $key => $dbdir) {
103 /// Detect if this is the lastused dir
104 $hithis = false;
105 if (str_replace($CFG->dirroot, '', $key) == $lastused) {
106 $hithis = true;
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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&amp;time=' . time() . '&amp;postaction=main_view#lastused">[' . $this->str['create'] . ']</a>';
130 } else {
131 $b .= '[' . $this->str['create'] . ']';
133 $b .= '</td><td class="button cell">';
134 /// The load button
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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&amp;time=' . time() . '&amp;postaction=main_view#lastused">[' . $this->str['load'] . ']</a>';
140 } else {
141 $b .= '[' . $this->str['load'] . ']';
143 $b .= '</td><td class="button cell">';
144 /// The edit button
145 if ($dbdir->path_exists &&
146 file_exists($key . '/install.xml') &&
147 is_readable($key . '/install.xml') &&
148 is_readable($key) &&
149 !empty($dbdir->xml_loaded)) {
150 $b .= '<a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['edit'] . ']</a>';
151 } else {
152 $b .= '[' . $this->str['edit'] . ']';
154 $b .= '</td><td class="button cell">';
155 /// The save button
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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&amp;time=' . time() . '&amp;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';
170 } else {
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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['revert'] . ']</a>';
182 } else {
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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '&amp;time=' . time() . '&amp;postaction=main_view#lastused">[' . $this->str['unload'] . ']</a>';
193 } else {
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&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $key)) . '">[' . $this->str['delete'] . ']</a>';
204 } else {
205 $b .= '[' . $this->str['delete'] . ']';
207 $b .= '</td>';
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&amp;file=' . urlencode(str_replace($CFG->dirroot, '', $key) . '/install.xml') . '">' . $elementtext . '</a></td>';
213 } else {
214 $elementtext = $elementtext . '</td>';
216 /// include the higlight
217 if ($hithis) {
218 $o .= '<tr class="highlight"><td class="directory cell"><a name="lastused" />' . $elementtext . $b . '</tr>';
219 } else {
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()) {
227 if ($hithis) {
228 $o .= '<tr class="highlight"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
229 } else {
230 $o .= '<tr class="r' . $row . '"><td class="error cell" colspan="8">' . implode (', ', $errors) . '</td></tr>';
236 $o .= '</table>';
238 /// Set the output
239 $this->output = $o;
242 /// Finally, return result
243 return $result;