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

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

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