Annotation of loncom/interface/loncreateuser.pm, revision 1.109

1.20      harris41    1: # The LearningOnline Network with CAPA
1.1       www         2: # Create a user
                      3: #
1.109   ! albertel    4: # $Id: loncreateuser.pm,v 1.108 2005/09/01 19:27:35 albertel Exp $
1.22      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.20      harris41   28: ###
                     29: 
1.1       www        30: package Apache::loncreateuser;
1.66      bowersj2   31: 
                     32: =pod
                     33: 
                     34: =head1 NAME
                     35: 
                     36: Apache::loncreateuser - handler to create users and custom roles
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Apache::loncreateuser provides an Apache handler for creating users,
                     41:     editing their login parameters, roles, and removing roles, and
                     42:     also creating and assigning custom roles.
                     43: 
                     44: =head1 OVERVIEW
                     45: 
                     46: =head2 Custom Roles
                     47: 
                     48: In LON-CAPA, roles are actually collections of privileges. "Teaching
                     49: Assistant", "Course Coordinator", and other such roles are really just
                     50: collection of privileges that are useful in many circumstances.
                     51: 
                     52: Creating custom roles can be done by the Domain Coordinator through
                     53: the Create User functionality. That screen will show all privileges
                     54: that can be assigned to users. For a complete list of privileges,
                     55: please see C</home/httpd/lonTabs/rolesplain.tab>.
                     56: 
                     57: Custom role definitions are stored in the C<roles.db> file of the role
                     58: author.
                     59: 
                     60: =cut
1.1       www        61: 
                     62: use strict;
                     63: use Apache::Constants qw(:common :http);
                     64: use Apache::lonnet;
1.54      bowersj2   65: use Apache::loncommon;
1.68      www        66: use Apache::lonlocal;
1.1       www        67: 
1.20      harris41   68: my $loginscript; # piece of javascript used in two separate instances
                     69: my $generalrule;
                     70: my $authformnop;
                     71: my $authformkrb;
                     72: my $authformint;
                     73: my $authformfsys;
                     74: my $authformloc;
                     75: 
1.94      matthew    76: sub initialize_authen_forms {
                     77:     my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
                     78:     $krbdefdom= uc($krbdefdom);
1.31      matthew    79:     my %param = ( formname => 'document.cu',
                     80:                   kerb_def_dom => $krbdefdom 
                     81:                   );
1.48      albertel   82: # no longer static due to configurable kerberos defaults
                     83: #    $loginscript  = &Apache::loncommon::authform_header(%param);
1.31      matthew    84:     $generalrule  = &Apache::loncommon::authform_authorwarning(%param);
                     85:     $authformnop  = &Apache::loncommon::authform_nochange(%param);
1.48      albertel   86: # no longer static due to configurable kerberos defaults
                     87: #    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
1.31      matthew    88:     $authformint  = &Apache::loncommon::authform_internal(%param);
                     89:     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
                     90:     $authformloc  = &Apache::loncommon::authform_local(%param);
1.20      harris41   91: }
                     92: 
1.43      www        93: 
1.59      www        94: # ======================================================= Existing Custom Roles
                     95: 
                     96: sub my_custom_roles {
                     97:     my %returnhash=();
                     98:     my %rolehash=&Apache::lonnet::dump('roles');
                     99:     foreach (keys %rolehash) {
                    100: 	if ($_=~/^rolesdef\_(\w+)$/) {
1.61      www       101: 	    $returnhash{$1}=$1;
1.59      www       102: 	}
                    103:     }
                    104:     return %returnhash;
                    105: }
1.43      www       106: 
                    107: # ==================================================== Figure out author access
                    108: 
                    109: sub authorpriv {
                    110:     my ($auname,$audom)=@_;
1.105     www       111:     unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
                    112:          || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
1.43      www       113:     return 1;
                    114: }
                    115: 
1.2       www       116: # =================================================================== Phase one
1.1       www       117: 
1.42      matthew   118: sub print_username_entry_form {
1.2       www       119:     my $r=shift;
1.101     albertel  120:     my $defdom=$env{'request.role.domain'};
1.33      matthew   121:     my @domains = &Apache::loncommon::get_domains();
                    122:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.100     albertel  123:     my $html=&Apache::lonxml::xmlbegin();
1.84      albertel  124:     my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
1.46      www       125:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
                    126:     my $sellink=&Apache::loncommon::selectstudent_link
                    127:                                         ('crtuser','ccuname','ccdomain');
1.59      www       128:     my %existingroles=&my_custom_roles();
                    129:     my $choice=&Apache::loncommon::select_form('make new role','rolename',
                    130: 		('make new role' => 'Generate new role ...',%existingroles));
1.71      sakharuk  131:     my %lt=&Apache::lonlocal::texthash(
                    132: 		    'siur'   => "Set Individual User Roles",
                    133: 		    'usr'  => "Username",
                    134:                     'dom'  => "Domain",
                    135:                     'usrr' => "User Roles",
                    136:                     'ecrp' => "Edit Custom Role Privileges",
1.72      sakharuk  137:                     'nr'   => "Name of Role",
1.71      sakharuk  138:                     'cre'  => "Custom Role Editor"
                    139: 				       );
1.76      www       140:     my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
                    141:     my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
1.33      matthew   142:     $r->print(<<"ENDDOCUMENT");
1.100     albertel  143: $html
1.1       www       144: <head>
                    145: <title>The LearningOnline Network with CAPA</title>
1.46      www       146: $selscript
1.1       www       147: </head>
1.40      www       148: $bodytag
1.46      www       149: <form action="/adm/createuser" method="post" name="crtuser">
1.42      matthew   150: <input type="hidden" name="phase" value="get_user_info">
1.76      www       151: <h2>$lt{siur}$helpsiur</h2>
1.43      www       152: <table>
1.71      sakharuk  153: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
1.46      www       154: </td><td rowspan="2">$sellink</td></tr><tr><td>
1.71      sakharuk  155: $lt{'dom'}:</td><td>$domform</td></tr>
1.58      www       156: </table>
1.71      sakharuk  157: <input name="userrole" type="submit" value="$lt{usrr}" />
1.2       www       158: </form>
1.106     www       159: ENDDOCUMENT
                    160:    if (&Apache::lonnet::allowed('mcr','/')) {
                    161:        $r->print(<<ENDCUSTOM);
1.58      www       162: <form action="/adm/createuser" method="post" name="docustom">
                    163: <input type="hidden" name="phase" value="selected_custom_edit">
1.76      www       164: <h2>$lt{'ecrp'}$helpecpr</h2>
1.72      sakharuk  165: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71      sakharuk  166: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107     www       167: </form>
1.106     www       168: ENDCUSTOM
1.107     www       169:     }
                    170:     $r->print('</body></html>');
1.2       www       171: }
                    172: 
                    173: # =================================================================== Phase two
1.42      matthew   174: sub print_user_modification_page {
1.2       www       175:     my $r=shift;
1.101     albertel  176:     my $ccuname=$env{'form.ccuname'};
                    177:     my $ccdomain=$env{'form.ccdomain'};
1.4       www       178: 
1.98      albertel  179:     $ccuname=~s/\W//g;
                    180:     $ccdomain=~s/\W//g;
1.58      www       181: 
                    182:     unless (($ccuname) && ($ccdomain)) {
                    183: 	&print_username_entry_form($r);
                    184:         return;
                    185:     }
                    186: 
1.101     albertel  187:     my $defdom=$env{'request.role.domain'};
1.48      albertel  188: 
                    189:     my ($krbdef,$krbdefdom) =
                    190:        &Apache::loncommon::get_kerberos_defaults($defdom);
                    191: 
1.31      matthew   192:     my %param = ( formname => 'document.cu',
1.48      albertel  193:                   kerb_def_dom => $krbdefdom,
                    194:                   kerb_def_auth => $krbdef
1.31      matthew   195:                   );
                    196:     $loginscript  = &Apache::loncommon::authform_header(%param);
1.48      albertel  197:     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
1.4       www       198: 
1.2       www       199:     $ccuname=~s/\W//g;
                    200:     $ccdomain=~s/\W//g;
1.52      matthew   201:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88      raeburn   202:     my $dc_setcourse_code = '';
                    203:     my $loaditem;
1.101     albertel  204:     if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.88      raeburn   205:         my $dcdom = $1;
                    206:         $loaditem = qq|OnLoad="document.cu.coursedesc.value=''"|;
                    207:         $dc_setcourse_code = <<"ENDSCRIPT";
                    208:     function setCourse() {
                    209:         var course = document.cu.dccourse.value;
                    210:         if (course != "") {
                    211:             if (document.cu.dcdomain.value != document.cu.origdom.value) {
                    212:                 alert("You must select a course in the current domain");
                    213:                 return;
                    214:             } 
                    215:             var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
1.91      raeburn   216:             var section="";
1.88      raeburn   217:             var numsections = 0;
1.89      raeburn   218:             for (var i=0; i<document.cu.currsec.length; i++) {
                    219:                 if (document.cu.currsec.options[i].selected == true ) {
                    220:                     if (document.cu.currsec.options[i].value != "" && document.cu.currsec.options[i].value != null) { 
                    221:                         if (numsections == 0) {
                    222:                             section = document.cu.currsec.options[i].value
                    223:                             numsections = 1;
                    224:                         }
                    225:                         else {
                    226:                             section = section + "," +  document.cu.currsec.options[i].value
                    227:                             numsections ++;
1.88      raeburn   228:                         }
                    229:                     }
                    230:                 }
1.89      raeburn   231:             }
                    232:             if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
                    233:                 if (numsections == 0) {
                    234:                     section = document.cu.newsec.value
                    235:                 }
                    236:                 else {
                    237:                     section = section + "," +  document.cu.newsec.value
1.88      raeburn   238:                 }
1.89      raeburn   239:                 var numsplit = document.cu.newsec.value.split(/,/g);
                    240:                 numsections = numsections + numsplit.length;
                    241:             }
                    242:             if ((userrole == 'st') && (numsections > 1)) {
                    243:                 alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.")
                    244:                 return;
                    245:             }
                    246:             if ((userrole == 'cc') && (numsections > 0)) {
                    247:                 alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
                    248:                 section = "";
1.88      raeburn   249:             }
                    250:             var numcourse = getIndex(document.cu.dccourse);
                    251:             if (numcourse == "-1") {
                    252:                 alert("There was a problem with your course selection");
                    253:                 return
                    254:             }
                    255:             else { 
                    256:                 var coursename = "_$dcdom"+"_"+course+"_"+userrole
                    257:                 document.cu.elements[numcourse].name = "act"+coursename
                    258:                 document.cu.elements[numcourse+4].name = "sec"+coursename
                    259:                 document.cu.elements[numcourse+4].value = section
                    260:                 document.cu.elements[numcourse+5].name = "start"+coursename
                    261:                 document.cu.elements[numcourse+6].name = "end"+coursename
                    262:             }
                    263:         }
                    264:         document.cu.submit();
                    265:     }
                    266: 
                    267:     function getIndex(caller) {
                    268:         for (var i=0;i<document.cu.elements.length;i++) {
                    269:             if (document.cu.elements[i] == caller) {
                    270:                 return i;
                    271:             }
                    272:         }
                    273:         return -1;
                    274:     }
                    275: ENDSCRIPT
                    276:     }
1.100     albertel  277:     my $html=&Apache::lonxml::xmlbegin();
1.25      matthew   278:     my $dochead =<<"ENDDOCHEAD";
1.100     albertel  279: $html
1.2       www       280: <head>
                    281: <title>The LearningOnline Network with CAPA</title>
1.31      matthew   282: <script type="text/javascript" language="Javascript">
1.3       www       283: 
                    284:     function pclose() {
                    285:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    286:                  "height=350,width=350,scrollbars=no,menubar=no");
                    287:         parmwin.close();
                    288:     }
                    289: 
1.52      matthew   290:     $pjump_def
1.88      raeburn   291:     $dc_setcourse_code
1.3       www       292: 
                    293:     function dateset() {
                    294:         eval("document.cu."+document.cu.pres_marker.value+
                    295:             ".value=document.cu.pres_value.value");
                    296:         pclose();
                    297:     }
                    298: 
1.89      raeburn   299:     function setSections() {
                    300:         var re1 = /^currsec_/;
                    301:         for (var i=0;i<document.cu.elements.length;i++) {
                    302:             var str = document.cu.elements[i].name;
                    303:             var checkcurr = str.match(re1);
                    304:             if (checkcurr != null) {
                    305:                 var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
                    306:                 if (document.cu.elements[i-1].checked == true) {
                    307:                     var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
                    308:                     match = re2.exec(str);
                    309:                     var role = match[1];
                    310:                     if (role == 'cc') {
                    311:                         alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
                    312:                     }
                    313:                     else {
                    314:                         var sections = '';
                    315:                         var numsec = 0;
                    316:                         var sections;
                    317:                         for (var j=0; j<document.cu.elements[i].length; j++) {
                    318:                             if (document.cu.elements[i].options[j].selected == true ) {
                    319:                                 if (document.cu.elements[i].options[j].value != "") {
                    320:                                     if (numsec == 0) {
                    321:                                         if (document.cu.elements[i].options[j].value != "") {
                    322:                                             sections = document.cu.elements[i].options[j].value;
                    323:                                             numsec ++;
                    324:                                         }
                    325:                                     }
                    326:                                     else {
                    327:                                         sections = sections + "," +  document.cu.elements[i].options[j].value
                    328:                                         numsec ++;
                    329:                                     }
                    330:                                 }
                    331:                             }
                    332:                         }
                    333:                         if (numsec > 0) {
                    334:                             if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
                    335:                                 sections = sections + "," +  document.cu.elements[i+1].value;
                    336:                             } 
                    337:                         }
                    338:                         else {
                    339:                             sections = document.cu.elements[i+1].value;    
                    340:                         }
                    341:                         var newsecs = document.cu.elements[i+1].value;
                    342:                         if (newsecs != null && newsecs != "") {
                    343:                             var numsplit = newsecs.split(/,/g);
                    344:                             numsec = numsec + numsplit.length;
                    345:                         }
                    346:                         if ((role == 'st') && (numsec > 1)) {
                    347:                             alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")  
                    348:                             return;
                    349:                         }
                    350:                         else { 
                    351:                             document.cu.elements[i+2].value = sections;
                    352:                         }
                    353:                     }
                    354:                 }
                    355:             }
                    356:         }
                    357:         document.cu.submit();
                    358:     }
1.3       www       359: </script>
1.2       www       360: </head>
1.25      matthew   361: ENDDOCHEAD
1.40      www       362:     $r->print(&Apache::loncommon::bodytag(
1.88      raeburn   363:                                      'Create Users, Change User Privileges',undef,$loaditem));
1.25      matthew   364:     my $forminfo =<<"ENDFORMINFO";
                    365: <form action="/adm/createuser" method="post" name="cu">
1.42      matthew   366: <input type="hidden" name="phase"       value="update_user_data">
1.25      matthew   367: <input type="hidden" name="ccuname"     value="$ccuname">
                    368: <input type="hidden" name="ccdomain"    value="$ccdomain">
                    369: <input type="hidden" name="pres_value"  value="" >
                    370: <input type="hidden" name="pres_type"   value="" >
                    371: <input type="hidden" name="pres_marker" value="" >
                    372: ENDFORMINFO
1.2       www       373:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
                    374:     my %incdomains; 
                    375:     my %inccourses;
1.49      albertel  376:     foreach (values(%Apache::lonnet::hostdom)) {
1.13      www       377:        $incdomains{$_}=1;
1.24      matthew   378:     }
1.101     albertel  379:     foreach (keys(%env)) {
1.2       www       380: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
                    381: 	    $inccourses{$1.'_'.$2}=1;
                    382:         }
1.24      matthew   383:     }
1.2       www       384:     if ($uhome eq 'no_host') {
1.29      matthew   385:         my $home_server_list=
1.32      matthew   386:             '<option value="default" selected>default</option>'."\n".
                    387:                 &Apache::loncommon::home_server_option_list($ccdomain);
                    388:         
1.79      albertel  389: 	my %lt=&Apache::lonlocal::texthash(
1.72      sakharuk  390:                     'cnu'  => "Create New User",
                    391:                     'nu'   => "New User",
                    392:                     'id'   => "in domain",
                    393:                     'pd'   => "Personal Data",
                    394:                     'fn'   => "First Name",
                    395:                     'mn'   => "Middle Name",
                    396:                     'ln'   => "Last Name",
                    397:                     'gen'  => "Generation",
                    398:                     'idsn' => "ID/Student Number",
                    399:                     'hs'   => "Home Server",
                    400:                     'lg'   => "Login Data"
                    401: 				       );
1.78      www       402: 	my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1.94      matthew   403:         &initialize_authen_forms();
1.26      matthew   404: 	$r->print(<<ENDNEWUSER);
1.25      matthew   405: $dochead
1.72      sakharuk  406: <h1>$lt{'cnu'}</h1>
1.25      matthew   407: $forminfo
1.72      sakharuk  408: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
1.31      matthew   409: <script type="text/javascript" language="Javascript">
1.20      harris41  410: $loginscript
1.31      matthew   411: </script>
1.20      harris41  412: <input type='hidden' name='makeuser' value='1' />
1.72      sakharuk  413: <h3>$lt{'pd'}</h3>
1.25      matthew   414: <p>
                    415: <table>
1.72      sakharuk  416: <tr><td>$lt{'fn'}  </td>
1.25      matthew   417:     <td><input type='text' name='cfirst'  size='15' /></td></tr>
1.72      sakharuk  418: <tr><td>$lt{'mn'} </td> 
1.25      matthew   419:     <td><input type='text' name='cmiddle' size='15' /></td></tr>
1.72      sakharuk  420: <tr><td>$lt{'ln'}   </td>
1.25      matthew   421:     <td><input type='text' name='clast'   size='15' /></td></tr>
1.78      www       422: <tr><td>$lt{'gen'}$genhelp</td>
1.25      matthew   423:     <td><input type='text' name='cgen'    size='5'  /></td></tr>
                    424: </table>
1.72      sakharuk  425: $lt{'idsn'} <input type='text' name='cstid'   size='15' /></p>
1.74      sakharuk  426: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
1.25      matthew   427: <hr />
1.72      sakharuk  428: <h3>$lt{'lg'}</h3>
1.31      matthew   429: <p>$generalrule </p>
                    430: <p>$authformkrb </p>
                    431: <p>$authformint </p>
                    432: <p>$authformfsys</p>
                    433: <p>$authformloc </p>
1.26      matthew   434: ENDNEWUSER
1.25      matthew   435:     } else { # user already exists
1.79      albertel  436: 	my %lt=&Apache::lonlocal::texthash(
1.72      sakharuk  437:                     'cup'  => "Change User Privileges",
                    438:                     'usr'  => "User",                    
                    439:                     'id'   => "in domain",
                    440:                     'fn'   => "first name",
                    441:                     'mn'   => "middle name",
                    442:                     'ln'   => "last name",
                    443:                     'gen'  => "generation"
                    444: 				       );
1.26      matthew   445: 	$r->print(<<ENDCHANGEUSER);
1.25      matthew   446: $dochead
1.72      sakharuk  447: <h1>$lt{'cup'}</h1>
1.25      matthew   448: $forminfo
1.72      sakharuk  449: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
1.26      matthew   450: ENDCHANGEUSER
1.28      matthew   451:         # Get the users information
                    452:         my %userenv = &Apache::lonnet::get('environment',
                    453:                           ['firstname','middlename','lastname','generation'],
                    454:                           $ccdomain,$ccuname);
                    455:         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
                    456:         $r->print(<<END);
                    457: <hr />
                    458: <table border="2">
                    459: <tr>
1.72      sakharuk  460: <th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th>
1.28      matthew   461: </tr>
                    462: <tr>
                    463: END
                    464:         foreach ('firstname','middlename','lastname','generation') {
                    465:            if (&Apache::lonnet::allowed('mau',$ccdomain)) {
                    466:               $r->print(<<"END");            
1.53      www       467: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
1.28      matthew   468: END
                    469:            } else {
                    470:                $r->print('<td>'.$userenv{$_}.'</td>');
                    471:            }
                    472:         }
1.72      sakharuk  473:       $r->print(<<END);
1.28      matthew   474: </tr>
                    475: </table>
                    476: END
1.25      matthew   477:         # Build up table of user roles to allow revocation of a role.
1.28      matthew   478:         my ($tmp) = keys(%rolesdump);
                    479:         unless ($tmp =~ /^(con_lost|error)/i) {
1.2       www       480:            my $now=time;
1.72      sakharuk  481: 	   my %lt=&Apache::lonlocal::texthash(
                    482: 		    'rer'  => "Revoke Existing Roles",
                    483:                     'rev'  => "Revoke",                    
                    484:                     'del'  => "Delete",
1.81      albertel  485: 		    'ren'  => "Re-Enable",
1.72      sakharuk  486:                     'rol'  => "Role",
                    487:                     'ext'  => "Extent",
                    488:                     'sta'  => "Start",
                    489:                     'end'  => "End"
                    490: 				       );
1.89      raeburn   491:            my (%roletext,%sortrole,%roleclass,%rolepriv);
1.67      albertel  492: 	   foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
                    493: 				    my $b1=join('_',(split('_',$b))[1,0]);
                    494: 				    return $a1 cmp $b1;
                    495: 				} keys(%rolesdump)) {
1.37      matthew   496:                next if ($area =~ /^rolesdef/);
1.79      albertel  497: 	       my $envkey=$area;
1.37      matthew   498:                my $role = $rolesdump{$area};
                    499:                my $thisrole=$area;
                    500:                $area =~ s/\_\w\w$//;
                    501:                my ($role_code,$role_end_time,$role_start_time) = 
                    502:                    split(/_/,$role);
1.64      www       503: # Is this a custom role? Get role owner and title.
                    504: 	       my ($croleudom,$croleuname,$croletitle)=
                    505: 	           ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
1.37      matthew   506:                my $bgcol='ffffff';
                    507:                my $allowed=0;
1.53      www       508:                my $delallowed=0;
1.79      albertel  509: 	       my $sortkey=$role_code;
                    510: 	       my $class='Unknown';
1.37      matthew   511:                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
1.79      albertel  512: 		   $class='Course';
1.57      matthew   513:                    my ($coursedom,$coursedir) = ($1,$2);
1.79      albertel  514: 		   $sortkey.="\0$1";
1.57      matthew   515:                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.37      matthew   516:                    my %coursedata=
                    517:                        &Apache::lonnet::coursedescription($1.'_'.$2);
1.51      albertel  518: 		   my $carea;
                    519: 		   if (defined($coursedata{'description'})) {
1.79      albertel  520: 		       $carea=$coursedata{'description'}.
1.72      sakharuk  521:                            '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
1.57      matthew   522:      &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
1.79      albertel  523: 		       $sortkey.="\0".$coursedata{'description'};
1.51      albertel  524: 		   } else {
1.72      sakharuk  525: 		       $carea=&mt('Unavailable course').': '.$area;
1.86      albertel  526: 		       $sortkey.="\0".&mt('Unavailable course').': '.$area;
1.51      albertel  527: 		   }
1.37      matthew   528:                    $inccourses{$1.'_'.$2}=1;
1.53      www       529:                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
                    530:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37      matthew   531:                        $allowed=1;
                    532:                    }
1.53      www       533:                    if ((&Apache::lonnet::allowed('dro',$1)) ||
                    534:                        (&Apache::lonnet::allowed('dro',$ccdomain))) {
                    535:                        $delallowed=1;
                    536:                    }
1.64      www       537: # - custom role. Needs more info, too
                    538: 		   if ($croletitle) {
                    539: 		       if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
                    540: 			   $allowed=1;
                    541: 			   $thisrole.='.'.$role_code;
                    542: 		       }
                    543: 		   }
1.37      matthew   544:                    # Compute the background color based on $area
                    545:                    $bgcol=$1.'_'.$2;
1.62      www       546:                    $bgcol=~s/[^7-9a-e]//g;
                    547:                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.37      matthew   548:                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
1.102     albertel  549:                        $carea.='<br />Section/Group: '.$3;
1.87      albertel  550: 		       $sortkey.="\0$3";
1.37      matthew   551:                    }
                    552:                    $area=$carea;
                    553:                } else {
1.79      albertel  554: 		   $sortkey.="\0".$area;
1.37      matthew   555:                    # Determine if current user is able to revoke privileges
                    556:                    if ($area=~ /^\/(\w+)\//) {
1.53      www       557:                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
                    558:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37      matthew   559:                            $allowed=1;
                    560:                        }
1.53      www       561:                        if (((&Apache::lonnet::allowed('dro',$1))  ||
                    562:                             (&Apache::lonnet::allowed('dro',$ccdomain))) &&
                    563:                            ($role_code ne 'dc')) {
                    564:                            $delallowed=1;
                    565:                        }
1.37      matthew   566:                    } else {
                    567:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
                    568:                            $allowed=1;
                    569:                        }
                    570:                    }
1.79      albertel  571: 		   if ($role_code eq 'ca' || $role_code eq 'au') {
                    572: 		       $class='Construction Space';
                    573: 		   } elsif ($role_code eq 'su') {
                    574: 		       $class='System';
                    575: 		   } else {
                    576: 		       $class='Domain';
                    577: 		   }
1.37      matthew   578:                }
1.105     www       579:                if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1.43      www       580:                    $area=~/\/(\w+)\/(\w+)/;
                    581: 		   if (&authorpriv($2,$1)) {
                    582: 		       $allowed=1;
                    583:                    } else {
                    584:                        $allowed=0;
1.37      matthew   585:                    }
                    586:                }
1.79      albertel  587: 	       $bgcol='77FF77';
1.37      matthew   588:                my $row = '';
1.62      www       589:                $row.='<tr bgcolor="#'.$bgcol.'"><td>';
1.37      matthew   590:                my $active=1;
                    591:                $active=0 if (($role_end_time) && ($now>$role_end_time));
                    592:                if (($active) && ($allowed)) {
                    593:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
                    594:                } else {
1.56      www       595:                    if ($active) {
                    596:                       $row.='&nbsp;';
                    597: 		   } else {
1.72      sakharuk  598:                       $row.=&mt('expired or revoked');
1.56      www       599: 		   }
1.37      matthew   600:                }
1.53      www       601: 	       $row.='</td><td>';
1.81      albertel  602:                if ($allowed && !$active) {
                    603:                    $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
                    604:                } else {
                    605:                    $row.='&nbsp;';
                    606:                }
                    607: 	       $row.='</td><td>';
1.53      www       608:                if ($delallowed) {
                    609:                    $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
                    610:                } else {
                    611:                    $row.='&nbsp;';
                    612:                }
1.64      www       613: 	       my $plaintext='';
                    614: 	       unless ($croletitle) {
                    615: 		   $plaintext=&Apache::lonnet::plaintext($role_code);
                    616: 	       } else {
                    617: 	           $plaintext=
                    618: 		"Customrole '$croletitle' defined by $croleuname\@$croleudom";
                    619: 	       }
                    620:                $row.= '</td><td>'.$plaintext.
1.37      matthew   621:                       '</td><td>'.$area.
                    622:                       '</td><td>'.($role_start_time?localtime($role_start_time)
                    623:                                                    : '&nbsp;' ).
                    624:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
                    625:                                                    : '&nbsp;' )
                    626:                       ."</td></tr>\n";
1.79      albertel  627: 	       $sortrole{$sortkey}=$envkey;
                    628: 	       $roletext{$envkey}=$row;
                    629: 	       $roleclass{$envkey}=$class;
1.89      raeburn   630:                $rolepriv{$envkey}=$allowed;
1.79      albertel  631:                #$r->print($row);
1.28      matthew   632:            } # end of foreach        (table building loop)
1.89      raeburn   633:            my $rolesdisplay = 0;
                    634:            my %output = ();
1.79      albertel  635: 	   foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
1.89      raeburn   636: 	       $output{$type} = '';
1.79      albertel  637: 	       foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1.89      raeburn   638: 		   if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) { 
                    639: 		       $output{$type}.=$roletext{$sortrole{$which}};
1.79      albertel  640: 		   }
                    641: 	       }
1.89      raeburn   642: 	       unless($output{$type} eq '') {
                    643: 		   $output{$type} = "<tr bgcolor='#BBffBB'>".
                    644: 			     "<td align='center' colspan='7'>".&mt($type)."</td>".
                    645:                               $output{$type};
                    646:                    $rolesdisplay = 1;
1.79      albertel  647: 	       }
                    648: 	   }
1.89      raeburn   649:            if ($rolesdisplay == 1) {
                    650:                $r->print(<<END);
                    651: <hr />
                    652: <h3>$lt{'rer'}</h3>
                    653: <table>
                    654: <tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'e
                    655: xt'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
                    656: END
                    657:                foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
                    658:                    if ($output{$type}) {
                    659:                        $r->print($output{$type}."\n");
                    660:                    }
                    661:                }
                    662: 	       $r->print('</table>');
                    663:            }
1.28      matthew   664:         }  # End of unless
1.20      harris41  665: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.41      albertel  666: 	if ($currentauth=~/^krb(4|5):/) {
                    667: 	    $currentauth=~/^krb(4|5):(.*)/;
1.108     albertel  668: 	    my $krbdefdom=$2;
1.31      matthew   669:             my %param = ( formname => 'document.cu',
                    670:                           kerb_def_dom => $krbdefdom 
                    671:                           );
                    672:             $loginscript  = &Apache::loncommon::authform_header(%param);
1.20      harris41  673: 	}
1.26      matthew   674: 	# Check for a bad authentication type
1.41      albertel  675:         unless ($currentauth=~/^krb(4|5):/ or
1.20      harris41  676: 		$currentauth=~/^unix:/ or
                    677: 		$currentauth=~/^internal:/ or
                    678: 		$currentauth=~/^localauth:/
1.26      matthew   679: 		) { # bad authentication scheme
1.101     albertel  680: 	    if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.94      matthew   681:                 &initialize_authen_forms();
1.73      sakharuk  682: 		my %lt=&Apache::lonlocal::texthash(
                    683:                                'err'   => "ERROR",
                    684: 			       'uuas'  => "This user has an unrecognized authentication scheme",
                    685:                                'sldb'  => "Please specify login data below",
                    686:                                'ld'    => "Login Data"
                    687: 						   );
1.26      matthew   688: 		$r->print(<<ENDBADAUTH);
1.21      harris41  689: <hr />
1.31      matthew   690: <script type="text/javascript" language="Javascript">
1.21      harris41  691: $loginscript
1.31      matthew   692: </script>
1.73      sakharuk  693: <font color='#ff0000'>$lt{'err'}:</font>
                    694: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
                    695: <h3>$lt{'ld'}</h3>
1.31      matthew   696: <p>$generalrule</p>
                    697: <p>$authformkrb</p>
                    698: <p>$authformint</p>
                    699: <p>$authformfsys</p>
                    700: <p>$authformloc</p>
1.26      matthew   701: ENDBADAUTH
                    702:             } else { 
                    703:                 # This user is not allowed to modify the users 
                    704:                 # authentication scheme, so just notify them of the problem
1.73      sakharuk  705: 		my %lt=&Apache::lonlocal::texthash(
                    706:                                'err'   => "ERROR",
                    707: 			       'uuas'  => "This user has an unrecognized authentication scheme",
                    708:                                'adcs'  => "Please alert a domain coordinator of this situation"
                    709: 						   );
1.26      matthew   710: 		$r->print(<<ENDBADAUTH);
                    711: <hr />
1.31      matthew   712: <script type="text/javascript" language="Javascript">
1.26      matthew   713: $loginscript
1.31      matthew   714: </script>
1.73      sakharuk  715: <font color="#ff0000"> $lt{'err'}: </font>
                    716: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1.26      matthew   717: <hr />
                    718: ENDBADAUTH
                    719:             }
                    720:         } else { # Authentication type is valid
1.20      harris41  721: 	    my $authformcurrent='';
1.26      matthew   722: 	    my $authform_other='';
1.94      matthew   723:             &initialize_authen_forms();
1.41      albertel  724: 	    if ($currentauth=~/^krb(4|5):/) {
1.20      harris41  725: 		$authformcurrent=$authformkrb;
1.31      matthew   726: 		$authform_other="<p>$authformint</p>\n".
                    727:                     "<p>$authformfsys</p><p>$authformloc</p>";
1.20      harris41  728: 	    }
                    729: 	    elsif ($currentauth=~/^internal:/) {
                    730: 		$authformcurrent=$authformint;
1.31      matthew   731: 		$authform_other="<p>$authformkrb</p>".
                    732:                     "<p>$authformfsys</p><p>$authformloc</p>";
1.20      harris41  733: 	    }
                    734: 	    elsif ($currentauth=~/^unix:/) {
                    735: 		$authformcurrent=$authformfsys;
1.31      matthew   736: 		$authform_other="<p>$authformkrb</p>".
                    737:                     "<p>$authformint</p><p>$authformloc;</p>";
1.20      harris41  738: 	    }
                    739: 	    elsif ($currentauth=~/^localauth:/) {
                    740: 		$authformcurrent=$authformloc;
1.31      matthew   741: 		$authform_other="<p>$authformkrb</p>".
                    742:                     "<p>$authformint</p><p>$authformfsys</p>";
1.20      harris41  743: 	    }
1.53      www       744:             $authformcurrent.=' <i>(will override current values)</i><br />';
1.101     albertel  745:             if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.26      matthew   746: 		# Current user has login modification privileges
1.73      sakharuk  747: 		my %lt=&Apache::lonlocal::texthash(
                    748:                                'ccld'  => "Change Current Login Data",
                    749: 			       'enld'  => "Enter New Login Data"
                    750: 						   );
1.26      matthew   751: 		$r->print(<<ENDOTHERAUTHS);
1.21      harris41  752: <hr />
1.31      matthew   753: <script type="text/javascript" language="Javascript">
1.21      harris41  754: $loginscript
1.31      matthew   755: </script>
1.73      sakharuk  756: <h3>$lt{'ccld'}</h3>
1.31      matthew   757: <p>$generalrule</p>
                    758: <p>$authformnop</p>
                    759: <p>$authformcurrent</p>
1.73      sakharuk  760: <h3>$lt{'enld'}</h3>
1.26      matthew   761: $authform_other
                    762: ENDOTHERAUTHS
                    763:             }
                    764:         }  ## End of "check for bad authentication type" logic
1.25      matthew   765:     } ## End of new user/old user logic
1.72      sakharuk  766:     $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1.17      www       767: #
                    768: # Co-Author
                    769: # 
1.101     albertel  770:     if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
                    771:         ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1.44      matthew   772:         # No sense in assigning co-author role to yourself
1.101     albertel  773: 	my $cuname=$env{'user.name'};
                    774:         my $cudom=$env{'request.role.domain'};
1.72      sakharuk  775: 	   my %lt=&Apache::lonlocal::texthash(
                    776: 		    'cs'   => "Construction Space",
                    777:                     'act'  => "Activate",                    
                    778:                     'rol'  => "Role",
                    779:                     'ext'  => "Extent",
                    780:                     'sta'  => "Start",
1.80      www       781:                     'end'  => "End",
1.72      sakharuk  782:                     'cau'  => "Co-Author",
1.105     www       783:                     'caa'  => "Assistant Co-Author",
1.72      sakharuk  784:                     'ssd'  => "Set Start Date",
                    785:                     'sed'  => "Set End Date"
                    786: 				       );
1.17      www       787:        $r->print(<<ENDCOAUTH);
1.72      sakharuk  788: <h4>$lt{'cs'}</h4>
1.74      sakharuk  789: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1.72      sakharuk  790: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.17      www       791: <tr>
1.80      www       792: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
1.72      sakharuk  793: <td>$lt{'cau'}</td>
1.17      www       794: <td>$cudom\_$cuname</td>
1.80      www       795: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
1.17      www       796: <a href=
1.72      sakharuk  797: "javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.80      www       798: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
1.17      www       799: <a href=
1.72      sakharuk  800: "javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'sed'}</a></td>
1.17      www       801: </tr>
1.105     www       802: <tr>
                    803: <td><input type=checkbox name="act_$cudom\_$cuname\_aa" /></td>
                    804: <td>$lt{'caa'}</td>
                    805: <td>$cudom\_$cuname</td>
                    806: <td><input type=hidden name="start_$cudom\_$cuname\_aa" value='' />
                    807: <a href=
                    808: "javascript:pjump('date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset')">$lt{'ssd'}</a></td>
                    809: <td><input type=hidden name="end_$cudom\_$cuname\_aa" value='' />
                    810: <a href=
                    811: "javascript:pjump('date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset')">$lt{'sed'}</a></td>
                    812: </tr>
1.17      www       813: </table>
                    814: ENDCOAUTH
                    815:     }
1.8       www       816: #
                    817: # Domain level
                    818: #
1.89      raeburn   819:     my $num_domain_level = 0;
                    820:     my $domaintext = 
                    821:     '<h4>'.&mt('Domain Level').'</h4>'.
1.73      sakharuk  822:     '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
1.89      raeburn   823:     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>';
1.24      matthew   824:     foreach ( sort( keys(%incdomains))) {
1.2       www       825: 	my $thisdomain=$_;
1.69      albertel  826:         foreach ('dc','li','dg','au','sc') {
1.2       www       827:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8       www       828:                my $plrole=&Apache::lonnet::plaintext($_);
1.72      sakharuk  829: 	       my %lt=&Apache::lonlocal::texthash(
                    830:                     'ssd'  => "Set Start Date",
                    831:                     'sed'  => "Set End Date"
                    832: 				       );
1.89      raeburn   833:                $num_domain_level ++;
                    834:                $domaintext .= <<"ENDDROW";
1.8       www       835: <tr>
                    836: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
                    837: <td>$plrole</td>
                    838: <td>$thisdomain</td>
                    839: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
                    840: <a href=
1.72      sakharuk  841: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.8       www       842: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
                    843: <a href=
1.72      sakharuk  844: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.8       www       845: </tr>
                    846: ENDDROW
1.2       www       847:             }
1.24      matthew   848:         } 
                    849:     }
1.89      raeburn   850:     $domaintext.='</table>';
                    851:     if ($num_domain_level > 0) {
                    852:         $r->print($domaintext);
                    853:     }
1.8       www       854: #
                    855: # Course level
                    856: #
1.89      raeburn   857:     my $num_sections;
1.88      raeburn   858: 
1.101     albertel  859:     if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.88      raeburn   860:         $r->print(&course_level_dc($1));
                    861:         $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
                    862:     } else {
                    863:         $r->print(&course_level_table(%inccourses));
1.89      raeburn   864:         $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()">'."\n");
1.88      raeburn   865:     }
1.26      matthew   866:     $r->print("</form></body></html>");
1.2       www       867: }
1.1       www       868: 
1.4       www       869: # ================================================================= Phase Three
1.42      matthew   870: sub update_user_data {
1.4       www       871:     my $r=shift;
1.101     albertel  872:     my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                    873:                                           $env{'form.ccdomain'});
1.27      matthew   874:     # Error messages
1.73      sakharuk  875:     my $error     = '<font color="#ff0000">'.&mt('Error').':</font>';
1.27      matthew   876:     my $end       = '</body></html>';
                    877:     # Print header
1.100     albertel  878:     my $html=&Apache::lonxml::xmlbegin();
1.4       www       879:     $r->print(<<ENDTHREEHEAD);
1.100     albertel  880: $html
1.4       www       881: <head>
                    882: <title>The LearningOnline Network with CAPA</title>
                    883: </head>
                    884: ENDTHREEHEAD
1.40      www       885:     my $title;
1.101     albertel  886:     if (exists($env{'form.makeuser'})) {
1.40      www       887: 	$title='Set Privileges for New User';
                    888:     } else {
                    889:         $title='Modify User Privileges';
                    890:     }
                    891:     $r->print(&Apache::loncommon::bodytag($title));
1.27      matthew   892:     # Check Inputs
1.101     albertel  893:     if (! $env{'form.ccuname'} ) {
1.73      sakharuk  894: 	$r->print($error.&mt('No login name specified').'.'.$end);
1.27      matthew   895: 	return;
                    896:     }
1.101     albertel  897:     if (  $env{'form.ccuname'}  =~/\W/) {
1.73      sakharuk  898: 	$r->print($error.&mt('Invalid login name').'.  '.
                    899: 		  &mt('Only letters, numbers, and underscores are valid').'.'.
1.27      matthew   900: 		  $end);
                    901: 	return;
                    902:     }
1.101     albertel  903:     if (! $env{'form.ccdomain'}       ) {
1.73      sakharuk  904: 	$r->print($error.&mt('No domain specified').'.'.$end);
1.27      matthew   905: 	return;
                    906:     }
1.101     albertel  907:     if (  $env{'form.ccdomain'} =~/\W/) {
1.73      sakharuk  908: 	$r->print($error.&mt ('Invalid domain name').'.  '.
                    909: 		  &mt('Only letters, numbers, and underscores are valid').'.'.
1.27      matthew   910: 		  $end);
                    911: 	return;
                    912:     }
1.101     albertel  913:     if (! exists($env{'form.makeuser'})) {
1.29      matthew   914:         # Modifying an existing user, so check the validity of the name
                    915:         if ($uhome eq 'no_host') {
1.73      sakharuk  916:             $r->print($error.&mt('Unable to determine home server for ').
1.101     albertel  917:                       $env{'form.ccuname'}.&mt(' in domain ').
                    918:                       $env{'form.ccdomain'}.'.');
1.29      matthew   919:             return;
                    920:         }
                    921:     }
1.27      matthew   922:     # Determine authentication method and password for the user being modified
                    923:     my $amode='';
                    924:     my $genpwd='';
1.101     albertel  925:     if ($env{'form.login'} eq 'krb') {
1.41      albertel  926: 	$amode='krb';
1.101     albertel  927: 	$amode.=$env{'form.krbver'};
                    928: 	$genpwd=$env{'form.krbarg'};
                    929:     } elsif ($env{'form.login'} eq 'int') {
1.27      matthew   930: 	$amode='internal';
1.101     albertel  931: 	$genpwd=$env{'form.intarg'};
                    932:     } elsif ($env{'form.login'} eq 'fsys') {
1.27      matthew   933: 	$amode='unix';
1.101     albertel  934: 	$genpwd=$env{'form.fsysarg'};
                    935:     } elsif ($env{'form.login'} eq 'loc') {
1.27      matthew   936: 	$amode='localauth';
1.101     albertel  937: 	$genpwd=$env{'form.locarg'};
1.27      matthew   938: 	$genpwd=" " if (!$genpwd);
1.101     albertel  939:     } elsif (($env{'form.login'} eq 'nochange') ||
                    940:              ($env{'form.login'} eq ''        )) { 
1.34      matthew   941:         # There is no need to tell the user we did not change what they
                    942:         # did not ask us to change.
1.35      matthew   943:         # If they are creating a new user but have not specified login
                    944:         # information this will be caught below.
1.30      matthew   945:     } else {
1.73      sakharuk  946: 	    $r->print($error.&mt('Invalid login mode or password').$end);    
1.30      matthew   947: 	    return;
1.27      matthew   948:     }
1.101     albertel  949:     if ($env{'form.makeuser'}) {
1.27      matthew   950:         # Create a new user
1.73      sakharuk  951: 	my %lt=&Apache::lonlocal::texthash(
                    952:                     'cru'  => "Creating user",                    
                    953:                     'id'   => "in domain"
                    954: 					   );
1.27      matthew   955: 	$r->print(<<ENDNEWUSERHEAD);
1.101     albertel  956: <h3>$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h3>
1.27      matthew   957: ENDNEWUSERHEAD
                    958:         # Check for the authentication mode and password
                    959:         if (! $amode || ! $genpwd) {
1.73      sakharuk  960: 	    $r->print($error.&mt('Invalid login mode or password').$end);    
1.27      matthew   961: 	    return;
1.18      albertel  962: 	}
1.29      matthew   963:         # Determine desired host
1.101     albertel  964:         my $desiredhost = $env{'form.hserver'};
1.29      matthew   965:         if (lc($desiredhost) eq 'default') {
                    966:             $desiredhost = undef;
                    967:         } else {
1.39      matthew   968:             my %home_servers = &Apache::loncommon::get_library_servers
1.101     albertel  969:                 ($env{'form.ccdomain'});  
1.29      matthew   970:             if (! exists($home_servers{$desiredhost})) {
1.73      sakharuk  971:                 $r->print($error.&mt('Invalid home server specified'));
1.29      matthew   972:                 return;
                    973:             }
                    974:         }
1.27      matthew   975: 	# Call modifyuser
                    976: 	my $result = &Apache::lonnet::modifyuser
1.101     albertel  977: 	    ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
                    978:              $amode,$genpwd,$env{'form.cfirst'},
                    979:              $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1.29      matthew   980:              undef,$desiredhost
1.27      matthew   981: 	     );
1.77      www       982: 	$r->print(&mt('Generating user').': '.$result);
1.101     albertel  983:         my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
                    984:                                                $env{'form.ccdomain'});
1.77      www       985:         $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.29      matthew   986:                   $Apache::lonnet::libserv{$home});
1.101     albertel  987:     } elsif (($env{'form.login'} ne 'nochange') &&
                    988:              ($env{'form.login'} ne ''        )) {
1.27      matthew   989: 	# Modify user privileges
1.73      sakharuk  990:     my %lt=&Apache::lonlocal::texthash(
                    991:                     'usr'  => "User",                    
                    992:                     'id'   => "in domain"
                    993: 				       );
1.27      matthew   994: 	$r->print(<<ENDMODIFYUSERHEAD);
1.101     albertel  995: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.27      matthew   996: ENDMODIFYUSERHEAD
                    997:         if (! $amode || ! $genpwd) {
                    998: 	    $r->print($error.'Invalid login mode or password'.$end);    
                    999: 	    return;
1.20      harris41 1000: 	}
1.27      matthew  1001: 	# Only allow authentification modification if the person has authority
1.101     albertel 1002: 	if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20      harris41 1003: 	    $r->print('Modifying authentication: '.
1.31      matthew  1004:                       &Apache::lonnet::modifyuserauth(
1.101     albertel 1005: 		       $env{'form.ccdomain'},$env{'form.ccuname'},
1.21      harris41 1006:                        $amode,$genpwd));
1.102     albertel 1007:             $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101     albertel 1008: 		  ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4       www      1009: 	} else {
1.27      matthew  1010: 	    # Okay, this is a non-fatal error.
1.73      sakharuk 1011: 	    $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');    
1.27      matthew  1012: 	}
1.28      matthew  1013:     }
                   1014:     ##
1.101     albertel 1015:     if (! $env{'form.makeuser'} ) {
1.28      matthew  1016:         # Check for need to change
                   1017:         my %userenv = &Apache::lonnet::get
                   1018:             ('environment',['firstname','middlename','lastname','generation'],
1.101     albertel 1019:              $env{'form.ccdomain'},$env{'form.ccuname'});
1.28      matthew  1020:         my ($tmp) = keys(%userenv);
                   1021:         if ($tmp =~ /^(con_lost|error)/i) { 
                   1022:             %userenv = ();
                   1023:         }
                   1024:         # Check to see if we need to change user information
                   1025:         foreach ('firstname','middlename','lastname','generation') {
                   1026:             # Strip leading and trailing whitespace
1.101     albertel 1027:             $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
1.28      matthew  1028:         }
1.101     albertel 1029:         if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && 
                   1030:             ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
                   1031:              $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
                   1032:              $env{'form.clastname'}   ne $userenv{'lastname'}   ||
                   1033:              $env{'form.cgeneration'} ne $userenv{'generation'} )) {
1.28      matthew  1034:             # Make the change
                   1035:             my %changeHash;
1.101     albertel 1036:             $changeHash{'firstname'}  = $env{'form.cfirstname'};
                   1037:             $changeHash{'middlename'} = $env{'form.cmiddlename'};
                   1038:             $changeHash{'lastname'}   = $env{'form.clastname'};
                   1039:             $changeHash{'generation'} = $env{'form.cgeneration'};
1.28      matthew  1040:             my $putresult = &Apache::lonnet::put
                   1041:                 ('environment',\%changeHash,
1.101     albertel 1042:                  $env{'form.ccdomain'},$env{'form.ccuname'});
1.28      matthew  1043:             if ($putresult eq 'ok') {
                   1044:             # Tell the user we changed the name
1.73      sakharuk 1045: 		my %lt=&Apache::lonlocal::texthash(
                   1046:                              'uic'  => "User Information Changed",             
                   1047:                              'frst' => "first",
                   1048:                              'mddl' => "middle",
                   1049:                              'lst'  => "last",
                   1050: 			     'gen'  => "generation",
                   1051:                              'prvs' => "Previous",
                   1052:                              'chto' => "Changed To"
                   1053: 						   );
1.28      matthew  1054:                 $r->print(<<"END");
                   1055: <table border="2">
1.73      sakharuk 1056: <caption>$lt{'uic'}</caption>
1.28      matthew  1057: <tr><th>&nbsp;</th>
1.73      sakharuk 1058:     <th>$lt{'frst'}</th>
                   1059:     <th>$lt{'mddl'}</th>
                   1060:     <th>$lt{'lst'}</th>
                   1061:     <th>$lt{'gen'}</th></tr>
                   1062: <tr><td>$lt{'prvs'}</td>
1.28      matthew  1063:     <td>$userenv{'firstname'}  </td>
                   1064:     <td>$userenv{'middlename'} </td>
                   1065:     <td>$userenv{'lastname'}   </td>
                   1066:     <td>$userenv{'generation'} </td></tr>
1.73      sakharuk 1067: <tr><td>$lt{'chto'}</td>
1.101     albertel 1068:     <td>$env{'form.cfirstname'}  </td>
                   1069:     <td>$env{'form.cmiddlename'} </td>
                   1070:     <td>$env{'form.clastname'}   </td>
                   1071:     <td>$env{'form.cgeneration'} </td></tr>
1.28      matthew  1072: </table>
                   1073: END
                   1074:             } else { # error occurred
1.73      sakharuk 1075:                 $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1.101     albertel 1076:                       $env{'form.ccuname'}." ".&mt('in domain')." ".
                   1077:                       $env{'form.ccdomain'}."</h2>");
1.28      matthew  1078:             }
1.101     albertel 1079:         }  else { # End of if ($env ... ) logic
1.28      matthew  1080:             # They did not want to change the users name but we can
                   1081:             # still tell them what the name is
1.73      sakharuk 1082: 	    my %lt=&Apache::lonlocal::texthash(
                   1083:                            'usr'  => "User",                    
                   1084:                            'id'   => "in domain",
                   1085:                            'gen'  => "Generation"
                   1086: 					       );
1.28      matthew  1087:                 $r->print(<<"END");
1.101     albertel 1088: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.28      matthew  1089: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1.73      sakharuk 1090: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1.28      matthew  1091: END
                   1092:         }
1.4       www      1093:     }
1.27      matthew  1094:     ##
1.4       www      1095:     my $now=time;
1.73      sakharuk 1096:     $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.101     albertel 1097:     foreach (keys (%env)) {
                   1098: 	next if (! $env{$_});
1.27      matthew  1099: 	# Revoke roles
                   1100: 	if ($_=~/^form\.rev/) {
1.64      www      1101: 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
                   1102: # Revoke standard role
1.73      sakharuk 1103: 	        $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.101     albertel 1104:                      &Apache::lonnet::revokerole($env{'form.ccdomain'},
1.102     albertel 1105:                      $env{'form.ccuname'},$1,$2).'</b><br />');
1.53      www      1106: 		if ($2 eq 'st') {
                   1107: 		    $1=~/^\/(\w+)\/(\w+)/;
                   1108: 		    my $cid=$1.'_'.$2;
1.73      sakharuk 1109: 		    $r->print(&mt('Drop from classlist').': <b>'.
1.53      www      1110: 			 &Apache::lonnet::critical('put:'.
1.101     albertel 1111:                              $env{'course.'.$cid.'.domain'}.':'.
                   1112: 	                     $env{'course.'.$cid.'.num'}.':classlist:'.
                   1113:                          &Apache::lonnet::escape($env{'form.ccuname'}.':'.
                   1114:                              $env{'form.ccdomain'}).'='.
1.53      www      1115:                          &Apache::lonnet::escape($now.':'),
1.102     albertel 1116: 	                     $env{'course.'.$cid.'.home'}).'</b><br />');
1.53      www      1117: 		}
                   1118: 	    } 
1.64      www      1119: 	    if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
                   1120: # Revoke custom role
1.73      sakharuk 1121: 		$r->print(&mt('Revoking custom role').
                   1122:                       ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
1.101     albertel 1123:                       &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
                   1124: 				  $env{'form.ccuname'},$1,$2,$3,$4).
1.102     albertel 1125: 		'</b><br />');
1.64      www      1126: 	    }
1.53      www      1127: 	} elsif ($_=~/^form\.del/) {
                   1128: 	    if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
1.73      sakharuk 1129: 	        $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.101     albertel 1130:                      &Apache::lonnet::assignrole($env{'form.ccdomain'},
1.102     albertel 1131:                      $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1.27      matthew  1132: 		if ($2 eq 'st') {
                   1133: 		    $1=~/^\/(\w+)\/(\w+)/;
                   1134: 		    my $cid=$1.'_'.$2;
1.73      sakharuk 1135: 		    $r->print(&mt('Drop from classlist').': <b>'.
1.27      matthew  1136: 			 &Apache::lonnet::critical('put:'.
1.101     albertel 1137:                              $env{'course.'.$cid.'.domain'}.':'.
                   1138: 	                     $env{'course.'.$cid.'.num'}.':classlist:'.
                   1139:                          &Apache::lonnet::escape($env{'form.ccuname'}.':'.
                   1140:                              $env{'form.ccdomain'}).'='.
1.27      matthew  1141:                          &Apache::lonnet::escape($now.':'),
1.102     albertel 1142: 	                     $env{'course.'.$cid.'.home'}).'</b><br />');
1.81      albertel 1143: 		}
                   1144: 	    } 
                   1145: 	} elsif ($_=~/^form\.ren/) {
1.101     albertel 1146:             my $udom = $env{'form.ccdomain'};
                   1147:             my $uname = $env{'form.ccuname'};
1.81      albertel 1148: 	    if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
1.89      raeburn  1149:                 my $url = $1;
                   1150:                 my $role = $2;
                   1151:                 my $logmsg;
                   1152:                 my $output;
                   1153:                 if ($role eq 'st') {
                   1154:                     if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
1.99      raeburn  1155:                         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89      raeburn  1156:                         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
                   1157:                             $output = "Error: $result\n";
                   1158:                         } else {
                   1159:                             $output = &mt('Assigning').' '.$role.' in '.$url.
                   1160:                                       &mt('starting').' '.localtime($now).
                   1161:                                       ': <br />'.$logmsg.'<br />'.
                   1162:                                       &mt('Add to classlist').': <b>ok</b><br />';
                   1163:                         }
                   1164:                     }
                   1165:                 } else {
1.101     albertel 1166: 		    my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
                   1167:                                $env{'form.ccuname'},$url,$role,0,$now);
1.89      raeburn  1168: 		    $output = &mt('Re-Enabling [_1] in [_2]: [_3]',
                   1169: 			      $role,$url,$result).'<br />';
1.27      matthew  1170: 		}
1.89      raeburn  1171:                 $r->print($output);
1.27      matthew  1172: 	    } 
                   1173: 	} elsif ($_=~/^form\.act/) {
1.101     albertel 1174:             my $udom = $env{'form.ccdomain'};
                   1175:             my $uname = $env{'form.ccuname'};
1.83      albertel 1176: 	    if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1.65      www      1177:                 # Activate a custom role
1.83      albertel 1178: 		my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
                   1179: 		my $url='/'.$one.'/'.$two;
                   1180: 		my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65      www      1181: 
1.101     albertel 1182:                 my $start = ( $env{'form.start_'.$full} ?
                   1183:                               $env{'form.start_'.$full} :
1.88      raeburn  1184:                               $now );
1.101     albertel 1185:                 my $end   = ( $env{'form.end_'.$full} ?
                   1186:                               $env{'form.end_'.$full} :
1.88      raeburn  1187:                               0 );
                   1188:                                                                                      
                   1189:                 # split multiple sections
                   1190:                 my %sections = ();
1.101     albertel 1191:                 my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88      raeburn  1192:                 if ($num_sections == 0) {
1.99      raeburn  1193:                     $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88      raeburn  1194:                 } else {
                   1195:                     foreach (sort {$a cmp $b} keys %sections) {
                   1196:                         my $securl = $url.'/'.$_;
1.99      raeburn  1197: 		        $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88      raeburn  1198:                     }
                   1199:                 }
1.98      albertel 1200: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
1.27      matthew  1201: 		# Activate roles for sections with 3 id numbers
                   1202: 		# set start, end times, and the url for the class
1.83      albertel 1203: 		my ($one,$two,$three)=($1,$2,$3);
1.101     albertel 1204: 		my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ? 
                   1205: 			      $env{'form.start_'.$one.'_'.$two.'_'.$three} : 
1.27      matthew  1206: 			      $now );
1.101     albertel 1207: 		my $end   = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ? 
                   1208: 			      $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27      matthew  1209: 			      0 );
1.83      albertel 1210: 		my $url='/'.$one.'/'.$two;
1.88      raeburn  1211:                 my $type = 'three';
                   1212:                 # split multiple sections
                   1213:                 my %sections = ();
1.101     albertel 1214:                 my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88      raeburn  1215:                 if ($num_sections == 0) {
1.99      raeburn  1216:                     $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88      raeburn  1217:                 } else {
                   1218:                     my $emptysec = 0;
                   1219:                     foreach my $sec (sort {$a cmp $b} keys %sections) {
                   1220:                         $sec =~ s/\W//g;
                   1221:                         if ($sec ne '') {  
                   1222:                             my $securl = $url.'/'.$sec;
1.99      raeburn  1223:                             $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88      raeburn  1224:                         } else {
                   1225:                             $emptysec = 1;
                   1226:                         }
                   1227:                     }
                   1228:                     if ($emptysec) {
1.99      raeburn  1229:                         $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88      raeburn  1230:                     }
                   1231:                 } 
1.27      matthew  1232: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
                   1233: 		# Activate roles for sections with two id numbers
                   1234: 		# set start, end times, and the url for the class
1.101     albertel 1235: 		my $start = ( $env{'form.start_'.$1.'_'.$2} ? 
                   1236: 			      $env{'form.start_'.$1.'_'.$2} : 
1.27      matthew  1237: 			      $now );
1.101     albertel 1238: 		my $end   = ( $env{'form.end_'.$1.'_'.$2} ? 
                   1239: 			      $env{'form.end_'.$1.'_'.$2} :
1.27      matthew  1240: 			      0 );
                   1241: 		my $url='/'.$1.'/';
1.88      raeburn  1242:                 # split multiple sections
                   1243:                 my %sections = ();
1.101     albertel 1244:                 my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88      raeburn  1245:                 if ($num_sections == 0) {
1.99      raeburn  1246:                     $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88      raeburn  1247:                 } else {
                   1248:                     my $emptysec = 0;
                   1249:                     foreach my $sec (sort {$a cmp $b} keys %sections) {
                   1250:                         if ($sec ne '') {
                   1251:                             my $securl = $url.'/'.$sec;
1.99      raeburn  1252:                             $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88      raeburn  1253:                         } else {
                   1254:                             $emptysec = 1;
                   1255:                         }
                   1256:                     }
                   1257:                     if ($emptysec) {
1.99      raeburn  1258:                         $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88      raeburn  1259:                     }
                   1260:                 }
1.64      www      1261: 	    } else {
1.102     albertel 1262: 		$r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />');
1.64      www      1263:             }
1.27      matthew  1264: 	} 
1.101     albertel 1265:     } # End of foreach (keys(%env))
1.75      www      1266: # Flush the course logs so reverse user roles immediately updated
                   1267:     &Apache::lonnet::flushcourselogs();
1.103     albertel 1268:     $r->print('<p><a href="/adm/createuser">Create/Modify Another User</a></p>');
1.5       www      1269:     $r->print('</body></html>');
1.4       www      1270: }
                   1271: 
1.88      raeburn  1272: sub commit_customrole {
1.99      raeburn  1273:     my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1.88      raeburn  1274:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
                   1275:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   1276:                          ($end?', ending '.localtime($end):'').': <b>'.
                   1277:               &Apache::lonnet::assigncustomrole(
1.99      raeburn  1278:                  $udom,$uname,$url,$three,$four,$five,$end,$start).
1.102     albertel 1279:                  '</b><br />';
1.88      raeburn  1280:     return $output;
                   1281: }
                   1282: 
                   1283: sub commit_standardrole {
1.99      raeburn  1284:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89      raeburn  1285:     my $output;
                   1286:     my $logmsg;
                   1287:     if ($three eq 'st') {
1.99      raeburn  1288:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
1.89      raeburn  1289:         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
                   1290:             $output = "Error: $result\n"; 
                   1291:         } else {
                   1292:             $output = &mt('Assigning').' '.$three.' in '.$url.
                   1293:                ($start?', '.&mt('starting').' '.localtime($start):'').
                   1294:                ($end?', '.&mt('ending').' '.localtime($end):'').
                   1295:                ': <b>'.$result.'</b><br />'.
                   1296:                &mt('Add to classlist').': <b>ok</b><br />';
                   1297:         }
                   1298:     } else {
1.92      raeburn  1299:         $output = &mt('Assigning').' '.$three.' in '.$url.
1.89      raeburn  1300:                ($start?', '.&mt('starting').' '.localtime($start):'').
                   1301:                ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
                   1302:                &Apache::lonnet::assignrole(
1.99      raeburn  1303:                    $udom,$uname,$url,$three,$end,$start).
1.102     albertel 1304:                    '</b><br />';
1.88      raeburn  1305:     }
                   1306:     return $output;
                   1307: }
                   1308: 
1.89      raeburn  1309: sub commit_studentrole {
1.99      raeburn  1310:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89      raeburn  1311:     my $linefeed =  '<br />'."\n";
                   1312:     my $result;
                   1313:     if (defined($one) && defined($two)) {
                   1314:         my $cid=$one.'_'.$two;
                   1315:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   1316:         my $secchange = 0;
                   1317:         my $expire_role_result;
                   1318:         my $modify_section_result;
                   1319:         unless ($oldsec eq '-1') {
                   1320:             unless ($sec eq $oldsec) {
                   1321:                 $secchange = 1;
                   1322:                 my $uurl='/'.$cid;
                   1323:                 $uurl=~s/\_/\//g;
                   1324:                 if ($oldsec) {
                   1325:                     $uurl.='/'.$oldsec;
                   1326:                 }
                   1327:                 $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
                   1328:                 $result = $expire_role_result;
                   1329:             }
                   1330:         }
                   1331:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
                   1332:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
                   1333:             if ($modify_section_result =~ /^ok/) {
                   1334:                 if ($secchange == 1) {
                   1335:                     $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
                   1336:                 } elsif ($oldsec eq '-1') {
                   1337:                     $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
                   1338:                 } else {
                   1339:                     $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
                   1340:                 }
                   1341:             } else {
                   1342:                 $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
                   1343:             }
                   1344:             $result = $modify_section_result;
                   1345:         } elsif ($secchange == 1) {
                   1346:             $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
                   1347:         }
                   1348:     } else {
                   1349:         $$logmsg .= "Incomplete course id defined.  Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
                   1350:         $result = "Error: incomplete course id\n";
                   1351:     }
                   1352:     return $result;
                   1353: }
1.88      raeburn  1354: 
                   1355: sub build_roles {
1.89      raeburn  1356:     my ($sectionstr,$sections,$role) = @_;
1.88      raeburn  1357:     my $num_sections = 0;
                   1358:     if ($sectionstr=~ /,/) {
                   1359:         my @secnums = split/,/,$sectionstr;
1.89      raeburn  1360:         if ($role eq 'st') {
                   1361:             $secnums[0] =~ s/\W//g;
                   1362:             $$sections{$secnums[0]} = 1;
                   1363:             $num_sections = 1;
                   1364:         } else {
                   1365:             foreach my $sec (@secnums) {
                   1366:                 $sec =~ ~s/\W//g;
                   1367:                 unless ($sec eq "") {
                   1368:                     if (exists($$sections{$sec})) {
                   1369:                         $$sections{$sec} ++;
                   1370:                     } else {
                   1371:                         $$sections{$sec} = 1;
                   1372:                         $num_sections ++;
                   1373:                     }
1.88      raeburn  1374:                 }
                   1375:             }
                   1376:         }
                   1377:     } else {
                   1378:         $sectionstr=~s/\W//g;
                   1379:         unless ($sectionstr eq '') {
                   1380:             $$sections{$sectionstr} = 1;
                   1381:             $num_sections ++;
                   1382:         }
                   1383:     }
                   1384:                                                                                      
                   1385:     return $num_sections;
                   1386: }
                   1387: 
1.58      www      1388: # ========================================================== Custom Role Editor
                   1389: 
                   1390: sub custom_role_editor {
                   1391:     my $r=shift;
1.101     albertel 1392:     my $rolename=$env{'form.rolename'};
1.58      www      1393: 
1.59      www      1394:     if ($rolename eq 'make new role') {
1.101     albertel 1395: 	$rolename=$env{'form.newrolename'};
1.59      www      1396:     }
                   1397: 
1.63      www      1398:     $rolename=~s/[^A-Za-z0-9]//gs;
1.58      www      1399: 
                   1400:     unless ($rolename) {
                   1401: 	&print_username_entry_form($r);
                   1402:         return;
                   1403:     }
                   1404: 
                   1405:     $r->print(&Apache::loncommon::bodytag(
1.59      www      1406:                      'Create Users, Change User Privileges').'<h2>');
1.61      www      1407:     my $syspriv='';
                   1408:     my $dompriv='';
                   1409:     my $coursepriv='';
1.59      www      1410:     my ($rdummy,$roledef)=
                   1411: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60      www      1412: # ------------------------------------------------------- Does this role exist?
1.59      www      1413:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73      sakharuk 1414: 	$r->print(&mt('Existing Role').' "');
1.61      www      1415: # ------------------------------------------------- Get current role privileges
                   1416: 	($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59      www      1417:     } else {
1.73      sakharuk 1418: 	$r->print(&mt('New Role').' "');
1.59      www      1419: 	$roledef='';
                   1420:     }
                   1421:     $r->print($rolename.'"</h2>');
1.60      www      1422: # ------------------------------------------------------- What can be assigned?
                   1423:     my %full=();
                   1424:     my %courselevel=();
1.61      www      1425:     my %courselevelcurrent=();
1.60      www      1426:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
                   1427: 	my ($priv,$restrict)=split(/\&/,$_);
                   1428:         unless ($restrict) { $restrict='F'; }
                   1429:         $courselevel{$priv}=$restrict;
1.61      www      1430:         if ($coursepriv=~/\:$priv/) {
                   1431: 	    $courselevelcurrent{$priv}=1;
                   1432: 	}
1.60      www      1433: 	$full{$priv}=1;
                   1434:     }
                   1435:     my %domainlevel=();
1.61      www      1436:     my %domainlevelcurrent=();
1.60      www      1437:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
                   1438: 	my ($priv,$restrict)=split(/\&/,$_);
                   1439:         unless ($restrict) { $restrict='F'; }
                   1440:         $domainlevel{$priv}=$restrict;
1.61      www      1441:         if ($dompriv=~/\:$priv/) {
                   1442: 	    $domainlevelcurrent{$priv}=1;
                   1443: 	}
1.60      www      1444: 	$full{$priv}=1;
                   1445:     }
1.61      www      1446:     my %systemlevel=();
                   1447:     my %systemlevelcurrent=();
                   1448:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
                   1449: 	my ($priv,$restrict)=split(/\&/,$_);
                   1450:         unless ($restrict) { $restrict='F'; }
                   1451:         $systemlevel{$priv}=$restrict;
                   1452:         if ($syspriv=~/\:$priv/) {
                   1453: 	    $systemlevelcurrent{$priv}=1;
                   1454: 	}
                   1455: 	$full{$priv}=1;
                   1456:     }
1.73      sakharuk 1457:     my %lt=&Apache::lonlocal::texthash(
                   1458: 		    'prv'  => "Privilege",
                   1459: 		    'crl'  => "Course Level",
                   1460:                     'dml'  => "Domain Level",
                   1461:                     'ssl'  => "System Level"
                   1462: 				       );
1.61      www      1463:     $r->print(<<ENDCCF);
                   1464: <form method="post">
                   1465: <input type="hidden" name="phase" value="set_custom_roles" />
                   1466: <input type="hidden" name="rolename" value="$rolename" />
                   1467: <table border="2">
1.73      sakharuk 1468: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
                   1469: <th>$lt{'ssl'}</th></tr>
1.61      www      1470: ENDCCF
1.60      www      1471:     foreach (sort keys %full) {
                   1472: 	$r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1.61      www      1473:     ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
                   1474:     ($courselevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
                   1475:     '</td><td>'.
                   1476:     ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
                   1477:     ($domainlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
                   1478:     '</td><td>'.
                   1479:     ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
                   1480:     ($systemlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
                   1481:     '</td></tr>');
1.60      www      1482:     }
1.61      www      1483:     $r->print(
1.73      sakharuk 1484:    '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
1.61      www      1485: }
                   1486: 
                   1487: # ---------------------------------------------------------- Call to definerole
                   1488: sub set_custom_role {
                   1489:     my $r=shift;
                   1490: 
1.101     albertel 1491:     my $rolename=$env{'form.rolename'};
1.61      www      1492: 
1.63      www      1493:     $rolename=~s/[^A-Za-z0-9]//gs;
1.61      www      1494: 
                   1495:     unless ($rolename) {
                   1496: 	&print_username_entry_form($r);
                   1497:         return;
                   1498:     }
                   1499: 
                   1500:     $r->print(&Apache::loncommon::bodytag(
                   1501:                      'Create Users, Change User Privileges').'<h2>');
                   1502:     my ($rdummy,$roledef)=
                   1503: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
                   1504: # ------------------------------------------------------- Does this role exist?
                   1505:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73      sakharuk 1506: 	$r->print(&mt('Existing Role').' "');
1.61      www      1507:     } else {
1.73      sakharuk 1508: 	$r->print(&mt('New Role').' "');
1.61      www      1509: 	$roledef='';
                   1510:     }
                   1511:     $r->print($rolename.'"</h2>');
                   1512: # ------------------------------------------------------- What can be assigned?
                   1513:     my $sysrole='';
                   1514:     my $domrole='';
                   1515:     my $courole='';
                   1516: 
                   1517:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
                   1518: 	my ($priv,$restrict)=split(/\&/,$_);
                   1519:         unless ($restrict) { $restrict=''; }
1.101     albertel 1520:         if ($env{'form.'.$priv.':c'}) {
1.61      www      1521: 	    $courole.=':'.$_;
                   1522: 	}
                   1523:     }
                   1524: 
                   1525:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
                   1526: 	my ($priv,$restrict)=split(/\&/,$_);
                   1527:         unless ($restrict) { $restrict=''; }
1.101     albertel 1528:         if ($env{'form.'.$priv.':d'}) {
1.61      www      1529: 	    $domrole.=':'.$_;
                   1530: 	}
                   1531:     }
                   1532: 
                   1533:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
                   1534: 	my ($priv,$restrict)=split(/\&/,$_);
                   1535:         unless ($restrict) { $restrict=''; }
1.101     albertel 1536:         if ($env{'form.'.$priv.':s'}) {
1.61      www      1537: 	    $sysrole.=':'.$_;
                   1538: 	}
                   1539:     }
1.63      www      1540:     $r->print('<br />Defining Role: '.
1.61      www      1541: 	   &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101     albertel 1542:     if ($env{'request.course.id'}) {
                   1543:         my $url='/'.$env{'request.course.id'};
1.63      www      1544:         $url=~s/\_/\//g;
1.73      sakharuk 1545: 	$r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101     albertel 1546: 	      &Apache::lonnet::assigncustomrole($env{'user.domain'},
                   1547: 						$env{'user.name'},
1.63      www      1548: 						$url,
1.101     albertel 1549: 						$env{'user.domain'},
                   1550: 						$env{'user.name'},
1.63      www      1551: 						$rolename));
                   1552:     }
1.109   ! albertel 1553:     $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p>');
1.61      www      1554:     $r->print('</body></html>');
1.58      www      1555: }
                   1556: 
1.2       www      1557: # ================================================================ Main Handler
                   1558: sub handler {
                   1559:     my $r = shift;
                   1560: 
                   1561:     if ($r->header_only) {
1.68      www      1562:        &Apache::loncommon::content_type($r,'text/html');
1.2       www      1563:        $r->send_http_header;
                   1564:        return OK;
                   1565:     }
                   1566: 
1.101     albertel 1567:     if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
                   1568:         (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) || 
                   1569:         (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) || 
                   1570:         (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1.104     albertel 1571: 	(&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1.101     albertel 1572:         (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1.68      www      1573:        &Apache::loncommon::content_type($r,'text/html');
1.2       www      1574:        $r->send_http_header;
1.101     albertel 1575:        unless ($env{'form.phase'}) {
1.42      matthew  1576: 	   &print_username_entry_form($r);
1.2       www      1577:        }
1.101     albertel 1578:        if ($env{'form.phase'} eq 'get_user_info') {
1.42      matthew  1579:            &print_user_modification_page($r);
1.101     albertel 1580:        } elsif ($env{'form.phase'} eq 'update_user_data') {
1.42      matthew  1581:            &update_user_data($r);
1.101     albertel 1582:        } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1.58      www      1583:            &custom_role_editor($r);
1.101     albertel 1584:        } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1.61      www      1585: 	   &set_custom_role($r);
1.2       www      1586:        }
1.1       www      1587:    } else {
1.101     albertel 1588:       $env{'user.error.msg'}=
1.9       albertel 1589:         "/adm/createuser:mau:0:0:Cannot modify user data";
1.1       www      1590:       return HTTP_NOT_ACCEPTABLE; 
                   1591:    }
                   1592:    return OK;
                   1593: } 
1.26      matthew  1594: 
1.27      matthew  1595: #-------------------------------------------------- functions for &phase_two
1.26      matthew  1596: sub course_level_table {
1.89      raeburn  1597:     my (%inccourses) = @_;
1.26      matthew  1598:     my $table = '';
1.62      www      1599: # Custom Roles?
                   1600: 
                   1601:     my %customroles=&my_custom_roles();
1.89      raeburn  1602:     my %lt=&Apache::lonlocal::texthash(
                   1603:             'exs'  => "Existing sections",
                   1604:             'new'  => "Define new section",
                   1605:             'ssd'  => "Set Start Date",
                   1606:             'sed'  => "Set End Date",
                   1607:             'crl'  => "Course Level",
                   1608:             'act'  => "Activate",
                   1609:             'rol'  => "Role",
                   1610:             'ext'  => "Extent",
                   1611:             'grs'  => "Group/Section",
                   1612:             'sta'  => "Start",
                   1613:             'end'  => "End"
                   1614:     );
1.62      www      1615: 
1.26      matthew  1616:     foreach (sort( keys(%inccourses))) {
                   1617: 	my $thiscourse=$_;
                   1618: 	my $protectedcourse=$_;
                   1619: 	$thiscourse=~s:_:/:g;
                   1620: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
                   1621: 	my $area=$coursedata{'description'};
1.72      sakharuk 1622: 	if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1.26      matthew  1623: 	my $bgcol=$thiscourse;
1.62      www      1624: 	$bgcol=~s/[^7-9a-e]//g;
                   1625: 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.89      raeburn  1626: 	my ($domain,$cnum)=split(/\//,$thiscourse);
                   1627:         my %sections_count = ();
1.92      raeburn  1628:         my $num_sections = 0;
1.101     albertel 1629:         if (defined($env{'request.course.id'})) {
                   1630:             if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.92      raeburn  1631:                 $num_sections = &Apache::loncommon::get_sections($domain,$cnum,\%sections_count);
                   1632:             }
                   1633:         }
1.26      matthew  1634: 	foreach  ('st','ta','ep','ad','in','cc') {
                   1635: 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
                   1636: 		my $plrole=&Apache::lonnet::plaintext($_);
                   1637: 		$table .= <<ENDEXTENT;
                   1638: <tr bgcolor="#$bgcol">
                   1639: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
                   1640: <td>$plrole</td>
1.82      albertel 1641: <td>$area<br />Domain: $domain</td>
1.26      matthew  1642: ENDEXTENT
                   1643: 	        if ($_ ne 'cc') {
1.89      raeburn  1644:                     if ($num_sections > 0) {
                   1645:                         my $currsec = &course_sections($num_sections,\%sections_count,$protectedcourse.'_'.$_);
                   1646:                         $table .= 
                   1647:                     '<td><table border="0" cellspacing="0" cellpadding="0">'.
                   1648:                      '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
                   1649:                         $currsec.'</td>'.
                   1650:                      '<td>&nbsp;&nbsp;</td>'.
                   1651:                      '<td valign="top">&nbsp;'.$lt{'new'}.'<br />'.
                   1652:                      '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
                   1653:                      '<input type="hidden" '.
                   1654:                      'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
                   1655:                      '</tr></table></td>';
                   1656:                     } else {
                   1657:                         $table .= '<td><input type="text" size="10" '.
                   1658:                      'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
                   1659:                     }
1.26      matthew  1660:                 } else { 
1.89      raeburn  1661: 		    $table .= '<td>&nbsp</td>';
1.26      matthew  1662:                 }
                   1663: 		$table .= <<ENDTIMEENTRY;
                   1664: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
                   1665: <a href=
1.73      sakharuk 1666: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26      matthew  1667: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
                   1668: <a href=
1.73      sakharuk 1669: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26      matthew  1670: ENDTIMEENTRY
                   1671:                 $table.= "</tr>\n";
                   1672:             }
                   1673:         }
1.62      www      1674:         foreach (sort keys %customroles) {
1.65      www      1675: 	    if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
                   1676: 		my $plrole=$_;
1.101     albertel 1677:                 my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
                   1678: 		    '_'.$env{'user.name'}.'_'.$plrole;
1.89      raeburn  1679: 		$table .= <<END;
1.62      www      1680: <tr bgcolor="#$bgcol">
1.65      www      1681: <td><input type="checkbox" name="act_$customrole"></td>
1.62      www      1682: <td>$plrole</td>
                   1683: <td>$area</td>
1.89      raeburn  1684: END
                   1685:                 if ($num_sections > 0) {
                   1686:                     my $currsec = &course_sections($num_sections,\%sections_count,$customrole);
                   1687:                     $table.=
                   1688:                    '<td><table border="0" cellspacing="0" cellpadding="0">'.
                   1689:                    '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
                   1690:                      $currsec.'</td>'.
                   1691:                    '<td>&nbsp;&nbsp;</td>'.
                   1692:                    '<td valign="top">&nbsp;'.$lt{'new'}.'<br />'.
                   1693:                    '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
                   1694:                    '<input type="hidden" '.
                   1695:                    'name="sec_'.$customrole.'"></td>'.
                   1696:                    '</tr></table></td>';
                   1697:                 } else {
                   1698:                     $table .= '<td><input type="text" size="10" '.
                   1699:                      'name="sec_'.$customrole.'"></td>';
                   1700:                 }
                   1701:                 $table .= <<ENDENTRY;
1.65      www      1702: <td><input type=hidden name="start_$customrole" value=''>
1.62      www      1703: <a href=
1.73      sakharuk 1704: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65      www      1705: <td><input type=hidden name="end_$customrole" value=''>
1.62      www      1706: <a href=
1.73      sakharuk 1707: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
1.62      www      1708: ENDENTRY
1.65      www      1709:            }
1.62      www      1710: 	}
1.26      matthew  1711:     }
                   1712:     return '' if ($table eq ''); # return nothing if there is nothing 
                   1713:                                  # in the table
                   1714:     my $result = <<ENDTABLE;
1.73      sakharuk 1715: <h4>$lt{'crl'}</h4>
                   1716: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
                   1717: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26      matthew  1718: $table
                   1719: </table>
                   1720: ENDTABLE
                   1721:     return $result;
                   1722: }
1.88      raeburn  1723: 
1.89      raeburn  1724: sub course_sections {
                   1725:     my ($num_sections,$sections_count,$role) = @_;
                   1726:     my $output = '';
                   1727:     my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.92      raeburn  1728:     if ($num_sections == 1) {
                   1729:         $output = '<select name="currsec_'.$role.'" >'."\n".
                   1730:                   '  <option value="">Select</option>'."\n".
1.93      raeburn  1731:                   '  <option value="">No section</option>'."\n".
1.92      raeburn  1732:                   '  <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
                   1733:     } else {
                   1734:         $output = '<select name="currsec_'.$role.'" ';
                   1735:         my $multiple = 4;
                   1736:         if ($num_sections <4) { $multiple = $num_sections; }
1.95      albertel 1737:         $output .= '"multiple" size="'.$multiple.'">'."\n";
1.92      raeburn  1738:         foreach (@sections) {
                   1739:             $output .= '<option value="'.$_.'">'.$_."</option>\n";
                   1740:         }
1.89      raeburn  1741:     }
                   1742:     $output .= '</select>'; 
                   1743:     return $output;
                   1744: }
                   1745: 
1.88      raeburn  1746: sub course_level_dc {
                   1747:     my ($dcdom) = @_;
                   1748:     my %customroles=&my_custom_roles();
                   1749:     my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
                   1750:                       '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
                   1751:                       '<input type="hidden" name="dccourse" value="" />';
                   1752:     my $courseform='<b>'.&Apache::loncommon::selectcourse_link
                   1753:                      ('cu','dccourse','dcdomain','coursedesc').'</b>';
                   1754:                                                                                       
                   1755:     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
                   1756:     my %lt=&Apache::lonlocal::texthash(
                   1757:                     'crl'  => "Course Level",
                   1758:                     'crt'  => "Course Title",
                   1759:                     'rol'  => "Role",
                   1760:                     'grs'  => "Group/Section",
                   1761:                     'exs'  => "Existing sections",
                   1762:                     'new'  => "Define new section", 
                   1763:                     'sta'  => "Start",
                   1764:                     'end'  => "End",
                   1765:                     'ssd'  => "Set Start Date",
                   1766:                     'sed'  => "Set End Date"
                   1767:                   );
                   1768:     my $header = '<h4>'.$lt{'crl'}.'</h4>'.
                   1769:                  '<table border="2"><tr><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th></tr>';
1.89      raeburn  1770:     my $otheritems = '<tr><td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'".'cu'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."',''".')" /></td>'.
1.88      raeburn  1771:                      '<td><select name="role">'."\n";
                   1772:     foreach  ('st','ta','ep','ad','in','cc') {
                   1773:         my $plrole=&Apache::lonnet::plaintext($_);
                   1774:         $otheritems .= '  <option value="'.$_.'">'.$plrole;
                   1775:     }
                   1776:     if ( keys %customroles > 0) {
                   1777:         foreach (sort keys %customroles) {
1.101     albertel 1778:             my $custrole='cr_cr_'.$env{'user.domain'}.
                   1779:                     '_'.$env{'user.name'}.'_'.$_;
1.88      raeburn  1780:             $otheritems .= '  <option value="'.$custrole.'">'.$_;
                   1781:         }
                   1782:     }
                   1783:     $otheritems .= '</select></td><td>'.
                   1784:                      '<table border="0" cellspacing="0" cellpadding="0">'.
                   1785:                      '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
                   1786:                      ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
                   1787:                      '<td>&nbsp;&nbsp;</td>'.
                   1788:                      '<td valign="top">&nbsp;<b>'.$lt{'new'}.'</b><br />'.
                   1789:                      '<input type="text" name="newsec" value="" /></td>'.
                   1790:                      '</tr></table></td>';
                   1791:     $otheritems .= <<ENDTIMEENTRY;
                   1792: <td><input type=hidden name="start" value=''>
                   1793: <a href=
                   1794: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
                   1795: <td><input type=hidden name="end" value=''>
                   1796: <a href=
                   1797: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
                   1798: ENDTIMEENTRY
                   1799:     $otheritems .= "</tr></table>\n";
                   1800:     return $cb_jscript.$header.$hiddenitems.$otheritems;
                   1801: }
                   1802: 
1.27      matthew  1803: #---------------------------------------------- end functions for &phase_two
1.29      matthew  1804: 
                   1805: #--------------------------------- functions for &phase_two and &phase_three
                   1806: 
                   1807: #--------------------------end of functions for &phase_two and &phase_three
1.1       www      1808: 
                   1809: 1;
                   1810: __END__
1.2       www      1811: 
                   1812: 

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