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