--- loncom/interface/portfolio.pm 2006/11/05 21:08:53 1.170 +++ loncom/interface/portfolio.pm 2006/12/11 03:43:15 1.175 @@ -1,7 +1,7 @@ # The LearningOnline Network # portfolio browser # -# $Id: portfolio.pm,v 1.170 2006/11/05 21:08:53 raeburn Exp $ +# $Id: portfolio.pm,v 1.175 2006/12/11 03:43:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -101,7 +101,6 @@ sub display_common { # FIXME: This line should be deleted once Portfolio uses breadcrumbs $r->print(&Apache::loncommon::help_open_topic('Portfolio About', 'Help on the portfolio')); - $r->print(<<"TABLE"); <table id="LC_portfolio_actions"> <tr id="LC_portfolio_upload"> @@ -270,7 +269,9 @@ sub display_directory { $r->print(&Apache::loncommon::help_open_topic('Portfolio FileList', 'Using the portfolio file list')); $r->print('<table id="LC_browser">'. - '<tr><th colspan="2">Actions</th><th> </th><th> </th><th>Name'. + '<tr><th colspan="2">Actions'. + &Apache::loncommon::help_open_topic('Portfolio FileAction'). + '</th><th> </th><th> </th><th>Name'. &Apache::loncommon::help_open_topic('Portfolio OpenFile'). '</th><th>Size</th><th>Last Modified</th><th>Current Access Status'. &Apache::loncommon::help_open_topic('Portfolio ShareFile'). @@ -760,9 +761,16 @@ sub display_access { $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.'); $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.'); $info .= '</li><li>'.&explain_conditionals(); - $info .= '</li></ul>'; + $info .= '</li></ul>'. + &mt('A listing of files viewable without log-in is available at: ')."<a href=\"/adm/$udom/$uname/aboutme/portfolio\">http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio</a>.<br />"; if ($group eq '') { - $info .= (&mt("A listing of files viewable without log-in is available at: <a href='/adm/$udom/$uname/aboutme/portfolio'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio</a>.<br />For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:<br /><a href='/adm/$udom/$uname/aboutme'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme</a><br />")); + $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:"); + } else { + $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:"); + } + $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme</a><br />"; + if ($group ne '') { + $info .= &mt("Users with privileges to edit course contents may add a course information page to a course using the 'Course Info' button in DOCS").'<br />'; } } else { $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'. @@ -872,7 +880,7 @@ sub build_access_summary { if ($scope eq 'guest') { $r->print(&mt('Passphrase').': '.$content->{'password'}); } elsif ($scope eq 'course') { - $r->print('<table><tr>'); + $r->print('<table width="100%"><tr>'); $r->print('<th>'.&mt('Roles').'</th><th>'. &mt('Access').'</th><th>'. &mt('Sections').'</th>'); @@ -1334,7 +1342,7 @@ sub display_access_row { $r->print(&Apache::loncommon::start_data_table_header_row()); $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'. &mt('Dates available').'</th>'); - if ($type eq 'course') { + if ($type eq 'course' && $status eq 'old') { $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type). '</th>'); $colspan ++; @@ -1371,34 +1379,37 @@ sub display_access_row { sub course_js { return qq| <script type="text/javascript"> -function setRoleOptions(caller,num,cdom,cnum,type) { - addIndexnum = getCallerIndex(caller); - updateIndexnum = getIndex('update',num); - if (caller.checked) { - document.portform.elements[updateIndexnum].checked = true; - var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type; +function setRoleOptions(num,roleid,cdom,cnum,type) { + updateIndexNum = getIndexByValue('update',num); + var addItem = 'add_role_'+num; + var addIndexNum = getIndexByName(addItem); + if (document.portform.elements[addItem].checked) { + document.portform.elements[updateIndexNum].checked = true; + var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type; var title = 'Roles_Chooser'; var options = 'scrollbars=1,resizable=1,menubar=0'; options += ',width=700,height=600'; rolebrowser = open(url,title,options,'1'); rolebrowser.focus(); } else { - for (var j=0;j<5;j++) { - document.portform.elements[addIndexnum+j].value = ''; + addArray = new Array ('role','access','section','group'); + for (var j=0;j<addArray.length;j++) { + var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid); + document.portform.elements[itemIndex].value = ''; } } } -function getCallerIndex(caller) { +function getIndexByName(item) { for (var i=0;i<document.portform.elements.length;i++) { - if (document.portform.elements[i] == caller) { + if (document.portform.elements[i].name == item) { return i; } } return -1; } -function getIndex(name,value) { +function getIndexByValue(name,value) { for (var i=0;i<document.portform.elements.length;i++) { if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) { return i; @@ -1431,33 +1442,53 @@ sub course_row { my %course_description = &Apache::lonnet::coursedescription($cid); $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,undef,undef,$uctype).' <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,$uctype).' <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).'</td>'); - $r->print('<td><table><tr>'); - $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'. - &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'. - &mt('Groups').'</th></tr>'); + $r->print('<td>'.&dateboxes($num,$start,$end)); + my $newrole_id = 1; if ($status eq 'old') { + $r->print('</td><td>'); my $max_id = 0; - foreach my $role_id (sort(keys(%{$content->{'roles'}}))) { - if ($role_id > $max_id) { - $max_id = $role_id; - } - $max_id ++; - my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display'); - $r->print('<tr><td><span style="white-space: nowrap"><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><br />'.&mt('Add a roles-based condition').' <input type="checkbox" name ="add_role_'.$num.'" onClick="javascript:setRoleOptions(this,'."'$num','$content->{'domain'}','$content->{'number'}','$uctype'".')" value="'.$max_id.'" /><input type="hidden" name="role_'.$num.'_'.$max_id.'" /><input type="hidden" name="access_'.$num.'_'.$max_id.'" /><input type="hidden" name="section_'.$num.'_'.$max_id.'" /><input type="hidden" name="group_'.$num.'_'.$max_id.'" /></td>'); - } elsif ($status eq 'new') { - my $role_id = 1; - my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display'); - $r->print('<tr><td><input type="checkbox" name="add_role_'.$num.'" value="'.$role_id.'" checked="checked" />'.&mt('Add').'<input type="hidden" name="grplist_'.$num.'_'.$role_id.'" /></td>'.$role_selects); - $r->print('</tr></table></td>'); + if (keys(%{$content->{'roles'}}) > 0) { + $r->print('<table><tr><th>'.&mt('Action').'</th>'. + '<th>'.&mt('Roles').'</th>'. + '<th>'.&mt('Access').'</th>'. + '<th>'.&mt('Sections').'</th>'. + '<th>'.&mt('Groups').'</th></tr>'); + foreach my $role_id (sort(keys(%{$content->{'roles'}}))) { + if ($role_id > $max_id) { + $max_id = $role_id; + } + $max_id ++; + my $role_selects = &role_selectors($num,$role_id,$type,$content,'display'); + $r->print('<tr><td><span style="white-space: nowrap"><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>'); + } + $r->print('<br />'.&mt('Add a roles-based condition'). + ' <input type="checkbox" name ="add_role_'. + $num.'" onClick="javascript:setRoleOptions('."'$num', + '$max_id','$content->{'domain'}','$content->{'number'}', + '$uctype'".')" value="" />'); + $newrole_id = $max_id; + } else { + $r->print('<input type="hidden" name ="add_role_'.$num.'" value="" />'); } + $r->print(&add_course_role($num,$newrole_id)); + $r->print('</td>'); return; } +sub add_course_role { + my ($num,$max_id) = @_; + my $output; + $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'. + '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'. + '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'. + '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />'; + return $output; +} + sub domains_row { my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_; my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then, @@ -1560,21 +1591,12 @@ sub set_identifiers { } sub role_selectors { - my ($num,$role_id,$status,$type,$content,$caller) = @_; + my ($num,$role_id,$type,$content,$caller) = @_; my ($output,$cdom,$cnum,$longid); if ($caller eq 'display') { $longid = '_'.$num.'_'.$role_id; - if ($status eq 'new') { - foreach my $item ('role','access','section','group') { - $output .= '<td><select name="'.$item.$longid.'">'. - '<option value="">'.&mt('Pick [_1] first',$type). - '</option></select></td>'; - } - return $output; - } else { - $cdom = $$content{'domain'}; - $cnum = $$content{'number'}; - } + $cdom = $$content{'domain'}; + $cnum = $$content{'number'}; } elsif ($caller eq 'rolepicker') { $cdom = $env{'form.cdom'}; $cnum = $env{'form.cnum'}; @@ -1612,7 +1634,7 @@ sub role_selectors { 'role' => $allroles, 'access' => \@allaccesses, 'section' => $sections, - 'group' => $groups, + 'group' => $groups, ); foreach my $item ('role','access','section','group') { $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n"; @@ -1636,16 +1658,21 @@ sub role_selectors { sub role_options_window { my ($r) = @_; - my $cdom = $env{'form.cdom'}; - my $cnum = $env{'form.cnum'}; my $type = $env{'form.type'}; - my $addindex = $env{'form.setroles'}; - my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker'); + my $rolenum = $env{'form.setroles'}; + my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/); + my $role_elements; + foreach my $item ('role','access','section','group') { + $role_elements .= "'".$item.'_'.$rolenum."',"; + } + $role_elements =~ s/,$//; + my $role_selects = &role_selectors($num,$role_id,$type,undef, + 'rolepicker'); $r->print(<<"END_SCRIPT"); <script type="text/javascript"> function setRoles() { - var addidx = $addindex+1; - for (var i=0; i<4; i++) { + var role_elements = new Array($role_elements); + for (var i=0; i<role_elements.length; i++) { var copylist = ''; for (var j=0; j<document.rolepicker.elements[i].length; j++) { if (document.rolepicker.elements[i].options[j].selected) { @@ -1653,10 +1680,23 @@ function setRoles() { } } copylist = copylist.substr(0,copylist.length-1); - opener.document.portform.elements[addidx+i].value = copylist; + var openerItem = getIndexByName(role_elements[i]); + opener.document.portform.elements[openerItem].value = copylist; } + var roleAdder = getIndexByName('add_role_$num'); + opener.document.portform.elements[roleAdder].value = '$role_id'; self.close(); } + +function getIndexByName(item) { + for (var i=0;i<opener.document.portform.elements.length;i++) { + if (opener.document.portform.elements[i].name == item) { + return i; + } + } + return -1; +} + </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.')); @@ -1714,15 +1754,7 @@ sub upload { my ($r,$url,$group)=@_; my $fname=$env{'form.uploaddoc.filename'}; my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?) - my $disk_quota = 20000; # expressed in k - if (defined($group)) { - my $grp_quota = &get_group_quota($group); # quota expressed in k - if ($grp_quota ne '') { - $disk_quota = $grp_quota; - } else { - $disk_quota = 0; - } - } + my $disk_quota = &get_quota($group); $fname=&Apache::lonnet::clean_filename($fname); my $portfolio_root=&get_portfolio_root(); @@ -1988,6 +2020,23 @@ sub coursegrp_portfolio_header { return $output; } +sub get_quota { + my ($group) = @_; + my $disk_quota; + if (defined($group)) { + my $grp_quota = &get_group_quota($group); # quota expressed in k + if ($grp_quota ne '') { + $disk_quota = $grp_quota; + } else { + $disk_quota = 0; + } + } else { + $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'}, + $env{'user.domain'}); #expressed in Mb + $disk_quota = 1000 * $disk_quota; # convert from Mb to kb + } + return $disk_quota; +} sub handler { # this handles file management @@ -2084,6 +2133,13 @@ sub handler { $r->print(&Apache::loncommon::start_page($title)); } $r->rflush(); + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('port',$uname,$udom); + if ($blocked) { + $r->print($blocktext); + $r->print(&Apache::loncommon::end_page()); + return OK; + } if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){ $r->print('<span class="LC_error">'. 'No file was selected to upload.'.