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