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

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

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