<?php

function isimage($str)
{
$image_file = array("gif","jpg","jpeg","png");
for ( $f = 0 ; $f < count($image_file) ; $f++)
{
if ( $str == $image_file[$f] ) return true;
}
return false;
}

function iseditable($str)
{
$edit_file= array("php","txt","htm","html","php3","asp","xml","css","inc","js","zip","tpl");
for ( $f = 0 ; $f < count($edit_file) ; $f++)
{
if ( $str == $edit_file[$f] ) return true;
}
return false;
}

function isviewable($str)
{
$edit_file= array("php","txt","htm","html","php3","asp","xml","css","inc","js","zip","tpl");
for ( $f = 0 ; $f < count($edit_file) ; $f++)
{
if ( $str == $edit_file[$f] ) return true;
}
return false;
}

  function getPerms( $in_Perms ) {
   $sP= '';

 /*  if($in_Perms & 0x1000)    // FIFO pipe
     $sP = 'p';
   elseif($in_Perms & 0x2000) // Character special
     $sP = 'c';
   elseif($in_Perms & 0x4000) // Directory
     $sP = 'd';
   elseif($in_Perms & 0x6000) // Block special
     $sP = 'b';
   elseif($in_Perms & 0x8000) // Regular
     $sP = '&minus;';
   elseif($in_Perms & 0xA000) // Symbolic Link
     $sP = 'l';
   elseif($in_Perms & 0xC000) // Socket
     $sP = 's';
   else                        // UNKNOWN
     $sP = 'u';
*/
   // owner
   $sP .= (($in_Perms & 0x0100) ? 'r' : '&minus;') .
           (($in_Perms & 0x0080) ? 'w' : '&minus;') .
           (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) :
                                   (($in_Perms & 0x0800) ? 'S' : '&minus;'));

   // group
   $sP .= (($in_Perms & 0x0020) ? 'r' : '&minus;') .
           (($in_Perms & 0x0010) ? 'w' : '&minus;') .
           (($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) :
                                   (($in_Perms & 0x0400) ? 'S' : '&minus;'));

   // world
   $sP .= (($in_Perms & 0x0004) ? 'r' : '&minus;') .
           (($in_Perms & 0x0002) ? 'w' : '&minus;') .
           (($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' ) :
                                   (($in_Perms & 0x0200) ? 'T' : '&minus;'));
   return $sP;
  }

  function purge($dir)
  {
  $handle = opendir($dir);
  while (false !== ($file = readdir($handle)))
  {
  if ($file != "." && $file != "..")
  {
  if (is_dir($dir.$file))
  {
  purge ($dir.$file."/");
  rmdir($dir.$file);
  }
  else
  {
  unlink($dir.$file);
  }
  }
  }
  closedir($handle);
  }

  function chmoddir($dir,$perm)
  {
  $handle = opendir($dir);
  while (false !== ($file = readdir($handle)))
  {
  if ($file != "." && $file != "..")
  {
  if (is_dir($dir.$file))
  {
  chmoddir ($dir.$file."/",$perm);
  chmod($dir.$file,$perm);
  }
  else
  {
  chmod($dir.$file,$perm);
  }
  }
  }
  closedir($handle);
  }

function xcopy($basedir,$txtFolderName,$action){
    if ($handle = @opendir($basedir)) {
        while (false !== ($dir = readdir($handle))){
            if ($dir != '.' && $dir != '..'){
                if (is_dir($basedir."/".$dir)){
                    $mkSuccess = mkdir($txtFolderName."/".$dir);
                    xcopy($basedir."/".$dir,$txtFolderName."/".$dir,$action);
					if($action=="cut")purge($basedir."/".$dir);
                }
                else{
                    copy($basedir."/".$dir, $txtFolderName."/".$dir);
					if($action=="cut")unlink($basedir."/".$dir);
                }
            }
        }
        closedir($handle);
    }
}


?>