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