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