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