Annotation of loncom/interface/loncreateuser.pm, revision 1.244
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.244 ! bisitz 4: # $Id: loncreateuser.pm,v 1.243 2008/06/05 12:55:04 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
1.1 www 61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
1.54 bowersj2 65: use Apache::loncommon;
1.68 www 66: use Apache::lonlocal;
1.117 raeburn 67: use Apache::longroup;
1.190 raeburn 68: use Apache::lonuserutils;
1.139 albertel 69: use LONCAPA qw(:DEFAULT :match);
1.1 www 70:
1.20 harris41 71: my $loginscript; # piece of javascript used in two separate instances
72: my $authformnop;
73: my $authformkrb;
74: my $authformint;
75: my $authformfsys;
76: my $authformloc;
77:
1.94 matthew 78: sub initialize_authen_forms {
1.227 raeburn 79: my ($dom,$formname,$curr_authtype,$mode) = @_;
80: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
81: my %param = ( formname => $formname,
1.187 raeburn 82: kerb_def_dom => $krbdefdom,
1.227 raeburn 83: kerb_def_auth => $krbdef,
1.187 raeburn 84: domain => $dom,
85: );
1.188 raeburn 86: my %abv_auth = &auth_abbrev();
1.227 raeburn 87: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 88: my $long_auth = $1;
1.227 raeburn 89: my $curr_autharg = $2;
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
91: $param{'curr_authtype'} = $abv_auth{$long_auth};
92: if ($long_auth =~ /^krb(4|5)$/) {
93: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 94: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 95: }
1.205 raeburn 96: if ($mode eq 'modifyuser') {
97: $param{'mode'} = $mode;
98: }
1.187 raeburn 99: }
1.227 raeburn 100: $loginscript = &Apache::loncommon::authform_header(%param);
101: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 102: $authformnop = &Apache::loncommon::authform_nochange(%param);
103: $authformint = &Apache::loncommon::authform_internal(%param);
104: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
105: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 106: }
107:
1.188 raeburn 108: sub auth_abbrev {
109: my %abv_auth = (
110: krb4 => 'krb',
111: internal => 'int',
112: localuth => 'loc',
113: unix => 'fsys',
114: );
115: return %abv_auth;
116: }
1.43 www 117:
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 '') {
1.230 bisitz 159: $defaultinfo = &mt('For this user, the default quota would be [_1]'
160: .' Mb.',$defquota);
1.149 raeburn 161: } else {
1.231 raeburn 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);
1.149 raeburn 165: }
166: } else {
167: if ($longinsttype eq '') {
1.230 bisitz 168: $defaultinfo = &mt('For this user, the default quota is [_1]'
169: .' Mb.',$defquota);
1.149 raeburn 170: } else {
1.231 raeburn 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);
1.149 raeburn 174: }
175: }
176: my $output = $quota_javascript.
177: '<h3>'.$lt{'disk'}.'</h3>'.
1.188 raeburn 178: &Apache::loncommon::start_data_table().
179: &Apache::loncommon::start_data_table_row().
180: '<td>'.$lt{'cuqu'}.': '.$currquota.' Mb. '.
181: $defaultinfo.'</td>'.
182: &Apache::loncommon::end_data_table_row().
183: &Apache::loncommon::start_data_table_row().
184: '<td><span class="LC_nobreak">'.$lt{'chqu'}.
1.149 raeburn 185: ': <label>'.
186: '<input type="radio" name="customquota" value="0" '.
187: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"
188: />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
189: ' <label><input type="radio" name="customquota" value="1" '.
190: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
191: $lt{'cust'}.':</label> '.
1.134 raeburn 192: '<input type="text" name="portfolioquota" size ="5" value="'.
1.149 raeburn 193: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
1.188 raeburn 194: '/> Mb</span></td>'.
195: &Apache::loncommon::end_data_table_row().
196: &Apache::loncommon::end_data_table();
1.134 raeburn 197: return $output;
198: }
199:
1.2 www 200: # =================================================================== Phase one
1.1 www 201:
1.42 matthew 202: sub print_username_entry_form {
1.207 raeburn 203: my ($r,$context,$response,$srch,$forcenewuser) = @_;
1.101 albertel 204: my $defdom=$env{'request.role.domain'};
1.160 raeburn 205: my $formtoset = 'crtuser';
206: if (exists($env{'form.startrolename'})) {
207: $formtoset = 'docustom';
208: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 209: } elsif ($env{'form.origform'} eq 'crtusername') {
210: $formtoset = $env{'form.origform'};
1.160 raeburn 211: }
212:
213: my ($jsback,$elements) = &crumb_utilities();
214:
215: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 216: '<script type="text/javascript">'."\n".
1.160 raeburn 217: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
1.162 raeburn 218: '</script>'."\n";
1.160 raeburn 219:
220: my %loaditems = (
221: 'onload' => "javascript:setFormElements(document.$formtoset)",
222: );
1.229 raeburn 223: my %breadcrumb_text = &singleuser_breadcrumb();
1.110 albertel 224: my $start_page =
1.190 raeburn 225: &Apache::loncommon::start_page('User Management',
1.160 raeburn 226: $jscript,{'add_entries' => \%loaditems,});
1.214 raeburn 227: if ($env{'form.action'} eq 'custom') {
228: &Apache::lonhtmlcommon::add_breadcrumb
229: ({href=>"javascript:backPage(document.crtuser)",
230: text=>"Pick custom role",});
231: } else {
1.190 raeburn 232: &Apache::lonhtmlcommon::add_breadcrumb
233: ({href=>"javascript:backPage(document.crtuser)",
1.229 raeburn 234: text=>$breadcrumb_text{'search'},
1.190 raeburn 235: faq=>282,bug=>'Instructor Interface',});
236: }
1.224 raeburn 237: my $helpitem = 'Course_Change_Privileges';
238: if ($env{'form.action'} eq 'custom') {
239: $helpitem = 'Course_Editing_Custom_Roles';
240: } elsif ($env{'form.action'} eq 'singlestudent') {
241: $helpitem = 'Course_Add_Student';
242: }
243: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
244: $helpitem);
1.190 raeburn 245: my %existingroles=&Apache::lonuserutils::my_custom_roles();
1.59 www 246: my $choice=&Apache::loncommon::select_form('make new role','rolename',
247: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 248: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 249: 'srst' => 'Search for a user and enroll as a student',
250: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 251: 'usr' => "Username",
252: 'dom' => "Domain",
253: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 254: 'nr' => "Name of Role",
1.160 raeburn 255: 'cre' => "Custom Role Editor",
1.71 sakharuk 256: );
1.190 raeburn 257: $r->print($start_page."\n".$crumbs);
1.214 raeburn 258: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 259: if (&Apache::lonnet::allowed('mcr','/')) {
260: $r->print(<<ENDCUSTOM);
1.58 www 261: <form action="/adm/createuser" method="post" name="docustom">
1.190 raeburn 262: <input type="hidden" name="action" value="$env{'form.action'}" />
1.157 albertel 263: <input type="hidden" name="phase" value="selected_custom_edit" />
1.224 raeburn 264: <h3>$lt{'ecrp'}</h3>
1.72 sakharuk 265: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 266: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107 www 267: </form>
1.106 www 268: ENDCUSTOM
1.190 raeburn 269: }
1.213 raeburn 270: } else {
1.229 raeburn 271: my $actiontext = $lt{'srad'};
1.213 raeburn 272: if ($env{'form.action'} eq 'singlestudent') {
1.229 raeburn 273: $actiontext = $lt{'srst'};
1.213 raeburn 274: }
275: $r->print("
1.229 raeburn 276: <h3>$actiontext</h3>");
1.213 raeburn 277: if ($env{'form.origform'} ne 'crtusername') {
278: $r->print("\n".$response);
279: }
280: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
1.107 www 281: }
1.110 albertel 282: $r->print(&Apache::loncommon::end_page());
283: }
284:
1.160 raeburn 285: sub entry_form {
1.214 raeburn 286: my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
1.207 raeburn 287: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.229 raeburn 288: my ($usertype,$inexact);
1.214 raeburn 289: if (ref($srch) eq 'HASH') {
290: if (($srch->{'srchin'} eq 'dom') &&
291: ($srch->{'srchby'} eq 'uname') &&
292: ($srch->{'srchtype'} eq 'exact') &&
293: ($srch->{'srchdomain'} ne '') &&
294: ($srch->{'srchterm'} ne '')) {
295: my ($rules,$ruleorder) =
296: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
297: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
1.229 raeburn 298: } else {
299: $inexact = 1;
1.214 raeburn 300: }
1.207 raeburn 301: }
1.214 raeburn 302: my $cancreate =
303: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 304: my $userpicker =
1.179 raeburn 305: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 306: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 307: my $srchbutton = &mt('Search');
1.229 raeburn 308: if ($env{'form.action'} eq 'singlestudent') {
309: $srchbutton = &mt('Search and Enroll');
310: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
311: $srchbutton = &mt('Search or Add New User');
312: }
1.207 raeburn 313: my $output = <<"ENDBLOCK";
1.160 raeburn 314: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 315: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 316: <input type="hidden" name="phase" value="get_user_info" />
317: $userpicker
1.179 raeburn 318: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 319: </form>
1.207 raeburn 320: ENDBLOCK
1.229 raeburn 321: if ($env{'form.phase'} eq '') {
1.207 raeburn 322: my $defdom=$env{'request.role.domain'};
323: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
324: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 325: 'enro' => 'Enroll one student',
326: 'admo' => 'Add/modify a single user',
327: 'crea' => 'create new user if required',
328: 'uskn' => "username is known",
1.207 raeburn 329: 'crnu' => 'Create a new user',
330: 'usr' => 'Username',
331: 'dom' => 'in domain',
1.229 raeburn 332: 'enrl' => 'Enroll',
333: 'cram' => 'Create/Modify user',
1.207 raeburn 334: );
1.229 raeburn 335: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
336: my ($title,$buttontext,$showresponse);
337: if ($env{'form.action'} eq 'singlestudent') {
338: $title = $lt{'enro'};
339: $buttontext = $lt{'enrl'};
340: } else {
341: $title = $lt{'admo'};
342: $buttontext = $lt{'cram'};
343: }
344: if ($cancreate) {
345: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
346: } else {
347: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
348: }
349: if ($env{'form.origform'} eq 'crtusername') {
350: $showresponse = $responsemsg;
351: }
1.207 raeburn 352: $output .= <<"ENDDOCUMENT";
1.229 raeburn 353: <br />
1.207 raeburn 354: <form action="/adm/createuser" method="post" name="crtusername">
355: <input type="hidden" name="action" value="$env{'form.action'}" />
356: <input type="hidden" name="phase" value="createnewuser" />
357: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 358: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 359: <input type="hidden" name="srchin" value="dom" />
360: <input type="hidden" name="forcenewuser" value="1" />
361: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 362: <h3>$title</h3>
363: $showresponse
1.207 raeburn 364: <table>
365: <tr>
366: <td>$lt{'usr'}:</td>
367: <td><input type="text" size="15" name="srchterm" /></td>
368: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 369: <td> $sellink </td>
370: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 371: </tr>
372: </table>
373: </form>
1.160 raeburn 374: ENDDOCUMENT
1.207 raeburn 375: }
1.160 raeburn 376: return $output;
377: }
1.110 albertel 378:
379: sub user_modification_js {
1.113 raeburn 380: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
381:
1.110 albertel 382: return <<END;
383: <script type="text/javascript" language="Javascript">
384:
385: function pclose() {
386: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
387: "height=350,width=350,scrollbars=no,menubar=no");
388: parmwin.close();
389: }
390:
391: $pjump_def
392: $dc_setcourse_code
393:
394: function dateset() {
395: eval("document.cu."+document.cu.pres_marker.value+
396: ".value=document.cu.pres_value.value");
397: pclose();
398: }
399:
1.113 raeburn 400: $nondc_setsection_code
401:
1.110 albertel 402: </script>
403: END
1.2 www 404: }
405:
406: # =================================================================== Phase two
1.160 raeburn 407: sub print_user_selection_page {
1.229 raeburn 408: my ($r,$response,$srch,$srch_results,$srcharray,$context) = @_;
1.160 raeburn 409: my @fields = ('username','domain','lastname','firstname','permanentemail');
410: my $sortby = $env{'form.sortby'};
411:
412: if (!grep(/^\Q$sortby\E$/,@fields)) {
413: $sortby = 'lastname';
414: }
415:
416: my ($jsback,$elements) = &crumb_utilities();
417:
418: my $jscript = (<<ENDSCRIPT);
419: <script type="text/javascript">
420: function pickuser(uname,udom) {
421: document.usersrchform.seluname.value=uname;
422: document.usersrchform.seludom.value=udom;
423: document.usersrchform.phase.value="userpicked";
424: document.usersrchform.submit();
425: }
426:
427: $jsback
428: </script>
429: ENDSCRIPT
430:
431: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 432: 'usrch' => "User Search to add/modify roles",
433: 'stusrch' => "User Search to enroll student",
434: 'usel' => "Select a user to add/modify roles",
435: 'stusel' => "Select a user to enroll as a student",
1.160 raeburn 436: 'username' => "username",
437: 'domain' => "domain",
438: 'lastname' => "last name",
439: 'firstname' => "first name",
440: 'permanentemail' => "permanent e-mail",
441: );
1.214 raeburn 442: $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.229 raeburn 443:
444: my %breadcrumb_text = &singleuser_breadcrumb();
445: &Apache::lonhtmlcommon::add_breadcrumb
446: ({href=>"javascript:backPage(document.usersrchform,'','')",
447: text=>$breadcrumb_text{'search'},
448: faq=>282,bug=>'Instructor Interface',},
449: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
450: text=>$breadcrumb_text{'userpicked'},
451: faq=>282,bug=>'Instructor Interface',});
452: if ($env{'form.action'} eq 'singleuser') {
1.224 raeburn 453: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
454: 'Course_Change_Privileges'));
1.179 raeburn 455: $r->print("<b>$lt{'usrch'}</b><br />");
1.207 raeburn 456: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179 raeburn 457: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1.229 raeburn 458: } elsif ($env{'form.action'} eq 'singlestudent') {
1.224 raeburn 459: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
460: 'Course_Add_Student'));
1.179 raeburn 461: $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
1.214 raeburn 462: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179 raeburn 463: $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
464: }
1.160 raeburn 465: $r->print('<form name="usersrchform" method="post">'.
466: &Apache::loncommon::start_data_table()."\n".
467: &Apache::loncommon::start_data_table_header_row()."\n".
468: ' <th> </th>'."\n");
469: foreach my $field (@fields) {
470: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
471: "'".$field."'".';document.usersrchform.submit();">'.
472: $lt{$field}.'</a></th>'."\n");
473: }
474: $r->print(&Apache::loncommon::end_data_table_header_row());
475:
476: my @sorted_users = sort {
1.167 albertel 477: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 478: ||
1.167 albertel 479: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 480: ||
481: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 482: ||
483: lc($a) cmp lc($b)
1.160 raeburn 484: } (keys(%$srch_results));
485:
486: foreach my $user (@sorted_users) {
487: my ($uname,$udom) = split(/:/,$user);
488: $r->print(&Apache::loncommon::start_data_table_row().
489: '<td><input type="button" name="seluser" value="'.&mt('Select').'" onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".')" /></td>'.
490: '<td><tt>'.$uname.'</tt></td>'.
491: '<td><tt>'.$udom.'</tt></td>');
492: foreach my $field ('lastname','firstname','permanentemail') {
493: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
494: }
495: $r->print(&Apache::loncommon::end_data_table_row());
496: }
497: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 498: if (ref($srcharray) eq 'ARRAY') {
499: foreach my $item (@{$srcharray}) {
500: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
501: }
502: }
1.160 raeburn 503: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
504: ' <input type="hidden" name="seluname" value="" />'."\n".
505: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 506: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 507: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 508: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
509: $r->print($response.'</form>'.&Apache::loncommon::end_page());
1.160 raeburn 510: }
511:
512: sub print_user_query_page {
1.179 raeburn 513: my ($r,$caller) = @_;
1.160 raeburn 514: # FIXME - this is for a network-wide name search (similar to catalog search)
515: # To use frames with similar behavior to catalog/portfolio search.
516: # To be implemented.
517: return;
518: }
519:
1.42 matthew 520: sub print_user_modification_page {
1.215 raeburn 521: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_;
1.185 raeburn 522: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 523: my $usermsg = &mt('No username and/or domain provided.');
524: $env{'form.phase'} = '';
1.207 raeburn 525: &print_username_entry_form($r,$context,$usermsg);
1.58 www 526: return;
527: }
1.213 raeburn 528: my ($form,$formname);
529: if ($env{'form.action'} eq 'singlestudent') {
530: $form = 'document.enrollstudent';
531: $formname = 'enrollstudent';
532: } else {
533: $form = 'document.cu';
534: $formname = 'cu';
535: }
1.188 raeburn 536: my %abv_auth = &auth_abbrev();
1.227 raeburn 537: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 538: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
539: if ($uhome eq 'no_host') {
1.215 raeburn 540: my $usertype;
541: my ($rules,$ruleorder) =
542: &Apache::lonnet::inst_userrules($ccdomain,'username');
543: $usertype =
544: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
545: my $cancreate =
546: &Apache::lonuserutils::can_create_user($ccdomain,$context,
547: $usertype);
548: if (!$cancreate) {
549: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
550: my %usertypetext = (
551: official => 'institutional',
552: unofficial => 'non-institutional',
553: );
554: my $response;
555: if ($env{'form.origform'} eq 'crtusername') {
556: $response = '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
557: '</span><br />';
558: }
559: $response .= '<span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
560: $env{'form.phase'} = '';
561: &print_username_entry_form($r,$context,$response);
562: return;
563: }
1.188 raeburn 564: $newuser = 1;
1.193 raeburn 565: my $checkhash;
566: my $checks = { 'username' => 1 };
1.196 raeburn 567: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 568: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 569: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
570: if (ref($alerts{'username'}) eq 'HASH') {
571: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
572: my $domdesc =
1.193 raeburn 573: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 574: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
575: my $userchkmsg;
576: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
577: $userchkmsg =
578: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 579: $domdesc,1).
580: &Apache::loncommon::user_rule_formats($ccdomain,
581: $domdesc,$curr_rules{$ccdomain}{'username'},
582: 'username');
1.196 raeburn 583: }
1.215 raeburn 584: $env{'form.phase'} = '';
1.207 raeburn 585: &print_username_entry_form($r,$context,$userchkmsg);
1.196 raeburn 586: return;
1.215 raeburn 587: }
1.193 raeburn 588: }
1.185 raeburn 589: }
1.187 raeburn 590: } else {
1.188 raeburn 591: $newuser = 0;
1.185 raeburn 592: }
1.160 raeburn 593: if ($response) {
1.215 raeburn 594: $response = '<br />'.$response;
1.160 raeburn 595: }
1.149 raeburn 596:
1.52 matthew 597: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 598: my $dc_setcourse_code = '';
1.119 raeburn 599: my $nondc_setsection_code = '';
1.112 albertel 600: my %loaditem;
1.114 albertel 601:
1.216 raeburn 602: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 603:
1.216 raeburn 604: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
605: $groupslist,$newuser,$formname,\%loaditem);
1.233 raeburn 606: my $args = {'add_entries' => \%loaditem};
607: if ($env{'form.popup'}) {
608: $args->{'no_nav_bar'} = 1;
609: }
1.110 albertel 610: my $start_page =
1.233 raeburn 611: &Apache::loncommon::start_page('User Management',$js,$args);
1.216 raeburn 612: my %breadcrumb_text = &singleuser_breadcrumb();
1.160 raeburn 613: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 614: ({href=>"javascript:backPage($form)",
615: text=>$breadcrumb_text{'search'},
1.160 raeburn 616: faq=>282,bug=>'Instructor Interface',});
617:
618: if ($env{'form.phase'} eq 'userpicked') {
619: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 620: ({href=>"javascript:backPage($form,'get_user_info','select')",
621: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 622: faq=>282,bug=>'Instructor Interface',});
623: }
624: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 625: ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
626: text=>$breadcrumb_text{'modify'},
1.160 raeburn 627: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 628: my $helpitem = 'Course_Change_Privileges';
629: if ($env{'form.action'} eq 'singlestudent') {
630: $helpitem = 'Course_Add_Student';
631: }
632: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
633: $helpitem);
1.3 www 634:
1.25 matthew 635: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 636: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 637: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 638: <input type="hidden" name="ccuname" value="$ccuname" />
639: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 640: <input type="hidden" name="pres_value" value="" />
641: <input type="hidden" name="pres_type" value="" />
642: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 643: ENDFORMINFO
1.2 www 644: my %inccourses;
1.135 raeburn 645: foreach my $key (keys(%env)) {
1.139 albertel 646: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1.2 www 647: $inccourses{$1.'_'.$2}=1;
648: }
1.24 matthew 649: }
1.216 raeburn 650: if ($newuser) {
1.134 raeburn 651: my $portfolioform;
652: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
653: # Current user has quota modification privileges
1.188 raeburn 654: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 655: }
1.227 raeburn 656: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 657: my %lt=&Apache::lonlocal::texthash(
658: 'cnu' => 'Create New User',
1.213 raeburn 659: 'ast' => 'as a student',
1.188 raeburn 660: 'ind' => 'in domain',
661: 'lg' => 'Login Data',
1.190 raeburn 662: 'hs' => "Home Server",
1.188 raeburn 663: );
1.185 raeburn 664: $r->print(<<ENDTITLE);
1.110 albertel 665: $start_page
1.160 raeburn 666: $crumbs
667: $response
1.25 matthew 668: $forminfo
1.31 matthew 669: <script type="text/javascript" language="Javascript">
1.20 harris41 670: $loginscript
1.31 matthew 671: </script>
1.20 harris41 672: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 673: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 674: ENDTITLE
1.213 raeburn 675: if ($env{'form.action'} eq 'singlestudent') {
676: $r->print(' ('.$lt{'ast'}.')');
677: }
678: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 679: my $personal_table =
1.210 raeburn 680: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
681: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 682: $r->print($personal_table);
1.187 raeburn 683: my ($home_server_pick,$numlib) =
684: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
685: 'default','hide');
686: if ($numlib > 1) {
687: $r->print("
1.185 raeburn 688: <br />
1.187 raeburn 689: $lt{'hs'}: $home_server_pick
690: <br />");
691: } else {
692: $r->print($home_server_pick);
693: }
1.188 raeburn 694: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
695: $lt{'lg'}.'</h3>');
1.185 raeburn 696: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 697: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
698: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
699: my ($rules,$ruleorder) =
700: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 701: if (ref($rules) eq 'HASH') {
1.193 raeburn 702: if (ref($rules->{$matchedrule}) eq 'HASH') {
703: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 704: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 705: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 706: } else {
1.193 raeburn 707: my $authparm = $rules->{$matchedrule}{'authparm'};
1.185 raeburn 708: if ($authtype =~ /^krb(4|5)$/) {
709: my $ver = $1;
710: if ($authparm ne '') {
711: $fixedauth = <<"KERB";
712: <input type="hidden" name="login" value="krb" />
713: <input type="hidden" name="krbver" value="$ver" />
714: <input type="hidden" name="krbarg" value="$authparm" />
715: KERB
1.193 raeburn 716: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 717: }
718: } else {
719: $fixedauth =
720: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 721: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 722: $fixedauth .=
723: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
724: } else {
725: $varauth =
726: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
727: }
728: }
729: }
730: } else {
1.190 raeburn 731: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 732: }
733: }
734: if ($authmsg) {
735: $r->print(<<ENDAUTH);
736: $fixedauth
737: $authmsg
738: $varauth
739: ENDAUTH
740: }
741: } else {
1.190 raeburn 742: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 743: }
1.215 raeburn 744: $r->print($portfolioform);
745: if ($env{'form.action'} eq 'singlestudent') {
746: $r->print(&date_sections_select($context,$newuser,$formname,
747: $permission));
748: }
749: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 750: } else { # user already exists
1.79 albertel 751: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 752: 'cup' => "Modify existing user: ",
1.213 raeburn 753: 'ens' => "Enroll one student: ",
1.72 sakharuk 754: 'id' => "in domain",
755: );
1.26 matthew 756: $r->print(<<ENDCHANGEUSER);
1.110 albertel 757: $start_page
1.160 raeburn 758: $crumbs
1.25 matthew 759: $forminfo
1.213 raeburn 760: <h2>
1.26 matthew 761: ENDCHANGEUSER
1.213 raeburn 762: if ($env{'form.action'} eq 'singlestudent') {
763: $r->print($lt{'ens'});
764: } else {
765: $r->print($lt{'cup'});
766: }
767: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
768: "\n".'<div class="LC_left_float">');
1.206 raeburn 769: my ($personal_table,$showforceid) =
1.210 raeburn 770: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
771: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 772: $r->print($personal_table);
773: if ($showforceid) {
1.203 raeburn 774: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 775: }
776: $r->print('</div>');
1.227 raeburn 777: my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
1.188 raeburn 778: my $user_quota_text;
779: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
780: # Current user has quota modification privileges
781: $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
782: } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
783: # Get the user's portfolio information
784: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
785: $ccdomain,$ccuname);
786:
787: my %lt=&Apache::lonlocal::texthash(
788: 'dska' => "Disk space allocated to user's portfolio files",
789: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
790: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
791: );
792: $user_quota_text = <<ENDNOPORTPRIV;
793: <h3>$lt{'dska'}</h3>
794: $lt{'youd'} $lt{'ichr'}: $ccdomain
795: ENDNOPORTPRIV
796: }
797: if ($user_auth_text ne '') {
798: $r->print('<div class="LC_left_float">'.$user_auth_text);
799: if ($user_quota_text ne '') {
800: $r->print($user_quota_text);
801: }
1.213 raeburn 802: if ($env{'form.action'} eq 'singlestudent') {
803: $r->print(&date_sections_select($context,$newuser,$formname));
804: }
1.188 raeburn 805: } elsif ($user_quota_text ne '') {
1.213 raeburn 806: $r->print('<div class="LC_left_float">'.$user_quota_text);
807: if ($env{'form.action'} eq 'singlestudent') {
808: $r->print(&date_sections_select($context,$newuser,$formname));
809: }
810: } else {
811: if ($env{'form.action'} eq 'singlestudent') {
812: $r->print('<div class="LC_left_float">'.
813: &date_sections_select($context,$newuser,$formname));
814: }
1.188 raeburn 815: }
1.213 raeburn 816: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.217 raeburn 817: if ($env{'form.action'} ne 'singlestudent') {
818: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
819: }
1.25 matthew 820: } ## End of new user/old user logic
1.218 raeburn 821:
822: if ($env{'form.action'} eq 'singlestudent') {
823: $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onClick="setSections(this.form)" />'."\n");
824: } else {
825: $r->print('<h3>'.&mt('Add Roles').'</h3>');
826: my $addrolesdisplay = 0;
827: if ($context eq 'domain' || $context eq 'author') {
828: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
829: }
830: if ($context eq 'domain') {
831: my $add_domainroles = &new_domain_roles($r);
832: if (!$addrolesdisplay) {
833: $addrolesdisplay = $add_domainroles;
1.2 www 834: }
1.218 raeburn 835: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
836: $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
837: } elsif ($context eq 'author') {
838: if ($addrolesdisplay) {
839: $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
840: if ($newuser) {
1.227 raeburn 841: $r->print(' onClick="auth_check()" \>'."\n");
1.218 raeburn 842: } else {
843: $r->print('onClick="this.form.submit()" \>'."\n");
844: }
1.188 raeburn 845: } else {
1.218 raeburn 846: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
847: &mt('Back to previous page').'</a>');
1.188 raeburn 848: }
849: } else {
1.218 raeburn 850: $r->print(&course_level_table(%inccourses));
851: $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
1.188 raeburn 852: }
1.88 raeburn 853: }
1.188 raeburn 854: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 855: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 856: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 857: $r->print("</form>".&Apache::loncommon::end_page());
1.218 raeburn 858: return;
1.2 www 859: }
1.1 www 860:
1.213 raeburn 861: sub singleuser_breadcrumb {
862: my %breadcrumb_text;
863: if ($env{'form.action'} eq 'singlestudent') {
864: $breadcrumb_text{'search'} = 'Enroll a student';
865: $breadcrumb_text{'userpicked'} = 'Select a user',
866: $breadcrumb_text{'modify'} = 'Set section/dates',
867: } else {
1.229 raeburn 868: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 869: $breadcrumb_text{'userpicked'} = 'Select a user',
870: $breadcrumb_text{'modify'} = 'Set user role',
871: }
872: return %breadcrumb_text;
873: }
874:
875: sub date_sections_select {
876: my ($context,$newuser,$formname,$permission) = @_;
877: my $cid = $env{'request.course.id'};
878: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
879: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
880: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
881: undef,$formname,$permission);
882: my $rowtitle = 'Section';
883: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
884: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
885: $permission);
886: my $output = $date_table.$secbox;
887: return $output;
888: }
889:
1.216 raeburn 890: sub validation_javascript {
891: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
892: $loaditem) = @_;
893: my $dc_setcourse_code = '';
894: my $nondc_setsection_code = '';
895: if ($context eq 'domain') {
896: my $dcdom = $env{'request.role.domain'};
897: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 898: $dc_setcourse_code =
899: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 900: } else {
1.227 raeburn 901: my $checkauth;
902: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
903: $checkauth = 1;
904: }
905: if ($context eq 'course') {
906: $nondc_setsection_code =
907: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
908: undef,$checkauth);
909: }
910: if ($checkauth) {
911: $nondc_setsection_code .=
912: &Apache::lonuserutils::verify_authen($formname,$context);
913: }
1.216 raeburn 914: }
915: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
916: $nondc_setsection_code,$groupslist);
917: my ($jsback,$elements) = &crumb_utilities();
918: $js .= "\n".
1.227 raeburn 919: '<script type="text/javascript">'."\n".$jsback."\n".'</script>';
1.216 raeburn 920: return $js;
921: }
922:
1.217 raeburn 923: sub display_existing_roles {
924: my ($r,$ccuname,$ccdomain,$inccourses) = @_;
925: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
926: # Build up table of user roles to allow revocation and re-enabling of roles.
927: my ($tmp) = keys(%rolesdump);
928: if ($tmp !~ /^(con_lost|error)/i) {
929: my $now=time;
930: my %lt=&Apache::lonlocal::texthash(
931: 'rer' => "Existing Roles",
932: 'rev' => "Revoke",
933: 'del' => "Delete",
934: 'ren' => "Re-Enable",
935: 'rol' => "Role",
936: 'ext' => "Extent",
937: 'sta' => "Start",
938: 'end' => "End",
939: );
940: my (%roletext,%sortrole,%roleclass,%rolepriv);
941: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
942: my $b1=join('_',(split('_',$b))[1,0]);
943: return $a1 cmp $b1;
944: } keys(%rolesdump)) {
945: next if ($area =~ /^rolesdef/);
946: my $envkey=$area;
947: my $role = $rolesdump{$area};
948: my $thisrole=$area;
949: $area =~ s/\_\w\w$//;
950: my ($role_code,$role_end_time,$role_start_time) =
951: split(/_/,$role);
952: # Is this a custom role? Get role owner and title.
953: my ($croleudom,$croleuname,$croletitle)=
954: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
955: my $allowed=0;
956: my $delallowed=0;
957: my $sortkey=$role_code;
958: my $class='Unknown';
959: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
960: $class='Course';
961: my ($coursedom,$coursedir) = ($1,$2);
962: $sortkey.="\0$coursedom";
963: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
964: my %coursedata=
965: &Apache::lonnet::coursedescription($1.'_'.$2);
966: my $carea;
967: if (defined($coursedata{'description'})) {
968: $carea=$coursedata{'description'}.
969: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
970: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
971: $sortkey.="\0".$coursedata{'description'};
972: $class=$coursedata{'type'};
973: } else {
974: $carea=&mt('Unavailable course').': '.$area;
975: $sortkey.="\0".&mt('Unavailable course').': '.$area;
976: }
977: $sortkey.="\0$coursedir";
978: $inccourses->{$1.'_'.$2}=1;
979: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
980: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
981: $allowed=1;
982: }
983: if ((&Apache::lonnet::allowed('dro',$1)) ||
984: (&Apache::lonnet::allowed('dro',$ccdomain))) {
985: $delallowed=1;
986: }
987: # - custom role. Needs more info, too
988: if ($croletitle) {
989: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
990: $allowed=1;
991: $thisrole.='.'.$role_code;
992: }
993: }
994: # Compute the background color based on $area
995: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
996: $carea.='<br />Section: '.$3;
997: $sortkey.="\0$3";
998: if (!$allowed) {
999: if ($env{'request.course.sec'} eq $3) {
1000: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1001: $allowed = 1;
1002: }
1003: }
1004: }
1005: }
1006: $area=$carea;
1007: } else {
1008: $sortkey.="\0".$area;
1009: # Determine if current user is able to revoke privileges
1010: if ($area=~m{^/($match_domain)/}) {
1011: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1012: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1013: $allowed=1;
1014: }
1015: if (((&Apache::lonnet::allowed('dro',$1)) ||
1016: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1017: ($role_code ne 'dc')) {
1018: $delallowed=1;
1019: }
1020: } else {
1021: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1022: $allowed=1;
1023: }
1024: }
1025: if ($role_code eq 'ca' || $role_code eq 'au') {
1026: $class='Construction Space';
1027: } elsif ($role_code eq 'su') {
1028: $class='System';
1029: } else {
1030: $class='Domain';
1031: }
1032: }
1033: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1034: $area=~m{/($match_domain)/($match_username)};
1035: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1036: $allowed=1;
1037: } else {
1038: $allowed=0;
1039: }
1040: }
1041: my $row = '';
1042: $row.= '<td>';
1043: my $active=1;
1044: $active=0 if (($role_end_time) && ($now>$role_end_time));
1045: if (($active) && ($allowed)) {
1046: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1047: } else {
1048: if ($active) {
1049: $row.=' ';
1050: } else {
1051: $row.=&mt('expired or revoked');
1052: }
1053: }
1054: $row.='</td><td>';
1055: if ($allowed && !$active) {
1056: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1057: } else {
1058: $row.=' ';
1059: }
1060: $row.='</td><td>';
1061: if ($delallowed) {
1062: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1063: } else {
1064: $row.=' ';
1065: }
1066: my $plaintext='';
1067: if (!$croletitle) {
1068: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1069: } else {
1070: $plaintext=
1071: "Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
1072: }
1073: $row.= '</td><td>'.$plaintext.
1074: '</td><td>'.$area.
1075: '</td><td>'.($role_start_time?localtime($role_start_time)
1076: : ' ' ).
1077: '</td><td>'.($role_end_time ?localtime($role_end_time)
1078: : ' ' )
1079: ."</td>";
1080: $sortrole{$sortkey}=$envkey;
1081: $roletext{$envkey}=$row;
1082: $roleclass{$envkey}=$class;
1083: $rolepriv{$envkey}=$allowed;
1084: #$r->print($row);
1085: } # end of foreach (table building loop)
1086: my $rolesdisplay = 0;
1087: my %output = ();
1088: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1089: $output{$type} = '';
1090: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1091: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1092: $output{$type}.=
1093: &Apache::loncommon::start_data_table_row().
1094: $roletext{$sortrole{$which}}.
1095: &Apache::loncommon::end_data_table_row();
1096: }
1097: }
1098: unless($output{$type} eq '') {
1099: $output{$type} = '<tr class="LC_info_row">'.
1100: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1101: $output{$type};
1102: $rolesdisplay = 1;
1103: }
1104: }
1105: if ($rolesdisplay == 1) {
1106: $r->print('
1107: <h3>'.$lt{'rer'}.'</h3>'.
1108: &Apache::loncommon::start_data_table("LC_createuser").
1109: &Apache::loncommon::start_data_table_header_row().
1110: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1111: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1112: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1113: &Apache::loncommon::end_data_table_header_row());
1114: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1115: if ($output{$type}) {
1116: $r->print($output{$type}."\n");
1117: }
1118: }
1119: $r->print(&Apache::loncommon::end_data_table());
1120: }
1121: } # End of check for keys in rolesdump
1122: return;
1123: }
1124:
1.218 raeburn 1125: sub new_coauthor_roles {
1126: my ($r,$ccuname,$ccdomain) = @_;
1127: my $addrolesdisplay = 0;
1128: #
1129: # Co-Author
1130: #
1131: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1132: $env{'request.role.domain'}) &&
1133: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1134: # No sense in assigning co-author role to yourself
1135: $addrolesdisplay = 1;
1136: my $cuname=$env{'user.name'};
1137: my $cudom=$env{'request.role.domain'};
1138: my %lt=&Apache::lonlocal::texthash(
1139: 'cs' => "Construction Space",
1140: 'act' => "Activate",
1141: 'rol' => "Role",
1142: 'ext' => "Extent",
1143: 'sta' => "Start",
1144: 'end' => "End",
1145: 'cau' => "Co-Author",
1146: 'caa' => "Assistant Co-Author",
1147: 'ssd' => "Set Start Date",
1148: 'sed' => "Set End Date"
1149: );
1150: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1151: &Apache::loncommon::start_data_table()."\n".
1152: &Apache::loncommon::start_data_table_header_row()."\n".
1153: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1154: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1155: '<th>'.$lt{'end'}.'</th>'."\n".
1156: &Apache::loncommon::end_data_table_header_row()."\n".
1157: &Apache::loncommon::start_data_table_row().'
1158: <td>
1159: <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
1160: </td>
1161: <td>'.$lt{'cau'}.'</td>
1162: <td>'.$cudom.'_'.$cuname.'</td>
1163: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1164: <a href=
1165: "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>
1166: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1167: <a href=
1168: "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".
1169: &Apache::loncommon::end_data_table_row()."\n".
1170: &Apache::loncommon::start_data_table_row()."\n".
1171: '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1172: <td>'.$lt{'caa'}.'</td>
1173: <td>'.$cudom.'_'.$cuname.'</td>
1174: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1175: <a href=
1176: "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>
1177: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1178: <a href=
1179: "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".
1180: &Apache::loncommon::end_data_table_row()."\n".
1181: &Apache::loncommon::end_data_table());
1182: } elsif ($env{'request.role'} =~ /^au\./) {
1183: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1184: $env{'request.role.domain'}))) {
1185: $r->print('<span class="LC_error">'.
1186: &mt('You do not have privileges to assign co-author roles.').
1187: '</span>');
1188: } elsif (($env{'user.name'} eq $ccuname) &&
1189: ($env{'user.domain'} eq $ccdomain)) {
1190: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1191: }
1192: }
1193: return $addrolesdisplay;;
1194: }
1195:
1196: sub new_domain_roles {
1197: my ($r) = @_;
1198: my $addrolesdisplay = 0;
1199: #
1200: # Domain level
1201: #
1202: my $num_domain_level = 0;
1203: my $domaintext =
1204: '<h4>'.&mt('Domain Level').'</h4>'.
1205: &Apache::loncommon::start_data_table().
1206: &Apache::loncommon::start_data_table_header_row().
1207: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1208: &mt('Extent').'</th>'.
1209: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1210: &Apache::loncommon::end_data_table_header_row();
1211: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1212: foreach my $role ('dc','li','dg','au','sc') {
1213: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1214: my $plrole=&Apache::lonnet::plaintext($role);
1215: my %lt=&Apache::lonlocal::texthash(
1216: 'ssd' => "Set Start Date",
1217: 'sed' => "Set End Date"
1218: );
1219: $num_domain_level ++;
1220: $domaintext .=
1221: &Apache::loncommon::start_data_table_row().
1222: '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
1223: <td>'.$plrole.'</td>
1224: <td>'.$thisdomain.'</td>
1225: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1226: <a href=
1227: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1228: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1229: <a href=
1230: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1231: &Apache::loncommon::end_data_table_row();
1232: }
1233: }
1234: }
1235: $domaintext.= &Apache::loncommon::end_data_table();
1236: if ($num_domain_level > 0) {
1237: $r->print($domaintext);
1238: $addrolesdisplay = 1;
1239: }
1240: return $addrolesdisplay;
1241: }
1242:
1.188 raeburn 1243: sub user_authentication {
1.227 raeburn 1244: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1245: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1246: my $outcome;
1.188 raeburn 1247: # Check for a bad authentication type
1248: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1249: # bad authentication scheme
1250: my %lt=&Apache::lonlocal::texthash(
1251: 'err' => "ERROR",
1252: 'uuas' => "This user has an unrecognized authentication scheme",
1253: 'adcs' => "Please alert a domain coordinator of this situation",
1254: 'sldb' => "Please specify login data below",
1255: 'ld' => "Login Data"
1256: );
1257: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1258: &initialize_authen_forms($ccdomain,$formname);
1259:
1.190 raeburn 1260: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1261: $outcome = <<ENDBADAUTH;
1262: <script type="text/javascript" language="Javascript">
1263: $loginscript
1264: </script>
1265: <span class="LC_error">$lt{'err'}:
1266: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1267: <h3>$lt{'ld'}</h3>
1268: $choices
1269: ENDBADAUTH
1270: } else {
1271: # This user is not allowed to modify the user's
1272: # authentication scheme, so just notify them of the problem
1273: $outcome = <<ENDBADAUTH;
1274: <span class="LC_error"> $lt{'err'}:
1275: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1276: </span>
1277: ENDBADAUTH
1278: }
1279: } else { # Authentication type is valid
1.227 raeburn 1280: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1281: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1282: &modify_login_block($ccdomain,$currentauth);
1283: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1284: # Current user has login modification privileges
1285: my %lt=&Apache::lonlocal::texthash (
1286: 'ld' => "Login Data",
1287: 'ccld' => "Change Current Login Data",
1288: 'enld' => "Enter New Login Data"
1289: );
1290: $outcome =
1291: '<script type="text/javascript" language="Javascript">'."\n".
1292: $loginscript."\n".
1293: '</script>'."\n".
1294: '<h3>'.$lt{'ld'}.'</h3>'.
1295: &Apache::loncommon::start_data_table().
1.205 raeburn 1296: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1297: '<td>'.$authformnop;
1298: if ($can_modify) {
1299: $outcome .= '</td>'."\n".
1300: &Apache::loncommon::end_data_table_row().
1301: &Apache::loncommon::start_data_table_row().
1302: '<td>'.$authformcurrent.'</td>'.
1303: &Apache::loncommon::end_data_table_row()."\n";
1304: } else {
1.200 raeburn 1305: $outcome .= ' ('.$authformcurrent.')</td>'.
1306: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1307: }
1.205 raeburn 1308: foreach my $item (@authform_others) {
1309: $outcome .= &Apache::loncommon::start_data_table_row().
1310: '<td>'.$item.'</td>'.
1311: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1312: }
1.205 raeburn 1313: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 1314: } else {
1315: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1316: my %lt=&Apache::lonlocal::texthash(
1317: 'ccld' => "Change Current Login Data",
1318: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1319: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1320: );
1321: $outcome .= <<ENDNOPRIV;
1322: <h3>$lt{'ccld'}</h3>
1323: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 1324: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 1325: ENDNOPRIV
1326: }
1327: }
1328: } ## End of "check for bad authentication type" logic
1329: return $outcome;
1330: }
1331:
1.187 raeburn 1332: sub modify_login_block {
1333: my ($dom,$currentauth) = @_;
1334: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1335: my ($authnum,%can_assign) =
1336: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 1337: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 1338: if ($currentauth=~/^krb(4|5):/) {
1339: $authformcurrent=$authformkrb;
1340: if ($can_assign{'int'}) {
1.205 raeburn 1341: push(@authform_others,$authformint);
1.187 raeburn 1342: }
1343: if ($can_assign{'loc'}) {
1.205 raeburn 1344: push(@authform_others,$authformloc);
1.187 raeburn 1345: }
1346: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1347: $show_override_msg = 1;
1348: }
1349: } elsif ($currentauth=~/^internal:/) {
1350: $authformcurrent=$authformint;
1351: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1352: push(@authform_others,$authformkrb);
1.187 raeburn 1353: }
1354: if ($can_assign{'loc'}) {
1.205 raeburn 1355: push(@authform_others,$authformloc);
1.187 raeburn 1356: }
1357: if ($can_assign{'int'}) {
1358: $show_override_msg = 1;
1359: }
1360: } elsif ($currentauth=~/^unix:/) {
1361: $authformcurrent=$authformfsys;
1362: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1363: push(@authform_others,$authformkrb);
1.187 raeburn 1364: }
1365: if ($can_assign{'int'}) {
1.205 raeburn 1366: push(@authform_others,$authformint);
1.187 raeburn 1367: }
1368: if ($can_assign{'loc'}) {
1.205 raeburn 1369: push(@authform_others,$authformloc);
1.187 raeburn 1370: }
1371: if ($can_assign{'fsys'}) {
1372: $show_override_msg = 1;
1373: }
1374: } elsif ($currentauth=~/^localauth:/) {
1375: $authformcurrent=$authformloc;
1376: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1377: push(@authform_others,$authformkrb);
1.187 raeburn 1378: }
1379: if ($can_assign{'int'}) {
1.205 raeburn 1380: push(@authform_others,$authformint);
1.187 raeburn 1381: }
1382: if ($can_assign{'loc'}) {
1383: $show_override_msg = 1;
1384: }
1385: }
1386: if ($show_override_msg) {
1.205 raeburn 1387: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
1388: '</td></tr>'."\n".
1389: '<tr><td> </td>'.
1390: '<td><b>'.&mt('Currently in use').'</b></td>'.
1391: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 1392: &mt('will override current values').
1.205 raeburn 1393: '</span></td></tr></table>';
1.187 raeburn 1394: }
1.205 raeburn 1395: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 1396: }
1397:
1.188 raeburn 1398: sub personal_data_display {
1.210 raeburn 1399: my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
1.219 raeburn 1400: my ($output,$showforceid,%userenv,%canmodify);
1401: my @userinfo = ('firstname','middlename','lastname','generation',
1402: 'permanentemail','id');
1.188 raeburn 1403: if (!$newuser) {
1404: # Get the users information
1405: %userenv = &Apache::lonnet::get('environment',
1406: ['firstname','middlename','lastname','generation',
1407: 'permanentemail','id'],$ccdomain,$ccuname);
1.219 raeburn 1408: %canmodify =
1409: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1410: \@userinfo);
1.188 raeburn 1411: }
1412: my %lt=&Apache::lonlocal::texthash(
1413: 'pd' => "Personal Data",
1414: 'firstname' => "First Name",
1415: 'middlename' => "Middle Name",
1416: 'lastname' => "Last Name",
1417: 'generation' => "Generation",
1418: 'permanentemail' => "Permanent e-mail address",
1419: 'id' => "ID/Student Number",
1420: 'lg' => "Login Data"
1421: );
1422: my %textboxsize = (
1423: firstname => '15',
1424: middlename => '15',
1425: lastname => '15',
1426: generation => '5',
1427: permanentemail => '25',
1428: id => '15',
1429: );
1430: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1431: $output = '<h3>'.$lt{'pd'}.'</h3>'.
1432: &Apache::lonhtmlcommon::start_pick_box();
1433: foreach my $item (@userinfo) {
1434: my $rowtitle = $lt{$item};
1435: if ($item eq 'generation') {
1436: $rowtitle = $genhelp.$rowtitle;
1437: }
1438: $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1439: if ($newuser) {
1.210 raeburn 1440: if (ref($inst_results) eq 'HASH') {
1441: if ($inst_results->{$item} ne '') {
1442: $output .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1443: } else {
1444: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1445: }
1.188 raeburn 1446: } else {
1447: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1448: }
1449: } else {
1.219 raeburn 1450: if ($canmodify{$item}) {
1.188 raeburn 1451: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1452: } else {
1453: $output .= $userenv{$item};
1454: }
1.206 raeburn 1455: if ($item eq 'id') {
1.219 raeburn 1456: $showforceid = $canmodify{$item};
1457: }
1.188 raeburn 1458: }
1459: $output .= &Apache::lonhtmlcommon::row_closure(1);
1460: }
1461: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1462: if (wantarray) {
1463: return ($output,$showforceid);
1464: } else {
1465: return $output;
1466: }
1.188 raeburn 1467: }
1468:
1.4 www 1469: # ================================================================= Phase Three
1.42 matthew 1470: sub update_user_data {
1.206 raeburn 1471: my ($r,$context) = @_;
1.101 albertel 1472: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1473: $env{'form.ccdomain'});
1.27 matthew 1474: # Error messages
1.188 raeburn 1475: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1476: my $end = '</span><br /><br />';
1477: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1478: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 1479: &mt('Return to previous page').'</a>'.
1480: &Apache::loncommon::end_page();
1481: my $now = time;
1.40 www 1482: my $title;
1.101 albertel 1483: if (exists($env{'form.makeuser'})) {
1.40 www 1484: $title='Set Privileges for New User';
1485: } else {
1486: $title='Modify User Privileges';
1487: }
1.213 raeburn 1488: my $newuser = 0;
1.160 raeburn 1489: my ($jsback,$elements) = &crumb_utilities();
1490: my $jscript = '<script type="text/javascript">'."\n".
1491: $jsback."\n".'</script>'."\n";
1.213 raeburn 1492: my %breadcrumb_text = &singleuser_breadcrumb();
1.233 raeburn 1493: my $args;
1494: if ($env{'form.popup'}) {
1495: $args->{'no_nav_bar'} = 1;
1496: } else {
1497: $args = undef;
1498: }
1499: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 1500: &Apache::lonhtmlcommon::add_breadcrumb
1501: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1502: text=>$breadcrumb_text{'search'},
1.160 raeburn 1503: faq=>282,bug=>'Instructor Interface',});
1504: if ($env{'form.prevphase'} eq 'userpicked') {
1505: &Apache::lonhtmlcommon::add_breadcrumb
1506: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1507: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1508: faq=>282,bug=>'Instructor Interface',});
1509: }
1510: &Apache::lonhtmlcommon::add_breadcrumb
1511: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 1512: text=>$breadcrumb_text{'modify'},
1.160 raeburn 1513: faq=>282,bug=>'Instructor Interface',},
1514: {href=>"/adm/createuser",
1515: text=>"Result",
1516: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 1517: my $helpitem = 'Course_Change_Privileges';
1518: if ($env{'form.action'} eq 'singlestudent') {
1519: $helpitem = 'Course_Add_Student';
1520: }
1521: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1522: $helpitem));
1.188 raeburn 1523: $r->print(&update_result_form($uhome));
1.27 matthew 1524: # Check Inputs
1.101 albertel 1525: if (! $env{'form.ccuname'} ) {
1.193 raeburn 1526: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 1527: return;
1528: }
1.138 albertel 1529: if ( $env{'form.ccuname'} ne
1530: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1531: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1532: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193 raeburn 1533: $end.$rtnlink);
1.27 matthew 1534: return;
1535: }
1.101 albertel 1536: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 1537: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 1538: return;
1539: }
1.138 albertel 1540: if ( $env{'form.ccdomain'} ne
1541: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1542: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1543: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193 raeburn 1544: $end.$rtnlink);
1.27 matthew 1545: return;
1546: }
1.219 raeburn 1547: if ($uhome eq 'no_host') {
1548: $newuser = 1;
1549: }
1.101 albertel 1550: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1551: # Modifying an existing user, so check the validity of the name
1552: if ($uhome eq 'no_host') {
1.73 sakharuk 1553: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1554: $env{'form.ccuname'}.&mt(' in domain ').
1555: $env{'form.ccdomain'}.'.');
1.29 matthew 1556: return;
1557: }
1558: }
1.27 matthew 1559: # Determine authentication method and password for the user being modified
1560: my $amode='';
1561: my $genpwd='';
1.101 albertel 1562: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1563: $amode='krb';
1.101 albertel 1564: $amode.=$env{'form.krbver'};
1565: $genpwd=$env{'form.krbarg'};
1566: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1567: $amode='internal';
1.101 albertel 1568: $genpwd=$env{'form.intarg'};
1569: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1570: $amode='unix';
1.101 albertel 1571: $genpwd=$env{'form.fsysarg'};
1572: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1573: $amode='localauth';
1.101 albertel 1574: $genpwd=$env{'form.locarg'};
1.27 matthew 1575: $genpwd=" " if (!$genpwd);
1.101 albertel 1576: } elsif (($env{'form.login'} eq 'nochange') ||
1577: ($env{'form.login'} eq '' )) {
1.34 matthew 1578: # There is no need to tell the user we did not change what they
1579: # did not ask us to change.
1.35 matthew 1580: # If they are creating a new user but have not specified login
1581: # information this will be caught below.
1.30 matthew 1582: } else {
1.193 raeburn 1583: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 1584: return;
1.27 matthew 1585: }
1.164 albertel 1586:
1.188 raeburn 1587: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1588: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 1589: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.101 albertel 1590: if ($env{'form.makeuser'}) {
1.164 albertel 1591: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1592: # Check for the authentication mode and password
1593: if (! $amode || ! $genpwd) {
1.193 raeburn 1594: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 1595: return;
1.18 albertel 1596: }
1.29 matthew 1597: # Determine desired host
1.101 albertel 1598: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1599: if (lc($desiredhost) eq 'default') {
1600: $desiredhost = undef;
1601: } else {
1.147 albertel 1602: my %home_servers =
1603: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1604: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 1605: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
1606: return;
1607: }
1608: }
1609: # Check ID format
1610: my %checkhash;
1611: my %checks = ('id' => 1);
1612: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 1613: 'newuser' => $newuser,
1.196 raeburn 1614: 'id' => $env{'form.cid'},
1.193 raeburn 1615: );
1.196 raeburn 1616: if ($env{'form.cid'} ne '') {
1617: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1618: \%rulematch,\%inst_results,\%curr_rules);
1619: if (ref($alerts{'id'}) eq 'HASH') {
1620: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1621: my $domdesc =
1622: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
1623: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
1624: my $userchkmsg;
1625: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
1626: $userchkmsg =
1627: &Apache::loncommon::instrule_disallow_msg('id',
1628: $domdesc,1).
1629: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
1630: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
1631: }
1632: $r->print($error.&mt('Invalid ID format').$end.
1633: $userchkmsg.$rtnlink);
1634: return;
1635: }
1636: }
1.29 matthew 1637: }
1638: }
1.27 matthew 1639: # Call modifyuser
1640: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 1641: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 1642: $amode,$genpwd,$env{'form.cfirstname'},
1643: $env{'form.cmiddlename'},$env{'form.clastname'},
1644: $env{'form.cgeneration'},undef,$desiredhost,
1645: $env{'form.cpermanentemail'});
1.77 www 1646: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 1647: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 1648: $env{'form.ccdomain'});
1.232 raeburn 1649: if (($uhome ne 'no_host') && ($env{'form.customquota'} == 1)) {
1650: my (%changeHash,$newportfolioquota);
1651: if ($env{'form.portfolioquota'} eq '') {
1652: $newportfolioquota = 0;
1653: } else {
1654: $newportfolioquota = $env{'form.portfolioquota'};
1655: $newportfolioquota =~ s/[^\d\.]//g;
1656: }
1657: my $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1658: if ($quotachanged) {
1659: $changeHash{'firstname'} = $env{'form.cfirstname'};
1660: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1661: $changeHash{'lastname'} = $env{'form.clastname'};
1662: $changeHash{'generation'} = $env{'form.cgeneration'};
1663: $changeHash{'id'} = $env{'form.cid'};
1664: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1665: my $quotachgresult =
1666: &Apache::lonnet::put('environment',\%changeHash,
1667: $env{'form.ccdomain'},$env{'form.ccuname'});
1668: }
1669: }
1.219 raeburn 1670: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
1671: &Apache::lonnet::hostname($uhome));
1.101 albertel 1672: } elsif (($env{'form.login'} ne 'nochange') &&
1673: ($env{'form.login'} ne '' )) {
1.27 matthew 1674: # Modify user privileges
1675: if (! $amode || ! $genpwd) {
1.193 raeburn 1676: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1677: return;
1.20 harris41 1678: }
1.27 matthew 1679: # Only allow authentification modification if the person has authority
1.101 albertel 1680: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1681: $r->print('Modifying authentication: '.
1.31 matthew 1682: &Apache::lonnet::modifyuserauth(
1.101 albertel 1683: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1684: $amode,$genpwd));
1.102 albertel 1685: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1686: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1687: } else {
1.27 matthew 1688: # Okay, this is a non-fatal error.
1.193 raeburn 1689: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1690: }
1.28 matthew 1691: }
1692: ##
1.213 raeburn 1693: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1694: if ($context eq 'course') {
1695: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1696: }
1.101 albertel 1697: if (! $env{'form.makeuser'} ) {
1.28 matthew 1698: # Check for need to change
1699: my %userenv = &Apache::lonnet::get
1.134 raeburn 1700: ('environment',['firstname','middlename','lastname','generation',
1.196 raeburn 1701: 'id','permanentemail','portfolioquota','inststatus'],
1.160 raeburn 1702: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1703: my ($tmp) = keys(%userenv);
1704: if ($tmp =~ /^(con_lost|error)/i) {
1705: %userenv = ();
1706: }
1.206 raeburn 1707: my $no_forceid_alert;
1708: # Check to see if user information can be changed
1709: my %domconfig =
1710: &Apache::lonnet::get_dom('configuration',['usermodification'],
1711: $env{'form.ccdomain'});
1.213 raeburn 1712: my @statuses = ('active','future');
1713: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1714: my ($auname,$audom);
1.220 raeburn 1715: if ($context eq 'author') {
1.206 raeburn 1716: $auname = $env{'user.name'};
1717: $audom = $env{'user.domain'};
1718: }
1719: foreach my $item (keys(%roles)) {
1.220 raeburn 1720: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 1721: if ($context eq 'course') {
1722: if ($cnum ne '' && $cdom ne '') {
1723: if ($rolenum eq $cnum && $roledom eq $cdom) {
1724: if (!grep(/^\Q$role\E$/,@userroles)) {
1725: push(@userroles,$role);
1726: }
1727: }
1728: }
1729: } elsif ($context eq 'author') {
1730: if ($rolenum eq $auname && $roledom eq $audom) {
1731: if (!grep(/^\Q$role\E$/,@userroles)) {
1732: push(@userroles,$role);
1733: }
1734: }
1735: }
1736: }
1.220 raeburn 1737: if ($env{'form.action'} eq 'singlestudent') {
1738: if (!grep(/^st$/,@userroles)) {
1739: push(@userroles,'st');
1740: }
1741: } else {
1742: # Check for course or co-author roles being activated or re-enabled
1743: if ($context eq 'author' || $context eq 'course') {
1744: foreach my $key (keys(%env)) {
1745: if ($context eq 'author') {
1746: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1747: if (!grep(/^\Q$1\E$/,@userroles)) {
1748: push(@userroles,$1);
1749: }
1750: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1751: if (!grep(/^\Q$1\E$/,@userroles)) {
1752: push(@userroles,$1);
1753: }
1.206 raeburn 1754: }
1.220 raeburn 1755: } elsif ($context eq 'course') {
1756: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1757: if (!grep(/^\Q$1\E$/,@userroles)) {
1758: push(@userroles,$1);
1759: }
1760: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1761: if (!grep(/^\Q$1\E$/,@userroles)) {
1762: push(@userroles,$1);
1763: }
1.206 raeburn 1764: }
1765: }
1766: }
1767: }
1768: }
1769: #Check to see if we can change personal data for the user
1770: my (@mod_disallowed,@longroles);
1771: foreach my $role (@userroles) {
1772: if ($role eq 'cr') {
1773: push(@longroles,'Custom');
1774: } else {
1775: push(@longroles,&Apache::lonnet::plaintext($role));
1776: }
1777: }
1.219 raeburn 1778: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1779: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
1780: foreach my $item (@userinfo) {
1.28 matthew 1781: # Strip leading and trailing whitespace
1.203 raeburn 1782: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 1783: if (!$canmodify{$item}) {
1.207 raeburn 1784: if (defined($env{'form.c'.$item})) {
1785: if ($env{'form.c'.$item} ne $userenv{$item}) {
1786: push(@mod_disallowed,$item);
1787: }
1.206 raeburn 1788: }
1789: $env{'form.c'.$item} = $userenv{$item};
1790: }
1.28 matthew 1791: }
1.196 raeburn 1792: # Check to see if we can change the ID/student number
1793: my $forceid = $env{'form.forceid'};
1794: my $recurseid = $env{'form.recurseid'};
1795: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1796: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1797: $env{'form.ccuname'});
1798: if (($uidhash{$env{'form.ccuname'}}) &&
1799: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1800: (!$forceid)) {
1801: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1802: $env{'form.cid'} = $userenv{'id'};
1.206 raeburn 1803: $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'<br />'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'<br />'."\n";
1.203 raeburn 1804: }
1805: }
1806: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1807: my $checkhash;
1808: my $checks = { 'id' => 1 };
1809: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1810: { 'newuser' => $newuser,
1811: 'id' => $env{'form.cid'},
1812: };
1813: &Apache::loncommon::user_rule_check($checkhash,$checks,
1814: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1815: if (ref($alerts{'id'}) eq 'HASH') {
1816: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1817: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1818: }
1819: }
1820: }
1.213 raeburn 1821: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1822: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1823: $newdefquotatext);
1.149 raeburn 1824: my ($defquota,$settingstatus) =
1825: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.220 raeburn 1826: my $showquota;
1827: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1828: $showquota = 1;
1829: }
1.134 raeburn 1830: my %changeHash;
1.204 raeburn 1831: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 1832: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1833: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1834: if ($env{'form.customquota'} == 1) {
1835: if ($env{'form.portfolioquota'} eq '') {
1836: $newportfolioquota = 0;
1837: } else {
1838: $newportfolioquota = $env{'form.portfolioquota'};
1839: $newportfolioquota =~ s/[^\d\.]//g;
1840: }
1.204 raeburn 1841: if ($newportfolioquota != $oldportfolioquota) {
1.149 raeburn 1842: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1843: }
1.149 raeburn 1844: } else {
1845: $quotachanged = "a_admin('',\%changeHash);
1846: $newportfolioquota = $defquota;
1.204 raeburn 1847: $newisdefault = 1;
1.134 raeburn 1848: }
1849: } else {
1.204 raeburn 1850: $oldisdefault = 1;
1.149 raeburn 1851: $oldportfolioquota = $defquota;
1852: if ($env{'form.customquota'} == 1) {
1853: if ($env{'form.portfolioquota'} eq '') {
1854: $newportfolioquota = 0;
1855: } else {
1856: $newportfolioquota = $env{'form.portfolioquota'};
1857: $newportfolioquota =~ s/[^\d\.]//g;
1858: }
1859: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1860: } else {
1861: $newportfolioquota = $defquota;
1.204 raeburn 1862: $newisdefault = 1;
1.149 raeburn 1863: }
1864: }
1.204 raeburn 1865: if ($oldisdefault) {
1866: $olddefquotatext = &get_defaultquota_text($settingstatus);
1867: }
1868: if ($newisdefault) {
1869: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 1870: }
1.206 raeburn 1871: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1872: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1873: $env{'form.clastname'} ne $userenv{'lastname'} ||
1874: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1875: $env{'form.cid'} ne $userenv{'id'} ||
1876: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 1877: $namechanged = 1;
1878: }
1.204 raeburn 1879: if ($namechanged || $quotachanged) {
1.101 albertel 1880: $changeHash{'firstname'} = $env{'form.cfirstname'};
1881: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1882: $changeHash{'lastname'} = $env{'form.clastname'};
1883: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1884: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1885: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204 raeburn 1886: my ($quotachgresult,$namechgresult);
1887: if ($quotachanged) {
1888: $quotachgresult =
1889: &Apache::lonnet::put('environment',\%changeHash,
1890: $env{'form.ccdomain'},$env{'form.ccuname'});
1891: }
1892: if ($namechanged) {
1893: # Make the change
1894: $namechgresult =
1895: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
1896: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
1897: $changeHash{'firstname'},$changeHash{'middlename'},
1898: $changeHash{'lastname'},$changeHash{'generation'},
1899: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 1900: %userupdate = (
1901: lastname => $env{'form.clastname'},
1902: middlename => $env{'form.cmiddlename'},
1903: firstname => $env{'form.cfirstname'},
1904: generation => $env{'form.cgeneration'},
1905: id => $env{'form.cid'},
1906: );
1.204 raeburn 1907: }
1908: if (($namechanged && $namechgresult eq 'ok') ||
1909: ($quotachanged && $quotachgresult eq 'ok')) {
1.28 matthew 1910: # Tell the user we changed the name
1.73 sakharuk 1911: my %lt=&Apache::lonlocal::texthash(
1912: 'uic' => "User Information Changed",
1913: 'frst' => "first",
1914: 'mddl' => "middle",
1915: 'lst' => "last",
1916: 'gen' => "generation",
1.196 raeburn 1917: 'id' => "ID/Student number",
1.160 raeburn 1918: 'mail' => "permanent e-mail",
1.134 raeburn 1919: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1920: 'prvs' => "Previous",
1921: 'chto' => "Changed To"
1922: );
1.201 raeburn 1923: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1924: &Apache::loncommon::start_data_table().
1925: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1926: $r->print(<<"END");
1.201 raeburn 1927: <th> </th>
1.73 sakharuk 1928: <th>$lt{'frst'}</th>
1929: <th>$lt{'mddl'}</th>
1930: <th>$lt{'lst'}</th>
1.134 raeburn 1931: <th>$lt{'gen'}</th>
1.196 raeburn 1932: <th>$lt{'id'}</th>
1.173 raeburn 1933: <th>$lt{'mail'}</th>
1.201 raeburn 1934: END
1.220 raeburn 1935: if ($showquota) {
1936: $r->print("
1937: <th>$lt{'disk'}</th>\n");
1938: }
1.201 raeburn 1939: $r->print(&Apache::loncommon::end_data_table_header_row().
1940: &Apache::loncommon::start_data_table_row());
1941: $r->print(<<"END");
1942: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 1943: <td>$userenv{'firstname'} </td>
1944: <td>$userenv{'middlename'} </td>
1945: <td>$userenv{'lastname'} </td>
1.134 raeburn 1946: <td>$userenv{'generation'} </td>
1.196 raeburn 1947: <td>$userenv{'id'}</td>
1.160 raeburn 1948: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 1949: END
1.220 raeburn 1950: if ($showquota) {
1951: $r->print("
1952: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
1953: }
1.201 raeburn 1954: $r->print(&Apache::loncommon::end_data_table_row().
1955: &Apache::loncommon::start_data_table_row());
1956: $r->print(<<"END");
1957: <td><b>$lt{'chto'}</b></td>
1.101 albertel 1958: <td>$env{'form.cfirstname'} </td>
1959: <td>$env{'form.cmiddlename'} </td>
1960: <td>$env{'form.clastname'} </td>
1.134 raeburn 1961: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 1962: <td>$env{'form.cid'} </td>
1.160 raeburn 1963: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 1964: END
1.220 raeburn 1965: if ($showquota) {
1966: $r->print("
1967: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
1968: }
1.201 raeburn 1969: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 1970: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 1971: if ($env{'form.cid'} ne $userenv{'id'}) {
1972: &Apache::lonnet::idput($env{'form.ccdomain'},
1973: ($env{'form.ccuname'} => $env{'form.cid'}));
1974: if (($recurseid) &&
1975: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
1976: my $idresult =
1977: &Apache::lonuserutils::propagate_id_change(
1978: $env{'form.ccuname'},$env{'form.ccdomain'},
1979: \%userupdate);
1980: $r->print('<br />'.$idresult.'<br />');
1981: }
1.196 raeburn 1982: }
1.149 raeburn 1983: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1984: ($env{'form.ccuname'} eq $env{'user.name'})) {
1985: my %newenvhash;
1986: foreach my $key (keys(%changeHash)) {
1987: $newenvhash{'environment.'.$key} = $changeHash{$key};
1988: }
1.238 raeburn 1989: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 1990: }
1.28 matthew 1991: } else { # error occurred
1.188 raeburn 1992: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
1993: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 1994: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 1995: }
1.101 albertel 1996: } else { # End of if ($env ... ) logic
1.204 raeburn 1997: # They did not want to change the users name or quota but we can
1998: # still tell them what the name and quota are
1.73 sakharuk 1999: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 2000: 'id' => "ID/Student number",
1.160 raeburn 2001: 'mail' => "Permanent e-mail",
1.134 raeburn 2002: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 2003: );
1.134 raeburn 2004: $r->print(<<"END");
1.196 raeburn 2005: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2006: END
1.204 raeburn 2007: if ($userenv{'permanentemail'} ne '') {
2008: $r->print('<br />['.$lt{'mail'}.': '.
2009: $userenv{'permanentemail'}.']');
1.134 raeburn 2010: }
1.220 raeburn 2011: if ($showquota) {
2012: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
2013: $olddefquotatext.']');
2014: }
2015: $r->print('</h4>');
1.28 matthew 2016: }
1.206 raeburn 2017: if (@mod_disallowed) {
2018: my ($rolestr,$contextname);
2019: if (@longroles > 0) {
2020: $rolestr = join(', ',@longroles);
2021: } else {
2022: $rolestr = &mt('No roles');
2023: }
2024: if ($context eq 'course') {
2025: $contextname = &mt('course');
2026: } elsif ($context eq 'author') {
2027: $contextname = &mt('co-author');
2028: }
2029: $r->print(&mt('The following fields were not updated: ').'<ul>');
2030: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2031: foreach my $field (@mod_disallowed) {
2032: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2033: }
1.207 raeburn 2034: $r->print('</ul>');
2035: if (@mod_disallowed == 1) {
2036: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
2037: } else {
2038: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
2039: }
2040: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2041: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2042: }
2043: $r->print($no_forceid_alert.
1.239 raeburn 2044: &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules));
1.4 www 2045: }
1.220 raeburn 2046: if ($env{'form.action'} eq 'singlestudent') {
1.239 raeburn 2047: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
2048: $r->print('<p><a href="javascript:backPage(document.userupdate)">'.
2049: &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2050: } else {
1.239 raeburn 2051: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2052: if ($namechanged) {
1.220 raeburn 2053: if ($context eq 'course') {
2054: if (@userroles > 0) {
1.225 raeburn 2055: if ((@rolechanges == 0) ||
2056: (!(grep(/^st$/,@rolechanges)))) {
2057: if (grep(/^st$/,@userroles)) {
2058: my $classlistupdated =
2059: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2060: $cnum,$env{'form.ccdomain'},
2061: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2062: }
1.220 raeburn 2063: }
2064: }
2065: }
2066: }
1.226 raeburn 2067: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2068: $env{'form.ccdomain'});
2069: if ($env{'form.popup'}) {
2070: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2071: } else {
2072: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'.&mt('Modify this user: <span class="LC_cusr_emph">([_1])</span>',$userinfo).'</a>'.(' 'x5).'<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a></p>');
2073: }
1.220 raeburn 2074: }
2075: $r->print(&Apache::loncommon::end_page());
2076: }
2077:
2078: sub update_roles {
1.239 raeburn 2079: my ($r,$context) = @_;
1.4 www 2080: my $now=time;
1.225 raeburn 2081: my @rolechanges;
1.220 raeburn 2082: my %disallowed;
1.73 sakharuk 2083: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2084: foreach my $key (keys (%env)) {
2085: next if (! $env{$key});
1.190 raeburn 2086: next if ($key eq 'form.action');
1.27 matthew 2087: # Revoke roles
1.135 raeburn 2088: if ($key=~/^form\.rev/) {
2089: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2090: # Revoke standard role
1.170 albertel 2091: my ($scope,$role) = ($1,$2);
2092: my $result =
2093: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2094: $env{'form.ccuname'},
1.239 raeburn 2095: $scope,$role,'','',$context);
1.170 albertel 2096: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2097: $role,$scope,'<b>'.$result.'</b>').'<br />');
2098: if ($role eq 'st') {
1.202 raeburn 2099: my $result =
1.198 raeburn 2100: &Apache::lonuserutils::classlist_drop($scope,
2101: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2102: $now);
1.170 albertel 2103: $r->print($result);
1.53 www 2104: }
1.225 raeburn 2105: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2106: push(@rolechanges,$role);
2107: }
1.196 raeburn 2108: }
1.195 raeburn 2109: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2110: # Revoke custom role
1.113 raeburn 2111: $r->print(&mt('Revoking custom role:').
1.139 albertel 2112: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2113: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 2114: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 2115: '</b><br />');
1.225 raeburn 2116: if (!grep(/^cr$/,@rolechanges)) {
2117: push(@rolechanges,'cr');
2118: }
1.64 www 2119: }
1.135 raeburn 2120: } elsif ($key=~/^form\.del/) {
2121: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2122: # Delete standard role
1.170 albertel 2123: my ($scope,$role) = ($1,$2);
2124: my $result =
2125: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2126: $env{'form.ccuname'},
1.239 raeburn 2127: $scope,$role,$now,0,1,'',
2128: $context);
1.170 albertel 2129: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2130: '<b>'.$result.'</b>').'<br />');
2131: if ($role eq 'st') {
1.202 raeburn 2132: my $result =
1.198 raeburn 2133: &Apache::lonuserutils::classlist_drop($scope,
2134: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2135: $now);
1.170 albertel 2136: $r->print($result);
1.81 albertel 2137: }
1.225 raeburn 2138: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2139: push(@rolechanges,$role);
2140: }
1.116 raeburn 2141: }
1.139 albertel 2142: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2143: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2144: # Delete custom role
1.170 albertel 2145: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2146: $rolename,$rnam,$rdom,$url).': <b>'.
2147: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2148: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 2149: 0,1,$context).'</b><br />');
1.225 raeburn 2150: if (!grep(/^cr$/,@rolechanges)) {
2151: push(@rolechanges,'cr');
2152: }
1.116 raeburn 2153: }
1.135 raeburn 2154: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2155: my $udom = $env{'form.ccdomain'};
2156: my $uname = $env{'form.ccuname'};
1.116 raeburn 2157: # Re-enable standard role
1.135 raeburn 2158: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2159: my $url = $1;
2160: my $role = $2;
2161: my $logmsg;
2162: my $output;
2163: if ($role eq 'st') {
1.141 albertel 2164: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2165: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2166: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2167: if ($result eq 'refused' && $logmsg) {
2168: $output = $logmsg;
2169: } else {
2170: $output = "Error: $result\n";
2171: }
1.89 raeburn 2172: } else {
2173: $output = &mt('Assigning').' '.$role.' in '.$url.
2174: &mt('starting').' '.localtime($now).
2175: ': <br />'.$logmsg.'<br />'.
2176: &mt('Add to classlist').': <b>ok</b><br />';
2177: }
2178: }
2179: } else {
1.101 albertel 2180: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 2181: $env{'form.ccuname'},$url,$role,0,$now,'','',
2182: $context);
1.116 raeburn 2183: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 2184: $role,$url,$result).'<br />';
1.27 matthew 2185: }
1.89 raeburn 2186: $r->print($output);
1.225 raeburn 2187: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2188: push(@rolechanges,$role);
2189: }
1.113 raeburn 2190: }
1.116 raeburn 2191: # Re-enable custom role
1.139 albertel 2192: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2193: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2194: my $result = &Apache::lonnet::assigncustomrole(
2195: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 2196: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.116 raeburn 2197: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
2198: $rolename,$rnam,$rdom,$url,$result).'<br />');
1.225 raeburn 2199: if (!grep(/^cr$/,@rolechanges)) {
2200: push(@rolechanges,'cr');
2201: }
1.116 raeburn 2202: }
1.135 raeburn 2203: } elsif ($key=~/^form\.act/) {
1.101 albertel 2204: my $udom = $env{'form.ccdomain'};
2205: my $uname = $env{'form.ccuname'};
1.141 albertel 2206: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2207: # Activate a custom role
1.83 albertel 2208: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2209: my $url='/'.$one.'/'.$two;
2210: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2211:
1.101 albertel 2212: my $start = ( $env{'form.start_'.$full} ?
2213: $env{'form.start_'.$full} :
1.88 raeburn 2214: $now );
1.101 albertel 2215: my $end = ( $env{'form.end_'.$full} ?
2216: $env{'form.end_'.$full} :
1.88 raeburn 2217: 0 );
2218:
2219: # split multiple sections
2220: my %sections = ();
1.101 albertel 2221: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2222: if ($num_sections == 0) {
1.240 raeburn 2223: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2224: } else {
1.114 albertel 2225: my %curr_groups =
1.117 raeburn 2226: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2227: foreach my $sec (sort {$a cmp $b} keys %sections) {
2228: if (($sec eq 'none') || ($sec eq 'all') ||
2229: exists($curr_groups{$sec})) {
2230: $disallowed{$sec} = $url;
2231: next;
2232: }
2233: my $securl = $url.'/'.$sec;
1.240 raeburn 2234: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2235: }
2236: }
1.225 raeburn 2237: if (!grep(/^cr$/,@rolechanges)) {
2238: push(@rolechanges,'cr');
2239: }
1.142 raeburn 2240: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2241: # Activate roles for sections with 3 id numbers
2242: # set start, end times, and the url for the class
1.83 albertel 2243: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2244: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2245: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2246: $now );
1.101 albertel 2247: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2248: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2249: 0 );
1.83 albertel 2250: my $url='/'.$one.'/'.$two;
1.88 raeburn 2251: my $type = 'three';
2252: # split multiple sections
2253: my %sections = ();
1.101 albertel 2254: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2255: if ($num_sections == 0) {
1.240 raeburn 2256: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2257: } else {
1.114 albertel 2258: my %curr_groups =
1.117 raeburn 2259: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2260: my $emptysec = 0;
2261: foreach my $sec (sort {$a cmp $b} keys %sections) {
2262: $sec =~ s/\W//g;
1.113 raeburn 2263: if ($sec ne '') {
2264: if (($sec eq 'none') || ($sec eq 'all') ||
2265: exists($curr_groups{$sec})) {
2266: $disallowed{$sec} = $url;
2267: next;
2268: }
1.88 raeburn 2269: my $securl = $url.'/'.$sec;
1.240 raeburn 2270: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 2271: } else {
2272: $emptysec = 1;
2273: }
2274: }
2275: if ($emptysec) {
1.240 raeburn 2276: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2277: }
1.225 raeburn 2278: }
2279: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2280: push(@rolechanges,$three);
2281: }
1.135 raeburn 2282: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2283: # Activate roles for sections with two id numbers
2284: # set start, end times, and the url for the class
1.101 albertel 2285: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2286: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2287: $now );
1.101 albertel 2288: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2289: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2290: 0 );
1.225 raeburn 2291: my $one = $1;
2292: my $two = $2;
2293: my $url='/'.$one.'/';
1.88 raeburn 2294: # split multiple sections
2295: my %sections = ();
1.225 raeburn 2296: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2297: if ($num_sections == 0) {
1.240 raeburn 2298: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2299: } else {
2300: my $emptysec = 0;
2301: foreach my $sec (sort {$a cmp $b} keys %sections) {
2302: if ($sec ne '') {
2303: my $securl = $url.'/'.$sec;
1.240 raeburn 2304: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 2305: } else {
2306: $emptysec = 1;
2307: }
2308: }
2309: if ($emptysec) {
1.240 raeburn 2310: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2311: }
2312: }
1.225 raeburn 2313: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2314: push(@rolechanges,$two);
2315: }
1.64 www 2316: } else {
1.190 raeburn 2317: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2318: }
1.113 raeburn 2319: foreach my $key (sort(keys(%disallowed))) {
2320: if (($key eq 'none') || ($key eq 'all')) {
2321: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2322: } else {
2323: $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));
2324: }
2325: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2326: }
2327: }
1.101 albertel 2328: } # End of foreach (keys(%env))
1.75 www 2329: # Flush the course logs so reverse user roles immediately updated
2330: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2331: if (@rolechanges == 0) {
1.193 raeburn 2332: $r->print(&mt('No roles to modify'));
2333: }
1.225 raeburn 2334: return @rolechanges;
1.220 raeburn 2335: }
2336:
2337: sub enroll_single_student {
1.239 raeburn 2338: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
1.220 raeburn 2339: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2340:
2341: # Remove non alphanumeric values from section
2342: $env{'form.sections'}=~s/\W//g;
2343:
2344: # Clean out any old student roles the user has in this class.
2345: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2346: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2347: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2348: my $enroll_result =
2349: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2350: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2351: $env{'form.cmiddlename'},$env{'form.clastname'},
2352: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 2353: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 2354: if ($enroll_result =~ /^ok/) {
2355: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2356: if ($env{'form.sections'} ne '') {
2357: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2358: }
2359: my ($showstart,$showend);
2360: if ($startdate <= $now) {
2361: $showstart = &mt('Access starts immediately');
2362: } else {
2363: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2364: }
2365: if ($enddate == 0) {
2366: $showend = &mt('ends: no ending date');
2367: } else {
2368: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2369: }
2370: $r->print('.<br />'.$showstart.'; '.$showend);
2371: if ($startdate <= $now && !$newuser) {
2372: $r->print("<p> ".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."</p>");
2373: }
2374: } else {
2375: $r->print(&mt('unable to enroll').": ".$enroll_result);
2376: }
2377: return;
1.188 raeburn 2378: }
2379:
1.204 raeburn 2380: sub get_defaultquota_text {
2381: my ($settingstatus) = @_;
2382: my $defquotatext;
2383: if ($settingstatus eq '') {
2384: $defquotatext = &mt('(default)');
2385: } else {
2386: my ($usertypes,$order) =
2387: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2388: if ($usertypes->{$settingstatus} eq '') {
2389: $defquotatext = &mt('(default)');
2390: } else {
2391: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2392: }
2393: }
2394: return $defquotatext;
2395: }
2396:
1.188 raeburn 2397: sub update_result_form {
2398: my ($uhome) = @_;
2399: my $outcome =
2400: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2401: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2402: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2403: }
1.207 raeburn 2404: if ($env{'form.origname'} ne '') {
2405: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2406: }
1.160 raeburn 2407: foreach my $item ('sortby','seluname','seludom') {
2408: if (exists($env{'form.'.$item})) {
1.188 raeburn 2409: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2410: }
2411: }
1.188 raeburn 2412: if ($uhome eq 'no_host') {
2413: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2414: }
2415: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2416: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2417: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2418: '</form>';
2419: return $outcome;
1.4 www 2420: }
2421:
1.149 raeburn 2422: sub quota_admin {
2423: my ($setquota,$changeHash) = @_;
2424: my $quotachanged;
2425: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2426: # Current user has quota modification privileges
2427: $quotachanged = 1;
2428: $changeHash->{'portfolioquota'} = $setquota;
2429: }
2430: return $quotachanged;
2431: }
2432:
1.88 raeburn 2433: sub build_roles {
1.89 raeburn 2434: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2435: my $num_sections = 0;
2436: if ($sectionstr=~ /,/) {
2437: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2438: if ($role eq 'st') {
2439: $secnums[0] =~ s/\W//g;
2440: $$sections{$secnums[0]} = 1;
2441: $num_sections = 1;
2442: } else {
2443: foreach my $sec (@secnums) {
2444: $sec =~ ~s/\W//g;
1.150 banghart 2445: if (!($sec eq "")) {
1.89 raeburn 2446: if (exists($$sections{$sec})) {
2447: $$sections{$sec} ++;
2448: } else {
2449: $$sections{$sec} = 1;
2450: $num_sections ++;
2451: }
1.88 raeburn 2452: }
2453: }
2454: }
2455: } else {
2456: $sectionstr=~s/\W//g;
2457: unless ($sectionstr eq '') {
2458: $$sections{$sectionstr} = 1;
2459: $num_sections ++;
2460: }
2461: }
1.129 albertel 2462:
1.88 raeburn 2463: return $num_sections;
2464: }
2465:
1.58 www 2466: # ========================================================== Custom Role Editor
2467:
2468: sub custom_role_editor {
1.160 raeburn 2469: my ($r) = @_;
1.101 albertel 2470: my $rolename=$env{'form.rolename'};
1.58 www 2471:
1.59 www 2472: if ($rolename eq 'make new role') {
1.101 albertel 2473: $rolename=$env{'form.newrolename'};
1.59 www 2474: }
2475:
1.63 www 2476: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2477:
1.190 raeburn 2478: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2479: &print_username_entry_form($r);
2480: return;
2481: }
1.153 banghart 2482: # ------------------------------------------------------- What can be assigned?
2483: my %full=();
2484: my %courselevel=();
2485: my %courselevelcurrent=();
1.61 www 2486: my $syspriv='';
2487: my $dompriv='';
2488: my $coursepriv='';
1.153 banghart 2489: my $body_top;
1.150 banghart 2490: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2491: my ($rdummy,$roledef)=
2492: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2493: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2494: $body_top .= '<h2>';
1.59 www 2495: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2496: $body_top .= &mt('Existing Role').' "';
1.61 www 2497: # ------------------------------------------------- Get current role privileges
2498: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2499: } else {
1.153 banghart 2500: $body_top .= &mt('New Role').' "';
1.59 www 2501: $roledef='';
2502: }
1.153 banghart 2503: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2504: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2505: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2506: if (!$restrict) { $restrict='F'; }
1.60 www 2507: $courselevel{$priv}=$restrict;
1.61 www 2508: if ($coursepriv=~/\:$priv/) {
2509: $courselevelcurrent{$priv}=1;
2510: }
1.60 www 2511: $full{$priv}=1;
2512: }
2513: my %domainlevel=();
1.61 www 2514: my %domainlevelcurrent=();
1.135 raeburn 2515: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2516: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2517: if (!$restrict) { $restrict='F'; }
1.60 www 2518: $domainlevel{$priv}=$restrict;
1.61 www 2519: if ($dompriv=~/\:$priv/) {
2520: $domainlevelcurrent{$priv}=1;
2521: }
1.60 www 2522: $full{$priv}=1;
2523: }
1.61 www 2524: my %systemlevel=();
2525: my %systemlevelcurrent=();
1.135 raeburn 2526: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2527: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2528: if (!$restrict) { $restrict='F'; }
1.61 www 2529: $systemlevel{$priv}=$restrict;
2530: if ($syspriv=~/\:$priv/) {
2531: $systemlevelcurrent{$priv}=1;
2532: }
2533: $full{$priv}=1;
2534: }
1.160 raeburn 2535: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2536: my $button_code = "\n";
1.153 banghart 2537: my $head_script = "\n";
2538: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2539: my @template_roles = ("cc","in","ta","ep","st");
2540: foreach my $role (@template_roles) {
2541: $head_script .= &make_script_template($role);
2542: $button_code .= &make_button_code($role);
2543: }
1.160 raeburn 2544: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2545: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2546: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2547: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2548: text=>"Pick custom role",
1.160 raeburn 2549: faq=>282,bug=>'Instructor Interface',},
2550: {href=>"javascript:backPage(document.form1,'','')",
2551: text=>"Edit custom role",
2552: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2553: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2554: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2555:
1.153 banghart 2556: $r->print($body_top);
1.73 sakharuk 2557: my %lt=&Apache::lonlocal::texthash(
2558: 'prv' => "Privilege",
1.131 raeburn 2559: 'crl' => "Course Level",
1.73 sakharuk 2560: 'dml' => "Domain Level",
1.150 banghart 2561: 'ssl' => "System Level");
1.236 bisitz 2562: $r->print(&mt('Select a Template').'<br />');
1.154 banghart 2563: $r->print('<form action="">');
2564: $r->print($button_code);
2565: $r->print('</form>');
1.61 www 2566: $r->print(<<ENDCCF);
1.160 raeburn 2567: <form name="form1" method="post">
1.61 www 2568: <input type="hidden" name="phase" value="set_custom_roles" />
2569: <input type="hidden" name="rolename" value="$rolename" />
2570: ENDCCF
1.135 raeburn 2571: $r->print(&Apache::loncommon::start_data_table().
2572: &Apache::loncommon::start_data_table_header_row().
2573: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2574: '</th><th>'.$lt{'ssl'}.'</th>'.
2575: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2576: foreach my $priv (sort keys %full) {
2577: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2578: $r->print(&Apache::loncommon::start_data_table_row().
2579: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2580: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2581: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2582: '</td><td>'.
1.150 banghart 2583: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2584: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2585: '</td><td>'.
1.150 banghart 2586: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2587: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2588: '</td>'.
2589: &Apache::loncommon::end_data_table_row());
1.60 www 2590: }
1.135 raeburn 2591: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2592: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2593: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2594: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2595: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2596: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2597: &Apache::loncommon::end_page());
1.61 www 2598: }
1.153 banghart 2599: # --------------------------------------------------------
2600: sub make_script_template {
2601: my ($role) = @_;
2602: my %full_c=();
2603: my %full_d=();
2604: my %full_s=();
2605: my $return_script;
2606: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2607: my ($priv,$restrict)=split(/\&/,$item);
2608: $full_c{$priv}=1;
2609: }
2610: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2611: my ($priv,$restrict)=split(/\&/,$item);
2612: $full_d{$priv}=1;
2613: }
1.154 banghart 2614: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2615: my ($priv,$restrict)=split(/\&/,$item);
2616: $full_s{$priv}=1;
2617: }
2618: $return_script .= 'function set_'.$role.'() {'."\n";
2619: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2620: my %role_c;
1.155 banghart 2621: foreach my $priv (@temp) {
1.153 banghart 2622: my ($priv_item, $dummy) = split(/\&/,$priv);
2623: $role_c{$priv_item} = 1;
2624: }
2625: foreach my $priv_item (keys(%full_c)) {
2626: my ($priv, $dummy) = split(/\&/,$priv_item);
2627: if (exists($role_c{$priv})) {
2628: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2629: } else {
2630: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2631: }
2632: }
1.154 banghart 2633: my %role_d;
2634: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2635: foreach my $priv(@temp) {
2636: my ($priv_item, $dummy) = split(/\&/,$priv);
2637: $role_d{$priv_item} = 1;
2638: }
2639: foreach my $priv_item (keys(%full_d)) {
2640: my ($priv, $dummy) = split(/\&/,$priv_item);
2641: if (exists($role_d{$priv})) {
2642: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2643: } else {
2644: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2645: }
2646: }
2647: my %role_s;
2648: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2649: foreach my $priv(@temp) {
2650: my ($priv_item, $dummy) = split(/\&/,$priv);
2651: $role_s{$priv_item} = 1;
2652: }
2653: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2654: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2655: if (exists($role_s{$priv})) {
2656: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2657: } else {
2658: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2659: }
1.153 banghart 2660: }
2661: $return_script .= '}'."\n";
1.154 banghart 2662: return ($return_script);
2663: }
2664: # ----------------------------------------------------------
2665: sub make_button_code {
2666: my ($role) = @_;
2667: my $label = &Apache::lonnet::plaintext($role);
2668: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2669: return ($button_code);
1.153 banghart 2670: }
1.61 www 2671: # ---------------------------------------------------------- Call to definerole
2672: sub set_custom_role {
1.240 raeburn 2673: my ($r,$context) = @_;
1.101 albertel 2674: my $rolename=$env{'form.rolename'};
1.63 www 2675: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2676: if (!$rolename) {
1.190 raeburn 2677: &custom_role_editor($r);
1.61 www 2678: return;
2679: }
1.160 raeburn 2680: my ($jsback,$elements) = &crumb_utilities();
2681: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2682:
2683: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2684: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2685: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2686: text=>"Pick custom role",
1.160 raeburn 2687: faq=>282,bug=>'Instructor Interface',},
2688: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2689: text=>"Edit custom role",
2690: faq=>282,bug=>'Instructor Interface',},
2691: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2692: text=>"Result",
2693: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2694: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2695: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2696:
1.61 www 2697: my ($rdummy,$roledef)=
1.110 albertel 2698: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2699:
1.61 www 2700: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2701: $r->print('<h3>');
1.61 www 2702: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2703: $r->print(&mt('Existing Role').' "');
1.61 www 2704: } else {
1.73 sakharuk 2705: $r->print(&mt('New Role').' "');
1.61 www 2706: $roledef='';
2707: }
1.188 raeburn 2708: $r->print($rolename.'"</h3>');
1.61 www 2709: # ------------------------------------------------------- What can be assigned?
2710: my $sysrole='';
2711: my $domrole='';
2712: my $courole='';
2713:
1.135 raeburn 2714: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2715: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2716: if (!$restrict) { $restrict=''; }
2717: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2718: $courole.=':'.$item;
1.61 www 2719: }
2720: }
2721:
1.135 raeburn 2722: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2723: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2724: if (!$restrict) { $restrict=''; }
2725: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2726: $domrole.=':'.$item;
1.61 www 2727: }
2728: }
2729:
1.135 raeburn 2730: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2731: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2732: if (!$restrict) { $restrict=''; }
2733: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2734: $sysrole.=':'.$item;
1.61 www 2735: }
2736: }
1.63 www 2737: $r->print('<br />Defining Role: '.
1.61 www 2738: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2739: if ($env{'request.course.id'}) {
2740: my $url='/'.$env{'request.course.id'};
1.63 www 2741: $url=~s/\_/\//g;
1.73 sakharuk 2742: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2743: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2744: $env{'user.name'},
1.63 www 2745: $url,
1.101 albertel 2746: $env{'user.domain'},
2747: $env{'user.name'},
1.240 raeburn 2748: $rolename,undef,undef,undef,$context));
1.63 www 2749: }
1.190 raeburn 2750: $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160 raeburn 2751: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2752: $r->print(&Apache::loncommon::end_page());
1.58 www 2753: }
2754:
1.2 www 2755: # ================================================================ Main Handler
2756: sub handler {
2757: my $r = shift;
2758: if ($r->header_only) {
1.68 www 2759: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2760: $r->send_http_header;
2761: return OK;
2762: }
1.190 raeburn 2763: my $context;
2764: if ($env{'request.course.id'}) {
2765: $context = 'course';
2766: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 2767: $context = 'author';
1.190 raeburn 2768: } else {
2769: $context = 'domain';
2770: }
2771: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 2772: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
2773: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 2774: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2775: if ($env{'form.action'} ne 'dateselect') {
2776: &Apache::lonhtmlcommon::add_breadcrumb
2777: ({href=>"/adm/createuser",
2778: text=>"User Management"});
2779: }
1.209 raeburn 2780: my ($permission,$allowed) =
2781: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 2782: if (!$allowed) {
2783: $env{'user.error.msg'}=
2784: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2785: "or view user status.";
2786: return HTTP_NOT_ACCEPTABLE;
2787: }
2788:
2789: &Apache::loncommon::content_type($r,'text/html');
2790: $r->send_http_header;
2791:
2792: # Main switch on form.action and form.state, as appropriate
2793: if (! exists($env{'form.action'})) {
2794: $r->print(&header());
2795: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 2796: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2797: $r->print(&Apache::loncommon::end_page());
2798: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2799: $r->print(&header());
2800: &Apache::lonhtmlcommon::add_breadcrumb
2801: ({href=>'/adm/createuser?action=upload&state=',
2802: text=>"Upload Users List"});
2803: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 2804: 'Course_Create_Class_List'));
1.190 raeburn 2805: $r->print('<form name="studentform" method="post" '.
2806: 'enctype="multipart/form-data" '.
2807: ' action="/adm/createuser">'."\n");
2808: if (! exists($env{'form.state'})) {
2809: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2810: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 2811: &Apache::lonuserutils::print_upload_manager_form($r,$context,
2812: $permission);
1.190 raeburn 2813: } elsif ($env{'form.state'} eq 'enrolling') {
2814: if ($env{'form.datatoken'}) {
1.221 raeburn 2815: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 2816: }
2817: } else {
2818: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2819: }
2820: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 2821: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
2822: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 2823: my $phase = $env{'form.phase'};
2824: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2825: &Apache::loncreateuser::restore_prev_selections();
2826: my $srch;
2827: foreach my $item (@search) {
2828: $srch->{$item} = $env{'form.'.$item};
2829: }
1.207 raeburn 2830: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
2831: ($phase eq 'createnewuser')) {
2832: if ($env{'form.phase'} eq 'createnewuser') {
2833: my $response;
2834: if ($env{'form.srchterm'} !~ /^$match_username$/) {
2835: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 2836: $env{'form.phase'} = '';
1.207 raeburn 2837: &print_username_entry_form($r,$context,$response,$srch);
2838: } else {
2839: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
2840: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
2841: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2842: $srch,$response,$context,
2843: $permission);
1.207 raeburn 2844: }
2845: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 2846: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 2847: &user_search_result($context,$srch);
1.190 raeburn 2848: if ($env{'form.currstate'} eq 'modify') {
2849: $currstate = $env{'form.currstate'};
2850: }
2851: if ($currstate eq 'select') {
2852: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 2853: \@search,$context);
1.190 raeburn 2854: } elsif ($currstate eq 'modify') {
2855: my ($ccuname,$ccdomain);
2856: if (($srch->{'srchby'} eq 'uname') &&
2857: ($srch->{'srchtype'} eq 'exact')) {
2858: $ccuname = $srch->{'srchterm'};
2859: $ccdomain= $srch->{'srchdomain'};
2860: } else {
2861: my @matchedunames = keys(%{$results});
2862: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2863: }
2864: $ccuname =&LONCAPA::clean_username($ccuname);
2865: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2866: if ($env{'form.forcenewuser'}) {
2867: $response = '';
2868: }
2869: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2870: $srch,$response,$context,
2871: $permission);
1.190 raeburn 2872: } elsif ($currstate eq 'query') {
2873: &print_user_query_page($r,'createuser');
2874: } else {
1.229 raeburn 2875: $env{'form.phase'} = '';
1.207 raeburn 2876: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 2877: $forcenewuser);
2878: }
2879: } elsif ($env{'form.phase'} eq 'userpicked') {
2880: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2881: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2882: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 2883: $context,$permission);
1.190 raeburn 2884: }
2885: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 2886: &update_user_data($r,$context);
1.190 raeburn 2887: } else {
1.207 raeburn 2888: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 2889: }
2890: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2891: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 2892: &set_custom_role($r,$context);
1.190 raeburn 2893: } else {
2894: &custom_role_editor($r);
2895: }
1.207 raeburn 2896: } elsif (($env{'form.action'} eq 'listusers') &&
2897: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 2898: if ($env{'form.phase'} eq 'bulkchange') {
2899: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 2900: ({href=>'/adm/createuser?action=listusers',
2901: text=>"List Users"},
2902: {href=>"/adm/createuser",
2903: text=>"Result"});
1.202 raeburn 2904: my $setting = $env{'form.roletype'};
2905: my $choice = $env{'form.bulkaction'};
2906: $r->print(&header());
1.221 raeburn 2907: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 2908: 'Course_View_Class_List'));
1.202 raeburn 2909: if ($permission->{'cusr'}) {
2910: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 2911: $r->print(&Apache::loncommon::end_page());
2912: } else {
2913: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 2914: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 2915: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2916: }
2917: } else {
2918: &Apache::lonhtmlcommon::add_breadcrumb
2919: ({href=>'/adm/createuser?action=listusers',
2920: text=>"List Users"});
2921: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2922: my $formname = 'studentform';
2923: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2924: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2925: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2926: $formname);
2927: $jscript .= &verify_user_display();
2928: my $js = &add_script($jscript).$cb_jscript;
2929: my $loadcode =
2930: &Apache::lonuserutils::course_selector_loadcode($formname);
2931: if ($loadcode ne '') {
2932: $r->print(&header($js,{'onload' => $loadcode,}));
2933: } else {
2934: $r->print(&header($js));
2935: }
1.191 raeburn 2936: } else {
1.202 raeburn 2937: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 2938: }
1.202 raeburn 2939: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 2940: 'Course_View_Class_List'));
1.202 raeburn 2941: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
2942: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
2943: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 2944: }
1.213 raeburn 2945: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
2946: $r->print(&header());
2947: &Apache::lonhtmlcommon::add_breadcrumb
2948: ({href=>'/adm/createuser?action=drop',
2949: text=>"Drop Students"});
2950: if (!exists($env{'form.state'})) {
2951: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2952: 'Course_Drop_Student'));
2953:
2954: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
2955: } elsif ($env{'form.state'} eq 'done') {
2956: &Apache::lonhtmlcommon::add_breadcrumb
2957: ({href=>'/adm/createuser?action=drop',
2958: text=>"Result"});
2959: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2960: 'Course_Drop_Student'));
2961: &Apache::lonuserutils::update_user_list($r,$context,undef,
2962: $env{'form.action'});
2963: }
2964: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2965: } elsif ($env{'form.action'} eq 'dateselect') {
2966: if ($permission->{'cusr'}) {
2967: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 2968: &Apache::lonuserutils::date_section_selector($context,
2969: $permission).
1.202 raeburn 2970: &Apache::loncommon::end_page());
2971: } else {
2972: $r->print(&header().
2973: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
2974: &Apache::loncommon::end_page());
2975: }
1.237 raeburn 2976: } elsif ($env{'form.action'} eq 'selfenroll') {
2977: $r->print(&header());
2978: &Apache::lonhtmlcommon::add_breadcrumb
2979: ({href=>'/adm/createuser?action=selfenroll',
2980: text=>"Configure Self-enrollment"});
2981: if (!exists($env{'form.state'})) {
2982: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
2983: 'Course_Self_Enrollment'));
1.241 raeburn 2984: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 2985: &print_selfenroll_menu($r,$context,$permission);
2986: } elsif ($env{'form.state'} eq 'done') {
2987: &Apache::lonhtmlcommon::add_breadcrumb
2988: ({href=>'/adm/createuser?action=selfenroll',
2989: text=>"Result"});
2990: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
2991: 'Course_Self_Enrollment'));
1.241 raeburn 2992: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
2993: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 2994: }
2995: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 2996: } elsif ($env{'form.action'} eq 'changelogs') {
2997: $r->print(&header());
2998: &Apache::lonhtmlcommon::add_breadcrumb
2999: ({href=>'/adm/createuser?action=changelogs',
3000: text=>"User Management Logs"});
3001: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
3002: 'Course_User_Logs'));
3003: &print_userchangelogs_display($r,$context,$permission);
3004: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 3005: } else {
3006: $r->print(&header());
1.202 raeburn 3007: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 3008: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3009: $r->print(&Apache::loncommon::end_page());
3010: }
3011: return OK;
3012: }
3013:
3014: sub header {
1.202 raeburn 3015: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 3016: my $start_page;
3017: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 3018: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 3019: } else {
1.202 raeburn 3020: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 3021: }
3022: return $start_page;
3023: }
1.2 www 3024:
1.191 raeburn 3025: sub add_script {
3026: my ($js) = @_;
3027: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
3028: }
3029:
1.202 raeburn 3030: sub verify_user_display {
3031: my $output = <<"END";
3032:
3033: function display_update() {
3034: document.studentform.action.value = 'listusers';
3035: document.studentform.phase.value = 'display';
3036: document.studentform.submit();
3037: }
3038:
3039: END
3040: return $output;
3041:
3042: }
3043:
1.190 raeburn 3044: ###############################################################
3045: ###############################################################
3046: # Menu Phase One
3047: sub print_main_menu {
1.208 raeburn 3048: my ($permission,$context) = @_;
3049: my %links = (
3050: domain => {
3051: upload => 'Upload a File of Users',
1.221 raeburn 3052: singleuser => 'Add/Modify a Single User',
1.208 raeburn 3053: listusers => 'Manage Multiple Users',
3054: },
3055: author => {
3056: upload => 'Upload a File of Co-authors',
1.221 raeburn 3057: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 3058: listusers => 'Display Co-authors and Manage Multiple Users',
3059: },
3060: course => {
3061: upload => 'Upload a File of Course Users',
1.221 raeburn 3062: singleuser => 'Add/Modify a Single Course User',
1.208 raeburn 3063: listusers => 'Display Class Lists and Manage Multiple Users',
3064: },
3065: );
1.190 raeburn 3066: my @menu =
3067: (
1.208 raeburn 3068: { text => $links{$context}{'upload'},
1.224 raeburn 3069: help => 'Course_Create_Class_List',
1.190 raeburn 3070: action => 'upload',
3071: permission => $permission->{'cusr'},
3072: },
1.208 raeburn 3073: { text => $links{$context}{'singleuser'},
1.224 raeburn 3074: help => 'Course_Change_Privileges',
1.190 raeburn 3075: action => 'singleuser',
3076: permission => $permission->{'cusr'},
3077: },
1.208 raeburn 3078: { text => $links{$context}{'listusers'},
1.224 raeburn 3079: help => 'Course_View_Class_List',
1.191 raeburn 3080: action => 'listusers',
1.208 raeburn 3081: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190 raeburn 3082: },
3083: );
1.208 raeburn 3084: if ($context eq 'domain' || $context eq 'course') {
3085: my $customlink = { text => 'Edit Custom Roles',
1.224 raeburn 3086: help => 'Course_Editing_Custom_Roles',
1.208 raeburn 3087: action => 'custom',
3088: permission => $permission->{'custom'},
3089: };
3090: push(@menu,$customlink);
3091: }
3092: if ($context eq 'course') {
1.213 raeburn 3093: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
3094: my @courselinks =
1.208 raeburn 3095: (
1.213 raeburn 3096: { text => 'Enroll a Single Student',
1.224 raeburn 3097: help => 'Course_Add_Student',
1.213 raeburn 3098: action => 'singlestudent',
3099: permission => $permission->{'cusr'},
3100: },
3101: { text => 'Drop Students',
3102: help => 'Course_Drop_Student',
3103: action => 'drop',
3104: permission => $permission->{'cusr'},
3105: });
3106: if (!exists($permission->{'cusr_section'})) {
3107: push(@courselinks,
1.242 bisitz 3108: { text => 'Automated Enrollment Manager',
1.228 raeburn 3109: help => 'Course_Automated_Enrollment',
1.208 raeburn 3110: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
3111: && $permission->{'cusr'}),
3112: url => '/adm/populate',
1.237 raeburn 3113: },
3114: { text => 'Configure User Self-enrollment',
3115: help => 'Course_Self_Enrollment',
3116: action => 'selfenroll',
3117: permission => $permission->{'cusr'},
3118: });
1.213 raeburn 3119: }
3120: push(@courselinks,
1.208 raeburn 3121: { text => 'Manage Course Groups',
3122: help => 'Course_Manage_Group',
3123: permission => $permission->{'grp_manage'},
3124: url => '/adm/coursegroups?refpage=cusr',
1.239 raeburn 3125: },
1.240 raeburn 3126: { text => 'View Change Logs',
3127: help => 'Course_User_Logs',
3128: action => 'changelogs',
3129: permission => $permission->{'cusr'},
3130: },
1.239 raeburn 3131: { text => 'View Log-in History',
3132: help => 'Course_User_Logins',
3133: action => 'logins',
3134: permission => $permission->{'cusr'},
1.213 raeburn 3135: });
1.208 raeburn 3136: push(@menu,@courselinks);
3137: }
1.190 raeburn 3138: my $menu_html = '';
3139: foreach my $menu_item (@menu) {
3140: next if (! $menu_item->{'permission'});
3141: $menu_html.='<p>';
1.234 raeburn 3142: if (exists($menu_item->{'help'})) {
3143: $menu_html.=
3144: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3145: }
1.190 raeburn 3146: $menu_html.='<font size="+1">';
3147: if (exists($menu_item->{'url'})) {
3148: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3149: } else {
3150: $menu_html.=
3151: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
3152: }
3153: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3154: $menu_html.='</p>';
3155: }
3156: return $menu_html;
3157: }
3158:
1.189 albertel 3159: sub restore_prev_selections {
3160: my %saveable_parameters = ('srchby' => 'scalar',
3161: 'srchin' => 'scalar',
3162: 'srchtype' => 'scalar',
3163: );
3164: &Apache::loncommon::store_settings('user','user_picker',
3165: \%saveable_parameters);
3166: &Apache::loncommon::restore_settings('user','user_picker',
3167: \%saveable_parameters);
3168: }
3169:
1.237 raeburn 3170: sub print_selfenroll_menu {
3171: my ($r,$context,$permission) = @_;
3172: my $formname = 'enrollstudent';
3173: my $nolink = 1;
3174: my ($row,$lt) = &get_selfenroll_titles();
3175: my $groupslist = &Apache::lonuserutils::get_groupslist();
3176: my $setsec_js =
3177: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
3178: my $output = '<script type="text/javascript">'."\n".
3179: $setsec_js."\n".
3180: '</script>'."\n".
3181: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n".
1.241 raeburn 3182: '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
1.237 raeburn 3183: &Apache::lonhtmlcommon::start_pick_box();
1.241 raeburn 3184: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3185: my $cnum = $env{'course.'.$env{'request.course.id'},'.num'};
1.237 raeburn 3186: if (ref($row) eq 'ARRAY') {
3187: foreach my $item (@{$row}) {
3188: my $title = $item;
3189: if (ref($lt) eq 'HASH') {
3190: $title = $lt->{$item};
3191: }
3192: $output .=
3193: &Apache::lonhtmlcommon::row_title($title,
3194: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
3195: if ($item eq 'types') {
3196: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 3197: my $showdomdesc = 1;
3198: my $includeempty = 1;
3199: my $num = 0;
3200: $output .= &Apache::loncommon::start_data_table().
3201: &Apache::loncommon::start_data_table_row()
3202: .'<td colspan="2"><span class="LC_nobreak"><label>'
3203: .&mt('Any user in any domain:')
3204: .' <input type="radio" name="selfenroll_all" value="1" ';
3205: if ($curr_types eq '*') {
3206: $output .= ' checked="checked" ';
3207: }
3208: $output .= '/>'.&mt('Yes').'</label> <input type="radio" name="selfenroll_all" value="0" ';
3209: if ($curr_types ne '*') {
3210: $output .= ' checked="checked" ';
3211: }
3212: $output .= '/>'.&mt('No').'</label></td>'
3213: .&Apache::loncommon::end_data_table_row();
3214: my %currdoms;
3215: if (($curr_types eq '') && ($env{'form.selfenroll_newdom'} eq '')) {
3216: $output .= &new_selfenroll_dom_row($cdom,'0');
3217: } elsif ($curr_types ne '*') {
3218: my @entries = split(/;/,$curr_types);
3219: if (@entries > 0) {
3220: foreach my $entry (@entries) {
3221: my ($currdom,$typestr) = split(/:/,$entry);
3222: $currdoms{$currdom} = 1;
3223: my $domdesc = &Apache::lonnet::domain($currdom);
3224: my @currinsttypes = split(/,/,$typestr);
3225: $output .= &Apache::loncommon::start_data_table_row()
3226: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
3227: .' '.$domdesc.' ('.$currdom.')'
3228: .'</b><input type="hidden" name="selfenroll_dom_'.$num
3229: .'" value="'.$currdom.'" /></span><br />'
3230: .'<span class="LC_nobreak"><label><input type="checkbox" '
3231: .'name="selfenroll_delete" value="'.$num.'" />'
3232: .&mt('Delete').'</label></span></td>';
3233: $output .= '<td valign="top">'.&mt('User types:').'<br />'
3234: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
3235: .&Apache::loncommon::end_data_table_row();
3236: $num ++;
3237: }
3238: }
3239: }
3240: if ($env{'form.selfenroll_newdom'} ne '') {
3241: if (!defined($currdoms{$env{'form.selfenroll_newdom'}})) {
3242: $output .= &new_selfenroll_dom_row($env{'form.selfenroll_newdom'},$num);
3243: $num ++;
3244: }
3245: }
3246: my $add_domtitle = &mt('Additional domain:');
3247: if ($curr_types eq '*') {
1.244 ! bisitz 3248: $add_domtitle = &mt('Specific domain:');
1.241 raeburn 3249: } elsif ($curr_types eq '') {
3250: $add_domtitle = &mt('Other domain:');
3251: }
3252: $output .= &Apache::loncommon::start_data_table_row()
3253: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
3254: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
3255: $includeempty,$showdomdesc)
3256: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
3257: .'</td>'.&Apache::loncommon::end_data_table_row()
3258: .&Apache::loncommon::end_data_table();
1.237 raeburn 3259: } elsif ($item eq 'registered') {
3260: my ($regon,$regoff);
3261: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
3262: $regon = ' checked="checked" ';
3263: $regoff = ' ';
3264: } else {
3265: $regon = ' ';
3266: $regoff = ' checked="checked" ';
3267: }
3268: $output .= '<label>'.
1.244 ! bisitz 3269: '<input type="radio" name="registered" value="1"'.$regon.'/>'.
! 3270: &mt('Yes').'</label> <label>'.
1.237 raeburn 3271: '<input type="radio" name="registered" value="0"'.$regoff.'/>'.
1.244 ! bisitz 3272: &mt('No').'</label>';
1.237 raeburn 3273: } elsif ($item eq 'enroll_dates') {
3274: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
3275: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
3276: if ($starttime eq '') {
3277: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3278: }
3279: if ($endtime eq '') {
3280: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3281: }
3282: my $startform =
3283: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
3284: undef,undef,undef,undef,undef,undef,undef,$nolink);
3285: my $endform =
3286: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
3287: undef,undef,undef,undef,undef,undef,undef,$nolink);
3288: $output .= &selfenroll_date_forms($startform,$endform);
3289: } elsif ($item eq 'access_dates') {
3290: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
3291: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
3292: if ($starttime eq '') {
3293: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3294: }
3295: if ($endtime eq '') {
3296: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3297: }
3298: my $startform =
3299: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
3300: undef,undef,undef,undef,undef,undef,undef,$nolink);
3301: my $endform =
3302: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
3303: undef,undef,undef,undef,undef,undef,undef,$nolink);
3304: $output .= &selfenroll_date_forms($startform,$endform);
3305: } elsif ($item eq 'section') {
3306: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
3307: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3308: my $newsecval;
3309: if ($currsec ne 'none' && $currsec ne '') {
3310: if (!defined($sections_count{$currsec})) {
3311: $newsecval = $currsec;
3312: }
3313: }
3314: my $sections_select =
3315: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
3316: $output .= '<table class="LC_createuser">'."\n".
3317: '<tr class="LC_section_row">'."\n".
3318: '<td align="center">'.&mt('Existing sections')."\n".
3319: '<br />'.$sections_select.'</td><td align="center">'.
3320: &mt('New section').'<br />'."\n".
3321: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
3322: '<input type="hidden" name="sections" value="" />'."\n".
3323: '<input type="hidden" name="state" value="done" />'."\n".
3324: '</td></tr></table>'."\n";
3325: }
3326: $output .= &Apache::lonhtmlcommon::row_closure(1);
3327: }
3328: }
3329: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 3330: '<br /><input type="button" name="selfenrollconf" value="'
3331: .&mt('Save changes').'" onclick="setSections(this.form);" />'
3332: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 3333: $r->print($output);
3334: return;
3335: }
3336:
1.241 raeburn 3337: sub new_selfenroll_dom_row {
3338: my ($newdom,$num) = @_;
3339: my $domdesc = &Apache::lonnet::domain($newdom);
3340: my $output;
3341: if ($domdesc ne '') {
3342: $output .= &Apache::loncommon::start_data_table_row()
3343: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
3344: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
3345: .'" value="'.$newdom.'" /></span></td>';
3346: my @currinsttypes;
3347: $output .= '<td>'.&mt('User types:').'<br />'
3348: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
3349: .&Apache::loncommon::end_data_table_row();
3350: }
3351: return $output;
3352: }
3353:
3354: sub selfenroll_inst_types {
3355: my ($num,$currdom,$currinsttypes) = @_;
3356: my $output;
3357: my $numinrow = 4;
3358: my $count = 0;
3359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
3360: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
3361: $output .= '<table><tr>';
3362: foreach my $type (@{$types}) {
3363: if (($count > 0) && ($count%$numinrow == 0)) {
3364: $output .= '</tr><tr>';
3365: }
3366: if (defined($usertypes->{$type})) {
3367: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
3368: $type.'" ';
3369: if (ref($currinsttypes) eq 'ARRAY') {
3370: if (@{$currinsttypes} > 0) {
3371: if (grep(/^\Q$type\E$/,@{$currinsttypes})) {
3372: $output .= 'checked="checked"';
3373: }
3374: }
3375: }
3376: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
3377: }
3378: $count ++;
3379: }
3380: if (($count > 0) && ($count%$numinrow == 0)) {
3381: $output .= '</tr><tr>';
3382: }
3383: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="other" ';
3384: if (ref($currinsttypes) eq 'ARRAY') {
3385: if (@{$currinsttypes} > 0) {
3386: if (grep(/^other$/,@{$currinsttypes})) {
3387: $output .= 'checked="checked" ';
3388: }
3389: }
3390: }
3391: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
3392: }
3393: return $output;
3394: }
3395:
1.237 raeburn 3396: sub selfenroll_date_forms {
3397: my ($startform,$endform) = @_;
3398: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 ! bisitz 3399: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 3400: 'LC_oddrow_value')."\n".
3401: $startform."\n".
3402: &Apache::lonhtmlcommon::row_closure(1).
1.244 ! bisitz 3403: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 3404: 'LC_oddrow_value')."\n".
3405: $endform."\n".
3406: &Apache::lonhtmlcommon::row_closure(1).
3407: &Apache::lonhtmlcommon::end_pick_box();
3408: return $output;
3409: }
3410:
1.239 raeburn 3411: sub print_userchangelogs_display {
3412: my ($r,$context,$permission) = @_;
3413: my $formname = 'roleslog';
3414: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3415: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3416: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
3417: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
3418:
3419: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
3420: my %saveable_parameters = ('show' => 'scalar',);
3421: &Apache::loncommon::store_course_settings('roles_log',
3422: \%saveable_parameters);
3423: &Apache::loncommon::restore_course_settings('roles_log',
3424: \%saveable_parameters);
3425: # set defaults
3426: my $now = time();
3427: my $defstart = $now - (7*24*3600); #7 days ago
3428: my %defaults = (
3429: page => '1',
3430: show => '10',
3431: role => 'any',
3432: chgcontext => 'any',
3433: rolelog_start_date => $defstart,
3434: rolelog_end_date => $now,
3435: );
3436: my $more_records = 0;
3437:
3438: # set current
3439: my %curr;
3440: foreach my $item ('show','page','role','chgcontext') {
3441: $curr{$item} = $env{'form.'.$item};
3442: }
3443: my ($startdate,$enddate) =
3444: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
3445: $curr{'rolelog_start_date'} = $startdate;
3446: $curr{'rolelog_end_date'} = $enddate;
3447: foreach my $key (keys(%defaults)) {
3448: if ($curr{$key} eq '') {
3449: $curr{$key} = $defaults{$key};
3450: }
3451: }
3452: my (%whodunit,%changed);
3453: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr));
3454: my $showntablehdr = 0;
3455: my $tablehdr = &Apache::loncommon::start_data_table().
3456: &Apache::loncommon::start_data_table_header_row().
3457: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
3458: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
3459: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
3460: &Apache::loncommon::end_data_table_header_row();
3461: my ($minshown,$maxshown);
3462: my $minshown = 1;
3463: my $count = 0;
3464: if ($curr{'show'} ne &mt('all')) {
3465: $maxshown = $curr{'page'} * $curr{'show'};
3466: if ($curr{'page'} > 1) {
3467: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
3468: }
3469: }
3470: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
3471: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
3472: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
3473: if ($curr{'show'} ne &mt('all')) {
3474: if ($count >= $curr{'page'} * $curr{'show'}) {
3475: $more_records = 1;
3476: last;
3477: }
3478: }
3479: if ($curr{'role'} ne 'any') {
3480: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
3481: }
3482: if ($curr{'chgcontext'} ne 'any') {
3483: if ($curr{'chgcontext'} eq 'selfenroll') {
3484: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
3485: } else {
3486: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
3487: }
3488: }
3489: $count ++;
3490: next if ($count < $minshown);
3491: if (!$showntablehdr) {
3492: $r->print($tablehdr);
3493: $showntablehdr = 1;
3494: }
3495: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
3496: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
3497: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
3498: }
3499: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
3500: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
3501: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
3502: }
3503: my $sec = $roleslog{$id}{'logentry'}{'section'};
3504: if ($sec eq '') {
3505: $sec = &mt('None');
3506: }
3507: my ($rolestart,$roleend);
3508: if ($roleslog{$id}{'delflag'}) {
3509: $rolestart = &mt('deleted');
3510: $roleend = &mt('deleted');
3511: } else {
3512: $rolestart = $roleslog{$id}{'logentry'}{'start'};
3513: $roleend = $roleslog{$id}{'logentry'}{'end'};
3514: if ($rolestart eq '' || $rolestart == 0) {
3515: $rolestart = &mt('No start date');
3516: } else {
3517: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
3518: }
3519: if ($roleend eq '' || $roleend == 0) {
3520: $roleend = &mt('No end date');
3521: } else {
3522: $roleend = &Apache::lonlocal::locallocaltime($roleend);
3523: }
3524: }
3525: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
3526: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
3527: $chgcontext = 'selfenroll';
3528: }
3529: my %lt = &rolechg_contexts();
3530: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
3531: $chgcontext = $lt{$chgcontext};
3532: }
3533: $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td><td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td><td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td><td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'}).'</td><td>'.$sec.'</td><td>'.$chgcontext.'</td><td>'.$rolestart.'</td><td>'.$roleend.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
3534: }
3535: if ($showntablehdr) {
3536: $r->print(&Apache::loncommon::end_data_table().'<br />');
3537: if (($curr{'page'} > 1) || ($more_records)) {
3538: $r->print('<table><tr>');
3539: if ($curr{'page'} > 1) {
3540: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
3541: }
3542: if ($more_records) {
3543: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
3544: }
3545: $r->print('</tr></table>');
3546: $r->print(<<"ENDSCRIPT");
3547: <script type="text/javascript">
3548: function chgPage(caller) {
3549: if (caller == 'previous') {
3550: document.$formname.page.value --;
3551: }
3552: if (caller == 'next') {
3553: document.$formname.page.value ++;
3554: }
3555: document.$formname.submit();
3556: return;
3557: }
3558: </script>
3559: ENDSCRIPT
3560: }
3561: } else {
3562: $r->print(&mt('There are no records to display'));
3563: }
3564: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
3565: '<input type="hidden" name="action" value="changelogs" /></form>');
3566: return;
3567: }
3568:
3569: sub role_display_filter {
3570: my ($formname,$cdom,$cnum,$curr) = @_;
3571: my $context = 'course';
3572: my $nolink = 1;
3573: my $output = '<table><tr><td valign="top">'.
3574: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
3575: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
3576: (&mt('all'),5,10,20,50,100,1000,10000)).
3577: '</td><td> </td>';
3578: my $startform =
3579: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
3580: $curr->{'rolelog_start_date'},undef,
3581: undef,undef,undef,undef,undef,undef,$nolink);
3582: my $endform =
3583: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
3584: $curr->{'rolelog_end_date'},undef,
3585: undef,undef,undef,undef,undef,undef,$nolink);
3586: my %lt = &rolechg_contexts();
3587: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
3588: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
3589: $endform.'</td></tr></table></td><td> </td>'.
3590: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
3591: '<select name="role"><option value="any"';
3592: if ($curr->{'role'} eq 'any') {
3593: $output .= ' selected="selected"';
3594: }
3595: $output .= '>'.&mt('Any').'</option>'."\n";
3596: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
3597: foreach my $role (@roles) {
3598: my $plrole;
3599: if ($role eq 'cr') {
3600: $plrole = &mt('Custom Role');
3601: } else {
3602: $plrole=&Apache::lonnet::plaintext($role);
3603: }
3604: my $selstr = '';
3605: if ($role eq $curr->{'role'}) {
3606: $selstr = ' selected="selected"';
3607: }
3608: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
3609: }
3610: $output .= '</select></td><td> </td><td valign="top"><b>'.
3611: &mt('Context:').'</b><br /><select name="chgcontext">';
3612: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
3613: my $selstr = '';
3614: if ($curr->{'chgcontext'} eq $chgtype) {
3615: $output .= $selstr = ' selected="selected"';
3616: }
3617: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
3618: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
3619: }
3620: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
3621: }
3622: $output .= '</select></td><td> </td><td valign="middle"><input type="submit" value="'.
3623: &mt('Update Display').'" /></tr></table><hr noshade><br />';
3624: return $output;
3625: }
3626:
3627: sub rolechg_contexts {
3628: my %lt = &Apache::lonlocal::texthash (
3629: any => 'Any',
3630: auto => 'Automated enrollment',
3631: updatenow => 'Roster Update',
3632: createcourse => 'Course Creation',
3633: course => 'User Management in course',
3634: domain => 'User Management in domain',
3635: selfenroll => 'Self-enrolled',
3636: );
3637: return %lt;
3638: }
3639:
1.27 matthew 3640: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 3641: sub user_search_result {
1.221 raeburn 3642: my ($context,$srch) = @_;
1.160 raeburn 3643: my %allhomes;
3644: my %inst_matches;
3645: my %srch_results;
1.181 raeburn 3646: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 3647: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 3648: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 3649: $response = &mt('Invalid search.');
3650: }
3651: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
3652: $response = &mt('Invalid search.');
3653: }
1.177 raeburn 3654: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 3655: $response = &mt('Invalid search.');
3656: }
3657: if ($srch->{'srchterm'} eq '') {
3658: $response = &mt('You must enter a search term.');
3659: }
1.183 raeburn 3660: if ($srch->{'srchterm'} =~ /^\s+$/) {
3661: $response = &mt('Your search term must contain more than just spaces.');
3662: }
1.160 raeburn 3663: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
3664: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 3665: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 3666: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
3667: }
3668: }
3669: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
3670: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 3671: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 3672: my $unamecheck = $srch->{'srchterm'};
3673: if ($srch->{'srchtype'} eq 'contains') {
3674: if ($unamecheck !~ /^\w/) {
3675: $unamecheck = 'a'.$unamecheck;
3676: }
3677: }
3678: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 3679: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
3680: }
1.160 raeburn 3681: }
3682: }
1.180 raeburn 3683: if ($response ne '') {
3684: $response = '<span class="LC_warning">'.$response.'</span>';
3685: }
1.160 raeburn 3686: if ($srch->{'srchin'} eq 'instd') {
3687: my $instd_chk = &directorysrch_check($srch);
3688: if ($instd_chk ne 'ok') {
1.180 raeburn 3689: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
3690: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 3691: }
3692: }
3693: if ($response ne '') {
1.180 raeburn 3694: return ($currstate,$response);
1.160 raeburn 3695: }
3696: if ($srch->{'srchby'} eq 'uname') {
3697: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
3698: if ($env{'form.forcenew'}) {
3699: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
3700: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3701: if ($uhome eq 'no_host') {
3702: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 3703: my $showdom = &display_domain_info($env{'request.role.domain'});
3704: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 3705: } else {
1.179 raeburn 3706: $currstate = 'modify';
1.160 raeburn 3707: }
3708: } else {
1.179 raeburn 3709: $currstate = 'modify';
1.160 raeburn 3710: }
3711: } else {
3712: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 3713: if ($srch->{'srchtype'} eq 'exact') {
3714: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3715: if ($uhome eq 'no_host') {
1.179 raeburn 3716: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3717: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 3718: } else {
1.179 raeburn 3719: $currstate = 'modify';
1.162 raeburn 3720: }
3721: } else {
3722: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3723: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3724: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3725: }
3726: } else {
1.167 albertel 3727: my $courseusers = &get_courseusers();
1.162 raeburn 3728: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 3729: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 3730: $currstate = 'modify';
1.162 raeburn 3731: } else {
1.179 raeburn 3732: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3733: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 3734: }
1.160 raeburn 3735: } else {
1.167 albertel 3736: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 3737: my ($cuname,$cudomain) = split(/:/,$user);
3738: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 3739: my $matched = 0;
3740: if ($srch->{'srchtype'} eq 'begins') {
3741: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
3742: $matched = 1;
3743: }
3744: } else {
3745: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
3746: $matched = 1;
3747: }
3748: }
3749: if ($matched) {
1.167 albertel 3750: $srch_results{$user} =
3751: {&Apache::lonnet::get('environment',
3752: ['firstname',
3753: 'lastname',
1.194 albertel 3754: 'permanentemail'],
3755: $cudomain,$cuname)};
1.162 raeburn 3756: }
3757: }
3758: }
1.179 raeburn 3759: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3760: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3761: }
3762: }
3763: }
3764: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3765: $currstate = 'query';
1.160 raeburn 3766: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3767: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3768: if ($dirsrchres eq 'ok') {
3769: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3770: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 3771: } else {
3772: my $showdom = &display_domain_info($srch->{'srchdomain'});
3773: $response = '<span class="LC_warning">'.
3774: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3775: '</span><br />'.
3776: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3777: '<br /><br />';
3778: }
1.160 raeburn 3779: }
3780: } else {
3781: if ($srch->{'srchin'} eq 'dom') {
3782: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3783: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3784: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3785: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 3786: my $courseusers = &get_courseusers();
3787: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 3788: my ($uname,$udom) = split(/:/,$user);
3789: my %names = &Apache::loncommon::getnames($uname,$udom);
3790: my %emails = &Apache::loncommon::getemails($uname,$udom);
3791: if ($srch->{'srchby'} eq 'lastname') {
3792: if ((($srch->{'srchtype'} eq 'exact') &&
3793: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 3794: (($srch->{'srchtype'} eq 'begins') &&
3795: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 3796: (($srch->{'srchtype'} eq 'contains') &&
3797: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
3798: $srch_results{$user} = {firstname => $names{'firstname'},
3799: lastname => $names{'lastname'},
3800: permanentemail => $emails{'permanentemail'},
3801: };
3802: }
3803: } elsif ($srch->{'srchby'} eq 'lastfirst') {
3804: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 3805: $srchlast =~ s/\s+$//;
3806: $srchfirst =~ s/^\s+//;
1.160 raeburn 3807: if ($srch->{'srchtype'} eq 'exact') {
3808: if (($names{'lastname'} eq $srchlast) &&
3809: ($names{'firstname'} eq $srchfirst)) {
3810: $srch_results{$user} = {firstname => $names{'firstname'},
3811: lastname => $names{'lastname'},
3812: permanentemail => $emails{'permanentemail'},
3813:
3814: };
3815: }
1.177 raeburn 3816: } elsif ($srch->{'srchtype'} eq 'begins') {
3817: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
3818: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
3819: $srch_results{$user} = {firstname => $names{'firstname'},
3820: lastname => $names{'lastname'},
3821: permanentemail => $emails{'permanentemail'},
3822: };
3823: }
3824: } else {
1.160 raeburn 3825: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
3826: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
3827: $srch_results{$user} = {firstname => $names{'firstname'},
3828: lastname => $names{'lastname'},
3829: permanentemail => $emails{'permanentemail'},
3830: };
3831: }
3832: }
3833: }
3834: }
1.179 raeburn 3835: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3836: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3837: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3838: $currstate = 'query';
1.160 raeburn 3839: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3840: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3841: if ($dirsrchres eq 'ok') {
3842: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3843: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 3844: } else {
3845: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
3846: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3847: '</span><br />'.
3848: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3849: '<br /><br />';
3850: }
1.160 raeburn 3851: }
3852: }
1.179 raeburn 3853: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 3854: }
3855:
3856: sub directorysrch_check {
3857: my ($srch) = @_;
3858: my $can_search = 0;
3859: my $response;
3860: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
3861: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 3862: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 3863: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
3864: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 3865: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 3866: }
3867: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
3868: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 3869: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 3870: }
3871: my @usertypes = split(/:/,$env{'environment.inststatus'});
3872: if (!@usertypes) {
3873: push(@usertypes,'default');
3874: }
3875: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
3876: foreach my $type (@usertypes) {
3877: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
3878: $can_search = 1;
3879: last;
3880: }
3881: }
3882: }
3883: if (!$can_search) {
3884: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
3885: my @longtypes;
3886: foreach my $item (@usertypes) {
1.229 raeburn 3887: if (defined($insttypes->{$item})) {
3888: push (@longtypes,$insttypes->{$item});
3889: } elsif ($item eq 'default') {
3890: push (@longtypes,&mt('other'));
3891: }
1.160 raeburn 3892: }
3893: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 3894: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 3895: }
1.160 raeburn 3896: } else {
3897: $can_search = 1;
3898: }
3899: } else {
1.180 raeburn 3900: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 3901: }
3902: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 3903: uname => 'username',
1.160 raeburn 3904: lastfirst => 'last name, first name',
1.167 albertel 3905: lastname => 'last name',
1.172 raeburn 3906: contains => 'contains',
1.178 raeburn 3907: exact => 'as exact match to',
3908: begins => 'begins with',
1.160 raeburn 3909: );
3910: if ($can_search) {
3911: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
3912: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 3913: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 3914: }
3915: } else {
1.180 raeburn 3916: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 3917: }
3918: }
3919: if ($can_search) {
1.178 raeburn 3920: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
3921: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
3922: return 'ok';
3923: } else {
1.180 raeburn 3924: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3925: }
3926: } else {
3927: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
3928: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
3929: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
3930: return 'ok';
3931: } else {
1.180 raeburn 3932: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3933: }
1.160 raeburn 3934: }
3935: }
3936: }
3937:
3938: sub get_courseusers {
3939: my %advhash;
1.167 albertel 3940: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 3941: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
3942: foreach my $role (sort(keys(%coursepersonnel))) {
3943: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 3944: if (!exists($classlist->{$user})) {
3945: $classlist->{$user} = [];
3946: }
1.160 raeburn 3947: }
3948: }
1.167 albertel 3949: return $classlist;
1.160 raeburn 3950: }
3951:
3952: sub build_search_response {
1.221 raeburn 3953: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 3954: my ($currstate,$response,$forcenewuser);
1.160 raeburn 3955: my %names = (
3956: 'uname' => 'username',
3957: 'lastname' => 'last name',
3958: 'lastfirst' => 'last name, first name',
3959: 'crs' => 'this course',
1.180 raeburn 3960: 'dom' => 'LON-CAPA domain: ',
3961: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 3962: );
3963:
3964: my %single = (
1.180 raeburn 3965: begins => 'A match',
1.160 raeburn 3966: contains => 'A match',
1.180 raeburn 3967: exact => 'An exact match',
1.160 raeburn 3968: );
3969: my %nomatch = (
1.180 raeburn 3970: begins => 'No match',
1.160 raeburn 3971: contains => 'No match',
1.180 raeburn 3972: exact => 'No exact match',
1.160 raeburn 3973: );
3974: if (keys(%srch_results) > 1) {
1.179 raeburn 3975: $currstate = 'select';
1.160 raeburn 3976: } else {
3977: if (keys(%srch_results) == 1) {
1.179 raeburn 3978: $currstate = 'modify';
1.180 raeburn 3979: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
3980: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3981: $response .= &display_domain_info($srch->{'srchdomain'});
3982: }
1.160 raeburn 3983: } else {
1.180 raeburn 3984: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
3985: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3986: $response .= &display_domain_info($srch->{'srchdomain'});
3987: }
3988: $response .= '</span>';
1.160 raeburn 3989: if ($srch->{'srchin'} ne 'alc') {
3990: $forcenewuser = 1;
3991: my $cansrchinst = 0;
3992: if ($srch->{'srchdomain'}) {
3993: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
3994: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3995: if ($domconfig{'directorysrch'}{'available'}) {
3996: $cansrchinst = 1;
3997: }
3998: }
3999: }
1.180 raeburn 4000: if ((($srch->{'srchby'} eq 'lastfirst') ||
4001: ($srch->{'srchby'} eq 'lastname')) &&
4002: ($srch->{'srchin'} eq 'dom')) {
4003: if ($cansrchinst) {
4004: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 4005: }
4006: }
1.180 raeburn 4007: if ($srch->{'srchin'} eq 'crs') {
4008: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
4009: }
4010: }
4011: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 4012: my $cancreate =
4013: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
4014: if ($cancreate) {
4015: my $showdom = &display_domain_info($env{'request.role.domain'});
1.229 raeburn 4016: $response .= '<br /><br />'.&mt("<b>To add a new user</b> (you can only create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>):",$env{'request.role.domain'}).'<ul><li>'.&mt("Set 'Domain/institution to search' to: <span class=\"LC_cusr_emph\">[_1]</span>",$showdom).'<li>'.&mt("Set 'Search criteria' to: <span class=\"LC_cusr_emph\">'username is ...... in selected LON-CAPA domain'").'</span></li><li>'.&mt('Provide the proposed username').'</li><li>'.&mt('Search').'</li></ul><br />';
1.221 raeburn 4017: } else {
4018: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
4019: $response .= '<br /><br />'.&mt("You are not authorized to create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>.",$env{'request.role.domain'}).'<br />'.&mt('Contact the <a[_1]>helpdesk</a> if you need to create a new user.',$helplink).'<br /><br />';
4020: }
1.160 raeburn 4021: }
4022: }
4023: }
1.179 raeburn 4024: return ($currstate,$response,$forcenewuser);
1.160 raeburn 4025: }
4026:
1.180 raeburn 4027: sub display_domain_info {
4028: my ($dom) = @_;
4029: my $output = $dom;
4030: if ($dom ne '') {
4031: my $domdesc = &Apache::lonnet::domain($dom,'description');
4032: if ($domdesc ne '') {
4033: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
4034: }
4035: }
4036: return $output;
4037: }
4038:
1.160 raeburn 4039: sub crumb_utilities {
4040: my %elements = (
4041: crtuser => {
4042: srchterm => 'text',
1.172 raeburn 4043: srchin => 'selectbox',
1.160 raeburn 4044: srchby => 'selectbox',
4045: srchtype => 'selectbox',
4046: srchdomain => 'selectbox',
4047: },
1.207 raeburn 4048: crtusername => {
4049: srchterm => 'text',
4050: srchdomain => 'selectbox',
4051: },
1.160 raeburn 4052: docustom => {
4053: rolename => 'selectbox',
4054: newrolename => 'textbox',
4055: },
1.179 raeburn 4056: studentform => {
4057: srchterm => 'text',
4058: srchin => 'selectbox',
4059: srchby => 'selectbox',
4060: srchtype => 'selectbox',
4061: srchdomain => 'selectbox',
4062: },
1.160 raeburn 4063: );
4064:
4065: my $jsback .= qq|
4066: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 4067: if (typeof prevphase == 'undefined') {
4068: formname.phase.value = '';
4069: }
4070: else {
4071: formname.phase.value = prevphase;
4072: }
4073: if (typeof prevstate == 'undefined') {
4074: formname.currstate.value = '';
4075: }
4076: else {
4077: formname.currstate.value = prevstate;
4078: }
1.160 raeburn 4079: formname.submit();
4080: }
4081: |;
4082: return ($jsback,\%elements);
4083: }
4084:
1.26 matthew 4085: sub course_level_table {
1.89 raeburn 4086: my (%inccourses) = @_;
1.26 matthew 4087: my $table = '';
1.62 www 4088: # Custom Roles?
4089:
1.190 raeburn 4090: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 4091: my %lt=&Apache::lonlocal::texthash(
4092: 'exs' => "Existing sections",
4093: 'new' => "Define new section",
4094: 'ssd' => "Set Start Date",
4095: 'sed' => "Set End Date",
1.131 raeburn 4096: 'crl' => "Course Level",
1.89 raeburn 4097: 'act' => "Activate",
4098: 'rol' => "Role",
4099: 'ext' => "Extent",
1.113 raeburn 4100: 'grs' => "Section",
1.89 raeburn 4101: 'sta' => "Start",
4102: 'end' => "End"
4103: );
1.62 www 4104:
1.135 raeburn 4105: foreach my $protectedcourse (sort( keys(%inccourses))) {
4106: my $thiscourse=$protectedcourse;
1.26 matthew 4107: $thiscourse=~s:_:/:g;
4108: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
4109: my $area=$coursedata{'description'};
1.119 raeburn 4110: my $type=$coursedata{'type'};
1.135 raeburn 4111: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 4112: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 4113: my %sections_count;
1.101 albertel 4114: if (defined($env{'request.course.id'})) {
4115: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 4116: %sections_count =
4117: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 4118: }
4119: }
1.213 raeburn 4120: my @roles = &Apache::lonuserutils::roles_by_context('course');
4121: foreach my $role (@roles) {
1.221 raeburn 4122: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 4123: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 4124: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4125: $plrole,\%sections_count,\%lt);
4126: } elsif ($env{'request.course.sec'} ne '') {
4127: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
4128: $env{'request.course.sec'})) {
4129: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4130: $plrole,\%sections_count,\%lt);
1.26 matthew 4131: }
4132: }
4133: }
1.221 raeburn 4134: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
4135: foreach my $cust (sort keys %customroles) {
4136: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
4137: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4138: $cust,\%sections_count,\%lt);
4139: }
1.62 www 4140: }
1.26 matthew 4141: }
4142: return '' if ($table eq ''); # return nothing if there is nothing
4143: # in the table
1.188 raeburn 4144: my $result;
4145: if (!$env{'request.course.id'}) {
4146: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
4147: }
4148: $result .=
1.136 raeburn 4149: &Apache::loncommon::start_data_table().
4150: &Apache::loncommon::start_data_table_header_row().
4151: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
4152: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
4153: &Apache::loncommon::end_data_table_header_row().
4154: $table.
4155: &Apache::loncommon::end_data_table();
1.26 matthew 4156: return $result;
4157: }
1.88 raeburn 4158:
1.221 raeburn 4159: sub course_level_row {
4160: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 4161: my $row = &Apache::loncommon::start_data_table_row().
4162: ' <td><input type="checkbox" name="act_'.
4163: $protectedcourse.'_'.$role.'" /></td>'."\n".
4164: ' <td>'.$plrole.'</td>'."\n".
4165: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 4166: if ($role eq 'cc') {
1.222 raeburn 4167: $row .= '<td> </td>';
1.221 raeburn 4168: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 4169: $row .= ' <td><input type="hidden" value="'.
4170: $env{'request.course.sec'}.'" '.
4171: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
4172: $env{'request.course.sec'}.'</td>';
1.221 raeburn 4173: } else {
4174: if (ref($sections_count) eq 'HASH') {
4175: my $currsec =
4176: &Apache::lonuserutils::course_sections($sections_count,
4177: $protectedcourse.'_'.$role);
1.222 raeburn 4178: $row .= '<td><table class="LC_createuser">'."\n".
4179: '<tr class="LC_section_row">'."\n".
4180: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
4181: $currsec.'</td>'."\n".
4182: ' <td> </td>'."\n".
4183: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 4184: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
4185: '" value="" />'.
4186: '<input type="hidden" '.
4187: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 4188: '</tr></table></td>'."\n";
1.221 raeburn 4189: } else {
1.222 raeburn 4190: $row .= '<td><input type="text" size="10" '.
4191: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 4192: }
4193: }
1.222 raeburn 4194: $row .= <<ENDTIMEENTRY;
4195: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 4196: <a href=
4197: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
1.222 raeburn 4198: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 4199: <a href=
4200: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
4201: ENDTIMEENTRY
1.222 raeburn 4202: $row .= &Apache::loncommon::end_data_table_row();
4203: return $row;
1.221 raeburn 4204: }
4205:
1.88 raeburn 4206: sub course_level_dc {
4207: my ($dcdom) = @_;
1.190 raeburn 4208: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 4209: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 4210: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
4211: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 4212: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 4213: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 4214: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
4215: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 4216: my %lt=&Apache::lonlocal::texthash(
4217: 'rol' => "Role",
1.113 raeburn 4218: 'grs' => "Section",
1.88 raeburn 4219: 'exs' => "Existing sections",
4220: 'new' => "Define new section",
4221: 'sta' => "Start",
4222: 'end' => "End",
4223: 'ssd' => "Set Start Date",
4224: 'sed' => "Set End Date"
4225: );
1.131 raeburn 4226: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 4227: &Apache::loncommon::start_data_table().
4228: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 4229: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 4230: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 4231: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 4232: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 4233: '<td><select name="role">'."\n";
1.213 raeburn 4234: foreach my $role (@roles) {
1.135 raeburn 4235: my $plrole=&Apache::lonnet::plaintext($role);
4236: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 4237: }
4238: if ( keys %customroles > 0) {
1.135 raeburn 4239: foreach my $cust (sort keys %customroles) {
1.101 albertel 4240: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 4241: '_'.$env{'user.name'}.'_'.$cust;
4242: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 4243: }
4244: }
4245: $otheritems .= '</select></td><td>'.
4246: '<table border="0" cellspacing="0" cellpadding="0">'.
4247: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
4248: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
4249: '<td> </td>'.
4250: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 4251: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 4252: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 4253: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 4254: '</tr></table></td>';
4255: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 4256: <td><input type="hidden" name="start" value='' />
1.88 raeburn 4257: <a href=
4258: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 4259: <td><input type="hidden" name="end" value='' />
1.88 raeburn 4260: <a href=
4261: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
4262: ENDTIMEENTRY
1.136 raeburn 4263: $otheritems .= &Apache::loncommon::end_data_table_row().
4264: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 4265: return $cb_jscript.$header.$hiddenitems.$otheritems;
4266: }
4267:
1.237 raeburn 4268: sub update_selfenroll_config {
1.241 raeburn 4269: my ($r,$context,$permission) = @_;
1.237 raeburn 4270: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 4271: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 4272: my (%changes,%warning);
4273: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4274: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 4275: my $curr_types;
1.237 raeburn 4276: if (ref($row) eq 'ARRAY') {
4277: foreach my $item (@{$row}) {
4278: if ($item eq 'enroll_dates') {
4279: my (%currenrolldate,%newenrolldate);
4280: foreach my $type ('start','end') {
4281: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
4282: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
4283: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
4284: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
4285: }
4286: }
4287: } elsif ($item eq 'access_dates') {
4288: my (%currdate,%newdate);
4289: foreach my $type ('start','end') {
4290: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
4291: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
4292: if ($newdate{$type} ne $currdate{$type}) {
4293: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
4294: }
4295: }
1.241 raeburn 4296: } elsif ($item eq 'types') {
4297: $curr_types =
4298: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4299: if ($env{'form.selfenroll_all'}) {
4300: if ($curr_types ne '*') {
4301: $changes{'internal.selfenroll_types'} = '*';
4302: } else {
4303: next;
4304: }
4305: } elsif ($curr_types eq '') {
4306: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_0');
4307: if (@types > 0) {
4308: $changes{'internal.selfenroll_types'} = $env{'form.selfenroll_dom_0'}.':'.join(',',@types);
4309: }
4310: } else {
4311: my @entries = split(/;/,$curr_types);
4312: my $num = 0;
4313: my @latesttypes;
4314: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
4315: my $newnum = 0;
4316: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
4317: if (!grep(/^$j$/,@deletedoms)) {
4318: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
4319: @types = sort(@types);
4320: my $typestr = join(',',@types);
4321: $latesttypes[$newnum] = $env{'form.selfenroll_dom_'.$j}.':'.$typestr;
4322: $newnum ++;
4323: }
4324: }
4325: my $selfenroll_types = join(';',@latesttypes);
4326: if ($selfenroll_types ne $curr_types) {
4327: $changes{'internal.selfenroll_types'} = $selfenroll_types;
4328: }
4329: }
1.237 raeburn 4330: } else {
4331: my $curr_val =
4332: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4333: my $newval = $env{'form.selfenroll_'.$item};
4334: if ($item eq 'section') {
4335: $newval = $env{'form.sections'};
1.241 raeburn 4336: if (defined($curr_groups{$newval})) {
1.237 raeburn 4337: $newval = $curr_val;
4338: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
4339: } elsif ($newval eq 'all') {
4340: $newval = $curr_val;
4341: $warning{$item} = &mt("Section for self-enrolled users unchanged, as 'all' is a reserved section name.");
4342: }
4343: if ($newval eq '') {
4344: $newval = 'none';
4345: }
4346: }
4347: if ($newval ne $curr_val) {
4348: $changes{'internal.selfenroll_'.$item} = $newval;
4349: }
1.241 raeburn 4350: }
1.237 raeburn 4351: }
4352: if (keys(%warning) > 0) {
4353: foreach my $item (@{$row}) {
4354: if (exists($warning{$item})) {
4355: $r->print($warning{$item}.'<br />');
4356: }
4357: }
4358: }
4359: if (keys(%changes) > 0) {
4360: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
4361: if ($putresult eq 'ok') {
4362: if ((exists($changes{'internal.selfenroll_types'})) ||
4363: (exists($changes{'internal.selfenroll_start_date'})) ||
4364: (exists($changes{'internal.selfenroll_end_date'}))) {
4365: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
4366: $cnum,undef,undef,'Course');
4367: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
4368: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
4369: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
4370: if (exists($changes{'internal.'.$item})) {
4371: $crsinfo{$env{'request.course.id'}}{$item} =
4372: $changes{'internal.'.$item};
4373: }
4374: }
4375: my $crsputresult =
4376: &Apache::lonnet::courseidput($cdom,\%crsinfo,
4377: $chome,'notime');
4378: }
4379: }
4380: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
4381: foreach my $item (@{$row}) {
4382: my $title = $item;
4383: if (ref($lt) eq 'HASH') {
4384: $title = $lt->{$item};
4385: }
4386: if ($item eq 'enroll_dates') {
4387: foreach my $type ('start','end') {
4388: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
4389: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 ! bisitz 4390: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 4391: $title,$type,$newdate).'</li>');
4392: }
4393: }
4394: } elsif ($item eq 'access_dates') {
4395: foreach my $type ('start','end') {
4396: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
4397: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 ! bisitz 4398: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 4399: $title,$type,$newdate).'</li>');
4400: }
4401: }
4402: } else {
4403: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 4404: my $newval = $changes{'internal.selfenroll_'.$item};
4405: if ($item eq 'types') {
4406: if ($newval eq '') {
4407: $newval = &mt('None');
4408: } elsif ($newval eq '*') {
4409: $newval = &mt('Any user in any domain');
4410: }
4411: }
1.244 ! bisitz 4412: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 4413: }
4414: }
4415: }
4416: $r->print('</ul>');
4417: my %newenvhash;
4418: foreach my $key (keys(%changes)) {
4419: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
4420: }
1.238 raeburn 4421: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 4422: } else {
4423: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
4424: }
4425: } else {
4426: $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
4427: }
4428: } else {
4429: $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
4430: }
1.241 raeburn 4431: if ($env{'form.selfenroll_newdom'} ne '') {
4432: &print_selfenroll_menu($r,$context,$permission);
4433: }
1.237 raeburn 4434: return;
4435: }
4436:
4437: sub get_selfenroll_titles {
4438: my @row = ('types','registered','enroll_dates','access_dates','section');
4439: my %lt = &Apache::lonlocal::texthash (
4440: types => 'Users allowed to self-enroll in this course',
1.244 ! bisitz 4441: registered => 'Restrict self-enrollment to registered students',
1.237 raeburn 4442: enroll_dates => 'Dates self-enrollment available',
1.244 ! bisitz 4443: access_dates => 'Course access dates for self-enrolled users',
1.241 raeburn 4444: section => 'Section assigned to self-enrolled users',
1.237 raeburn 4445: );
4446: return (\@row,\%lt);
4447: }
4448:
1.27 matthew 4449: #---------------------------------------------- end functions for &phase_two
1.29 matthew 4450:
4451: #--------------------------------- functions for &phase_two and &phase_three
4452:
4453: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 4454:
4455: 1;
4456: __END__
1.2 www 4457:
4458:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>