File:  [LON-CAPA] / loncom / interface / lonevaluate.pm
Revision 1.27: download - view: text, annotated - select for diffs
Wed Nov 26 10:51:36 2008 UTC (15 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Get rid of hardcoded styles and use standard LON-CAPA styles for headline, warning and success messages

    1: # The LearningOnline Network
    2: # Evaluate
    3: #
    4: # $Id: lonevaluate.pm,v 1.27 2008/11/26 10:51:36 bisitz 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/^http\:\/\///;
   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:     if ($env{'form.submiteval'} eq 'true') {
   80: # ------------------------------------------------ User is submitting something
   81:         my $complete=1;
   82: 	foreach my $item (@items) {
   83: 	    if ($env{'form.'.$item}) {
   84: 		$currenteval{$prefix.$item}=$env{'form.'.$item};
   85:             } elsif ($item ne 'comments') {
   86:                 $complete=0;
   87:             }
   88:         }
   89:         if ($complete) {
   90: 	    my $showurl=&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($feedurl));
   91: 	    my $js =<<ENDJS;
   92: <script type="text/javascript">
   93:     function goback() {
   94: 	if ((window.name=='loncapaclient')) {
   95:             window.location='$showurl';
   96:         } else {
   97:             self.close();
   98:         }
   99:     }
  100: </script>
  101: ENDJS
  102: 
  103:            my $start_page = &Apache::loncommon::start_page('Evaluate Resource',$js);
  104:            $r->print($start_page
  105:                      .'<h1>'.&mt('Thank you for your input!').'</h1>');
  106:            $r->print('<div class="LC_success">'
  107:                      .&mt('Saving feedback: [_1]'
  108:                          ,&Apache::lonnet::put('nohist_resevaldata',\%currenteval,$rdomain,$rauth))
  109:                      .'</div>');
  110:            unless ($already) {
  111: 	       $r->print('<br />'.&mt('Logging first evaluation'));
  112:            }
  113:            $r->print(
  114:             '<script type="text/javascript">setTimeout("goback()",2000);</script>'.&Apache::loncommon::end_page());
  115:            return OK;
  116:         } else {
  117: 	    $warning=&mt('Please fill out all fields below.');
  118:         }
  119:    
  120:     }
  121: 
  122: # ---------------------------------------------------------- Dial in old values
  123:     my $dialold='';
  124:     my $oldcomments='';
  125: 
  126:     foreach my $item (@items) {
  127:        unless ($item eq 'comments') {
  128:            unless (($item eq 'timestamp') || 
  129:                    (!defined($currenteval{$prefix.$item}))) {
  130:               $dialold.=
  131:                    'document.evaluation.'.$item.'.selectedIndex='.
  132:                    $currenteval{$prefix.$item}.";\n";
  133: 	   }
  134:        } else {
  135:            $oldcomments=$currenteval{$prefix.$item};
  136:        }       
  137:     }
  138: # ------------------------------------------------------- Print out eval screen
  139:     my %lt=&Apache::lonlocal::texthash('a' => 'Strongly Disagree',
  140: 				       'b' => 'Disagree',
  141: 				       'c' => 'Neutral',
  142: 				       'd' => 'Agree',
  143: 				       'e' => 'Strongly Agree',);
  144:     my $standardoptions='';
  145:     $standardoptions = (<<ENDOPTIONS);
  146: <option value="0">-</option>
  147: <option value="1">$lt{'a'}</option>
  148: <option value="2">$lt{'b'}</option>
  149: <option value="3">$lt{'c'}</option>
  150: <option value="4">$lt{'d'}</option>
  151: <option value="5">$lt{'e'}</option>
  152: ENDOPTIONS
  153: 
  154:     my $start_page = &Apache::loncommon::start_page('Evaluate Resource');
  155:     my $end_page   = &Apache::loncommon::end_page();
  156: 
  157:      %lt=&Apache::lonlocal::texthash(
  158:        'pleaserank' => 'Please rank the following criteria:',
  159:        'correct'    => 'The material appears to be correct',
  160:        'helpful'    => 'The material is helpful',
  161:        'depth'      => 'The material is covered with sufficient depth',
  162:        'clear'      => 'The material is presented in a clear way',
  163:        'technical'  => 'The resource is technically correct (loads fast enough, does not produce errors, links work, etc)',
  164:        'comments'   => 'Any comments?',
  165:        'submit'     => 'Submit Evaluation',
  166:     );
  167:     $r->print(<<ENDDOCUMENT);
  168: $start_page
  169: <h2>$title</h2>
  170: <p class="LC_warning">$warning</p>
  171: $lt{'pleaserank'}<br />
  172: <form method="post" name="evaluation" action="/adm/evaluate">
  173: <input type="hidden" name="submiteval" value="true" />
  174: <input type="hidden" name="postdata" value="$showurl" />
  175: <hr />
  176: $lt{'correct'}
  177: <br /><select name="correct">
  178: $standardoptions
  179: </select>
  180: <hr />
  181: $lt{'helpful'}
  182: <br /><select name="helpful">
  183: $standardoptions
  184: </select>
  185: <hr />
  186: $lt{'depth'}
  187: <br /><select name="depth">
  188: $standardoptions
  189: </select>
  190: <hr />
  191: $lt{'clear'}
  192: <br /><select name="clear">
  193: $standardoptions
  194: </select>
  195: <hr />
  196: $lt{'technical'}
  197: <br /><select name="technical">
  198: $standardoptions
  199: </select>
  200: <hr />
  201: $lt{'comments'}
  202: <br /><textarea name="comments" cols="40" rows="5">$oldcomments</textarea>
  203: <script type="text/javascript">$dialold</script>
  204: <br /><input type="submit" value="$lt{'submit'}" />
  205: </form>
  206: $end_page
  207: ENDDOCUMENT
  208:     return OK;
  209: } 
  210: 
  211: 1;
  212: __END__
  213: 
  214: =pod
  215: 
  216: =head1 NAME
  217: 
  218: Apache::lonevaluate.pm
  219: 
  220: =head1 SYNOPSIS
  221: 
  222: Handles evaluation.
  223: 
  224: This is part of the LearningOnline Network with CAPA project
  225: described at http://www.lon-capa.org.
  226: 
  227: =head1 OVERVIEW
  228: 
  229: None
  230: 
  231: =cut

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