Annotation of loncom/interface/loncreateuser.pm, revision 1.203
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.203 ! raeburn 4: # $Id: loncreateuser.pm,v 1.202 2007/12/05 21:23:14 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') {
1.203 ! raeburn 790: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 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.203 ! 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 (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 ! raeburn 1601: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
! 1602: $env{'form.ccuname'});
! 1603: if (($uidhash{$env{'form.ccuname'}}) &&
! 1604: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
! 1605: (!$forceid)) {
! 1606: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
! 1607: $env{'form.cid'} = $userenv{'id'};
! 1608: }
! 1609: }
! 1610: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1611: my $checkhash;
1612: my $checks = { 'id' => 1 };
1613: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1614: { 'newuser' => $newuser,
1615: 'id' => $env{'form.cid'},
1616: };
1617: &Apache::loncommon::user_rule_check($checkhash,$checks,
1618: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1619: if (ref($alerts{'id'}) eq 'HASH') {
1620: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 ! raeburn 1621: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1622: }
1623: }
1624: }
1.149 raeburn 1625: my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
1626: $inststatus,$isdefault,$defquotatext);
1627: my ($defquota,$settingstatus) =
1628: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.134 raeburn 1629: my %changeHash;
1.149 raeburn 1630: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1631: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1632: if ($env{'form.customquota'} == 1) {
1633: if ($env{'form.portfolioquota'} eq '') {
1634: $newportfolioquota = 0;
1635: } else {
1636: $newportfolioquota = $env{'form.portfolioquota'};
1637: $newportfolioquota =~ s/[^\d\.]//g;
1638: }
1639: if ($newportfolioquota != $userenv{'portfolioquota'}) {
1640: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1641: }
1.149 raeburn 1642: } else {
1643: $quotachanged = "a_admin('',\%changeHash);
1644: $newportfolioquota = $defquota;
1645: $isdefault = 1;
1.134 raeburn 1646: }
1647: } else {
1.149 raeburn 1648: $oldportfolioquota = $defquota;
1649: if ($env{'form.customquota'} == 1) {
1650: if ($env{'form.portfolioquota'} eq '') {
1651: $newportfolioquota = 0;
1652: } else {
1653: $newportfolioquota = $env{'form.portfolioquota'};
1654: $newportfolioquota =~ s/[^\d\.]//g;
1655: }
1656: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1657: } else {
1658: $newportfolioquota = $defquota;
1659: $isdefault = 1;
1660: }
1661: }
1662: if ($isdefault) {
1663: if ($settingstatus eq '') {
1664: $defquotatext = &mt('(default)');
1665: } else {
1666: my ($usertypes,$order) =
1667: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
1668: if ($usertypes->{$settingstatus} eq '') {
1669: $defquotatext = &mt('(default)');
1670: } else {
1671: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
1672: }
1673: }
1.134 raeburn 1674: }
1.101 albertel 1675: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1676: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1677: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1678: $env{'form.clastname'} ne $userenv{'lastname'} ||
1.160 raeburn 1679: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1.196 raeburn 1680: $env{'form.cid'} ne $userenv{'id'} ||
1.160 raeburn 1681: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
1.134 raeburn 1682: $namechanged = 1;
1683: }
1684: if ($namechanged) {
1.28 matthew 1685: # Make the change
1.101 albertel 1686: $changeHash{'firstname'} = $env{'form.cfirstname'};
1687: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1688: $changeHash{'lastname'} = $env{'form.clastname'};
1689: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1690: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1691: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.28 matthew 1692: my $putresult = &Apache::lonnet::put
1693: ('environment',\%changeHash,
1.101 albertel 1694: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1695: if ($putresult eq 'ok') {
1696: # Tell the user we changed the name
1.73 sakharuk 1697: my %lt=&Apache::lonlocal::texthash(
1698: 'uic' => "User Information Changed",
1699: 'frst' => "first",
1700: 'mddl' => "middle",
1701: 'lst' => "last",
1702: 'gen' => "generation",
1.196 raeburn 1703: 'id' => "ID/Student number",
1.160 raeburn 1704: 'mail' => "permanent e-mail",
1.134 raeburn 1705: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1706: 'prvs' => "Previous",
1707: 'chto' => "Changed To"
1708: );
1.201 raeburn 1709: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1710: &Apache::loncommon::start_data_table().
1711: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1712: $r->print(<<"END");
1.201 raeburn 1713: <th> </th>
1.73 sakharuk 1714: <th>$lt{'frst'}</th>
1715: <th>$lt{'mddl'}</th>
1716: <th>$lt{'lst'}</th>
1.134 raeburn 1717: <th>$lt{'gen'}</th>
1.196 raeburn 1718: <th>$lt{'id'}</th>
1.173 raeburn 1719: <th>$lt{'mail'}</th>
1.201 raeburn 1720: <th>$lt{'disk'}</th>
1721: END
1722: $r->print(&Apache::loncommon::end_data_table_header_row().
1723: &Apache::loncommon::start_data_table_row());
1724: $r->print(<<"END");
1725: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 1726: <td>$userenv{'firstname'} </td>
1727: <td>$userenv{'middlename'} </td>
1728: <td>$userenv{'lastname'} </td>
1.134 raeburn 1729: <td>$userenv{'generation'} </td>
1.196 raeburn 1730: <td>$userenv{'id'}</td>
1.160 raeburn 1731: <td>$userenv{'permanentemail'} </td>
1.149 raeburn 1732: <td>$oldportfolioquota Mb</td>
1.201 raeburn 1733: END
1734: $r->print(&Apache::loncommon::end_data_table_row().
1735: &Apache::loncommon::start_data_table_row());
1736: $r->print(<<"END");
1737: <td><b>$lt{'chto'}</b></td>
1.101 albertel 1738: <td>$env{'form.cfirstname'} </td>
1739: <td>$env{'form.cmiddlename'} </td>
1740: <td>$env{'form.clastname'} </td>
1.134 raeburn 1741: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 1742: <td>$env{'form.cid'} </td>
1.160 raeburn 1743: <td>$env{'form.cpermanentemail'} </td>
1.201 raeburn 1744: <td>$newportfolioquota Mb $defquotatext </td>
1.28 matthew 1745: END
1.201 raeburn 1746: $r->print(&Apache::loncommon::end_data_table_row().
1747: &Apache::loncommon::end_data_table());
1.203 ! raeburn 1748: if ($env{'form.cid'} ne $userenv{'id'}) {
! 1749: &Apache::lonnet::idput($env{'form.ccdomain'},
! 1750: ($env{'form.ccuname'} => $env{'form.cid'}));
! 1751: if (($recurseid) &&
! 1752: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
! 1753: my %userupdate = (
1.196 raeburn 1754: lastname => $env{'form.clasaname'},
1755: middlename => $env{'form.cmiddlename'},
1756: firstname => $env{'form.cfirstname'},
1757: generation => $env{'fora.cgeneration'},
1758: id => $env{'form.cid'},
1759: );
1.203 ! raeburn 1760: my $idresult =
! 1761: &Apache::lonuserutils::propagate_id_change(
! 1762: $env{'form.ccuname'},$env{'form.ccdomain'},
! 1763: \%userupdate);
! 1764: $r->print('<br />'.$idresult.'<br />');
! 1765: }
1.196 raeburn 1766: }
1.149 raeburn 1767: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1768: ($env{'form.ccuname'} eq $env{'user.name'})) {
1769: my %newenvhash;
1770: foreach my $key (keys(%changeHash)) {
1771: $newenvhash{'environment.'.$key} = $changeHash{$key};
1772: }
1773: &Apache::lonnet::appenv(%newenvhash);
1774: }
1.28 matthew 1775: } else { # error occurred
1.188 raeburn 1776: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
1777: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1778: $env{'form.ccdomain'}.'</span>');
1.28 matthew 1779: }
1.101 albertel 1780: } else { # End of if ($env ... ) logic
1.134 raeburn 1781: my $putresult;
1782: if ($quotachanged) {
1783: $putresult = &Apache::lonnet::put
1784: ('environment',\%changeHash,
1785: $env{'form.ccdomain'},$env{'form.ccuname'});
1786: }
1.28 matthew 1787: # They did not want to change the users name but we can
1788: # still tell them what the name is
1.73 sakharuk 1789: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 1790: 'id' => "ID/Student number",
1.160 raeburn 1791: 'mail' => "Permanent e-mail",
1.134 raeburn 1792: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 1793: );
1.134 raeburn 1794: $r->print(<<"END");
1.196 raeburn 1795: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 1796: END
1.196 raeburn 1797: if ($userenv{'permanentemail'} eq '') {
1798: $r->print('</h4>');
1799: } else {
1800: $r->print(' ('.$lt{'mail'}.': '.
1801: $userenv{'permanentemail'}.')</h4>');
1802: }
1.134 raeburn 1803: if ($putresult eq 'ok') {
1.149 raeburn 1804: if ($oldportfolioquota != $newportfolioquota) {
1805: $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
1806: $defquotatext.'</h4>');
1807: &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
1.134 raeburn 1808: }
1809: }
1.28 matthew 1810: }
1.4 www 1811: }
1.27 matthew 1812: ##
1.4 www 1813: my $now=time;
1.193 raeburn 1814: my $rolechanges = 0;
1.73 sakharuk 1815: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 1816: foreach my $key (keys (%env)) {
1817: next if (! $env{$key});
1.190 raeburn 1818: next if ($key eq 'form.action');
1.27 matthew 1819: # Revoke roles
1.135 raeburn 1820: if ($key=~/^form\.rev/) {
1821: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 1822: # Revoke standard role
1.170 albertel 1823: my ($scope,$role) = ($1,$2);
1824: my $result =
1825: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1826: $env{'form.ccuname'},
1827: $scope,$role);
1828: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
1829: $role,$scope,'<b>'.$result.'</b>').'<br />');
1830: if ($role eq 'st') {
1.202 raeburn 1831: my $result =
1.198 raeburn 1832: &Apache::lonuserutils::classlist_drop($scope,
1833: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 1834: $now);
1.170 albertel 1835: $r->print($result);
1.53 www 1836: }
1.196 raeburn 1837: }
1.195 raeburn 1838: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 1839: # Revoke custom role
1.113 raeburn 1840: $r->print(&mt('Revoking custom role:').
1.139 albertel 1841: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 1842: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1843: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 1844: '</b><br />');
1.64 www 1845: }
1.193 raeburn 1846: $rolechanges ++;
1.135 raeburn 1847: } elsif ($key=~/^form\.del/) {
1848: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 1849: # Delete standard role
1.170 albertel 1850: my ($scope,$role) = ($1,$2);
1851: my $result =
1852: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1853: $env{'form.ccuname'},
1854: $scope,$role,$now,0,1);
1855: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
1856: '<b>'.$result.'</b>').'<br />');
1857: if ($role eq 'st') {
1.202 raeburn 1858: my $result =
1.198 raeburn 1859: &Apache::lonuserutils::classlist_drop($scope,
1860: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 1861: $now);
1.170 albertel 1862: $r->print($result);
1.81 albertel 1863: }
1.116 raeburn 1864: }
1.139 albertel 1865: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 1866: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1867: # Delete custom role
1.170 albertel 1868: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 1869: $rolename,$rnam,$rdom,$url).': <b>'.
1870: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1871: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1872: 0,1).'</b><br />');
1873: }
1.193 raeburn 1874: $rolechanges ++;
1.135 raeburn 1875: } elsif ($key=~/^form\.ren/) {
1.101 albertel 1876: my $udom = $env{'form.ccdomain'};
1877: my $uname = $env{'form.ccuname'};
1.116 raeburn 1878: # Re-enable standard role
1.135 raeburn 1879: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 1880: my $url = $1;
1881: my $role = $2;
1882: my $logmsg;
1883: my $output;
1884: if ($role eq 'st') {
1.141 albertel 1885: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 1886: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 1887: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1888: $output = "Error: $result\n";
1889: } else {
1890: $output = &mt('Assigning').' '.$role.' in '.$url.
1891: &mt('starting').' '.localtime($now).
1892: ': <br />'.$logmsg.'<br />'.
1893: &mt('Add to classlist').': <b>ok</b><br />';
1894: }
1895: }
1896: } else {
1.101 albertel 1897: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1898: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 1899: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 1900: $role,$url,$result).'<br />';
1.27 matthew 1901: }
1.89 raeburn 1902: $r->print($output);
1.113 raeburn 1903: }
1.116 raeburn 1904: # Re-enable custom role
1.139 albertel 1905: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 1906: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1907: my $result = &Apache::lonnet::assigncustomrole(
1908: $env{'form.ccdomain'}, $env{'form.ccuname'},
1909: $url,$rdom,$rnam,$rolename,0,$now);
1910: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1911: $rolename,$rnam,$rdom,$url,$result).'<br />');
1912: }
1.193 raeburn 1913: $rolechanges ++;
1.135 raeburn 1914: } elsif ($key=~/^form\.act/) {
1.101 albertel 1915: my $udom = $env{'form.ccdomain'};
1916: my $uname = $env{'form.ccuname'};
1.141 albertel 1917: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 1918: # Activate a custom role
1.83 albertel 1919: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1920: my $url='/'.$one.'/'.$two;
1921: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 1922:
1.101 albertel 1923: my $start = ( $env{'form.start_'.$full} ?
1924: $env{'form.start_'.$full} :
1.88 raeburn 1925: $now );
1.101 albertel 1926: my $end = ( $env{'form.end_'.$full} ?
1927: $env{'form.end_'.$full} :
1.88 raeburn 1928: 0 );
1929:
1930: # split multiple sections
1931: my %sections = ();
1.101 albertel 1932: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 1933: if ($num_sections == 0) {
1.129 albertel 1934: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 1935: } else {
1.114 albertel 1936: my %curr_groups =
1.117 raeburn 1937: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 1938: foreach my $sec (sort {$a cmp $b} keys %sections) {
1939: if (($sec eq 'none') || ($sec eq 'all') ||
1940: exists($curr_groups{$sec})) {
1941: $disallowed{$sec} = $url;
1942: next;
1943: }
1944: my $securl = $url.'/'.$sec;
1.129 albertel 1945: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 1946: }
1947: }
1.142 raeburn 1948: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 1949: # Activate roles for sections with 3 id numbers
1950: # set start, end times, and the url for the class
1.83 albertel 1951: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 1952: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1953: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1954: $now );
1.101 albertel 1955: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1956: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1957: 0 );
1.83 albertel 1958: my $url='/'.$one.'/'.$two;
1.88 raeburn 1959: my $type = 'three';
1960: # split multiple sections
1961: my %sections = ();
1.101 albertel 1962: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 1963: if ($num_sections == 0) {
1.129 albertel 1964: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1965: } else {
1.114 albertel 1966: my %curr_groups =
1.117 raeburn 1967: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 1968: my $emptysec = 0;
1969: foreach my $sec (sort {$a cmp $b} keys %sections) {
1970: $sec =~ s/\W//g;
1.113 raeburn 1971: if ($sec ne '') {
1972: if (($sec eq 'none') || ($sec eq 'all') ||
1973: exists($curr_groups{$sec})) {
1974: $disallowed{$sec} = $url;
1975: next;
1976: }
1.88 raeburn 1977: my $securl = $url.'/'.$sec;
1.129 albertel 1978: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 1979: } else {
1980: $emptysec = 1;
1981: }
1982: }
1983: if ($emptysec) {
1.129 albertel 1984: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1985: }
1986: }
1.135 raeburn 1987: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 1988: # Activate roles for sections with two id numbers
1989: # set start, end times, and the url for the class
1.101 albertel 1990: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1991: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 1992: $now );
1.101 albertel 1993: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1994: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 1995: 0 );
1996: my $url='/'.$1.'/';
1.88 raeburn 1997: # split multiple sections
1998: my %sections = ();
1.101 albertel 1999: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 2000: if ($num_sections == 0) {
1.129 albertel 2001: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 2002: } else {
2003: my $emptysec = 0;
2004: foreach my $sec (sort {$a cmp $b} keys %sections) {
2005: if ($sec ne '') {
2006: my $securl = $url.'/'.$sec;
1.129 albertel 2007: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 2008: } else {
2009: $emptysec = 1;
2010: }
2011: }
2012: if ($emptysec) {
1.129 albertel 2013: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 2014: }
2015: }
1.64 www 2016: } else {
1.190 raeburn 2017: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2018: }
1.113 raeburn 2019: foreach my $key (sort(keys(%disallowed))) {
2020: if (($key eq 'none') || ($key eq 'all')) {
2021: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2022: } else {
2023: $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));
2024: }
2025: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2026: }
1.193 raeburn 2027: $rolechanges ++;
1.113 raeburn 2028: }
1.101 albertel 2029: } # End of foreach (keys(%env))
1.75 www 2030: # Flush the course logs so reverse user roles immediately updated
2031: &Apache::lonnet::flushcourselogs();
1.193 raeburn 2032: if (!$rolechanges) {
2033: $r->print(&mt('No roles to modify'));
2034: }
1.188 raeburn 2035: $r->print(&Apache::loncommon::end_page());
2036: }
2037:
2038: sub update_result_form {
2039: my ($uhome) = @_;
2040: my $outcome =
2041: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2042: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2043: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2044: }
2045: foreach my $item ('sortby','seluname','seludom') {
2046: if (exists($env{'form.'.$item})) {
1.188 raeburn 2047: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2048: }
2049: }
1.188 raeburn 2050: if ($uhome eq 'no_host') {
2051: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2052: }
2053: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2054: '<input type ="hidden" name="currstate" value="" />'."\n".
1.190 raeburn 2055: '<input type ="hidden" name="action" value="singleuser" />'."\n".
1.188 raeburn 2056: '</form>';
2057: return $outcome;
1.4 www 2058: }
2059:
1.149 raeburn 2060: sub quota_admin {
2061: my ($setquota,$changeHash) = @_;
2062: my $quotachanged;
2063: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2064: # Current user has quota modification privileges
2065: $quotachanged = 1;
2066: $changeHash->{'portfolioquota'} = $setquota;
2067: }
2068: return $quotachanged;
2069: }
2070:
1.88 raeburn 2071: sub build_roles {
1.89 raeburn 2072: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2073: my $num_sections = 0;
2074: if ($sectionstr=~ /,/) {
2075: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2076: if ($role eq 'st') {
2077: $secnums[0] =~ s/\W//g;
2078: $$sections{$secnums[0]} = 1;
2079: $num_sections = 1;
2080: } else {
2081: foreach my $sec (@secnums) {
2082: $sec =~ ~s/\W//g;
1.150 banghart 2083: if (!($sec eq "")) {
1.89 raeburn 2084: if (exists($$sections{$sec})) {
2085: $$sections{$sec} ++;
2086: } else {
2087: $$sections{$sec} = 1;
2088: $num_sections ++;
2089: }
1.88 raeburn 2090: }
2091: }
2092: }
2093: } else {
2094: $sectionstr=~s/\W//g;
2095: unless ($sectionstr eq '') {
2096: $$sections{$sectionstr} = 1;
2097: $num_sections ++;
2098: }
2099: }
1.129 albertel 2100:
1.88 raeburn 2101: return $num_sections;
2102: }
2103:
1.58 www 2104: # ========================================================== Custom Role Editor
2105:
2106: sub custom_role_editor {
1.160 raeburn 2107: my ($r) = @_;
1.101 albertel 2108: my $rolename=$env{'form.rolename'};
1.58 www 2109:
1.59 www 2110: if ($rolename eq 'make new role') {
1.101 albertel 2111: $rolename=$env{'form.newrolename'};
1.59 www 2112: }
2113:
1.63 www 2114: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2115:
1.190 raeburn 2116: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2117: &print_username_entry_form($r);
2118: return;
2119: }
1.153 banghart 2120: # ------------------------------------------------------- What can be assigned?
2121: my %full=();
2122: my %courselevel=();
2123: my %courselevelcurrent=();
1.61 www 2124: my $syspriv='';
2125: my $dompriv='';
2126: my $coursepriv='';
1.153 banghart 2127: my $body_top;
1.150 banghart 2128: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2129: my ($rdummy,$roledef)=
2130: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2131: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2132: $body_top .= '<h2>';
1.59 www 2133: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2134: $body_top .= &mt('Existing Role').' "';
1.61 www 2135: # ------------------------------------------------- Get current role privileges
2136: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2137: } else {
1.153 banghart 2138: $body_top .= &mt('New Role').' "';
1.59 www 2139: $roledef='';
2140: }
1.153 banghart 2141: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2142: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2143: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2144: if (!$restrict) { $restrict='F'; }
1.60 www 2145: $courselevel{$priv}=$restrict;
1.61 www 2146: if ($coursepriv=~/\:$priv/) {
2147: $courselevelcurrent{$priv}=1;
2148: }
1.60 www 2149: $full{$priv}=1;
2150: }
2151: my %domainlevel=();
1.61 www 2152: my %domainlevelcurrent=();
1.135 raeburn 2153: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2154: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2155: if (!$restrict) { $restrict='F'; }
1.60 www 2156: $domainlevel{$priv}=$restrict;
1.61 www 2157: if ($dompriv=~/\:$priv/) {
2158: $domainlevelcurrent{$priv}=1;
2159: }
1.60 www 2160: $full{$priv}=1;
2161: }
1.61 www 2162: my %systemlevel=();
2163: my %systemlevelcurrent=();
1.135 raeburn 2164: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2165: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2166: if (!$restrict) { $restrict='F'; }
1.61 www 2167: $systemlevel{$priv}=$restrict;
2168: if ($syspriv=~/\:$priv/) {
2169: $systemlevelcurrent{$priv}=1;
2170: }
2171: $full{$priv}=1;
2172: }
1.160 raeburn 2173: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2174: my $button_code = "\n";
1.153 banghart 2175: my $head_script = "\n";
2176: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2177: my @template_roles = ("cc","in","ta","ep","st");
2178: foreach my $role (@template_roles) {
2179: $head_script .= &make_script_template($role);
2180: $button_code .= &make_button_code($role);
2181: }
1.160 raeburn 2182: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2183: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2184: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2185: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2186: text=>"Pick custom role",
1.160 raeburn 2187: faq=>282,bug=>'Instructor Interface',},
2188: {href=>"javascript:backPage(document.form1,'','')",
2189: text=>"Edit custom role",
2190: faq=>282,bug=>'Instructor Interface',});
2191: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2192:
1.153 banghart 2193: $r->print($body_top);
1.73 sakharuk 2194: my %lt=&Apache::lonlocal::texthash(
2195: 'prv' => "Privilege",
1.131 raeburn 2196: 'crl' => "Course Level",
1.73 sakharuk 2197: 'dml' => "Domain Level",
1.150 banghart 2198: 'ssl' => "System Level");
1.152 banghart 2199: $r->print('Select a Template<br />');
1.154 banghart 2200: $r->print('<form action="">');
2201: $r->print($button_code);
2202: $r->print('</form>');
1.61 www 2203: $r->print(<<ENDCCF);
1.160 raeburn 2204: <form name="form1" method="post">
1.61 www 2205: <input type="hidden" name="phase" value="set_custom_roles" />
2206: <input type="hidden" name="rolename" value="$rolename" />
2207: ENDCCF
1.135 raeburn 2208: $r->print(&Apache::loncommon::start_data_table().
2209: &Apache::loncommon::start_data_table_header_row().
2210: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2211: '</th><th>'.$lt{'ssl'}.'</th>'.
2212: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2213: foreach my $priv (sort keys %full) {
2214: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2215: $r->print(&Apache::loncommon::start_data_table_row().
2216: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2217: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2218: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2219: '</td><td>'.
1.150 banghart 2220: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2221: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2222: '</td><td>'.
1.150 banghart 2223: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2224: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2225: '</td>'.
2226: &Apache::loncommon::end_data_table_row());
1.60 www 2227: }
1.135 raeburn 2228: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2229: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2230: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2231: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2232: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2233: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2234: &Apache::loncommon::end_page());
1.61 www 2235: }
1.153 banghart 2236: # --------------------------------------------------------
2237: sub make_script_template {
2238: my ($role) = @_;
2239: my %full_c=();
2240: my %full_d=();
2241: my %full_s=();
2242: my $return_script;
2243: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2244: my ($priv,$restrict)=split(/\&/,$item);
2245: $full_c{$priv}=1;
2246: }
2247: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2248: my ($priv,$restrict)=split(/\&/,$item);
2249: $full_d{$priv}=1;
2250: }
1.154 banghart 2251: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2252: my ($priv,$restrict)=split(/\&/,$item);
2253: $full_s{$priv}=1;
2254: }
2255: $return_script .= 'function set_'.$role.'() {'."\n";
2256: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2257: my %role_c;
1.155 banghart 2258: foreach my $priv (@temp) {
1.153 banghart 2259: my ($priv_item, $dummy) = split(/\&/,$priv);
2260: $role_c{$priv_item} = 1;
2261: }
2262: foreach my $priv_item (keys(%full_c)) {
2263: my ($priv, $dummy) = split(/\&/,$priv_item);
2264: if (exists($role_c{$priv})) {
2265: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2266: } else {
2267: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2268: }
2269: }
1.154 banghart 2270: my %role_d;
2271: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2272: foreach my $priv(@temp) {
2273: my ($priv_item, $dummy) = split(/\&/,$priv);
2274: $role_d{$priv_item} = 1;
2275: }
2276: foreach my $priv_item (keys(%full_d)) {
2277: my ($priv, $dummy) = split(/\&/,$priv_item);
2278: if (exists($role_d{$priv})) {
2279: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2280: } else {
2281: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2282: }
2283: }
2284: my %role_s;
2285: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2286: foreach my $priv(@temp) {
2287: my ($priv_item, $dummy) = split(/\&/,$priv);
2288: $role_s{$priv_item} = 1;
2289: }
2290: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2291: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2292: if (exists($role_s{$priv})) {
2293: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2294: } else {
2295: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2296: }
1.153 banghart 2297: }
2298: $return_script .= '}'."\n";
1.154 banghart 2299: return ($return_script);
2300: }
2301: # ----------------------------------------------------------
2302: sub make_button_code {
2303: my ($role) = @_;
2304: my $label = &Apache::lonnet::plaintext($role);
2305: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2306: return ($button_code);
1.153 banghart 2307: }
1.61 www 2308: # ---------------------------------------------------------- Call to definerole
2309: sub set_custom_role {
1.110 albertel 2310: my ($r) = @_;
1.101 albertel 2311: my $rolename=$env{'form.rolename'};
1.63 www 2312: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2313: if (!$rolename) {
1.190 raeburn 2314: &custom_role_editor($r);
1.61 www 2315: return;
2316: }
1.160 raeburn 2317: my ($jsback,$elements) = &crumb_utilities();
2318: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2319:
2320: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2321: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2322: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2323: text=>"Pick custom role",
1.160 raeburn 2324: faq=>282,bug=>'Instructor Interface',},
2325: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2326: text=>"Edit custom role",
2327: faq=>282,bug=>'Instructor Interface',},
2328: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2329: text=>"Result",
2330: faq=>282,bug=>'Instructor Interface',});
2331: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2332:
1.61 www 2333: my ($rdummy,$roledef)=
1.110 albertel 2334: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2335:
1.61 www 2336: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2337: $r->print('<h3>');
1.61 www 2338: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2339: $r->print(&mt('Existing Role').' "');
1.61 www 2340: } else {
1.73 sakharuk 2341: $r->print(&mt('New Role').' "');
1.61 www 2342: $roledef='';
2343: }
1.188 raeburn 2344: $r->print($rolename.'"</h3>');
1.61 www 2345: # ------------------------------------------------------- What can be assigned?
2346: my $sysrole='';
2347: my $domrole='';
2348: my $courole='';
2349:
1.135 raeburn 2350: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2351: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2352: if (!$restrict) { $restrict=''; }
2353: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2354: $courole.=':'.$item;
1.61 www 2355: }
2356: }
2357:
1.135 raeburn 2358: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2359: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2360: if (!$restrict) { $restrict=''; }
2361: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2362: $domrole.=':'.$item;
1.61 www 2363: }
2364: }
2365:
1.135 raeburn 2366: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2367: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2368: if (!$restrict) { $restrict=''; }
2369: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2370: $sysrole.=':'.$item;
1.61 www 2371: }
2372: }
1.63 www 2373: $r->print('<br />Defining Role: '.
1.61 www 2374: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2375: if ($env{'request.course.id'}) {
2376: my $url='/'.$env{'request.course.id'};
1.63 www 2377: $url=~s/\_/\//g;
1.73 sakharuk 2378: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2379: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2380: $env{'user.name'},
1.63 www 2381: $url,
1.101 albertel 2382: $env{'user.domain'},
2383: $env{'user.name'},
1.63 www 2384: $rolename));
2385: }
1.190 raeburn 2386: $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 2387: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2388: $r->print(&Apache::loncommon::end_page());
1.58 www 2389: }
2390:
1.2 www 2391: # ================================================================ Main Handler
2392: sub handler {
2393: my $r = shift;
2394: if ($r->header_only) {
1.68 www 2395: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2396: $r->send_http_header;
2397: return OK;
2398: }
1.190 raeburn 2399: my $context;
2400: if ($env{'request.course.id'}) {
2401: $context = 'course';
2402: } elsif ($env{'request.role'} =~ /^au\./) {
2403: $context = 'construction_space';
2404: } else {
2405: $context = 'domain';
2406: }
2407: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.202 raeburn 2408: ['action','state','callingform','roletype','showrole','bulkaction']);
1.190 raeburn 2409: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2410: if ($env{'form.action'} ne 'dateselect') {
2411: &Apache::lonhtmlcommon::add_breadcrumb
2412: ({href=>"/adm/createuser",
2413: text=>"User Management"});
2414: }
1.190 raeburn 2415: my ($permission,$allowed) = &get_permission($context);
2416: if (!$allowed) {
2417: $env{'user.error.msg'}=
2418: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2419: "or view user status.";
2420: return HTTP_NOT_ACCEPTABLE;
2421: }
2422:
2423: &Apache::loncommon::content_type($r,'text/html');
2424: $r->send_http_header;
2425:
2426: # Main switch on form.action and form.state, as appropriate
2427: if (! exists($env{'form.action'})) {
2428: $r->print(&header());
2429: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2430: $r->print(&print_main_menu($permission));
2431: $r->print(&Apache::loncommon::end_page());
2432: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2433: $r->print(&header());
2434: &Apache::lonhtmlcommon::add_breadcrumb
2435: ({href=>'/adm/createuser?action=upload&state=',
2436: text=>"Upload Users List"});
2437: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
2438: 'User_Management_Upload'));
2439: $r->print('<form name="studentform" method="post" '.
2440: 'enctype="multipart/form-data" '.
2441: ' action="/adm/createuser">'."\n");
2442: if (! exists($env{'form.state'})) {
2443: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2444: } elsif ($env{'form.state'} eq 'got_file') {
2445: &Apache::lonuserutils::print_upload_manager_form($r,$context);
2446: } elsif ($env{'form.state'} eq 'enrolling') {
2447: if ($env{'form.datatoken'}) {
2448: &Apache::lonuserutils::upfile_drop_add($r,$context);
2449: }
2450: } else {
2451: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2452: }
2453: $r->print('</form>'.&Apache::loncommon::end_page());
2454: } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
2455: $r->print(&header());
2456: &Apache::lonhtmlcommon::add_breadcrumb
2457: ({href=>'/adm/createuser?action=expire',
2458: text=>"Expire User Roles"});
2459: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Expire User Roles',
2460: 'User_Management_Drops'));
2461: if (! exists($env{'form.state'})) {
2462: &Apache::lonuserutils::print_expire_menu($r,$context);
2463: } elsif ($env{'form.state'} eq 'done') {
1.202 raeburn 2464: &Apache::lonuserutils::expire_user_list($r,$context);
1.190 raeburn 2465: } else {
2466: &Apache::lonuserutils::print_expire_menu($r,$context);
2467: }
2468: $r->print(&Apache::loncommon::end_page());
2469: } elsif ($env{'form.action'} eq 'singleuser' && $permission->{'cusr'}) {
2470: my $phase = $env{'form.phase'};
2471: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2472: &Apache::loncreateuser::restore_prev_selections();
2473: my $srch;
2474: foreach my $item (@search) {
2475: $srch->{$item} = $env{'form.'.$item};
2476: }
1.190 raeburn 2477:
2478: if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
2479: if ($env{'form.phase'} eq 'get_user_info') {
2480: my ($currstate,$response,$forcenewuser,$results) =
2481: &user_search_result($srch);
2482: if ($env{'form.currstate'} eq 'modify') {
2483: $currstate = $env{'form.currstate'};
2484: }
2485: if ($currstate eq 'select') {
2486: &print_user_selection_page($r,$response,$srch,$results,
2487: 'createuser',\@search);
2488: } elsif ($currstate eq 'modify') {
2489: my ($ccuname,$ccdomain);
2490: if (($srch->{'srchby'} eq 'uname') &&
2491: ($srch->{'srchtype'} eq 'exact')) {
2492: $ccuname = $srch->{'srchterm'};
2493: $ccdomain= $srch->{'srchdomain'};
2494: } else {
2495: my @matchedunames = keys(%{$results});
2496: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2497: }
2498: $ccuname =&LONCAPA::clean_username($ccuname);
2499: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2500: if ($env{'form.forcenewuser'}) {
2501: $response = '';
2502: }
2503: &print_user_modification_page($r,$ccuname,$ccdomain,
1.196 raeburn 2504: $srch,$response,$context);
1.190 raeburn 2505: } elsif ($currstate eq 'query') {
2506: &print_user_query_page($r,'createuser');
2507: } else {
2508: &print_username_entry_form($r,$response,$srch,
2509: $forcenewuser);
2510: }
2511: } elsif ($env{'form.phase'} eq 'userpicked') {
2512: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2513: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2514: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
2515: $context);
1.190 raeburn 2516: }
2517: } elsif ($env{'form.phase'} eq 'update_user_data') {
2518: &update_user_data($r);
2519: } else {
1.192 albertel 2520: &print_username_entry_form($r,undef,$srch);
1.190 raeburn 2521: }
2522: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2523: if ($env{'form.phase'} eq 'set_custom_roles') {
2524: &set_custom_role($r);
2525: } else {
2526: &custom_role_editor($r);
2527: }
2528: } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
1.202 raeburn 2529: if ($env{'form.phase'} eq 'bulkchange') {
2530: &Apache::lonhtmlcommon::add_breadcrumb
2531: ({href=>'backPage(document.studentform)',
2532: text=>"List Users"});
2533: my $setting = $env{'form.roletype'};
2534: my $choice = $env{'form.bulkaction'};
2535: $r->print(&header());
2536: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
2537: 'User_Management_List'));
2538: if ($permission->{'cusr'}) {
2539: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
2540: }
2541: } else {
2542: &Apache::lonhtmlcommon::add_breadcrumb
2543: ({href=>'/adm/createuser?action=listusers',
2544: text=>"List Users"});
2545: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2546: my $formname = 'studentform';
2547: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2548: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2549: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2550: $formname);
2551: $jscript .= &verify_user_display();
2552: my $js = &add_script($jscript).$cb_jscript;
2553: my $loadcode =
2554: &Apache::lonuserutils::course_selector_loadcode($formname);
2555: if ($loadcode ne '') {
2556: $r->print(&header($js,{'onload' => $loadcode,}));
2557: } else {
2558: $r->print(&header($js));
2559: }
1.191 raeburn 2560: } else {
1.202 raeburn 2561: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 2562: }
1.202 raeburn 2563: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
2564: 'User_Management_List'));
2565: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
2566: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
2567: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 2568: }
1.190 raeburn 2569: } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
2570: $r->print(&header());
2571: &Apache::lonhtmlcommon::add_breadcrumb
2572: ({href=>'/adm/createuser?action=drop',
2573: text=>"Expire Users"});
2574: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Expire User Roles',
2575: 'User_Management_Drops'));
2576: if (! exists($env{'form.state'})) {
2577: &Apache::lonuserutils::print_expire_menu($r,$context);
2578: } elsif ($env{'form.state'} eq 'done') {
1.202 raeburn 2579: &Apache::lonuserutiles::expire_user_list($r,$context);
1.190 raeburn 2580: } else {
2581: &print_expire_menu($r,$context);
2582: }
2583: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2584: } elsif ($env{'form.action'} eq 'dateselect') {
2585: if ($permission->{'cusr'}) {
2586: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
2587: &Apache::lonuserutils::date_section_selector($context).
2588: &Apache::loncommon::end_page());
2589: } else {
2590: $r->print(&header().
2591: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
2592: &Apache::loncommon::end_page());
2593: }
1.190 raeburn 2594: } else {
2595: $r->print(&header());
1.202 raeburn 2596: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2597: $r->print(&print_main_menu($permission));
1.190 raeburn 2598: $r->print(&Apache::loncommon::end_page());
2599: }
2600: return OK;
2601: }
2602:
2603: sub header {
1.202 raeburn 2604: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 2605: my $start_page;
2606: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 2607: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 2608: } else {
1.202 raeburn 2609: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 2610: }
2611: return $start_page;
2612: }
1.2 www 2613:
1.191 raeburn 2614: sub add_script {
2615: my ($js) = @_;
2616: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
2617: }
2618:
1.202 raeburn 2619: sub verify_user_display {
2620: my $output = <<"END";
2621:
2622: function display_update() {
2623: document.studentform.action.value = 'listusers';
2624: document.studentform.phase.value = 'display';
2625: document.studentform.submit();
2626: }
2627:
2628: END
2629: return $output;
2630:
2631: }
2632:
1.190 raeburn 2633: ###############################################################
2634: ###############################################################
2635: # Menu Phase One
2636: sub print_main_menu {
2637: my ($permission) = @_;
2638: my @menu =
2639: (
1.191 raeburn 2640: { text => 'Upload a File of Users to Modify/Create Users and/or Add roles',
1.190 raeburn 2641: help => 'User_Management_Upload',
2642: action => 'upload',
2643: permission => $permission->{'cusr'},
2644: },
1.191 raeburn 2645: { text => 'Create User/Set User Roles for a single user',
1.190 raeburn 2646: help => 'User_Management_Single_User',
2647: action => 'singleuser',
2648: permission => $permission->{'cusr'},
2649: },
1.191 raeburn 2650: { text => 'Display Lists of Users',
2651: help => 'User_Management_List',
2652: action => 'listusers',
2653: permission => $permission->{'view'},
2654: },
2655: # { text => 'Expire User Roles',
1.190 raeburn 2656: # help => 'User_Management_Drops',
2657: # action => 'expire',
2658: # permission => $permission->{'cusr'},
2659: # },
2660: { text => 'Edit Custom Roles',
2661: help => 'Custom_Role_Edit',
2662: action => 'custom',
2663: permission => $permission->{'custom'},
2664: },
2665: );
2666: my $menu_html = '';
2667: foreach my $menu_item (@menu) {
2668: next if (! $menu_item->{'permission'});
2669: $menu_html.='<p>';
2670: $menu_html.='<font size="+1">';
2671: if (exists($menu_item->{'url'})) {
2672: $menu_html.=qq{<a href="$menu_item->{'url'}">};
2673: } else {
2674: $menu_html.=
2675: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
2676: }
2677: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
2678: if (exists($menu_item->{'help'})) {
2679: $menu_html.=
2680: &Apache::loncommon::help_open_topic($menu_item->{'help'});
2681: }
2682: $menu_html.='</p>';
2683: }
2684: return $menu_html;
2685: }
2686:
2687: sub get_permission {
2688: my ($context) = @_;
2689: my %permission;
2690: if ($context eq 'course') {
2691: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
2692: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
2693: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
2694: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
2695: (&Apache::lonnet::allowed('cst',$env{'request.course.id'}))) {
2696: $permission{'cusr'} = 1;
2697: $permission{'view'} =
2698: &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
2699:
2700: }
2701: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
2702: $permission{'custom'} = 1;
2703: }
2704: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
2705: $permission{'view'} = 1;
2706: if (!$permission{'view'}) {
2707: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
2708: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
2709: if ($permission{'view'}) {
2710: $permission{'view_section'} = $env{'request.course.sec'};
2711: }
2712: }
2713: }
2714: } elsif ($context eq 'construction_space') {
2715: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
2716: $permission{'view'} = $permission{'cusr'};
2717: } else {
2718: if ((&Apache::lonnet::allowed('cad',$env{'request.role.domain'})) ||
2719: (&Apache::lonnet::allowed('cli',$env{'request.role.domain'})) ||
2720: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
2721: (&Apache::lonnet::allowed('csc',$env{'request.role.domain'})) ||
2722: (&Apache::lonnet::allowed('cdg',$env{'request.role.domain'})) ||
2723: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
2724: $permission{'cusr'} = 1;
2725: }
2726: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
2727: $permission{'custom'} = 1;
2728: }
2729: $permission{'view'} = $permission{'cusr'};
2730: }
2731: my $allowed = 0;
2732: foreach my $perm (values(%permission)) {
2733: if ($perm) { $allowed=1; last; }
2734: }
2735: return (\%permission,$allowed);
1.160 raeburn 2736: }
1.26 matthew 2737:
1.189 albertel 2738: sub restore_prev_selections {
2739: my %saveable_parameters = ('srchby' => 'scalar',
2740: 'srchin' => 'scalar',
2741: 'srchtype' => 'scalar',
2742: );
2743: &Apache::loncommon::store_settings('user','user_picker',
2744: \%saveable_parameters);
2745: &Apache::loncommon::restore_settings('user','user_picker',
2746: \%saveable_parameters);
2747: }
2748:
1.27 matthew 2749: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 2750: sub user_search_result {
2751: my ($srch) = @_;
2752: my %allhomes;
2753: my %inst_matches;
2754: my %srch_results;
1.181 raeburn 2755: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 2756: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 2757: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 2758: $response = &mt('Invalid search.');
2759: }
2760: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
2761: $response = &mt('Invalid search.');
2762: }
1.177 raeburn 2763: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 2764: $response = &mt('Invalid search.');
2765: }
2766: if ($srch->{'srchterm'} eq '') {
2767: $response = &mt('You must enter a search term.');
2768: }
1.183 raeburn 2769: if ($srch->{'srchterm'} =~ /^\s+$/) {
2770: $response = &mt('Your search term must contain more than just spaces.');
2771: }
1.160 raeburn 2772: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
2773: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 2774: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 2775: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
2776: }
2777: }
2778: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
2779: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 2780: if ($srch->{'srchby'} eq 'uname') {
2781: if ($srch->{'srchterm'} !~ /^$match_username$/) {
2782: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
2783: }
1.160 raeburn 2784: }
2785: }
1.180 raeburn 2786: if ($response ne '') {
2787: $response = '<span class="LC_warning">'.$response.'</span>';
2788: }
1.160 raeburn 2789: if ($srch->{'srchin'} eq 'instd') {
2790: my $instd_chk = &directorysrch_check($srch);
2791: if ($instd_chk ne 'ok') {
1.180 raeburn 2792: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
2793: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 2794: }
2795: }
2796: if ($response ne '') {
1.180 raeburn 2797: return ($currstate,$response);
1.160 raeburn 2798: }
2799: if ($srch->{'srchby'} eq 'uname') {
2800: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
2801: if ($env{'form.forcenew'}) {
2802: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
2803: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2804: if ($uhome eq 'no_host') {
2805: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 2806: my $showdom = &display_domain_info($env{'request.role.domain'});
2807: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 2808: } else {
1.179 raeburn 2809: $currstate = 'modify';
1.160 raeburn 2810: }
2811: } else {
1.179 raeburn 2812: $currstate = 'modify';
1.160 raeburn 2813: }
2814: } else {
2815: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 2816: if ($srch->{'srchtype'} eq 'exact') {
2817: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2818: if ($uhome eq 'no_host') {
1.179 raeburn 2819: ($currstate,$response,$forcenewuser) =
1.162 raeburn 2820: &build_search_response($srch,%srch_results);
2821: } else {
1.179 raeburn 2822: $currstate = 'modify';
1.162 raeburn 2823: }
2824: } else {
2825: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 2826: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2827: &build_search_response($srch,%srch_results);
2828: }
2829: } else {
1.167 albertel 2830: my $courseusers = &get_courseusers();
1.162 raeburn 2831: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 2832: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 2833: $currstate = 'modify';
1.162 raeburn 2834: } else {
1.179 raeburn 2835: ($currstate,$response,$forcenewuser) =
1.162 raeburn 2836: &build_search_response($srch,%srch_results);
2837: }
1.160 raeburn 2838: } else {
1.167 albertel 2839: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 2840: my ($cuname,$cudomain) = split(/:/,$user);
2841: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 2842: my $matched = 0;
2843: if ($srch->{'srchtype'} eq 'begins') {
2844: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
2845: $matched = 1;
2846: }
2847: } else {
2848: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
2849: $matched = 1;
2850: }
2851: }
2852: if ($matched) {
1.167 albertel 2853: $srch_results{$user} =
2854: {&Apache::lonnet::get('environment',
2855: ['firstname',
2856: 'lastname',
1.194 albertel 2857: 'permanentemail'],
2858: $cudomain,$cuname)};
1.162 raeburn 2859: }
2860: }
2861: }
1.179 raeburn 2862: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2863: &build_search_response($srch,%srch_results);
2864: }
2865: }
2866: }
2867: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 2868: $currstate = 'query';
1.160 raeburn 2869: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 2870: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
2871: if ($dirsrchres eq 'ok') {
2872: ($currstate,$response,$forcenewuser) =
2873: &build_search_response($srch,%srch_results);
2874: } else {
2875: my $showdom = &display_domain_info($srch->{'srchdomain'});
2876: $response = '<span class="LC_warning">'.
2877: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
2878: '</span><br />'.
2879: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
2880: '<br /><br />';
2881: }
1.160 raeburn 2882: }
2883: } else {
2884: if ($srch->{'srchin'} eq 'dom') {
2885: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 2886: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2887: &build_search_response($srch,%srch_results);
2888: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 2889: my $courseusers = &get_courseusers();
2890: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 2891: my ($uname,$udom) = split(/:/,$user);
2892: my %names = &Apache::loncommon::getnames($uname,$udom);
2893: my %emails = &Apache::loncommon::getemails($uname,$udom);
2894: if ($srch->{'srchby'} eq 'lastname') {
2895: if ((($srch->{'srchtype'} eq 'exact') &&
2896: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 2897: (($srch->{'srchtype'} eq 'begins') &&
2898: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 2899: (($srch->{'srchtype'} eq 'contains') &&
2900: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
2901: $srch_results{$user} = {firstname => $names{'firstname'},
2902: lastname => $names{'lastname'},
2903: permanentemail => $emails{'permanentemail'},
2904: };
2905: }
2906: } elsif ($srch->{'srchby'} eq 'lastfirst') {
2907: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 2908: $srchlast =~ s/\s+$//;
2909: $srchfirst =~ s/^\s+//;
1.160 raeburn 2910: if ($srch->{'srchtype'} eq 'exact') {
2911: if (($names{'lastname'} eq $srchlast) &&
2912: ($names{'firstname'} eq $srchfirst)) {
2913: $srch_results{$user} = {firstname => $names{'firstname'},
2914: lastname => $names{'lastname'},
2915: permanentemail => $emails{'permanentemail'},
2916:
2917: };
2918: }
1.177 raeburn 2919: } elsif ($srch->{'srchtype'} eq 'begins') {
2920: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
2921: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
2922: $srch_results{$user} = {firstname => $names{'firstname'},
2923: lastname => $names{'lastname'},
2924: permanentemail => $emails{'permanentemail'},
2925: };
2926: }
2927: } else {
1.160 raeburn 2928: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
2929: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
2930: $srch_results{$user} = {firstname => $names{'firstname'},
2931: lastname => $names{'lastname'},
2932: permanentemail => $emails{'permanentemail'},
2933: };
2934: }
2935: }
2936: }
2937: }
1.179 raeburn 2938: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2939: &build_search_response($srch,%srch_results);
2940: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 2941: $currstate = 'query';
1.160 raeburn 2942: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 2943: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
2944: if ($dirsrchres eq 'ok') {
2945: ($currstate,$response,$forcenewuser) =
2946: &build_search_response($srch,%srch_results);
2947: } else {
2948: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
2949: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
2950: '</span><br />'.
2951: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
2952: '<br /><br />';
2953: }
1.160 raeburn 2954: }
2955: }
1.179 raeburn 2956: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 2957: }
2958:
2959: sub directorysrch_check {
2960: my ($srch) = @_;
2961: my $can_search = 0;
2962: my $response;
2963: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
2964: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 2965: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 2966: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
2967: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 2968: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 2969: }
2970: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
2971: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 2972: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 2973: }
2974: my @usertypes = split(/:/,$env{'environment.inststatus'});
2975: if (!@usertypes) {
2976: push(@usertypes,'default');
2977: }
2978: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
2979: foreach my $type (@usertypes) {
2980: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
2981: $can_search = 1;
2982: last;
2983: }
2984: }
2985: }
2986: if (!$can_search) {
2987: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
2988: my @longtypes;
2989: foreach my $item (@usertypes) {
2990: push (@longtypes,$insttypes->{$item});
2991: }
2992: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 2993: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.160 raeburn 2994: }
2995: } else {
2996: $can_search = 1;
2997: }
2998: } else {
1.180 raeburn 2999: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 3000: }
3001: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 3002: uname => 'username',
1.160 raeburn 3003: lastfirst => 'last name, first name',
1.167 albertel 3004: lastname => 'last name',
1.172 raeburn 3005: contains => 'contains',
1.178 raeburn 3006: exact => 'as exact match to',
3007: begins => 'begins with',
1.160 raeburn 3008: );
3009: if ($can_search) {
3010: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
3011: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 3012: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 3013: }
3014: } else {
1.180 raeburn 3015: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 3016: }
3017: }
3018: if ($can_search) {
1.178 raeburn 3019: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
3020: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
3021: return 'ok';
3022: } else {
1.180 raeburn 3023: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3024: }
3025: } else {
3026: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
3027: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
3028: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
3029: return 'ok';
3030: } else {
1.180 raeburn 3031: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3032: }
1.160 raeburn 3033: }
3034: }
3035: }
3036:
3037: sub get_courseusers {
3038: my %advhash;
1.167 albertel 3039: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 3040: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
3041: foreach my $role (sort(keys(%coursepersonnel))) {
3042: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 3043: if (!exists($classlist->{$user})) {
3044: $classlist->{$user} = [];
3045: }
1.160 raeburn 3046: }
3047: }
1.167 albertel 3048: return $classlist;
1.160 raeburn 3049: }
3050:
3051: sub build_search_response {
3052: my ($srch,%srch_results) = @_;
1.179 raeburn 3053: my ($currstate,$response,$forcenewuser);
1.160 raeburn 3054: my %names = (
3055: 'uname' => 'username',
3056: 'lastname' => 'last name',
3057: 'lastfirst' => 'last name, first name',
3058: 'crs' => 'this course',
1.180 raeburn 3059: 'dom' => 'LON-CAPA domain: ',
3060: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 3061: );
3062:
3063: my %single = (
1.180 raeburn 3064: begins => 'A match',
1.160 raeburn 3065: contains => 'A match',
1.180 raeburn 3066: exact => 'An exact match',
1.160 raeburn 3067: );
3068: my %nomatch = (
1.180 raeburn 3069: begins => 'No match',
1.160 raeburn 3070: contains => 'No match',
1.180 raeburn 3071: exact => 'No exact match',
1.160 raeburn 3072: );
3073: if (keys(%srch_results) > 1) {
1.179 raeburn 3074: $currstate = 'select';
1.160 raeburn 3075: } else {
3076: if (keys(%srch_results) == 1) {
1.179 raeburn 3077: $currstate = 'modify';
1.180 raeburn 3078: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
3079: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3080: $response .= &display_domain_info($srch->{'srchdomain'});
3081: }
1.160 raeburn 3082: } else {
1.180 raeburn 3083: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
3084: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3085: $response .= &display_domain_info($srch->{'srchdomain'});
3086: }
3087: $response .= '</span>';
1.160 raeburn 3088: if ($srch->{'srchin'} ne 'alc') {
3089: $forcenewuser = 1;
3090: my $cansrchinst = 0;
3091: if ($srch->{'srchdomain'}) {
3092: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
3093: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3094: if ($domconfig{'directorysrch'}{'available'}) {
3095: $cansrchinst = 1;
3096: }
3097: }
3098: }
1.180 raeburn 3099: if ((($srch->{'srchby'} eq 'lastfirst') ||
3100: ($srch->{'srchby'} eq 'lastname')) &&
3101: ($srch->{'srchin'} eq 'dom')) {
3102: if ($cansrchinst) {
3103: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 3104: }
3105: }
1.180 raeburn 3106: if ($srch->{'srchin'} eq 'crs') {
3107: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
3108: }
3109: }
3110: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.182 raeburn 3111: my $showdom = &display_domain_info($env{'request.role.domain'});
3112: $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 3113: }
3114: }
3115: }
1.179 raeburn 3116: return ($currstate,$response,$forcenewuser);
1.160 raeburn 3117: }
3118:
1.180 raeburn 3119: sub display_domain_info {
3120: my ($dom) = @_;
3121: my $output = $dom;
3122: if ($dom ne '') {
3123: my $domdesc = &Apache::lonnet::domain($dom,'description');
3124: if ($domdesc ne '') {
3125: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
3126: }
3127: }
3128: return $output;
3129: }
3130:
1.160 raeburn 3131: sub crumb_utilities {
3132: my %elements = (
3133: crtuser => {
3134: srchterm => 'text',
1.172 raeburn 3135: srchin => 'selectbox',
1.160 raeburn 3136: srchby => 'selectbox',
3137: srchtype => 'selectbox',
3138: srchdomain => 'selectbox',
3139: },
3140: docustom => {
3141: rolename => 'selectbox',
3142: newrolename => 'textbox',
3143: },
1.179 raeburn 3144: studentform => {
3145: srchterm => 'text',
3146: srchin => 'selectbox',
3147: srchby => 'selectbox',
3148: srchtype => 'selectbox',
3149: srchdomain => 'selectbox',
3150: },
1.160 raeburn 3151: );
3152:
3153: my $jsback .= qq|
3154: function backPage(formname,prevphase,prevstate) {
3155: formname.phase.value = prevphase;
1.179 raeburn 3156: formname.currstate.value = prevstate;
1.160 raeburn 3157: formname.submit();
3158: }
3159: |;
3160: return ($jsback,\%elements);
3161: }
3162:
1.26 matthew 3163: sub course_level_table {
1.89 raeburn 3164: my (%inccourses) = @_;
1.26 matthew 3165: my $table = '';
1.62 www 3166: # Custom Roles?
3167:
1.190 raeburn 3168: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 3169: my %lt=&Apache::lonlocal::texthash(
3170: 'exs' => "Existing sections",
3171: 'new' => "Define new section",
3172: 'ssd' => "Set Start Date",
3173: 'sed' => "Set End Date",
1.131 raeburn 3174: 'crl' => "Course Level",
1.89 raeburn 3175: 'act' => "Activate",
3176: 'rol' => "Role",
3177: 'ext' => "Extent",
1.113 raeburn 3178: 'grs' => "Section",
1.89 raeburn 3179: 'sta' => "Start",
3180: 'end' => "End"
3181: );
1.62 www 3182:
1.135 raeburn 3183: foreach my $protectedcourse (sort( keys(%inccourses))) {
3184: my $thiscourse=$protectedcourse;
1.26 matthew 3185: $thiscourse=~s:_:/:g;
3186: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
3187: my $area=$coursedata{'description'};
1.119 raeburn 3188: my $type=$coursedata{'type'};
1.135 raeburn 3189: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 3190: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 3191: my %sections_count;
1.101 albertel 3192: if (defined($env{'request.course.id'})) {
3193: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 3194: %sections_count =
3195: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 3196: }
3197: }
1.135 raeburn 3198: foreach my $role ('st','ta','ep','in','cc') {
3199: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
3200: my $plrole=&Apache::lonnet::plaintext($role);
1.136 raeburn 3201: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 3202: '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
1.136 raeburn 3203: <td>'.$plrole.'</td>
3204: <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.135 raeburn 3205: if ($role ne 'cc') {
1.115 albertel 3206: if (%sections_count) {
1.202 raeburn 3207: my $currsec =
1.198 raeburn 3208: &Apache::lonuserutils::course_sections(\%sections_count,
1.202 raeburn 3209: $protectedcourse.'_'.$role);
1.89 raeburn 3210: $table .=
1.137 raeburn 3211: '<td><table class="LC_createuser">'.
3212: '<tr class="LC_section_row">
3213: <td valign="top">'.$lt{'exs'}.'<br />'.
1.89 raeburn 3214: $currsec.'</td>'.
3215: '<td> </td>'.
3216: '<td valign="top"> '.$lt{'new'}.'<br />'.
1.157 albertel 3217: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
1.89 raeburn 3218: '<input type="hidden" '.
1.157 albertel 3219: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
1.89 raeburn 3220: '</tr></table></td>';
3221: } else {
3222: $table .= '<td><input type="text" size="10" '.
1.157 albertel 3223: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
1.89 raeburn 3224: }
1.26 matthew 3225: } else {
1.89 raeburn 3226: $table .= '<td> </td>';
1.26 matthew 3227: }
3228: $table .= <<ENDTIMEENTRY;
1.169 albertel 3229: <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
1.26 matthew 3230: <a href=
1.135 raeburn 3231: "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 3232: <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
1.26 matthew 3233: <a href=
1.135 raeburn 3234: "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 3235: ENDTIMEENTRY
1.136 raeburn 3236: $table.= &Apache::loncommon::end_data_table_row();
1.26 matthew 3237: }
3238: }
1.135 raeburn 3239: foreach my $cust (sort keys %customroles) {
1.65 www 3240: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.135 raeburn 3241: my $plrole=$cust;
1.101 albertel 3242: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
3243: '_'.$env{'user.name'}.'_'.$plrole;
1.136 raeburn 3244: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 3245: '<td><input type="checkbox" name="act_'.$customrole.'" /></td>
1.136 raeburn 3246: <td>'.$plrole.'</td>
3247: <td>'.$area.'</td>'."\n";
1.115 albertel 3248: if (%sections_count) {
1.202 raeburn 3249: my $currsec =
1.198 raeburn 3250: &Apache::lonuserutils::course_sections(\%sections_count,
3251: $customrole);
1.89 raeburn 3252: $table.=
1.188 raeburn 3253: '<td><table class="LC_createuser">'.
3254: '<tr class="LC_section_row"><td valign="top">'.
3255: $lt{'exs'}.'<br />'.$currsec.'</td>'.
1.89 raeburn 3256: '<td> </td>'.
3257: '<td valign="top"> '.$lt{'new'}.'<br />'.
3258: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
3259: '<input type="hidden" '.
1.157 albertel 3260: 'name="sec_'.$customrole.'" /></td>'.
1.89 raeburn 3261: '</tr></table></td>';
3262: } else {
3263: $table .= '<td><input type="text" size="10" '.
1.157 albertel 3264: 'name="sec_'.$customrole.'" /></td>';
1.89 raeburn 3265: }
3266: $table .= <<ENDENTRY;
1.169 albertel 3267: <td><input type="hidden" name="start_$customrole" value='' />
1.62 www 3268: <a href=
1.73 sakharuk 3269: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3270: <td><input type="hidden" name="end_$customrole" value='' />
1.62 www 3271: <a href=
1.136 raeburn 3272: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
1.62 www 3273: ENDENTRY
1.136 raeburn 3274: $table .= &Apache::loncommon::end_data_table_row();
1.65 www 3275: }
1.62 www 3276: }
1.26 matthew 3277: }
3278: return '' if ($table eq ''); # return nothing if there is nothing
3279: # in the table
1.188 raeburn 3280: my $result;
3281: if (!$env{'request.course.id'}) {
3282: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
3283: }
3284: $result .=
1.136 raeburn 3285: &Apache::loncommon::start_data_table().
3286: &Apache::loncommon::start_data_table_header_row().
3287: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
3288: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
3289: &Apache::loncommon::end_data_table_header_row().
3290: $table.
3291: &Apache::loncommon::end_data_table();
1.26 matthew 3292: return $result;
3293: }
1.88 raeburn 3294:
3295: sub course_level_dc {
3296: my ($dcdom) = @_;
1.190 raeburn 3297: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.88 raeburn 3298: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
3299: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 3300: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 3301: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 3302: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
3303: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 3304: my %lt=&Apache::lonlocal::texthash(
3305: 'rol' => "Role",
1.113 raeburn 3306: 'grs' => "Section",
1.88 raeburn 3307: 'exs' => "Existing sections",
3308: 'new' => "Define new section",
3309: 'sta' => "Start",
3310: 'end' => "End",
3311: 'ssd' => "Set Start Date",
3312: 'sed' => "Set End Date"
3313: );
1.131 raeburn 3314: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 3315: &Apache::loncommon::start_data_table().
3316: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 3317: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 3318: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 3319: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 3320: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 3321: '<td><select name="role">'."\n";
1.135 raeburn 3322: foreach my $role ('st','ta','ep','in','cc') {
3323: my $plrole=&Apache::lonnet::plaintext($role);
3324: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 3325: }
3326: if ( keys %customroles > 0) {
1.135 raeburn 3327: foreach my $cust (sort keys %customroles) {
1.101 albertel 3328: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 3329: '_'.$env{'user.name'}.'_'.$cust;
3330: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 3331: }
3332: }
3333: $otheritems .= '</select></td><td>'.
3334: '<table border="0" cellspacing="0" cellpadding="0">'.
3335: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
3336: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
3337: '<td> </td>'.
3338: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 3339: '<input type="text" name="newsec" value="" />'.
3340: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 3341: '</tr></table></td>';
3342: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 3343: <td><input type="hidden" name="start" value='' />
1.88 raeburn 3344: <a href=
3345: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3346: <td><input type="hidden" name="end" value='' />
1.88 raeburn 3347: <a href=
3348: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
3349: ENDTIMEENTRY
1.136 raeburn 3350: $otheritems .= &Apache::loncommon::end_data_table_row().
3351: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 3352: return $cb_jscript.$header.$hiddenitems.$otheritems;
3353: }
3354:
1.27 matthew 3355: #---------------------------------------------- end functions for &phase_two
1.29 matthew 3356:
3357: #--------------------------------- functions for &phase_two and &phase_three
3358:
3359: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 3360:
3361: 1;
3362: __END__
1.2 www 3363:
3364:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>