| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: edit_table.class.php,v 1.5 2007/10/10 05:25:28 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 provide the interface for all the edit table actions 28 29 class edit_table 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 'vieworiginal' => 'xmldb', 43 'viewedited' => 'xmldb', 44 'viewsqlcode' => 'xmldb', 45 'viewphpcode' => 'xmldb', 46 'newfield' => 'xmldb', 47 'newkey' => 'xmldb', 48 'newindex' => 'xmldb', 49 'fields' => 'xmldb', 50 'keys' => 'xmldb', 51 'indexes' => 'xmldb', 52 'edit' => 'xmldb', 53 'up' => 'xmldb', 54 'down' => 'xmldb', 55 'delete' => 'xmldb', 56 'reserved' => 'xmldb', 57 'back' => 'xmldb' 58 )); 59 } 60 61 /** 62 * Invoke method, every class will have its own 63 * returns true/false on completion, setting both 64 * errormsg and output as necessary 65 */ 66 function invoke() { 67 parent::invoke(); 68 69 $result = true; 70 71 /// Set own core attributes 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 /// Get the dir containing the file 79 $dirpath = required_param('dir', PARAM_PATH); 80 $dirpath = $CFG->dirroot . stripslashes_safe($dirpath); 81 82 /// Get the correct dirs 83 if (!empty($XMLDB->dbdirs)) { 84 $dbdir =& $XMLDB->dbdirs[$dirpath]; 85 } else { 86 return false; 87 } 88 if (!empty($XMLDB->editeddirs)) { 89 $editeddir =& $XMLDB->editeddirs[$dirpath]; 90 $structure =& $editeddir->xml_file->getStructure(); 91 } 92 93 /// ADD YOUR CODE HERE 94 $tableparam = required_param('table', PARAM_CLEAN); 95 if (!$table =& $structure->getTable($tableparam)) { 96 /// Arriving here from a name change, looking for the new table name 97 $tableparam = required_param('name', PARAM_CLEAN); 98 $table =& $structure->getTable($tableparam); 99 } 100 101 $dbdir =& $XMLDB->dbdirs[$dirpath]; 102 $origstructure =& $dbdir->xml_file->getStructure(); 103 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 ="table" value="' . $tableparam .'" />'; 109 $o.= ' <input type="hidden" name ="action" value="edit_table_save" />'; 110 $o.= ' <input type="hidden" name ="postaction" value="edit_table" />'; 111 $o.= ' <table id="formelements" class="boxaligncenter">'; 112 /// If the table is being used, we cannot rename it 113 if ($structure->getTableUses($table->getName())) { 114 $o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($table->getName()) . '" />' . s($table->getName()) .'</td></tr>'; 115 } else { 116 $o.= ' <tr valign="top"><td><label for="name" accesskey="p">Name:</label></td><td><input name="name" type="text" size="28" maxlength="28" id="name" value="' . s($table->getName()) . '" /></td></tr>'; 117 } 118 $o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . s($table->getComment()) . '</textarea></td></tr>'; 119 $o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>'; 120 $o.= ' </table>'; 121 $o.= '</div></form>'; 122 /// Calculate the buttons 123 $b = ' <p class="centerpara buttons">'; 124 /// The view original XML button 125 if ($origstructure->getTable($tableparam)) { 126 $b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '">[' . $this->str['vieworiginal'] . ']</a>'; 127 } else { 128 $b .= ' [' . $this->str['vieworiginal'] . ']'; 129 } 130 /// The view edited XML button 131 if ($table->hasChanged()) { 132 $b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '">[' . $this->str['viewedited'] . ']</a>'; 133 } else { 134 $b .= ' [' . $this->str['viewedited'] . ']'; 135 } 136 /// The new field button 137 $b .= ' <a href="index.php?action=new_field&postaction=edit_field&table=' . $tableparam . '&field=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newfield'] . ']</a>'; 138 /// The new key button 139 $b .= ' <a href="index.php?action=new_key&postaction=edit_key&table=' . $tableparam . '&key=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newkey'] . ']</a>'; 140 /// The new index button 141 $b .= ' <a href="index.php?action=new_index&postaction=edit_index&table=' . $tableparam . '&index=changeme&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newindex'] . ']</a>'; 142 /// The back to edit xml file button 143 $b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>'; 144 $b .= '</p>'; 145 $b .= ' <p class="centerpara buttons">'; 146 /// The view sql code button 147 $b .= '<a href="index.php?action=view_table_sql&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>'; 148 /// The view php code button 149 $b .= ' <a href="index.php?action=view_table_php&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>'; 150 $b .= '</p>'; 151 $o .= $b; 152 153 /// Join all the reserved words into one big array 154 /// Calculate list of available SQL generators 155 $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); 156 $reserved_words = array(); 157 foreach($plugins as $plugin) { 158 $classname = 'XMLDB' . $plugin; 159 $generator = new $classname(); 160 $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); 161 } 162 sort($reserved_words); 163 $reserved_words = array_unique($reserved_words); 164 165 /// Delete any 'changeme' field/key/index 166 $table->deleteField('changeme'); 167 $table->deleteKey('changeme'); 168 $table->deleteIndex('changeme'); 169 170 /// Add the fields list 171 $fields =& $table->getFields(); 172 if (!empty($fields)) { 173 $o .= '<h3 class="main">' . $this->str['fields'] . '</h3>'; 174 $o .= '<table id="listfields" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">'; 175 $row = 0; 176 foreach ($fields as $field) { 177 /// Calculate buttons 178 $b = '</td><td class="button cell">'; 179 /// The edit button (if the field has no uses) 180 if (!$structure->getFieldUses($table->getName(), $field->getName())) { 181 $b .= '<a href="index.php?action=edit_field&field=' .$field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>'; 182 } else { 183 $b .= '[' . $this->str['edit'] . ']'; 184 } 185 $b .= '</td><td class="button cell">'; 186 /// The up button 187 if ($field->getPrevious()) { 188 $b .= '<a href="index.php?action=move_updown_field&direction=up&field=' . $field->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>'; 189 } else { 190 $b .= '[' . $this->str['up'] . ']'; 191 } 192 $b .= '</td><td class="button cell">'; 193 /// The down button 194 if ($field->getNext()) { 195 $b .= '<a href="index.php?action=move_updown_field&direction=down&field=' . $field->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>'; 196 } else { 197 $b .= '[' . $this->str['down'] . ']'; 198 } 199 $b .= '</td><td class="button cell">'; 200 /// The delete button (if we have more than one and it isn't used 201 if (count($fields) > 1 && 202 !$structure->getFieldUses($table->getName(), $field->getName())) { 203 $b .= '<a href="index.php?action=delete_field&field=' . $field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>'; 204 } else { 205 $b .= '[' . $this->str['delete'] . ']'; 206 } 207 /// Detect if the table name is a reserved word 208 if (in_array($field->getName(), $reserved_words)) { 209 $b .= ' <a href="index.php?action=view_reserved_words"><span class="error">' . $this->str['reserved'] . '</span></a>'; 210 } 211 /// The readable info 212 $r = '</td><td class="readableinfo cell">' . $field->readableInfo() . '</td>'; 213 /// Print table row 214 $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&field=' . $field->getName() . '&table=' . $table->getName() . '&select=edited">' . $field->getName() . '</a>' . $b . $r . '</tr>'; 215 $row = ($row + 1) % 2; 216 } 217 $o .= '</table>'; 218 } 219 /// Add the keys list 220 $keys =& $table->getKeys(); 221 if (!empty($keys)) { 222 $o .= '<h3 class="main">' . $this->str['keys'] . '</h3>'; 223 $o .= '<table id="listkeys" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">'; 224 $row = 0; 225 foreach ($keys as $key) { 226 /// Calculate buttons 227 $b = '</td><td class="button cell">'; 228 /// The edit button (if the key hasn't uses) 229 if (!$structure->getKeyUses($table->getName(), $key->getName())) { 230 $b .= '<a href="index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>'; 231 } else { 232 $b .= '[' . $this->str['edit'] . ']'; 233 } 234 $b .= '</td><td class="button cell">'; 235 /// The up button 236 if ($key->getPrevious()) { 237 $b .= '<a href="index.php?action=move_updown_key&direction=up&key=' . $key->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>'; 238 } else { 239 $b .= '[' . $this->str['up'] . ']'; 240 } 241 $b .= '</td><td class="button cell">'; 242 /// The down button 243 if ($key->getNext()) { 244 $b .= '<a href="index.php?action=move_updown_key&direction=down&key=' . $key->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>'; 245 } else { 246 $b .= '[' . $this->str['down'] . ']'; 247 } 248 $b .= '</td><td class="button cell">'; 249 /// The delete button (if the key hasn't uses) 250 if (!$structure->getKeyUses($table->getName(), $key->getName())) { 251 $b .= '<a href="index.php?action=delete_key&key=' . $key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>'; 252 } else { 253 $b .= '[' . $this->str['delete'] . ']'; 254 } 255 /// The readable info 256 $r = '</td><td class="readableinfo cell">' . $key->readableInfo() . '</td>'; 257 /// Print table row 258 $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&key=' . $key->getName() . '&table=' . $table->getName() . '&select=edited">' . $key->getName() . '</a>' . $b . $r .'</tr>'; 259 $row = ($row + 1) % 2; 260 } 261 $o .= '</table>'; 262 } 263 /// Add the indexes list 264 $indexes =& $table->getIndexes(); 265 if (!empty($indexes)) { 266 $o .= '<h3 class="main">' . $this->str['indexes'] . '</h3>'; 267 $o .= '<table id="listindexes" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">'; 268 $row = 0; 269 foreach ($indexes as $index) { 270 /// Calculate buttons 271 $b = '</td><td class="button cell">'; 272 /// The edit button 273 $b .= '<a href="index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>'; 274 $b .= '</td><td class="button cell">'; 275 /// The up button 276 if ($index->getPrevious()) { 277 $b .= '<a href="index.php?action=move_updown_index&direction=up&index=' . $index->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>'; 278 } else { 279 $b .= '[' . $this->str['up'] . ']'; 280 } 281 $b .= '</td><td class="button cell">'; 282 /// The down button 283 if ($index->getNext()) { 284 $b .= '<a href="index.php?action=move_updown_index&direction=down&index=' . $index->getName() . '&table=' . $table->getName() . '&postaction=edit_table' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>'; 285 } else { 286 $b .= '[' . $this->str['down'] . ']'; 287 } 288 $b .= '</td><td class="button cell">'; 289 /// The delete button 290 $b .= '<a href="index.php?action=delete_index&index=' . $index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>'; 291 /// The readable info 292 $r = '</td><td class="readableinfo cell">' . $index->readableInfo() . '</td>'; 293 /// Print table row 294 $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&index=' . $index->getName() . '&table=' . $table->getName() . '&select=edited">' . $index->getName() . '</a>' . $b . $r .'</tr>'; 295 $row = ($row + 1) % 2; 296 } 297 $o .= '</table>'; 298 } 299 300 $this->output = $o; 301 302 /// Launch postaction if exists (leave this here!) 303 if ($this->getPostAction() && $result) { 304 return $this->launch($this->getPostAction()); 305 } 306 307 /// Return ok if arrived here 308 return $result; 309 } 310 } 311 ?>
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 |