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