Annotation of loncom/interface/lonevaluate.pm, revision 1.23

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

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