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

1.20      harris41    1: # The LearningOnline Network with CAPA
1.1       www         2: # Create a user
                      3: #
1.215   ! raeburn     4: # $Id: loncreateuser.pm,v 1.214 2007/12/21 14:05:40 raeburn Exp $
1.22      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.20      harris41   28: ###
                     29: 
1.1       www        30: package Apache::loncreateuser;
1.66      bowersj2   31: 
                     32: =pod
                     33: 
                     34: =head1 NAME
                     35: 
                     36: Apache::loncreateuser - handler to create users and custom roles
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Apache::loncreateuser provides an Apache handler for creating users,
                     41:     editing their login parameters, roles, and removing roles, and
                     42:     also creating and assigning custom roles.
                     43: 
                     44: =head1 OVERVIEW
                     45: 
                     46: =head2 Custom Roles
                     47: 
                     48: In LON-CAPA, roles are actually collections of privileges. "Teaching
                     49: Assistant", "Course Coordinator", and other such roles are really just
                     50: collection of privileges that are useful in many circumstances.
                     51: 
                     52: Creating custom roles can be done by the Domain Coordinator through
                     53: the Create User functionality. That screen will show all privileges
                     54: that can be assigned to users. For a complete list of privileges,
                     55: please see C</home/httpd/lonTabs/rolesplain.tab>.
                     56: 
                     57: Custom role definitions are stored in the C<roles.db> file of the role
                     58: author.
                     59: 
                     60: =cut
1.1       www        61: 
                     62: use strict;
                     63: use Apache::Constants qw(:common :http);
                     64: use Apache::lonnet;
1.54      bowersj2   65: use Apache::loncommon;
1.68      www        66: use Apache::lonlocal;
1.117     raeburn    67: use Apache::longroup;
1.190     raeburn    68: use Apache::lonuserutils;
1.139     albertel   69: use LONCAPA qw(:DEFAULT :match);
1.1       www        70: 
1.20      harris41   71: my $loginscript; # piece of javascript used in two separate instances
                     72: my $authformnop;
                     73: my $authformkrb;
                     74: my $authformint;
                     75: my $authformfsys;
                     76: my $authformloc;
                     77: 
1.94      matthew    78: sub initialize_authen_forms {
1.205     raeburn    79:     my ($dom,$curr_authtype,$mode) = @_; 
1.94      matthew    80:     my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
                     81:     $krbdefdom= uc($krbdefdom);
1.31      matthew    82:     my %param = ( formname => 'document.cu',
1.187     raeburn    83:                   kerb_def_dom => $krbdefdom,
                     84:                   domain => $dom,
                     85:                 );
1.188     raeburn    86:     my %abv_auth = &auth_abbrev();
1.187     raeburn    87:     if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):$/) {
1.188     raeburn    88:         my $long_auth = $1;
                     89:         my %abv_auth = &auth_abbrev();
                     90:         $param{'curr_authtype'} = $abv_auth{$long_auth};
                     91:         if ($long_auth =~ /^krb(4|5)$/) {
                     92:             $param{'curr_kerb_ver'} = $1;
                     93:         }
1.205     raeburn    94:         if ($mode eq 'modifyuser') {
                     95:             $param{'mode'} = $mode;
                     96:         }
1.187     raeburn    97:     }
1.48      albertel   98: # no longer static due to configurable kerberos defaults
                     99: #    $loginscript  = &Apache::loncommon::authform_header(%param);
1.31      matthew   100:     $authformnop  = &Apache::loncommon::authform_nochange(%param);
1.48      albertel  101: # no longer static due to configurable kerberos defaults
                    102: #    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
1.31      matthew   103:     $authformint  = &Apache::loncommon::authform_internal(%param);
                    104:     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
                    105:     $authformloc  = &Apache::loncommon::authform_local(%param);
1.20      harris41  106: }
                    107: 
1.188     raeburn   108: sub auth_abbrev {
                    109:     my %abv_auth = (
                    110:                      krb4     => 'krb',
                    111:                      internal => 'int',
                    112:                      localuth => 'loc',
                    113:                      unix     => 'fsys',
                    114:                    );
                    115:     return %abv_auth;
                    116: }
1.43      www       117: 
1.134     raeburn   118: # ====================================================
                    119: 
                    120: sub portfolio_quota {
                    121:     my ($ccuname,$ccdomain) = @_;
                    122:     my %lt = &Apache::lonlocal::texthash(
                    123:                    'disk' => "Disk space allocated to user's portfolio files",
1.149     raeburn   124:                    'cuqu' => "Current quota",
                    125:                    'cust' => "Custom quota",
                    126:                    'defa' => "Default",
                    127:                    'chqu' => "Change quota",
1.134     raeburn   128:     );
1.149     raeburn   129:     my ($currquota,$quotatype,$inststatus,$defquota) = 
                    130:         &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
                    131:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
                    132:     my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
                    133:     if ($inststatus ne '') {
                    134:         if ($usertypes->{$inststatus} ne '') {
                    135:             $longinsttype = $usertypes->{$inststatus};
                    136:         }
                    137:     }
                    138:     $custom_on = ' ';
                    139:     $custom_off = ' checked="checked" ';
                    140:     my $quota_javascript = <<"END_SCRIPT";
                    141: <script type="text/javascript">
                    142: function quota_changes(caller) {
                    143:     if (caller == "custom") {
                    144:         if (document.cu.customquota[0].checked) {
                    145:             document.cu.portfolioquota.value = "";
                    146:         }
                    147:     }
                    148:     if (caller == "quota") {
                    149:         document.cu.customquota[1].checked = true;
                    150:     }
                    151: }
                    152: </script>
                    153: END_SCRIPT
                    154:     if ($quotatype eq 'custom') {
                    155:         $custom_on = $custom_off;
                    156:         $custom_off = ' ';
                    157:         $showquota = $currquota;
                    158:         if ($longinsttype eq '') {
                    159:             $defaultinfo = &mt('For this user, the default quota would be [_1]
                    160:                             Mb.',$defquota);
                    161:         } else {
                    162:             $defaultinfo = &mt("For this user, the default quota would be [_1] 
                    163:                             Mb, as determined by the user's institutional
                    164:                            affiliation ([_2]).",$defquota,$longinsttype);
                    165:         }
                    166:     } else {
                    167:         if ($longinsttype eq '') {
                    168:             $defaultinfo = &mt('For this user, the default quota is [_1]
                    169:                             Mb.',$defquota);
                    170:         } else {
                    171:             $defaultinfo = &mt("For this user, the default quota of [_1]
                    172:                             Mb, is determined by the user's institutional
                    173:                             affiliation ([_2]).",$defquota,$longinsttype);
                    174:         }
                    175:     }
                    176:     my $output = $quota_javascript.
                    177:                  '<h3>'.$lt{'disk'}.'</h3>'.
1.188     raeburn   178:                  &Apache::loncommon::start_data_table().
                    179:                  &Apache::loncommon::start_data_table_row().
                    180:                  '<td>'.$lt{'cuqu'}.': '.$currquota.'&nbsp;Mb.&nbsp;&nbsp;'.
                    181:                  $defaultinfo.'</td>'.
                    182:                  &Apache::loncommon::end_data_table_row().
                    183:                  &Apache::loncommon::start_data_table_row().
                    184:                  '<td><span class="LC_nobreak">'.$lt{'chqu'}.
1.149     raeburn   185:                  ': <label>'.
                    186:                  '<input type="radio" name="customquota" value="0" '.
                    187:                  $custom_off.' onchange="javascript:quota_changes('."'custom'".')"
                    188:                   />'.$lt{'defa'}.'&nbsp;('.$defquota.' Mb).</label>&nbsp;'.
                    189:                  '&nbsp;<label><input type="radio" name="customquota" value="1" '. 
                    190:                  $custom_on.'  onchange="javascript:quota_changes('."'custom'".')" />'.
                    191:                  $lt{'cust'}.':</label>&nbsp;'.
1.134     raeburn   192:                  '<input type="text" name="portfolioquota" size ="5" value="'.
1.149     raeburn   193:                  $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
1.188     raeburn   194:                  '/>&nbsp;Mb</span></td>'.
                    195:                  &Apache::loncommon::end_data_table_row().
                    196:                  &Apache::loncommon::end_data_table();
1.134     raeburn   197:     return $output;
                    198: }
                    199: 
1.2       www       200: # =================================================================== Phase one
1.1       www       201: 
1.42      matthew   202: sub print_username_entry_form {
1.207     raeburn   203:     my ($r,$context,$response,$srch,$forcenewuser) = @_;
1.101     albertel  204:     my $defdom=$env{'request.role.domain'};
1.160     raeburn   205:     my $formtoset = 'crtuser';
                    206:     if (exists($env{'form.startrolename'})) {
                    207:         $formtoset = 'docustom';
                    208:         $env{'form.rolename'} = $env{'form.startrolename'};
1.207     raeburn   209:     } elsif ($env{'form.origform'} eq 'crtusername') {
                    210:         $formtoset =  $env{'form.origform'};
1.160     raeburn   211:     }
                    212: 
                    213:     my ($jsback,$elements) = &crumb_utilities();
                    214: 
                    215:     my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165     albertel  216:         '<script type="text/javascript">'."\n".
1.160     raeburn   217:         &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
1.162     raeburn   218:         '</script>'."\n";
1.160     raeburn   219: 
                    220:     my %loaditems = (
                    221:                 'onload' => "javascript:setFormElements(document.$formtoset)",
                    222:                     );
1.110     albertel  223:     my $start_page =
1.190     raeburn   224: 	&Apache::loncommon::start_page('User Management',
1.160     raeburn   225: 				       $jscript,{'add_entries' => \%loaditems,});
1.214     raeburn   226:     if ($env{'form.action'} eq 'custom') {
                    227:         &Apache::lonhtmlcommon::add_breadcrumb
                    228:           ({href=>"javascript:backPage(document.crtuser)",
                    229:             text=>"Pick custom role",});
                    230:     } else {
1.190     raeburn   231:         &Apache::lonhtmlcommon::add_breadcrumb
                    232:           ({href=>"javascript:backPage(document.crtuser)",
                    233:             text=>"Single user search",
                    234:             faq=>282,bug=>'Instructor Interface',});
                    235:     }
1.160     raeburn   236:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
1.190     raeburn   237:     my %existingroles=&Apache::lonuserutils::my_custom_roles();
1.59      www       238:     my $choice=&Apache::loncommon::select_form('make new role','rolename',
                    239: 		('make new role' => 'Generate new role ...',%existingroles));
1.71      sakharuk  240:     my %lt=&Apache::lonlocal::texthash(
1.160     raeburn   241:                     'srch' => "User Search",
                    242:                      or    => "or",
1.71      sakharuk  243: 		    'usr'  => "Username",
                    244:                     'dom'  => "Domain",
                    245:                     'ecrp' => "Edit Custom Role Privileges",
1.72      sakharuk  246:                     'nr'   => "Name of Role",
1.160     raeburn   247:                     'cre'  => "Custom Role Editor",
1.214     raeburn   248:                     'mod'  => "to modify user information or add/modify roles",
                    249:                     'enrl' => "to enroll one student",
1.71      sakharuk  250: 				       );
1.122     albertel  251:     my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
1.76      www       252:     my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
1.213     raeburn   253:     my $helpsist=&Apache::loncommon::help_open_topic('Course_Add_Student');
1.76      www       254:     my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
1.160     raeburn   255:     my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
                    256:     if ($sellink) {
                    257:         $sellink = "$lt{'or'} ".$sellink;
                    258:     } 
1.190     raeburn   259:     $r->print($start_page."\n".$crumbs);
1.214     raeburn   260:     if ($env{'form.action'} eq 'custom') {
1.190     raeburn   261:         if (&Apache::lonnet::allowed('mcr','/')) {
                    262:             $r->print(<<ENDCUSTOM);
1.58      www       263: <form action="/adm/createuser" method="post" name="docustom">
1.190     raeburn   264: <input type="hidden" name="action" value="$env{'form.action'}" />
1.157     albertel  265: <input type="hidden" name="phase" value="selected_custom_edit" />
1.190     raeburn   266: <h3>$lt{'ecrp'}$helpecpr</h3>
1.72      sakharuk  267: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71      sakharuk  268: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107     www       269: </form>
1.106     www       270: ENDCUSTOM
1.190     raeburn   271:         }
1.213     raeburn   272:     } else {
                    273:         my $actiontext = $lt{'mod'}.$helpsiur;
                    274:         if ($env{'form.action'} eq 'singlestudent') {
                    275:             $actiontext = $lt{'enrl'}.$helpsist;
                    276:         }
                    277:         $r->print("
                    278: <h3>$lt{'srch'} $sellink $actiontext</h3>");
                    279:         if ($env{'form.origform'} ne 'crtusername') {
                    280:             $r->print("\n".$response);
                    281:         }
                    282:         $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
1.107     www       283:     }
1.110     albertel  284:     $r->print(&Apache::loncommon::end_page());
                    285: }
                    286: 
1.160     raeburn   287: sub entry_form {
1.214     raeburn   288:     my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
1.207     raeburn   289:     my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.214     raeburn   290:     my $usertype;
                    291:     if (ref($srch) eq 'HASH') {
                    292:         if (($srch->{'srchin'} eq 'dom') &&
                    293:             ($srch->{'srchby'} eq 'uname') &&
                    294:             ($srch->{'srchtype'} eq 'exact') &&
                    295:             ($srch->{'srchdomain'} ne '') &&
                    296:             ($srch->{'srchterm'} ne '')) {
                    297:             my ($rules,$ruleorder) =
                    298:                 &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
                    299:             $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
                    300:         }
1.207     raeburn   301:     }
1.214     raeburn   302:     my $cancreate =
                    303:         &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160     raeburn   304:     my $userpicker = 
1.179     raeburn   305:        &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214     raeburn   306:                                        'document.crtuser',$cancreate,$usertype);
1.160     raeburn   307:     my $srchbutton = &mt('Search');
1.207     raeburn   308:     my $output = <<"ENDBLOCK";
1.160     raeburn   309: <form action="/adm/createuser" method="post" name="crtuser">
1.190     raeburn   310: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160     raeburn   311: <input type="hidden" name="phase" value="get_user_info" />
                    312: $userpicker
1.179     raeburn   313: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160     raeburn   314: </form>
1.207     raeburn   315: ENDBLOCK
1.211     raeburn   316:     if ($cancreate && $env{'form.phase'} eq '') {
1.207     raeburn   317:         my $defdom=$env{'request.role.domain'};
                    318:         my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
                    319:         my $helpcrt=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
                    320:         my %lt=&Apache::lonlocal::texthash(
                    321:                   'crnu' => 'Create a new user',
                    322:                   'usr'  => 'Username',
                    323:                   'dom'  => 'in domain',
                    324:                   'cra'  => 'Create user',
                    325:         );
                    326:         $output .= <<"ENDDOCUMENT";
                    327: <form action="/adm/createuser" method="post" name="crtusername">
                    328: <input type="hidden" name="action" value="$env{'form.action'}" />
                    329: <input type="hidden" name="phase" value="createnewuser" />
                    330: <input type="hidden" name="srchtype" value="exact" />
                    331: <input type="hidden" name="srchby" value="username" />
                    332: <input type="hidden" name="srchin" value="dom" />
                    333: <input type="hidden" name="forcenewuser" value="1" />
                    334: <input type="hidden" name="origform" value="crtusername" />
                    335: <h3>$lt{crnu}$helpcrt</h3>
1.214     raeburn   336: $responsemsg
1.207     raeburn   337: <table>
                    338:  <tr>
                    339:   <td>$lt{'usr'}:</td>
                    340:   <td><input type="text" size="15" name="srchterm" /></td>
                    341:   <td>&nbsp;$lt{'dom'}:</td><td>$domform</td>
                    342:   <td>&nbsp;<input name="userrole" type="submit" value="$lt{'cra'}" /></td>
                    343:  </tr>
                    344: </table>
                    345: </form>
1.160     raeburn   346: ENDDOCUMENT
1.207     raeburn   347:     }
1.160     raeburn   348:     return $output;
                    349: }
1.110     albertel  350: 
                    351: sub user_modification_js {
1.113     raeburn   352:     my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
                    353:     
1.110     albertel  354:     return <<END;
                    355: <script type="text/javascript" language="Javascript">
                    356: 
                    357:     function pclose() {
                    358:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    359:                  "height=350,width=350,scrollbars=no,menubar=no");
                    360:         parmwin.close();
                    361:     }
                    362: 
                    363:     $pjump_def
                    364:     $dc_setcourse_code
                    365: 
                    366:     function dateset() {
                    367:         eval("document.cu."+document.cu.pres_marker.value+
                    368:             ".value=document.cu.pres_value.value");
                    369:         pclose();
                    370:     }
                    371: 
1.113     raeburn   372:     $nondc_setsection_code
                    373: 
1.110     albertel  374: </script>
                    375: END
1.2       www       376: }
                    377: 
                    378: # =================================================================== Phase two
1.160     raeburn   379: sub print_user_selection_page {
1.207     raeburn   380:     my ($r,$response,$srch,$srch_results,$operation,$srcharray,$context) = @_;
1.160     raeburn   381:     my @fields = ('username','domain','lastname','firstname','permanentemail');
                    382:     my $sortby = $env{'form.sortby'};
                    383: 
                    384:     if (!grep(/^\Q$sortby\E$/,@fields)) {
                    385:         $sortby = 'lastname';
                    386:     }
                    387: 
                    388:     my ($jsback,$elements) = &crumb_utilities();
                    389: 
                    390:     my $jscript = (<<ENDSCRIPT);
                    391: <script type="text/javascript">
                    392: function pickuser(uname,udom) {
                    393:     document.usersrchform.seluname.value=uname;
                    394:     document.usersrchform.seludom.value=udom;
                    395:     document.usersrchform.phase.value="userpicked";
                    396:     document.usersrchform.submit();
                    397: }
                    398: 
                    399: $jsback
                    400: </script>
                    401: ENDSCRIPT
                    402: 
                    403:     my %lt=&Apache::lonlocal::texthash(
1.179     raeburn   404:                                        'usrch'          => "User Search to add/modify roles",
                    405:                                        'stusrch'        => "User Search to enroll student",
                    406:                                        'usel'           => "Select a user to add/modify roles",
                    407:                                        'stusel'         => "Select a user to enroll as a student", 
1.160     raeburn   408:                                        'username'       => "username",
                    409:                                        'domain'         => "domain",
                    410:                                        'lastname'       => "last name",
                    411:                                        'firstname'      => "first name",
                    412:                                        'permanentemail' => "permanent e-mail",
                    413:                                       );
1.214     raeburn   414:     $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.190     raeburn   415:     if ($operation eq 'createuser') {
1.179     raeburn   416:         &Apache::lonhtmlcommon::add_breadcrumb
                    417:             ({href=>"javascript:backPage(document.usersrchform,'','')",
1.190     raeburn   418:               text=>"Create/modify user",
1.179     raeburn   419:               faq=>282,bug=>'Instructor Interface',},
                    420:              {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
                    421:               text=>"Select User",
                    422:               faq=>282,bug=>'Instructor Interface',});
                    423:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
                    424:         $r->print("<b>$lt{'usrch'}</b><br />");
1.207     raeburn   425:         $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179     raeburn   426:         $r->print('<h3>'.$lt{'usel'}.'</h3>');
1.214     raeburn   427:     } elsif ($operation eq 'enrollstudent') {
                    428:         &Apache::lonhtmlcommon::add_breadcrumb
                    429:             ({href=>"javascript:backPage(document.usersrchform,'','')",
                    430:               text=>"Create/modify student",
                    431:               faq=>282,bug=>'Instructor Interface',},
                    432:              {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
                    433:               text=>"Select Student",
                    434:               faq=>282,bug=>'Instructor Interface',});
                    435:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.179     raeburn   436:         $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
1.214     raeburn   437:         $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179     raeburn   438:         $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
                    439:     }
1.160     raeburn   440:     $r->print('<form name="usersrchform" method="post">'.
                    441:               &Apache::loncommon::start_data_table()."\n".
                    442:               &Apache::loncommon::start_data_table_header_row()."\n".
                    443:               ' <th> </th>'."\n");
                    444:     foreach my $field (@fields) {
                    445:         $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
                    446:                   "'".$field."'".';document.usersrchform.submit();">'.
                    447:                   $lt{$field}.'</a></th>'."\n");
                    448:     }
                    449:     $r->print(&Apache::loncommon::end_data_table_header_row());
                    450: 
                    451:     my @sorted_users = sort {
1.167     albertel  452:         lc($srch_results->{$a}->{$sortby})   cmp lc($srch_results->{$b}->{$sortby})
1.160     raeburn   453:             ||
1.167     albertel  454:         lc($srch_results->{$a}->{lastname})  cmp lc($srch_results->{$b}->{lastname})
1.160     raeburn   455:             ||
                    456:         lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167     albertel  457: 	    ||
                    458: 	lc($a) cmp lc($b)
1.160     raeburn   459:         } (keys(%$srch_results));
                    460: 
                    461:     foreach my $user (@sorted_users) {
                    462:         my ($uname,$udom) = split(/:/,$user);
                    463:         $r->print(&Apache::loncommon::start_data_table_row().
                    464:                   '<td><input type="button" name="seluser" value="'.&mt('Select').'" onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".')" /></td>'.
                    465:                   '<td><tt>'.$uname.'</tt></td>'.
                    466:                   '<td><tt>'.$udom.'</tt></td>');
                    467:         foreach my $field ('lastname','firstname','permanentemail') {
                    468:             $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
                    469:         }
                    470:         $r->print(&Apache::loncommon::end_data_table_row());
                    471:     }
                    472:     $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179     raeburn   473:     if (ref($srcharray) eq 'ARRAY') {
                    474:         foreach my $item (@{$srcharray}) {
                    475:             $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
                    476:         }
                    477:     }
1.160     raeburn   478:     $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
                    479:               ' <input type="hidden" name="seluname" value="" />'."\n".
                    480:               ' <input type="hidden" name="seludom" value="" />'."\n".
1.179     raeburn   481:               ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190     raeburn   482:               ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214     raeburn   483:               ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
                    484:     $r->print($response.'</form>'.&Apache::loncommon::end_page());
1.160     raeburn   485: }
                    486: 
                    487: sub print_user_query_page {
1.179     raeburn   488:     my ($r,$caller) = @_;
1.160     raeburn   489: # FIXME - this is for a network-wide name search (similar to catalog search)
                    490: # To use frames with similar behavior to catalog/portfolio search.
                    491: # To be implemented. 
                    492:     return;
                    493: }
                    494: 
1.42      matthew   495: sub print_user_modification_page {
1.215   ! raeburn   496:     my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_;
1.185     raeburn   497:     if (($ccuname eq '') || ($ccdomain eq '')) {
1.215   ! raeburn   498:         my $usermsg = &mt('No username and/or domain provided.');
        !           499:         $env{'form.phase'} = '';
1.207     raeburn   500: 	&print_username_entry_form($r,$context,$usermsg);
1.58      www       501:         return;
                    502:     }
1.213     raeburn   503:     my ($form,$formname);
                    504:     if ($env{'form.action'} eq 'singlestudent') {
                    505:         $form = 'document.enrollstudent';
                    506:         $formname = 'enrollstudent';
                    507:     } else {
                    508:         $form = 'document.cu';
                    509:         $formname = 'cu';
                    510:     }
1.188     raeburn   511:     my %abv_auth = &auth_abbrev();
1.193     raeburn   512:     my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
1.196     raeburn   513:         %alerts,%curr_rules,%got_rules);
1.185     raeburn   514:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
                    515:     if ($uhome eq 'no_host') {
1.215   ! raeburn   516:         my $usertype;
        !           517:         my ($rules,$ruleorder) =
        !           518:             &Apache::lonnet::inst_userrules($ccdomain,'username');
        !           519:             $usertype =
        !           520:                 &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
        !           521:         my $cancreate =
        !           522:             &Apache::lonuserutils::can_create_user($ccdomain,$context,
        !           523:                                                    $usertype);
        !           524:         if (!$cancreate) {
        !           525:             my $helplink = ' href="javascript:helpMenu('."'display'".')"';
        !           526:             my %usertypetext = (
        !           527:                 official   => 'institutional',
        !           528:                 unofficial => 'non-institutional',
        !           529:             );
        !           530:             my $response;
        !           531:             if ($env{'form.origform'} eq 'crtusername') {
        !           532:                 $response =  '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
        !           533:                             '</span><br />';
        !           534:             }
        !           535:             $response .= '<span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
        !           536:             $env{'form.phase'} = '';
        !           537:             &print_username_entry_form($r,$context,$response);
        !           538:             return;
        !           539:         }
1.188     raeburn   540:         $newuser = 1;
1.193     raeburn   541:         my $checkhash;
                    542:         my $checks = { 'username' => 1 };
1.196     raeburn   543:         $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193     raeburn   544:         &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196     raeburn   545:             \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
                    546:         if (ref($alerts{'username'}) eq 'HASH') {
                    547:             if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
                    548:                 my $domdesc =
1.193     raeburn   549:                     &Apache::lonnet::domain($ccdomain,'description');
1.196     raeburn   550:                 if ($alerts{'username'}{$ccdomain}{$ccuname}) {
                    551:                     my $userchkmsg;
                    552:                     if (ref($curr_rules{$ccdomain}) eq 'HASH') {  
                    553:                         $userchkmsg = 
                    554:                             &Apache::loncommon::instrule_disallow_msg('username',
1.193     raeburn   555:                                                                  $domdesc,1).
                    556:                         &Apache::loncommon::user_rule_formats($ccdomain,
                    557:                             $domdesc,$curr_rules{$ccdomain}{'username'},
                    558:                             'username');
1.196     raeburn   559:                     }
1.215   ! raeburn   560:                     $env{'form.phase'} = '';
1.207     raeburn   561:                     &print_username_entry_form($r,$context,$userchkmsg);
1.196     raeburn   562:                     return;
1.215   ! raeburn   563:                 }
1.193     raeburn   564:             }
1.185     raeburn   565:         }
1.187     raeburn   566:     } else {
1.188     raeburn   567:         $newuser = 0;
                    568:         my $currentauth = 
1.187     raeburn   569:             &Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.188     raeburn   570:         if ($currentauth =~ /^(krb4|krb5|unix|internal|localauth):/) {	
                    571:             $curr_authtype = $abv_auth{$1};
                    572:             if ($currentauth =~ /^krb(4|5)/) {
                    573:                 $curr_kerb_ver = $1;
                    574:             }
                    575:         }
1.185     raeburn   576:     }
1.160     raeburn   577:     if ($response) {
1.215   ! raeburn   578:         $response = '<br />'.$response;
1.160     raeburn   579:     }
1.101     albertel  580:     my $defdom=$env{'request.role.domain'};
1.48      albertel  581: 
                    582:     my ($krbdef,$krbdefdom) =
                    583:        &Apache::loncommon::get_kerberos_defaults($defdom);
                    584: 
1.31      matthew   585:     my %param = ( formname => 'document.cu',
1.48      albertel  586:                   kerb_def_dom => $krbdefdom,
1.187     raeburn   587:                   kerb_def_auth => $krbdef,
                    588:                   curr_authtype => $curr_authtype,
1.188     raeburn   589:                   curr_kerb_ver => $curr_kerb_ver,
1.187     raeburn   590:                   domain => $ccdomain,
1.160     raeburn   591:                 );
1.31      matthew   592:     $loginscript  = &Apache::loncommon::authform_header(%param);
1.48      albertel  593:     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
1.149     raeburn   594: 
1.52      matthew   595:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88      raeburn   596:     my $dc_setcourse_code = '';
1.119     raeburn   597:     my $nondc_setsection_code = '';                                        
1.112     albertel  598:     my %loaditem;
1.114     albertel  599: 
                    600:     my $groupslist;
1.117     raeburn   601:     my %curr_groups = &Apache::longroup::coursegroups();
1.114     albertel  602:     if (%curr_groups) {
1.113     raeburn   603:         $groupslist = join('","',sort(keys(%curr_groups)));
                    604:         $groupslist = '"'.$groupslist.'"';   
                    605:     }
1.114     albertel  606: 
1.139     albertel  607:     if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
1.88      raeburn   608:         my $dcdom = $1;
1.119     raeburn   609:         $loaditem{'onload'} = "document.cu.coursedesc.value='';";
                    610:         my @rolevals = ('st','ta','ep','in','cc');
                    611:         my (@crsroles,@grproles);
                    612:         for (my $i=0; $i<@rolevals; $i++) {
1.120     raeburn   613:             $crsroles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Course');
                    614:             $grproles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Group');
1.119     raeburn   615:         }
                    616:         my $rolevalslist = join('","',@rolevals);
                    617:         my $crsrolenameslist = join('","',@crsroles);
                    618:         my $grprolenameslist = join('","',@grproles);
                    619:         my $pickcrsfirst = '<--'.&mt('Pick course first');
                    620:         my $pickgrpfirst = '<--'.&mt('Pick group first'); 
1.88      raeburn   621:         $dc_setcourse_code = <<"ENDSCRIPT";
                    622:     function setCourse() {
                    623:         var course = document.cu.dccourse.value;
                    624:         if (course != "") {
                    625:             if (document.cu.dcdomain.value != document.cu.origdom.value) {
                    626:                 alert("You must select a course in the current domain");
                    627:                 return;
                    628:             } 
                    629:             var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
1.91      raeburn   630:             var section="";
1.88      raeburn   631:             var numsections = 0;
1.116     raeburn   632:             var newsecs = new Array();
1.89      raeburn   633:             for (var i=0; i<document.cu.currsec.length; i++) {
                    634:                 if (document.cu.currsec.options[i].selected == true ) {
                    635:                     if (document.cu.currsec.options[i].value != "" && document.cu.currsec.options[i].value != null) { 
                    636:                         if (numsections == 0) {
                    637:                             section = document.cu.currsec.options[i].value
                    638:                             numsections = 1;
                    639:                         }
                    640:                         else {
                    641:                             section = section + "," +  document.cu.currsec.options[i].value
                    642:                             numsections ++;
1.88      raeburn   643:                         }
                    644:                     }
                    645:                 }
1.89      raeburn   646:             }
                    647:             if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
                    648:                 if (numsections == 0) {
                    649:                     section = document.cu.newsec.value
                    650:                 }
                    651:                 else {
                    652:                     section = section + "," +  document.cu.newsec.value
1.88      raeburn   653:                 }
1.116     raeburn   654:                 newsecs = document.cu.newsec.value.split(/,/g);
                    655:                 numsections = numsections + newsecs.length;
1.89      raeburn   656:             }
                    657:             if ((userrole == 'st') && (numsections > 1)) {
                    658:                 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.")
                    659:                 return;
                    660:             }
1.116     raeburn   661:             for (var j=0; j<newsecs.length; j++) {
                    662:                 if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
                    663:                     alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
1.113     raeburn   664:                     return;
                    665:                 }
                    666:                 if (document.cu.groups.value != '') {
                    667:                     var groups = document.cu.groups.value.split(/,/g);
                    668:                     for (var k=0; k<groups.length; k++) {
1.116     raeburn   669:                         if (newsecs[j] == groups[k]) {
                    670:                             alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
1.113     raeburn   671:                             return; 
                    672:                         }
                    673:                     }
                    674:                 }
                    675:             }
1.89      raeburn   676:             if ((userrole == 'cc') && (numsections > 0)) {
                    677:                 alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
                    678:                 section = "";
1.88      raeburn   679:             }
1.131     raeburn   680:             var coursename = "_$dcdom"+"_"+course+"_"+userrole
1.88      raeburn   681:             var numcourse = getIndex(document.cu.dccourse);
                    682:             if (numcourse == "-1") {
                    683:                 alert("There was a problem with your course selection");
                    684:                 return
                    685:             }
1.131     raeburn   686:             else {
                    687:                 document.cu.elements[numcourse].name = "act"+coursename;
                    688:                 var numnewsec = getIndex(document.cu.newsec);
                    689:                 if (numnewsec != "-1") {
                    690:                     document.cu.elements[numnewsec].name = "sec"+coursename;
                    691:                     document.cu.elements[numnewsec].value = section;
                    692:                 }
                    693:                 var numstart = getIndex(document.cu.start);
                    694:                 if (numstart != "-1") {
                    695:                     document.cu.elements[numstart].name = "start"+coursename;
                    696:                 }
                    697:                 var numend = getIndex(document.cu.end);
                    698:                 if (numend != "-1") {
                    699:                     document.cu.elements[numend].name = "end"+coursename
                    700:                 }
1.88      raeburn   701:             }
                    702:         }
                    703:         document.cu.submit();
                    704:     }
                    705: 
                    706:     function getIndex(caller) {
                    707:         for (var i=0;i<document.cu.elements.length;i++) {
                    708:             if (document.cu.elements[i] == caller) {
                    709:                 return i;
                    710:             }
                    711:         }
                    712:         return -1;
                    713:     }
                    714: ENDSCRIPT
1.113     raeburn   715:     } else {
1.202     raeburn   716:         $nondc_setsection_code = 
1.198     raeburn   717:             &Apache::lonuserutils::setsections_javascript('cu',$groupslist);
1.88      raeburn   718:     }
1.113     raeburn   719:     my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
                    720:                                    $nondc_setsection_code,$groupslist);
1.160     raeburn   721: 
                    722:     my ($jsback,$elements) = &crumb_utilities();
1.188     raeburn   723:     my $javascript_validations;
                    724:     if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($uhome eq 'no_host')) {
                    725:         my ($krbdef,$krbdefdom) =
                    726:             &Apache::loncommon::get_kerberos_defaults($ccdomain);
                    727:         $javascript_validations = 
1.190     raeburn   728:             &Apache::lonuserutils::javascript_validations('auth',$krbdefdom,undef,
1.188     raeburn   729:                                                         undef,$ccdomain);
                    730:     }
1.160     raeburn   731:     $js .= "\n".
1.188     raeburn   732:        '<script type="text/javascript">'."\n".$jsback."\n".
                    733:        $javascript_validations.'</script>';
1.110     albertel  734:     my $start_page = 
1.190     raeburn   735: 	&Apache::loncommon::start_page('User Management',
1.112     albertel  736: 				       $js,{'add_entries' => \%loaditem,});
1.160     raeburn   737:     &Apache::lonhtmlcommon::add_breadcrumb
                    738:      ({href=>"javascript:backPage(document.cu)",
1.190     raeburn   739:        text=>"Create/modify user",
1.160     raeburn   740:        faq=>282,bug=>'Instructor Interface',});
                    741: 
                    742:     if ($env{'form.phase'} eq 'userpicked') {
                    743:         &Apache::lonhtmlcommon::add_breadcrumb
                    744:      ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
                    745:        text=>"Select a user",
                    746:        faq=>282,bug=>'Instructor Interface',});
                    747:     }
                    748:     &Apache::lonhtmlcommon::add_breadcrumb
                    749:       ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
                    750:         text=>"Set user role",
                    751:         faq=>282,bug=>'Instructor Interface',});
                    752:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
1.3       www       753: 
1.25      matthew   754:     my $forminfo =<<"ENDFORMINFO";
                    755: <form action="/adm/createuser" method="post" name="cu">
1.190     raeburn   756: <input type="hidden" name="phase" value="update_user_data" />
1.188     raeburn   757: <input type="hidden" name="ccuname" value="$ccuname" />
                    758: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157     albertel  759: <input type="hidden" name="pres_value"  value="" />
                    760: <input type="hidden" name="pres_type"   value="" />
                    761: <input type="hidden" name="pres_marker" value="" />
1.25      matthew   762: ENDFORMINFO
1.2       www       763:     my %inccourses;
1.135     raeburn   764:     foreach my $key (keys(%env)) {
1.139     albertel  765: 	if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1.2       www       766: 	    $inccourses{$1.'_'.$2}=1;
                    767:         }
1.24      matthew   768:     }
1.2       www       769:     if ($uhome eq 'no_host') {
1.134     raeburn   770:         my $portfolioform;
                    771:         if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
                    772:             # Current user has quota modification privileges
1.188     raeburn   773:             $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134     raeburn   774:         }
1.187     raeburn   775:         &initialize_authen_forms($ccdomain);
1.188     raeburn   776:         my %lt=&Apache::lonlocal::texthash(
                    777:                 'cnu'            => 'Create New User',
1.213     raeburn   778:                 'ast'            => 'as a student',
1.188     raeburn   779:                 'ind'            => 'in domain',
                    780:                 'lg'             => 'Login Data',
1.190     raeburn   781:                 'hs'             => "Home Server",
1.188     raeburn   782:         );
1.185     raeburn   783: 	$r->print(<<ENDTITLE);
1.110     albertel  784: $start_page
1.160     raeburn   785: $crumbs
                    786: $response
1.25      matthew   787: $forminfo
1.31      matthew   788: <script type="text/javascript" language="Javascript">
1.20      harris41  789: $loginscript
1.31      matthew   790: </script>
1.20      harris41  791: <input type='hidden' name='makeuser' value='1' />
1.193     raeburn   792: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain</h2>
1.185     raeburn   793: ENDTITLE
1.213     raeburn   794:         if ($env{'form.action'} eq 'singlestudent') {
                    795:             $r->print(' ('.$lt{'ast'}.')');
                    796:         }
                    797:         $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206     raeburn   798:         my $personal_table = 
1.210     raeburn   799:             &personal_data_display($ccuname,$ccdomain,$newuser,$context,
                    800:                                    $inst_results{$ccuname.':'.$ccdomain});
1.206     raeburn   801:         $r->print($personal_table);
1.187     raeburn   802:         my ($home_server_pick,$numlib) = 
                    803:             &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
                    804:                                                       'default','hide');
                    805:         if ($numlib > 1) {
                    806:             $r->print("
1.185     raeburn   807: <br />
1.187     raeburn   808: $lt{'hs'}: $home_server_pick
                    809: <br />");
                    810:         } else {
                    811:             $r->print($home_server_pick);
                    812:         }
1.188     raeburn   813:         $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
                    814:                   $lt{'lg'}.'</h3>');
1.185     raeburn   815:         my ($fixedauth,$varauth,$authmsg); 
1.193     raeburn   816:         if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
                    817:             my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
                    818:             my ($rules,$ruleorder) = 
                    819:                 &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185     raeburn   820:             if (ref($rules) eq 'HASH') {
1.193     raeburn   821:                 if (ref($rules->{$matchedrule}) eq 'HASH') {
                    822:                     my $authtype = $rules->{$matchedrule}{'authtype'};
1.185     raeburn   823:                     if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190     raeburn   824:                         $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185     raeburn   825:                     } else { 
1.193     raeburn   826:                         my $authparm = $rules->{$matchedrule}{'authparm'};
1.185     raeburn   827:                         if ($authtype =~ /^krb(4|5)$/) {
                    828:                             my $ver = $1;
                    829:                             if ($authparm ne '') {
                    830:                                 $fixedauth = <<"KERB"; 
                    831: <input type="hidden" name="login" value="krb" />
                    832: <input type="hidden" name="krbver" value="$ver" />
                    833: <input type="hidden" name="krbarg" value="$authparm" />
                    834: KERB
1.193     raeburn   835:                                 $authmsg = $rules->{$matchedrule}{'authmsg'};    
1.185     raeburn   836:                             }
                    837:                         } else {
                    838:                             $fixedauth = 
                    839: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193     raeburn   840:                             if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185     raeburn   841:                                 $fixedauth .=    
                    842: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
                    843:                             } else {
                    844:                                 $varauth =  
                    845: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
                    846:                             }
                    847:                         }
                    848:                     }
                    849:                 } else {
1.190     raeburn   850:                     $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185     raeburn   851:                 }
                    852:             }
                    853:             if ($authmsg) {
                    854:                 $r->print(<<ENDAUTH);
                    855: $fixedauth
                    856: $authmsg
                    857: $varauth
                    858: ENDAUTH
                    859:             }
                    860:         } else {
1.190     raeburn   861:             $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc)); 
1.187     raeburn   862:         }
1.215   ! raeburn   863:         $r->print($portfolioform);
        !           864:         if ($env{'form.action'} eq 'singlestudent') {
        !           865:             $r->print(&date_sections_select($context,$newuser,$formname,
        !           866:                                             $permission));
        !           867:         }
        !           868:         $r->print('</div><div class="LC_clear_float_footer"></div>');
1.213     raeburn   869:     } else { # user already exist-
1.79      albertel  870: 	my %lt=&Apache::lonlocal::texthash(
1.191     raeburn   871:                     'cup'  => "Modify existing user: ",
1.213     raeburn   872:                     'ens'  => "Enroll one student: ",
1.72      sakharuk  873:                     'id'   => "in domain",
                    874: 				       );
1.26      matthew   875: 	$r->print(<<ENDCHANGEUSER);
1.110     albertel  876: $start_page
1.160     raeburn   877: $crumbs
1.25      matthew   878: $forminfo
1.213     raeburn   879: <h2>
1.26      matthew   880: ENDCHANGEUSER
1.213     raeburn   881:         if ($env{'form.action'} eq 'singlestudent') {
                    882:             $r->print($lt{'ens'});
                    883:         } else {
                    884:             $r->print($lt{'cup'});
                    885:         }
                    886:         $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
                    887:                   "\n".'<div class="LC_left_float">');
1.206     raeburn   888:         my ($personal_table,$showforceid) = 
1.210     raeburn   889:             &personal_data_display($ccuname,$ccdomain,$newuser,$context,
                    890:                                    $inst_results{$ccuname.':'.$ccdomain});
1.206     raeburn   891:         $r->print($personal_table);
                    892:         if ($showforceid) {
1.203     raeburn   893:             $r->print(&Apache::lonuserutils::forceid_change($context));
1.199     raeburn   894:         }
                    895:         $r->print('</div>');
1.188     raeburn   896:         my $user_auth_text = 
                    897:             &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);
                    898:         my $user_quota_text;
                    899:         if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
                    900:             # Current user has quota modification privileges
                    901:             $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
                    902:         } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
                    903:             # Get the user's portfolio information
                    904:             my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
                    905:                                              $ccdomain,$ccuname);
                    906: 
                    907:             my %lt=&Apache::lonlocal::texthash(
                    908:                 'dska'  => "Disk space allocated to user's portfolio files",
                    909:                 'youd'  => "You do not have privileges to modify the portfolio quota for this user.",
                    910:                 'ichr'  => "If a change is required, contact a domain coordinator for the domain",
                    911:             );
                    912:             $user_quota_text = <<ENDNOPORTPRIV;
                    913: <h3>$lt{'dska'}</h3>
                    914: $lt{'youd'} $lt{'ichr'}: $ccdomain
                    915: ENDNOPORTPRIV
                    916:         }
                    917:         if ($user_auth_text ne '') {
                    918:             $r->print('<div class="LC_left_float">'.$user_auth_text);
                    919:             if ($user_quota_text ne '') {
                    920:                 $r->print($user_quota_text);
                    921:             }
1.213     raeburn   922:             if ($env{'form.action'} eq 'singlestudent') {
                    923:                 $r->print(&date_sections_select($context,$newuser,$formname));
                    924:             }
1.188     raeburn   925:         } elsif ($user_quota_text ne '') {
1.213     raeburn   926:             $r->print('<div class="LC_left_float">'.$user_quota_text);
                    927:             if ($env{'form.action'} eq 'singlestudent') {
                    928:                 $r->print(&date_sections_select($context,$newuser,$formname));
                    929:             }
                    930:         } else {
                    931:             if ($env{'form.action'} eq 'singlestudent') {
                    932:                 $r->print('<div class="LC_left_float">'.
                    933:                           &date_sections_select($context,$newuser,$formname));
                    934:             }
1.188     raeburn   935:         }
1.213     raeburn   936:         $r->print('</div><div class="LC_clear_float_footer"></div>');
1.28      matthew   937:         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.25      matthew   938:         # Build up table of user roles to allow revocation of a role.
1.28      matthew   939:         my ($tmp) = keys(%rolesdump);
                    940:         unless ($tmp =~ /^(con_lost|error)/i) {
1.2       www       941:            my $now=time;
1.72      sakharuk  942: 	   my %lt=&Apache::lonlocal::texthash(
1.191     raeburn   943: 		    'rer'  => "Existing Roles",
1.72      sakharuk  944:                     'rev'  => "Revoke",                    
                    945:                     'del'  => "Delete",
1.81      albertel  946: 		    'ren'  => "Re-Enable",
1.72      sakharuk  947:                     'rol'  => "Role",
                    948:                     'ext'  => "Extent",
                    949:                     'sta'  => "Start",
                    950:                     'end'  => "End"
                    951: 				       );
1.89      raeburn   952:            my (%roletext,%sortrole,%roleclass,%rolepriv);
1.67      albertel  953: 	   foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
                    954: 				    my $b1=join('_',(split('_',$b))[1,0]);
                    955: 				    return $a1 cmp $b1;
                    956: 				} keys(%rolesdump)) {
1.37      matthew   957:                next if ($area =~ /^rolesdef/);
1.79      albertel  958: 	       my $envkey=$area;
1.37      matthew   959:                my $role = $rolesdump{$area};
                    960:                my $thisrole=$area;
                    961:                $area =~ s/\_\w\w$//;
                    962:                my ($role_code,$role_end_time,$role_start_time) = 
                    963:                    split(/_/,$role);
1.64      www       964: # Is this a custom role? Get role owner and title.
                    965: 	       my ($croleudom,$croleuname,$croletitle)=
1.139     albertel  966: 	           ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1.37      matthew   967:                my $allowed=0;
1.53      www       968:                my $delallowed=0;
1.79      albertel  969: 	       my $sortkey=$role_code;
                    970: 	       my $class='Unknown';
1.141     albertel  971:                if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1.79      albertel  972: 		   $class='Course';
1.57      matthew   973:                    my ($coursedom,$coursedir) = ($1,$2);
1.130     albertel  974: 		   $sortkey.="\0$coursedom";
1.57      matthew   975:                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.37      matthew   976:                    my %coursedata=
                    977:                        &Apache::lonnet::coursedescription($1.'_'.$2);
1.51      albertel  978: 		   my $carea;
                    979: 		   if (defined($coursedata{'description'})) {
1.79      albertel  980: 		       $carea=$coursedata{'description'}.
1.72      sakharuk  981:                            '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
1.57      matthew   982:      &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
1.79      albertel  983: 		       $sortkey.="\0".$coursedata{'description'};
1.119     raeburn   984:                        $class=$coursedata{'type'};
1.51      albertel  985: 		   } else {
1.72      sakharuk  986: 		       $carea=&mt('Unavailable course').': '.$area;
1.86      albertel  987: 		       $sortkey.="\0".&mt('Unavailable course').': '.$area;
1.51      albertel  988: 		   }
1.130     albertel  989: 		   $sortkey.="\0$coursedir";
1.37      matthew   990:                    $inccourses{$1.'_'.$2}=1;
1.53      www       991:                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
                    992:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37      matthew   993:                        $allowed=1;
                    994:                    }
1.53      www       995:                    if ((&Apache::lonnet::allowed('dro',$1)) ||
                    996:                        (&Apache::lonnet::allowed('dro',$ccdomain))) {
                    997:                        $delallowed=1;
                    998:                    }
1.64      www       999: # - custom role. Needs more info, too
                   1000: 		   if ($croletitle) {
                   1001: 		       if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
                   1002: 			   $allowed=1;
                   1003: 			   $thisrole.='.'.$role_code;
                   1004: 		       }
                   1005: 		   }
1.37      matthew  1006:                    # Compute the background color based on $area
1.141     albertel 1007:                    if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.113     raeburn  1008:                        $carea.='<br />Section: '.$3;
1.87      albertel 1009: 		       $sortkey.="\0$3";
1.37      matthew  1010:                    }
                   1011:                    $area=$carea;
                   1012:                } else {
1.79      albertel 1013: 		   $sortkey.="\0".$area;
1.37      matthew  1014:                    # Determine if current user is able to revoke privileges
1.139     albertel 1015:                    if ($area=~m{^/($match_domain)/}) {
1.53      www      1016:                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
                   1017:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37      matthew  1018:                            $allowed=1;
                   1019:                        }
1.53      www      1020:                        if (((&Apache::lonnet::allowed('dro',$1))  ||
                   1021:                             (&Apache::lonnet::allowed('dro',$ccdomain))) &&
                   1022:                            ($role_code ne 'dc')) {
                   1023:                            $delallowed=1;
                   1024:                        }
1.37      matthew  1025:                    } else {
                   1026:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
                   1027:                            $allowed=1;
                   1028:                        }
                   1029:                    }
1.79      albertel 1030: 		   if ($role_code eq 'ca' || $role_code eq 'au') {
                   1031: 		       $class='Construction Space';
                   1032: 		   } elsif ($role_code eq 'su') {
                   1033: 		       $class='System';
                   1034: 		   } else {
                   1035: 		       $class='Domain';
                   1036: 		   }
1.37      matthew  1037:                }
1.105     www      1038:                if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1.139     albertel 1039:                    $area=~m{/($match_domain)/($match_username)};
1.209     raeburn  1040: 		   if (&Apache::lonuserutils::authorpriv($2,$1)) {
1.43      www      1041: 		       $allowed=1;
                   1042:                    } else {
                   1043:                        $allowed=0;
1.37      matthew  1044:                    }
                   1045:                }
                   1046:                my $row = '';
1.137     raeburn  1047:                $row.= '<td>';
1.37      matthew  1048:                my $active=1;
                   1049:                $active=0 if (($role_end_time) && ($now>$role_end_time));
                   1050:                if (($active) && ($allowed)) {
1.157     albertel 1051:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.37      matthew  1052:                } else {
1.56      www      1053:                    if ($active) {
                   1054:                       $row.='&nbsp;';
                   1055: 		   } else {
1.72      sakharuk 1056:                       $row.=&mt('expired or revoked');
1.56      www      1057: 		   }
1.37      matthew  1058:                }
1.53      www      1059: 	       $row.='</td><td>';
1.81      albertel 1060:                if ($allowed && !$active) {
1.157     albertel 1061:                    $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1.81      albertel 1062:                } else {
                   1063:                    $row.='&nbsp;';
                   1064:                }
                   1065: 	       $row.='</td><td>';
1.53      www      1066:                if ($delallowed) {
1.157     albertel 1067:                    $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.53      www      1068:                } else {
                   1069:                    $row.='&nbsp;';
                   1070:                }
1.64      www      1071: 	       my $plaintext='';
1.150     banghart 1072: 	       if (!$croletitle) {
1.120     raeburn  1073:                    $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1.64      www      1074: 	       } else {
                   1075: 	           $plaintext=
1.188     raeburn  1076: 		"Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
1.64      www      1077: 	       }
                   1078:                $row.= '</td><td>'.$plaintext.
1.37      matthew  1079:                       '</td><td>'.$area.
                   1080:                       '</td><td>'.($role_start_time?localtime($role_start_time)
                   1081:                                                    : '&nbsp;' ).
                   1082:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
                   1083:                                                    : '&nbsp;' )
1.137     raeburn  1084:                       ."</td>";
1.79      albertel 1085: 	       $sortrole{$sortkey}=$envkey;
                   1086: 	       $roletext{$envkey}=$row;
                   1087: 	       $roleclass{$envkey}=$class;
1.89      raeburn  1088:                $rolepriv{$envkey}=$allowed;
1.79      albertel 1089:                #$r->print($row);
1.28      matthew  1090:            } # end of foreach        (table building loop)
1.89      raeburn  1091:            my $rolesdisplay = 0;
                   1092:            my %output = ();
1.119     raeburn  1093: 	   foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1.89      raeburn  1094: 	       $output{$type} = '';
1.79      albertel 1095: 	       foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1.89      raeburn  1096: 		   if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) { 
1.137     raeburn  1097: 		       $output{$type}.=
                   1098:                              &Apache::loncommon::start_data_table_row().
                   1099:                              $roletext{$sortrole{$which}}.
                   1100:                              &Apache::loncommon::end_data_table_row();
1.79      albertel 1101: 		   }
                   1102: 	       }
1.89      raeburn  1103: 	       unless($output{$type} eq '') {
1.137     raeburn  1104: 		   $output{$type} = '<tr class="LC_info_row">'.
                   1105: 			     "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1.89      raeburn  1106:                               $output{$type};
                   1107:                    $rolesdisplay = 1;
1.79      albertel 1108: 	       }
                   1109: 	   }
1.89      raeburn  1110:            if ($rolesdisplay == 1) {
1.137     raeburn  1111:                $r->print('
                   1112: <h3>'.$lt{'rer'}.'</h3>'.
                   1113: &Apache::loncommon::start_data_table("LC_createuser").
                   1114: &Apache::loncommon::start_data_table_header_row().
                   1115: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
                   1116: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
                   1117: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
                   1118: &Apache::loncommon::end_data_table_header_row());
1.119     raeburn  1119:                foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1.89      raeburn  1120:                    if ($output{$type}) {
                   1121:                        $r->print($output{$type}."\n");
                   1122:                    }
                   1123:                }
1.137     raeburn  1124: 	       $r->print(&Apache::loncommon::end_data_table());
1.89      raeburn  1125:            }
1.28      matthew  1126:         }  # End of unless
1.25      matthew  1127:     } ## End of new user/old user logic
1.188     raeburn  1128:     my $addrolesdisplay = 0;
                   1129:     $r->print('<h3>'.&mt('Add Roles').'</h3>');
1.17      www      1130: #
                   1131: # Co-Author
                   1132: # 
1.209     raeburn  1133:     if (&Apache::lonuserutils::authorpriv($env{'user.name'},
                   1134:                                           $env{'request.role.domain'}) &&
1.101     albertel 1135:         ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1.44      matthew  1136:         # No sense in assigning co-author role to yourself
1.188     raeburn  1137:         $addrolesdisplay = 1;
1.101     albertel 1138: 	my $cuname=$env{'user.name'};
                   1139:         my $cudom=$env{'request.role.domain'};
1.72      sakharuk 1140: 	   my %lt=&Apache::lonlocal::texthash(
                   1141: 		    'cs'   => "Construction Space",
                   1142:                     'act'  => "Activate",                    
                   1143:                     'rol'  => "Role",
                   1144:                     'ext'  => "Extent",
                   1145:                     'sta'  => "Start",
1.80      www      1146:                     'end'  => "End",
1.72      sakharuk 1147:                     'cau'  => "Co-Author",
1.105     www      1148:                     'caa'  => "Assistant Co-Author",
1.72      sakharuk 1149:                     'ssd'  => "Set Start Date",
                   1150:                     'sed'  => "Set End Date"
                   1151: 				       );
1.135     raeburn  1152:        $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n". 
                   1153:            &Apache::loncommon::start_data_table()."\n".
                   1154:            &Apache::loncommon::start_data_table_header_row()."\n".
                   1155:            '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
                   1156:            '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
                   1157:            '<th>'.$lt{'end'}.'</th>'."\n".
                   1158:            &Apache::loncommon::end_data_table_header_row()."\n".
                   1159:            &Apache::loncommon::start_data_table_row()."\n".
                   1160:            '<td>
                   1161:             <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
                   1162:            </td>
                   1163:            <td>'.$lt{'cau'}.'</td>
                   1164:            <td>'.$cudom.'_'.$cuname.'</td>
                   1165:            <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
                   1166:              <a href=
                   1167: "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.169     albertel 1168: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1.17      www      1169: <a href=
1.135     raeburn  1170: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
                   1171:           &Apache::loncommon::end_data_table_row()."\n".
                   1172:           &Apache::loncommon::start_data_table_row()."\n".
                   1173: '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
                   1174: <td>'.$lt{'caa'}.'</td>
                   1175: <td>'.$cudom.'_'.$cuname.'</td>
1.169     albertel 1176: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1.17      www      1177: <a href=
1.135     raeburn  1178: "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>
1.169     albertel 1179: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1.105     www      1180: <a href=
1.135     raeburn  1181: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
                   1182:          &Apache::loncommon::end_data_table_row()."\n".
                   1183:          &Apache::loncommon::end_data_table());
1.190     raeburn  1184:     } elsif ($env{'request.role'} =~ /^au\./) {
1.209     raeburn  1185:         if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
                   1186:                                                 $env{'request.role.domain'}))) {
1.190     raeburn  1187:             $r->print('<span class="LC_error">'.
                   1188:                       &mt('You do not have privileges to assign co-author roles.').
                   1189:                       '</span>');
                   1190:         } elsif (($env{'user.name'} eq $ccuname) && 
1.188     raeburn  1191:              ($env{'user.domain'} eq $ccdomain)) {
1.190     raeburn  1192:            $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
                   1193:         }
1.17      www      1194:     }
1.8       www      1195: #
                   1196: # Domain level
                   1197: #
1.89      raeburn  1198:     my $num_domain_level = 0;
                   1199:     my $domaintext = 
                   1200:     '<h4>'.&mt('Domain Level').'</h4>'.
1.135     raeburn  1201:     &Apache::loncommon::start_data_table().
                   1202:     &Apache::loncommon::start_data_table_header_row().
                   1203:     '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
                   1204:     &mt('Extent').'</th>'.
                   1205:     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
                   1206:     &Apache::loncommon::end_data_table_header_row();
1.146     albertel 1207:     foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.135     raeburn  1208:         foreach my $role ('dc','li','dg','au','sc') {
                   1209:             if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
                   1210:                my $plrole=&Apache::lonnet::plaintext($role);
1.72      sakharuk 1211: 	       my %lt=&Apache::lonlocal::texthash(
                   1212:                     'ssd'  => "Set Start Date",
                   1213:                     'sed'  => "Set End Date"
                   1214: 				       );
1.89      raeburn  1215:                $num_domain_level ++;
1.135     raeburn  1216:                $domaintext .= 
                   1217: &Apache::loncommon::start_data_table_row().
1.157     albertel 1218: '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
1.135     raeburn  1219: <td>'.$plrole.'</td>
                   1220: <td>'.$thisdomain.'</td>
1.169     albertel 1221: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1.8       www      1222: <a href=
1.135     raeburn  1223: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1.169     albertel 1224: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1.8       www      1225: <a href=
1.135     raeburn  1226: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
                   1227: &Apache::loncommon::end_data_table_row();
1.2       www      1228:             }
1.24      matthew  1229:         } 
                   1230:     }
1.135     raeburn  1231:     $domaintext.= &Apache::loncommon::end_data_table();
1.89      raeburn  1232:     if ($num_domain_level > 0) {
                   1233:         $r->print($domaintext);
1.188     raeburn  1234:         $addrolesdisplay = 1;
1.89      raeburn  1235:     }
1.8       www      1236: #
1.188     raeburn  1237: # Course level
1.8       www      1238: #
1.88      raeburn  1239: 
1.139     albertel 1240:     if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
1.119     raeburn  1241:         $r->print(&course_level_dc($1,'Course'));
1.188     raeburn  1242:         $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
                   1243:     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/$}) {
                   1244:         if ($addrolesdisplay) {
                   1245:             $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
                   1246:             if ($newuser) {
                   1247:                 $r->print(' onClick="verify_message(this.form)" \>'."\n");
                   1248:             } else {
                   1249:                 $r->print('onClick="this.form.submit()" \>'."\n"); 
                   1250:             }
                   1251:         } else {
                   1252:             $r->print('<br /><a href="javascript:backPage(document.cu)">'.
                   1253:                       &mt('Back to previous page').'</a>');
                   1254:         }
1.88      raeburn  1255:     } else {
                   1256:         $r->print(&course_level_table(%inccourses));
1.198     raeburn  1257:         $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
1.88      raeburn  1258:     }
1.188     raeburn  1259:     $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179     raeburn  1260:     $r->print('<input type="hidden" name="currstate" value="" />');
1.160     raeburn  1261:     $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110     albertel 1262:     $r->print("</form>".&Apache::loncommon::end_page());
1.2       www      1263: }
1.1       www      1264: 
1.213     raeburn  1265: sub singleuser_breadcrumb {
                   1266:     my %breadcrumb_text;
                   1267:     if ($env{'form.action'} eq 'singlestudent') {
                   1268:         $breadcrumb_text{'search'} = 'Enroll a student';
                   1269:         $breadcrumb_text{'userpicked'} = 'Select a user',
                   1270:         $breadcrumb_text{'modify'} = 'Set section/dates',
                   1271:     } else {
                   1272:         $breadcrumb_text{'search'} = 'Create/modify user';
                   1273:         $breadcrumb_text{'userpicked'} = 'Select a user',
                   1274:         $breadcrumb_text{'modify'} = 'Set user role',
                   1275:     }
                   1276:     return %breadcrumb_text;
                   1277: }
                   1278: 
                   1279: sub date_sections_select {
                   1280:     my ($context,$newuser,$formname,$permission) = @_;
                   1281:     my $cid = $env{'request.course.id'};
                   1282:     my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
                   1283:     my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
                   1284:         &Apache::lonuserutils::date_setting_table(undef,undef,$context,
                   1285:                                                   undef,$formname,$permission);
                   1286:     my $rowtitle = 'Section';
                   1287:     my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
                   1288:         &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
                   1289:                                               $permission);
                   1290:     my $output = $date_table.$secbox;
                   1291:     return $output;
                   1292: }
                   1293: 
1.188     raeburn  1294: sub user_authentication {
                   1295:     my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
                   1296:     my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
                   1297:     my ($loginscript,$outcome);
                   1298:     if ($currentauth=~/^(krb)(4|5):(.*)/) {
                   1299:         my $long_auth = $1.$2;
                   1300:         my $curr_kerb_ver = $2;
                   1301:         my $krbdefdom=$3;
                   1302:         my $curr_authtype = $abv_auth->{$long_auth};
                   1303:         my %param = ( formname      => 'document.cu',
                   1304:                       kerb_def_dom  => $krbdefdom,
                   1305:                       domain        => $ccdomain,
                   1306:                       curr_authtype => $curr_authtype,
                   1307:                       curr_kerb_ver => $curr_kerb_ver,
                   1308:                           );
                   1309:         $loginscript  = &Apache::loncommon::authform_header(%param);
                   1310:     }
                   1311:     # Check for a bad authentication type
                   1312:     if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
                   1313:         # bad authentication scheme
                   1314:         my %lt=&Apache::lonlocal::texthash(
                   1315:                        'err'   => "ERROR",
                   1316:                        'uuas'  => "This user has an unrecognized authentication scheme",
                   1317:                        'adcs'  => "Please alert a domain coordinator of this situation",
                   1318:                        'sldb'  => "Please specify login data below",
                   1319:                        'ld'    => "Login Data"
                   1320:         );
                   1321:         if (&Apache::lonnet::allowed('mau',$ccdomain)) {
                   1322:             &initialize_authen_forms($ccdomain);
1.190     raeburn  1323:             my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188     raeburn  1324:             $outcome = <<ENDBADAUTH;
                   1325: <script type="text/javascript" language="Javascript">
                   1326: $loginscript
                   1327: </script>
                   1328: <span class="LC_error">$lt{'err'}:
                   1329: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
                   1330: <h3>$lt{'ld'}</h3>
                   1331: $choices
                   1332: ENDBADAUTH
                   1333:         } else {
                   1334:             # This user is not allowed to modify the user's
                   1335:             # authentication scheme, so just notify them of the problem
                   1336:             $outcome = <<ENDBADAUTH;
                   1337: <span class="LC_error"> $lt{'err'}: 
                   1338: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
                   1339: </span>
                   1340: ENDBADAUTH
                   1341:         }
                   1342:     } else { # Authentication type is valid
1.205     raeburn  1343:         &initialize_authen_forms($ccdomain,$currentauth,'modifyuser');
                   1344:         my ($authformcurrent,$can_modify,@authform_others) =
1.188     raeburn  1345:             &modify_login_block($ccdomain,$currentauth);
                   1346:         if (&Apache::lonnet::allowed('mau',$ccdomain)) {
                   1347:             # Current user has login modification privileges
                   1348:             my %lt=&Apache::lonlocal::texthash (
                   1349:                            'ld'    => "Login Data",
                   1350:                            'ccld'  => "Change Current Login Data",
                   1351:                            'enld'  => "Enter New Login Data"
                   1352:                                                );
                   1353:             $outcome =
                   1354:                        '<script type="text/javascript" language="Javascript">'."\n".
                   1355:                        $loginscript."\n".
                   1356:                        '</script>'."\n".
                   1357:                        '<h3>'.$lt{'ld'}.'</h3>'.
                   1358:                        &Apache::loncommon::start_data_table().
1.205     raeburn  1359:                        &Apache::loncommon::start_data_table_row().
1.188     raeburn  1360:                        '<td>'.$authformnop;
                   1361:             if ($can_modify) {
                   1362:                 $outcome .= '</td>'."\n".
                   1363:                             &Apache::loncommon::end_data_table_row().
                   1364:                             &Apache::loncommon::start_data_table_row().
                   1365:                             '<td>'.$authformcurrent.'</td>'.
                   1366:                             &Apache::loncommon::end_data_table_row()."\n";
                   1367:             } else {
1.200     raeburn  1368:                 $outcome .= '&nbsp;('.$authformcurrent.')</td>'.
                   1369:                             &Apache::loncommon::end_data_table_row()."\n";
1.188     raeburn  1370:             }
1.205     raeburn  1371:             foreach my $item (@authform_others) { 
                   1372:                 $outcome .= &Apache::loncommon::start_data_table_row().
                   1373:                             '<td>'.$item.'</td>'.
                   1374:                             &Apache::loncommon::end_data_table_row()."\n";
1.188     raeburn  1375:             }
1.205     raeburn  1376:             $outcome .= &Apache::loncommon::end_data_table();
1.188     raeburn  1377:         } else {
                   1378:             if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
                   1379:                 my %lt=&Apache::lonlocal::texthash(
                   1380:                            'ccld'  => "Change Current Login Data",
                   1381:                            'yodo'  => "You do not have privileges to modify the authentication configuration for this user.",
                   1382:                            'ifch'  => "If a change is required, contact a domain coordinator for the domain",
                   1383:                 );
                   1384:                 $outcome .= <<ENDNOPRIV;
                   1385: <h3>$lt{'ccld'}</h3>
                   1386: $lt{'yodo'} $lt{'ifch'}: $ccdomain
                   1387: ENDNOPRIV
                   1388:             }
                   1389:         }
                   1390:     }  ## End of "check for bad authentication type" logic
                   1391:     return $outcome;
                   1392: }
                   1393: 
1.187     raeburn  1394: sub modify_login_block {
                   1395:     my ($dom,$currentauth) = @_;
                   1396:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   1397:     my ($authnum,%can_assign) =
                   1398:         &Apache::loncommon::get_assignable_auth($dom);
1.205     raeburn  1399:     my ($authformcurrent,@authform_others,$show_override_msg);
1.187     raeburn  1400:     if ($currentauth=~/^krb(4|5):/) {
                   1401:         $authformcurrent=$authformkrb;
                   1402:         if ($can_assign{'int'}) {
1.205     raeburn  1403:             push(@authform_others,$authformint);
1.187     raeburn  1404:         }
                   1405:         if ($can_assign{'loc'}) {
1.205     raeburn  1406:             push(@authform_others,$authformloc);
1.187     raeburn  1407:         }
                   1408:         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
                   1409:             $show_override_msg = 1;
                   1410:         }
                   1411:     } elsif ($currentauth=~/^internal:/) {
                   1412:         $authformcurrent=$authformint;
                   1413:         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205     raeburn  1414:             push(@authform_others,$authformkrb);
1.187     raeburn  1415:         }
                   1416:         if ($can_assign{'loc'}) {
1.205     raeburn  1417:             push(@authform_others,$authformloc);
1.187     raeburn  1418:         }
                   1419:         if ($can_assign{'int'}) {
                   1420:             $show_override_msg = 1;
                   1421:         }
                   1422:     } elsif ($currentauth=~/^unix:/) {
                   1423:         $authformcurrent=$authformfsys;
                   1424:         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205     raeburn  1425:             push(@authform_others,$authformkrb);
1.187     raeburn  1426:         }
                   1427:         if ($can_assign{'int'}) {
1.205     raeburn  1428:             push(@authform_others,$authformint);
1.187     raeburn  1429:         }
                   1430:         if ($can_assign{'loc'}) {
1.205     raeburn  1431:             push(@authform_others,$authformloc);
1.187     raeburn  1432:         }
                   1433:         if ($can_assign{'fsys'}) {
                   1434:             $show_override_msg = 1;
                   1435:         }
                   1436:     } elsif ($currentauth=~/^localauth:/) {
                   1437:         $authformcurrent=$authformloc;
                   1438:         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205     raeburn  1439:             push(@authform_others,$authformkrb);
1.187     raeburn  1440:         }
                   1441:         if ($can_assign{'int'}) {
1.205     raeburn  1442:             push(@authform_others,$authformint);
1.187     raeburn  1443:         }
                   1444:         if ($can_assign{'loc'}) {
                   1445:             $show_override_msg = 1;
                   1446:         }
                   1447:     }
                   1448:     if ($show_override_msg) {
1.205     raeburn  1449:         $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
                   1450:                            '</td></tr>'."\n".
                   1451:                            '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
                   1452:                            '<td><b>'.&mt('Currently in use').'</b></td>'.
                   1453:                            '<td align="right"><span class="LC_cusr_emph">'.
1.187     raeburn  1454:                             &mt('will override current values').
1.205     raeburn  1455:                             '</span></td></tr></table>';
1.187     raeburn  1456:     }
1.205     raeburn  1457:     return ($authformcurrent,$show_override_msg,@authform_others); 
1.187     raeburn  1458: }
                   1459: 
1.188     raeburn  1460: sub personal_data_display {
1.210     raeburn  1461:     my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
1.206     raeburn  1462:     my ($output,$showforceid,%userenv,%domconfig);
1.188     raeburn  1463:     if (!$newuser) {
                   1464:         # Get the users information
                   1465:         %userenv = &Apache::lonnet::get('environment',
                   1466:                    ['firstname','middlename','lastname','generation',
                   1467:                     'permanentemail','id'],$ccdomain,$ccuname);
1.206     raeburn  1468:         %domconfig =
                   1469:             &Apache::lonnet::get_dom('configuration',['usermodification'],
                   1470:                                      $ccdomain);
1.188     raeburn  1471:     }
                   1472:     my %lt=&Apache::lonlocal::texthash(
                   1473:                 'pd'             => "Personal Data",
                   1474:                 'firstname'      => "First Name",
                   1475:                 'middlename'     => "Middle Name",
                   1476:                 'lastname'       => "Last Name",
                   1477:                 'generation'     => "Generation",
                   1478:                 'permanentemail' => "Permanent e-mail address",
                   1479:                 'id'             => "ID/Student Number",
                   1480:                 'lg'             => "Login Data"
                   1481:     );
                   1482:     my @userinfo = ('firstname','middlename','lastname','generation',
                   1483:                     'permanentemail','id');
                   1484:     my %textboxsize = (
                   1485:                        firstname      => '15',
                   1486:                        middlename     => '15',
                   1487:                        lastname       => '15',
                   1488:                        generation     => '5',
                   1489:                        permanentemail => '25',
                   1490:                        id             => '15',
                   1491:                       );
                   1492:     my $genhelp=&Apache::loncommon::help_open_topic('Generation');
                   1493:     $output = '<h3>'.$lt{'pd'}.'</h3>'.
                   1494:               &Apache::lonhtmlcommon::start_pick_box();
                   1495:     foreach my $item (@userinfo) {
                   1496:         my $rowtitle = $lt{$item};
                   1497:         if ($item eq 'generation') {
                   1498:             $rowtitle = $genhelp.$rowtitle;
                   1499:         }
                   1500:         $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
                   1501:         if ($newuser) {
1.210     raeburn  1502:             if (ref($inst_results) eq 'HASH') {
                   1503:                 if ($inst_results->{$item} ne '') {
                   1504:                     $output .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
                   1505:                 } else {
                   1506:                     $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
                   1507:                 }
1.188     raeburn  1508:             } else {
                   1509:                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
                   1510:             }
                   1511:         } else {
1.206     raeburn  1512:             my $canmodify = 0;
1.188     raeburn  1513:             if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.206     raeburn  1514:                 $canmodify = 1;
                   1515:             } else {
                   1516:                 if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   1517:                     if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
                   1518:                         foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
                   1519:                             if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
                   1520:                                 if ($domconfig{'usermodification'}{$context}{$key}{$item}) { 
                   1521:                                     $canmodify = 1;
                   1522:                                     last;
                   1523:                                 }
                   1524:                             }
                   1525:                         }
                   1526:                     }
                   1527:                 } elsif ($context eq 'course') {
                   1528:                     $canmodify = 1;
                   1529:                 }
                   1530:             }
                   1531:             if ($canmodify) {
1.188     raeburn  1532:                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
                   1533:             } else {
                   1534:                 $output .= $userenv{$item};
                   1535:             }
1.206     raeburn  1536:             if ($item eq 'id') {
                   1537:                 $showforceid = $canmodify; 
                   1538:             } 
1.188     raeburn  1539:         }
                   1540:         $output .= &Apache::lonhtmlcommon::row_closure(1);
                   1541:     }
                   1542:     $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206     raeburn  1543:     if (wantarray) {
                   1544:         return ($output,$showforceid);
                   1545:     } else {
                   1546:         return $output;
                   1547:     }
1.188     raeburn  1548: }
                   1549: 
1.4       www      1550: # ================================================================= Phase Three
1.42      matthew  1551: sub update_user_data {
1.206     raeburn  1552:     my ($r,$context) = @_; 
1.101     albertel 1553:     my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                   1554:                                           $env{'form.ccdomain'});
1.27      matthew  1555:     # Error messages
1.188     raeburn  1556:     my $error     = '<span class="LC_error">'.&mt('Error').': ';
1.193     raeburn  1557:     my $end       = '</span><br /><br />';
                   1558:     my $rtnlink   = '<a href="javascript:backPage(document.userupdate,'.
1.188     raeburn  1559:                     "'$env{'form.prevphase'}','modify')".'" />'.
                   1560:                     &mt('Return to previous page').'</a>'.&Apache::loncommon::end_page();
1.40      www      1561:     my $title;
1.101     albertel 1562:     if (exists($env{'form.makeuser'})) {
1.40      www      1563: 	$title='Set Privileges for New User';
                   1564:     } else {
                   1565:         $title='Modify User Privileges';
                   1566:     }
1.213     raeburn  1567:     my $newuser = 0;
1.160     raeburn  1568:     my ($jsback,$elements) = &crumb_utilities();
                   1569:     my $jscript = '<script type="text/javascript">'."\n".
                   1570:                   $jsback."\n".'</script>'."\n";
1.213     raeburn  1571:     my %breadcrumb_text = &singleuser_breadcrumb();
1.160     raeburn  1572:     $r->print(&Apache::loncommon::start_page($title,$jscript));
                   1573:     &Apache::lonhtmlcommon::add_breadcrumb
                   1574:        ({href=>"javascript:backPage(document.userupdate)",
1.213     raeburn  1575:          text=>$breadcrumb_text{'search'},
1.160     raeburn  1576:          faq=>282,bug=>'Instructor Interface',});
                   1577:     if ($env{'form.prevphase'} eq 'userpicked') {
                   1578:         &Apache::lonhtmlcommon::add_breadcrumb
                   1579:            ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213     raeburn  1580:              text=>$breadcrumb_text{'userpicked'},
1.160     raeburn  1581:              faq=>282,bug=>'Instructor Interface',});
                   1582:     }
                   1583:     &Apache::lonhtmlcommon::add_breadcrumb
                   1584:        ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
                   1585:          text=>"Set user role",
                   1586:          faq=>282,bug=>'Instructor Interface',},
                   1587:         {href=>"/adm/createuser",
                   1588:          text=>"Result",
                   1589:          faq=>282,bug=>'Instructor Interface',});
                   1590:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
                   1591: 
1.113     raeburn  1592:     my %disallowed;
1.188     raeburn  1593:     $r->print(&update_result_form($uhome));
1.27      matthew  1594:     # Check Inputs
1.101     albertel 1595:     if (! $env{'form.ccuname'} ) {
1.193     raeburn  1596: 	$r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27      matthew  1597: 	return;
                   1598:     }
1.138     albertel 1599:     if (  $env{'form.ccuname'} ne 
                   1600: 	  &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73      sakharuk 1601: 	$r->print($error.&mt('Invalid login name').'.  '.
1.160     raeburn  1602: 		  &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193     raeburn  1603: 		  $end.$rtnlink);
1.27      matthew  1604: 	return;
                   1605:     }
1.101     albertel 1606:     if (! $env{'form.ccdomain'}       ) {
1.193     raeburn  1607: 	$r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27      matthew  1608: 	return;
                   1609:     }
1.138     albertel 1610:     if (  $env{'form.ccdomain'} ne
                   1611: 	  &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73      sakharuk 1612: 	$r->print($error.&mt ('Invalid domain name').'.  '.
1.138     albertel 1613: 		  &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193     raeburn  1614: 		  $end.$rtnlink);
1.27      matthew  1615: 	return;
                   1616:     }
1.101     albertel 1617:     if (! exists($env{'form.makeuser'})) {
1.29      matthew  1618:         # Modifying an existing user, so check the validity of the name
                   1619:         if ($uhome eq 'no_host') {
1.73      sakharuk 1620:             $r->print($error.&mt('Unable to determine home server for ').
1.101     albertel 1621:                       $env{'form.ccuname'}.&mt(' in domain ').
                   1622:                       $env{'form.ccdomain'}.'.');
1.29      matthew  1623:             return;
                   1624:         }
                   1625:     }
1.27      matthew  1626:     # Determine authentication method and password for the user being modified
                   1627:     my $amode='';
                   1628:     my $genpwd='';
1.101     albertel 1629:     if ($env{'form.login'} eq 'krb') {
1.41      albertel 1630: 	$amode='krb';
1.101     albertel 1631: 	$amode.=$env{'form.krbver'};
                   1632: 	$genpwd=$env{'form.krbarg'};
                   1633:     } elsif ($env{'form.login'} eq 'int') {
1.27      matthew  1634: 	$amode='internal';
1.101     albertel 1635: 	$genpwd=$env{'form.intarg'};
                   1636:     } elsif ($env{'form.login'} eq 'fsys') {
1.27      matthew  1637: 	$amode='unix';
1.101     albertel 1638: 	$genpwd=$env{'form.fsysarg'};
                   1639:     } elsif ($env{'form.login'} eq 'loc') {
1.27      matthew  1640: 	$amode='localauth';
1.101     albertel 1641: 	$genpwd=$env{'form.locarg'};
1.27      matthew  1642: 	$genpwd=" " if (!$genpwd);
1.101     albertel 1643:     } elsif (($env{'form.login'} eq 'nochange') ||
                   1644:              ($env{'form.login'} eq ''        )) { 
1.34      matthew  1645:         # There is no need to tell the user we did not change what they
                   1646:         # did not ask us to change.
1.35      matthew  1647:         # If they are creating a new user but have not specified login
                   1648:         # information this will be caught below.
1.30      matthew  1649:     } else {
1.193     raeburn  1650: 	    $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);    
1.30      matthew  1651: 	    return;
1.27      matthew  1652:     }
1.164     albertel 1653: 
                   1654: 
1.188     raeburn  1655:     $r->print('<h3>'.&mt('User [_1] in domain [_2]',
                   1656: 			 $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193     raeburn  1657:     my (%alerts,%rulematch,%inst_results,%curr_rules);
1.101     albertel 1658:     if ($env{'form.makeuser'}) {
1.164     albertel 1659: 	$r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27      matthew  1660:         # Check for the authentication mode and password
                   1661:         if (! $amode || ! $genpwd) {
1.193     raeburn  1662: 	    $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);    
1.27      matthew  1663: 	    return;
1.18      albertel 1664: 	}
1.29      matthew  1665:         # Determine desired host
1.101     albertel 1666:         my $desiredhost = $env{'form.hserver'};
1.29      matthew  1667:         if (lc($desiredhost) eq 'default') {
                   1668:             $desiredhost = undef;
                   1669:         } else {
1.147     albertel 1670:             my %home_servers = 
                   1671: 		&Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29      matthew  1672:             if (! exists($home_servers{$desiredhost})) {
1.193     raeburn  1673:                 $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
                   1674:                 return;
                   1675:             }
                   1676:         }
                   1677:         # Check ID format
                   1678:         my %checkhash;
                   1679:         my %checks = ('id' => 1);
                   1680:         %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.196     raeburn  1681:             'newuser' => 1, 
                   1682:             'id' => $env{'form.cid'},
1.193     raeburn  1683:         );
1.196     raeburn  1684:         if ($env{'form.cid'} ne '') {
                   1685:             &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
                   1686:                                           \%rulematch,\%inst_results,\%curr_rules);
                   1687:             if (ref($alerts{'id'}) eq 'HASH') {
                   1688:                 if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
                   1689:                     my $domdesc =
                   1690:                         &Apache::lonnet::domain($env{'form.ccdomain'},'description');
                   1691:                     if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
                   1692:                         my $userchkmsg;
                   1693:                         if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
                   1694:                             $userchkmsg  = 
                   1695:                                 &Apache::loncommon::instrule_disallow_msg('id',
                   1696:                                                                     $domdesc,1).
                   1697:                                 &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
                   1698:                                     $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
                   1699:                         }
                   1700:                         $r->print($error.&mt('Invalid ID format').$end.
                   1701:                                   $userchkmsg.$rtnlink);
                   1702:                         return;
                   1703:                     }
                   1704:                 }
1.29      matthew  1705:             }
                   1706:         }
1.27      matthew  1707: 	# Call modifyuser
                   1708: 	my $result = &Apache::lonnet::modifyuser
1.193     raeburn  1709: 	    ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188     raeburn  1710:              $amode,$genpwd,$env{'form.cfirstname'},
                   1711:              $env{'form.cmiddlename'},$env{'form.clastname'},
                   1712:              $env{'form.cgeneration'},undef,$desiredhost,
                   1713:              $env{'form.cpermanentemail'});
1.77      www      1714: 	$r->print(&mt('Generating user').': '.$result);
1.101     albertel 1715:         my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
                   1716:                                                $env{'form.ccdomain'});
1.77      www      1717:         $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.148     albertel 1718:                   &Apache::lonnet::hostname($home));
1.101     albertel 1719:     } elsif (($env{'form.login'} ne 'nochange') &&
                   1720:              ($env{'form.login'} ne ''        )) {
1.27      matthew  1721: 	# Modify user privileges
                   1722:         if (! $amode || ! $genpwd) {
1.193     raeburn  1723: 	    $r->print($error.'Invalid login mode or password'.$end.$rtnlink);    
1.27      matthew  1724: 	    return;
1.20      harris41 1725: 	}
1.27      matthew  1726: 	# Only allow authentification modification if the person has authority
1.101     albertel 1727: 	if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20      harris41 1728: 	    $r->print('Modifying authentication: '.
1.31      matthew  1729:                       &Apache::lonnet::modifyuserauth(
1.101     albertel 1730: 		       $env{'form.ccdomain'},$env{'form.ccuname'},
1.21      harris41 1731:                        $amode,$genpwd));
1.102     albertel 1732:             $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101     albertel 1733: 		  ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4       www      1734: 	} else {
1.27      matthew  1735: 	    # Okay, this is a non-fatal error.
1.193     raeburn  1736: 	    $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);    
1.27      matthew  1737: 	}
1.28      matthew  1738:     }
                   1739:     ##
1.213     raeburn  1740:     my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
                   1741:     if ($context eq 'course') {
                   1742:         ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
                   1743:     }
1.101     albertel 1744:     if (! $env{'form.makeuser'} ) {
1.28      matthew  1745:         # Check for need to change
                   1746:         my %userenv = &Apache::lonnet::get
1.134     raeburn  1747:             ('environment',['firstname','middlename','lastname','generation',
1.196     raeburn  1748:              'id','permanentemail','portfolioquota','inststatus'],
1.160     raeburn  1749:               $env{'form.ccdomain'},$env{'form.ccuname'});
1.28      matthew  1750:         my ($tmp) = keys(%userenv);
                   1751:         if ($tmp =~ /^(con_lost|error)/i) { 
                   1752:             %userenv = ();
                   1753:         }
1.206     raeburn  1754:         my $no_forceid_alert;
                   1755:         # Check to see if user information can be changed
                   1756:         my %domconfig =
                   1757:             &Apache::lonnet::get_dom('configuration',['usermodification'],
                   1758:                                      $env{'form.ccdomain'});
1.213     raeburn  1759:         my @statuses = ('active','future');
                   1760:         my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
                   1761:         my ($auname,$audom);
1.206     raeburn  1762:         if ($context eq 'course') {
                   1763:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1764:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1765:             if ($cnum eq '' || $cdom eq '') {
                   1766:                 my $cid = $env{'request.course.id'};
                   1767:                 my %coursehash =
                   1768:                      &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1769:                 $cdom = $coursehash{'domain'};
                   1770:                 $cnum = $coursehash{'num'};
                   1771:             } 
                   1772:         } elsif ($context eq 'author') {
                   1773:             $auname = $env{'user.name'};
                   1774:             $audom = $env{'user.domain'};     
                   1775:         }
                   1776:         foreach my $item (keys(%roles)) {
                   1777:             my ($rolenum,$roledom,$role) = split(/:/,$item);
                   1778:             if ($context eq 'course') {
                   1779:                 if ($cnum ne '' && $cdom ne '') {
                   1780:                     if ($rolenum eq $cnum && $roledom eq $cdom) {
                   1781:                         if (!grep(/^\Q$role\E$/,@userroles)) {
                   1782:                             push(@userroles,$role);
                   1783:                         }
                   1784:                     }
                   1785:                 }
                   1786:             } elsif ($context eq 'author') {
                   1787:                 if ($rolenum eq $auname && $roledom eq $audom) {
                   1788:                     if (!grep(/^\Q$role\E$/,@userroles)) { 
                   1789:                         push(@userroles,$role);
                   1790:                     }
                   1791:                 }
                   1792:             }
                   1793:         }
                   1794:         # Check for course or co-author roles being activated or re-enabled
                   1795:         if ($context eq 'author' || $context eq 'course') {
                   1796:             foreach my $key (keys(%env)) {
                   1797:                 if ($context eq 'author') {
                   1798:                     if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
                   1799:                         if (!grep(/^\Q$1\E$/,@userroles)) {
                   1800:                             push(@userroles,$1);
                   1801:                         }
                   1802:                     } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
                   1803:                         if (!grep(/^\Q$1\E$/,@userroles)) {
                   1804:                             push(@userroles,$1);
                   1805:                         }
                   1806:                     }
                   1807:                 } elsif ($context eq 'course') {
                   1808:                     if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
                   1809:                         if (!grep(/^\Q$1\E$/,@userroles)) {
                   1810:                             push(@userroles,$1);
                   1811:                         }
                   1812:                     } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
                   1813:                         if (!grep(/^\Q$1\E$/,@userroles)) {
                   1814:                             push(@userroles,$1);
                   1815:                         }
                   1816:                     }
                   1817:                 }
                   1818:             }
                   1819:         }
                   1820:         #Check to see if we can change personal data for the user 
                   1821:         my (@mod_disallowed,@longroles);
                   1822:         foreach my $role (@userroles) {
                   1823:             if ($role eq 'cr') {
                   1824:                 push(@longroles,'Custom');
                   1825:             } else {
                   1826:                 push(@longroles,&Apache::lonnet::plaintext($role)); 
                   1827:             }
                   1828:         }
1.196     raeburn  1829:         foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
1.206     raeburn  1830:             my $canmodify = 0;
                   1831:             if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
                   1832:                 $canmodify = 1;
                   1833:             } else {
                   1834:                 if ($context eq 'course' || $context eq 'author') {
                   1835:                     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   1836:                         if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
                   1837:                             foreach my $role (@userroles) {
                   1838:                                 if (ref($domconfig{'usermodification'}{$context}{$role}) eq 'HASH') {
                   1839:                                     if ($domconfig{'usermodification'}{$context}{$role}{$item}) {
                   1840:                                         $canmodify = 1;
                   1841:                                         last;
                   1842:                                     }
                   1843:                                 }
                   1844:                             }
                   1845:                         }
                   1846:                     }
                   1847:                 } elsif ($context eq 'course') {
                   1848:                     if (grep(/^st$/,@userroles)) {
                   1849:                         $canmodify = 1;
                   1850:                     }
                   1851:                 }
                   1852:             }
1.28      matthew  1853:             # Strip leading and trailing whitespace
1.203     raeburn  1854:             $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.206     raeburn  1855:             if (!$canmodify) {
1.207     raeburn  1856:                 if (defined($env{'form.c'.$item})) {
                   1857:                     if ($env{'form.c'.$item} ne $userenv{$item}) {
                   1858:                         push(@mod_disallowed,$item);
                   1859:                     }
1.206     raeburn  1860:                 }
                   1861:                 $env{'form.c'.$item} = $userenv{$item};
                   1862:             }
1.28      matthew  1863:         }
1.196     raeburn  1864:         # Check to see if we can change the ID/student number
                   1865:         my $forceid = $env{'form.forceid'};
                   1866:         my $recurseid = $env{'form.recurseid'};
                   1867:         my $newuser = 0;
                   1868:         my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203     raeburn  1869:         my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
                   1870:                                             $env{'form.ccuname'});
                   1871:         if (($uidhash{$env{'form.ccuname'}}) && 
                   1872:             ($uidhash{$env{'form.ccuname'}}!~/error\:/) && 
                   1873:             (!$forceid)) {
                   1874:             if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
                   1875:                 $env{'form.cid'} = $userenv{'id'};
1.206     raeburn  1876:                 $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'<br />'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'<br />'."\n";        
1.203     raeburn  1877:             }
                   1878:         }
                   1879:         if ($env{'form.cid'} ne $userenv{'id'}) {
1.196     raeburn  1880:             my $checkhash;
                   1881:             my $checks = { 'id' => 1 };
                   1882:             $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} = 
                   1883:                    { 'newuser' => $newuser,
                   1884:                      'id'  => $env{'form.cid'}, 
                   1885:                    };
                   1886:             &Apache::loncommon::user_rule_check($checkhash,$checks,
                   1887:                 \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
                   1888:             if (ref($alerts{'id'}) eq 'HASH') {
                   1889:                 if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203     raeburn  1890:                    $env{'form.cid'} = $userenv{'id'};
1.196     raeburn  1891:                 }
                   1892:             }
                   1893:         }
1.213     raeburn  1894:         my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204     raeburn  1895:             $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
                   1896:             $newdefquotatext);
1.149     raeburn  1897:         my ($defquota,$settingstatus) = 
                   1898:             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.134     raeburn  1899:         my %changeHash;
1.204     raeburn  1900:         $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149     raeburn  1901:         if ($userenv{'portfolioquota'} ne '') {
1.134     raeburn  1902:             $oldportfolioquota = $userenv{'portfolioquota'};
1.149     raeburn  1903:             if ($env{'form.customquota'} == 1) {
                   1904:                 if ($env{'form.portfolioquota'} eq '') {
                   1905:                     $newportfolioquota = 0;
                   1906:                 } else {
                   1907:                     $newportfolioquota = $env{'form.portfolioquota'};
                   1908:                     $newportfolioquota =~ s/[^\d\.]//g;
                   1909:                 }
1.204     raeburn  1910:                 if ($newportfolioquota != $oldportfolioquota) {
1.149     raeburn  1911:                     $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
1.134     raeburn  1912:                 }
1.149     raeburn  1913:             } else {
                   1914:                 $quotachanged = &quota_admin('',\%changeHash);
                   1915:                 $newportfolioquota = $defquota;
1.204     raeburn  1916:                 $newisdefault = 1; 
1.134     raeburn  1917:             }
                   1918:         } else {
1.204     raeburn  1919:             $oldisdefault = 1;
1.149     raeburn  1920:             $oldportfolioquota = $defquota;
                   1921:             if ($env{'form.customquota'} == 1) {
                   1922:                 if ($env{'form.portfolioquota'} eq '') {
                   1923:                     $newportfolioquota = 0;
                   1924:                 } else {
                   1925:                     $newportfolioquota = $env{'form.portfolioquota'};
                   1926:                     $newportfolioquota =~ s/[^\d\.]//g;
                   1927:                 }
                   1928:                 $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
                   1929:             } else {
                   1930:                 $newportfolioquota = $defquota;
1.204     raeburn  1931:                 $newisdefault = 1;
1.149     raeburn  1932:             }
                   1933:         }
1.204     raeburn  1934:         if ($oldisdefault) {
                   1935:             $olddefquotatext = &get_defaultquota_text($settingstatus);
                   1936:         }
                   1937:         if ($newisdefault) {
                   1938:             $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134     raeburn  1939:         }
1.206     raeburn  1940:         if ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
                   1941:             $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
                   1942:             $env{'form.clastname'}   ne $userenv{'lastname'}   ||
                   1943:             $env{'form.cgeneration'} ne $userenv{'generation'} ||
                   1944:             $env{'form.cid'} ne $userenv{'id'}                 ||
                   1945:             $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134     raeburn  1946:             $namechanged = 1;
                   1947:         }
1.204     raeburn  1948:         if ($namechanged || $quotachanged) {
1.101     albertel 1949:             $changeHash{'firstname'}  = $env{'form.cfirstname'};
                   1950:             $changeHash{'middlename'} = $env{'form.cmiddlename'};
                   1951:             $changeHash{'lastname'}   = $env{'form.clastname'};
                   1952:             $changeHash{'generation'} = $env{'form.cgeneration'};
1.196     raeburn  1953:             $changeHash{'id'}         = $env{'form.cid'};
1.174     raeburn  1954:             $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204     raeburn  1955:             my ($quotachgresult,$namechgresult);
                   1956:             if ($quotachanged) {
                   1957:                 $quotachgresult = 
                   1958:                     &Apache::lonnet::put('environment',\%changeHash,
                   1959:                                   $env{'form.ccdomain'},$env{'form.ccuname'});
                   1960:             }
                   1961:             if ($namechanged) {
                   1962:             # Make the change
                   1963:                 $namechgresult =
                   1964:                     &Apache::lonnet::modifyuser($env{'form.ccdomain'},
                   1965:                         $env{'form.ccuname'},$changeHash{'id'},undef,undef,
                   1966:                         $changeHash{'firstname'},$changeHash{'middlename'},
                   1967:                         $changeHash{'lastname'},$changeHash{'generation'},
                   1968:                         $changeHash{'id'},undef,$changeHash{'permanentemail'});
                   1969:             }
                   1970:             if (($namechanged && $namechgresult eq 'ok') || 
                   1971:                 ($quotachanged && $quotachgresult eq 'ok')) {
1.28      matthew  1972:             # Tell the user we changed the name
1.73      sakharuk 1973: 		my %lt=&Apache::lonlocal::texthash(
                   1974:                              'uic'  => "User Information Changed",             
                   1975:                              'frst' => "first",
                   1976:                              'mddl' => "middle",
                   1977:                              'lst'  => "last",
                   1978: 			     'gen'  => "generation",
1.196     raeburn  1979:                              'id'   => "ID/Student number",
1.160     raeburn  1980:                              'mail' => "permanent e-mail",
1.134     raeburn  1981:                              'disk' => "disk space allocated to portfolio files",
1.73      sakharuk 1982:                              'prvs' => "Previous",
                   1983:                              'chto' => "Changed To"
                   1984: 						   );
1.201     raeburn  1985:                 $r->print('<h4>'.$lt{'uic'}.'</h4>'.
                   1986:                           &Apache::loncommon::start_data_table().
                   1987:                           &Apache::loncommon::start_data_table_header_row());
1.28      matthew  1988:                 $r->print(<<"END");
1.201     raeburn  1989:     <th>&nbsp;</th>
1.73      sakharuk 1990:     <th>$lt{'frst'}</th>
                   1991:     <th>$lt{'mddl'}</th>
                   1992:     <th>$lt{'lst'}</th>
1.134     raeburn  1993:     <th>$lt{'gen'}</th>
1.196     raeburn  1994:     <th>$lt{'id'}</th>
1.173     raeburn  1995:     <th>$lt{'mail'}</th>
1.201     raeburn  1996:     <th>$lt{'disk'}</th>
                   1997: END
                   1998:                 $r->print(&Apache::loncommon::end_data_table_header_row().
                   1999:                           &Apache::loncommon::start_data_table_row());
                   2000:                 $r->print(<<"END");
                   2001:     <td><b>$lt{'prvs'}</b></td>
1.28      matthew  2002:     <td>$userenv{'firstname'}  </td>
                   2003:     <td>$userenv{'middlename'} </td>
                   2004:     <td>$userenv{'lastname'}   </td>
1.134     raeburn  2005:     <td>$userenv{'generation'} </td>
1.196     raeburn  2006:     <td>$userenv{'id'}</td>
1.160     raeburn  2007:     <td>$userenv{'permanentemail'} </td>
1.204     raeburn  2008:     <td>$oldportfolioquota Mb $olddefquotatext </td>
1.201     raeburn  2009: END
                   2010:                 $r->print(&Apache::loncommon::end_data_table_row().
                   2011:                           &Apache::loncommon::start_data_table_row());
                   2012:                 $r->print(<<"END");
                   2013:     <td><b>$lt{'chto'}</b></td>
1.101     albertel 2014:     <td>$env{'form.cfirstname'}  </td>
                   2015:     <td>$env{'form.cmiddlename'} </td>
                   2016:     <td>$env{'form.clastname'}   </td>
1.134     raeburn  2017:     <td>$env{'form.cgeneration'} </td>
1.196     raeburn  2018:     <td>$env{'form.cid'} </td>
1.160     raeburn  2019:     <td>$env{'form.cpermanentemail'} </td>
1.204     raeburn  2020:     <td>$newportfolioquota Mb $newdefquotatext </td>
1.28      matthew  2021: END
1.201     raeburn  2022:                 $r->print(&Apache::loncommon::end_data_table_row().
1.206     raeburn  2023:                           &Apache::loncommon::end_data_table().'<br />');
1.203     raeburn  2024:                 if ($env{'form.cid'} ne $userenv{'id'}) {
                   2025:                     &Apache::lonnet::idput($env{'form.ccdomain'},
                   2026:                          ($env{'form.ccuname'} => $env{'form.cid'}));
                   2027:                     if (($recurseid) &&
                   2028:                         (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
1.213     raeburn  2029:                         %userupdate = (
1.196     raeburn  2030:                                   lastname   => $env{'form.clasaname'},
                   2031:                                   middlename => $env{'form.cmiddlename'},
                   2032:                                   firstname  => $env{'form.cfirstname'},
                   2033:                                   generation => $env{'fora.cgeneration'},
                   2034:                                   id         => $env{'form.cid'},
                   2035:                              );
1.203     raeburn  2036:                         my $idresult = 
                   2037:                             &Apache::lonuserutils::propagate_id_change(
                   2038:                                 $env{'form.ccuname'},$env{'form.ccdomain'},
                   2039:                                 \%userupdate);
                   2040:                         $r->print('<br />'.$idresult.'<br />');
                   2041:                     }
1.196     raeburn  2042:                 }
1.149     raeburn  2043:                 if (($env{'form.ccdomain'} eq $env{'user.domain'}) && 
                   2044:                     ($env{'form.ccuname'} eq $env{'user.name'})) {
                   2045:                     my %newenvhash;
                   2046:                     foreach my $key (keys(%changeHash)) {
                   2047:                         $newenvhash{'environment.'.$key} = $changeHash{$key};
                   2048:                     }
                   2049:                     &Apache::lonnet::appenv(%newenvhash);
                   2050:                 }
1.28      matthew  2051:             } else { # error occurred
1.188     raeburn  2052:                 $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
                   2053:                       $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206     raeburn  2054:                       $env{'form.ccdomain'}.'</span><br />');
1.28      matthew  2055:             }
1.101     albertel 2056:         }  else { # End of if ($env ... ) logic
1.204     raeburn  2057:             # They did not want to change the users name or quota but we can
                   2058:             # still tell them what the name and quota are 
1.73      sakharuk 2059: 	    my %lt=&Apache::lonlocal::texthash(
1.196     raeburn  2060:                            'id'   => "ID/Student number",
1.160     raeburn  2061:                            'mail' => "Permanent e-mail",
1.134     raeburn  2062:                            'disk' => "Disk space allocated to user's portfolio files",
1.73      sakharuk 2063: 					       );
1.134     raeburn  2064:             $r->print(<<"END");
1.196     raeburn  2065: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28      matthew  2066: END
1.204     raeburn  2067:             if ($userenv{'permanentemail'} ne '') {
                   2068:                 $r->print('<br />['.$lt{'mail'}.': '.
                   2069:                           $userenv{'permanentemail'}.']');
1.134     raeburn  2070:             }
1.204     raeburn  2071:             $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. 
                   2072:                  $olddefquotatext.']</h4>');
1.28      matthew  2073:         }
1.206     raeburn  2074:         if (@mod_disallowed) {
                   2075:             my ($rolestr,$contextname);
                   2076:             if (@longroles > 0) {
                   2077:                 $rolestr = join(', ',@longroles);
                   2078:             } else {
                   2079:                 $rolestr = &mt('No roles');
                   2080:             }
                   2081:             if ($context eq 'course') {
                   2082:                 $contextname = &mt('course');
                   2083:             } elsif ($context eq 'author') {
                   2084:                 $contextname = &mt('co-author');
                   2085:             }
                   2086:             $r->print(&mt('The following fields were not updated: ').'<ul>');
                   2087:             my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   2088:             foreach my $field (@mod_disallowed) {
                   2089:                 $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n"); 
                   2090:             }
1.207     raeburn  2091:             $r->print('</ul>');
                   2092:             if (@mod_disallowed == 1) {
                   2093:                 $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
                   2094:             } else {
                   2095:                 $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
                   2096:             }
                   2097:             $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
                   2098:                       &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206     raeburn  2099:         }
                   2100:         $r->print($no_forceid_alert.
                   2101:                   &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
1.4       www      2102:     }
1.27      matthew  2103:     ##
1.4       www      2104:     my $now=time;
1.193     raeburn  2105:     my $rolechanges = 0;
1.73      sakharuk 2106:     $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135     raeburn  2107:     foreach my $key (keys (%env)) {
                   2108: 	next if (! $env{$key});
1.190     raeburn  2109:         next if ($key eq 'form.action');
1.27      matthew  2110: 	# Revoke roles
1.135     raeburn  2111: 	if ($key=~/^form\.rev/) {
                   2112: 	    if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64      www      2113: # Revoke standard role
1.170     albertel 2114: 		my ($scope,$role) = ($1,$2);
                   2115: 		my $result =
                   2116: 		    &Apache::lonnet::revokerole($env{'form.ccdomain'},
                   2117: 						$env{'form.ccuname'},
                   2118: 						$scope,$role);
                   2119: 	        $r->print(&mt('Revoking [_1] in [_2]: [_3]',
                   2120: 			      $role,$scope,'<b>'.$result.'</b>').'<br />');
                   2121: 		if ($role eq 'st') {
1.202     raeburn  2122: 		    my $result = 
1.198     raeburn  2123:                         &Apache::lonuserutils::classlist_drop($scope,
                   2124:                             $env{'form.ccuname'},$env{'form.ccdomain'},
1.202     raeburn  2125: 			    $now);
1.170     albertel 2126: 		    $r->print($result);
1.53      www      2127: 		}
1.196     raeburn  2128: 	    }
1.195     raeburn  2129: 	    if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64      www      2130: # Revoke custom role
1.113     raeburn  2131: 		$r->print(&mt('Revoking custom role:').
1.139     albertel 2132:                       ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101     albertel 2133:                       &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
                   2134: 				  $env{'form.ccuname'},$1,$2,$3,$4).
1.102     albertel 2135: 		'</b><br />');
1.64      www      2136: 	    }
1.193     raeburn  2137:             $rolechanges ++;
1.135     raeburn  2138: 	} elsif ($key=~/^form\.del/) {
                   2139: 	    if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116     raeburn  2140: # Delete standard role
1.170     albertel 2141: 		my ($scope,$role) = ($1,$2);
                   2142: 		my $result =
                   2143: 		    &Apache::lonnet::assignrole($env{'form.ccdomain'},
                   2144: 						$env{'form.ccuname'},
                   2145: 						$scope,$role,$now,0,1);
                   2146: 	        $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
                   2147: 			      '<b>'.$result.'</b>').'<br />');
                   2148: 		if ($role eq 'st') {
1.202     raeburn  2149: 		    my $result = 
1.198     raeburn  2150:                         &Apache::lonuserutils::classlist_drop($scope,
                   2151:                             $env{'form.ccuname'},$env{'form.ccdomain'},
1.202     raeburn  2152: 			    $now);
1.170     albertel 2153: 		    $r->print($result);
1.81      albertel 2154: 		}
1.116     raeburn  2155:             }
1.139     albertel 2156: 	    if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116     raeburn  2157:                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
                   2158: # Delete custom role
1.170     albertel 2159:                 $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116     raeburn  2160:                       $rolename,$rnam,$rdom,$url).': <b>'.
                   2161:                       &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
                   2162:                          $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
                   2163:                          0,1).'</b><br />');
                   2164:             }
1.193     raeburn  2165:             $rolechanges ++;
1.135     raeburn  2166: 	} elsif ($key=~/^form\.ren/) {
1.101     albertel 2167:             my $udom = $env{'form.ccdomain'};
                   2168:             my $uname = $env{'form.ccuname'};
1.116     raeburn  2169: # Re-enable standard role
1.135     raeburn  2170: 	    if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89      raeburn  2171:                 my $url = $1;
                   2172:                 my $role = $2;
                   2173:                 my $logmsg;
                   2174:                 my $output;
                   2175:                 if ($role eq 'st') {
1.141     albertel 2176:                     if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129     albertel 2177:                         my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89      raeburn  2178:                         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
                   2179:                             $output = "Error: $result\n";
                   2180:                         } else {
                   2181:                             $output = &mt('Assigning').' '.$role.' in '.$url.
                   2182:                                       &mt('starting').' '.localtime($now).
                   2183:                                       ': <br />'.$logmsg.'<br />'.
                   2184:                                       &mt('Add to classlist').': <b>ok</b><br />';
                   2185:                         }
                   2186:                     }
                   2187:                 } else {
1.101     albertel 2188: 		    my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
                   2189:                                $env{'form.ccuname'},$url,$role,0,$now);
1.116     raeburn  2190: 		    $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89      raeburn  2191: 			      $role,$url,$result).'<br />';
1.27      matthew  2192: 		}
1.89      raeburn  2193:                 $r->print($output);
1.113     raeburn  2194: 	    }
1.116     raeburn  2195: # Re-enable custom role
1.139     albertel 2196: 	    if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116     raeburn  2197:                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
                   2198:                 my $result = &Apache::lonnet::assigncustomrole(
                   2199:                                $env{'form.ccdomain'}, $env{'form.ccuname'},
                   2200:                                $url,$rdom,$rnam,$rolename,0,$now);
                   2201:                 $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
                   2202:                           $rolename,$rnam,$rdom,$url,$result).'<br />');
                   2203:             }
1.193     raeburn  2204:             $rolechanges ++;
1.135     raeburn  2205: 	} elsif ($key=~/^form\.act/) {
1.101     albertel 2206:             my $udom = $env{'form.ccdomain'};
                   2207:             my $uname = $env{'form.ccuname'};
1.141     albertel 2208: 	    if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65      www      2209:                 # Activate a custom role
1.83      albertel 2210: 		my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
                   2211: 		my $url='/'.$one.'/'.$two;
                   2212: 		my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65      www      2213: 
1.101     albertel 2214:                 my $start = ( $env{'form.start_'.$full} ?
                   2215:                               $env{'form.start_'.$full} :
1.88      raeburn  2216:                               $now );
1.101     albertel 2217:                 my $end   = ( $env{'form.end_'.$full} ?
                   2218:                               $env{'form.end_'.$full} :
1.88      raeburn  2219:                               0 );
                   2220:                                                                                      
                   2221:                 # split multiple sections
                   2222:                 my %sections = ();
1.101     albertel 2223:                 my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88      raeburn  2224:                 if ($num_sections == 0) {
1.129     albertel 2225:                     $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88      raeburn  2226:                 } else {
1.114     albertel 2227: 		    my %curr_groups =
1.117     raeburn  2228: 			&Apache::longroup::coursegroups($one,$two);
1.113     raeburn  2229:                     foreach my $sec (sort {$a cmp $b} keys %sections) {
                   2230:                         if (($sec eq 'none') || ($sec eq 'all') || 
                   2231:                             exists($curr_groups{$sec})) {
                   2232:                             $disallowed{$sec} = $url;
                   2233:                             next;
                   2234:                         }
                   2235:                         my $securl = $url.'/'.$sec;
1.129     albertel 2236: 		        $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88      raeburn  2237:                     }
                   2238:                 }
1.142     raeburn  2239: 	    } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27      matthew  2240: 		# Activate roles for sections with 3 id numbers
                   2241: 		# set start, end times, and the url for the class
1.83      albertel 2242: 		my ($one,$two,$three)=($1,$2,$3);
1.101     albertel 2243: 		my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ? 
                   2244: 			      $env{'form.start_'.$one.'_'.$two.'_'.$three} : 
1.27      matthew  2245: 			      $now );
1.101     albertel 2246: 		my $end   = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ? 
                   2247: 			      $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27      matthew  2248: 			      0 );
1.83      albertel 2249: 		my $url='/'.$one.'/'.$two;
1.88      raeburn  2250:                 my $type = 'three';
                   2251:                 # split multiple sections
                   2252:                 my %sections = ();
1.101     albertel 2253:                 my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88      raeburn  2254:                 if ($num_sections == 0) {
1.129     albertel 2255:                     $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88      raeburn  2256:                 } else {
1.114     albertel 2257:                     my %curr_groups = 
1.117     raeburn  2258: 			&Apache::longroup::coursegroups($one,$two);
1.88      raeburn  2259:                     my $emptysec = 0;
                   2260:                     foreach my $sec (sort {$a cmp $b} keys %sections) {
                   2261:                         $sec =~ s/\W//g;
1.113     raeburn  2262:                         if ($sec ne '') {
                   2263:                             if (($sec eq 'none') || ($sec eq 'all') || 
                   2264:                                 exists($curr_groups{$sec})) {
                   2265:                                 $disallowed{$sec} = $url;
                   2266:                                 next;
                   2267:                             }
1.88      raeburn  2268:                             my $securl = $url.'/'.$sec;
1.129     albertel 2269:                             $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88      raeburn  2270:                         } else {
                   2271:                             $emptysec = 1;
                   2272:                         }
                   2273:                     }
                   2274:                     if ($emptysec) {
1.129     albertel 2275:                         $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88      raeburn  2276:                     }
                   2277:                 } 
1.135     raeburn  2278: 	    } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27      matthew  2279: 		# Activate roles for sections with two id numbers
                   2280: 		# set start, end times, and the url for the class
1.101     albertel 2281: 		my $start = ( $env{'form.start_'.$1.'_'.$2} ? 
                   2282: 			      $env{'form.start_'.$1.'_'.$2} : 
1.27      matthew  2283: 			      $now );
1.101     albertel 2284: 		my $end   = ( $env{'form.end_'.$1.'_'.$2} ? 
                   2285: 			      $env{'form.end_'.$1.'_'.$2} :
1.27      matthew  2286: 			      0 );
                   2287: 		my $url='/'.$1.'/';
1.88      raeburn  2288:                 # split multiple sections
                   2289:                 my %sections = ();
1.101     albertel 2290:                 my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88      raeburn  2291:                 if ($num_sections == 0) {
1.129     albertel 2292:                     $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88      raeburn  2293:                 } else {
                   2294:                     my $emptysec = 0;
                   2295:                     foreach my $sec (sort {$a cmp $b} keys %sections) {
                   2296:                         if ($sec ne '') {
                   2297:                             my $securl = $url.'/'.$sec;
1.129     albertel 2298:                             $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88      raeburn  2299:                         } else {
                   2300:                             $emptysec = 1;
                   2301:                         }
                   2302:                     }
                   2303:                     if ($emptysec) {
1.129     albertel 2304:                         $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88      raeburn  2305:                     }
                   2306:                 }
1.64      www      2307: 	    } else {
1.190     raeburn  2308: 		$r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64      www      2309:             }
1.113     raeburn  2310:             foreach my $key (sort(keys(%disallowed))) {
                   2311:                 if (($key eq 'none') || ($key eq 'all')) {  
                   2312:                     $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
                   2313:                 } else {
                   2314:                     $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key));
                   2315:                 }
                   2316:                 $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
                   2317:             }
1.193     raeburn  2318:             $rolechanges ++;
1.113     raeburn  2319: 	}
1.101     albertel 2320:     } # End of foreach (keys(%env))
1.75      www      2321: # Flush the course logs so reverse user roles immediately updated
                   2322:     &Apache::lonnet::flushcourselogs();
1.193     raeburn  2323:     if (!$rolechanges) {
                   2324:         $r->print(&mt('No roles to modify'));
                   2325:     }
1.188     raeburn  2326:     $r->print(&Apache::loncommon::end_page());
                   2327: }
                   2328: 
1.204     raeburn  2329: sub get_defaultquota_text {
                   2330:     my ($settingstatus) = @_;
                   2331:     my $defquotatext; 
                   2332:     if ($settingstatus eq '') {
                   2333:         $defquotatext = &mt('(default)');
                   2334:     } else {
                   2335:         my ($usertypes,$order) =
                   2336:             &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
                   2337:         if ($usertypes->{$settingstatus} eq '') {
                   2338:             $defquotatext = &mt('(default)');
                   2339:         } else {
                   2340:             $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
                   2341:         }
                   2342:     }
                   2343:     return $defquotatext;
                   2344: }
                   2345: 
1.188     raeburn  2346: sub update_result_form {
                   2347:     my ($uhome) = @_;
                   2348:     my $outcome = 
                   2349:     '<form name="userupdate" method="post" />'."\n";
1.160     raeburn  2350:     foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188     raeburn  2351:         $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160     raeburn  2352:     }
1.207     raeburn  2353:     if ($env{'form.origname'} ne '') {
                   2354:         $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
                   2355:     }
1.160     raeburn  2356:     foreach my $item ('sortby','seluname','seludom') {
                   2357:         if (exists($env{'form.'.$item})) {
1.188     raeburn  2358:             $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160     raeburn  2359:         }
                   2360:     }
1.188     raeburn  2361:     if ($uhome eq 'no_host') {
                   2362:         $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
                   2363:     }
                   2364:     $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
                   2365:                 '<input type ="hidden" name="currstate" value="" />'."\n".
1.190     raeburn  2366:                 '<input type ="hidden" name="action" value="singleuser" />'."\n".
1.188     raeburn  2367:                 '</form>';
                   2368:     return $outcome;
1.4       www      2369: }
                   2370: 
1.149     raeburn  2371: sub quota_admin {
                   2372:     my ($setquota,$changeHash) = @_;
                   2373:     my $quotachanged;
                   2374:     if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
                   2375:         # Current user has quota modification privileges
                   2376:         $quotachanged = 1;
                   2377:         $changeHash->{'portfolioquota'} = $setquota;
                   2378:     }
                   2379:     return $quotachanged;
                   2380: }
                   2381: 
1.88      raeburn  2382: sub build_roles {
1.89      raeburn  2383:     my ($sectionstr,$sections,$role) = @_;
1.88      raeburn  2384:     my $num_sections = 0;
                   2385:     if ($sectionstr=~ /,/) {
                   2386:         my @secnums = split/,/,$sectionstr;
1.89      raeburn  2387:         if ($role eq 'st') {
                   2388:             $secnums[0] =~ s/\W//g;
                   2389:             $$sections{$secnums[0]} = 1;
                   2390:             $num_sections = 1;
                   2391:         } else {
                   2392:             foreach my $sec (@secnums) {
                   2393:                 $sec =~ ~s/\W//g;
1.150     banghart 2394:                 if (!($sec eq "")) {
1.89      raeburn  2395:                     if (exists($$sections{$sec})) {
                   2396:                         $$sections{$sec} ++;
                   2397:                     } else {
                   2398:                         $$sections{$sec} = 1;
                   2399:                         $num_sections ++;
                   2400:                     }
1.88      raeburn  2401:                 }
                   2402:             }
                   2403:         }
                   2404:     } else {
                   2405:         $sectionstr=~s/\W//g;
                   2406:         unless ($sectionstr eq '') {
                   2407:             $$sections{$sectionstr} = 1;
                   2408:             $num_sections ++;
                   2409:         }
                   2410:     }
1.129     albertel 2411: 
1.88      raeburn  2412:     return $num_sections;
                   2413: }
                   2414: 
1.58      www      2415: # ========================================================== Custom Role Editor
                   2416: 
                   2417: sub custom_role_editor {
1.160     raeburn  2418:     my ($r) = @_;
1.101     albertel 2419:     my $rolename=$env{'form.rolename'};
1.58      www      2420: 
1.59      www      2421:     if ($rolename eq 'make new role') {
1.101     albertel 2422: 	$rolename=$env{'form.newrolename'};
1.59      www      2423:     }
                   2424: 
1.63      www      2425:     $rolename=~s/[^A-Za-z0-9]//gs;
1.58      www      2426: 
1.190     raeburn  2427:     if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58      www      2428: 	&print_username_entry_form($r);
                   2429:         return;
                   2430:     }
1.153     banghart 2431: # ------------------------------------------------------- What can be assigned?
                   2432:     my %full=();
                   2433:     my %courselevel=();
                   2434:     my %courselevelcurrent=();
1.61      www      2435:     my $syspriv='';
                   2436:     my $dompriv='';
                   2437:     my $coursepriv='';
1.153     banghart 2438:     my $body_top;
1.150     banghart 2439:     my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59      www      2440:     my ($rdummy,$roledef)=
                   2441: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60      www      2442: # ------------------------------------------------------- Does this role exist?
1.153     banghart 2443:     $body_top .= '<h2>';
1.59      www      2444:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153     banghart 2445: 	$body_top .= &mt('Existing Role').' "';
1.61      www      2446: # ------------------------------------------------- Get current role privileges
                   2447: 	($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59      www      2448:     } else {
1.153     banghart 2449: 	$body_top .= &mt('New Role').' "';
1.59      www      2450: 	$roledef='';
                   2451:     }
1.153     banghart 2452:     $body_top .= $rolename.'"</h2>';
1.135     raeburn  2453:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
                   2454: 	my ($priv,$restrict)=split(/\&/,$item);
1.150     banghart 2455:         if (!$restrict) { $restrict='F'; }
1.60      www      2456:         $courselevel{$priv}=$restrict;
1.61      www      2457:         if ($coursepriv=~/\:$priv/) {
                   2458: 	    $courselevelcurrent{$priv}=1;
                   2459: 	}
1.60      www      2460: 	$full{$priv}=1;
                   2461:     }
                   2462:     my %domainlevel=();
1.61      www      2463:     my %domainlevelcurrent=();
1.135     raeburn  2464:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
                   2465: 	my ($priv,$restrict)=split(/\&/,$item);
1.150     banghart 2466:         if (!$restrict) { $restrict='F'; }
1.60      www      2467:         $domainlevel{$priv}=$restrict;
1.61      www      2468:         if ($dompriv=~/\:$priv/) {
                   2469: 	    $domainlevelcurrent{$priv}=1;
                   2470: 	}
1.60      www      2471: 	$full{$priv}=1;
                   2472:     }
1.61      www      2473:     my %systemlevel=();
                   2474:     my %systemlevelcurrent=();
1.135     raeburn  2475:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
                   2476: 	my ($priv,$restrict)=split(/\&/,$item);
1.150     banghart 2477:         if (!$restrict) { $restrict='F'; }
1.61      www      2478:         $systemlevel{$priv}=$restrict;
                   2479:         if ($syspriv=~/\:$priv/) {
                   2480: 	    $systemlevelcurrent{$priv}=1;
                   2481: 	}
                   2482: 	$full{$priv}=1;
                   2483:     }
1.160     raeburn  2484:     my ($jsback,$elements) = &crumb_utilities();
1.154     banghart 2485:     my $button_code = "\n";
1.153     banghart 2486:     my $head_script = "\n";
                   2487:     $head_script .= '<script type="text/javascript">'."\n";
1.154     banghart 2488:     my @template_roles = ("cc","in","ta","ep","st");
                   2489:     foreach my $role (@template_roles) {
                   2490:         $head_script .= &make_script_template($role);
                   2491:         $button_code .= &make_button_code($role);
                   2492:     }
1.160     raeburn  2493:     $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153     banghart 2494:     $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160     raeburn  2495:    &Apache::lonhtmlcommon::add_breadcrumb
1.190     raeburn  2496:      ({href=>"javascript:backPage(document.form1,'pickrole','')",
                   2497:        text=>"Pick custom role",
1.160     raeburn  2498:        faq=>282,bug=>'Instructor Interface',},
                   2499:       {href=>"javascript:backPage(document.form1,'','')",
                   2500:          text=>"Edit custom role",
                   2501:          faq=>282,bug=>'Instructor Interface',});
                   2502:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
                   2503: 
1.153     banghart 2504:     $r->print($body_top);
1.73      sakharuk 2505:     my %lt=&Apache::lonlocal::texthash(
                   2506: 		    'prv'  => "Privilege",
1.131     raeburn  2507: 		    'crl'  => "Course Level",
1.73      sakharuk 2508:                     'dml'  => "Domain Level",
1.150     banghart 2509:                     'ssl'  => "System Level");
1.152     banghart 2510:     $r->print('Select a Template<br />');
1.154     banghart 2511:     $r->print('<form action="">');
                   2512:     $r->print($button_code);
                   2513:     $r->print('</form>');
1.61      www      2514:     $r->print(<<ENDCCF);
1.160     raeburn  2515: <form name="form1" method="post">
1.61      www      2516: <input type="hidden" name="phase" value="set_custom_roles" />
                   2517: <input type="hidden" name="rolename" value="$rolename" />
                   2518: ENDCCF
1.135     raeburn  2519:     $r->print(&Apache::loncommon::start_data_table().
                   2520:               &Apache::loncommon::start_data_table_header_row(). 
                   2521: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
                   2522: '</th><th>'.$lt{'ssl'}.'</th>'.
                   2523:               &Apache::loncommon::end_data_table_header_row());
1.119     raeburn  2524:     foreach my $priv (sort keys %full) {
                   2525:         my $privtext = &Apache::lonnet::plaintext($priv);
1.135     raeburn  2526:         $r->print(&Apache::loncommon::start_data_table_row().
                   2527: 	          '<td>'.$privtext.'</td><td>'.
1.150     banghart 2528:     ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119     raeburn  2529:     ($courselevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
1.61      www      2530:     '</td><td>'.
1.150     banghart 2531:     ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119     raeburn  2532:     ($domainlevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
1.61      www      2533:     '</td><td>'.
1.150     banghart 2534:     ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119     raeburn  2535:     ($systemlevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
1.135     raeburn  2536:     '</td>'.
                   2537:              &Apache::loncommon::end_data_table_row());
1.60      www      2538:     }
1.135     raeburn  2539:     $r->print(&Apache::loncommon::end_data_table().
1.190     raeburn  2540:    '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160     raeburn  2541:    '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179     raeburn  2542:    '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".   
1.160     raeburn  2543:    '<input type="reset" value="'.&mt("Reset").'" />'."\n".
                   2544:    '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110     albertel 2545: 	      &Apache::loncommon::end_page());
1.61      www      2546: }
1.153     banghart 2547: # --------------------------------------------------------
                   2548: sub make_script_template {
                   2549:     my ($role) = @_;
                   2550:     my %full_c=();
                   2551:     my %full_d=();
                   2552:     my %full_s=();
                   2553:     my $return_script;
                   2554:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
                   2555:         my ($priv,$restrict)=split(/\&/,$item);
                   2556:         $full_c{$priv}=1;
                   2557:     }
                   2558:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
                   2559:         my ($priv,$restrict)=split(/\&/,$item);
                   2560:         $full_d{$priv}=1;
                   2561:     }
1.154     banghart 2562:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153     banghart 2563:         my ($priv,$restrict)=split(/\&/,$item);
                   2564:         $full_s{$priv}=1;
                   2565:     }
                   2566:     $return_script .= 'function set_'.$role.'() {'."\n";
                   2567:     my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
                   2568:     my %role_c;
1.155     banghart 2569:     foreach my $priv (@temp) {
1.153     banghart 2570:         my ($priv_item, $dummy) = split(/\&/,$priv);
                   2571:         $role_c{$priv_item} = 1;
                   2572:     }
                   2573:     foreach my $priv_item (keys(%full_c)) {
                   2574:         my ($priv, $dummy) = split(/\&/,$priv_item);
                   2575:         if (exists($role_c{$priv})) {
                   2576:             $return_script .= "document.form1.$priv"."_c.checked = true;\n";
                   2577:         } else {
                   2578:             $return_script .= "document.form1.$priv"."_c.checked = false;\n";
                   2579:         }
                   2580:     }
1.154     banghart 2581:     my %role_d;
                   2582:     @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
                   2583:     foreach my $priv(@temp) {
                   2584:         my ($priv_item, $dummy) = split(/\&/,$priv);
                   2585:         $role_d{$priv_item} = 1;
                   2586:     }
                   2587:     foreach my $priv_item (keys(%full_d)) {
                   2588:         my ($priv, $dummy) = split(/\&/,$priv_item);
                   2589:         if (exists($role_d{$priv})) {
                   2590:             $return_script .= "document.form1.$priv"."_d.checked = true;\n";
                   2591:         } else {
                   2592:             $return_script .= "document.form1.$priv"."_d.checked = false;\n";
                   2593:         }
                   2594:     }
                   2595:     my %role_s;
                   2596:     @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
                   2597:     foreach my $priv(@temp) {
                   2598:         my ($priv_item, $dummy) = split(/\&/,$priv);
                   2599:         $role_s{$priv_item} = 1;
                   2600:     }
                   2601:     foreach my $priv_item (keys(%full_s)) {
1.153     banghart 2602:         my ($priv, $dummy) = split(/\&/,$priv_item);
1.154     banghart 2603:         if (exists($role_s{$priv})) {
                   2604:             $return_script .= "document.form1.$priv"."_s.checked = true;\n";
                   2605:         } else {
                   2606:             $return_script .= "document.form1.$priv"."_s.checked = false;\n";
                   2607:         }
1.153     banghart 2608:     }
                   2609:     $return_script .= '}'."\n";
1.154     banghart 2610:     return ($return_script);
                   2611: }
                   2612: # ----------------------------------------------------------
                   2613: sub make_button_code {
                   2614:     my ($role) = @_;
                   2615:     my $label = &Apache::lonnet::plaintext($role);
                   2616:     my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';    
                   2617:     return ($button_code);
1.153     banghart 2618: }
1.61      www      2619: # ---------------------------------------------------------- Call to definerole
                   2620: sub set_custom_role {
1.110     albertel 2621:     my ($r) = @_;
1.101     albertel 2622:     my $rolename=$env{'form.rolename'};
1.63      www      2623:     $rolename=~s/[^A-Za-z0-9]//gs;
1.150     banghart 2624:     if (!$rolename) {
1.190     raeburn  2625: 	&custom_role_editor($r);
1.61      www      2626:         return;
                   2627:     }
1.160     raeburn  2628:     my ($jsback,$elements) = &crumb_utilities();
                   2629:     my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
                   2630: 
                   2631:     $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
                   2632:     &Apache::lonhtmlcommon::add_breadcrumb
1.190     raeburn  2633:         ({href=>"javascript:backPage(document.customresult,'pickrole','')",
                   2634:           text=>"Pick custom role",
1.160     raeburn  2635:           faq=>282,bug=>'Instructor Interface',},
                   2636:          {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
                   2637:           text=>"Edit custom role",
                   2638:           faq=>282,bug=>'Instructor Interface',},
                   2639:          {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
                   2640:           text=>"Result",
                   2641:           faq=>282,bug=>'Instructor Interface',});
                   2642:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
                   2643: 
1.61      www      2644:     my ($rdummy,$roledef)=
1.110     albertel 2645: 	&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
                   2646: 
1.61      www      2647: # ------------------------------------------------------- Does this role exist?
1.188     raeburn  2648:     $r->print('<h3>');
1.61      www      2649:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73      sakharuk 2650: 	$r->print(&mt('Existing Role').' "');
1.61      www      2651:     } else {
1.73      sakharuk 2652: 	$r->print(&mt('New Role').' "');
1.61      www      2653: 	$roledef='';
                   2654:     }
1.188     raeburn  2655:     $r->print($rolename.'"</h3>');
1.61      www      2656: # ------------------------------------------------------- What can be assigned?
                   2657:     my $sysrole='';
                   2658:     my $domrole='';
                   2659:     my $courole='';
                   2660: 
1.135     raeburn  2661:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
                   2662: 	my ($priv,$restrict)=split(/\&/,$item);
1.150     banghart 2663:         if (!$restrict) { $restrict=''; }
                   2664:         if ($env{'form.'.$priv.'_c'}) {
1.135     raeburn  2665: 	    $courole.=':'.$item;
1.61      www      2666: 	}
                   2667:     }
                   2668: 
1.135     raeburn  2669:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
                   2670: 	my ($priv,$restrict)=split(/\&/,$item);
1.150     banghart 2671:         if (!$restrict) { $restrict=''; }
                   2672:         if ($env{'form.'.$priv.'_d'}) {
1.135     raeburn  2673: 	    $domrole.=':'.$item;
1.61      www      2674: 	}
                   2675:     }
                   2676: 
1.135     raeburn  2677:     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
                   2678: 	my ($priv,$restrict)=split(/\&/,$item);
1.150     banghart 2679:         if (!$restrict) { $restrict=''; }
                   2680:         if ($env{'form.'.$priv.'_s'}) {
1.135     raeburn  2681: 	    $sysrole.=':'.$item;
1.61      www      2682: 	}
                   2683:     }
1.63      www      2684:     $r->print('<br />Defining Role: '.
1.61      www      2685: 	   &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101     albertel 2686:     if ($env{'request.course.id'}) {
                   2687:         my $url='/'.$env{'request.course.id'};
1.63      www      2688:         $url=~s/\_/\//g;
1.73      sakharuk 2689: 	$r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101     albertel 2690: 	      &Apache::lonnet::assigncustomrole($env{'user.domain'},
                   2691: 						$env{'user.name'},
1.63      www      2692: 						$url,
1.101     albertel 2693: 						$env{'user.domain'},
                   2694: 						$env{'user.name'},
1.63      www      2695: 						$rolename));
                   2696:     }
1.190     raeburn  2697:     $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160     raeburn  2698:     $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110     albertel 2699:     $r->print(&Apache::loncommon::end_page());
1.58      www      2700: }
                   2701: 
1.2       www      2702: # ================================================================ Main Handler
                   2703: sub handler {
                   2704:     my $r = shift;
                   2705:     if ($r->header_only) {
1.68      www      2706:        &Apache::loncommon::content_type($r,'text/html');
1.2       www      2707:        $r->send_http_header;
                   2708:        return OK;
                   2709:     }
1.190     raeburn  2710:     my $context;
                   2711:     if ($env{'request.course.id'}) {
                   2712:         $context = 'course';
                   2713:     } elsif ($env{'request.role'} =~ /^au\./) {
1.206     raeburn  2714:         $context = 'author';
1.190     raeburn  2715:     } else {
                   2716:         $context = 'domain';
                   2717:     }
                   2718:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.202     raeburn  2719:         ['action','state','callingform','roletype','showrole','bulkaction']);
1.190     raeburn  2720:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202     raeburn  2721:     if ($env{'form.action'} ne 'dateselect') {
                   2722:         &Apache::lonhtmlcommon::add_breadcrumb
                   2723:             ({href=>"/adm/createuser",
                   2724:               text=>"User Management"});
                   2725:     }
1.209     raeburn  2726:     my ($permission,$allowed) = 
                   2727:         &Apache::lonuserutils::get_permission($context);
1.190     raeburn  2728:     if (!$allowed) {
                   2729:         $env{'user.error.msg'}=
                   2730:             "/adm/createuser:cst:0:0:Cannot create/modify user data ".
                   2731:                                  "or view user status.";
                   2732:         return HTTP_NOT_ACCEPTABLE;
                   2733:     }
                   2734: 
                   2735:     &Apache::loncommon::content_type($r,'text/html');
                   2736:     $r->send_http_header;
                   2737: 
                   2738:     # Main switch on form.action and form.state, as appropriate
                   2739:     if (! exists($env{'form.action'})) {
                   2740:         $r->print(&header());
                   2741:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208     raeburn  2742:         $r->print(&print_main_menu($permission,$context));
1.190     raeburn  2743:         $r->print(&Apache::loncommon::end_page());
                   2744:     } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
                   2745:         $r->print(&header());
                   2746:         &Apache::lonhtmlcommon::add_breadcrumb
                   2747:             ({href=>'/adm/createuser?action=upload&state=',
                   2748:               text=>"Upload Users List"});
                   2749:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
                   2750:                                                    'User_Management_Upload'));
                   2751:         $r->print('<form name="studentform" method="post" '.
                   2752:                   'enctype="multipart/form-data" '.
                   2753:                   ' action="/adm/createuser">'."\n");
                   2754:         if (! exists($env{'form.state'})) {
                   2755:             &Apache::lonuserutils::print_first_users_upload_form($r,$context);
                   2756:         } elsif ($env{'form.state'} eq 'got_file') {
                   2757:             &Apache::lonuserutils::print_upload_manager_form($r,$context);
                   2758:         } elsif ($env{'form.state'} eq 'enrolling') {
                   2759:             if ($env{'form.datatoken'}) {
                   2760:                 &Apache::lonuserutils::upfile_drop_add($r,$context);
                   2761:             }
                   2762:         } else {
                   2763:             &Apache::lonuserutils::print_first_users_upload_form($r,$context);
                   2764:         }
                   2765:         $r->print('</form>'.&Apache::loncommon::end_page());
1.213     raeburn  2766:     } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
                   2767:              eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190     raeburn  2768:         my $phase = $env{'form.phase'};
                   2769:         my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192     albertel 2770: 	&Apache::loncreateuser::restore_prev_selections();
                   2771: 	my $srch;
                   2772: 	foreach my $item (@search) {
                   2773: 	    $srch->{$item} = $env{'form.'.$item};
                   2774: 	}
1.190     raeburn  2775: 
1.207     raeburn  2776:         if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
                   2777:             ($phase eq 'createnewuser')) {
                   2778:             if ($env{'form.phase'} eq 'createnewuser') {
                   2779:                 my $response;
                   2780:                 if ($env{'form.srchterm'} !~ /^$match_username$/) {
                   2781:                     my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
                   2782:                     &print_username_entry_form($r,$context,$response,$srch);
                   2783:                 } else {
                   2784:                     my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
                   2785:                     my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
                   2786:                     &print_user_modification_page($r,$ccuname,$ccdomain,
                   2787:                                                   $srch,$response,$context);
                   2788:                 }
                   2789:             } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190     raeburn  2790:                 my ($currstate,$response,$forcenewuser,$results) = 
                   2791:                     &user_search_result($srch);
                   2792:                 if ($env{'form.currstate'} eq 'modify') {
                   2793:                     $currstate = $env{'form.currstate'};
                   2794:                 }
                   2795:                 if ($currstate eq 'select') {
1.214     raeburn  2796:                     my $operation; 
                   2797:                     if ($env{'form.action'} eq 'singleuser') {
                   2798:                         $operation = 'createuser';
                   2799:                     } elsif ($env{'form.action'} eq 'singlestudent') {
                   2800:                         $operation = 'enrollstudent';
                   2801:                     }
1.190     raeburn  2802:                     &print_user_selection_page($r,$response,$srch,$results,
1.214     raeburn  2803:                                                $operation,\@search,$context);
1.190     raeburn  2804:                 } elsif ($currstate eq 'modify') {
                   2805:                     my ($ccuname,$ccdomain);
                   2806:                     if (($srch->{'srchby'} eq 'uname') && 
                   2807:                         ($srch->{'srchtype'} eq 'exact')) {
                   2808:                         $ccuname = $srch->{'srchterm'};
                   2809:                         $ccdomain= $srch->{'srchdomain'};
                   2810:                     } else {
                   2811:                         my @matchedunames = keys(%{$results});
                   2812:                         ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
                   2813:                     }
                   2814:                     $ccuname =&LONCAPA::clean_username($ccuname);
                   2815:                     $ccdomain=&LONCAPA::clean_domain($ccdomain);
                   2816:                     if ($env{'form.forcenewuser'}) {
                   2817:                         $response = '';
                   2818:                     }
                   2819:                     &print_user_modification_page($r,$ccuname,$ccdomain,
1.196     raeburn  2820:                                                   $srch,$response,$context);
1.190     raeburn  2821:                 } elsif ($currstate eq 'query') {
                   2822:                     &print_user_query_page($r,'createuser');
                   2823:                 } else {
1.207     raeburn  2824:                     &print_username_entry_form($r,$context,$response,$srch,
1.190     raeburn  2825:                                                $forcenewuser);
                   2826:                 }
                   2827:             } elsif ($env{'form.phase'} eq 'userpicked') {
                   2828:                 my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
                   2829:                 my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196     raeburn  2830:                 &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
                   2831:                                               $context);
1.190     raeburn  2832:             }
                   2833:         } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206     raeburn  2834:             &update_user_data($r,$context);
1.190     raeburn  2835:         } else {
1.207     raeburn  2836:             &print_username_entry_form($r,$context,undef,$srch);
1.190     raeburn  2837:         }
                   2838:     } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
                   2839:         if ($env{'form.phase'} eq 'set_custom_roles') {
                   2840:             &set_custom_role($r);
                   2841:         } else {
                   2842:             &custom_role_editor($r);
                   2843:         }
1.207     raeburn  2844:     } elsif (($env{'form.action'} eq 'listusers') && 
                   2845:              ($permission->{'view'} || $permission->{'cusr'})) {
1.202     raeburn  2846:         if ($env{'form.phase'} eq 'bulkchange') {
                   2847:             &Apache::lonhtmlcommon::add_breadcrumb
                   2848:                 ({href=>'backPage(document.studentform)',
                   2849:                   text=>"List Users"});
                   2850:             my $setting = $env{'form.roletype'};
                   2851:             my $choice = $env{'form.bulkaction'};
                   2852:             $r->print(&header());
                   2853:             $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
                   2854:                                                           'User_Management_List'));
                   2855:             if ($permission->{'cusr'}) {
                   2856:                 &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
                   2857:             }
                   2858:         } else {
                   2859:             &Apache::lonhtmlcommon::add_breadcrumb
                   2860:                 ({href=>'/adm/createuser?action=listusers',
                   2861:                   text=>"List Users"});
                   2862:             my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
                   2863:             my $formname = 'studentform';
                   2864:             if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
                   2865:                 ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) = 
                   2866:                     &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
                   2867:                                                             $formname);
                   2868:                 $jscript .= &verify_user_display();
                   2869:                 my $js = &add_script($jscript).$cb_jscript;
                   2870:                 my $loadcode = 
                   2871:                     &Apache::lonuserutils::course_selector_loadcode($formname);
                   2872:                 if ($loadcode ne '') {
                   2873:                     $r->print(&header($js,{'onload' => $loadcode,}));
                   2874:                 } else {
                   2875:                     $r->print(&header($js));
                   2876:                 }
1.191     raeburn  2877:             } else {
1.202     raeburn  2878:                 $r->print(&header(&add_script(&verify_user_display())));
1.191     raeburn  2879:             }
1.202     raeburn  2880:             $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
                   2881:                                                           'User_Management_List'));
                   2882:             &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
                   2883:                          $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
                   2884:             $r->print(&Apache::loncommon::end_page());
1.191     raeburn  2885:         }
1.213     raeburn  2886:     } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
                   2887:         $r->print(&header());
                   2888:         &Apache::lonhtmlcommon::add_breadcrumb
                   2889:             ({href=>'/adm/createuser?action=drop',
                   2890:               text=>"Drop Students"});
                   2891:         if (!exists($env{'form.state'})) {
                   2892:             $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
                   2893:                                                           'Course_Drop_Student'));
                   2894: 
                   2895:             &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
                   2896:         } elsif ($env{'form.state'} eq 'done') {
                   2897:             &Apache::lonhtmlcommon::add_breadcrumb
                   2898:             ({href=>'/adm/createuser?action=drop',
                   2899:               text=>"Result"});
                   2900:             $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
                   2901:                                                           'Course_Drop_Student'));
                   2902:             &Apache::lonuserutils::update_user_list($r,$context,undef,
                   2903:                                                     $env{'form.action'});
                   2904:         }
                   2905:         $r->print(&Apache::loncommon::end_page());
1.202     raeburn  2906:     } elsif ($env{'form.action'} eq 'dateselect') {
                   2907:         if ($permission->{'cusr'}) {
                   2908:             $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
                   2909:                       &Apache::lonuserutils::date_section_selector($context).
                   2910:                       &Apache::loncommon::end_page());
                   2911:         } else {
                   2912:             $r->print(&header().
                   2913:                      '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'. 
                   2914:                      &Apache::loncommon::end_page());
                   2915:         }
1.190     raeburn  2916:     } else {
                   2917:         $r->print(&header());
1.202     raeburn  2918:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207     raeburn  2919:         $r->print(&print_main_menu($permission,$context));
1.190     raeburn  2920:         $r->print(&Apache::loncommon::end_page());
                   2921:     }
                   2922:     return OK;
                   2923: }
                   2924: 
                   2925: sub header {
1.202     raeburn  2926:     my ($jscript,$loaditems,$args) = @_;
1.190     raeburn  2927:     my $start_page;
                   2928:     if (ref($loaditems) eq 'HASH') {
1.202     raeburn  2929:         $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190     raeburn  2930:     } else {
1.202     raeburn  2931:         $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190     raeburn  2932:     }
                   2933:     return $start_page;
                   2934: }
1.2       www      2935: 
1.191     raeburn  2936: sub add_script {
                   2937:     my ($js) = @_;
                   2938:     return '<script type="text/javascript">'."\n".$js."\n".'</script>';
                   2939: }
                   2940: 
1.202     raeburn  2941: sub verify_user_display {
                   2942:     my $output = <<"END";
                   2943: 
                   2944: function display_update() {
                   2945:     document.studentform.action.value = 'listusers';
                   2946:     document.studentform.phase.value = 'display';
                   2947:     document.studentform.submit();
                   2948: }
                   2949: 
                   2950: END
                   2951:     return $output;
                   2952: 
                   2953: }
                   2954: 
1.190     raeburn  2955: ###############################################################
                   2956: ###############################################################
                   2957: #  Menu Phase One
                   2958: sub print_main_menu {
1.208     raeburn  2959:     my ($permission,$context) = @_;
                   2960:     my %links = (
                   2961:                        domain => {
                   2962:                                    upload => 'Upload a File of Users',
                   2963:                                    singleuser => 'Add/Manage a Single User',
                   2964:                                    listusers => 'Manage Multiple Users',
                   2965:                                  },
                   2966:                        author => {
                   2967:                                    upload => 'Upload a File of Co-authors',
                   2968:                                    singleuser => 'Add/Manage a Single Co-author',
                   2969:                                    listusers => 'Display Co-authors and Manage Multiple Users',
                   2970:                                  },
                   2971:                        course => {
                   2972:                                    upload => 'Upload a File of Course Users',
                   2973:                                    singleuser => 'Add/Manage a Single Course User',
                   2974:                                    listusers => 'Display Class Lists and Manage Multiple Users',
                   2975:                                  },
                   2976:                      );
1.190     raeburn  2977:     my @menu =
                   2978:         (
1.208     raeburn  2979:           { text => $links{$context}{'upload'},
1.190     raeburn  2980:             help => 'User_Management_Upload',
                   2981:             action => 'upload',
                   2982:             permission => $permission->{'cusr'},
                   2983:             },
1.208     raeburn  2984:           { text => $links{$context}{'singleuser'}, 
1.190     raeburn  2985:             help => 'User_Management_Single_User',
                   2986:             action => 'singleuser',
                   2987:             permission => $permission->{'cusr'},
                   2988:             },
1.208     raeburn  2989:           { text => $links{$context}{'listusers'},
1.191     raeburn  2990:             help => 'User_Management_List',
                   2991:             action => 'listusers',
1.208     raeburn  2992:             permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190     raeburn  2993:           },
                   2994:         );
1.208     raeburn  2995:     if ($context eq 'domain' || $context eq 'course') {
                   2996:         my $customlink =  { text => 'Edit Custom Roles',
                   2997:                             help => 'Custom_Role_Edit',
                   2998:                             action => 'custom',
                   2999:                             permission => $permission->{'custom'},
                   3000:                           };
                   3001:         push(@menu,$customlink);
                   3002:     }
                   3003:     if ($context eq 'course') {
1.213     raeburn  3004:         my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
                   3005:         my @courselinks =
1.208     raeburn  3006:             (
1.213     raeburn  3007:               { text => 'Enroll a Single Student',
                   3008:                  help => 'Course_Single_Student',
                   3009:                  action => 'singlestudent',
                   3010:                  permission => $permission->{'cusr'},
                   3011:                  },
                   3012:               { text => 'Drop Students',
                   3013:                 help => 'Course_Drop_Student',
                   3014:                 action => 'drop',
                   3015:                 permission => $permission->{'cusr'},
                   3016:               });
                   3017:         if (!exists($permission->{'cusr_section'})) {
                   3018:             push(@courselinks,
                   3019:                { text => 'Automated Student Enrollment Manager',
1.208     raeburn  3020:                  permission => (&Apache::lonnet::auto_run($cnum,$cdom)
                   3021:                                 && $permission->{'cusr'}),
                   3022:                  url  => '/adm/populate',
1.213     raeburn  3023:                  });
                   3024:         }
                   3025:         push(@courselinks,
1.208     raeburn  3026:                { text => 'Manage Course Groups',
                   3027:                  help => 'Course_Manage_Group',
                   3028:                  permission => $permission->{'grp_manage'},
                   3029:                  url => '/adm/coursegroups?refpage=cusr',
1.213     raeburn  3030:                });
1.208     raeburn  3031:         push(@menu,@courselinks);
                   3032:     }
1.190     raeburn  3033:     my $menu_html = '';
                   3034:     foreach my $menu_item (@menu) {
                   3035:         next if (! $menu_item->{'permission'});
                   3036:         $menu_html.='<p>';
                   3037:         $menu_html.='<font size="+1">';
                   3038:         if (exists($menu_item->{'url'})) {
                   3039:             $menu_html.=qq{<a href="$menu_item->{'url'}">};
                   3040:         } else {
                   3041:             $menu_html.=
                   3042:                 qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
                   3043:         }
                   3044:         $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
                   3045:         if (exists($menu_item->{'help'})) {
                   3046:             $menu_html.=
                   3047:                 &Apache::loncommon::help_open_topic($menu_item->{'help'});
                   3048:         }
                   3049:         $menu_html.='</p>';
                   3050:     }
                   3051:     return $menu_html;
                   3052: }
                   3053: 
1.189     albertel 3054: sub restore_prev_selections {
                   3055:     my %saveable_parameters = ('srchby'   => 'scalar',
                   3056: 			       'srchin'   => 'scalar',
                   3057: 			       'srchtype' => 'scalar',
                   3058: 			       );
                   3059:     &Apache::loncommon::store_settings('user','user_picker',
                   3060: 				       \%saveable_parameters);
                   3061:     &Apache::loncommon::restore_settings('user','user_picker',
                   3062: 					 \%saveable_parameters);
                   3063: }
                   3064: 
1.27      matthew  3065: #-------------------------------------------------- functions for &phase_two
1.160     raeburn  3066: sub user_search_result {
                   3067:     my ($srch) = @_;
                   3068:     my %allhomes;
                   3069:     my %inst_matches;
                   3070:     my %srch_results;
1.181     raeburn  3071:     my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183     raeburn  3072:     $srch->{'srchterm'} =~ s/\s+/ /g;
1.176     raeburn  3073:     if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160     raeburn  3074:         $response = &mt('Invalid search.');
                   3075:     }
                   3076:     if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
                   3077:         $response = &mt('Invalid search.');
                   3078:     }
1.177     raeburn  3079:     if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160     raeburn  3080:         $response = &mt('Invalid search.');
                   3081:     }
                   3082:     if ($srch->{'srchterm'} eq '') {
                   3083:         $response = &mt('You must enter a search term.');
                   3084:     }
1.183     raeburn  3085:     if ($srch->{'srchterm'} =~ /^\s+$/) {
                   3086:         $response = &mt('Your search term must contain more than just spaces.');
                   3087:     }
1.160     raeburn  3088:     if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
                   3089:         if (($srch->{'srchdomain'} eq '') || 
1.163     albertel 3090: 	    ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160     raeburn  3091:             $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
                   3092:         }
                   3093:     }
                   3094:     if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
                   3095:         ($srch->{'srchin'} eq 'alc')) {
1.176     raeburn  3096:         if ($srch->{'srchby'} eq 'uname') {
                   3097:             if ($srch->{'srchterm'} !~ /^$match_username$/) {
                   3098:                 $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
                   3099:             }
1.160     raeburn  3100:         }
                   3101:     }
1.180     raeburn  3102:     if ($response ne '') {
                   3103:         $response = '<span class="LC_warning">'.$response.'</span>';
                   3104:     }
1.160     raeburn  3105:     if ($srch->{'srchin'} eq 'instd') {
                   3106:         my $instd_chk = &directorysrch_check($srch);
                   3107:         if ($instd_chk ne 'ok') {
1.180     raeburn  3108:             $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
                   3109:                         '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160     raeburn  3110:         }
                   3111:     }
                   3112:     if ($response ne '') {
1.180     raeburn  3113:         return ($currstate,$response);
1.160     raeburn  3114:     }
                   3115:     if ($srch->{'srchby'} eq 'uname') {
                   3116:         if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
                   3117:             if ($env{'form.forcenew'}) {
                   3118:                 if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
                   3119:                     my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
                   3120:                     if ($uhome eq 'no_host') {
                   3121:                         my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180     raeburn  3122:                         my $showdom = &display_domain_info($env{'request.role.domain'});
                   3123:                         $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160     raeburn  3124:                     } else {
1.179     raeburn  3125:                         $currstate = 'modify';
1.160     raeburn  3126:                     }
                   3127:                 } else {
1.179     raeburn  3128:                     $currstate = 'modify';
1.160     raeburn  3129:                 }
                   3130:             } else {
                   3131:                 if ($srch->{'srchin'} eq 'dom') {
1.162     raeburn  3132:                     if ($srch->{'srchtype'} eq 'exact') {
                   3133:                         my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
                   3134:                         if ($uhome eq 'no_host') {
1.179     raeburn  3135:                             ($currstate,$response,$forcenewuser) =
1.162     raeburn  3136:                                 &build_search_response($srch,%srch_results);
                   3137:                         } else {
1.179     raeburn  3138:                             $currstate = 'modify';
1.162     raeburn  3139:                         }
                   3140:                     } else {
                   3141:                         %srch_results = &Apache::lonnet::usersearch($srch);
1.179     raeburn  3142:                         ($currstate,$response,$forcenewuser) =
1.160     raeburn  3143:                             &build_search_response($srch,%srch_results);
                   3144:                     }
                   3145:                 } else {
1.167     albertel 3146:                     my $courseusers = &get_courseusers();
1.162     raeburn  3147:                     if ($srch->{'srchtype'} eq 'exact') {
1.167     albertel 3148:                         if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179     raeburn  3149:                             $currstate = 'modify';
1.162     raeburn  3150:                         } else {
1.179     raeburn  3151:                             ($currstate,$response,$forcenewuser) =
1.162     raeburn  3152:                                 &build_search_response($srch,%srch_results);
                   3153:                         }
1.160     raeburn  3154:                     } else {
1.167     albertel 3155:                         foreach my $user (keys(%$courseusers)) {
1.162     raeburn  3156:                             my ($cuname,$cudomain) = split(/:/,$user);
                   3157:                             if ($cudomain eq $srch->{'srchdomain'}) {
1.177     raeburn  3158:                                 my $matched = 0;
                   3159:                                 if ($srch->{'srchtype'} eq 'begins') {
                   3160:                                     if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
                   3161:                                         $matched = 1;
                   3162:                                     }
                   3163:                                 } else {
                   3164:                                     if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
                   3165:                                         $matched = 1;
                   3166:                                     }
                   3167:                                 }
                   3168:                                 if ($matched) {
1.167     albertel 3169:                                     $srch_results{$user} = 
                   3170: 					{&Apache::lonnet::get('environment',
                   3171: 							     ['firstname',
                   3172: 							      'lastname',
1.194     albertel 3173: 							      'permanentemail'],
                   3174: 							      $cudomain,$cuname)};
1.162     raeburn  3175:                                 }
                   3176:                             }
                   3177:                         }
1.179     raeburn  3178:                         ($currstate,$response,$forcenewuser) =
1.160     raeburn  3179:                             &build_search_response($srch,%srch_results);
                   3180:                     }
                   3181:                 }
                   3182:             }
                   3183:         } elsif ($srch->{'srchin'} eq 'alc') {
1.179     raeburn  3184:             $currstate = 'query';
1.160     raeburn  3185:         } elsif ($srch->{'srchin'} eq 'instd') {
1.181     raeburn  3186:             ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
                   3187:             if ($dirsrchres eq 'ok') {
                   3188:                 ($currstate,$response,$forcenewuser) = 
                   3189:                     &build_search_response($srch,%srch_results);
                   3190:             } else {
                   3191:                 my $showdom = &display_domain_info($srch->{'srchdomain'});
                   3192:                 $response = '<span class="LC_warning">'.
                   3193:                     &mt('Institutional directory search is not available in domain: [_1]',$showdom).
                   3194:                     '</span><br />'.
                   3195:                     &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
                   3196:                     '<br /><br />'; 
                   3197:             }
1.160     raeburn  3198:         }
                   3199:     } else {
                   3200:         if ($srch->{'srchin'} eq 'dom') {
                   3201:             %srch_results = &Apache::lonnet::usersearch($srch);
1.179     raeburn  3202:             ($currstate,$response,$forcenewuser) = 
1.160     raeburn  3203:                 &build_search_response($srch,%srch_results); 
                   3204:         } elsif ($srch->{'srchin'} eq 'crs') {
1.167     albertel 3205:             my $courseusers = &get_courseusers(); 
                   3206:             foreach my $user (keys(%$courseusers)) {
1.160     raeburn  3207:                 my ($uname,$udom) = split(/:/,$user);
                   3208:                 my %names = &Apache::loncommon::getnames($uname,$udom);
                   3209:                 my %emails = &Apache::loncommon::getemails($uname,$udom);
                   3210:                 if ($srch->{'srchby'} eq 'lastname') {
                   3211:                     if ((($srch->{'srchtype'} eq 'exact') && 
                   3212:                          ($names{'lastname'} eq $srch->{'srchterm'})) || 
1.177     raeburn  3213:                         (($srch->{'srchtype'} eq 'begins') &&
                   3214:                          ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160     raeburn  3215:                         (($srch->{'srchtype'} eq 'contains') &&
                   3216:                          ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
                   3217:                         $srch_results{$user} = {firstname => $names{'firstname'},
                   3218:                                             lastname => $names{'lastname'},
                   3219:                                             permanentemail => $emails{'permanentemail'},
                   3220:                                            };
                   3221:                     }
                   3222:                 } elsif ($srch->{'srchby'} eq 'lastfirst') {
                   3223:                     my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177     raeburn  3224:                     $srchlast =~ s/\s+$//;
                   3225:                     $srchfirst =~ s/^\s+//;
1.160     raeburn  3226:                     if ($srch->{'srchtype'} eq 'exact') {
                   3227:                         if (($names{'lastname'} eq $srchlast) &&
                   3228:                             ($names{'firstname'} eq $srchfirst)) {
                   3229:                             $srch_results{$user} = {firstname => $names{'firstname'},
                   3230:                                                 lastname => $names{'lastname'},
                   3231:                                                 permanentemail => $emails{'permanentemail'},
                   3232: 
                   3233:                                            };
                   3234:                         }
1.177     raeburn  3235:                     } elsif ($srch->{'srchtype'} eq 'begins') {
                   3236:                         if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
                   3237:                             ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
                   3238:                             $srch_results{$user} = {firstname => $names{'firstname'},
                   3239:                                                 lastname => $names{'lastname'},
                   3240:                                                 permanentemail => $emails{'permanentemail'},
                   3241:                                                };
                   3242:                         }
                   3243:                     } else {
1.160     raeburn  3244:                         if (($names{'lastname'} =~ /\Q$srchlast\E/i) && 
                   3245:                             ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
                   3246:                             $srch_results{$user} = {firstname => $names{'firstname'},
                   3247:                                                 lastname => $names{'lastname'},
                   3248:                                                 permanentemail => $emails{'permanentemail'},
                   3249:                                                };
                   3250:                         }
                   3251:                     }
                   3252:                 }
                   3253:             }
1.179     raeburn  3254:             ($currstate,$response,$forcenewuser) = 
1.160     raeburn  3255:                 &build_search_response($srch,%srch_results); 
                   3256:         } elsif ($srch->{'srchin'} eq 'alc') {
1.179     raeburn  3257:             $currstate = 'query';
1.160     raeburn  3258:         } elsif ($srch->{'srchin'} eq 'instd') {
1.181     raeburn  3259:             ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch); 
                   3260:             if ($dirsrchres eq 'ok') {
                   3261:                 ($currstate,$response,$forcenewuser) = 
                   3262:                     &build_search_response($srch,%srch_results);
                   3263:             } else {
                   3264:                 my $showdom = &display_domain_info($srch->{'srchdomain'});                $response = '<span class="LC_warning">'.
                   3265:                     &mt('Institutional directory search is not available in domain: [_1]',$showdom).
                   3266:                     '</span><br />'.
                   3267:                     &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
                   3268:                     '<br /><br />';
                   3269:             }
1.160     raeburn  3270:         }
                   3271:     }
1.179     raeburn  3272:     return ($currstate,$response,$forcenewuser,\%srch_results);
1.160     raeburn  3273: }
                   3274: 
                   3275: sub directorysrch_check {
                   3276:     my ($srch) = @_;
                   3277:     my $can_search = 0;
                   3278:     my $response;
                   3279:     my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
                   3280:                                              ['directorysrch'],$srch->{'srchdomain'});
1.180     raeburn  3281:     my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160     raeburn  3282:     if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
                   3283:         if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180     raeburn  3284:             return &mt('Institutional directory search is not available in domain: [_1]',$showdom); 
1.160     raeburn  3285:         }
                   3286:         if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
                   3287:             if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180     raeburn  3288:                 return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom); 
1.160     raeburn  3289:             }
                   3290:             my @usertypes = split(/:/,$env{'environment.inststatus'});
                   3291:             if (!@usertypes) {
                   3292:                 push(@usertypes,'default');
                   3293:             }
                   3294:             if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
                   3295:                 foreach my $type (@usertypes) {
                   3296:                     if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
                   3297:                         $can_search = 1;
                   3298:                         last;
                   3299:                     }
                   3300:                 }
                   3301:             }
                   3302:             if (!$can_search) {
                   3303:                 my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
                   3304:                 my @longtypes; 
                   3305:                 foreach my $item (@usertypes) {
                   3306:                     push (@longtypes,$insttypes->{$item});
                   3307:                 }
                   3308:                 my $insttype_str = join(', ',@longtypes); 
1.180     raeburn  3309:                 return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.160     raeburn  3310:             } 
                   3311:         } else {
                   3312:             $can_search = 1;
                   3313:         }
                   3314:     } else {
1.180     raeburn  3315:         return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160     raeburn  3316:     }
                   3317:     my %longtext = &Apache::lonlocal::texthash (
1.167     albertel 3318:                        uname     => 'username',
1.160     raeburn  3319:                        lastfirst => 'last name, first name',
1.167     albertel 3320:                        lastname  => 'last name',
1.172     raeburn  3321:                        contains  => 'contains',
1.178     raeburn  3322:                        exact     => 'as exact match to',
                   3323:                        begins    => 'begins with',
1.160     raeburn  3324:                    );
                   3325:     if ($can_search) {
                   3326:         if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
                   3327:             if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180     raeburn  3328:                 return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160     raeburn  3329:             }
                   3330:         } else {
1.180     raeburn  3331:             return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160     raeburn  3332:         }
                   3333:     }
                   3334:     if ($can_search) {
1.178     raeburn  3335:         if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
                   3336:             if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
                   3337:                 return 'ok';
                   3338:             } else {
1.180     raeburn  3339:                 return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178     raeburn  3340:             }
                   3341:         } else {
                   3342:             if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
                   3343:                  ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
                   3344:                 ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
                   3345:                 return 'ok';
                   3346:             } else {
1.180     raeburn  3347:                 return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178     raeburn  3348:             }
1.160     raeburn  3349:         }
                   3350:     }
                   3351: }
                   3352: 
                   3353: sub get_courseusers {
                   3354:     my %advhash;
1.167     albertel 3355:     my $classlist = &Apache::loncoursedata::get_classlist();
1.160     raeburn  3356:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
                   3357:     foreach my $role (sort(keys(%coursepersonnel))) {
                   3358:         foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167     albertel 3359: 	    if (!exists($classlist->{$user})) {
                   3360: 		$classlist->{$user} = [];
                   3361: 	    }
1.160     raeburn  3362:         }
                   3363:     }
1.167     albertel 3364:     return $classlist;
1.160     raeburn  3365: }
                   3366: 
                   3367: sub build_search_response {
                   3368:     my ($srch,%srch_results) = @_;
1.179     raeburn  3369:     my ($currstate,$response,$forcenewuser);
1.160     raeburn  3370:     my %names = (
                   3371:           'uname' => 'username',
                   3372:           'lastname' => 'last name',
                   3373:           'lastfirst' => 'last name, first name',
                   3374:           'crs' => 'this course',
1.180     raeburn  3375:           'dom' => 'LON-CAPA domain: ',
                   3376:           'instd' => 'the institutional directory for domain: ',
1.160     raeburn  3377:     );
                   3378: 
                   3379:     my %single = (
1.180     raeburn  3380:                    begins   => 'A match',
1.160     raeburn  3381:                    contains => 'A match',
1.180     raeburn  3382:                    exact    => 'An exact match',
1.160     raeburn  3383:                  );
                   3384:     my %nomatch = (
1.180     raeburn  3385:                    begins   => 'No match',
1.160     raeburn  3386:                    contains => 'No match',
1.180     raeburn  3387:                    exact    => 'No exact match',
1.160     raeburn  3388:                   );
                   3389:     if (keys(%srch_results) > 1) {
1.179     raeburn  3390:         $currstate = 'select';
1.160     raeburn  3391:     } else {
                   3392:         if (keys(%srch_results) == 1) {
1.179     raeburn  3393:             $currstate = 'modify';
1.180     raeburn  3394:             $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
                   3395:             if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
                   3396:                 $response .= &display_domain_info($srch->{'srchdomain'});
                   3397:             }
1.160     raeburn  3398:         } else {
1.180     raeburn  3399:             $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
                   3400:             if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
                   3401:                 $response .= &display_domain_info($srch->{'srchdomain'});
                   3402:             }
                   3403:             $response .= '</span>';
1.160     raeburn  3404:             if ($srch->{'srchin'} ne 'alc') {
                   3405:                 $forcenewuser = 1;
                   3406:                 my $cansrchinst = 0; 
                   3407:                 if ($srch->{'srchdomain'}) {
                   3408:                     my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
                   3409:                     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   3410:                         if ($domconfig{'directorysrch'}{'available'}) {
                   3411:                             $cansrchinst = 1;
                   3412:                         } 
                   3413:                     }
                   3414:                 }
1.180     raeburn  3415:                 if ((($srch->{'srchby'} eq 'lastfirst') || 
                   3416:                      ($srch->{'srchby'} eq 'lastname')) &&
                   3417:                     ($srch->{'srchin'} eq 'dom')) {
                   3418:                     if ($cansrchinst) {
                   3419:                         $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160     raeburn  3420:                     }
                   3421:                 }
1.180     raeburn  3422:                 if ($srch->{'srchin'} eq 'crs') {
                   3423:                     $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
                   3424:                 }
                   3425:             }
                   3426:             if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.182     raeburn  3427:                 my $showdom = &display_domain_info($env{'request.role.domain'}); 
                   3428:                 $response .= '<br /><br />'.&mt("<b>To add a new user</b> (you can only create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>):",$env{'request.role.domain'}).'<ul><li>'.&mt("Set 'Domain/institution to search' to: <span class=\"LC_cusr_emph\">[_1]</span>",$showdom).'<li>'.&mt("Set 'Search criteria' to: <span class=\"LC_cusr_emph\">'username is ...... in selected LON-CAPA domain'").'</span></li><li>'.&mt('Provide the proposed username').'</li><li>'.&mt('Search').'</li></ul><br />';
1.160     raeburn  3429:             }
                   3430:         }
                   3431:     }
1.179     raeburn  3432:     return ($currstate,$response,$forcenewuser);
1.160     raeburn  3433: }
                   3434: 
1.180     raeburn  3435: sub display_domain_info {
                   3436:     my ($dom) = @_;
                   3437:     my $output = $dom;
                   3438:     if ($dom ne '') { 
                   3439:         my $domdesc = &Apache::lonnet::domain($dom,'description');
                   3440:         if ($domdesc ne '') {
                   3441:             $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
                   3442:         }
                   3443:     }
                   3444:     return $output;
                   3445: }
                   3446: 
1.160     raeburn  3447: sub crumb_utilities {
                   3448:     my %elements = (
                   3449:        crtuser => {
                   3450:            srchterm => 'text',
1.172     raeburn  3451:            srchin => 'selectbox',
1.160     raeburn  3452:            srchby => 'selectbox',
                   3453:            srchtype => 'selectbox',
                   3454:            srchdomain => 'selectbox',
                   3455:        },
1.207     raeburn  3456:        crtusername => {
                   3457:            srchterm => 'text',
                   3458:            srchdomain => 'selectbox',
                   3459:        },
1.160     raeburn  3460:        docustom => {
                   3461:            rolename => 'selectbox',
                   3462:            newrolename => 'textbox',
                   3463:        },
1.179     raeburn  3464:        studentform => {
                   3465:            srchterm => 'text',
                   3466:            srchin => 'selectbox',
                   3467:            srchby => 'selectbox',
                   3468:            srchtype => 'selectbox',
                   3469:            srchdomain => 'selectbox',
                   3470:        },
1.160     raeburn  3471:     );
                   3472: 
                   3473:     my $jsback .= qq|
                   3474: function backPage(formname,prevphase,prevstate) {
1.211     raeburn  3475:     if (typeof prevphase == 'undefined') {
                   3476:         formname.phase.value = '';
                   3477:     }
                   3478:     else {  
                   3479:         formname.phase.value = prevphase;
                   3480:     }
                   3481:     if (typeof prevstate == 'undefined') {
                   3482:         formname.currstate.value = '';
                   3483:     }
                   3484:     else {
                   3485:         formname.currstate.value = prevstate;
                   3486:     }
1.160     raeburn  3487:     formname.submit();
                   3488: }
                   3489: |;
                   3490:     return ($jsback,\%elements);
                   3491: }
                   3492: 
1.26      matthew  3493: sub course_level_table {
1.89      raeburn  3494:     my (%inccourses) = @_;
1.26      matthew  3495:     my $table = '';
1.62      www      3496: # Custom Roles?
                   3497: 
1.190     raeburn  3498:     my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89      raeburn  3499:     my %lt=&Apache::lonlocal::texthash(
                   3500:             'exs'  => "Existing sections",
                   3501:             'new'  => "Define new section",
                   3502:             'ssd'  => "Set Start Date",
                   3503:             'sed'  => "Set End Date",
1.131     raeburn  3504:             'crl'  => "Course Level",
1.89      raeburn  3505:             'act'  => "Activate",
                   3506:             'rol'  => "Role",
                   3507:             'ext'  => "Extent",
1.113     raeburn  3508:             'grs'  => "Section",
1.89      raeburn  3509:             'sta'  => "Start",
                   3510:             'end'  => "End"
                   3511:     );
1.62      www      3512: 
1.135     raeburn  3513:     foreach my $protectedcourse (sort( keys(%inccourses))) {
                   3514: 	my $thiscourse=$protectedcourse;
1.26      matthew  3515: 	$thiscourse=~s:_:/:g;
                   3516: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
                   3517: 	my $area=$coursedata{'description'};
1.119     raeburn  3518:         my $type=$coursedata{'type'};
1.135     raeburn  3519: 	if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89      raeburn  3520: 	my ($domain,$cnum)=split(/\//,$thiscourse);
1.115     albertel 3521:         my %sections_count;
1.101     albertel 3522:         if (defined($env{'request.course.id'})) {
                   3523:             if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115     albertel 3524:                 %sections_count = 
                   3525: 		    &Apache::loncommon::get_sections($domain,$cnum);
1.92      raeburn  3526:             }
                   3527:         }
1.213     raeburn  3528:         my @roles = &Apache::lonuserutils::roles_by_context('course');
                   3529: 	foreach my $role (@roles) {
1.135     raeburn  3530: 	    if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
                   3531: 		my $plrole=&Apache::lonnet::plaintext($role);
1.136     raeburn  3532: 		$table .= &Apache::loncommon::start_data_table_row().
1.157     albertel 3533: '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
1.136     raeburn  3534: <td>'.$plrole.'</td>
                   3535: <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.135     raeburn  3536: 	        if ($role ne 'cc') {
1.115     albertel 3537:                     if (%sections_count) {
1.202     raeburn  3538:                         my $currsec = 
1.198     raeburn  3539:                             &Apache::lonuserutils::course_sections(\%sections_count,
1.202     raeburn  3540:                                                         $protectedcourse.'_'.$role);
1.89      raeburn  3541:                         $table .= 
1.137     raeburn  3542:                     '<td><table class="LC_createuser">'.
                   3543:                      '<tr class="LC_section_row">
                   3544:                         <td valign="top">'.$lt{'exs'}.'<br />'.
1.89      raeburn  3545:                         $currsec.'</td>'.
                   3546:                      '<td>&nbsp;&nbsp;</td>'.
                   3547:                      '<td valign="top">&nbsp;'.$lt{'new'}.'<br />'.
1.157     albertel 3548:                      '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
1.89      raeburn  3549:                      '<input type="hidden" '.
1.157     albertel 3550:                      'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
1.89      raeburn  3551:                      '</tr></table></td>';
                   3552:                     } else {
                   3553:                         $table .= '<td><input type="text" size="10" '.
1.157     albertel 3554:                      'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
1.89      raeburn  3555:                     }
1.26      matthew  3556:                 } else { 
1.89      raeburn  3557: 		    $table .= '<td>&nbsp</td>';
1.26      matthew  3558:                 }
                   3559: 		$table .= <<ENDTIMEENTRY;
1.169     albertel 3560: <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
1.26      matthew  3561: <a href=
1.135     raeburn  3562: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169     albertel 3563: <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
1.26      matthew  3564: <a href=
1.135     raeburn  3565: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26      matthew  3566: ENDTIMEENTRY
1.136     raeburn  3567:                 $table.= &Apache::loncommon::end_data_table_row();
1.26      matthew  3568:             }
                   3569:         }
1.135     raeburn  3570:         foreach my $cust (sort keys %customroles) {
1.65      www      3571: 	    if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.135     raeburn  3572: 		my $plrole=$cust;
1.101     albertel 3573:                 my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
                   3574: 		    '_'.$env{'user.name'}.'_'.$plrole;
1.136     raeburn  3575: 		$table .= &Apache::loncommon::start_data_table_row().
1.157     albertel 3576: '<td><input type="checkbox" name="act_'.$customrole.'" /></td>
1.136     raeburn  3577: <td>'.$plrole.'</td>
                   3578: <td>'.$area.'</td>'."\n";
1.115     albertel 3579:                 if (%sections_count) {
1.202     raeburn  3580:                     my $currsec = 
1.198     raeburn  3581:                         &Apache::lonuserutils::course_sections(\%sections_count,
                   3582:                                                                $customrole);
1.89      raeburn  3583:                     $table.=
1.188     raeburn  3584:                    '<td><table class="LC_createuser">'.
                   3585:                    '<tr class="LC_section_row"><td valign="top">'.
                   3586:                    $lt{'exs'}.'<br />'.$currsec.'</td>'.
1.89      raeburn  3587:                    '<td>&nbsp;&nbsp;</td>'.
                   3588:                    '<td valign="top">&nbsp;'.$lt{'new'}.'<br />'.
                   3589:                    '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
                   3590:                    '<input type="hidden" '.
1.157     albertel 3591:                    'name="sec_'.$customrole.'" /></td>'.
1.89      raeburn  3592:                    '</tr></table></td>';
                   3593:                 } else {
                   3594:                     $table .= '<td><input type="text" size="10" '.
1.157     albertel 3595:                      'name="sec_'.$customrole.'" /></td>';
1.89      raeburn  3596:                 }
                   3597:                 $table .= <<ENDENTRY;
1.169     albertel 3598: <td><input type="hidden" name="start_$customrole" value='' />
1.62      www      3599: <a href=
1.73      sakharuk 3600: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169     albertel 3601: <td><input type="hidden" name="end_$customrole" value='' />
1.62      www      3602: <a href=
1.136     raeburn  3603: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
1.62      www      3604: ENDENTRY
1.136     raeburn  3605:                $table .= &Apache::loncommon::end_data_table_row();
1.65      www      3606:            }
1.62      www      3607: 	}
1.26      matthew  3608:     }
                   3609:     return '' if ($table eq ''); # return nothing if there is nothing 
                   3610:                                  # in the table
1.188     raeburn  3611:     my $result;
                   3612:     if (!$env{'request.course.id'}) {
                   3613:         $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
                   3614:     }
                   3615:     $result .= 
1.136     raeburn  3616: &Apache::loncommon::start_data_table().
                   3617: &Apache::loncommon::start_data_table_header_row().
                   3618: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
                   3619: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
                   3620: &Apache::loncommon::end_data_table_header_row().
                   3621: $table.
                   3622: &Apache::loncommon::end_data_table();
1.26      matthew  3623:     return $result;
                   3624: }
1.88      raeburn  3625: 
                   3626: sub course_level_dc {
                   3627:     my ($dcdom) = @_;
1.190     raeburn  3628:     my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213     raeburn  3629:     my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88      raeburn  3630:     my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
                   3631:                       '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133     raeburn  3632:                       '<input type="hidden" name="dccourse" value="" />';
1.88      raeburn  3633:     my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131     raeburn  3634:             ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
                   3635:     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88      raeburn  3636:     my %lt=&Apache::lonlocal::texthash(
                   3637:                     'rol'  => "Role",
1.113     raeburn  3638:                     'grs'  => "Section",
1.88      raeburn  3639:                     'exs'  => "Existing sections",
                   3640:                     'new'  => "Define new section", 
                   3641:                     'sta'  => "Start",
                   3642:                     'end'  => "End",
                   3643:                     'ssd'  => "Set Start Date",
                   3644:                     'sed'  => "Set End Date"
                   3645:                   );
1.131     raeburn  3646:     my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136     raeburn  3647:                  &Apache::loncommon::start_data_table().
                   3648:                  &Apache::loncommon::start_data_table_header_row().
1.143     raeburn  3649:                  '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136     raeburn  3650:                  &Apache::loncommon::end_data_table_header_row();
1.143     raeburn  3651:     my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131     raeburn  3652:                      '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88      raeburn  3653:                      '<td><select name="role">'."\n";
1.213     raeburn  3654:     foreach my $role (@roles) {
1.135     raeburn  3655:         my $plrole=&Apache::lonnet::plaintext($role);
                   3656:         $otheritems .= '  <option value="'.$role.'">'.$plrole;
1.88      raeburn  3657:     }
                   3658:     if ( keys %customroles > 0) {
1.135     raeburn  3659:         foreach my $cust (sort keys %customroles) {
1.101     albertel 3660:             my $custrole='cr_cr_'.$env{'user.domain'}.
1.135     raeburn  3661:                     '_'.$env{'user.name'}.'_'.$cust;
                   3662:             $otheritems .= '  <option value="'.$custrole.'">'.$cust;
1.88      raeburn  3663:         }
                   3664:     }
                   3665:     $otheritems .= '</select></td><td>'.
                   3666:                      '<table border="0" cellspacing="0" cellpadding="0">'.
                   3667:                      '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
                   3668:                      ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
                   3669:                      '<td>&nbsp;&nbsp;</td>'.
                   3670:                      '<td valign="top">&nbsp;<b>'.$lt{'new'}.'</b><br />'.
1.113     raeburn  3671:                      '<input type="text" name="newsec" value="" />'.
                   3672:                      '<input type="hidden" name="groups" value="" /></td>'.
1.88      raeburn  3673:                      '</tr></table></td>';
                   3674:     $otheritems .= <<ENDTIMEENTRY;
1.169     albertel 3675: <td><input type="hidden" name="start" value='' />
1.88      raeburn  3676: <a href=
                   3677: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169     albertel 3678: <td><input type="hidden" name="end" value='' />
1.88      raeburn  3679: <a href=
                   3680: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
                   3681: ENDTIMEENTRY
1.136     raeburn  3682:     $otheritems .= &Apache::loncommon::end_data_table_row().
                   3683:                    &Apache::loncommon::end_data_table()."\n";
1.88      raeburn  3684:     return $cb_jscript.$header.$hiddenitems.$otheritems;
                   3685: }
                   3686: 
1.27      matthew  3687: #---------------------------------------------- end functions for &phase_two
1.29      matthew  3688: 
                   3689: #--------------------------------- functions for &phase_two and &phase_three
                   3690: 
                   3691: #--------------------------end of functions for &phase_two and &phase_three
1.1       www      3692: 
                   3693: 1;
                   3694: __END__
1.2       www      3695: 
                   3696: 

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