Annotation of loncom/interface/loncreateuser.pm, revision 1.169
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.169 ! albertel 4: # $Id: loncreateuser.pm,v 1.168 2007/08/02 01:07:00 albertel Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
1.1 www 61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
1.54 bowersj2 65: use Apache::loncommon;
1.68 www 66: use Apache::lonlocal;
1.117 raeburn 67: use Apache::longroup;
1.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.166 albertel 219: text=>"User modify/custom role",
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.166 albertel 332: 'srch' => "User Search to add/modify roles of",
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.166 albertel 350: $r->print('<h3>'.&mt('Select a user to add/modify roles of').'</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.160 raeburn 786: foreach my $item ('firstname','middlename','lastname','generation','permenanentemail') {
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.160 raeburn 1449: $changeHash{'permanentemail'} = $env{'form.permanentemail'};
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>
1474: <th>$lt{'disk'}<th></tr>
1.73 sakharuk 1475: <tr><td>$lt{'prvs'}</td>
1.28 matthew 1476: <td>$userenv{'firstname'} </td>
1477: <td>$userenv{'middlename'} </td>
1478: <td>$userenv{'lastname'} </td>
1.134 raeburn 1479: <td>$userenv{'generation'} </td>
1.160 raeburn 1480: <td>$userenv{'permanentemail'} </td>
1.149 raeburn 1481: <td>$oldportfolioquota Mb</td>
1.134 raeburn 1482: </tr>
1.73 sakharuk 1483: <tr><td>$lt{'chto'}</td>
1.101 albertel 1484: <td>$env{'form.cfirstname'} </td>
1485: <td>$env{'form.cmiddlename'} </td>
1486: <td>$env{'form.clastname'} </td>
1.134 raeburn 1487: <td>$env{'form.cgeneration'} </td>
1.160 raeburn 1488: <td>$env{'form.cpermanentemail'} </td>
1.149 raeburn 1489: <td>$newportfolioquota Mb $defquotatext </td></tr>
1.28 matthew 1490: </table>
1491: END
1.149 raeburn 1492: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1493: ($env{'form.ccuname'} eq $env{'user.name'})) {
1494: my %newenvhash;
1495: foreach my $key (keys(%changeHash)) {
1496: $newenvhash{'environment.'.$key} = $changeHash{$key};
1497: }
1498: &Apache::lonnet::appenv(%newenvhash);
1499: }
1.28 matthew 1500: } else { # error occurred
1.73 sakharuk 1501: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1.101 albertel 1502: $env{'form.ccuname'}." ".&mt('in domain')." ".
1503: $env{'form.ccdomain'}."</h2>");
1.28 matthew 1504: }
1.101 albertel 1505: } else { # End of if ($env ... ) logic
1.134 raeburn 1506: my $putresult;
1507: if ($quotachanged) {
1508: $putresult = &Apache::lonnet::put
1509: ('environment',\%changeHash,
1510: $env{'form.ccdomain'},$env{'form.ccuname'});
1511: }
1.28 matthew 1512: # They did not want to change the users name but we can
1513: # still tell them what the name is
1.73 sakharuk 1514: my %lt=&Apache::lonlocal::texthash(
1.160 raeburn 1515: 'mail' => "Permanent e-mail",
1.134 raeburn 1516: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 1517: );
1.134 raeburn 1518: $r->print(<<"END");
1.164 albertel 1519: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}</h4>
1.160 raeburn 1520: <h4>$lt{'mail'}: $userenv{'permanentemail'}</h4>
1.28 matthew 1521: END
1.134 raeburn 1522: if ($putresult eq 'ok') {
1.149 raeburn 1523: if ($oldportfolioquota != $newportfolioquota) {
1524: $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
1525: $defquotatext.'</h4>');
1526: &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
1.134 raeburn 1527: }
1528: }
1.28 matthew 1529: }
1.4 www 1530: }
1.27 matthew 1531: ##
1.4 www 1532: my $now=time;
1.73 sakharuk 1533: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 1534: foreach my $key (keys (%env)) {
1535: next if (! $env{$key});
1.27 matthew 1536: # Revoke roles
1.135 raeburn 1537: if ($key=~/^form\.rev/) {
1538: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 1539: # Revoke standard role
1.73 sakharuk 1540: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.101 albertel 1541: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1.102 albertel 1542: $env{'form.ccuname'},$1,$2).'</b><br />');
1.53 www 1543: if ($2 eq 'st') {
1.141 albertel 1544: $1=~m{^/($match_domain)/($match_courseid)};
1.53 www 1545: my $cid=$1.'_'.$2;
1.159 albertel 1546: my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
1547: my $result =
1548: &Apache::lonnet::cput('classlist',
1549: { $user => $now },
1550: $env{'course.'.$cid.'.domain'},
1551: $env{'course.'.$cid.'.num'});
1552: $r->print(&mt('Drop from classlist: [_1]',
1553: '<b>'.$result.'</b>').'<br />');
1.53 www 1554: }
1555: }
1.139 albertel 1556: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.64 www 1557: # Revoke custom role
1.113 raeburn 1558: $r->print(&mt('Revoking custom role:').
1.139 albertel 1559: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 1560: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1561: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 1562: '</b><br />');
1.64 www 1563: }
1.135 raeburn 1564: } elsif ($key=~/^form\.del/) {
1565: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 1566: # Delete standard role
1.73 sakharuk 1567: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.101 albertel 1568: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1.102 albertel 1569: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1.27 matthew 1570: if ($2 eq 'st') {
1.141 albertel 1571: $1=~m{^/($match_domain)/($match_courseid)};
1.27 matthew 1572: my $cid=$1.'_'.$2;
1.159 albertel 1573: my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
1574: my $result =
1575: &Apache::lonnet::cput('classlist',
1576: { $user => $now },
1577: $env{'course.'.$cid.'.domain'},
1578: $env{'course.'.$cid.'.num'});
1579: $r->print(&mt('Drop from classlist: [_1]',
1580: '<b>'.$result.'</b>').'<br />');
1.81 albertel 1581: }
1.116 raeburn 1582: }
1.139 albertel 1583: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 1584: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1585: # Delete custom role
1586: $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
1587: $rolename,$rnam,$rdom,$url).': <b>'.
1588: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1589: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1590: 0,1).'</b><br />');
1591: }
1.135 raeburn 1592: } elsif ($key=~/^form\.ren/) {
1.101 albertel 1593: my $udom = $env{'form.ccdomain'};
1594: my $uname = $env{'form.ccuname'};
1.116 raeburn 1595: # Re-enable standard role
1.135 raeburn 1596: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 1597: my $url = $1;
1598: my $role = $2;
1599: my $logmsg;
1600: my $output;
1601: if ($role eq 'st') {
1.141 albertel 1602: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 1603: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 1604: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1605: $output = "Error: $result\n";
1606: } else {
1607: $output = &mt('Assigning').' '.$role.' in '.$url.
1608: &mt('starting').' '.localtime($now).
1609: ': <br />'.$logmsg.'<br />'.
1610: &mt('Add to classlist').': <b>ok</b><br />';
1611: }
1612: }
1613: } else {
1.101 albertel 1614: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1615: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 1616: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 1617: $role,$url,$result).'<br />';
1.27 matthew 1618: }
1.89 raeburn 1619: $r->print($output);
1.113 raeburn 1620: }
1.116 raeburn 1621: # Re-enable custom role
1.139 albertel 1622: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 1623: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1624: my $result = &Apache::lonnet::assigncustomrole(
1625: $env{'form.ccdomain'}, $env{'form.ccuname'},
1626: $url,$rdom,$rnam,$rolename,0,$now);
1627: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1628: $rolename,$rnam,$rdom,$url,$result).'<br />');
1629: }
1.135 raeburn 1630: } elsif ($key=~/^form\.act/) {
1.101 albertel 1631: my $udom = $env{'form.ccdomain'};
1632: my $uname = $env{'form.ccuname'};
1.141 albertel 1633: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 1634: # Activate a custom role
1.83 albertel 1635: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1636: my $url='/'.$one.'/'.$two;
1637: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 1638:
1.101 albertel 1639: my $start = ( $env{'form.start_'.$full} ?
1640: $env{'form.start_'.$full} :
1.88 raeburn 1641: $now );
1.101 albertel 1642: my $end = ( $env{'form.end_'.$full} ?
1643: $env{'form.end_'.$full} :
1.88 raeburn 1644: 0 );
1645:
1646: # split multiple sections
1647: my %sections = ();
1.101 albertel 1648: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 1649: if ($num_sections == 0) {
1.129 albertel 1650: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 1651: } else {
1.114 albertel 1652: my %curr_groups =
1.117 raeburn 1653: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 1654: foreach my $sec (sort {$a cmp $b} keys %sections) {
1655: if (($sec eq 'none') || ($sec eq 'all') ||
1656: exists($curr_groups{$sec})) {
1657: $disallowed{$sec} = $url;
1658: next;
1659: }
1660: my $securl = $url.'/'.$sec;
1.129 albertel 1661: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 1662: }
1663: }
1.142 raeburn 1664: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 1665: # Activate roles for sections with 3 id numbers
1666: # set start, end times, and the url for the class
1.83 albertel 1667: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 1668: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1669: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1670: $now );
1.101 albertel 1671: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1672: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1673: 0 );
1.83 albertel 1674: my $url='/'.$one.'/'.$two;
1.88 raeburn 1675: my $type = 'three';
1676: # split multiple sections
1677: my %sections = ();
1.101 albertel 1678: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 1679: if ($num_sections == 0) {
1.129 albertel 1680: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1681: } else {
1.114 albertel 1682: my %curr_groups =
1.117 raeburn 1683: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 1684: my $emptysec = 0;
1685: foreach my $sec (sort {$a cmp $b} keys %sections) {
1686: $sec =~ s/\W//g;
1.113 raeburn 1687: if ($sec ne '') {
1688: if (($sec eq 'none') || ($sec eq 'all') ||
1689: exists($curr_groups{$sec})) {
1690: $disallowed{$sec} = $url;
1691: next;
1692: }
1.88 raeburn 1693: my $securl = $url.'/'.$sec;
1.129 albertel 1694: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 1695: } else {
1696: $emptysec = 1;
1697: }
1698: }
1699: if ($emptysec) {
1.129 albertel 1700: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1701: }
1702: }
1.135 raeburn 1703: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 1704: # Activate roles for sections with two id numbers
1705: # set start, end times, and the url for the class
1.101 albertel 1706: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1707: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 1708: $now );
1.101 albertel 1709: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1710: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 1711: 0 );
1712: my $url='/'.$1.'/';
1.88 raeburn 1713: # split multiple sections
1714: my %sections = ();
1.101 albertel 1715: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 1716: if ($num_sections == 0) {
1.129 albertel 1717: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1718: } else {
1719: my $emptysec = 0;
1720: foreach my $sec (sort {$a cmp $b} keys %sections) {
1721: if ($sec ne '') {
1722: my $securl = $url.'/'.$sec;
1.129 albertel 1723: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 1724: } else {
1725: $emptysec = 1;
1726: }
1727: }
1728: if ($emptysec) {
1.129 albertel 1729: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1730: }
1731: }
1.64 www 1732: } else {
1.135 raeburn 1733: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></p><br />');
1.64 www 1734: }
1.113 raeburn 1735: foreach my $key (sort(keys(%disallowed))) {
1736: if (($key eq 'none') || ($key eq 'all')) {
1737: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1738: } else {
1739: $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));
1740: }
1741: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1742: }
1743: }
1.101 albertel 1744: } # End of foreach (keys(%env))
1.75 www 1745: # Flush the course logs so reverse user roles immediately updated
1746: &Apache::lonnet::flushcourselogs();
1.163 albertel 1747: $r->print('<p><a href="/adm/createuser">'.&mt('Create/Modify Another User').'</a></p>');
1.160 raeburn 1748: $r->print('<form name="userupdate" method="post" />'."\n");
1749: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1750: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1751: }
1752: foreach my $item ('sortby','seluname','seludom') {
1753: if (exists($env{'form.'.$item})) {
1754: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1755: }
1756: }
1757: $r->print('<input type="hidden" name="phase" value="" />'."\n".
1758: '<input type ="hidden" name="state" value="" />'."\n".
1759: '</form>');
1.110 albertel 1760: $r->print(&Apache::loncommon::end_page());
1.4 www 1761: }
1762:
1.149 raeburn 1763: sub quota_admin {
1764: my ($setquota,$changeHash) = @_;
1765: my $quotachanged;
1766: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1767: # Current user has quota modification privileges
1768: $quotachanged = 1;
1769: $changeHash->{'portfolioquota'} = $setquota;
1770: }
1771: return $quotachanged;
1772: }
1773:
1.88 raeburn 1774: sub build_roles {
1.89 raeburn 1775: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 1776: my $num_sections = 0;
1777: if ($sectionstr=~ /,/) {
1778: my @secnums = split/,/,$sectionstr;
1.89 raeburn 1779: if ($role eq 'st') {
1780: $secnums[0] =~ s/\W//g;
1781: $$sections{$secnums[0]} = 1;
1782: $num_sections = 1;
1783: } else {
1784: foreach my $sec (@secnums) {
1785: $sec =~ ~s/\W//g;
1.150 banghart 1786: if (!($sec eq "")) {
1.89 raeburn 1787: if (exists($$sections{$sec})) {
1788: $$sections{$sec} ++;
1789: } else {
1790: $$sections{$sec} = 1;
1791: $num_sections ++;
1792: }
1.88 raeburn 1793: }
1794: }
1795: }
1796: } else {
1797: $sectionstr=~s/\W//g;
1798: unless ($sectionstr eq '') {
1799: $$sections{$sectionstr} = 1;
1800: $num_sections ++;
1801: }
1802: }
1.129 albertel 1803:
1.88 raeburn 1804: return $num_sections;
1805: }
1806:
1.58 www 1807: # ========================================================== Custom Role Editor
1808:
1809: sub custom_role_editor {
1.160 raeburn 1810: my ($r) = @_;
1.101 albertel 1811: my $rolename=$env{'form.rolename'};
1.58 www 1812:
1.59 www 1813: if ($rolename eq 'make new role') {
1.101 albertel 1814: $rolename=$env{'form.newrolename'};
1.59 www 1815: }
1816:
1.63 www 1817: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1818:
1.150 banghart 1819: if (!$rolename) {
1.58 www 1820: &print_username_entry_form($r);
1821: return;
1822: }
1.153 banghart 1823: # ------------------------------------------------------- What can be assigned?
1824: my %full=();
1825: my %courselevel=();
1826: my %courselevelcurrent=();
1.61 www 1827: my $syspriv='';
1828: my $dompriv='';
1829: my $coursepriv='';
1.153 banghart 1830: my $body_top;
1.150 banghart 1831: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 1832: my ($rdummy,$roledef)=
1833: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1834: # ------------------------------------------------------- Does this role exist?
1.153 banghart 1835: $body_top .= '<h2>';
1.59 www 1836: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 1837: $body_top .= &mt('Existing Role').' "';
1.61 www 1838: # ------------------------------------------------- Get current role privileges
1839: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1840: } else {
1.153 banghart 1841: $body_top .= &mt('New Role').' "';
1.59 www 1842: $roledef='';
1843: }
1.153 banghart 1844: $body_top .= $rolename.'"</h2>';
1.135 raeburn 1845: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1846: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 1847: if (!$restrict) { $restrict='F'; }
1.60 www 1848: $courselevel{$priv}=$restrict;
1.61 www 1849: if ($coursepriv=~/\:$priv/) {
1850: $courselevelcurrent{$priv}=1;
1851: }
1.60 www 1852: $full{$priv}=1;
1853: }
1854: my %domainlevel=();
1.61 www 1855: my %domainlevelcurrent=();
1.135 raeburn 1856: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1857: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 1858: if (!$restrict) { $restrict='F'; }
1.60 www 1859: $domainlevel{$priv}=$restrict;
1.61 www 1860: if ($dompriv=~/\:$priv/) {
1861: $domainlevelcurrent{$priv}=1;
1862: }
1.60 www 1863: $full{$priv}=1;
1864: }
1.61 www 1865: my %systemlevel=();
1866: my %systemlevelcurrent=();
1.135 raeburn 1867: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1868: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 1869: if (!$restrict) { $restrict='F'; }
1.61 www 1870: $systemlevel{$priv}=$restrict;
1871: if ($syspriv=~/\:$priv/) {
1872: $systemlevelcurrent{$priv}=1;
1873: }
1874: $full{$priv}=1;
1875: }
1.160 raeburn 1876: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 1877: my $button_code = "\n";
1.153 banghart 1878: my $head_script = "\n";
1879: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 1880: my @template_roles = ("cc","in","ta","ep","st");
1881: foreach my $role (@template_roles) {
1882: $head_script .= &make_script_template($role);
1883: $button_code .= &make_button_code($role);
1884: }
1.160 raeburn 1885: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 1886: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 1887: &Apache::lonhtmlcommon::add_breadcrumb
1888: ({href=>"javascript:backPage(document.form1,'','')",
1.166 albertel 1889: text=>"User modify/custom role edit",
1.160 raeburn 1890: faq=>282,bug=>'Instructor Interface',},
1891: {href=>"javascript:backPage(document.form1,'','')",
1892: text=>"Edit custom role",
1893: faq=>282,bug=>'Instructor Interface',});
1894: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1895:
1.153 banghart 1896: $r->print($body_top);
1.73 sakharuk 1897: my %lt=&Apache::lonlocal::texthash(
1898: 'prv' => "Privilege",
1.131 raeburn 1899: 'crl' => "Course Level",
1.73 sakharuk 1900: 'dml' => "Domain Level",
1.150 banghart 1901: 'ssl' => "System Level");
1.152 banghart 1902: $r->print('Select a Template<br />');
1.154 banghart 1903: $r->print('<form action="">');
1904: $r->print($button_code);
1905: $r->print('</form>');
1.61 www 1906: $r->print(<<ENDCCF);
1.160 raeburn 1907: <form name="form1" method="post">
1.61 www 1908: <input type="hidden" name="phase" value="set_custom_roles" />
1909: <input type="hidden" name="rolename" value="$rolename" />
1910: ENDCCF
1.135 raeburn 1911: $r->print(&Apache::loncommon::start_data_table().
1912: &Apache::loncommon::start_data_table_header_row().
1913: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
1914: '</th><th>'.$lt{'ssl'}.'</th>'.
1915: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 1916: foreach my $priv (sort keys %full) {
1917: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 1918: $r->print(&Apache::loncommon::start_data_table_row().
1919: '<td>'.$privtext.'</td><td>'.
1.150 banghart 1920: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 1921: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1922: '</td><td>'.
1.150 banghart 1923: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 1924: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1925: '</td><td>'.
1.150 banghart 1926: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 1927: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 1928: '</td>'.
1929: &Apache::loncommon::end_data_table_row());
1.60 www 1930: }
1.135 raeburn 1931: $r->print(&Apache::loncommon::end_data_table().
1.160 raeburn 1932: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1933: '" />'."\n".'<input type="hidden" name="state" value="" />'."\n".
1934: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1935: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 1936: &Apache::loncommon::end_page());
1.61 www 1937: }
1.153 banghart 1938: # --------------------------------------------------------
1939: sub make_script_template {
1940: my ($role) = @_;
1941: my %full_c=();
1942: my %full_d=();
1943: my %full_s=();
1944: my $return_script;
1945: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1946: my ($priv,$restrict)=split(/\&/,$item);
1947: $full_c{$priv}=1;
1948: }
1949: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1950: my ($priv,$restrict)=split(/\&/,$item);
1951: $full_d{$priv}=1;
1952: }
1.154 banghart 1953: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 1954: my ($priv,$restrict)=split(/\&/,$item);
1955: $full_s{$priv}=1;
1956: }
1957: $return_script .= 'function set_'.$role.'() {'."\n";
1958: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
1959: my %role_c;
1.155 banghart 1960: foreach my $priv (@temp) {
1.153 banghart 1961: my ($priv_item, $dummy) = split(/\&/,$priv);
1962: $role_c{$priv_item} = 1;
1963: }
1964: foreach my $priv_item (keys(%full_c)) {
1965: my ($priv, $dummy) = split(/\&/,$priv_item);
1966: if (exists($role_c{$priv})) {
1967: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
1968: } else {
1969: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
1970: }
1971: }
1.154 banghart 1972: my %role_d;
1973: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
1974: foreach my $priv(@temp) {
1975: my ($priv_item, $dummy) = split(/\&/,$priv);
1976: $role_d{$priv_item} = 1;
1977: }
1978: foreach my $priv_item (keys(%full_d)) {
1979: my ($priv, $dummy) = split(/\&/,$priv_item);
1980: if (exists($role_d{$priv})) {
1981: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
1982: } else {
1983: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
1984: }
1985: }
1986: my %role_s;
1987: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
1988: foreach my $priv(@temp) {
1989: my ($priv_item, $dummy) = split(/\&/,$priv);
1990: $role_s{$priv_item} = 1;
1991: }
1992: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 1993: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 1994: if (exists($role_s{$priv})) {
1995: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
1996: } else {
1997: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
1998: }
1.153 banghart 1999: }
2000: $return_script .= '}'."\n";
1.154 banghart 2001: return ($return_script);
2002: }
2003: # ----------------------------------------------------------
2004: sub make_button_code {
2005: my ($role) = @_;
2006: my $label = &Apache::lonnet::plaintext($role);
2007: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2008: return ($button_code);
1.153 banghart 2009: }
1.61 www 2010: # ---------------------------------------------------------- Call to definerole
2011: sub set_custom_role {
1.110 albertel 2012: my ($r) = @_;
1.61 www 2013:
1.101 albertel 2014: my $rolename=$env{'form.rolename'};
1.61 www 2015:
1.63 www 2016: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 2017:
1.150 banghart 2018: if (!$rolename) {
1.61 www 2019: &print_username_entry_form($r);
2020: return;
2021: }
2022:
1.160 raeburn 2023: my ($jsback,$elements) = &crumb_utilities();
2024: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2025:
2026: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2027: &Apache::lonhtmlcommon::add_breadcrumb
2028: ({href=>"javascript:backPage(document.customresult,'','')",
1.166 albertel 2029: text=>"User modify/custom role edit",
1.160 raeburn 2030: faq=>282,bug=>'Instructor Interface',},
2031: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2032: text=>"Edit custom role",
2033: faq=>282,bug=>'Instructor Interface',},
2034: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2035: text=>"Result",
2036: faq=>282,bug=>'Instructor Interface',});
2037: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2038:
1.61 www 2039: my ($rdummy,$roledef)=
1.110 albertel 2040: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2041:
1.61 www 2042: # ------------------------------------------------------- Does this role exist?
1.160 raeburn 2043: $r->print('<h2>');
1.61 www 2044: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2045: $r->print(&mt('Existing Role').' "');
1.61 www 2046: } else {
1.73 sakharuk 2047: $r->print(&mt('New Role').' "');
1.61 www 2048: $roledef='';
2049: }
2050: $r->print($rolename.'"</h2>');
2051: # ------------------------------------------------------- What can be assigned?
2052: my $sysrole='';
2053: my $domrole='';
2054: my $courole='';
2055:
1.135 raeburn 2056: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2057: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2058: if (!$restrict) { $restrict=''; }
2059: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2060: $courole.=':'.$item;
1.61 www 2061: }
2062: }
2063:
1.135 raeburn 2064: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2065: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2066: if (!$restrict) { $restrict=''; }
2067: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2068: $domrole.=':'.$item;
1.61 www 2069: }
2070: }
2071:
1.135 raeburn 2072: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2073: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2074: if (!$restrict) { $restrict=''; }
2075: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2076: $sysrole.=':'.$item;
1.61 www 2077: }
2078: }
1.63 www 2079: $r->print('<br />Defining Role: '.
1.61 www 2080: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2081: if ($env{'request.course.id'}) {
2082: my $url='/'.$env{'request.course.id'};
1.63 www 2083: $url=~s/\_/\//g;
1.73 sakharuk 2084: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2085: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2086: $env{'user.name'},
1.63 www 2087: $url,
1.101 albertel 2088: $env{'user.domain'},
2089: $env{'user.name'},
1.63 www 2090: $rolename));
2091: }
1.160 raeburn 2092: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p><form name="customresult" method="post">');
2093: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2094: $r->print(&Apache::loncommon::end_page());
1.58 www 2095: }
2096:
1.2 www 2097: # ================================================================ Main Handler
2098: sub handler {
2099: my $r = shift;
2100:
2101: if ($r->header_only) {
1.68 www 2102: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2103: $r->send_http_header;
2104: return OK;
2105: }
2106:
1.101 albertel 2107: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
2108: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
2109: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
2110: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1.104 albertel 2111: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1.101 albertel 2112: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1.68 www 2113: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2114: $r->send_http_header;
1.160 raeburn 2115: &Apache::lonhtmlcommon::clear_breadcrumbs();
2116:
2117: my $phase = $env{'form.phase'};
2118: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
2119:
2120: if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
2121: my $srch;
2122: foreach my $item (@search) {
2123: $srch->{$item} = $env{'form.'.$item};
2124: }
2125: if ($env{'form.phase'} eq 'get_user_info') {
2126: my ($state,$response,$forcenewuser,$results) =
2127: &user_search_result($srch);
2128: if ($state eq 'select') {
2129: &print_user_selection_page($r,$response,$srch,$results);
2130: } elsif ($state eq 'modify') {
2131: my ($ccuname,$ccdomain);
1.162 raeburn 2132: if (($srch->{'srchby'} eq 'uname') &&
2133: ($srch->{'srchtype'} eq 'exact')) {
1.160 raeburn 2134: $ccuname = $srch->{'srchterm'};
2135: $ccdomain= $srch->{'srchdomain'};
2136: } else {
2137: my @matchedunames = keys(%{$results});
2138: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2139: }
2140: $ccuname =&LONCAPA::clean_username($ccuname);
2141: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2142: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,
2143: $response);
2144: } elsif ($state eq 'query') {
2145: &print_user_query_page($r);
2146: } else {
2147: &print_username_entry_form($r,$response,$srch,$forcenewuser);
2148: }
2149: } elsif ($env{'form.phase'} eq 'userpicked') {
2150: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2151: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
2152: &print_user_modification_page($r,$ccuname,$ccdomain,$srch);
2153: }
1.101 albertel 2154: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.42 matthew 2155: &update_user_data($r);
1.101 albertel 2156: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1.58 www 2157: &custom_role_editor($r);
1.101 albertel 2158: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1.61 www 2159: &set_custom_role($r);
1.160 raeburn 2160: } else {
2161: &print_username_entry_form($r);
1.2 www 2162: }
1.1 www 2163: } else {
1.101 albertel 2164: $env{'user.error.msg'}=
1.9 albertel 2165: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 2166: return HTTP_NOT_ACCEPTABLE;
2167: }
2168: return OK;
1.160 raeburn 2169: }
1.26 matthew 2170:
1.27 matthew 2171: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 2172: sub user_search_result {
2173: my ($srch) = @_;
2174: my %allhomes;
2175: my %inst_matches;
2176: my %srch_results;
2177: my ($response,$state,$forcenewuser);
2178:
2179: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
2180: $response = &mt('Invalid search.');
2181: }
2182: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
2183: $response = &mt('Invalid search.');
2184: }
2185: if ($srch->{'srchtype'} !~ /^(exact|contains)$/) {
2186: $response = &mt('Invalid search.');
2187: }
2188: if ($srch->{'srchterm'} eq '') {
2189: $response = &mt('You must enter a search term.');
2190: }
2191: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
2192: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 2193: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 2194: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
2195: }
2196: }
2197: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
2198: ($srch->{'srchin'} eq 'alc')) {
2199: if ($srch->{'srchterm'} !~ /^$match_username$/) {
2200: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
2201: }
2202: }
2203: if ($srch->{'srchin'} eq 'instd') {
2204: my $instd_chk = &directorysrch_check($srch);
2205: if ($instd_chk ne 'ok') {
2206: $response = $instd_chk;
2207: }
2208: }
2209: if ($response ne '') {
1.163 albertel 2210: return ($state,'<span class="LC_warning">'.$response.'</span>');
1.160 raeburn 2211: }
2212: if ($srch->{'srchby'} eq 'uname') {
2213: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
2214: if ($env{'form.forcenew'}) {
2215: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
2216: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2217: if ($uhome eq 'no_host') {
2218: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2219: $response = &mt('New users can only be created in the domain to which you current role belongs - [_1].',$env{'request.role.domain'}.' ('.$domdesc.')');
2220: } else {
2221: $state = 'modify';
2222: }
2223: } else {
2224: $state = 'modify';
2225: }
2226: } else {
2227: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 2228: if ($srch->{'srchtype'} eq 'exact') {
2229: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2230: if ($uhome eq 'no_host') {
2231: ($state,$response,$forcenewuser) =
2232: &build_search_response($srch,%srch_results);
2233: } else {
2234: $state = 'modify';
2235: }
2236: } else {
2237: %srch_results = &Apache::lonnet::usersearch($srch);
1.160 raeburn 2238: ($state,$response,$forcenewuser) =
2239: &build_search_response($srch,%srch_results);
2240: }
2241: } else {
1.167 albertel 2242: my $courseusers = &get_courseusers();
1.162 raeburn 2243: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 2244: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.162 raeburn 2245: $state = 'modify';
2246: } else {
2247: ($state,$response,$forcenewuser) =
2248: &build_search_response($srch,%srch_results);
2249: }
1.160 raeburn 2250: } else {
1.167 albertel 2251: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 2252: my ($cuname,$cudomain) = split(/:/,$user);
2253: if ($cudomain eq $srch->{'srchdomain'}) {
2254: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
1.167 albertel 2255: $srch_results{$user} =
2256: {&Apache::lonnet::get('environment',
2257: ['firstname',
2258: 'lastname',
2259: 'permanentemail'])};
1.162 raeburn 2260: }
2261: }
2262: }
1.160 raeburn 2263: ($state,$response,$forcenewuser) =
2264: &build_search_response($srch,%srch_results);
2265: }
2266: }
2267: }
2268: } elsif ($srch->{'srchin'} eq 'alc') {
2269: $state = 'query';
2270: } elsif ($srch->{'srchin'} eq 'instd') {
2271: %srch_results = &Apache::lonnet::inst_directory_query($srch);
2272: ($state,$response,$forcenewuser) =
2273: &build_search_response($srch,%srch_results);
2274: }
2275: } else {
2276: if ($srch->{'srchin'} eq 'dom') {
2277: %srch_results = &Apache::lonnet::usersearch($srch);
2278: ($state,$response,$forcenewuser) =
2279: &build_search_response($srch,%srch_results);
2280: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 2281: my $courseusers = &get_courseusers();
2282: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 2283: my ($uname,$udom) = split(/:/,$user);
2284: my %names = &Apache::loncommon::getnames($uname,$udom);
2285: my %emails = &Apache::loncommon::getemails($uname,$udom);
2286: if ($srch->{'srchby'} eq 'lastname') {
2287: if ((($srch->{'srchtype'} eq 'exact') &&
2288: ($names{'lastname'} eq $srch->{'srchterm'})) ||
2289: (($srch->{'srchtype'} eq 'contains') &&
2290: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
2291: $srch_results{$user} = {firstname => $names{'firstname'},
2292: lastname => $names{'lastname'},
2293: permanentemail => $emails{'permanentemail'},
2294: };
2295: }
2296: } elsif ($srch->{'srchby'} eq 'lastfirst') {
2297: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
2298: if ($srch->{'srchtype'} eq 'exact') {
2299: if (($names{'lastname'} eq $srchlast) &&
2300: ($names{'firstname'} eq $srchfirst)) {
2301: $srch_results{$user} = {firstname => $names{'firstname'},
2302: lastname => $names{'lastname'},
2303: permanentemail => $emails{'permanentemail'},
2304:
2305: };
2306: }
2307: } elsif ($srch->{'srchtype'} eq 'contains') {
2308: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
2309: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
2310: $srch_results{$user} = {firstname => $names{'firstname'},
2311: lastname => $names{'lastname'},
2312: permanentemail => $emails{'permanentemail'},
2313: };
2314: }
2315: }
2316: }
2317: }
2318: ($state,$response,$forcenewuser) =
2319: &build_search_response($srch,%srch_results);
2320: } elsif ($srch->{'srchin'} eq 'alc') {
2321: $state = 'query';
2322: } elsif ($srch->{'srchin'} eq 'instd') {
2323: %srch_results = &Apache::lonnet::inst_directory_query($srch);
2324: ($state,$response,$forcenewuser) =
2325: &build_search_response($srch,%srch_results);
2326: }
2327: }
2328: return ($state,$response,$forcenewuser,\%srch_results);
2329: }
2330:
2331: sub directorysrch_check {
2332: my ($srch) = @_;
2333: my $can_search = 0;
2334: my $response;
2335: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
2336: ['directorysrch'],$srch->{'srchdomain'});
2337: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
2338: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.163 albertel 2339: return &mt('Institutional directory search unavailable in domain: [_1]',$srch->{'srchdomain'});
1.160 raeburn 2340: }
2341: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
2342: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.163 albertel 2343: 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 2344: }
2345: my @usertypes = split(/:/,$env{'environment.inststatus'});
2346: if (!@usertypes) {
2347: push(@usertypes,'default');
2348: }
2349: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
2350: foreach my $type (@usertypes) {
2351: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
2352: $can_search = 1;
2353: last;
2354: }
2355: }
2356: }
2357: if (!$can_search) {
2358: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
2359: my @longtypes;
2360: foreach my $item (@usertypes) {
2361: push (@longtypes,$insttypes->{$item});
2362: }
2363: my $insttype_str = join(', ',@longtypes);
2364: return &mt('Directory search in domain: [_1] is unavailable to your user type: ',$srch->{'srchdomain'}).$insttype_str;
2365: }
2366: } else {
2367: $can_search = 1;
2368: }
2369: } else {
2370: return &mt('Directory search has not been configured for domain: [_1]',$srch->{'srchdomain'});
2371: }
2372: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 2373: uname => 'username',
1.160 raeburn 2374: lastfirst => 'last name, first name',
1.167 albertel 2375: lastname => 'last name',
2376: contains => 'is contained in',
2377: exact => 'as exact match to'
1.160 raeburn 2378: );
2379: if ($can_search) {
2380: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
2381: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
2382: return &mt('Directory search in domain: [_1] is not available for searching by [_2]',$srch->{'srchdomain'},$longtext{$srch->{'srchby'}});
2383: }
2384: } else {
2385: return &mt('Directory search in domain: [_1] is not available.', $srch->{'srchdomain'});
2386: }
2387: }
2388: if ($can_search) {
2389: if (($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') ||
2390: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
2391: return 'ok';
2392: } else {
2393: return &mt('Directory search in domain [_1] is not available for the requested search type: [_2]',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
2394: }
2395: }
2396: }
2397:
2398:
2399: sub get_courseusers {
2400: my %advhash;
1.167 albertel 2401: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 2402: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
2403: foreach my $role (sort(keys(%coursepersonnel))) {
2404: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 2405: if (!exists($classlist->{$user})) {
2406: $classlist->{$user} = [];
2407: }
1.160 raeburn 2408: }
2409: }
1.167 albertel 2410: return $classlist;
1.160 raeburn 2411: }
2412:
2413: sub build_search_response {
2414: my ($srch,%srch_results) = @_;
2415: my ($state,$response,$forcenewuser);
2416: my %names = (
2417: 'uname' => 'username',
2418: 'lastname' => 'last name',
2419: 'lastfirst' => 'last name, first name',
2420: 'crs' => 'this course',
2421: 'dom' => 'this domain',
2422: 'instd' => "your institution's directory",
2423: );
2424:
2425: my %single = (
2426: contains => 'A match',
2427: exact => 'An exact match',
2428: );
2429: my %nomatch = (
2430: contains => 'No match',
2431: exact => 'No exact match',
2432: );
2433: if (keys(%srch_results) > 1) {
2434: $state = 'select';
2435: } else {
2436: if (keys(%srch_results) == 1) {
2437: $state = 'modify';
2438: $response = &mt("$single{$srch->{'srchtype'}} was found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
2439: } else {
1.163 albertel 2440: $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 2441: if ($srch->{'srchin'} ne 'alc') {
2442: $forcenewuser = 1;
2443: my $cansrchinst = 0;
2444: if ($srch->{'srchdomain'}) {
2445: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
2446: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2447: if ($domconfig{'directorysrch'}{'available'}) {
2448: $cansrchinst = 1;
2449: }
2450: }
2451: }
2452: if (($srch->{'srchby'} eq 'lastfirst') ||
2453: ($srch->{'srchby'} eq 'lastname')) {
2454: if ($srch->{'srchin'} eq 'crs') {
2455: $response .= '<br />'.&mt('You may want to broaden your search to the whole domain.');
2456: } elsif ($srch->{'srchin'} eq 'dom') {
2457: if ($cansrchinst) {
2458: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for this domain.');
2459: }
2460: }
2461: }
2462: }
2463: }
2464: }
2465: return ($state,$response,$forcenewuser);
2466: }
2467:
2468: sub crumb_utilities {
2469: my %elements = (
2470: crtuser => {
2471: srchterm => 'text',
1.168 albertel 2472: srchin => 'radio',
1.160 raeburn 2473: srchby => 'selectbox',
2474: srchtype => 'selectbox',
2475: srchdomain => 'selectbox',
2476: },
2477: docustom => {
2478: rolename => 'selectbox',
2479: newrolename => 'textbox',
2480: },
2481: );
2482:
2483: my $jsback .= qq|
2484: function backPage(formname,prevphase,prevstate) {
2485: formname.phase.value = prevphase;
2486: formname.state.value = prevstate;
2487: formname.submit();
2488: }
2489: |;
2490: return ($jsback,\%elements);
2491: }
2492:
1.26 matthew 2493: sub course_level_table {
1.89 raeburn 2494: my (%inccourses) = @_;
1.26 matthew 2495: my $table = '';
1.62 www 2496: # Custom Roles?
2497:
2498: my %customroles=&my_custom_roles();
1.89 raeburn 2499: my %lt=&Apache::lonlocal::texthash(
2500: 'exs' => "Existing sections",
2501: 'new' => "Define new section",
2502: 'ssd' => "Set Start Date",
2503: 'sed' => "Set End Date",
1.131 raeburn 2504: 'crl' => "Course Level",
1.89 raeburn 2505: 'act' => "Activate",
2506: 'rol' => "Role",
2507: 'ext' => "Extent",
1.113 raeburn 2508: 'grs' => "Section",
1.89 raeburn 2509: 'sta' => "Start",
2510: 'end' => "End"
2511: );
1.62 www 2512:
1.135 raeburn 2513: foreach my $protectedcourse (sort( keys(%inccourses))) {
2514: my $thiscourse=$protectedcourse;
1.26 matthew 2515: $thiscourse=~s:_:/:g;
2516: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
2517: my $area=$coursedata{'description'};
1.119 raeburn 2518: my $type=$coursedata{'type'};
1.135 raeburn 2519: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 2520: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 2521: my %sections_count;
1.101 albertel 2522: if (defined($env{'request.course.id'})) {
2523: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 2524: %sections_count =
2525: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 2526: }
2527: }
1.135 raeburn 2528: foreach my $role ('st','ta','ep','in','cc') {
2529: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
2530: my $plrole=&Apache::lonnet::plaintext($role);
1.136 raeburn 2531: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 2532: '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
1.136 raeburn 2533: <td>'.$plrole.'</td>
2534: <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.135 raeburn 2535: if ($role ne 'cc') {
1.115 albertel 2536: if (%sections_count) {
1.135 raeburn 2537: my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
1.89 raeburn 2538: $table .=
1.137 raeburn 2539: '<td><table class="LC_createuser">'.
2540: '<tr class="LC_section_row">
2541: <td valign="top">'.$lt{'exs'}.'<br />'.
1.89 raeburn 2542: $currsec.'</td>'.
2543: '<td> </td>'.
2544: '<td valign="top"> '.$lt{'new'}.'<br />'.
1.157 albertel 2545: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
1.89 raeburn 2546: '<input type="hidden" '.
1.157 albertel 2547: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
1.89 raeburn 2548: '</tr></table></td>';
2549: } else {
2550: $table .= '<td><input type="text" size="10" '.
1.157 albertel 2551: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
1.89 raeburn 2552: }
1.26 matthew 2553: } else {
1.89 raeburn 2554: $table .= '<td> </td>';
1.26 matthew 2555: }
2556: $table .= <<ENDTIMEENTRY;
1.169 ! albertel 2557: <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
1.26 matthew 2558: <a href=
1.135 raeburn 2559: "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 2560: <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
1.26 matthew 2561: <a href=
1.135 raeburn 2562: "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 2563: ENDTIMEENTRY
1.136 raeburn 2564: $table.= &Apache::loncommon::end_data_table_row();
1.26 matthew 2565: }
2566: }
1.135 raeburn 2567: foreach my $cust (sort keys %customroles) {
1.65 www 2568: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.135 raeburn 2569: my $plrole=$cust;
1.101 albertel 2570: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
2571: '_'.$env{'user.name'}.'_'.$plrole;
1.136 raeburn 2572: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 2573: '<td><input type="checkbox" name="act_'.$customrole.'" /></td>
1.136 raeburn 2574: <td>'.$plrole.'</td>
2575: <td>'.$area.'</td>'."\n";
1.115 albertel 2576: if (%sections_count) {
2577: my $currsec = &course_sections(\%sections_count,$customrole);
1.89 raeburn 2578: $table.=
2579: '<td><table border="0" cellspacing="0" cellpadding="0">'.
2580: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
2581: $currsec.'</td>'.
2582: '<td> </td>'.
2583: '<td valign="top"> '.$lt{'new'}.'<br />'.
2584: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
2585: '<input type="hidden" '.
1.157 albertel 2586: 'name="sec_'.$customrole.'" /></td>'.
1.89 raeburn 2587: '</tr></table></td>';
2588: } else {
2589: $table .= '<td><input type="text" size="10" '.
1.157 albertel 2590: 'name="sec_'.$customrole.'" /></td>';
1.89 raeburn 2591: }
2592: $table .= <<ENDENTRY;
1.169 ! albertel 2593: <td><input type="hidden" name="start_$customrole" value='' />
1.62 www 2594: <a href=
1.73 sakharuk 2595: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 ! albertel 2596: <td><input type="hidden" name="end_$customrole" value='' />
1.62 www 2597: <a href=
1.136 raeburn 2598: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
1.62 www 2599: ENDENTRY
1.136 raeburn 2600: $table .= &Apache::loncommon::end_data_table_row();
1.65 www 2601: }
1.62 www 2602: }
1.26 matthew 2603: }
2604: return '' if ($table eq ''); # return nothing if there is nothing
2605: # in the table
1.136 raeburn 2606: my $result = '
2607: <h4>'.$lt{'crl'}.'</h4>'.
2608: &Apache::loncommon::start_data_table().
2609: &Apache::loncommon::start_data_table_header_row().
2610: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
2611: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
2612: &Apache::loncommon::end_data_table_header_row().
2613: $table.
2614: &Apache::loncommon::end_data_table();
1.26 matthew 2615: return $result;
2616: }
1.88 raeburn 2617:
1.89 raeburn 2618: sub course_sections {
1.115 albertel 2619: my ($sections_count,$role) = @_;
1.89 raeburn 2620: my $output = '';
2621: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.115 albertel 2622: if (scalar(@sections) == 1) {
1.92 raeburn 2623: $output = '<select name="currsec_'.$role.'" >'."\n".
2624: ' <option value="">Select</option>'."\n".
1.93 raeburn 2625: ' <option value="">No section</option>'."\n".
1.92 raeburn 2626: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
2627: } else {
2628: $output = '<select name="currsec_'.$role.'" ';
2629: my $multiple = 4;
1.115 albertel 2630: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.145 raeburn 2631: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
1.135 raeburn 2632: foreach my $sec (@sections) {
2633: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
1.92 raeburn 2634: }
1.89 raeburn 2635: }
2636: $output .= '</select>';
2637: return $output;
2638: }
2639:
1.88 raeburn 2640: sub course_level_dc {
2641: my ($dcdom) = @_;
2642: my %customroles=&my_custom_roles();
2643: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
2644: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 2645: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 2646: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 2647: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
2648: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 2649: my %lt=&Apache::lonlocal::texthash(
2650: 'rol' => "Role",
1.113 raeburn 2651: 'grs' => "Section",
1.88 raeburn 2652: 'exs' => "Existing sections",
2653: 'new' => "Define new section",
2654: 'sta' => "Start",
2655: 'end' => "End",
2656: 'ssd' => "Set Start Date",
2657: 'sed' => "Set End Date"
2658: );
1.131 raeburn 2659: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 2660: &Apache::loncommon::start_data_table().
2661: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 2662: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 2663: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 2664: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 2665: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 2666: '<td><select name="role">'."\n";
1.135 raeburn 2667: foreach my $role ('st','ta','ep','in','cc') {
2668: my $plrole=&Apache::lonnet::plaintext($role);
2669: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 2670: }
2671: if ( keys %customroles > 0) {
1.135 raeburn 2672: foreach my $cust (sort keys %customroles) {
1.101 albertel 2673: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 2674: '_'.$env{'user.name'}.'_'.$cust;
2675: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 2676: }
2677: }
2678: $otheritems .= '</select></td><td>'.
2679: '<table border="0" cellspacing="0" cellpadding="0">'.
2680: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
2681: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
2682: '<td> </td>'.
2683: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 2684: '<input type="text" name="newsec" value="" />'.
2685: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 2686: '</tr></table></td>';
2687: $otheritems .= <<ENDTIMEENTRY;
1.169 ! albertel 2688: <td><input type="hidden" name="start" value='' />
1.88 raeburn 2689: <a href=
2690: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 ! albertel 2691: <td><input type="hidden" name="end" value='' />
1.88 raeburn 2692: <a href=
2693: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
2694: ENDTIMEENTRY
1.136 raeburn 2695: $otheritems .= &Apache::loncommon::end_data_table_row().
2696: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 2697: return $cb_jscript.$header.$hiddenitems.$otheritems;
2698: }
2699:
1.27 matthew 2700: #---------------------------------------------- end functions for &phase_two
1.29 matthew 2701:
2702: #--------------------------------- functions for &phase_two and &phase_three
2703:
2704: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 2705:
2706: 1;
2707: __END__
1.2 www 2708:
2709:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>