--- loncom/interface/loncreatecourse.pm	2006/08/11 22:11:21	1.93.2.5
+++ loncom/interface/loncreatecourse.pm	2007/08/23 21:54:40	1.104
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Create a course
 #
-# $Id: loncreatecourse.pm,v 1.93.2.5 2006/08/11 22:11:21 albertel Exp $
+# $Id: loncreatecourse.pm,v 1.104 2007/08/23 21:54:40 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,7 +33,6 @@ use strict;
 use Apache::Constants qw(:common :http);
 use Apache::lonnet;
 use Apache::loncommon;
-use Apache::lonratedt;
 use Apache::londocs;
 use Apache::lonlocal;
 use Apache::londropadd;
@@ -45,13 +44,12 @@ use LONCAPA;
 
 sub print_course_creation_page {
     my $r=shift;
-    my $crstype = 'Course';
-#    my $crstype = 'Group';
-#    if ($env{'form.phase'} eq 'courseone') {
-#        $crstype = 'Course';
-#    }
+    my $crstype = 'Group';
+    if ($env{'form.phase'} eq 'courseone') {
+        $crstype = 'Course';
+    }
     my $defdom=$env{'request.role.domain'};
-    my %host_servers = &Apache::loncommon::get_library_servers($defdom);
+    my %host_servers = &Apache::lonnet::get_servers($defdom,'library');
     my $course_home = '<select name="course_home" size="1">'."\n";
     foreach my $server (sort(keys(%host_servers))) {
         $course_home .= qq{<option value="$server"};
@@ -568,10 +566,8 @@ ENDDOCUMENT
 
 sub create_course {
     my $r=shift;
-    my $ccuname=$env{'form.ccuname'};
-    my $ccdomain=$env{'form.ccdomain'};
-    $ccuname=~s/\W//g;
-    $ccdomain=~s/\W//g;
+    my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
+    my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
     my $crstype = 'Group';
     my ($enrollstart,$enrollend,$startaccess,$endaccess);
 
@@ -579,7 +575,6 @@ sub create_course {
         $crstype='Course';
         $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
         $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
-
     }
     $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
     $endaccess   = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
@@ -666,33 +661,39 @@ sub create_course {
 	return;
     }
     # Check the proposed home server for the course
-    my %host_servers = &Apache::loncommon::get_library_servers
-        ($env{'request.role.domain'});
+    my %host_servers = 
+	&Apache::lonnet::get_servers($env{'request.role.domain'},'library');
     if (! exists($host_servers{$env{'form.course_home'}})) {
         $r->print(&mt('Invalid home server for course').': '.
                   $env{'form.course_home'}.&Apache::loncommon::end_page());
         return;
     }
     my ($courseid,$crsudom,$crsunum);
-    $r->print(&Apache::loncommon::construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
-
-#
-# Make the requested user a course coordinator or group coordinator
-#
-    if (($ccdomain) && ($ccuname)) {
-        $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]:',
-                     $crstype,$ccuname,$ccdomain).
-                  &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
-                                              'cc').'<p>');
-    }
-    if ($env{'form.setkeys'}) {
-        $r->print(
- '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
-    }
-# Flush the course logs so reverse user roles immediately updated
-    &Apache::lonnet::flushcourselogs();
-    $r->print('<p>'.&mt('Roles will be active at next login').'.</p>'.
-	      '<p><a href="/adm/createcourse">'.
+    my ($success,$output) = 
+	&Apache::loncommon::construct_course($args,\$logmsg,\$courseid,
+					     \$crsudom,\$crsunum,
+					     $env{'user.domain'},
+					     $env{'user.name'});
+    $r->print($output);
+    if ($success) {
+        #
+	# Make the requested user a course coordinator or group coordinator
+        #
+	if (($ccdomain) && ($ccuname)) {
+	    $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]: ',
+			  $crstype,$ccuname,$ccdomain).
+		      &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
+						  'cc').'<p>');
+	}
+	if ($env{'form.setkeys'}) {
+	    $r->print(
+		      '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
+	}
+        # Flush the course logs so reverse user roles immediately updated
+	&Apache::lonnet::flushcourselogs();
+	$r->print('<p>'.&mt('Roles will be active at next login').'.</p>');
+    }
+    $r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'.
 	      &mt('Create Another [_1]',$crstype).'</a></p>'.
 	      &Apache::loncommon::end_page());
 }
@@ -700,7 +701,7 @@ sub create_course {
 sub print_intro_page {
     my $r = shift;
     my $start_page =
-        &Apache::loncommon::start_page('Create a New Course');
+        &Apache::loncommon::start_page('Create a New Course or Group Space');
     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
     my $end_page =
         &Apache::loncommon::end_page();
@@ -711,23 +712,27 @@ sub print_intro_page {
                      short_description =>
     &mt('Create a new course by completing an online form.'),
                  },
-#                   { internal_name => 'groupone',
-#                     name => &mt('Create a single collaborative group space '),
-#                     short_description =>
-#    &mt('Create a new group space for non-course use by completing an online form .'),
-#                 },
+                   { internal_name => 'groupone',
+                     name => &mt('Create a single collaborative group space '),
+                     short_description =>
+    &mt('Create a new group space for non-course use by completing an online form .'),
+                 },
                    { internal_name => 'batchone',
                      name => &mt('Create courses/groups by uploading an attributes file'),
                      short_description =>
     &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format'),
+                     help => 'Batch_Creation',
                  },
     );
     my $options;
     foreach my $choice (@choices) {
         $options .='    <h3><a href="/adm/createcourse?phase='.
             $choice->{'internal_name'}.'" >'.
-            $choice->{'name'}."</a></h3>\n";
-        $options .= '    '.('&nbsp;'x8).$choice->{'short_description'}.
+            $choice->{'name'}.'</a>';
+        if (exists($choice->{'help'})) {
+            $options .= &Apache::loncommon::help_open_topic($choice->{'help'});
+        }
+        $options .= "</h3>\n".'    '.('&nbsp;'x8).$choice->{'short_description'}.
             "\n";
     }
 
@@ -743,11 +748,11 @@ sub upload_batchfile {
     my $r = shift;
     my $start_page =
         &Apache::loncommon::start_page('Create a New Course or Group Space');
-    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course Attributes File','Create_Course',undef,'Create_Courses');
+    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses');
     my $end_page =
         &Apache::loncommon::end_page();
     $r->print($start_page.$crumbs);
-    $r->print('<h3>'.&mt('Upload a courses attributes file').'</h3>');
+    $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
     $r->print('<form name="batchcreate" method="post" '.
                 'enctype="multipart/form-data" action="/adm/createcourse">'.
               '<input type="file" name="coursecreatorxml" />'.
@@ -794,7 +799,8 @@ sub process_batchfile {
             }
         }
     }
-    $r->print($start_page.$crumbs.$result.$end_page);
+    $r->print($start_page.$crumbs.$logmsg.$result.'<br /><a href="/adm/createcourse">'.
+              &mt('Creation options menu').'</a>'.$end_page);
  
 }