--- loncom/interface/portfolio.pm	2010/02/02 07:09:41	1.212.2.3
+++ loncom/interface/portfolio.pm	2010/04/12 17:27:24	1.223
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.212.2.3 2010/02/02 07:09:41 raeburn Exp $
+# $Id: portfolio.pm,v 1.223 2010/04/12 17:27:24 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,7 +38,7 @@ use Apache::lonnet;
 use Apache::longroup;
 use Apache::lonhtmlcommon;
 use HTML::Entities;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
 
 sub group_args {
     my $output;
@@ -88,13 +88,12 @@ sub display_common {
 
         my $iconpath= $r->dir_config('lonIconsURL') . "/";
         my %lt=&Apache::lonlocal::texthash(
-					 'upload' => 'Upload',
-					 'upload_label' => 'Upload file to current directory',
-					 'createdir' => 'Create Subdirectory',
-					 'createdir_label' => 
-					 'Create subdirectory in current directory',
-                                         'parse' => 'If HTML file, upload embedded images/multimedia/css/linked files'
-                                            );
+                   'upload'          => 'Upload',
+                   'upload_label'    => 'Upload file to current directory',
+                   'createdir'       => 'Create Subdirectory',
+                   'createdir_label' => 'Create subdirectory in current directory',
+                   'parse'           => 'Upload embedded images/multimedia/css/linked files if HTML file',
+               );
         my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
 	my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
 	my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
@@ -105,8 +104,9 @@ sub display_common {
             $parse_check = <<"END";
         <br />
         <span class="LC_nobreak">
-         <label>$lt{'parse'}
-         <input type="checkbox" name="parserflag" checked="checked" />
+         <label>
+          <input type="checkbox" name="parserflag" checked="checked" />
+          $lt{'parse'}
          </label>
         </span>
 END
@@ -223,7 +223,7 @@ sub display_usage {
 '    <div id="meter3" style="display:block; background-color:'.$color.'; width:'.$prog_width.'%; height:10px; color:#000000; margin:0px;"></div>'."\n".
 '   </div>'."\n".
 '  </div>';
-    return $disk_meter;
+    return &Apache::loncommon::head_subbox($disk_meter);
 }
 
 sub display_directory_line {
@@ -236,7 +236,7 @@ sub display_directory_line {
     $r->print($line); # contains first two cells of table
     my $lock_info;
     if ($version_flag) { # versioned can't be versioned, so TRUE when root file
-        $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
+        $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" class="LC_fileicon" /></td>');
         $r->print('<td>'.$version_flag.'</td>');
     } else { # this is a graded or handed back file
         my ($user,$domain) = &get_name_dom($env{'form.group'});
@@ -287,7 +287,6 @@ sub display_directory {
     my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
         $can_modify,$can_delete,$can_setacl)=@_;
     my $iconpath= $r->dir_config('lonIconsURL') . "/";
-    my $display_out;
     my $select_mode;
     my $checked_files;
     my $port_path = &get_port_path();
@@ -304,30 +303,17 @@ sub display_directory {
     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
     my $now = time;
     if ($env{"form.mode"} eq 'selectfile') {
-	&select_files($r);
-	$checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
-	$select_mode = 'true';
-    } 
-    if ($is_empty && ($current_path ne '/') && $can_delete) {
-        $display_out = '<form method="post" action="'.$url.'">'.
-	    &group_form_data().
-        '<input type="hidden" name="action" value="deletedir" />'.
-        '<p>'.
-        '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
-        '</p>'.
-        '<input type="hidden" name="selectfile" value="" />'.
-        '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
-        '</form>';
-        
-        $r->print($display_out);
-	return;
+        &select_files($r);
+        $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
+        $select_mode = 'true';
     }
     if ($select_mode eq 'true') {
         $r->print('<form method="post" name="checkselect" action="'.$url.'">');
         $r->print(&Apache::loncommon::start_data_table()
                  .&Apache::loncommon::start_data_table_header_row()
                  .'<th>'.&mt('Select').'</th>'
-                 .'<th>&nbsp;</th><th>&nbsp;</th>'
+                 .'<th>&nbsp;</th>'
+                 .'<th>&nbsp;</th>'
                  .'<th>'.&mt('Name').'</th>'
                  .'<th>'.&mt('Size').'</th>'
                  .'<th>'.&mt('Last Modified').'</th>'
@@ -336,12 +322,18 @@ sub display_directory {
         );
     } else {
         $r->print('<form method="post" action="'.$url.'">');
-	$r->print(&Apache::loncommon::help_open_topic('Portfolio FileList',
-						      &mt('Using the portfolio file list')));
+        $r->print(
+            '<p>'
+           .&Apache::loncommon::help_open_topic(
+                'Portfolio FileList',
+                &mt('Using the portfolio file list'))
+           .'</p>'
+        );
         $r->print(&Apache::loncommon::start_data_table()
                  .&Apache::loncommon::start_data_table_header_row()
                  .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
-                 .'<th>&nbsp;</th><th>&nbsp;</th>'
+                 .'<th>&nbsp;</th>'
+                 .'<th>&nbsp;</th>'
                  .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
                  .'<th>'.&mt('Size').'</th>'
                  .'<th>'.&mt('Last Modified').'</th>'
@@ -349,6 +341,38 @@ sub display_directory {
                  .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
                  .&Apache::loncommon::end_data_table_header_row());
     }
+
+    # Empty directory?
+    if ($is_empty && ($current_path ne '/') && $can_delete) {
+        my $cols = ($select_mode eq 'true') ? 7 : 9;
+        # Empty message
+        $r->print(
+            &Apache::loncommon::start_data_table_row()
+           .'<td colspan="'.$cols.'">'
+           .'<p class="LC_info">'
+           .&mt('This directory is empty.')
+           .'</p>'
+           .'</td>'
+           .&Apache::loncommon::end_data_table_row()
+           .&Apache::loncommon::end_data_table()
+           .'</form>'
+        );
+        # Delete button
+        $r->print(
+            '<form method="post" action="'.$url.'">'.
+            &group_form_data().
+            '<input type="hidden" name="action" value="deletedir" />'.
+            '<p>'.
+            '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
+            '</p>'.
+            '<input type="hidden" name="selectfile" value="" />'.
+            '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
+            '</form>'
+        );
+        # Directory is empty, so nothing else to display
+        return;
+    }
+
     $r->print("\n".&group_form_data()."\n");
 
     my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
@@ -414,7 +438,7 @@ sub display_directory {
                     $colspan_fill=' colspan="4"';
                 }
 		$r->print('<tr class="LC_browser_folder">');
-                $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_closed.gif" /></td>'
+                $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'navmap.folder.closed.gif" class="LC_fileicon" /></td>'
                          .'<td>'.&mt('Go to ...').'</td>');
                 my %anchor_fields = (
                     'selectfile'    => $filename.'/',
@@ -880,7 +904,7 @@ sub display_access {
 sub explain_conditionals {
     return
         &mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').'<br />'."\n".
-        &mt('The conditions can include affiliation with a particular course, or a user account in a specific domain.').'<br />'."\n".
+        &mt('The conditions can include affiliation with a particular course or community, or a user account in a specific domain.').'<br />'."\n".
         &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.');
 }
 
@@ -921,7 +945,7 @@ sub build_access_summary {
                       guest => 'Passphrase-protected',
                       domains => 'Conditional: domain-based',
                       users => 'Conditional: user-based',
-                      course => 'Conditional: course-based',
+                      course => 'Conditional: course/community-based',
                      );
     my @allscopes = ('public','guest','domains','users','course');
     foreach my $scope (@allscopes) {
@@ -946,11 +970,16 @@ sub build_access_summary {
                 }
             }
             $r->print('<td>'.&mt($scope_desc{$scope}));
+            my $crstype;
             if ($scope eq 'course') {
                 if ($chg ne 'delete') {
                     my $cid = $content->{'domain'}.'_'.$content->{'number'};
                     my %course_description = &Apache::lonnet::coursedescription($cid);
                     $r->print('<br />('.$course_description{'description'}.')');
+                    $crstype = 'Course';
+                    if ($course_description{'type'} ne '') {
+                        $crstype = $course_description{'type'};
+                    }
                 }
             }
             $r->print('</td><td>'.&mt('Start: ').$showstart.
@@ -970,8 +999,6 @@ sub build_access_summary {
                         foreach my $item ('role','access','section','group') {
                             $r->print('<td>');
                             if ($item eq 'role') {
-                                my $ucscope = $scope;
-                                $ucscope =~ s/^(\w)/uc($1)/e;
                                 my $role_output;
                                 foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
                                     if ($role eq 'all') {
@@ -979,7 +1006,7 @@ sub build_access_summary {
                                     } elsif ($role =~ /^cr/) {
                                         $role_output .= (split('/',$role))[3].',';
                                     } else {
-                                        $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
+                                        $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
                                     }
                                 }
                                 $role_output =~ s/,$//;
@@ -1105,16 +1132,22 @@ sub update_access {
     my $totalnew = 0;
     my $status = 'new';
     my ($firstitem,$lastitem);
-    foreach my $newitem ('course','domains','users') {
+    my @types = ('course','domains','users');
+    foreach my $newitem (@types) {
         $allnew += $env{'form.new'.$newitem};
     }
     if ($allnew > 0) {
         my $now = time;
         my $then = $now + (60*60*24*180); # six months approx.
         &open_form($r,$url);
-        foreach my $newitem ('course','domains','users') {
+        my %showtypes = &Apache::lonlocal::texthash (
+           course  => 'course/community',
+           domains => 'domain',
+           users   => 'user',
+        );
+        foreach my $newitem (@types) {
             if ($env{'form.new'.$newitem} > 0) {
-                $r->print('<br />'.&mt('Add new <b>[_1]-based</b> access control for portfolio file: <b>[_2]</b>',&mt($newitem),$env{'form.currentpath'}.$env{'form.selectfile'}).'<br /><br />');
+                $r->print('<br />'.&mt('Add new [_1]-based[_2] access control for portfolio file: [_3]','<b>'.$showtypes{$newitem},'</b>','<b>'.$env{'form.currentpath'}.$env{'form.selectfile'}.'</b>').'<br /><br />');
                 $firstitem = $totalnew;
                 $lastitem = $totalnew + $env{'form.new'.$newitem};
                 $totalnew = $lastitem;
@@ -1391,10 +1424,12 @@ sub acl_status {
 
 sub access_element {
     my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
-    my $title = $type;
-    $title =~ s/s$//;
-    $title =~ s/^(\w)/uc($1)/e;
-    $r->print('<h3>'.&mt('[_1]-based conditional access: ',&mt($title)));
+    my %typetext = &Apache::lonlocal::texthash(
+        domains => 'Domain',
+        users   => 'User',
+        course  => 'Course/Community'
+    );
+    $r->print('<h3>'.&mt('[_1]-based conditional access: ',$typetext{$type}));
     if ($$acl_count{$type}) {
         $r->print($$acl_count{$type}.' ');
         if ($$acl_count{$type} > 1) {
@@ -1412,17 +1447,24 @@ sub access_element {
 
 sub display_access_row {
     my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
+    my $showtype;
+    if ($type eq 'course') {
+        $showtype = &mt('Courses/Communities');
+    } elsif ($type eq 'domains') {
+        $showtype = &mt('Domains');
+    } elsif ($type eq 'users') {
+        $showtype = &mt('Users');
+    }
     if (@{$items} > 0) {
         my @all_doms;
         my $colspan = 3;
-        my $uctype = $type;
-        $uctype =~ s/^(\w)/uc($1)/e;
         $r->print(&Apache::loncommon::start_data_table());
         $r->print(&Apache::loncommon::start_data_table_header_row());
-        $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
+        $r->print('<th>'.&mt('Action?').'</th><th>'.$showtype.'</th><th>'.
               &mt('Dates available').'</th>');
         if ($type eq 'course' && $status eq 'old') {
-            $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
+            
+            $r->print('<th>'.&mt('Allowed course/community affiliations').
                       '</th>');
             $colspan ++;
         } elsif ($type eq 'domains') {
@@ -1449,8 +1491,8 @@ sub display_access_row {
         }
         $r->print(&Apache::loncommon::end_data_table());
     } else {
-        $r->print(&mt('No [_1]-based conditions defined.',&mt($type)).'<br />'
-                  .&additional_item($type));
+        $r->print(&mt('No [_1]-based conditions defined.',$showtype).'<br />'.
+                  &additional_item($type));
     }
     return;
 }
@@ -1511,17 +1553,20 @@ sub course_row {
     }
     my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
 	.&course_js();
-    my $uctype = $type;
-    $uctype =~ s/^(\w)/uc($1)/e;
+    my $showtype = &mt('Course/Community');
+    my $crstype = 'Course';
     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
                                                     $type);
     $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
     if ($status eq 'old') {
         my $cid = $content->{'domain'}.'_'.$content->{'number'};
         my %course_description = &Apache::lonnet::coursedescription($cid);
+        if ($course_description{'type'} ne '') {
+            $crstype = $course_description{'type'};
+        }
         $r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
     } elsif ($status eq 'new') {
-        $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$uctype).'&nbsp;&nbsp;<input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
+        $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$showtype).'&nbsp;&nbsp;<input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
     }
     $r->print('<td>'.&dateboxes($num,$start,$end));
     my $newrole_id = 1;
@@ -1539,7 +1584,7 @@ sub course_row {
                     $max_id = $role_id;
                 }
                 $max_id ++;
-                my $role_selects = &role_selectors($num,$role_id,$type,$content,'display');
+                my $role_selects = &role_selectors($num,$role_id,$crstype,$content,'display');
                 $r->print('<tr><td><span class="LC_nobreak"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
             }
             $r->print('</table>');
@@ -1548,7 +1593,7 @@ sub course_row {
                   '&nbsp;<input type="checkbox" name="add_role_'.
                   $num.'" onClick="javascript:setRoleOptions('."'$num',
                   '$max_id','$content->{'domain'}','$content->{'number'}',
-                  '$uctype'".')" value="" />');
+                  '$showtype'".')" value="" />');
         $newrole_id = $max_id;
     } else {
         $r->print('<input type="hidden" name="add_role_'.$num.'" value="" />');
@@ -1609,7 +1654,15 @@ sub users_row {
 
 sub additional_item {
     my ($type) = @_;
-    my $output = &mt('Add new [_1] condition(s)?',&mt($type)).'&nbsp;'.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
+    my $showtype;
+    if ($type eq 'course') {
+        $showtype = &mt('course/community');
+    } elsif ($type eq 'domains') {
+        $showtype = &mt('domains');
+    } elsif ($type eq 'users') {
+        $showtype = &mt('users');
+    }
+    my $output = &mt('Add new [_1] condition(s)?',$showtype).'&nbsp;'.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
     return $output;
 }
 
@@ -1680,10 +1733,12 @@ sub role_selectors {
          $cdom = $env{'form.cdom'};
          $cnum = $env{'form.cnum'};
     }
-    my $uctype = $type;
-    $uctype =~ s/^(\w)/uc($1)/e;
+    my $crstype = 'Course';
+    if ($cnum =~ /^$match_community$/) {
+        $crstype = 'Community'
+    }
     my ($sections,$groups,$allroles,$rolehash,$accesshash) =
-            &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
+            &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$crstype);
     if (!@{$sections}) {
         @{$sections} = ('none');
     } else {
@@ -1778,8 +1833,23 @@ function getIndexByName(item) {
 
 </script>
 END_SCRIPT
-    $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
-    $r->print('<form name="rolepicker" action="/adm/portfolio" method="post"><table><tr><th>'.&mt('Roles').'</th><th>'.&mt('[_1] status',$type).'</th><th>'.&mt('Sections').'</th><th>'.&mt('Groups').'</th></tr><tr>'.$role_selects.'</tr></table><br /><input type="button" name="rolepickbutton" value="Save selections" onclick="setRoles()" />');
+    $r->print(
+        '<p>'
+       .&mt('Select roles, '.lc($type).' status, section(s) and group(s) for users'
+           .' who will be able to access the portfolio file.')
+       .'</p>'
+    );
+    $r->print(
+        '<form name="rolepicker" action="/adm/portfolio" method="post">'
+       .'<table><tr>'
+       .'<th>'.&mt('Roles').'</th>'
+       .'<th>'.&mt("$type status").'</th>'
+       .'<th>'.&mt('Sections').'</th>'
+       .'<th>'.&mt('Groups').'</th>'
+       .'</tr><tr>'.$role_selects.'</tr>'
+       .'</table><br />'
+       .'<input type="button" name="rolepickbutton" value="'.&mt('Save').'" onclick="setRoles()" />'
+    );
     return;
 }
 
@@ -2273,7 +2343,7 @@ sub handler {
     } else {
         ($uname,$udom) = &get_name_dom();
         $portfolio_root = &get_portfolio_root();
-        $title = &mt('Portfolio Manager');
+        $title = &mt('My Space');
         $can_modify = 1;
         $can_delete = 1;
         $can_upload = 1;