| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: edit_xml_file.class.php,v 1.6 2007/10/10 05:25:26 nicolasconnault Exp $ 2 3 /////////////////////////////////////////////////////////////////////////// 4 // // 5 // NOTICE OF COPYRIGHT // 6 // // 7 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 8 // http://moodle.com // 9 // // 10 // Copyright (C) 1999 onwards 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 /////////////////////////////////////////////////////////////////////////// 26 27 /// This class will edit one loaded XML file 28 29 class edit_xml_file extends XMLDBAction { 30 31 /** 32 * Init method, every subclass will have its own 33 */ 34 function init() { 35 parent::init(); 36 37 /// Set own custom attributes 38 39 /// Get needed strings 40 $this->loadStrings(array( 41 'change' => 'xmldb', 42 'edit' => 'xmldb', 43 'up' => 'xmldb', 44 'down' => 'xmldb', 45 'delete' => 'xmldb', 46 'vieworiginal' => 'xmldb', 47 'viewedited' => 'xmldb', 48 'tables' => 'xmldb', 49 'statements' => 'xmldb', 50 'newtable' => 'xmldb', 51 'newtablefrommysql' => 'xmldb', 52 'newstatement' => 'xmldb', 53 'viewsqlcode' => 'xmldb', 54 'viewphpcode' => 'xmldb', 55 'reserved' => 'xmldb', 56 'backtomainview' => 'xmldb' 57 )); 58 } 59 60 /** 61 * Invoke method, every class will have its own 62 * returns true/false on completion, setting both 63 * errormsg and output as necessary 64 */ 65 function invoke() { 66 parent::invoke(); 67 68 $result = true; 69 70 /// Set own core attributes 71 //$this->does_generate = ACTION_NONE; 72 $this->does_generate = ACTION_GENERATE_HTML; 73 74 /// These are always here 75 global $CFG, $XMLDB; 76 77 /// Do the job, setting $result as needed 78 79 /// Get the dir containing the file 80 $dirpath = required_param('dir', PARAM_PATH); 81 $dirpath = $CFG->dirroot . stripslashes_safe($dirpath); 82 83 /// Get the correct dir 84 if (!empty($XMLDB->dbdirs)) { 85 $dbdir =& $XMLDB->dbdirs[$dirpath]; 86 if ($dbdir) { 87 /// Only if the directory exists and it has been loaded 88 if (!$dbdir->path_exists || !$dbdir->xml_loaded) { 89 return false; 90 } 91 /// Check if the in-memory object exists and create it 92 if (empty($XMLDB->editeddirs)) { 93 $XMLDB->editeddirs = array(); 94 } 95 /// Check if the dir exists and copy it from dbdirs 96 if (!isset($XMLDB->editeddirs[$dirpath])) { 97 $XMLDB->editeddirs[$dirpath] = unserialize(serialize($dbdir)); 98 } 99 /// Get it 100 $editeddir =& $XMLDB->editeddirs[$dirpath]; 101 $structure =& $editeddir->xml_file->getStructure(); 102 /// Add the main form 103 $o = '<form id="form" action="index.php" method="post">'; 104 $o .= '<div>'; 105 $o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />'; 106 $o.= ' <input type="hidden" name ="action" value="edit_xml_file_save" />'; 107 $o.= ' <input type="hidden" name ="postaction" value="edit_xml_file" />'; 108 $o.= ' <input type="hidden" name ="path" value="' . s($structure->getPath()) .'" />'; 109 $o.= ' <input type="hidden" name ="version" value="' . s($structure->getVersion()) .'" />'; 110 $o.= ' <table id="formelements" class="boxaligncenter">'; 111 $o.= ' <tr valign="top"><td>Path:</td><td>' . s($structure->getPath()) . '</td></tr>'; 112 $o.= ' <tr valign="top"><td>Version:</td><td>' . s($structure->getVersion()) . '</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">' . $structure->getComment() . '</textarea></td></tr>'; 114 $o.= ' <tr><td> </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 $b .= ' <a href="index.php?action=view_structure_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original">[' . $this->str['vieworiginal'] . ']</a>'; 121 /// The view edited XML button 122 if ($structure->hasChanged()) { 123 $b .= ' <a href="index.php?action=view_structure_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited">[' . $this->str['viewedited'] . ']</a>'; 124 } else { 125 $b .= ' [' . $this->str['viewedited'] . ']'; 126 } 127 /// The new table button 128 $b .= ' <a href="index.php?action=new_table&postaction=edit_table&table=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newtable'] . ']</a>'; 129 /// The new from MySQL button 130 if ($CFG->dbfamily == 'mysql') { 131 $b .= ' <a href="index.php?action=new_table_from_mysql&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newtablefrommysql'] . ']</a>'; 132 } else { 133 $b .= ' [' . $this->str['newtablefrommysql'] . ']'; 134 } 135 /// The new statement button 136 $b .= ' <a href="index.php?action=new_statement&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newstatement'] . ']</a>'; 137 /// The back to main menu button 138 $b .= ' <a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>'; 139 $b .= '</p>'; 140 $b .= ' <p class="centerpara buttons">'; 141 /// The view sql code button 142 $b .= '<a href="index.php?action=view_structure_sql&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>'; 143 /// The view php code button 144 $b .= ' <a href="index.php?action=view_structure_php&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>'; 145 $b .= '</p>'; 146 $o .= $b; 147 /// Join all the reserved words into one big array 148 /// Calculate list of available SQL generators 149 $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); 150 $reserved_words = array(); 151 foreach($plugins as $plugin) { 152 $classname = 'XMLDB' . $plugin; 153 $generator = new $classname(); 154 $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); 155 } 156 sort($reserved_words); 157 $reserved_words = array_unique($reserved_words); 158 /// Add the tables list 159 $tables =& $structure->getTables(); 160 if ($tables) { 161 $o .= '<h3 class="main">' . $this->str['tables'] . '</h3>'; 162 $o .= '<table id="listtables" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">'; 163 $row = 0; 164 foreach ($tables as $table) { 165 /// Calculate buttons 166 $b = '</td><td class="button cell">'; 167 /// The edit button 168 $b .= '<a href="index.php?action=edit_table&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>'; 169 $b .= '</td><td class="button cell">'; 170 /// The up button 171 if ($table->getPrevious()) { 172 $b .= '<a href="index.php?action=move_updown_table&direction=up&table=' . $table->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>'; 173 } else { 174 $b .= '[' . $this->str['up'] . ']'; 175 } 176 $b .= '</td><td class="button cell">'; 177 /// The down button 178 if ($table->getNext()) { 179 $b .= '<a href="index.php?action=move_updown_table&direction=down&table=' . $table->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>'; 180 } else { 181 $b .= '[' . $this->str['down'] . ']'; 182 } 183 $b .= '</td><td class="button cell">'; 184 /// The delete button (if we have more than one and it isn't used) 185 if (count($tables) > 1 && 186 !$structure->getTableUses($table->getName())) { 187 ///!$structure->getTableUses($table->getName())) { 188 $b .= '<a href="index.php?action=delete_table&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>'; 189 } else { 190 $b .= '[' . $this->str['delete'] . ']'; 191 } 192 /// Detect if the table name is a reserved word 193 if (in_array($table->getName(), $reserved_words)) { 194 $b .= ' <a href="index.php?action=view_reserved_words"><span class="error">' . $this->str['reserved'] . '</span></a>'; 195 } 196 $b .= '</td>'; 197 /// Print table row 198 $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&table=' . $table->getName() . '&select=edited">' . $table->getName() . '</a>' . $b . '</tr>'; 199 $row = ($row + 1) % 2; 200 } 201 $o .= '</table>'; 202 } 203 ///Add the statements list 204 $statements =& $structure->getStatements(); 205 if ($statements) { 206 $o .= '<h3 class="main">' . $this->str['statements'] . '</h3>'; 207 $o .= '<table id="liststatements" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">'; 208 $row = 0; 209 foreach ($statements as $statement) { 210 /// Calculate buttons 211 $b = '</td><td class="button cell">'; 212 /// The edit button 213 $b .= '<a href="index.php?action=edit_statement&statement=' . $statement->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>'; 214 $b .= '</td><td class="button cell">'; 215 /// The up button 216 if ($statement->getPrevious()) { 217 $b .= '<a href="index.php?action=move_updown_statement&direction=up&statement=' . $statement->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>'; 218 } else { 219 $b .= '[' . $this->str['up'] . ']'; 220 } 221 $b .= '</td><td class="button cell">'; 222 /// The down button 223 if ($statement->getNext()) { 224 $b .= '<a href="index.php?action=move_updown_statement&direction=down&statement=' . $statement->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>'; 225 } else { 226 $b .= '[' . $this->str['down'] . ']'; 227 } 228 $b .= '</td><td class="button cell">'; 229 /// The delete button 230 $b .= '<a href="index.php?action=delete_statement&statement=' . $statement->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>'; 231 $b .= '</td>'; 232 /// Print statement row 233 $o .= '<tr class="r' . $row . '"><td class="statement cell"><a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&statement=' . $statement->getName() . '&select=edited">' . $statement->getName() . '</a>' . $b . '</tr>'; 234 $row = ($row + 1) % 2; 235 } 236 $o .= '</table>'; 237 } 238 ///Add the back to main 239 240 241 $this->output = $o; 242 } 243 } 244 245 /// Launch postaction if exists (leave this unmodified) 246 if ($this->getPostAction() && $result) { 247 return $this->launch($this->getPostAction()); 248 } 249 250 return $result; 251 } 252 } 253 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |