[LON-CAPA-cvs] cvs: loncom /xml scripttag.pm

www www@source.lon-capa.org
Wed, 26 May 2010 02:04:20 -0000


www		Wed May 26 02:04:20 2010 EDT

  Modified files:              
    /loncom/xml	scripttag.pm 
  Log:
  Ability to import problems as problem part, and import problems with duplicate IDs
  
  
Index: loncom/xml/scripttag.pm
diff -u loncom/xml/scripttag.pm:1.153 loncom/xml/scripttag.pm:1.154
--- loncom/xml/scripttag.pm:1.153	Sun May 23 12:29:25 2010
+++ loncom/xml/scripttag.pm	Wed May 26 02:04:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # <script> definiton
 #
-# $Id: scripttag.pm,v 1.153 2010/05/23 12:29:25 www Exp $
+# $Id: scripttag.pm,v 1.154 2010/05/26 02:04:20 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -385,9 +385,27 @@
       return "";
     }
     my $importmode=&Apache::lonxml::get_param('importmode',$parstack,$safeeval);
-    if ($importmode eq 'problem') {
-       $file=~s/^\s*<problem>/<library>/s;
-       $file=~s/<\/problem>\s*$/<\/library>/s;
+    if (($importmode eq 'problem') || ($importmode eq 'part')) {
+# We are using import to import published problems
+# This will require some on-the-fly rewriting
+       my $importid=&Apache::lonxml::get_param('id',$parstack,$safeeval);
+       if ($importid) {
+# Rewrite all internal IDs of the problem to avoid duplicates
+          $file=~s/id\s*=\s*([\"\'])(\w+)([\"\'])/id=$1$2DynPart$importid$3/gs;
+       }
+       if (($importmode eq 'problem') || ($file=~/<part[^<]*>/s)) {
+# We explicitly don't want this to be a separate part or the problem already has parts
+          $file=~s/^\s*<problem>/<library>/s;
+	  $file=~s/<\/problem>\s*$/<\/library>/s;
+       } else {
+# We want this to be a separate part, but it currently is not
+          if ($importid) {
+             $file=~s/^\s*<problem>/<library><part id="DynPart$importid">/s;
+          } else {
+             $file=~s/^\s*<problem>/<library><part>/s;
+          }
+	  $file=~s/<\/problem>\s*$/<\/part><\/library>/s;
+       }
     }
     my $dir=$location;
     $dir=~s:/[^/]*$::;
@@ -406,14 +424,17 @@
     $location=~s/\s*$//s;
     $result.=&Apache::edit::editline($location,$bodytext,'',40);
     $result.=&Apache::edit::browse(undef,'textnode');
-        $result.= '<label>'.&mt('Import as:').
+    $result.= '&nbsp;<label>'.&mt('Import as:').
               '<select name="importmode_'.$Apache::lonxml::curdepth.'">';
-    foreach my $option ('','problem') {
+    my %options=&Apache::lonlocal::texthash(''        => 'as standard library',
+                                            'problem' => 'as problem',
+                                            'part'    => 'as problem part(s)');
+    foreach my $option (sort(keys(%options))) {
        $result.='<option value="'.$option.'"';
        if ($option eq &Apache::lonxml::get_param('importmode',$parstack,$safeeval)) {
           $result.=' selected="selected"';
        }
-       $result.='>'.($option?&mt('as problem'):&mt('as standard library')).'</option>';
+       $result.='>'.$options{$option}.'</option>';
     }
     $result.='</select></label>';
     #FIXME this need to convert $bodytext to be a contruction space reference