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