Annotation of loncom/interface/loncreateuser.pm, revision 1.306
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.306 ! raeburn 4: # $Id: loncreateuser.pm,v 1.305 2009/08/06 20:40:59 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:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
54: Creating custom roles can be done by the Domain Coordinator through
55: the Create User functionality. That screen will show all privileges
56: that can be assigned to users. For a complete list of privileges,
57: please see C</home/httpd/lonTabs/rolesplain.tab>.
58:
59: Custom role definitions are stored in the C<roles.db> file of the role
60: author.
61:
62: =cut
1.1 www 63:
64: use strict;
65: use Apache::Constants qw(:common :http);
66: use Apache::lonnet;
1.54 bowersj2 67: use Apache::loncommon;
1.68 www 68: use Apache::lonlocal;
1.117 raeburn 69: use Apache::longroup;
1.190 raeburn 70: use Apache::lonuserutils;
1.277 raeburn 71: use Apache::selfenroll();
1.139 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.1 www 73:
1.20 harris41 74: my $loginscript; # piece of javascript used in two separate instances
75: my $authformnop;
76: my $authformkrb;
77: my $authformint;
78: my $authformfsys;
79: my $authformloc;
80:
1.94 matthew 81: sub initialize_authen_forms {
1.227 raeburn 82: my ($dom,$formname,$curr_authtype,$mode) = @_;
83: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
84: my %param = ( formname => $formname,
1.187 raeburn 85: kerb_def_dom => $krbdefdom,
1.227 raeburn 86: kerb_def_auth => $krbdef,
1.187 raeburn 87: domain => $dom,
88: );
1.188 raeburn 89: my %abv_auth = &auth_abbrev();
1.227 raeburn 90: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 91: my $long_auth = $1;
1.227 raeburn 92: my $curr_autharg = $2;
1.188 raeburn 93: my %abv_auth = &auth_abbrev();
94: $param{'curr_authtype'} = $abv_auth{$long_auth};
95: if ($long_auth =~ /^krb(4|5)$/) {
96: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 97: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 98: }
1.205 raeburn 99: if ($mode eq 'modifyuser') {
100: $param{'mode'} = $mode;
101: }
1.187 raeburn 102: }
1.227 raeburn 103: $loginscript = &Apache::loncommon::authform_header(%param);
104: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 105: $authformnop = &Apache::loncommon::authform_nochange(%param);
106: $authformint = &Apache::loncommon::authform_internal(%param);
107: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
108: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 109: }
110:
1.188 raeburn 111: sub auth_abbrev {
112: my %abv_auth = (
113: krb4 => 'krb',
114: internal => 'int',
115: localuth => 'loc',
116: unix => 'fsys',
117: );
118: return %abv_auth;
119: }
1.43 www 120:
1.134 raeburn 121: # ====================================================
122:
123: sub portfolio_quota {
124: my ($ccuname,$ccdomain) = @_;
125: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 126: 'usrt' => "User Tools",
127: 'disk' => "Disk space allocated to user's portfolio files",
128: 'cuqu' => "Current quota",
129: 'cust' => "Custom quota",
130: 'defa' => "Default",
131: 'chqu' => "Change quota",
1.134 raeburn 132: );
1.149 raeburn 133: my ($currquota,$quotatype,$inststatus,$defquota) =
134: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
135: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
136: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
137: if ($inststatus ne '') {
138: if ($usertypes->{$inststatus} ne '') {
139: $longinsttype = $usertypes->{$inststatus};
140: }
141: }
142: $custom_on = ' ';
143: $custom_off = ' checked="checked" ';
144: my $quota_javascript = <<"END_SCRIPT";
145: <script type="text/javascript">
1.301 bisitz 146: // <![CDATA[
1.149 raeburn 147: function quota_changes(caller) {
148: if (caller == "custom") {
149: if (document.cu.customquota[0].checked) {
150: document.cu.portfolioquota.value = "";
151: }
152: }
153: if (caller == "quota") {
154: document.cu.customquota[1].checked = true;
155: }
156: }
1.301 bisitz 157: // ]]>
1.149 raeburn 158: </script>
159: END_SCRIPT
160: if ($quotatype eq 'custom') {
161: $custom_on = $custom_off;
162: $custom_off = ' ';
163: $showquota = $currquota;
164: if ($longinsttype eq '') {
1.230 bisitz 165: $defaultinfo = &mt('For this user, the default quota would be [_1]'
166: .' Mb.',$defquota);
1.149 raeburn 167: } else {
1.231 raeburn 168: $defaultinfo = &mt("For this user, the default quota would be [_1]".
169: " Mb, as determined by the user's institutional".
170: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 171: }
172: } else {
173: if ($longinsttype eq '') {
1.230 bisitz 174: $defaultinfo = &mt('For this user, the default quota is [_1]'
175: .' Mb.',$defquota);
1.149 raeburn 176: } else {
1.231 raeburn 177: $defaultinfo = &mt("For this user, the default quota of [_1]".
178: " Mb, is determined by the user's institutional".
179: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 180: }
181: }
1.267 raeburn 182:
183: my $output = $quota_javascript."\n".
184: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
185: &Apache::loncommon::start_data_table();
186:
187: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 188: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 189: }
190: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
191: $output .= '<tr class="LC_info_row">'."\n".
192: ' <td>'.$lt{'disk'}.'</td>'."\n".
193: ' </tr>'."\n".
194: &Apache::loncommon::start_data_table_row()."\n".
195: ' <td>'.$lt{'cuqu'}.': '.
196: $currquota.' Mb. '.
197: $defaultinfo.'</td>'."\n".
198: &Apache::loncommon::end_data_table_row()."\n".
199: &Apache::loncommon::start_data_table_row()."\n".
200: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
201: ': <label>'.
202: '<input type="radio" name="customquota" value="0" '.
203: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"'.
204: ' />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
205: ' <label><input type="radio" name="customquota" value="1" '.
206: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
207: $lt{'cust'}.':</label> '.
208: '<input type="text" name="portfolioquota" size ="5" value="'.
209: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
210: '/> Mb</span></td>'."\n".
211: &Apache::loncommon::end_data_table_row()."\n";
212: }
213: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 214: return $output;
215: }
216:
1.275 raeburn 217: sub build_tools_display {
218: my ($ccuname,$ccdomain,$context) = @_;
1.306 ! raeburn 219: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
! 220: $colspan);
1.275 raeburn 221: my %lt = &Apache::lonlocal::texthash (
222: 'blog' => "Personal User Blog",
223: 'aboutme' => "Personal Information Page",
224: 'portfolio' => "Personal User Portfolio",
225: 'avai' => "Available",
226: 'cusa' => "availability",
227: 'chse' => "Change setting",
228: 'usde' => "Use default",
229: 'uscu' => "Use custom",
230: 'official' => 'Can request creation of official courses',
1.299 raeburn 231: 'unofficial' => 'Can request creation of unofficial courses',
232: 'community' => 'Can request creation of communities',
1.275 raeburn 233: );
1.279 raeburn 234: if ($context eq 'requestcourses') {
1.275 raeburn 235: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 236: 'requestcourses.official','requestcourses.unofficial',
237: 'requestcourses.community');
238: @usertools = ('official','unofficial','community');
1.306 ! raeburn 239: @options =('norequest','approve','autolimit','validate');
! 240: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
! 241: %reqtitles = &courserequest_titles();
! 242: %reqdisplay = &courserequest_display();
! 243: $colspan = ' colspan="2"';
1.275 raeburn 244: } else {
245: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
246: 'tools.aboutme','tools.portfolio','tools.blog');
247: @usertools = ('aboutme','blog','portfolio');
248: }
249: foreach my $item (@usertools) {
1.306 ! raeburn 250: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
! 251: $currdisp,$custdisp,$custradio);
1.275 raeburn 252: $cust_off = 'checked="checked" ';
253: $tool_on = 'checked="checked" ';
254: $curr_access =
255: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
256: $context);
1.306 ! raeburn 257: if ($userenv{$context.'.'.$item} ne '') {
! 258: $cust_on = ' checked="checked" ';
! 259: $cust_off = '';
! 260: }
! 261: if ($context eq 'requestcourses') {
! 262: if ($userenv{$context.'.'.$item} eq '') {
! 263: $custom_access = &mt('Currently from default setting.');
! 264: } else {
! 265: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 266: }
267: } else {
1.306 ! raeburn 268: if ($userenv{$context.'.'.$item} eq '') {
! 269: $custom_access =
! 270: &mt('Availability determined currently from default setting.');
! 271: if (!$curr_access) {
! 272: $tool_off = 'checked="checked" ';
! 273: $tool_on = '';
! 274: }
! 275: } else {
! 276: $custom_access =
! 277: &mt('Availability determined currently from custom setting.');
! 278: if ($userenv{$context.'.'.$item} == 0) {
! 279: $tool_off = 'checked="checked" ';
! 280: $tool_on = '';
! 281: }
1.275 raeburn 282: }
283: }
284: $output .= ' <tr class="LC_info_row">'."\n".
1.306 ! raeburn 285: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 286: ' </tr>'."\n".
1.306 ! raeburn 287: &Apache::loncommon::start_data_table_row()."\n";
! 288: if ($context eq 'requestcourses') {
! 289: my ($curroption,$currlimit);
! 290: $curroption = $userenv{$context.'.'.$item};
! 291: if (!$curroption) {
! 292: $curroption = 'norequest';
! 293: }
! 294: if ($curroption =~ /^autolimit=(\d*)$/) {
! 295: $currlimit = $1;
! 296: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
! 297: } else {
! 298: $currdisp = $reqdisplay{$curroption};
! 299: }
! 300: $custdisp = '<table>';
! 301: foreach my $option (@options) {
! 302: my $val = $option;
! 303: if ($option eq 'norequest') {
! 304: $val = 0;
! 305: }
! 306: if ($option eq 'validate') {
! 307: my $canvalidate = 0;
! 308: if (ref($validations{$item}) eq 'HASH') {
! 309: if ($validations{$item}{'_custom_'}) {
! 310: $canvalidate = 1;
! 311: }
! 312: }
! 313: next if (!$canvalidate);
! 314: }
! 315: my $checked = '';
! 316: if ($option eq $curroption) {
! 317: $checked = ' checked="checked"';
! 318: } elsif ($option eq 'autolimit') {
! 319: if ($curroption =~ /^autolimit/) {
! 320: $checked = ' checked="checked"';
! 321: }
! 322: }
! 323: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
! 324: '<input type="radio" name="crsreq_'.$item.
! 325: '" value="'.$val.'"'.$checked.' />'.
! 326: $reqtitles{$option}.'</label> ';
! 327: if ($option eq 'autolimit') {
! 328: $custdisp .= '<input type="text" name="crsreq_'.
! 329: $item.'_limit" size="1" '.
! 330: 'value="'.$currlimit.'" />';
! 331: }
! 332: $custdisp .= '</span></td></tr>';
! 333: }
! 334: $custdisp .= '</table>';
! 335: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
! 336: } else {
! 337: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
! 338: $custdisp = '<span class="LC_nobreak"><label>'.
! 339: '<input type="radio" name="'.$context.'_'.$item.'"'.
! 340: ' value="1"'. $tool_on.'/>'.&mt('On').'</label> <label>'.
! 341: '<input type="radio" name="'.$context.'_'.$item.'" value="0" '.
! 342: $tool_off.'/>'.&mt('Off').'</label></span>';
! 343: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
! 344: '</span>';
! 345: }
! 346: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
! 347: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 348: &Apache::loncommon::end_data_table_row()."\n".
349: &Apache::loncommon::start_data_table_row()."\n".
1.306 ! raeburn 350: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
! 351: $lt{'chse'}.': <label>'.
1.275 raeburn 352: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 ! raeburn 353: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
! 354: '<label><input type="radio" name="custom'.$item.'" value="1" '.
! 355: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 356: &Apache::loncommon::end_data_table_row()."\n";
357: }
358: return $output;
359: }
360:
1.300 raeburn 361: sub coursereq_externaluser {
362: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 ! raeburn 363: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 364: my %lt = &Apache::lonlocal::texthash (
365: 'official' => 'Can request creation of official courses',
366: 'unofficial' => 'Can request creation of unofficial courses',
367: 'community' => 'Can request creation of communities',
368: );
369:
370: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
371: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
372: 'reqcrsotherdom.community');
373: @usertools = ('official','unofficial','community');
1.306 ! raeburn 374: @options = ('approve','validate','autolimit');
! 375: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
! 376: my $optregex = join('|',@options);
! 377: my %reqtitles = &courserequest_titles();
1.300 raeburn 378: foreach my $item (@usertools) {
1.306 ! raeburn 379: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 380: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
381: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.306 ! raeburn 382: if (grep(/^\Q$cdom\E:($optregex)=?(\d*)$/,@curr)) {
! 383: $curroption = $1;
! 384: $currlimit = $2;
! 385: if (!$curroption) {
! 386: $curroption = 'norequest';
! 387: }
! 388: }
! 389: } else {
! 390: $curroption = 'norequest';
! 391: $tooloff = ' checked="checked"';
! 392: }
! 393: $output.= &Apache::loncommon::start_data_table_row()."\n".
! 394: ' <td><span class="LC_nobreak">'.$lt{$item}.': '.
! 395: '<label><input type="radio" name="reqcrsotherdom_'.$item.
! 396: '" value="0"'.$tooloff.' />'.$reqtitles{'norequest'}.
! 397: '</label> ';
! 398: foreach my $option (@options) {
! 399: if ($option eq 'validate') {
! 400: my $canvalidate = 0;
! 401: if (ref($validations{$item}) eq 'HASH') {
! 402: if ($validations{$item}{'_external_'}) {
! 403: $canvalidate = 1;
! 404: }
! 405: }
! 406: next if (!$canvalidate);
! 407: }
! 408: my $checked = '';
! 409: if ($option eq $curroption) {
! 410: $checked = ' checked="checked"';
! 411: }
! 412: $output .= '<span class="LC_nobreak"><label>'.
! 413: '<input type="radio" name="reqcrsotherdom_'.$item.
! 414: '" value="'.$option.'"'.$checked.' />'.
! 415: $reqtitles{$option}.'</label> ';
! 416: if ($option eq 'autolimit') {
! 417: $output .= '<input type="text" name="reqcrsotherdom_'.
! 418: $item.'_limit" size="1" '.
! 419: 'value="'.$currlimit.'" />';
1.300 raeburn 420: }
1.306 ! raeburn 421: $output .= ' '
1.300 raeburn 422: }
1.306 ! raeburn 423: $output .= '</span></td>'."\n".
1.300 raeburn 424: &Apache::loncommon::end_data_table_row()."\n";
425: }
426: return $output;
427: }
428:
1.306 ! raeburn 429: sub courserequest_titles {
! 430: my %titles = &Apache::lonlocal::texthash (
! 431: official => 'Official',
! 432: unofficial => 'Unofficial',
! 433: community => 'Communities',
! 434: norequest => 'Not allowed',
! 435: approve => 'Approval by Dom. Coord.',
! 436: validate => 'With validation',
! 437: autolimit => 'Numerical limit',
! 438: );
! 439: return %titles;
! 440: }
! 441:
! 442: sub courserequest_display {
! 443: my %titles = &Apache::lonlocal::texthash (
! 444: approve => 'Yes, need approval',
! 445: validate => 'Yes, with validation',
! 446: norequest => 'No',
! 447: );
! 448: return %titles;
! 449: }
! 450:
1.2 www 451: # =================================================================== Phase one
1.1 www 452:
1.42 matthew 453: sub print_username_entry_form {
1.207 raeburn 454: my ($r,$context,$response,$srch,$forcenewuser) = @_;
1.101 albertel 455: my $defdom=$env{'request.role.domain'};
1.160 raeburn 456: my $formtoset = 'crtuser';
457: if (exists($env{'form.startrolename'})) {
458: $formtoset = 'docustom';
459: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 460: } elsif ($env{'form.origform'} eq 'crtusername') {
461: $formtoset = $env{'form.origform'};
1.160 raeburn 462: }
463:
464: my ($jsback,$elements) = &crumb_utilities();
465:
466: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 467: '<script type="text/javascript">'."\n".
1.301 bisitz 468: '// <![CDATA['."\n".
469: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
470: '// ]]>'."\n".
1.162 raeburn 471: '</script>'."\n";
1.160 raeburn 472:
473: my %loaditems = (
474: 'onload' => "javascript:setFormElements(document.$formtoset)",
475: );
1.229 raeburn 476: my %breadcrumb_text = &singleuser_breadcrumb();
1.110 albertel 477: my $start_page =
1.190 raeburn 478: &Apache::loncommon::start_page('User Management',
1.160 raeburn 479: $jscript,{'add_entries' => \%loaditems,});
1.214 raeburn 480: if ($env{'form.action'} eq 'custom') {
481: &Apache::lonhtmlcommon::add_breadcrumb
482: ({href=>"javascript:backPage(document.crtuser)",
483: text=>"Pick custom role",});
484: } else {
1.190 raeburn 485: &Apache::lonhtmlcommon::add_breadcrumb
486: ({href=>"javascript:backPage(document.crtuser)",
1.229 raeburn 487: text=>$breadcrumb_text{'search'},
1.190 raeburn 488: faq=>282,bug=>'Instructor Interface',});
489: }
1.224 raeburn 490: my $helpitem = 'Course_Change_Privileges';
491: if ($env{'form.action'} eq 'custom') {
492: $helpitem = 'Course_Editing_Custom_Roles';
493: } elsif ($env{'form.action'} eq 'singlestudent') {
494: $helpitem = 'Course_Add_Student';
495: }
496: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
497: $helpitem);
1.190 raeburn 498: my %existingroles=&Apache::lonuserutils::my_custom_roles();
1.59 www 499: my $choice=&Apache::loncommon::select_form('make new role','rolename',
500: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 501: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 502: 'srst' => 'Search for a user and enroll as a student',
503: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 504: 'usr' => "Username",
505: 'dom' => "Domain",
506: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 507: 'nr' => "Name of Role",
1.282 schafran 508: 'cre' => "Next",
1.71 sakharuk 509: );
1.190 raeburn 510: $r->print($start_page."\n".$crumbs);
1.214 raeburn 511: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 512: if (&Apache::lonnet::allowed('mcr','/')) {
513: $r->print(<<ENDCUSTOM);
1.58 www 514: <form action="/adm/createuser" method="post" name="docustom">
1.190 raeburn 515: <input type="hidden" name="action" value="$env{'form.action'}" />
1.157 albertel 516: <input type="hidden" name="phase" value="selected_custom_edit" />
1.224 raeburn 517: <h3>$lt{'ecrp'}</h3>
1.282 schafran 518: $choice $lt{'nr'}: <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 519: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107 www 520: </form>
1.106 www 521: ENDCUSTOM
1.190 raeburn 522: }
1.213 raeburn 523: } else {
1.229 raeburn 524: my $actiontext = $lt{'srad'};
1.213 raeburn 525: if ($env{'form.action'} eq 'singlestudent') {
1.229 raeburn 526: $actiontext = $lt{'srst'};
1.213 raeburn 527: }
528: $r->print("
1.229 raeburn 529: <h3>$actiontext</h3>");
1.213 raeburn 530: if ($env{'form.origform'} ne 'crtusername') {
531: $r->print("\n".$response);
532: }
533: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
1.107 www 534: }
1.110 albertel 535: $r->print(&Apache::loncommon::end_page());
536: }
537:
1.160 raeburn 538: sub entry_form {
1.214 raeburn 539: my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
1.207 raeburn 540: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.229 raeburn 541: my ($usertype,$inexact);
1.214 raeburn 542: if (ref($srch) eq 'HASH') {
543: if (($srch->{'srchin'} eq 'dom') &&
544: ($srch->{'srchby'} eq 'uname') &&
545: ($srch->{'srchtype'} eq 'exact') &&
546: ($srch->{'srchdomain'} ne '') &&
547: ($srch->{'srchterm'} ne '')) {
548: my ($rules,$ruleorder) =
549: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
550: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
1.229 raeburn 551: } else {
552: $inexact = 1;
1.214 raeburn 553: }
1.207 raeburn 554: }
1.214 raeburn 555: my $cancreate =
556: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 557: my $userpicker =
1.179 raeburn 558: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 559: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 560: my $srchbutton = &mt('Search');
1.229 raeburn 561: if ($env{'form.action'} eq 'singlestudent') {
562: $srchbutton = &mt('Search and Enroll');
563: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
564: $srchbutton = &mt('Search or Add New User');
565: }
1.207 raeburn 566: my $output = <<"ENDBLOCK";
1.160 raeburn 567: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 568: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 569: <input type="hidden" name="phase" value="get_user_info" />
570: $userpicker
1.179 raeburn 571: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 572: </form>
1.207 raeburn 573: ENDBLOCK
1.229 raeburn 574: if ($env{'form.phase'} eq '') {
1.207 raeburn 575: my $defdom=$env{'request.role.domain'};
576: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
577: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 578: 'enro' => 'Enroll one student',
579: 'admo' => 'Add/modify a single user',
580: 'crea' => 'create new user if required',
581: 'uskn' => "username is known",
1.207 raeburn 582: 'crnu' => 'Create a new user',
583: 'usr' => 'Username',
584: 'dom' => 'in domain',
1.229 raeburn 585: 'enrl' => 'Enroll',
586: 'cram' => 'Create/Modify user',
1.207 raeburn 587: );
1.229 raeburn 588: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
589: my ($title,$buttontext,$showresponse);
590: if ($env{'form.action'} eq 'singlestudent') {
591: $title = $lt{'enro'};
592: $buttontext = $lt{'enrl'};
593: } else {
594: $title = $lt{'admo'};
595: $buttontext = $lt{'cram'};
596: }
597: if ($cancreate) {
598: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
599: } else {
600: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
601: }
602: if ($env{'form.origform'} eq 'crtusername') {
603: $showresponse = $responsemsg;
604: }
1.207 raeburn 605: $output .= <<"ENDDOCUMENT";
1.229 raeburn 606: <br />
1.207 raeburn 607: <form action="/adm/createuser" method="post" name="crtusername">
608: <input type="hidden" name="action" value="$env{'form.action'}" />
609: <input type="hidden" name="phase" value="createnewuser" />
610: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 611: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 612: <input type="hidden" name="srchin" value="dom" />
613: <input type="hidden" name="forcenewuser" value="1" />
614: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 615: <h3>$title</h3>
616: $showresponse
1.207 raeburn 617: <table>
618: <tr>
619: <td>$lt{'usr'}:</td>
620: <td><input type="text" size="15" name="srchterm" /></td>
621: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 622: <td> $sellink </td>
623: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 624: </tr>
625: </table>
626: </form>
1.160 raeburn 627: ENDDOCUMENT
1.207 raeburn 628: }
1.160 raeburn 629: return $output;
630: }
1.110 albertel 631:
632: sub user_modification_js {
1.113 raeburn 633: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
634:
1.110 albertel 635: return <<END;
636: <script type="text/javascript" language="Javascript">
1.301 bisitz 637: // <![CDATA[
1.110 albertel 638: function pclose() {
639: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
640: "height=350,width=350,scrollbars=no,menubar=no");
641: parmwin.close();
642: }
643:
644: $pjump_def
645: $dc_setcourse_code
646:
647: function dateset() {
648: eval("document.cu."+document.cu.pres_marker.value+
649: ".value=document.cu.pres_value.value");
650: pclose();
651: }
652:
1.113 raeburn 653: $nondc_setsection_code
1.301 bisitz 654: // ]]>
1.110 albertel 655: </script>
656: END
1.2 www 657: }
658:
659: # =================================================================== Phase two
1.160 raeburn 660: sub print_user_selection_page {
1.302 raeburn 661: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements) = @_;
1.160 raeburn 662: my @fields = ('username','domain','lastname','firstname','permanentemail');
663: my $sortby = $env{'form.sortby'};
664:
665: if (!grep(/^\Q$sortby\E$/,@fields)) {
666: $sortby = 'lastname';
667: }
668:
669: my ($jsback,$elements) = &crumb_utilities();
670:
671: my $jscript = (<<ENDSCRIPT);
672: <script type="text/javascript">
1.301 bisitz 673: // <![CDATA[
1.160 raeburn 674: function pickuser(uname,udom) {
675: document.usersrchform.seluname.value=uname;
676: document.usersrchform.seludom.value=udom;
677: document.usersrchform.phase.value="userpicked";
678: document.usersrchform.submit();
679: }
680:
681: $jsback
1.301 bisitz 682: // ]]>
1.160 raeburn 683: </script>
684: ENDSCRIPT
685:
686: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 687: 'usrch' => "User Search to add/modify roles",
688: 'stusrch' => "User Search to enroll student",
689: 'usel' => "Select a user to add/modify roles",
690: 'stusel' => "Select a user to enroll as a student",
1.160 raeburn 691: 'username' => "username",
692: 'domain' => "domain",
693: 'lastname' => "last name",
694: 'firstname' => "first name",
695: 'permanentemail' => "permanent e-mail",
696: );
1.302 raeburn 697: if ($context eq 'requestcrs') {
698: $r->print('<div>');
699: } else {
700: $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.229 raeburn 701:
1.302 raeburn 702: my %breadcrumb_text = &singleuser_breadcrumb();
703: &Apache::lonhtmlcommon::add_breadcrumb
704: ({href=>"javascript:backPage(document.usersrchform,'','')",
705: text=>$breadcrumb_text{'search'},
706: faq=>282,bug=>'Instructor Interface',},
707: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
708: text=>$breadcrumb_text{'userpicked'},
709: faq=>282,bug=>'Instructor Interface',});
710: if ($env{'form.action'} eq 'singleuser') {
711: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
712: 'Course_Change_Privileges'));
713: $r->print("<b>$lt{'usrch'}</b><br />");
714: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
715: $r->print('<h3>'.$lt{'usel'}.'</h3>');
716: } elsif ($env{'form.action'} eq 'singlestudent') {
717: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
718: 'Course_Add_Student'));
719: $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
720: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
721: $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
722: }
1.179 raeburn 723: }
1.160 raeburn 724: $r->print('<form name="usersrchform" method="post">'.
725: &Apache::loncommon::start_data_table()."\n".
726: &Apache::loncommon::start_data_table_header_row()."\n".
727: ' <th> </th>'."\n");
728: foreach my $field (@fields) {
729: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
730: "'".$field."'".';document.usersrchform.submit();">'.
731: $lt{$field}.'</a></th>'."\n");
732: }
733: $r->print(&Apache::loncommon::end_data_table_header_row());
734:
735: my @sorted_users = sort {
1.167 albertel 736: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 737: ||
1.167 albertel 738: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 739: ||
740: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 741: ||
742: lc($a) cmp lc($b)
1.160 raeburn 743: } (keys(%$srch_results));
744:
745: foreach my $user (@sorted_users) {
746: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 747: my $onclick;
748: if ($context eq 'requestcrs') {
749: $onclick =
750: 'onclick="javascript:gochoose('."'$uname','$udom',".
751: "'$srch_results->{$user}->{firstname}',".
752: "'$srch_results->{$user}->{lastname}',".
753: "'$srch_results->{$user}->{permanentemail}'".');"';
754: } else {
755: $onclick =
756: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
757: }
1.160 raeburn 758: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 759: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
760: $onclick.' /></td>'.
1.160 raeburn 761: '<td><tt>'.$uname.'</tt></td>'.
762: '<td><tt>'.$udom.'</tt></td>');
763: foreach my $field ('lastname','firstname','permanentemail') {
764: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
765: }
766: $r->print(&Apache::loncommon::end_data_table_row());
767: }
768: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 769: if (ref($srcharray) eq 'ARRAY') {
770: foreach my $item (@{$srcharray}) {
771: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
772: }
773: }
1.160 raeburn 774: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
775: ' <input type="hidden" name="seluname" value="" />'."\n".
776: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 777: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 778: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 779: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 780: if ($context eq 'requestcrs') {
781: $r->print($opener_elements.'</form></div>');
782: } else {
783: $r->print($response.'</form>'.&Apache::loncommon::end_page());
784: }
1.160 raeburn 785: }
786:
787: sub print_user_query_page {
1.179 raeburn 788: my ($r,$caller) = @_;
1.160 raeburn 789: # FIXME - this is for a network-wide name search (similar to catalog search)
790: # To use frames with similar behavior to catalog/portfolio search.
791: # To be implemented.
792: return;
793: }
794:
1.42 matthew 795: sub print_user_modification_page {
1.215 raeburn 796: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_;
1.185 raeburn 797: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 798: my $usermsg = &mt('No username and/or domain provided.');
799: $env{'form.phase'} = '';
1.207 raeburn 800: &print_username_entry_form($r,$context,$usermsg);
1.58 www 801: return;
802: }
1.213 raeburn 803: my ($form,$formname);
804: if ($env{'form.action'} eq 'singlestudent') {
805: $form = 'document.enrollstudent';
806: $formname = 'enrollstudent';
807: } else {
808: $form = 'document.cu';
809: $formname = 'cu';
810: }
1.188 raeburn 811: my %abv_auth = &auth_abbrev();
1.227 raeburn 812: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 813: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
814: if ($uhome eq 'no_host') {
1.215 raeburn 815: my $usertype;
816: my ($rules,$ruleorder) =
817: &Apache::lonnet::inst_userrules($ccdomain,'username');
818: $usertype =
819: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
820: my $cancreate =
821: &Apache::lonuserutils::can_create_user($ccdomain,$context,
822: $usertype);
823: if (!$cancreate) {
1.292 bisitz 824: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 825: my %usertypetext = (
826: official => 'institutional',
827: unofficial => 'non-institutional',
828: );
829: my $response;
830: if ($env{'form.origform'} eq 'crtusername') {
831: $response = '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
832: '</span><br />';
833: }
1.292 bisitz 834: $response .= '<p class="LC_warning">'
835: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
836: .' '
837: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
838: ,'<a href="'.$helplink.'">','</a>')
839: .'</p><br />';
1.215 raeburn 840: $env{'form.phase'} = '';
841: &print_username_entry_form($r,$context,$response);
842: return;
843: }
1.188 raeburn 844: $newuser = 1;
1.193 raeburn 845: my $checkhash;
846: my $checks = { 'username' => 1 };
1.196 raeburn 847: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 848: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 849: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
850: if (ref($alerts{'username'}) eq 'HASH') {
851: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
852: my $domdesc =
1.193 raeburn 853: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 854: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
855: my $userchkmsg;
856: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
857: $userchkmsg =
858: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 859: $domdesc,1).
860: &Apache::loncommon::user_rule_formats($ccdomain,
861: $domdesc,$curr_rules{$ccdomain}{'username'},
862: 'username');
1.196 raeburn 863: }
1.215 raeburn 864: $env{'form.phase'} = '';
1.207 raeburn 865: &print_username_entry_form($r,$context,$userchkmsg);
1.196 raeburn 866: return;
1.215 raeburn 867: }
1.193 raeburn 868: }
1.185 raeburn 869: }
1.187 raeburn 870: } else {
1.188 raeburn 871: $newuser = 0;
1.185 raeburn 872: }
1.160 raeburn 873: if ($response) {
1.215 raeburn 874: $response = '<br />'.$response;
1.160 raeburn 875: }
1.149 raeburn 876:
1.52 matthew 877: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 878: my $dc_setcourse_code = '';
1.119 raeburn 879: my $nondc_setsection_code = '';
1.112 albertel 880: my %loaditem;
1.114 albertel 881:
1.216 raeburn 882: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 883:
1.216 raeburn 884: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
885: $groupslist,$newuser,$formname,\%loaditem);
1.233 raeburn 886: my $args = {'add_entries' => \%loaditem};
887: if ($env{'form.popup'}) {
888: $args->{'no_nav_bar'} = 1;
889: }
1.110 albertel 890: my $start_page =
1.233 raeburn 891: &Apache::loncommon::start_page('User Management',$js,$args);
1.216 raeburn 892: my %breadcrumb_text = &singleuser_breadcrumb();
1.160 raeburn 893: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 894: ({href=>"javascript:backPage($form)",
895: text=>$breadcrumb_text{'search'},
1.160 raeburn 896: faq=>282,bug=>'Instructor Interface',});
897:
898: if ($env{'form.phase'} eq 'userpicked') {
899: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 900: ({href=>"javascript:backPage($form,'get_user_info','select')",
901: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 902: faq=>282,bug=>'Instructor Interface',});
903: }
904: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 905: ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
906: text=>$breadcrumb_text{'modify'},
1.160 raeburn 907: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 908: my $helpitem = 'Course_Change_Privileges';
909: if ($env{'form.action'} eq 'singlestudent') {
910: $helpitem = 'Course_Add_Student';
911: }
912: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
913: $helpitem);
1.3 www 914:
1.25 matthew 915: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 916: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 917: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 918: <input type="hidden" name="ccuname" value="$ccuname" />
919: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 920: <input type="hidden" name="pres_value" value="" />
921: <input type="hidden" name="pres_type" value="" />
922: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 923: ENDFORMINFO
1.2 www 924: my %inccourses;
1.135 raeburn 925: foreach my $key (keys(%env)) {
1.139 albertel 926: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1.2 www 927: $inccourses{$1.'_'.$2}=1;
928: }
1.24 matthew 929: }
1.216 raeburn 930: if ($newuser) {
1.134 raeburn 931: my $portfolioform;
1.267 raeburn 932: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
933: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
934: # Current user has quota or user tools modification privileges
1.188 raeburn 935: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 936: }
1.227 raeburn 937: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 938: my %lt=&Apache::lonlocal::texthash(
939: 'cnu' => 'Create New User',
1.213 raeburn 940: 'ast' => 'as a student',
1.188 raeburn 941: 'ind' => 'in domain',
942: 'lg' => 'Login Data',
1.190 raeburn 943: 'hs' => "Home Server",
1.188 raeburn 944: );
1.185 raeburn 945: $r->print(<<ENDTITLE);
1.110 albertel 946: $start_page
1.160 raeburn 947: $crumbs
948: $response
1.25 matthew 949: $forminfo
1.31 matthew 950: <script type="text/javascript" language="Javascript">
1.301 bisitz 951: // <![CDATA[
1.20 harris41 952: $loginscript
1.301 bisitz 953: // ]]>
1.31 matthew 954: </script>
1.20 harris41 955: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 956: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 957: ENDTITLE
1.213 raeburn 958: if ($env{'form.action'} eq 'singlestudent') {
959: $r->print(' ('.$lt{'ast'}.')');
960: }
961: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 962: my $personal_table =
1.210 raeburn 963: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
964: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 965: $r->print($personal_table);
1.304 raeburn 966: #FIXME
1.187 raeburn 967: my ($home_server_pick,$numlib) =
968: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
969: 'default','hide');
970: if ($numlib > 1) {
971: $r->print("
1.185 raeburn 972: <br />
1.187 raeburn 973: $lt{'hs'}: $home_server_pick
974: <br />");
975: } else {
976: $r->print($home_server_pick);
977: }
1.304 raeburn 978: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
979: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses in this Domain?').'</h3>'.
980: &Apache::loncommon::start_data_table().
981: &build_tools_display($ccuname,$ccdomain,
982: 'requestcourses').
983: &Apache::loncommon::end_data_table());
984: }
1.188 raeburn 985: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
986: $lt{'lg'}.'</h3>');
1.185 raeburn 987: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 988: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
989: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
990: my ($rules,$ruleorder) =
991: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 992: if (ref($rules) eq 'HASH') {
1.193 raeburn 993: if (ref($rules->{$matchedrule}) eq 'HASH') {
994: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 995: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 996: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 997: } else {
1.193 raeburn 998: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 999: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1000: if ($authtype =~ /^krb(4|5)$/) {
1001: my $ver = $1;
1002: if ($authparm ne '') {
1003: $fixedauth = <<"KERB";
1004: <input type="hidden" name="login" value="krb" />
1005: <input type="hidden" name="krbver" value="$ver" />
1006: <input type="hidden" name="krbarg" value="$authparm" />
1007: KERB
1008: }
1009: } else {
1010: $fixedauth =
1011: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1012: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1013: $fixedauth .=
1014: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1015: } else {
1.273 raeburn 1016: if ($authtype eq 'int') {
1017: $varauth = '<br />'.
1.301 bisitz 1018: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1019: } elsif ($authtype eq 'loc') {
1020: $varauth = '<br />'.
1021: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1022: } else {
1023: $varauth =
1.185 raeburn 1024: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1025: }
1.185 raeburn 1026: }
1027: }
1028: }
1029: } else {
1.190 raeburn 1030: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1031: }
1032: }
1033: if ($authmsg) {
1034: $r->print(<<ENDAUTH);
1035: $fixedauth
1036: $authmsg
1037: $varauth
1038: ENDAUTH
1039: }
1040: } else {
1.190 raeburn 1041: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1042: }
1.215 raeburn 1043: $r->print($portfolioform);
1044: if ($env{'form.action'} eq 'singlestudent') {
1045: $r->print(&date_sections_select($context,$newuser,$formname,
1046: $permission));
1047: }
1048: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1049: } else { # user already exists
1.79 albertel 1050: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1051: 'cup' => "Modify existing user: ",
1.213 raeburn 1052: 'ens' => "Enroll one student: ",
1.72 sakharuk 1053: 'id' => "in domain",
1054: );
1.26 matthew 1055: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1056: $start_page
1.160 raeburn 1057: $crumbs
1.25 matthew 1058: $forminfo
1.213 raeburn 1059: <h2>
1.26 matthew 1060: ENDCHANGEUSER
1.213 raeburn 1061: if ($env{'form.action'} eq 'singlestudent') {
1062: $r->print($lt{'ens'});
1063: } else {
1064: $r->print($lt{'cup'});
1065: }
1066: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1067: "\n".'<div class="LC_left_float">');
1.206 raeburn 1068: my ($personal_table,$showforceid) =
1.210 raeburn 1069: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1070: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1071: $r->print($personal_table);
1072: if ($showforceid) {
1.203 raeburn 1073: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 1074: }
1.275 raeburn 1075: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.300 raeburn 1076: $r->print('<h3>'.&mt('User Can Request Creation of Courses in this Domain?').'</h3>'.
1077: &Apache::loncommon::start_data_table());
1078: if ($env{'request.role.domain'} eq $ccdomain) {
1079: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1080: } else {
1081: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1082: $env{'request.role.domain'}));
1083: }
1084: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1085: }
1.199 raeburn 1086: $r->print('</div>');
1.227 raeburn 1087: my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
1.275 raeburn 1088: my ($user_quota_text,$user_tools_text,$user_reqcrs_text);
1.267 raeburn 1089: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1090: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1091: # Current user has quota modification privileges
1092: $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
1.267 raeburn 1093: }
1094: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1095: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1096: # Get the user's portfolio information
1097: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
1098: $ccdomain,$ccuname);
1099: my %lt=&Apache::lonlocal::texthash(
1100: 'dska' => "Disk space allocated to user's portfolio files",
1101: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1102: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1103: );
1104: $user_quota_text = <<ENDNOPORTPRIV;
1.188 raeburn 1105: <h3>$lt{'dska'}</h3>
1106: $lt{'youd'} $lt{'ichr'}: $ccdomain
1107: ENDNOPORTPRIV
1.267 raeburn 1108: }
1109: }
1110: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1111: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1112: my %lt=&Apache::lonlocal::texthash(
1113: 'utav' => "User Tools Availability",
1.285 weissno 1114: 'yodo' => "You do not have privileges to modify Portfolio, Blog or Personal Information Page settings for this user.",
1.267 raeburn 1115: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1116: );
1117: $user_tools_text = <<ENDNOTOOLSPRIV;
1118: <h3>$lt{'utav'}</h3>
1119: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1120: ENDNOTOOLSPRIV
1121: }
1.188 raeburn 1122: }
1123: if ($user_auth_text ne '') {
1124: $r->print('<div class="LC_left_float">'.$user_auth_text);
1125: if ($user_quota_text ne '') {
1126: $r->print($user_quota_text);
1127: }
1.267 raeburn 1128: if ($user_tools_text ne '') {
1129: $r->print($user_tools_text);
1130: }
1.213 raeburn 1131: if ($env{'form.action'} eq 'singlestudent') {
1132: $r->print(&date_sections_select($context,$newuser,$formname));
1133: }
1.188 raeburn 1134: } elsif ($user_quota_text ne '') {
1.213 raeburn 1135: $r->print('<div class="LC_left_float">'.$user_quota_text);
1.267 raeburn 1136: if ($user_tools_text ne '') {
1137: $r->print($user_tools_text);
1138: }
1139: if ($env{'form.action'} eq 'singlestudent') {
1140: $r->print(&date_sections_select($context,$newuser,$formname));
1141: }
1142: } elsif ($user_tools_text ne '') {
1143: $r->print('<div class="LC_left_float">'.$user_tools_text);
1.213 raeburn 1144: if ($env{'form.action'} eq 'singlestudent') {
1145: $r->print(&date_sections_select($context,$newuser,$formname));
1146: }
1147: } else {
1148: if ($env{'form.action'} eq 'singlestudent') {
1149: $r->print('<div class="LC_left_float">'.
1150: &date_sections_select($context,$newuser,$formname));
1151: }
1.188 raeburn 1152: }
1.213 raeburn 1153: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.217 raeburn 1154: if ($env{'form.action'} ne 'singlestudent') {
1155: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
1156: }
1.25 matthew 1157: } ## End of new user/old user logic
1.218 raeburn 1158:
1159: if ($env{'form.action'} eq 'singlestudent') {
1.301 bisitz 1160: $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1161: } else {
1162: $r->print('<h3>'.&mt('Add Roles').'</h3>');
1163: my $addrolesdisplay = 0;
1164: if ($context eq 'domain' || $context eq 'author') {
1165: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1166: }
1167: if ($context eq 'domain') {
1168: my $add_domainroles = &new_domain_roles($r);
1169: if (!$addrolesdisplay) {
1170: $addrolesdisplay = $add_domainroles;
1.2 www 1171: }
1.218 raeburn 1172: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
1.301 bisitz 1173: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1174: } elsif ($context eq 'author') {
1175: if ($addrolesdisplay) {
1.262 schafran 1176: $r->print('<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1177: if ($newuser) {
1.301 bisitz 1178: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1179: } else {
1.301 bisitz 1180: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1181: }
1.188 raeburn 1182: } else {
1.218 raeburn 1183: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
1184: &mt('Back to previous page').'</a>');
1.188 raeburn 1185: }
1186: } else {
1.218 raeburn 1187: $r->print(&course_level_table(%inccourses));
1.301 bisitz 1188: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1189: }
1.88 raeburn 1190: }
1.188 raeburn 1191: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1192: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 1193: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 1194: $r->print("</form>".&Apache::loncommon::end_page());
1.218 raeburn 1195: return;
1.2 www 1196: }
1.1 www 1197:
1.213 raeburn 1198: sub singleuser_breadcrumb {
1199: my %breadcrumb_text;
1200: if ($env{'form.action'} eq 'singlestudent') {
1201: $breadcrumb_text{'search'} = 'Enroll a student';
1202: $breadcrumb_text{'userpicked'} = 'Select a user',
1203: $breadcrumb_text{'modify'} = 'Set section/dates',
1204: } else {
1.229 raeburn 1205: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1206: $breadcrumb_text{'userpicked'} = 'Select a user',
1207: $breadcrumb_text{'modify'} = 'Set user role',
1208: }
1209: return %breadcrumb_text;
1210: }
1211:
1212: sub date_sections_select {
1213: my ($context,$newuser,$formname,$permission) = @_;
1214: my $cid = $env{'request.course.id'};
1215: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1216: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1217: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1218: undef,$formname,$permission);
1219: my $rowtitle = 'Section';
1220: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
1221: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1222: $permission);
1223: my $output = $date_table.$secbox;
1224: return $output;
1225: }
1226:
1.216 raeburn 1227: sub validation_javascript {
1228: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
1229: $loaditem) = @_;
1230: my $dc_setcourse_code = '';
1231: my $nondc_setsection_code = '';
1232: if ($context eq 'domain') {
1233: my $dcdom = $env{'request.role.domain'};
1234: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1235: $dc_setcourse_code =
1236: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1237: } else {
1.227 raeburn 1238: my $checkauth;
1239: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1240: $checkauth = 1;
1241: }
1242: if ($context eq 'course') {
1243: $nondc_setsection_code =
1244: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1245: undef,$checkauth);
1246: }
1247: if ($checkauth) {
1248: $nondc_setsection_code .=
1249: &Apache::lonuserutils::verify_authen($formname,$context);
1250: }
1.216 raeburn 1251: }
1252: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1253: $nondc_setsection_code,$groupslist);
1254: my ($jsback,$elements) = &crumb_utilities();
1255: $js .= "\n".
1.301 bisitz 1256: '<script type="text/javascript">'."\n".
1257: '// <![CDATA['."\n".
1258: $jsback."\n".
1259: '// ]]>'."\n".
1260: '</script>'."\n";
1.216 raeburn 1261: return $js;
1262: }
1263:
1.217 raeburn 1264: sub display_existing_roles {
1265: my ($r,$ccuname,$ccdomain,$inccourses) = @_;
1266: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1267: # Build up table of user roles to allow revocation and re-enabling of roles.
1268: my ($tmp) = keys(%rolesdump);
1269: if ($tmp !~ /^(con_lost|error)/i) {
1270: my $now=time;
1271: my %lt=&Apache::lonlocal::texthash(
1272: 'rer' => "Existing Roles",
1273: 'rev' => "Revoke",
1274: 'del' => "Delete",
1275: 'ren' => "Re-Enable",
1276: 'rol' => "Role",
1277: 'ext' => "Extent",
1278: 'sta' => "Start",
1279: 'end' => "End",
1280: );
1281: my (%roletext,%sortrole,%roleclass,%rolepriv);
1282: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1283: my $b1=join('_',(split('_',$b))[1,0]);
1284: return $a1 cmp $b1;
1285: } keys(%rolesdump)) {
1286: next if ($area =~ /^rolesdef/);
1287: my $envkey=$area;
1288: my $role = $rolesdump{$area};
1289: my $thisrole=$area;
1290: $area =~ s/\_\w\w$//;
1291: my ($role_code,$role_end_time,$role_start_time) =
1292: split(/_/,$role);
1293: # Is this a custom role? Get role owner and title.
1294: my ($croleudom,$croleuname,$croletitle)=
1295: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1296: my $allowed=0;
1297: my $delallowed=0;
1298: my $sortkey=$role_code;
1299: my $class='Unknown';
1300: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1301: $class='Course';
1302: my ($coursedom,$coursedir) = ($1,$2);
1303: $sortkey.="\0$coursedom";
1304: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1305: my %coursedata=
1306: &Apache::lonnet::coursedescription($1.'_'.$2);
1307: my $carea;
1308: if (defined($coursedata{'description'})) {
1309: $carea=$coursedata{'description'}.
1310: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1.259 bisitz 1311: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1.217 raeburn 1312: $sortkey.="\0".$coursedata{'description'};
1313: $class=$coursedata{'type'};
1314: } else {
1315: $carea=&mt('Unavailable course').': '.$area;
1316: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1317: }
1318: $sortkey.="\0$coursedir";
1319: $inccourses->{$1.'_'.$2}=1;
1320: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
1321: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1322: $allowed=1;
1323: }
1324: if ((&Apache::lonnet::allowed('dro',$1)) ||
1325: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1326: $delallowed=1;
1327: }
1328: # - custom role. Needs more info, too
1329: if ($croletitle) {
1330: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
1331: $allowed=1;
1332: $thisrole.='.'.$role_code;
1333: }
1334: }
1335: # Compute the background color based on $area
1336: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1337: $carea.='<br />Section: '.$3;
1338: $sortkey.="\0$3";
1339: if (!$allowed) {
1340: if ($env{'request.course.sec'} eq $3) {
1341: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1342: $allowed = 1;
1343: }
1344: }
1345: }
1346: }
1347: $area=$carea;
1348: } else {
1349: $sortkey.="\0".$area;
1350: # Determine if current user is able to revoke privileges
1351: if ($area=~m{^/($match_domain)/}) {
1352: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1353: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1354: $allowed=1;
1355: }
1356: if (((&Apache::lonnet::allowed('dro',$1)) ||
1357: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1358: ($role_code ne 'dc')) {
1359: $delallowed=1;
1360: }
1361: } else {
1362: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1363: $allowed=1;
1364: }
1365: }
1366: if ($role_code eq 'ca' || $role_code eq 'au') {
1367: $class='Construction Space';
1368: } elsif ($role_code eq 'su') {
1369: $class='System';
1370: } else {
1371: $class='Domain';
1372: }
1373: }
1374: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1375: $area=~m{/($match_domain)/($match_username)};
1376: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1377: $allowed=1;
1378: } else {
1379: $allowed=0;
1380: }
1381: }
1382: my $row = '';
1383: $row.= '<td>';
1384: my $active=1;
1385: $active=0 if (($role_end_time) && ($now>$role_end_time));
1386: if (($active) && ($allowed)) {
1387: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1388: } else {
1389: if ($active) {
1390: $row.=' ';
1391: } else {
1392: $row.=&mt('expired or revoked');
1393: }
1394: }
1395: $row.='</td><td>';
1396: if ($allowed && !$active) {
1397: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1398: } else {
1399: $row.=' ';
1400: }
1401: $row.='</td><td>';
1402: if ($delallowed) {
1403: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1404: } else {
1405: $row.=' ';
1406: }
1407: my $plaintext='';
1408: if (!$croletitle) {
1409: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1410: } else {
1411: $plaintext=
1412: "Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
1413: }
1414: $row.= '</td><td>'.$plaintext.
1415: '</td><td>'.$area.
1416: '</td><td>'.($role_start_time?localtime($role_start_time)
1417: : ' ' ).
1418: '</td><td>'.($role_end_time ?localtime($role_end_time)
1419: : ' ' )
1420: ."</td>";
1421: $sortrole{$sortkey}=$envkey;
1422: $roletext{$envkey}=$row;
1423: $roleclass{$envkey}=$class;
1424: $rolepriv{$envkey}=$allowed;
1425: #$r->print($row);
1426: } # end of foreach (table building loop)
1427: my $rolesdisplay = 0;
1428: my %output = ();
1429: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1430: $output{$type} = '';
1431: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1432: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1433: $output{$type}.=
1434: &Apache::loncommon::start_data_table_row().
1435: $roletext{$sortrole{$which}}.
1436: &Apache::loncommon::end_data_table_row();
1437: }
1438: }
1439: unless($output{$type} eq '') {
1440: $output{$type} = '<tr class="LC_info_row">'.
1441: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1442: $output{$type};
1443: $rolesdisplay = 1;
1444: }
1445: }
1446: if ($rolesdisplay == 1) {
1.290 bisitz 1447: my $contextrole='';
1448: if ($env{'request.course.id'}) {
1449: $contextrole = 'Existing Roles in this Course';
1450: } elsif ($env{'request.role'} =~ /^au\./) {
1451: $contextrole = 'Existing Co-Author Roles in your Construction Space';
1452: } else {
1453: $contextrole = 'Existing Roles in this Domain';
1454: }
1.217 raeburn 1455: $r->print('
1456: <h3>'.$lt{'rer'}.'</h3>'.
1.290 bisitz 1457: '<div>'.&mt($contextrole).'</div>'.
1.217 raeburn 1458: &Apache::loncommon::start_data_table("LC_createuser").
1459: &Apache::loncommon::start_data_table_header_row().
1460: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1461: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1462: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1463: &Apache::loncommon::end_data_table_header_row());
1464: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1465: if ($output{$type}) {
1466: $r->print($output{$type}."\n");
1467: }
1468: }
1469: $r->print(&Apache::loncommon::end_data_table());
1470: }
1471: } # End of check for keys in rolesdump
1472: return;
1473: }
1474:
1.218 raeburn 1475: sub new_coauthor_roles {
1476: my ($r,$ccuname,$ccdomain) = @_;
1477: my $addrolesdisplay = 0;
1478: #
1479: # Co-Author
1480: #
1481: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1482: $env{'request.role.domain'}) &&
1483: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1484: # No sense in assigning co-author role to yourself
1485: $addrolesdisplay = 1;
1486: my $cuname=$env{'user.name'};
1487: my $cudom=$env{'request.role.domain'};
1488: my %lt=&Apache::lonlocal::texthash(
1489: 'cs' => "Construction Space",
1490: 'act' => "Activate",
1491: 'rol' => "Role",
1492: 'ext' => "Extent",
1493: 'sta' => "Start",
1494: 'end' => "End",
1495: 'cau' => "Co-Author",
1496: 'caa' => "Assistant Co-Author",
1497: 'ssd' => "Set Start Date",
1498: 'sed' => "Set End Date"
1499: );
1500: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1501: &Apache::loncommon::start_data_table()."\n".
1502: &Apache::loncommon::start_data_table_header_row()."\n".
1503: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1504: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1505: '<th>'.$lt{'end'}.'</th>'."\n".
1506: &Apache::loncommon::end_data_table_header_row()."\n".
1507: &Apache::loncommon::start_data_table_row().'
1508: <td>
1.291 bisitz 1509: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1510: </td>
1511: <td>'.$lt{'cau'}.'</td>
1512: <td>'.$cudom.'_'.$cuname.'</td>
1513: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1514: <a href=
1515: "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>
1516: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1517: <a href=
1518: "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".
1519: &Apache::loncommon::end_data_table_row()."\n".
1520: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1521: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1522: <td>'.$lt{'caa'}.'</td>
1523: <td>'.$cudom.'_'.$cuname.'</td>
1524: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1525: <a href=
1526: "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>
1527: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1528: <a href=
1529: "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".
1530: &Apache::loncommon::end_data_table_row()."\n".
1531: &Apache::loncommon::end_data_table());
1532: } elsif ($env{'request.role'} =~ /^au\./) {
1533: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1534: $env{'request.role.domain'}))) {
1535: $r->print('<span class="LC_error">'.
1536: &mt('You do not have privileges to assign co-author roles.').
1537: '</span>');
1538: } elsif (($env{'user.name'} eq $ccuname) &&
1539: ($env{'user.domain'} eq $ccdomain)) {
1540: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1541: }
1542: }
1543: return $addrolesdisplay;;
1544: }
1545:
1546: sub new_domain_roles {
1547: my ($r) = @_;
1548: my $addrolesdisplay = 0;
1549: #
1550: # Domain level
1551: #
1552: my $num_domain_level = 0;
1553: my $domaintext =
1554: '<h4>'.&mt('Domain Level').'</h4>'.
1555: &Apache::loncommon::start_data_table().
1556: &Apache::loncommon::start_data_table_header_row().
1557: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1558: &mt('Extent').'</th>'.
1559: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1560: &Apache::loncommon::end_data_table_header_row();
1561: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1562: foreach my $role ('dc','li','dg','au','sc') {
1563: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1564: my $plrole=&Apache::lonnet::plaintext($role);
1565: my %lt=&Apache::lonlocal::texthash(
1566: 'ssd' => "Set Start Date",
1567: 'sed' => "Set End Date"
1568: );
1569: $num_domain_level ++;
1570: $domaintext .=
1571: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1572: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1573: <td>'.$plrole.'</td>
1574: <td>'.$thisdomain.'</td>
1575: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1576: <a href=
1577: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1578: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1579: <a href=
1580: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1581: &Apache::loncommon::end_data_table_row();
1582: }
1583: }
1584: }
1585: $domaintext.= &Apache::loncommon::end_data_table();
1586: if ($num_domain_level > 0) {
1587: $r->print($domaintext);
1588: $addrolesdisplay = 1;
1589: }
1590: return $addrolesdisplay;
1591: }
1592:
1.188 raeburn 1593: sub user_authentication {
1.227 raeburn 1594: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1595: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1596: my $outcome;
1.188 raeburn 1597: # Check for a bad authentication type
1598: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1599: # bad authentication scheme
1600: my %lt=&Apache::lonlocal::texthash(
1601: 'err' => "ERROR",
1602: 'uuas' => "This user has an unrecognized authentication scheme",
1603: 'adcs' => "Please alert a domain coordinator of this situation",
1604: 'sldb' => "Please specify login data below",
1605: 'ld' => "Login Data"
1606: );
1607: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1608: &initialize_authen_forms($ccdomain,$formname);
1609:
1.190 raeburn 1610: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1611: $outcome = <<ENDBADAUTH;
1612: <script type="text/javascript" language="Javascript">
1.301 bisitz 1613: // <![CDATA[
1.188 raeburn 1614: $loginscript
1.301 bisitz 1615: // ]]>
1.188 raeburn 1616: </script>
1617: <span class="LC_error">$lt{'err'}:
1618: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1619: <h3>$lt{'ld'}</h3>
1620: $choices
1621: ENDBADAUTH
1622: } else {
1623: # This user is not allowed to modify the user's
1624: # authentication scheme, so just notify them of the problem
1625: $outcome = <<ENDBADAUTH;
1626: <span class="LC_error"> $lt{'err'}:
1627: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1628: </span>
1629: ENDBADAUTH
1630: }
1631: } else { # Authentication type is valid
1.227 raeburn 1632: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1633: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1634: &modify_login_block($ccdomain,$currentauth);
1635: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1636: # Current user has login modification privileges
1637: my %lt=&Apache::lonlocal::texthash (
1638: 'ld' => "Login Data",
1639: 'ccld' => "Change Current Login Data",
1640: 'enld' => "Enter New Login Data"
1641: );
1642: $outcome =
1643: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 1644: '// <![CDATA['."\n".
1.188 raeburn 1645: $loginscript."\n".
1.301 bisitz 1646: '// ]]>'."\n".
1.188 raeburn 1647: '</script>'."\n".
1648: '<h3>'.$lt{'ld'}.'</h3>'.
1649: &Apache::loncommon::start_data_table().
1.205 raeburn 1650: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1651: '<td>'.$authformnop;
1652: if ($can_modify) {
1653: $outcome .= '</td>'."\n".
1654: &Apache::loncommon::end_data_table_row().
1655: &Apache::loncommon::start_data_table_row().
1656: '<td>'.$authformcurrent.'</td>'.
1657: &Apache::loncommon::end_data_table_row()."\n";
1658: } else {
1.200 raeburn 1659: $outcome .= ' ('.$authformcurrent.')</td>'.
1660: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1661: }
1.205 raeburn 1662: foreach my $item (@authform_others) {
1663: $outcome .= &Apache::loncommon::start_data_table_row().
1664: '<td>'.$item.'</td>'.
1665: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1666: }
1.205 raeburn 1667: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 1668: } else {
1669: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1670: my %lt=&Apache::lonlocal::texthash(
1671: 'ccld' => "Change Current Login Data",
1672: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1673: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1674: );
1675: $outcome .= <<ENDNOPRIV;
1676: <h3>$lt{'ccld'}</h3>
1677: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 1678: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 1679: ENDNOPRIV
1680: }
1681: }
1682: } ## End of "check for bad authentication type" logic
1683: return $outcome;
1684: }
1685:
1.187 raeburn 1686: sub modify_login_block {
1687: my ($dom,$currentauth) = @_;
1688: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1689: my ($authnum,%can_assign) =
1690: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 1691: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 1692: if ($currentauth=~/^krb(4|5):/) {
1693: $authformcurrent=$authformkrb;
1694: if ($can_assign{'int'}) {
1.205 raeburn 1695: push(@authform_others,$authformint);
1.187 raeburn 1696: }
1697: if ($can_assign{'loc'}) {
1.205 raeburn 1698: push(@authform_others,$authformloc);
1.187 raeburn 1699: }
1700: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1701: $show_override_msg = 1;
1702: }
1703: } elsif ($currentauth=~/^internal:/) {
1704: $authformcurrent=$authformint;
1705: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1706: push(@authform_others,$authformkrb);
1.187 raeburn 1707: }
1708: if ($can_assign{'loc'}) {
1.205 raeburn 1709: push(@authform_others,$authformloc);
1.187 raeburn 1710: }
1711: if ($can_assign{'int'}) {
1712: $show_override_msg = 1;
1713: }
1714: } elsif ($currentauth=~/^unix:/) {
1715: $authformcurrent=$authformfsys;
1716: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1717: push(@authform_others,$authformkrb);
1.187 raeburn 1718: }
1719: if ($can_assign{'int'}) {
1.205 raeburn 1720: push(@authform_others,$authformint);
1.187 raeburn 1721: }
1722: if ($can_assign{'loc'}) {
1.205 raeburn 1723: push(@authform_others,$authformloc);
1.187 raeburn 1724: }
1725: if ($can_assign{'fsys'}) {
1726: $show_override_msg = 1;
1727: }
1728: } elsif ($currentauth=~/^localauth:/) {
1729: $authformcurrent=$authformloc;
1730: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1731: push(@authform_others,$authformkrb);
1.187 raeburn 1732: }
1733: if ($can_assign{'int'}) {
1.205 raeburn 1734: push(@authform_others,$authformint);
1.187 raeburn 1735: }
1736: if ($can_assign{'loc'}) {
1737: $show_override_msg = 1;
1738: }
1739: }
1740: if ($show_override_msg) {
1.205 raeburn 1741: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
1742: '</td></tr>'."\n".
1743: '<tr><td> </td>'.
1744: '<td><b>'.&mt('Currently in use').'</b></td>'.
1745: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 1746: &mt('will override current values').
1.205 raeburn 1747: '</span></td></tr></table>';
1.187 raeburn 1748: }
1.205 raeburn 1749: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 1750: }
1751:
1.188 raeburn 1752: sub personal_data_display {
1.252 raeburn 1753: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 1754: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 1755: my @userinfo = ('firstname','middlename','lastname','generation',
1756: 'permanentemail','id');
1.252 raeburn 1757: my $rowcount = 0;
1758: my $editable = 0;
1.286 raeburn 1759: %canmodify_status =
1760: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1761: ['inststatus'],$rolesarray);
1.253 raeburn 1762: if (!$newuser) {
1.188 raeburn 1763: # Get the users information
1764: %userenv = &Apache::lonnet::get('environment',
1765: ['firstname','middlename','lastname','generation',
1.286 raeburn 1766: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 1767: %canmodify =
1768: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 1769: \@userinfo,$rolesarray);
1.257 raeburn 1770: } elsif ($context eq 'selfcreate') {
1771: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
1772: $inst_results,$rolesarray);
1.188 raeburn 1773: }
1774: my %lt=&Apache::lonlocal::texthash(
1775: 'pd' => "Personal Data",
1776: 'firstname' => "First Name",
1777: 'middlename' => "Middle Name",
1778: 'lastname' => "Last Name",
1779: 'generation' => "Generation",
1780: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 1781: 'id' => "Student/Employee ID",
1.286 raeburn 1782: 'lg' => "Login Data",
1783: 'inststatus' => "Affiliation",
1.188 raeburn 1784: );
1785: my %textboxsize = (
1786: firstname => '15',
1787: middlename => '15',
1788: lastname => '15',
1789: generation => '5',
1790: permanentemail => '25',
1791: id => '15',
1792: );
1793: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1794: $output = '<h3>'.$lt{'pd'}.'</h3>'.
1795: &Apache::lonhtmlcommon::start_pick_box();
1796: foreach my $item (@userinfo) {
1797: my $rowtitle = $lt{$item};
1.252 raeburn 1798: my $hiderow = 0;
1.188 raeburn 1799: if ($item eq 'generation') {
1800: $rowtitle = $genhelp.$rowtitle;
1801: }
1.252 raeburn 1802: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 1803: if ($newuser) {
1.210 raeburn 1804: if (ref($inst_results) eq 'HASH') {
1805: if ($inst_results->{$item} ne '') {
1.252 raeburn 1806: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 1807: } else {
1.252 raeburn 1808: if ($context eq 'selfcreate') {
1809: if ($canmodify{$item}) {
1810: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1811: $editable ++;
1812: } else {
1813: $hiderow = 1;
1814: }
1.253 raeburn 1815: } else {
1816: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1817: }
1.210 raeburn 1818: }
1.188 raeburn 1819: } else {
1.252 raeburn 1820: if ($context eq 'selfcreate') {
1.287 raeburn 1821: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
1822: $row .= $ccuname;
1.252 raeburn 1823: } else {
1.287 raeburn 1824: if ($canmodify{$item}) {
1825: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1826: $editable ++;
1827: } else {
1828: $hiderow = 1;
1829: }
1.252 raeburn 1830: }
1.253 raeburn 1831: } else {
1832: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1833: }
1.188 raeburn 1834: }
1835: } else {
1.219 raeburn 1836: if ($canmodify{$item}) {
1.252 raeburn 1837: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 1838: } else {
1.252 raeburn 1839: $row .= $userenv{$item};
1.188 raeburn 1840: }
1.206 raeburn 1841: if ($item eq 'id') {
1.219 raeburn 1842: $showforceid = $canmodify{$item};
1843: }
1.188 raeburn 1844: }
1.252 raeburn 1845: $row .= &Apache::lonhtmlcommon::row_closure(1);
1846: if (!$hiderow) {
1847: $output .= $row;
1848: $rowcount ++;
1849: }
1.188 raeburn 1850: }
1.286 raeburn 1851: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
1852: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
1853: if (ref($types) eq 'ARRAY') {
1854: if (@{$types} > 0) {
1855: my ($hiderow,$shown);
1856: if ($canmodify_status{'inststatus'}) {
1857: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
1858: } else {
1859: $shown .= $userenv{'inststatus'};
1860: if ($userenv{'inststatus'} eq '') {
1861: $hiderow = 1;
1862: }
1863: }
1864: if (!$hiderow) {
1865: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
1866: $shown.&Apache::lonhtmlcommon::row_closure(1);
1867: if ($context eq 'selfcreate') {
1868: $rowcount ++;
1869: }
1870: $output .= $row;
1871: }
1872: }
1873: }
1874: }
1.188 raeburn 1875: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1876: if (wantarray) {
1.252 raeburn 1877: if ($context eq 'selfcreate') {
1878: return($output,$rowcount,$editable);
1879: } else {
1880: return ($output,$showforceid);
1881: }
1.206 raeburn 1882: } else {
1883: return $output;
1884: }
1.188 raeburn 1885: }
1886:
1.286 raeburn 1887: sub pick_inst_statuses {
1888: my ($curr,$usertypes,$types) = @_;
1889: my ($output,$rem,@currtypes);
1890: if ($curr ne '') {
1891: @currtypes = map { &unescape($_); } split(/:/,$curr);
1892: }
1893: my $numinrow = 2;
1894: if (ref($types) eq 'ARRAY') {
1895: $output = '<table>';
1896: my $lastcolspan;
1897: for (my $i=0; $i<@{$types}; $i++) {
1898: if (defined($usertypes->{$types->[$i]})) {
1899: my $rem = $i%($numinrow);
1900: if ($rem == 0) {
1901: if ($i<@{$types}-1) {
1902: if ($i > 0) {
1903: $output .= '</tr>';
1904: }
1905: $output .= '<tr>';
1906: }
1907: } elsif ($i==@{$types}-1) {
1908: my $colsleft = $numinrow - $rem;
1909: if ($colsleft > 1) {
1910: $lastcolspan = ' colspan="'.$colsleft.'"';
1911: }
1912: }
1913: my $check = ' ';
1914: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
1915: $check = ' checked="checked" ';
1916: }
1917: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
1918: '<span class="LC_nobreak"><label>'.
1919: '<input type="checkbox" name="inststatus" '.
1920: 'value="'.$types->[$i].'"'.$check.'/>'.
1921: $usertypes->{$types->[$i]}.'</label></span></td>';
1922: }
1923: }
1924: $output .= '</tr></table>';
1925: }
1926: return $output;
1927: }
1928:
1.257 raeburn 1929: sub selfcreate_canmodify {
1930: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
1931: if (ref($inst_results) eq 'HASH') {
1932: my @inststatuses = &get_inststatuses($inst_results);
1933: if (@inststatuses == 0) {
1934: @inststatuses = ('default');
1935: }
1936: $rolesarray = \@inststatuses;
1937: }
1938: my %canmodify =
1939: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
1940: $rolesarray);
1941: return %canmodify;
1942: }
1943:
1.252 raeburn 1944: sub get_inststatuses {
1945: my ($insthashref) = @_;
1946: my @inststatuses = ();
1947: if (ref($insthashref) eq 'HASH') {
1948: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
1949: @inststatuses = @{$insthashref->{'inststatus'}};
1950: }
1951: }
1952: return @inststatuses;
1953: }
1954:
1.4 www 1955: # ================================================================= Phase Three
1.42 matthew 1956: sub update_user_data {
1.206 raeburn 1957: my ($r,$context) = @_;
1.101 albertel 1958: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1959: $env{'form.ccdomain'});
1.27 matthew 1960: # Error messages
1.188 raeburn 1961: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1962: my $end = '</span><br /><br />';
1963: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1964: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 1965: &mt('Return to previous page').'</a>'.
1966: &Apache::loncommon::end_page();
1967: my $now = time;
1.40 www 1968: my $title;
1.101 albertel 1969: if (exists($env{'form.makeuser'})) {
1.40 www 1970: $title='Set Privileges for New User';
1971: } else {
1972: $title='Modify User Privileges';
1973: }
1.213 raeburn 1974: my $newuser = 0;
1.160 raeburn 1975: my ($jsback,$elements) = &crumb_utilities();
1976: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 1977: '// <![CDATA['."\n".
1978: $jsback."\n".
1979: '// ]]>'."\n".
1980: '</script>'."\n";
1.213 raeburn 1981: my %breadcrumb_text = &singleuser_breadcrumb();
1.233 raeburn 1982: my $args;
1983: if ($env{'form.popup'}) {
1984: $args->{'no_nav_bar'} = 1;
1985: } else {
1986: $args = undef;
1987: }
1988: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 1989: &Apache::lonhtmlcommon::add_breadcrumb
1990: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1991: text=>$breadcrumb_text{'search'},
1.160 raeburn 1992: faq=>282,bug=>'Instructor Interface',});
1993: if ($env{'form.prevphase'} eq 'userpicked') {
1994: &Apache::lonhtmlcommon::add_breadcrumb
1995: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1996: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1997: faq=>282,bug=>'Instructor Interface',});
1998: }
1999: &Apache::lonhtmlcommon::add_breadcrumb
2000: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 2001: text=>$breadcrumb_text{'modify'},
1.160 raeburn 2002: faq=>282,bug=>'Instructor Interface',},
2003: {href=>"/adm/createuser",
2004: text=>"Result",
2005: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2006: my $helpitem = 'Course_Change_Privileges';
2007: if ($env{'form.action'} eq 'singlestudent') {
2008: $helpitem = 'Course_Add_Student';
2009: }
2010: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2011: $helpitem));
1.188 raeburn 2012: $r->print(&update_result_form($uhome));
1.27 matthew 2013: # Check Inputs
1.101 albertel 2014: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2015: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2016: return;
2017: }
1.138 albertel 2018: if ( $env{'form.ccuname'} ne
2019: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2020: $r->print($error.&mt('Invalid login name.').' '.
2021: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2022: $end.$rtnlink);
1.27 matthew 2023: return;
2024: }
1.101 albertel 2025: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2026: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2027: return;
2028: }
1.138 albertel 2029: if ( $env{'form.ccdomain'} ne
2030: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2031: $r->print($error.&mt('Invalid domain name.').' '.
2032: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2033: $end.$rtnlink);
1.27 matthew 2034: return;
2035: }
1.219 raeburn 2036: if ($uhome eq 'no_host') {
2037: $newuser = 1;
2038: }
1.101 albertel 2039: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2040: # Modifying an existing user, so check the validity of the name
2041: if ($uhome eq 'no_host') {
1.73 sakharuk 2042: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2043: $env{'form.ccuname'}.&mt(' in domain ').
2044: $env{'form.ccdomain'}.'.');
1.29 matthew 2045: return;
2046: }
2047: }
1.27 matthew 2048: # Determine authentication method and password for the user being modified
2049: my $amode='';
2050: my $genpwd='';
1.101 albertel 2051: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2052: $amode='krb';
1.101 albertel 2053: $amode.=$env{'form.krbver'};
2054: $genpwd=$env{'form.krbarg'};
2055: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2056: $amode='internal';
1.101 albertel 2057: $genpwd=$env{'form.intarg'};
2058: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2059: $amode='unix';
1.101 albertel 2060: $genpwd=$env{'form.fsysarg'};
2061: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2062: $amode='localauth';
1.101 albertel 2063: $genpwd=$env{'form.locarg'};
1.27 matthew 2064: $genpwd=" " if (!$genpwd);
1.101 albertel 2065: } elsif (($env{'form.login'} eq 'nochange') ||
2066: ($env{'form.login'} eq '' )) {
1.34 matthew 2067: # There is no need to tell the user we did not change what they
2068: # did not ask us to change.
1.35 matthew 2069: # If they are creating a new user but have not specified login
2070: # information this will be caught below.
1.30 matthew 2071: } else {
1.193 raeburn 2072: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 2073: return;
1.27 matthew 2074: }
1.164 albertel 2075:
1.188 raeburn 2076: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
2077: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 2078: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.267 raeburn 2079: my @usertools = ('aboutme','blog','portfolio');
1.299 raeburn 2080: my @requestcourses = ('official','unofficial','community');
1.286 raeburn 2081: my ($othertitle,$usertypes,$types) =
2082: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.101 albertel 2083: if ($env{'form.makeuser'}) {
1.164 albertel 2084: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2085: # Check for the authentication mode and password
2086: if (! $amode || ! $genpwd) {
1.193 raeburn 2087: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2088: return;
1.18 albertel 2089: }
1.29 matthew 2090: # Determine desired host
1.101 albertel 2091: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2092: if (lc($desiredhost) eq 'default') {
2093: $desiredhost = undef;
2094: } else {
1.147 albertel 2095: my %home_servers =
2096: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2097: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2098: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2099: return;
2100: }
2101: }
2102: # Check ID format
2103: my %checkhash;
2104: my %checks = ('id' => 1);
2105: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2106: 'newuser' => $newuser,
1.196 raeburn 2107: 'id' => $env{'form.cid'},
1.193 raeburn 2108: );
1.196 raeburn 2109: if ($env{'form.cid'} ne '') {
2110: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2111: \%rulematch,\%inst_results,\%curr_rules);
2112: if (ref($alerts{'id'}) eq 'HASH') {
2113: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2114: my $domdesc =
2115: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2116: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2117: my $userchkmsg;
2118: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2119: $userchkmsg =
2120: &Apache::loncommon::instrule_disallow_msg('id',
2121: $domdesc,1).
2122: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2123: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2124: }
2125: $r->print($error.&mt('Invalid ID format').$end.
2126: $userchkmsg.$rtnlink);
2127: return;
2128: }
2129: }
1.29 matthew 2130: }
2131: }
1.27 matthew 2132: # Call modifyuser
2133: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2134: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2135: $amode,$genpwd,$env{'form.cfirstname'},
2136: $env{'form.cmiddlename'},$env{'form.clastname'},
2137: $env{'form.cgeneration'},undef,$desiredhost,
2138: $env{'form.cpermanentemail'});
1.77 www 2139: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2140: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2141: $env{'form.ccdomain'});
1.267 raeburn 2142: my (%changeHash,%newcustom,%changed);
2143: if ($uhome ne 'no_host') {
2144: if ($env{'form.customquota'} == 1) {
2145: if ($env{'form.portfolioquota'} eq '') {
2146: $newcustom{'quota'} = 0;
2147: } else {
2148: $newcustom{'quota'} = $env{'form.portfolioquota'};
2149: $newcustom{'quota'} =~ s/[^\d\.]//g;
2150: }
2151: $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
2152: }
2153: foreach my $item (@usertools) {
2154: if ($env{'form.custom'.$item} == 1) {
2155: $newcustom{$item} = $env{'form.tools_'.$item};
1.275 raeburn 2156: $changed{$item} = &tool_admin($item,$newcustom{$item},
2157: \%changeHash,'tools');
2158: }
2159: }
1.279 raeburn 2160: foreach my $item (@requestcourses) {
1.306 ! raeburn 2161: $newcustom{$item} = $env{'form.crsreq_'.$item};
! 2162: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
! 2163: $newcustom{$item} .= '=';
! 2164: unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
! 2165: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
! 2166: }
! 2167: }
1.279 raeburn 2168: $changed{$item} = &tool_admin($item,$newcustom{$item},
2169: \%changeHash,'requestcourses');
1.232 raeburn 2170: }
1.286 raeburn 2171: if (exists($env{'form.inststatus'})) {
2172: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2173: if (@inststatuses > 0) {
2174: $changeHash{'inststatus'} = join(',',@inststatuses);
2175: $changed{'inststatus'} = $changeHash{'inststatus'};
2176: }
2177: }
1.267 raeburn 2178: if (keys(%changed)) {
1.232 raeburn 2179: $changeHash{'firstname'} = $env{'form.cfirstname'};
2180: $changeHash{'middlename'} = $env{'form.cmiddlename'};
2181: $changeHash{'lastname'} = $env{'form.clastname'};
2182: $changeHash{'generation'} = $env{'form.cgeneration'};
2183: $changeHash{'id'} = $env{'form.cid'};
2184: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 2185: my $chgresult =
2186: &Apache::lonnet::put('environment',\%changeHash,
2187: $env{'form.ccdomain'},$env{'form.ccuname'});
2188: }
1.232 raeburn 2189: }
1.219 raeburn 2190: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2191: &Apache::lonnet::hostname($uhome));
1.101 albertel 2192: } elsif (($env{'form.login'} ne 'nochange') &&
2193: ($env{'form.login'} ne '' )) {
1.27 matthew 2194: # Modify user privileges
2195: if (! $amode || ! $genpwd) {
1.193 raeburn 2196: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2197: return;
1.20 harris41 2198: }
1.27 matthew 2199: # Only allow authentification modification if the person has authority
1.101 albertel 2200: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2201: $r->print('Modifying authentication: '.
1.31 matthew 2202: &Apache::lonnet::modifyuserauth(
1.101 albertel 2203: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2204: $amode,$genpwd));
1.102 albertel 2205: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2206: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2207: } else {
1.27 matthew 2208: # Okay, this is a non-fatal error.
1.193 raeburn 2209: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2210: }
1.28 matthew 2211: }
2212: ##
1.213 raeburn 2213: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
2214: if ($context eq 'course') {
2215: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
2216: }
1.101 albertel 2217: if (! $env{'form.makeuser'} ) {
1.28 matthew 2218: # Check for need to change
2219: my %userenv = &Apache::lonnet::get
1.134 raeburn 2220: ('environment',['firstname','middlename','lastname','generation',
1.267 raeburn 2221: 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
1.279 raeburn 2222: 'tools.blog','tools.portfolio','requestcourses.official',
1.300 raeburn 2223: 'requestcourses.unofficial','requestcourses.community',
2224: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2225: 'reqcrsotherdom.community'],
1.160 raeburn 2226: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2227: my ($tmp) = keys(%userenv);
2228: if ($tmp =~ /^(con_lost|error)/i) {
2229: %userenv = ();
2230: }
1.206 raeburn 2231: my $no_forceid_alert;
2232: # Check to see if user information can be changed
2233: my %domconfig =
2234: &Apache::lonnet::get_dom('configuration',['usermodification'],
2235: $env{'form.ccdomain'});
1.213 raeburn 2236: my @statuses = ('active','future');
2237: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2238: my ($auname,$audom);
1.220 raeburn 2239: if ($context eq 'author') {
1.206 raeburn 2240: $auname = $env{'user.name'};
2241: $audom = $env{'user.domain'};
2242: }
2243: foreach my $item (keys(%roles)) {
1.220 raeburn 2244: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2245: if ($context eq 'course') {
2246: if ($cnum ne '' && $cdom ne '') {
2247: if ($rolenum eq $cnum && $roledom eq $cdom) {
2248: if (!grep(/^\Q$role\E$/,@userroles)) {
2249: push(@userroles,$role);
2250: }
2251: }
2252: }
2253: } elsif ($context eq 'author') {
2254: if ($rolenum eq $auname && $roledom eq $audom) {
2255: if (!grep(/^\Q$role\E$/,@userroles)) {
2256: push(@userroles,$role);
2257: }
2258: }
2259: }
2260: }
1.220 raeburn 2261: if ($env{'form.action'} eq 'singlestudent') {
2262: if (!grep(/^st$/,@userroles)) {
2263: push(@userroles,'st');
2264: }
2265: } else {
2266: # Check for course or co-author roles being activated or re-enabled
2267: if ($context eq 'author' || $context eq 'course') {
2268: foreach my $key (keys(%env)) {
2269: if ($context eq 'author') {
2270: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2271: if (!grep(/^\Q$1\E$/,@userroles)) {
2272: push(@userroles,$1);
2273: }
2274: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2275: if (!grep(/^\Q$1\E$/,@userroles)) {
2276: push(@userroles,$1);
2277: }
1.206 raeburn 2278: }
1.220 raeburn 2279: } elsif ($context eq 'course') {
2280: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2281: if (!grep(/^\Q$1\E$/,@userroles)) {
2282: push(@userroles,$1);
2283: }
2284: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2285: if (!grep(/^\Q$1\E$/,@userroles)) {
2286: push(@userroles,$1);
2287: }
1.206 raeburn 2288: }
2289: }
2290: }
2291: }
2292: }
2293: #Check to see if we can change personal data for the user
2294: my (@mod_disallowed,@longroles);
2295: foreach my $role (@userroles) {
2296: if ($role eq 'cr') {
2297: push(@longroles,'Custom');
2298: } else {
2299: push(@longroles,&Apache::lonnet::plaintext($role));
2300: }
2301: }
1.219 raeburn 2302: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
2303: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2304: foreach my $item (@userinfo) {
1.28 matthew 2305: # Strip leading and trailing whitespace
1.203 raeburn 2306: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2307: if (!$canmodify{$item}) {
1.207 raeburn 2308: if (defined($env{'form.c'.$item})) {
2309: if ($env{'form.c'.$item} ne $userenv{$item}) {
2310: push(@mod_disallowed,$item);
2311: }
1.206 raeburn 2312: }
2313: $env{'form.c'.$item} = $userenv{$item};
2314: }
1.28 matthew 2315: }
1.259 bisitz 2316: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2317: my $forceid = $env{'form.forceid'};
2318: my $recurseid = $env{'form.recurseid'};
2319: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2320: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2321: $env{'form.ccuname'});
2322: if (($uidhash{$env{'form.ccuname'}}) &&
2323: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2324: (!$forceid)) {
2325: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2326: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2327: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2328: .'<br />'
2329: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2330: .'<br />'."\n";
1.203 raeburn 2331: }
2332: }
2333: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2334: my $checkhash;
2335: my $checks = { 'id' => 1 };
2336: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2337: { 'newuser' => $newuser,
2338: 'id' => $env{'form.cid'},
2339: };
2340: &Apache::loncommon::user_rule_check($checkhash,$checks,
2341: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2342: if (ref($alerts{'id'}) eq 'HASH') {
2343: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2344: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2345: }
2346: }
2347: }
1.286 raeburn 2348: my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
2349: $inststatus,$newinststatus,$oldisdefault,$newisdefault,$olddefquotatext,
2350: $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext,
2351: $oldinststatuses,$newinststatuses);
1.149 raeburn 2352: my ($defquota,$settingstatus) =
2353: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.300 raeburn 2354: my ($showquota,$showtools,$showrequestcourses,$showinststatus,$showreqotherdom);
1.220 raeburn 2355: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2356: $showquota = 1;
2357: }
1.267 raeburn 2358: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
2359: $showtools = 1;
2360: }
1.275 raeburn 2361: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
2362: $showrequestcourses = 1;
1.300 raeburn 2363: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
2364: $showreqotherdom = 1;
1.275 raeburn 2365: }
1.286 raeburn 2366: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
2367: $showinststatus = 1;
2368: }
1.267 raeburn 2369: my (%changeHash,%changed);
1.286 raeburn 2370: $oldinststatus = $userenv{'inststatus'};
2371: if ($oldinststatus eq '') {
2372: $oldinststatuses = $othertitle;
2373: } else {
2374: if (ref($usertypes) eq 'HASH') {
2375: $oldinststatuses = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
2376: } else {
2377: $oldinststatuses = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
2378: }
2379: }
2380: $changeHash{'inststatus'} = $userenv{'inststatus'};
2381: my %canmodify_inststatus = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},['inststatus'],\@userroles);
2382: if ($canmodify_inststatus{'inststatus'}) {
2383: if (exists($env{'form.inststatus'})) {
2384: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2385: if (@inststatuses > 0) {
2386: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2387: $changeHash{'inststatus'} = $newinststatus;
2388: if ($newinststatus ne $oldinststatus) {
2389: $changed{'inststatus'} = $newinststatus;
2390: }
2391: if (ref($usertypes) eq 'HASH') {
2392: $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
2393: } else {
2394: $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
2395: }
2396: } else {
2397: $newinststatus = '';
2398: $changeHash{'inststatus'} = $newinststatus;
2399: $newinststatuses = $othertitle;
2400: if ($newinststatus ne $oldinststatus) {
2401: $changed{'inststatus'} = $changeHash{'inststatus'};
2402: }
2403: }
2404: }
2405: }
1.204 raeburn 2406: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 2407: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 2408: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 2409: if ($env{'form.customquota'} == 1) {
2410: if ($env{'form.portfolioquota'} eq '') {
2411: $newportfolioquota = 0;
2412: } else {
2413: $newportfolioquota = $env{'form.portfolioquota'};
2414: $newportfolioquota =~ s/[^\d\.]//g;
2415: }
1.204 raeburn 2416: if ($newportfolioquota != $oldportfolioquota) {
1.267 raeburn 2417: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 2418: }
1.149 raeburn 2419: } else {
1.267 raeburn 2420: $changed{'quota'} = "a_admin('',\%changeHash);
1.149 raeburn 2421: $newportfolioquota = $defquota;
1.284 bisitz 2422: $newisdefault = 1;
1.134 raeburn 2423: }
2424: } else {
1.204 raeburn 2425: $oldisdefault = 1;
1.149 raeburn 2426: $oldportfolioquota = $defquota;
2427: if ($env{'form.customquota'} == 1) {
2428: if ($env{'form.portfolioquota'} eq '') {
2429: $newportfolioquota = 0;
2430: } else {
2431: $newportfolioquota = $env{'form.portfolioquota'};
2432: $newportfolioquota =~ s/[^\d\.]//g;
2433: }
1.267 raeburn 2434: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.149 raeburn 2435: } else {
2436: $newportfolioquota = $defquota;
1.204 raeburn 2437: $newisdefault = 1;
1.149 raeburn 2438: }
2439: }
1.204 raeburn 2440: if ($oldisdefault) {
2441: $olddefquotatext = &get_defaultquota_text($settingstatus);
2442: }
2443: if ($newisdefault) {
2444: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 2445: }
1.275 raeburn 2446: &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv,
2447: \%changeHash,\%changed,\%newaccess,\%newaccesstext);
1.300 raeburn 2448: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2449: &tool_changes('requestcourses',\@requestcourses,\%oldaccess,\%oldaccesstext,
2450: \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext);
2451: } else {
2452: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldaccess,\%oldaccesstext,
2453: \%userenv,
2454: \%changeHash,\%changed,\%newaccess,\%newaccesstext);
2455: }
1.206 raeburn 2456: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
2457: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
2458: $env{'form.clastname'} ne $userenv{'lastname'} ||
2459: $env{'form.cgeneration'} ne $userenv{'generation'} ||
2460: $env{'form.cid'} ne $userenv{'id'} ||
2461: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 2462: $namechanged = 1;
2463: }
1.267 raeburn 2464: if (($namechanged) || (keys(%changed) > 0)) {
1.101 albertel 2465: $changeHash{'firstname'} = $env{'form.cfirstname'};
2466: $changeHash{'middlename'} = $env{'form.cmiddlename'};
2467: $changeHash{'lastname'} = $env{'form.clastname'};
2468: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 2469: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 2470: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 2471: my ($chgresult,$namechgresult);
2472: if (keys(%changed) > 0) {
2473: $chgresult =
1.204 raeburn 2474: &Apache::lonnet::put('environment',\%changeHash,
2475: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2476: if ($chgresult eq 'ok') {
2477: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2478: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2479: my %newenvhash;
2480: foreach my $key (keys(%changed)) {
1.299 raeburn 2481: if (($key eq 'official') || ($key eq 'unofficial')
2482: || ($key eq 'community')) {
1.279 raeburn 2483: $newenvhash{'environment.requestcourses.'.$key} =
2484: $changeHash{'requestcourses.'.$key};
2485: if ($changeHash{'requestcourses.'.$key} ne '') {
2486: $newenvhash{'environment.canrequest.'.$key} =
2487: $changeHash{'requestcourses.'.$key};
2488: } else {
2489: $newenvhash{'environment.canrequest.'.$key} =
2490: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2491: $key,'reload','requestcourses');
2492: }
1.275 raeburn 2493: } elsif ($key ne 'quota') {
1.270 raeburn 2494: $newenvhash{'environment.tools.'.$key} =
2495: $changeHash{'tools.'.$key};
1.279 raeburn 2496: if ($changeHash{'tools.'.$key} ne '') {
2497: $newenvhash{'environment.availabletools.'.$key} =
2498: $changeHash{'tools.'.$key};
2499: } else {
2500: $newenvhash{'environment.availabletools.'.$key} =
2501: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, $key,'reload','tools');
2502: }
1.270 raeburn 2503: }
2504: }
1.271 raeburn 2505: if (keys(%newenvhash)) {
2506: &Apache::lonnet::appenv(\%newenvhash);
2507: }
1.267 raeburn 2508: }
2509: }
1.204 raeburn 2510: }
2511: if ($namechanged) {
2512: # Make the change
2513: $namechgresult =
2514: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2515: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2516: $changeHash{'firstname'},$changeHash{'middlename'},
2517: $changeHash{'lastname'},$changeHash{'generation'},
2518: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 2519: %userupdate = (
2520: lastname => $env{'form.clastname'},
2521: middlename => $env{'form.cmiddlename'},
2522: firstname => $env{'form.cfirstname'},
2523: generation => $env{'form.cgeneration'},
2524: id => $env{'form.cid'},
2525: );
1.204 raeburn 2526: }
2527: if (($namechanged && $namechgresult eq 'ok') ||
1.267 raeburn 2528: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2529: # Tell the user we changed the name
1.73 sakharuk 2530: my %lt=&Apache::lonlocal::texthash(
1.284 bisitz 2531: 'uic' => 'User Information Changed',
2532: 'frst' => 'First Name',
2533: 'mddl' => 'Middle Name',
2534: 'lst' => 'Last Name',
2535: 'gen' => 'Generation',
2536: 'id' => 'Student/Employee ID',
2537: 'mail' => 'Permanent e-mail address',
2538: 'disk' => 'Disk space allocated to portfolio files',
2539: 'blog' => 'Blog Availability',
2540: 'aboutme' => 'Personal Information Page Availability',
2541: 'portfolio' => 'Portfolio Availability',
2542: 'official' => 'Can Request Official Courses',
2543: 'unofficial' => 'Can Request Unofficial Courses',
1.299 raeburn 2544: 'community' => 'Can Request Communities',
1.286 raeburn 2545: 'inststatus' => "Affiliation",
1.284 bisitz 2546: 'prvs' => 'Previous Value:',
2547: 'chto' => 'Changed To:'
1.73 sakharuk 2548: );
1.201 raeburn 2549: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
2550: &Apache::loncommon::start_data_table().
2551: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 2552: $r->print(<<"END");
1.201 raeburn 2553: <th> </th>
1.73 sakharuk 2554: <th>$lt{'frst'}</th>
2555: <th>$lt{'mddl'}</th>
2556: <th>$lt{'lst'}</th>
1.134 raeburn 2557: <th>$lt{'gen'}</th>
1.196 raeburn 2558: <th>$lt{'id'}</th>
1.173 raeburn 2559: <th>$lt{'mail'}</th>
1.201 raeburn 2560: END
1.286 raeburn 2561: if ($showinststatus) {
2562: $r->print("
2563: <th>$lt{'inststatus'}</th>\n");
2564: }
1.275 raeburn 2565: if ($showrequestcourses) {
2566: foreach my $item (@requestcourses) {
2567: $r->print("
2568: <th>$lt{$item}</th>\n");
2569: }
1.300 raeburn 2570: } elsif ($showreqotherdom) {
2571: foreach my $item (@requestcourses) {
2572: $r->print("
2573: <th>$lt{$item}</th>\n");
2574: }
1.275 raeburn 2575: }
1.220 raeburn 2576: if ($showquota) {
2577: $r->print("
2578: <th>$lt{'disk'}</th>\n");
2579: }
1.267 raeburn 2580: if ($showtools) {
2581: foreach my $item (@usertools) {
2582: $r->print("
2583: <th>$lt{$item}</th>\n");
2584: }
2585: }
1.201 raeburn 2586: $r->print(&Apache::loncommon::end_data_table_header_row().
2587: &Apache::loncommon::start_data_table_row());
2588: $r->print(<<"END");
2589: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 2590: <td>$userenv{'firstname'} </td>
2591: <td>$userenv{'middlename'} </td>
2592: <td>$userenv{'lastname'} </td>
1.134 raeburn 2593: <td>$userenv{'generation'} </td>
1.196 raeburn 2594: <td>$userenv{'id'}</td>
1.160 raeburn 2595: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 2596: END
1.286 raeburn 2597: if ($showinststatus) {
2598: $r->print("
2599: <td>$oldinststatuses</td>\n");
2600: }
1.275 raeburn 2601: if ($showrequestcourses) {
2602: foreach my $item (@requestcourses) {
2603: $r->print("
2604: <td>$oldaccess{$item} $oldaccesstext{$item}</td>\n");
2605: }
1.300 raeburn 2606: } elsif ($showreqotherdom) {
2607: foreach my $item (@requestcourses) {
2608: $r->print("
2609: <td>$oldaccess{$item} $oldaccesstext{$item}</td>\n");
2610: }
1.275 raeburn 2611: }
1.220 raeburn 2612: if ($showquota) {
2613: $r->print("
2614: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
2615: }
1.267 raeburn 2616: if ($showtools) {
2617: foreach my $item (@usertools) {
2618: $r->print("
2619: <td>$oldaccess{$item} $oldaccesstext{$item} </td>\n");
2620: }
2621: }
1.201 raeburn 2622: $r->print(&Apache::loncommon::end_data_table_row().
2623: &Apache::loncommon::start_data_table_row());
2624: $r->print(<<"END");
1.267 raeburn 2625: <td><span class="LC_nobreak"><b>$lt{'chto'}</b></span></td>
1.101 albertel 2626: <td>$env{'form.cfirstname'} </td>
2627: <td>$env{'form.cmiddlename'} </td>
2628: <td>$env{'form.clastname'} </td>
1.134 raeburn 2629: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 2630: <td>$env{'form.cid'} </td>
1.160 raeburn 2631: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 2632: END
1.286 raeburn 2633: if ($showinststatus) {
2634: $r->print("
2635: <td>$newinststatuses</td>\n");
2636: }
1.275 raeburn 2637: if ($showrequestcourses) {
2638: foreach my $item (@requestcourses) {
2639: $r->print("
2640: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2641: }
1.300 raeburn 2642: } elsif ($showreqotherdom) {
2643: foreach my $item (@requestcourses) {
2644: $r->print("
2645: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2646: }
1.275 raeburn 2647: }
1.220 raeburn 2648: if ($showquota) {
2649: $r->print("
2650: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
2651: }
1.267 raeburn 2652: if ($showtools) {
2653: foreach my $item (@usertools) {
2654: $r->print("
2655: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2656: }
2657: }
1.201 raeburn 2658: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 2659: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 2660: if ($env{'form.cid'} ne $userenv{'id'}) {
2661: &Apache::lonnet::idput($env{'form.ccdomain'},
2662: ($env{'form.ccuname'} => $env{'form.cid'}));
2663: if (($recurseid) &&
2664: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2665: my $idresult =
2666: &Apache::lonuserutils::propagate_id_change(
2667: $env{'form.ccuname'},$env{'form.ccdomain'},
2668: \%userupdate);
2669: $r->print('<br />'.$idresult.'<br />');
2670: }
1.196 raeburn 2671: }
1.149 raeburn 2672: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2673: ($env{'form.ccuname'} eq $env{'user.name'})) {
2674: my %newenvhash;
2675: foreach my $key (keys(%changeHash)) {
2676: $newenvhash{'environment.'.$key} = $changeHash{$key};
2677: }
1.238 raeburn 2678: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2679: }
1.28 matthew 2680: } else { # error occurred
1.188 raeburn 2681: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2682: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2683: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2684: }
1.101 albertel 2685: } else { # End of if ($env ... ) logic
1.275 raeburn 2686: # They did not want to change the users name, quota, tool availability,
2687: # or ability to request creation of courses,
1.267 raeburn 2688: # but we can still tell them what the name and quota and availabilities are
1.73 sakharuk 2689: my %lt=&Apache::lonlocal::texthash(
1.275 raeburn 2690: 'id' => "Student/Employee ID",
1.284 bisitz 2691: 'mail' => "Permanent e-mail address",
1.275 raeburn 2692: 'disk' => "Disk space allocated to user's portfolio files",
2693: 'blog' => "Blog Availability",
1.285 weissno 2694: 'aboutme' => "Personal Information Page Availability",
1.275 raeburn 2695: 'portfolio' => "Portfolio Availability",
2696: 'official' => "Can Request Official Courses",
1.299 raeburn 2697: 'unofficial' => "Can Request Unofficial Courses",
2698: 'community' => "Can Request Communities",
1.286 raeburn 2699: 'inststatus' => "Affiliation",
1.73 sakharuk 2700: );
1.134 raeburn 2701: $r->print(<<"END");
1.196 raeburn 2702: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2703: END
1.204 raeburn 2704: if ($userenv{'permanentemail'} ne '') {
2705: $r->print('<br />['.$lt{'mail'}.': '.
2706: $userenv{'permanentemail'}.']');
1.134 raeburn 2707: }
1.286 raeburn 2708: if ($showinststatus) {
2709: $r->print('<br />['.$lt{'inststatus'}.': '.$oldinststatuses.']');
2710: }
1.275 raeburn 2711: if ($showrequestcourses) {
2712: foreach my $item (@requestcourses) {
2713: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2714: $newaccesstext{$item}.']'."\n");
2715: }
1.300 raeburn 2716: } elsif ($showreqotherdom) {
2717: foreach my $item (@requestcourses) {
2718: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2719: $newaccesstext{$item}.']'."\n");
2720: }
1.275 raeburn 2721: }
1.267 raeburn 2722: if ($showtools) {
2723: foreach my $item (@usertools) {
2724: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2725: $newaccesstext{$item}.']'."\n");
2726: }
2727: }
1.220 raeburn 2728: if ($showquota) {
1.267 raeburn 2729: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
1.220 raeburn 2730: $olddefquotatext.']');
2731: }
2732: $r->print('</h4>');
1.28 matthew 2733: }
1.206 raeburn 2734: if (@mod_disallowed) {
2735: my ($rolestr,$contextname);
2736: if (@longroles > 0) {
2737: $rolestr = join(', ',@longroles);
2738: } else {
2739: $rolestr = &mt('No roles');
2740: }
2741: if ($context eq 'course') {
2742: $contextname = &mt('course');
2743: } elsif ($context eq 'author') {
2744: $contextname = &mt('co-author');
2745: }
2746: $r->print(&mt('The following fields were not updated: ').'<ul>');
2747: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2748: foreach my $field (@mod_disallowed) {
2749: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2750: }
1.207 raeburn 2751: $r->print('</ul>');
2752: if (@mod_disallowed == 1) {
2753: $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));
2754: } else {
2755: $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));
2756: }
1.292 bisitz 2757: my $helplink = 'javascript:helpMenu('."'display'".')';
2758: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
2759: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
2760: ,'<a href="'.$helplink.'">','</a>')
2761: .'<br />');
1.206 raeburn 2762: }
1.259 bisitz 2763: $r->print('<span class="LC_warning">'
2764: .$no_forceid_alert
2765: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
2766: .'</span>');
1.4 www 2767: }
1.220 raeburn 2768: if ($env{'form.action'} eq 'singlestudent') {
1.239 raeburn 2769: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
2770: $r->print('<p><a href="javascript:backPage(document.userupdate)">'.
2771: &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2772: } else {
1.239 raeburn 2773: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2774: if ($namechanged) {
1.220 raeburn 2775: if ($context eq 'course') {
2776: if (@userroles > 0) {
1.225 raeburn 2777: if ((@rolechanges == 0) ||
2778: (!(grep(/^st$/,@rolechanges)))) {
2779: if (grep(/^st$/,@userroles)) {
2780: my $classlistupdated =
2781: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2782: $cnum,$env{'form.ccdomain'},
2783: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2784: }
1.220 raeburn 2785: }
2786: }
2787: }
2788: }
1.226 raeburn 2789: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2790: $env{'form.ccdomain'});
2791: if ($env{'form.popup'}) {
2792: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2793: } else {
1.246 bisitz 2794: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2795: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2796: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2797: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2798: }
1.220 raeburn 2799: }
2800: $r->print(&Apache::loncommon::end_page());
2801: }
2802:
1.275 raeburn 2803: sub tool_changes {
2804: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
2805: $changed,$newaccess,$newaccesstext) = @_;
2806: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
2807: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
2808: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
2809: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
2810: return;
2811: }
1.300 raeburn 2812: if ($context eq 'reqcrsotherdom') {
1.306 ! raeburn 2813: my @options = ('approve','validate','autolimit');
! 2814: my $optregex = join('|',@options);
! 2815: my %reqdisplay = &courserequest_display();
1.300 raeburn 2816: my $cdom = $env{'request.role.domain'};
2817: foreach my $tool (@{$usertools}) {
2818: $oldaccesstext->{$tool} = &mt('no');
2819: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
2820: if ($userenv->{$context.'.'.$tool} eq '') {
2821: if ($env{'form.'.$context.'_'.$tool}) {
2822: $changed->{$tool}=&tool_admin($tool,$cdom,
2823: $changeHash,$context);
2824: if ($changed->{$tool}) {
2825: $newaccesstext->{$tool} = &mt('yes');
2826: } else {
2827: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
2828: }
2829: }
2830: } else {
2831: my @curr = split(',',$userenv->{$context.'.'.$tool});
2832: my @new;
2833: my $changedoms;
1.306 ! raeburn 2834: my $newop = $env{'form.'.$context.'_'.$tool};
! 2835: if ($newop eq 'autolimit') {
! 2836: $newop .= '=';
! 2837: unless ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) {
! 2838: $newop .= $env{'form.'.$context.'_'.$tool.'_limit'};
! 2839: }
! 2840: }
! 2841: if (grep(/^\Q$cdom:($optregex\=?\d*)\E$/,@curr)) {
1.300 raeburn 2842: $oldaccesstext->{$tool} = &mt('yes');
1.306 ! raeburn 2843: my $oldop = $1;
! 2844: if ($oldop ne $newop) {
1.300 raeburn 2845: $changedoms = 1;
2846: foreach my $dom (@curr) {
2847: unless ($dom eq $cdom) {
2848: push(@new,$dom);
2849: }
2850: }
1.306 ! raeburn 2851: if ($newop) {
! 2852: push(@new,$cdom.':'.$newop);
! 2853: }
! 2854: @new = sort(@new);
1.300 raeburn 2855: }
2856: } elsif ($env{'form.'.$context.'_'.$tool}) {
2857: $changedoms = 1;
1.306 ! raeburn 2858: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 2859: }
2860: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
2861: if ($changedoms) {
2862: my $newdomstr;
2863: if (@new) {
2864: $newdomstr = join(',',@new);
2865: }
2866: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
2867: $context);
2868: if ($changed->{$tool}) {
2869: if ($env{'form.'.$context.'_'.$tool}) {
1.306 ! raeburn 2870: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
! 2871: if ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) {
! 2872: $newaccesstext->{$tool} = &mt('Yes, processed automatically');
! 2873: } else {
! 2874: $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user).',$env{'form.'.$context.'_'.$tool.'_limit'});
! 2875: }
! 2876: } else {
! 2877: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
! 2878: }
1.300 raeburn 2879: } else {
1.306 ! raeburn 2880: $newaccesstext->{$tool} = &mt('No');
1.300 raeburn 2881: }
2882: }
2883: }
2884: }
2885: }
2886: return;
2887: }
1.275 raeburn 2888: foreach my $tool (@{$usertools}) {
1.306 ! raeburn 2889: my $newval;
! 2890: if ($context eq 'requestcourses') {
! 2891: $newval = $env{'form.crsreq_'.$tool};
! 2892: if ($newval eq 'autolimit') {
! 2893: $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
! 2894: }
! 2895: } else {
! 2896: $newval = $env{'form.'.$context.'_'.$tool};
! 2897: }
1.275 raeburn 2898: if ($userenv->{$context.'.'.$tool} ne '') {
2899: $oldaccess->{$tool} = &mt('custom');
2900: if ($userenv->{$context.'.'.$tool}) {
2901: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
2902: } else {
2903: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
2904: }
1.279 raeburn 2905: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.275 raeburn 2906: if ($env{'form.custom'.$tool} == 1) {
1.306 ! raeburn 2907: if ($newval ne $userenv->{$context.'.'.$tool}) {
! 2908: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
! 2909: $context);
1.275 raeburn 2910: if ($changed->{$tool}) {
2911: $newaccess->{$tool} = &mt('custom');
1.306 ! raeburn 2912: if ($newval) {
1.275 raeburn 2913: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2914: } else {
2915: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2916: }
2917: } else {
2918: $newaccess->{$tool} = $oldaccess->{$tool};
2919: if ($userenv->{$context.'.'.$tool}) {
2920: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2921: } else {
2922: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2923: }
2924: }
2925: } else {
2926: $newaccess->{$tool} = $oldaccess->{$tool};
2927: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
2928: }
2929: } else {
2930: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
2931: if ($changed->{$tool}) {
2932: $newaccess->{$tool} = &mt('default');
2933: } else {
2934: $newaccess->{$tool} = $oldaccess->{$tool};
2935: if ($userenv->{$context.'.'.$tool}) {
1.300 raeburn 2936: $newaccesstext->{$tool} = &mt("availability set to 'on'");
1.275 raeburn 2937: } else {
1.300 raeburn 2938: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.275 raeburn 2939: }
2940: }
2941: }
2942: } else {
2943: $oldaccess->{$tool} = &mt('default');
2944: if ($env{'form.custom'.$tool} == 1) {
1.306 ! raeburn 2945: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
! 2946: $context);
1.275 raeburn 2947: if ($changed->{$tool}) {
2948: $newaccess->{$tool} = &mt('custom');
1.306 ! raeburn 2949: if ($newval) {
1.275 raeburn 2950: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2951: } else {
2952: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2953: }
2954: } else {
2955: $newaccess->{$tool} = $oldaccess->{$tool};
2956: }
2957: } else {
2958: $newaccess->{$tool} = $oldaccess->{$tool};
2959: }
2960: }
2961: }
2962: return;
2963: }
2964:
1.220 raeburn 2965: sub update_roles {
1.239 raeburn 2966: my ($r,$context) = @_;
1.4 www 2967: my $now=time;
1.225 raeburn 2968: my @rolechanges;
1.220 raeburn 2969: my %disallowed;
1.73 sakharuk 2970: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2971: foreach my $key (keys (%env)) {
2972: next if (! $env{$key});
1.190 raeburn 2973: next if ($key eq 'form.action');
1.27 matthew 2974: # Revoke roles
1.135 raeburn 2975: if ($key=~/^form\.rev/) {
2976: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2977: # Revoke standard role
1.170 albertel 2978: my ($scope,$role) = ($1,$2);
2979: my $result =
2980: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2981: $env{'form.ccuname'},
1.239 raeburn 2982: $scope,$role,'','',$context);
1.170 albertel 2983: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2984: $role,$scope,'<b>'.$result.'</b>').'<br />');
2985: if ($role eq 'st') {
1.202 raeburn 2986: my $result =
1.198 raeburn 2987: &Apache::lonuserutils::classlist_drop($scope,
2988: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2989: $now);
1.170 albertel 2990: $r->print($result);
1.53 www 2991: }
1.225 raeburn 2992: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2993: push(@rolechanges,$role);
2994: }
1.196 raeburn 2995: }
1.195 raeburn 2996: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2997: # Revoke custom role
1.113 raeburn 2998: $r->print(&mt('Revoking custom role:').
1.139 albertel 2999: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 3000: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 3001: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 3002: '</b><br />');
1.225 raeburn 3003: if (!grep(/^cr$/,@rolechanges)) {
3004: push(@rolechanges,'cr');
3005: }
1.64 www 3006: }
1.135 raeburn 3007: } elsif ($key=~/^form\.del/) {
3008: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3009: # Delete standard role
1.170 albertel 3010: my ($scope,$role) = ($1,$2);
3011: my $result =
3012: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3013: $env{'form.ccuname'},
1.239 raeburn 3014: $scope,$role,$now,0,1,'',
3015: $context);
1.170 albertel 3016: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
3017: '<b>'.$result.'</b>').'<br />');
3018: if ($role eq 'st') {
1.202 raeburn 3019: my $result =
1.198 raeburn 3020: &Apache::lonuserutils::classlist_drop($scope,
3021: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3022: $now);
1.170 albertel 3023: $r->print($result);
1.81 albertel 3024: }
1.225 raeburn 3025: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3026: push(@rolechanges,$role);
3027: }
1.116 raeburn 3028: }
1.139 albertel 3029: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3030: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3031: # Delete custom role
1.294 bisitz 3032: $r->print(&mt('Deleting custom role [_1] by [_2] in [_3]',
3033: $rolename,$rnam.':'.$rdom,$url).': <b>'.
1.116 raeburn 3034: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3035: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 3036: 0,1,$context).'</b><br />');
1.225 raeburn 3037: if (!grep(/^cr$/,@rolechanges)) {
3038: push(@rolechanges,'cr');
3039: }
1.116 raeburn 3040: }
1.135 raeburn 3041: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3042: my $udom = $env{'form.ccdomain'};
3043: my $uname = $env{'form.ccuname'};
1.116 raeburn 3044: # Re-enable standard role
1.135 raeburn 3045: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3046: my $url = $1;
3047: my $role = $2;
3048: my $logmsg;
3049: my $output;
3050: if ($role eq 'st') {
1.141 albertel 3051: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 3052: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 3053: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3054: if ($result eq 'refused' && $logmsg) {
3055: $output = $logmsg;
3056: } else {
3057: $output = "Error: $result\n";
3058: }
1.89 raeburn 3059: } else {
3060: $output = &mt('Assigning').' '.$role.' in '.$url.
3061: &mt('starting').' '.localtime($now).
3062: ': <br />'.$logmsg.'<br />'.
3063: &mt('Add to classlist').': <b>ok</b><br />';
3064: }
3065: }
3066: } else {
1.101 albertel 3067: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3068: $env{'form.ccuname'},$url,$role,0,$now,'','',
3069: $context);
1.266 bisitz 3070: $output = &mt('Re-enabling [_1] in [_2]: [_3]',
3071: $role,$url,'<b>'.$result.'</b>').'<br />';
1.27 matthew 3072: }
1.89 raeburn 3073: $r->print($output);
1.225 raeburn 3074: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3075: push(@rolechanges,$role);
3076: }
1.113 raeburn 3077: }
1.116 raeburn 3078: # Re-enable custom role
1.139 albertel 3079: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3080: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3081: my $result = &Apache::lonnet::assigncustomrole(
3082: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3083: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.294 bisitz 3084: $r->print(&mt('Re-enabling custom role [_1] by [_2] in [_3]: [_4]',
3085: $rolename,$rnam.':'.$rdom,$url,'<b>'.$result.'</b>').'<br />');
1.225 raeburn 3086: if (!grep(/^cr$/,@rolechanges)) {
3087: push(@rolechanges,'cr');
3088: }
1.116 raeburn 3089: }
1.135 raeburn 3090: } elsif ($key=~/^form\.act/) {
1.101 albertel 3091: my $udom = $env{'form.ccdomain'};
3092: my $uname = $env{'form.ccuname'};
1.141 albertel 3093: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3094: # Activate a custom role
1.83 albertel 3095: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3096: my $url='/'.$one.'/'.$two;
3097: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3098:
1.101 albertel 3099: my $start = ( $env{'form.start_'.$full} ?
3100: $env{'form.start_'.$full} :
1.88 raeburn 3101: $now );
1.101 albertel 3102: my $end = ( $env{'form.end_'.$full} ?
3103: $env{'form.end_'.$full} :
1.88 raeburn 3104: 0 );
3105:
3106: # split multiple sections
3107: my %sections = ();
1.101 albertel 3108: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3109: if ($num_sections == 0) {
1.240 raeburn 3110: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3111: } else {
1.114 albertel 3112: my %curr_groups =
1.117 raeburn 3113: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3114: foreach my $sec (sort {$a cmp $b} keys %sections) {
3115: if (($sec eq 'none') || ($sec eq 'all') ||
3116: exists($curr_groups{$sec})) {
3117: $disallowed{$sec} = $url;
3118: next;
3119: }
3120: my $securl = $url.'/'.$sec;
1.240 raeburn 3121: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3122: }
3123: }
1.225 raeburn 3124: if (!grep(/^cr$/,@rolechanges)) {
3125: push(@rolechanges,'cr');
3126: }
1.142 raeburn 3127: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3128: # Activate roles for sections with 3 id numbers
3129: # set start, end times, and the url for the class
1.83 albertel 3130: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3131: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3132: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3133: $now );
1.101 albertel 3134: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3135: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3136: 0 );
1.83 albertel 3137: my $url='/'.$one.'/'.$two;
1.88 raeburn 3138: my $type = 'three';
3139: # split multiple sections
3140: my %sections = ();
1.101 albertel 3141: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 3142: if ($num_sections == 0) {
1.240 raeburn 3143: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3144: } else {
1.114 albertel 3145: my %curr_groups =
1.117 raeburn 3146: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3147: my $emptysec = 0;
3148: foreach my $sec (sort {$a cmp $b} keys %sections) {
3149: $sec =~ s/\W//g;
1.113 raeburn 3150: if ($sec ne '') {
3151: if (($sec eq 'none') || ($sec eq 'all') ||
3152: exists($curr_groups{$sec})) {
3153: $disallowed{$sec} = $url;
3154: next;
3155: }
1.88 raeburn 3156: my $securl = $url.'/'.$sec;
1.240 raeburn 3157: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 3158: } else {
3159: $emptysec = 1;
3160: }
3161: }
3162: if ($emptysec) {
1.240 raeburn 3163: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3164: }
1.225 raeburn 3165: }
3166: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3167: push(@rolechanges,$three);
3168: }
1.135 raeburn 3169: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3170: # Activate roles for sections with two id numbers
3171: # set start, end times, and the url for the class
1.101 albertel 3172: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3173: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3174: $now );
1.101 albertel 3175: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3176: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3177: 0 );
1.225 raeburn 3178: my $one = $1;
3179: my $two = $2;
3180: my $url='/'.$one.'/';
1.88 raeburn 3181: # split multiple sections
3182: my %sections = ();
1.225 raeburn 3183: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3184: if ($num_sections == 0) {
1.240 raeburn 3185: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3186: } else {
3187: my $emptysec = 0;
3188: foreach my $sec (sort {$a cmp $b} keys %sections) {
3189: if ($sec ne '') {
3190: my $securl = $url.'/'.$sec;
1.240 raeburn 3191: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3192: } else {
3193: $emptysec = 1;
3194: }
3195: }
3196: if ($emptysec) {
1.240 raeburn 3197: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3198: }
3199: }
1.225 raeburn 3200: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3201: push(@rolechanges,$two);
3202: }
1.64 www 3203: } else {
1.190 raeburn 3204: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3205: }
1.113 raeburn 3206: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3207: $r->print('<p class="LC_warning">');
1.113 raeburn 3208: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3209: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 3210: } else {
1.274 bisitz 3211: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 3212: }
1.274 bisitz 3213: $r->print('</p><p>'
3214: .&mt('Please [_1]go back[_2] and choose a different section name.'
3215: ,'<a href="javascript:history.go(-1)'
3216: ,'</a>')
3217: .'</p><br />'
3218: );
1.113 raeburn 3219: }
3220: }
1.101 albertel 3221: } # End of foreach (keys(%env))
1.75 www 3222: # Flush the course logs so reverse user roles immediately updated
3223: &Apache::lonnet::flushcourselogs();
1.225 raeburn 3224: if (@rolechanges == 0) {
1.193 raeburn 3225: $r->print(&mt('No roles to modify'));
3226: }
1.225 raeburn 3227: return @rolechanges;
1.220 raeburn 3228: }
3229:
3230: sub enroll_single_student {
1.239 raeburn 3231: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
1.220 raeburn 3232: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
3233:
3234: # Remove non alphanumeric values from section
3235: $env{'form.sections'}=~s/\W//g;
3236:
3237: # Clean out any old student roles the user has in this class.
3238: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3239: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3240: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3241: my $enroll_result =
3242: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3243: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3244: $env{'form.cmiddlename'},$env{'form.clastname'},
3245: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 3246: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 3247: if ($enroll_result =~ /^ok/) {
3248: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
3249: if ($env{'form.sections'} ne '') {
3250: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3251: }
3252: my ($showstart,$showend);
3253: if ($startdate <= $now) {
3254: $showstart = &mt('Access starts immediately');
3255: } else {
3256: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3257: }
3258: if ($enddate == 0) {
3259: $showend = &mt('ends: no ending date');
3260: } else {
3261: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3262: }
3263: $r->print('.<br />'.$showstart.'; '.$showend);
3264: if ($startdate <= $now && !$newuser) {
3265: $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>");
3266: }
3267: } else {
3268: $r->print(&mt('unable to enroll').": ".$enroll_result);
3269: }
3270: return;
1.188 raeburn 3271: }
3272:
1.204 raeburn 3273: sub get_defaultquota_text {
3274: my ($settingstatus) = @_;
3275: my $defquotatext;
3276: if ($settingstatus eq '') {
3277: $defquotatext = &mt('(default)');
3278: } else {
3279: my ($usertypes,$order) =
3280: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3281: if ($usertypes->{$settingstatus} eq '') {
3282: $defquotatext = &mt('(default)');
3283: } else {
3284: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
3285: }
3286: }
3287: return $defquotatext;
3288: }
3289:
1.188 raeburn 3290: sub update_result_form {
3291: my ($uhome) = @_;
3292: my $outcome =
3293: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 3294: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3295: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3296: }
1.207 raeburn 3297: if ($env{'form.origname'} ne '') {
3298: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3299: }
1.160 raeburn 3300: foreach my $item ('sortby','seluname','seludom') {
3301: if (exists($env{'form.'.$item})) {
1.188 raeburn 3302: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3303: }
3304: }
1.188 raeburn 3305: if ($uhome eq 'no_host') {
3306: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3307: }
3308: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
3309: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 3310: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3311: '</form>';
3312: return $outcome;
1.4 www 3313: }
3314:
1.149 raeburn 3315: sub quota_admin {
3316: my ($setquota,$changeHash) = @_;
3317: my $quotachanged;
3318: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3319: # Current user has quota modification privileges
1.267 raeburn 3320: if (ref($changeHash) eq 'HASH') {
3321: $quotachanged = 1;
3322: $changeHash->{'portfolioquota'} = $setquota;
3323: }
1.149 raeburn 3324: }
3325: return $quotachanged;
3326: }
3327:
1.267 raeburn 3328: sub tool_admin {
1.275 raeburn 3329: my ($tool,$settool,$changeHash,$context) = @_;
3330: my $canchange = 0;
1.279 raeburn 3331: if ($context eq 'requestcourses') {
1.275 raeburn 3332: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3333: $canchange = 1;
3334: }
1.300 raeburn 3335: } elsif ($context eq 'reqcrsotherdom') {
3336: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3337: $canchange = 1;
3338: }
1.275 raeburn 3339: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3340: # Current user has quota modification privileges
3341: $canchange = 1;
3342: }
1.267 raeburn 3343: my $toolchanged;
1.275 raeburn 3344: if ($canchange) {
1.267 raeburn 3345: if (ref($changeHash) eq 'HASH') {
3346: $toolchanged = 1;
1.275 raeburn 3347: $changeHash->{$context.'.'.$tool} = $settool;
1.267 raeburn 3348: }
3349: }
3350: return $toolchanged;
3351: }
3352:
1.88 raeburn 3353: sub build_roles {
1.89 raeburn 3354: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3355: my $num_sections = 0;
3356: if ($sectionstr=~ /,/) {
3357: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3358: if ($role eq 'st') {
3359: $secnums[0] =~ s/\W//g;
3360: $$sections{$secnums[0]} = 1;
3361: $num_sections = 1;
3362: } else {
3363: foreach my $sec (@secnums) {
3364: $sec =~ ~s/\W//g;
1.150 banghart 3365: if (!($sec eq "")) {
1.89 raeburn 3366: if (exists($$sections{$sec})) {
3367: $$sections{$sec} ++;
3368: } else {
3369: $$sections{$sec} = 1;
3370: $num_sections ++;
3371: }
1.88 raeburn 3372: }
3373: }
3374: }
3375: } else {
3376: $sectionstr=~s/\W//g;
3377: unless ($sectionstr eq '') {
3378: $$sections{$sectionstr} = 1;
3379: $num_sections ++;
3380: }
3381: }
1.129 albertel 3382:
1.88 raeburn 3383: return $num_sections;
3384: }
3385:
1.58 www 3386: # ========================================================== Custom Role Editor
3387:
3388: sub custom_role_editor {
1.160 raeburn 3389: my ($r) = @_;
1.101 albertel 3390: my $rolename=$env{'form.rolename'};
1.58 www 3391:
1.59 www 3392: if ($rolename eq 'make new role') {
1.101 albertel 3393: $rolename=$env{'form.newrolename'};
1.59 www 3394: }
3395:
1.63 www 3396: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 3397:
1.190 raeburn 3398: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 3399: &print_username_entry_form($r);
3400: return;
3401: }
1.153 banghart 3402: # ------------------------------------------------------- What can be assigned?
3403: my %full=();
3404: my %courselevel=();
3405: my %courselevelcurrent=();
1.61 www 3406: my $syspriv='';
3407: my $dompriv='';
3408: my $coursepriv='';
1.153 banghart 3409: my $body_top;
1.150 banghart 3410: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 3411: my ($rdummy,$roledef)=
3412: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3413: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3414: $body_top .= '<h2>';
1.59 www 3415: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3416: $body_top .= &mt('Existing Role').' "';
1.61 www 3417: # ------------------------------------------------- Get current role privileges
3418: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 3419: } else {
1.153 banghart 3420: $body_top .= &mt('New Role').' "';
1.59 www 3421: $roledef='';
3422: }
1.153 banghart 3423: $body_top .= $rolename.'"</h2>';
1.135 raeburn 3424: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3425: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3426: if (!$restrict) { $restrict='F'; }
1.60 www 3427: $courselevel{$priv}=$restrict;
1.61 www 3428: if ($coursepriv=~/\:$priv/) {
3429: $courselevelcurrent{$priv}=1;
3430: }
1.60 www 3431: $full{$priv}=1;
3432: }
3433: my %domainlevel=();
1.61 www 3434: my %domainlevelcurrent=();
1.135 raeburn 3435: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3436: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3437: if (!$restrict) { $restrict='F'; }
1.60 www 3438: $domainlevel{$priv}=$restrict;
1.61 www 3439: if ($dompriv=~/\:$priv/) {
3440: $domainlevelcurrent{$priv}=1;
3441: }
1.60 www 3442: $full{$priv}=1;
3443: }
1.61 www 3444: my %systemlevel=();
3445: my %systemlevelcurrent=();
1.135 raeburn 3446: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3447: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3448: if (!$restrict) { $restrict='F'; }
1.61 www 3449: $systemlevel{$priv}=$restrict;
3450: if ($syspriv=~/\:$priv/) {
3451: $systemlevelcurrent{$priv}=1;
3452: }
3453: $full{$priv}=1;
3454: }
1.160 raeburn 3455: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 3456: my $button_code = "\n";
1.153 banghart 3457: my $head_script = "\n";
1.301 bisitz 3458: $head_script .= '<script type="text/javascript">'."\n"
3459: .'// <![CDATA['."\n";
1.154 banghart 3460: my @template_roles = ("cc","in","ta","ep","st");
3461: foreach my $role (@template_roles) {
3462: $head_script .= &make_script_template($role);
1.264 bisitz 3463: $button_code .= &make_button_code($role).' ';
1.154 banghart 3464: }
1.301 bisitz 3465: $head_script .= "\n".$jsback."\n"
3466: .'// ]]>'."\n"
3467: .'</script>'."\n";
1.153 banghart 3468: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 3469: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3470: ({href=>"javascript:backPage(document.form1,'pickrole','')",
3471: text=>"Pick custom role",
1.160 raeburn 3472: faq=>282,bug=>'Instructor Interface',},
3473: {href=>"javascript:backPage(document.form1,'','')",
3474: text=>"Edit custom role",
3475: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3476: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3477: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3478:
1.153 banghart 3479: $r->print($body_top);
1.73 sakharuk 3480: my %lt=&Apache::lonlocal::texthash(
3481: 'prv' => "Privilege",
1.131 raeburn 3482: 'crl' => "Course Level",
1.73 sakharuk 3483: 'dml' => "Domain Level",
1.150 banghart 3484: 'ssl' => "System Level");
1.264 bisitz 3485:
3486: $r->print('<div>'
3487: .'<form action=""><fieldset>'
3488: .'<legend>'.&mt('Select a Template').'</legend>'
3489: .$button_code
3490: .'</fieldset></form>'
3491: .'</div>'
3492: );
3493:
1.61 www 3494: $r->print(<<ENDCCF);
1.160 raeburn 3495: <form name="form1" method="post">
1.61 www 3496: <input type="hidden" name="phase" value="set_custom_roles" />
3497: <input type="hidden" name="rolename" value="$rolename" />
3498: ENDCCF
1.135 raeburn 3499: $r->print(&Apache::loncommon::start_data_table().
3500: &Apache::loncommon::start_data_table_header_row().
3501: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
3502: '</th><th>'.$lt{'ssl'}.'</th>'.
3503: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 3504: foreach my $priv (sort keys %full) {
3505: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 3506: $r->print(&Apache::loncommon::start_data_table_row().
3507: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 3508: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
3509: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3510: '</td><td>'.
1.288 bisitz 3511: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
3512: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3513: '</td><td>'.
1.288 bisitz 3514: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
3515: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.135 raeburn 3516: '</td>'.
3517: &Apache::loncommon::end_data_table_row());
1.60 www 3518: }
1.135 raeburn 3519: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 3520: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 3521: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 3522: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 3523: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.282 schafran 3524: '<input type="submit" value="'.&mt('Save').'" /></form>'.
1.110 albertel 3525: &Apache::loncommon::end_page());
1.61 www 3526: }
1.153 banghart 3527: # --------------------------------------------------------
3528: sub make_script_template {
3529: my ($role) = @_;
3530: my %full_c=();
3531: my %full_d=();
3532: my %full_s=();
3533: my $return_script;
3534: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3535: my ($priv,$restrict)=split(/\&/,$item);
3536: $full_c{$priv}=1;
3537: }
3538: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3539: my ($priv,$restrict)=split(/\&/,$item);
3540: $full_d{$priv}=1;
3541: }
1.154 banghart 3542: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 3543: my ($priv,$restrict)=split(/\&/,$item);
3544: $full_s{$priv}=1;
3545: }
3546: $return_script .= 'function set_'.$role.'() {'."\n";
3547: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
3548: my %role_c;
1.155 banghart 3549: foreach my $priv (@temp) {
1.153 banghart 3550: my ($priv_item, $dummy) = split(/\&/,$priv);
3551: $role_c{$priv_item} = 1;
3552: }
1.269 raeburn 3553: my %role_d;
3554: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
3555: foreach my $priv(@temp) {
3556: my ($priv_item, $dummy) = split(/\&/,$priv);
3557: $role_d{$priv_item} = 1;
3558: }
3559: my %role_s;
3560: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
3561: foreach my $priv(@temp) {
3562: my ($priv_item, $dummy) = split(/\&/,$priv);
3563: $role_s{$priv_item} = 1;
3564: }
1.153 banghart 3565: foreach my $priv_item (keys(%full_c)) {
3566: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3567: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
3568: (exists($role_s{$priv}))) {
1.153 banghart 3569: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
3570: } else {
3571: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
3572: }
3573: }
1.154 banghart 3574: foreach my $priv_item (keys(%full_d)) {
3575: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3576: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 3577: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
3578: } else {
3579: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
3580: }
3581: }
3582: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 3583: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 3584: if (exists($role_s{$priv})) {
3585: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
3586: } else {
3587: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
3588: }
1.153 banghart 3589: }
3590: $return_script .= '}'."\n";
1.154 banghart 3591: return ($return_script);
3592: }
3593: # ----------------------------------------------------------
3594: sub make_button_code {
3595: my ($role) = @_;
3596: my $label = &Apache::lonnet::plaintext($role);
1.301 bisitz 3597: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 3598: return ($button_code);
1.153 banghart 3599: }
1.61 www 3600: # ---------------------------------------------------------- Call to definerole
3601: sub set_custom_role {
1.240 raeburn 3602: my ($r,$context) = @_;
1.101 albertel 3603: my $rolename=$env{'form.rolename'};
1.63 www 3604: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 3605: if (!$rolename) {
1.190 raeburn 3606: &custom_role_editor($r);
1.61 www 3607: return;
3608: }
1.160 raeburn 3609: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 3610: my $jscript = '<script type="text/javascript">'
3611: .'// <![CDATA['."\n"
3612: .$jsback."\n"
3613: .'// ]]>'."\n"
3614: .'</script>'."\n";
1.160 raeburn 3615:
3616: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
3617: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3618: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
3619: text=>"Pick custom role",
1.160 raeburn 3620: faq=>282,bug=>'Instructor Interface',},
3621: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
3622: text=>"Edit custom role",
3623: faq=>282,bug=>'Instructor Interface',},
3624: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
3625: text=>"Result",
3626: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3627: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3628: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3629:
1.61 www 3630: my ($rdummy,$roledef)=
1.110 albertel 3631: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
3632:
1.61 www 3633: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 3634: $r->print('<h3>');
1.61 www 3635: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 3636: $r->print(&mt('Existing Role').' "');
1.61 www 3637: } else {
1.73 sakharuk 3638: $r->print(&mt('New Role').' "');
1.61 www 3639: $roledef='';
3640: }
1.188 raeburn 3641: $r->print($rolename.'"</h3>');
1.61 www 3642: # ------------------------------------------------------- What can be assigned?
3643: my $sysrole='';
3644: my $domrole='';
3645: my $courole='';
3646:
1.135 raeburn 3647: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3648: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3649: if (!$restrict) { $restrict=''; }
3650: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 3651: $courole.=':'.$item;
1.61 www 3652: }
3653: }
3654:
1.135 raeburn 3655: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3656: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3657: if (!$restrict) { $restrict=''; }
3658: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 3659: $domrole.=':'.$item;
1.61 www 3660: }
3661: }
3662:
1.135 raeburn 3663: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3664: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3665: if (!$restrict) { $restrict=''; }
3666: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 3667: $sysrole.=':'.$item;
1.61 www 3668: }
3669: }
1.63 www 3670: $r->print('<br />Defining Role: '.
1.61 www 3671: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 3672: if ($env{'request.course.id'}) {
3673: my $url='/'.$env{'request.course.id'};
1.63 www 3674: $url=~s/\_/\//g;
1.73 sakharuk 3675: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 3676: &Apache::lonnet::assigncustomrole($env{'user.domain'},
3677: $env{'user.name'},
1.63 www 3678: $url,
1.101 albertel 3679: $env{'user.domain'},
3680: $env{'user.name'},
1.240 raeburn 3681: $rolename,undef,undef,undef,$context));
1.63 www 3682: }
1.190 raeburn 3683: $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 3684: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 3685: $r->print(&Apache::loncommon::end_page());
1.58 www 3686: }
3687:
1.2 www 3688: # ================================================================ Main Handler
3689: sub handler {
3690: my $r = shift;
3691: if ($r->header_only) {
1.68 www 3692: &Apache::loncommon::content_type($r,'text/html');
1.2 www 3693: $r->send_http_header;
3694: return OK;
3695: }
1.190 raeburn 3696: my $context;
3697: if ($env{'request.course.id'}) {
3698: $context = 'course';
3699: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 3700: $context = 'author';
1.190 raeburn 3701: } else {
3702: $context = 'domain';
3703: }
3704: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 3705: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
3706: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 3707: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 3708: if ($env{'form.action'} ne 'dateselect') {
3709: &Apache::lonhtmlcommon::add_breadcrumb
3710: ({href=>"/adm/createuser",
1.289 droeschl 3711: text=>"User Management",
3712: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'});
1.202 raeburn 3713: }
1.289 droeschl 3714: #SD Following files not added to help, because the corresponding .tex-files seem to
3715: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 3716: my ($permission,$allowed) =
3717: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 3718: if (!$allowed) {
3719: $env{'user.error.msg'}=
3720: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
3721: "or view user status.";
3722: return HTTP_NOT_ACCEPTABLE;
3723: }
3724:
3725: &Apache::loncommon::content_type($r,'text/html');
3726: $r->send_http_header;
3727:
3728: # Main switch on form.action and form.state, as appropriate
3729: if (! exists($env{'form.action'})) {
3730: $r->print(&header());
3731: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 3732: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3733: $r->print(&Apache::loncommon::end_page());
3734: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
3735: $r->print(&header());
3736: &Apache::lonhtmlcommon::add_breadcrumb
3737: ({href=>'/adm/createuser?action=upload&state=',
3738: text=>"Upload Users List"});
3739: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 3740: 'Course_Create_Class_List'));
1.190 raeburn 3741: $r->print('<form name="studentform" method="post" '.
3742: 'enctype="multipart/form-data" '.
3743: ' action="/adm/createuser">'."\n");
3744: if (! exists($env{'form.state'})) {
3745: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3746: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 3747: &Apache::lonuserutils::print_upload_manager_form($r,$context,
3748: $permission);
1.190 raeburn 3749: } elsif ($env{'form.state'} eq 'enrolling') {
3750: if ($env{'form.datatoken'}) {
1.221 raeburn 3751: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 3752: }
3753: } else {
3754: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3755: }
3756: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 3757: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
3758: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 3759: my $phase = $env{'form.phase'};
3760: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 3761: &Apache::loncreateuser::restore_prev_selections();
3762: my $srch;
3763: foreach my $item (@search) {
3764: $srch->{$item} = $env{'form.'.$item};
3765: }
1.207 raeburn 3766: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
3767: ($phase eq 'createnewuser')) {
3768: if ($env{'form.phase'} eq 'createnewuser') {
3769: my $response;
3770: if ($env{'form.srchterm'} !~ /^$match_username$/) {
3771: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 3772: $env{'form.phase'} = '';
1.207 raeburn 3773: &print_username_entry_form($r,$context,$response,$srch);
3774: } else {
3775: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
3776: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
3777: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3778: $srch,$response,$context,
3779: $permission);
1.207 raeburn 3780: }
3781: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 3782: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 3783: &user_search_result($context,$srch);
1.190 raeburn 3784: if ($env{'form.currstate'} eq 'modify') {
3785: $currstate = $env{'form.currstate'};
3786: }
3787: if ($currstate eq 'select') {
3788: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 3789: \@search,$context);
1.190 raeburn 3790: } elsif ($currstate eq 'modify') {
3791: my ($ccuname,$ccdomain);
3792: if (($srch->{'srchby'} eq 'uname') &&
3793: ($srch->{'srchtype'} eq 'exact')) {
3794: $ccuname = $srch->{'srchterm'};
3795: $ccdomain= $srch->{'srchdomain'};
3796: } else {
3797: my @matchedunames = keys(%{$results});
3798: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
3799: }
3800: $ccuname =&LONCAPA::clean_username($ccuname);
3801: $ccdomain=&LONCAPA::clean_domain($ccdomain);
3802: if ($env{'form.forcenewuser'}) {
3803: $response = '';
3804: }
3805: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3806: $srch,$response,$context,
3807: $permission);
1.190 raeburn 3808: } elsif ($currstate eq 'query') {
3809: &print_user_query_page($r,'createuser');
3810: } else {
1.229 raeburn 3811: $env{'form.phase'} = '';
1.207 raeburn 3812: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 3813: $forcenewuser);
3814: }
3815: } elsif ($env{'form.phase'} eq 'userpicked') {
3816: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
3817: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 3818: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 3819: $context,$permission);
1.190 raeburn 3820: }
3821: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 3822: &update_user_data($r,$context);
1.190 raeburn 3823: } else {
1.207 raeburn 3824: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 3825: }
3826: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
3827: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 3828: &set_custom_role($r,$context);
1.190 raeburn 3829: } else {
3830: &custom_role_editor($r);
3831: }
1.207 raeburn 3832: } elsif (($env{'form.action'} eq 'listusers') &&
3833: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 3834: if ($env{'form.phase'} eq 'bulkchange') {
3835: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 3836: ({href=>'/adm/createuser?action=listusers',
3837: text=>"List Users"},
3838: {href=>"/adm/createuser",
3839: text=>"Result"});
1.202 raeburn 3840: my $setting = $env{'form.roletype'};
3841: my $choice = $env{'form.bulkaction'};
3842: $r->print(&header());
1.221 raeburn 3843: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 3844: 'Course_View_Class_List'));
1.202 raeburn 3845: if ($permission->{'cusr'}) {
3846: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 3847: $r->print(&Apache::loncommon::end_page());
3848: } else {
3849: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 3850: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 3851: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3852: }
3853: } else {
3854: &Apache::lonhtmlcommon::add_breadcrumb
3855: ({href=>'/adm/createuser?action=listusers',
3856: text=>"List Users"});
3857: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
3858: my $formname = 'studentform';
3859: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
3860: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
3861: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
3862: $formname);
3863: $jscript .= &verify_user_display();
3864: my $js = &add_script($jscript).$cb_jscript;
3865: my $loadcode =
3866: &Apache::lonuserutils::course_selector_loadcode($formname);
3867: if ($loadcode ne '') {
3868: $r->print(&header($js,{'onload' => $loadcode,}));
3869: } else {
3870: $r->print(&header($js));
3871: }
1.191 raeburn 3872: } else {
1.202 raeburn 3873: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 3874: }
1.202 raeburn 3875: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3876: 'Course_View_Class_List'));
1.202 raeburn 3877: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3878: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3879: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3880: }
1.213 raeburn 3881: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3882: $r->print(&header());
3883: &Apache::lonhtmlcommon::add_breadcrumb
3884: ({href=>'/adm/createuser?action=drop',
3885: text=>"Drop Students"});
3886: if (!exists($env{'form.state'})) {
3887: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3888: 'Course_Drop_Student'));
3889:
3890: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
3891: } elsif ($env{'form.state'} eq 'done') {
3892: &Apache::lonhtmlcommon::add_breadcrumb
3893: ({href=>'/adm/createuser?action=drop',
3894: text=>"Result"});
3895: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3896: 'Course_Drop_Student'));
3897: &Apache::lonuserutils::update_user_list($r,$context,undef,
3898: $env{'form.action'});
3899: }
3900: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3901: } elsif ($env{'form.action'} eq 'dateselect') {
3902: if ($permission->{'cusr'}) {
3903: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 3904: &Apache::lonuserutils::date_section_selector($context,
3905: $permission).
1.202 raeburn 3906: &Apache::loncommon::end_page());
3907: } else {
3908: $r->print(&header().
3909: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
3910: &Apache::loncommon::end_page());
3911: }
1.237 raeburn 3912: } elsif ($env{'form.action'} eq 'selfenroll') {
3913: $r->print(&header());
3914: &Apache::lonhtmlcommon::add_breadcrumb
3915: ({href=>'/adm/createuser?action=selfenroll',
3916: text=>"Configure Self-enrollment"});
3917: if (!exists($env{'form.state'})) {
3918: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
3919: 'Course_Self_Enrollment'));
1.241 raeburn 3920: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 3921: &print_selfenroll_menu($r,$context,$permission);
3922: } elsif ($env{'form.state'} eq 'done') {
3923: &Apache::lonhtmlcommon::add_breadcrumb
3924: ({href=>'/adm/createuser?action=selfenroll',
3925: text=>"Result"});
3926: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
3927: 'Course_Self_Enrollment'));
1.241 raeburn 3928: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
3929: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 3930: }
3931: $r->print(&Apache::loncommon::end_page());
1.277 raeburn 3932: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
3933: $r->print(&header());
3934: &Apache::lonhtmlcommon::add_breadcrumb
3935: ({href=>'/adm/createuser?action=selfenrollqueue',
3936: text=>"Enrollment requests"});
3937: my $cid = $env{'request.course.id'};
3938: my $cdom = $env{'course.'.$cid.'.domain'};
3939: my $cnum = $env{'course.'.$cid.'.num'};
3940: if (!exists($env{'form.state'})) {
3941: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests',
3942: 'Course_SelfEnrollment_Approval'));
3943: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
3944: &display_selfenroll_queue($r,$context,$permission,$cnum,$cdom);
3945: } elsif ($env{'form.state'} eq 'done') {
3946: &Apache::lonhtmlcommon::add_breadcrumb
3947: ({href=>'/adm/createuser?action=selfenrollqueue',
3948: text=>"Result"});
3949: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result',
3950: 'Course_Self_Enrollment'));
3951: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
3952: &update_selfenroll_queue($r,$context,$permission,$cid,$cnum,$cdom);
3953: }
3954: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 3955: } elsif ($env{'form.action'} eq 'changelogs') {
3956: $r->print(&header());
3957: &Apache::lonhtmlcommon::add_breadcrumb
3958: ({href=>'/adm/createuser?action=changelogs',
3959: text=>"User Management Logs"});
3960: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
3961: 'Course_User_Logs'));
3962: &print_userchangelogs_display($r,$context,$permission);
3963: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 3964: } else {
3965: $r->print(&header());
1.202 raeburn 3966: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 3967: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3968: $r->print(&Apache::loncommon::end_page());
3969: }
3970: return OK;
3971: }
3972:
3973: sub header {
1.202 raeburn 3974: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 3975: my $start_page;
3976: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 3977: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 3978: } else {
1.202 raeburn 3979: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 3980: }
3981: return $start_page;
3982: }
1.2 www 3983:
1.191 raeburn 3984: sub add_script {
3985: my ($js) = @_;
1.301 bisitz 3986: return '<script type="text/javascript">'."\n"
3987: .'// <![CDATA['."\n"
3988: .$js."\n"
3989: .'// ]]>'."\n"
3990: .'</script>'."\n";
1.191 raeburn 3991: }
3992:
1.202 raeburn 3993: sub verify_user_display {
3994: my $output = <<"END";
3995:
3996: function display_update() {
3997: document.studentform.action.value = 'listusers';
3998: document.studentform.phase.value = 'display';
3999: document.studentform.submit();
4000: }
4001:
4002: END
4003: return $output;
4004:
4005: }
4006:
1.190 raeburn 4007: ###############################################################
4008: ###############################################################
4009: # Menu Phase One
4010: sub print_main_menu {
1.208 raeburn 4011: my ($permission,$context) = @_;
4012: my %links = (
1.298 droeschl 4013: domain => {
4014: upload => 'Upload a File of Users',
4015: singleuser => 'Add/Modify a User',
4016: listusers => 'Manage Users',
4017: },
4018: author => {
4019: upload => 'Upload a File of Co-authors',
4020: singleuser => 'Add/Modify a Co-author',
4021: listusers => 'Manage Co-authors',
4022: },
4023: course => {
4024: upload => 'Upload a File of Course Users',
4025: singleuser => 'Add/Modify a Course User',
4026: listusers => 'Manage Course Users',
4027: },
4028: );
4029: my @menu = ( {categorytitle => 'Single Users',
4030: items =>
4031: [
4032: {
4033: linktext => $links{$context}{'singleuser'},
4034: icon => 'edit-redo.png',
4035: #help => 'Course_Change_Privileges',
4036: url => '/adm/createuser?action=singleuser',
4037: permission => $permission->{'cusr'},
4038: linktitle => 'Add a user with a certain role to this course.',
4039: },
4040: ]},
4041:
4042: {categorytitle => 'Multiple Users',
4043: items =>
4044: [
4045: {
4046: linktext => $links{$context}{'upload'},
4047: icon => 'sctr.png',
4048: #help => 'Course_Create_Class_List',
4049: url => '/adm/createuser?action=upload',
4050: permission => $permission->{'cusr'},
4051: linktitle => 'Upload a CSV or a text file containing users.',
4052: },
4053: {
4054: linktext => $links{$context}{'listusers'},
4055: icon => 'edit-find.png',
4056: #help => 'Course_View_Class_List',
4057: url => '/adm/createuser?action=listusers',
4058: permission => ($permission->{'view'} || $permission->{'cusr'}),
4059: linktitle => 'Show and manage users of this course.',
4060: },
4061:
4062: ]},
4063:
4064: {categorytitle => 'Administration',
4065: items => [ ]},
4066: );
4067:
1.265 mielkec 4068: if ($context eq 'domain'){
1.298 droeschl 4069:
4070: push(@{ $menu[2]->{items} }, #Category: Administration
4071: {
4072: linktext => 'Custom Roles',
4073: icon => 'emblem-photos.png',
4074: #help => 'Course_Editing_Custom_Roles',
4075: url => '/adm/createuser?action=custom',
4076: permission => $permission->{'custom'},
4077: linktitle => 'Configure a custom role.',
4078: },
4079: );
4080:
1.265 mielkec 4081: }elsif ($context eq 'course'){
1.298 droeschl 4082: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
4083:
4084: push(@{ $menu[0]->{items} }, #Category: Single Users
4085: {
4086: linktext => 'Add/Modify a Student',
4087: #help => 'Course_Add_Student',
4088: icon => 'list-add.png',
4089: url => '/adm/createuser?action=singlestudent',
4090: permission => $permission->{'cusr'},
4091: linktitle => 'Add a user with the role student to this course.',
4092: },
4093: );
4094:
4095: push(@{ $menu[1]->{items} }, #Category: Multiple Users
4096: {
4097: linktext => 'Drop Students',
4098: icon => 'edit-undo.png',
4099: #help => 'Course_Drop_Student',
4100: url => '/adm/createuser?action=drop',
4101: permission => $permission->{'cusr'},
4102: linktitle =>'Remove a student from this course.',
4103: },
4104: );
4105: push(@{ $menu[2]->{items} }, #Category: Administration
4106: {
4107: linktext => 'Custom Roles',
4108: icon => 'emblem-photos.png',
4109: #help => 'Course_Editing_Custom_Roles',
4110: url => '/adm/createuser?action=custom',
4111: permission => $permission->{'custom'},
4112: linktitle => 'Configure a custom role.',
4113: },
4114: {
4115: linktext => 'Course Groups',
4116: icon => 'conf.png',
4117: #help => 'Course_Manage_Group',
4118: url => '/adm/coursegroups?refpage=cusr',
4119: permission => $permission->{'grp_manage'},
4120: linktitle => 'Manage course groups.',
4121: },
4122: {
4123: linktext => 'Change Logs',
4124: icon => 'document-properties.png',
4125: #help => 'Course_User_Logs',
4126: url => '/adm/createuser?action=changelogs',
4127: permission => $permission->{'cusr'},
4128: linktitle => 'View change log.',
4129: },
4130: );
1.277 raeburn 4131: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 4132: push(@{ $menu[2]->{items} },
4133: {
4134: linktext => 'Enrollment Requests',
4135: icon => 'selfenrl-queue.png',
4136: #help => 'Course_Approve_Selfenroll',
4137: url => '/adm/createuser?action=selfenrollqueue',
4138: permission => $permission->{'cusr'},
4139: linktitle =>'Approve or reject enrollment requests.',
4140: },
4141: );
1.277 raeburn 4142: }
1.298 droeschl 4143:
1.265 mielkec 4144: if (!exists($permission->{'cusr_section'})){
1.298 droeschl 4145:
4146: push(@{ $menu[2]->{items} },
4147: {
4148: linktext => 'Automated Enrollment',
4149: icon => 'roles.png',
4150: #help => 'Course_Automated_Enrollment',
4151: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
4152: && $permission->{'cusr'}),
4153: url => '/adm/populate',
4154: linktitle => 'Automated enrollment manager.',
4155: },
4156: {
4157: linktext => 'User Self-Enrollment',
4158: icon => 'cstr.png',
4159: #help => 'Course_Self_Enrollment',
4160: url => '/adm/createuser?action=selfenroll',
4161: permission => $permission->{'cusr'},
4162: linktitle => 'Configure user self enrollment.',
4163: },
4164: );
4165:
4166: }
1.265 mielkec 4167: };
4168: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 4169: # { text => 'View Log-in History',
4170: # help => 'Course_User_Logins',
4171: # action => 'logins',
4172: # permission => $permission->{'cusr'},
4173: # });
1.190 raeburn 4174: }
4175:
1.189 albertel 4176: sub restore_prev_selections {
4177: my %saveable_parameters = ('srchby' => 'scalar',
4178: 'srchin' => 'scalar',
4179: 'srchtype' => 'scalar',
4180: );
4181: &Apache::loncommon::store_settings('user','user_picker',
4182: \%saveable_parameters);
4183: &Apache::loncommon::restore_settings('user','user_picker',
4184: \%saveable_parameters);
4185: }
4186:
1.237 raeburn 4187: sub print_selfenroll_menu {
4188: my ($r,$context,$permission) = @_;
4189: my $formname = 'enrollstudent';
4190: my $nolink = 1;
4191: my ($row,$lt) = &get_selfenroll_titles();
4192: my $groupslist = &Apache::lonuserutils::get_groupslist();
4193: my $setsec_js =
4194: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4195: my %alerts = &Apache::lonlocal::texthash(
4196: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4197: butn => 'but no user types have been checked.',
4198: wilf => "Please uncheck 'activate' or check at least one type.",
4199: );
4200: my $selfenroll_js = <<"ENDSCRIPT";
4201: function update_types(caller,num) {
4202: var delidx = getIndexByName('selfenroll_delete');
4203: var actidx = getIndexByName('selfenroll_activate');
4204: if (caller == 'selfenroll_all') {
4205: var selall;
4206: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4207: if (document.$formname.selfenroll_all[i].checked) {
4208: selall = document.$formname.selfenroll_all[i].value;
4209: }
4210: }
4211: if (selall == 1) {
4212: if (delidx != -1) {
4213: if (document.$formname.selfenroll_delete.length) {
4214: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4215: document.$formname.selfenroll_delete[j].checked = true;
4216: }
4217: } else {
4218: document.$formname.elements[delidx].checked = true;
4219: }
4220: }
4221: if (actidx != -1) {
4222: if (document.$formname.selfenroll_activate.length) {
4223: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4224: document.$formname.selfenroll_activate[j].checked = false;
4225: }
4226: } else {
4227: document.$formname.elements[actidx].checked = false;
4228: }
4229: }
4230: document.$formname.selfenroll_newdom.selectedIndex = 0;
4231: }
4232: }
4233: if (caller == 'selfenroll_activate') {
4234: if (document.$formname.selfenroll_activate.length) {
4235: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4236: if (document.$formname.selfenroll_activate[j].value == num) {
4237: if (document.$formname.selfenroll_activate[j].checked) {
4238: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4239: if (document.$formname.selfenroll_all[i].value == '1') {
4240: document.$formname.selfenroll_all[i].checked = false;
4241: }
4242: if (document.$formname.selfenroll_all[i].value == '0') {
4243: document.$formname.selfenroll_all[i].checked = true;
4244: }
4245: }
4246: }
4247: }
4248: }
4249: } else {
4250: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4251: if (document.$formname.selfenroll_all[i].value == '1') {
4252: document.$formname.selfenroll_all[i].checked = false;
4253: }
4254: if (document.$formname.selfenroll_all[i].value == '0') {
4255: document.$formname.selfenroll_all[i].checked = true;
4256: }
4257: }
4258: }
4259: }
4260: if (caller == 'selfenroll_delete') {
4261: if (document.$formname.selfenroll_delete.length) {
4262: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4263: if (document.$formname.selfenroll_delete[j].value == num) {
4264: if (document.$formname.selfenroll_delete[j].checked) {
4265: var delindex = getIndexByName('selfenroll_types_'+num);
4266: if (delindex != -1) {
4267: if (document.$formname.elements[delindex].length) {
4268: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4269: document.$formname.elements[delindex][k].checked = false;
4270: }
4271: } else {
4272: document.$formname.elements[delindex].checked = false;
4273: }
4274: }
4275: }
4276: }
4277: }
4278: } else {
4279: if (document.$formname.selfenroll_delete.checked) {
4280: var delindex = getIndexByName('selfenroll_types_'+num);
4281: if (delindex != -1) {
4282: if (document.$formname.elements[delindex].length) {
4283: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4284: document.$formname.elements[delindex][k].checked = false;
4285: }
4286: } else {
4287: document.$formname.elements[delindex].checked = false;
4288: }
4289: }
4290: }
4291: }
4292: }
4293: return;
4294: }
4295:
4296: function validate_types(form) {
4297: var needaction = new Array();
4298: var countfail = 0;
4299: var actidx = getIndexByName('selfenroll_activate');
4300: if (actidx != -1) {
4301: if (document.$formname.selfenroll_activate.length) {
4302: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4303: var num = document.$formname.selfenroll_activate[j].value;
4304: if (document.$formname.selfenroll_activate[j].checked) {
4305: countfail = check_types(num,countfail,needaction)
4306: }
4307: }
4308: } else {
4309: if (document.$formname.selfenroll_activate.checked) {
4310: var num = document.enrollstudent.selfenroll_activate.value;
4311: countfail = check_types(num,countfail,needaction)
4312: }
4313: }
4314: }
4315: if (countfail > 0) {
4316: var msg = "$alerts{'acto'}\\n";
4317: var loopend = needaction.length -1;
4318: if (loopend > 0) {
4319: for (var m=0; m<loopend; m++) {
4320: msg += needaction[m]+", ";
4321: }
4322: }
4323: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
4324: alert(msg);
4325: return;
4326: }
4327: setSections(form);
4328: }
4329:
4330: function check_types(num,countfail,needaction) {
4331: var typeidx = getIndexByName('selfenroll_types_'+num);
4332: var count = 0;
4333: if (typeidx != -1) {
4334: if (document.$formname.elements[typeidx].length) {
4335: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
4336: if (document.$formname.elements[typeidx][k].checked) {
4337: count ++;
4338: }
4339: }
4340: } else {
4341: if (document.$formname.elements[typeidx].checked) {
4342: count ++;
4343: }
4344: }
4345: if (count == 0) {
4346: var domidx = getIndexByName('selfenroll_dom_'+num);
4347: if (domidx != -1) {
4348: var domname = document.$formname.elements[domidx].value;
4349: needaction[countfail] = domname;
4350: countfail ++;
4351: }
4352: }
4353: }
4354: return countfail;
4355: }
4356:
4357: function getIndexByName(item) {
4358: for (var i=0;i<document.$formname.elements.length;i++) {
4359: if (document.$formname.elements[i].name == item) {
4360: return i;
4361: }
4362: }
4363: return -1;
4364: }
4365: ENDSCRIPT
1.256 raeburn 4366: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4367: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4368:
1.237 raeburn 4369: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 4370: '// <![CDATA['."\n".
1.249 raeburn 4371: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 4372: '// ]]>'."\n".
1.237 raeburn 4373: '</script>'."\n".
1.256 raeburn 4374: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
4375: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4376: if (ref($visactions) eq 'HASH') {
4377: if ($visible) {
1.283 bisitz 4378: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 4379: } else {
1.283 bisitz 4380: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
4381: .$visactions->{'yous'}.
1.256 raeburn 4382: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
4383: if (ref($vismsgs) eq 'ARRAY') {
4384: $output .= '<br />'.$visactions->{'make'}.'<ul>';
4385: foreach my $item (@{$vismsgs}) {
4386: $output .= '<li>'.$visactions->{$item}.'</li>';
4387: }
4388: $output .= '</ul>';
4389: }
4390: $output .= '</p>';
4391: }
4392: }
4393: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
4394: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 4395: if (ref($row) eq 'ARRAY') {
4396: foreach my $item (@{$row}) {
4397: my $title = $item;
4398: if (ref($lt) eq 'HASH') {
4399: $title = $lt->{$item};
4400: }
1.297 bisitz 4401: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 4402: if ($item eq 'types') {
4403: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 4404: my $showdomdesc = 1;
4405: my $includeempty = 1;
4406: my $num = 0;
4407: $output .= &Apache::loncommon::start_data_table().
4408: &Apache::loncommon::start_data_table_row()
4409: .'<td colspan="2"><span class="LC_nobreak"><label>'
4410: .&mt('Any user in any domain:')
4411: .' <input type="radio" name="selfenroll_all" value="1" ';
4412: if ($curr_types eq '*') {
4413: $output .= ' checked="checked" ';
4414: }
1.249 raeburn 4415: $output .= 'onchange="javascript:update_types('.
4416: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
4417: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 4418: if ($curr_types ne '*') {
4419: $output .= ' checked="checked" ';
4420: }
1.249 raeburn 4421: $output .= ' onchange="javascript:update_types('.
4422: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
4423: &Apache::loncommon::end_data_table_row().
4424: &Apache::loncommon::end_data_table().
4425: &mt('Or').'<br />'.
4426: &Apache::loncommon::start_data_table();
1.241 raeburn 4427: my %currdoms;
1.249 raeburn 4428: if ($curr_types eq '') {
1.241 raeburn 4429: $output .= &new_selfenroll_dom_row($cdom,'0');
4430: } elsif ($curr_types ne '*') {
4431: my @entries = split(/;/,$curr_types);
4432: if (@entries > 0) {
4433: foreach my $entry (@entries) {
4434: my ($currdom,$typestr) = split(/:/,$entry);
4435: $currdoms{$currdom} = 1;
4436: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 4437: my @currinsttypes = split(',',$typestr);
1.241 raeburn 4438: $output .= &Apache::loncommon::start_data_table_row()
4439: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
4440: .' '.$domdesc.' ('.$currdom.')'
4441: .'</b><input type="hidden" name="selfenroll_dom_'.$num
4442: .'" value="'.$currdom.'" /></span><br />'
4443: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 4444: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 4445: .&mt('Delete').'</label></span></td>';
1.249 raeburn 4446: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 4447: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
4448: .&Apache::loncommon::end_data_table_row();
4449: $num ++;
4450: }
4451: }
4452: }
1.249 raeburn 4453: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 4454: if ($curr_types eq '*') {
1.249 raeburn 4455: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 4456: } elsif ($curr_types eq '') {
1.249 raeburn 4457: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 4458: }
4459: $output .= &Apache::loncommon::start_data_table_row()
4460: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
4461: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
4462: $includeempty,$showdomdesc)
4463: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
4464: .'</td>'.&Apache::loncommon::end_data_table_row()
4465: .&Apache::loncommon::end_data_table();
1.237 raeburn 4466: } elsif ($item eq 'registered') {
4467: my ($regon,$regoff);
4468: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
4469: $regon = ' checked="checked" ';
4470: $regoff = ' ';
4471: } else {
4472: $regon = ' ';
4473: $regoff = ' checked="checked" ';
4474: }
4475: $output .= '<label>'.
1.245 raeburn 4476: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 4477: &mt('Yes').'</label> <label>'.
1.245 raeburn 4478: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 4479: &mt('No').'</label>';
1.237 raeburn 4480: } elsif ($item eq 'enroll_dates') {
4481: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
4482: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
4483: if ($starttime eq '') {
4484: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4485: }
4486: if ($endtime eq '') {
4487: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4488: }
4489: my $startform =
4490: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
4491: undef,undef,undef,undef,undef,undef,undef,$nolink);
4492: my $endform =
4493: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
4494: undef,undef,undef,undef,undef,undef,undef,$nolink);
4495: $output .= &selfenroll_date_forms($startform,$endform);
4496: } elsif ($item eq 'access_dates') {
4497: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
4498: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
4499: if ($starttime eq '') {
4500: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4501: }
4502: if ($endtime eq '') {
4503: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4504: }
4505: my $startform =
4506: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
4507: undef,undef,undef,undef,undef,undef,undef,$nolink);
4508: my $endform =
4509: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
4510: undef,undef,undef,undef,undef,undef,undef,$nolink);
4511: $output .= &selfenroll_date_forms($startform,$endform);
4512: } elsif ($item eq 'section') {
4513: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
4514: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4515: my $newsecval;
4516: if ($currsec ne 'none' && $currsec ne '') {
4517: if (!defined($sections_count{$currsec})) {
4518: $newsecval = $currsec;
4519: }
4520: }
4521: my $sections_select =
4522: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
4523: $output .= '<table class="LC_createuser">'."\n".
4524: '<tr class="LC_section_row">'."\n".
4525: '<td align="center">'.&mt('Existing sections')."\n".
4526: '<br />'.$sections_select.'</td><td align="center">'.
4527: &mt('New section').'<br />'."\n".
4528: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
4529: '<input type="hidden" name="sections" value="" />'."\n".
4530: '<input type="hidden" name="state" value="done" />'."\n".
4531: '</td></tr></table>'."\n";
1.276 raeburn 4532: } elsif ($item eq 'approval') {
4533: my ($appon,$appoff);
4534: my $cid = $env{'request.course.id'};
4535: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4536: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4537: $appon = ' checked="checked" ';
4538: $appoff = ' ';
4539: } else {
4540: $appon = ' ';
4541: $appoff = ' checked="checked" ';
4542: }
4543: $output .= '<label>'.
4544: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4545: &mt('Yes').'</label> <label>'.
4546: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4547: &mt('No').'</label>';
4548: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4549: my (@ccs,%notified);
4550: if ($advhash{'cc'}) {
4551: @ccs = split(/,/,$advhash{'cc'});
4552: }
4553: if ($currnotified) {
4554: foreach my $current (split(/,/,$currnotified)) {
4555: $notified{$current} = 1;
4556: if (!grep(/^\Q$current\E$/,@ccs)) {
4557: push(@ccs,$current);
4558: }
4559: }
4560: }
4561: if (@ccs) {
1.277 raeburn 4562: $output .= '<br />'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
1.276 raeburn 4563: &Apache::loncommon::start_data_table_row();
4564: my $count = 0;
4565: my $numcols = 4;
4566: foreach my $cc (sort(@ccs)) {
4567: my $notifyon;
4568: my ($ccuname,$ccudom) = split(/:/,$cc);
4569: if ($notified{$cc}) {
4570: $notifyon = ' checked="checked" ';
4571: }
4572: if ($count && !$count%$numcols) {
4573: $output .= &Apache::loncommon::end_data_table_row().
4574: &Apache::loncommon::start_data_table_row()
4575: }
4576: $output .= '<td><span class="LC_nobreak"><label>'.
4577: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4578: &Apache::loncommon::plainname($ccuname,$ccudom).
4579: '</label></span></td>';
4580: $count;
4581: }
4582: my $rem = $count%$numcols;
4583: if ($rem) {
4584: my $emptycols = $numcols - $rem;
4585: for (my $i=0; $i<$emptycols; $i++) {
4586: $output .= '<td> </td>';
4587: }
4588: }
4589: $output .= &Apache::loncommon::end_data_table_row().
4590: &Apache::loncommon::end_data_table();
4591: }
4592: } elsif ($item eq 'limit') {
4593: my ($crslimit,$selflimit,$nolimit);
4594: my $cid = $env{'request.course.id'};
4595: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4596: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4597: my $nolimit = ' checked="checked" ';
4598: if ($currlim eq 'allstudents') {
4599: $crslimit = ' checked="checked" ';
4600: $selflimit = ' ';
4601: $nolimit = ' ';
4602: } elsif ($currlim eq 'selfenrolled') {
4603: $crslimit = ' ';
4604: $selflimit = ' checked="checked" ';
4605: $nolimit = ' ';
4606: } else {
4607: $crslimit = ' ';
4608: $selflimit = ' ';
4609: }
4610: $output .= '<table><tr><td><label>'.
1.278 raeburn 4611: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4612: &mt('No limit').'</label></td><td><label>'.
4613: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4614: &mt('Limit by total students').'</label></td><td><label>'.
4615: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4616: &mt('Limit by total self-enrolled students').
4617: '</td></tr><tr>'.
4618: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4619: (' 'x3).&mt('Maximum number allowed: ').
4620: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4621: }
4622: $output .= &Apache::lonhtmlcommon::row_closure(1);
4623: }
4624: }
4625: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4626: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 4627: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4628: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4629: $r->print($output);
4630: return;
4631: }
4632:
1.277 raeburn 4633: sub display_selfenroll_queue {
4634: my ($r,$context,$permission,$cnum,$cdom) = @_;
4635: my $namespace = 'selfenrollrequests';
4636: my ($output,%queue_by_date);
4637: my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
4638: if (keys(%requesthash) > 0) {
4639: $r->print('<form method="post" name="changequeue" action="/adm/createuser" />'.
4640: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4641: '<input type="hidden" name="state" value="done" />'.
4642: &Apache::loncommon::start_data_table().
4643: &Apache::loncommon::start_data_table_header_row().
4644: '<th>'.&mt('Action').'</th>'.
4645: '<th>'.&mt('Requestor').'</th>'.
4646: '<th>'.&mt('Section').'</th>'.
4647: '<th>'.&mt('Date requested').'</th>'.
4648: &Apache::loncommon::end_data_table_header_row());
4649: foreach my $item (keys(%requesthash)) {
4650: my ($timestamp,$usec) = split(/:/,$requesthash{$item});
4651: if (exists($queue_by_date{$timestamp})) {
4652: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
4653: push(@{$queue_by_date{$timestamp}},$item.':'.$usec);
4654: }
4655: } else {
4656: @{$queue_by_date{$timestamp}} = ($item.':'.$usec);
4657: }
4658: }
4659: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
4660: my $count = 0;
4661: foreach my $item (@sortedtimes) {
4662: if (ref($queue_by_date{$item}) eq 'ARRAY') {
4663: foreach my $request (sort(@{$queue_by_date{$item}})) {
4664: my ($puname,$pudom,$pusec) = split(/:/,$request);
4665: my $showsec = $pusec;
4666: if ($showsec eq '') {
4667: $showsec = &mt('none');
4668: }
4669: my $namelink = &Apache::loncommon::aboutmewrapper(
4670: &Apache::loncommon::plainname($puname,$pudom),
4671: $puname,$pudom);
4672: $r->print(&Apache::loncommon::start_data_table_row().
4673: '<td><span class="LC_nobreak"><label>'.
4674: '<input type="checkbox" value="'.$count.':'.$puname.':'.$pudom.':'.$pusec.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
4675: '<span class="LC_nobreak"><label>'.
4676: '<input type="checkbox" value="'.$puname.':'.$pudom.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
4677: '<td>'.$namelink.'</td>'.
4678: '<td>'.$showsec.'</td>'.
4679: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
4680: &Apache::loncommon::end_data_table_row());
4681: $count ++;
4682: }
4683: }
4684: }
4685: $r->print(&Apache::loncommon::end_data_table().
4686: '<input type="submit" name="processqueue" value="'.&mt('Save').'" /></form>');
4687: } else {
4688: $r->print(&mt('There are currently no enrollment requests.'));
4689: }
4690: return;
4691: }
4692:
4693: sub update_selfenroll_queue {
4694: my ($r,$context,$permission,$cid,$cnum,$cdom) = @_;
4695: my @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
4696: my @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
4697: my $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
4698: my $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
4699: my $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4700: my $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4701: my $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4702: my $namespace = 'selfenrollrequests';
4703: my ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
4704: my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
4705: my $coursedesc = $env{'course.'.$cid.'.description'};
4706: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
4707: my $hostname = &Apache::lonnet::hostname($chome);
4708: my $protocol = $Apache::lonnet::protocol{$chome};
4709: $protocol = 'http' if ($protocol ne 'https');
1.280 raeburn 4710: my (@existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,
4711: @enrollerrors,@warn_approves,@warn_rejects);
1.277 raeburn 4712: my $now = time;
4713: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
4714: my $approvedmsg = [{
4715: mt => 'Your request for enrollment has been approved.',
4716: },
4717: {
4718: mt => 'Visit [_1], to log-in and access the course',
4719: args => [$protocol.'://'.$hostname],
4720: }];
4721:
4722: my $rejectedmsg = [{
4723: mt => 'Your request for enrollment has not been approved.',
4724: }];
4725: foreach my $item (sort {$a <=> $b} @approvals) {
4726: my ($num,$uname,$udom,$usec) = split(/:/,$item);
4727: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
4728: if ($uhome ne 'no_host') {
4729: if (exists($requesthash{$uname.':'.$udom})) {
4730:
4731: if (exists($classlist->{$uname.':'.$udom})) {
4732: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
4733: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
4734: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
4735: push(@existing,$uname.':'.$udom);
4736: next;
4737: }
4738: }
4739: }
4740: } else {
4741: push(@missingreq,$uname.':'.$udom);
4742: next;
4743: }
4744: if (!grep(/^\Q$item\E$/,@rejections)) {
4745: if ($limit eq 'allstudents') {
4746: if ($stucounts->{$limit} >= $cap) {
4747: push(@limitexceeded,$uname.':'.$udom);
4748: last;
4749: }
4750: } elsif ($limit eq 'selfenrolled') {
4751: if ($stucounts->{$limit} >= $cap) {
4752: push(@limitexceeded,$uname.':'.$udom);
4753: last;
4754: }
4755: }
4756: my $result =
4757: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
4758: if ($result eq 'ok') {
4759: push(@enrolled,$uname.':'.$udom);
4760: $stucounts->{'allstudents'} ++;
4761: $stucounts->{'selfenrolled'} ++;
4762: &Apache::selfenroll::send_notification($uname.':'.$udom,$approvedmsg,$cid,
4763: $coursedesc,$now,'enroller',$sender);
1.280 raeburn 4764: my %userrequest = (
4765: $cdom.'_'.$cnum => {
4766: timestamp => $now,
4767: section => $usec,
4768: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
4769: status => 'approved',
4770: }
4771: );
4772: my $userresult =
4773: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
4774: if ($userresult ne 'ok') {
4775: push(@warn_approves,$uname.':'.$udom);
4776: }
1.277 raeburn 4777: } else {
4778: push(@enrollerrors,$uname.':'.$udom);
4779: }
4780: }
4781: } else {
4782: push(@invalidusers,$uname.':'.$udom);
4783: }
4784: }
4785: my @changes = (@enrolled,@rejections);
4786: if (@rejections) {
4787: foreach my $user (@rejections) {
4788: &Apache::selfenroll::send_notification($user,$rejectedmsg,$cid,
4789: $coursedesc,$now,'enroller',$sender);
1.280 raeburn 4790: my ($uname,$udom) = split(/:/,$user);
4791: my %userrequest = (
4792: $cdom.'_'.$cnum => {
4793: timestamp => $now,
4794: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
4795: status => 'rejected',
4796: }
4797: );
4798: my $userresult =
4799: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
4800: if ($userresult ne 'ok') {
4801: push(@warn_rejects,$user);
4802: }
1.277 raeburn 4803: }
4804: }
4805: if (@changes) {
4806: my $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
4807: if ($delresult eq 'ok') {
4808: my $namelink =
4809: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
4810: my $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
4811: my ($approvedlist,$rejectedlist);
1.279 raeburn 4812: if (@enrolled) {
1.277 raeburn 4813: $approvedlist = join("\n",@enrolled);
4814: $r->print('<p>'.&mt('The following were enrolled in the course:').'<ul>');
4815: foreach my $user (@enrolled) {
4816: my ($uname,$udom) = split(/:/,$user);
4817: my $userlink =
4818: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
4819: $r->print('<li>'.$userlink.'</li>');
4820: }
4821: $r->print('</ul></p>');
4822: }
4823: if (@rejections) {
4824: $rejectedlist = join("\n",@rejections);
4825: $r->print('<p>'.&mt('The following enrollment requests were rejected:').'<ul>');
4826: foreach my $user (@rejections) {
4827: $r->print('<li>'.$user.'</li>');
4828: }
4829: $r->print('</ul></p>');
4830: }
4831: &Apache::selfenroll::send_notification($notifylist,$chgmsg,$cid,
4832: $coursedesc,$now,'managers',
4833: $sender,$approvedlist,$rejectedlist);
4834: }
4835: }
4836: if (@existing) {
4837: $r->print('<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>');
4838: foreach my $user (@existing) {
4839: $r->print('<li>'.$user.'</li>');
4840: }
4841: $r->print('</ul></p>');
4842: }
4843: if (@missingreq) {
4844: $r->print('<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>');
4845: foreach my $user (@missingreq) {
4846: $r->print('<li>'.$user.'</li>');
4847: }
4848: $r->print('</ul></p>');
4849: }
4850: if (@invalidusers) {
4851: $r->print('<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>');
4852: foreach my $user (@invalidusers) {
4853: $r->print('<li>'.$user.'</li>');
4854: }
4855: $r->print('</ul></p>');
4856: }
4857: if (@limitexceeded) {
4858: $r->print('<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>');
4859: foreach my $user (@limitexceeded) {
4860: $r->print('<li>'.$user.'</li>');
4861: }
4862: $r->print('</ul></p>');
4863: }
4864: if (@enrollerrors) {
4865: $r->print('<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>');
4866: foreach my $user (@enrollerrors) {
4867: $r->print('<li>'.$user.'</li>');
4868: }
4869: $r->print('</ul></p>');
4870: }
1.280 raeburn 4871: if (@warn_approves) {
4872: $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
4873: foreach my $user (@warn_approves) {
4874: $r->print('<li>'.$user.'</li>');
4875: }
4876: $r->print('</ul></p>');
4877: }
4878: if (@warn_rejects) {
4879: $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
4880: foreach my $user (@warn_rejects) {
4881: $r->print('<li>'.$user.'</li>');
4882: }
4883: $r->print('</ul></p>');
4884: }
1.277 raeburn 4885: return;
4886: }
4887:
4888: sub get_student_counts {
4889: my ($cdom,$cnum) = @_;
4890: my (%idx,%stucounts);
4891: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
4892: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
4893: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
4894: while (my ($student,$data) = each(%$classlist)) {
4895: if (($data->[$idx{'status'}] eq 'Active') ||
4896: ($data->[$idx{'status'}] eq 'Future')) {
4897: if ($data->[$idx{'type'}] eq 'selfenroll') {
4898: $stucounts{'selfenroll'} ++;
4899: }
4900: $stucounts{'allstudents'} ++;
4901: }
4902: }
4903: return (\%stucounts,\%idx,$classlist);
4904: }
4905:
1.256 raeburn 4906: sub visible_in_cat {
4907: my ($cdom,$cnum) = @_;
4908: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4909: my ($cathash,%settable,@vismsgs,$cansetvis);
4910: my %visactions = &Apache::lonlocal::texthash(
4911: vis => 'Your course currently appears in the Course Catalog for this domain.',
4912: 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.',
4913: miss => 'Your course does not currently appear in the Course Catalog for this domain.',
4914: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4915: 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.',
1.282 schafran 4916: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4917: take => 'Take the following action to ensure the course appears in the Catalog:',
4918: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4919: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4920: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4921: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4922: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4923: 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',
4924: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4925: );
1.261 raeburn 4926: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4927: $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>"');
4928: $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"<a href="/adm/parmset?action=crsenv">','</a>"');
1.256 raeburn 4929: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4930: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4931: $settable{'togglecats'} = 1;
4932: }
4933: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4934: $settable{'categorize'} = 1;
4935: }
4936: $cathash = $domconf{'coursecategories'}{'cats'};
4937: }
1.260 raeburn 4938: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4939: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4940: } elsif ($settable{'togglecats'}) {
4941: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
1.260 raeburn 4942: } elsif ($settable{'categorize'}) {
1.256 raeburn 4943: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4944: } else {
4945: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4946: }
4947:
4948: my %currsettings =
4949: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4950: $cdom,$cnum);
4951: my $visible = 0;
4952: if ($currsettings{'internal.coursecode'} ne '') {
4953: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4954: $cathash = $domconf{'coursecategories'}{'cats'};
4955: if (ref($cathash) eq 'HASH') {
4956: if ($cathash->{'instcode::0'} eq '') {
4957: push(@vismsgs,'dc_addinst');
4958: } else {
4959: $visible = 1;
4960: }
4961: } else {
4962: $visible = 1;
4963: }
4964: } else {
4965: $visible = 1;
4966: }
4967: } else {
4968: if (ref($cathash) eq 'HASH') {
4969: if ($cathash->{'instcode::0'} ne '') {
4970: push(@vismsgs,'dc_instcode');
4971: }
4972: } else {
4973: push(@vismsgs,'dc_instcode');
4974: }
4975: }
4976: if ($currsettings{'categories'} ne '') {
4977: my $cathash;
4978: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4979: $cathash = $domconf{'coursecategories'}{'cats'};
4980: if (ref($cathash) eq 'HASH') {
4981: if (keys(%{$cathash}) == 0) {
4982: push(@vismsgs,'dc_catalog');
4983: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
4984: push(@vismsgs,'dc_categories');
4985: } else {
4986: my @currcategories = split('&',$currsettings{'categories'});
4987: my $matched = 0;
4988: foreach my $cat (@currcategories) {
4989: if ($cathash->{$cat} ne '') {
4990: $visible = 1;
4991: $matched = 1;
4992: last;
4993: }
4994: }
4995: if (!$matched) {
1.260 raeburn 4996: if ($settable{'categorize'}) {
1.256 raeburn 4997: push(@vismsgs,'chgcat');
4998: } else {
4999: push(@vismsgs,'dc_chgcat');
5000: }
5001: }
5002: }
5003: }
5004: }
5005: } else {
5006: if (ref($cathash) eq 'HASH') {
5007: if ((keys(%{$cathash}) > 1) ||
5008: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5009: if ($settable{'categorize'}) {
1.256 raeburn 5010: push(@vismsgs,'addcat');
5011: } else {
5012: push(@vismsgs,'dc_addcat');
5013: }
5014: }
5015: }
5016: }
5017: if ($currsettings{'hidefromcat'} eq 'yes') {
5018: $visible = 0;
5019: if ($settable{'togglecats'}) {
5020: unshift(@vismsgs,'unhide');
5021: } else {
5022: unshift(@vismsgs,'dc_unhide')
5023: }
5024: }
5025: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5026: }
5027:
1.241 raeburn 5028: sub new_selfenroll_dom_row {
5029: my ($newdom,$num) = @_;
5030: my $domdesc = &Apache::lonnet::domain($newdom);
5031: my $output;
5032: if ($domdesc ne '') {
5033: $output .= &Apache::loncommon::start_data_table_row()
5034: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5035: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5036: .'" value="'.$newdom.'" /></span><br />'
5037: .'<span class="LC_nobreak"><label><input type="checkbox" '
5038: .'name="selfenroll_activate" value="'.$num.'" '
5039: .'onchange="javascript:update_types('
5040: ."'selfenroll_activate','$num'".');" />'
5041: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5042: my @currinsttypes;
5043: $output .= '<td>'.&mt('User types:').'<br />'
5044: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5045: .&Apache::loncommon::end_data_table_row();
5046: }
5047: return $output;
5048: }
5049:
5050: sub selfenroll_inst_types {
5051: my ($num,$currdom,$currinsttypes) = @_;
5052: my $output;
5053: my $numinrow = 4;
5054: my $count = 0;
5055: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5056: my $othervalue = 'any';
1.241 raeburn 5057: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5058: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5059: $othervalue = 'other';
5060: }
1.241 raeburn 5061: $output .= '<table><tr>';
5062: foreach my $type (@{$types}) {
5063: if (($count > 0) && ($count%$numinrow == 0)) {
5064: $output .= '</tr><tr>';
5065: }
5066: if (defined($usertypes->{$type})) {
1.257 raeburn 5067: my $esc_type = &escape($type);
1.241 raeburn 5068: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5069: $esc_type.'" ';
1.241 raeburn 5070: if (ref($currinsttypes) eq 'ARRAY') {
5071: if (@{$currinsttypes} > 0) {
1.249 raeburn 5072: if (grep(/^any$/,@{$currinsttypes})) {
5073: $output .= 'checked="checked"';
1.257 raeburn 5074: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5075: $output .= 'checked="checked"';
5076: }
1.249 raeburn 5077: } else {
5078: $output .= 'checked="checked"';
1.241 raeburn 5079: }
5080: }
5081: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5082: }
5083: $count ++;
5084: }
5085: if (($count > 0) && ($count%$numinrow == 0)) {
5086: $output .= '</tr><tr>';
5087: }
1.249 raeburn 5088: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5089: if (ref($currinsttypes) eq 'ARRAY') {
5090: if (@{$currinsttypes} > 0) {
1.249 raeburn 5091: if (grep(/^any$/,@{$currinsttypes})) {
5092: $output .= ' checked="checked"';
5093: } elsif ($othervalue eq 'other') {
5094: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5095: $output .= ' checked="checked"';
5096: }
1.241 raeburn 5097: }
1.249 raeburn 5098: } else {
5099: $output .= ' checked="checked"';
1.241 raeburn 5100: }
1.249 raeburn 5101: } else {
5102: $output .= ' checked="checked"';
1.241 raeburn 5103: }
5104: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5105: }
5106: return $output;
5107: }
5108:
1.237 raeburn 5109: sub selfenroll_date_forms {
5110: my ($startform,$endform) = @_;
5111: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5112: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5113: 'LC_oddrow_value')."\n".
5114: $startform."\n".
5115: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5116: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5117: 'LC_oddrow_value')."\n".
5118: $endform."\n".
5119: &Apache::lonhtmlcommon::row_closure(1).
5120: &Apache::lonhtmlcommon::end_pick_box();
5121: return $output;
5122: }
5123:
1.239 raeburn 5124: sub print_userchangelogs_display {
5125: my ($r,$context,$permission) = @_;
5126: my $formname = 'roleslog';
5127: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5128: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5129: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
5130: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5131:
5132: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
5133: my %saveable_parameters = ('show' => 'scalar',);
5134: &Apache::loncommon::store_course_settings('roles_log',
5135: \%saveable_parameters);
5136: &Apache::loncommon::restore_course_settings('roles_log',
5137: \%saveable_parameters);
5138: # set defaults
5139: my $now = time();
5140: my $defstart = $now - (7*24*3600); #7 days ago
5141: my %defaults = (
5142: page => '1',
5143: show => '10',
5144: role => 'any',
5145: chgcontext => 'any',
5146: rolelog_start_date => $defstart,
5147: rolelog_end_date => $now,
5148: );
5149: my $more_records = 0;
5150:
5151: # set current
5152: my %curr;
5153: foreach my $item ('show','page','role','chgcontext') {
5154: $curr{$item} = $env{'form.'.$item};
5155: }
5156: my ($startdate,$enddate) =
5157: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5158: $curr{'rolelog_start_date'} = $startdate;
5159: $curr{'rolelog_end_date'} = $enddate;
5160: foreach my $key (keys(%defaults)) {
5161: if ($curr{$key} eq '') {
5162: $curr{$key} = $defaults{$key};
5163: }
5164: }
1.248 raeburn 5165: my (%whodunit,%changed,$version);
5166: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
5167: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
1.239 raeburn 5168: my ($minshown,$maxshown);
1.255 raeburn 5169: $minshown = 1;
1.239 raeburn 5170: my $count = 0;
5171: if ($curr{'show'} ne &mt('all')) {
5172: $maxshown = $curr{'page'} * $curr{'show'};
5173: if ($curr{'page'} > 1) {
5174: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5175: }
5176: }
1.301 bisitz 5177:
5178: # Collect user change log data
5179: my $content = '';
1.239 raeburn 5180: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5181: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5182: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5183: if ($curr{'show'} ne &mt('all')) {
5184: if ($count >= $curr{'page'} * $curr{'show'}) {
5185: $more_records = 1;
5186: last;
5187: }
5188: }
5189: if ($curr{'role'} ne 'any') {
5190: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5191: }
5192: if ($curr{'chgcontext'} ne 'any') {
5193: if ($curr{'chgcontext'} eq 'selfenroll') {
5194: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5195: } else {
5196: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5197: }
5198: }
5199: $count ++;
5200: next if ($count < $minshown);
1.301 bisitz 5201:
1.239 raeburn 5202: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5203: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5204: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5205: }
5206: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5207: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5208: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5209: }
5210: my $sec = $roleslog{$id}{'logentry'}{'section'};
5211: if ($sec eq '') {
5212: $sec = &mt('None');
5213: }
5214: my ($rolestart,$roleend);
5215: if ($roleslog{$id}{'delflag'}) {
5216: $rolestart = &mt('deleted');
5217: $roleend = &mt('deleted');
5218: } else {
5219: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5220: $roleend = $roleslog{$id}{'logentry'}{'end'};
5221: if ($rolestart eq '' || $rolestart == 0) {
5222: $rolestart = &mt('No start date');
5223: } else {
5224: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5225: }
5226: if ($roleend eq '' || $roleend == 0) {
5227: $roleend = &mt('No end date');
5228: } else {
5229: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5230: }
5231: }
5232: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5233: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5234: $chgcontext = 'selfenroll';
5235: }
5236: my %lt = &rolechg_contexts();
5237: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5238: $chgcontext = $lt{$chgcontext};
5239: }
1.301 bisitz 5240: $content .=
5241: &Apache::loncommon::start_data_table_row()
5242: .'<td>'.$count.'</td>'
5243: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
5244: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
5245: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
5246: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'}).'</td>'
5247: .'<td>'.$sec.'</td>'
5248: .'<td>'.$chgcontext.'</td>'
5249: .'<td>'.$rolestart.'</td>'
5250: .'<td>'.$roleend.'</td>'
5251: .&Apache::loncommon::end_data_table_row();
5252: }
5253:
5254: # Form Footer
5255: my $form_footer =
5256: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
5257: .'<input type="hidden" name="action" value="changelogs" />'
5258: .'</form>';
5259:
5260: # Only display table, if content is available (has been collected above)
5261: if (!$content) {
5262: $r->print('<p class="LC_info">'
5263: .&mt('There are no records to display.')
5264: .'</p>'
5265: );
5266: $r->print($form_footer);
5267: return;
1.239 raeburn 5268: }
1.301 bisitz 5269:
5270: # Content to display, so create navigation and display table
5271:
5272: # Create Navigation:
5273: # Navigation Script
5274: my $nav_script = <<"ENDSCRIPT";
1.239 raeburn 5275: <script type="text/javascript">
1.301 bisitz 5276: // <![CDATA[
1.239 raeburn 5277: function chgPage(caller) {
5278: if (caller == 'previous') {
5279: document.$formname.page.value --;
5280: }
5281: if (caller == 'next') {
5282: document.$formname.page.value ++;
5283: }
5284: document.$formname.submit();
5285: return;
5286: }
1.301 bisitz 5287: // ]]>
1.239 raeburn 5288: </script>
5289: ENDSCRIPT
1.301 bisitz 5290: # Navigation Buttons
5291: my $nav_links;
5292: $nav_links = '<p>';
5293: if (($curr{'page'} > 1) || ($more_records)) {
5294: if ($curr{'page'} > 1) {
5295: $nav_links .= '<input type="button"'
5296: .' onclick="javascript:chgPage('."'previous'".');"'
5297: .' value="'.&mt('Previous [_1] changes',$curr{'show'})
5298: .'" /> ';
5299: }
5300: if ($more_records) {
5301: $nav_links .= '<input type="button"'
5302: .' onclick="javascript:chgPage('."'next'".');"'
5303: .' value="'.&mt('Next [_1] changes',$curr{'show'})
5304: .'" />';
5305: }
5306: }
5307: $nav_links .= '</p>';
5308:
5309: # Table Header
5310: my $tableheader =
1.303 bisitz 5311: &Apache::loncommon::start_data_table_header_row()
1.301 bisitz 5312: .'<th> </th>'
5313: .'<th>'.&mt('When').'</th>'
5314: .'<th>'.&mt('Who made the change').'</th>'
5315: .'<th>'.&mt('Changed User').'</th>'
5316: .'<th>'.&mt('Role').'</th>'
5317: .'<th>'.&mt('Section').'</th>'
5318: .'<th>'.&mt('Context').'</th>'
5319: .'<th>'.&mt('Start').'</th>'
5320: .'<th>'.&mt('End').'</th>'
5321: .&Apache::loncommon::end_data_table_header_row();
5322:
5323: # Print Content
5324: $r->print(
5325: $nav_script
5326: .$nav_links
5327: .&Apache::loncommon::start_data_table()
5328: .$tableheader
5329: .$content
5330: .&Apache::loncommon::end_data_table()
5331: .$nav_links
5332: .$form_footer
5333: );
1.239 raeburn 5334: return;
5335: }
5336:
5337: sub role_display_filter {
1.248 raeburn 5338: my ($formname,$cdom,$cnum,$curr,$version) = @_;
1.239 raeburn 5339: my $context = 'course';
5340: my $nolink = 1;
5341: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 5342: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5343: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5344: (&mt('all'),5,10,20,50,100,1000,10000)).
5345: '</td><td> </td>';
5346: my $startform =
5347: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5348: $curr->{'rolelog_start_date'},undef,
5349: undef,undef,undef,undef,undef,undef,$nolink);
5350: my $endform =
5351: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5352: $curr->{'rolelog_end_date'},undef,
5353: undef,undef,undef,undef,undef,undef,$nolink);
5354: my %lt = &rolechg_contexts();
1.301 bisitz 5355: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
5356: '<table><tr><td>'.&mt('After:').
5357: '</td><td>'.$startform.'</td></tr>'.
5358: '<tr><td>'.&mt('Before:').'</td>'.
5359: '<td>'.$endform.'</td></tr></table>'.
5360: '</td>'.
5361: '<td> </td>'.
1.239 raeburn 5362: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5363: '<select name="role"><option value="any"';
5364: if ($curr->{'role'} eq 'any') {
5365: $output .= ' selected="selected"';
5366: }
5367: $output .= '>'.&mt('Any').'</option>'."\n";
5368: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
5369: foreach my $role (@roles) {
5370: my $plrole;
5371: if ($role eq 'cr') {
5372: $plrole = &mt('Custom Role');
5373: } else {
5374: $plrole=&Apache::lonnet::plaintext($role);
5375: }
5376: my $selstr = '';
5377: if ($role eq $curr->{'role'}) {
5378: $selstr = ' selected="selected"';
5379: }
5380: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5381: }
1.301 bisitz 5382: $output .= '</select></td>'.
5383: '<td> </td>'.
5384: '<td valign="top"><b>'.
1.239 raeburn 5385: &mt('Context:').'</b><br /><select name="chgcontext">';
5386: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
5387: my $selstr = '';
5388: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 5389: $selstr = ' selected="selected"';
1.239 raeburn 5390: }
5391: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5392: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5393: }
5394: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5395: }
1.303 bisitz 5396: $output .= '</select></td>'
5397: .'</tr></table>';
5398:
5399: # Update Display button
5400: $output .= '<p>'
5401: .'<input type="submit" value="'.&mt('Update Display').'" />'
5402: .'</p>';
5403:
5404: # Server version info
5405: $output .= '<p class="LC_info">'
5406: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
5407: ,'2.6.99.0');
1.248 raeburn 5408: if ($version) {
1.303 bisitz 5409: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5410: }
5411: $output .= '</p><hr />';
1.239 raeburn 5412: return $output;
5413: }
5414:
5415: sub rolechg_contexts {
5416: my %lt = &Apache::lonlocal::texthash (
5417: any => 'Any',
5418: auto => 'Automated enrollment',
5419: updatenow => 'Roster Update',
5420: createcourse => 'Course Creation',
5421: course => 'User Management in course',
5422: domain => 'User Management in domain',
5423: selfenroll => 'Self-enrolled',
5424: );
5425: return %lt;
5426: }
5427:
1.27 matthew 5428: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5429: sub user_search_result {
1.221 raeburn 5430: my ($context,$srch) = @_;
1.160 raeburn 5431: my %allhomes;
5432: my %inst_matches;
5433: my %srch_results;
1.181 raeburn 5434: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5435: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 5436: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 5437: $response = &mt('Invalid search.');
5438: }
5439: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
5440: $response = &mt('Invalid search.');
5441: }
1.177 raeburn 5442: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 5443: $response = &mt('Invalid search.');
5444: }
5445: if ($srch->{'srchterm'} eq '') {
5446: $response = &mt('You must enter a search term.');
5447: }
1.183 raeburn 5448: if ($srch->{'srchterm'} =~ /^\s+$/) {
5449: $response = &mt('Your search term must contain more than just spaces.');
5450: }
1.160 raeburn 5451: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5452: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5453: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5454: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5455: }
5456: }
5457: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5458: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5459: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5460: my $unamecheck = $srch->{'srchterm'};
5461: if ($srch->{'srchtype'} eq 'contains') {
5462: if ($unamecheck !~ /^\w/) {
5463: $unamecheck = 'a'.$unamecheck;
5464: }
5465: }
5466: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5467: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5468: }
1.160 raeburn 5469: }
5470: }
1.180 raeburn 5471: if ($response ne '') {
5472: $response = '<span class="LC_warning">'.$response.'</span>';
5473: }
1.160 raeburn 5474: if ($srch->{'srchin'} eq 'instd') {
5475: my $instd_chk = &directorysrch_check($srch);
5476: if ($instd_chk ne 'ok') {
1.180 raeburn 5477: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5478: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5479: }
5480: }
5481: if ($response ne '') {
1.180 raeburn 5482: return ($currstate,$response);
1.160 raeburn 5483: }
5484: if ($srch->{'srchby'} eq 'uname') {
5485: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5486: if ($env{'form.forcenew'}) {
5487: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5488: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5489: if ($uhome eq 'no_host') {
5490: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5491: my $showdom = &display_domain_info($env{'request.role.domain'});
5492: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5493: } else {
1.179 raeburn 5494: $currstate = 'modify';
1.160 raeburn 5495: }
5496: } else {
1.179 raeburn 5497: $currstate = 'modify';
1.160 raeburn 5498: }
5499: } else {
5500: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 5501: if ($srch->{'srchtype'} eq 'exact') {
5502: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5503: if ($uhome eq 'no_host') {
1.179 raeburn 5504: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5505: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5506: } else {
1.179 raeburn 5507: $currstate = 'modify';
1.162 raeburn 5508: }
5509: } else {
5510: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5511: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5512: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5513: }
5514: } else {
1.167 albertel 5515: my $courseusers = &get_courseusers();
1.162 raeburn 5516: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 5517: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 5518: $currstate = 'modify';
1.162 raeburn 5519: } else {
1.179 raeburn 5520: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5521: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5522: }
1.160 raeburn 5523: } else {
1.167 albertel 5524: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 5525: my ($cuname,$cudomain) = split(/:/,$user);
5526: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 5527: my $matched = 0;
5528: if ($srch->{'srchtype'} eq 'begins') {
5529: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
5530: $matched = 1;
5531: }
5532: } else {
5533: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
5534: $matched = 1;
5535: }
5536: }
5537: if ($matched) {
1.167 albertel 5538: $srch_results{$user} =
5539: {&Apache::lonnet::get('environment',
5540: ['firstname',
5541: 'lastname',
1.194 albertel 5542: 'permanentemail'],
5543: $cudomain,$cuname)};
1.162 raeburn 5544: }
5545: }
5546: }
1.179 raeburn 5547: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5548: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5549: }
5550: }
5551: }
5552: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5553: $currstate = 'query';
1.160 raeburn 5554: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5555: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5556: if ($dirsrchres eq 'ok') {
5557: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5558: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5559: } else {
5560: my $showdom = &display_domain_info($srch->{'srchdomain'});
5561: $response = '<span class="LC_warning">'.
5562: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5563: '</span><br />'.
5564: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5565: '<br /><br />';
5566: }
1.160 raeburn 5567: }
5568: } else {
5569: if ($srch->{'srchin'} eq 'dom') {
5570: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5571: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5572: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5573: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 5574: my $courseusers = &get_courseusers();
5575: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 5576: my ($uname,$udom) = split(/:/,$user);
5577: my %names = &Apache::loncommon::getnames($uname,$udom);
5578: my %emails = &Apache::loncommon::getemails($uname,$udom);
5579: if ($srch->{'srchby'} eq 'lastname') {
5580: if ((($srch->{'srchtype'} eq 'exact') &&
5581: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 5582: (($srch->{'srchtype'} eq 'begins') &&
5583: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 5584: (($srch->{'srchtype'} eq 'contains') &&
5585: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
5586: $srch_results{$user} = {firstname => $names{'firstname'},
5587: lastname => $names{'lastname'},
5588: permanentemail => $emails{'permanentemail'},
5589: };
5590: }
5591: } elsif ($srch->{'srchby'} eq 'lastfirst') {
5592: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 5593: $srchlast =~ s/\s+$//;
5594: $srchfirst =~ s/^\s+//;
1.160 raeburn 5595: if ($srch->{'srchtype'} eq 'exact') {
5596: if (($names{'lastname'} eq $srchlast) &&
5597: ($names{'firstname'} eq $srchfirst)) {
5598: $srch_results{$user} = {firstname => $names{'firstname'},
5599: lastname => $names{'lastname'},
5600: permanentemail => $emails{'permanentemail'},
5601:
5602: };
5603: }
1.177 raeburn 5604: } elsif ($srch->{'srchtype'} eq 'begins') {
5605: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5606: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5607: $srch_results{$user} = {firstname => $names{'firstname'},
5608: lastname => $names{'lastname'},
5609: permanentemail => $emails{'permanentemail'},
5610: };
5611: }
5612: } else {
1.160 raeburn 5613: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5614: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5615: $srch_results{$user} = {firstname => $names{'firstname'},
5616: lastname => $names{'lastname'},
5617: permanentemail => $emails{'permanentemail'},
5618: };
5619: }
5620: }
5621: }
5622: }
1.179 raeburn 5623: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5624: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5625: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5626: $currstate = 'query';
1.160 raeburn 5627: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5628: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5629: if ($dirsrchres eq 'ok') {
5630: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5631: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5632: } else {
5633: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5634: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5635: '</span><br />'.
5636: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5637: '<br /><br />';
5638: }
1.160 raeburn 5639: }
5640: }
1.179 raeburn 5641: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5642: }
5643:
5644: sub directorysrch_check {
5645: my ($srch) = @_;
5646: my $can_search = 0;
5647: my $response;
5648: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5649: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5650: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5651: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5652: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5653: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5654: }
5655: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5656: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5657: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5658: }
5659: my @usertypes = split(/:/,$env{'environment.inststatus'});
5660: if (!@usertypes) {
5661: push(@usertypes,'default');
5662: }
5663: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5664: foreach my $type (@usertypes) {
5665: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5666: $can_search = 1;
5667: last;
5668: }
5669: }
5670: }
5671: if (!$can_search) {
5672: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5673: my @longtypes;
5674: foreach my $item (@usertypes) {
1.229 raeburn 5675: if (defined($insttypes->{$item})) {
5676: push (@longtypes,$insttypes->{$item});
5677: } elsif ($item eq 'default') {
5678: push (@longtypes,&mt('other'));
5679: }
1.160 raeburn 5680: }
5681: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5682: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5683: }
1.160 raeburn 5684: } else {
5685: $can_search = 1;
5686: }
5687: } else {
1.180 raeburn 5688: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5689: }
5690: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5691: uname => 'username',
1.160 raeburn 5692: lastfirst => 'last name, first name',
1.167 albertel 5693: lastname => 'last name',
1.172 raeburn 5694: contains => 'contains',
1.178 raeburn 5695: exact => 'as exact match to',
5696: begins => 'begins with',
1.160 raeburn 5697: );
5698: if ($can_search) {
5699: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5700: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5701: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5702: }
5703: } else {
1.180 raeburn 5704: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5705: }
5706: }
5707: if ($can_search) {
1.178 raeburn 5708: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5709: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5710: return 'ok';
5711: } else {
1.180 raeburn 5712: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5713: }
5714: } else {
5715: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5716: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5717: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5718: return 'ok';
5719: } else {
1.180 raeburn 5720: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5721: }
1.160 raeburn 5722: }
5723: }
5724: }
5725:
5726: sub get_courseusers {
5727: my %advhash;
1.167 albertel 5728: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5729: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5730: foreach my $role (sort(keys(%coursepersonnel))) {
5731: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5732: if (!exists($classlist->{$user})) {
5733: $classlist->{$user} = [];
5734: }
1.160 raeburn 5735: }
5736: }
1.167 albertel 5737: return $classlist;
1.160 raeburn 5738: }
5739:
5740: sub build_search_response {
1.221 raeburn 5741: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5742: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5743: my %names = (
5744: 'uname' => 'username',
5745: 'lastname' => 'last name',
5746: 'lastfirst' => 'last name, first name',
5747: 'crs' => 'this course',
1.180 raeburn 5748: 'dom' => 'LON-CAPA domain: ',
5749: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5750: );
5751:
5752: my %single = (
1.180 raeburn 5753: begins => 'A match',
1.160 raeburn 5754: contains => 'A match',
1.180 raeburn 5755: exact => 'An exact match',
1.160 raeburn 5756: );
5757: my %nomatch = (
1.180 raeburn 5758: begins => 'No match',
1.160 raeburn 5759: contains => 'No match',
1.180 raeburn 5760: exact => 'No exact match',
1.160 raeburn 5761: );
5762: if (keys(%srch_results) > 1) {
1.179 raeburn 5763: $currstate = 'select';
1.160 raeburn 5764: } else {
5765: if (keys(%srch_results) == 1) {
1.179 raeburn 5766: $currstate = 'modify';
1.180 raeburn 5767: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5768: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5769: $response .= &display_domain_info($srch->{'srchdomain'});
5770: }
1.160 raeburn 5771: } else {
1.180 raeburn 5772: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
5773: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5774: $response .= &display_domain_info($srch->{'srchdomain'});
5775: }
5776: $response .= '</span>';
1.160 raeburn 5777: if ($srch->{'srchin'} ne 'alc') {
5778: $forcenewuser = 1;
5779: my $cansrchinst = 0;
5780: if ($srch->{'srchdomain'}) {
5781: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5782: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5783: if ($domconfig{'directorysrch'}{'available'}) {
5784: $cansrchinst = 1;
5785: }
5786: }
5787: }
1.180 raeburn 5788: if ((($srch->{'srchby'} eq 'lastfirst') ||
5789: ($srch->{'srchby'} eq 'lastname')) &&
5790: ($srch->{'srchin'} eq 'dom')) {
5791: if ($cansrchinst) {
5792: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5793: }
5794: }
1.180 raeburn 5795: if ($srch->{'srchin'} eq 'crs') {
5796: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5797: }
5798: }
1.305 raeburn 5799: my $createdom = $env{'request.role.domain'};
5800: if ($context eq 'requestcrs') {
5801: if ($env{'form.coursedom'} ne '') {
5802: $createdom = $env{'form.coursedom'};
5803: }
5804: }
5805: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 5806: my $cancreate =
1.305 raeburn 5807: &Apache::lonuserutils::can_create_user($createdom,$context);
5808: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 5809: if ($cancreate) {
1.305 raeburn 5810: my $showdom = &display_domain_info($createdom);
1.266 bisitz 5811: $response .= '<br /><br />'
5812: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 5813: .'<br />';
5814: if ($context eq 'requestcrs') {
5815: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
5816: } else {
5817: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
5818: }
5819: $response .='<ul><li>'
1.266 bisitz 5820: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5821: .'</li><li>'
5822: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5823: .'</li><li>'
5824: .&mt('Provide the proposed username')
5825: .'</li><li>'
5826: .&mt("Click 'Search'")
5827: .'</li></ul><br />';
1.221 raeburn 5828: } else {
5829: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 5830: $response .= '<br /><br />';
5831: if ($context eq 'requestcrs') {
5832: $response .= &mt("You are not authorized to defined new users in the new course's domain - [_1].",$targetdom);
5833: } else {
5834: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
5835: }
5836: $response .= '<br />'
5837: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 5838: ,' <a'.$helplink.'>'
5839: ,'</a>')
1.305 raeburn 5840: .'<br /><br />';
1.221 raeburn 5841: }
1.160 raeburn 5842: }
5843: }
5844: }
1.179 raeburn 5845: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5846: }
5847:
1.180 raeburn 5848: sub display_domain_info {
5849: my ($dom) = @_;
5850: my $output = $dom;
5851: if ($dom ne '') {
5852: my $domdesc = &Apache::lonnet::domain($dom,'description');
5853: if ($domdesc ne '') {
5854: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5855: }
5856: }
5857: return $output;
5858: }
5859:
1.160 raeburn 5860: sub crumb_utilities {
5861: my %elements = (
5862: crtuser => {
5863: srchterm => 'text',
1.172 raeburn 5864: srchin => 'selectbox',
1.160 raeburn 5865: srchby => 'selectbox',
5866: srchtype => 'selectbox',
5867: srchdomain => 'selectbox',
5868: },
1.207 raeburn 5869: crtusername => {
5870: srchterm => 'text',
5871: srchdomain => 'selectbox',
5872: },
1.160 raeburn 5873: docustom => {
5874: rolename => 'selectbox',
5875: newrolename => 'textbox',
5876: },
1.179 raeburn 5877: studentform => {
5878: srchterm => 'text',
5879: srchin => 'selectbox',
5880: srchby => 'selectbox',
5881: srchtype => 'selectbox',
5882: srchdomain => 'selectbox',
5883: },
1.160 raeburn 5884: );
5885:
5886: my $jsback .= qq|
5887: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5888: if (typeof prevphase == 'undefined') {
5889: formname.phase.value = '';
5890: }
5891: else {
5892: formname.phase.value = prevphase;
5893: }
5894: if (typeof prevstate == 'undefined') {
5895: formname.currstate.value = '';
5896: }
5897: else {
5898: formname.currstate.value = prevstate;
5899: }
1.160 raeburn 5900: formname.submit();
5901: }
5902: |;
5903: return ($jsback,\%elements);
5904: }
5905:
1.26 matthew 5906: sub course_level_table {
1.89 raeburn 5907: my (%inccourses) = @_;
1.26 matthew 5908: my $table = '';
1.62 www 5909: # Custom Roles?
5910:
1.190 raeburn 5911: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5912: my %lt=&Apache::lonlocal::texthash(
5913: 'exs' => "Existing sections",
5914: 'new' => "Define new section",
5915: 'ssd' => "Set Start Date",
5916: 'sed' => "Set End Date",
1.131 raeburn 5917: 'crl' => "Course Level",
1.89 raeburn 5918: 'act' => "Activate",
5919: 'rol' => "Role",
5920: 'ext' => "Extent",
1.113 raeburn 5921: 'grs' => "Section",
1.89 raeburn 5922: 'sta' => "Start",
5923: 'end' => "End"
5924: );
1.62 www 5925:
1.135 raeburn 5926: foreach my $protectedcourse (sort( keys(%inccourses))) {
5927: my $thiscourse=$protectedcourse;
1.26 matthew 5928: $thiscourse=~s:_:/:g;
5929: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
5930: my $area=$coursedata{'description'};
1.119 raeburn 5931: my $type=$coursedata{'type'};
1.135 raeburn 5932: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5933: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5934: my %sections_count;
1.101 albertel 5935: if (defined($env{'request.course.id'})) {
5936: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5937: %sections_count =
5938: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5939: }
5940: }
1.213 raeburn 5941: my @roles = &Apache::lonuserutils::roles_by_context('course');
5942: foreach my $role (@roles) {
1.221 raeburn 5943: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 5944: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 5945: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5946: $plrole,\%sections_count,\%lt);
5947: } elsif ($env{'request.course.sec'} ne '') {
5948: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5949: $env{'request.course.sec'})) {
5950: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5951: $plrole,\%sections_count,\%lt);
1.26 matthew 5952: }
5953: }
5954: }
1.221 raeburn 5955: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
5956: foreach my $cust (sort keys %customroles) {
5957: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5958: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5959: $cust,\%sections_count,\%lt);
5960: }
1.62 www 5961: }
1.26 matthew 5962: }
5963: return '' if ($table eq ''); # return nothing if there is nothing
5964: # in the table
1.188 raeburn 5965: my $result;
5966: if (!$env{'request.course.id'}) {
5967: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5968: }
5969: $result .=
1.136 raeburn 5970: &Apache::loncommon::start_data_table().
5971: &Apache::loncommon::start_data_table_header_row().
5972: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5973: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5974: &Apache::loncommon::end_data_table_header_row().
5975: $table.
5976: &Apache::loncommon::end_data_table();
1.26 matthew 5977: return $result;
5978: }
1.88 raeburn 5979:
1.221 raeburn 5980: sub course_level_row {
5981: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5982: my $row = &Apache::loncommon::start_data_table_row().
5983: ' <td><input type="checkbox" name="act_'.
5984: $protectedcourse.'_'.$role.'" /></td>'."\n".
5985: ' <td>'.$plrole.'</td>'."\n".
5986: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 5987: if ($role eq 'cc') {
1.222 raeburn 5988: $row .= '<td> </td>';
1.221 raeburn 5989: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5990: $row .= ' <td><input type="hidden" value="'.
5991: $env{'request.course.sec'}.'" '.
5992: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5993: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5994: } else {
5995: if (ref($sections_count) eq 'HASH') {
5996: my $currsec =
5997: &Apache::lonuserutils::course_sections($sections_count,
5998: $protectedcourse.'_'.$role);
1.222 raeburn 5999: $row .= '<td><table class="LC_createuser">'."\n".
6000: '<tr class="LC_section_row">'."\n".
6001: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6002: $currsec.'</td>'."\n".
6003: ' <td> </td>'."\n".
6004: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6005: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6006: '" value="" />'.
6007: '<input type="hidden" '.
6008: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6009: '</tr></table></td>'."\n";
1.221 raeburn 6010: } else {
1.222 raeburn 6011: $row .= '<td><input type="text" size="10" '.
6012: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6013: }
6014: }
1.222 raeburn 6015: $row .= <<ENDTIMEENTRY;
6016: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6017: <a href=
6018: "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 6019: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6020: <a href=
6021: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6022: ENDTIMEENTRY
1.222 raeburn 6023: $row .= &Apache::loncommon::end_data_table_row();
6024: return $row;
1.221 raeburn 6025: }
6026:
1.88 raeburn 6027: sub course_level_dc {
6028: my ($dcdom) = @_;
1.190 raeburn 6029: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6030: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6031: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6032: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6033: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 6034: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 6035: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
6036: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 6037: my %lt=&Apache::lonlocal::texthash(
6038: 'rol' => "Role",
1.113 raeburn 6039: 'grs' => "Section",
1.88 raeburn 6040: 'exs' => "Existing sections",
6041: 'new' => "Define new section",
6042: 'sta' => "Start",
6043: 'end' => "End",
6044: 'ssd' => "Set Start Date",
6045: 'sed' => "Set End Date"
6046: );
1.131 raeburn 6047: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 6048: &Apache::loncommon::start_data_table().
6049: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 6050: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6051: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6052: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.301 bisitz 6053: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 6054: '<td><select name="role">'."\n";
1.213 raeburn 6055: foreach my $role (@roles) {
1.135 raeburn 6056: my $plrole=&Apache::lonnet::plaintext($role);
6057: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6058: }
6059: if ( keys %customroles > 0) {
1.135 raeburn 6060: foreach my $cust (sort keys %customroles) {
1.101 albertel 6061: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6062: '_'.$env{'user.name'}.'_'.$cust;
6063: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6064: }
6065: }
6066: $otheritems .= '</select></td><td>'.
6067: '<table border="0" cellspacing="0" cellpadding="0">'.
6068: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6069: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6070: '<td> </td>'.
6071: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6072: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6073: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 6074: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 6075: '</tr></table></td>';
6076: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 6077: <td><input type="hidden" name="start" value='' />
1.88 raeburn 6078: <a href=
6079: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 6080: <td><input type="hidden" name="end" value='' />
1.88 raeburn 6081: <a href=
6082: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
6083: ENDTIMEENTRY
1.136 raeburn 6084: $otheritems .= &Apache::loncommon::end_data_table_row().
6085: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 6086: return $cb_jscript.$header.$hiddenitems.$otheritems;
6087: }
6088:
1.237 raeburn 6089: sub update_selfenroll_config {
1.241 raeburn 6090: my ($r,$context,$permission) = @_;
1.237 raeburn 6091: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 6092: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 6093: my (%changes,%warning);
6094: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6095: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 6096: my $curr_types;
1.237 raeburn 6097: if (ref($row) eq 'ARRAY') {
6098: foreach my $item (@{$row}) {
6099: if ($item eq 'enroll_dates') {
6100: my (%currenrolldate,%newenrolldate);
6101: foreach my $type ('start','end') {
6102: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
6103: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
6104: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
6105: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
6106: }
6107: }
6108: } elsif ($item eq 'access_dates') {
6109: my (%currdate,%newdate);
6110: foreach my $type ('start','end') {
6111: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
6112: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
6113: if ($newdate{$type} ne $currdate{$type}) {
6114: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
6115: }
6116: }
1.241 raeburn 6117: } elsif ($item eq 'types') {
6118: $curr_types =
6119: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6120: if ($env{'form.selfenroll_all'}) {
6121: if ($curr_types ne '*') {
6122: $changes{'internal.selfenroll_types'} = '*';
6123: } else {
6124: next;
6125: }
6126: } else {
1.249 raeburn 6127: my %currdoms;
1.241 raeburn 6128: my @entries = split(/;/,$curr_types);
6129: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 6130: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 6131: my $newnum = 0;
1.249 raeburn 6132: my @latesttypes;
6133: foreach my $num (@activations) {
6134: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
6135: if (@types > 0) {
1.241 raeburn 6136: @types = sort(@types);
6137: my $typestr = join(',',@types);
1.249 raeburn 6138: my $typedom = $env{'form.selfenroll_dom_'.$num};
6139: $latesttypes[$newnum] = $typedom.':'.$typestr;
6140: $currdoms{$typedom} = 1;
1.241 raeburn 6141: $newnum ++;
6142: }
6143: }
1.249 raeburn 6144: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
6145: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
6146: if (@types > 0) {
6147: @types = sort(@types);
6148: my $typestr = join(',',@types);
6149: my $typedom = $env{'form.selfenroll_dom_'.$j};
6150: $latesttypes[$newnum] = $typedom.':'.$typestr;
6151: $currdoms{$typedom} = 1;
6152: $newnum ++;
6153: }
6154: }
6155: }
6156: if ($env{'form.selfenroll_newdom'} ne '') {
6157: my $typedom = $env{'form.selfenroll_newdom'};
6158: if ((!defined($currdoms{$typedom})) &&
6159: (&Apache::lonnet::domain($typedom) ne '')) {
6160: my $typestr;
6161: my ($othertitle,$usertypes,$types) =
6162: &Apache::loncommon::sorted_inst_types($typedom);
6163: my $othervalue = 'any';
6164: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6165: if (@{$types} > 0) {
1.257 raeburn 6166: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 6167: $othervalue = 'other';
1.258 raeburn 6168: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 6169: }
6170: $typestr = $othervalue;
6171: } else {
6172: $typestr = $othervalue;
6173: }
6174: $latesttypes[$newnum] = $typedom.':'.$typestr;
6175: $newnum ++ ;
6176: }
6177: }
1.241 raeburn 6178: my $selfenroll_types = join(';',@latesttypes);
6179: if ($selfenroll_types ne $curr_types) {
6180: $changes{'internal.selfenroll_types'} = $selfenroll_types;
6181: }
6182: }
1.276 raeburn 6183: } elsif ($item eq 'limit') {
6184: my $newlimit = $env{'form.selfenroll_limit'};
6185: my $newcap = $env{'form.selfenroll_cap'};
6186: $newcap =~s/\s+//g;
6187: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6188: $currlimit = 'none' if ($currlimit eq '');
6189: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6190: if ($newlimit ne $currlimit) {
6191: if ($newlimit ne 'none') {
6192: if ($newcap =~ /^\d+$/) {
6193: if ($newcap ne $currcap) {
6194: $changes{'internal.selfenroll_cap'} = $newcap;
6195: }
6196: $changes{'internal.selfenroll_limit'} = $newlimit;
6197: } else {
6198: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
6199: }
6200: } elsif ($currcap ne '') {
6201: $changes{'internal.selfenroll_cap'} = '';
6202: $changes{'internal.selfenroll_limit'} = $newlimit;
6203: }
6204: } elsif ($currlimit ne 'none') {
6205: if ($newcap =~ /^\d+$/) {
6206: if ($newcap ne $currcap) {
6207: $changes{'internal.selfenroll_cap'} = $newcap;
6208: }
6209: } else {
6210: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
6211: }
6212: }
6213: } elsif ($item eq 'approval') {
6214: my (@currnotified,@newnotified);
6215: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6216: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6217: if ($currnotifylist ne '') {
6218: @currnotified = split(/,/,$currnotifylist);
6219: @currnotified = sort(@currnotified);
6220: }
6221: my $newapproval = $env{'form.selfenroll_approval'};
6222: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
6223: @newnotified = sort(@newnotified);
6224: if ($newapproval ne $currapproval) {
6225: $changes{'internal.selfenroll_approval'} = $newapproval;
6226: if (!$newapproval) {
6227: if ($currnotifylist ne '') {
6228: $changes{'internal.selfenroll_notifylist'} = '';
6229: }
6230: } else {
6231: my @differences =
1.295 raeburn 6232: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6233: if (@differences > 0) {
6234: if (@newnotified > 0) {
6235: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6236: } else {
6237: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6238: }
6239: }
6240: }
6241: } else {
1.295 raeburn 6242: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6243: if (@differences > 0) {
6244: if (@newnotified > 0) {
6245: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6246: } else {
6247: $changes{'internal.selfenroll_notifylist'} = '';
6248: }
6249: }
6250: }
1.237 raeburn 6251: } else {
6252: my $curr_val =
6253: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6254: my $newval = $env{'form.selfenroll_'.$item};
6255: if ($item eq 'section') {
6256: $newval = $env{'form.sections'};
1.241 raeburn 6257: if (defined($curr_groups{$newval})) {
1.237 raeburn 6258: $newval = $curr_val;
6259: $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');
6260: } elsif ($newval eq 'all') {
6261: $newval = $curr_val;
1.274 bisitz 6262: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6263: }
6264: if ($newval eq '') {
6265: $newval = 'none';
6266: }
6267: }
6268: if ($newval ne $curr_val) {
6269: $changes{'internal.selfenroll_'.$item} = $newval;
6270: }
1.241 raeburn 6271: }
1.237 raeburn 6272: }
6273: if (keys(%warning) > 0) {
6274: foreach my $item (@{$row}) {
6275: if (exists($warning{$item})) {
6276: $r->print($warning{$item}.'<br />');
6277: }
6278: }
6279: }
6280: if (keys(%changes) > 0) {
6281: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6282: if ($putresult eq 'ok') {
6283: if ((exists($changes{'internal.selfenroll_types'})) ||
6284: (exists($changes{'internal.selfenroll_start_date'})) ||
6285: (exists($changes{'internal.selfenroll_end_date'}))) {
6286: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6287: $cnum,undef,undef,'Course');
6288: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6289: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6290: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6291: if (exists($changes{'internal.'.$item})) {
6292: $crsinfo{$env{'request.course.id'}}{$item} =
6293: $changes{'internal.'.$item};
6294: }
6295: }
6296: my $crsputresult =
6297: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6298: $chome,'notime');
6299: }
6300: }
6301: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6302: foreach my $item (@{$row}) {
6303: my $title = $item;
6304: if (ref($lt) eq 'HASH') {
6305: $title = $lt->{$item};
6306: }
6307: if ($item eq 'enroll_dates') {
6308: foreach my $type ('start','end') {
6309: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6310: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6311: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6312: $title,$type,$newdate).'</li>');
6313: }
6314: }
6315: } elsif ($item eq 'access_dates') {
6316: foreach my $type ('start','end') {
6317: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6318: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6319: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6320: $title,$type,$newdate).'</li>');
6321: }
6322: }
1.276 raeburn 6323: } elsif ($item eq 'limit') {
6324: if ((exists($changes{'internal.selfenroll_limit'})) ||
6325: (exists($changes{'internal.selfenroll_cap'}))) {
6326: my ($newval,$newcap);
6327: if ($changes{'internal.selfenroll_cap'} ne '') {
6328: $newcap = $changes{'internal.selfenroll_cap'}
6329: } else {
6330: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6331: }
6332: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6333: $newval = &mt('No limit');
6334: } elsif ($changes{'internal.selfenroll_limit'} eq
6335: 'allstudents') {
6336: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6337: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6338: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6339: } else {
6340: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6341: if ($currlimit eq 'allstudents') {
6342: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6343: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6344: $newval = &mt('New self-enrollment no longer allowed when total umber of self-enrolled students reaches [_1].',$newcap);
6345: }
6346: }
6347: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6348: }
6349: } elsif ($item eq 'approval') {
6350: if ((exists($changes{'internal.selfenroll_approval'})) ||
6351: (exists($changes{'internal.selfenroll_notifylist'}))) {
6352: my ($newval,$newnotify);
6353: if (exists($changes{'internal.selfenroll_notifylist'})) {
6354: $newnotify = $changes{'internal.selfenroll_notifylist'};
6355: } else {
6356: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6357: }
6358: if ($changes{'internal.selfenroll_approval'}) {
6359: $newval = &mt('Yes');
6360: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6361: $newval = &mt('No');
6362: } else {
6363: my $currapproval =
6364: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6365: if ($currapproval) {
6366: $newval = &mt('Yes');
6367: } else {
6368: $newval = &mt('No');
6369: }
6370: }
6371: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6372: if ($newnotify) {
1.277 raeburn 6373: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6374: } else {
1.277 raeburn 6375: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6376: }
6377: $r->print('</li>'."\n");
6378: }
1.237 raeburn 6379: } else {
6380: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6381: my $newval = $changes{'internal.selfenroll_'.$item};
6382: if ($item eq 'types') {
6383: if ($newval eq '') {
6384: $newval = &mt('None');
6385: } elsif ($newval eq '*') {
6386: $newval = &mt('Any user in any domain');
6387: }
1.245 raeburn 6388: } elsif ($item eq 'registered') {
6389: if ($newval eq '1') {
6390: $newval = &mt('Yes');
6391: } elsif ($newval eq '0') {
6392: $newval = &mt('No');
6393: }
1.241 raeburn 6394: }
1.244 bisitz 6395: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6396: }
6397: }
6398: }
6399: $r->print('</ul>');
6400: my %newenvhash;
6401: foreach my $key (keys(%changes)) {
6402: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6403: }
1.238 raeburn 6404: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6405: } else {
6406: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6407: }
6408: } else {
1.249 raeburn 6409: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6410: }
6411: } else {
1.249 raeburn 6412: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6413: }
1.256 raeburn 6414: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
6415: if (ref($visactions) eq 'HASH') {
6416: if (!$visible) {
6417: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
6418: '<br />');
6419: if (ref($vismsgs) eq 'ARRAY') {
6420: $r->print('<br />'.$visactions->{'take'}.'<ul>');
6421: foreach my $item (@{$vismsgs}) {
6422: $r->print('<li>'.$visactions->{$item}.'</li>');
6423: }
6424: $r->print('</ul>');
6425: }
6426: $r->print($cansetvis);
6427: }
6428: }
1.237 raeburn 6429: return;
6430: }
6431:
6432: sub get_selfenroll_titles {
1.276 raeburn 6433: my @row = ('types','registered','enroll_dates','access_dates','section',
6434: 'approval','limit');
1.237 raeburn 6435: my %lt = &Apache::lonlocal::texthash (
6436: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 6437: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 6438: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 6439: access_dates => 'Course access dates assigned to self-enrolling users',
6440: section => 'Section assigned to self-enrolling users',
1.276 raeburn 6441: approval => 'Self-enrollment requests need approval?',
6442: limit => 'Enrollment limit',
1.237 raeburn 6443: );
6444: return (\@row,\%lt);
6445: }
6446:
1.27 matthew 6447: #---------------------------------------------- end functions for &phase_two
1.29 matthew 6448:
6449: #--------------------------------- functions for &phase_two and &phase_three
6450:
6451: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 6452:
6453: 1;
6454: __END__
1.2 www 6455:
6456:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>