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