File:  [LON-CAPA] / loncom / interface / lonevaluate.pm
Revision 1.31: download - view: text, annotated - select for diffs
Sat Apr 14 02:29:44 2018 UTC (6 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Bug 6754 LON-CAPA as LTI Provider
  - Original LTI launch of LON-CAPA is for a resource, a map, or an entire
    course, and display is for iframe, tab or window; retain this in %env.

    1: # The LearningOnline Network
    2: # Evaluate
    3: #
    4: # $Id: lonevaluate.pm,v 1.31 2018/04/14 02:29:44 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: 
   30: 
   31: package Apache::lonevaluate;
   32: 
   33: use strict;
   34: use Apache::lonnet;
   35: use Apache::Constants qw(:common);
   36: use Apache::loncommon();
   37: use Apache::lonenc();
   38: use Apache::lonlocal;
   39: use LONCAPA();
   40: 
   41: sub handler {
   42:     my $r = shift;
   43:     &Apache::loncommon::content_type($r,'text/html');
   44:     &Apache::loncommon::no_cache($r);
   45:     
   46:     $r->send_http_header;
   47:     return OK if $r->header_only;
   48: 
   49:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
   50:     my $feedurl=$env{'form.postdata'};
   51:     $feedurl=~s/^https?\:\/\///;
   52:     $feedurl=~s/^$ENV{'SERVER_NAME'}//;
   53:     $feedurl=~s/^$ENV{'HTTP_HOST'}//;
   54: 
   55:     $feedurl=&Apache::lonnet::declutter($feedurl);
   56: 
   57:     my $title=&Apache::lonnet::gettitle($feedurl);
   58:     my $showurl=&Apache::lonenc::check_encrypt($feedurl);
   59: 
   60:     my ($rdomain,$rauth)=($feedurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\//);
   61: 
   62:     my $prefix=$env{'user.name'}.'@'.$env{'user.domain'}.'___'.
   63: 	$feedurl.'___';
   64: 
   65:     my @items=('correct','helpful','depth','clear','technical','comments',
   66:                'timestamp');
   67: 
   68:     my @retrieve=map{ $prefix.$_ } @items;
   69: 
   70:     my %currenteval=
   71:        &Apache::lonnet::get('nohist_resevaldata',\@retrieve,$rdomain,$rauth);
   72: 
   73:     my $already=($currenteval{$prefix.'timestamp'} ne '');
   74: 
   75:     $env{'form.timestamp'}=time;
   76: 
   77:     my $warning='';
   78: 
   79:     my $windowname = 'loncapaclient';
   80:     if ($env{'request.lti.login'}) {
   81:         $windowname .= 'lti';
   82:     }
   83: 
   84:     if ($env{'form.submiteval'} eq 'true') {
   85: # ------------------------------------------------ User is submitting something
   86:         my $complete=1;
   87: 	foreach my $item (@items) {
   88: 	    if ($env{'form.'.$item}) {
   89: 		$currenteval{$prefix.$item}=$env{'form.'.$item};
   90:             } elsif ($item ne 'comments') {
   91:                 $complete=0;
   92:             }
   93:         }
   94:         if ($complete) {
   95: 	    my $showurl=&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($feedurl));
   96:             my $js = &Apache::lonhtmlcommon::scripttag(<<ENDJS);
   97:     function goback() {
   98:         if ((window.name=='$windowname')) {
   99:             window.location='$showurl';
  100:         } else {
  101:             self.close();
  102:         }
  103:     }
  104: ENDJS
  105: 
  106:             # Breadcrumbs
  107:             my $brcrum = [{'href' => '/adm/evaluate',
  108:                            'text' => 'Evaluate Resource'},
  109:                           {'href' => '',
  110:                            'text' => 'Done'}];
  111: 
  112:             my $start_page = &Apache::loncommon::start_page('Evaluate Resource',
  113:                                                             $js,
  114:                                                             {'bread_crumbs' => $brcrum,});
  115: 
  116:             $r->print($start_page
  117:                      .'<p class="LC_success">'
  118:                      .&mt('Saving feedback: [_1]'
  119:                           ,&Apache::lonnet::put(
  120:                                'nohist_resevaldata',\%currenteval,$rdomain,$rauth))
  121:                      .'</p>'
  122:             );
  123:            unless ($already) {
  124:                $r->print('<p>'.&mt('Logging first evaluation').'</p>');
  125:            }
  126:            $r->print('<p><b>'.&mt('Thank you for your input!').'</b></p>'
  127:                     .&Apache::lonhtmlcommon::scripttag(
  128:                         'setTimeout("goback()",2000);')
  129:                     .&Apache::loncommon::end_page()
  130:            );
  131:            return OK;
  132:         } else {
  133:             $warning=&mt('Please fill out all required fields below!');
  134:         }
  135:    
  136:     }
  137: 
  138: # ---------------------------------------------------------- Dial in old values
  139:     my $dialold='';
  140:     my $oldcomments='';
  141: 
  142:     foreach my $item (@items) {
  143:        unless ($item eq 'comments') {
  144:            unless (($item eq 'timestamp') || 
  145:                    (!defined($currenteval{$prefix.$item}))) {
  146:               $dialold.=
  147:                    'document.evaluation.'.$item.'.selectedIndex='.
  148:                    $currenteval{$prefix.$item}.";\n";
  149: 	   }
  150:        } else {
  151:            $oldcomments=$currenteval{$prefix.$item};
  152:        }       
  153:     }
  154: # ------------------------------------------------------- Print out eval screen
  155:     my %lt=&Apache::lonlocal::texthash('a' => 'Strongly Disagree',
  156: 				       'b' => 'Disagree',
  157: 				       'c' => 'Neutral',
  158: 				       'd' => 'Agree',
  159: 				       'e' => 'Strongly Agree',);
  160:     my $standardoptions='';
  161:     $standardoptions = (<<ENDOPTIONS);
  162: <option value="0">-</option>
  163: <option value="1">$lt{'a'}</option>
  164: <option value="2">$lt{'b'}</option>
  165: <option value="3">$lt{'c'}</option>
  166: <option value="4">$lt{'d'}</option>
  167: <option value="5">$lt{'e'}</option>
  168: ENDOPTIONS
  169: 
  170:     # Breadcrumbs
  171:     my $brcrum = [{'href' => '/adm/evaluate',
  172:                    'text' => 'Evaluate Resource'}];
  173: 
  174:     my $start_page = &Apache::loncommon::start_page('Evaluate Resource',
  175:                                                     undef,
  176:                                                     {'bread_crumbs' => $brcrum,});
  177:     my $end_page   = &Apache::loncommon::end_page();
  178: 
  179:     %lt=&Apache::lonlocal::texthash(
  180:        'pleaserank' => 'Please rank the following criteria:',
  181:        'required'   => '(All fields marked with * are required.)',
  182:        'correct'    => 'The material appears to be correct',
  183:        'helpful'    => 'The material is helpful',
  184:        'depth'      => 'The material is covered with sufficient depth',
  185:        'clear'      => 'The material is presented in a clear way',
  186:        'technical'  => 'The resource is technically correct (loads fast enough, does not produce errors, links work, etc)',
  187:        'comments'   => 'Comments',
  188:        'submit'     => 'Submit Evaluation',
  189:     );
  190:     $r->print(
  191:         $start_page
  192:        .'<h2>'.$title.'</h2>');
  193: 
  194:     if ($warning) {
  195:         $r->print(
  196:             &Apache::loncommon::confirmwrapper(
  197:                 &Apache::lonhtmlcommon::confirm_success(
  198:             $warning,1)));
  199:     }
  200:     $r->print(
  201:         '<form method="post" name="evaluation" action="/adm/evaluate">'
  202:        .'<input type="hidden" name="submiteval" value="true" />'
  203:        .'<input type="hidden" name="postdata" value="'.$showurl.'" />'
  204:     );
  205:     $r->print(
  206:         &Apache::lonhtmlcommon::start_pick_box()
  207:        .&Apache::lonhtmlcommon::row_headline()
  208:        .$lt{'pleaserank'}.'<br />'
  209:        .'<span class="LC_info">'.$lt{'required'}.'</span>'
  210:        .&Apache::lonhtmlcommon::row_closure()
  211:     );
  212: 
  213:     foreach my $key ('correct', 'helpful', 'depth', 'clear', 'technical') {
  214:         $r->print(
  215:             &Apache::lonhtmlcommon::row_title(
  216:                 '<span title="'.&mt('required').'">'.$lt{$key}
  217:                .' <span class="LC_info">*</span></span>')
  218:            .'<select name="'.$key.'">'
  219:            .$standardoptions
  220:            .'</select>'
  221:            .&Apache::lonhtmlcommon::row_closure()
  222:         );
  223:     }
  224: 
  225:     $r->print(
  226:         &Apache::lonhtmlcommon::row_title($lt{'comments'})
  227:        .'<textarea name="comments" cols="40" rows="5">'
  228:        .$oldcomments
  229:        .'</textarea>'
  230:        .&Apache::lonhtmlcommon::row_closure(1)
  231:        .&Apache::lonhtmlcommon::end_pick_box()
  232:        .'<p>'
  233:        .'<input type="submit" value="'.$lt{'submit'}.'" />'
  234:        .'</p>'
  235:     );
  236: 
  237:     $r->print(
  238:         &Apache::lonhtmlcommon::scripttag($dialold)
  239:        .'</form>'
  240:        .$end_page
  241:     );
  242: 
  243:     return OK;
  244: } 
  245: 
  246: 1;
  247: __END__
  248: 
  249: =pod
  250: 
  251: =head1 NAME
  252: 
  253: Apache::lonevaluate.pm
  254: 
  255: =head1 SYNOPSIS
  256: 
  257: Handles evaluation.
  258: 
  259: This is part of the LearningOnline Network with CAPA project
  260: described at http://www.lon-capa.org.
  261: 
  262: =head1 OVERVIEW
  263: 
  264: None
  265: 
  266: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>