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

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

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