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