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