--- loncom/interface/spreadsheet/lonspreadsheet.pm 2005/04/07 06:56:23 1.40 +++ loncom/interface/spreadsheet/lonspreadsheet.pm 2013/07/15 14:33:06 1.64 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.40 2005/04/07 06:56:23 albertel Exp $ +# $Id: lonspreadsheet.pm,v 1.64 2013/07/15 14:33:06 bisitz 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:
".''; @@ -100,15 +101,19 @@ sub file_dialogs { my $message = ''; ## ## Deal with saving the spreadsheet + $spreadsheet->check_formulas_loaded(); if ((exists($env{'form.save'}) || exists($env{'form.makedefault'})) && exists($env{'form.savefilename'})) { $spreadsheet->filename($env{'form.savefilename'}); my $save_status = $spreadsheet->save(); if ($save_status ne 'ok') { - $message .= "An error occurred while saving the spreadsheet". - "There error is:".$save_status; + $message .= ''. + &mt('An error occurred while saving the spreadsheet. The error is: [_1].', + $save_status).''; } else { - $message .= "Spreadsheet saved as ".$spreadsheet->filename(); + $message .= ''.&mt('Spreadsheet saved as: [_1] .', + ''.$spreadsheet->filename().''). + ''; } } elsif (exists($env{'form.newformula'}) && exists($env{'form.cell'}) && @@ -139,13 +144,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').""; @@ -153,9 +158,9 @@ sub file_dialogs { my $load_dialog = < - + - $link + $link   \n \n\n"; # + my $headline = &mt('File Dialogs'); $result .=< - File Dialogs + $headline --> @@ -198,16 +204,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) { @@ -225,15 +221,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; } } # @@ -251,41 +271,47 @@ 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'})); my $name = $env{'user.name'}; my $domain = $env{'user.domain'}; + my $warning; if (exists($env{'form.sname'}) && $env{'form.sname'} ne '') { - $name = $env{'form.sname'}; - $domain = $env{'form.sdomain'}; + if (($env{'form.sname'} ne $env{'user.name'}) || + ($env{'form.sdomain'} ne $env{'user.domain'})) { + if (($allowed_to_view) || ($allowed_to_edit)) { + if (&Apache::lonnet::homeserver($env{'form.sname'},$env{'form.sdomain'}) ne 'no_host') { + $name = $env{'form.sname'}; + $domain = $env{'form.sdomain'}; + } else { + $warning = &mt('Requested user: "[_1]" does not exist; your own sheet is displayed instead.',$env{'form.sname'}.':'.$env{'form.sdomain'}); + } + } else { + $warning = &mt('Your current role is not permitted to display this sheet for the requested user: "[_1]"; your own sheet is displayed instead.',$env{'form.sname'}.':'.$env{'form.sdomain'}); + } + } } $env{'form.sname'} = $name; $env{'form.sdomain'} = $domain; - ## - ## 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. + my $section = &Apache::lonnet::getsection($domain,$name, + $env{'request.course.id'}); + my @groups; + if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain)) { + @groups = &Apache::lonnet::sort_course_groups($env{'request.course.id'}, + split(':',$env{'request.course.groups'})); + } else { + @groups = &Apache::lonnet::get_users_groups($domain,$name, + $env{'request.course.id'}); } + # # 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'} ) || @@ -313,20 +339,33 @@ sub handler { # # Header.... # - $r->print('LON-CAPA Spreadsheet'); my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); ## ## Spit out the javascript required for editing ## + my $js; if ($allowed_to_edit) { - my %lt=( + my %lt=&Apache::lonlocal::texthash( 'ce' => 'Cell', - 'ac' => 'Accept', - 'dc' => 'Discard Changes' + 'ac' => 'Save', + 'dc' => 'Cancel' ); my $extra_javascript = &Apache::loncommon::browser_and_searcher_javascript(); - $r->print(< 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,}); + + $js = < // @@ -375,9 +416,22 @@ ENDSCRIPT text => 'Spreadsheet', faq => 134, bug => 'Spreadsheet'}); - $r->print(''.&Apache::loncommon::bodytag('Grades Spreadsheet'). - &Apache::lonhtmlcommon::breadcrumbs(undef,'Spreadsheet'). - '
'); + $r->print(&Apache::loncommon::start_page('Grades Spreadsheet',$js). + &Apache::lonhtmlcommon::breadcrumbs('Spreadsheet', + 'Spreadsheet_About')); + + # + # Tabs + # + &Apache::lonquickgrades::startGradeScreen($r,'spreadsheet'); + + # + # Open the form + # + if ($warning) { + $r->print('

'.$warning.'

'); + } + $r->print(''); $r->print(&hiddenfield('sname' ,$env{'form.sname'}). &hiddenfield('sdomain',$env{'form.sdomain'}). &hiddenfield('usymb' ,$env{'form.usymb'})); @@ -399,7 +453,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'); @@ -437,13 +491,16 @@ ENDSCRIPT &Apache::Spreadsheet::initialize_spreadsheet_package(); my $spreadsheet = undef; if ($sheettype eq 'classcalc') { - $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef); + $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef, + $section,\@groups); } elsif ($sheettype eq 'studentcalc') { - $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef); + $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef, + $section,\@groups); } elsif ($sheettype eq 'assesscalc' && defined($symb) && $allowed_to_edit) { - $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb); + $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb, + $section,\@groups); } else { return HTTP_NOT_ACCEPTABLE; } @@ -478,14 +535,11 @@ ENDSCRIPT ''. '
'.$html."
\n"); if ($action_message ne '') { - $r->print(< -Last Action: -   - $action_message - - -END + $r->print( + &Apache::loncommon::confirmwrapper( + &mt('Last Action:') + .$action_message) + ); } $r->rflush(); } else { @@ -501,13 +555,13 @@ END if ($allowed_to_view) { $r->print(''. &Apache::loncommon::help_open_topic("Spreadsheet_About", - 'Spreadsheet Help'). + &mt('Spreadsheet Help')). ''); } if ($allowed_to_edit) { $r->print(''. &Apache::loncommon::help_open_topic("Spreadsheet_Editing", - 'Editing Help'). + &mt('Editing Help')). ''); } $r->print(''); @@ -516,7 +570,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()); @@ -526,7 +580,10 @@ END $r->rflush(); $spreadsheet->display($r); } - $r->print(''); + $r->print(''); + &Apache::lonquickgrades::endGradeScreen($r); + $r->print(&Apache::loncommon::end_page()); + $spreadsheet->clear_package(); return OK; }