File:  [LON-CAPA] / loncom / imspackages / imsexport.pm
Revision 1.7: download - view: text, annotated - select for diffs
Fri Aug 28 17:17:25 2009 UTC (14 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, GCI_1, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
- &unescape() was moved from lonnet.pm to LONCAPA.pm some time ago.

    1: # The LearningOnline Network
    2: #
    3: # $Id: imsexport.pm,v 1.7 2009/08/28 17:17:25 raeburn Exp $
    4: #
    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: use LONCAPA;
   33: 
   34: sub simpleproblem  {
   35:     my ($symb) = @_;
   36:     my $output;
   37:     my %qparms = &Apache::lonnet::dump('resourcedata',
   38:                   $env{'course.'.$env{'request.course.id'}.'.domain'},
   39:                   $env{'course.'.$env{'request.course.id'}.'.num'},
   40:                   $env{'request.course.id'}.'.'.$symb);
   41:     if ($symb) {
   42:         my $prefix=$env{'request.course.id'}.'.'.$symb.'.0.';
   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);
   54:                 $output .= qq|
   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;
   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";
   64:                 }
   65:                 chomp($output);
   66:                 $output .= qq|
   67:     </foilgroup>
   68: |;
   69:                 if ($hint) {
   70:                     $output .= '
   71:     <hintgroup>
   72:      <hintpart on="default">
   73:       <startouttext />'.$hint.'<endouttext/>
   74:      </hintpart>
   75:     </hintgroup>';
   76:                 }
   77:                 $output .= qq|
   78:   </optionresponse>
   79: </problem>
   80: |;
   81:             } else {
   82:                 $output .= qq|
   83: <problem>
   84:   <radiobuttonresponse max="$maxfoils" randomize="$randomize">
   85:    <foilgroup>
   86: |;
   87:                 for (my $k=0; $k<10; $k++) {
   88:                     my $iter = $k+1;
   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";
   92:                 }
   93:                 chomp($output);
   94:                 $output .= qq|
   95:    </foilgroup>
   96: |;
   97:                 if ($hint) {
   98:                     $output .= '
   99:    <hintgroup>
  100:     <hintpart on="default">
  101:      <startouttext />'.$hint.'<endouttext/>
  102:     </hintpart>
  103:    </hintgroup>';
  104:                 }
  105:                 $output .= qq|
  106:   </radiobuttonresponse>
  107: </problem>
  108: |;
  109:             }
  110:         } elsif ($qtype eq 'stringanswer') {
  111:             my $stringanswer = $qparms{$prefix.'stringanswer'};
  112:             my $stringtype=$qparms{$prefix.'stringtype'};
  113:             $output .= qq|
  114: <problem>
  115:   <stringresponse answer="$stringanswer" type="$stringtype">
  116:     <textline>
  117:     </textline>
  118:             |;
  119:             if ($hint) {
  120:                 $output .= '
  121:    <hintgroup>
  122:     <hintpart on="default">
  123:      <startouttext />'.$hint.'<endouttext/>
  124:     </hintpart>
  125:    </hintgroup>';
  126:             }
  127:             $output .= qq|
  128:   </stringresponse>
  129: </problem>
  130: |;
  131:         } else {
  132:             $output .= qq|
  133: <problem>
  134:   <startouttext />$qtext<endouttext />
  135:   <essayresponse>
  136:   <textfield></textfield>
  137:   </essayresponse>
  138: </problem>
  139: |;
  140:         }
  141:     }
  142:     return $output;
  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;
  159:     if ($symb =~  m-\.sequence___\d+___ext(.+)$-) {
  160:         my $exturl = &unescape($1);
  161:         $output = qq|
  162: <html>
  163: <head><title>$title</title>
  164: </head>
  165: <frameset rows="0,*" border="0">
  166: <frame src='' />
  167: <frame src="http://$exturl" name="external" />
  168: </frameset>
  169: </html>
  170:         |;
  171:     }
  172:     return $output;
  173: }
  174: 
  175: sub templatedpage {
  176:     my ($content_type,$timestamp,$count,$uploads,$udom,$uname) = @_;
  177:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  178:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};  
  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',
  221:            'bbb_aboutme'       => 'Personal Information',
  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'})) {
  237:         if ($syllabusdata{'uploaded.photourl'} =~  m-/([^/]+)$-) {
  238:             push @$uploads, $syllabusdata{'uploaded.photourl'};
  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>