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