edit_table.class.php
来自「很棒的在线教学系统」· PHP 代码 · 共 312 行 · 第 1/2 页
PHP
312 行
<?php // $Id: edit_table.class.php,v 1.5 2007/10/10 05:25:28 nicolasconnault Exp $///////////////////////////////////////////////////////////////////////////// //// NOTICE OF COPYRIGHT //// //// Moodle - Modular Object-Oriented Dynamic Learning Environment //// http://moodle.com //// //// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //// //// This program is free software; you can redistribute it and/or modify //// it under the terms of the GNU General Public License as published by //// the Free Software Foundation; either version 2 of the License, or //// (at your option) any later version. //// //// This program is distributed in the hope that it will be useful, //// but WITHOUT ANY WARRANTY; without even the implied warranty of //// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //// GNU General Public License for more details: //// //// http://www.gnu.org/copyleft/gpl.html //// //////////////////////////////////////////////////////////////////////////////// This class will provide the interface for all the edit table actionsclass edit_table extends XMLDBAction { /** * Init method, every subclass will have its own */ function init() { parent::init(); /// Set own custom attributes /// 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 = '<form id="form" action="index.php" method="post">'; $o.= '<div>'; $o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />'; $o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />'; $o.= ' <input type="hidden" name ="action" value="edit_table_save" />'; $o.= ' <input type="hidden" name ="postaction" value="edit_table" />'; $o.= ' <table id="formelements" class="boxaligncenter">'; /// If the table is being used, we cannot rename it if ($structure->getTableUses($table->getName())) { $o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($table->getName()) . '" />' . s($table->getName()) .'</td></tr>'; } else { $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>'; } $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>'; $o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>'; $o.= ' </table>'; $o.= '</div></form>'; /// Calculate the buttons $b = ' <p class="centerpara buttons">'; /// The view original XML button if ($origstructure->getTable($tableparam)) { $b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '">[' . $this->str['vieworiginal'] . ']</a>'; } else { $b .= ' [' . $this->str['vieworiginal'] . ']'; } /// The view edited XML button if ($table->hasChanged()) { $b .= ' <a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '">[' . $this->str['viewedited'] . ']</a>'; } else { $b .= ' [' . $this->str['viewedited'] . ']'; } /// The new field button $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>'; /// The new key button $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>'; /// The new index button $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>'; /// The back to edit xml file button $b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>'; $b .= '</p>'; $b .= ' <p class="centerpara buttons">'; /// The view sql code button $b .= '<a href="index.php?action=view_table_sql&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>'; /// The view php code button $b .= ' <a href="index.php?action=view_table_php&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['viewphpcode'] . ']</a>'; $b .= '</p>'; $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();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?