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

1.65      raeburn     1: # The LearningOnline Network
1.1       www         2: # Create a course
1.5       albertel    3: #
1.98    ! albertel    4: # $Id: loncreatecourse.pm,v 1.97 2006/08/19 01:21:22 raeburn 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.78      albertel  569:     my $ccuname=$env{'form.ccuname'};
                    570:     my $ccdomain=$env{'form.ccdomain'};
1.2       www       571:     $ccuname=~s/\W//g;
                    572:     $ccdomain=~s/\W//g;
1.90      raeburn   573:     my $crstype = 'Group';
                    574:     my ($enrollstart,$enrollend,$startaccess,$endaccess);
1.74      raeburn   575: 
1.90      raeburn   576:     if ($env{'form.phase'} eq 'coursetwo') {
                    577:         $crstype='Course';
                    578:         $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
                    579:         $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
                    580: 
                    581:     }
                    582:     $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
                    583:     $endaccess   = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
1.74      raeburn   584: 
                    585:     my $autharg;
                    586:     my $authtype;
                    587: 
1.78      albertel  588:     if ($env{'form.login'} eq 'krb') {
1.74      raeburn   589:         $authtype = 'krb';
1.78      albertel  590:         $authtype .=$env{'form.krbver'};
                    591:         $autharg = $env{'form.krbarg'};
                    592:     } elsif ($env{'form.login'} eq 'int') {
1.74      raeburn   593:         $authtype ='internal';
1.78      albertel  594:         if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
                    595:             $autharg = $env{'form.intarg'};
1.74      raeburn   596:         }
1.78      albertel  597:     } elsif ($env{'form.login'} eq 'loc') {
1.74      raeburn   598:         $authtype = 'localauth';
1.78      albertel  599:         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
                    600:             $autharg = $env{'form.locarg'};
1.74      raeburn   601:         }
                    602:     }
1.90      raeburn   603:     my $logmsg;
1.91      albertel  604:     my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
1.90      raeburn   605:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
1.74      raeburn   606: 
1.90      raeburn   607:     $r->print($start_page.$crumbs);
1.74      raeburn   608: 
                    609:     my $args = {
1.90      raeburn   610:                crstype => $crstype,
1.74      raeburn   611:                ccuname => $ccuname,
                    612:                ccdomain => $ccdomain,
1.78      albertel  613:                cdescr => $env{'form.title'},
                    614:                curl => $env{'form.topmap'},
                    615:                course_domain => $env{'request.role.domain'},
                    616:                course_home =>  $env{'form.course_home'},
                    617:                nonstandard => $env{'form.nonstandard'},
                    618:                crscode => $env{'form.crscode'},
1.93      raeburn   619:                crsquota => $env{'form.crsquota'},
1.78      albertel  620:                clonecourse => $env{'form.clonecourse'},
                    621:                clonedomain => $env{'form.clonedomain'},
                    622:                crsid => $env{'form.crsid'},
1.94      raeburn   623:                curruser => $env{'user.name'}.':'.$env{'user.domain'},
1.78      albertel  624:                crssections => $env{'form.crssections'},
                    625:                crsxlist => $env{'form.crsxlist'},
                    626:                autoadds => $env{'form.autoadds'},
                    627:                autodrops => $env{'form.autodrops'},
                    628:                notify_owner => $env{'form.notify_owner'},
                    629:                notify_dc => $env{'form.notify_dc'},
                    630:                no_end_date => $env{'form.no_end_date'},
                    631:                showphotos => $env{'form.showphotos'},
1.74      raeburn   632:                authtype => $authtype,
                    633:                autharg => $autharg,
                    634:                enrollstart => $enrollstart,
                    635:                enrollend => $enrollend,
                    636:                startaccess => $startaccess,
                    637:                endaccess => $endaccess,
1.78      albertel  638:                setpolicy => $env{'form.setpolicy'},
                    639:                setcontent => $env{'form.setcontent'},
                    640:                reshome => $env{'form.reshome'},
                    641:                setkeys => $env{'form.setkeys'},
                    642:                keyauth => $env{'form.keyauth'},
                    643:                disresdis => $env{'form.disresdis'},
                    644:                disablechat => $env{'form.disablechat'},
                    645:                openall => $env{'form.openall'},
                    646:                firstres => $env{'form.firstres'}
1.74      raeburn   647:                };
                    648: 
1.10      matthew   649:     #
                    650:     # Verify data
                    651:     #
                    652:     # Check the veracity of the course coordinator
1.2       www       653:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.52      albertel  654: 	$r->print('<form action="/adm/createuser" method="post" name="crtuser">');
                    655:         $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
                    656: 	$r->print(&mt("Please click Back on your browser and select another user, or "));
                    657: 	$r->print('
                    658: 	    <input type="hidden" name="phase" value="get_user_info" />
                    659:             <input type="hidden" name="ccuname" value="'.$ccuname.'" />
                    660:             <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
                    661:             <input name="userrole" type="submit" value="'.
                    662: 		  &mt('Create User').'" />
1.86      albertel  663: 	</form>'.&Apache::loncommon::end_page());
1.2       www       664: 	return;
                    665:     }
1.10      matthew   666:     # Check the proposed home server for the course
                    667:     my %host_servers = &Apache::loncommon::get_library_servers
1.78      albertel  668:         ($env{'request.role.domain'});
                    669:     if (! exists($host_servers{$env{'form.course_home'}})) {
1.46      sakharuk  670:         $r->print(&mt('Invalid home server for course').': '.
1.86      albertel  671:                   $env{'form.course_home'}.&Apache::loncommon::end_page());
1.10      matthew   672:         return;
                    673:     }
1.74      raeburn   674:     my ($courseid,$crsudom,$crsunum);
1.96      albertel  675:     $r->print(&Apache::loncommon::construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
1.74      raeburn   676: 
                    677: #
1.90      raeburn   678: # Make the requested user a course coordinator or group coordinator
1.74      raeburn   679: #
1.90      raeburn   680:     if (($ccdomain) && ($ccuname)) {
                    681:         $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]:',
                    682:                      $crstype,$ccuname,$ccdomain).
                    683:                   &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
                    684:                                               'cc').'<p>');
                    685:     }
1.78      albertel  686:     if ($env{'form.setkeys'}) {
1.74      raeburn   687:         $r->print(
                    688:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
                    689:     }
                    690: # Flush the course logs so reverse user roles immediately updated
                    691:     &Apache::lonnet::flushcourselogs();
1.86      albertel  692:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p>'.
1.87      www       693: 	      '<p><a href="/adm/createcourse">'.
1.90      raeburn   694: 	      &mt('Create Another [_1]',$crstype).'</a></p>'.
1.86      albertel  695: 	      &Apache::loncommon::end_page());
1.74      raeburn   696: }
                    697: 
1.90      raeburn   698: sub print_intro_page {
                    699:     my $r = shift;
                    700:     my $start_page =
                    701:         &Apache::loncommon::start_page('Create a New Course or Group Space');
                    702:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
                    703:     my $end_page =
                    704:         &Apache::loncommon::end_page();
                    705:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course_GroupSpace',&mt('Help on Creating Courses and Groups'));
                    706: 
                    707:     my @choices = ({ internal_name => 'courseone',
                    708:                      name => &mt('Create a single course'),
                    709:                      short_description =>
                    710:     &mt('Create a new course by completing an online form.'),
                    711:                  },
                    712:                    { internal_name => 'groupone',
                    713:                      name => &mt('Create a single collaborative group space '),
                    714:                      short_description =>
                    715:     &mt('Create a new group space for non-course use by completing an online form .'),
                    716:                  },
                    717:                    { internal_name => 'batchone',
                    718:                      name => &mt('Create courses/groups by uploading an attributes file'),
                    719:                      short_description =>
                    720:     &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format'),
1.97      raeburn   721:                      help => 'Batch_Creation',
1.90      raeburn   722:                  },
                    723:     );
                    724:     my $options;
                    725:     foreach my $choice (@choices) {
                    726:         $options .='    <h3><a href="/adm/createcourse?phase='.
                    727:             $choice->{'internal_name'}.'" >'.
1.97      raeburn   728:             $choice->{'name'}.'</a>';
                    729:         if (exists($choice->{'help'})) {
                    730:             $options .= &Apache::loncommon::help_open_topic($choice->{'help'});
                    731:         }
                    732:         $options .= "</h3>\n".'    '.('&nbsp;'x8).$choice->{'short_description'}.
1.90      raeburn   733:             "\n";
                    734:     }
                    735: 
                    736:     $r->print(<<ENDDOCUMENT);
                    737: $start_page
                    738: $crumbs
                    739: $options
                    740: $end_page
                    741: ENDDOCUMENT
                    742: }
                    743: 
                    744: sub upload_batchfile {
                    745:     my $r = shift;
                    746:     my $start_page =
                    747:         &Apache::loncommon::start_page('Create a New Course or Group Space');
                    748:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses');
                    749:     my $end_page =
                    750:         &Apache::loncommon::end_page();
                    751:     $r->print($start_page.$crumbs);
                    752:     $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
                    753:     $r->print('<form name="batchcreate" method="post" '.
                    754:                 'enctype="multipart/form-data" action="/adm/createcourse">'.
                    755:               '<input type="file" name="coursecreatorxml" />'.
                    756:               '<input type="hidden" name="phase" value="batchtwo"><br /><br />'.
                    757:               '<input type="submit" name="batchsubmit" '.
                    758:               'value="Create Courses/Groups" /></form>');
                    759:     $r->print($end_page);
                    760:     return;
                    761: }
                    762: 
                    763: sub process_batchfile {
                    764:     my $r = shift;
                    765:     my $start_page =
                    766:         &Apache::loncommon::start_page('Create a New Course or Group Space');
                    767:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
                    768:     my $end_page =
                    769:         &Apache::loncommon::end_page();
                    770:     my $defdom=$env{'request.role.domain'};
                    771:     my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
                    772:                                                       'batchupload',undef,undef,
                    773:                                                        undef,undef,$defdom);
                    774:     my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
                    775:     my ($result,$logmsg);
                    776:     if (-e "$batchfilepath") {
                    777:         open(FILE,"<$batchfilepath");
                    778:         my @buffer = <FILE>;
                    779:         close(FILE);
                    780:         if ((defined($filename)) && (defined($batchdir))) {
                    781:             my @requests = ($filename);
                    782:             my %courseids = ();
                    783:             ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
                    784:                                         \@requests,\%courseids,'web',$defdom,
                    785:                                         $env{'user.name'},$env{'user.domain'});
                    786:             if ($result) {
                    787:                 if (!-e "$batchdir/processed") {
                    788:                     mkdir("$batchdir/processed", 0755);
                    789:                     open(FILE,">$batchdir/processed/$filename");
                    790:                     print FILE @buffer;
                    791:                     close(FILE);
                    792:                     if (-e "$batchdir/processed/$filename") {
                    793:                         unlink("$batchdir/pending/$filename");
                    794:                     }
                    795:                 }
                    796:             }
                    797:         }
                    798:     }
                    799:     $r->print($start_page.$crumbs.$result.$end_page);
                    800:  
                    801: }
                    802: 
1.2       www       803: # ===================================================================== Handler
1.1       www       804: sub handler {
                    805:     my $r = shift;
                    806: 
                    807:     if ($r->header_only) {
1.38      www       808:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       809:        $r->send_http_header;
                    810:        return OK;
                    811:     }
                    812: 
1.78      albertel  813:     if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.38      www       814:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       815:        $r->send_http_header;
                    816: 
1.90      raeburn   817:        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    818:                                             ['phase']);
                    819:        &Apache::lonhtmlcommon::clear_breadcrumbs();
                    820:        &Apache::lonhtmlcommon::add_breadcrumb
                    821:           ({href=>"/adm/createcourse",
                    822:             text=>"Creation Options",
                    823:             faq=>79,bug=>'Dom Coord Interface',});
                    824:        if (($env{'form.phase'} eq 'coursetwo') ||
                    825:            ($env{'form.phase'} eq 'grouptwo')) {
                    826:            &Apache::lonhtmlcommon::add_breadcrumb
                    827:                  ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
                    828:                    text=>&mt('[_1] Creation Settings',),
                    829:                    faq=>9,bug=>'Dom Coord Interface',});
                    830:           &Apache::lonhtmlcommon::add_breadcrumb
                    831:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
                    832:                    text=>"Creation Outcome",
                    833:                    faq=>9,bug=>'Dom Coord Interface',});
1.10      matthew   834:            &create_course($r);
1.90      raeburn   835:        } elsif (($env{'form.phase'} eq 'courseone') || 
                    836:                 ($env{'form.phase'} eq 'groupone')) {
                    837:            &Apache::lonhtmlcommon::add_breadcrumb
                    838:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
                    839:                    text=>&mt('[_1] Creation Settings',),
                    840:                    faq=>9,bug=>'Dom Coord Interface',});
                    841: 	   &print_course_creation_page($r);
                    842:        } elsif ($env{'form.phase'} eq 'batchone') {
                    843:            &Apache::lonhtmlcommon::add_breadcrumb
                    844:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
                    845:                    text=>"Upload Description File",
                    846:                    faq=>9,bug=>'Dom Coord Interface',});
                    847:            &upload_batchfile($r);
                    848:        } elsif ($env{'form.phase'} eq 'batchtwo') {
                    849:            &Apache::lonhtmlcommon::add_breadcrumb
                    850:                  ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
                    851:                    text=>"Upload Description File",
                    852:                    faq=>9,bug=>'Dom Coord Interface',});
                    853:            &Apache::lonhtmlcommon::add_breadcrumb
                    854:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
                    855:                    text=>"Creation Outcome",
                    856:                    faq=>9,bug=>'Dom Coord Interface',});
                    857:            &process_batchfile($r);
1.2       www       858:        } else {
1.90      raeburn   859:            &print_intro_page($r);
1.2       www       860:        }
1.1       www       861:    } else {
1.78      albertel  862:       $env{'user.error.msg'}=
1.90      raeburn   863:         "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
1.1       www       864:       return HTTP_NOT_ACCEPTABLE; 
                    865:    }
                    866:    return OK;
1.90      raeburn   867: }
1.1       www       868: 
                    869: 1;
                    870: __END__

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