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

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

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