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