File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.103.2.2: download - view: text, annotated - select for diffs
Fri Aug 24 07:21:43 2007 UTC (16 years, 8 months ago) by albertel
Branches: version_2_5_X
CVS tags: version_2_5_2, version_2_5_1
- backport 1.104

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

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