PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/xmldb/actions/edit_index/edit_index.class.php

https://github.com/nadavkav/Moodle-RTL--Shenkar-Translation-Team-
PHP | 162 lines | 88 code | 19 blank | 55 comment | 12 complexity | 53801e8306465ad56b6d7edd2c7a7e51 MD5 | raw file
  1. <?php // $Id: edit_index.class.php,v 1.8.2.2 2009/11/20 14:26:24 stronk7 Exp $
  2. ///////////////////////////////////////////////////////////////////////////
  3. // //
  4. // NOTICE OF COPYRIGHT //
  5. // //
  6. // Moodle - Modular Object-Oriented Dynamic Learning Environment //
  7. // http://moodle.com //
  8. // //
  9. // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
  10. // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
  11. // //
  12. // This program is free software; you can redistribute it and/or modify //
  13. // it under the terms of the GNU General Public License as published by //
  14. // the Free Software Foundation; either version 2 of the License, or //
  15. // (at your option) any later version. //
  16. // //
  17. // This program is distributed in the hope that it will be useful, //
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  20. // GNU General Public License for more details: //
  21. // //
  22. // http://www.gnu.org/copyleft/gpl.html //
  23. // //
  24. ///////////////////////////////////////////////////////////////////////////
  25. /// This class will provide the interface for all the edit index actions
  26. class edit_index extends XMLDBAction {
  27. /**
  28. * Init method, every subclass will have its own
  29. */
  30. function init() {
  31. parent::init();
  32. /// Set own custom attributes
  33. $this->sesskey_protected = false; // This action doesn't need sesskey protection
  34. /// Get needed strings
  35. $this->loadStrings(array(
  36. 'change' => 'xmldb',
  37. 'vieworiginal' => 'xmldb',
  38. 'viewedited' => 'xmldb',
  39. 'yes' => '',
  40. 'no' => '',
  41. 'back' => 'xmldb'
  42. ));
  43. }
  44. /**
  45. * Invoke method, every class will have its own
  46. * returns true/false on completion, setting both
  47. * errormsg and output as necessary
  48. */
  49. function invoke() {
  50. parent::invoke();
  51. $result = true;
  52. /// Set own core attributes
  53. $this->does_generate = ACTION_GENERATE_HTML;
  54. /// These are always here
  55. global $CFG, $XMLDB;
  56. /// Do the job, setting result as needed
  57. /// Get the dir containing the file
  58. $dirpath = required_param('dir', PARAM_PATH);
  59. $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
  60. /// Get the correct dirs
  61. if (!empty($XMLDB->dbdirs)) {
  62. $dbdir =& $XMLDB->dbdirs[$dirpath];
  63. } else {
  64. return false;
  65. }
  66. if (!empty($XMLDB->editeddirs)) {
  67. $editeddir =& $XMLDB->editeddirs[$dirpath];
  68. $structure =& $editeddir->xml_file->getStructure();
  69. }
  70. /// ADD YOUR CODE HERE
  71. /// Fetch request data
  72. $tableparam = required_param('table', PARAM_CLEAN);
  73. if (!$table =& $structure->getTable($tableparam)) {
  74. $this->errormsg = 'Wrong table specified: ' . $tableparam;
  75. return false;
  76. }
  77. $indexparam = required_param('index', PARAM_CLEAN);
  78. if (!$index =& $table->getIndex($indexparam)) {
  79. /// Arriving here from a name change, looking for the new key name
  80. $indexparam = required_param('name', PARAM_CLEAN);
  81. $index =& $table->getIndex($indexparam);
  82. }
  83. $dbdir =& $XMLDB->dbdirs[$dirpath];
  84. $origstructure =& $dbdir->xml_file->getStructure();
  85. /// Add the main form
  86. $o = '<form id="form" action="index.php" method="post">';
  87. $o.= '<div>';
  88. $o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
  89. $o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
  90. $o.= ' <input type="hidden" name ="index" value="' . $indexparam .'" />';
  91. $o.= ' <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
  92. $o.= ' <input type="hidden" name ="action" value="edit_index_save" />';
  93. $o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
  94. $o.= ' <table id="formelements" class="boxaligncenter">';
  95. /// XMLDB index name
  96. /// If the index has dependencies, we cannot change its name
  97. $disabled = '';
  98. if ($structure->getIndexUses($table->getName(), $index->getName())) {
  99. $disabled = ' disabled="disabled " ';
  100. }
  101. $o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" id="name"' . $disabled . ' value="' . s($index->getName()) . '" /></td></tr>';
  102. /// XMLDB key comment
  103. $o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($index->getComment()) . '</textarea></td></tr>';
  104. /// XMLDBIndex Type
  105. $typeoptions = array (0 => 'not unique',
  106. 1 => 'unique');
  107. $o.= ' <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
  108. $o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'unique', $index->getUnique(), '', '', '', true) . '</td></tr>';
  109. /// XMLDBIndex Fields
  110. $o.= ' <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
  111. $o.= ' <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
  112. /// Change button
  113. $o.= ' <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
  114. $o.= ' </table>';
  115. $o.= '</div></form>';
  116. /// Calculate the buttons
  117. $b = ' <p class="centerpara buttons">';
  118. /// The view original XML button
  119. if ($table->getIndex($indexparam)) {
  120. $b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['vieworiginal'] . ']</a>';
  121. } else {
  122. $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
  123. }
  124. /// The view edited XML button
  125. if ($index->hasChanged()) {
  126. $b .= '&nbsp;<a href="index.php?action=view_index_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;index=' . $indexparam . '">[' . $this->str['viewedited'] . ']</a>';
  127. } else {
  128. $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
  129. }
  130. /// The back to edit table button
  131. $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
  132. $b .= '</p>';
  133. $o .= $b;
  134. $this->output = $o;
  135. /// Launch postaction if exists (leave this here!)
  136. if ($this->getPostAction() && $result) {
  137. return $this->launch($this->getPostAction());
  138. }
  139. /// Return ok if arrived here
  140. return $result;
  141. }
  142. }
  143. ?>