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