--- /tmp/Ivica/og_files.module	2008-01-06 03:56:18.000000000 +0200
+++ og_files.module	2008-01-23 23:21:29.000000000 +0200
@@ -54,7 +54,15 @@ function og_files($gid) {
 
 function og_files_file_download($file) {
   global $user;
-  if(($user->uid != 1) && !db_result(db_query("SELECT o.uid FROM {og_uid} o, {files} f WHERE f.filepath = '%d' AND f.nid = o.nid AND o.uid = '%d' LIMIT 1",$file,$user->uid))) {
+
+  // Should only check files from 'og_files' dir. This is needed when drupal file system is
+  // set to private - then accessing files from /files dir is not possible because this function
+  // returns -1.
+  if (strpos($file, '/og_files/') === FALSE)
+    return;
+
+  // Sql is not created correctly - f.filepath = '%d' should be f.filepath = '%s'
+  if(($user->uid != 1) && !db_result(db_query("SELECT o.uid FROM {og_uid} o, {files} f WHERE f.filepath = '%s' AND f.nid = o.nid AND o.uid = '%d' LIMIT 1",$file,$user->uid))) {
     return -1;
   }
 }
@@ -131,8 +139,11 @@ function og_file_list_form($gid, $path){
     if((count($array) - $virtualpath_count) > 0) { //in a subdir
 
       
-      $dir_list[$array[0]] = l($array[0], og_files_virtual_base_path($gid).implode('/',$array));
-      $dir_count++;
+      // We just want to show first level of subfolders in current folder
+      if (count($array) - $virtualpath_count < 2) {
+        $dir_list[$array[count($array)-1]] = l($array[count($array)-1], og_files_virtual_base_path($gid).implode('/',$array));
+        $dir_count++;
+      }
 
     }
     else {
@@ -191,9 +202,16 @@ function og_file_list_form_submit($form_
     
     case t('Create directory'):
       $destination = 'node/'.$gid.'/files';
-      if($form_values['dir'][0] != '/')
-        $destination .= '/'.og_files_relative_path($form_values['gid'],$form_values['path']).'/';
+      if($form_values['dir'][0] != '/') {
+        // The last '/' should be added only if og_files_relative_path return nonempty string
+        // in other situation adding of '/' should be skiped.
+        $destination .= '/';
+        $relpath = og_files_relative_path($form_values['gid'],$form_values['path']);
+        if ($relpath)
+          $destination .= $relpath . '/';
+      }
       $destination .= $form_values['dir'];
+      drupal_set_message(t('Directory will be created when you upload first file in it.'));
       drupal_goto($destination);
       break;
     
@@ -202,6 +220,7 @@ function og_file_list_form_submit($form_
       $files = db_query('SELECT * FROM {files} WHERE nid = %d AND fid IN (%s)',$gid, $string);
       while($file = db_fetch_object($files)) {
         file_delete($file->filepath);
+        drupal_set_message(t('The file %file has been sucessful deleted.', array('%file' => $file->filename)));
       }
       db_query('DELETE FROM {files} WHERE nid = %d AND fid IN (%s)',$gid, $string);
   }
@@ -228,7 +247,7 @@ function og_files_format_path($gid, $fil
   return implode('/',$patharray);
 }
 
-function og_files_install() {
+/*function og_files_install() {
   //seems to be not working
   switch ($GLOBALS['db_type']) {
     case 'mysql':
@@ -240,7 +259,7 @@ function og_files_install() {
       );
       break;
   }
-}
+}*/
 
 function og_files_form_alter($form_id,&$form){
   if (!isset($form['#node']) || ($form_id != $form['#node']->type .'_node_form') || (!og_is_group_type($form['#node']->type)))
