Location: PHPKode > projects > MembersGear > membersgear/includes/phptreeview/browse_web_directory.php
<?php
   require_once "../../config/config.php";
?>
<center>
          <table border="0" align="center"  cellspacing="0" cellpadding="0" id="ctl00_ContentPlaceHolder1_UpdatePanel1" style="width:100%;padding-bottom:5px">
           <tr>
                     <td>
                     <table border="0" align="center"  cellspacing="0" cellpadding="0" style="width:100%;display:block;" id="ctl00_ContentPlaceHolder1_UpdateProgress1">
                     <tr>
                     <td style="padding-left:75px">
                        <center>
                        <img src="images/DBRestoreloader.gif" align="absmiddle">   <span class="Lable" id="ctl00_ContentPlaceHolder1_UpdatePanelProgressLoading1_lblmessage">&nbsp;&nbsp;<b>Please wait while your request is being processed..</b></span>
                        </center>
                     </td>
                    </tr>
                   </table>            
                   </td>
                    </tr>
                   </table>            
</center>
   
<?php   
   function getFilePermission($filename)
    {
            //$filename="\"".PHYSICAL_DIR.$filename."\"";
            $perms = fileperms($filename);

            if (($perms & 0xC000) == 0xC000) {
                // Socket
                $info = 's';
            } elseif (($perms & 0xA000) == 0xA000) {
                // Symbolic Link
                $info = 'l';
            } elseif (($perms & 0x8000) == 0x8000) {
                // Regular
                $info = '-';
            } elseif (($perms & 0x6000) == 0x6000) {
                // Block special
                $info = 'b';
            } elseif (($perms & 0x4000) == 0x4000) {
                // Directory
                $info = 'd';
            } elseif (($perms & 0x2000) == 0x2000) {
                // Character special
                $info = 'c';
            } elseif (($perms & 0x1000) == 0x1000) {
                // FIFO pipe
                $info = 'p';
            } else {
                // Unknown
                $info = 'u';
            }

            // Owner
            $info .= (($perms & 0x0100) ? 'r' : '-');
            $info .= (($perms & 0x0080) ? 'w' : '-');
            $info .= (($perms & 0x0040) ?
                        (($perms & 0x0800) ? 's' : 'x' ) :
                        (($perms & 0x0800) ? 'S' : '-'));

            // Group
            $info .= (($perms & 0x0020) ? 'r' : '-');
            $info .= (($perms & 0x0010) ? 'w' : '-');
            $info .= (($perms & 0x0008) ?
                        (($perms & 0x0400) ? 's' : 'x' ) :
                        (($perms & 0x0400) ? 'S' : '-'));

            // World
            $info .= (($perms & 0x0004) ? 'r' : '-');
            $info .= (($perms & 0x0002) ? 'w' : '-');
            $info .= (($perms & 0x0001) ?
                        (($perms & 0x0200) ? 't' : 'x' ) :
                        (($perms & 0x0200) ? 'T' : '-'));
                        

            return $info;
    }       
             
  function getDirectory( $path = '.', $level = 0 , &$parentnode='', &$result)
  {

    $ignore = array( 'cgi-bin', '.', '..' );
    // Directories to ignore when listing output. Many hosts
    // will deny PHP access to the cgi-bin.

    $dh = @opendir( $path );
    // Open the directory to the handle $dh
    
    $style='';
    
    while( false !== ( $file = readdir( $dh ) ) ){
    // Loop through the directory
    
        if( !in_array( $file, $ignore ) ){
        // Check that this file is not to be ignored
            
            $spaces = str_repeat( '&nbsp;', ( $level * 4 ) );
            // Just to add spacing to the list, to better
            // show the directory tree.
            
            if( is_dir( "$path/$file" ) ){
            // Its a directory, so we need to keep reading down...
            
                if($level==0)
                {
                     $style="font-family:verdana,arial,helvetica,sans-serif;font-size:13px;padding-right:5px;";
                     //$parentnode=='';
                     $parentnode=$file.'$';
                }
                else
                {
                     $style="font-family:Verdana,Arial,Helvetica,Sans-serif;font-size:13px;display:none;";
                     
                    if(strpos($parentnode,'$')>0)
                    {   
                        $parentnodearr = explode('$',$parentnode);            
                        $parentnode='';
                        $iparentnodearrloop=0;

                        foreach($parentnodearr as  $key=>$value)
                        {
                            if($iparentnodearrloop<$level)
                                $parentnode .= $value.'$';
                                
                            $iparentnodearrloop+=1;        
                        }
                        
                        $parentnode = substr($parentnode,0,strlen($parentnode)-1);
                    }
                         
                     $parentnode= $parentnode.'$'.$file.'$';
                }     
            
                //($parentnode=='')?($parentnode=$file.$level):($parentnode='childof'.$parentnode);
                $pathoffile=$path."/".$file;
                $permission=getFilePermission($pathoffile);    
                $result .=  "<tr id=\"$parentnode\" name=\"$parentnode\" style=\"$style\">";
                $result .=  "<td>$spaces<a href=\"#\" style=\"border:none;text-decoration:none;\" onclick=\"return false;\"><img border=\"0\" id=\"img{$parentnode}\" onclick=\"opennodes('$parentnode');\" src=\"images/add.gif\" alt=\"$spaces $file\" /><span style=\"margin-left:3px;color:#000000;\" id=\"spn{$parentnode}\" onclick=\"return CustomFunction('$parentnode')\">$file</span></a>
                </td>
                
                <td style='padding-left:50px;'>$permission</td>
                
                </tr>\r\n";
                
                //$parentnode= str_replace('$'.$file,'',$parentnode);
                
                getDirectory( "$path/$file", ($level+1),$parentnode,$result );
                // Re-call this same function but on a new directory.
                // this is what makes function recursive.
            
            }
            /*
            else 
            {
            
                echo "$spaces $file<br />";
                // Just print out the filename
            
            }
            */
        
        }
    
    }
    
    closedir( $dh );
    // Close the directory handle
    return $result;
} 
                                            
$parentnode='';    
$result = '';
//echo "<div style=\"height:500;width:400px;border:solid 1px \#000000;overflow:auto\">";
echo "<span style='font-weight:bold;font-family:verdana;font-size:12px;'>Browse the web directory and select product folder to protect it.</span><br /><br />";
echo "<table id=\"treeviewtable\">";
echo "<tr><td style='font-family:verdana;font-size:12px;'><b>Web Directory</b></td><td style='font-family:verdana;font-size:12px;padding-left:50px;'><b>Current Permissions</b></td></tr>";
echo getDirectory(PHYSICAL_DIR,0,$parentnode,$result);
echo "</table>";
//echo "</div>";
?>

<script language="javascript" type="text/javascript">

function opennodes(parentNodeId)
{
    var parentNode= document.getElementById(parentNodeId);
    var parentNodeImg =  document.getElementById('img'+parentNodeId);   
    var treeviewtable_tbody_childnodes = parentNode.parentNode.childNodes;
     //alert(treeviewtable_tbody_childnodes.length);
     var childnodeid='';
     if(treeviewtable_tbody_childnodes.length>0)
     {
         for(i=0;i<treeviewtable_tbody_childnodes.length;i++)
         {
             childnodeid = treeviewtable_tbody_childnodes[i].id;
             
             if(childnodeid)
             {
                 if(childnodeid.indexOf(parentNodeId)>=0)
                 {
                    childnodeid = childnodeid.replace(parentNodeId,'');
                    
                     
                        if(parentNodeImg.src.indexOf('add.gif')>=0)
                        {                  
                             if(childnodeid.split('$').length==2 && parentNodeId+childnodeid == treeviewtable_tbody_childnodes[i].id ) {
                               //alert(parentNodeId+','+childnodeid+','+ treeviewtable_tbody_childnodes[i].id); 
                                treeviewtable_tbody_childnodes[i].style.display='';
                             }  
                        }
                        
                        // if "-" node clicked then close all child nodes of child as well
                        if(parentNodeImg.src.indexOf('subtract.gif')>=0)
                        {
                             //alert(treeviewtable_tbody_childnodes[i].id);
                             //alert(treeviewtable_tbody_childnodes[i].parentNode)
                             //alert(parentNode);
                              //&& treeviewtable_tbody_childnodes[i].parentNode.id==parentNode.id
                             // if(treeviewtable_tbody_childnodes[i].id == parentNodeId)
                             // {
                             //   treeviewtable_tbody_childnodes[i].style.display='none';
                             //   document.getElementById('img'+treeviewtable_tbody_childnodes[i].id).src='images/add.gif';
                             // } 
                              
                             if(childnodeid.split('$').length==2 && parentNodeId+childnodeid == treeviewtable_tbody_childnodes[i].id )
                             {  
                                treeviewtable_tbody_childnodes[i].style.display='none';
                                document.getElementById('img'+treeviewtable_tbody_childnodes[i].id).src='images/add.gif';
                             } 
                            
                        }    

                 }
             }
         }
     }

     //replace image of opened node
     if(parentNodeImg.src.indexOf('add.gif')>=0)
        parentNodeImg.src='images/subtract.gif';
     else
        parentNodeImg.src='images/add.gif'; 
}


function CustomFunction(nodetext)
{
    //alert('here');
    //parentNode = document.getElementById('parentNodeId').parentNode;
    //childNodeText = parentNode.childNodes[0].innerHTML; 
    
    //alert(nodetext);  
    //alert(nodetext.length);
    
    arrnodetext = nodetext.split('$');
    
    nodetext = '';
    for(i=0;i<arrnodetext.length;i++)
    {
        nodetext += arrnodetext[i]+'/';
    }
    
    nodetext = '/'+nodetext.substring(0,nodetext.length-2);
    
    if(window.opener)
    {
        window.opener.document.addform.folder.value=nodetext;
        window.close();
        
    }
    
    return false;
}

</script>
<script language=javascript> 
document.getElementById('ctl00_ContentPlaceHolder1_UpdateProgress1').style.display='none'; 
</script>
Return current item: MembersGear