Annotation of loncom/interface/loncreatecourse.pm, revision 1.99

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

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