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