File:  [LON-CAPA] / loncom / interface / lonevaluate.pm
Revision 1.24: download - view: text, annotated - select for diffs
Wed Nov 28 01:46:12 2007 UTC (16 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_2_7_X, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_99_1, version_2_5_99_0, HEAD
- &mt()ing

    1: # The LearningOnline Network
    2: # Evaluate
    3: #
    4: # $Id: lonevaluate.pm,v 1.24 2007/11/28 01:46:12 albertel 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: package Apache::lonevaluate;
   30: 
   31: use strict;
   32: use Apache::lonnet;
   33: use Apache::Constants qw(:common);
   34: use Apache::loncommon();
   35: use Apache::lonenc();
   36: use Apache::lonlocal;
   37: use LONCAPA();
   38: 
   39: sub handler {
   40:     my $r = shift;
   41:     &Apache::loncommon::content_type($r,'text/html');
   42:     &Apache::loncommon::no_cache($r);
   43:     
   44:     $r->send_http_header;
   45:     return OK if $r->header_only;
   46: 
   47:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
   48:     my $feedurl=$env{'form.postdata'};
   49:     $feedurl=~s/^http\:\/\///;
   50:     $feedurl=~s/^$ENV{'SERVER_NAME'}//;
   51:     $feedurl=~s/^$ENV{'HTTP_HOST'}//;
   52: 
   53:     $feedurl=&Apache::lonnet::declutter($feedurl);
   54: 
   55:     my $title=&Apache::lonnet::gettitle($feedurl);
   56:     my $showurl=&Apache::lonenc::check_encrypt($feedurl);
   57: 
   58:     my ($rdomain,$rauth)=($feedurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\//);
   59: 
   60:     my $prefix=$env{'user.name'}.'@'.$env{'user.domain'}.'___'.
   61: 	$feedurl.'___';
   62: 
   63:     my @items=('correct','helpful','depth','clear','technical','comments',
   64:                'timestamp');
   65: 
   66:     my @retrieve=map{ $prefix.$_ } @items;
   67: 
   68:     my %currenteval=
   69:        &Apache::lonnet::get('nohist_resevaldata',\@retrieve,$rdomain,$rauth);
   70: 
   71:     my $already=($currenteval{$prefix.'timestamp'} ne '');
   72: 
   73:     $env{'form.timestamp'}=time;
   74: 
   75:     my $warning='';
   76: 
   77:     if ($env{'form.submiteval'} eq 'true') {
   78: # ------------------------------------------------ User is submitting something
   79:         my $complete=1;
   80: 	foreach my $item (@items) {
   81: 	    if ($env{'form.'.$item}) {
   82: 		$currenteval{$prefix.$item}=$env{'form.'.$item};
   83:             } elsif ($item ne 'comments') {
   84:                 $complete=0;
   85:             }
   86:         }
   87:         if ($complete) {
   88: 	    my $showurl=&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($feedurl));
   89: 	    my $js =<<ENDJS;
   90: <script type="text/javascript">
   91:     function goback() {
   92: 	if ((window.name=='loncapaclient')) {
   93:             window.location='$showurl';
   94:         } else {
   95:             self.close();
   96:         }
   97:     }
   98: </script>
   99: ENDJS
  100: 
  101:             my $start_page = 
  102: 	        &Apache::loncommon::start_page('Evaluate Resource',$js);
  103: 	    $r->print('
  104: '.$start_page.'
  105: <h1>'.&mt('Thank you for your input!').'</h1>
  106: ');
  107:        $r->print(&mt('Saving feedback: [_1]',
  108: 		     &Apache::lonnet::put('nohist_resevaldata',\%currenteval,$rdomain,$rauth)));
  109:            unless ($already) {
  110: 	       $r->print('<br />'.&mt('Logging first evaluation'));
  111:            }
  112:            $r->print(
  113:             '<script type="text/javascript">setTimeout("goback()",2000);</script>'.&Apache::loncommon::end_page());
  114:            return OK;
  115:         } else {
  116: 	    $warning=&mt('Please fill out all fields below');
  117:         }
  118:    
  119:     }
  120: 
  121: # ---------------------------------------------------------- Dial in old values
  122:     my $dialold='';
  123:     my $oldcomments='';
  124: 
  125:     foreach my $item (@items) {
  126:        unless ($item eq 'comments') {
  127:            unless (($item eq 'timestamp') || 
  128:                    (!defined($currenteval{$prefix.$item}))) {
  129:               $dialold.=
  130:                    'document.evaluation.'.$item.'.selectedIndex='.
  131:                    $currenteval{$prefix.$item}.";\n";
  132: 	   }
  133:        } else {
  134:            $oldcomments=$currenteval{$prefix.$item};
  135:        }       
  136:     }
  137: # ------------------------------------------------------- Print out eval screen
  138:     my %lt=&Apache::lonlocal::texthash('a' => 'Strongly Disagree',
  139: 				       'b' => 'Disagree',
  140: 				       'c' => 'Neutral',
  141: 				       'd' => 'Agree',
  142: 				       'e' => 'Strongly Agree',);
  143:     my $standardoptions='';
  144:     $standardoptions = (<<ENDOPTIONS);
  145: <option value="0">-</option>
  146: <option value="1">$lt{'a'}</option>
  147: <option value="2">$lt{'b'}</option>
  148: <option value="3">$lt{'c'}</option>
  149: <option value="4">$lt{'d'}</option>
  150: <option value="5">$lt{'e'}</option>
  151: ENDOPTIONS
  152: 
  153:     my $start_page = &Apache::loncommon::start_page('Evaluate Resource');
  154:     my $end_page   = &Apache::loncommon::end_page();
  155: 
  156:      %lt=&Apache::lonlocal::texthash(
  157:        'pleaserank' => 'Please rank the following criteria:',
  158:        'correct'    => 'The material appears to be correct',
  159:        'helpful'    => 'The material is helpful',
  160:        'depth'      => 'The material is covered with sufficient depth',
  161:        'clear'      => 'The material is presented in a clear way',
  162:        'technical'  => 'The resource is technically correct (loads fast enough, does not produce errors, links work, etc)',
  163:        'comments'   => 'Any comments?',
  164:        'submit'     => 'Submit Evaluation',
  165:     );
  166:     $r->print(<<ENDDOCUMENT);
  167: $start_page
  168: <h2><tt>$title</tt></h2><br /><br />
  169: <h3><font color="red">$warning</font></h3>
  170: $lt{'pleaserank'}<br />
  171: <form method="post" name="evaluation" action="/adm/evaluate">
  172: <input type="hidden" name="submiteval" value="true" />
  173: <input type="hidden" name="postdata" value="$showurl" />
  174: <hr />
  175: $lt{'correct'}
  176: <br /><select name="correct">
  177: $standardoptions
  178: </select>
  179: <hr />
  180: $lt{'helpful'}
  181: <br /><select name="helpful">
  182: $standardoptions
  183: </select>
  184: <hr />
  185: $lt{'depth'}
  186: <br /><select name="depth">
  187: $standardoptions
  188: </select>
  189: <hr />
  190: $lt{'clear'}
  191: <br /><select name="clear">
  192: $standardoptions
  193: </select>
  194: <hr />
  195: $lt{'technical'}
  196: <br /><select name="technical">
  197: $standardoptions
  198: </select>
  199: <hr />
  200: $lt{'comments'}
  201: <br /><textarea name="comments" cols="40" rows="5">$oldcomments</textarea>
  202: <script type="text/javascript">$dialold</script>
  203: <br /><input type="submit" value="$lt{'submit'}" />
  204: </form>
  205: $end_page
  206: ENDDOCUMENT
  207:     return OK;
  208: } 
  209: 
  210: 1;
  211: __END__

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