[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface loncreatecourse.pm

raeburn raeburn at source.lon-capa.org
Tue Sep 11 15:39:59 EDT 2018


raeburn		Tue Sep 11 19:39:59 2018 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	loncreatecourse.pm 
  Log:
  - For 2.11
    Backport 1.168, 1.169
  
  
Index: loncom/interface/loncreatecourse.pm
diff -u loncom/interface/loncreatecourse.pm:1.158.2.3 loncom/interface/loncreatecourse.pm:1.158.2.4
--- loncom/interface/loncreatecourse.pm:1.158.2.3	Sun Jan 22 19:46:46 2017
+++ loncom/interface/loncreatecourse.pm	Tue Sep 11 19:39:58 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Create a course
 #
-# $Id: loncreatecourse.pm,v 1.158.2.3 2017/01/22 19:46:46 raeburn Exp $
+# $Id: loncreatecourse.pm,v 1.158.2.4 2018/09/11 19:39:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -82,7 +82,7 @@
 use Apache::lonuserutils;
 use Apache::lonclonecourse;
 use LONCAPA::batchcreatecourse;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
 
 # ===================================================== Phase one: fill-in form
 
@@ -848,43 +848,60 @@
 
 sub process_batchfile {
     my $r = shift;
-    my $start_page =
-        &Apache::loncommon::start_page('Create a New Course or Community');
-    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
-    my $end_page =
-        &Apache::loncommon::end_page();
     my $defdom=$env{'request.role.domain'};
-    my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
-                                                      'batchupload',undef,undef,
-                                                       undef,undef,$defdom);
-    my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
+    my $uname = $env{'user.name'};
+    my $udom = $env{'user.domain'};
+    my $dir = &LONCAPA::tempdir().'addcourse';
     my ($result,$logmsg);
-    if (-e "$batchfilepath") {
-        open(FILE,"<$batchfilepath");
-        my @buffer = <FILE>;
-        close(FILE);
-        if ((defined($filename)) && (defined($batchdir))) {
-            my @requests = ($filename);
-            my %courseids = ();
-            ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
-                                        \@requests,\%courseids,'web',$defdom,
-                                        $env{'user.name'},$env{'user.domain'});
-            if ($result) {
-                if (!-e "$batchdir/processed") {
-                    mkdir("$batchdir/processed", 0755);
-                    open(FILE,">$batchdir/processed/$filename");
-                    print FILE @buffer;
+    if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) {
+        my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
+                                                          'batchupload',undef,undef,
+                                                          undef,undef,$defdom);
+        if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\_$udom\E)/pending/([^/]+)$}) {
+            my ($batchdir,$filename) = ($1,$2);
+            if (-e "$batchfilepath") {
+                if (open(FILE,"<",$batchfilepath)) {
+                    my @buffer = <FILE>;
                     close(FILE);
-                    if (-e "$batchdir/processed/$filename") {
-                        unlink("$batchdir/pending/$filename");
+                    if ((defined($filename)) && (defined($batchdir))) {
+                        my @requests = ($filename);
+                        my %courseids = ();
+                        ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
+                                                    \@requests,\%courseids,'web',$defdom,
+                                                    $uname,$udom);
+                        if (keys(%courseids) > 0) {
+                            if (!-e "$batchdir/processed") {
+                                mkdir("$batchdir/processed", 0755);
+                            }
+                            if (-d "$batchdir/processed") {
+                                if (open(FILE,">","$batchdir/processed/$filename")) {
+                                    print FILE @buffer;
+                                    close(FILE);
+                                }
+                            }
+                            if (-e "$batchdir/processed/$filename") {
+                                unlink("$batchdir/pending/$filename");
+                            }
+                        }
                     }
+                } else {
+                    $result = '<p class="LC_error">'.&mt('Could not open attributes file.').'<br />'.&mt('No courses created.').'</p>';
                 }
+            } else {
+                $result = '<p class="LC_error">'.&mt('No uploaded attributes file found.').'<br />'.&mt('No courses created.').'</p>';
             }
+        } else {
+            $result = '<p class="LC_error">'.&mt('Invalid path to attributes file.').'<br />'.&mt('No courses created.').'</p>';
         }
+    } else {
+        $result = '<p class="LC_error">'.&mt("Your username, domain, and/or your current role's domain are missing or contain invalid characters.").
+                  '<br />'.&mt('No courses created.').'</p>';
     }
-    $r->print($start_page.$crumbs.$logmsg.$result.'<br /><a href="/adm/createcourse">'.
-              &mt('Creation options menu').'</a>'.$end_page);
- 
+    $r->print(&Apache::loncommon::start_page('Create a New Course, Community or Placement Test').
+              &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses').
+              $logmsg.$result.'<br /><a href="/adm/createcourse">'.
+              &mt('Creation options menu').'</a>'.
+              &Apache::loncommon::end_page());
 }
 
 sub courserequestbrowser_javascript {




More information about the LON-CAPA-cvs mailing list