[LON-CAPA-cvs] cvs: loncom /imspackages imsexport.pm /interface londocs.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 23 Dec 2004 16:31:28 -0000


This is a MIME encoded message

--raeburn1103819488
Content-Type: text/plain

raeburn		Thu Dec 23 11:31:28 2004 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
    /loncom/imspackages	imsexport.pm 
  Log:
  IMS exports now include photos uploaded to templated pages.  simpleproblems now exported correctly and output stored.
  
  
--raeburn1103819488
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20041223113128.txt"

Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.158 loncom/interface/londocs.pm:1.159
--- loncom/interface/londocs.pm:1.158	Thu Dec 23 09:00:58 2004
+++ loncom/interface/londocs.pm	Thu Dec 23 11:31:27 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.158 2004/12/23 14:00:58 raeburn Exp $
+# $Id: londocs.pm,v 1.159 2004/12/23 16:31:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -486,6 +486,9 @@
     if (!-e $$tempexport) {
         mkdir($$tempexport,0700);
     }
+    if (!-e "$$tempexport/resources") {
+        mkdir("$$tempexport/resources",0700);
+    }
 # open manifest file
     my $manifest = '/imsmanifest.xml';
     my $manifestfilename = $$tempexport.$manifest;
@@ -609,7 +612,7 @@
                             }
                             my %extras = (
                                           caller => 'imsexport',
-                                          tempexport => $tempexport,
+                                          tempexport => $tempexport.'/resources',
                                           count => $count
                                          );
                             my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
@@ -729,7 +732,7 @@
     if (@uploads > 0) {
         foreach my $item (@uploads) {
             my $uploadmsg = '';
-            &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'uploaded');
+            &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
             if ($uploadmsg) {
                 $$copyresult .= $uploadmsg."\n";
             }
@@ -742,9 +745,13 @@
 
 sub replicate_content {
     my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
-    my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
-    my $feedurl = &Apache::lonnet::clutter($url);
-
+    my ($map,$ind,$url);
+    if ($caller eq 'templateupload') {
+        $url = $symb;
+        $url =~ s#//#/#g;
+    } else { 
+        ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
+    }
     my $content;
     my $filename;
     my $repstatus;
@@ -769,7 +776,7 @@
                     &extract_media($content,$count,$tempexport,$href,'resource');
                     $repstatus = 'ok';
                 }
-            } elsif ($caller eq 'noedit' || $caller eq 'uploaded') {
+            } elsif ($caller eq 'noedit' || $caller eq 'uploaded' || $caller eq 'templateupload') {
                 my $rtncode;
                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
                 if ($repstatus eq 'ok') {
@@ -788,7 +795,7 @@
             $$message = 'Could not open destination file for '.$filename."\n";
         }
     } else {
-        $$message = 'Could not determine name of file for '.$url."\n";
+        $$message = 'Could not determine name of file for '.$symb."\n";
     }
     if ($repstatus eq 'ok') {
         $content_name = $count.'/'.$filename;
@@ -808,13 +815,25 @@
 sub store_template {
     my ($contents,$tempexport,$count,$content_type) = @_;
     if ($contents) {
-        my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
-        my $storetemplate;
-        if ($storetemplate = Apache::File->new('>'.$destination)) {
-            print $storetemplate $contents;
-            close($storetemplate);
+        if ($tempexport) {
+            if (!-e $tempexport.'/resources') {
+                mkdir($tempexport.'/resources',0700);
+            }
+            if (!-e $tempexport.'/resources/'.$count) {
+                mkdir($tempexport.'/resources/'.$count,0700);
+            }
+            my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
+            my $storetemplate;
+            if ($storetemplate = Apache::File->new('>'.$destination)) {
+                print $storetemplate $contents;
+                close($storetemplate);
+            }
+            if ($content_type eq 'external') {
+                return $count.'/'.$content_type.'.html';
+            } else {
+                return $count.'/'.$content_type.'.xml';
+            }
         }
-        return $count.'/'.$content_type.'.xml';
     }
 }
 
Index: loncom/imspackages/imsexport.pm
diff -u loncom/imspackages/imsexport.pm:1.1 loncom/imspackages/imsexport.pm:1.2
--- loncom/imspackages/imsexport.pm:1.1	Thu Dec 23 09:00:58 2004
+++ loncom/imspackages/imsexport.pm	Thu Dec 23 11:31:28 2004
@@ -27,7 +27,8 @@
 use Apache::lonnet;
 
 sub simpleproblem  {
-    my ($symb,$output) = @_;
+    my ($symb) = @_;
+    my $output;
     my %qparms = &Apache::lonnet::dump('resourcedata',
                   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
@@ -45,58 +46,58 @@
             if ($qtype eq 'option') {
                 my $options=$qparms{$prefix.'options'};
                 %values = &evaloptionhash($options);
-                $$output .= qq|
+                $output .= qq|
 <problem>
   <optionresponse max="$maxfoils" randomize="$randomize">
     <foilgroup options="$options">
 |;
                 for (my $k=0; $k<10; $k++) {
                     my $iter = $k+1;
-                    $$output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'.value.'.$iter}.'"';
-                    $$output .= 'location="'.$qparms{$prefix.'.position.'.$iter}.'" ';
-                    $$output .= '><startouttext />'.$qparms{$prefix.'.text.'.$iter}.'<endouttext /></foil>'."\n";
+                    $output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'value'.$iter}.'"';
+                    $output .= ' location="'.$qparms{$prefix.'position'.$iter}.'" ';
+                    $output .= '><startouttext />'.$qparms{$prefix.'text'.$iter}.'<endouttext /></foil>'."\n";
                 }
-                chomp($$output);
-                $$output .= qq|
+                chomp($output);
+                $output .= qq|
     </foilgroup>
 |;
                 if ($hint) {
-                    $$output .= '
+                    $output .= '
     <hintgroup>
      <hintpart on="default">
       <startouttext />'.$hint.'<endouttext/>
      </hintpart>
     </hintgroup>';
                 }
-                $$output .= qq|
+                $output .= qq|
   </optionresponse>
 </problem>
 |;
             } else {
-                $$output .= qq|
+                $output .= qq|
 <problem>
   <radiobuttonresponse max="$maxfoils" randomize="$randomize">
    <foilgroup>
 |;
                 for (my $k=0; $k<10; $k++) {
                     my $iter = $k+1;
-                    $$output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'.value.'.$iter}.'"';
-                    $$output .= 'location="'.$qparms{$prefix.'.position.'.$iter}.'" ';
-                    $$output .= '><startouttext />'.$qparms{$prefix.'.text.'.$iter}.'<endouttext /></foil>'."\n";
+                    $output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'value'.$iter}.'"';
+                    $output .= ' location="'.$qparms{$prefix.'position'.$iter}.'" ';
+                    $output .= '><startouttext />'.$qparms{$prefix.'text'.$iter}.'<endouttext /></foil>'."\n";
                 }
-                chomp($$output);
-                $$output .= qq|
+                chomp($output);
+                $output .= qq|
    </foilgroup>
 |;
                 if ($hint) {
-                    $$output .= '
+                    $output .= '
    <hintgroup>
     <hintpart on="default">
      <startouttext />'.$hint.'<endouttext/>
     </hintpart>
    </hintgroup>';
                 }
-                $$output .= qq|
+                $output .= qq|
   </radiobuttonresponse>
 </problem>
 |;
@@ -104,26 +105,26 @@
         } elsif ($qtype eq 'stringanswer') {
             my $stringanswer = $qparms{$prefix.'stringanswer'};
             my $stringtype=$qparms{$prefix.'stringtype'};
-            $$output .= qq|
+            $output .= qq|
 <problem>
   <stringresponse answer="$stringanswer" type="$stringtype">
     <textline>
     </textline>
             |;
             if ($hint) {
-                $$output .= '
+                $output .= '
    <hintgroup>
     <hintpart on="default">
      <startouttext />'.$hint.'<endouttext/>
     </hintpart>
    </hintgroup>';
             }
-            $$output .= qq|
+            $output .= qq|
   </stringresponse>
 </problem>
 |;
         } else {
-            $$output .= qq|
+            $output .= qq|
 <problem>
   <startouttext />$qtext<endouttext />
   <essayresponse>
@@ -133,7 +134,7 @@
 |;
         }
     }
-    return;
+    return $output;
 }
 
 sub evaloptionhash {
@@ -150,15 +151,15 @@
 sub external {
     my ($symb,$title) = @_;
     my $output;
-    if ($symb =~  m-\.sequence___\d+___ext$-) {
-        my $exturl = &Apache::lonnet::escape($1);
+    if ($symb =~  m-\.sequence___\d+___ext(.+)$-) {
+        my $exturl = &Apache::lonnet::unescape($1);
         $output = qq|
 <html>
 <head><title>$title</title>
 </head>
 <frameset rows="0,*" border="0">
-<frame src=''>
-<frame src="$exturl" name="external">
+<frame src='' />
+<frame src="http://$exturl" name="external" />
 </frameset>
 </html>
         |;
@@ -228,8 +229,8 @@
 </$_>|;
     }
     if (defined($syllabusdata{'uploaded.photourl'})) {
-        if ($syllabusdata{'uploaded.photourl'} =~  m-^/uploaded/$cdom/$cnum/$content_type/(.+)$-) {
-            push @{$$uploads}, $syllabusdata{'uploaded.photourl'};
+        if ($syllabusdata{'uploaded.photourl'} =~  m-/([^/]+)$-) {
+            push @$uploads, $syllabusdata{'uploaded.photourl'};
         }
         $output .= '
 <photo>

--raeburn1103819488--