File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.112: download - view: text, annotated - select for diffs
Tue Nov 18 19:14:22 2008 UTC (15 years, 6 months ago) by jms
Branches: MAIN
CVS tags: HEAD
Added/updated/converted POD. Many files had their POD redone to new standards.

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.112 2008/11/18 19:14:22 jms Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: =head1 NAME
   31: 
   32: Apache::loncreatecourse.pm
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Allows domain coordinators to create new
   37: courses and assign course coordinators.
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 SUBROUTINES
   43: 
   44: =over
   45: 
   46: =item handler()
   47: 
   48: =item print_course_creation_page()
   49: 
   50: =item create_course()
   51: 
   52: =item print_intro_page()
   53: 
   54: =item upload_batchfile()
   55: 
   56: =item process_batchfile()
   57: 
   58: =back
   59: 
   60: =cut
   61: 
   62: package Apache::loncreatecourse;
   63: 
   64: use strict;
   65: use Apache::Constants qw(:common :http);
   66: use Apache::lonnet;
   67: use Apache::loncommon;
   68: use Apache::londocs;
   69: use Apache::lonlocal;
   70: use Apache::lonuserutils;
   71: use Apache::lonclonecourse;
   72: use LONCAPA::batchcreatecourse;
   73: use LONCAPA;
   74: 
   75: # ===================================================== Phase one: fill-in form
   76: 
   77: sub print_course_creation_page {
   78:     my $r=shift;
   79:     my $crstype = 'Group';
   80:     if ($env{'form.phase'} eq 'courseone') {
   81:         $crstype = 'Course';
   82:     }
   83:     my $defdom=$env{'request.role.domain'};
   84:     my %host_servers = &Apache::lonnet::get_servers($defdom,'library');
   85:     my $course_home = '<select name="course_home" size="1">'."\n";
   86:     foreach my $server (sort(keys(%host_servers))) {
   87:         $course_home .= qq{<option value="$server"};
   88:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
   89:             $course_home .= " selected ";
   90:         }
   91:         $course_home .= qq{>$server $host_servers{$server}</option>};
   92:     }
   93:     $course_home .= "\n</select>\n";
   94:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
   95:     my $cloneform=&Apache::loncommon::select_dom_form
   96: 	($env{'request.role.domain'},'clonedomain').
   97: 		     &Apache::loncommon::selectcourse_link
   98: 	     ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype);
   99:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
  100:     my ($enroll_table,$access_table,$krbdef,$krbdefdom,$krbform,$intform,$locform,
  101:         $javascript_validations);
  102:     if ($crstype eq 'Course') {
  103:         my $starttime = time;
  104:         my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
  105:         $enroll_table = &Apache::lonuserutils::date_setting_table($starttime,
  106:                                               $endtime,'create_enrolldates');
  107:         $access_table = &Apache::lonuserutils::date_setting_table($starttime,
  108:                                              $endtime,'create_defaultdates');
  109:         ($krbdef,$krbdefdom) =
  110:         &Apache::loncommon::get_kerberos_defaults($defdom);
  111:         $javascript_validations=&Apache::lonuserutils::javascript_validations(
  112:                                                     'createcourse',$krbdefdom);
  113:         my %param = ( formname      => 'document.ccrs',
  114:                       kerb_def_dom  => $krbdefdom,
  115:                       kerb_def_auth => $krbdef
  116:                     );
  117:         $krbform = &Apache::loncommon::authform_kerberos(%param);
  118:         $intform = &Apache::loncommon::authform_internal(%param);
  119:         $locform = &Apache::loncommon::authform_local(%param);
  120:     } else {
  121:         $javascript_validations = qq|
  122: function validate(formname) {
  123:     if (formname.title == '') {
  124:         alert("A group title is required");
  125:         return;
  126:     }
  127:     if (formname.ccuname == '') {
  128:         alert("The username of the group coordinator is required");
  129:     }
  130:     formname.submit();
  131: }
  132:         |;
  133:     }
  134:     my %lt=&Apache::lonlocal::texthash(
  135: 		    'cinf' => "Course Information",
  136:                     'ctit' => "Course Title",
  137:                     'chsr' => "Course Home Server",
  138:                     'cidn' => "Course ID/Number",
  139:                     'opt'  => "optional",
  140:                     'iinf' => "Institutional Information",
  141:                     'stat' => "The following entries will be used to identify the course according to the naming scheme adopted by your institution. Your choices will be used to map an internal LON-CAPA course ID to the corresponding course section ID(s) used by the office responsible for providing official class lists for courses at your institution. This mapping is required if you choose to employ automatic population of class lists.",
  142:                     'ccod' => "Course Code",
  143:                     'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
  144:                     'snid' => "Section Numbers and corresponding LON-CAPA section IDs",
  145:                     'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section ID to be used in LON-CAPA e.g., 001:1,002:2",
  146:                     'crcs' => "Crosslisted courses",
  147:                     'cscs' => "a comma separated list of course sections crosslisted with the current course, with each entry including the institutional course section name followed by a colon and then the (optional) sectionID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2",
  148:                     'crco' => "Course Content",
  149:                     'cncr' => "Completely new course",
  150:                     'cecr' => "Clone an existing course", 
  151:                     'map'  => "Map",
  152:                     'smap' => "Select Map",
  153:                     'sacr' => "Do NOT generate as standard course",
  154:                     'ocik' => "only check if you know what you are doing",
  155:                     'fres' => "First Resource",
  156:                     'stco' => "standard courses only",
  157:                     'blnk' => "Blank",
  158:                     'sllb' => "Syllabus",
  159:                     'navi' => "Navigate",
  160:                     'cid'  => "Course ID",
  161:                     'dmn'  => "Domain",
  162:                     'dsh'  => "Date Shift",
  163:                     'asov' => "Additional settings, if specified below, will override cloned settings",
  164:                     'ncd'  => "Do not clone date parameters",
  165:                     'prd'  => 'Clone date parameters as-is',
  166:                     'shd'  => 'Shift date parameters by number of days',
  167:                     'assp' => "Assessment Parameters",
  168:                     'oaas' => "Open all assessments",
  169:                     'mssg' => "Messaging",
  170:                     'scpf' => "Set course policy feedback to Course Coordinator",
  171:                     'scfc' => "Set content feedback to Course Coordinator",
  172:                     'cmmn' => "Communication",
  173:                     'dsrd' => "Disable student resource discussion",
  174:                     'dsuc' => "Disable student use of chatrooms",
  175:                     'acco' => "Access Control",
  176:                     'snak' => "Students need access key to enter course",
  177: 		    'kaut' => 
  178: 		    'Key authority (<tt>id@domain</tt>) if other than course',
  179:                     'cc'   => "Course Coordinator",
  180:                     'user' => "Username",
  181:                     'aens' => "Automated enrollment settings",
  182:                     'aesc' => "The following settings control automatic enrollment of students in this class based on information available for this specific course from your institution's official classlists.",
  183:                     'aadd' => "Automated adds",
  184:                     'yes'  => "Yes",
  185:                     'no'   => "No",
  186:                     'audr' => "Automated drops",
  187:                     'dacu' => "Duration of automated classlist updates",
  188:                     'dacc' => "Default start and end dates for student access",
  189:                     'psam' => "Please select the Authentication mechanism",
  190:                     'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
  191:                     'nech' => "Notification of enrollment changes",
  192:                     'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  193:                     'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  194:                     'irsp' => "Include retrieval of student photographs?",
  195: 		    'rshm' => 'Resource Space Home',
  196:                     'cgrs' => "Course Group Settings",
  197:                     'cgrq' => "Set a quota for the total disk space available for storage of course group portfolio files.",
  198:                     'opco' => "Open Course",
  199:                     'ginf' => "Group Information",
  200:                     'gtit' => "Group Title",
  201:                     'ghsr' => "Group Home Server",
  202:                     'gidn' => "Group ID/Number",
  203:                     'grco' => "Group Content",
  204:                     'cngr' => "Completely new group",
  205:                     'cegr' => "Clone an existing group",
  206:                     'sagr' => "Do NOT generate as standard group",
  207:                     'stgo' => "standard groups only",
  208:                     'sgpf' => "Set group policy feedback to Group Coordinator",
  209:                     'scfg' => "Set content feedback to Group Coordinator",
  210:                     'dmrd' => "Disable member resource discussion",
  211:                     'dmuc' => "Disable member use of chatrooms",
  212:                     'mnak' => "Members need access key to enter group",
  213:                     'kaug' =>
  214:                     'Key authority (<tt>id@domain</tt>) if other than group',
  215:                     'gc'   => "Group Coordinator",
  216:                     'gid'  => "Group ID",
  217:                     'crgr' => "Create Group",
  218:                     'grts' => "Group Teams Settings",
  219:                     'grtq' => "Set a quota for the total disk space available for storage of group team portfolio files.",
  220: 
  221: 				       );
  222:     my $js = <<END;
  223: <script type="text/javascript">
  224: var editbrowser = null;
  225: function openbrowser(formname,elementname) {
  226:     var url = '/res/?';
  227:     if (editbrowser == null) {
  228:         url += 'launch=1&';
  229:     }
  230:     url += 'catalogmode=interactive&';
  231:     url += 'mode=edit&';
  232:     url += 'form=' + formname + '&';
  233:     url += 'element=' + elementname + '&';
  234:     url += 'only=sequence' + '';
  235:     var title = 'Browser';
  236:     var options = 'scrollbars=1,resizable=1,menubar=0';
  237:     options += ',width=700,height=600';
  238:     editbrowser = open(url,title,options,'1');
  239:     editbrowser.focus();
  240: }
  241: $javascript_validations
  242: </script>
  243: $coursebrowserjs
  244: END
  245: 
  246:     my %titles = &Apache::lonlocal::texthash(
  247:                   courseone => 'Create a New Course',
  248:                   groupone => 'Create a New Group',
  249:     );  
  250:     my $start_page = 
  251:         &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js);
  252:     my $end_page = 
  253:         &Apache::loncommon::end_page();
  254:     my $crumbs = 
  255: 	&Apache::lonhtmlcommon::breadcrumbs($crstype.' Information',
  256: 					    'Create_Course',undef,
  257: 					    'Create_Courses');
  258:     $r->print($start_page.$crumbs);
  259: 
  260:     if ($crstype eq 'Course') {
  261:         $r->print('<form action="/adm/createcourse" method="post" name="ccrs">'
  262:                  .&Apache::lonhtmlcommon::start_pick_box()
  263: 
  264:                  .&Apache::lonhtmlcommon::row_headline()
  265:                  .'<h3>'.$lt{'cinf'}.'</h3>'
  266:                  .&Apache::lonhtmlcommon::row_closure()
  267: 
  268:                  .&Apache::lonhtmlcommon::row_title($lt{'ctit'})
  269:                  .'<input type="text" size="50" name="title" />'
  270:                  .&Apache::lonhtmlcommon::row_closure()
  271: 
  272:                  .&Apache::lonhtmlcommon::row_title($lt{'chsr'})
  273:                  .$course_home
  274:                  .&Apache::lonhtmlcommon::row_closure()
  275: 
  276:                  .&Apache::lonhtmlcommon::row_title($lt{'cidn'}.' ('.$lt{'opt'}.')')
  277:                  .'<input type="text" size="30" name="crsid" />'
  278:                  .&Apache::lonhtmlcommon::row_closure()
  279: 
  280:                  .&Apache::lonhtmlcommon::row_headline()
  281:                  .'<h3>'.$lt{'iinf'}.'</h3>'
  282:                  .$lt{'stat'}
  283:                  .&Apache::lonhtmlcommon::row_closure()
  284: 
  285:                  .&Apache::lonhtmlcommon::row_title($lt{'ccod'})
  286:                  .'<input type="text" size="30" name="crscode" />'
  287:                  .'<br />('.$lt{'toin'}.')'
  288:                  .&Apache::lonhtmlcommon::row_closure()
  289: 
  290:                  .&Apache::lonhtmlcommon::row_title($lt{'snid'})
  291:                  .'<input type="text" size="30" name="crssections" />'
  292:                  .'<br />('.$lt{'csli'}.')'
  293:                  .&Apache::lonhtmlcommon::row_closure()
  294: 
  295:                  .&Apache::lonhtmlcommon::row_title($lt{'crcs'})
  296:                  .'<input type="text" size="30" name="crsxlist" />'
  297:                  .'<br />('.$lt{'cscs'}.')'
  298:                  .&Apache::lonhtmlcommon::row_closure()
  299:         );
  300: 
  301:         # Table: New Course / Clone Course
  302:         $r->print(&Apache::lonhtmlcommon::row_headline()
  303:                  .'<h3>'.$lt{'crco'}.'</h3>'
  304:                  .&Apache::loncommon::start_data_table()
  305:                  .&Apache::loncommon::start_data_table_header_row()
  306:                  .'<th>'.$lt{'cncr'}.'</th>'
  307:                  .'<th>&nbsp;'.&mt('or').'&nbsp;</th>'
  308:                  .'<th>'.$lt{'cecr'}.'</th>'
  309:                  .&Apache::loncommon::end_data_table_header_row()
  310:                  .&Apache::loncommon::start_data_table_row()
  311: 
  312:                  # New Course:
  313:                  .'<td>'
  314:                  .&Apache::lonhtmlcommon::start_pick_box()
  315:                  .&Apache::lonhtmlcommon::row_title($lt{'map'})
  316:                  .'<input type="text" size="50" name="topmap" />'
  317:                  .'<a href="javascript:openbrowser(\'ccrs\',\'topmap\')">'.$lt{'smap'}.'</a>'
  318:                  .&Apache::lonhtmlcommon::row_closure()
  319:                  .&Apache::lonhtmlcommon::row_title('<label for="nonstd">'.$lt{'sacr'}.'</label>')
  320:                  .'<input id="nonstd" type="checkbox" name="nonstandard" />'
  321:                  .'<br />('.$lt{'ocik'}.')'
  322:                  .&Apache::lonhtmlcommon::row_closure()
  323:                  .&Apache::lonhtmlcommon::row_title($lt{'fres'})
  324:                  .'<label>'
  325:                  .'<input type="radio" name="firstres" value="blank" />'.$lt{'blnk'}
  326:                  .'</label>'
  327:                  .'&nbsp;'
  328:                  .'<label>'
  329:                  .'<input type="radio" name="firstres" value="syl" checked="checked" />'.$lt{'sllb'}
  330:                  .'</label>'
  331:                  .'&nbsp;'
  332:                  .'<label>'
  333:                  .'<input type="radio" name="firstres" value="nav" />'.$lt{'navi'}
  334:                  .'</label>'
  335:                  .'<br />('.$lt{'stco'}.')'
  336:                  .&Apache::lonhtmlcommon::row_closure(1)
  337:                  .&Apache::lonhtmlcommon::end_pick_box()
  338: 
  339:                  .'<td>&nbsp;</td>'
  340: 
  341:                  # Clone Course:
  342:                  .'<td>'
  343:                  .&Apache::lonhtmlcommon::start_pick_box()
  344:                  .&Apache::lonhtmlcommon::row_title($lt{'cid'})
  345:                  .'<label>'
  346:                  .'<input type="text" size="25" name="clonecourse" value="" />'
  347:                  .'</label>'
  348:                  .&Apache::lonhtmlcommon::row_closure(1)
  349:                  .&Apache::lonhtmlcommon::row_title($lt{'dmn'})
  350:                  .'<label>'
  351:                  .$cloneform
  352:                  .'</label>'
  353:                  .&Apache::lonhtmlcommon::row_closure()
  354:                  .&Apache::lonhtmlcommon::row_title($lt{'dsh'})
  355:                  .'<label>'
  356:                  .'<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}
  357:                  .'</label><br />'
  358:                  .'<label>'
  359:                  .'<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}
  360:                  .'</label><br />'
  361:                  .'<label>'
  362:                  .'<input type="radio" name="datemode" value="shift" checked="checked" /> '.$lt{'shd'}
  363:                  .'</label>'
  364:                  .' <input type="text" size="5" name="dateshift" value="365" />'
  365:                  .&Apache::lonhtmlcommon::row_closure()
  366:                  .&Apache::lonhtmlcommon::row_headline()
  367:                  .$lt{'asov'}
  368:                  .&Apache::lonhtmlcommon::row_closure(1)
  369:                  .&Apache::lonhtmlcommon::end_pick_box()
  370:                  .'</td>'
  371:                  .&Apache::loncommon::end_data_table_row()
  372:                  .&Apache::loncommon::end_data_table()
  373:                  .&Apache::lonhtmlcommon::row_closure()
  374:         );
  375: 
  376:         $r->print(&Apache::lonhtmlcommon::row_headline()
  377:                  .'<h3>'.$lt{'assp'}.'</h3>'
  378:                  .&Apache::lonhtmlcommon::row_closure()
  379: 
  380:                  .&Apache::lonhtmlcommon::row_title($lt{'oaas'})
  381:                  .'<input type="checkbox" name="openall" />'
  382:                  .&Apache::lonhtmlcommon::row_closure()
  383: 
  384:                  .&Apache::lonhtmlcommon::row_headline()
  385:                  .'<h3>'.$lt{'mssg'}.'</h3>'
  386:                  .&Apache::lonhtmlcommon::row_closure()
  387: 
  388:                  .&Apache::lonhtmlcommon::row_title($lt{'scpf'})
  389:                  .'<input type="checkbox" name="setpolicy" checked="checked" />'
  390:                  .&Apache::lonhtmlcommon::row_closure()
  391: 
  392:                  .&Apache::lonhtmlcommon::row_title($lt{'scfc'})
  393:                  .'<input type="checkbox" name="setcontent" checked="checked" />'
  394:                  .&Apache::lonhtmlcommon::row_closure()
  395: 
  396:                  .&Apache::lonhtmlcommon::row_headline()
  397:                  .'<h3>'.$lt{'cmmn'}.'</h3>'
  398:                  .&Apache::lonhtmlcommon::row_closure()
  399: 
  400:                  .&Apache::lonhtmlcommon::row_title($lt{'dsrd'})
  401:                  .'<input type="checkbox" name="disresdis" />'
  402:                  .&Apache::lonhtmlcommon::row_closure()
  403: 
  404:                  .&Apache::lonhtmlcommon::row_title($lt{'dsuc'})
  405:                  .'<input type="checkbox" name="disablechat" /'
  406:                  .&Apache::lonhtmlcommon::row_closure()
  407: 
  408:                  .&Apache::lonhtmlcommon::row_headline()
  409:                  .'<h3>'.$lt{'acco'}.'</h3>'
  410:                  .&Apache::lonhtmlcommon::row_closure()
  411: 
  412:                  .&Apache::lonhtmlcommon::row_title($lt{'snak'})
  413:                  .'<input type="checkbox" name="setkeys" />'
  414:                  .&Apache::lonhtmlcommon::row_closure()
  415: 
  416:                  .&Apache::lonhtmlcommon::row_title($lt{'kaut'})
  417:                  .'<input type="text" size="30" name="keyauth" />'
  418:                  .&Apache::lonhtmlcommon::row_closure()
  419: 
  420:                  .&Apache::lonhtmlcommon::row_headline()
  421:                  .'<h3>'.$lt{'rshm'}.'</h3>'
  422:                  .&Apache::lonhtmlcommon::row_closure()
  423: 
  424:                  .&Apache::lonhtmlcommon::row_title($lt{'rshm'})
  425:                  .'<input type="text" name="reshome" size="30" value="/res/'.$defdom.'/" />'
  426:                  .&Apache::lonhtmlcommon::row_closure()
  427: 
  428:                  .&Apache::lonhtmlcommon::row_headline()
  429:                  .'<h3>'.$lt{'aens'}.'</h3>'
  430:                  .&Apache::lonhtmlcommon::row_closure()
  431: 
  432:                  .&Apache::lonhtmlcommon::row_title($lt{'aadd'})
  433:                  .'<label><input type="radio" name="autoadds" value="1" />'.$lt{'yes'}.'</label>'
  434:                  .'<label><input type="radio" name="autoadds" value="0" checked="checked" />'.$lt{'no'}.'</label>'
  435:                  .&Apache::lonhtmlcommon::row_closure()
  436: 
  437:                  .&Apache::lonhtmlcommon::row_title($lt{'audr'})
  438:                  .'<label><input type="radio" name="autodrops" value="1" />'.$lt{'yes'}.'</label>'
  439:                  .'<label><input type="radio" name="autodrops" value="0" checked="checked" />'.$lt{'no'}.'</label>'
  440:                  .&Apache::lonhtmlcommon::row_closure()
  441: 
  442:                  .&Apache::lonhtmlcommon::row_title($lt{'dacu'})
  443:                  .$enroll_table
  444:                  .&Apache::lonhtmlcommon::row_closure()
  445: 
  446:                  .&Apache::lonhtmlcommon::row_title($lt{'dacc'})
  447:                  .$access_table
  448:                  .&Apache::lonhtmlcommon::row_closure()
  449: 
  450:                  .&Apache::lonhtmlcommon::row_title($lt{'psam'})
  451:                  .$lt{'pcda'}.'<br />'
  452:                  .$krbform.'<br />'
  453:                  .$intform.'<br />'
  454:                  .$locform
  455:                  .&Apache::lonhtmlcommon::row_closure()
  456: 
  457:                  .&Apache::lonhtmlcommon::row_title($lt{'nech'})
  458:                  .$lt{'nccl'}.'<br/>'
  459:                  .'<label><input type="radio" name="notify_owner" value="1" />'.$lt{'yes'}.'</label>'
  460:                  .'<label><input type="radio" name="notify_owner" value="0" checked="checked" />'.$lt{'no'}.'</label>'
  461:                  .'<br />'
  462:                  .$lt{'ndcl'}.'<br/>'
  463:                  .'<label><input type="radio" name="notify_dc" value="1" />'.$lt{'yes'}.'</label>'
  464:                  .'<label><input type="radio" name="notify_dc" value="0" checked="checked" />'.$lt{'no'}.'</label>'
  465:                  .&Apache::lonhtmlcommon::row_closure()
  466: 
  467:                  .&Apache::lonhtmlcommon::row_title($lt{'irsp'})
  468:                  .'<label>'
  469:                  .'<input type="radio" name="showphotos" value="1" />'.$lt{'yes'}
  470:                  .'</label> '
  471:                  .'<label>'
  472:                  .'<input type="radio" name="showphotos" value="0" checked="checked" />'.$lt{'no'}
  473:                  .'</label> '
  474:                  .&Apache::lonhtmlcommon::row_closure()
  475: 
  476:                  .&Apache::lonhtmlcommon::row_headline()
  477:                  .'<h3>'.$lt{'cgrs'}.'</h3>'
  478:                  .&Apache::lonhtmlcommon::row_closure()
  479: 
  480:                  .&Apache::lonhtmlcommon::row_title($lt{'cgrq'})
  481:                  .'<input type="text" name="crsquota" value="20" size="6" />Mb'
  482:                  .&Apache::lonhtmlcommon::row_closure()
  483: 
  484:                  .&Apache::lonhtmlcommon::row_headline()
  485:                  .'<h3>'.$lt{'cc'}.'</h3>'
  486:                  .&Apache::lonhtmlcommon::row_closure()
  487: 
  488:                  .&Apache::lonhtmlcommon::row_title($lt{'user'})
  489:                  .'<input type="text" size="15" name="ccuname" />'
  490:                  .&Apache::lonhtmlcommon::row_closure()
  491: 
  492:                  .&Apache::lonhtmlcommon::row_title($lt{'dmn'},"","LC_odd_row_value")
  493:                  .$domform
  494:                  .&Apache::lonhtmlcommon::row_closure(1)
  495: 
  496:                  .&Apache::lonhtmlcommon::end_pick_box()
  497:         );
  498: 
  499:         $r->print(<<ENDDOCUMENT);
  500: <p>
  501: <input type="hidden" name="prevphase" value="courseone" />
  502: <input type="hidden" name="phase" value="coursetwo" />
  503: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
  504: </p>
  505: </form>
  506: ENDDOCUMENT
  507: 
  508:     } elsif ($crstype eq 'Group') {
  509:         $r->print(<<ENDDOCUMENT);
  510: <form action="/adm/createcourse" method="post" name="ccrs">
  511: <h2>$lt{'ginf'}</h2>
  512: <p>
  513: <label><b>$lt{'gtit'}:</b>
  514: <input type="text" size="50" name="title" /></label>
  515: </p><p>
  516: <label>
  517:     <b>$lt{'ghsr'}:</b>$course_home
  518: </label>
  519: </p><p>
  520: <label>
  521:     <b>$lt{'gidn'} ($lt{'opt'})</b>
  522:     <input type="text" size="30" name="crsid" />
  523: </label>
  524: </p>
  525: <h2>$lt{'grco'}</h2>
  526: <table border="2">
  527: <tr><th>$lt{'cngr'}</th><th>$lt{'cegr'}</th></tr>
  528: <tr><td>
  529: <p>
  530: <label>
  531:     <b>$lt{'map'}:</b>
  532:     <input type="text" size="50" name="topmap" />
  533: </label>
  534: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
  535: </p><p>
  536: <label for="nonstd"><b>$lt{'sagr'}</b></label>
  537: <br />
  538: ($lt{'ocik'}):
  539: <input id="nonstd" type="checkbox" name="nonstandard" />
  540: </p><p>
  541: <b>$lt{'fres'}</b><br />($lt{'stgo'}):
  542: <label>
  543:     <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
  544: </label>
  545: &nbsp;
  546: <label>
  547:     <input type="radio" name="firstres" value="syl" checked="checked" />$lt{'sllb'}
  548: </label>
  549: &nbsp;
  550: <label>
  551:     <input type="radio" name="firstres" value="nav" />$lt{'navi'}
  552: </label>
  553: </p>
  554: </td><td>
  555: <label>
  556:     $lt{'gid'}: <input type="text" size="25" name="clonecourse" value="" />
  557: </label>
  558: <br />
  559: <label>
  560:     $lt{'dmn'}: $cloneform
  561: </label>
  562: <br />
  563:  <label><input type="radio" name="datemode" value="delete" /> $lt{'ncd'}</label><br />
  564:  <label><input type="radio" name="datemode" value="preserve" /> $lt{'prd'}</label><br />
  565:  <label><input type="radio" name="datemode" value="shift" checked="checked" /> $lt{'shd'}</label>
  566:  <input type="text" size="5" name="dateshift" value="365" /><br />&nbsp;<br />
  567: $lt{'asov'}.
  568: </td></tr>
  569: </table>
  570: </p>
  571: <p>
  572: <h2>$lt{'mssg'}</h2>
  573: <p>
  574: <label>
  575:     <b>$lt{'sgpf'}: </b>
  576:     <input type="checkbox" name="setpolicy" checked="checked" />
  577: </label>
  578: <br />
  579: <label>
  580:     <b>$lt{'scfg'}: </b>
  581:     <input type="checkbox" name="setcontent" checked="checked" />
  582: </label>
  583: </p>
  584: <h2>$lt{'cmmn'}</h2>
  585: <p>
  586: <label>
  587:     <b>$lt{'dmrd'}: </b>
  588:     <input type="checkbox" name="disresdis" />
  589: </label>
  590: <br />
  591: <label>
  592:     <b>$lt{'dmuc'}: </b>
  593:     <input type="checkbox" name="disablechat" />
  594: </label>
  595: </p>
  596: <h2>$lt{'acco'}</h2>
  597: <p>
  598: <label>
  599:     <b>$lt{'mnak'}: </b>
  600:     <input type="checkbox" name="setkeys" />
  601: </label>
  602: <br />
  603: <label>
  604:     <b>$lt{'kaug'}: </b>
  605:     <input type="text" size="30" name="keyauth" />
  606: </label>
  607: </p>
  608: <h2>$lt{'rshm'}</h2>
  609: <p>
  610: <label>
  611:     <b>$lt{'rshm'}: </b>
  612:     <input type="text" name="reshome" size="30" value="/res/$defdom/" />
  613: </label>
  614: </p>
  615: <p>
  616: <h2>$lt{'grts'}</h2>
  617: $lt{'grtq'}
  618: <input type="text" name="crsquota" value="20" />Mb
  619: </p>
  620: <hr />
  621: <h2>$lt{'gc'}</h2>
  622: <p>
  623: <label>
  624:     <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
  625: </label>
  626: </p><p>
  627: <label>
  628:     <b>$lt{'dmn'}:</b> $domform
  629: </label>
  630: </p>
  631: <p>
  632: <input type="hidden" name="prevphase" value="groupone" />
  633: <input type="hidden" name="phase" value="grouptwo" />
  634: <input type="button" onClick="validate(this.form)" value="$lt{'crgr'}" />
  635: </p>
  636: </form>
  637: ENDDOCUMENT
  638:     }
  639:     $r->print($end_page);
  640: }
  641: 
  642: # ====================================================== Phase two: make course
  643: 
  644: sub create_course {
  645:     my $r=shift;
  646:     my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
  647:     my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
  648:     my $crstype = 'Group';
  649:     my ($enrollstart,$enrollend,$startaccess,$endaccess);
  650: 
  651:     if ($env{'form.phase'} eq 'coursetwo') {
  652:         $crstype='Course';
  653:         $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
  654:         $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
  655:     }
  656:     $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
  657:     $endaccess   = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
  658: 
  659:     my $autharg;
  660:     my $authtype;
  661: 
  662:     if ($env{'form.login'} eq 'krb') {
  663:         $authtype = 'krb';
  664:         $authtype .=$env{'form.krbver'};
  665:         $autharg = $env{'form.krbarg'};
  666:     } elsif ($env{'form.login'} eq 'int') {
  667:         $authtype ='internal';
  668:         if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
  669:             $autharg = $env{'form.intarg'};
  670:         }
  671:     } elsif ($env{'form.login'} eq 'loc') {
  672:         $authtype = 'localauth';
  673:         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
  674:             $autharg = $env{'form.locarg'};
  675:         }
  676:     }
  677:     my $logmsg;
  678:     my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
  679:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
  680: 
  681:     $r->print($start_page.$crumbs);
  682: 
  683:     my $args = {
  684:                crstype => $crstype,
  685:                ccuname => $ccuname,
  686:                ccdomain => $ccdomain,
  687:                cdescr => $env{'form.title'},
  688:                curl => $env{'form.topmap'},
  689:                course_domain => $env{'request.role.domain'},
  690:                course_home =>  $env{'form.course_home'},
  691:                nonstandard => $env{'form.nonstandard'},
  692:                crscode => $env{'form.crscode'},
  693:                crsquota => $env{'form.crsquota'},
  694:                clonecourse => $env{'form.clonecourse'},
  695:                clonedomain => $env{'form.clonedomain'},
  696:                datemode => $env{'form.datemode'},
  697:                dateshift => $env{'form.dateshift'},
  698:                crsid => $env{'form.crsid'},
  699:                curruser => $env{'user.name'}.':'.$env{'user.domain'},
  700:                crssections => $env{'form.crssections'},
  701:                crsxlist => $env{'form.crsxlist'},
  702:                autoadds => $env{'form.autoadds'},
  703:                autodrops => $env{'form.autodrops'},
  704:                notify_owner => $env{'form.notify_owner'},
  705:                notify_dc => $env{'form.notify_dc'},
  706:                no_end_date => $env{'form.no_end_date'},
  707:                showphotos => $env{'form.showphotos'},
  708:                authtype => $authtype,
  709:                autharg => $autharg,
  710:                enrollstart => $enrollstart,
  711:                enrollend => $enrollend,
  712:                startaccess => $startaccess,
  713:                endaccess => $endaccess,
  714:                setpolicy => $env{'form.setpolicy'},
  715:                setcontent => $env{'form.setcontent'},
  716:                reshome => $env{'form.reshome'},
  717:                setkeys => $env{'form.setkeys'},
  718:                keyauth => $env{'form.keyauth'},
  719:                disresdis => $env{'form.disresdis'},
  720:                disablechat => $env{'form.disablechat'},
  721:                openall => $env{'form.openall'},
  722:                firstres => $env{'form.firstres'}
  723:                };
  724: 
  725:     #
  726:     # Verify data
  727:     #
  728:     # Check the veracity of the course coordinator
  729:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  730: 	$r->print('<form action="/adm/createuser" method="post" name="crtuser">');
  731:         $r->print('<div class="LC_warning">'
  732:                   .&mt('No such user [_1] at domain [_2].','<tt>'.$ccuname.'</tt>','<tt>'.$ccdomain.'</tt>')
  733:                  .'</div>');
  734: 	$r->print(&mt('Please click Back on your browser and select another user, or [_1]Create User[_2]'
  735: 	             , '<input type="hidden" name="phase" value="get_user_info" />'
  736:                       .'<input type="hidden" name="ccuname" value="'.$ccuname.'" />'
  737:                       .'<input type="hidden" name="ccdomain" value="'.$ccdomain.'" />'
  738:                       .'<input name="userrole" type="submit" value="'
  739:                      , '" />'
  740:                      )
  741:                  .'</form>'.&Apache::loncommon::end_page()
  742:                  );
  743: 	return;
  744:     }
  745:     # Check the proposed home server for the course
  746:     my %host_servers = 
  747: 	&Apache::lonnet::get_servers($env{'request.role.domain'},'library');
  748:     if (! exists($host_servers{$env{'form.course_home'}})) {
  749:         $r->print(&mt('Invalid home server for course: [_1]'
  750:                      ,$env{'form.course_home'}.&Apache::loncommon::end_page()));
  751:         return;
  752:     }
  753:     my ($courseid,$crsudom,$crsunum);
  754:     my ($success,$output) = 
  755: 	&Apache::loncommon::construct_course($args,\$logmsg,\$courseid,
  756: 					     \$crsudom,\$crsunum,
  757: 					     $env{'user.domain'},
  758: 					     $env{'user.name'});
  759:     $r->print($output);
  760:     if ($success) {
  761:         #
  762: 	# Make the requested user a course coordinator or group coordinator
  763:         #
  764: 	if (($ccdomain) && ($ccuname)) {
  765: 	    $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]: ',
  766: 			  $crstype,$ccuname,$ccdomain).
  767: 		      &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
  768: 						  'cc','','','','','createcourse').'<p>');
  769: 	}
  770: 	if ($env{'form.setkeys'}) {
  771: 	    $r->print(
  772: 		      '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
  773: 	}
  774:         # Flush the course logs so reverse user roles immediately updated
  775: 	&Apache::lonnet::flushcourselogs();
  776: 	$r->print('<p>'.&mt('Roles will be active at next login').'.</p>');
  777:     }
  778:     $r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'.
  779: 	      &mt('Create Another [_1]',$crstype).'</a></p>'.
  780: 	      &Apache::loncommon::end_page());
  781: }
  782: 
  783: sub print_intro_page {
  784:     my $r = shift;
  785:     my $start_page =
  786:         &Apache::loncommon::start_page('Create a New Course or Group Space');
  787:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
  788:     my $end_page =
  789:         &Apache::loncommon::end_page();
  790:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course_GroupSpace',&mt('Help on Creating Courses and Groups'));
  791: 
  792:     my @choices = ({ internal_name => 'courseone',
  793:                      name => &mt('Create a single course'),
  794:                      short_description =>
  795:     &mt('Create a new course by completing an online form.'),
  796:                  },
  797:                    { internal_name => 'groupone',
  798:                      name => &mt('Create a single collaborative group space'),
  799:                      short_description =>
  800:     &mt('Create a new group space for non-course use by completing an online form.'),
  801:                  },
  802:                    { internal_name => 'batchone',
  803:                      name => &mt('Create courses/groups by uploading an attributes file'),
  804:                      short_description =>
  805:     &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format.'),
  806:                      help => 'Batch_Creation',
  807:                  },
  808:     );
  809:     my $options;
  810:     foreach my $choice (@choices) {
  811:         $options .='    <h3><a href="/adm/createcourse?phase='.
  812:             $choice->{'internal_name'}.'" >'.
  813:             $choice->{'name'}.'</a>';
  814:         if (exists($choice->{'help'})) {
  815:             $options .= &Apache::loncommon::help_open_topic($choice->{'help'});
  816:         }
  817:         $options .= "</h3>\n".'    '.('&nbsp;'x8).$choice->{'short_description'}.
  818:             "\n";
  819:     }
  820: 
  821:     $r->print(<<ENDDOCUMENT);
  822: $start_page
  823: $crumbs
  824: $options
  825: $end_page
  826: ENDDOCUMENT
  827: }
  828: 
  829: sub upload_batchfile {
  830:     my $r = shift;
  831:     my $start_page =
  832:         &Apache::loncommon::start_page('Create a New Course or Group Space');
  833:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses');
  834:     my $end_page =
  835:         &Apache::loncommon::end_page();
  836:     $r->print($start_page.$crumbs);
  837:     $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
  838:     $r->print('<form name="batchcreate" method="post" '.
  839:                 'enctype="multipart/form-data" action="/adm/createcourse">'.
  840:               '<input type="file" name="coursecreatorxml" />'.
  841:               '<input type="hidden" name="phase" value="batchtwo"><br /><br />'.
  842:               '<input type="submit" name="batchsubmit" '.
  843:               'value="Create Courses/Groups" /></form>');
  844:     $r->print($end_page);
  845:     return;
  846: }
  847: 
  848: sub process_batchfile {
  849:     my $r = shift;
  850:     my $start_page =
  851:         &Apache::loncommon::start_page('Create a New Course or Group Space');
  852:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
  853:     my $end_page =
  854:         &Apache::loncommon::end_page();
  855:     my $defdom=$env{'request.role.domain'};
  856:     my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
  857:                                                       'batchupload',undef,undef,
  858:                                                        undef,undef,$defdom);
  859:     my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
  860:     my ($result,$logmsg);
  861:     if (-e "$batchfilepath") {
  862:         open(FILE,"<$batchfilepath");
  863:         my @buffer = <FILE>;
  864:         close(FILE);
  865:         if ((defined($filename)) && (defined($batchdir))) {
  866:             my @requests = ($filename);
  867:             my %courseids = ();
  868:             ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
  869:                                         \@requests,\%courseids,'web',$defdom,
  870:                                         $env{'user.name'},$env{'user.domain'});
  871:             if ($result) {
  872:                 if (!-e "$batchdir/processed") {
  873:                     mkdir("$batchdir/processed", 0755);
  874:                     open(FILE,">$batchdir/processed/$filename");
  875:                     print FILE @buffer;
  876:                     close(FILE);
  877:                     if (-e "$batchdir/processed/$filename") {
  878:                         unlink("$batchdir/pending/$filename");
  879:                     }
  880:                 }
  881:             }
  882:         }
  883:     }
  884:     $r->print($start_page.$crumbs.$logmsg.$result.'<br /><a href="/adm/createcourse">'.
  885:               &mt('Creation options menu').'</a>'.$end_page);
  886:  
  887: }
  888: 
  889: # ===================================================================== Handler
  890: sub handler {
  891:     my $r = shift;
  892: 
  893:     if ($r->header_only) {
  894:        &Apache::loncommon::content_type($r,'text/html');
  895:        $r->send_http_header;
  896:        return OK;
  897:     }
  898: 
  899:     if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
  900:        &Apache::loncommon::content_type($r,'text/html');
  901:        $r->send_http_header;
  902: 
  903:        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  904:                                             ['phase']);
  905:        &Apache::lonhtmlcommon::clear_breadcrumbs();
  906:        &Apache::lonhtmlcommon::add_breadcrumb
  907:           ({href=>"/adm/createcourse",
  908:             text=>"Creation Options",
  909:             faq=>79,bug=>'Dom Coord Interface',});
  910:        if (($env{'form.phase'} eq 'coursetwo') ||
  911:            ($env{'form.phase'} eq 'grouptwo')) {
  912:            &Apache::lonhtmlcommon::add_breadcrumb
  913:                  ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
  914:                    text=>&mt('[_1] Creation Settings',),
  915:                    faq=>9,bug=>'Dom Coord Interface',});
  916:           &Apache::lonhtmlcommon::add_breadcrumb
  917:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
  918:                    text=>"Creation Outcome",
  919:                    faq=>9,bug=>'Dom Coord Interface',});
  920:            &create_course($r);
  921:        } elsif (($env{'form.phase'} eq 'courseone') || 
  922:                 ($env{'form.phase'} eq 'groupone')) {
  923:            &Apache::lonhtmlcommon::add_breadcrumb
  924:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
  925:                    text=>&mt('[_1] Creation Settings',),
  926:                    faq=>9,bug=>'Dom Coord Interface',});
  927: 	   &print_course_creation_page($r);
  928:        } elsif ($env{'form.phase'} eq 'batchone') {
  929:            &Apache::lonhtmlcommon::add_breadcrumb
  930:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
  931:                    text=>"Upload Description File",
  932:                    faq=>9,bug=>'Dom Coord Interface',});
  933:            &upload_batchfile($r);
  934:        } elsif ($env{'form.phase'} eq 'batchtwo') {
  935:            &Apache::lonhtmlcommon::add_breadcrumb
  936:                  ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
  937:                    text=>"Upload Description File",
  938:                    faq=>9,bug=>'Dom Coord Interface',});
  939:            &Apache::lonhtmlcommon::add_breadcrumb
  940:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
  941:                    text=>"Creation Outcome",
  942:                    faq=>9,bug=>'Dom Coord Interface',});
  943:            &process_batchfile($r);
  944:        } else {
  945:            &print_intro_page($r);
  946:        }
  947:    } else {
  948:       $env{'user.error.msg'}=
  949:         "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
  950:       return HTTP_NOT_ACCEPTABLE; 
  951:    }
  952:    return OK;
  953: }
  954: 
  955: 1;
  956: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>