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