File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.88: download - view: text, annotated - select for diffs
Tue Nov 23 18:03:04 2004 UTC (19 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
DC can now add user roles to courses without needing an role in the target course.  Choice of sections can be made from existing sections, or new sections can be added.  Still need to add contextual help, and javascript to alert/prohibit > 1 section for a student role.

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

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