Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / xmldb / actions / edit_statement / edit_statement.class.php
bloba3443d2c102dab0dec17b18a86952e38faea813f
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 provide the interface for all the edit statement actions
29 class edit_statement 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 'change' => 'xmldb',
42 'vieworiginal' => 'xmldb',
43 'viewedited' => 'xmldb',
44 'newsentence' => 'xmldb',
45 'sentences' => 'xmldb',
46 'edit' => 'xmldb',
47 'delete' => 'xmldb',
48 'duplicate' => 'xmldb',
49 'back' => 'xmldb'
50 ));
53 /**
54 * Invoke method, every class will have its own
55 * returns true/false on completion, setting both
56 * errormsg and output as necessary
58 function invoke() {
59 parent::invoke();
61 $result = true;
63 /// Set own core attributes
64 $this->does_generate = ACTION_GENERATE_HTML;
66 /// These are always here
67 global $CFG, $XMLDB;
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];
77 } else {
78 return false;
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">';
106 $o.= '<div>';
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>&nbsp;</td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
115 $o.= ' </table>';
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 .= '&nbsp;<a href="index.php?action=view_statement_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;statement=' . $statementparam . '">[' . $this->str['vieworiginal'] . ']</a>';
122 } else {
123 $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
125 /// The view edited XML button
126 if ($statement->hasChanged()) {
127 $b .= '&nbsp;<a href="index.php?action=view_statement_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;statement=' . $statementparam . '">[' . $this->str['viewedited'] . ']</a>';
128 } else {
129 $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
131 /// The new sentence button
132 $b .= '&nbsp;<a href="index.php?action=new_sentence&amp;postaction=edit_sentence&amp;statement=' . $statementparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newsentence'] . ']</a>';
133 /// The back to edit xml file button
134 $b .= '&nbsp;<a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
135 $b .= '</p>';
136 $o .= $b;
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">';
146 $row = 0;
147 foreach ($sentences as $key => $sentence) {
148 /// Prepend some SQL
149 if ($statement->getType() == XMLDB_STATEMENT_INSERT) {
150 $p = 'INSERT INTO ' . $statement->getTable() . ' ';
151 } else {
152 $p = 'UNSUPPORTED SENTENCE TYPE ';
154 /// Calculate buttons
155 $b = '</td><td class="button cell">';
156 /// The edit button
157 $b .= '<a href="index.php?action=edit_sentence&amp;sentence=' .$key . '&amp;statement=' . urlencode($statement->getName()) . '&amp;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&amp;postaction=edit_sentence&amp;basesentence=' . $key . '&amp;statement=' . urlencode($statement->getName()) . '&amp;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&amp;sentence=' . $key . '&amp;statement=' . urlencode($statement->getName()) . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
164 $b .= '</td>';
165 /// Print table row
166 $o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
167 $row = ($row + 1) % 2;
169 $o .= '</table>';
172 $this->output = $o;
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
180 return $result;