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

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

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