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

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

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