[LON-CAPA-cvs] cvs: loncom /imspackages imsimportdocs.pm

bisitz bisitz@source.lon-capa.org
Fri, 20 Nov 2009 11:16:59 -0000


bisitz		Fri Nov 20 11:16:59 2009 EDT

  Modified files:              
    /loncom/imspackages	imsimportdocs.pm 
  Log:
  - Code style: Early escape in phase two when errors occurred/not allowed
  - Show warning message for unsupported cms types found in IMS package
  - Added error style to error message when privs are not sufficiant
  - Added headline to PopUp window
  - Added some code comments
  
  
Index: loncom/imspackages/imsimportdocs.pm
diff -u loncom/imspackages/imsimportdocs.pm:1.24 loncom/imspackages/imsimportdocs.pm:1.25
--- loncom/imspackages/imsimportdocs.pm:1.24	Fri Nov  6 17:16:53 2009
+++ loncom/imspackages/imsimportdocs.pm	Fri Nov 20 11:16:59 2009
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: imsimportdocs.pm,v 1.24 2009/11/06 17:16:53 bisitz Exp $
+# $Id: imsimportdocs.pm,v 1.25 2009/11/20 11:16:59 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -165,9 +165,15 @@
     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
     unless ($allowed) {
         $r->print(&Apache::loncommon::start_page('Import IMS package',undef,
-						 {'only_body' => 1,}));  
-        $r->print('<h3>'.&mt('Modification of Course Contents Disallowed').'</h3>'.&mt('Your current role does not grant you the right to modify course content in this course.').
-		  &Apache::loncommon::end_page());
+                                                 {'only_body' => 1,}));  
+        $r->print(
+            '<p class="LC_error">'
+           .&mt('Modification of Course Contents Disallowed')
+           .'</p><p>'
+           .&mt('Your current role does not grant you the right to modify course content in this course.')
+           .'</p>'
+           .&Apache::loncommon::end_page()
+        );
         return OK;
     }
 
@@ -183,11 +189,13 @@
     }
 
     $javascript = 
-	 "<script type=\"text/javascript\">\n".
-	 "//<!--\n$javascript\n// --></script>\n";
-    my $start_page = &Apache::loncommon::start_page('Import IMS package',
-						    $javascript,
-						    {'only_body' => 1,});
+        "<script type=\"text/javascript\">\n".
+        "//<!--\n$javascript\n// --></script>\n";
+    my $headline = 'Import IMS package';
+    my $start_page = &Apache::loncommon::start_page($headline,
+                                                    $javascript,
+                                                    {'only_body' => 1,})
+                    .'<h1>'.&mt($headline).'</h1>';
 # print screen
     $r->print($start_page);
 
@@ -278,28 +286,57 @@
                 users => 0,
                 );
 
-    if ($unzip_result eq 'ok') {
-        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems);
-        if ($manifest_result eq 'ok') {
-            foreach my $res (sort keys %resources) {
-                if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
-                    foreach my $area (keys %{$cmsmap{$cms}}) {
-                        if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
-                            $count{$area} ++;
-                        }
-                    }
-                } elsif ($cms eq 'angel5') {
-                    foreach my $area (keys %{$cmsmap{$cms}}) {
-                        if ($area eq 'doc') {
-                            if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
-                                $count{$area} ++;
-                            }
-                        } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
-                            $count{$area} ++;
-                        }
+    if ($unzip_result ne 'ok') {
+        $r->print(
+            '<p class="LC_warning">'
+           .&mt('Processing of your IMS package failed because the file you'
+               .' uploaded could not be unzipped.')
+           .'</p>'
+        );
+        return();
+    }
+
+    # Get manifest file from package
+    $manifest_result = &Apache::imsprocessor::process_manifest(
+                           $cms,$tempdir,\%resources,\%items,\%hrefs,
+                           \%resinfo,'choose',\%includedres,\%includeditems);
+    if ($manifest_result ne 'ok') {
+        $r->print(
+           '<p class="LC_warning">'
+          .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.')
+          .'</p>'
+        );
+        return();
+    }
+
+    # Count areas depending on cms version
+    foreach my $res (sort keys %resources) {
+        if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') {
+            foreach my $area (keys %{$cmsmap{$cms}}) {
+                if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
+                    $count{$area} ++;
+                }
+            }
+        } elsif ($cms eq 'angel5') {
+            foreach my $area (keys %{$cmsmap{$cms}}) {
+                if ($area eq 'doc') {
+                    if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
+                        $count{$area} ++;
                     }
+                } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
+                    $count{$area} ++;
                 }
             }
+        } else { # Unknown cms format
+            $r->print(
+                '<span class="LC_warning">'
+               .&mt('Unsupported IMS format: [_1]',$cms)
+               .'</span><br />'
+            );
+            # return();
+        }
+    }
+
             $r->print(<<ENDBLOCK);
 <form name="pickoptions" method="post">
   <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
@@ -437,21 +474,6 @@
    </tr>
   </table>
 ENDDOCUMENT
-        } else {
-            $r->print(
-               '<p class="LC_warning">'
-               .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.')
-               .'</p>'
-            );
-        }
-    } else {
-        $r->print(
-            '<p class="LC_warning">'
-           .&mt('Processing of your IMS package failed because the file you'
-               .' uploaded could not be unzipped.')
-           .'</p>'
-        );
-    }
 }