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

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

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