Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / xmldb / actions / edit_sentence / edit_sentence.class.php
blobe997cb9fa71134ccf405ef11dcd93342efb3e905
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 sentence actions
29 class edit_sentence 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 'back' => 'xmldb'
45 ));
48 /**
49 * Invoke method, every class will have its own
50 * returns true/false on completion, setting both
51 * errormsg and output as necessary
53 function invoke() {
54 parent::invoke();
56 $result = true;
58 /// Set own core attributes
59 $this->does_generate = ACTION_GENERATE_HTML;
61 /// These are always here
62 global $CFG, $XMLDB;
64 /// Do the job, setting result as needed
65 /// Get the dir containing the file
66 $dirpath = required_param('dir', PARAM_PATH);
67 $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
69 /// Get the correct dirs
70 if (!empty($XMLDB->dbdirs)) {
71 $dbdir =& $XMLDB->dbdirs[$dirpath];
72 } else {
73 return false;
75 if (!empty($XMLDB->editeddirs)) {
76 $editeddir =& $XMLDB->editeddirs[$dirpath];
77 $structure =& $editeddir->xml_file->getStructure();
80 /// ADD YOUR CODE HERE
82 /// Fetch request data
83 $statementparam = required_param('statement', PARAM_CLEAN);
84 $sentenceparam = optional_param('sentence', NULL, PARAM_CLEAN);
86 if (!$statement =& $structure->getStatement($statementparam)) {
87 $this->errormsg = 'Wrong statement specified: ' . $statementparam;
88 return false;
90 $sentences =& $statement->getSentences();
92 /// If no sentence has been specified, edit the last one
93 if ($sentenceparam === NULL) {
94 end($sentences);
95 $sentenceparam = key($sentences);
98 if (!$sentence =& $sentences[$sentenceparam]) {
99 $this->errormsg = 'Wrong Sentence: ' . $sentenceparam;
100 return false;
103 $dbdir =& $XMLDB->dbdirs[$dirpath];
104 $origstructure =& $dbdir->xml_file->getStructure();
106 /// Based in the type of statement, print different forms
107 if ($statement->getType() != XMLDB_STATEMENT_INSERT) {
108 /// Only INSERT is allowed!!
109 $this->errormsg = 'Wrong Statement Type. Only INSERT allowed';
110 return false;
111 } else {
112 /// Prepare INSERT sentence
113 $fields = $statement->getFieldsFromInsertSentence($sentence);
114 $values = $statement->getValuesFromInsertSentence($sentence);
116 /// Add the main form
117 $o = '<form id="form" action="index.php" method="post">';
118 $o.= '<div>';
119 $o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
120 $o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
121 $o.= ' <input type="hidden" name ="sentence" value="' . $sentenceparam .'" />';
122 $o.= ' <input type="hidden" name ="action" value="edit_sentence_save" />';
123 $o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
124 $o.= ' <table id="formelements" class="boxaligncenter">';
125 /// The fields box
126 $o.= ' <tr><td>INSERT INTO ' . s($statement->getTable()) . '</td></tr>';
127 $o.= ' <tr><td><textarea name="fields" rows="2" cols="70" id="fields">' . s(implode(', ', $fields)) . '</textarea></td></tr>';
128 /// The values box
129 $o.= ' <tr><td>VALUES</td></tr>';
130 $o.= ' <tr><td><textarea name="values" rows="2" cols="70" id="values">' . s(implode(', ', $values)) . '</textarea></td></tr>';
131 /// The submit button
132 $o.= ' <tr valign="top"><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
133 $o.= ' </table>';
134 $o.= '</div></form>';
135 /// Calculate the buttons
136 $b = ' <p class="centerpara buttons">';
137 /// The back to edit statement button
138 $b .= '&nbsp;<a href="index.php?action=edit_statement&amp;statement=' . urlencode($statementparam) . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
139 $b .= '</p>';
140 $o .= $b;
142 $this->output = $o;
145 /// Launch postaction if exists (leave this here!)
146 if ($this->getPostAction() && $result) {
147 return $this->launch($this->getPostAction());
150 /// Return ok if arrived here
151 return $result;