Annotation of loncom/interface/loncreateuser.pm, revision 1.257
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.257 ! raeburn 4: # $Id: loncreateuser.pm,v 1.256 2008/07/16 12:06:28 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.252 raeburn 1399: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.257 ! raeburn 1400: my ($output,$showforceid,%userenv,%canmodify);
1.219 raeburn 1401: my @userinfo = ('firstname','middlename','lastname','generation',
1402: 'permanentemail','id');
1.252 raeburn 1403: my $rowcount = 0;
1404: my $editable = 0;
1.253 raeburn 1405: if (!$newuser) {
1.188 raeburn 1406: # Get the users information
1407: %userenv = &Apache::lonnet::get('environment',
1408: ['firstname','middlename','lastname','generation',
1409: 'permanentemail','id'],$ccdomain,$ccuname);
1.253 raeburn 1410: }
1.257 ! raeburn 1411: if (!$newuser) {
1.219 raeburn 1412: %canmodify =
1413: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 1414: \@userinfo,$rolesarray);
1.257 ! raeburn 1415: } elsif ($context eq 'selfcreate') {
! 1416: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
! 1417: $inst_results,$rolesarray);
1.188 raeburn 1418: }
1419: my %lt=&Apache::lonlocal::texthash(
1420: 'pd' => "Personal Data",
1421: 'firstname' => "First Name",
1422: 'middlename' => "Middle Name",
1423: 'lastname' => "Last Name",
1424: 'generation' => "Generation",
1425: 'permanentemail' => "Permanent e-mail address",
1426: 'id' => "ID/Student Number",
1427: 'lg' => "Login Data"
1428: );
1429: my %textboxsize = (
1430: firstname => '15',
1431: middlename => '15',
1432: lastname => '15',
1433: generation => '5',
1434: permanentemail => '25',
1435: id => '15',
1436: );
1437: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1438: $output = '<h3>'.$lt{'pd'}.'</h3>'.
1439: &Apache::lonhtmlcommon::start_pick_box();
1440: foreach my $item (@userinfo) {
1441: my $rowtitle = $lt{$item};
1.252 raeburn 1442: my $hiderow = 0;
1.188 raeburn 1443: if ($item eq 'generation') {
1444: $rowtitle = $genhelp.$rowtitle;
1445: }
1.252 raeburn 1446: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 1447: if ($newuser) {
1.210 raeburn 1448: if (ref($inst_results) eq 'HASH') {
1449: if ($inst_results->{$item} ne '') {
1.252 raeburn 1450: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 1451: } else {
1.252 raeburn 1452: if ($context eq 'selfcreate') {
1453: if ($canmodify{$item}) {
1454: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1455: $editable ++;
1456: } else {
1457: $hiderow = 1;
1458: }
1.253 raeburn 1459: } else {
1460: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1461: }
1.210 raeburn 1462: }
1.188 raeburn 1463: } else {
1.252 raeburn 1464: if ($context eq 'selfcreate') {
1465: if ($canmodify{$item}) {
1466: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1467: $editable ++;
1468: } else {
1469: $hiderow = 1;
1470: }
1.253 raeburn 1471: } else {
1472: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1473: }
1.188 raeburn 1474: }
1475: } else {
1.219 raeburn 1476: if ($canmodify{$item}) {
1.252 raeburn 1477: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 1478: } else {
1.252 raeburn 1479: $row .= $userenv{$item};
1.188 raeburn 1480: }
1.206 raeburn 1481: if ($item eq 'id') {
1.219 raeburn 1482: $showforceid = $canmodify{$item};
1483: }
1.188 raeburn 1484: }
1.252 raeburn 1485: $row .= &Apache::lonhtmlcommon::row_closure(1);
1486: if (!$hiderow) {
1487: $output .= $row;
1488: $rowcount ++;
1489: }
1.188 raeburn 1490: }
1491: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1492: if (wantarray) {
1.252 raeburn 1493: if ($context eq 'selfcreate') {
1494: return($output,$rowcount,$editable);
1495: } else {
1496: return ($output,$showforceid);
1497: }
1.206 raeburn 1498: } else {
1499: return $output;
1500: }
1.188 raeburn 1501: }
1502:
1.257 ! raeburn 1503: sub selfcreate_canmodify {
! 1504: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
! 1505: if (ref($inst_results) eq 'HASH') {
! 1506: my @inststatuses = &get_inststatuses($inst_results);
! 1507: if (@inststatuses == 0) {
! 1508: @inststatuses = ('default');
! 1509: }
! 1510: $rolesarray = \@inststatuses;
! 1511: }
! 1512: my %canmodify =
! 1513: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
! 1514: $rolesarray);
! 1515: return %canmodify;
! 1516: }
! 1517:
1.252 raeburn 1518: sub get_inststatuses {
1519: my ($insthashref) = @_;
1520: my @inststatuses = ();
1521: if (ref($insthashref) eq 'HASH') {
1522: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
1523: @inststatuses = @{$insthashref->{'inststatus'}};
1524: }
1525: }
1526: return @inststatuses;
1527: }
1528:
1.4 www 1529: # ================================================================= Phase Three
1.42 matthew 1530: sub update_user_data {
1.206 raeburn 1531: my ($r,$context) = @_;
1.101 albertel 1532: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1533: $env{'form.ccdomain'});
1.27 matthew 1534: # Error messages
1.188 raeburn 1535: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1536: my $end = '</span><br /><br />';
1537: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1538: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 1539: &mt('Return to previous page').'</a>'.
1540: &Apache::loncommon::end_page();
1541: my $now = time;
1.40 www 1542: my $title;
1.101 albertel 1543: if (exists($env{'form.makeuser'})) {
1.40 www 1544: $title='Set Privileges for New User';
1545: } else {
1546: $title='Modify User Privileges';
1547: }
1.213 raeburn 1548: my $newuser = 0;
1.160 raeburn 1549: my ($jsback,$elements) = &crumb_utilities();
1550: my $jscript = '<script type="text/javascript">'."\n".
1551: $jsback."\n".'</script>'."\n";
1.213 raeburn 1552: my %breadcrumb_text = &singleuser_breadcrumb();
1.233 raeburn 1553: my $args;
1554: if ($env{'form.popup'}) {
1555: $args->{'no_nav_bar'} = 1;
1556: } else {
1557: $args = undef;
1558: }
1559: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 1560: &Apache::lonhtmlcommon::add_breadcrumb
1561: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1562: text=>$breadcrumb_text{'search'},
1.160 raeburn 1563: faq=>282,bug=>'Instructor Interface',});
1564: if ($env{'form.prevphase'} eq 'userpicked') {
1565: &Apache::lonhtmlcommon::add_breadcrumb
1566: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1567: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1568: faq=>282,bug=>'Instructor Interface',});
1569: }
1570: &Apache::lonhtmlcommon::add_breadcrumb
1571: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 1572: text=>$breadcrumb_text{'modify'},
1.160 raeburn 1573: faq=>282,bug=>'Instructor Interface',},
1574: {href=>"/adm/createuser",
1575: text=>"Result",
1576: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 1577: my $helpitem = 'Course_Change_Privileges';
1578: if ($env{'form.action'} eq 'singlestudent') {
1579: $helpitem = 'Course_Add_Student';
1580: }
1581: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1582: $helpitem));
1.188 raeburn 1583: $r->print(&update_result_form($uhome));
1.27 matthew 1584: # Check Inputs
1.101 albertel 1585: if (! $env{'form.ccuname'} ) {
1.193 raeburn 1586: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 1587: return;
1588: }
1.138 albertel 1589: if ( $env{'form.ccuname'} ne
1590: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1591: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1592: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193 raeburn 1593: $end.$rtnlink);
1.27 matthew 1594: return;
1595: }
1.101 albertel 1596: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 1597: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 1598: return;
1599: }
1.138 albertel 1600: if ( $env{'form.ccdomain'} ne
1601: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1602: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1603: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193 raeburn 1604: $end.$rtnlink);
1.27 matthew 1605: return;
1606: }
1.219 raeburn 1607: if ($uhome eq 'no_host') {
1608: $newuser = 1;
1609: }
1.101 albertel 1610: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1611: # Modifying an existing user, so check the validity of the name
1612: if ($uhome eq 'no_host') {
1.73 sakharuk 1613: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1614: $env{'form.ccuname'}.&mt(' in domain ').
1615: $env{'form.ccdomain'}.'.');
1.29 matthew 1616: return;
1617: }
1618: }
1.27 matthew 1619: # Determine authentication method and password for the user being modified
1620: my $amode='';
1621: my $genpwd='';
1.101 albertel 1622: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1623: $amode='krb';
1.101 albertel 1624: $amode.=$env{'form.krbver'};
1625: $genpwd=$env{'form.krbarg'};
1626: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1627: $amode='internal';
1.101 albertel 1628: $genpwd=$env{'form.intarg'};
1629: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1630: $amode='unix';
1.101 albertel 1631: $genpwd=$env{'form.fsysarg'};
1632: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1633: $amode='localauth';
1.101 albertel 1634: $genpwd=$env{'form.locarg'};
1.27 matthew 1635: $genpwd=" " if (!$genpwd);
1.101 albertel 1636: } elsif (($env{'form.login'} eq 'nochange') ||
1637: ($env{'form.login'} eq '' )) {
1.34 matthew 1638: # There is no need to tell the user we did not change what they
1639: # did not ask us to change.
1.35 matthew 1640: # If they are creating a new user but have not specified login
1641: # information this will be caught below.
1.30 matthew 1642: } else {
1.193 raeburn 1643: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 1644: return;
1.27 matthew 1645: }
1.164 albertel 1646:
1.188 raeburn 1647: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1648: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 1649: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.101 albertel 1650: if ($env{'form.makeuser'}) {
1.164 albertel 1651: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1652: # Check for the authentication mode and password
1653: if (! $amode || ! $genpwd) {
1.193 raeburn 1654: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 1655: return;
1.18 albertel 1656: }
1.29 matthew 1657: # Determine desired host
1.101 albertel 1658: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1659: if (lc($desiredhost) eq 'default') {
1660: $desiredhost = undef;
1661: } else {
1.147 albertel 1662: my %home_servers =
1663: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1664: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 1665: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
1666: return;
1667: }
1668: }
1669: # Check ID format
1670: my %checkhash;
1671: my %checks = ('id' => 1);
1672: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 1673: 'newuser' => $newuser,
1.196 raeburn 1674: 'id' => $env{'form.cid'},
1.193 raeburn 1675: );
1.196 raeburn 1676: if ($env{'form.cid'} ne '') {
1677: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1678: \%rulematch,\%inst_results,\%curr_rules);
1679: if (ref($alerts{'id'}) eq 'HASH') {
1680: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1681: my $domdesc =
1682: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
1683: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
1684: my $userchkmsg;
1685: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
1686: $userchkmsg =
1687: &Apache::loncommon::instrule_disallow_msg('id',
1688: $domdesc,1).
1689: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
1690: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
1691: }
1692: $r->print($error.&mt('Invalid ID format').$end.
1693: $userchkmsg.$rtnlink);
1694: return;
1695: }
1696: }
1.29 matthew 1697: }
1698: }
1.27 matthew 1699: # Call modifyuser
1700: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 1701: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 1702: $amode,$genpwd,$env{'form.cfirstname'},
1703: $env{'form.cmiddlename'},$env{'form.clastname'},
1704: $env{'form.cgeneration'},undef,$desiredhost,
1705: $env{'form.cpermanentemail'});
1.77 www 1706: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 1707: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 1708: $env{'form.ccdomain'});
1.232 raeburn 1709: if (($uhome ne 'no_host') && ($env{'form.customquota'} == 1)) {
1710: my (%changeHash,$newportfolioquota);
1711: if ($env{'form.portfolioquota'} eq '') {
1712: $newportfolioquota = 0;
1713: } else {
1714: $newportfolioquota = $env{'form.portfolioquota'};
1715: $newportfolioquota =~ s/[^\d\.]//g;
1716: }
1717: my $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1718: if ($quotachanged) {
1719: $changeHash{'firstname'} = $env{'form.cfirstname'};
1720: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1721: $changeHash{'lastname'} = $env{'form.clastname'};
1722: $changeHash{'generation'} = $env{'form.cgeneration'};
1723: $changeHash{'id'} = $env{'form.cid'};
1724: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1725: my $quotachgresult =
1726: &Apache::lonnet::put('environment',\%changeHash,
1727: $env{'form.ccdomain'},$env{'form.ccuname'});
1728: }
1729: }
1.219 raeburn 1730: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
1731: &Apache::lonnet::hostname($uhome));
1.101 albertel 1732: } elsif (($env{'form.login'} ne 'nochange') &&
1733: ($env{'form.login'} ne '' )) {
1.27 matthew 1734: # Modify user privileges
1735: if (! $amode || ! $genpwd) {
1.193 raeburn 1736: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1737: return;
1.20 harris41 1738: }
1.27 matthew 1739: # Only allow authentification modification if the person has authority
1.101 albertel 1740: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1741: $r->print('Modifying authentication: '.
1.31 matthew 1742: &Apache::lonnet::modifyuserauth(
1.101 albertel 1743: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1744: $amode,$genpwd));
1.102 albertel 1745: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1746: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1747: } else {
1.27 matthew 1748: # Okay, this is a non-fatal error.
1.193 raeburn 1749: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1750: }
1.28 matthew 1751: }
1752: ##
1.213 raeburn 1753: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1754: if ($context eq 'course') {
1755: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1756: }
1.101 albertel 1757: if (! $env{'form.makeuser'} ) {
1.28 matthew 1758: # Check for need to change
1759: my %userenv = &Apache::lonnet::get
1.134 raeburn 1760: ('environment',['firstname','middlename','lastname','generation',
1.196 raeburn 1761: 'id','permanentemail','portfolioquota','inststatus'],
1.160 raeburn 1762: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1763: my ($tmp) = keys(%userenv);
1764: if ($tmp =~ /^(con_lost|error)/i) {
1765: %userenv = ();
1766: }
1.206 raeburn 1767: my $no_forceid_alert;
1768: # Check to see if user information can be changed
1769: my %domconfig =
1770: &Apache::lonnet::get_dom('configuration',['usermodification'],
1771: $env{'form.ccdomain'});
1.213 raeburn 1772: my @statuses = ('active','future');
1773: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1774: my ($auname,$audom);
1.220 raeburn 1775: if ($context eq 'author') {
1.206 raeburn 1776: $auname = $env{'user.name'};
1777: $audom = $env{'user.domain'};
1778: }
1779: foreach my $item (keys(%roles)) {
1.220 raeburn 1780: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 1781: if ($context eq 'course') {
1782: if ($cnum ne '' && $cdom ne '') {
1783: if ($rolenum eq $cnum && $roledom eq $cdom) {
1784: if (!grep(/^\Q$role\E$/,@userroles)) {
1785: push(@userroles,$role);
1786: }
1787: }
1788: }
1789: } elsif ($context eq 'author') {
1790: if ($rolenum eq $auname && $roledom eq $audom) {
1791: if (!grep(/^\Q$role\E$/,@userroles)) {
1792: push(@userroles,$role);
1793: }
1794: }
1795: }
1796: }
1.220 raeburn 1797: if ($env{'form.action'} eq 'singlestudent') {
1798: if (!grep(/^st$/,@userroles)) {
1799: push(@userroles,'st');
1800: }
1801: } else {
1802: # Check for course or co-author roles being activated or re-enabled
1803: if ($context eq 'author' || $context eq 'course') {
1804: foreach my $key (keys(%env)) {
1805: if ($context eq 'author') {
1806: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1807: if (!grep(/^\Q$1\E$/,@userroles)) {
1808: push(@userroles,$1);
1809: }
1810: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1811: if (!grep(/^\Q$1\E$/,@userroles)) {
1812: push(@userroles,$1);
1813: }
1.206 raeburn 1814: }
1.220 raeburn 1815: } elsif ($context eq 'course') {
1816: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1817: if (!grep(/^\Q$1\E$/,@userroles)) {
1818: push(@userroles,$1);
1819: }
1820: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1821: if (!grep(/^\Q$1\E$/,@userroles)) {
1822: push(@userroles,$1);
1823: }
1.206 raeburn 1824: }
1825: }
1826: }
1827: }
1828: }
1829: #Check to see if we can change personal data for the user
1830: my (@mod_disallowed,@longroles);
1831: foreach my $role (@userroles) {
1832: if ($role eq 'cr') {
1833: push(@longroles,'Custom');
1834: } else {
1835: push(@longroles,&Apache::lonnet::plaintext($role));
1836: }
1837: }
1.219 raeburn 1838: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1839: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
1840: foreach my $item (@userinfo) {
1.28 matthew 1841: # Strip leading and trailing whitespace
1.203 raeburn 1842: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 1843: if (!$canmodify{$item}) {
1.207 raeburn 1844: if (defined($env{'form.c'.$item})) {
1845: if ($env{'form.c'.$item} ne $userenv{$item}) {
1846: push(@mod_disallowed,$item);
1847: }
1.206 raeburn 1848: }
1849: $env{'form.c'.$item} = $userenv{$item};
1850: }
1.28 matthew 1851: }
1.196 raeburn 1852: # Check to see if we can change the ID/student number
1853: my $forceid = $env{'form.forceid'};
1854: my $recurseid = $env{'form.recurseid'};
1855: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1856: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1857: $env{'form.ccuname'});
1858: if (($uidhash{$env{'form.ccuname'}}) &&
1859: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1860: (!$forceid)) {
1861: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1862: $env{'form.cid'} = $userenv{'id'};
1.206 raeburn 1863: $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 1864: }
1865: }
1866: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1867: my $checkhash;
1868: my $checks = { 'id' => 1 };
1869: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1870: { 'newuser' => $newuser,
1871: 'id' => $env{'form.cid'},
1872: };
1873: &Apache::loncommon::user_rule_check($checkhash,$checks,
1874: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1875: if (ref($alerts{'id'}) eq 'HASH') {
1876: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1877: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1878: }
1879: }
1880: }
1.213 raeburn 1881: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1882: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1883: $newdefquotatext);
1.149 raeburn 1884: my ($defquota,$settingstatus) =
1885: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.220 raeburn 1886: my $showquota;
1887: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1888: $showquota = 1;
1889: }
1.134 raeburn 1890: my %changeHash;
1.204 raeburn 1891: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 1892: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1893: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1894: if ($env{'form.customquota'} == 1) {
1895: if ($env{'form.portfolioquota'} eq '') {
1896: $newportfolioquota = 0;
1897: } else {
1898: $newportfolioquota = $env{'form.portfolioquota'};
1899: $newportfolioquota =~ s/[^\d\.]//g;
1900: }
1.204 raeburn 1901: if ($newportfolioquota != $oldportfolioquota) {
1.149 raeburn 1902: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1903: }
1.149 raeburn 1904: } else {
1905: $quotachanged = "a_admin('',\%changeHash);
1906: $newportfolioquota = $defquota;
1.204 raeburn 1907: $newisdefault = 1;
1.134 raeburn 1908: }
1909: } else {
1.204 raeburn 1910: $oldisdefault = 1;
1.149 raeburn 1911: $oldportfolioquota = $defquota;
1912: if ($env{'form.customquota'} == 1) {
1913: if ($env{'form.portfolioquota'} eq '') {
1914: $newportfolioquota = 0;
1915: } else {
1916: $newportfolioquota = $env{'form.portfolioquota'};
1917: $newportfolioquota =~ s/[^\d\.]//g;
1918: }
1919: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1920: } else {
1921: $newportfolioquota = $defquota;
1.204 raeburn 1922: $newisdefault = 1;
1.149 raeburn 1923: }
1924: }
1.204 raeburn 1925: if ($oldisdefault) {
1926: $olddefquotatext = &get_defaultquota_text($settingstatus);
1927: }
1928: if ($newisdefault) {
1929: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 1930: }
1.206 raeburn 1931: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1932: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1933: $env{'form.clastname'} ne $userenv{'lastname'} ||
1934: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1935: $env{'form.cid'} ne $userenv{'id'} ||
1936: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 1937: $namechanged = 1;
1938: }
1.204 raeburn 1939: if ($namechanged || $quotachanged) {
1.101 albertel 1940: $changeHash{'firstname'} = $env{'form.cfirstname'};
1941: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1942: $changeHash{'lastname'} = $env{'form.clastname'};
1943: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1944: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1945: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204 raeburn 1946: my ($quotachgresult,$namechgresult);
1947: if ($quotachanged) {
1948: $quotachgresult =
1949: &Apache::lonnet::put('environment',\%changeHash,
1950: $env{'form.ccdomain'},$env{'form.ccuname'});
1951: }
1952: if ($namechanged) {
1953: # Make the change
1954: $namechgresult =
1955: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
1956: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
1957: $changeHash{'firstname'},$changeHash{'middlename'},
1958: $changeHash{'lastname'},$changeHash{'generation'},
1959: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 1960: %userupdate = (
1961: lastname => $env{'form.clastname'},
1962: middlename => $env{'form.cmiddlename'},
1963: firstname => $env{'form.cfirstname'},
1964: generation => $env{'form.cgeneration'},
1965: id => $env{'form.cid'},
1966: );
1.204 raeburn 1967: }
1968: if (($namechanged && $namechgresult eq 'ok') ||
1969: ($quotachanged && $quotachgresult eq 'ok')) {
1.28 matthew 1970: # Tell the user we changed the name
1.73 sakharuk 1971: my %lt=&Apache::lonlocal::texthash(
1972: 'uic' => "User Information Changed",
1973: 'frst' => "first",
1974: 'mddl' => "middle",
1975: 'lst' => "last",
1976: 'gen' => "generation",
1.196 raeburn 1977: 'id' => "ID/Student number",
1.160 raeburn 1978: 'mail' => "permanent e-mail",
1.134 raeburn 1979: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1980: 'prvs' => "Previous",
1981: 'chto' => "Changed To"
1982: );
1.201 raeburn 1983: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1984: &Apache::loncommon::start_data_table().
1985: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1986: $r->print(<<"END");
1.201 raeburn 1987: <th> </th>
1.73 sakharuk 1988: <th>$lt{'frst'}</th>
1989: <th>$lt{'mddl'}</th>
1990: <th>$lt{'lst'}</th>
1.134 raeburn 1991: <th>$lt{'gen'}</th>
1.196 raeburn 1992: <th>$lt{'id'}</th>
1.173 raeburn 1993: <th>$lt{'mail'}</th>
1.201 raeburn 1994: END
1.220 raeburn 1995: if ($showquota) {
1996: $r->print("
1997: <th>$lt{'disk'}</th>\n");
1998: }
1.201 raeburn 1999: $r->print(&Apache::loncommon::end_data_table_header_row().
2000: &Apache::loncommon::start_data_table_row());
2001: $r->print(<<"END");
2002: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 2003: <td>$userenv{'firstname'} </td>
2004: <td>$userenv{'middlename'} </td>
2005: <td>$userenv{'lastname'} </td>
1.134 raeburn 2006: <td>$userenv{'generation'} </td>
1.196 raeburn 2007: <td>$userenv{'id'}</td>
1.160 raeburn 2008: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 2009: END
1.220 raeburn 2010: if ($showquota) {
2011: $r->print("
2012: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
2013: }
1.201 raeburn 2014: $r->print(&Apache::loncommon::end_data_table_row().
2015: &Apache::loncommon::start_data_table_row());
2016: $r->print(<<"END");
2017: <td><b>$lt{'chto'}</b></td>
1.101 albertel 2018: <td>$env{'form.cfirstname'} </td>
2019: <td>$env{'form.cmiddlename'} </td>
2020: <td>$env{'form.clastname'} </td>
1.134 raeburn 2021: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 2022: <td>$env{'form.cid'} </td>
1.160 raeburn 2023: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 2024: END
1.220 raeburn 2025: if ($showquota) {
2026: $r->print("
2027: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
2028: }
1.201 raeburn 2029: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 2030: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 2031: if ($env{'form.cid'} ne $userenv{'id'}) {
2032: &Apache::lonnet::idput($env{'form.ccdomain'},
2033: ($env{'form.ccuname'} => $env{'form.cid'}));
2034: if (($recurseid) &&
2035: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2036: my $idresult =
2037: &Apache::lonuserutils::propagate_id_change(
2038: $env{'form.ccuname'},$env{'form.ccdomain'},
2039: \%userupdate);
2040: $r->print('<br />'.$idresult.'<br />');
2041: }
1.196 raeburn 2042: }
1.149 raeburn 2043: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2044: ($env{'form.ccuname'} eq $env{'user.name'})) {
2045: my %newenvhash;
2046: foreach my $key (keys(%changeHash)) {
2047: $newenvhash{'environment.'.$key} = $changeHash{$key};
2048: }
1.238 raeburn 2049: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2050: }
1.28 matthew 2051: } else { # error occurred
1.188 raeburn 2052: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2053: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2054: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2055: }
1.101 albertel 2056: } else { # End of if ($env ... ) logic
1.204 raeburn 2057: # They did not want to change the users name or quota but we can
2058: # still tell them what the name and quota are
1.73 sakharuk 2059: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 2060: 'id' => "ID/Student number",
1.160 raeburn 2061: 'mail' => "Permanent e-mail",
1.134 raeburn 2062: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 2063: );
1.134 raeburn 2064: $r->print(<<"END");
1.196 raeburn 2065: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2066: END
1.204 raeburn 2067: if ($userenv{'permanentemail'} ne '') {
2068: $r->print('<br />['.$lt{'mail'}.': '.
2069: $userenv{'permanentemail'}.']');
1.134 raeburn 2070: }
1.220 raeburn 2071: if ($showquota) {
2072: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
2073: $olddefquotatext.']');
2074: }
2075: $r->print('</h4>');
1.28 matthew 2076: }
1.206 raeburn 2077: if (@mod_disallowed) {
2078: my ($rolestr,$contextname);
2079: if (@longroles > 0) {
2080: $rolestr = join(', ',@longroles);
2081: } else {
2082: $rolestr = &mt('No roles');
2083: }
2084: if ($context eq 'course') {
2085: $contextname = &mt('course');
2086: } elsif ($context eq 'author') {
2087: $contextname = &mt('co-author');
2088: }
2089: $r->print(&mt('The following fields were not updated: ').'<ul>');
2090: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2091: foreach my $field (@mod_disallowed) {
2092: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2093: }
1.207 raeburn 2094: $r->print('</ul>');
2095: if (@mod_disallowed == 1) {
2096: $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));
2097: } else {
2098: $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));
2099: }
2100: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2101: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2102: }
2103: $r->print($no_forceid_alert.
1.239 raeburn 2104: &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules));
1.4 www 2105: }
1.220 raeburn 2106: if ($env{'form.action'} eq 'singlestudent') {
1.239 raeburn 2107: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
2108: $r->print('<p><a href="javascript:backPage(document.userupdate)">'.
2109: &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2110: } else {
1.239 raeburn 2111: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2112: if ($namechanged) {
1.220 raeburn 2113: if ($context eq 'course') {
2114: if (@userroles > 0) {
1.225 raeburn 2115: if ((@rolechanges == 0) ||
2116: (!(grep(/^st$/,@rolechanges)))) {
2117: if (grep(/^st$/,@userroles)) {
2118: my $classlistupdated =
2119: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2120: $cnum,$env{'form.ccdomain'},
2121: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2122: }
1.220 raeburn 2123: }
2124: }
2125: }
2126: }
1.226 raeburn 2127: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2128: $env{'form.ccdomain'});
2129: if ($env{'form.popup'}) {
2130: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2131: } else {
1.246 bisitz 2132: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2133: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2134: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2135: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2136: }
1.220 raeburn 2137: }
2138: $r->print(&Apache::loncommon::end_page());
2139: }
2140:
2141: sub update_roles {
1.239 raeburn 2142: my ($r,$context) = @_;
1.4 www 2143: my $now=time;
1.225 raeburn 2144: my @rolechanges;
1.220 raeburn 2145: my %disallowed;
1.73 sakharuk 2146: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2147: foreach my $key (keys (%env)) {
2148: next if (! $env{$key});
1.190 raeburn 2149: next if ($key eq 'form.action');
1.27 matthew 2150: # Revoke roles
1.135 raeburn 2151: if ($key=~/^form\.rev/) {
2152: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2153: # Revoke standard role
1.170 albertel 2154: my ($scope,$role) = ($1,$2);
2155: my $result =
2156: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2157: $env{'form.ccuname'},
1.239 raeburn 2158: $scope,$role,'','',$context);
1.170 albertel 2159: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2160: $role,$scope,'<b>'.$result.'</b>').'<br />');
2161: if ($role eq 'st') {
1.202 raeburn 2162: my $result =
1.198 raeburn 2163: &Apache::lonuserutils::classlist_drop($scope,
2164: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2165: $now);
1.170 albertel 2166: $r->print($result);
1.53 www 2167: }
1.225 raeburn 2168: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2169: push(@rolechanges,$role);
2170: }
1.196 raeburn 2171: }
1.195 raeburn 2172: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2173: # Revoke custom role
1.113 raeburn 2174: $r->print(&mt('Revoking custom role:').
1.139 albertel 2175: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2176: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 2177: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 2178: '</b><br />');
1.225 raeburn 2179: if (!grep(/^cr$/,@rolechanges)) {
2180: push(@rolechanges,'cr');
2181: }
1.64 www 2182: }
1.135 raeburn 2183: } elsif ($key=~/^form\.del/) {
2184: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2185: # Delete standard role
1.170 albertel 2186: my ($scope,$role) = ($1,$2);
2187: my $result =
2188: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2189: $env{'form.ccuname'},
1.239 raeburn 2190: $scope,$role,$now,0,1,'',
2191: $context);
1.170 albertel 2192: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2193: '<b>'.$result.'</b>').'<br />');
2194: if ($role eq 'st') {
1.202 raeburn 2195: my $result =
1.198 raeburn 2196: &Apache::lonuserutils::classlist_drop($scope,
2197: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2198: $now);
1.170 albertel 2199: $r->print($result);
1.81 albertel 2200: }
1.225 raeburn 2201: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2202: push(@rolechanges,$role);
2203: }
1.116 raeburn 2204: }
1.139 albertel 2205: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2206: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2207: # Delete custom role
1.170 albertel 2208: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2209: $rolename,$rnam,$rdom,$url).': <b>'.
2210: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2211: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 2212: 0,1,$context).'</b><br />');
1.225 raeburn 2213: if (!grep(/^cr$/,@rolechanges)) {
2214: push(@rolechanges,'cr');
2215: }
1.116 raeburn 2216: }
1.135 raeburn 2217: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2218: my $udom = $env{'form.ccdomain'};
2219: my $uname = $env{'form.ccuname'};
1.116 raeburn 2220: # Re-enable standard role
1.135 raeburn 2221: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2222: my $url = $1;
2223: my $role = $2;
2224: my $logmsg;
2225: my $output;
2226: if ($role eq 'st') {
1.141 albertel 2227: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2228: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2229: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2230: if ($result eq 'refused' && $logmsg) {
2231: $output = $logmsg;
2232: } else {
2233: $output = "Error: $result\n";
2234: }
1.89 raeburn 2235: } else {
2236: $output = &mt('Assigning').' '.$role.' in '.$url.
2237: &mt('starting').' '.localtime($now).
2238: ': <br />'.$logmsg.'<br />'.
2239: &mt('Add to classlist').': <b>ok</b><br />';
2240: }
2241: }
2242: } else {
1.101 albertel 2243: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 2244: $env{'form.ccuname'},$url,$role,0,$now,'','',
2245: $context);
1.116 raeburn 2246: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 2247: $role,$url,$result).'<br />';
1.27 matthew 2248: }
1.89 raeburn 2249: $r->print($output);
1.225 raeburn 2250: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2251: push(@rolechanges,$role);
2252: }
1.113 raeburn 2253: }
1.116 raeburn 2254: # Re-enable custom role
1.139 albertel 2255: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2256: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2257: my $result = &Apache::lonnet::assigncustomrole(
2258: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 2259: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.116 raeburn 2260: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
2261: $rolename,$rnam,$rdom,$url,$result).'<br />');
1.225 raeburn 2262: if (!grep(/^cr$/,@rolechanges)) {
2263: push(@rolechanges,'cr');
2264: }
1.116 raeburn 2265: }
1.135 raeburn 2266: } elsif ($key=~/^form\.act/) {
1.101 albertel 2267: my $udom = $env{'form.ccdomain'};
2268: my $uname = $env{'form.ccuname'};
1.141 albertel 2269: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2270: # Activate a custom role
1.83 albertel 2271: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2272: my $url='/'.$one.'/'.$two;
2273: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2274:
1.101 albertel 2275: my $start = ( $env{'form.start_'.$full} ?
2276: $env{'form.start_'.$full} :
1.88 raeburn 2277: $now );
1.101 albertel 2278: my $end = ( $env{'form.end_'.$full} ?
2279: $env{'form.end_'.$full} :
1.88 raeburn 2280: 0 );
2281:
2282: # split multiple sections
2283: my %sections = ();
1.101 albertel 2284: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2285: if ($num_sections == 0) {
1.240 raeburn 2286: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2287: } else {
1.114 albertel 2288: my %curr_groups =
1.117 raeburn 2289: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2290: foreach my $sec (sort {$a cmp $b} keys %sections) {
2291: if (($sec eq 'none') || ($sec eq 'all') ||
2292: exists($curr_groups{$sec})) {
2293: $disallowed{$sec} = $url;
2294: next;
2295: }
2296: my $securl = $url.'/'.$sec;
1.240 raeburn 2297: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2298: }
2299: }
1.225 raeburn 2300: if (!grep(/^cr$/,@rolechanges)) {
2301: push(@rolechanges,'cr');
2302: }
1.142 raeburn 2303: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2304: # Activate roles for sections with 3 id numbers
2305: # set start, end times, and the url for the class
1.83 albertel 2306: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2307: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2308: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2309: $now );
1.101 albertel 2310: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2311: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2312: 0 );
1.83 albertel 2313: my $url='/'.$one.'/'.$two;
1.88 raeburn 2314: my $type = 'three';
2315: # split multiple sections
2316: my %sections = ();
1.101 albertel 2317: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2318: if ($num_sections == 0) {
1.240 raeburn 2319: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2320: } else {
1.114 albertel 2321: my %curr_groups =
1.117 raeburn 2322: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2323: my $emptysec = 0;
2324: foreach my $sec (sort {$a cmp $b} keys %sections) {
2325: $sec =~ s/\W//g;
1.113 raeburn 2326: if ($sec ne '') {
2327: if (($sec eq 'none') || ($sec eq 'all') ||
2328: exists($curr_groups{$sec})) {
2329: $disallowed{$sec} = $url;
2330: next;
2331: }
1.88 raeburn 2332: my $securl = $url.'/'.$sec;
1.240 raeburn 2333: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 2334: } else {
2335: $emptysec = 1;
2336: }
2337: }
2338: if ($emptysec) {
1.240 raeburn 2339: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2340: }
1.225 raeburn 2341: }
2342: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2343: push(@rolechanges,$three);
2344: }
1.135 raeburn 2345: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2346: # Activate roles for sections with two id numbers
2347: # set start, end times, and the url for the class
1.101 albertel 2348: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2349: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2350: $now );
1.101 albertel 2351: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2352: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2353: 0 );
1.225 raeburn 2354: my $one = $1;
2355: my $two = $2;
2356: my $url='/'.$one.'/';
1.88 raeburn 2357: # split multiple sections
2358: my %sections = ();
1.225 raeburn 2359: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2360: if ($num_sections == 0) {
1.240 raeburn 2361: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2362: } else {
2363: my $emptysec = 0;
2364: foreach my $sec (sort {$a cmp $b} keys %sections) {
2365: if ($sec ne '') {
2366: my $securl = $url.'/'.$sec;
1.240 raeburn 2367: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 2368: } else {
2369: $emptysec = 1;
2370: }
2371: }
2372: if ($emptysec) {
1.240 raeburn 2373: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2374: }
2375: }
1.225 raeburn 2376: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2377: push(@rolechanges,$two);
2378: }
1.64 www 2379: } else {
1.190 raeburn 2380: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2381: }
1.113 raeburn 2382: foreach my $key (sort(keys(%disallowed))) {
2383: if (($key eq 'none') || ($key eq 'all')) {
2384: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2385: } else {
2386: $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));
2387: }
2388: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2389: }
2390: }
1.101 albertel 2391: } # End of foreach (keys(%env))
1.75 www 2392: # Flush the course logs so reverse user roles immediately updated
2393: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2394: if (@rolechanges == 0) {
1.193 raeburn 2395: $r->print(&mt('No roles to modify'));
2396: }
1.225 raeburn 2397: return @rolechanges;
1.220 raeburn 2398: }
2399:
2400: sub enroll_single_student {
1.239 raeburn 2401: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
1.220 raeburn 2402: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2403:
2404: # Remove non alphanumeric values from section
2405: $env{'form.sections'}=~s/\W//g;
2406:
2407: # Clean out any old student roles the user has in this class.
2408: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2409: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2410: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2411: my $enroll_result =
2412: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2413: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2414: $env{'form.cmiddlename'},$env{'form.clastname'},
2415: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 2416: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 2417: if ($enroll_result =~ /^ok/) {
2418: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2419: if ($env{'form.sections'} ne '') {
2420: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2421: }
2422: my ($showstart,$showend);
2423: if ($startdate <= $now) {
2424: $showstart = &mt('Access starts immediately');
2425: } else {
2426: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2427: }
2428: if ($enddate == 0) {
2429: $showend = &mt('ends: no ending date');
2430: } else {
2431: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2432: }
2433: $r->print('.<br />'.$showstart.'; '.$showend);
2434: if ($startdate <= $now && !$newuser) {
2435: $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>");
2436: }
2437: } else {
2438: $r->print(&mt('unable to enroll').": ".$enroll_result);
2439: }
2440: return;
1.188 raeburn 2441: }
2442:
1.204 raeburn 2443: sub get_defaultquota_text {
2444: my ($settingstatus) = @_;
2445: my $defquotatext;
2446: if ($settingstatus eq '') {
2447: $defquotatext = &mt('(default)');
2448: } else {
2449: my ($usertypes,$order) =
2450: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2451: if ($usertypes->{$settingstatus} eq '') {
2452: $defquotatext = &mt('(default)');
2453: } else {
2454: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2455: }
2456: }
2457: return $defquotatext;
2458: }
2459:
1.188 raeburn 2460: sub update_result_form {
2461: my ($uhome) = @_;
2462: my $outcome =
2463: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2464: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2465: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2466: }
1.207 raeburn 2467: if ($env{'form.origname'} ne '') {
2468: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2469: }
1.160 raeburn 2470: foreach my $item ('sortby','seluname','seludom') {
2471: if (exists($env{'form.'.$item})) {
1.188 raeburn 2472: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2473: }
2474: }
1.188 raeburn 2475: if ($uhome eq 'no_host') {
2476: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2477: }
2478: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2479: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2480: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2481: '</form>';
2482: return $outcome;
1.4 www 2483: }
2484:
1.149 raeburn 2485: sub quota_admin {
2486: my ($setquota,$changeHash) = @_;
2487: my $quotachanged;
2488: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2489: # Current user has quota modification privileges
2490: $quotachanged = 1;
2491: $changeHash->{'portfolioquota'} = $setquota;
2492: }
2493: return $quotachanged;
2494: }
2495:
1.88 raeburn 2496: sub build_roles {
1.89 raeburn 2497: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2498: my $num_sections = 0;
2499: if ($sectionstr=~ /,/) {
2500: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2501: if ($role eq 'st') {
2502: $secnums[0] =~ s/\W//g;
2503: $$sections{$secnums[0]} = 1;
2504: $num_sections = 1;
2505: } else {
2506: foreach my $sec (@secnums) {
2507: $sec =~ ~s/\W//g;
1.150 banghart 2508: if (!($sec eq "")) {
1.89 raeburn 2509: if (exists($$sections{$sec})) {
2510: $$sections{$sec} ++;
2511: } else {
2512: $$sections{$sec} = 1;
2513: $num_sections ++;
2514: }
1.88 raeburn 2515: }
2516: }
2517: }
2518: } else {
2519: $sectionstr=~s/\W//g;
2520: unless ($sectionstr eq '') {
2521: $$sections{$sectionstr} = 1;
2522: $num_sections ++;
2523: }
2524: }
1.129 albertel 2525:
1.88 raeburn 2526: return $num_sections;
2527: }
2528:
1.58 www 2529: # ========================================================== Custom Role Editor
2530:
2531: sub custom_role_editor {
1.160 raeburn 2532: my ($r) = @_;
1.101 albertel 2533: my $rolename=$env{'form.rolename'};
1.58 www 2534:
1.59 www 2535: if ($rolename eq 'make new role') {
1.101 albertel 2536: $rolename=$env{'form.newrolename'};
1.59 www 2537: }
2538:
1.63 www 2539: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2540:
1.190 raeburn 2541: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2542: &print_username_entry_form($r);
2543: return;
2544: }
1.153 banghart 2545: # ------------------------------------------------------- What can be assigned?
2546: my %full=();
2547: my %courselevel=();
2548: my %courselevelcurrent=();
1.61 www 2549: my $syspriv='';
2550: my $dompriv='';
2551: my $coursepriv='';
1.153 banghart 2552: my $body_top;
1.150 banghart 2553: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2554: my ($rdummy,$roledef)=
2555: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2556: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2557: $body_top .= '<h2>';
1.59 www 2558: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2559: $body_top .= &mt('Existing Role').' "';
1.61 www 2560: # ------------------------------------------------- Get current role privileges
2561: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2562: } else {
1.153 banghart 2563: $body_top .= &mt('New Role').' "';
1.59 www 2564: $roledef='';
2565: }
1.153 banghart 2566: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2567: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2568: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2569: if (!$restrict) { $restrict='F'; }
1.60 www 2570: $courselevel{$priv}=$restrict;
1.61 www 2571: if ($coursepriv=~/\:$priv/) {
2572: $courselevelcurrent{$priv}=1;
2573: }
1.60 www 2574: $full{$priv}=1;
2575: }
2576: my %domainlevel=();
1.61 www 2577: my %domainlevelcurrent=();
1.135 raeburn 2578: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2579: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2580: if (!$restrict) { $restrict='F'; }
1.60 www 2581: $domainlevel{$priv}=$restrict;
1.61 www 2582: if ($dompriv=~/\:$priv/) {
2583: $domainlevelcurrent{$priv}=1;
2584: }
1.60 www 2585: $full{$priv}=1;
2586: }
1.61 www 2587: my %systemlevel=();
2588: my %systemlevelcurrent=();
1.135 raeburn 2589: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2590: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2591: if (!$restrict) { $restrict='F'; }
1.61 www 2592: $systemlevel{$priv}=$restrict;
2593: if ($syspriv=~/\:$priv/) {
2594: $systemlevelcurrent{$priv}=1;
2595: }
2596: $full{$priv}=1;
2597: }
1.160 raeburn 2598: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2599: my $button_code = "\n";
1.153 banghart 2600: my $head_script = "\n";
2601: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2602: my @template_roles = ("cc","in","ta","ep","st");
2603: foreach my $role (@template_roles) {
2604: $head_script .= &make_script_template($role);
2605: $button_code .= &make_button_code($role);
2606: }
1.160 raeburn 2607: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2608: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2609: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2610: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2611: text=>"Pick custom role",
1.160 raeburn 2612: faq=>282,bug=>'Instructor Interface',},
2613: {href=>"javascript:backPage(document.form1,'','')",
2614: text=>"Edit custom role",
2615: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2616: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2617: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2618:
1.153 banghart 2619: $r->print($body_top);
1.73 sakharuk 2620: my %lt=&Apache::lonlocal::texthash(
2621: 'prv' => "Privilege",
1.131 raeburn 2622: 'crl' => "Course Level",
1.73 sakharuk 2623: 'dml' => "Domain Level",
1.150 banghart 2624: 'ssl' => "System Level");
1.236 bisitz 2625: $r->print(&mt('Select a Template').'<br />');
1.154 banghart 2626: $r->print('<form action="">');
2627: $r->print($button_code);
2628: $r->print('</form>');
1.61 www 2629: $r->print(<<ENDCCF);
1.160 raeburn 2630: <form name="form1" method="post">
1.61 www 2631: <input type="hidden" name="phase" value="set_custom_roles" />
2632: <input type="hidden" name="rolename" value="$rolename" />
2633: ENDCCF
1.135 raeburn 2634: $r->print(&Apache::loncommon::start_data_table().
2635: &Apache::loncommon::start_data_table_header_row().
2636: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2637: '</th><th>'.$lt{'ssl'}.'</th>'.
2638: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2639: foreach my $priv (sort keys %full) {
2640: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2641: $r->print(&Apache::loncommon::start_data_table_row().
2642: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2643: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2644: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2645: '</td><td>'.
1.150 banghart 2646: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2647: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2648: '</td><td>'.
1.150 banghart 2649: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2650: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2651: '</td>'.
2652: &Apache::loncommon::end_data_table_row());
1.60 www 2653: }
1.135 raeburn 2654: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2655: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2656: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2657: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2658: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2659: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2660: &Apache::loncommon::end_page());
1.61 www 2661: }
1.153 banghart 2662: # --------------------------------------------------------
2663: sub make_script_template {
2664: my ($role) = @_;
2665: my %full_c=();
2666: my %full_d=();
2667: my %full_s=();
2668: my $return_script;
2669: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2670: my ($priv,$restrict)=split(/\&/,$item);
2671: $full_c{$priv}=1;
2672: }
2673: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2674: my ($priv,$restrict)=split(/\&/,$item);
2675: $full_d{$priv}=1;
2676: }
1.154 banghart 2677: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2678: my ($priv,$restrict)=split(/\&/,$item);
2679: $full_s{$priv}=1;
2680: }
2681: $return_script .= 'function set_'.$role.'() {'."\n";
2682: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2683: my %role_c;
1.155 banghart 2684: foreach my $priv (@temp) {
1.153 banghart 2685: my ($priv_item, $dummy) = split(/\&/,$priv);
2686: $role_c{$priv_item} = 1;
2687: }
2688: foreach my $priv_item (keys(%full_c)) {
2689: my ($priv, $dummy) = split(/\&/,$priv_item);
2690: if (exists($role_c{$priv})) {
2691: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2692: } else {
2693: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2694: }
2695: }
1.154 banghart 2696: my %role_d;
2697: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2698: foreach my $priv(@temp) {
2699: my ($priv_item, $dummy) = split(/\&/,$priv);
2700: $role_d{$priv_item} = 1;
2701: }
2702: foreach my $priv_item (keys(%full_d)) {
2703: my ($priv, $dummy) = split(/\&/,$priv_item);
2704: if (exists($role_d{$priv})) {
2705: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2706: } else {
2707: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2708: }
2709: }
2710: my %role_s;
2711: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2712: foreach my $priv(@temp) {
2713: my ($priv_item, $dummy) = split(/\&/,$priv);
2714: $role_s{$priv_item} = 1;
2715: }
2716: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2717: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2718: if (exists($role_s{$priv})) {
2719: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2720: } else {
2721: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2722: }
1.153 banghart 2723: }
2724: $return_script .= '}'."\n";
1.154 banghart 2725: return ($return_script);
2726: }
2727: # ----------------------------------------------------------
2728: sub make_button_code {
2729: my ($role) = @_;
2730: my $label = &Apache::lonnet::plaintext($role);
2731: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2732: return ($button_code);
1.153 banghart 2733: }
1.61 www 2734: # ---------------------------------------------------------- Call to definerole
2735: sub set_custom_role {
1.240 raeburn 2736: my ($r,$context) = @_;
1.101 albertel 2737: my $rolename=$env{'form.rolename'};
1.63 www 2738: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2739: if (!$rolename) {
1.190 raeburn 2740: &custom_role_editor($r);
1.61 www 2741: return;
2742: }
1.160 raeburn 2743: my ($jsback,$elements) = &crumb_utilities();
2744: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2745:
2746: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2747: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2748: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2749: text=>"Pick custom role",
1.160 raeburn 2750: faq=>282,bug=>'Instructor Interface',},
2751: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2752: text=>"Edit custom role",
2753: faq=>282,bug=>'Instructor Interface',},
2754: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2755: text=>"Result",
2756: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2757: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2758: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2759:
1.61 www 2760: my ($rdummy,$roledef)=
1.110 albertel 2761: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2762:
1.61 www 2763: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2764: $r->print('<h3>');
1.61 www 2765: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2766: $r->print(&mt('Existing Role').' "');
1.61 www 2767: } else {
1.73 sakharuk 2768: $r->print(&mt('New Role').' "');
1.61 www 2769: $roledef='';
2770: }
1.188 raeburn 2771: $r->print($rolename.'"</h3>');
1.61 www 2772: # ------------------------------------------------------- What can be assigned?
2773: my $sysrole='';
2774: my $domrole='';
2775: my $courole='';
2776:
1.135 raeburn 2777: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2778: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2779: if (!$restrict) { $restrict=''; }
2780: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2781: $courole.=':'.$item;
1.61 www 2782: }
2783: }
2784:
1.135 raeburn 2785: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2786: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2787: if (!$restrict) { $restrict=''; }
2788: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2789: $domrole.=':'.$item;
1.61 www 2790: }
2791: }
2792:
1.135 raeburn 2793: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2794: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2795: if (!$restrict) { $restrict=''; }
2796: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2797: $sysrole.=':'.$item;
1.61 www 2798: }
2799: }
1.63 www 2800: $r->print('<br />Defining Role: '.
1.61 www 2801: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2802: if ($env{'request.course.id'}) {
2803: my $url='/'.$env{'request.course.id'};
1.63 www 2804: $url=~s/\_/\//g;
1.73 sakharuk 2805: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2806: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2807: $env{'user.name'},
1.63 www 2808: $url,
1.101 albertel 2809: $env{'user.domain'},
2810: $env{'user.name'},
1.240 raeburn 2811: $rolename,undef,undef,undef,$context));
1.63 www 2812: }
1.190 raeburn 2813: $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 2814: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2815: $r->print(&Apache::loncommon::end_page());
1.58 www 2816: }
2817:
1.2 www 2818: # ================================================================ Main Handler
2819: sub handler {
2820: my $r = shift;
2821: if ($r->header_only) {
1.68 www 2822: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2823: $r->send_http_header;
2824: return OK;
2825: }
1.190 raeburn 2826: my $context;
2827: if ($env{'request.course.id'}) {
2828: $context = 'course';
2829: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 2830: $context = 'author';
1.190 raeburn 2831: } else {
2832: $context = 'domain';
2833: }
2834: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 2835: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
2836: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 2837: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2838: if ($env{'form.action'} ne 'dateselect') {
2839: &Apache::lonhtmlcommon::add_breadcrumb
2840: ({href=>"/adm/createuser",
2841: text=>"User Management"});
2842: }
1.209 raeburn 2843: my ($permission,$allowed) =
2844: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 2845: if (!$allowed) {
2846: $env{'user.error.msg'}=
2847: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2848: "or view user status.";
2849: return HTTP_NOT_ACCEPTABLE;
2850: }
2851:
2852: &Apache::loncommon::content_type($r,'text/html');
2853: $r->send_http_header;
2854:
2855: # Main switch on form.action and form.state, as appropriate
2856: if (! exists($env{'form.action'})) {
2857: $r->print(&header());
2858: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 2859: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2860: $r->print(&Apache::loncommon::end_page());
2861: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2862: $r->print(&header());
2863: &Apache::lonhtmlcommon::add_breadcrumb
2864: ({href=>'/adm/createuser?action=upload&state=',
2865: text=>"Upload Users List"});
2866: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 2867: 'Course_Create_Class_List'));
1.190 raeburn 2868: $r->print('<form name="studentform" method="post" '.
2869: 'enctype="multipart/form-data" '.
2870: ' action="/adm/createuser">'."\n");
2871: if (! exists($env{'form.state'})) {
2872: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2873: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 2874: &Apache::lonuserutils::print_upload_manager_form($r,$context,
2875: $permission);
1.190 raeburn 2876: } elsif ($env{'form.state'} eq 'enrolling') {
2877: if ($env{'form.datatoken'}) {
1.221 raeburn 2878: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 2879: }
2880: } else {
2881: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2882: }
2883: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 2884: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
2885: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 2886: my $phase = $env{'form.phase'};
2887: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2888: &Apache::loncreateuser::restore_prev_selections();
2889: my $srch;
2890: foreach my $item (@search) {
2891: $srch->{$item} = $env{'form.'.$item};
2892: }
1.207 raeburn 2893: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
2894: ($phase eq 'createnewuser')) {
2895: if ($env{'form.phase'} eq 'createnewuser') {
2896: my $response;
2897: if ($env{'form.srchterm'} !~ /^$match_username$/) {
2898: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 2899: $env{'form.phase'} = '';
1.207 raeburn 2900: &print_username_entry_form($r,$context,$response,$srch);
2901: } else {
2902: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
2903: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
2904: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2905: $srch,$response,$context,
2906: $permission);
1.207 raeburn 2907: }
2908: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 2909: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 2910: &user_search_result($context,$srch);
1.190 raeburn 2911: if ($env{'form.currstate'} eq 'modify') {
2912: $currstate = $env{'form.currstate'};
2913: }
2914: if ($currstate eq 'select') {
2915: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 2916: \@search,$context);
1.190 raeburn 2917: } elsif ($currstate eq 'modify') {
2918: my ($ccuname,$ccdomain);
2919: if (($srch->{'srchby'} eq 'uname') &&
2920: ($srch->{'srchtype'} eq 'exact')) {
2921: $ccuname = $srch->{'srchterm'};
2922: $ccdomain= $srch->{'srchdomain'};
2923: } else {
2924: my @matchedunames = keys(%{$results});
2925: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2926: }
2927: $ccuname =&LONCAPA::clean_username($ccuname);
2928: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2929: if ($env{'form.forcenewuser'}) {
2930: $response = '';
2931: }
2932: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2933: $srch,$response,$context,
2934: $permission);
1.190 raeburn 2935: } elsif ($currstate eq 'query') {
2936: &print_user_query_page($r,'createuser');
2937: } else {
1.229 raeburn 2938: $env{'form.phase'} = '';
1.207 raeburn 2939: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 2940: $forcenewuser);
2941: }
2942: } elsif ($env{'form.phase'} eq 'userpicked') {
2943: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2944: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2945: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 2946: $context,$permission);
1.190 raeburn 2947: }
2948: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 2949: &update_user_data($r,$context);
1.190 raeburn 2950: } else {
1.207 raeburn 2951: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 2952: }
2953: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2954: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 2955: &set_custom_role($r,$context);
1.190 raeburn 2956: } else {
2957: &custom_role_editor($r);
2958: }
1.207 raeburn 2959: } elsif (($env{'form.action'} eq 'listusers') &&
2960: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 2961: if ($env{'form.phase'} eq 'bulkchange') {
2962: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 2963: ({href=>'/adm/createuser?action=listusers',
2964: text=>"List Users"},
2965: {href=>"/adm/createuser",
2966: text=>"Result"});
1.202 raeburn 2967: my $setting = $env{'form.roletype'};
2968: my $choice = $env{'form.bulkaction'};
2969: $r->print(&header());
1.221 raeburn 2970: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 2971: 'Course_View_Class_List'));
1.202 raeburn 2972: if ($permission->{'cusr'}) {
2973: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 2974: $r->print(&Apache::loncommon::end_page());
2975: } else {
2976: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 2977: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 2978: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2979: }
2980: } else {
2981: &Apache::lonhtmlcommon::add_breadcrumb
2982: ({href=>'/adm/createuser?action=listusers',
2983: text=>"List Users"});
2984: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2985: my $formname = 'studentform';
2986: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2987: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2988: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2989: $formname);
2990: $jscript .= &verify_user_display();
2991: my $js = &add_script($jscript).$cb_jscript;
2992: my $loadcode =
2993: &Apache::lonuserutils::course_selector_loadcode($formname);
2994: if ($loadcode ne '') {
2995: $r->print(&header($js,{'onload' => $loadcode,}));
2996: } else {
2997: $r->print(&header($js));
2998: }
1.191 raeburn 2999: } else {
1.202 raeburn 3000: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 3001: }
1.202 raeburn 3002: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3003: 'Course_View_Class_List'));
1.202 raeburn 3004: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3005: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3006: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3007: }
1.213 raeburn 3008: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3009: $r->print(&header());
3010: &Apache::lonhtmlcommon::add_breadcrumb
3011: ({href=>'/adm/createuser?action=drop',
3012: text=>"Drop Students"});
3013: if (!exists($env{'form.state'})) {
3014: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3015: 'Course_Drop_Student'));
3016:
3017: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
3018: } elsif ($env{'form.state'} eq 'done') {
3019: &Apache::lonhtmlcommon::add_breadcrumb
3020: ({href=>'/adm/createuser?action=drop',
3021: text=>"Result"});
3022: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3023: 'Course_Drop_Student'));
3024: &Apache::lonuserutils::update_user_list($r,$context,undef,
3025: $env{'form.action'});
3026: }
3027: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3028: } elsif ($env{'form.action'} eq 'dateselect') {
3029: if ($permission->{'cusr'}) {
3030: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 3031: &Apache::lonuserutils::date_section_selector($context,
3032: $permission).
1.202 raeburn 3033: &Apache::loncommon::end_page());
3034: } else {
3035: $r->print(&header().
3036: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
3037: &Apache::loncommon::end_page());
3038: }
1.237 raeburn 3039: } elsif ($env{'form.action'} eq 'selfenroll') {
3040: $r->print(&header());
3041: &Apache::lonhtmlcommon::add_breadcrumb
3042: ({href=>'/adm/createuser?action=selfenroll',
3043: text=>"Configure Self-enrollment"});
3044: if (!exists($env{'form.state'})) {
3045: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
3046: 'Course_Self_Enrollment'));
1.241 raeburn 3047: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 3048: &print_selfenroll_menu($r,$context,$permission);
3049: } elsif ($env{'form.state'} eq 'done') {
3050: &Apache::lonhtmlcommon::add_breadcrumb
3051: ({href=>'/adm/createuser?action=selfenroll',
3052: text=>"Result"});
3053: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
3054: 'Course_Self_Enrollment'));
1.241 raeburn 3055: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
3056: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 3057: }
3058: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 3059: } elsif ($env{'form.action'} eq 'changelogs') {
3060: $r->print(&header());
3061: &Apache::lonhtmlcommon::add_breadcrumb
3062: ({href=>'/adm/createuser?action=changelogs',
3063: text=>"User Management Logs"});
3064: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
3065: 'Course_User_Logs'));
3066: &print_userchangelogs_display($r,$context,$permission);
3067: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 3068: } else {
3069: $r->print(&header());
1.202 raeburn 3070: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 3071: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3072: $r->print(&Apache::loncommon::end_page());
3073: }
3074: return OK;
3075: }
3076:
3077: sub header {
1.202 raeburn 3078: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 3079: my $start_page;
3080: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 3081: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 3082: } else {
1.202 raeburn 3083: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 3084: }
3085: return $start_page;
3086: }
1.2 www 3087:
1.191 raeburn 3088: sub add_script {
3089: my ($js) = @_;
3090: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
3091: }
3092:
1.202 raeburn 3093: sub verify_user_display {
3094: my $output = <<"END";
3095:
3096: function display_update() {
3097: document.studentform.action.value = 'listusers';
3098: document.studentform.phase.value = 'display';
3099: document.studentform.submit();
3100: }
3101:
3102: END
3103: return $output;
3104:
3105: }
3106:
1.190 raeburn 3107: ###############################################################
3108: ###############################################################
3109: # Menu Phase One
3110: sub print_main_menu {
1.208 raeburn 3111: my ($permission,$context) = @_;
3112: my %links = (
3113: domain => {
3114: upload => 'Upload a File of Users',
1.221 raeburn 3115: singleuser => 'Add/Modify a Single User',
1.208 raeburn 3116: listusers => 'Manage Multiple Users',
3117: },
3118: author => {
3119: upload => 'Upload a File of Co-authors',
1.221 raeburn 3120: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 3121: listusers => 'Display Co-authors and Manage Multiple Users',
3122: },
3123: course => {
3124: upload => 'Upload a File of Course Users',
1.221 raeburn 3125: singleuser => 'Add/Modify a Single Course User',
1.208 raeburn 3126: listusers => 'Display Class Lists and Manage Multiple Users',
3127: },
3128: );
1.190 raeburn 3129: my @menu =
3130: (
1.208 raeburn 3131: { text => $links{$context}{'upload'},
1.224 raeburn 3132: help => 'Course_Create_Class_List',
1.190 raeburn 3133: action => 'upload',
3134: permission => $permission->{'cusr'},
3135: },
1.208 raeburn 3136: { text => $links{$context}{'singleuser'},
1.224 raeburn 3137: help => 'Course_Change_Privileges',
1.190 raeburn 3138: action => 'singleuser',
3139: permission => $permission->{'cusr'},
3140: },
1.208 raeburn 3141: { text => $links{$context}{'listusers'},
1.224 raeburn 3142: help => 'Course_View_Class_List',
1.191 raeburn 3143: action => 'listusers',
1.208 raeburn 3144: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190 raeburn 3145: },
3146: );
1.208 raeburn 3147: if ($context eq 'domain' || $context eq 'course') {
3148: my $customlink = { text => 'Edit Custom Roles',
1.224 raeburn 3149: help => 'Course_Editing_Custom_Roles',
1.208 raeburn 3150: action => 'custom',
3151: permission => $permission->{'custom'},
3152: };
3153: push(@menu,$customlink);
3154: }
3155: if ($context eq 'course') {
1.213 raeburn 3156: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
3157: my @courselinks =
1.208 raeburn 3158: (
1.213 raeburn 3159: { text => 'Enroll a Single Student',
1.224 raeburn 3160: help => 'Course_Add_Student',
1.213 raeburn 3161: action => 'singlestudent',
3162: permission => $permission->{'cusr'},
3163: },
3164: { text => 'Drop Students',
3165: help => 'Course_Drop_Student',
3166: action => 'drop',
3167: permission => $permission->{'cusr'},
3168: });
3169: if (!exists($permission->{'cusr_section'})) {
3170: push(@courselinks,
1.242 bisitz 3171: { text => 'Automated Enrollment Manager',
1.228 raeburn 3172: help => 'Course_Automated_Enrollment',
1.208 raeburn 3173: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
3174: && $permission->{'cusr'}),
3175: url => '/adm/populate',
1.237 raeburn 3176: },
3177: { text => 'Configure User Self-enrollment',
3178: help => 'Course_Self_Enrollment',
3179: action => 'selfenroll',
3180: permission => $permission->{'cusr'},
3181: });
1.213 raeburn 3182: }
3183: push(@courselinks,
1.208 raeburn 3184: { text => 'Manage Course Groups',
3185: help => 'Course_Manage_Group',
3186: permission => $permission->{'grp_manage'},
3187: url => '/adm/coursegroups?refpage=cusr',
1.239 raeburn 3188: },
1.240 raeburn 3189: { text => 'View Change Logs',
3190: help => 'Course_User_Logs',
3191: action => 'changelogs',
3192: permission => $permission->{'cusr'},
1.250 raeburn 3193: },);
3194: # { text => 'View Log-in History',
3195: # help => 'Course_User_Logins',
3196: # action => 'logins',
3197: # permission => $permission->{'cusr'},
3198: # });
1.208 raeburn 3199: push(@menu,@courselinks);
3200: }
1.190 raeburn 3201: my $menu_html = '';
3202: foreach my $menu_item (@menu) {
3203: next if (! $menu_item->{'permission'});
3204: $menu_html.='<p>';
1.234 raeburn 3205: if (exists($menu_item->{'help'})) {
3206: $menu_html.=
3207: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3208: }
1.190 raeburn 3209: $menu_html.='<font size="+1">';
3210: if (exists($menu_item->{'url'})) {
3211: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3212: } else {
3213: $menu_html.=
3214: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
3215: }
3216: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3217: $menu_html.='</p>';
3218: }
3219: return $menu_html;
3220: }
3221:
1.189 albertel 3222: sub restore_prev_selections {
3223: my %saveable_parameters = ('srchby' => 'scalar',
3224: 'srchin' => 'scalar',
3225: 'srchtype' => 'scalar',
3226: );
3227: &Apache::loncommon::store_settings('user','user_picker',
3228: \%saveable_parameters);
3229: &Apache::loncommon::restore_settings('user','user_picker',
3230: \%saveable_parameters);
3231: }
3232:
1.237 raeburn 3233: sub print_selfenroll_menu {
3234: my ($r,$context,$permission) = @_;
3235: my $formname = 'enrollstudent';
3236: my $nolink = 1;
3237: my ($row,$lt) = &get_selfenroll_titles();
3238: my $groupslist = &Apache::lonuserutils::get_groupslist();
3239: my $setsec_js =
3240: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 3241: my %alerts = &Apache::lonlocal::texthash(
3242: acto => 'Activation of self-enrollment was selected for the following domain(s)',
3243: butn => 'but no user types have been checked.',
3244: wilf => "Please uncheck 'activate' or check at least one type.",
3245: );
3246: my $selfenroll_js = <<"ENDSCRIPT";
3247: function update_types(caller,num) {
3248: var delidx = getIndexByName('selfenroll_delete');
3249: var actidx = getIndexByName('selfenroll_activate');
3250: if (caller == 'selfenroll_all') {
3251: var selall;
3252: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3253: if (document.$formname.selfenroll_all[i].checked) {
3254: selall = document.$formname.selfenroll_all[i].value;
3255: }
3256: }
3257: if (selall == 1) {
3258: if (delidx != -1) {
3259: if (document.$formname.selfenroll_delete.length) {
3260: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
3261: document.$formname.selfenroll_delete[j].checked = true;
3262: }
3263: } else {
3264: document.$formname.elements[delidx].checked = true;
3265: }
3266: }
3267: if (actidx != -1) {
3268: if (document.$formname.selfenroll_activate.length) {
3269: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3270: document.$formname.selfenroll_activate[j].checked = false;
3271: }
3272: } else {
3273: document.$formname.elements[actidx].checked = false;
3274: }
3275: }
3276: document.$formname.selfenroll_newdom.selectedIndex = 0;
3277: }
3278: }
3279: if (caller == 'selfenroll_activate') {
3280: if (document.$formname.selfenroll_activate.length) {
3281: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3282: if (document.$formname.selfenroll_activate[j].value == num) {
3283: if (document.$formname.selfenroll_activate[j].checked) {
3284: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3285: if (document.$formname.selfenroll_all[i].value == '1') {
3286: document.$formname.selfenroll_all[i].checked = false;
3287: }
3288: if (document.$formname.selfenroll_all[i].value == '0') {
3289: document.$formname.selfenroll_all[i].checked = true;
3290: }
3291: }
3292: }
3293: }
3294: }
3295: } else {
3296: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3297: if (document.$formname.selfenroll_all[i].value == '1') {
3298: document.$formname.selfenroll_all[i].checked = false;
3299: }
3300: if (document.$formname.selfenroll_all[i].value == '0') {
3301: document.$formname.selfenroll_all[i].checked = true;
3302: }
3303: }
3304: }
3305: }
3306: if (caller == 'selfenroll_delete') {
3307: if (document.$formname.selfenroll_delete.length) {
3308: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
3309: if (document.$formname.selfenroll_delete[j].value == num) {
3310: if (document.$formname.selfenroll_delete[j].checked) {
3311: var delindex = getIndexByName('selfenroll_types_'+num);
3312: if (delindex != -1) {
3313: if (document.$formname.elements[delindex].length) {
3314: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
3315: document.$formname.elements[delindex][k].checked = false;
3316: }
3317: } else {
3318: document.$formname.elements[delindex].checked = false;
3319: }
3320: }
3321: }
3322: }
3323: }
3324: } else {
3325: if (document.$formname.selfenroll_delete.checked) {
3326: var delindex = getIndexByName('selfenroll_types_'+num);
3327: if (delindex != -1) {
3328: if (document.$formname.elements[delindex].length) {
3329: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
3330: document.$formname.elements[delindex][k].checked = false;
3331: }
3332: } else {
3333: document.$formname.elements[delindex].checked = false;
3334: }
3335: }
3336: }
3337: }
3338: }
3339: return;
3340: }
3341:
3342: function validate_types(form) {
3343: var needaction = new Array();
3344: var countfail = 0;
3345: var actidx = getIndexByName('selfenroll_activate');
3346: if (actidx != -1) {
3347: if (document.$formname.selfenroll_activate.length) {
3348: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3349: var num = document.$formname.selfenroll_activate[j].value;
3350: if (document.$formname.selfenroll_activate[j].checked) {
3351: countfail = check_types(num,countfail,needaction)
3352: }
3353: }
3354: } else {
3355: if (document.$formname.selfenroll_activate.checked) {
3356: var num = document.enrollstudent.selfenroll_activate.value;
3357: countfail = check_types(num,countfail,needaction)
3358: }
3359: }
3360: }
3361: if (countfail > 0) {
3362: var msg = "$alerts{'acto'}\\n";
3363: var loopend = needaction.length -1;
3364: if (loopend > 0) {
3365: for (var m=0; m<loopend; m++) {
3366: msg += needaction[m]+", ";
3367: }
3368: }
3369: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
3370: alert(msg);
3371: return;
3372: }
3373: setSections(form);
3374: }
3375:
3376: function check_types(num,countfail,needaction) {
3377: var typeidx = getIndexByName('selfenroll_types_'+num);
3378: var count = 0;
3379: if (typeidx != -1) {
3380: if (document.$formname.elements[typeidx].length) {
3381: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
3382: if (document.$formname.elements[typeidx][k].checked) {
3383: count ++;
3384: }
3385: }
3386: } else {
3387: if (document.$formname.elements[typeidx].checked) {
3388: count ++;
3389: }
3390: }
3391: if (count == 0) {
3392: var domidx = getIndexByName('selfenroll_dom_'+num);
3393: if (domidx != -1) {
3394: var domname = document.$formname.elements[domidx].value;
3395: needaction[countfail] = domname;
3396: countfail ++;
3397: }
3398: }
3399: }
3400: return countfail;
3401: }
3402:
3403: function getIndexByName(item) {
3404: for (var i=0;i<document.$formname.elements.length;i++) {
3405: if (document.$formname.elements[i].name == item) {
3406: return i;
3407: }
3408: }
3409: return -1;
3410: }
3411: ENDSCRIPT
1.256 raeburn 3412: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3413: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3414:
1.237 raeburn 3415: my $output = '<script type="text/javascript">'."\n".
1.249 raeburn 3416: $setsec_js."\n".$selfenroll_js."\n".
1.237 raeburn 3417: '</script>'."\n".
1.256 raeburn 3418: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
3419: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
3420: if (ref($visactions) eq 'HASH') {
3421: if ($visible) {
3422: $output .= '<p>'.$visactions->{'vis'}.'</p>';
3423: } else {
3424: $output .= $visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
3425: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
3426: if (ref($vismsgs) eq 'ARRAY') {
3427: $output .= '<br />'.$visactions->{'make'}.'<ul>';
3428: foreach my $item (@{$vismsgs}) {
3429: $output .= '<li>'.$visactions->{$item}.'</li>';
3430: }
3431: $output .= '</ul>';
3432: }
3433: $output .= '</p>';
3434: }
3435: }
3436: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
3437: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 3438: if (ref($row) eq 'ARRAY') {
3439: foreach my $item (@{$row}) {
3440: my $title = $item;
3441: if (ref($lt) eq 'HASH') {
3442: $title = $lt->{$item};
3443: }
3444: $output .=
3445: &Apache::lonhtmlcommon::row_title($title,
3446: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
3447: if ($item eq 'types') {
3448: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 3449: my $showdomdesc = 1;
3450: my $includeempty = 1;
3451: my $num = 0;
3452: $output .= &Apache::loncommon::start_data_table().
3453: &Apache::loncommon::start_data_table_row()
3454: .'<td colspan="2"><span class="LC_nobreak"><label>'
3455: .&mt('Any user in any domain:')
3456: .' <input type="radio" name="selfenroll_all" value="1" ';
3457: if ($curr_types eq '*') {
3458: $output .= ' checked="checked" ';
3459: }
1.249 raeburn 3460: $output .= 'onchange="javascript:update_types('.
3461: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
3462: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 3463: if ($curr_types ne '*') {
3464: $output .= ' checked="checked" ';
3465: }
1.249 raeburn 3466: $output .= ' onchange="javascript:update_types('.
3467: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
3468: &Apache::loncommon::end_data_table_row().
3469: &Apache::loncommon::end_data_table().
3470: &mt('Or').'<br />'.
3471: &Apache::loncommon::start_data_table();
1.241 raeburn 3472: my %currdoms;
1.249 raeburn 3473: if ($curr_types eq '') {
1.241 raeburn 3474: $output .= &new_selfenroll_dom_row($cdom,'0');
3475: } elsif ($curr_types ne '*') {
3476: my @entries = split(/;/,$curr_types);
3477: if (@entries > 0) {
3478: foreach my $entry (@entries) {
3479: my ($currdom,$typestr) = split(/:/,$entry);
3480: $currdoms{$currdom} = 1;
3481: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 3482: my @currinsttypes = split(',',$typestr);
1.241 raeburn 3483: $output .= &Apache::loncommon::start_data_table_row()
3484: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
3485: .' '.$domdesc.' ('.$currdom.')'
3486: .'</b><input type="hidden" name="selfenroll_dom_'.$num
3487: .'" value="'.$currdom.'" /></span><br />'
3488: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 3489: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 3490: .&mt('Delete').'</label></span></td>';
1.249 raeburn 3491: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 3492: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
3493: .&Apache::loncommon::end_data_table_row();
3494: $num ++;
3495: }
3496: }
3497: }
1.249 raeburn 3498: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 3499: if ($curr_types eq '*') {
1.249 raeburn 3500: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 3501: } elsif ($curr_types eq '') {
1.249 raeburn 3502: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 3503: }
3504: $output .= &Apache::loncommon::start_data_table_row()
3505: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
3506: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
3507: $includeempty,$showdomdesc)
3508: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
3509: .'</td>'.&Apache::loncommon::end_data_table_row()
3510: .&Apache::loncommon::end_data_table();
1.237 raeburn 3511: } elsif ($item eq 'registered') {
3512: my ($regon,$regoff);
3513: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
3514: $regon = ' checked="checked" ';
3515: $regoff = ' ';
3516: } else {
3517: $regon = ' ';
3518: $regoff = ' checked="checked" ';
3519: }
3520: $output .= '<label>'.
1.245 raeburn 3521: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 3522: &mt('Yes').'</label> <label>'.
1.245 raeburn 3523: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 3524: &mt('No').'</label>';
1.237 raeburn 3525: } elsif ($item eq 'enroll_dates') {
3526: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
3527: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
3528: if ($starttime eq '') {
3529: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3530: }
3531: if ($endtime eq '') {
3532: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3533: }
3534: my $startform =
3535: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
3536: undef,undef,undef,undef,undef,undef,undef,$nolink);
3537: my $endform =
3538: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
3539: undef,undef,undef,undef,undef,undef,undef,$nolink);
3540: $output .= &selfenroll_date_forms($startform,$endform);
3541: } elsif ($item eq 'access_dates') {
3542: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
3543: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
3544: if ($starttime eq '') {
3545: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3546: }
3547: if ($endtime eq '') {
3548: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3549: }
3550: my $startform =
3551: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
3552: undef,undef,undef,undef,undef,undef,undef,$nolink);
3553: my $endform =
3554: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
3555: undef,undef,undef,undef,undef,undef,undef,$nolink);
3556: $output .= &selfenroll_date_forms($startform,$endform);
3557: } elsif ($item eq 'section') {
3558: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
3559: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3560: my $newsecval;
3561: if ($currsec ne 'none' && $currsec ne '') {
3562: if (!defined($sections_count{$currsec})) {
3563: $newsecval = $currsec;
3564: }
3565: }
3566: my $sections_select =
3567: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
3568: $output .= '<table class="LC_createuser">'."\n".
3569: '<tr class="LC_section_row">'."\n".
3570: '<td align="center">'.&mt('Existing sections')."\n".
3571: '<br />'.$sections_select.'</td><td align="center">'.
3572: &mt('New section').'<br />'."\n".
3573: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
3574: '<input type="hidden" name="sections" value="" />'."\n".
3575: '<input type="hidden" name="state" value="done" />'."\n".
3576: '</td></tr></table>'."\n";
3577: }
3578: $output .= &Apache::lonhtmlcommon::row_closure(1);
3579: }
3580: }
3581: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 3582: '<br /><input type="button" name="selfenrollconf" value="'
1.249 raeburn 3583: .&mt('Save changes').'" onclick="validate_types(this.form);" />'
1.241 raeburn 3584: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 3585: $r->print($output);
3586: return;
3587: }
3588:
1.256 raeburn 3589: sub visible_in_cat {
3590: my ($cdom,$cnum) = @_;
3591: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
3592: my ($cathash,%settable,@vismsgs,$cansetvis);
3593: my %visactions = &Apache::lonlocal::texthash(
3594: vis => 'Your course currently appears in the Course Catalog for this domain.',
3595: gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
3596: miss => 'Your course does not currently appear in the Course Catalog for this domain.',
3597: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
3598: coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
3599: make => 'Make any changes to self-enrollment settings below, click "Save changes", then take action to include the course in the Catalog:',
3600: take => 'Take the following action to ensure the course appears in the Catalog:',
3601: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
3602: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
3603: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
3604: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
3605: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
3606: dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
3607: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
3608: );
3609: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/parmset?action=crsenv">','</a>');
3610: $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','<a href="/adm/parmset?action=crsenv">','</a>');
3611: $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','<a href="/adm/parmset?action=crsenv">','</a>');
3612: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3613: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
3614: $settable{'togglecats'} = 1;
3615: }
3616: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
3617: $settable{'categorize'} = 1;
3618: }
3619: $cathash = $domconf{'coursecategories'}{'cats'};
3620: }
3621: if ($settable{'togglecats'} && $settable{'categories'}) {
3622: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
3623: } elsif ($settable{'togglecats'}) {
3624: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
3625: } elsif ($settable{'categories'}) {
3626: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
3627: } else {
3628: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
3629: }
3630:
3631: my %currsettings =
3632: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
3633: $cdom,$cnum);
3634: my $visible = 0;
3635: if ($currsettings{'internal.coursecode'} ne '') {
3636: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3637: $cathash = $domconf{'coursecategories'}{'cats'};
3638: if (ref($cathash) eq 'HASH') {
3639: if ($cathash->{'instcode::0'} eq '') {
3640: push(@vismsgs,'dc_addinst');
3641: } else {
3642: $visible = 1;
3643: }
3644: } else {
3645: $visible = 1;
3646: }
3647: } else {
3648: $visible = 1;
3649: }
3650: } else {
3651: if (ref($cathash) eq 'HASH') {
3652: if ($cathash->{'instcode::0'} ne '') {
3653: push(@vismsgs,'dc_instcode');
3654: }
3655: } else {
3656: push(@vismsgs,'dc_instcode');
3657: }
3658: }
3659: if ($currsettings{'categories'} ne '') {
3660: my $cathash;
3661: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3662: $cathash = $domconf{'coursecategories'}{'cats'};
3663: if (ref($cathash) eq 'HASH') {
3664: if (keys(%{$cathash}) == 0) {
3665: push(@vismsgs,'dc_catalog');
3666: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
3667: push(@vismsgs,'dc_categories');
3668: } else {
3669: my @currcategories = split('&',$currsettings{'categories'});
3670: my $matched = 0;
3671: foreach my $cat (@currcategories) {
3672: if ($cathash->{$cat} ne '') {
3673: $visible = 1;
3674: $matched = 1;
3675: last;
3676: }
3677: }
3678: if (!$matched) {
3679: if ($settable{'categories'}) {
3680: push(@vismsgs,'chgcat');
3681: } else {
3682: push(@vismsgs,'dc_chgcat');
3683: }
3684: }
3685: }
3686: }
3687: }
3688: } else {
3689: if (ref($cathash) eq 'HASH') {
3690: if ((keys(%{$cathash}) > 1) ||
3691: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
3692: if ($settable{'categories'}) {
3693: push(@vismsgs,'addcat');
3694: } else {
3695: push(@vismsgs,'dc_addcat');
3696: }
3697: }
3698: }
3699: }
3700: if ($currsettings{'hidefromcat'} eq 'yes') {
3701: $visible = 0;
3702: if ($settable{'togglecats'}) {
3703: unshift(@vismsgs,'unhide');
3704: } else {
3705: unshift(@vismsgs,'dc_unhide')
3706: }
3707: }
3708: return ($visible,$cansetvis,\@vismsgs,\%visactions);
3709: }
3710:
1.241 raeburn 3711: sub new_selfenroll_dom_row {
3712: my ($newdom,$num) = @_;
3713: my $domdesc = &Apache::lonnet::domain($newdom);
3714: my $output;
3715: if ($domdesc ne '') {
3716: $output .= &Apache::loncommon::start_data_table_row()
3717: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
3718: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 3719: .'" value="'.$newdom.'" /></span><br />'
3720: .'<span class="LC_nobreak"><label><input type="checkbox" '
3721: .'name="selfenroll_activate" value="'.$num.'" '
3722: .'onchange="javascript:update_types('
3723: ."'selfenroll_activate','$num'".');" />'
3724: .&mt('Activate').'</label></span></td>';
1.241 raeburn 3725: my @currinsttypes;
3726: $output .= '<td>'.&mt('User types:').'<br />'
3727: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
3728: .&Apache::loncommon::end_data_table_row();
3729: }
3730: return $output;
3731: }
3732:
3733: sub selfenroll_inst_types {
3734: my ($num,$currdom,$currinsttypes) = @_;
3735: my $output;
3736: my $numinrow = 4;
3737: my $count = 0;
3738: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 3739: my $othervalue = 'any';
1.241 raeburn 3740: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 3741: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 3742: $othervalue = 'other';
3743: }
1.241 raeburn 3744: $output .= '<table><tr>';
3745: foreach my $type (@{$types}) {
3746: if (($count > 0) && ($count%$numinrow == 0)) {
3747: $output .= '</tr><tr>';
3748: }
3749: if (defined($usertypes->{$type})) {
1.257 ! raeburn 3750: my $esc_type = &escape($type);
1.241 raeburn 3751: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 ! raeburn 3752: $esc_type.'" ';
1.241 raeburn 3753: if (ref($currinsttypes) eq 'ARRAY') {
3754: if (@{$currinsttypes} > 0) {
1.249 raeburn 3755: if (grep(/^any$/,@{$currinsttypes})) {
3756: $output .= 'checked="checked"';
1.257 ! raeburn 3757: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 3758: $output .= 'checked="checked"';
3759: }
1.249 raeburn 3760: } else {
3761: $output .= 'checked="checked"';
1.241 raeburn 3762: }
3763: }
3764: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
3765: }
3766: $count ++;
3767: }
3768: if (($count > 0) && ($count%$numinrow == 0)) {
3769: $output .= '</tr><tr>';
3770: }
1.249 raeburn 3771: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 3772: if (ref($currinsttypes) eq 'ARRAY') {
3773: if (@{$currinsttypes} > 0) {
1.249 raeburn 3774: if (grep(/^any$/,@{$currinsttypes})) {
3775: $output .= ' checked="checked"';
3776: } elsif ($othervalue eq 'other') {
3777: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
3778: $output .= ' checked="checked"';
3779: }
1.241 raeburn 3780: }
1.249 raeburn 3781: } else {
3782: $output .= ' checked="checked"';
1.241 raeburn 3783: }
1.249 raeburn 3784: } else {
3785: $output .= ' checked="checked"';
1.241 raeburn 3786: }
3787: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
3788: }
3789: return $output;
3790: }
3791:
1.237 raeburn 3792: sub selfenroll_date_forms {
3793: my ($startform,$endform) = @_;
3794: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 3795: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 3796: 'LC_oddrow_value')."\n".
3797: $startform."\n".
3798: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 3799: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 3800: 'LC_oddrow_value')."\n".
3801: $endform."\n".
3802: &Apache::lonhtmlcommon::row_closure(1).
3803: &Apache::lonhtmlcommon::end_pick_box();
3804: return $output;
3805: }
3806:
1.239 raeburn 3807: sub print_userchangelogs_display {
3808: my ($r,$context,$permission) = @_;
3809: my $formname = 'roleslog';
3810: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3811: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3812: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
3813: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
3814:
3815: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
3816: my %saveable_parameters = ('show' => 'scalar',);
3817: &Apache::loncommon::store_course_settings('roles_log',
3818: \%saveable_parameters);
3819: &Apache::loncommon::restore_course_settings('roles_log',
3820: \%saveable_parameters);
3821: # set defaults
3822: my $now = time();
3823: my $defstart = $now - (7*24*3600); #7 days ago
3824: my %defaults = (
3825: page => '1',
3826: show => '10',
3827: role => 'any',
3828: chgcontext => 'any',
3829: rolelog_start_date => $defstart,
3830: rolelog_end_date => $now,
3831: );
3832: my $more_records = 0;
3833:
3834: # set current
3835: my %curr;
3836: foreach my $item ('show','page','role','chgcontext') {
3837: $curr{$item} = $env{'form.'.$item};
3838: }
3839: my ($startdate,$enddate) =
3840: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
3841: $curr{'rolelog_start_date'} = $startdate;
3842: $curr{'rolelog_end_date'} = $enddate;
3843: foreach my $key (keys(%defaults)) {
3844: if ($curr{$key} eq '') {
3845: $curr{$key} = $defaults{$key};
3846: }
3847: }
1.248 raeburn 3848: my (%whodunit,%changed,$version);
3849: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
3850: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
1.239 raeburn 3851: my $showntablehdr = 0;
3852: my $tablehdr = &Apache::loncommon::start_data_table().
3853: &Apache::loncommon::start_data_table_header_row().
3854: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
3855: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
3856: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
3857: &Apache::loncommon::end_data_table_header_row();
3858: my ($minshown,$maxshown);
1.255 raeburn 3859: $minshown = 1;
1.239 raeburn 3860: my $count = 0;
3861: if ($curr{'show'} ne &mt('all')) {
3862: $maxshown = $curr{'page'} * $curr{'show'};
3863: if ($curr{'page'} > 1) {
3864: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
3865: }
3866: }
3867: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
3868: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
3869: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
3870: if ($curr{'show'} ne &mt('all')) {
3871: if ($count >= $curr{'page'} * $curr{'show'}) {
3872: $more_records = 1;
3873: last;
3874: }
3875: }
3876: if ($curr{'role'} ne 'any') {
3877: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
3878: }
3879: if ($curr{'chgcontext'} ne 'any') {
3880: if ($curr{'chgcontext'} eq 'selfenroll') {
3881: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
3882: } else {
3883: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
3884: }
3885: }
3886: $count ++;
3887: next if ($count < $minshown);
3888: if (!$showntablehdr) {
3889: $r->print($tablehdr);
3890: $showntablehdr = 1;
3891: }
3892: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
3893: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
3894: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
3895: }
3896: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
3897: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
3898: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
3899: }
3900: my $sec = $roleslog{$id}{'logentry'}{'section'};
3901: if ($sec eq '') {
3902: $sec = &mt('None');
3903: }
3904: my ($rolestart,$roleend);
3905: if ($roleslog{$id}{'delflag'}) {
3906: $rolestart = &mt('deleted');
3907: $roleend = &mt('deleted');
3908: } else {
3909: $rolestart = $roleslog{$id}{'logentry'}{'start'};
3910: $roleend = $roleslog{$id}{'logentry'}{'end'};
3911: if ($rolestart eq '' || $rolestart == 0) {
3912: $rolestart = &mt('No start date');
3913: } else {
3914: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
3915: }
3916: if ($roleend eq '' || $roleend == 0) {
3917: $roleend = &mt('No end date');
3918: } else {
3919: $roleend = &Apache::lonlocal::locallocaltime($roleend);
3920: }
3921: }
3922: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
3923: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
3924: $chgcontext = 'selfenroll';
3925: }
3926: my %lt = &rolechg_contexts();
3927: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
3928: $chgcontext = $lt{$chgcontext};
3929: }
3930: $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");
3931: }
3932: if ($showntablehdr) {
3933: $r->print(&Apache::loncommon::end_data_table().'<br />');
3934: if (($curr{'page'} > 1) || ($more_records)) {
3935: $r->print('<table><tr>');
3936: if ($curr{'page'} > 1) {
3937: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
3938: }
3939: if ($more_records) {
3940: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
3941: }
3942: $r->print('</tr></table>');
3943: $r->print(<<"ENDSCRIPT");
3944: <script type="text/javascript">
3945: function chgPage(caller) {
3946: if (caller == 'previous') {
3947: document.$formname.page.value --;
3948: }
3949: if (caller == 'next') {
3950: document.$formname.page.value ++;
3951: }
3952: document.$formname.submit();
3953: return;
3954: }
3955: </script>
3956: ENDSCRIPT
3957: }
3958: } else {
3959: $r->print(&mt('There are no records to display'));
3960: }
3961: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
3962: '<input type="hidden" name="action" value="changelogs" /></form>');
3963: return;
3964: }
3965:
3966: sub role_display_filter {
1.248 raeburn 3967: my ($formname,$cdom,$cnum,$curr,$version) = @_;
1.239 raeburn 3968: my $context = 'course';
3969: my $nolink = 1;
3970: my $output = '<table><tr><td valign="top">'.
3971: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
3972: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
3973: (&mt('all'),5,10,20,50,100,1000,10000)).
3974: '</td><td> </td>';
3975: my $startform =
3976: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
3977: $curr->{'rolelog_start_date'},undef,
3978: undef,undef,undef,undef,undef,undef,$nolink);
3979: my $endform =
3980: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
3981: $curr->{'rolelog_end_date'},undef,
3982: undef,undef,undef,undef,undef,undef,$nolink);
3983: my %lt = &rolechg_contexts();
3984: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
3985: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
3986: $endform.'</td></tr></table></td><td> </td>'.
3987: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
3988: '<select name="role"><option value="any"';
3989: if ($curr->{'role'} eq 'any') {
3990: $output .= ' selected="selected"';
3991: }
3992: $output .= '>'.&mt('Any').'</option>'."\n";
3993: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
3994: foreach my $role (@roles) {
3995: my $plrole;
3996: if ($role eq 'cr') {
3997: $plrole = &mt('Custom Role');
3998: } else {
3999: $plrole=&Apache::lonnet::plaintext($role);
4000: }
4001: my $selstr = '';
4002: if ($role eq $curr->{'role'}) {
4003: $selstr = ' selected="selected"';
4004: }
4005: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
4006: }
4007: $output .= '</select></td><td> </td><td valign="top"><b>'.
4008: &mt('Context:').'</b><br /><select name="chgcontext">';
4009: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
4010: my $selstr = '';
4011: if ($curr->{'chgcontext'} eq $chgtype) {
4012: $output .= $selstr = ' selected="selected"';
4013: }
4014: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
4015: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
4016: }
4017: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 4018: }
1.239 raeburn 4019: $output .= '</select></td><td> </td><td valign="middle"><input type="submit" value="'.
1.248 raeburn 4020: &mt('Update Display').'" /></tr></table>'.
4021: '<span class="LC_roleslog_note">'.
4022: &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
4023: if ($version) {
4024: $output .= ' '.&mt('This server is version [_3].','<b>','</b>',$version); }
4025: $output .= '</span><hr noshade><br />';
1.239 raeburn 4026: return $output;
4027: }
4028:
4029: sub rolechg_contexts {
4030: my %lt = &Apache::lonlocal::texthash (
4031: any => 'Any',
4032: auto => 'Automated enrollment',
4033: updatenow => 'Roster Update',
4034: createcourse => 'Course Creation',
4035: course => 'User Management in course',
4036: domain => 'User Management in domain',
4037: selfenroll => 'Self-enrolled',
4038: );
4039: return %lt;
4040: }
4041:
1.27 matthew 4042: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 4043: sub user_search_result {
1.221 raeburn 4044: my ($context,$srch) = @_;
1.160 raeburn 4045: my %allhomes;
4046: my %inst_matches;
4047: my %srch_results;
1.181 raeburn 4048: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 4049: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 4050: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 4051: $response = &mt('Invalid search.');
4052: }
4053: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
4054: $response = &mt('Invalid search.');
4055: }
1.177 raeburn 4056: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 4057: $response = &mt('Invalid search.');
4058: }
4059: if ($srch->{'srchterm'} eq '') {
4060: $response = &mt('You must enter a search term.');
4061: }
1.183 raeburn 4062: if ($srch->{'srchterm'} =~ /^\s+$/) {
4063: $response = &mt('Your search term must contain more than just spaces.');
4064: }
1.160 raeburn 4065: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
4066: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 4067: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 4068: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
4069: }
4070: }
4071: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
4072: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 4073: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 4074: my $unamecheck = $srch->{'srchterm'};
4075: if ($srch->{'srchtype'} eq 'contains') {
4076: if ($unamecheck !~ /^\w/) {
4077: $unamecheck = 'a'.$unamecheck;
4078: }
4079: }
4080: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 4081: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
4082: }
1.160 raeburn 4083: }
4084: }
1.180 raeburn 4085: if ($response ne '') {
4086: $response = '<span class="LC_warning">'.$response.'</span>';
4087: }
1.160 raeburn 4088: if ($srch->{'srchin'} eq 'instd') {
4089: my $instd_chk = &directorysrch_check($srch);
4090: if ($instd_chk ne 'ok') {
1.180 raeburn 4091: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
4092: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 4093: }
4094: }
4095: if ($response ne '') {
1.180 raeburn 4096: return ($currstate,$response);
1.160 raeburn 4097: }
4098: if ($srch->{'srchby'} eq 'uname') {
4099: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
4100: if ($env{'form.forcenew'}) {
4101: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
4102: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4103: if ($uhome eq 'no_host') {
4104: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 4105: my $showdom = &display_domain_info($env{'request.role.domain'});
4106: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 4107: } else {
1.179 raeburn 4108: $currstate = 'modify';
1.160 raeburn 4109: }
4110: } else {
1.179 raeburn 4111: $currstate = 'modify';
1.160 raeburn 4112: }
4113: } else {
4114: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 4115: if ($srch->{'srchtype'} eq 'exact') {
4116: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4117: if ($uhome eq 'no_host') {
1.179 raeburn 4118: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4119: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4120: } else {
1.179 raeburn 4121: $currstate = 'modify';
1.162 raeburn 4122: }
4123: } else {
4124: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4125: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4126: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4127: }
4128: } else {
1.167 albertel 4129: my $courseusers = &get_courseusers();
1.162 raeburn 4130: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 4131: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 4132: $currstate = 'modify';
1.162 raeburn 4133: } else {
1.179 raeburn 4134: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4135: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4136: }
1.160 raeburn 4137: } else {
1.167 albertel 4138: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 4139: my ($cuname,$cudomain) = split(/:/,$user);
4140: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 4141: my $matched = 0;
4142: if ($srch->{'srchtype'} eq 'begins') {
4143: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
4144: $matched = 1;
4145: }
4146: } else {
4147: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
4148: $matched = 1;
4149: }
4150: }
4151: if ($matched) {
1.167 albertel 4152: $srch_results{$user} =
4153: {&Apache::lonnet::get('environment',
4154: ['firstname',
4155: 'lastname',
1.194 albertel 4156: 'permanentemail'],
4157: $cudomain,$cuname)};
1.162 raeburn 4158: }
4159: }
4160: }
1.179 raeburn 4161: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4162: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4163: }
4164: }
4165: }
4166: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4167: $currstate = 'query';
1.160 raeburn 4168: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4169: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4170: if ($dirsrchres eq 'ok') {
4171: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4172: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4173: } else {
4174: my $showdom = &display_domain_info($srch->{'srchdomain'});
4175: $response = '<span class="LC_warning">'.
4176: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4177: '</span><br />'.
4178: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4179: '<br /><br />';
4180: }
1.160 raeburn 4181: }
4182: } else {
4183: if ($srch->{'srchin'} eq 'dom') {
4184: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4185: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4186: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4187: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 4188: my $courseusers = &get_courseusers();
4189: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 4190: my ($uname,$udom) = split(/:/,$user);
4191: my %names = &Apache::loncommon::getnames($uname,$udom);
4192: my %emails = &Apache::loncommon::getemails($uname,$udom);
4193: if ($srch->{'srchby'} eq 'lastname') {
4194: if ((($srch->{'srchtype'} eq 'exact') &&
4195: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 4196: (($srch->{'srchtype'} eq 'begins') &&
4197: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 4198: (($srch->{'srchtype'} eq 'contains') &&
4199: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
4200: $srch_results{$user} = {firstname => $names{'firstname'},
4201: lastname => $names{'lastname'},
4202: permanentemail => $emails{'permanentemail'},
4203: };
4204: }
4205: } elsif ($srch->{'srchby'} eq 'lastfirst') {
4206: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 4207: $srchlast =~ s/\s+$//;
4208: $srchfirst =~ s/^\s+//;
1.160 raeburn 4209: if ($srch->{'srchtype'} eq 'exact') {
4210: if (($names{'lastname'} eq $srchlast) &&
4211: ($names{'firstname'} eq $srchfirst)) {
4212: $srch_results{$user} = {firstname => $names{'firstname'},
4213: lastname => $names{'lastname'},
4214: permanentemail => $emails{'permanentemail'},
4215:
4216: };
4217: }
1.177 raeburn 4218: } elsif ($srch->{'srchtype'} eq 'begins') {
4219: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
4220: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
4221: $srch_results{$user} = {firstname => $names{'firstname'},
4222: lastname => $names{'lastname'},
4223: permanentemail => $emails{'permanentemail'},
4224: };
4225: }
4226: } else {
1.160 raeburn 4227: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
4228: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
4229: $srch_results{$user} = {firstname => $names{'firstname'},
4230: lastname => $names{'lastname'},
4231: permanentemail => $emails{'permanentemail'},
4232: };
4233: }
4234: }
4235: }
4236: }
1.179 raeburn 4237: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4238: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4239: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4240: $currstate = 'query';
1.160 raeburn 4241: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4242: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4243: if ($dirsrchres eq 'ok') {
4244: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4245: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4246: } else {
4247: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
4248: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4249: '</span><br />'.
4250: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4251: '<br /><br />';
4252: }
1.160 raeburn 4253: }
4254: }
1.179 raeburn 4255: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 4256: }
4257:
4258: sub directorysrch_check {
4259: my ($srch) = @_;
4260: my $can_search = 0;
4261: my $response;
4262: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
4263: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 4264: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 4265: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
4266: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 4267: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 4268: }
4269: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
4270: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 4271: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 4272: }
4273: my @usertypes = split(/:/,$env{'environment.inststatus'});
4274: if (!@usertypes) {
4275: push(@usertypes,'default');
4276: }
4277: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
4278: foreach my $type (@usertypes) {
4279: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
4280: $can_search = 1;
4281: last;
4282: }
4283: }
4284: }
4285: if (!$can_search) {
4286: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
4287: my @longtypes;
4288: foreach my $item (@usertypes) {
1.229 raeburn 4289: if (defined($insttypes->{$item})) {
4290: push (@longtypes,$insttypes->{$item});
4291: } elsif ($item eq 'default') {
4292: push (@longtypes,&mt('other'));
4293: }
1.160 raeburn 4294: }
4295: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 4296: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 4297: }
1.160 raeburn 4298: } else {
4299: $can_search = 1;
4300: }
4301: } else {
1.180 raeburn 4302: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 4303: }
4304: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 4305: uname => 'username',
1.160 raeburn 4306: lastfirst => 'last name, first name',
1.167 albertel 4307: lastname => 'last name',
1.172 raeburn 4308: contains => 'contains',
1.178 raeburn 4309: exact => 'as exact match to',
4310: begins => 'begins with',
1.160 raeburn 4311: );
4312: if ($can_search) {
4313: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
4314: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 4315: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 4316: }
4317: } else {
1.180 raeburn 4318: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 4319: }
4320: }
4321: if ($can_search) {
1.178 raeburn 4322: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
4323: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
4324: return 'ok';
4325: } else {
1.180 raeburn 4326: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 4327: }
4328: } else {
4329: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
4330: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
4331: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
4332: return 'ok';
4333: } else {
1.180 raeburn 4334: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 4335: }
1.160 raeburn 4336: }
4337: }
4338: }
4339:
4340: sub get_courseusers {
4341: my %advhash;
1.167 albertel 4342: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 4343: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
4344: foreach my $role (sort(keys(%coursepersonnel))) {
4345: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 4346: if (!exists($classlist->{$user})) {
4347: $classlist->{$user} = [];
4348: }
1.160 raeburn 4349: }
4350: }
1.167 albertel 4351: return $classlist;
1.160 raeburn 4352: }
4353:
4354: sub build_search_response {
1.221 raeburn 4355: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 4356: my ($currstate,$response,$forcenewuser);
1.160 raeburn 4357: my %names = (
4358: 'uname' => 'username',
4359: 'lastname' => 'last name',
4360: 'lastfirst' => 'last name, first name',
4361: 'crs' => 'this course',
1.180 raeburn 4362: 'dom' => 'LON-CAPA domain: ',
4363: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 4364: );
4365:
4366: my %single = (
1.180 raeburn 4367: begins => 'A match',
1.160 raeburn 4368: contains => 'A match',
1.180 raeburn 4369: exact => 'An exact match',
1.160 raeburn 4370: );
4371: my %nomatch = (
1.180 raeburn 4372: begins => 'No match',
1.160 raeburn 4373: contains => 'No match',
1.180 raeburn 4374: exact => 'No exact match',
1.160 raeburn 4375: );
4376: if (keys(%srch_results) > 1) {
1.179 raeburn 4377: $currstate = 'select';
1.160 raeburn 4378: } else {
4379: if (keys(%srch_results) == 1) {
1.179 raeburn 4380: $currstate = 'modify';
1.180 raeburn 4381: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
4382: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
4383: $response .= &display_domain_info($srch->{'srchdomain'});
4384: }
1.160 raeburn 4385: } else {
1.180 raeburn 4386: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
4387: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
4388: $response .= &display_domain_info($srch->{'srchdomain'});
4389: }
4390: $response .= '</span>';
1.160 raeburn 4391: if ($srch->{'srchin'} ne 'alc') {
4392: $forcenewuser = 1;
4393: my $cansrchinst = 0;
4394: if ($srch->{'srchdomain'}) {
4395: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
4396: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4397: if ($domconfig{'directorysrch'}{'available'}) {
4398: $cansrchinst = 1;
4399: }
4400: }
4401: }
1.180 raeburn 4402: if ((($srch->{'srchby'} eq 'lastfirst') ||
4403: ($srch->{'srchby'} eq 'lastname')) &&
4404: ($srch->{'srchin'} eq 'dom')) {
4405: if ($cansrchinst) {
4406: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 4407: }
4408: }
1.180 raeburn 4409: if ($srch->{'srchin'} eq 'crs') {
4410: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
4411: }
4412: }
4413: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 4414: my $cancreate =
4415: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
4416: if ($cancreate) {
4417: my $showdom = &display_domain_info($env{'request.role.domain'});
1.229 raeburn 4418: $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 4419: } else {
4420: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
4421: $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 />';
4422: }
1.160 raeburn 4423: }
4424: }
4425: }
1.179 raeburn 4426: return ($currstate,$response,$forcenewuser);
1.160 raeburn 4427: }
4428:
1.180 raeburn 4429: sub display_domain_info {
4430: my ($dom) = @_;
4431: my $output = $dom;
4432: if ($dom ne '') {
4433: my $domdesc = &Apache::lonnet::domain($dom,'description');
4434: if ($domdesc ne '') {
4435: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
4436: }
4437: }
4438: return $output;
4439: }
4440:
1.160 raeburn 4441: sub crumb_utilities {
4442: my %elements = (
4443: crtuser => {
4444: srchterm => 'text',
1.172 raeburn 4445: srchin => 'selectbox',
1.160 raeburn 4446: srchby => 'selectbox',
4447: srchtype => 'selectbox',
4448: srchdomain => 'selectbox',
4449: },
1.207 raeburn 4450: crtusername => {
4451: srchterm => 'text',
4452: srchdomain => 'selectbox',
4453: },
1.160 raeburn 4454: docustom => {
4455: rolename => 'selectbox',
4456: newrolename => 'textbox',
4457: },
1.179 raeburn 4458: studentform => {
4459: srchterm => 'text',
4460: srchin => 'selectbox',
4461: srchby => 'selectbox',
4462: srchtype => 'selectbox',
4463: srchdomain => 'selectbox',
4464: },
1.160 raeburn 4465: );
4466:
4467: my $jsback .= qq|
4468: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 4469: if (typeof prevphase == 'undefined') {
4470: formname.phase.value = '';
4471: }
4472: else {
4473: formname.phase.value = prevphase;
4474: }
4475: if (typeof prevstate == 'undefined') {
4476: formname.currstate.value = '';
4477: }
4478: else {
4479: formname.currstate.value = prevstate;
4480: }
1.160 raeburn 4481: formname.submit();
4482: }
4483: |;
4484: return ($jsback,\%elements);
4485: }
4486:
1.26 matthew 4487: sub course_level_table {
1.89 raeburn 4488: my (%inccourses) = @_;
1.26 matthew 4489: my $table = '';
1.62 www 4490: # Custom Roles?
4491:
1.190 raeburn 4492: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 4493: my %lt=&Apache::lonlocal::texthash(
4494: 'exs' => "Existing sections",
4495: 'new' => "Define new section",
4496: 'ssd' => "Set Start Date",
4497: 'sed' => "Set End Date",
1.131 raeburn 4498: 'crl' => "Course Level",
1.89 raeburn 4499: 'act' => "Activate",
4500: 'rol' => "Role",
4501: 'ext' => "Extent",
1.113 raeburn 4502: 'grs' => "Section",
1.89 raeburn 4503: 'sta' => "Start",
4504: 'end' => "End"
4505: );
1.62 www 4506:
1.135 raeburn 4507: foreach my $protectedcourse (sort( keys(%inccourses))) {
4508: my $thiscourse=$protectedcourse;
1.26 matthew 4509: $thiscourse=~s:_:/:g;
4510: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
4511: my $area=$coursedata{'description'};
1.119 raeburn 4512: my $type=$coursedata{'type'};
1.135 raeburn 4513: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 4514: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 4515: my %sections_count;
1.101 albertel 4516: if (defined($env{'request.course.id'})) {
4517: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 4518: %sections_count =
4519: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 4520: }
4521: }
1.213 raeburn 4522: my @roles = &Apache::lonuserutils::roles_by_context('course');
4523: foreach my $role (@roles) {
1.221 raeburn 4524: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 4525: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 4526: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4527: $plrole,\%sections_count,\%lt);
4528: } elsif ($env{'request.course.sec'} ne '') {
4529: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
4530: $env{'request.course.sec'})) {
4531: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4532: $plrole,\%sections_count,\%lt);
1.26 matthew 4533: }
4534: }
4535: }
1.221 raeburn 4536: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
4537: foreach my $cust (sort keys %customroles) {
4538: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
4539: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4540: $cust,\%sections_count,\%lt);
4541: }
1.62 www 4542: }
1.26 matthew 4543: }
4544: return '' if ($table eq ''); # return nothing if there is nothing
4545: # in the table
1.188 raeburn 4546: my $result;
4547: if (!$env{'request.course.id'}) {
4548: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
4549: }
4550: $result .=
1.136 raeburn 4551: &Apache::loncommon::start_data_table().
4552: &Apache::loncommon::start_data_table_header_row().
4553: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
4554: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
4555: &Apache::loncommon::end_data_table_header_row().
4556: $table.
4557: &Apache::loncommon::end_data_table();
1.26 matthew 4558: return $result;
4559: }
1.88 raeburn 4560:
1.221 raeburn 4561: sub course_level_row {
4562: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 4563: my $row = &Apache::loncommon::start_data_table_row().
4564: ' <td><input type="checkbox" name="act_'.
4565: $protectedcourse.'_'.$role.'" /></td>'."\n".
4566: ' <td>'.$plrole.'</td>'."\n".
4567: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 4568: if ($role eq 'cc') {
1.222 raeburn 4569: $row .= '<td> </td>';
1.221 raeburn 4570: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 4571: $row .= ' <td><input type="hidden" value="'.
4572: $env{'request.course.sec'}.'" '.
4573: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
4574: $env{'request.course.sec'}.'</td>';
1.221 raeburn 4575: } else {
4576: if (ref($sections_count) eq 'HASH') {
4577: my $currsec =
4578: &Apache::lonuserutils::course_sections($sections_count,
4579: $protectedcourse.'_'.$role);
1.222 raeburn 4580: $row .= '<td><table class="LC_createuser">'."\n".
4581: '<tr class="LC_section_row">'."\n".
4582: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
4583: $currsec.'</td>'."\n".
4584: ' <td> </td>'."\n".
4585: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 4586: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
4587: '" value="" />'.
4588: '<input type="hidden" '.
4589: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 4590: '</tr></table></td>'."\n";
1.221 raeburn 4591: } else {
1.222 raeburn 4592: $row .= '<td><input type="text" size="10" '.
4593: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 4594: }
4595: }
1.222 raeburn 4596: $row .= <<ENDTIMEENTRY;
4597: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 4598: <a href=
4599: "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 4600: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 4601: <a href=
4602: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
4603: ENDTIMEENTRY
1.222 raeburn 4604: $row .= &Apache::loncommon::end_data_table_row();
4605: return $row;
1.221 raeburn 4606: }
4607:
1.88 raeburn 4608: sub course_level_dc {
4609: my ($dcdom) = @_;
1.190 raeburn 4610: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 4611: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 4612: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
4613: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 4614: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 4615: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 4616: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
4617: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 4618: my %lt=&Apache::lonlocal::texthash(
4619: 'rol' => "Role",
1.113 raeburn 4620: 'grs' => "Section",
1.88 raeburn 4621: 'exs' => "Existing sections",
4622: 'new' => "Define new section",
4623: 'sta' => "Start",
4624: 'end' => "End",
4625: 'ssd' => "Set Start Date",
4626: 'sed' => "Set End Date"
4627: );
1.131 raeburn 4628: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 4629: &Apache::loncommon::start_data_table().
4630: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 4631: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 4632: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 4633: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 4634: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 4635: '<td><select name="role">'."\n";
1.213 raeburn 4636: foreach my $role (@roles) {
1.135 raeburn 4637: my $plrole=&Apache::lonnet::plaintext($role);
4638: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 4639: }
4640: if ( keys %customroles > 0) {
1.135 raeburn 4641: foreach my $cust (sort keys %customroles) {
1.101 albertel 4642: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 4643: '_'.$env{'user.name'}.'_'.$cust;
4644: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 4645: }
4646: }
4647: $otheritems .= '</select></td><td>'.
4648: '<table border="0" cellspacing="0" cellpadding="0">'.
4649: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
4650: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
4651: '<td> </td>'.
4652: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 4653: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 4654: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 4655: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 4656: '</tr></table></td>';
4657: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 4658: <td><input type="hidden" name="start" value='' />
1.88 raeburn 4659: <a href=
4660: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 4661: <td><input type="hidden" name="end" value='' />
1.88 raeburn 4662: <a href=
4663: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
4664: ENDTIMEENTRY
1.136 raeburn 4665: $otheritems .= &Apache::loncommon::end_data_table_row().
4666: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 4667: return $cb_jscript.$header.$hiddenitems.$otheritems;
4668: }
4669:
1.237 raeburn 4670: sub update_selfenroll_config {
1.241 raeburn 4671: my ($r,$context,$permission) = @_;
1.237 raeburn 4672: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 4673: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 4674: my (%changes,%warning);
4675: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4676: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 4677: my $curr_types;
1.237 raeburn 4678: if (ref($row) eq 'ARRAY') {
4679: foreach my $item (@{$row}) {
4680: if ($item eq 'enroll_dates') {
4681: my (%currenrolldate,%newenrolldate);
4682: foreach my $type ('start','end') {
4683: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
4684: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
4685: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
4686: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
4687: }
4688: }
4689: } elsif ($item eq 'access_dates') {
4690: my (%currdate,%newdate);
4691: foreach my $type ('start','end') {
4692: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
4693: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
4694: if ($newdate{$type} ne $currdate{$type}) {
4695: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
4696: }
4697: }
1.241 raeburn 4698: } elsif ($item eq 'types') {
4699: $curr_types =
4700: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4701: if ($env{'form.selfenroll_all'}) {
4702: if ($curr_types ne '*') {
4703: $changes{'internal.selfenroll_types'} = '*';
4704: } else {
4705: next;
4706: }
4707: } else {
1.249 raeburn 4708: my %currdoms;
1.241 raeburn 4709: my @entries = split(/;/,$curr_types);
4710: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 4711: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 4712: my $newnum = 0;
1.249 raeburn 4713: my @latesttypes;
4714: foreach my $num (@activations) {
4715: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
4716: if (@types > 0) {
1.241 raeburn 4717: @types = sort(@types);
4718: my $typestr = join(',',@types);
1.249 raeburn 4719: my $typedom = $env{'form.selfenroll_dom_'.$num};
4720: $latesttypes[$newnum] = $typedom.':'.$typestr;
4721: $currdoms{$typedom} = 1;
1.241 raeburn 4722: $newnum ++;
4723: }
4724: }
1.249 raeburn 4725: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
4726: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
4727: if (@types > 0) {
4728: @types = sort(@types);
4729: my $typestr = join(',',@types);
4730: my $typedom = $env{'form.selfenroll_dom_'.$j};
4731: $latesttypes[$newnum] = $typedom.':'.$typestr;
4732: $currdoms{$typedom} = 1;
4733: $newnum ++;
4734: }
4735: }
4736: }
4737: if ($env{'form.selfenroll_newdom'} ne '') {
4738: my $typedom = $env{'form.selfenroll_newdom'};
4739: if ((!defined($currdoms{$typedom})) &&
4740: (&Apache::lonnet::domain($typedom) ne '')) {
4741: my $typestr;
4742: my ($othertitle,$usertypes,$types) =
4743: &Apache::loncommon::sorted_inst_types($typedom);
4744: my $othervalue = 'any';
4745: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4746: if (@{$types} > 0) {
1.257 ! raeburn 4747: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 4748: $othervalue = 'other';
1.257 ! raeburn 4749: $typestr = join(',',($othervalue,@esc_types));
1.249 raeburn 4750: }
4751: $typestr = $othervalue;
4752: } else {
4753: $typestr = $othervalue;
4754: }
4755: $latesttypes[$newnum] = $typedom.':'.$typestr;
4756: $newnum ++ ;
4757: }
4758: }
1.241 raeburn 4759: my $selfenroll_types = join(';',@latesttypes);
4760: if ($selfenroll_types ne $curr_types) {
4761: $changes{'internal.selfenroll_types'} = $selfenroll_types;
4762: }
4763: }
1.237 raeburn 4764: } else {
4765: my $curr_val =
4766: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4767: my $newval = $env{'form.selfenroll_'.$item};
4768: if ($item eq 'section') {
4769: $newval = $env{'form.sections'};
1.241 raeburn 4770: if (defined($curr_groups{$newval})) {
1.237 raeburn 4771: $newval = $curr_val;
4772: $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');
4773: } elsif ($newval eq 'all') {
4774: $newval = $curr_val;
4775: $warning{$item} = &mt("Section for self-enrolled users unchanged, as 'all' is a reserved section name.");
4776: }
4777: if ($newval eq '') {
4778: $newval = 'none';
4779: }
4780: }
4781: if ($newval ne $curr_val) {
4782: $changes{'internal.selfenroll_'.$item} = $newval;
4783: }
1.241 raeburn 4784: }
1.237 raeburn 4785: }
4786: if (keys(%warning) > 0) {
4787: foreach my $item (@{$row}) {
4788: if (exists($warning{$item})) {
4789: $r->print($warning{$item}.'<br />');
4790: }
4791: }
4792: }
4793: if (keys(%changes) > 0) {
4794: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
4795: if ($putresult eq 'ok') {
4796: if ((exists($changes{'internal.selfenroll_types'})) ||
4797: (exists($changes{'internal.selfenroll_start_date'})) ||
4798: (exists($changes{'internal.selfenroll_end_date'}))) {
4799: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
4800: $cnum,undef,undef,'Course');
4801: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
4802: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
4803: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
4804: if (exists($changes{'internal.'.$item})) {
4805: $crsinfo{$env{'request.course.id'}}{$item} =
4806: $changes{'internal.'.$item};
4807: }
4808: }
4809: my $crsputresult =
4810: &Apache::lonnet::courseidput($cdom,\%crsinfo,
4811: $chome,'notime');
4812: }
4813: }
4814: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
4815: foreach my $item (@{$row}) {
4816: my $title = $item;
4817: if (ref($lt) eq 'HASH') {
4818: $title = $lt->{$item};
4819: }
4820: if ($item eq 'enroll_dates') {
4821: foreach my $type ('start','end') {
4822: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
4823: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 4824: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 4825: $title,$type,$newdate).'</li>');
4826: }
4827: }
4828: } elsif ($item eq 'access_dates') {
4829: foreach my $type ('start','end') {
4830: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
4831: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 4832: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 4833: $title,$type,$newdate).'</li>');
4834: }
4835: }
4836: } else {
4837: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 4838: my $newval = $changes{'internal.selfenroll_'.$item};
4839: if ($item eq 'types') {
4840: if ($newval eq '') {
4841: $newval = &mt('None');
4842: } elsif ($newval eq '*') {
4843: $newval = &mt('Any user in any domain');
4844: }
1.245 raeburn 4845: } elsif ($item eq 'registered') {
4846: if ($newval eq '1') {
4847: $newval = &mt('Yes');
4848: } elsif ($newval eq '0') {
4849: $newval = &mt('No');
4850: }
1.241 raeburn 4851: }
1.244 bisitz 4852: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 4853: }
4854: }
4855: }
4856: $r->print('</ul>');
4857: my %newenvhash;
4858: foreach my $key (keys(%changes)) {
4859: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
4860: }
1.238 raeburn 4861: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 4862: } else {
4863: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
4864: }
4865: } else {
1.249 raeburn 4866: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 4867: }
4868: } else {
1.249 raeburn 4869: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 4870: }
1.256 raeburn 4871: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4872: if (ref($visactions) eq 'HASH') {
4873: if (!$visible) {
4874: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
4875: '<br />');
4876: if (ref($vismsgs) eq 'ARRAY') {
4877: $r->print('<br />'.$visactions->{'take'}.'<ul>');
4878: foreach my $item (@{$vismsgs}) {
4879: $r->print('<li>'.$visactions->{$item}.'</li>');
4880: }
4881: $r->print('</ul>');
4882: }
4883: $r->print($cansetvis);
4884: }
4885: }
1.237 raeburn 4886: return;
4887: }
4888:
4889: sub get_selfenroll_titles {
4890: my @row = ('types','registered','enroll_dates','access_dates','section');
4891: my %lt = &Apache::lonlocal::texthash (
4892: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 4893: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 4894: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 4895: access_dates => 'Course access dates assigned to self-enrolling users',
4896: section => 'Section assigned to self-enrolling users',
1.237 raeburn 4897: );
4898: return (\@row,\%lt);
4899: }
4900:
1.27 matthew 4901: #---------------------------------------------- end functions for &phase_two
1.29 matthew 4902:
4903: #--------------------------------- functions for &phase_two and &phase_three
4904:
4905: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 4906:
4907: 1;
4908: __END__
1.2 www 4909:
4910:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>