Annotation of loncom/interface/loncreateuser.pm, revision 1.322
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.322 ! raeburn 4: # $Id: loncreateuser.pm,v 1.321 2009/10/31 14:27:48 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';
1.321 raeburn 3960: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
3961: ($env{'form.roletype'} eq 'community'))) {
3962: if ($env{'form.roletype'} eq 'course') {
3963: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
3964: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
3965: $formname);
3966: } elsif ($env{'form.roletype'} eq 'community') {
3967: $cb_jscript =
3968: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
3969: my %elements = (
3970: coursepick => 'radio',
3971: coursetotal => 'text',
3972: courselist => 'text',
3973: );
3974: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
3975: }
1.202 raeburn 3976: $jscript .= &verify_user_display();
3977: my $js = &add_script($jscript).$cb_jscript;
3978: my $loadcode =
3979: &Apache::lonuserutils::course_selector_loadcode($formname);
3980: if ($loadcode ne '') {
3981: $r->print(&header($js,{'onload' => $loadcode,}));
3982: } else {
3983: $r->print(&header($js));
3984: }
1.191 raeburn 3985: } else {
1.202 raeburn 3986: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 3987: }
1.202 raeburn 3988: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3989: 'Course_View_Class_List'));
1.202 raeburn 3990: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3991: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3992: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3993: }
1.213 raeburn 3994: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3995: $r->print(&header());
1.318 raeburn 3996: my $brtext;
3997: if ($crstype eq 'Community') {
3998: $brtext = 'Drop Members';
3999: } else {
4000: $brtext = 'Drop Students';
4001: }
1.213 raeburn 4002: &Apache::lonhtmlcommon::add_breadcrumb
4003: ({href=>'/adm/createuser?action=drop',
1.318 raeburn 4004: text=>$brtext});
1.213 raeburn 4005: if (!exists($env{'form.state'})) {
1.318 raeburn 4006: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brtext,
1.213 raeburn 4007: 'Course_Drop_Student'));
4008:
1.318 raeburn 4009: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4010: } elsif ($env{'form.state'} eq 'done') {
4011: &Apache::lonhtmlcommon::add_breadcrumb
4012: ({href=>'/adm/createuser?action=drop',
4013: text=>"Result"});
1.318 raeburn 4014: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brtext,
1.213 raeburn 4015: 'Course_Drop_Student'));
4016: &Apache::lonuserutils::update_user_list($r,$context,undef,
4017: $env{'form.action'});
4018: }
4019: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 4020: } elsif ($env{'form.action'} eq 'dateselect') {
4021: if ($permission->{'cusr'}) {
4022: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 4023: &Apache::lonuserutils::date_section_selector($context,
1.318 raeburn 4024: $permission,$crstype).
1.202 raeburn 4025: &Apache::loncommon::end_page());
4026: } else {
4027: $r->print(&header().
4028: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
4029: &Apache::loncommon::end_page());
4030: }
1.237 raeburn 4031: } elsif ($env{'form.action'} eq 'selfenroll') {
4032: $r->print(&header());
4033: &Apache::lonhtmlcommon::add_breadcrumb
4034: ({href=>'/adm/createuser?action=selfenroll',
4035: text=>"Configure Self-enrollment"});
4036: if (!exists($env{'form.state'})) {
4037: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
4038: 'Course_Self_Enrollment'));
1.241 raeburn 4039: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4040: &print_selfenroll_menu($r,$context,$permission);
4041: } elsif ($env{'form.state'} eq 'done') {
4042: &Apache::lonhtmlcommon::add_breadcrumb
4043: ({href=>'/adm/createuser?action=selfenroll',
4044: text=>"Result"});
4045: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
4046: 'Course_Self_Enrollment'));
1.241 raeburn 4047: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4048: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4049: }
4050: $r->print(&Apache::loncommon::end_page());
1.277 raeburn 4051: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
4052: $r->print(&header());
4053: &Apache::lonhtmlcommon::add_breadcrumb
4054: ({href=>'/adm/createuser?action=selfenrollqueue',
4055: text=>"Enrollment requests"});
4056: my $cid = $env{'request.course.id'};
4057: my $cdom = $env{'course.'.$cid.'.domain'};
4058: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4059: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4060: if (!exists($env{'form.state'})) {
4061: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests',
4062: 'Course_SelfEnrollment_Approval'));
4063: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4064: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4065: $cdom,$cnum));
1.277 raeburn 4066: } elsif ($env{'form.state'} eq 'done') {
4067: &Apache::lonhtmlcommon::add_breadcrumb
4068: ({href=>'/adm/createuser?action=selfenrollqueue',
4069: text=>"Result"});
4070: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result',
4071: 'Course_Self_Enrollment'));
4072: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4073: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4074: $cdom,$cnum,$coursedesc));
1.277 raeburn 4075: }
4076: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 4077: } elsif ($env{'form.action'} eq 'changelogs') {
4078: $r->print(&header());
4079: &Apache::lonhtmlcommon::add_breadcrumb
4080: ({href=>'/adm/createuser?action=changelogs',
4081: text=>"User Management Logs"});
4082: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
4083: 'Course_User_Logs'));
4084: &print_userchangelogs_display($r,$context,$permission);
4085: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4086: } else {
4087: $r->print(&header());
1.202 raeburn 4088: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.318 raeburn 4089: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4090: $r->print(&Apache::loncommon::end_page());
4091: }
4092: return OK;
4093: }
4094:
4095: sub header {
1.202 raeburn 4096: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 4097: my $start_page;
4098: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 4099: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 4100: } else {
1.202 raeburn 4101: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4102: }
4103: return $start_page;
4104: }
1.2 www 4105:
1.191 raeburn 4106: sub add_script {
4107: my ($js) = @_;
1.301 bisitz 4108: return '<script type="text/javascript">'."\n"
4109: .'// <![CDATA['."\n"
4110: .$js."\n"
4111: .'// ]]>'."\n"
4112: .'</script>'."\n";
1.191 raeburn 4113: }
4114:
1.202 raeburn 4115: sub verify_user_display {
4116: my $output = <<"END";
4117:
4118: function display_update() {
4119: document.studentform.action.value = 'listusers';
4120: document.studentform.phase.value = 'display';
4121: document.studentform.submit();
4122: }
4123:
4124: END
4125: return $output;
4126:
4127: }
4128:
1.190 raeburn 4129: ###############################################################
4130: ###############################################################
4131: # Menu Phase One
4132: sub print_main_menu {
1.318 raeburn 4133: my ($permission,$context,$crstype) = @_;
4134: my $linkcontext = $context;
4135: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
4136: if (($context eq 'course') && ($crstype eq 'Community')) {
4137: $linkcontext = lc($crstype);
4138: $stuterm = 'Members';
4139: }
1.208 raeburn 4140: my %links = (
1.298 droeschl 4141: domain => {
4142: upload => 'Upload a File of Users',
4143: singleuser => 'Add/Modify a User',
4144: listusers => 'Manage Users',
4145: },
4146: author => {
4147: upload => 'Upload a File of Co-authors',
4148: singleuser => 'Add/Modify a Co-author',
4149: listusers => 'Manage Co-authors',
4150: },
4151: course => {
4152: upload => 'Upload a File of Course Users',
4153: singleuser => 'Add/Modify a Course User',
4154: listusers => 'Manage Course Users',
4155: },
1.318 raeburn 4156: community => {
4157: upload => 'Upload a File of Community Users',
4158: singleuser => 'Add/Modify a Community User',
4159: listusers => 'Manage Community Users',
4160: },
4161: );
4162: my %linktitles = (
4163: domain => {
4164: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
4165: listusers => 'Show and manage users in this domain.',
4166: },
4167: author => {
4168: singleuser => 'Add a user with a co- or assistant author role.',
4169: listusers => 'Show and manage co- or assistant authors.',
4170: },
4171: course => {
4172: singleuser => 'Add a user with a certain role to this course.',
4173: listusers => 'Show and manage users in this course.',
4174: },
4175: community => {
4176: singleuser => 'Add a user with a certain role to this community.',
4177: listusers => 'Show and manage users in this community.',
4178: },
1.298 droeschl 4179: );
4180: my @menu = ( {categorytitle => 'Single Users',
4181: items =>
4182: [
4183: {
1.318 raeburn 4184: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 4185: icon => 'edit-redo.png',
4186: #help => 'Course_Change_Privileges',
4187: url => '/adm/createuser?action=singleuser',
4188: permission => $permission->{'cusr'},
1.318 raeburn 4189: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 4190: },
4191: ]},
4192:
4193: {categorytitle => 'Multiple Users',
4194: items =>
4195: [
4196: {
1.318 raeburn 4197: linktext => $links{$linkcontext}{'upload'},
1.298 droeschl 4198: icon => 'sctr.png',
4199: #help => 'Course_Create_Class_List',
4200: url => '/adm/createuser?action=upload',
4201: permission => $permission->{'cusr'},
4202: linktitle => 'Upload a CSV or a text file containing users.',
4203: },
4204: {
1.318 raeburn 4205: linktext => $links{$linkcontext}{'listusers'},
1.298 droeschl 4206: icon => 'edit-find.png',
4207: #help => 'Course_View_Class_List',
4208: url => '/adm/createuser?action=listusers',
4209: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 4210: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 4211: },
4212:
4213: ]},
4214:
4215: {categorytitle => 'Administration',
4216: items => [ ]},
4217: );
4218:
1.265 mielkec 4219: if ($context eq 'domain'){
1.298 droeschl 4220:
4221: push(@{ $menu[2]->{items} }, #Category: Administration
4222: {
4223: linktext => 'Custom Roles',
4224: icon => 'emblem-photos.png',
4225: #help => 'Course_Editing_Custom_Roles',
4226: url => '/adm/createuser?action=custom',
4227: permission => $permission->{'custom'},
4228: linktitle => 'Configure a custom role.',
4229: },
4230: );
4231:
1.265 mielkec 4232: }elsif ($context eq 'course'){
1.298 droeschl 4233: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 4234:
4235: my %linktext = (
4236: 'Course' => {
4237: single => 'Add/Modify a Student',
4238: drop => 'Drop Students',
4239: groups => 'Course Groups',
4240: },
4241: 'Community' => {
4242: single => 'Add/Modify a Member',
4243: drop => 'Drop Members',
4244: groups => 'Community Groups',
4245: },
4246: );
4247:
4248: my %linktitle = (
4249: 'Course' => {
4250: single => 'Add a user with the role of student to this course',
4251: drop => 'Remove a student from this course.',
4252: groups => 'Manage course groups',
4253: },
4254: 'Community' => {
4255: single => 'Add a user with the role of member to this community',
4256: drop => 'Remove a member from this community.',
4257: groups => 'Manage community groups',
4258: },
4259: );
4260:
1.298 droeschl 4261: push(@{ $menu[0]->{items} }, #Category: Single Users
4262: {
1.318 raeburn 4263: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 4264: #help => 'Course_Add_Student',
4265: icon => 'list-add.png',
4266: url => '/adm/createuser?action=singlestudent',
4267: permission => $permission->{'cusr'},
1.318 raeburn 4268: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 4269: },
4270: );
4271:
4272: push(@{ $menu[1]->{items} }, #Category: Multiple Users
4273: {
1.318 raeburn 4274: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 4275: icon => 'edit-undo.png',
4276: #help => 'Course_Drop_Student',
4277: url => '/adm/createuser?action=drop',
4278: permission => $permission->{'cusr'},
1.318 raeburn 4279: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 4280: },
4281: );
4282: push(@{ $menu[2]->{items} }, #Category: Administration
4283: {
4284: linktext => 'Custom Roles',
4285: icon => 'emblem-photos.png',
4286: #help => 'Course_Editing_Custom_Roles',
4287: url => '/adm/createuser?action=custom',
4288: permission => $permission->{'custom'},
4289: linktitle => 'Configure a custom role.',
4290: },
4291: {
1.318 raeburn 4292: linktext => $linktext{$crstype}{'groups'},
1.298 droeschl 4293: icon => 'conf.png',
4294: #help => 'Course_Manage_Group',
4295: url => '/adm/coursegroups?refpage=cusr',
4296: permission => $permission->{'grp_manage'},
1.318 raeburn 4297: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 4298: },
4299: {
4300: linktext => 'Change Logs',
4301: icon => 'document-properties.png',
4302: #help => 'Course_User_Logs',
4303: url => '/adm/createuser?action=changelogs',
4304: permission => $permission->{'cusr'},
4305: linktitle => 'View change log.',
4306: },
4307: );
1.277 raeburn 4308: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 4309: push(@{ $menu[2]->{items} },
4310: {
4311: linktext => 'Enrollment Requests',
4312: icon => 'selfenrl-queue.png',
4313: #help => 'Course_Approve_Selfenroll',
4314: url => '/adm/createuser?action=selfenrollqueue',
4315: permission => $permission->{'cusr'},
4316: linktitle =>'Approve or reject enrollment requests.',
4317: },
4318: );
1.277 raeburn 4319: }
1.298 droeschl 4320:
1.265 mielkec 4321: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 4322: if ($crstype ne 'Community') {
4323: push(@{ $menu[2]->{items} },
4324: {
4325: linktext => 'Automated Enrollment',
4326: icon => 'roles.png',
4327: #help => 'Course_Automated_Enrollment',
4328: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
4329: && $permission->{'cusr'}),
4330: url => '/adm/populate',
4331: linktitle => 'Automated enrollment manager.',
4332: }
4333: );
4334: }
4335: push(@{ $menu[2]->{items} },
1.298 droeschl 4336: {
4337: linktext => 'User Self-Enrollment',
4338: icon => 'cstr.png',
4339: #help => 'Course_Self_Enrollment',
4340: url => '/adm/createuser?action=selfenroll',
4341: permission => $permission->{'cusr'},
1.317 bisitz 4342: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 4343: },
4344: );
4345: }
1.265 mielkec 4346: };
4347: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 4348: # { text => 'View Log-in History',
4349: # help => 'Course_User_Logins',
4350: # action => 'logins',
4351: # permission => $permission->{'cusr'},
4352: # });
1.190 raeburn 4353: }
4354:
1.189 albertel 4355: sub restore_prev_selections {
4356: my %saveable_parameters = ('srchby' => 'scalar',
4357: 'srchin' => 'scalar',
4358: 'srchtype' => 'scalar',
4359: );
4360: &Apache::loncommon::store_settings('user','user_picker',
4361: \%saveable_parameters);
4362: &Apache::loncommon::restore_settings('user','user_picker',
4363: \%saveable_parameters);
4364: }
4365:
1.237 raeburn 4366: sub print_selfenroll_menu {
4367: my ($r,$context,$permission) = @_;
1.322 ! raeburn 4368: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 4369: my $formname = 'enrollstudent';
4370: my $nolink = 1;
4371: my ($row,$lt) = &get_selfenroll_titles();
4372: my $groupslist = &Apache::lonuserutils::get_groupslist();
4373: my $setsec_js =
4374: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4375: my %alerts = &Apache::lonlocal::texthash(
4376: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4377: butn => 'but no user types have been checked.',
4378: wilf => "Please uncheck 'activate' or check at least one type.",
4379: );
4380: my $selfenroll_js = <<"ENDSCRIPT";
4381: function update_types(caller,num) {
4382: var delidx = getIndexByName('selfenroll_delete');
4383: var actidx = getIndexByName('selfenroll_activate');
4384: if (caller == 'selfenroll_all') {
4385: var selall;
4386: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4387: if (document.$formname.selfenroll_all[i].checked) {
4388: selall = document.$formname.selfenroll_all[i].value;
4389: }
4390: }
4391: if (selall == 1) {
4392: if (delidx != -1) {
4393: if (document.$formname.selfenroll_delete.length) {
4394: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4395: document.$formname.selfenroll_delete[j].checked = true;
4396: }
4397: } else {
4398: document.$formname.elements[delidx].checked = true;
4399: }
4400: }
4401: if (actidx != -1) {
4402: if (document.$formname.selfenroll_activate.length) {
4403: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4404: document.$formname.selfenroll_activate[j].checked = false;
4405: }
4406: } else {
4407: document.$formname.elements[actidx].checked = false;
4408: }
4409: }
4410: document.$formname.selfenroll_newdom.selectedIndex = 0;
4411: }
4412: }
4413: if (caller == 'selfenroll_activate') {
4414: if (document.$formname.selfenroll_activate.length) {
4415: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4416: if (document.$formname.selfenroll_activate[j].value == num) {
4417: if (document.$formname.selfenroll_activate[j].checked) {
4418: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4419: if (document.$formname.selfenroll_all[i].value == '1') {
4420: document.$formname.selfenroll_all[i].checked = false;
4421: }
4422: if (document.$formname.selfenroll_all[i].value == '0') {
4423: document.$formname.selfenroll_all[i].checked = true;
4424: }
4425: }
4426: }
4427: }
4428: }
4429: } else {
4430: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4431: if (document.$formname.selfenroll_all[i].value == '1') {
4432: document.$formname.selfenroll_all[i].checked = false;
4433: }
4434: if (document.$formname.selfenroll_all[i].value == '0') {
4435: document.$formname.selfenroll_all[i].checked = true;
4436: }
4437: }
4438: }
4439: }
4440: if (caller == 'selfenroll_delete') {
4441: if (document.$formname.selfenroll_delete.length) {
4442: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4443: if (document.$formname.selfenroll_delete[j].value == num) {
4444: if (document.$formname.selfenroll_delete[j].checked) {
4445: var delindex = getIndexByName('selfenroll_types_'+num);
4446: if (delindex != -1) {
4447: if (document.$formname.elements[delindex].length) {
4448: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4449: document.$formname.elements[delindex][k].checked = false;
4450: }
4451: } else {
4452: document.$formname.elements[delindex].checked = false;
4453: }
4454: }
4455: }
4456: }
4457: }
4458: } else {
4459: if (document.$formname.selfenroll_delete.checked) {
4460: var delindex = getIndexByName('selfenroll_types_'+num);
4461: if (delindex != -1) {
4462: if (document.$formname.elements[delindex].length) {
4463: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4464: document.$formname.elements[delindex][k].checked = false;
4465: }
4466: } else {
4467: document.$formname.elements[delindex].checked = false;
4468: }
4469: }
4470: }
4471: }
4472: }
4473: return;
4474: }
4475:
4476: function validate_types(form) {
4477: var needaction = new Array();
4478: var countfail = 0;
4479: var actidx = getIndexByName('selfenroll_activate');
4480: if (actidx != -1) {
4481: if (document.$formname.selfenroll_activate.length) {
4482: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4483: var num = document.$formname.selfenroll_activate[j].value;
4484: if (document.$formname.selfenroll_activate[j].checked) {
4485: countfail = check_types(num,countfail,needaction)
4486: }
4487: }
4488: } else {
4489: if (document.$formname.selfenroll_activate.checked) {
4490: var num = document.enrollstudent.selfenroll_activate.value;
4491: countfail = check_types(num,countfail,needaction)
4492: }
4493: }
4494: }
4495: if (countfail > 0) {
4496: var msg = "$alerts{'acto'}\\n";
4497: var loopend = needaction.length -1;
4498: if (loopend > 0) {
4499: for (var m=0; m<loopend; m++) {
4500: msg += needaction[m]+", ";
4501: }
4502: }
4503: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
4504: alert(msg);
4505: return;
4506: }
4507: setSections(form);
4508: }
4509:
4510: function check_types(num,countfail,needaction) {
4511: var typeidx = getIndexByName('selfenroll_types_'+num);
4512: var count = 0;
4513: if (typeidx != -1) {
4514: if (document.$formname.elements[typeidx].length) {
4515: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
4516: if (document.$formname.elements[typeidx][k].checked) {
4517: count ++;
4518: }
4519: }
4520: } else {
4521: if (document.$formname.elements[typeidx].checked) {
4522: count ++;
4523: }
4524: }
4525: if (count == 0) {
4526: var domidx = getIndexByName('selfenroll_dom_'+num);
4527: if (domidx != -1) {
4528: var domname = document.$formname.elements[domidx].value;
4529: needaction[countfail] = domname;
4530: countfail ++;
4531: }
4532: }
4533: }
4534: return countfail;
4535: }
4536:
4537: function getIndexByName(item) {
4538: for (var i=0;i<document.$formname.elements.length;i++) {
4539: if (document.$formname.elements[i].name == item) {
4540: return i;
4541: }
4542: }
4543: return -1;
4544: }
4545: ENDSCRIPT
1.256 raeburn 4546: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4547: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4548:
1.237 raeburn 4549: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 4550: '// <![CDATA['."\n".
1.249 raeburn 4551: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 4552: '// ]]>'."\n".
1.237 raeburn 4553: '</script>'."\n".
1.256 raeburn 4554: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
4555: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4556: if (ref($visactions) eq 'HASH') {
4557: if ($visible) {
1.283 bisitz 4558: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 4559: } else {
1.283 bisitz 4560: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
4561: .$visactions->{'yous'}.
1.256 raeburn 4562: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
4563: if (ref($vismsgs) eq 'ARRAY') {
4564: $output .= '<br />'.$visactions->{'make'}.'<ul>';
4565: foreach my $item (@{$vismsgs}) {
4566: $output .= '<li>'.$visactions->{$item}.'</li>';
4567: }
4568: $output .= '</ul>';
4569: }
4570: $output .= '</p>';
4571: }
4572: }
4573: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
4574: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 4575: if (ref($row) eq 'ARRAY') {
4576: foreach my $item (@{$row}) {
4577: my $title = $item;
4578: if (ref($lt) eq 'HASH') {
4579: $title = $lt->{$item};
4580: }
1.297 bisitz 4581: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 4582: if ($item eq 'types') {
4583: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 4584: my $showdomdesc = 1;
4585: my $includeempty = 1;
4586: my $num = 0;
4587: $output .= &Apache::loncommon::start_data_table().
4588: &Apache::loncommon::start_data_table_row()
4589: .'<td colspan="2"><span class="LC_nobreak"><label>'
4590: .&mt('Any user in any domain:')
4591: .' <input type="radio" name="selfenroll_all" value="1" ';
4592: if ($curr_types eq '*') {
4593: $output .= ' checked="checked" ';
4594: }
1.249 raeburn 4595: $output .= 'onchange="javascript:update_types('.
4596: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
4597: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 4598: if ($curr_types ne '*') {
4599: $output .= ' checked="checked" ';
4600: }
1.249 raeburn 4601: $output .= ' onchange="javascript:update_types('.
4602: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
4603: &Apache::loncommon::end_data_table_row().
4604: &Apache::loncommon::end_data_table().
4605: &mt('Or').'<br />'.
4606: &Apache::loncommon::start_data_table();
1.241 raeburn 4607: my %currdoms;
1.249 raeburn 4608: if ($curr_types eq '') {
1.241 raeburn 4609: $output .= &new_selfenroll_dom_row($cdom,'0');
4610: } elsif ($curr_types ne '*') {
4611: my @entries = split(/;/,$curr_types);
4612: if (@entries > 0) {
4613: foreach my $entry (@entries) {
4614: my ($currdom,$typestr) = split(/:/,$entry);
4615: $currdoms{$currdom} = 1;
4616: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 4617: my @currinsttypes = split(',',$typestr);
1.241 raeburn 4618: $output .= &Apache::loncommon::start_data_table_row()
4619: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
4620: .' '.$domdesc.' ('.$currdom.')'
4621: .'</b><input type="hidden" name="selfenroll_dom_'.$num
4622: .'" value="'.$currdom.'" /></span><br />'
4623: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 4624: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 4625: .&mt('Delete').'</label></span></td>';
1.249 raeburn 4626: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 4627: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
4628: .&Apache::loncommon::end_data_table_row();
4629: $num ++;
4630: }
4631: }
4632: }
1.249 raeburn 4633: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 4634: if ($curr_types eq '*') {
1.249 raeburn 4635: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 4636: } elsif ($curr_types eq '') {
1.249 raeburn 4637: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 4638: }
4639: $output .= &Apache::loncommon::start_data_table_row()
4640: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
4641: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
4642: $includeempty,$showdomdesc)
4643: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
4644: .'</td>'.&Apache::loncommon::end_data_table_row()
4645: .&Apache::loncommon::end_data_table();
1.237 raeburn 4646: } elsif ($item eq 'registered') {
4647: my ($regon,$regoff);
4648: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
4649: $regon = ' checked="checked" ';
4650: $regoff = ' ';
4651: } else {
4652: $regon = ' ';
4653: $regoff = ' checked="checked" ';
4654: }
4655: $output .= '<label>'.
1.245 raeburn 4656: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 4657: &mt('Yes').'</label> <label>'.
1.245 raeburn 4658: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 4659: &mt('No').'</label>';
1.237 raeburn 4660: } elsif ($item eq 'enroll_dates') {
4661: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
4662: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
4663: if ($starttime eq '') {
4664: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4665: }
4666: if ($endtime eq '') {
4667: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4668: }
4669: my $startform =
4670: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
4671: undef,undef,undef,undef,undef,undef,undef,$nolink);
4672: my $endform =
4673: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
4674: undef,undef,undef,undef,undef,undef,undef,$nolink);
4675: $output .= &selfenroll_date_forms($startform,$endform);
4676: } elsif ($item eq 'access_dates') {
4677: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
4678: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
4679: if ($starttime eq '') {
4680: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4681: }
4682: if ($endtime eq '') {
4683: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4684: }
4685: my $startform =
4686: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
4687: undef,undef,undef,undef,undef,undef,undef,$nolink);
4688: my $endform =
4689: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
4690: undef,undef,undef,undef,undef,undef,undef,$nolink);
4691: $output .= &selfenroll_date_forms($startform,$endform);
4692: } elsif ($item eq 'section') {
4693: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
4694: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4695: my $newsecval;
4696: if ($currsec ne 'none' && $currsec ne '') {
4697: if (!defined($sections_count{$currsec})) {
4698: $newsecval = $currsec;
4699: }
4700: }
4701: my $sections_select =
4702: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
4703: $output .= '<table class="LC_createuser">'."\n".
4704: '<tr class="LC_section_row">'."\n".
4705: '<td align="center">'.&mt('Existing sections')."\n".
4706: '<br />'.$sections_select.'</td><td align="center">'.
4707: &mt('New section').'<br />'."\n".
4708: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
4709: '<input type="hidden" name="sections" value="" />'."\n".
4710: '<input type="hidden" name="state" value="done" />'."\n".
4711: '</td></tr></table>'."\n";
1.276 raeburn 4712: } elsif ($item eq 'approval') {
4713: my ($appon,$appoff);
4714: my $cid = $env{'request.course.id'};
4715: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4716: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4717: $appon = ' checked="checked" ';
4718: $appoff = ' ';
4719: } else {
4720: $appon = ' ';
4721: $appoff = ' checked="checked" ';
4722: }
4723: $output .= '<label>'.
4724: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4725: &mt('Yes').'</label> <label>'.
4726: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4727: &mt('No').'</label>';
4728: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4729: my (@ccs,%notified);
1.322 ! raeburn 4730: my $ccrole = 'cc';
! 4731: if ($crstype eq 'Community') {
! 4732: $ccrole = 'co';
! 4733: }
! 4734: if ($advhash{$ccrole}) {
! 4735: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 4736: }
4737: if ($currnotified) {
4738: foreach my $current (split(/,/,$currnotified)) {
4739: $notified{$current} = 1;
4740: if (!grep(/^\Q$current\E$/,@ccs)) {
4741: push(@ccs,$current);
4742: }
4743: }
4744: }
4745: if (@ccs) {
1.277 raeburn 4746: $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 4747: &Apache::loncommon::start_data_table_row();
4748: my $count = 0;
4749: my $numcols = 4;
4750: foreach my $cc (sort(@ccs)) {
4751: my $notifyon;
4752: my ($ccuname,$ccudom) = split(/:/,$cc);
4753: if ($notified{$cc}) {
4754: $notifyon = ' checked="checked" ';
4755: }
4756: if ($count && !$count%$numcols) {
4757: $output .= &Apache::loncommon::end_data_table_row().
4758: &Apache::loncommon::start_data_table_row()
4759: }
4760: $output .= '<td><span class="LC_nobreak"><label>'.
4761: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4762: &Apache::loncommon::plainname($ccuname,$ccudom).
4763: '</label></span></td>';
4764: $count;
4765: }
4766: my $rem = $count%$numcols;
4767: if ($rem) {
4768: my $emptycols = $numcols - $rem;
4769: for (my $i=0; $i<$emptycols; $i++) {
4770: $output .= '<td> </td>';
4771: }
4772: }
4773: $output .= &Apache::loncommon::end_data_table_row().
4774: &Apache::loncommon::end_data_table();
4775: }
4776: } elsif ($item eq 'limit') {
4777: my ($crslimit,$selflimit,$nolimit);
4778: my $cid = $env{'request.course.id'};
4779: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4780: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4781: my $nolimit = ' checked="checked" ';
4782: if ($currlim eq 'allstudents') {
4783: $crslimit = ' checked="checked" ';
4784: $selflimit = ' ';
4785: $nolimit = ' ';
4786: } elsif ($currlim eq 'selfenrolled') {
4787: $crslimit = ' ';
4788: $selflimit = ' checked="checked" ';
4789: $nolimit = ' ';
4790: } else {
4791: $crslimit = ' ';
4792: $selflimit = ' ';
4793: }
4794: $output .= '<table><tr><td><label>'.
1.278 raeburn 4795: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4796: &mt('No limit').'</label></td><td><label>'.
4797: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4798: &mt('Limit by total students').'</label></td><td><label>'.
4799: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4800: &mt('Limit by total self-enrolled students').
4801: '</td></tr><tr>'.
4802: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4803: (' 'x3).&mt('Maximum number allowed: ').
4804: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4805: }
4806: $output .= &Apache::lonhtmlcommon::row_closure(1);
4807: }
4808: }
4809: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4810: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 4811: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4812: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4813: $r->print($output);
4814: return;
4815: }
4816:
1.256 raeburn 4817: sub visible_in_cat {
4818: my ($cdom,$cnum) = @_;
4819: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4820: my ($cathash,%settable,@vismsgs,$cansetvis);
4821: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 4822: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 4823: 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 4824: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 4825: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4826: 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 4827: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4828: take => 'Take the following action to ensure the course appears in the Catalog:',
4829: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4830: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4831: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4832: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4833: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4834: 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',
4835: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4836: );
1.261 raeburn 4837: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4838: $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>"');
4839: $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 4840: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4841: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4842: $settable{'togglecats'} = 1;
4843: }
4844: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4845: $settable{'categorize'} = 1;
4846: }
4847: $cathash = $domconf{'coursecategories'}{'cats'};
4848: }
1.260 raeburn 4849: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4850: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4851: } elsif ($settable{'togglecats'}) {
4852: $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 4853: } elsif ($settable{'categorize'}) {
1.256 raeburn 4854: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4855: } else {
4856: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4857: }
4858:
4859: my %currsettings =
4860: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4861: $cdom,$cnum);
4862: my $visible = 0;
4863: if ($currsettings{'internal.coursecode'} ne '') {
4864: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4865: $cathash = $domconf{'coursecategories'}{'cats'};
4866: if (ref($cathash) eq 'HASH') {
4867: if ($cathash->{'instcode::0'} eq '') {
4868: push(@vismsgs,'dc_addinst');
4869: } else {
4870: $visible = 1;
4871: }
4872: } else {
4873: $visible = 1;
4874: }
4875: } else {
4876: $visible = 1;
4877: }
4878: } else {
4879: if (ref($cathash) eq 'HASH') {
4880: if ($cathash->{'instcode::0'} ne '') {
4881: push(@vismsgs,'dc_instcode');
4882: }
4883: } else {
4884: push(@vismsgs,'dc_instcode');
4885: }
4886: }
4887: if ($currsettings{'categories'} ne '') {
4888: my $cathash;
4889: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4890: $cathash = $domconf{'coursecategories'}{'cats'};
4891: if (ref($cathash) eq 'HASH') {
4892: if (keys(%{$cathash}) == 0) {
4893: push(@vismsgs,'dc_catalog');
4894: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
4895: push(@vismsgs,'dc_categories');
4896: } else {
4897: my @currcategories = split('&',$currsettings{'categories'});
4898: my $matched = 0;
4899: foreach my $cat (@currcategories) {
4900: if ($cathash->{$cat} ne '') {
4901: $visible = 1;
4902: $matched = 1;
4903: last;
4904: }
4905: }
4906: if (!$matched) {
1.260 raeburn 4907: if ($settable{'categorize'}) {
1.256 raeburn 4908: push(@vismsgs,'chgcat');
4909: } else {
4910: push(@vismsgs,'dc_chgcat');
4911: }
4912: }
4913: }
4914: }
4915: }
4916: } else {
4917: if (ref($cathash) eq 'HASH') {
4918: if ((keys(%{$cathash}) > 1) ||
4919: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 4920: if ($settable{'categorize'}) {
1.256 raeburn 4921: push(@vismsgs,'addcat');
4922: } else {
4923: push(@vismsgs,'dc_addcat');
4924: }
4925: }
4926: }
4927: }
4928: if ($currsettings{'hidefromcat'} eq 'yes') {
4929: $visible = 0;
4930: if ($settable{'togglecats'}) {
4931: unshift(@vismsgs,'unhide');
4932: } else {
4933: unshift(@vismsgs,'dc_unhide')
4934: }
4935: }
4936: return ($visible,$cansetvis,\@vismsgs,\%visactions);
4937: }
4938:
1.241 raeburn 4939: sub new_selfenroll_dom_row {
4940: my ($newdom,$num) = @_;
4941: my $domdesc = &Apache::lonnet::domain($newdom);
4942: my $output;
4943: if ($domdesc ne '') {
4944: $output .= &Apache::loncommon::start_data_table_row()
4945: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
4946: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 4947: .'" value="'.$newdom.'" /></span><br />'
4948: .'<span class="LC_nobreak"><label><input type="checkbox" '
4949: .'name="selfenroll_activate" value="'.$num.'" '
4950: .'onchange="javascript:update_types('
4951: ."'selfenroll_activate','$num'".');" />'
4952: .&mt('Activate').'</label></span></td>';
1.241 raeburn 4953: my @currinsttypes;
4954: $output .= '<td>'.&mt('User types:').'<br />'
4955: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
4956: .&Apache::loncommon::end_data_table_row();
4957: }
4958: return $output;
4959: }
4960:
4961: sub selfenroll_inst_types {
4962: my ($num,$currdom,$currinsttypes) = @_;
4963: my $output;
4964: my $numinrow = 4;
4965: my $count = 0;
4966: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 4967: my $othervalue = 'any';
1.241 raeburn 4968: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 4969: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 4970: $othervalue = 'other';
4971: }
1.241 raeburn 4972: $output .= '<table><tr>';
4973: foreach my $type (@{$types}) {
4974: if (($count > 0) && ($count%$numinrow == 0)) {
4975: $output .= '</tr><tr>';
4976: }
4977: if (defined($usertypes->{$type})) {
1.257 raeburn 4978: my $esc_type = &escape($type);
1.241 raeburn 4979: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 4980: $esc_type.'" ';
1.241 raeburn 4981: if (ref($currinsttypes) eq 'ARRAY') {
4982: if (@{$currinsttypes} > 0) {
1.249 raeburn 4983: if (grep(/^any$/,@{$currinsttypes})) {
4984: $output .= 'checked="checked"';
1.257 raeburn 4985: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 4986: $output .= 'checked="checked"';
4987: }
1.249 raeburn 4988: } else {
4989: $output .= 'checked="checked"';
1.241 raeburn 4990: }
4991: }
4992: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
4993: }
4994: $count ++;
4995: }
4996: if (($count > 0) && ($count%$numinrow == 0)) {
4997: $output .= '</tr><tr>';
4998: }
1.249 raeburn 4999: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5000: if (ref($currinsttypes) eq 'ARRAY') {
5001: if (@{$currinsttypes} > 0) {
1.249 raeburn 5002: if (grep(/^any$/,@{$currinsttypes})) {
5003: $output .= ' checked="checked"';
5004: } elsif ($othervalue eq 'other') {
5005: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5006: $output .= ' checked="checked"';
5007: }
1.241 raeburn 5008: }
1.249 raeburn 5009: } else {
5010: $output .= ' checked="checked"';
1.241 raeburn 5011: }
1.249 raeburn 5012: } else {
5013: $output .= ' checked="checked"';
1.241 raeburn 5014: }
5015: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5016: }
5017: return $output;
5018: }
5019:
1.237 raeburn 5020: sub selfenroll_date_forms {
5021: my ($startform,$endform) = @_;
5022: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5023: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5024: 'LC_oddrow_value')."\n".
5025: $startform."\n".
5026: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5027: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5028: 'LC_oddrow_value')."\n".
5029: $endform."\n".
5030: &Apache::lonhtmlcommon::row_closure(1).
5031: &Apache::lonhtmlcommon::end_pick_box();
5032: return $output;
5033: }
5034:
1.239 raeburn 5035: sub print_userchangelogs_display {
5036: my ($r,$context,$permission) = @_;
5037: my $formname = 'roleslog';
5038: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5039: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.318 raeburn 5040: my $crstype = &Apache::loncommon::course_type();
1.239 raeburn 5041: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
5042: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5043:
5044: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
5045: my %saveable_parameters = ('show' => 'scalar',);
5046: &Apache::loncommon::store_course_settings('roles_log',
5047: \%saveable_parameters);
5048: &Apache::loncommon::restore_course_settings('roles_log',
5049: \%saveable_parameters);
5050: # set defaults
5051: my $now = time();
5052: my $defstart = $now - (7*24*3600); #7 days ago
5053: my %defaults = (
5054: page => '1',
5055: show => '10',
5056: role => 'any',
5057: chgcontext => 'any',
5058: rolelog_start_date => $defstart,
5059: rolelog_end_date => $now,
5060: );
5061: my $more_records = 0;
5062:
5063: # set current
5064: my %curr;
5065: foreach my $item ('show','page','role','chgcontext') {
5066: $curr{$item} = $env{'form.'.$item};
5067: }
5068: my ($startdate,$enddate) =
5069: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5070: $curr{'rolelog_start_date'} = $startdate;
5071: $curr{'rolelog_end_date'} = $enddate;
5072: foreach my $key (keys(%defaults)) {
5073: if ($curr{$key} eq '') {
5074: $curr{$key} = $defaults{$key};
5075: }
5076: }
1.248 raeburn 5077: my (%whodunit,%changed,$version);
5078: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.318 raeburn 5079: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
1.239 raeburn 5080: my ($minshown,$maxshown);
1.255 raeburn 5081: $minshown = 1;
1.239 raeburn 5082: my $count = 0;
5083: if ($curr{'show'} ne &mt('all')) {
5084: $maxshown = $curr{'page'} * $curr{'show'};
5085: if ($curr{'page'} > 1) {
5086: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5087: }
5088: }
1.301 bisitz 5089:
5090: # Collect user change log data
5091: my $content = '';
1.239 raeburn 5092: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5093: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5094: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5095: if ($curr{'show'} ne &mt('all')) {
5096: if ($count >= $curr{'page'} * $curr{'show'}) {
5097: $more_records = 1;
5098: last;
5099: }
5100: }
5101: if ($curr{'role'} ne 'any') {
5102: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5103: }
5104: if ($curr{'chgcontext'} ne 'any') {
5105: if ($curr{'chgcontext'} eq 'selfenroll') {
5106: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5107: } else {
5108: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5109: }
5110: }
5111: $count ++;
5112: next if ($count < $minshown);
1.301 bisitz 5113:
1.239 raeburn 5114: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5115: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5116: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5117: }
5118: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5119: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5120: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5121: }
5122: my $sec = $roleslog{$id}{'logentry'}{'section'};
5123: if ($sec eq '') {
5124: $sec = &mt('None');
5125: }
5126: my ($rolestart,$roleend);
5127: if ($roleslog{$id}{'delflag'}) {
5128: $rolestart = &mt('deleted');
5129: $roleend = &mt('deleted');
5130: } else {
5131: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5132: $roleend = $roleslog{$id}{'logentry'}{'end'};
5133: if ($rolestart eq '' || $rolestart == 0) {
5134: $rolestart = &mt('No start date');
5135: } else {
5136: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5137: }
5138: if ($roleend eq '' || $roleend == 0) {
5139: $roleend = &mt('No end date');
5140: } else {
5141: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5142: }
5143: }
5144: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5145: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5146: $chgcontext = 'selfenroll';
5147: }
1.318 raeburn 5148: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5149: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5150: $chgcontext = $lt{$chgcontext};
5151: }
1.301 bisitz 5152: $content .=
5153: &Apache::loncommon::start_data_table_row()
5154: .'<td>'.$count.'</td>'
5155: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
5156: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
5157: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.318 raeburn 5158: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>'
1.301 bisitz 5159: .'<td>'.$sec.'</td>'
5160: .'<td>'.$chgcontext.'</td>'
5161: .'<td>'.$rolestart.'</td>'
5162: .'<td>'.$roleend.'</td>'
5163: .&Apache::loncommon::end_data_table_row();
5164: }
5165:
5166: # Form Footer
5167: my $form_footer =
5168: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
5169: .'<input type="hidden" name="action" value="changelogs" />'
5170: .'</form>';
5171:
5172: # Only display table, if content is available (has been collected above)
5173: if (!$content) {
5174: $r->print('<p class="LC_info">'
5175: .&mt('There are no records to display.')
5176: .'</p>'
5177: );
5178: $r->print($form_footer);
5179: return;
1.239 raeburn 5180: }
1.301 bisitz 5181:
5182: # Content to display, so create navigation and display table
5183:
5184: # Create Navigation:
5185: # Navigation Script
5186: my $nav_script = <<"ENDSCRIPT";
1.239 raeburn 5187: <script type="text/javascript">
1.301 bisitz 5188: // <![CDATA[
1.239 raeburn 5189: function chgPage(caller) {
5190: if (caller == 'previous') {
5191: document.$formname.page.value --;
5192: }
5193: if (caller == 'next') {
5194: document.$formname.page.value ++;
5195: }
5196: document.$formname.submit();
5197: return;
5198: }
1.301 bisitz 5199: // ]]>
1.239 raeburn 5200: </script>
5201: ENDSCRIPT
1.301 bisitz 5202: # Navigation Buttons
5203: my $nav_links;
5204: $nav_links = '<p>';
5205: if (($curr{'page'} > 1) || ($more_records)) {
5206: if ($curr{'page'} > 1) {
5207: $nav_links .= '<input type="button"'
5208: .' onclick="javascript:chgPage('."'previous'".');"'
5209: .' value="'.&mt('Previous [_1] changes',$curr{'show'})
5210: .'" /> ';
5211: }
5212: if ($more_records) {
5213: $nav_links .= '<input type="button"'
5214: .' onclick="javascript:chgPage('."'next'".');"'
5215: .' value="'.&mt('Next [_1] changes',$curr{'show'})
5216: .'" />';
5217: }
5218: }
5219: $nav_links .= '</p>';
5220:
5221: # Table Header
5222: my $tableheader =
1.303 bisitz 5223: &Apache::loncommon::start_data_table_header_row()
1.301 bisitz 5224: .'<th> </th>'
5225: .'<th>'.&mt('When').'</th>'
5226: .'<th>'.&mt('Who made the change').'</th>'
5227: .'<th>'.&mt('Changed User').'</th>'
5228: .'<th>'.&mt('Role').'</th>'
5229: .'<th>'.&mt('Section').'</th>'
5230: .'<th>'.&mt('Context').'</th>'
5231: .'<th>'.&mt('Start').'</th>'
5232: .'<th>'.&mt('End').'</th>'
5233: .&Apache::loncommon::end_data_table_header_row();
5234:
5235: # Print Content
5236: $r->print(
5237: $nav_script
5238: .$nav_links
5239: .&Apache::loncommon::start_data_table()
5240: .$tableheader
5241: .$content
5242: .&Apache::loncommon::end_data_table()
5243: .$nav_links
5244: .$form_footer
5245: );
1.239 raeburn 5246: return;
5247: }
5248:
5249: sub role_display_filter {
1.318 raeburn 5250: my ($formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 5251: my $context = 'course';
1.318 raeburn 5252: my $lctype = lc($crstype);
1.239 raeburn 5253: my $nolink = 1;
5254: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 5255: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5256: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5257: (&mt('all'),5,10,20,50,100,1000,10000)).
5258: '</td><td> </td>';
5259: my $startform =
5260: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5261: $curr->{'rolelog_start_date'},undef,
5262: undef,undef,undef,undef,undef,undef,$nolink);
5263: my $endform =
5264: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5265: $curr->{'rolelog_end_date'},undef,
5266: undef,undef,undef,undef,undef,undef,$nolink);
1.318 raeburn 5267: my %lt = &rolechg_contexts($crstype);
1.301 bisitz 5268: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
5269: '<table><tr><td>'.&mt('After:').
5270: '</td><td>'.$startform.'</td></tr>'.
5271: '<tr><td>'.&mt('Before:').'</td>'.
5272: '<td>'.$endform.'</td></tr></table>'.
5273: '</td>'.
5274: '<td> </td>'.
1.239 raeburn 5275: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5276: '<select name="role"><option value="any"';
5277: if ($curr->{'role'} eq 'any') {
5278: $output .= ' selected="selected"';
5279: }
5280: $output .= '>'.&mt('Any').'</option>'."\n";
1.318 raeburn 5281: my @roles = &Apache::lonuserutils::course_roles($context,undef,1,$lctype);
1.239 raeburn 5282: foreach my $role (@roles) {
5283: my $plrole;
5284: if ($role eq 'cr') {
5285: $plrole = &mt('Custom Role');
5286: } else {
1.318 raeburn 5287: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 5288: }
5289: my $selstr = '';
5290: if ($role eq $curr->{'role'}) {
5291: $selstr = ' selected="selected"';
5292: }
5293: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5294: }
1.301 bisitz 5295: $output .= '</select></td>'.
5296: '<td> </td>'.
5297: '<td valign="top"><b>'.
1.239 raeburn 5298: &mt('Context:').'</b><br /><select name="chgcontext">';
1.318 raeburn 5299: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses') {
1.239 raeburn 5300: my $selstr = '';
5301: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 5302: $selstr = ' selected="selected"';
1.239 raeburn 5303: }
5304: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5305: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5306: }
5307: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5308: }
1.303 bisitz 5309: $output .= '</select></td>'
5310: .'</tr></table>';
5311:
5312: # Update Display button
5313: $output .= '<p>'
5314: .'<input type="submit" value="'.&mt('Update Display').'" />'
5315: .'</p>';
5316:
5317: # Server version info
5318: $output .= '<p class="LC_info">'
5319: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
5320: ,'2.6.99.0');
1.248 raeburn 5321: if ($version) {
1.303 bisitz 5322: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5323: }
5324: $output .= '</p><hr />';
1.239 raeburn 5325: return $output;
5326: }
5327:
5328: sub rolechg_contexts {
1.318 raeburn 5329: my ($crstype) = @_;
1.239 raeburn 5330: my %lt = &Apache::lonlocal::texthash (
5331: any => 'Any',
5332: auto => 'Automated enrollment',
5333: updatenow => 'Roster Update',
5334: createcourse => 'Course Creation',
5335: course => 'User Management in course',
5336: domain => 'User Management in domain',
1.313 raeburn 5337: selfenroll => 'Self-enrolled',
1.318 raeburn 5338: requestcourses => 'Course Request',
1.239 raeburn 5339: );
1.318 raeburn 5340: if ($crstype eq 'Community') {
5341: $lt{'createcourse'} = &mt('Community Creation');
5342: $lt{'course'} = &mt('User Management in community');
5343: $lt{'requestcourses'} = &mt('Community Request');
5344: }
1.239 raeburn 5345: return %lt;
5346: }
5347:
1.27 matthew 5348: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5349: sub user_search_result {
1.221 raeburn 5350: my ($context,$srch) = @_;
1.160 raeburn 5351: my %allhomes;
5352: my %inst_matches;
5353: my %srch_results;
1.181 raeburn 5354: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5355: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 5356: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 5357: $response = &mt('Invalid search.');
5358: }
5359: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
5360: $response = &mt('Invalid search.');
5361: }
1.177 raeburn 5362: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 5363: $response = &mt('Invalid search.');
5364: }
5365: if ($srch->{'srchterm'} eq '') {
5366: $response = &mt('You must enter a search term.');
5367: }
1.183 raeburn 5368: if ($srch->{'srchterm'} =~ /^\s+$/) {
5369: $response = &mt('Your search term must contain more than just spaces.');
5370: }
1.160 raeburn 5371: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5372: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5373: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5374: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5375: }
5376: }
5377: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5378: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5379: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5380: my $unamecheck = $srch->{'srchterm'};
5381: if ($srch->{'srchtype'} eq 'contains') {
5382: if ($unamecheck !~ /^\w/) {
5383: $unamecheck = 'a'.$unamecheck;
5384: }
5385: }
5386: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5387: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5388: }
1.160 raeburn 5389: }
5390: }
1.180 raeburn 5391: if ($response ne '') {
5392: $response = '<span class="LC_warning">'.$response.'</span>';
5393: }
1.160 raeburn 5394: if ($srch->{'srchin'} eq 'instd') {
5395: my $instd_chk = &directorysrch_check($srch);
5396: if ($instd_chk ne 'ok') {
1.180 raeburn 5397: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5398: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5399: }
5400: }
5401: if ($response ne '') {
1.180 raeburn 5402: return ($currstate,$response);
1.160 raeburn 5403: }
5404: if ($srch->{'srchby'} eq 'uname') {
5405: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5406: if ($env{'form.forcenew'}) {
5407: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5408: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5409: if ($uhome eq 'no_host') {
5410: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5411: my $showdom = &display_domain_info($env{'request.role.domain'});
5412: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5413: } else {
1.179 raeburn 5414: $currstate = 'modify';
1.160 raeburn 5415: }
5416: } else {
1.179 raeburn 5417: $currstate = 'modify';
1.160 raeburn 5418: }
5419: } else {
5420: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 5421: if ($srch->{'srchtype'} eq 'exact') {
5422: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5423: if ($uhome eq 'no_host') {
1.179 raeburn 5424: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5425: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5426: } else {
1.179 raeburn 5427: $currstate = 'modify';
1.310 raeburn 5428: my $uname = $srch->{'srchterm'};
5429: my $udom = $srch->{'srchdomain'};
5430: $srch_results{$uname.':'.$udom} =
5431: { &Apache::lonnet::get('environment',
5432: ['firstname',
5433: 'lastname',
5434: 'permanentemail'],
5435: $udom,$uname)
5436: };
1.162 raeburn 5437: }
5438: } else {
5439: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5440: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5441: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5442: }
5443: } else {
1.167 albertel 5444: my $courseusers = &get_courseusers();
1.162 raeburn 5445: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 5446: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 5447: $currstate = 'modify';
1.162 raeburn 5448: } else {
1.179 raeburn 5449: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5450: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5451: }
1.160 raeburn 5452: } else {
1.167 albertel 5453: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 5454: my ($cuname,$cudomain) = split(/:/,$user);
5455: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 5456: my $matched = 0;
5457: if ($srch->{'srchtype'} eq 'begins') {
5458: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
5459: $matched = 1;
5460: }
5461: } else {
5462: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
5463: $matched = 1;
5464: }
5465: }
5466: if ($matched) {
1.167 albertel 5467: $srch_results{$user} =
5468: {&Apache::lonnet::get('environment',
5469: ['firstname',
5470: 'lastname',
1.194 albertel 5471: 'permanentemail'],
5472: $cudomain,$cuname)};
1.162 raeburn 5473: }
5474: }
5475: }
1.179 raeburn 5476: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5477: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5478: }
5479: }
5480: }
5481: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5482: $currstate = 'query';
1.160 raeburn 5483: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5484: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5485: if ($dirsrchres eq 'ok') {
5486: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5487: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5488: } else {
5489: my $showdom = &display_domain_info($srch->{'srchdomain'});
5490: $response = '<span class="LC_warning">'.
5491: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5492: '</span><br />'.
5493: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5494: '<br /><br />';
5495: }
1.160 raeburn 5496: }
5497: } else {
5498: if ($srch->{'srchin'} eq 'dom') {
5499: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5500: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5501: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5502: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 5503: my $courseusers = &get_courseusers();
5504: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 5505: my ($uname,$udom) = split(/:/,$user);
5506: my %names = &Apache::loncommon::getnames($uname,$udom);
5507: my %emails = &Apache::loncommon::getemails($uname,$udom);
5508: if ($srch->{'srchby'} eq 'lastname') {
5509: if ((($srch->{'srchtype'} eq 'exact') &&
5510: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 5511: (($srch->{'srchtype'} eq 'begins') &&
5512: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 5513: (($srch->{'srchtype'} eq 'contains') &&
5514: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
5515: $srch_results{$user} = {firstname => $names{'firstname'},
5516: lastname => $names{'lastname'},
5517: permanentemail => $emails{'permanentemail'},
5518: };
5519: }
5520: } elsif ($srch->{'srchby'} eq 'lastfirst') {
5521: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 5522: $srchlast =~ s/\s+$//;
5523: $srchfirst =~ s/^\s+//;
1.160 raeburn 5524: if ($srch->{'srchtype'} eq 'exact') {
5525: if (($names{'lastname'} eq $srchlast) &&
5526: ($names{'firstname'} eq $srchfirst)) {
5527: $srch_results{$user} = {firstname => $names{'firstname'},
5528: lastname => $names{'lastname'},
5529: permanentemail => $emails{'permanentemail'},
5530:
5531: };
5532: }
1.177 raeburn 5533: } elsif ($srch->{'srchtype'} eq 'begins') {
5534: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5535: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5536: $srch_results{$user} = {firstname => $names{'firstname'},
5537: lastname => $names{'lastname'},
5538: permanentemail => $emails{'permanentemail'},
5539: };
5540: }
5541: } else {
1.160 raeburn 5542: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5543: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5544: $srch_results{$user} = {firstname => $names{'firstname'},
5545: lastname => $names{'lastname'},
5546: permanentemail => $emails{'permanentemail'},
5547: };
5548: }
5549: }
5550: }
5551: }
1.179 raeburn 5552: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5553: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5554: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5555: $currstate = 'query';
1.160 raeburn 5556: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5557: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5558: if ($dirsrchres eq 'ok') {
5559: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5560: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5561: } else {
5562: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5563: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5564: '</span><br />'.
5565: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5566: '<br /><br />';
5567: }
1.160 raeburn 5568: }
5569: }
1.179 raeburn 5570: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5571: }
5572:
5573: sub directorysrch_check {
5574: my ($srch) = @_;
5575: my $can_search = 0;
5576: my $response;
5577: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5578: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5579: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5580: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5581: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5582: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5583: }
5584: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5585: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5586: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5587: }
5588: my @usertypes = split(/:/,$env{'environment.inststatus'});
5589: if (!@usertypes) {
5590: push(@usertypes,'default');
5591: }
5592: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5593: foreach my $type (@usertypes) {
5594: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5595: $can_search = 1;
5596: last;
5597: }
5598: }
5599: }
5600: if (!$can_search) {
5601: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5602: my @longtypes;
5603: foreach my $item (@usertypes) {
1.229 raeburn 5604: if (defined($insttypes->{$item})) {
5605: push (@longtypes,$insttypes->{$item});
5606: } elsif ($item eq 'default') {
5607: push (@longtypes,&mt('other'));
5608: }
1.160 raeburn 5609: }
5610: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5611: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5612: }
1.160 raeburn 5613: } else {
5614: $can_search = 1;
5615: }
5616: } else {
1.180 raeburn 5617: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5618: }
5619: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5620: uname => 'username',
1.160 raeburn 5621: lastfirst => 'last name, first name',
1.167 albertel 5622: lastname => 'last name',
1.172 raeburn 5623: contains => 'contains',
1.178 raeburn 5624: exact => 'as exact match to',
5625: begins => 'begins with',
1.160 raeburn 5626: );
5627: if ($can_search) {
5628: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5629: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5630: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5631: }
5632: } else {
1.180 raeburn 5633: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5634: }
5635: }
5636: if ($can_search) {
1.178 raeburn 5637: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5638: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5639: return 'ok';
5640: } else {
1.180 raeburn 5641: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5642: }
5643: } else {
5644: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5645: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5646: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5647: return 'ok';
5648: } else {
1.180 raeburn 5649: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5650: }
1.160 raeburn 5651: }
5652: }
5653: }
5654:
5655: sub get_courseusers {
5656: my %advhash;
1.167 albertel 5657: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5658: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5659: foreach my $role (sort(keys(%coursepersonnel))) {
5660: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5661: if (!exists($classlist->{$user})) {
5662: $classlist->{$user} = [];
5663: }
1.160 raeburn 5664: }
5665: }
1.167 albertel 5666: return $classlist;
1.160 raeburn 5667: }
5668:
5669: sub build_search_response {
1.221 raeburn 5670: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5671: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5672: my %names = (
5673: 'uname' => 'username',
5674: 'lastname' => 'last name',
5675: 'lastfirst' => 'last name, first name',
5676: 'crs' => 'this course',
1.180 raeburn 5677: 'dom' => 'LON-CAPA domain: ',
5678: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5679: );
5680:
5681: my %single = (
1.180 raeburn 5682: begins => 'A match',
1.160 raeburn 5683: contains => 'A match',
1.180 raeburn 5684: exact => 'An exact match',
1.160 raeburn 5685: );
5686: my %nomatch = (
1.180 raeburn 5687: begins => 'No match',
1.160 raeburn 5688: contains => 'No match',
1.180 raeburn 5689: exact => 'No exact match',
1.160 raeburn 5690: );
5691: if (keys(%srch_results) > 1) {
1.179 raeburn 5692: $currstate = 'select';
1.160 raeburn 5693: } else {
5694: if (keys(%srch_results) == 1) {
1.179 raeburn 5695: $currstate = 'modify';
1.180 raeburn 5696: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5697: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5698: $response .= &display_domain_info($srch->{'srchdomain'});
5699: }
1.160 raeburn 5700: } else {
1.180 raeburn 5701: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
5702: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5703: $response .= &display_domain_info($srch->{'srchdomain'});
5704: }
5705: $response .= '</span>';
1.160 raeburn 5706: if ($srch->{'srchin'} ne 'alc') {
5707: $forcenewuser = 1;
5708: my $cansrchinst = 0;
5709: if ($srch->{'srchdomain'}) {
5710: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5711: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5712: if ($domconfig{'directorysrch'}{'available'}) {
5713: $cansrchinst = 1;
5714: }
5715: }
5716: }
1.180 raeburn 5717: if ((($srch->{'srchby'} eq 'lastfirst') ||
5718: ($srch->{'srchby'} eq 'lastname')) &&
5719: ($srch->{'srchin'} eq 'dom')) {
5720: if ($cansrchinst) {
5721: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5722: }
5723: }
1.180 raeburn 5724: if ($srch->{'srchin'} eq 'crs') {
5725: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5726: }
5727: }
1.305 raeburn 5728: my $createdom = $env{'request.role.domain'};
5729: if ($context eq 'requestcrs') {
5730: if ($env{'form.coursedom'} ne '') {
5731: $createdom = $env{'form.coursedom'};
5732: }
5733: }
5734: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 5735: my $cancreate =
1.305 raeburn 5736: &Apache::lonuserutils::can_create_user($createdom,$context);
5737: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 5738: if ($cancreate) {
1.305 raeburn 5739: my $showdom = &display_domain_info($createdom);
1.266 bisitz 5740: $response .= '<br /><br />'
5741: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 5742: .'<br />';
5743: if ($context eq 'requestcrs') {
5744: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
5745: } else {
5746: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
5747: }
5748: $response .='<ul><li>'
1.266 bisitz 5749: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5750: .'</li><li>'
5751: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5752: .'</li><li>'
5753: .&mt('Provide the proposed username')
5754: .'</li><li>'
5755: .&mt("Click 'Search'")
5756: .'</li></ul><br />';
1.221 raeburn 5757: } else {
5758: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 5759: $response .= '<br /><br />';
5760: if ($context eq 'requestcrs') {
1.314 raeburn 5761: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 5762: } else {
5763: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
5764: }
5765: $response .= '<br />'
5766: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 5767: ,' <a'.$helplink.'>'
5768: ,'</a>')
1.305 raeburn 5769: .'<br /><br />';
1.221 raeburn 5770: }
1.160 raeburn 5771: }
5772: }
5773: }
1.179 raeburn 5774: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5775: }
5776:
1.180 raeburn 5777: sub display_domain_info {
5778: my ($dom) = @_;
5779: my $output = $dom;
5780: if ($dom ne '') {
5781: my $domdesc = &Apache::lonnet::domain($dom,'description');
5782: if ($domdesc ne '') {
5783: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5784: }
5785: }
5786: return $output;
5787: }
5788:
1.160 raeburn 5789: sub crumb_utilities {
5790: my %elements = (
5791: crtuser => {
5792: srchterm => 'text',
1.172 raeburn 5793: srchin => 'selectbox',
1.160 raeburn 5794: srchby => 'selectbox',
5795: srchtype => 'selectbox',
5796: srchdomain => 'selectbox',
5797: },
1.207 raeburn 5798: crtusername => {
5799: srchterm => 'text',
5800: srchdomain => 'selectbox',
5801: },
1.160 raeburn 5802: docustom => {
5803: rolename => 'selectbox',
5804: newrolename => 'textbox',
5805: },
1.179 raeburn 5806: studentform => {
5807: srchterm => 'text',
5808: srchin => 'selectbox',
5809: srchby => 'selectbox',
5810: srchtype => 'selectbox',
5811: srchdomain => 'selectbox',
5812: },
1.160 raeburn 5813: );
5814:
5815: my $jsback .= qq|
5816: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5817: if (typeof prevphase == 'undefined') {
5818: formname.phase.value = '';
5819: }
5820: else {
5821: formname.phase.value = prevphase;
5822: }
5823: if (typeof prevstate == 'undefined') {
5824: formname.currstate.value = '';
5825: }
5826: else {
5827: formname.currstate.value = prevstate;
5828: }
1.160 raeburn 5829: formname.submit();
5830: }
5831: |;
5832: return ($jsback,\%elements);
5833: }
5834:
1.26 matthew 5835: sub course_level_table {
1.89 raeburn 5836: my (%inccourses) = @_;
1.26 matthew 5837: my $table = '';
1.62 www 5838: # Custom Roles?
5839:
1.190 raeburn 5840: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5841: my %lt=&Apache::lonlocal::texthash(
5842: 'exs' => "Existing sections",
5843: 'new' => "Define new section",
5844: 'ssd' => "Set Start Date",
5845: 'sed' => "Set End Date",
1.131 raeburn 5846: 'crl' => "Course Level",
1.89 raeburn 5847: 'act' => "Activate",
5848: 'rol' => "Role",
5849: 'ext' => "Extent",
1.113 raeburn 5850: 'grs' => "Section",
1.89 raeburn 5851: 'sta' => "Start",
5852: 'end' => "End"
5853: );
1.62 www 5854:
1.135 raeburn 5855: foreach my $protectedcourse (sort( keys(%inccourses))) {
5856: my $thiscourse=$protectedcourse;
1.26 matthew 5857: $thiscourse=~s:_:/:g;
5858: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
5859: my $area=$coursedata{'description'};
1.321 raeburn 5860: my $crstype=$coursedata{'type'};
1.135 raeburn 5861: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5862: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5863: my %sections_count;
1.101 albertel 5864: if (defined($env{'request.course.id'})) {
5865: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5866: %sections_count =
5867: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5868: }
5869: }
1.321 raeburn 5870: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 5871: foreach my $role (@roles) {
1.321 raeburn 5872: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.135 raeburn 5873: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 5874: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5875: $plrole,\%sections_count,\%lt);
5876: } elsif ($env{'request.course.sec'} ne '') {
5877: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5878: $env{'request.course.sec'})) {
5879: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5880: $plrole,\%sections_count,\%lt);
1.26 matthew 5881: }
5882: }
5883: }
1.221 raeburn 5884: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
5885: foreach my $cust (sort keys %customroles) {
5886: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5887: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5888: $cust,\%sections_count,\%lt);
5889: }
1.62 www 5890: }
1.26 matthew 5891: }
5892: return '' if ($table eq ''); # return nothing if there is nothing
5893: # in the table
1.188 raeburn 5894: my $result;
5895: if (!$env{'request.course.id'}) {
5896: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5897: }
5898: $result .=
1.136 raeburn 5899: &Apache::loncommon::start_data_table().
5900: &Apache::loncommon::start_data_table_header_row().
5901: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5902: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5903: &Apache::loncommon::end_data_table_header_row().
5904: $table.
5905: &Apache::loncommon::end_data_table();
1.26 matthew 5906: return $result;
5907: }
1.88 raeburn 5908:
1.221 raeburn 5909: sub course_level_row {
5910: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5911: my $row = &Apache::loncommon::start_data_table_row().
5912: ' <td><input type="checkbox" name="act_'.
5913: $protectedcourse.'_'.$role.'" /></td>'."\n".
5914: ' <td>'.$plrole.'</td>'."\n".
5915: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.322 ! raeburn 5916: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 5917: $row .= '<td> </td>';
1.221 raeburn 5918: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5919: $row .= ' <td><input type="hidden" value="'.
5920: $env{'request.course.sec'}.'" '.
5921: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5922: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5923: } else {
5924: if (ref($sections_count) eq 'HASH') {
5925: my $currsec =
5926: &Apache::lonuserutils::course_sections($sections_count,
5927: $protectedcourse.'_'.$role);
1.222 raeburn 5928: $row .= '<td><table class="LC_createuser">'."\n".
5929: '<tr class="LC_section_row">'."\n".
5930: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
5931: $currsec.'</td>'."\n".
5932: ' <td> </td>'."\n".
5933: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 5934: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
5935: '" value="" />'.
5936: '<input type="hidden" '.
5937: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 5938: '</tr></table></td>'."\n";
1.221 raeburn 5939: } else {
1.222 raeburn 5940: $row .= '<td><input type="text" size="10" '.
5941: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 5942: }
5943: }
1.222 raeburn 5944: $row .= <<ENDTIMEENTRY;
5945: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 5946: <a href=
5947: "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 5948: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 5949: <a href=
5950: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
5951: ENDTIMEENTRY
1.222 raeburn 5952: $row .= &Apache::loncommon::end_data_table_row();
5953: return $row;
1.221 raeburn 5954: }
5955:
1.88 raeburn 5956: sub course_level_dc {
5957: my ($dcdom) = @_;
1.190 raeburn 5958: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 5959: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 5960: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
5961: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 5962: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 5963: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 5964: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
1.319 raeburn 5965: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role');
1.88 raeburn 5966: my %lt=&Apache::lonlocal::texthash(
5967: 'rol' => "Role",
1.113 raeburn 5968: 'grs' => "Section",
1.88 raeburn 5969: 'exs' => "Existing sections",
5970: 'new' => "Define new section",
5971: 'sta' => "Start",
5972: 'end' => "End",
5973: 'ssd' => "Set Start Date",
5974: 'sed' => "Set End Date"
5975: );
1.131 raeburn 5976: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 5977: &Apache::loncommon::start_data_table().
5978: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 5979: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 5980: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 5981: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.301 bisitz 5982: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 5983: '<td><select name="role">'."\n";
1.213 raeburn 5984: foreach my $role (@roles) {
1.135 raeburn 5985: my $plrole=&Apache::lonnet::plaintext($role);
5986: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 5987: }
5988: if ( keys %customroles > 0) {
1.135 raeburn 5989: foreach my $cust (sort keys %customroles) {
1.101 albertel 5990: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 5991: '_'.$env{'user.name'}.'_'.$cust;
5992: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 5993: }
5994: }
5995: $otheritems .= '</select></td><td>'.
5996: '<table border="0" cellspacing="0" cellpadding="0">'.
5997: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
5998: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
5999: '<td> </td>'.
6000: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6001: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6002: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 6003: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 6004: '</tr></table></td>';
6005: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 6006: <td><input type="hidden" name="start" value='' />
1.88 raeburn 6007: <a href=
6008: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 6009: <td><input type="hidden" name="end" value='' />
1.88 raeburn 6010: <a href=
6011: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
6012: ENDTIMEENTRY
1.136 raeburn 6013: $otheritems .= &Apache::loncommon::end_data_table_row().
6014: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 6015: return $cb_jscript.$header.$hiddenitems.$otheritems;
6016: }
6017:
1.237 raeburn 6018: sub update_selfenroll_config {
1.241 raeburn 6019: my ($r,$context,$permission) = @_;
1.237 raeburn 6020: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 6021: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 6022: my (%changes,%warning);
6023: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6024: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 6025: my $curr_types;
1.237 raeburn 6026: if (ref($row) eq 'ARRAY') {
6027: foreach my $item (@{$row}) {
6028: if ($item eq 'enroll_dates') {
6029: my (%currenrolldate,%newenrolldate);
6030: foreach my $type ('start','end') {
6031: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
6032: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
6033: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
6034: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
6035: }
6036: }
6037: } elsif ($item eq 'access_dates') {
6038: my (%currdate,%newdate);
6039: foreach my $type ('start','end') {
6040: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
6041: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
6042: if ($newdate{$type} ne $currdate{$type}) {
6043: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
6044: }
6045: }
1.241 raeburn 6046: } elsif ($item eq 'types') {
6047: $curr_types =
6048: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6049: if ($env{'form.selfenroll_all'}) {
6050: if ($curr_types ne '*') {
6051: $changes{'internal.selfenroll_types'} = '*';
6052: } else {
6053: next;
6054: }
6055: } else {
1.249 raeburn 6056: my %currdoms;
1.241 raeburn 6057: my @entries = split(/;/,$curr_types);
6058: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 6059: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 6060: my $newnum = 0;
1.249 raeburn 6061: my @latesttypes;
6062: foreach my $num (@activations) {
6063: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
6064: if (@types > 0) {
1.241 raeburn 6065: @types = sort(@types);
6066: my $typestr = join(',',@types);
1.249 raeburn 6067: my $typedom = $env{'form.selfenroll_dom_'.$num};
6068: $latesttypes[$newnum] = $typedom.':'.$typestr;
6069: $currdoms{$typedom} = 1;
1.241 raeburn 6070: $newnum ++;
6071: }
6072: }
1.249 raeburn 6073: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
6074: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
6075: if (@types > 0) {
6076: @types = sort(@types);
6077: my $typestr = join(',',@types);
6078: my $typedom = $env{'form.selfenroll_dom_'.$j};
6079: $latesttypes[$newnum] = $typedom.':'.$typestr;
6080: $currdoms{$typedom} = 1;
6081: $newnum ++;
6082: }
6083: }
6084: }
6085: if ($env{'form.selfenroll_newdom'} ne '') {
6086: my $typedom = $env{'form.selfenroll_newdom'};
6087: if ((!defined($currdoms{$typedom})) &&
6088: (&Apache::lonnet::domain($typedom) ne '')) {
6089: my $typestr;
6090: my ($othertitle,$usertypes,$types) =
6091: &Apache::loncommon::sorted_inst_types($typedom);
6092: my $othervalue = 'any';
6093: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6094: if (@{$types} > 0) {
1.257 raeburn 6095: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 6096: $othervalue = 'other';
1.258 raeburn 6097: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 6098: }
6099: $typestr = $othervalue;
6100: } else {
6101: $typestr = $othervalue;
6102: }
6103: $latesttypes[$newnum] = $typedom.':'.$typestr;
6104: $newnum ++ ;
6105: }
6106: }
1.241 raeburn 6107: my $selfenroll_types = join(';',@latesttypes);
6108: if ($selfenroll_types ne $curr_types) {
6109: $changes{'internal.selfenroll_types'} = $selfenroll_types;
6110: }
6111: }
1.276 raeburn 6112: } elsif ($item eq 'limit') {
6113: my $newlimit = $env{'form.selfenroll_limit'};
6114: my $newcap = $env{'form.selfenroll_cap'};
6115: $newcap =~s/\s+//g;
6116: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6117: $currlimit = 'none' if ($currlimit eq '');
6118: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6119: if ($newlimit ne $currlimit) {
6120: if ($newlimit ne 'none') {
6121: if ($newcap =~ /^\d+$/) {
6122: if ($newcap ne $currcap) {
6123: $changes{'internal.selfenroll_cap'} = $newcap;
6124: }
6125: $changes{'internal.selfenroll_limit'} = $newlimit;
6126: } else {
6127: $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.');
6128: }
6129: } elsif ($currcap ne '') {
6130: $changes{'internal.selfenroll_cap'} = '';
6131: $changes{'internal.selfenroll_limit'} = $newlimit;
6132: }
6133: } elsif ($currlimit ne 'none') {
6134: if ($newcap =~ /^\d+$/) {
6135: if ($newcap ne $currcap) {
6136: $changes{'internal.selfenroll_cap'} = $newcap;
6137: }
6138: } else {
6139: $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.');
6140: }
6141: }
6142: } elsif ($item eq 'approval') {
6143: my (@currnotified,@newnotified);
6144: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6145: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6146: if ($currnotifylist ne '') {
6147: @currnotified = split(/,/,$currnotifylist);
6148: @currnotified = sort(@currnotified);
6149: }
6150: my $newapproval = $env{'form.selfenroll_approval'};
6151: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
6152: @newnotified = sort(@newnotified);
6153: if ($newapproval ne $currapproval) {
6154: $changes{'internal.selfenroll_approval'} = $newapproval;
6155: if (!$newapproval) {
6156: if ($currnotifylist ne '') {
6157: $changes{'internal.selfenroll_notifylist'} = '';
6158: }
6159: } else {
6160: my @differences =
1.295 raeburn 6161: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6162: if (@differences > 0) {
6163: if (@newnotified > 0) {
6164: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6165: } else {
6166: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6167: }
6168: }
6169: }
6170: } else {
1.295 raeburn 6171: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6172: if (@differences > 0) {
6173: if (@newnotified > 0) {
6174: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6175: } else {
6176: $changes{'internal.selfenroll_notifylist'} = '';
6177: }
6178: }
6179: }
1.237 raeburn 6180: } else {
6181: my $curr_val =
6182: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6183: my $newval = $env{'form.selfenroll_'.$item};
6184: if ($item eq 'section') {
6185: $newval = $env{'form.sections'};
1.241 raeburn 6186: if (defined($curr_groups{$newval})) {
1.237 raeburn 6187: $newval = $curr_val;
6188: $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');
6189: } elsif ($newval eq 'all') {
6190: $newval = $curr_val;
1.274 bisitz 6191: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6192: }
6193: if ($newval eq '') {
6194: $newval = 'none';
6195: }
6196: }
6197: if ($newval ne $curr_val) {
6198: $changes{'internal.selfenroll_'.$item} = $newval;
6199: }
1.241 raeburn 6200: }
1.237 raeburn 6201: }
6202: if (keys(%warning) > 0) {
6203: foreach my $item (@{$row}) {
6204: if (exists($warning{$item})) {
6205: $r->print($warning{$item}.'<br />');
6206: }
6207: }
6208: }
6209: if (keys(%changes) > 0) {
6210: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6211: if ($putresult eq 'ok') {
6212: if ((exists($changes{'internal.selfenroll_types'})) ||
6213: (exists($changes{'internal.selfenroll_start_date'})) ||
6214: (exists($changes{'internal.selfenroll_end_date'}))) {
6215: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6216: $cnum,undef,undef,'Course');
6217: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6218: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6219: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6220: if (exists($changes{'internal.'.$item})) {
6221: $crsinfo{$env{'request.course.id'}}{$item} =
6222: $changes{'internal.'.$item};
6223: }
6224: }
6225: my $crsputresult =
6226: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6227: $chome,'notime');
6228: }
6229: }
6230: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6231: foreach my $item (@{$row}) {
6232: my $title = $item;
6233: if (ref($lt) eq 'HASH') {
6234: $title = $lt->{$item};
6235: }
6236: if ($item eq 'enroll_dates') {
6237: foreach my $type ('start','end') {
6238: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6239: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6240: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6241: $title,$type,$newdate).'</li>');
6242: }
6243: }
6244: } elsif ($item eq 'access_dates') {
6245: foreach my $type ('start','end') {
6246: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6247: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6248: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6249: $title,$type,$newdate).'</li>');
6250: }
6251: }
1.276 raeburn 6252: } elsif ($item eq 'limit') {
6253: if ((exists($changes{'internal.selfenroll_limit'})) ||
6254: (exists($changes{'internal.selfenroll_cap'}))) {
6255: my ($newval,$newcap);
6256: if ($changes{'internal.selfenroll_cap'} ne '') {
6257: $newcap = $changes{'internal.selfenroll_cap'}
6258: } else {
6259: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6260: }
6261: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6262: $newval = &mt('No limit');
6263: } elsif ($changes{'internal.selfenroll_limit'} eq
6264: 'allstudents') {
6265: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6266: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6267: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6268: } else {
6269: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6270: if ($currlimit eq 'allstudents') {
6271: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6272: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 6273: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 6274: }
6275: }
6276: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6277: }
6278: } elsif ($item eq 'approval') {
6279: if ((exists($changes{'internal.selfenroll_approval'})) ||
6280: (exists($changes{'internal.selfenroll_notifylist'}))) {
6281: my ($newval,$newnotify);
6282: if (exists($changes{'internal.selfenroll_notifylist'})) {
6283: $newnotify = $changes{'internal.selfenroll_notifylist'};
6284: } else {
6285: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6286: }
6287: if ($changes{'internal.selfenroll_approval'}) {
6288: $newval = &mt('Yes');
6289: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6290: $newval = &mt('No');
6291: } else {
6292: my $currapproval =
6293: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6294: if ($currapproval) {
6295: $newval = &mt('Yes');
6296: } else {
6297: $newval = &mt('No');
6298: }
6299: }
6300: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6301: if ($newnotify) {
1.277 raeburn 6302: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6303: } else {
1.277 raeburn 6304: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6305: }
6306: $r->print('</li>'."\n");
6307: }
1.237 raeburn 6308: } else {
6309: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6310: my $newval = $changes{'internal.selfenroll_'.$item};
6311: if ($item eq 'types') {
6312: if ($newval eq '') {
6313: $newval = &mt('None');
6314: } elsif ($newval eq '*') {
6315: $newval = &mt('Any user in any domain');
6316: }
1.245 raeburn 6317: } elsif ($item eq 'registered') {
6318: if ($newval eq '1') {
6319: $newval = &mt('Yes');
6320: } elsif ($newval eq '0') {
6321: $newval = &mt('No');
6322: }
1.241 raeburn 6323: }
1.244 bisitz 6324: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6325: }
6326: }
6327: }
6328: $r->print('</ul>');
6329: my %newenvhash;
6330: foreach my $key (keys(%changes)) {
6331: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6332: }
1.238 raeburn 6333: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6334: } else {
6335: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6336: }
6337: } else {
1.249 raeburn 6338: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6339: }
6340: } else {
1.249 raeburn 6341: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6342: }
1.256 raeburn 6343: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
6344: if (ref($visactions) eq 'HASH') {
6345: if (!$visible) {
6346: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
6347: '<br />');
6348: if (ref($vismsgs) eq 'ARRAY') {
6349: $r->print('<br />'.$visactions->{'take'}.'<ul>');
6350: foreach my $item (@{$vismsgs}) {
6351: $r->print('<li>'.$visactions->{$item}.'</li>');
6352: }
6353: $r->print('</ul>');
6354: }
6355: $r->print($cansetvis);
6356: }
6357: }
1.237 raeburn 6358: return;
6359: }
6360:
6361: sub get_selfenroll_titles {
1.276 raeburn 6362: my @row = ('types','registered','enroll_dates','access_dates','section',
6363: 'approval','limit');
1.237 raeburn 6364: my %lt = &Apache::lonlocal::texthash (
6365: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 6366: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 6367: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 6368: access_dates => 'Course access dates assigned to self-enrolling users',
6369: section => 'Section assigned to self-enrolling users',
1.276 raeburn 6370: approval => 'Self-enrollment requests need approval?',
6371: limit => 'Enrollment limit',
1.237 raeburn 6372: );
6373: return (\@row,\%lt);
6374: }
6375:
1.27 matthew 6376: #---------------------------------------------- end functions for &phase_two
1.29 matthew 6377:
6378: #--------------------------------- functions for &phase_two and &phase_three
6379:
6380: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 6381:
6382: 1;
6383: __END__
1.2 www 6384:
6385:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>