Annotation of loncom/interface/loncreateuser.pm, revision 1.218
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.218 ! raeburn 4: # $Id: loncreateuser.pm,v 1.217 2007/12/21 15:33:32 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.206 raeburn 1400: my ($output,$showforceid,%userenv,%domconfig);
1.188 raeburn 1401: if (!$newuser) {
1402: # Get the users information
1403: %userenv = &Apache::lonnet::get('environment',
1404: ['firstname','middlename','lastname','generation',
1405: 'permanentemail','id'],$ccdomain,$ccuname);
1.206 raeburn 1406: %domconfig =
1407: &Apache::lonnet::get_dom('configuration',['usermodification'],
1408: $ccdomain);
1.188 raeburn 1409: }
1410: my %lt=&Apache::lonlocal::texthash(
1411: 'pd' => "Personal Data",
1412: 'firstname' => "First Name",
1413: 'middlename' => "Middle Name",
1414: 'lastname' => "Last Name",
1415: 'generation' => "Generation",
1416: 'permanentemail' => "Permanent e-mail address",
1417: 'id' => "ID/Student Number",
1418: 'lg' => "Login Data"
1419: );
1420: my @userinfo = ('firstname','middlename','lastname','generation',
1421: 'permanentemail','id');
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.206 raeburn 1450: my $canmodify = 0;
1.188 raeburn 1451: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.206 raeburn 1452: $canmodify = 1;
1453: } else {
1454: if (ref($domconfig{'usermodification'}) eq 'HASH') {
1455: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
1456: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
1457: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
1458: if ($domconfig{'usermodification'}{$context}{$key}{$item}) {
1459: $canmodify = 1;
1460: last;
1461: }
1462: }
1463: }
1464: }
1465: } elsif ($context eq 'course') {
1466: $canmodify = 1;
1467: }
1468: }
1469: if ($canmodify) {
1.188 raeburn 1470: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1471: } else {
1472: $output .= $userenv{$item};
1473: }
1.206 raeburn 1474: if ($item eq 'id') {
1475: $showforceid = $canmodify;
1476: }
1.188 raeburn 1477: }
1478: $output .= &Apache::lonhtmlcommon::row_closure(1);
1479: }
1480: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1481: if (wantarray) {
1482: return ($output,$showforceid);
1483: } else {
1484: return $output;
1485: }
1.188 raeburn 1486: }
1487:
1.4 www 1488: # ================================================================= Phase Three
1.42 matthew 1489: sub update_user_data {
1.206 raeburn 1490: my ($r,$context) = @_;
1.101 albertel 1491: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1492: $env{'form.ccdomain'});
1.27 matthew 1493: # Error messages
1.188 raeburn 1494: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1495: my $end = '</span><br /><br />';
1496: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1497: "'$env{'form.prevphase'}','modify')".'" />'.
1498: &mt('Return to previous page').'</a>'.&Apache::loncommon::end_page();
1.40 www 1499: my $title;
1.101 albertel 1500: if (exists($env{'form.makeuser'})) {
1.40 www 1501: $title='Set Privileges for New User';
1502: } else {
1503: $title='Modify User Privileges';
1504: }
1.213 raeburn 1505: my $newuser = 0;
1.160 raeburn 1506: my ($jsback,$elements) = &crumb_utilities();
1507: my $jscript = '<script type="text/javascript">'."\n".
1508: $jsback."\n".'</script>'."\n";
1.213 raeburn 1509: my %breadcrumb_text = &singleuser_breadcrumb();
1.160 raeburn 1510: $r->print(&Apache::loncommon::start_page($title,$jscript));
1511: &Apache::lonhtmlcommon::add_breadcrumb
1512: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1513: text=>$breadcrumb_text{'search'},
1.160 raeburn 1514: faq=>282,bug=>'Instructor Interface',});
1515: if ($env{'form.prevphase'} eq 'userpicked') {
1516: &Apache::lonhtmlcommon::add_breadcrumb
1517: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1518: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1519: faq=>282,bug=>'Instructor Interface',});
1520: }
1521: &Apache::lonhtmlcommon::add_breadcrumb
1522: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1523: text=>"Set user role",
1524: faq=>282,bug=>'Instructor Interface',},
1525: {href=>"/adm/createuser",
1526: text=>"Result",
1527: faq=>282,bug=>'Instructor Interface',});
1528: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1529:
1.113 raeburn 1530: my %disallowed;
1.188 raeburn 1531: $r->print(&update_result_form($uhome));
1.27 matthew 1532: # Check Inputs
1.101 albertel 1533: if (! $env{'form.ccuname'} ) {
1.193 raeburn 1534: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 1535: return;
1536: }
1.138 albertel 1537: if ( $env{'form.ccuname'} ne
1538: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1539: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1540: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193 raeburn 1541: $end.$rtnlink);
1.27 matthew 1542: return;
1543: }
1.101 albertel 1544: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 1545: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 1546: return;
1547: }
1.138 albertel 1548: if ( $env{'form.ccdomain'} ne
1549: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1550: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1551: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193 raeburn 1552: $end.$rtnlink);
1.27 matthew 1553: return;
1554: }
1.101 albertel 1555: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1556: # Modifying an existing user, so check the validity of the name
1557: if ($uhome eq 'no_host') {
1.73 sakharuk 1558: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1559: $env{'form.ccuname'}.&mt(' in domain ').
1560: $env{'form.ccdomain'}.'.');
1.29 matthew 1561: return;
1562: }
1563: }
1.27 matthew 1564: # Determine authentication method and password for the user being modified
1565: my $amode='';
1566: my $genpwd='';
1.101 albertel 1567: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1568: $amode='krb';
1.101 albertel 1569: $amode.=$env{'form.krbver'};
1570: $genpwd=$env{'form.krbarg'};
1571: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1572: $amode='internal';
1.101 albertel 1573: $genpwd=$env{'form.intarg'};
1574: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1575: $amode='unix';
1.101 albertel 1576: $genpwd=$env{'form.fsysarg'};
1577: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1578: $amode='localauth';
1.101 albertel 1579: $genpwd=$env{'form.locarg'};
1.27 matthew 1580: $genpwd=" " if (!$genpwd);
1.101 albertel 1581: } elsif (($env{'form.login'} eq 'nochange') ||
1582: ($env{'form.login'} eq '' )) {
1.34 matthew 1583: # There is no need to tell the user we did not change what they
1584: # did not ask us to change.
1.35 matthew 1585: # If they are creating a new user but have not specified login
1586: # information this will be caught below.
1.30 matthew 1587: } else {
1.193 raeburn 1588: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 1589: return;
1.27 matthew 1590: }
1.164 albertel 1591:
1592:
1.188 raeburn 1593: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1594: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 1595: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.101 albertel 1596: if ($env{'form.makeuser'}) {
1.164 albertel 1597: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1598: # Check for the authentication mode and password
1599: if (! $amode || ! $genpwd) {
1.193 raeburn 1600: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 1601: return;
1.18 albertel 1602: }
1.29 matthew 1603: # Determine desired host
1.101 albertel 1604: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1605: if (lc($desiredhost) eq 'default') {
1606: $desiredhost = undef;
1607: } else {
1.147 albertel 1608: my %home_servers =
1609: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1610: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 1611: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
1612: return;
1613: }
1614: }
1615: # Check ID format
1616: my %checkhash;
1617: my %checks = ('id' => 1);
1618: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.196 raeburn 1619: 'newuser' => 1,
1620: 'id' => $env{'form.cid'},
1.193 raeburn 1621: );
1.196 raeburn 1622: if ($env{'form.cid'} ne '') {
1623: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1624: \%rulematch,\%inst_results,\%curr_rules);
1625: if (ref($alerts{'id'}) eq 'HASH') {
1626: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1627: my $domdesc =
1628: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
1629: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
1630: my $userchkmsg;
1631: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
1632: $userchkmsg =
1633: &Apache::loncommon::instrule_disallow_msg('id',
1634: $domdesc,1).
1635: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
1636: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
1637: }
1638: $r->print($error.&mt('Invalid ID format').$end.
1639: $userchkmsg.$rtnlink);
1640: return;
1641: }
1642: }
1.29 matthew 1643: }
1644: }
1.27 matthew 1645: # Call modifyuser
1646: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 1647: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 1648: $amode,$genpwd,$env{'form.cfirstname'},
1649: $env{'form.cmiddlename'},$env{'form.clastname'},
1650: $env{'form.cgeneration'},undef,$desiredhost,
1651: $env{'form.cpermanentemail'});
1.77 www 1652: $r->print(&mt('Generating user').': '.$result);
1.101 albertel 1653: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1654: $env{'form.ccdomain'});
1.77 www 1655: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.148 albertel 1656: &Apache::lonnet::hostname($home));
1.101 albertel 1657: } elsif (($env{'form.login'} ne 'nochange') &&
1658: ($env{'form.login'} ne '' )) {
1.27 matthew 1659: # Modify user privileges
1660: if (! $amode || ! $genpwd) {
1.193 raeburn 1661: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1662: return;
1.20 harris41 1663: }
1.27 matthew 1664: # Only allow authentification modification if the person has authority
1.101 albertel 1665: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1666: $r->print('Modifying authentication: '.
1.31 matthew 1667: &Apache::lonnet::modifyuserauth(
1.101 albertel 1668: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1669: $amode,$genpwd));
1.102 albertel 1670: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1671: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1672: } else {
1.27 matthew 1673: # Okay, this is a non-fatal error.
1.193 raeburn 1674: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1675: }
1.28 matthew 1676: }
1677: ##
1.213 raeburn 1678: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1679: if ($context eq 'course') {
1680: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1681: }
1.101 albertel 1682: if (! $env{'form.makeuser'} ) {
1.28 matthew 1683: # Check for need to change
1684: my %userenv = &Apache::lonnet::get
1.134 raeburn 1685: ('environment',['firstname','middlename','lastname','generation',
1.196 raeburn 1686: 'id','permanentemail','portfolioquota','inststatus'],
1.160 raeburn 1687: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1688: my ($tmp) = keys(%userenv);
1689: if ($tmp =~ /^(con_lost|error)/i) {
1690: %userenv = ();
1691: }
1.206 raeburn 1692: my $no_forceid_alert;
1693: # Check to see if user information can be changed
1694: my %domconfig =
1695: &Apache::lonnet::get_dom('configuration',['usermodification'],
1696: $env{'form.ccdomain'});
1.213 raeburn 1697: my @statuses = ('active','future');
1698: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1699: my ($auname,$audom);
1.206 raeburn 1700: if ($context eq 'course') {
1701: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1702: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1703: if ($cnum eq '' || $cdom eq '') {
1704: my $cid = $env{'request.course.id'};
1705: my %coursehash =
1706: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1707: $cdom = $coursehash{'domain'};
1708: $cnum = $coursehash{'num'};
1709: }
1710: } elsif ($context eq 'author') {
1711: $auname = $env{'user.name'};
1712: $audom = $env{'user.domain'};
1713: }
1714: foreach my $item (keys(%roles)) {
1715: my ($rolenum,$roledom,$role) = split(/:/,$item);
1716: if ($context eq 'course') {
1717: if ($cnum ne '' && $cdom ne '') {
1718: if ($rolenum eq $cnum && $roledom eq $cdom) {
1719: if (!grep(/^\Q$role\E$/,@userroles)) {
1720: push(@userroles,$role);
1721: }
1722: }
1723: }
1724: } elsif ($context eq 'author') {
1725: if ($rolenum eq $auname && $roledom eq $audom) {
1726: if (!grep(/^\Q$role\E$/,@userroles)) {
1727: push(@userroles,$role);
1728: }
1729: }
1730: }
1731: }
1732: # Check for course or co-author roles being activated or re-enabled
1733: if ($context eq 'author' || $context eq 'course') {
1734: foreach my $key (keys(%env)) {
1735: if ($context eq 'author') {
1736: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1737: if (!grep(/^\Q$1\E$/,@userroles)) {
1738: push(@userroles,$1);
1739: }
1740: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1741: if (!grep(/^\Q$1\E$/,@userroles)) {
1742: push(@userroles,$1);
1743: }
1744: }
1745: } elsif ($context eq 'course') {
1746: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1747: if (!grep(/^\Q$1\E$/,@userroles)) {
1748: push(@userroles,$1);
1749: }
1750: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1751: if (!grep(/^\Q$1\E$/,@userroles)) {
1752: push(@userroles,$1);
1753: }
1754: }
1755: }
1756: }
1757: }
1758: #Check to see if we can change personal data for the user
1759: my (@mod_disallowed,@longroles);
1760: foreach my $role (@userroles) {
1761: if ($role eq 'cr') {
1762: push(@longroles,'Custom');
1763: } else {
1764: push(@longroles,&Apache::lonnet::plaintext($role));
1765: }
1766: }
1.196 raeburn 1767: foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
1.206 raeburn 1768: my $canmodify = 0;
1769: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1770: $canmodify = 1;
1771: } else {
1772: if ($context eq 'course' || $context eq 'author') {
1773: if (ref($domconfig{'usermodification'}) eq 'HASH') {
1774: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
1775: foreach my $role (@userroles) {
1776: if (ref($domconfig{'usermodification'}{$context}{$role}) eq 'HASH') {
1777: if ($domconfig{'usermodification'}{$context}{$role}{$item}) {
1778: $canmodify = 1;
1779: last;
1780: }
1781: }
1782: }
1783: }
1784: }
1785: } elsif ($context eq 'course') {
1786: if (grep(/^st$/,@userroles)) {
1787: $canmodify = 1;
1788: }
1789: }
1790: }
1.28 matthew 1791: # Strip leading and trailing whitespace
1.203 raeburn 1792: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.206 raeburn 1793: if (!$canmodify) {
1.207 raeburn 1794: if (defined($env{'form.c'.$item})) {
1795: if ($env{'form.c'.$item} ne $userenv{$item}) {
1796: push(@mod_disallowed,$item);
1797: }
1.206 raeburn 1798: }
1799: $env{'form.c'.$item} = $userenv{$item};
1800: }
1.28 matthew 1801: }
1.196 raeburn 1802: # Check to see if we can change the ID/student number
1803: my $forceid = $env{'form.forceid'};
1804: my $recurseid = $env{'form.recurseid'};
1805: my $newuser = 0;
1806: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1807: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1808: $env{'form.ccuname'});
1809: if (($uidhash{$env{'form.ccuname'}}) &&
1810: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1811: (!$forceid)) {
1812: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1813: $env{'form.cid'} = $userenv{'id'};
1.206 raeburn 1814: $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 1815: }
1816: }
1817: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1818: my $checkhash;
1819: my $checks = { 'id' => 1 };
1820: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1821: { 'newuser' => $newuser,
1822: 'id' => $env{'form.cid'},
1823: };
1824: &Apache::loncommon::user_rule_check($checkhash,$checks,
1825: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1826: if (ref($alerts{'id'}) eq 'HASH') {
1827: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1828: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1829: }
1830: }
1831: }
1.213 raeburn 1832: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1833: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1834: $newdefquotatext);
1.149 raeburn 1835: my ($defquota,$settingstatus) =
1836: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.134 raeburn 1837: my %changeHash;
1.204 raeburn 1838: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 1839: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1840: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1841: if ($env{'form.customquota'} == 1) {
1842: if ($env{'form.portfolioquota'} eq '') {
1843: $newportfolioquota = 0;
1844: } else {
1845: $newportfolioquota = $env{'form.portfolioquota'};
1846: $newportfolioquota =~ s/[^\d\.]//g;
1847: }
1.204 raeburn 1848: if ($newportfolioquota != $oldportfolioquota) {
1.149 raeburn 1849: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1850: }
1.149 raeburn 1851: } else {
1852: $quotachanged = "a_admin('',\%changeHash);
1853: $newportfolioquota = $defquota;
1.204 raeburn 1854: $newisdefault = 1;
1.134 raeburn 1855: }
1856: } else {
1.204 raeburn 1857: $oldisdefault = 1;
1.149 raeburn 1858: $oldportfolioquota = $defquota;
1859: if ($env{'form.customquota'} == 1) {
1860: if ($env{'form.portfolioquota'} eq '') {
1861: $newportfolioquota = 0;
1862: } else {
1863: $newportfolioquota = $env{'form.portfolioquota'};
1864: $newportfolioquota =~ s/[^\d\.]//g;
1865: }
1866: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1867: } else {
1868: $newportfolioquota = $defquota;
1.204 raeburn 1869: $newisdefault = 1;
1.149 raeburn 1870: }
1871: }
1.204 raeburn 1872: if ($oldisdefault) {
1873: $olddefquotatext = &get_defaultquota_text($settingstatus);
1874: }
1875: if ($newisdefault) {
1876: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 1877: }
1.206 raeburn 1878: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1879: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1880: $env{'form.clastname'} ne $userenv{'lastname'} ||
1881: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1882: $env{'form.cid'} ne $userenv{'id'} ||
1883: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 1884: $namechanged = 1;
1885: }
1.204 raeburn 1886: if ($namechanged || $quotachanged) {
1.101 albertel 1887: $changeHash{'firstname'} = $env{'form.cfirstname'};
1888: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1889: $changeHash{'lastname'} = $env{'form.clastname'};
1890: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1891: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1892: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204 raeburn 1893: my ($quotachgresult,$namechgresult);
1894: if ($quotachanged) {
1895: $quotachgresult =
1896: &Apache::lonnet::put('environment',\%changeHash,
1897: $env{'form.ccdomain'},$env{'form.ccuname'});
1898: }
1899: if ($namechanged) {
1900: # Make the change
1901: $namechgresult =
1902: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
1903: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
1904: $changeHash{'firstname'},$changeHash{'middlename'},
1905: $changeHash{'lastname'},$changeHash{'generation'},
1906: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1907: }
1908: if (($namechanged && $namechgresult eq 'ok') ||
1909: ($quotachanged && $quotachgresult eq 'ok')) {
1.28 matthew 1910: # Tell the user we changed the name
1.73 sakharuk 1911: my %lt=&Apache::lonlocal::texthash(
1912: 'uic' => "User Information Changed",
1913: 'frst' => "first",
1914: 'mddl' => "middle",
1915: 'lst' => "last",
1916: 'gen' => "generation",
1.196 raeburn 1917: 'id' => "ID/Student number",
1.160 raeburn 1918: 'mail' => "permanent e-mail",
1.134 raeburn 1919: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1920: 'prvs' => "Previous",
1921: 'chto' => "Changed To"
1922: );
1.201 raeburn 1923: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1924: &Apache::loncommon::start_data_table().
1925: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1926: $r->print(<<"END");
1.201 raeburn 1927: <th> </th>
1.73 sakharuk 1928: <th>$lt{'frst'}</th>
1929: <th>$lt{'mddl'}</th>
1930: <th>$lt{'lst'}</th>
1.134 raeburn 1931: <th>$lt{'gen'}</th>
1.196 raeburn 1932: <th>$lt{'id'}</th>
1.173 raeburn 1933: <th>$lt{'mail'}</th>
1.201 raeburn 1934: <th>$lt{'disk'}</th>
1935: END
1936: $r->print(&Apache::loncommon::end_data_table_header_row().
1937: &Apache::loncommon::start_data_table_row());
1938: $r->print(<<"END");
1939: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 1940: <td>$userenv{'firstname'} </td>
1941: <td>$userenv{'middlename'} </td>
1942: <td>$userenv{'lastname'} </td>
1.134 raeburn 1943: <td>$userenv{'generation'} </td>
1.196 raeburn 1944: <td>$userenv{'id'}</td>
1.160 raeburn 1945: <td>$userenv{'permanentemail'} </td>
1.204 raeburn 1946: <td>$oldportfolioquota Mb $olddefquotatext </td>
1.201 raeburn 1947: END
1948: $r->print(&Apache::loncommon::end_data_table_row().
1949: &Apache::loncommon::start_data_table_row());
1950: $r->print(<<"END");
1951: <td><b>$lt{'chto'}</b></td>
1.101 albertel 1952: <td>$env{'form.cfirstname'} </td>
1953: <td>$env{'form.cmiddlename'} </td>
1954: <td>$env{'form.clastname'} </td>
1.134 raeburn 1955: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 1956: <td>$env{'form.cid'} </td>
1.160 raeburn 1957: <td>$env{'form.cpermanentemail'} </td>
1.204 raeburn 1958: <td>$newportfolioquota Mb $newdefquotatext </td>
1.28 matthew 1959: END
1.201 raeburn 1960: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 1961: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 1962: if ($env{'form.cid'} ne $userenv{'id'}) {
1963: &Apache::lonnet::idput($env{'form.ccdomain'},
1964: ($env{'form.ccuname'} => $env{'form.cid'}));
1965: if (($recurseid) &&
1966: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
1.213 raeburn 1967: %userupdate = (
1.196 raeburn 1968: lastname => $env{'form.clasaname'},
1969: middlename => $env{'form.cmiddlename'},
1970: firstname => $env{'form.cfirstname'},
1971: generation => $env{'fora.cgeneration'},
1972: id => $env{'form.cid'},
1973: );
1.203 raeburn 1974: my $idresult =
1975: &Apache::lonuserutils::propagate_id_change(
1976: $env{'form.ccuname'},$env{'form.ccdomain'},
1977: \%userupdate);
1978: $r->print('<br />'.$idresult.'<br />');
1979: }
1.196 raeburn 1980: }
1.149 raeburn 1981: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1982: ($env{'form.ccuname'} eq $env{'user.name'})) {
1983: my %newenvhash;
1984: foreach my $key (keys(%changeHash)) {
1985: $newenvhash{'environment.'.$key} = $changeHash{$key};
1986: }
1987: &Apache::lonnet::appenv(%newenvhash);
1988: }
1.28 matthew 1989: } else { # error occurred
1.188 raeburn 1990: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
1991: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 1992: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 1993: }
1.101 albertel 1994: } else { # End of if ($env ... ) logic
1.204 raeburn 1995: # They did not want to change the users name or quota but we can
1996: # still tell them what the name and quota are
1.73 sakharuk 1997: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 1998: 'id' => "ID/Student number",
1.160 raeburn 1999: 'mail' => "Permanent e-mail",
1.134 raeburn 2000: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 2001: );
1.134 raeburn 2002: $r->print(<<"END");
1.196 raeburn 2003: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2004: END
1.204 raeburn 2005: if ($userenv{'permanentemail'} ne '') {
2006: $r->print('<br />['.$lt{'mail'}.': '.
2007: $userenv{'permanentemail'}.']');
1.134 raeburn 2008: }
1.204 raeburn 2009: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
2010: $olddefquotatext.']</h4>');
1.28 matthew 2011: }
1.206 raeburn 2012: if (@mod_disallowed) {
2013: my ($rolestr,$contextname);
2014: if (@longroles > 0) {
2015: $rolestr = join(', ',@longroles);
2016: } else {
2017: $rolestr = &mt('No roles');
2018: }
2019: if ($context eq 'course') {
2020: $contextname = &mt('course');
2021: } elsif ($context eq 'author') {
2022: $contextname = &mt('co-author');
2023: }
2024: $r->print(&mt('The following fields were not updated: ').'<ul>');
2025: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2026: foreach my $field (@mod_disallowed) {
2027: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2028: }
1.207 raeburn 2029: $r->print('</ul>');
2030: if (@mod_disallowed == 1) {
2031: $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));
2032: } else {
2033: $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));
2034: }
2035: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2036: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2037: }
2038: $r->print($no_forceid_alert.
2039: &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
1.4 www 2040: }
1.27 matthew 2041: ##
1.4 www 2042: my $now=time;
1.193 raeburn 2043: my $rolechanges = 0;
1.73 sakharuk 2044: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2045: foreach my $key (keys (%env)) {
2046: next if (! $env{$key});
1.190 raeburn 2047: next if ($key eq 'form.action');
1.27 matthew 2048: # Revoke roles
1.135 raeburn 2049: if ($key=~/^form\.rev/) {
2050: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2051: # Revoke standard role
1.170 albertel 2052: my ($scope,$role) = ($1,$2);
2053: my $result =
2054: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2055: $env{'form.ccuname'},
2056: $scope,$role);
2057: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2058: $role,$scope,'<b>'.$result.'</b>').'<br />');
2059: if ($role eq 'st') {
1.202 raeburn 2060: my $result =
1.198 raeburn 2061: &Apache::lonuserutils::classlist_drop($scope,
2062: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2063: $now);
1.170 albertel 2064: $r->print($result);
1.53 www 2065: }
1.196 raeburn 2066: }
1.195 raeburn 2067: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2068: # Revoke custom role
1.113 raeburn 2069: $r->print(&mt('Revoking custom role:').
1.139 albertel 2070: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2071: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
2072: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 2073: '</b><br />');
1.64 www 2074: }
1.193 raeburn 2075: $rolechanges ++;
1.135 raeburn 2076: } elsif ($key=~/^form\.del/) {
2077: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2078: # Delete standard role
1.170 albertel 2079: my ($scope,$role) = ($1,$2);
2080: my $result =
2081: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2082: $env{'form.ccuname'},
2083: $scope,$role,$now,0,1);
2084: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2085: '<b>'.$result.'</b>').'<br />');
2086: if ($role eq 'st') {
1.202 raeburn 2087: my $result =
1.198 raeburn 2088: &Apache::lonuserutils::classlist_drop($scope,
2089: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2090: $now);
1.170 albertel 2091: $r->print($result);
1.81 albertel 2092: }
1.116 raeburn 2093: }
1.139 albertel 2094: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2095: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2096: # Delete custom role
1.170 albertel 2097: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2098: $rolename,$rnam,$rdom,$url).': <b>'.
2099: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2100: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
2101: 0,1).'</b><br />');
2102: }
1.193 raeburn 2103: $rolechanges ++;
1.135 raeburn 2104: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2105: my $udom = $env{'form.ccdomain'};
2106: my $uname = $env{'form.ccuname'};
1.116 raeburn 2107: # Re-enable standard role
1.135 raeburn 2108: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2109: my $url = $1;
2110: my $role = $2;
2111: my $logmsg;
2112: my $output;
2113: if ($role eq 'st') {
1.141 albertel 2114: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2115: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 2116: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
2117: $output = "Error: $result\n";
2118: } else {
2119: $output = &mt('Assigning').' '.$role.' in '.$url.
2120: &mt('starting').' '.localtime($now).
2121: ': <br />'.$logmsg.'<br />'.
2122: &mt('Add to classlist').': <b>ok</b><br />';
2123: }
2124: }
2125: } else {
1.101 albertel 2126: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
2127: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 2128: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 2129: $role,$url,$result).'<br />';
1.27 matthew 2130: }
1.89 raeburn 2131: $r->print($output);
1.113 raeburn 2132: }
1.116 raeburn 2133: # Re-enable custom role
1.139 albertel 2134: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2135: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2136: my $result = &Apache::lonnet::assigncustomrole(
2137: $env{'form.ccdomain'}, $env{'form.ccuname'},
2138: $url,$rdom,$rnam,$rolename,0,$now);
2139: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
2140: $rolename,$rnam,$rdom,$url,$result).'<br />');
2141: }
1.193 raeburn 2142: $rolechanges ++;
1.135 raeburn 2143: } elsif ($key=~/^form\.act/) {
1.101 albertel 2144: my $udom = $env{'form.ccdomain'};
2145: my $uname = $env{'form.ccuname'};
1.141 albertel 2146: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2147: # Activate a custom role
1.83 albertel 2148: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2149: my $url='/'.$one.'/'.$two;
2150: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2151:
1.101 albertel 2152: my $start = ( $env{'form.start_'.$full} ?
2153: $env{'form.start_'.$full} :
1.88 raeburn 2154: $now );
1.101 albertel 2155: my $end = ( $env{'form.end_'.$full} ?
2156: $env{'form.end_'.$full} :
1.88 raeburn 2157: 0 );
2158:
2159: # split multiple sections
2160: my %sections = ();
1.101 albertel 2161: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2162: if ($num_sections == 0) {
1.129 albertel 2163: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 2164: } else {
1.114 albertel 2165: my %curr_groups =
1.117 raeburn 2166: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2167: foreach my $sec (sort {$a cmp $b} keys %sections) {
2168: if (($sec eq 'none') || ($sec eq 'all') ||
2169: exists($curr_groups{$sec})) {
2170: $disallowed{$sec} = $url;
2171: next;
2172: }
2173: my $securl = $url.'/'.$sec;
1.129 albertel 2174: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 2175: }
2176: }
1.142 raeburn 2177: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2178: # Activate roles for sections with 3 id numbers
2179: # set start, end times, and the url for the class
1.83 albertel 2180: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2181: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2182: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2183: $now );
1.101 albertel 2184: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2185: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2186: 0 );
1.83 albertel 2187: my $url='/'.$one.'/'.$two;
1.88 raeburn 2188: my $type = 'three';
2189: # split multiple sections
2190: my %sections = ();
1.101 albertel 2191: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2192: if ($num_sections == 0) {
1.129 albertel 2193: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 2194: } else {
1.114 albertel 2195: my %curr_groups =
1.117 raeburn 2196: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2197: my $emptysec = 0;
2198: foreach my $sec (sort {$a cmp $b} keys %sections) {
2199: $sec =~ s/\W//g;
1.113 raeburn 2200: if ($sec ne '') {
2201: if (($sec eq 'none') || ($sec eq 'all') ||
2202: exists($curr_groups{$sec})) {
2203: $disallowed{$sec} = $url;
2204: next;
2205: }
1.88 raeburn 2206: my $securl = $url.'/'.$sec;
1.129 albertel 2207: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 2208: } else {
2209: $emptysec = 1;
2210: }
2211: }
2212: if ($emptysec) {
1.129 albertel 2213: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 2214: }
2215: }
1.135 raeburn 2216: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2217: # Activate roles for sections with two id numbers
2218: # set start, end times, and the url for the class
1.101 albertel 2219: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2220: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2221: $now );
1.101 albertel 2222: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2223: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2224: 0 );
2225: my $url='/'.$1.'/';
1.88 raeburn 2226: # split multiple sections
2227: my %sections = ();
1.101 albertel 2228: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 2229: if ($num_sections == 0) {
1.129 albertel 2230: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 2231: } else {
2232: my $emptysec = 0;
2233: foreach my $sec (sort {$a cmp $b} keys %sections) {
2234: if ($sec ne '') {
2235: my $securl = $url.'/'.$sec;
1.129 albertel 2236: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 2237: } else {
2238: $emptysec = 1;
2239: }
2240: }
2241: if ($emptysec) {
1.129 albertel 2242: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 2243: }
2244: }
1.64 www 2245: } else {
1.190 raeburn 2246: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2247: }
1.113 raeburn 2248: foreach my $key (sort(keys(%disallowed))) {
2249: if (($key eq 'none') || ($key eq 'all')) {
2250: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2251: } else {
2252: $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));
2253: }
2254: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2255: }
1.193 raeburn 2256: $rolechanges ++;
1.113 raeburn 2257: }
1.101 albertel 2258: } # End of foreach (keys(%env))
1.75 www 2259: # Flush the course logs so reverse user roles immediately updated
2260: &Apache::lonnet::flushcourselogs();
1.193 raeburn 2261: if (!$rolechanges) {
2262: $r->print(&mt('No roles to modify'));
2263: }
1.188 raeburn 2264: $r->print(&Apache::loncommon::end_page());
2265: }
2266:
1.204 raeburn 2267: sub get_defaultquota_text {
2268: my ($settingstatus) = @_;
2269: my $defquotatext;
2270: if ($settingstatus eq '') {
2271: $defquotatext = &mt('(default)');
2272: } else {
2273: my ($usertypes,$order) =
2274: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2275: if ($usertypes->{$settingstatus} eq '') {
2276: $defquotatext = &mt('(default)');
2277: } else {
2278: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2279: }
2280: }
2281: return $defquotatext;
2282: }
2283:
1.188 raeburn 2284: sub update_result_form {
2285: my ($uhome) = @_;
2286: my $outcome =
2287: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2288: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2289: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2290: }
1.207 raeburn 2291: if ($env{'form.origname'} ne '') {
2292: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2293: }
1.160 raeburn 2294: foreach my $item ('sortby','seluname','seludom') {
2295: if (exists($env{'form.'.$item})) {
1.188 raeburn 2296: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2297: }
2298: }
1.188 raeburn 2299: if ($uhome eq 'no_host') {
2300: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2301: }
2302: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2303: '<input type ="hidden" name="currstate" value="" />'."\n".
1.190 raeburn 2304: '<input type ="hidden" name="action" value="singleuser" />'."\n".
1.188 raeburn 2305: '</form>';
2306: return $outcome;
1.4 www 2307: }
2308:
1.149 raeburn 2309: sub quota_admin {
2310: my ($setquota,$changeHash) = @_;
2311: my $quotachanged;
2312: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2313: # Current user has quota modification privileges
2314: $quotachanged = 1;
2315: $changeHash->{'portfolioquota'} = $setquota;
2316: }
2317: return $quotachanged;
2318: }
2319:
1.88 raeburn 2320: sub build_roles {
1.89 raeburn 2321: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2322: my $num_sections = 0;
2323: if ($sectionstr=~ /,/) {
2324: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2325: if ($role eq 'st') {
2326: $secnums[0] =~ s/\W//g;
2327: $$sections{$secnums[0]} = 1;
2328: $num_sections = 1;
2329: } else {
2330: foreach my $sec (@secnums) {
2331: $sec =~ ~s/\W//g;
1.150 banghart 2332: if (!($sec eq "")) {
1.89 raeburn 2333: if (exists($$sections{$sec})) {
2334: $$sections{$sec} ++;
2335: } else {
2336: $$sections{$sec} = 1;
2337: $num_sections ++;
2338: }
1.88 raeburn 2339: }
2340: }
2341: }
2342: } else {
2343: $sectionstr=~s/\W//g;
2344: unless ($sectionstr eq '') {
2345: $$sections{$sectionstr} = 1;
2346: $num_sections ++;
2347: }
2348: }
1.129 albertel 2349:
1.88 raeburn 2350: return $num_sections;
2351: }
2352:
1.58 www 2353: # ========================================================== Custom Role Editor
2354:
2355: sub custom_role_editor {
1.160 raeburn 2356: my ($r) = @_;
1.101 albertel 2357: my $rolename=$env{'form.rolename'};
1.58 www 2358:
1.59 www 2359: if ($rolename eq 'make new role') {
1.101 albertel 2360: $rolename=$env{'form.newrolename'};
1.59 www 2361: }
2362:
1.63 www 2363: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2364:
1.190 raeburn 2365: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2366: &print_username_entry_form($r);
2367: return;
2368: }
1.153 banghart 2369: # ------------------------------------------------------- What can be assigned?
2370: my %full=();
2371: my %courselevel=();
2372: my %courselevelcurrent=();
1.61 www 2373: my $syspriv='';
2374: my $dompriv='';
2375: my $coursepriv='';
1.153 banghart 2376: my $body_top;
1.150 banghart 2377: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2378: my ($rdummy,$roledef)=
2379: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2380: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2381: $body_top .= '<h2>';
1.59 www 2382: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2383: $body_top .= &mt('Existing Role').' "';
1.61 www 2384: # ------------------------------------------------- Get current role privileges
2385: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2386: } else {
1.153 banghart 2387: $body_top .= &mt('New Role').' "';
1.59 www 2388: $roledef='';
2389: }
1.153 banghart 2390: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2391: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2392: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2393: if (!$restrict) { $restrict='F'; }
1.60 www 2394: $courselevel{$priv}=$restrict;
1.61 www 2395: if ($coursepriv=~/\:$priv/) {
2396: $courselevelcurrent{$priv}=1;
2397: }
1.60 www 2398: $full{$priv}=1;
2399: }
2400: my %domainlevel=();
1.61 www 2401: my %domainlevelcurrent=();
1.135 raeburn 2402: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2403: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2404: if (!$restrict) { $restrict='F'; }
1.60 www 2405: $domainlevel{$priv}=$restrict;
1.61 www 2406: if ($dompriv=~/\:$priv/) {
2407: $domainlevelcurrent{$priv}=1;
2408: }
1.60 www 2409: $full{$priv}=1;
2410: }
1.61 www 2411: my %systemlevel=();
2412: my %systemlevelcurrent=();
1.135 raeburn 2413: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2414: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2415: if (!$restrict) { $restrict='F'; }
1.61 www 2416: $systemlevel{$priv}=$restrict;
2417: if ($syspriv=~/\:$priv/) {
2418: $systemlevelcurrent{$priv}=1;
2419: }
2420: $full{$priv}=1;
2421: }
1.160 raeburn 2422: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2423: my $button_code = "\n";
1.153 banghart 2424: my $head_script = "\n";
2425: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2426: my @template_roles = ("cc","in","ta","ep","st");
2427: foreach my $role (@template_roles) {
2428: $head_script .= &make_script_template($role);
2429: $button_code .= &make_button_code($role);
2430: }
1.160 raeburn 2431: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2432: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2433: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2434: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2435: text=>"Pick custom role",
1.160 raeburn 2436: faq=>282,bug=>'Instructor Interface',},
2437: {href=>"javascript:backPage(document.form1,'','')",
2438: text=>"Edit custom role",
2439: faq=>282,bug=>'Instructor Interface',});
2440: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2441:
1.153 banghart 2442: $r->print($body_top);
1.73 sakharuk 2443: my %lt=&Apache::lonlocal::texthash(
2444: 'prv' => "Privilege",
1.131 raeburn 2445: 'crl' => "Course Level",
1.73 sakharuk 2446: 'dml' => "Domain Level",
1.150 banghart 2447: 'ssl' => "System Level");
1.152 banghart 2448: $r->print('Select a Template<br />');
1.154 banghart 2449: $r->print('<form action="">');
2450: $r->print($button_code);
2451: $r->print('</form>');
1.61 www 2452: $r->print(<<ENDCCF);
1.160 raeburn 2453: <form name="form1" method="post">
1.61 www 2454: <input type="hidden" name="phase" value="set_custom_roles" />
2455: <input type="hidden" name="rolename" value="$rolename" />
2456: ENDCCF
1.135 raeburn 2457: $r->print(&Apache::loncommon::start_data_table().
2458: &Apache::loncommon::start_data_table_header_row().
2459: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2460: '</th><th>'.$lt{'ssl'}.'</th>'.
2461: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2462: foreach my $priv (sort keys %full) {
2463: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2464: $r->print(&Apache::loncommon::start_data_table_row().
2465: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2466: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2467: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2468: '</td><td>'.
1.150 banghart 2469: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2470: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2471: '</td><td>'.
1.150 banghart 2472: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2473: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2474: '</td>'.
2475: &Apache::loncommon::end_data_table_row());
1.60 www 2476: }
1.135 raeburn 2477: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2478: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2479: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2480: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2481: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2482: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2483: &Apache::loncommon::end_page());
1.61 www 2484: }
1.153 banghart 2485: # --------------------------------------------------------
2486: sub make_script_template {
2487: my ($role) = @_;
2488: my %full_c=();
2489: my %full_d=();
2490: my %full_s=();
2491: my $return_script;
2492: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2493: my ($priv,$restrict)=split(/\&/,$item);
2494: $full_c{$priv}=1;
2495: }
2496: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2497: my ($priv,$restrict)=split(/\&/,$item);
2498: $full_d{$priv}=1;
2499: }
1.154 banghart 2500: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2501: my ($priv,$restrict)=split(/\&/,$item);
2502: $full_s{$priv}=1;
2503: }
2504: $return_script .= 'function set_'.$role.'() {'."\n";
2505: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2506: my %role_c;
1.155 banghart 2507: foreach my $priv (@temp) {
1.153 banghart 2508: my ($priv_item, $dummy) = split(/\&/,$priv);
2509: $role_c{$priv_item} = 1;
2510: }
2511: foreach my $priv_item (keys(%full_c)) {
2512: my ($priv, $dummy) = split(/\&/,$priv_item);
2513: if (exists($role_c{$priv})) {
2514: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2515: } else {
2516: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2517: }
2518: }
1.154 banghart 2519: my %role_d;
2520: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2521: foreach my $priv(@temp) {
2522: my ($priv_item, $dummy) = split(/\&/,$priv);
2523: $role_d{$priv_item} = 1;
2524: }
2525: foreach my $priv_item (keys(%full_d)) {
2526: my ($priv, $dummy) = split(/\&/,$priv_item);
2527: if (exists($role_d{$priv})) {
2528: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2529: } else {
2530: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2531: }
2532: }
2533: my %role_s;
2534: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2535: foreach my $priv(@temp) {
2536: my ($priv_item, $dummy) = split(/\&/,$priv);
2537: $role_s{$priv_item} = 1;
2538: }
2539: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2540: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2541: if (exists($role_s{$priv})) {
2542: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2543: } else {
2544: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2545: }
1.153 banghart 2546: }
2547: $return_script .= '}'."\n";
1.154 banghart 2548: return ($return_script);
2549: }
2550: # ----------------------------------------------------------
2551: sub make_button_code {
2552: my ($role) = @_;
2553: my $label = &Apache::lonnet::plaintext($role);
2554: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2555: return ($button_code);
1.153 banghart 2556: }
1.61 www 2557: # ---------------------------------------------------------- Call to definerole
2558: sub set_custom_role {
1.110 albertel 2559: my ($r) = @_;
1.101 albertel 2560: my $rolename=$env{'form.rolename'};
1.63 www 2561: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2562: if (!$rolename) {
1.190 raeburn 2563: &custom_role_editor($r);
1.61 www 2564: return;
2565: }
1.160 raeburn 2566: my ($jsback,$elements) = &crumb_utilities();
2567: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2568:
2569: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2570: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2571: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2572: text=>"Pick custom role",
1.160 raeburn 2573: faq=>282,bug=>'Instructor Interface',},
2574: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2575: text=>"Edit custom role",
2576: faq=>282,bug=>'Instructor Interface',},
2577: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2578: text=>"Result",
2579: faq=>282,bug=>'Instructor Interface',});
2580: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2581:
1.61 www 2582: my ($rdummy,$roledef)=
1.110 albertel 2583: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2584:
1.61 www 2585: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2586: $r->print('<h3>');
1.61 www 2587: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2588: $r->print(&mt('Existing Role').' "');
1.61 www 2589: } else {
1.73 sakharuk 2590: $r->print(&mt('New Role').' "');
1.61 www 2591: $roledef='';
2592: }
1.188 raeburn 2593: $r->print($rolename.'"</h3>');
1.61 www 2594: # ------------------------------------------------------- What can be assigned?
2595: my $sysrole='';
2596: my $domrole='';
2597: my $courole='';
2598:
1.135 raeburn 2599: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2600: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2601: if (!$restrict) { $restrict=''; }
2602: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2603: $courole.=':'.$item;
1.61 www 2604: }
2605: }
2606:
1.135 raeburn 2607: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2608: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2609: if (!$restrict) { $restrict=''; }
2610: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2611: $domrole.=':'.$item;
1.61 www 2612: }
2613: }
2614:
1.135 raeburn 2615: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2616: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2617: if (!$restrict) { $restrict=''; }
2618: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2619: $sysrole.=':'.$item;
1.61 www 2620: }
2621: }
1.63 www 2622: $r->print('<br />Defining Role: '.
1.61 www 2623: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2624: if ($env{'request.course.id'}) {
2625: my $url='/'.$env{'request.course.id'};
1.63 www 2626: $url=~s/\_/\//g;
1.73 sakharuk 2627: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2628: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2629: $env{'user.name'},
1.63 www 2630: $url,
1.101 albertel 2631: $env{'user.domain'},
2632: $env{'user.name'},
1.63 www 2633: $rolename));
2634: }
1.190 raeburn 2635: $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 2636: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2637: $r->print(&Apache::loncommon::end_page());
1.58 www 2638: }
2639:
1.2 www 2640: # ================================================================ Main Handler
2641: sub handler {
2642: my $r = shift;
2643: if ($r->header_only) {
1.68 www 2644: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2645: $r->send_http_header;
2646: return OK;
2647: }
1.190 raeburn 2648: my $context;
2649: if ($env{'request.course.id'}) {
2650: $context = 'course';
2651: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 2652: $context = 'author';
1.190 raeburn 2653: } else {
2654: $context = 'domain';
2655: }
2656: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.202 raeburn 2657: ['action','state','callingform','roletype','showrole','bulkaction']);
1.190 raeburn 2658: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2659: if ($env{'form.action'} ne 'dateselect') {
2660: &Apache::lonhtmlcommon::add_breadcrumb
2661: ({href=>"/adm/createuser",
2662: text=>"User Management"});
2663: }
1.209 raeburn 2664: my ($permission,$allowed) =
2665: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 2666: if (!$allowed) {
2667: $env{'user.error.msg'}=
2668: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2669: "or view user status.";
2670: return HTTP_NOT_ACCEPTABLE;
2671: }
2672:
2673: &Apache::loncommon::content_type($r,'text/html');
2674: $r->send_http_header;
2675:
2676: # Main switch on form.action and form.state, as appropriate
2677: if (! exists($env{'form.action'})) {
2678: $r->print(&header());
2679: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 2680: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2681: $r->print(&Apache::loncommon::end_page());
2682: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2683: $r->print(&header());
2684: &Apache::lonhtmlcommon::add_breadcrumb
2685: ({href=>'/adm/createuser?action=upload&state=',
2686: text=>"Upload Users List"});
2687: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
2688: 'User_Management_Upload'));
2689: $r->print('<form name="studentform" method="post" '.
2690: 'enctype="multipart/form-data" '.
2691: ' action="/adm/createuser">'."\n");
2692: if (! exists($env{'form.state'})) {
2693: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2694: } elsif ($env{'form.state'} eq 'got_file') {
2695: &Apache::lonuserutils::print_upload_manager_form($r,$context);
2696: } elsif ($env{'form.state'} eq 'enrolling') {
2697: if ($env{'form.datatoken'}) {
2698: &Apache::lonuserutils::upfile_drop_add($r,$context);
2699: }
2700: } else {
2701: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2702: }
2703: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 2704: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
2705: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 2706: my $phase = $env{'form.phase'};
2707: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2708: &Apache::loncreateuser::restore_prev_selections();
2709: my $srch;
2710: foreach my $item (@search) {
2711: $srch->{$item} = $env{'form.'.$item};
2712: }
1.190 raeburn 2713:
1.207 raeburn 2714: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
2715: ($phase eq 'createnewuser')) {
2716: if ($env{'form.phase'} eq 'createnewuser') {
2717: my $response;
2718: if ($env{'form.srchterm'} !~ /^$match_username$/) {
2719: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
2720: &print_username_entry_form($r,$context,$response,$srch);
2721: } else {
2722: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
2723: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
2724: &print_user_modification_page($r,$ccuname,$ccdomain,
2725: $srch,$response,$context);
2726: }
2727: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 2728: my ($currstate,$response,$forcenewuser,$results) =
2729: &user_search_result($srch);
2730: if ($env{'form.currstate'} eq 'modify') {
2731: $currstate = $env{'form.currstate'};
2732: }
2733: if ($currstate eq 'select') {
1.214 raeburn 2734: my $operation;
2735: if ($env{'form.action'} eq 'singleuser') {
2736: $operation = 'createuser';
2737: } elsif ($env{'form.action'} eq 'singlestudent') {
2738: $operation = 'enrollstudent';
2739: }
1.190 raeburn 2740: &print_user_selection_page($r,$response,$srch,$results,
1.214 raeburn 2741: $operation,\@search,$context);
1.190 raeburn 2742: } elsif ($currstate eq 'modify') {
2743: my ($ccuname,$ccdomain);
2744: if (($srch->{'srchby'} eq 'uname') &&
2745: ($srch->{'srchtype'} eq 'exact')) {
2746: $ccuname = $srch->{'srchterm'};
2747: $ccdomain= $srch->{'srchdomain'};
2748: } else {
2749: my @matchedunames = keys(%{$results});
2750: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2751: }
2752: $ccuname =&LONCAPA::clean_username($ccuname);
2753: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2754: if ($env{'form.forcenewuser'}) {
2755: $response = '';
2756: }
2757: &print_user_modification_page($r,$ccuname,$ccdomain,
1.196 raeburn 2758: $srch,$response,$context);
1.190 raeburn 2759: } elsif ($currstate eq 'query') {
2760: &print_user_query_page($r,'createuser');
2761: } else {
1.207 raeburn 2762: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 2763: $forcenewuser);
2764: }
2765: } elsif ($env{'form.phase'} eq 'userpicked') {
2766: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2767: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2768: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
2769: $context);
1.190 raeburn 2770: }
2771: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 2772: &update_user_data($r,$context);
1.190 raeburn 2773: } else {
1.207 raeburn 2774: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 2775: }
2776: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2777: if ($env{'form.phase'} eq 'set_custom_roles') {
2778: &set_custom_role($r);
2779: } else {
2780: &custom_role_editor($r);
2781: }
1.207 raeburn 2782: } elsif (($env{'form.action'} eq 'listusers') &&
2783: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 2784: if ($env{'form.phase'} eq 'bulkchange') {
2785: &Apache::lonhtmlcommon::add_breadcrumb
2786: ({href=>'backPage(document.studentform)',
2787: text=>"List Users"});
2788: my $setting = $env{'form.roletype'};
2789: my $choice = $env{'form.bulkaction'};
2790: $r->print(&header());
2791: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
2792: 'User_Management_List'));
2793: if ($permission->{'cusr'}) {
2794: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
2795: }
2796: } else {
2797: &Apache::lonhtmlcommon::add_breadcrumb
2798: ({href=>'/adm/createuser?action=listusers',
2799: text=>"List Users"});
2800: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2801: my $formname = 'studentform';
2802: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2803: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2804: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2805: $formname);
2806: $jscript .= &verify_user_display();
2807: my $js = &add_script($jscript).$cb_jscript;
2808: my $loadcode =
2809: &Apache::lonuserutils::course_selector_loadcode($formname);
2810: if ($loadcode ne '') {
2811: $r->print(&header($js,{'onload' => $loadcode,}));
2812: } else {
2813: $r->print(&header($js));
2814: }
1.191 raeburn 2815: } else {
1.202 raeburn 2816: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 2817: }
1.202 raeburn 2818: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
2819: 'User_Management_List'));
2820: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
2821: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
2822: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 2823: }
1.213 raeburn 2824: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
2825: $r->print(&header());
2826: &Apache::lonhtmlcommon::add_breadcrumb
2827: ({href=>'/adm/createuser?action=drop',
2828: text=>"Drop Students"});
2829: if (!exists($env{'form.state'})) {
2830: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2831: 'Course_Drop_Student'));
2832:
2833: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
2834: } elsif ($env{'form.state'} eq 'done') {
2835: &Apache::lonhtmlcommon::add_breadcrumb
2836: ({href=>'/adm/createuser?action=drop',
2837: text=>"Result"});
2838: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2839: 'Course_Drop_Student'));
2840: &Apache::lonuserutils::update_user_list($r,$context,undef,
2841: $env{'form.action'});
2842: }
2843: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2844: } elsif ($env{'form.action'} eq 'dateselect') {
2845: if ($permission->{'cusr'}) {
2846: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
2847: &Apache::lonuserutils::date_section_selector($context).
2848: &Apache::loncommon::end_page());
2849: } else {
2850: $r->print(&header().
2851: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
2852: &Apache::loncommon::end_page());
2853: }
1.190 raeburn 2854: } else {
2855: $r->print(&header());
1.202 raeburn 2856: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 2857: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2858: $r->print(&Apache::loncommon::end_page());
2859: }
2860: return OK;
2861: }
2862:
2863: sub header {
1.202 raeburn 2864: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 2865: my $start_page;
2866: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 2867: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 2868: } else {
1.202 raeburn 2869: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 2870: }
2871: return $start_page;
2872: }
1.2 www 2873:
1.191 raeburn 2874: sub add_script {
2875: my ($js) = @_;
2876: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
2877: }
2878:
1.202 raeburn 2879: sub verify_user_display {
2880: my $output = <<"END";
2881:
2882: function display_update() {
2883: document.studentform.action.value = 'listusers';
2884: document.studentform.phase.value = 'display';
2885: document.studentform.submit();
2886: }
2887:
2888: END
2889: return $output;
2890:
2891: }
2892:
1.190 raeburn 2893: ###############################################################
2894: ###############################################################
2895: # Menu Phase One
2896: sub print_main_menu {
1.208 raeburn 2897: my ($permission,$context) = @_;
2898: my %links = (
2899: domain => {
2900: upload => 'Upload a File of Users',
2901: singleuser => 'Add/Manage a Single User',
2902: listusers => 'Manage Multiple Users',
2903: },
2904: author => {
2905: upload => 'Upload a File of Co-authors',
2906: singleuser => 'Add/Manage a Single Co-author',
2907: listusers => 'Display Co-authors and Manage Multiple Users',
2908: },
2909: course => {
2910: upload => 'Upload a File of Course Users',
2911: singleuser => 'Add/Manage a Single Course User',
2912: listusers => 'Display Class Lists and Manage Multiple Users',
2913: },
2914: );
1.190 raeburn 2915: my @menu =
2916: (
1.208 raeburn 2917: { text => $links{$context}{'upload'},
1.190 raeburn 2918: help => 'User_Management_Upload',
2919: action => 'upload',
2920: permission => $permission->{'cusr'},
2921: },
1.208 raeburn 2922: { text => $links{$context}{'singleuser'},
1.190 raeburn 2923: help => 'User_Management_Single_User',
2924: action => 'singleuser',
2925: permission => $permission->{'cusr'},
2926: },
1.208 raeburn 2927: { text => $links{$context}{'listusers'},
1.191 raeburn 2928: help => 'User_Management_List',
2929: action => 'listusers',
1.208 raeburn 2930: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190 raeburn 2931: },
2932: );
1.208 raeburn 2933: if ($context eq 'domain' || $context eq 'course') {
2934: my $customlink = { text => 'Edit Custom Roles',
2935: help => 'Custom_Role_Edit',
2936: action => 'custom',
2937: permission => $permission->{'custom'},
2938: };
2939: push(@menu,$customlink);
2940: }
2941: if ($context eq 'course') {
1.213 raeburn 2942: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
2943: my @courselinks =
1.208 raeburn 2944: (
1.213 raeburn 2945: { text => 'Enroll a Single Student',
2946: help => 'Course_Single_Student',
2947: action => 'singlestudent',
2948: permission => $permission->{'cusr'},
2949: },
2950: { text => 'Drop Students',
2951: help => 'Course_Drop_Student',
2952: action => 'drop',
2953: permission => $permission->{'cusr'},
2954: });
2955: if (!exists($permission->{'cusr_section'})) {
2956: push(@courselinks,
2957: { text => 'Automated Student Enrollment Manager',
1.208 raeburn 2958: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
2959: && $permission->{'cusr'}),
2960: url => '/adm/populate',
1.213 raeburn 2961: });
2962: }
2963: push(@courselinks,
1.208 raeburn 2964: { text => 'Manage Course Groups',
2965: help => 'Course_Manage_Group',
2966: permission => $permission->{'grp_manage'},
2967: url => '/adm/coursegroups?refpage=cusr',
1.213 raeburn 2968: });
1.208 raeburn 2969: push(@menu,@courselinks);
2970: }
1.190 raeburn 2971: my $menu_html = '';
2972: foreach my $menu_item (@menu) {
2973: next if (! $menu_item->{'permission'});
2974: $menu_html.='<p>';
2975: $menu_html.='<font size="+1">';
2976: if (exists($menu_item->{'url'})) {
2977: $menu_html.=qq{<a href="$menu_item->{'url'}">};
2978: } else {
2979: $menu_html.=
2980: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
2981: }
2982: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
2983: if (exists($menu_item->{'help'})) {
2984: $menu_html.=
2985: &Apache::loncommon::help_open_topic($menu_item->{'help'});
2986: }
2987: $menu_html.='</p>';
2988: }
2989: return $menu_html;
2990: }
2991:
1.189 albertel 2992: sub restore_prev_selections {
2993: my %saveable_parameters = ('srchby' => 'scalar',
2994: 'srchin' => 'scalar',
2995: 'srchtype' => 'scalar',
2996: );
2997: &Apache::loncommon::store_settings('user','user_picker',
2998: \%saveable_parameters);
2999: &Apache::loncommon::restore_settings('user','user_picker',
3000: \%saveable_parameters);
3001: }
3002:
1.27 matthew 3003: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 3004: sub user_search_result {
3005: my ($srch) = @_;
3006: my %allhomes;
3007: my %inst_matches;
3008: my %srch_results;
1.181 raeburn 3009: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 3010: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 3011: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 3012: $response = &mt('Invalid search.');
3013: }
3014: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
3015: $response = &mt('Invalid search.');
3016: }
1.177 raeburn 3017: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 3018: $response = &mt('Invalid search.');
3019: }
3020: if ($srch->{'srchterm'} eq '') {
3021: $response = &mt('You must enter a search term.');
3022: }
1.183 raeburn 3023: if ($srch->{'srchterm'} =~ /^\s+$/) {
3024: $response = &mt('Your search term must contain more than just spaces.');
3025: }
1.160 raeburn 3026: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
3027: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 3028: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 3029: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
3030: }
3031: }
3032: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
3033: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 3034: if ($srch->{'srchby'} eq 'uname') {
3035: if ($srch->{'srchterm'} !~ /^$match_username$/) {
3036: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
3037: }
1.160 raeburn 3038: }
3039: }
1.180 raeburn 3040: if ($response ne '') {
3041: $response = '<span class="LC_warning">'.$response.'</span>';
3042: }
1.160 raeburn 3043: if ($srch->{'srchin'} eq 'instd') {
3044: my $instd_chk = &directorysrch_check($srch);
3045: if ($instd_chk ne 'ok') {
1.180 raeburn 3046: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
3047: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 3048: }
3049: }
3050: if ($response ne '') {
1.180 raeburn 3051: return ($currstate,$response);
1.160 raeburn 3052: }
3053: if ($srch->{'srchby'} eq 'uname') {
3054: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
3055: if ($env{'form.forcenew'}) {
3056: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
3057: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3058: if ($uhome eq 'no_host') {
3059: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 3060: my $showdom = &display_domain_info($env{'request.role.domain'});
3061: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 3062: } else {
1.179 raeburn 3063: $currstate = 'modify';
1.160 raeburn 3064: }
3065: } else {
1.179 raeburn 3066: $currstate = 'modify';
1.160 raeburn 3067: }
3068: } else {
3069: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 3070: if ($srch->{'srchtype'} eq 'exact') {
3071: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3072: if ($uhome eq 'no_host') {
1.179 raeburn 3073: ($currstate,$response,$forcenewuser) =
1.162 raeburn 3074: &build_search_response($srch,%srch_results);
3075: } else {
1.179 raeburn 3076: $currstate = 'modify';
1.162 raeburn 3077: }
3078: } else {
3079: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3080: ($currstate,$response,$forcenewuser) =
1.160 raeburn 3081: &build_search_response($srch,%srch_results);
3082: }
3083: } else {
1.167 albertel 3084: my $courseusers = &get_courseusers();
1.162 raeburn 3085: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 3086: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 3087: $currstate = 'modify';
1.162 raeburn 3088: } else {
1.179 raeburn 3089: ($currstate,$response,$forcenewuser) =
1.162 raeburn 3090: &build_search_response($srch,%srch_results);
3091: }
1.160 raeburn 3092: } else {
1.167 albertel 3093: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 3094: my ($cuname,$cudomain) = split(/:/,$user);
3095: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 3096: my $matched = 0;
3097: if ($srch->{'srchtype'} eq 'begins') {
3098: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
3099: $matched = 1;
3100: }
3101: } else {
3102: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
3103: $matched = 1;
3104: }
3105: }
3106: if ($matched) {
1.167 albertel 3107: $srch_results{$user} =
3108: {&Apache::lonnet::get('environment',
3109: ['firstname',
3110: 'lastname',
1.194 albertel 3111: 'permanentemail'],
3112: $cudomain,$cuname)};
1.162 raeburn 3113: }
3114: }
3115: }
1.179 raeburn 3116: ($currstate,$response,$forcenewuser) =
1.160 raeburn 3117: &build_search_response($srch,%srch_results);
3118: }
3119: }
3120: }
3121: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3122: $currstate = 'query';
1.160 raeburn 3123: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3124: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3125: if ($dirsrchres eq 'ok') {
3126: ($currstate,$response,$forcenewuser) =
3127: &build_search_response($srch,%srch_results);
3128: } else {
3129: my $showdom = &display_domain_info($srch->{'srchdomain'});
3130: $response = '<span class="LC_warning">'.
3131: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3132: '</span><br />'.
3133: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3134: '<br /><br />';
3135: }
1.160 raeburn 3136: }
3137: } else {
3138: if ($srch->{'srchin'} eq 'dom') {
3139: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3140: ($currstate,$response,$forcenewuser) =
1.160 raeburn 3141: &build_search_response($srch,%srch_results);
3142: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 3143: my $courseusers = &get_courseusers();
3144: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 3145: my ($uname,$udom) = split(/:/,$user);
3146: my %names = &Apache::loncommon::getnames($uname,$udom);
3147: my %emails = &Apache::loncommon::getemails($uname,$udom);
3148: if ($srch->{'srchby'} eq 'lastname') {
3149: if ((($srch->{'srchtype'} eq 'exact') &&
3150: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 3151: (($srch->{'srchtype'} eq 'begins') &&
3152: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 3153: (($srch->{'srchtype'} eq 'contains') &&
3154: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
3155: $srch_results{$user} = {firstname => $names{'firstname'},
3156: lastname => $names{'lastname'},
3157: permanentemail => $emails{'permanentemail'},
3158: };
3159: }
3160: } elsif ($srch->{'srchby'} eq 'lastfirst') {
3161: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 3162: $srchlast =~ s/\s+$//;
3163: $srchfirst =~ s/^\s+//;
1.160 raeburn 3164: if ($srch->{'srchtype'} eq 'exact') {
3165: if (($names{'lastname'} eq $srchlast) &&
3166: ($names{'firstname'} eq $srchfirst)) {
3167: $srch_results{$user} = {firstname => $names{'firstname'},
3168: lastname => $names{'lastname'},
3169: permanentemail => $emails{'permanentemail'},
3170:
3171: };
3172: }
1.177 raeburn 3173: } elsif ($srch->{'srchtype'} eq 'begins') {
3174: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
3175: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
3176: $srch_results{$user} = {firstname => $names{'firstname'},
3177: lastname => $names{'lastname'},
3178: permanentemail => $emails{'permanentemail'},
3179: };
3180: }
3181: } else {
1.160 raeburn 3182: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
3183: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
3184: $srch_results{$user} = {firstname => $names{'firstname'},
3185: lastname => $names{'lastname'},
3186: permanentemail => $emails{'permanentemail'},
3187: };
3188: }
3189: }
3190: }
3191: }
1.179 raeburn 3192: ($currstate,$response,$forcenewuser) =
1.160 raeburn 3193: &build_search_response($srch,%srch_results);
3194: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3195: $currstate = 'query';
1.160 raeburn 3196: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3197: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3198: if ($dirsrchres eq 'ok') {
3199: ($currstate,$response,$forcenewuser) =
3200: &build_search_response($srch,%srch_results);
3201: } else {
3202: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
3203: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3204: '</span><br />'.
3205: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3206: '<br /><br />';
3207: }
1.160 raeburn 3208: }
3209: }
1.179 raeburn 3210: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 3211: }
3212:
3213: sub directorysrch_check {
3214: my ($srch) = @_;
3215: my $can_search = 0;
3216: my $response;
3217: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
3218: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 3219: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 3220: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
3221: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 3222: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 3223: }
3224: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
3225: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 3226: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 3227: }
3228: my @usertypes = split(/:/,$env{'environment.inststatus'});
3229: if (!@usertypes) {
3230: push(@usertypes,'default');
3231: }
3232: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
3233: foreach my $type (@usertypes) {
3234: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
3235: $can_search = 1;
3236: last;
3237: }
3238: }
3239: }
3240: if (!$can_search) {
3241: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
3242: my @longtypes;
3243: foreach my $item (@usertypes) {
3244: push (@longtypes,$insttypes->{$item});
3245: }
3246: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 3247: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.160 raeburn 3248: }
3249: } else {
3250: $can_search = 1;
3251: }
3252: } else {
1.180 raeburn 3253: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 3254: }
3255: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 3256: uname => 'username',
1.160 raeburn 3257: lastfirst => 'last name, first name',
1.167 albertel 3258: lastname => 'last name',
1.172 raeburn 3259: contains => 'contains',
1.178 raeburn 3260: exact => 'as exact match to',
3261: begins => 'begins with',
1.160 raeburn 3262: );
3263: if ($can_search) {
3264: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
3265: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 3266: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 3267: }
3268: } else {
1.180 raeburn 3269: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 3270: }
3271: }
3272: if ($can_search) {
1.178 raeburn 3273: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
3274: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
3275: return 'ok';
3276: } else {
1.180 raeburn 3277: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3278: }
3279: } else {
3280: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
3281: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
3282: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
3283: return 'ok';
3284: } else {
1.180 raeburn 3285: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3286: }
1.160 raeburn 3287: }
3288: }
3289: }
3290:
3291: sub get_courseusers {
3292: my %advhash;
1.167 albertel 3293: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 3294: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
3295: foreach my $role (sort(keys(%coursepersonnel))) {
3296: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 3297: if (!exists($classlist->{$user})) {
3298: $classlist->{$user} = [];
3299: }
1.160 raeburn 3300: }
3301: }
1.167 albertel 3302: return $classlist;
1.160 raeburn 3303: }
3304:
3305: sub build_search_response {
3306: my ($srch,%srch_results) = @_;
1.179 raeburn 3307: my ($currstate,$response,$forcenewuser);
1.160 raeburn 3308: my %names = (
3309: 'uname' => 'username',
3310: 'lastname' => 'last name',
3311: 'lastfirst' => 'last name, first name',
3312: 'crs' => 'this course',
1.180 raeburn 3313: 'dom' => 'LON-CAPA domain: ',
3314: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 3315: );
3316:
3317: my %single = (
1.180 raeburn 3318: begins => 'A match',
1.160 raeburn 3319: contains => 'A match',
1.180 raeburn 3320: exact => 'An exact match',
1.160 raeburn 3321: );
3322: my %nomatch = (
1.180 raeburn 3323: begins => 'No match',
1.160 raeburn 3324: contains => 'No match',
1.180 raeburn 3325: exact => 'No exact match',
1.160 raeburn 3326: );
3327: if (keys(%srch_results) > 1) {
1.179 raeburn 3328: $currstate = 'select';
1.160 raeburn 3329: } else {
3330: if (keys(%srch_results) == 1) {
1.179 raeburn 3331: $currstate = 'modify';
1.180 raeburn 3332: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
3333: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3334: $response .= &display_domain_info($srch->{'srchdomain'});
3335: }
1.160 raeburn 3336: } else {
1.180 raeburn 3337: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
3338: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3339: $response .= &display_domain_info($srch->{'srchdomain'});
3340: }
3341: $response .= '</span>';
1.160 raeburn 3342: if ($srch->{'srchin'} ne 'alc') {
3343: $forcenewuser = 1;
3344: my $cansrchinst = 0;
3345: if ($srch->{'srchdomain'}) {
3346: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
3347: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3348: if ($domconfig{'directorysrch'}{'available'}) {
3349: $cansrchinst = 1;
3350: }
3351: }
3352: }
1.180 raeburn 3353: if ((($srch->{'srchby'} eq 'lastfirst') ||
3354: ($srch->{'srchby'} eq 'lastname')) &&
3355: ($srch->{'srchin'} eq 'dom')) {
3356: if ($cansrchinst) {
3357: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 3358: }
3359: }
1.180 raeburn 3360: if ($srch->{'srchin'} eq 'crs') {
3361: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
3362: }
3363: }
3364: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.182 raeburn 3365: my $showdom = &display_domain_info($env{'request.role.domain'});
3366: $response .= '<br /><br />'.&mt("<b>To add a new user</b> (you can only create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>):",$env{'request.role.domain'}).'<ul><li>'.&mt("Set 'Domain/institution to search' to: <span class=\"LC_cusr_emph\">[_1]</span>",$showdom).'<li>'.&mt("Set 'Search criteria' to: <span class=\"LC_cusr_emph\">'username is ...... in selected LON-CAPA domain'").'</span></li><li>'.&mt('Provide the proposed username').'</li><li>'.&mt('Search').'</li></ul><br />';
1.160 raeburn 3367: }
3368: }
3369: }
1.179 raeburn 3370: return ($currstate,$response,$forcenewuser);
1.160 raeburn 3371: }
3372:
1.180 raeburn 3373: sub display_domain_info {
3374: my ($dom) = @_;
3375: my $output = $dom;
3376: if ($dom ne '') {
3377: my $domdesc = &Apache::lonnet::domain($dom,'description');
3378: if ($domdesc ne '') {
3379: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
3380: }
3381: }
3382: return $output;
3383: }
3384:
1.160 raeburn 3385: sub crumb_utilities {
3386: my %elements = (
3387: crtuser => {
3388: srchterm => 'text',
1.172 raeburn 3389: srchin => 'selectbox',
1.160 raeburn 3390: srchby => 'selectbox',
3391: srchtype => 'selectbox',
3392: srchdomain => 'selectbox',
3393: },
1.207 raeburn 3394: crtusername => {
3395: srchterm => 'text',
3396: srchdomain => 'selectbox',
3397: },
1.160 raeburn 3398: docustom => {
3399: rolename => 'selectbox',
3400: newrolename => 'textbox',
3401: },
1.179 raeburn 3402: studentform => {
3403: srchterm => 'text',
3404: srchin => 'selectbox',
3405: srchby => 'selectbox',
3406: srchtype => 'selectbox',
3407: srchdomain => 'selectbox',
3408: },
1.160 raeburn 3409: );
3410:
3411: my $jsback .= qq|
3412: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 3413: if (typeof prevphase == 'undefined') {
3414: formname.phase.value = '';
3415: }
3416: else {
3417: formname.phase.value = prevphase;
3418: }
3419: if (typeof prevstate == 'undefined') {
3420: formname.currstate.value = '';
3421: }
3422: else {
3423: formname.currstate.value = prevstate;
3424: }
1.160 raeburn 3425: formname.submit();
3426: }
3427: |;
3428: return ($jsback,\%elements);
3429: }
3430:
1.26 matthew 3431: sub course_level_table {
1.89 raeburn 3432: my (%inccourses) = @_;
1.26 matthew 3433: my $table = '';
1.62 www 3434: # Custom Roles?
3435:
1.190 raeburn 3436: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 3437: my %lt=&Apache::lonlocal::texthash(
3438: 'exs' => "Existing sections",
3439: 'new' => "Define new section",
3440: 'ssd' => "Set Start Date",
3441: 'sed' => "Set End Date",
1.131 raeburn 3442: 'crl' => "Course Level",
1.89 raeburn 3443: 'act' => "Activate",
3444: 'rol' => "Role",
3445: 'ext' => "Extent",
1.113 raeburn 3446: 'grs' => "Section",
1.89 raeburn 3447: 'sta' => "Start",
3448: 'end' => "End"
3449: );
1.62 www 3450:
1.135 raeburn 3451: foreach my $protectedcourse (sort( keys(%inccourses))) {
3452: my $thiscourse=$protectedcourse;
1.26 matthew 3453: $thiscourse=~s:_:/:g;
3454: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
3455: my $area=$coursedata{'description'};
1.119 raeburn 3456: my $type=$coursedata{'type'};
1.135 raeburn 3457: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 3458: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 3459: my %sections_count;
1.101 albertel 3460: if (defined($env{'request.course.id'})) {
3461: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 3462: %sections_count =
3463: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 3464: }
3465: }
1.213 raeburn 3466: my @roles = &Apache::lonuserutils::roles_by_context('course');
3467: foreach my $role (@roles) {
1.135 raeburn 3468: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
3469: my $plrole=&Apache::lonnet::plaintext($role);
1.136 raeburn 3470: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 3471: '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
1.136 raeburn 3472: <td>'.$plrole.'</td>
3473: <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.135 raeburn 3474: if ($role ne 'cc') {
1.115 albertel 3475: if (%sections_count) {
1.202 raeburn 3476: my $currsec =
1.198 raeburn 3477: &Apache::lonuserutils::course_sections(\%sections_count,
1.202 raeburn 3478: $protectedcourse.'_'.$role);
1.89 raeburn 3479: $table .=
1.137 raeburn 3480: '<td><table class="LC_createuser">'.
3481: '<tr class="LC_section_row">
3482: <td valign="top">'.$lt{'exs'}.'<br />'.
1.89 raeburn 3483: $currsec.'</td>'.
3484: '<td> </td>'.
3485: '<td valign="top"> '.$lt{'new'}.'<br />'.
1.157 albertel 3486: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
1.89 raeburn 3487: '<input type="hidden" '.
1.157 albertel 3488: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
1.89 raeburn 3489: '</tr></table></td>';
3490: } else {
3491: $table .= '<td><input type="text" size="10" '.
1.157 albertel 3492: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
1.89 raeburn 3493: }
1.26 matthew 3494: } else {
1.89 raeburn 3495: $table .= '<td> </td>';
1.26 matthew 3496: }
3497: $table .= <<ENDTIMEENTRY;
1.169 albertel 3498: <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
1.26 matthew 3499: <a href=
1.135 raeburn 3500: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3501: <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
1.26 matthew 3502: <a href=
1.135 raeburn 3503: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 3504: ENDTIMEENTRY
1.136 raeburn 3505: $table.= &Apache::loncommon::end_data_table_row();
1.26 matthew 3506: }
3507: }
1.135 raeburn 3508: foreach my $cust (sort keys %customroles) {
1.65 www 3509: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.135 raeburn 3510: my $plrole=$cust;
1.101 albertel 3511: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
3512: '_'.$env{'user.name'}.'_'.$plrole;
1.136 raeburn 3513: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 3514: '<td><input type="checkbox" name="act_'.$customrole.'" /></td>
1.136 raeburn 3515: <td>'.$plrole.'</td>
3516: <td>'.$area.'</td>'."\n";
1.115 albertel 3517: if (%sections_count) {
1.202 raeburn 3518: my $currsec =
1.198 raeburn 3519: &Apache::lonuserutils::course_sections(\%sections_count,
3520: $customrole);
1.89 raeburn 3521: $table.=
1.188 raeburn 3522: '<td><table class="LC_createuser">'.
3523: '<tr class="LC_section_row"><td valign="top">'.
3524: $lt{'exs'}.'<br />'.$currsec.'</td>'.
1.89 raeburn 3525: '<td> </td>'.
3526: '<td valign="top"> '.$lt{'new'}.'<br />'.
3527: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
3528: '<input type="hidden" '.
1.157 albertel 3529: 'name="sec_'.$customrole.'" /></td>'.
1.89 raeburn 3530: '</tr></table></td>';
3531: } else {
3532: $table .= '<td><input type="text" size="10" '.
1.157 albertel 3533: 'name="sec_'.$customrole.'" /></td>';
1.89 raeburn 3534: }
3535: $table .= <<ENDENTRY;
1.169 albertel 3536: <td><input type="hidden" name="start_$customrole" value='' />
1.62 www 3537: <a href=
1.73 sakharuk 3538: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3539: <td><input type="hidden" name="end_$customrole" value='' />
1.62 www 3540: <a href=
1.136 raeburn 3541: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
1.62 www 3542: ENDENTRY
1.136 raeburn 3543: $table .= &Apache::loncommon::end_data_table_row();
1.65 www 3544: }
1.62 www 3545: }
1.26 matthew 3546: }
3547: return '' if ($table eq ''); # return nothing if there is nothing
3548: # in the table
1.188 raeburn 3549: my $result;
3550: if (!$env{'request.course.id'}) {
3551: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
3552: }
3553: $result .=
1.136 raeburn 3554: &Apache::loncommon::start_data_table().
3555: &Apache::loncommon::start_data_table_header_row().
3556: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
3557: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
3558: &Apache::loncommon::end_data_table_header_row().
3559: $table.
3560: &Apache::loncommon::end_data_table();
1.26 matthew 3561: return $result;
3562: }
1.88 raeburn 3563:
3564: sub course_level_dc {
3565: my ($dcdom) = @_;
1.190 raeburn 3566: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 3567: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 3568: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
3569: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 3570: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 3571: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 3572: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
3573: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 3574: my %lt=&Apache::lonlocal::texthash(
3575: 'rol' => "Role",
1.113 raeburn 3576: 'grs' => "Section",
1.88 raeburn 3577: 'exs' => "Existing sections",
3578: 'new' => "Define new section",
3579: 'sta' => "Start",
3580: 'end' => "End",
3581: 'ssd' => "Set Start Date",
3582: 'sed' => "Set End Date"
3583: );
1.131 raeburn 3584: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 3585: &Apache::loncommon::start_data_table().
3586: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 3587: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 3588: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 3589: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 3590: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 3591: '<td><select name="role">'."\n";
1.213 raeburn 3592: foreach my $role (@roles) {
1.135 raeburn 3593: my $plrole=&Apache::lonnet::plaintext($role);
3594: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 3595: }
3596: if ( keys %customroles > 0) {
1.135 raeburn 3597: foreach my $cust (sort keys %customroles) {
1.101 albertel 3598: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 3599: '_'.$env{'user.name'}.'_'.$cust;
3600: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 3601: }
3602: }
3603: $otheritems .= '</select></td><td>'.
3604: '<table border="0" cellspacing="0" cellpadding="0">'.
3605: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
3606: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
3607: '<td> </td>'.
3608: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 3609: '<input type="text" name="newsec" value="" />'.
3610: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 3611: '</tr></table></td>';
3612: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 3613: <td><input type="hidden" name="start" value='' />
1.88 raeburn 3614: <a href=
3615: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3616: <td><input type="hidden" name="end" value='' />
1.88 raeburn 3617: <a href=
3618: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
3619: ENDTIMEENTRY
1.136 raeburn 3620: $otheritems .= &Apache::loncommon::end_data_table_row().
3621: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 3622: return $cb_jscript.$header.$hiddenitems.$otheritems;
3623: }
3624:
1.27 matthew 3625: #---------------------------------------------- end functions for &phase_two
1.29 matthew 3626:
3627: #--------------------------------- functions for &phase_two and &phase_three
3628:
3629: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 3630:
3631: 1;
3632: __END__
1.2 www 3633:
3634:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>