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