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