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