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