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