File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.110.2.2: download - view: text, annotated - select for diffs
Mon Dec 15 08:44:25 2008 UTC (15 years, 6 months ago) by raeburn
Branches: version_2_8_X
CVS tags: version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_99_1, version_2_7_99_0, GCI_1
- hide type selector for 2.8.

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

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