Index: og_files.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_files/Attic/og_files.module,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 og_files.module
--- og_files.module	17 May 2008 13:42:16 -0000	1.1.2.2
+++ og_files.module	28 Nov 2008 02:21:33 -0000
@@ -79,37 +79,41 @@ function og_file_list_form($gid, $path){
     '#type' => 'value',
     '#value' => $path,
   );
-  
-  $form['upload'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Upload a new file'),
-    '#collapsible' => true,
-    '#collapsed' => true
-  );
-  $form['upload']['file'] = array(
-    '#type' => 'file',
-    '#title' => t('File'),
-  );
-  $form['upload']['upload'] = array(
-    '#type' => 'submit',
-    '#value' => t('Upload'),
-  );
-  
-  $form['mkdir'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Create a new directory'),
-    '#collapsible' => true,
-    '#collapsed' => true
-  );
-  $form['mkdir']['dir'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Directory'),
-    '#description' => t('Type the directory name, multiple levels allowed. For example "foo/bar" creates the directories foo and foo/bar.'),
-  );
-  $form['mkdir']['createdir'] = array(
-    '#type' => 'submit',
-    '#value' => t('Create directory'),
-  );
+
+  if (user_access('upload files for group')) {
+    $form['upload'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Upload a new file'),
+      '#collapsible' => true,
+      '#collapsed' => true
+    );
+    $form['upload']['file'] = array(
+      '#type' => 'file',
+      '#title' => t('File'),
+    );
+    $form['upload']['upload'] = array(
+      '#type' => 'submit',
+      '#value' => t('Upload'),
+    );
+  }
+
+  if (user_access('create directories for group')) {  
+    $form['mkdir'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Create a new directory'),
+      '#collapsible' => true,
+      '#collapsed' => true
+    );
+    $form['mkdir']['dir'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Directory'),
+      '#description' => t('Type the directory name, multiple levels allowed. For example "foo/bar" creates the directories foo and foo/bar.'),
+    );
+    $form['mkdir']['createdir'] = array(
+      '#type' => 'submit',
+      '#value' => t('Create directory'),
+    );
+  }
   
   $file_list = array();
   $file_count = 0;
@@ -185,34 +189,38 @@ function og_file_list_form_submit($form_
   $gid = $form_values['gid'];
   switch($form_values['op']) {
     case t('Upload'):
-      //print('Upload a new file'); die;
-      $path = $form_values['path'];
-
-      //$return = file_check_directory($path,FILE_CREATE_DIRECTORY);
-      if (!is_dir($path) && mkdir($path, 0777, true)) {
-        @chmod($path, 0775);
-        drupal_set_message(t('The directory %directory has been created.', array('%directory' => $directory)));
+      if (user_access('upload files for group')) {
+        //print('Upload a new file'); die;
+        $path = $form_values['path'];
+
+        //$return = file_check_directory($path,FILE_CREATE_DIRECTORY);
+        if (!is_dir($path) && mkdir($path, 0777, true)) {
+          @chmod($path, 0775);
+          drupal_set_message(t('The directory %directory has been created.', array('%directory' => $directory)));
+        }
+
+        $file = file_save_upload('file', $path);
+        $fid = db_next_id('{files}_fid');
+        db_query("INSERT into {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s','%s','%s',%d)", $fid, $gid, $file->filename, $file->filepath, $file->filemime, $file->filesize);
+        drupal_set_message(t('The file %file has been sucessful uploaded.', array('%file' => $file->filename)));
       }
-
-      $file = file_save_upload('file',$path);
-      $fid = db_next_id('{files}_fid');
-      db_query("INSERT into {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s','%s','%s',%d)", $fid, $gid, $file->filename, $file->filepath, $file->filemime, $file->filesize);
-      drupal_set_message(t('The file %file has been sucessful uploaded.', array('%file' => $file->filename)));
       break;
     
     case t('Create directory'):
-      $destination = 'node/'.$gid.'/files';
-      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);
+      if (user_access('create directories for group')) {
+        $destination = 'node/'.$gid.'/files';
+        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;
     
     case t('Delete selected files'):
@@ -302,4 +310,11 @@ function og_files_nodeapi(&$node, $op, $
       db_query('DELETE FROM {og_files} WHERE gid = %d',$node->nid);
       break;
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function og_files_perm() {
+  return array('create directories for group', 'upload files for group');
+}
