--- loncom/interface/spreadsheet/lonspreadsheet.pm 2006/04/10 22:59:16 1.46 +++ loncom/interface/spreadsheet/lonspreadsheet.pm 2011/09/26 12:15:39 1.59 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.46 2006/04/10 22:59:16 albertel Exp $ +# $Id: lonspreadsheet.pm,v 1.59 2011/09/26 12:15:39 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,6 +64,7 @@ use Apache::lonnet; use Apache::lonhtmlcommon; use Apache::lonlocal; use Apache::loncoursedata(); +use Apache::lonquickgrades(); use HTML::Entities(); ## @@ -73,12 +74,12 @@ use HTML::Entities(); sub textfield { my ($title,$name,$value)=@_; return "\n

$title:
". - ''; + ''; } sub hiddenfield { my ($name,$value)=@_; - return ''."\n"; + return ''."\n"; } sub selectbox { @@ -86,7 +87,7 @@ sub selectbox { my $selout="\n

$title:
".''; @@ -140,13 +141,13 @@ sub file_dialogs { if ($spreadsheet->is_default()) { $filename = 'Default'; } - my $save_dialog = ''. + my $save_dialog = ''. ' '. ''. - ''; + ''; my $makedefault_dialog = ''; + 'value="'.&mt('Save as & Make This Sheet the Default').'"/>'; # my $link = '".&mt('Select Spreadsheet File').""; @@ -154,9 +155,9 @@ sub file_dialogs { my $load_dialog = < - + - $link + $link   \n \n\n"; # + my $headline = &mt('File Dialogs'); $result .=< - File Dialogs + $headline --> @@ -199,16 +201,6 @@ END sub handler { my $r=shift; # - # Overload checking - # - # Check this server - my $loaderror=&Apache::lonnet::overloaderror($r); - if ($loaderror) { return $loaderror; } - # Check the course homeserver - $loaderror= &Apache::lonnet::overloaderror($r, - $env{'course.'.$env{'request.course.id'}.'.home'}); -# if ($loaderror) { return $loaderror; } - # # HTML Header # if ($r->header_only) { @@ -226,15 +218,39 @@ sub handler { $r->uri.":opa:0:0:Cannot modify spreadsheet"; return HTTP_NOT_ACCEPTABLE; } + my ($sheettype) = ($r->uri=~/\/(\w+)$/); my $courseid = $env{'request.course.id'}; + + ## + ## Check permissions + my $allowed_to_edit = &Apache::lonnet::allowed('mgr', + $env{'request.course.id'}); + # Only those instructors/tas/whatevers with complete access + # (not section restricted) are able to modify spreadsheets. + my $allowed_to_view = &Apache::lonnet::allowed('vgr', + $env{'request.course.id'}); + if (! $allowed_to_view) { + $allowed_to_view = &Apache::lonnet::allowed('vgr', + $env{'request.course.id'}.'/'.$env{'request.course.sec'}); + # Those who are restricted by section are allowed to view. + # The routines in lonstatistics which decide which students' + # will be shown take care of the restriction by section. + } + # - # Do not allow students to continue if standard or external grading is in - # effect. + # Do not allow users without vgr or mgr priv to continue unless + # grading type is set to spreadsheet. # - if ($env{'request.role'} =~ /^st\./) { - if ($env{'course.'.$courseid.'.grading'} eq 'standard' || - $env{'course.'.$courseid.'.grading'} eq 'external' ) { - return HTTP_NOT_ACCEPTABLE; + + if ((!$allowed_to_view) && (!$allowed_to_edit)) { + if ($env{'course.'.$courseid.'.grading'} eq 'spreadsheet') { + if ($sheettype ne 'studentcalc') { + $r->internal_redirect('/adm/studentcalc'); + return OK; + } + } else { + $r->internal_redirect('/adm/quickgrades'); + return OK; } } # @@ -252,7 +268,6 @@ sub handler { } # # Determine basic information about the spreadsheet - my ($sheettype) = ($r->uri=~/\/(\w+)$/); # my $symb = undef; $symb = $env{'form.usymb'} if (exists($env{'form.usymb'})); @@ -266,47 +281,22 @@ sub handler { $env{'form.sdomain'} = $domain; my $section = &Apache::lonnet::getsection($domain,$name, $env{'request.course.id'}); - my $group; - my @groups = (); + my @groups; if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain)) { - @groups=&Apache::lonnet::sort_course_groups( - $env{'request.course.groups'}, - $env{'request.course.id'}); + @groups = &Apache::lonnet::sort_course_groups($env{'request.course.id'}, + split(':',$env{'request.course.groups'})); } else { - my $grouplist = &Apache::lonnet::get_users_groups($domain,$name, - $env{'request.course.id'}); - if ($grouplist) { - @groups=&Apache::lonnet::sort_course_groups($grouplist, + @groups = &Apache::lonnet::get_users_groups($domain,$name, $env{'request.course.id'}); - } - } - if (@groups > 0) { - $group = $groups[0]; } - ## - ## Check permissions - my $allowed_to_edit = &Apache::lonnet::allowed('mgr', - $env{'request.course.id'}); - # Only those instructors/tas/whatevers with complete access - # (not section restricted) are able to modify spreadsheets. - my $allowed_to_view = &Apache::lonnet::allowed('vgr', - $env{'request.course.id'}); - if (! $allowed_to_view) { - $allowed_to_view = &Apache::lonnet::allowed('vgr', - $env{'request.course.id'}.'/'.$env{'request.course.sec'}); - # Those who are restricted by section are allowed to view. - # The routines in lonstatistics which decide which students' - # will be shown take care of the restriction by section. - } # # Only those able to view others grades will be allowed to continue # if they are not requesting their own. if ($sheettype eq 'classcalc') { - if (! $allowed_to_view) { - $env{'user.error.msg'}= - $r->uri.":vgr:0:0:Access Permission Denied"; - return HTTP_NOT_ACCEPTABLE; + if (!$allowed_to_view) { + $r->internal_redirect('/adm/studentcalc'); + return OK; } } if ((($name ne $env{'user.name'} ) || @@ -348,10 +338,15 @@ sub handler { my $extra_javascript = &Apache::loncommon::browser_and_searcher_javascript(); + my $cell_extra_js = &Apache::loncommon::resize_textarea_js(); my $cell_edit_start = - &Apache::loncommon::start_page('Cell Edit Window',undef, + &Apache::loncommon::start_page('Cell Edit Window',$cell_extra_js, {'only_body' => 1, - 'js_ready' => 1,}); + 'js_ready' => 1, + 'add_entries' => { + 'onresize' => "resize_textarea('LC_newformula','LC_aftertextarea')", + 'onload' => "resize_textarea('LC_newformula','LC_aftertextarea')", + }}); my $cell_edit_end = &Apache::loncommon::end_page({'js_ready' => 1,}); @@ -369,9 +364,10 @@ sub handler { edit_text +='$cell_edit_start'; edit_text += ''; edit_text += '

$lt{'ce'} '+cellname+'

'; - edit_text += ''; + edit_text += '

'; edit_text += ' @@ -405,8 +402,18 @@ ENDSCRIPT faq => 134, bug => 'Spreadsheet'}); $r->print(&Apache::loncommon::start_page('Grades Spreadsheet',$js). - &Apache::lonhtmlcommon::breadcrumbs(undef,'Spreadsheet'). - ''); + &Apache::lonhtmlcommon::breadcrumbs('Spreadsheet', + 'Spreadsheet_About')); + + # + # Tabs + # + &Apache::lonquickgrades::startGradeScreen($r,'spreadsheet'); + + # + # Open the form + # + $r->print(''); $r->print(&hiddenfield('sname' ,$env{'form.sname'}). &hiddenfield('sdomain',$env{'form.sdomain'}). &hiddenfield('usymb' ,$env{'form.usymb'})); @@ -428,7 +435,7 @@ ENDSCRIPT if (exists($env{'form.recalc'})) { &Apache::loncoursedata::delete_caches($env{'requres.course.id'}); } - if ($env{'form.recalc'} eq 'ilovewastingtime') { + if ($env{'form.recalc'} eq 'expireallsheets') { &Apache::lonnet::logthis('spreadsheet expired: entire course'); # expire ALL spreadsheets &Apache::lonnet::expirespread('','','studentcalc'); @@ -467,15 +474,15 @@ ENDSCRIPT my $spreadsheet = undef; if ($sheettype eq 'classcalc') { $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef, - $section,$group); + $section,\@groups); } elsif ($sheettype eq 'studentcalc') { $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef, - $section,$group); + $section,\@groups); } elsif ($sheettype eq 'assesscalc' && defined($symb) && $allowed_to_edit) { $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb, - $section,$group); + $section,\@groups); } else { return HTTP_NOT_ACCEPTABLE; } @@ -548,7 +555,7 @@ END $r->print(&hiddenfield('filename',$filename)); # # Keep track of the number of times we have been called, sort of. - $r->print(&hiddenfield('not_first_run','whatever')); + $r->print(&hiddenfield('not_first_run','1')); # if (exists($env{'form.not_first_run'}) || $sheettype ne 'classcalc') { $r->print($spreadsheet->get_html_title()); @@ -558,7 +565,9 @@ END $r->rflush(); $spreadsheet->display($r); } - $r->print(''.&Apache::loncommon::end_page()); + $r->print(''); + &Apache::lonquickgrades::endGradeScreen($r); + $r->print(&Apache::loncommon::end_page()); $spreadsheet->clear_package(); return OK; }