Annotation of loncom/imspackages/imsexport.pm, revision 1.7

1.5       www         1: # The LearningOnline Network
                      2: #
1.7     ! raeburn     3: # $Id: imsexport.pm,v 1.6 2009/02/25 10:26:05 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;
1.7     ! raeburn    32: use LONCAPA;
1.1       raeburn    33: 
                     34: sub simpleproblem  {
1.2       raeburn    35:     my ($symb) = @_;
                     36:     my $output;
1.1       raeburn    37:     my %qparms = &Apache::lonnet::dump('resourcedata',
1.3       albertel   38:                   $env{'course.'.$env{'request.course.id'}.'.domain'},
                     39:                   $env{'course.'.$env{'request.course.id'}.'.num'},
                     40:                   $env{'request.course.id'}.'.'.$symb);
1.1       raeburn    41:     if ($symb) {
1.3       albertel   42:         my $prefix=$env{'request.course.id'}.'.'.$symb.'.0.';
1.1       raeburn    43:         my $qtype=$qparms{$prefix.'questiontype'};
                     44:         my $qtext=$qparms{$prefix.'questiontext'};
                     45:         my $hint=$qparms{$prefix.'hinttext'};
                     46:         my %values = ();
                     47:         my %foils = ();
                     48:         if (($qtype eq 'radio') || ($qtype eq 'option')) {
                     49:             my $maxfoils=$qparms{$prefix.'maxfoils'};
                     50:             my $randomize=$qparms{$prefix.'randomize'};
                     51:             if ($qtype eq 'option') {
                     52:                 my $options=$qparms{$prefix.'options'};
                     53:                 %values = &evaloptionhash($options);
1.2       raeburn    54:                 $output .= qq|
1.1       raeburn    55: <problem>
                     56:   <optionresponse max="$maxfoils" randomize="$randomize">
                     57:     <foilgroup options="$options">
                     58: |;
                     59:                 for (my $k=0; $k<10; $k++) {
                     60:                     my $iter = $k+1;
1.2       raeburn    61:                     $output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'value'.$iter}.'"';
                     62:                     $output .= ' location="'.$qparms{$prefix.'position'.$iter}.'" ';
                     63:                     $output .= '><startouttext />'.$qparms{$prefix.'text'.$iter}.'<endouttext /></foil>'."\n";
1.1       raeburn    64:                 }
1.2       raeburn    65:                 chomp($output);
                     66:                 $output .= qq|
1.1       raeburn    67:     </foilgroup>
                     68: |;
                     69:                 if ($hint) {
1.2       raeburn    70:                     $output .= '
1.1       raeburn    71:     <hintgroup>
                     72:      <hintpart on="default">
                     73:       <startouttext />'.$hint.'<endouttext/>
                     74:      </hintpart>
                     75:     </hintgroup>';
                     76:                 }
1.2       raeburn    77:                 $output .= qq|
1.1       raeburn    78:   </optionresponse>
                     79: </problem>
                     80: |;
                     81:             } else {
1.2       raeburn    82:                 $output .= qq|
1.1       raeburn    83: <problem>
                     84:   <radiobuttonresponse max="$maxfoils" randomize="$randomize">
                     85:    <foilgroup>
                     86: |;
                     87:                 for (my $k=0; $k<10; $k++) {
                     88:                     my $iter = $k+1;
1.2       raeburn    89:                     $output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'value'.$iter}.'"';
                     90:                     $output .= ' location="'.$qparms{$prefix.'position'.$iter}.'" ';
                     91:                     $output .= '><startouttext />'.$qparms{$prefix.'text'.$iter}.'<endouttext /></foil>'."\n";
1.1       raeburn    92:                 }
1.2       raeburn    93:                 chomp($output);
                     94:                 $output .= qq|
1.1       raeburn    95:    </foilgroup>
                     96: |;
                     97:                 if ($hint) {
1.2       raeburn    98:                     $output .= '
1.1       raeburn    99:    <hintgroup>
                    100:     <hintpart on="default">
                    101:      <startouttext />'.$hint.'<endouttext/>
                    102:     </hintpart>
                    103:    </hintgroup>';
                    104:                 }
1.2       raeburn   105:                 $output .= qq|
1.1       raeburn   106:   </radiobuttonresponse>
                    107: </problem>
                    108: |;
                    109:             }
                    110:         } elsif ($qtype eq 'stringanswer') {
                    111:             my $stringanswer = $qparms{$prefix.'stringanswer'};
                    112:             my $stringtype=$qparms{$prefix.'stringtype'};
1.2       raeburn   113:             $output .= qq|
1.1       raeburn   114: <problem>
                    115:   <stringresponse answer="$stringanswer" type="$stringtype">
                    116:     <textline>
                    117:     </textline>
                    118:             |;
                    119:             if ($hint) {
1.2       raeburn   120:                 $output .= '
1.1       raeburn   121:    <hintgroup>
                    122:     <hintpart on="default">
                    123:      <startouttext />'.$hint.'<endouttext/>
                    124:     </hintpart>
                    125:    </hintgroup>';
                    126:             }
1.2       raeburn   127:             $output .= qq|
1.1       raeburn   128:   </stringresponse>
                    129: </problem>
                    130: |;
                    131:         } else {
1.2       raeburn   132:             $output .= qq|
1.1       raeburn   133: <problem>
                    134:   <startouttext />$qtext<endouttext />
                    135:   <essayresponse>
                    136:   <textfield></textfield>
                    137:   </essayresponse>
                    138: </problem>
                    139: |;
                    140:         }
                    141:     }
1.2       raeburn   142:     return $output;
1.1       raeburn   143: }
                    144: 
                    145: sub evaloptionhash {
                    146:     my $options=shift;
                    147:     $options=~s/^\(\'//;
                    148:     $options=~s/\'\)$//;
                    149:     my %returnhash=();
                    150:     foreach (split(/\'\,\'/,$options)) {
                    151:         $returnhash{$_}=$_;
                    152:     }
                    153:     return %returnhash;
                    154: }
                    155: 
                    156: sub external {
                    157:     my ($symb,$title) = @_;
                    158:     my $output;
1.2       raeburn   159:     if ($symb =~  m-\.sequence___\d+___ext(.+)$-) {
1.4       www       160:         my $exturl = &unescape($1);
1.1       raeburn   161:         $output = qq|
                    162: <html>
                    163: <head><title>$title</title>
                    164: </head>
                    165: <frameset rows="0,*" border="0">
1.2       raeburn   166: <frame src='' />
                    167: <frame src="http://$exturl" name="external" />
1.1       raeburn   168: </frameset>
                    169: </html>
                    170:         |;
                    171:     }
                    172:     return $output;
                    173: }
                    174: 
                    175: sub templatedpage {
                    176:     my ($content_type,$timestamp,$count,$uploads,$udom,$uname) = @_;
1.3       albertel  177:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    178:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};  
1.1       raeburn   179:     my $output = '
                    180: <'.$content_type.'>';
                    181:     my %syllabusdata=();
                    182:     my %syllabusfields=();
                    183:     if ($content_type eq 'syllabus') {
                    184:         %syllabusfields=&Apache::lonlocal::texthash(
                    185:            'aaa_instructorinfo' => 'Instructor Information',
                    186:            'bbb_description'    => 'Course Description',
                    187:            'ccc_prereq'         => 'Prerequisites',
                    188:            'cdc_classhours'     => 'Class Hours',
                    189:            'ddd_officehours'    => 'Office Hours',
                    190:            'eee_helproom'       => 'Helproom Hours',
                    191:            'efe_projectinfo'    => 'Project Information',
                    192:            'fff_examinfo'       => 'Exam Information',
                    193:            'fgf_deadlines'      => 'Deadlines',
                    194:            'ggg_grading'        => 'Grading Information',
                    195:            'hhh_readings'       => 'Readings',
                    196:            'iii_coursepack'     => 'Coursepack',
                    197:            'jjj_weblinks'       => 'Web Links',
                    198:            'kkk_textbook'       => 'Textbook',
                    199:            'lll_includeurl'     => 'URLs To Include in Syllabus'
                    200:         );
                    201:         %syllabusdata = &Apache::lonnet::dump('syllabus',$cdom,$cnum);
                    202: 
                    203:     } elsif ($content_type eq 'simplepage') {
                    204:         %syllabusfields=&Apache::lonlocal::texthash(
                    205:            'aaa_title'         => 'Page Title',
                    206:            'bbb_content'       => 'Content',
                    207:            'ccc_webreferences' => 'Web References'
                    208:         );
                    209:         %syllabusdata = &Apache::lonnet::dump('smppage_'.$timestamp,$cdom,$cnum);
                    210:     } elsif ($content_type eq 'bulletinboard') {
                    211:         %syllabusfields=&Apache::lonlocal::texthash(
                    212:            'aaa_title'         => 'Topic',
                    213:            'bbb_content'       => 'Task',
                    214:            'ccc_webreferences' => 'Web References'
                    215:         );
                    216:         %syllabusdata = &Apache::lonnet::dump('bulletinpage_'.$timestamp,$cdom,$cnum);
                    217:     } elsif ($content_type eq 'aboutme') {
                    218:         %syllabusdata=&Apache::lonnet::dump('aboutme',$udom,$uname);
                    219:         %syllabusfields=&Apache::lonlocal::texthash(
                    220:            'aaa_contactinfo'   => 'Contact Information',
1.6       weissno   221:            'bbb_aboutme'       => 'Personal Information',
1.1       raeburn   222:            'ccc_webreferences' => 'Web References'
                    223:         );
                    224:         $output .= qq|
                    225:   <username>$uname</username>
                    226:   <domain>$udom</domain>
                    227: |;
                    228:     }
                    229:     foreach (sort keys %syllabusfields) {
                    230:         $output .= qq|
                    231: <$_>
                    232:  <name>$syllabusfields{$_}</name>
                    233:  <value>$syllabusdata{$_}</value>
                    234: </$_>|;
                    235:     }
                    236:     if (defined($syllabusdata{'uploaded.photourl'})) {
1.2       raeburn   237:         if ($syllabusdata{'uploaded.photourl'} =~  m-/([^/]+)$-) {
                    238:             push @$uploads, $syllabusdata{'uploaded.photourl'};
1.1       raeburn   239:         }
                    240:         $output .= '
                    241: <photo>
                    242:  <filename>'.$count.'/'.$1.'</filename>
                    243: </photo>';
                    244:     }
                    245:     $output .= '
                    246: </'.$content_type.'>';
                    247:     return $output;
                    248: }
                    249: 
                    250: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.