Annotation of loncom/homework/lonsimpleproblemedit.pm, revision 1.1
1.1 ! www 1: # The LearningOnline Network
! 2: # Simple Problem Parameter Setting "Editor"
! 3: #
! 4: # $Id: lonsyllabus.pm,v 1.20 2003/06/20 13:31:46 www 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::lonsimpleproblemedit;
! 30:
! 31: use strict;
! 32: use Apache::Constants qw(:common :http);
! 33: use Apache::loncommon;
! 34: use Apache::lonnet;
! 35:
! 36: sub questiontext {
! 37: my $text=shift;
! 38: return (<<ENDQUESTION);
! 39: <table bgcolor="#dddd22" cellspacing="4" cellpadding="2">
! 40: <tr><td><b>Question Text</b><br />
! 41: <textarea name="questiontext" cols="80" rows="8">$text</textarea>
! 42: </td></tr>
! 43: </table>
! 44: <br />
! 45: ENDQUESTION
! 46: }
! 47:
! 48: sub hint {
! 49: my $text=shift;
! 50: return (<<ENDHINT);
! 51: <table bgcolor="#accacc" cellspacing="4" cellpadding="2">
! 52: <tr><td><b>Hint Text</b><br />
! 53: <textarea name="hinttext" cols="80" rows="4">$text</textarea>
! 54: </td></tr>
! 55: </table>
! 56: <br />
! 57: ENDHINT
! 58: }
! 59:
! 60: sub foil {
! 61: my ($number,$value,$position,$text,%values)=@_;
! 62: $values{'unused'}='Not shown, not used';
! 63: unless (defined($value)) { $value='unused'; }
! 64: unless ($values{$value}) { $value='unused'; }
! 65: my %positions=('random' => 'Random position',
! 66: 'top' => 'Show always at top position',
! 67: 'bottom' => 'Show always at bottom position');
! 68: unless (defined($position)) { $position='random'; }
! 69: unless ($positions{$position}) {
! 70: $position='random';
! 71: }
! 72: my $selectvalue=&Apache::loncommon::select_form
! 73: ($value,'value'.$number,%values);
! 74: my $selectposition=&Apache::loncommon::select_form
! 75: ($position,'position'.$number,%positions);
! 76: return (<<ENDFOIL);
! 77: <table bgcolor="#dd55ff" cellspacing="4" cellpadding="2">
! 78: <tr><td colspan="2"><b>Foil</b></td></tr>
! 79: <tr><td>Value: $selectvalue</td><td>Position: $selectposition</td></tr>
! 80: <tr><td colspan="2">Text:<br />
! 81: <textarea name="text$number" cols="80" rows="4">$text</textarea>
! 82: </td></tr>
! 83: </table>
! 84: <br />
! 85: ENDFOIL
! 86: }
! 87:
! 88: sub handler {
! 89: my $r = shift;
! 90:
! 91: if ($r->header_only) {
! 92: $r->content_type('text/html');
! 93: $r->send_http_header;
! 94: return OK;
! 95: }
! 96:
! 97: # -------------------------------------------------------------------- Allowed?
! 98: unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
! 99: return HTTP_NOT_ACCEPTABLE;
! 100: }
! 101: # ----------------------------------------------------------------- Send header
! 102: $r->content_type('text/html');
! 103: $r->send_http_header;
! 104: # ----------------------------------------------------- Figure out where we are
! 105: my $uri=$r->uri;
! 106: $uri=~s/\/smpedit$//;
! 107: my $symb=&Apache::lonnet::symbread($uri);
! 108:
! 109: # ---------------------------------------------------------- Anything to store?
! 110:
! 111: if (($symb) && ($ENV{'form.storeproblem'})) {
! 112: my %storecontent=();
! 113: undef %storecontent;
! 114: foreach (keys %ENV) {
! 115: if ($_=~/^form\.(\w+)$/) {
! 116: my $spnam=$1;
! 117: my $symbparm=$symb.'.'.$spnam;
! 118:
! 119: my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
! 120:
! 121: $storecontent{$courselevelr}=$ENV{'form.'.$spnam};;
! 122: }
! 123: }
! 124: my $reply=&Apache::lonnet::cput
! 125: ('resourcedata',\%storecontent,
! 126: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
! 127: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
! 128:
! 129: }
! 130: # ------------------------------------------------------------ Print the screen
! 131: $r->print(<<ENDDOCUMENT);
! 132: <html>
! 133: <head>
! 134: <title>The LearningOnline Network with CAPA</title>
! 135: ENDDOCUMENT
! 136: $r->print(&Apache::loncommon::bodytag('Simple Problem Editor'));
! 137: if ($symb) {
! 138: $r->print('<h1>'.&Apache::lonnet::gettitle($symb).'</h1>');
! 139: #
! 140: #
! 141: $r->print(&questiontext('What color?').
! 142: &foil(3,'green','bottom','Tomato',
! 143: ('green'=>'green','red'=>'red')).
! 144: &hint('This is the hint.'));
! 145: #
! 146: #
! 147:
! 148: } else {
! 149: $r->print('Could not identify problem.');
! 150: }
! 151: $r->print('</body></html>');
! 152: return OK;
! 153: }
! 154:
! 155: 1;
! 156: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>