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

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

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