File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.93.2.5: download - view: text, annotated - select for diffs
Fri Aug 11 22:11:21 2006 UTC (17 years, 8 months ago) by albertel
Branches: version_2_2_X
CVS tags: version_2_1_99_3
- backport 1.96

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

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