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