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