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