Annotation of loncom/imspackages/imsexport.pm, revision 1.4
1.1 raeburn 1: # Copyright Michigan State University Board of Trustees
2: #
3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
4: #
5: # LON-CAPA is free software; you can redistribute it and/or modify
6: # it under the terms of the GNU General Public License as published by
7: # the Free Software Foundation; either version 2 of the License, or
8: # (at your option) any later version.
9: #
10: # LON-CAPA is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with LON-CAPA; if not, write to the Free Software
17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: #
19: # /home/httpd/html/adm/gpl.txt
20: #
21: # http://www.lon-capa.org/
22: #
23:
24: package Apache::imsexport;
25:
26: use strict;
27: use Apache::lonnet;
28:
29: sub simpleproblem {
1.2 raeburn 30: my ($symb) = @_;
31: my $output;
1.1 raeburn 32: my %qparms = &Apache::lonnet::dump('resourcedata',
1.3 albertel 33: $env{'course.'.$env{'request.course.id'}.'.domain'},
34: $env{'course.'.$env{'request.course.id'}.'.num'},
35: $env{'request.course.id'}.'.'.$symb);
1.1 raeburn 36: if ($symb) {
1.3 albertel 37: my $prefix=$env{'request.course.id'}.'.'.$symb.'.0.';
1.1 raeburn 38: my $qtype=$qparms{$prefix.'questiontype'};
39: my $qtext=$qparms{$prefix.'questiontext'};
40: my $hint=$qparms{$prefix.'hinttext'};
41: my %values = ();
42: my %foils = ();
43: if (($qtype eq 'radio') || ($qtype eq 'option')) {
44: my $maxfoils=$qparms{$prefix.'maxfoils'};
45: my $randomize=$qparms{$prefix.'randomize'};
46: if ($qtype eq 'option') {
47: my $options=$qparms{$prefix.'options'};
48: %values = &evaloptionhash($options);
1.2 raeburn 49: $output .= qq|
1.1 raeburn 50: <problem>
51: <optionresponse max="$maxfoils" randomize="$randomize">
52: <foilgroup options="$options">
53: |;
54: for (my $k=0; $k<10; $k++) {
55: my $iter = $k+1;
1.2 raeburn 56: $output .= ' <foil name="foil'.$k.'" value="'.$qparms{$prefix.'value'.$iter}.'"';
57: $output .= ' location="'.$qparms{$prefix.'position'.$iter}.'" ';
58: $output .= '><startouttext />'.$qparms{$prefix.'text'.$iter}.'<endouttext /></foil>'."\n";
1.1 raeburn 59: }
1.2 raeburn 60: chomp($output);
61: $output .= qq|
1.1 raeburn 62: </foilgroup>
63: |;
64: if ($hint) {
1.2 raeburn 65: $output .= '
1.1 raeburn 66: <hintgroup>
67: <hintpart on="default">
68: <startouttext />'.$hint.'<endouttext/>
69: </hintpart>
70: </hintgroup>';
71: }
1.2 raeburn 72: $output .= qq|
1.1 raeburn 73: </optionresponse>
74: </problem>
75: |;
76: } else {
1.2 raeburn 77: $output .= qq|
1.1 raeburn 78: <problem>
79: <radiobuttonresponse max="$maxfoils" randomize="$randomize">
80: <foilgroup>
81: |;
82: for (my $k=0; $k<10; $k++) {
83: my $iter = $k+1;
1.2 raeburn 84: $output .= ' <foil name="foil'.$k.'" value="'.$qparms{$prefix.'value'.$iter}.'"';
85: $output .= ' location="'.$qparms{$prefix.'position'.$iter}.'" ';
86: $output .= '><startouttext />'.$qparms{$prefix.'text'.$iter}.'<endouttext /></foil>'."\n";
1.1 raeburn 87: }
1.2 raeburn 88: chomp($output);
89: $output .= qq|
1.1 raeburn 90: </foilgroup>
91: |;
92: if ($hint) {
1.2 raeburn 93: $output .= '
1.1 raeburn 94: <hintgroup>
95: <hintpart on="default">
96: <startouttext />'.$hint.'<endouttext/>
97: </hintpart>
98: </hintgroup>';
99: }
1.2 raeburn 100: $output .= qq|
1.1 raeburn 101: </radiobuttonresponse>
102: </problem>
103: |;
104: }
105: } elsif ($qtype eq 'stringanswer') {
106: my $stringanswer = $qparms{$prefix.'stringanswer'};
107: my $stringtype=$qparms{$prefix.'stringtype'};
1.2 raeburn 108: $output .= qq|
1.1 raeburn 109: <problem>
110: <stringresponse answer="$stringanswer" type="$stringtype">
111: <textline>
112: </textline>
113: |;
114: if ($hint) {
1.2 raeburn 115: $output .= '
1.1 raeburn 116: <hintgroup>
117: <hintpart on="default">
118: <startouttext />'.$hint.'<endouttext/>
119: </hintpart>
120: </hintgroup>';
121: }
1.2 raeburn 122: $output .= qq|
1.1 raeburn 123: </stringresponse>
124: </problem>
125: |;
126: } else {
1.2 raeburn 127: $output .= qq|
1.1 raeburn 128: <problem>
129: <startouttext />$qtext<endouttext />
130: <essayresponse>
131: <textfield></textfield>
132: </essayresponse>
133: </problem>
134: |;
135: }
136: }
1.2 raeburn 137: return $output;
1.1 raeburn 138: }
139:
140: sub evaloptionhash {
141: my $options=shift;
142: $options=~s/^\(\'//;
143: $options=~s/\'\)$//;
144: my %returnhash=();
145: foreach (split(/\'\,\'/,$options)) {
146: $returnhash{$_}=$_;
147: }
148: return %returnhash;
149: }
150:
151: sub external {
152: my ($symb,$title) = @_;
153: my $output;
1.2 raeburn 154: if ($symb =~ m-\.sequence___\d+___ext(.+)$-) {
1.4 ! www 155: my $exturl = &unescape($1);
1.1 raeburn 156: $output = qq|
157: <html>
158: <head><title>$title</title>
159: </head>
160: <frameset rows="0,*" border="0">
1.2 raeburn 161: <frame src='' />
162: <frame src="http://$exturl" name="external" />
1.1 raeburn 163: </frameset>
164: </html>
165: |;
166: }
167: return $output;
168: }
169:
170: sub templatedpage {
171: my ($content_type,$timestamp,$count,$uploads,$udom,$uname) = @_;
1.3 albertel 172: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
173: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 174: my $output = '
175: <'.$content_type.'>';
176: my %syllabusdata=();
177: my %syllabusfields=();
178: if ($content_type eq 'syllabus') {
179: %syllabusfields=&Apache::lonlocal::texthash(
180: 'aaa_instructorinfo' => 'Instructor Information',
181: 'bbb_description' => 'Course Description',
182: 'ccc_prereq' => 'Prerequisites',
183: 'cdc_classhours' => 'Class Hours',
184: 'ddd_officehours' => 'Office Hours',
185: 'eee_helproom' => 'Helproom Hours',
186: 'efe_projectinfo' => 'Project Information',
187: 'fff_examinfo' => 'Exam Information',
188: 'fgf_deadlines' => 'Deadlines',
189: 'ggg_grading' => 'Grading Information',
190: 'hhh_readings' => 'Readings',
191: 'iii_coursepack' => 'Coursepack',
192: 'jjj_weblinks' => 'Web Links',
193: 'kkk_textbook' => 'Textbook',
194: 'lll_includeurl' => 'URLs To Include in Syllabus'
195: );
196: %syllabusdata = &Apache::lonnet::dump('syllabus',$cdom,$cnum);
197:
198: } elsif ($content_type eq 'simplepage') {
199: %syllabusfields=&Apache::lonlocal::texthash(
200: 'aaa_title' => 'Page Title',
201: 'bbb_content' => 'Content',
202: 'ccc_webreferences' => 'Web References'
203: );
204: %syllabusdata = &Apache::lonnet::dump('smppage_'.$timestamp,$cdom,$cnum);
205: } elsif ($content_type eq 'bulletinboard') {
206: %syllabusfields=&Apache::lonlocal::texthash(
207: 'aaa_title' => 'Topic',
208: 'bbb_content' => 'Task',
209: 'ccc_webreferences' => 'Web References'
210: );
211: %syllabusdata = &Apache::lonnet::dump('bulletinpage_'.$timestamp,$cdom,$cnum);
212: } elsif ($content_type eq 'aboutme') {
213: %syllabusdata=&Apache::lonnet::dump('aboutme',$udom,$uname);
214: %syllabusfields=&Apache::lonlocal::texthash(
215: 'aaa_contactinfo' => 'Contact Information',
216: 'bbb_aboutme' => 'About Me',
217: 'ccc_webreferences' => 'Web References'
218: );
219: $output .= qq|
220: <username>$uname</username>
221: <domain>$udom</domain>
222: |;
223: }
224: foreach (sort keys %syllabusfields) {
225: $output .= qq|
226: <$_>
227: <name>$syllabusfields{$_}</name>
228: <value>$syllabusdata{$_}</value>
229: </$_>|;
230: }
231: if (defined($syllabusdata{'uploaded.photourl'})) {
1.2 raeburn 232: if ($syllabusdata{'uploaded.photourl'} =~ m-/([^/]+)$-) {
233: push @$uploads, $syllabusdata{'uploaded.photourl'};
1.1 raeburn 234: }
235: $output .= '
236: <photo>
237: <filename>'.$count.'/'.$1.'</filename>
238: </photo>';
239: }
240: $output .= '
241: </'.$content_type.'>';
242: return $output;
243: }
244:
245: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>