PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/components/admin/extplorer/include/rename.php

https://code.google.com/p/mwenhanced/
PHP | 154 lines | 105 code | 14 blank | 35 comment | 12 complexity | 9bb0e8b19e28c9e45e0e6c2c9b68d918 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. // ensure this file is being included by a parent file
  3. if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
  4. /**
  5. * @version $Id: rename.php 96 2008-02-03 18:13:22Z soeren $
  6. * @package eXtplorer
  7. * @copyright soeren 2007
  8. * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
  9. * @author The The QuiX project (http://quixplorer.sourceforge.net)
  10. *
  11. * @license
  12. * The contents of this file are subject to the Mozilla Public License
  13. * Version 1.1 (the "License"); you may not use this file except in
  14. * compliance with the License. You may obtain a copy of the License at
  15. * http://www.mozilla.org/MPL/
  16. *
  17. * Software distributed under the License is distributed on an "AS IS"
  18. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  19. * License for the specific language governing rights and limitations
  20. * under the License.
  21. *
  22. * Alternatively, the contents of this file may be used under the terms
  23. * of the GNU General Public License Version 2 or later (the "GPL"), in
  24. * which case the provisions of the GPL are applicable instead of
  25. * those above. If you wish to allow use of your version of this file only
  26. * under the terms of the GPL and not to allow others to use
  27. * your version of this file under the MPL, indicate your decision by
  28. * deleting the provisions above and replace them with the notice and
  29. * other provisions required by the GPL. If you do not delete
  30. * the provisions above, a recipient may use your version of this file
  31. * under either the MPL or the GPL."
  32. *
  33. */
  34. /**
  35. * Allows to rename files and dirs
  36. *
  37. */
  38. class ext_Rename extends ext_Action {
  39. function execAction($dir, $item) { // rename directory or file
  40. if(($GLOBALS["permissions"]&01)!=01) {
  41. ext_Result::sendResult('rename', false, $GLOBALS["error_msg"]["accessfunc"]);
  42. }
  43. if(isset($GLOBALS['__POST']["confirm"]) && $GLOBALS['__POST']["confirm"]=="true") {
  44. $newitemname=$GLOBALS['__POST']["newitemname"];
  45. $newitemname=trim(basename(stripslashes($newitemname)));
  46. if($newitemname=='' ) {
  47. ext_Result::sendResult('rename', false, $GLOBALS["error_msg"]["miscnoname"]);
  48. }
  49. if( !ext_isFTPMode()) {
  50. $abs_old = get_abs_item($dir,$item);
  51. $abs_new = get_abs_item($dir,$newitemname);
  52. } else {
  53. $abs_old = get_item_info($dir,$item);
  54. $abs_new = get_item_info($dir,$newitemname);
  55. }
  56. if(@$GLOBALS['ext_File']->file_exists($abs_new)) {
  57. ext_Result::sendResult('rename', false, $newitemname.": ".$GLOBALS["error_msg"]["itemdoesexist"]);
  58. }
  59. $perms_old = $GLOBALS['ext_File']->fileperms( $abs_old );
  60. $ok=$GLOBALS['ext_File']->rename( get_abs_item($dir,$item), get_abs_item($dir,$newitemname) );
  61. if( ext_isFTPMode()) {
  62. $abs_new = get_item_info($dir,$newitemname);
  63. }
  64. $GLOBALS['ext_File']->chmod( $abs_new, $perms_old );
  65. if($ok===false || PEAR::isError($ok)) {
  66. ext_Result::sendResult('rename', false, 'Could not rename '.$dir.'/'.$item.' to '.$newitemname);
  67. }
  68. $msg = sprintf( $GLOBALS['messages']['success_rename_file'], $item, $newitemname );
  69. ext_Result::sendResult('rename', true, $msg );
  70. }
  71. $is_dir = get_is_dir(ext_isFTPMode() ? get_item_info($dir,$item) : get_abs_item($dir,$item));
  72. ?>
  73. <div style="width:auto;">
  74. <div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
  75. <div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
  76. <h3 style="margin-bottom:5px;"><?php echo $GLOBALS['messages']['rename_file'] ?></h3>
  77. <div id="adminForm">
  78. </div>
  79. </div></div></div>
  80. <div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
  81. </div>
  82. <script type="text/javascript">
  83. var simple = new Ext.form.Form({
  84. labelWidth: 75, // label settings here cascade unless overridden
  85. url:'<?php echo basename( $GLOBALS['script_name']) ?>'
  86. });
  87. simple.add(
  88. new Ext.form.TextField({
  89. fieldLabel: '<?php echo ext_Lang::msg( 'newname', true ) ?>',
  90. name: 'newitemname',
  91. value: '<?php echo str_replace("'", "\'", stripslashes($item) ) ?>',
  92. width:175,
  93. allowBlank:false
  94. })
  95. );
  96. simple.addButton('<?php echo ext_Lang::msg( 'btnsave', true ) ?>', function() {
  97. statusBarMessage( 'Please wait...', true );
  98. simple.submit({
  99. //reset: true,
  100. reset: false,
  101. success: function(form, action) {
  102. <?php
  103. if( $is_dir ) {
  104. ?>
  105. parentDir = dirTree.getSelectionModel().getSelectedNode().parentNode;
  106. parentDir.reload();
  107. parentDir.select();
  108. <?php
  109. } else {
  110. ?>
  111. datastore.reload();
  112. <?php
  113. }
  114. ?>
  115. statusBarMessage( action.result.message, false, true );
  116. dialog.destroy();
  117. },
  118. failure: function(form, action) {
  119. if( !action.result ) return;
  120. Ext.MessageBox.alert('Error!', action.result.error);
  121. statusBarMessage( action.result.error, false, false );
  122. },
  123. scope: simple,
  124. // add some vars to the request, similar to hidden fields
  125. params: {option: 'com_extplorer',
  126. action: 'rename',
  127. dir: '<?php echo stripslashes($dir) ?>',
  128. item: '<?php echo stripslashes($item) ?>',
  129. confirm: 'true'}
  130. });
  131. });
  132. simple.addButton('<?php echo ext_Lang::msg( 'btncancel', true ) ?>', function() { dialog.destroy(); } );
  133. simple.render('adminForm');
  134. </script>
  135. <?php
  136. }
  137. }
  138. ?>