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

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

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