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

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

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