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

1.1       www         1: # The LearningOnline Network
                      2: # Evaluate
                      3: #
1.22    ! bisitz      4: # $Id: lonevaluate.pm,v 1.21 2007/05/02 01:33:49 albertel 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.22    ! bisitz    138:     my %lt=&Apache::lonlocal::texthash('a' => 'Strongly Disagree', 'b' => 'Disagree'
        !           139:                                        , 'c' => 'Neutral', 'd' => 'Agree', 'e' => 'Strongly Agree');
        !           140:     my $standardoptions='';
        !           141:     $standardoptions = (<<ENDOPTIONS);
1.18      albertel  142: <option value="0">-</option>
1.22    ! bisitz    143: <option value="1">$lt{'a'}</option>
        !           144: <option value="2">$lt{'b'}</option>
        !           145: <option value="3">$lt{'c'}</option>
        !           146: <option value="4">$lt{'d'}</option>
        !           147: <option value="5">$lt{'e'}</option>
1.2       www       148: ENDOPTIONS
1.22    ! bisitz    149: 
1.19      albertel  150:     my $start_page = &Apache::loncommon::start_page('Evaluate Resource');
                    151:     my $end_page   = &Apache::loncommon::end_page();
1.22    ! bisitz    152: 
        !           153:      %lt=&Apache::lonlocal::texthash(
        !           154:        'pleaserank' => 'Please rank the following criteria:'
        !           155:      , 'correct' => 'The material appears to be correct'
        !           156:      , 'helpful' => 'The material is helpful'
        !           157:      , 'depth' => 'The material is covered with sufficient depth'
        !           158:      , 'clear' => 'The material is presented in a clear way'
        !           159:      , 'technical' => 'The resource is technically correct (loads fast enough, does not produce errors, links work, etc)'
        !           160:      , 'comments' => 'Any comments?'
        !           161:      , 'submit' => 'Submit Evaluation'
        !           162:     );
1.1       www       163:     $r->print(<<ENDDOCUMENT);
1.19      albertel  164: $start_page
1.22    ! bisitz    165: <h2><tt>$title</tt></h2><br /><br />
1.4       www       166: <h3><font color="red">$warning</font></h3>
1.22    ! bisitz    167: $lt{'pleaserank'}<br />
1.18      albertel  168: <form method="post" name="evaluation" action="/adm/evaluate">
                    169: <input type="hidden" name="submiteval" value="true" />
                    170: <input type="hidden" name="postdata" value="$showurl" />
1.22    ! bisitz    171: <hr />
        !           172: $lt{'correct'}
1.18      albertel  173: <br /><select name="correct">
1.2       www       174: $standardoptions
                    175: </select>
1.18      albertel  176: <hr />
1.22    ! bisitz    177: $lt{'helpful'}
1.18      albertel  178: <br /><select name="helpful">
1.2       www       179: $standardoptions
                    180: </select>
1.18      albertel  181: <hr />
1.22    ! bisitz    182: $lt{'depth'}
1.18      albertel  183: <br /><select name="depth">
1.2       www       184: $standardoptions
                    185: </select>
1.18      albertel  186: <hr />
1.22    ! bisitz    187: $lt{'clear'}
1.18      albertel  188: <br /><select name="clear">
1.2       www       189: $standardoptions
                    190: </select>
1.18      albertel  191: <hr />
1.22    ! bisitz    192: $lt{'technical'}
1.18      albertel  193: <br /><select name="technical">
1.2       www       194: $standardoptions
                    195: </select>
1.18      albertel  196: <hr />
1.22    ! bisitz    197: $lt{'comments'}
1.18      albertel  198: <br /><textarea name="comments" cols="40" rows="5">$oldcomments</textarea>
                    199: <script type="text/javascript">$dialold</script>
1.22    ! bisitz    200: <br /><input type="submit" value="$lt{'submit'}" />
1.2       www       201: </form>
1.19      albertel  202: $end_page
1.1       www       203: ENDDOCUMENT
                    204:     return OK;
                    205: } 
                    206: 
                    207: 1;
                    208: __END__

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