sesskey_protected = false; // This action doesn't need sesskey protection /// Get needed strings $this->loadStrings(array( 'change' => 'xmldb', 'vieworiginal' => 'xmldb', 'viewedited' => '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 /// Fetch request data $statementparam = required_param('statement', PARAM_CLEAN); $sentenceparam = optional_param('sentence', NULL, PARAM_CLEAN); if (!$statement =& $structure->getStatement($statementparam)) { $this->errormsg = 'Wrong statement specified: ' . $statementparam; return false; } $sentences =& $statement->getSentences(); /// If no sentence has been specified, edit the last one if ($sentenceparam === NULL) { end($sentences); $sentenceparam = key($sentences); } if (!$sentence =& $sentences[$sentenceparam]) { $this->errormsg = 'Wrong Sentence: ' . $sentenceparam; return false; } $dbdir =& $XMLDB->dbdirs[$dirpath]; $origstructure =& $dbdir->xml_file->getStructure(); /// Based in the type of statement, print different forms if ($statement->getType() != XMLDB_STATEMENT_INSERT) { /// Only INSERT is allowed!! $this->errormsg = 'Wrong Statement Type. Only INSERT allowed'; return false; } else { /// Prepare INSERT sentence $fields = $statement->getFieldsFromInsertSentence($sentence); $values = $statement->getValuesFromInsertSentence($sentence); /// Add the main form $o = '
'; $o.= '
'; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; $o.= ' '; /// The fields box $o.= ' '; $o.= ' '; /// The values box $o.= ' '; $o.= ' '; /// The submit button $o.= ' '; $o.= '
INSERT INTO ' . s($statement->getTable()) . '
VALUES
'; $o.= '
'; /// Calculate the buttons $b = '

'; /// The back to edit statement button $b .= ' [' . $this->str['back'] . ']'; $b .= '

'; $o .= $b; $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; } } ?>