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

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

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