sesskey_protected = false; // This action doesn't need sesskey protection /// Get needed strings $this->loadStrings(array( 'change' => 'xmldb', 'vieworiginal' => 'xmldb', 'viewedited' => 'xmldb', 'viewsqlcode' => 'xmldb', 'viewphpcode' => 'xmldb', 'newfield' => 'xmldb', 'newkey' => 'xmldb', 'newindex' => 'xmldb', 'fields' => 'xmldb', 'keys' => 'xmldb', 'indexes' => 'xmldb', 'edit' => 'xmldb', 'up' => 'xmldb', 'down' => 'xmldb', 'delete' => 'xmldb', 'reserved' => 'xmldb', 'back' => 'xmldb' )); } /** * Invoke method, every class will have its own * returns true/false on completion, setting both * errormsg and output as necessary */ function invoke() { parent::invoke(); $result = true; /// Set own core attributes $this->does_generate = ACTION_GENERATE_HTML; /// These are always here global $CFG, $XMLDB; /// Do the job, setting result as needed /// Get the dir containing the file $dirpath = required_param('dir', PARAM_PATH); $dirpath = $CFG->dirroot . stripslashes_safe($dirpath); /// Get the correct dirs if (!empty($XMLDB->dbdirs)) { $dbdir =& $XMLDB->dbdirs[$dirpath]; } else { return false; } if (!empty($XMLDB->editeddirs)) { $editeddir =& $XMLDB->editeddirs[$dirpath]; $structure =& $editeddir->xml_file->getStructure(); } /// ADD YOUR CODE HERE $tableparam = required_param('table', PARAM_CLEAN); if (!$table =& $structure->getTable($tableparam)) { /// Arriving here from a name change, looking for the new table name $tableparam = required_param('name', PARAM_CLEAN); $table =& $structure->getTable($tableparam); } $dbdir =& $XMLDB->dbdirs[$dirpath]; $origstructure =& $dbdir->xml_file->getStructure(); /// Add the main form $o = '
'; $o.= '
'; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; /// If the table is being used, we cannot rename it if ($structure->getTableUses($table->getName())) { $o.= ' '; } else { $o.= ' '; } $o.= ' '; $o.= ' '; $o.= '
Name:' . s($table->getName()) .'
 
'; $o.= '
'; /// Calculate the buttons $b = '

'; /// The view original XML button if ($origstructure->getTable($tableparam)) { $b .= ' [' . $this->str['vieworiginal'] . ']'; } else { $b .= ' [' . $this->str['vieworiginal'] . ']'; } /// The view edited XML button if ($table->hasChanged()) { $b .= ' [' . $this->str['viewedited'] . ']'; } else { $b .= ' [' . $this->str['viewedited'] . ']'; } /// The new field button $b .= ' [' . $this->str['newfield'] . ']'; /// The new key button $b .= ' [' . $this->str['newkey'] . ']'; /// The new index button $b .= ' [' . $this->str['newindex'] . ']'; /// The back to edit xml file button $b .= ' [' . $this->str['back'] . ']'; $b .= '

'; $b .= '

'; /// The view sql code button $b .= '[' .$this->str['viewsqlcode'] . ']'; /// The view php code button $b .= ' [' . $this->str['viewphpcode'] . ']'; $b .= '

'; $o .= $b; /// Join all the reserved words into one big array /// Calculate list of available SQL generators $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); $reserved_words = array(); foreach($plugins as $plugin) { $classname = 'XMLDB' . $plugin; $generator = new $classname(); $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); } sort($reserved_words); $reserved_words = array_unique($reserved_words); /// Delete any 'changeme' field/key/index $table->deleteField('changeme'); $table->deleteKey('changeme'); $table->deleteIndex('changeme'); /// Add the fields list $fields =& $table->getFields(); if (!empty($fields)) { $o .= '

' . $this->str['fields'] . '

'; $o .= ''; $row = 0; foreach ($fields as $field) { /// Calculate buttons $b = ''; /// Print table row $o .= ''; $row = ($row + 1) % 2; } $o .= '
'; /// The edit button (if the field has no uses) if (!$structure->getFieldUses($table->getName(), $field->getName())) { $b .= '[' . $this->str['edit'] . ']'; } else { $b .= '[' . $this->str['edit'] . ']'; } $b .= ''; /// The up button if ($field->getPrevious()) { $b .= '[' . $this->str['up'] . ']'; } else { $b .= '[' . $this->str['up'] . ']'; } $b .= ''; /// The down button if ($field->getNext()) { $b .= '[' . $this->str['down'] . ']'; } else { $b .= '[' . $this->str['down'] . ']'; } $b .= ''; /// The delete button (if we have more than one and it isn't used if (count($fields) > 1 && !$structure->getFieldUses($table->getName(), $field->getName())) { $b .= '[' . $this->str['delete'] . ']'; } else { $b .= '[' . $this->str['delete'] . ']'; } /// Detect if the table name is a reserved word if (in_array($field->getName(), $reserved_words)) { $b .= ' ' . $this->str['reserved'] . ''; } /// The readable info $r = '' . $field->readableInfo() . '
' . $field->getName() . '' . $b . $r . '
'; } /// Add the keys list $keys =& $table->getKeys(); if (!empty($keys)) { $o .= '

' . $this->str['keys'] . '

'; $o .= ''; $row = 0; foreach ($keys as $key) { /// Calculate buttons $b = ''; /// Print table row $o .= ''; $row = ($row + 1) % 2; } $o .= '
'; /// The edit button (if the key hasn't uses) if (!$structure->getKeyUses($table->getName(), $key->getName())) { $b .= '[' . $this->str['edit'] . ']'; } else { $b .= '[' . $this->str['edit'] . ']'; } $b .= ''; /// The up button if ($key->getPrevious()) { $b .= '[' . $this->str['up'] . ']'; } else { $b .= '[' . $this->str['up'] . ']'; } $b .= ''; /// The down button if ($key->getNext()) { $b .= '[' . $this->str['down'] . ']'; } else { $b .= '[' . $this->str['down'] . ']'; } $b .= ''; /// The delete button (if the key hasn't uses) if (!$structure->getKeyUses($table->getName(), $key->getName())) { $b .= '[' . $this->str['delete'] . ']'; } else { $b .= '[' . $this->str['delete'] . ']'; } /// The readable info $r = '' . $key->readableInfo() . '
' . $key->getName() . '' . $b . $r .'
'; } /// Add the indexes list $indexes =& $table->getIndexes(); if (!empty($indexes)) { $o .= '

' . $this->str['indexes'] . '

'; $o .= ''; $row = 0; foreach ($indexes as $index) { /// Calculate buttons $b = ''; /// Print table row $o .= ''; $row = ($row + 1) % 2; } $o .= '
'; /// The edit button $b .= '[' . $this->str['edit'] . ']'; $b .= ''; /// The up button if ($index->getPrevious()) { $b .= '[' . $this->str['up'] . ']'; } else { $b .= '[' . $this->str['up'] . ']'; } $b .= ''; /// The down button if ($index->getNext()) { $b .= '[' . $this->str['down'] . ']'; } else { $b .= '[' . $this->str['down'] . ']'; } $b .= ''; /// The delete button $b .= '[' . $this->str['delete'] . ']'; /// The readable info $r = '' . $index->readableInfo() . '
' . $index->getName() . '' . $b . $r .'
'; } $this->output = $o; /// Launch postaction if exists (leave this here!) if ($this->getPostAction() && $result) { return $this->launch($this->getPostAction()); } /// Return ok if arrived here return $result; } } ?>