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