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