blank
authorJean-Michel Vourgère <jvourger@greenpeace.org>
Fri, 24 Feb 2017 00:30:05 +0000 (13:30 +1300)
committerJean-Michel Vourgère <jvourger@greenpeace.org>
Fri, 24 Feb 2017 21:44:23 +0000 (10:44 +1300)
include/connect.inc.php.example
index.php
squasher.class.php
squasher.php

index 583058fca24a8b5c2f10a38be5faf9c6a0710e33..2af3946c7b379823e1634b3d5e8a82d392a1cdd5 100644 (file)
@@ -1,10 +1,11 @@
-<?php\r
-\r
-// start session\r
-session_start();\r
-\r
-//connect to db\r
-$link_db = mysql_connect("dbip", "dbuser", "dbpassword");\r
-mysql_select_db("squasher", $link_db);\r
-\r
-?>\r
+<?php
+
+// start session
+session_start();
+
+//connect to db
+$link_db = mysql_connect("dbip", "dbuser", "dbpassword");
+mysql_select_db("squasher", $link_db);
+
+// vim: syntax=php ts=4 sw=4 sts=4 sr noet
+?>
index 10c7e195548a4cac1df08d0d542ccccc9d40d814..d092dd6df90c422195b8ab96c28dc8e49da0e803 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,17 +4,18 @@ require_once("include/connect.inc.php");
 
 require_once("squasher.class.php");
 
-$vars['debug']=$_GET['debug'];
-$vars['newtpl']=$_GET['newtpl'];
-$tools=$_GET['tools'];
+$vars['debug'] = $_GET['debug'];
+$vars['newtpl'] = $_GET['newtpl'];
+$tools = $_GET['tools'];
 
-foreach($_POST AS $key => $value) $submitted[$key]=$value;
+foreach($_POST AS $key => $value)
+       $submitted[$key]=$value;
 
-$salt=md5($_SERVER['REMOTE_ADDR']."|".$_SERVER['HTTP_USER_AGENT']);
+$salt = md5($_SERVER['REMOTE_ADDR']."|".$_SERVER['HTTP_USER_AGENT']);
 
 if ($tools=="logout"){
        session_destroy();
-       $_SESSION['creds']['validated']=false;
+       $_SESSION['creds']['validated'] = false;
        header( 'Location: '.$_SERVER['PHP_SELF'] ) ;
 }
 
@@ -22,21 +23,20 @@ if (!$_SESSION['creds']['validated']){
        validate_user($_POST['user'], $_POST['pass'], $salt);
 }
 
-if ($_SESSION['creds']['validated'] || isset($_GET['f'])){     
+if ($_SESSION['creds']['validated'] || isset($_GET['f'])) {
 //if ($_SESSION['creds']['validated']){
-//load squasher
+       //load squasher
        include("squasher.php");
-}else{
+} else {
+       //show login
 
-//show login
+       require_once("smarty/Smarty.class.php");
 
-require_once("smarty/Smarty.class.php");
-
-$smarty = new Smarty;
-
-$smarty->assign('salt',$salt);
-$smarty->assign('debug',$debug);
-$smarty->display('login.tpl');
+       $smarty = new Smarty;
 
+       $smarty->assign('salt',$salt);
+       $smarty->assign('debug',$debug);
+       $smarty->display('login.tpl');
 }
+// vim: syntax=php ts=4 sw=4 sts=4 sr noet
 ?>
index 7f36d63468cdd313155ab5deeb01d2db99b80329..c831fea68e140a77a0ea754419e7a3cc75803854 100644 (file)
@@ -1,30 +1,32 @@
 <?php
 require_once("include/connect.inc.php");
 
-function zfill($n,$a) {
-  return str_repeat("0",max(0,$a-strlen($n))).$n;
+function zfill($n, $a) {
+       return str_repeat("0", max(0,$a-strlen($n))) . $n;
 }
 
-function named_records_sort($named_recs, $order_by, $reverse=false, $flags=0)
-{
+function named_records_sort($named_recs, $order_by, $reverse=false, $flags=0) {
        $named_hash = array();
-       foreach($named_recs as $key => $fields)$named_hash[$key] = $fields[$order_by];
+       foreach ($named_recs as $key => $fields)
+               $named_hash[$key] = $fields[$order_by];
 
-       if($reverse) arsort($named_hash,$flags=0) ;
-       else asort($named_hash, $flags=0);
+       if ($reverse)
+               arsort($named_hash,$flags=0) ;
+       else
+               asort($named_hash, $flags=0);
 
        $sorted_records = array();
        foreach($named_hash as $key => $val)$sorted_records[$key] = $named_recs[$key];
+
        return $sorted_records;
 }
 
-function validate_user($username, $password, $salt){
+function validate_user($username, $password, $salt) {
        $creds['validated'] = false;
        $query="SELECT * FROM users WHERE user_name = '".mysql_escape_string($username)."'";
        $q_result = mysql_query($query);
-       while ($fetched_object = mysql_fetch_object($q_result)){
-               if (md5($fetched_object->user_pass.$salt) == $password){
+       while ($fetched_object = mysql_fetch_object($q_result)) {
+               if (md5($fetched_object->user_pass.$salt) == $password) {
                        //validated
                        $creds['user_id'] = $fetched_object->user_id;
                        $creds['user_name'] = $fetched_object->user_name;
@@ -39,6 +41,8 @@ function validate_user($username, $password, $salt){
        return $creds['validated'];
 }
 
+
+
 class squashweb {
 
 var $basepath;
@@ -50,73 +54,74 @@ var $folderrights;
 var $userrights;
 var $history;
 
-function set_root($root){
+function set_root($root) {
        $this->basepath = $root;
 }
 
-function get_configs(){
+function get_configs() {
        return $this->configs;
 }
 
-function subfolders(){
+function subfolders() {
        return $this->subfolders;
 }
 
-function get_config($h){
-       
+function get_config($h) {
+
        return $this->configs[$h];
 }
 
-function folderrights(){
+function folderrights() {
        return $this->folderrights;
 }
 
-function userrights(){
+function userrights() {
        return $this->userrights;
 }
 
-function update_history(){
+function update_history() {
        $q="SELECT md5_hash,file,completed,checked FROM file_hash";
        $r=mysql_query($q);
-       while($o=mysql_fetch_object($r)){
+       while($o=mysql_fetch_object($r)) {
                $this->history[$o->md5_hash]['file']=$o->file;
                $this->history[$o->md5_hash]['completed']=$o->completed;
                $this->history[$o->md5_hash]['checked']=$o->checked;
        }
 }
 
-function got_rights_checkbox($needle){
+function got_rights_checkbox($needle) {
        $result = $this->got_rights_array($needle,'',0,'userrights');
-       switch($result){
-               case 0 :
+       switch($result) {
+               case 0:
                        $return = '';
                        break;
-               case 1 :
-               case 2 :
+               case 1:
+               case 2:
                        $return = 'checked';
                        break;
        }
        return $return;
 }
 
-function get_users($user_level){
+function get_users($user_level) {
        $q = "SELECT * FROM users WHERE user_level < '".$user_level."' order by user_name asc";
        $r = mysql_query($q);
-       
-       while ($o = mysql_fetch_object($r)){
+
+       while ($o = mysql_fetch_object($r)) {
                $return[$o->user_id]['id']              = $o->user_id;
                $return[$o->user_id]['name']    = $o->user_name;
                $return[$o->user_id]['level']   = $o->user_level;
-               $return[$o->user_id]['enabled'] = ($o->user_pass == '') ? false : true ;;
+               $return[$o->user_id]['enabled'] = ($o->user_pass == '') ? false : true ;
        }
-       
+
        return $return;
 }
 
-function get_logs($type='all'){
+function get_logs($type='all') {
        $q="SELECT log.* FROM log WHERE log.user_id != '1' and ip != '87.233.211.2' ";
-       if($_SESSION['creds']['user_id'] == 1)$q="SELECT log.* FROM log WHERE log.user_id != 'x' ";
-       switch($type){
+       if ($_SESSION['creds']['user_id'] == 1)
+               $q="SELECT log.* FROM log WHERE log.user_id != 'x' ";
+       switch($type) {
        case "delete":
                $q.= " and log.action = 'delete'";
                break;
@@ -141,88 +146,93 @@ function get_logs($type='all'){
 
        $order=" order by log.log_id desc ";
        $r = mysql_query($q.$today.$order);
-       while($a = mysql_fetch_array($r)){
+       while($a = mysql_fetch_array($r)) {
                $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{".$a['ip']."}' group by users.user_name";
                $ru = mysql_query($qu);
-               $a['users_from_ip']=" | ";
-               while($au = mysql_fetch_array($ru))$a['users_from_ip'].=$au['user_name']." | ";
-               $return['today'][$a['log_id']]=$a;
+               $a['users_from_ip'] = " | ";
+               while($au = mysql_fetch_array($ru))
+                       $a['users_from_ip'] .= $au['user_name']." | ";
+               $return['today'][$a['log_id']] = $a;
        }
        $r = mysql_query($q.$yesterday.$order);
-       while($a = mysql_fetch_array($r)){
+       while($a = mysql_fetch_array($r)) {
                $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{".$a['ip']."}' group by users.user_name";
                $ru = mysql_query($qu);
-               $a['users_from_ip']=" | ";
-               while($au = mysql_fetch_array($ru))$a['users_from_ip'].=$au['user_name']." | ";
-               $return['yesterday'][$a['log_id']]=$a;
+               $a['users_from_ip'] = " | ";
+               while($au = mysql_fetch_array($ru))
+                       $a['users_from_ip'] .= $au['user_name']." | ";
+               $return['yesterday'][$a['log_id']] = $a;
        }
        $r = mysql_query($q.$lastweek.$order);
-       while($a = mysql_fetch_array($r)){
+       while($a = mysql_fetch_array($r)) {
                $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{".$a['ip']."}' group by users.user_name";
                $ru = mysql_query($qu);
-               $a['users_from_ip']=" | ";
-               while($au = mysql_fetch_array($ru))$a['users_from_ip'].=$au['user_name']." | ";
-               $return['lastweek'][$a['log_id']]=$a;
+               $a['users_from_ip'] = " | ";
+               while($au = mysql_fetch_array($ru))
+                       $a['users_from_ip'] .= $au['user_name']." | ";
+               $return['lastweek'][$a['log_id']] = $a;
        }
        $r = mysql_query($q.$older.$order);
-       while($a = mysql_fetch_array($r)){
+       while($a = mysql_fetch_array($r)) {
                $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{".$a['ip']."}' group by users.user_name";
                $ru = mysql_query($qu);
-               $a['users_from_ip']=" | ";
-               while($au = mysql_fetch_array($ru))$a['users_from_ip'].=$au['user_name']." | ";
-               $return['older'][$a['log_id']]=$a;
+               $a['users_from_ip'] = " | ";
+               while($au = mysql_fetch_array($ru))
+                       $a['users_from_ip'] .= $au['user_name']." | ";
+               $return['older'][$a['log_id']] = $a;
        }
 
        return $return;
 }
 
-function insert_users($submitted,$admin_level){
+function insert_users($submitted, $admin_level) {
        $q = "INSERT INTO users (user_name,user_pass,user_level) values ('".$submitted['u']['user_name']."','".md5($submitted['u']['user_pass'])."','".$submitted['u']['user_level']."')";
        $r = mysql_query($q);
 }
 
-function update_users($submitted){
+function update_users($submitted) {
        $q = "UPDATE users SET user_name = '".$submitted['u']['user_name']."', user_pass = '".md5($submitted['u']['user_pass'])."', user_level = '".$submitted['u']['user_level']."' WHERE user_id = '".$submitted['u']['user_id']."'";
        $r = mysql_query($q);
 }
 
-function disable_users($submitted){
+function disable_users($submitted) {
        $q = "UPDATE users SET user_name = '".$submitted['u']['user_name']."', user_pass = '', user_level = '".$submitted['u']['user_level']."' WHERE user_id = '".$submitted['u']['user_id']."'";
        $r = mysql_query($q);
 }
 
-function remove_users($submitted){
+function remove_users($submitted) {
        $q = "DELETE FROM users WHERE user_id = '".$submitted['u']['user_id']."'";
        $r = mysql_query($q);
 }
 
-function give_rights($user_id,$type='folderrights'){
-               
+function give_rights($user_id, $type='folderrights') {
+
        $q = "SELECT folder_path, access FROM user_rights WHERE user_id = '".$user_id."'";
        $r = mysql_query($q);
-       while ($o = mysql_fetch_object($r)){
+       while ($o = mysql_fetch_object($r)) {
 
-               //clean vars            
+               //clean vars
                $arr_string = '$this->'.$type;
-               
+
                //get foldernames from path
-               if($o->folder_path != '/'){
+               if ($o->folder_path != '/') {
                        $path = $o->folder_path;
-                       if($path{0}=='/')$path=substr($path,1);
+                       if ($path{0}=='/')
+                               $path=substr($path,1);
                        $folder_arr = explode('/',$path);
 
                        //create folder structure array
-                       foreach ($folder_arr AS $key => $value){
+                       foreach ($folder_arr AS $key => $value) {
                                $arr_string .= "['".$value."']";
                        }
                }
                $arr_string .= "['__access__']";
-               
+
                //choose access icon
                // access = # --deny-all
                // access = * --allow-dir-only
                // access = @ --allow-inc-subs
-/*             switch($o->access){
+/*             switch($o->access) {
                        case 0 :
                                $icon = '#';
                                break;
@@ -237,59 +247,65 @@ function give_rights($user_id,$type='folderrights'){
                //echo $arr_string." = '".$o->access."';";
                eval($arr_string." = '".$o->access."';");
        }
-       
+
        return $this->folderrights;
 }
 
-function update_rights($submitted,$admin_level){
+function update_rights($submitted, $admin_level) {
        $q = "SELECT count(*) result FROM users WHERE user_id = '".$submitted['edited_user']."' AND user_level < '".$admin_level."'";
        $r = mysql_query($q);
        $o = mysql_fetch_object($r);
-       
-       if ($o->result){
-               foreach ($submitted['m'] AS $path => $access){
+
+       if ($o->result) {
+               foreach ($submitted['m'] AS $path => $access) {
                        $p_q = "SELECT count(*) result FROM user_rights WHERE user_id = '".$submitted['edited_user']."' AND folder_path = '".$path."'";
                        $p_r = mysql_query($p_q);
                        $p_o = mysql_fetch_object($p_r);
-                       if ($p_o->result == 1) mysql_query("UPDATE user_rights SET access = ".$access." WHERE folder_path = '".$path."' AND user_id = '".$submitted['edited_user']."'");
-                       if ($p_o->result == 0) mysql_query("INSERT INTO user_rights (user_id,folder_path,access) values ('".$submitted['edited_user']."','".$path."','".$access."') ");
+                       if ($p_o->result == 1)
+                               mysql_query("UPDATE user_rights SET access = ".$access." WHERE folder_path = '".$path."' AND user_id = '".$submitted['edited_user']."'");
+                       if ($p_o->result == 0)
+                               mysql_query("INSERT INTO user_rights (user_id,folder_path,access) values ('".$submitted['edited_user']."','".$path."','".$access."') ");
                }
        }
 }
 
 
-function show_rights_tree($path,$depth=0,$userid=0){
+function show_rights_tree($path, $depth=0, $userid=0) {
 
-       if ($userid==0)return false;
-       if ($depth==0)$this->give_rights($userid,'userrights');
+       if ($userid==0)
+               return false;
+       if ($depth==0)
+               $this->give_rights($userid, 'userrights');
 
        // access = # | 0 --deny-all
        // access = * | 1 --allow-dir-only
        // access = @ | 2 --allow-inc-subs
 
-       for ($i=0;$depth > $i; $i++)$layout .= " ";
-       if ($dir = opendir($path)){
+       for ($i=0;$depth > $i; $i++)
+               $layout .= " ";
+       if ($dir = opendir($path)) {
                $layout .= "<div style='clear:both;' >\n";
                $f=0;
-               while (false !== ($file = readdir($dir))) { $files_array[]=$file; }
-                asort($files_array);
-                foreach ($files_array as $f_index => $file)
-                {
-//             while (false !== ($file = readdir($dir))) 
-//             {                                
-                       if (($file{0} !== ".") && ($file !== "..")) 
+               while (false !== ($file = readdir($dir))) {
+                       $files_array[]=$file;
+               }
+               asort($files_array);
+               foreach ($files_array as $f_index => $file) {
+//             while (false !== ($file = readdir($dir)))
+//             {
+                       if (($file{0} !== ".") && ($file !== ".."))
                        {
                                $filename = $path."/".$file;
-                               if (!is_file($filename)){if ($this->got_rights_array($filename) > 0)
-                               {
+                               if (!is_file($filename) && $this->got_rights_array($filename) > 0) {
                                        $f++;
-                                       if(substr($filename,0,strlen($this->basepath))==$this->basepath) $name=substr($filename,strlen($this->basepath));
+                                       if (substr($filename,0,strlen($this->basepath))==$this->basepath)
+                                               $name = substr($filename,strlen($this->basepath));
                                        //$check = $this->got_rights_checkbox($filename);
-                                       $check = $this->got_rights_array_admin($filename,'',0,'userrights');
-                                               $check_all = '';
-                                               $check_allow = '';
-                                               $check_deny = '';
-                                       switch($check){
+                                       $check = $this->got_rights_array_admin($filename, '', 0, 'userrights');
+                                       $check_all = '';
+                                       $check_allow = '';
+                                       $check_deny = '';
+                                       switch($check) {
                                                case 2:
                                                        $check_all = 'checked';
                                                        break;
@@ -302,19 +318,23 @@ function show_rights_tree($path,$depth=0,$userid=0){
                                                        break;
                                        }
 
-                                       if($f==1)$style[$depth] = ".depth".$depth."{float:right;width:".(600-($depth*10))."px;border-left:2px solid #FFFFFF;border-top:1px solid #FFFFFF;background:#".dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).";}";
-                                       if($f==1)$layout .= "<div class='depth".$depth."'>";
+                                       if ($f==1)
+                                               $style[$depth] = ".depth".$depth."{float:right;width:".(600-($depth*10))."px;border-left:2px solid #FFFFFF;border-top:1px solid #FFFFFF;background:#".dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).";}";
+                                       if ($f==1)
+                                               $layout .= "<div class='depth".$depth."'>";
                                        $layout .= "<div class='white_border' >".$file."</div>\n";
                                        $layout .= "<div class='check_deny'><input name='m[".$name."]' value=0 type=radio ".$check_deny."></div>\n";
                                        $layout .= "<div class='check_allow'><input name='m[".$name."]' value=1 type=radio ".$check_allow."></div>\n";
                                        $layout .= "<div class='check_all'><input name='m[".$name."]' value=2 type=radio ".$check_all."></div>\n";
                                        $sub_return = $this->show_rights_tree($filename,$depth+1,$userid);
-                                       if(is_array($style) && is_array($sub_return['style']))$style = $style + $sub_return['style'];
+                                       if (is_array($style) && is_array($sub_return['style']))
+                                               $style = $style + $sub_return['style'];
                                        $layout .= $sub_return['layout'];
-                               }}
+                               }
                        }
                }
-               if($f!=0)$layout .= "</div>";
+               if ($f!=0)
+                       $layout .= "</div>";
                $layout .= "</div>\n";
        }
 
@@ -324,44 +344,49 @@ function show_rights_tree($path,$depth=0,$userid=0){
        return $return;
 }
 
-function got_rights_path($needle,$haystack){
-       
-       if(!is_array($haystack)) $haystack = $this->folderrights;
-       foreach($haystack as $v){
-               if(!is_array($v)){
-                       if($needle == $v) return true;
-               }
-               else{
-                       if(is_in_array($needle, $v, $case_sensitive) === true) return true;
+function got_rights_path($needle, $haystack) {
+       if (!is_array($haystack))
+               $haystack = $this->folderrights;
+       foreach($haystack as $v) {
+               if (!is_array($v)) {
+                       if ($needle == $v)
+                               return true;
+               } else {
+                       if (is_in_array($needle, $v, $case_sensitive) === true)
+                               return true;
                }
        }
        return false;
 }
 
-function got_rights_array($needle,$haystack='',$c=0,$type='folderrights'){
-
-       if(!is_array($haystack)) eval('$haystack = $this->'.$type.';');
-       if(substr($needle,0,strlen($this->basepath))==$this->basepath) $needle=substr($needle,strlen($this->basepath));
+function got_rights_array($needle, $haystack='', $c=0, $type='folderrights') {
+       if (!is_array($haystack))
+               eval('$haystack = $this->'.$type.';');
+       if (substr($needle, 0, strlen($this->basepath)) == $this->basepath)
+               $needle=substr($needle,strlen($this->basepath));
 
-       //if($needle{0}=='.')$needle=substr($needle,strlen($this->basepath));
+       //if ($needle{0}=='.')
+       //      $needle=substr($needle, strlen($this->basepath));
 
        //check root rights
-       if($needle{0}=='/' && $haystack['__access__'] == 2 ) return 2;
+       if ($needle{0}=='/' && $haystack['__access__'] == 2 )
+               return 2;
 
        //check folder tights
-       if($needle{0}=='/')$needle=substr($needle,1);
-       
+       if ($needle{0}=='/')
+               $needle=substr($needle,1);
+
        $needle_arr = explode('/',$needle);
        $n = count($needle_arr);
        $d = $c+1;
 
-       foreach($haystack as $k => $v){
-               if($needle_arr[$c] == $k){
-                       if(!is_array($v['__access__'])){
+       foreach ($haystack as $k => $v) {
+               if ($needle_arr[$c] == $k) {
+                       if (!is_array($v['__access__'])) {
                                if (($v['__access__'] == '@' || $v['__access__'] == 2)                     ) return 2;
                                if (($v['__access__'] == '*' || $v['__access__'] == 1) && $d == $n ) return 1;
                                if (($v['__access__'] == '#' || $v['__access__'] == 0) && $d == $n ) return 0;
-                       }else{
+                       } else {
                                $return = $this->got_rights_array($needle, $v, $d);
                        }
                }
@@ -369,61 +394,75 @@ function got_rights_array($needle,$haystack='',$c=0,$type='folderrights'){
        return $return;
 }
 
-function got_rights_array_admin($needle,$haystack='',$c=0,$type='folderrights'){
+function got_rights_array_admin($needle, $haystack='', $c=0, $type='folderrights') {
+
+       if (!is_array($haystack))
+               eval('$haystack = $this->'.$type.';');
+       if (substr($needle, 0, strlen($this->basepath)) == $this->basepath)
+               $needle = substr($needle, strlen($this->basepath));
 
-       if(!is_array($haystack)) eval('$haystack = $this->'.$type.';');
-       if(substr($needle,0,strlen($this->basepath))==$this->basepath) $needle=substr($needle,strlen($this->basepath));
-       
-       //if($needle{0}=='.')$needle=substr($needle,strlen($this->basepath));
+       //if ($needle{0}=='.')
+       //      $needle=substr($needle,strlen($this->basepath));
 
        //check root rights
-       if($needle{0}=='/' && $haystack['__access__'] == 2 ) return 2;
+       if ($needle{0}=='/' && $haystack['__access__'] == 2 )
+               return 2;
 
        //check folder rights
-       if($needle{0}=='/')$needle=substr($needle,1);
+       if ($needle{0}=='/')
+               $needle=substr($needle, 1);
 
        $needle_arr = explode('/',$needle);
        $n = count($needle_arr);
        $d = $c+1;
        $return = 0;
 
-       if($c < $n){
-               if($haystack['__access__'] == 2)return $haystack['__access__'];
-               if(is_array($haystack[$needle_arr[$c]]))$return = $this->got_rights_array_admin($needle, $haystack[$needle_arr[$c]], $d);
-       }else{
-               if($haystack['__access__'] > 0)$return = $haystack['__access__'];
+       if ($c < $n) {
+               if ($haystack['__access__'] == 2)
+                       return $haystack['__access__'];
+               if (is_array($haystack[$needle_arr[$c]]))
+                       $return = $this->got_rights_array_admin($needle, $haystack[$needle_arr[$c]], $d);
+       } else {
+               if ($haystack['__access__'] > 0)
+                       $return = $haystack['__access__'];
        }
 
        return $return;
 }
 
-function got_rights_array_recursive($needle,$haystack='',$c=0,$type='folderrights'){
+function got_rights_array_recursive($needle, $haystack='', $c=0, $type='folderrights') {
 
-       if(!is_array($haystack)) eval('$haystack = $this->'.$type.';');
-       if(substr($needle,0,strlen($this->basepath))==$this->basepath) $needle=substr($needle,strlen($this->basepath));
-       
-       //if($needle{0}=='.')$needle=substr($needle,strlen($this->basepath));
+       if (!is_array($haystack))
+               eval('$haystack = $this->'.$type.';');
+       if (substr($needle, 0, strlen($this->basepath)) == $this->basepath)
+               $needle=substr($needle, strlen($this->basepath));
+
+       //if($needle{0}=='.')
+       //      $needle=substr($needle,strlen($this->basepath));
 
        //check root rights
-       if($needle{0}=='/' && $haystack['__access__'] == 2 ) return 2;
+       if($needle{0}=='/' && $haystack['__access__'] == 2 )
+               return 2;
 
        //check folder rights
-       if($needle{0}=='/')$needle=substr($needle,1);
-       
-       $needle_arr = explode('/',$needle);
+       if($needle{0}=='/')
+               $needle=substr($needle,1);
+
+       $needle_arr = explode('/', $needle);
        $n = count($needle_arr);
        $d = $c+1;
        $return = 0;
-       
-       foreach($haystack as $k => $v){
-               if($needle_arr[$c] == $k){
-                       if($c < $n){
-                               if($v['__access__'] == 2) $return = $return + $v['__access__'];
+
+       foreach($haystack as $k => $v) {
+               if ($needle_arr[$c] == $k) {
+                       if ($c < $n) {
+                               if ($v['__access__'] == 2)
+                                       $return = $return + $v['__access__'];
                                $return = $return + $this->got_rights_array_recursive($needle, $v, $d);
-                       }else{
+                       } else {
                                $return = $return + $this->in_array_recursive($v);
                        }
-               }elseif($c == $n){
+               } elseif ($c == $n) {
                        $return = $return + $v['__access__'];
                        if($k != '__access__')$return = $return + $this->in_array_recursive($v);
                }
@@ -432,37 +471,47 @@ function got_rights_array_recursive($needle,$haystack='',$c=0,$type='folderright
        return $return;
 }
 
-function in_array_recursive($haystack){
+function in_array_recursive($haystack) {
        $return = 0;
-       if (is_array($haystack))foreach ($haystack as $key1 => $value1){
-               if (is_array($value1)){
-                       $return = $return + $this->in_array_recursive($value1);
-               }
-               elseif($value1 > 0){
-                       return $value1;
+       if (is_array($haystack)) {
+               foreach ($haystack as $key1 => $value1) {
+                       if (is_array($value1)) {
+                               $return = $return + $this->in_array_recursive($value1);
+                       }
+                       elseif ($value1 > 0) {
+                               return $value1;
+                       }
                }
        }
        return $return;
 }
 
-function read_single_file($path,$file){
+function read_single_file($path, $file) {
        $filename = $path."/".$file;
-       $i=0;
-       if ($this->got_rights_array($path) > 0){
-               if (is_file($filename.'.Completed'))$file.='.Completed';
-               if (is_file($filename.'.InProgress'))$file.='.InProgress';
-               if (is_file($filename.'.Starting'))$file.='.Starting';
-               if (is_file($filename.'.Processed'))$file.='.Processed';
-               $filename = $path."/".$file;
+       $i = 0;
+       if ($this->got_rights_array($path) > 0) {
+               if (is_file($filename.'.Completed'))
+                       $file.='.Completed';
+               if (is_file($filename.'.InProgress'))
+                       $file.='.InProgress';
+               if (is_file($filename.'.Starting'))
+                       $file.='.Starting';
+               if (is_file($filename.'.Processed'))
+                       $file.='.Processed';
+               $filename = $path . "/" . $file;
                $handle = @fopen($filename, "rb");
-               if (strpos($file,'.Completed') )$ext='.Completed';
-               if (strpos($file,'.InProgress'))$ext='.InProgress';
-               if (strpos($file,'.Starting')  )$ext='.Starting';
-               if (strpos($file,'.Processed') )$ext='.Processed';
-               $sub_pos=strpos($file,$ext);
-               $base_name=substr($file,0,$sub_pos);
+               if (strpos($file,'.Completed'))
+                       $ext='.Completed';
+               if (strpos($file,'.InProgress'))
+                       $ext='.InProgress';
+               if (strpos($file,'.Starting'))
+                       $ext='.Starting';
+               if (strpos($file,'.Processed'))
+                       $ext='.Processed';
+               $sub_pos = strpos($file, $ext);
+               $base_name = substr($file, 0, $sub_pos);
                $filecontent = @fread($handle, @filesize($filename));
-               $config[$i]=explode("\r\n",$filecontent);
+               $config[$i] = explode("\r\n", $filecontent);
                /***
                *       $config:: array
                *       [0]     ->      versioncode
@@ -473,19 +522,19 @@ function read_single_file($path,$file){
                *       [5]     ->      chunkcount
                *       [6]     ->      CRC32 checksum
                ***/
-               if (@filesize($filename) > 0){
-                       $h=md5($path."/".$config[$i][2]);
-                       $this->configs[$h]=$config[$i];
-                       $this->configs[$h]['squashed']=true;
-                       $this->configs[$h]['path']=$path;
-                       $this->configs[$h]['status']=substr($ext, 1);
-                       $this->configs[$h]['mime']=$this->set_mime($this->configs[$h][2]);
-                       $this->configs[$h]['hidden']= (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
+               if (@filesize($filename) > 0) {
+                       $h = md5($path."/".$config[$i][2]);
+                       $this->configs[$h] = $config[$i];
+                       $this->configs[$h]['squashed'] = true;
+                       $this->configs[$h]['path'] = $path;
+                       $this->configs[$h]['status'] = substr($ext, 1);
+                       $this->configs[$h]['mime'] = $this->set_mime($this->configs[$h][2]);
+                       $this->configs[$h]['hidden'] = (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
                        //to prevent dates of 1-1-1970 we set te dates of the config file
                        $this->configs[$h]['added'] = filectime($filename);
                        $this->configs[$h]['lastchange'] = filemtime($filename);
                        fclose($handle);
-                       $this->populate_stats($path,$h);
+                       $this->populate_stats($path, $h);
                        //insert hash in db
                        #$this->update_hash($h,$path."/".$config[$i][2]);
                        //check stats
@@ -495,53 +544,57 @@ function read_single_file($path,$file){
 }
 
 
-function read_directory($path,$getsubs=false,$getfirstfiles=true,$getdeepfiles=true,$populate=true){
+function read_directory($path, $getsubs=false, $getfirstfiles=true, $getdeepfiles=true, $populate=true) {
 
-       if ($dir = @opendir($path)){
-               $i=0;
-               $last=1;
-               while (false !== ($file = readdir($dir))){
-                       if (($file{0} !== ".") && substr($file,0,1) !== "SQ"){
+       if ($dir = @opendir($path)) {
+               $i = 0;
+               $last = 1;
+               while (false !== ($file = readdir($dir))) {
+                       if (($file{0} !== ".") && substr($file,0,1) !== "SQ") {
                                $filename = $path."/".$file;
-                               if (!is_file($filename) && !strpos($filename,'./uploads/recieving')){
-                                       if($getsubs){
-                                               if ($this->got_rights_array_recursive($filename) > 0){
+                               if (!is_file($filename) && !strpos($filename, './uploads/recieving')) {
+                                       if ($getsubs) {
+                                               if ($this->got_rights_array_recursive($filename) > 0) {
                                                        $key = substr($path,strlen($this->basepath)) . '/' . $file;
-                                                       $this->subfolders[$key]=$file;
+                                                       $this->subfolders[$key] = $file;
                                                }
                                        }
-                                       if($getdeepfiles)$this->read_directory($filename,false,$getdeepfiles,$getdeepfiles,$populate);
-                               }elseif(strpos($filename,'./uploads/ftp')){ //ftp files
-                                       if ($this->got_rights_array($path) > 0 && !strpos($filename,'.hidden') ){
-                                               $h=md5($filename);
-                                               $name_only=substr($filename,strlen($path)+1);
-                                               $file_structure=explode('.',$name_only);
-                                               $ext=array_pop($file_structure);
-                                               $base_name=array_pop($file_structure);
-                                               $this->configs[$h]['path']=$path;
-                                               $this->configs[$h][0]='manual ftp';
-                                               $this->configs[$h][2]=$name_only;
-                                               $this->configs[$h][3]=filesize($filename);
-                                               $this->configs[$h]['added']=filectime($filename);
-                                               $this->configs[$h]['lastchange']=filemtime($filename);
-                                               $this->configs[$h]['status']='unknown';
-                                               $this->configs[$h]['squashed']=false;
-                                               $this->configs[$h]['mime']=$this->set_mime($name_only);
-                                               $this->configs[$h]['hidden']= (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
+                                       if ($getdeepfiles)$this->read_directory($filename, false, $getdeepfiles, $getdeepfiles, $populate);
+                               } elseif (strpos($filename,'./uploads/ftp')) { //ftp files
+                                       if ($this->got_rights_array($path) > 0 && !strpos($filename, '.hidden') ) {
+                                               $h = md5($filename);
+                                               $name_only = substr($filename, strlen($path)+1);
+                                               $file_structure = explode('.', $name_only);
+                                               $ext = array_pop($file_structure);
+                                               $base_name = array_pop($file_structure);
+                                               $this->configs[$h]['path'] = $path;
+                                               $this->configs[$h][0] = 'manual ftp';
+                                               $this->configs[$h][2] = $name_only;
+                                               $this->configs[$h][3] = filesize($filename);
+                                               $this->configs[$h]['added'] = filectime($filename);
+                                               $this->configs[$h]['lastchange'] = filemtime($filename);
+                                               $this->configs[$h]['status'] = 'unknown';
+                                               $this->configs[$h]['squashed'] = false;
+                                               $this->configs[$h]['mime'] = $this->set_mime($name_only);
+                                               $this->configs[$h]['hidden'] = (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
                                        }
-                               }elseif($getfirstfiles){ //squashed files
-                                       if ($this->got_rights_array($path) > 0){
-                                               if (strpos($filename,'.Completed') || strpos($filename,'.InProgress') || strpos($filename,'.Starting') || strpos($filename,'.Processed')){
+                               } elseif ($getfirstfiles) { //squashed files
+                                       if ($this->got_rights_array($path) > 0) {
+                                               if (strpos($filename, '.Completed') || strpos($filename, '.InProgress') || strpos($filename, '.Starting') || strpos($filename, '.Processed')) {
                                                        $i++;
                                                        $handle = @fopen($filename, "rb");
-                                                       if (strpos($file,'.Completed') )$ext='.Completed';
-                                                       if (strpos($file,'.InProgress'))$ext='.InProgress';
-                                                       if (strpos($file,'.Starting')  )$ext='.Starting';
-                                                       if (strpos($file,'.Processed') )$ext='.Processed';
-                                                       $sub_pos=strpos($file,$ext);
-                                                       $base_name=substr($file,0,$sub_pos);
+                                                       if (strpos($file,'.Completed'))
+                                                               $ext='.Completed';
+                                                       if (strpos($file,'.InProgress'))
+                                                               $ext='.InProgress';
+                                                       if (strpos($file,'.Starting'))
+                                                               $ext='.Starting';
+                                                       if (strpos($file,'.Processed'))
+                                                               $ext='.Processed';
+                                                       $sub_pos = strpos($file, $ext);
+                                                       $base_name = substr($file, 0, $sub_pos);
                                                        $filecontent = @fread($handle, @filesize($filename));
-                                                       $config[$i]=explode("\r\n",$filecontent);
+                                                       $config[$i] = explode("\r\n", $filecontent);
 
                                                        /***
                                                        *       $config:: array
@@ -554,21 +607,21 @@ function read_directory($path,$getsubs=false,$getfirstfiles=true,$getdeepfiles=t
                                                        *       [6]     ->      CRC32 checksum
                                                        ***/
 
-                                                       if (@filesize($filename) > 0){
-                                                               $h=md5($path."/".$config[$i][2]);
-                                                               $this->configs[$h]=$config[$i];
-                                                               $this->configs[$h]['squashed']=true;
-                                                               $this->configs[$h]['path']=$path;
-                                                               $this->configs[$h]['status']=substr($ext, 1);
-                                                               $this->configs[$h]['mime']=$this->set_mime($this->configs[$h][2]);
-                                                               $this->configs[$h]['hidden']= (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
+                                                       if (@filesize($filename) > 0) {
+                                                               $h = md5($path."/".$config[$i][2]);
+                                                               $this->configs[$h] = $config[$i];
+                                                               $this->configs[$h]['squashed'] = true;
+                                                               $this->configs[$h]['path'] = $path;
+                                                               $this->configs[$h]['status'] = substr($ext, 1);
+                                                               $this->configs[$h]['mime'] = $this->set_mime($this->configs[$h][2]);
+                                                               $this->configs[$h]['hidden'] = (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
                                                                //to prevent dates of 1-1-1970 we set te dates of the config file
                                                                $this->configs[$h]['added'] = filectime($filename);
                                                                $this->configs[$h]['lastchange'] = filemtime($filename);
                                                                fclose($handle);
-                                                               $this->populate_stats($path,$h);
+                                                               $this->populate_stats($path, $h);
                                                                //insert hash in db
-                                                               $this->update_hash($h,$path."/".$config[$i][2]);
+                                                               $this->update_hash($h, $path."/".$config[$i][2]);
                                                                //check stats
                                                                $this->check_stats($h);
                                                        }
@@ -580,72 +633,76 @@ function read_directory($path,$getsubs=false,$getfirstfiles=true,$getdeepfiles=t
        }
 }
 
-function check_stats($h){
+function check_stats($h) {
        $config = $this->get_config($h);
        $count = @array_sum($config['stats']);
-       if ($config['status']=='Completed' && $count != $config[5]){
+       if ($config['status']=='Completed' && $count != $config[5]) {
                $filepath=$config['path'].'/'.$config[2];
-               if($this->history[$h]['completed']=="1"){
+               if ($this->history[$h]['completed']=="1") {
                        //don't display broken file, remove it instead
                        unlink($config['path'].'/'.$config[2].'.Completed');
                        unset($this->configs[$h]);
 
-                       if (!$count)$count = 0;
-                       $m_subject="Squasher Debug: File Removed";
-                       $m_body="Upload removed: \n File: ".$config['path']."/".$config[2]." \n Status: ".$config['status']." \n Chunks: ".$count." out of ".$config[5];
-                       mail('jasper@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
-                       $qlog="insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','debug','-1','squasher-web','cleanup',NOW())";
+                       if (!$count)
+                               $count = 0;
+                       $m_subject = "Squasher Debug: File Removed";
+                       $m_body = "Upload removed: \n File: ".$config['path']."/".$config[2]." \n Status: ".$config['status']." \n Chunks: ".$count." out of ".$config[5];
+                       mail('jasper@netformatie.nl', $m_subject, $m_body, "From: support@netformatie.nl");
+                       $qlog = "insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','debug','-1','squasher-web','cleanup',NOW())";
                        mysql_query($qlog);
-
-               }else{
+               } else {
                        //do move
-                       rename($config['path'].'/'.$config[2].'.Completed',$config['path'].'/'.$config[2].'.InProgress');
-                       $this->configs[$h]['status']='InProgress';
+                       rename($config['path'].'/'.$config[2].'.Completed', $config['path'].'/'.$config[2].'.InProgress');
+                       $this->configs[$h]['status'] = 'InProgress';
 
                        //mail n4m
-                       if (!$count)$count = 0;
-                       $m_subject="Squasher Debug: Upload Error";
-                       $m_body="Upload error: \n File: ".$config['path']."/".$config[2]." \n Status: ".$config['status']." \n Chunks: ".$count." out of ".$config[5];
-                       mail('support@netformatie.nl',$m_subject,$m_body,"From: squasher@netformatie.nl");
-                       mail('jan@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
-                       mail('joop@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
-                       mail('jasper@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
+                       if (!$count)
+                               $count = 0;
+                       $m_subject = "Squasher Debug: Upload Error";
+                       $m_body = "Upload error: \n File: ".$config['path']."/".$config[2]." \n Status: ".$config['status']." \n Chunks: ".$count." out of ".$config[5];
+                       mail('support@netformatie.nl', $m_subject, $m_body, "From: squasher@netformatie.nl");
+                       mail('jan@netformatie.nl', $m_subject, $m_body, "From: support@netformatie.nl");
+                       mail('joop@netformatie.nl', $m_subject, $m_body, "From: support@netformatie.nl");
+                       mail('jasper@netformatie.nl', $m_subject, $m_body, "From: support@netformatie.nl");
 
                        //do sms
                        //wget -o/dev/null "http://www.mollie.nl/xml/sms/?username=netformatie&password=SMSdolsi&originator=Netformatie&recipients=${ENGINEER}&message=${CALLERID}";
 
                        //mail RO
-                       $ship=explode('/',$config['path']);
-                       if($ship[2] == 'myas' || $ship[2] == 'myez' || $ship[2] == 'myrw')mail('ro1@'.$ship[2].'.greenpeace.org','Squasher: '.$config[2].' resume request','The squasher server has detected an upload error. Please resume the squasher transmission for '.$config[2].' to correct this problem.',"From: support@netformatie.nl\nX-Priority: 1");
+                       $ship = explode('/',$config['path']);
+                       if ($ship[2] == 'myas' || $ship[2] == 'myez' || $ship[2] == 'myrw')
+                               mail('ro1@'.$ship[2].'.greenpeace.org','Squasher: '.$config[2].' resume request','The squasher server has detected an upload error. Please resume the squasher transmission for '.$config[2].' to correct this problem.',"From: support@netformatie.nl\nX-Priority: 1");
 
-                       $qlog="insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','debug','-1','squasher-web','retry',NOW())";
+                       $qlog = "insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','debug','-1','squasher-web','retry',NOW())";
                        mysql_query($qlog);
 
                }
-       }elseif($config['status']=='Completed' && $count == $config[5]){
-               if($this->history[$h]['completed']==0)mysql_query("UPDATE file_hash SET completed = 1 WHERE md5_hash = '".$h."'");
+       } elseif ($config['status']=='Completed' && $count == $config[5]) {
+               if ($this->history[$h]['completed']==0)
+                       mysql_query("UPDATE file_hash SET completed = 1 WHERE md5_hash = '".$h."'");
        }
 }
 
-function update_hash($hash,$path){
-       $check_hash_query="select * from file_hash where md5_hash = '".$hash."'";
-       $check_hash_result=mysql_query($check_hash_query);
-       if(mysql_num_rows($check_hash_result) == 0){
-               $insert_hash_query="INSERT INTO file_hash (md5_hash,file) values ('".$hash."','".$path."')";
+function update_hash($hash, $path) {
+       $check_hash_query = "select * from file_hash where md5_hash = '".$hash."'";
+       $check_hash_result = mysql_query($check_hash_query);
+       if(mysql_num_rows($check_hash_result) == 0) {
+               $insert_hash_query = "INSERT INTO file_hash (md5_hash,file) values ('".$hash."','".$path."')";
                mysql_query($insert_hash_query);
        }
 }
 
-function path_to_arraystring($path,$arrayname){
-       $path_values = explode('/',$path);
+function path_to_arraystring($path, $arrayname) {
+       $path_values = explode('/', $path);
        $return = $arrayname;
-       foreach ($path_values AS $key => $value){
-               if ($value != '.' && $value != '')$return.= "['".$value."']";
+       foreach ($path_values AS $key => $value) {
+               if ($value != '.' && $value != '')
+                       $return.= "['".$value."']";
        }
        return $return;
 }
 
-function populate_stats($path,$h){
+function populate_stats($path, $h) {
        /***
        *       $config:: array
        *       [0]     ->      versioncode
@@ -662,55 +719,59 @@ function populate_stats($path,$h){
        $r = mysql_query($q);
        $o = mysql_fetch_object($r);
        $validated_chunks = $o->validated_chunks;
-       
-       if($this->history[$h]['completed']=="1"){
+
+       if ($this->history[$h]['completed']=="1") {
                $file_part = $path."/SQ".zfill(1,6)."-".$config[2];
-               if (!is_file($file_part))$file_part = $path."/SQ".zfill(1,3)."-".$config[2];
-               if (is_file($file_part)){
+               if (!is_file($file_part))
+                       $file_part = $path."/SQ".zfill(1,3)."-".$config[2];
+               if (is_file($file_part)) {
                        $this->configs[$h]['added'] = filectime($file_part);
                        $file_part = $path."/SQ".zfill($config[5],6)."-".$config[2];
-                       if (!is_file($file_part))$file_part = $path."/SQ".zfill($config[5],3)."-".$config[2];
-                       if (is_file($file_part)) $this->configs[$h]['lastchange'] = filemtime($file_part);
-                       for ($i=1;$i<=$config[5];$i++) 
-                       {
-                               $this->configs[$h]['stats'][$i]="1.00";
-                       }
-               }else{
+                       if (!is_file($file_part))
+                               $file_part = $path."/SQ".zfill($config[5],3)."-".$config[2];
+                       if (is_file($file_part))
+                               $this->configs[$h]['lastchange'] = filemtime($file_part);
+                       for ($i=1; $i<=$config[5]; $i++)
+                               $this->configs[$h]['stats'][$i] = "1.00";
+               } else {
                        //failsafe voor verwijderde bestanden
                        mysql_query("UPDATE file_hash SET completed = 0 WHERE md5_hash = '".$h."'");
                }
-       }else{
+       } else {
                $keep_validating = true;
-               for ($i=1;$i<=$config[5];$i++){
-                       if ($validated_chunks > $i){
+               for ($i=1; $i<=$config[5]; $i++) {
+                       if ($validated_chunks > $i) {
                                $this->configs[$h]['stats'][$i]="1.00";
-                       }else{
+                       } else {
                                $file_part = $path."/SQ".zfill($i,6)."-".$config[2];
-                               if (!is_file($file_part))$file_part = $path."/SQ".zfill($i,3)."-".$config[2];
-                               if (is_file($file_part)){
+                               if (!is_file($file_part))
+                                       $file_part = $path."/SQ".zfill($i,3)."-".$config[2];
+                               if (is_file($file_part)) {
                                        $handle = fopen($file_part, "rb");
                                        $size_this = filesize($file_part);
                                        $added = filectime($file_part);
                                        $last_changed = filemtime($file_part);
-                                       if ($this->configs[$h]['added'] > $added || !is_numeric($this->configs[$h]['added'])) $this->configs[$h]['added'] = $added;
-                                       if ($this->configs[$h]['lastchange'] < $last_changed) $this->configs[$h]['lastchange'] = $last_changed;
-                                       if ($i != $config[5]){
-                                               $this->configs[$h]['stats'][$i]=number_format((1/$config[4])*$size_this, 2, '.', '');
+                                       if ($this->configs[$h]['added'] > $added || !is_numeric($this->configs[$h]['added']))
+                                               $this->configs[$h]['added'] = $added;
+                                       if ($this->configs[$h]['lastchange'] < $last_changed)
+                                               $this->configs[$h]['lastchange'] = $last_changed;
+                                       if ($i != $config[5]) {
+                                               $this->configs[$h]['stats'][$i] = number_format((1/$config[4])*$size_this, 2, '.', '');
                                        //number_format((100/$config[4])*$size_this, 2, '.', '')."%";
                                        }else{
-                                               $this->configs[$h]['stats'][$i]=number_format((1/($config[3]-($config[4]*($config[5]-1))))*$size_this, 2, '.', '');
+                                               $this->configs[$h]['stats'][$i] = number_format((1/($config[3]-($config[4]*($config[5]-1))))*$size_this, 2, '.', '');
                                                //number_format((100/($config[3]-($config[4]*($config[5]-1))))*$size_this, 2, '.', '')."%";
                                        }
                                        fclose($handle);
-                                       if ($config[4] == $size_this && $keep_validating){
+                                       if ($config[4] == $size_this && $keep_validating) {
                                                $validated_chunks = $i;
-                                       }else{
+                                       } else {
                                                $keep_validating = false;
                                        }
-                               }else{
-                                       $this->configs[$h]['stats'][$i]="0.00";
+                               } else {
+                                       $this->configs[$h]['stats'][$i] = "0.00";
                                        //$this->configs[$h]['stats'][$i]="0.00%";
-                                       
+
                                }
                        }
                }
@@ -718,41 +779,41 @@ function populate_stats($path,$h){
        }
 }
 
-function read_config($path,$filename){
-               if (is_file($path."/".$filename.".InProgress")){
-                       $config_handle = fopen($path."/".$filename.".InProgress","r");
-                       $conf_path=$path."/".$filename.".InProgress";
-               }elseif (is_file($path."/".$filename.".Completed" )){
-                       $config_handle = fopen($path."/".$filename.".Completed" ,"r");
-                       $conf_path=$path."/".$filename.".Completed";
-               }elseif (is_file($path."/".$filename.".Starting" )){
-                       $config_handle = fopen($path."/".$filename.".Starting"  ,"r");
-                       $conf_path=$path."/".$filename.".Starting";
-               }elseif (is_file($path."/".$filename.".Processed" )){
-                       $config_handle = fopen($path."/".$filename.".Processed" ,"r");
-                       $conf_path=$path."/".$filename.".Processed";
-               }else{
-                       return "Not Found";
-               }
-    $config_content = fread($config_handle, filesize($conf_path));
-               fclose($config_handle);
-               $config = explode("\n",$config_content);
-               
-               return $config;
+function read_config($path, $filename) {
+       if (is_file($path."/".$filename.".InProgress")) {
+               $config_handle = fopen($path."/".$filename.".InProgress", "r");
+               $conf_path=$path."/".$filename.".InProgress";
+       } elseif (is_file($path."/".$filename.".Completed" )) {
+               $config_handle = fopen($path."/".$filename.".Completed", "r");
+               $conf_path=$path."/".$filename.".Completed";
+       } elseif (is_file($path."/".$filename.".Starting" )) {
+               $config_handle = fopen($path."/".$filename.".Starting", "r");
+               $conf_path=$path."/".$filename.".Starting";
+       } elseif (is_file($path."/".$filename.".Processed" )) {
+               $config_handle = fopen($path."/".$filename.".Processed", "r");
+               $conf_path=$path."/".$filename.".Processed";
+       } else {
+               return "Not Found";
+       }
+       $config_content = fread($config_handle, filesize($conf_path));
+       fclose($config_handle);
+       $config = explode("\n", $config_content);
+
+       return $config;
 //             print_r($config);
 /*             $file_count = $config[5];
                $last=1;
-    for ($i=1;$i<=$file_count;$i++) 
+    for ($i=1; $i<=$file_count; $i++)
     {
        $file_part = $path."/SQ".zfill($i,6)."-".$filename;
        if (is_file($file_part))
        {
-        
+
         $handle = fopen($file_part, "rb");
-        $size_this = filesize($file_part);                                     
+        $size_this = filesize($file_part);
                                //$stats[$i]=round((100/$config[4])*$size_this)."%";
-                               if ((($size_this==$config[4] && ($last+1)==$i) )|| $i == $config[5]){
-                                       $merged_file.=fread($handle, filesize($file_part));                             
+                               if ((($size_this==$config[4] && ($last+1)==$i) )|| $i == $config[5]) {
+                                       $merged_file.=fread($handle, filesize($file_part));
                                        $last = $i;
                                }
         fclose($handle);
@@ -760,12 +821,12 @@ function read_config($path,$filename){
      }
      return $merged_file;
      */
-   }
+}
 
-function print_files($path,$filename,$tovar = false){
-       if(strpos($path,'./uploads/ftp')){
-               $filestring=$path.'/'.$filename;
-               if (is_file($filestring)){
+function print_files($path, $filename, $tovar=false) {
+       if (strpos($path, './uploads/ftp')) {
+               $filestring = $path.'/'.$filename;
+               if (is_file($filestring)) {
                        $handle = fopen($filestring, "rb");
                        while (!feof($handle))
                        {
@@ -774,20 +835,20 @@ function print_files($path,$filename,$tovar = false){
                                flush();
                        }
                }
-       }else{
-               if (is_file($path."/".$filename.".InProgress")){
-                       $config_handle = fopen($path."/".$filename.".InProgress","r");
+       } else {
+               if (is_file($path."/".$filename.".InProgress")) {
+                       $config_handle = fopen($path."/".$filename.".InProgress", "r");
                        $conf_path=$path."/".$filename.".InProgress";
-               }elseif (is_file($path."/".$filename.".Completed" )){
-                       $config_handle = fopen($path."/".$filename.".Completed" ,"r");
+               } elseif (is_file($path."/".$filename.".Completed" )) {
+                       $config_handle = fopen($path."/".$filename.".Completed""r");
                        $conf_path=$path."/".$filename.".Completed";
-               }elseif (is_file($path."/".$filename.".Starting" )){
-                       $config_handle = fopen($path."/".$filename.".Starting"  ,"r");
+               } elseif (is_file($path."/".$filename.".Starting" )) {
+                       $config_handle = fopen($path."/".$filename.".Starting""r");
                        $conf_path=$path."/".$filename.".Starting";
-               }elseif (is_file($path."/".$filename.".Processed" )){
-                       $config_handle = fopen($path."/".$filename.".Processed" ,"r");
+               } elseif (is_file($path."/".$filename.".Processed" )) {
+                       $config_handle = fopen($path."/".$filename.".Processed""r");
                        $conf_path=$path."/".$filename.".Processed";
-               }else{
+               } else{
                        return "Not Found";
                }
                $config_content = fread($config_handle, filesize($conf_path));
@@ -795,21 +856,22 @@ function print_files($path,$filename,$tovar = false){
                $config = explode("\n",$config_content);
 //             print_r($config);
                $file_count = $config[5];
-               $last=0;
-               $last_part_size=( $config[3] - ( ( $config[5] -1 ) * $config[4] ) );
-               for ($i=0;$i<=$file_count;$i++) 
+               $last = 0;
+               $last_part_size = ( $config[3] - ( ( $config[5] -1 ) * $config[4] ) );
+               for ($i=0;$i<=$file_count;$i++)
                {
                        $file_part = $path."/SQ".zfill($i,6)."-".$filename;
-                       if (!is_file($file_part))$file_part = $path."/SQ".zfill($i,3)."-".$filename;
+                       if (!is_file($file_part))
+                               $file_part = $path."/SQ".zfill($i,3)."-".$filename;
                        if (is_file($file_part))
                        {
                                $handle = fopen($file_part, "rb");
                                $size_this = filesize($file_part);
-                               if ( ( ( $size_this==$config[4] ) && ( ($last+1)==$i ) ) || ( ( $i == $config[5] ) && ( $size_this==$last_part_size ) && ( ($last+1)==$i ) ) ){
-                                       if ($tovar){
+                               if ( ( ( $size_this==$config[4] ) && ( ($last+1)==$i ) ) || ( ( $i == $config[5] ) && ( $size_this==$last_part_size ) && ( ($last+1)==$i ) ) ) {
+                                       if ($tovar) {
                                                $merged_file.=fread($handle, $size_this);
                                                $last = $i;
-                                       }else{                          
+                                       } else {
                                                while (!feof($handle))
                                                {
                                                        print(fread($handle, 4096));
@@ -822,89 +884,96 @@ function print_files($path,$filename,$tovar = false){
                                fclose($handle);
                        }
                }
-               if($tovar)return $merged_file;
+               if ($tovar)
+                       return $merged_file;
        }
 }
 
-       function check_md5($h){
-               $return=false;
-               $config=$this->configs[$h];
-               $var=$this->print_files($config['path'],$config[2],true);
-               $hash=md5($var);
-               if($hash==$config[6])$return=true;
-               
-               return $return;
-       }
+function check_md5($h) {
+       $return = false;
+       $config = $this->configs[$h];
+       $var = $this->print_files($config['path'], $config[2], true);
+       $hash = md5($var);
+       if ($hash==$config[6])
+               $return=true;
+
+       return $return;
+}
 
-       function file_crc($file_string){
+function file_crc($file_string) {
        //$file_string = file_get_contents($file);
 
        $crc = crc32($file_string);
        return sprintf("%u\n", $crc);
 }
 
-       function file_crc_debug($file){
+function file_crc_debug($file) {
        $file_string = file_get_contents($file);
 
        $crc = crc32($file_string);
        return sprintf("%u\n", $crc);
 }
 
-       function delete_file($h,$s){
-               $request = $this->get_config($h);
-               if(strpos($request['path'],'./uploads/ftp')){
-                       $filepath=$request['path'].'/'.$request[2];
-                       #remove file
-                       if(is_file($filepath))                          @unlink($filepath);
-                       if(is_file($filepath.'.hidden'))        @unlink($filepath.'.hidden');
-               }else{
-                       #remove fileparts
-                       for($i=0;$i<=$request[5];$i++){
-                               $part_six   = $request['path']."/SQ".zfill($i,6)."-".$request[2];
-                               $part_three = $request['path']."/SQ".zfill($i,3)."-".$request[2];
-                               if(is_file($part_six))          @unlink($part_six);
-                               if(is_file($part_three))        @unlink($part_six);
-                       }
-                       #remove config file
-                       if(is_file($request['path'].'/'.$request[2].'.hidden'))         @unlink($request['path'].'/'.$request[2].'.hidden');
-                       if(is_file($request['path'].'/'.$request[2].'.Completed'))      @unlink($request['path'].'/'.$request[2].'.Completed');
-                       if(is_file($request['path'].'/'.$request[2].'.InProgress'))     @unlink($request['path'].'/'.$request[2].'.InProgress');
-                       if(is_file($request['path'].'/'.$request[2].'.Processed'))      @unlink($request['path'].'/'.$request[2].'.Processed');
-                       if(is_file($request['path'].'/'.$request[2].'.Starting'))       @unlink($request['path'].'/'.$request[2].'.Starting');
+function delete_file($h, $s) {
+       $request = $this->get_config($h);
+       if (strpos($request['path'], './uploads/ftp')) {
+               $filepath=$request['path'].'/'.$request[2];
+               #remove file
+               if (is_file($filepath))
+                       @unlink($filepath);
+               if (is_file($filepath.'.hidden'))
+                       @unlink($filepath.'.hidden');
+       } else {
+               #remove fileparts
+               for ($i=0;$i<=$request[5];$i++) {
+                       $part_six   = $request['path']."/SQ".zfill($i,6)."-".$request[2];
+                       $part_three = $request['path']."/SQ".zfill($i,3)."-".$request[2];
+                       if (is_file($part_six))
+                               @unlink($part_six);
+                       if (is_file($part_three))
+                               @unlink($part_six);
                }
-
-               #Update DB
-               $q="delete from file_hash where file_hash = '{$h}'";
-               mysql_query($q);
-               $q="insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','delete','".$s['user_id']."','".$s['user_name']."','".$_SERVER['REMOTE_ADDR']."',NOW())";
-               mysql_query($q);
-
-               #Send debug mail
-               $m_name=$s['user_name'];
-               $m_subject="Squasher Debug: File Deleted by {$m_name}";
-               $m_body="File Deleted: \n Requested by: {$m_name} \n File: {$filepath}";
-               mail('jasper@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
+               #remove config file
+               if (is_file($request['path'].'/'.$request[2].'.hidden'))        @unlink($request['path'].'/'.$request[2].'.hidden');
+               if (is_file($request['path'].'/'.$request[2].'.Completed'))     @unlink($request['path'].'/'.$request[2].'.Completed');
+               if (is_file($request['path'].'/'.$request[2].'.InProgress'))@unlink($request['path'].'/'.$request[2].'.InProgress');
+               if (is_file($request['path'].'/'.$request[2].'.Processed'))     @unlink($request['path'].'/'.$request[2].'.Processed');
+               if (is_file($request['path'].'/'.$request[2].'.Starting'))      @unlink($request['path'].'/'.$request[2].'.Starting');
        }
 
-       function show_files() {
+       #Update DB
+       $q = "delete from file_hash where file_hash = '{$h}'";
+       mysql_query($q);
+       $q = "insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','delete','".$s['user_id']."','".$s['user_name']."','".$_SERVER['REMOTE_ADDR']."',NOW())";
+       mysql_query($q);
+
+       #Send debug mail
+       $m_name = $s['user_name'];
+       $m_subject = "Squasher Debug: File Deleted by {$m_name}";
+       $m_body = "File Deleted: \n Requested by: {$m_name} \n File: {$filepath}";
+       mail('jasper@netformatie.nl', $m_subject, $m_body, "From: support@netformatie.nl");
+}
+
+function show_files() {
 
        $path = "./uploads/";
 
-       if ($dir = opendir($path)){
-               $i=1;
-               $last=1;
-               $files=array();
-               $files_merged=array();
-               while (false !== ($file = readdir($dir))) 
+       if ($dir = opendir($path)) {
+               $i = 1;
+               $last = 1;
+               $files = array();
+               $files_merged = array();
+               while (false !== ($file = readdir($dir)))
                {
-                       if (($file !== ".") && ($file !== "..")) 
-                       { 
+                       if (($file !== ".") && ($file !== ".."))
+                       {
                                $filename = $path.$file;
                                $handle = fopen($filename, "rb");
                                $size_this = filesize($filename);
-                               if ($i==1) $size_first = $size_this;
+                               if ($i==1)
+                                       $size_first = $size_this;
                                $filecontent = fread($handle, filesize($filename));
-                               $files[$i++]=$filename;
+                               $files[$i++] = $filename;
                                $files_merged[$file_base][]=$filename;
                                fclose($handle);
                        }
@@ -916,82 +985,82 @@ function print_files($path,$filename,$tovar = false){
        echo "</pre>";
 }
 
-       function set_mime($filename){
-               $ext_arr = explode('.',$filename);
-               $ext = strtolower(array_pop($ext_arr));
-               switch($ext){
-                       case 'avi':
-                               $mime = 'video/avi';
-                               break;
-                       case 'mpeg':
-                       case 'mpg':
-                               $mime = 'video/mpeg';                                   //MPEG Video
-                               break;
-                       case 'exe':
-                       case 'bat':
-                       case 'doc':
-                       case 'xls':
-                               $mime = 'application/octet-stream';
-                               break;
-                       case 'gif':
-                               $mime = 'image/gif';                                    //GIF Image
-                               break;
-                       case 'jpg':
-                       case 'jpeg':
-                               $mime = 'image/jpeg';                                   //JPEG Image
-                               break;
-                       case 'png':
-                               $mime = 'image/png';                                    //PNG Image
-                               break;
-                       case 'wav':
-                       case 'wave':
-                               $mime = 'audio/wav';                                    //WAV Audio
-                               break;
-                       case 'mp3':
-                               $mime = 'audio/mpeg';                                   //MP3 Audio
-                               break;
-                       case 'mov':
-                               $mime   =       'video/mov';                                    //Quicktime Video
-                               break;
-                       case 'wmv':
-                               $mime   =       'video/x-ms-wmv';                       //Windows WMV video
-                               break;
-                       case 'wma':
-                               $mime   =       'audio/x-ms-wma';                       //Windows WMA audio
-                               break;
-                       case 'rm':
-                               $mime   =       'audio/x-realaudio';    //RealPlayer Audio/Video (.rm)
-                               break;
-                       case 'ram':
-                               $mime   =       'audio/x-pn-realaudio'; //RealPlayer Audio/Video (.ram)
-                               break;
-                       case 'pdf':
-                               $mime   =       'application/pdf';              //PDF Document
-                               break;
-                       case 'doc':
-                               $mime   =       'application/msword';   //MS Word .doc file
-                               break;
-                       case 'zip':
-                               $mime   =       'application/zip';              //Zip File
-                               break;
-                       default:
-                               $mime = 'application/octet-stream';
-                               break;                          
-               }
-               //$return['mime']=$mime;
-               //$return['ext']=$ext;
-               
-               return $mime;
+function set_mime($filename) {
+       $ext_arr = explode('.', $filename);
+       $ext = strtolower(array_pop($ext_arr));
+       switch($ext) {
+               case 'avi':
+                       $mime = 'video/avi';
+                       break;
+               case 'mpeg':
+               case 'mpg':
+                       $mime = 'video/mpeg';                                   //MPEG Video
+                       break;
+               case 'exe':
+               case 'bat':
+               case 'doc':
+               case 'xls':
+                       $mime = 'application/octet-stream';
+                       break;
+               case 'gif':
+                       $mime = 'image/gif';                                    //GIF Image
+                       break;
+               case 'jpg':
+               case 'jpeg':
+                       $mime = 'image/jpeg';                                   //JPEG Image
+                       break;
+               case 'png':
+                       $mime = 'image/png';                                    //PNG Image
+                       break;
+               case 'wav':
+               case 'wave':
+                       $mime = 'audio/wav';                                    //WAV Audio
+                       break;
+               case 'mp3':
+                       $mime = 'audio/mpeg';                                   //MP3 Audio
+                       break;
+               case 'mov':
+                       $mime = 'video/mov';                                    //Quicktime Video
+                       break;
+               case 'wmv':
+                       $mime = 'video/x-ms-wmv';                       //Windows WMV video
+                       break;
+               case 'wma':
+                       $mime = 'audio/x-ms-wma';                       //Windows WMA audio
+                       break;
+               case 'rm':
+                       $mime = 'audio/x-realaudio';    //RealPlayer Audio/Video (.rm)
+                       break;
+               case 'ram':
+                       $mime = 'audio/x-pn-realaudio'; //RealPlayer Audio/Video (.ram)
+                       break;
+               case 'pdf':
+                       $mime = 'application/pdf';              //PDF Document
+                       break;
+               case 'doc':
+                       $mime = 'application/msword';   //MS Word .doc file
+                       break;
+               case 'zip':
+                       $mime = 'application/zip';              //Zip File
+                       break;
+               default:
+                       $mime = 'application/octet-stream';
+                       break;
        }
-       
-       function embed_video($h){
+       //$return['mime']=$mime;
+       //$return['ext']=$ext;
+
+       return $mime;
+}
+
+function embed_video($h) {
        /*JASPER FIX, use config->systemurl */
                ?>
       <!-- begin embedded WindowsMedia file... -->
       <table border='0' cellpadding='0' align="center">
       <tr><td>
       <OBJECT id='mediaPlayer'
-      classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' 
+      classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
       codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
       standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
       <param name='fileName' value="http://master.squasher.netformatie.nl/?x=asx&f=<?=$h;?>">
@@ -1003,8 +1072,8 @@ function print_files($path,$filename,$tovar = false){
                        <param name="BufferingTime" value="3">
       <EMBED type='application/x-mplayer2'
         pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
-        id='mediaPlayer' name='mediaPlayer' autosize='1' 
-        bgcolor='darkblue' showcontrols="true" showtracker='-1' 
+        id='mediaPlayer' name='mediaPlayer' autosize='1'
+        bgcolor='darkblue' showcontrols="true" showtracker='-1'
         showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='480' height='320'
         src="http://master.squasher.netformatie.nl/?x=asx&f=<?=$h;?>" autostart="true" designtimesp='5311' loop="true">
       </EMBED>
@@ -1020,13 +1089,13 @@ function print_files($path,$filename,$tovar = false){
                <?
        }
 
-       function create_playlist($h,$t='asx',$title='Title'){
-               switch ($t){
+function create_playlist($h, $t='asx', $title='Title') {
+       switch ($t) {
 
-                       case 'asx':
+               case 'asx':
 
-header('Content-Disposition: attachment; filename="stream.asx"');
-echo '<ASX version="3.0">
+                       header('Content-Disposition: attachment; filename="stream.asx"');
+                       echo '<ASX version="3.0">
 <title>Squasher Streaming Video</title>
        <Entry>
                <title>Video Stream</title>
@@ -1034,27 +1103,26 @@ echo '<ASX version="3.0">
        </Entry>
 </ASX>';
 
-                               break;
-
-                       case 'vlc':
+                       break;
 
-header('Content-Disposition: attachment; filename="stream.'.$t.'"');
-echo '#EXTM3U
+               case 'vlc':
+                       header('Content-Disposition: attachment; filename="stream.'.$t.'"');
+                       echo '#EXTM3U
 #EXTINF:-1,Squasher Streaming Video - '.$title.'
 http://master.squasher.netformatie.nl/?a=x&f='.$h.'';
-                       
-                               break;
 
-                       case 'm3u':
-                       default:
+                       break;
 
-header('Content-Disposition: attachment; filename="stream.m3u"');
-echo '#EXTM3U
+               case 'm3u':
+               default:
+                       header('Content-Disposition: attachment; filename="stream.m3u"');
+                       echo '#EXTM3U
 #EXTINF:-1,Squasher Streaming Video - '.$title.'
 http://master.squasher.netformatie.nl/?a=x&f='.$h.'';
-                       
-                               break;
+
+                       break;
                }
        }
 }
+// vim: syntax=php ts=4 sw=4 sts=4 sr noet
 ?>
index 9800b59a7ff3ca4ebdf5d37d2ab1a8ac00a9397e..bcd64a198cee433d5c9ee581d4bc67db5e824705 100644 (file)
@@ -1,5 +1,6 @@
 <?php
-if (!$_SESSION['creds']['validated'] && !isset($_GET['f']))exit();
+if (!$_SESSION['creds']['validated'] && !isset($_GET['f']))
+       exit();
 
 require_once("squasher.class.php");
 
@@ -9,34 +10,35 @@ $squashweb->update_history();
 
 //set root directory
 $basedir = "../uploads";
-if (isset($_GET['path']) && $_GET['path']!=NULL && strlen($_GET['path'])!=1){
+if (isset($_GET['path']) && $_GET['path']!=NULL && strlen($_GET['path'])!=1) {
        $subf = $_GET['path'];
        $path = $basedir . $subf;
-}
-else{
+} else {
        $path = $basedir;
 }
+
 $squashweb->set_root($basedir);
 
-if ((isset($_GET['f']) && $_GET['f']!=NULL) || (isset($_GET['d']) && $_GET['d']!=NULL) || $_GET['show_all']==true || $_GET['tools']=='hide' || $_GET['tools']=='unhide' || $_GET['tools']=='delete'){
+if ((isset($_GET['f']) && $_GET['f']!=NULL) || (isset($_GET['d']) && $_GET['d']!=NULL) || $_GET['show_all']==true || $_GET['tools']=='hide' || $_GET['tools']=='unhide' || $_GET['tools']=='delete') {
        $getdeepfiles=true;
        $populate=false;
-}else{
+} else {
        $getdeepfiles=false;
        $populate=true;
 }
 
 //update folder rights if form is submitted
-if($submitted['edited_user'] > 0 && $submitted['formtype'] == 'folderrights') $squashweb->update_rights($submitted,$_SESSION['creds']['user_level']);
+if ($submitted['edited_user'] > 0 && $submitted['formtype'] == 'folderrights')
+       $squashweb->update_rights($submitted,$_SESSION['creds']['user_level']);
 
 //set folder rights
-if (isset($_GET['f']) && $_GET['f']!=NULL){
+if (isset($_GET['f']) && $_GET['f']!=NULL) {
        $squashweb->give_rights(2);
-}else{
+} else {
        $squashweb->give_rights($_SESSION['creds']['user_id']);
 }
 
-if (isset($_GET['f']) && $_GET['f']!=NULL){
+if (isset($_GET['f']) && $_GET['f']!=NULL) {
        $f_q = "SELECT * FROM file_hash WHERE md5_hash = '".$_GET['f']."'";
        $f_r = mysql_query($f_q);
        $f_o = mysql_fetch_object($f_r);
@@ -44,138 +46,143 @@ if (isset($_GET['f']) && $_GET['f']!=NULL){
        //log downloads
        @mysql_query("INSERT INTO log (hash,file,action,user_id,user_name,ip,date) VALUES ('".$_GET['f']."','{$f_o->file}','download','".$_SESSION['creds']['user_id']."','".$_SESSION['creds']['user_name']."','".$_SERVER['REMOTE_ADDR']."',NOW())");
 
-       $_hpath_arr=explode("/",$f_o->file);
+       $_hpath_arr=explode("/", $f_o->file);
        $file=array_pop($_hpath_arr); //Remove filename
-       $path=implode("/",$_hpath_arr);
-       $squashweb->read_single_file($path,$file);
-       #$squashweb->read_directory($path,false,true,false,false);
-}else{
+       $path=implode("/", $_hpath_arr);
+       $squashweb->read_single_file($path, $file);
+       #$squashweb->read_directory($path, false, true, false, false);
+} else {
        //parse folders for readable files
-       $squashweb->read_directory($path,true,true,$getdeepfiles,$populate);
+       $squashweb->read_directory($path, true, true, $getdeepfiles, $populate);
 }
 
 //check if a file is requested
-if (isset($_GET['f']) && $_GET['f']!=NULL){
+if (isset($_GET['f']) && $_GET['f']!=NULL) {
        //get the config of requested file
        $request = $squashweb->get_config($_GET['f']);
-       
+
        //------------------------------------
        //-check-file-and-request-type--start-
        //------------------------------------
-       if (strpos($request['mime'],'ideo') && isset($_GET['d'])){ //embed video
-               $squashweb->embed_video($_GET['f']);    
+       if (strpos($request['mime'],'ideo') && isset($_GET['d'])) { //embed video
+               $squashweb->embed_video($_GET['f']);
        }
-       elseif (strpos($request['mime'],'ideo') && isset($_GET['x'])) //show stream playlist
+       elseif (strpos($request['mime'],'ideo') && isset($_GET['x'])) { //show stream playlist
                $squashweb->create_playlist($_GET['f'],$_GET['x'],$request[2]);
        }
-       else  //show requested file
+       else {  //show requested file
        #       header('Cache-control: private');
                header('Content-Disposition: attachment; filename="'.$request[2].'"');
                header("Content-Type: ".$request['mime']);
-               if($request[3])header('Content-Length: '.$request[3]);
+               if ($request[3])header('Content-Length: '.$request[3]);
                #@ob_flush();
                @flush();
-               $squashweb->print_files($request['path'],$request[2]);
+               $squashweb->print_files($request['path'], $request[2]);
        }
        //---------------------------------
        //-check-file-and-request-type-end-
        //---------------------------------
 
-}elseif ($tools=="hide" && isset($_GET['h'])){
-       if ($_SESSION['creds']['user_level'] > 99){
+} elseif ($tools=="hide" && isset($_GET['h'])) {
+       if ($_SESSION['creds']['user_level'] > 99) {
                $request = $squashweb->get_config($_GET['h']);
                $handle = fopen($request['path'].'/'.$request[2].'.hidden', 'x');
                fwrite($handle, 'hidden by '.$_SESSION['creds']['user_name']);
                fclose($handle);
-               $path=substr($request['path'],strlen($basedir));
+               $path=substr($request['path'], strlen($basedir));
                header( 'Location: '.$_SERVER['PHP_SELF'].'?path='.$path) ;
        }
-}elseif ($tools=="unhide" && isset($_GET['h'])){
-       if ($_SESSION['creds']['user_level'] > 99){
+} elseif ($tools=="unhide" && isset($_GET['h'])) {
+       if ($_SESSION['creds']['user_level'] > 99) {
                $request = $squashweb->get_config($_GET['h']);
                @unlink($request['path'].'/'.$request[2].'.hidden');
-               $path=substr($request['path'],strlen($basedir));
+               $path=substr($request['path'], strlen($basedir));
                header( 'Location: '.$_SERVER['PHP_SELF'].'?path='.$path) ;
        }
-}elseif ($tools=="delete" && isset($_GET['h'])){
-       if ($_SESSION['creds']['user_level'] > 99){
-               if ($_GET['h'] == "multiple"){
+} elseif ($tools=="delete" && isset($_GET['h'])) {
+       if ($_SESSION['creds']['user_level'] > 99) {
+               if ($_GET['h'] == "multiple") {
                        $h_post = $_POST['h'];
-                       foreach ($h_post as $h_key => $h){
+                       foreach ($h_post as $h_key => $h) {
                                $request = $squashweb->get_config($h);
-                               $squashweb->delete_file($h,$_SESSION['creds']);
+                               $squashweb->delete_file($h, $_SESSION['creds']);
                        }
-               }else{
+               } else {
                        $h = $_GET['h'];
                        $request = $squashweb->get_config($h);
-                       $squashweb->delete_file($h,$_SESSION['creds']);
+                       $squashweb->delete_file($h, $_SESSION['creds']);
                }
-               $path=substr($request['path'],strlen($basedir));
+               $path=substr($request['path'], strlen($basedir));
                header( 'Location: '.$_SERVER['PHP_SELF'].'?path='.$path);
        }
-}elseif ($_GET['tools']=='access' && $_SESSION['creds']['user_level'] > 100){
+} elseif (@$_GET['tools']=='access' && $_SESSION['creds']['user_level'] > 100) {
 
-require_once("smarty/Smarty.class.php");
+       require_once("smarty/Smarty.class.php");
 
-$smarty = new Smarty;
+       $smarty = new Smarty;
 
-       $smarty->assign('user_level',$_SESSION['creds']['user_level']);
-       $smarty->assign('user_name',$_SESSION['creds']['user_name']);
-       $smarty->assign('users',$squashweb->get_users($_SESSION['creds']['user_level']));
+       $smarty->assign('user_level', $_SESSION['creds']['user_level']);
+       $smarty->assign('user_name', $_SESSION['creds']['user_name']);
+       $smarty->assign('users', $squashweb->get_users($_SESSION['creds']['user_level']));
 
-       $smarty->assign('edited_user',$_GET['user']);
-       
-       $tree = $squashweb->show_rights_tree($path,0,$_GET['user']);
-       
-       $smarty->assign('style',$tree['style']);
-       $smarty->assign('layout',$tree['layout']);
-       
-       $smarty->assign('debug',$vars['debug']);
-       $smarty->assign('folderrights',$squashweb->folderrights());
-       $smarty->assign('userrights',$squashweb->userrights());
+       $smarty->assign('edited_user', $_GET['user']);
+
+       $tree = $squashweb->show_rights_tree($path, 0, $_GET['user']);
+
+       $smarty->assign('style', $tree['style']);
+       $smarty->assign('layout', $tree['layout']);
+
+       $smarty->assign('debug', $vars['debug']);
+       $smarty->assign('folderrights', $squashweb->folderrights());
+       $smarty->assign('userrights', $squashweb->userrights());
        $smarty->display('admin.tpl');
-       
-}elseif ($_GET['tools']=='users' && $_SESSION['creds']['user_level'] > 100){
 
-if ($submitted['type']=="update"){$squashweb->update_users($submitted);}
-if ($submitted['type']=="disable"){$squashweb->disable_users($submitted);}
-if ($submitted['type']=="delete"){$squashweb->remove_users($submitted);}
-if ($submitted['type']=="new"){$squashweb->insert_users($submitted,$_SESSION['creds']['user_level']);}
-require_once("smarty/Smarty.class.php");
+} elseif (@$_GET['tools']=='users' && $_SESSION['creds']['user_level'] > 100) {
 
-$smarty = new Smarty;
+       if ($submitted['type']=="update")
+               $squashweb->update_users($submitted);
+       if ($submitted['type']=="disable")
+               $squashweb->disable_users($submitted);
+       if ($submitted['type']=="delete")
+               $squashweb->remove_users($submitted);
+       if ($submitted['type']=="new")
+               $squashweb->insert_users($submitted, $_SESSION['creds']['user_level']);
+       require_once("smarty/Smarty.class.php");
+
+       $smarty = new Smarty;
 
-       $smarty->assign('user_level',$_SESSION['creds']['user_level']);
-       $smarty->assign('user_name',$_SESSION['creds']['user_name']);
-       $smarty->assign('users',$squashweb->get_users($_SESSION['creds']['user_level']));
+       $smarty->assign('user_level', $_SESSION['creds']['user_level']);
+       $smarty->assign('user_name', $_SESSION['creds']['user_name']);
+       $smarty->assign('users', $squashweb->get_users($_SESSION['creds']['user_level']));
 
-       if ($_SESSION['creds']['user_level'] > 199){
-       $smarty->assign('user_levels', array(155 => 'admin' , 55 => 'user' ) );
-       }else{
-       $smarty->assign('user_levels', array(55 => 'user' ) );
+       if ($_SESSION['creds']['user_level'] > 199) {
+               $smarty->assign('user_levels', array(155 => 'admin' , 55 => 'user' ) );
+       } else {
+               $smarty->assign('user_levels', array(55 => 'user' ) );
        }
        $smarty->assign('debug',$vars['debug']);
 
        $smarty->display('udmin.tpl');
 
-}elseif ($_GET['tools']=='logs' && $_SESSION['creds']['user_level'] > 100){
+} elseif ($_GET['tools']=='logs' && $_SESSION['creds']['user_level'] > 100) {
        $logtype=($_GET['logtype']) ? $_GET['logtype'] : 'all';
        require_once("smarty/Smarty.class.php");
 
        $smarty = new Smarty;
 
-       $smarty->assign('user_level',$_SESSION['creds']['user_level']);
-       $smarty->assign('user_name',$_SESSION['creds']['user_name']);
-       $smarty->assign('logtype',$logtype);
-       $smarty->assign('logs',$squashweb->get_logs($logtype));
+       $smarty->assign('user_level', $_SESSION['creds']['user_level']);
+       $smarty->assign('user_name', $_SESSION['creds']['user_name']);
+       $smarty->assign('logtype', $logtype);
+       $smarty->assign('logs', $squashweb->get_logs($logtype));
 
        $smarty->display('logs.tpl');
 
-}else{ //show overview
+} else {
+       //show overview
 
-require_once("smarty/Smarty.class.php");
+       require_once("smarty/Smarty.class.php");
 
-$smarty = new Smarty;
+       $smarty = new Smarty;
 
        /***
        *       $config:: array
@@ -187,70 +194,73 @@ $smarty = new Smarty;
        *       [5]     ->      chunkcount
        *       [6]     ->      CRC32 checksum
        ***/
-       
-$configs_num = $squashweb->get_configs();
-
-$configs_sorted = named_records_sort($configs_num,'lastchange',true);
-
-foreach ($configs_sorted AS $key => $value){
-       $configs[$key]['squashed'] = $value['squashed'];
-       $configs[$key]['version'] = $value[0];
-       //$configs[$key]['date'] = $value[1]; //removed because user local creation date is irrelevant
-       $configs[$key]['name'] = $value[2];
-       $configs[$key]['size'] = $value[3];
-       $configs[$key]['chunk_size'] = $value[4];
-       $configs[$key]['chunks'] = $value[5];
-       $configs[$key]['crc'] = $value[6];
-       $paths[substr($value['path'], strlen($basedir))]=array_pop(explode('/',$value['path']));
-       (strpos($value['mime'],'ideo')) ? $embedable=true : $embedable=false;   
-       (@array_sum($value['stats']) == $value[5]) ? $finished=true : $finished=false;
-
-       $configs[$key]['embedable'] = $embedable;
-       $configs[$key]['finished'] = $finished;
-       $configs[$key]['mime'] = $value['mime'];
-       $configs[$key]['status'] = $value['status'];
-       $configs[$key]['hidden'] = $value['hidden'];
-       $configs[$key]['chunks_finished'] = @array_sum($value['stats']);
-       if($finished){
-               $configs[$key]['chunks_partial'] = $configs[$key]['chunks_finished'];
-       }else{
-               $continue=true;
-               foreach($value['stats'] AS $sk => $sv){
-                       if($continue){
-                               $configs[$key]['chunks_partial']=$configs[$key]['chunks_partial']+$sv;
-                               if($sv != '1.00')$continue=false;
+
+       $configs_num = $squashweb->get_configs();
+
+       $configs_sorted = named_records_sort($configs_num, 'lastchange', true);
+
+       foreach ($configs_sorted as $key => $value) {
+               $configs[$key]['squashed'] = $value['squashed'];
+               $configs[$key]['version'] = $value[0];
+               //$configs[$key]['date'] = $value[1]; //removed because user local creation date is irrelevant
+               $configs[$key]['name'] = $value[2];
+               $configs[$key]['size'] = $value[3];
+               $configs[$key]['chunk_size'] = $value[4];
+               $configs[$key]['chunks'] = $value[5];
+               $configs[$key]['crc'] = $value[6];
+               $paths[substr($value['path'], strlen($basedir))]=array_pop(explode('/',$value['path']));
+               (strpos($value['mime'],'ideo')) ? $embedable=true : $embedable=false;
+               (@array_sum($value['stats']) == $value[5]) ? $finished=true : $finished=false;
+
+               $configs[$key]['embedable'] = $embedable;
+               $configs[$key]['finished'] = $finished;
+               $configs[$key]['mime'] = $value['mime'];
+               $configs[$key]['status'] = $value['status'];
+               $configs[$key]['hidden'] = $value['hidden'];
+               $configs[$key]['chunks_finished'] = @array_sum($value['stats']);
+               if ($finished) {
+                       $configs[$key]['chunks_partial'] = $configs[$key]['chunks_finished'];
+               } else {
+                       $continue = true;
+                       foreach($value['stats'] as $sk => $sv) {
+                               if ($continue) {
+                                       $configs[$key]['chunks_partial'] = $configs[$key]['chunks_partial']+$sv;
+                                       if ($sv != '1.00') $continue=false;
+                               }
                        }
                }
+               $configs[$key]['date'] = date('d.m.y - H:i:s - T', $value['added']);
+               $configs[$key]['lastchange'] = date('d.m.y - H:i:s - T', $value['lastchange']);
        }
-       $configs[$key]['date'] = date('d.m.y - H:i:s - T',$value['added']);
-       $configs[$key]['lastchange'] = date('d.m.y - H:i:s - T',$value['lastchange']);
-}
 
 
-//set base folders
-       $basepath['/']='&nbsp;top&nbsp;';
-foreach (explode('/',$subf) AS $key => $value){
-       if ($value != ''){
-               $bpath.='/'.$value;
-               $basepath[$bpath]=$value;
+       //set base folders
+       $basepath['/'] = '&nbsp;top&nbsp;';
+       foreach (explode('/',$subf) as $key => $value) {
+               if ($value != '') {
+                       $bpath .= '/'.$value;
+                       $basepath[$bpath] = $value;
+               }
        }
-}
-$smarty->assign('debug',$vars['debug']);
-$smarty->assign('user_level',$_SESSION['creds']['user_level']);
-$smarty->assign('user_name',$_SESSION['creds']['user_name']);
-$smarty->assign('folderrights',$squashweb->folderrights());
-
-$smarty->assign('squashed',$configs);
-$smarty->assign('paths',$paths);
-$smarty->assign('base',$basepath);
-$smarty->assign('currentfolder',$subf);
-$subs = $squashweb->subfolders();
-asort($subs);
-$smarty->assign('subfolders',$subs);
-
-//if($vars[debug])print_r($configs);
-if(!$vars['newtpl'])$smarty->display('index.tpl'); //Display normal template
-if($vars['newtpl'])$smarty->display('wip_massdelete.tpl'); //Display Work In Progress template
+       $smarty->assign('debug', $vars['debug']);
+       $smarty->assign('user_level', $_SESSION['creds']['user_level']);
+       $smarty->assign('user_name', $_SESSION['creds']['user_name']);
+       $smarty->assign('folderrights', $squashweb->folderrights());
+
+       $smarty->assign('squashed', $configs);
+       $smarty->assign('paths', $paths);
+       $smarty->assign('base', $basepath);
+       $smarty->assign('currentfolder', $subf);
+       $subs = $squashweb->subfolders();
+       asort($subs);
+       $smarty->assign('subfolders', $subs);
+
+       //if($vars[debug])print_r($configs);
+       if (!$vars['newtpl'])
+               $smarty->display('index.tpl'); //Display normal template
+       if ($vars['newtpl'])
+               $smarty->display('wip_massdelete.tpl'); //Display Work In Progress template
 
 }
+// vim: syntax=php ts=4 sw=4 sts=4 sr noet
 ?>