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