PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website các món ăn và ẩm thực php/bbqvietnam.com/administrator/components/com_ninjaxplorer/include/fun_copy_move.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 278 lines | 175 code | 35 blank | 68 comment | 49 complexity | fc405f839fc3f4d3e2f06c6d52bc3152 MD5 | raw file
  1. <?php
  2. /** ensure this file is being included by a parent file */
  3. defined('_JEXEC') or die('Restricted access');
  4. /*------------------------------------------------------------------------------
  5. The contents of this file are subject to the Mozilla Public License
  6. Version 1.1 (the "License"); you may not use this file except in
  7. compliance with the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS"
  10. basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  11. License for the specific language governing rights and limitations
  12. under the License.
  13. The Original Code is fun_copy_move.php, released on 2003-03-31.
  14. The Initial Developer of the Original Code is The QuiX project.
  15. Alternatively, the contents of this file may be used under the terms
  16. of the GNU General Public License Version 2 or later (the "GPL"), in
  17. which case the provisions of the GPL are applicable instead of
  18. those above. If you wish to allow use of your version of this file only
  19. under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision by
  21. deleting the provisions above and replace them with the notice and
  22. other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this file
  24. under either the MPL or the GPL."
  25. ------------------------------------------------------------------------------*/
  26. /*------------------------------------------------------------------------------
  27. Author: The QuiX project
  28. quix@free.fr
  29. http://www.quix.tk
  30. http://quixplorer.sourceforge.net
  31. Comment:
  32. QuiXplorer Version 2.3
  33. File/Directory Copy & Move Functions
  34. Have Fun...
  35. ------------------------------------------------------------------------------*/
  36. //------------------------------------------------------------------------------
  37. function dir_list($dir) { // make list of directories
  38. // this list is used to copy/move items to a specific location
  39. $dir_list = Array();
  40. $handle = @$GLOBALS['nx_File']->opendir(get_abs_dir($dir));
  41. if($handle===false) return; // unable to open dir
  42. while(($new_item=$GLOBALS['nx_File']->readdir($handle))!==false) {
  43. //if(!@file_exists(get_abs_item($dir, $new_item))) continue;
  44. if(!get_show_item($dir, $new_item)) continue;
  45. if( nx_isFTPMode() ) {
  46. $new_item_name = $new_item['name'];
  47. }
  48. else {
  49. $new_item_name = $new_item;
  50. $new_item = get_abs_item( $dir, $new_item );
  51. }
  52. if(!get_is_dir( $new_item )) continue;
  53. $dir_list[$new_item_name] = $new_item;
  54. }
  55. // sort
  56. if(is_array($dir_list)) ksort($dir_list);
  57. return $dir_list;
  58. }
  59. //------------------------------------------------------------------------------
  60. function dir_print($dir_list, $new_dir) { // print list of directories
  61. // this list is used to copy/move items to a specific location
  62. // Link to Parent Directory
  63. $dir_up = dirname($new_dir);
  64. if($dir_up==".") $dir_up = "";
  65. echo "<tr><td><a href=\"javascript:NewDir('".$dir_up;
  66. echo "');\"><img border=\"0\" width=\"22\" height=\"22\"";
  67. echo " align=\"absmiddle\" src=\""._QUIXPLORER_URL."/images/_up.png\" alt=\"\">&nbsp;..</a></td></tr>\n";
  68. // Print List Of Target Directories
  69. if(!is_array($dir_list)) return;
  70. while(list($new_item,$info) = each($dir_list)) {
  71. if( is_array($info)) {
  72. $new_item = $info['name'];
  73. }
  74. $s_item=$new_item; if(strlen($s_item)>40) $s_item=substr($s_item,0,37)."...";
  75. echo "<tr><td><a href=\"javascript:NewDir('".get_rel_item($new_dir,$new_item).
  76. "');\"><img border=\"0\" width=\"22\" height=\"22\" align=\"absmiddle\" ".
  77. "src=\""._QUIXPLORER_URL."/images/dir.png\" alt=\"\">&nbsp;".$s_item."</a></td></tr>\n";
  78. }
  79. }
  80. //------------------------------------------------------------------------------
  81. function copy_move_items($dir) { // copy/move file/dir
  82. if(($GLOBALS["permissions"]&01)!=01) show_error($GLOBALS["error_msg"]["accessfunc"]);
  83. $action = stripslashes(JRequest::getCmd('action'));
  84. if( $action == "post" ) {
  85. $action = JRequest::getCmd( "do_action" );
  86. } elseif( empty( $action ))
  87. $action = "list";
  88. // Vars
  89. $first = $GLOBALS['__POST']["first"];
  90. if($first=="y") $new_dir=$dir;
  91. else $new_dir = stripslashes($GLOBALS['__POST']["new_dir"]);
  92. if($new_dir==".") $new_dir="";
  93. $cnt=count($GLOBALS['__POST']["selitems"]);
  94. // Copy or Move?
  95. if($action!="move") {
  96. $images="images/__copy.gif";
  97. } else {
  98. $images="images/__cut.gif";
  99. }
  100. // Get New Location & Names
  101. if(!isset($GLOBALS['__POST']["confirm"]) || $GLOBALS['__POST']["confirm"]!="true") {
  102. show_header(($action!="move"?
  103. $GLOBALS["messages"]["actcopyitems"]:
  104. $GLOBALS["messages"]["actmoveitems"]
  105. ));
  106. // JavaScript for Form:
  107. // Select new target directory / execute action
  108. ?><script language="JavaScript1.2" type="text/javascript">
  109. <!--
  110. function NewDir(newdir) {
  111. document.selform.new_dir.value = newdir;
  112. document.selform.submit();
  113. }
  114. function Execute() {
  115. document.selform.confirm.value = "true";
  116. }
  117. //-->
  118. </script><?php
  119. // "Copy / Move from .. to .."
  120. $s_dir=$dir; if(strlen($s_dir)>40) $s_dir="...".substr($s_dir,-37);
  121. $s_ndir=$new_dir; if(strlen($s_ndir)>40) $s_ndir="...".substr($s_ndir,-37);
  122. echo "<br /><img src=\""._QUIXPLORER_URL.'/images/'.$images."\" align=\"absmiddle\" alt=\"\" />&nbsp;<strong>";
  123. echo sprintf(($action!="move"?$GLOBALS["messages"]["actcopyfrom"]:
  124. $GLOBALS["messages"]["actmovefrom"]),$s_dir, $s_ndir);
  125. echo "</strong><img src=\""._QUIXPLORER_URL."/images/__paste.gif\" align=\"absmiddle\" alt=\"\">\n";
  126. // Form for Target Directory & New Names
  127. echo "<br /><br /><form name=\"selform\" method=\"post\" action=\"";
  128. echo make_link("post",$dir,NULL)."\"><table style=\"width:500px;\" class=\"adminform\">\n";
  129. echo "<input type=\"hidden\" name=\"do_action\" value=\"".$action."\">\n";
  130. echo "<input type=\"hidden\" name=\"confirm\" value=\"false\">\n";
  131. echo "<input type=\"hidden\" name=\"first\" value=\"n\">\n";
  132. echo "<input type=\"hidden\" name=\"new_dir\" value=\"".$new_dir."\">\n";
  133. // List Directories to select Target
  134. dir_print(dir_list($new_dir),$new_dir);
  135. echo "</table><br />
  136. <table style=\"width:500px;\" class=\"adminform\">\n";
  137. // Print Text Inputs to change Names
  138. for($i=0;$i<$cnt;++$i) {
  139. $selitem=stripslashes($GLOBALS['__POST']["selitems"][$i]);
  140. if(isset($GLOBALS['__POST']["newitems"][$i])) {
  141. $newitem=stripslashes($GLOBALS['__POST']["newitems"][$i]);
  142. if($first=="y") $newitem=$selitem;
  143. } else $newitem=$selitem;
  144. $s_item=$selitem; if(strlen($s_item)>50) $s_item=substr($s_item,0,47)."...";
  145. echo "<tr><td><img src=\""._QUIXPLORER_URL."/images/_info.gif\" align=\"absmiddle\" alt=\"\">";
  146. // old name
  147. echo "<input type=\"hidden\" name=\"selitems[]\" value=\"";
  148. echo $selitem."\">&nbsp;".$s_item."&nbsp;";
  149. // New Name
  150. echo "</td><td><input type=\"text\" size=\"25\" name=\"newitems[]\" value=\"";
  151. echo $newitem."\"></td></tr>\n";
  152. }
  153. // Submit & Cancel
  154. echo "</table><br /><table><tr>\n<td>";
  155. echo "<input type=\"submit\" value=\"";
  156. echo ($action!="move"?$GLOBALS["messages"]["btncopy"]:$GLOBALS["messages"]["btnmove"]);
  157. echo "\" onclick=\"javascript:Execute();\"></td>\n<td>";
  158. echo "<input type=\"button\" value=\"".$GLOBALS["messages"]["btncancel"];
  159. echo "\" onclick=\"javascript:location='".make_link("list",$dir,NULL);
  160. echo "';\"></td>\n</tr></table><br /></form>\n";
  161. return;
  162. }
  163. // DO COPY/MOVE
  164. // ALL OK?
  165. if(!@$GLOBALS['nx_File']->file_exists(get_abs_dir($new_dir))) show_error(get_abs_dir($new_dir).": ".$GLOBALS["error_msg"]["targetexist"]);
  166. if(!get_show_item($new_dir,"")) show_error($new_dir.": ".$GLOBALS["error_msg"]["accesstarget"]);
  167. if(!down_home(get_abs_dir($new_dir))) show_error($new_dir.": ".$GLOBALS["error_msg"]["targetabovehome"]);
  168. // copy / move files
  169. $err=false;
  170. for($i=0;$i<$cnt;++$i) {
  171. $tmp = stripslashes($GLOBALS['__POST']["selitems"][$i]);
  172. $new = basename(stripslashes($GLOBALS['__POST']["newitems"][$i]));
  173. if( nx_isFTPMode() ) {
  174. $abs_item = get_item_info($dir,$tmp);
  175. $abs_new_item = get_item_info('/'.$new_dir,$new);
  176. } else {
  177. $abs_item = get_abs_item($dir,$tmp);
  178. $abs_new_item = get_abs_item($new_dir,$new);
  179. }
  180. $items[$i] = $tmp;
  181. // Check
  182. if($new=="") {
  183. $error[$i]= $GLOBALS["error_msg"]["miscnoname"];
  184. $err=true; continue;
  185. }
  186. if(!@$GLOBALS['nx_File']->file_exists($abs_item)) {
  187. $error[$i]= $GLOBALS["error_msg"]["itemexist"];
  188. $err=true; continue;
  189. }
  190. if(!get_show_item($dir, $tmp)) {
  191. $error[$i]= $GLOBALS["error_msg"]["accessitem"];
  192. $err=true; continue;
  193. }
  194. if(@$GLOBALS['nx_File']->file_exists($abs_new_item)) {
  195. $error[$i]= $GLOBALS["error_msg"]["targetdoesexist"];
  196. $err=true; continue;
  197. }
  198. // Copy / Move
  199. if($action=="copy") {
  200. if(@is_link($abs_item) || get_is_file($abs_item)) {
  201. // check file-exists to avoid error with 0-size files (PHP 4.3.0)
  202. if( nx_isFTPMode() ) $abs_item = '/'.$dir.'/'.$abs_item['name'];
  203. $ok=@$GLOBALS['nx_File']->copy( $abs_item ,$abs_new_item); //||@file_exists($abs_new_item);
  204. }
  205. elseif(@get_is_dir($abs_item)) {
  206. $dir = nx_isFTPMode() ? '/'.$dir.'/'.$abs_item['name'].'/' : $abs_item;
  207. if( nx_isFTPMode() ) $abs_new_item .= '/';
  208. $ok=$GLOBALS['nx_File']->copy_dir( $dir, $abs_new_item);
  209. }
  210. }
  211. else {
  212. $ok= $GLOBALS['nx_File']->rename($abs_item,$abs_new_item);
  213. }
  214. if($ok===false || PEAR::isError( $ok ) ) {
  215. $error[$i]=($action=="copy"?
  216. $GLOBALS["error_msg"]["copyitem"]:
  217. $GLOBALS["error_msg"]["moveitem"]
  218. );
  219. if( PEAR::isError( $ok ) ) {
  220. $error[$i].= ' ['.$ok->getMessage().']';
  221. }
  222. $err=true; continue;
  223. }
  224. $error[$i]=NULL;
  225. }
  226. if($err) { // there were errors
  227. $err_msg="";
  228. for($i=0;$i<$cnt;++$i) {
  229. if($error[$i]==NULL) continue;
  230. $err_msg .= $items[$i]." : ".$error[$i]."<br />\n";
  231. }
  232. show_error($err_msg);
  233. }
  234. header("Location: ".make_link("list",$dir,NULL));
  235. }
  236. //------------------------------------------------------------------------------
  237. ?>