Annotation of loncom/interface/loncreateuser.pm, revision 1.282
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.282 ! schafran 4: # $Id: loncreateuser.pm,v 1.281 2009/02/17 16:53:37 bisitz 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",
904: 'yodo' => "You do not have privileges to modify Portfolio, Blog or Home Page settings for this user.",
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.204 raeburn 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.275 raeburn 2161: 'uic' => "User Information Changed",
2162: 'frst' => "First",
2163: 'mddl' => "Middle",
2164: 'lst' => "Last",
2165: 'gen' => "Generation",
2166: 'id' => "Student/Employee ID",
2167: 'mail' => "Permanent E-mail",
2168: 'disk' => "Disk space allocated to portfolio files",
2169: 'blog' => "Blog Availability",
2170: 'aboutme' => "Home Page Availability",
2171: 'portfolio' => "Portfolio Availability",
2172: 'official' => "Can Request Official Courses",
2173: 'unofficial' => "Can Request Unofficial Courses",
2174: 'prvs' => "Previous",
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",
2292: 'mail' => "Permanent e-mail",
2293: 'disk' => "Disk space allocated to user's portfolio files",
2294: 'blog' => "Blog Availability",
2295: 'aboutme' => "Home Page Availability",
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) {
3842: $output .= '<p>'.$visactions->{'vis'}.'</p>';
3843: } else {
3844: $output .= $visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
3845: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
3846: if (ref($vismsgs) eq 'ARRAY') {
3847: $output .= '<br />'.$visactions->{'make'}.'<ul>';
3848: foreach my $item (@{$vismsgs}) {
3849: $output .= '<li>'.$visactions->{$item}.'</li>';
3850: }
3851: $output .= '</ul>';
3852: }
3853: $output .= '</p>';
3854: }
3855: }
3856: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
3857: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 3858: if (ref($row) eq 'ARRAY') {
3859: foreach my $item (@{$row}) {
3860: my $title = $item;
3861: if (ref($lt) eq 'HASH') {
3862: $title = $lt->{$item};
3863: }
3864: $output .=
3865: &Apache::lonhtmlcommon::row_title($title,
3866: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
3867: if ($item eq 'types') {
3868: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 3869: my $showdomdesc = 1;
3870: my $includeempty = 1;
3871: my $num = 0;
3872: $output .= &Apache::loncommon::start_data_table().
3873: &Apache::loncommon::start_data_table_row()
3874: .'<td colspan="2"><span class="LC_nobreak"><label>'
3875: .&mt('Any user in any domain:')
3876: .' <input type="radio" name="selfenroll_all" value="1" ';
3877: if ($curr_types eq '*') {
3878: $output .= ' checked="checked" ';
3879: }
1.249 raeburn 3880: $output .= 'onchange="javascript:update_types('.
3881: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
3882: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 3883: if ($curr_types ne '*') {
3884: $output .= ' checked="checked" ';
3885: }
1.249 raeburn 3886: $output .= ' onchange="javascript:update_types('.
3887: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
3888: &Apache::loncommon::end_data_table_row().
3889: &Apache::loncommon::end_data_table().
3890: &mt('Or').'<br />'.
3891: &Apache::loncommon::start_data_table();
1.241 raeburn 3892: my %currdoms;
1.249 raeburn 3893: if ($curr_types eq '') {
1.241 raeburn 3894: $output .= &new_selfenroll_dom_row($cdom,'0');
3895: } elsif ($curr_types ne '*') {
3896: my @entries = split(/;/,$curr_types);
3897: if (@entries > 0) {
3898: foreach my $entry (@entries) {
3899: my ($currdom,$typestr) = split(/:/,$entry);
3900: $currdoms{$currdom} = 1;
3901: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 3902: my @currinsttypes = split(',',$typestr);
1.241 raeburn 3903: $output .= &Apache::loncommon::start_data_table_row()
3904: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
3905: .' '.$domdesc.' ('.$currdom.')'
3906: .'</b><input type="hidden" name="selfenroll_dom_'.$num
3907: .'" value="'.$currdom.'" /></span><br />'
3908: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 3909: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 3910: .&mt('Delete').'</label></span></td>';
1.249 raeburn 3911: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 3912: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
3913: .&Apache::loncommon::end_data_table_row();
3914: $num ++;
3915: }
3916: }
3917: }
1.249 raeburn 3918: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 3919: if ($curr_types eq '*') {
1.249 raeburn 3920: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 3921: } elsif ($curr_types eq '') {
1.249 raeburn 3922: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 3923: }
3924: $output .= &Apache::loncommon::start_data_table_row()
3925: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
3926: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
3927: $includeempty,$showdomdesc)
3928: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
3929: .'</td>'.&Apache::loncommon::end_data_table_row()
3930: .&Apache::loncommon::end_data_table();
1.237 raeburn 3931: } elsif ($item eq 'registered') {
3932: my ($regon,$regoff);
3933: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
3934: $regon = ' checked="checked" ';
3935: $regoff = ' ';
3936: } else {
3937: $regon = ' ';
3938: $regoff = ' checked="checked" ';
3939: }
3940: $output .= '<label>'.
1.245 raeburn 3941: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 3942: &mt('Yes').'</label> <label>'.
1.245 raeburn 3943: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 3944: &mt('No').'</label>';
1.237 raeburn 3945: } elsif ($item eq 'enroll_dates') {
3946: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
3947: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
3948: if ($starttime eq '') {
3949: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3950: }
3951: if ($endtime eq '') {
3952: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3953: }
3954: my $startform =
3955: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
3956: undef,undef,undef,undef,undef,undef,undef,$nolink);
3957: my $endform =
3958: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
3959: undef,undef,undef,undef,undef,undef,undef,$nolink);
3960: $output .= &selfenroll_date_forms($startform,$endform);
3961: } elsif ($item eq 'access_dates') {
3962: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
3963: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
3964: if ($starttime eq '') {
3965: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3966: }
3967: if ($endtime eq '') {
3968: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3969: }
3970: my $startform =
3971: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
3972: undef,undef,undef,undef,undef,undef,undef,$nolink);
3973: my $endform =
3974: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
3975: undef,undef,undef,undef,undef,undef,undef,$nolink);
3976: $output .= &selfenroll_date_forms($startform,$endform);
3977: } elsif ($item eq 'section') {
3978: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
3979: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3980: my $newsecval;
3981: if ($currsec ne 'none' && $currsec ne '') {
3982: if (!defined($sections_count{$currsec})) {
3983: $newsecval = $currsec;
3984: }
3985: }
3986: my $sections_select =
3987: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
3988: $output .= '<table class="LC_createuser">'."\n".
3989: '<tr class="LC_section_row">'."\n".
3990: '<td align="center">'.&mt('Existing sections')."\n".
3991: '<br />'.$sections_select.'</td><td align="center">'.
3992: &mt('New section').'<br />'."\n".
3993: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
3994: '<input type="hidden" name="sections" value="" />'."\n".
3995: '<input type="hidden" name="state" value="done" />'."\n".
3996: '</td></tr></table>'."\n";
1.276 raeburn 3997: } elsif ($item eq 'approval') {
3998: my ($appon,$appoff);
3999: my $cid = $env{'request.course.id'};
4000: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4001: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4002: $appon = ' checked="checked" ';
4003: $appoff = ' ';
4004: } else {
4005: $appon = ' ';
4006: $appoff = ' checked="checked" ';
4007: }
4008: $output .= '<label>'.
4009: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4010: &mt('Yes').'</label> <label>'.
4011: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4012: &mt('No').'</label>';
4013: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4014: my (@ccs,%notified);
4015: if ($advhash{'cc'}) {
4016: @ccs = split(/,/,$advhash{'cc'});
4017: }
4018: if ($currnotified) {
4019: foreach my $current (split(/,/,$currnotified)) {
4020: $notified{$current} = 1;
4021: if (!grep(/^\Q$current\E$/,@ccs)) {
4022: push(@ccs,$current);
4023: }
4024: }
4025: }
4026: if (@ccs) {
1.277 raeburn 4027: $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 4028: &Apache::loncommon::start_data_table_row();
4029: my $count = 0;
4030: my $numcols = 4;
4031: foreach my $cc (sort(@ccs)) {
4032: my $notifyon;
4033: my ($ccuname,$ccudom) = split(/:/,$cc);
4034: if ($notified{$cc}) {
4035: $notifyon = ' checked="checked" ';
4036: }
4037: if ($count && !$count%$numcols) {
4038: $output .= &Apache::loncommon::end_data_table_row().
4039: &Apache::loncommon::start_data_table_row()
4040: }
4041: $output .= '<td><span class="LC_nobreak"><label>'.
4042: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4043: &Apache::loncommon::plainname($ccuname,$ccudom).
4044: '</label></span></td>';
4045: $count;
4046: }
4047: my $rem = $count%$numcols;
4048: if ($rem) {
4049: my $emptycols = $numcols - $rem;
4050: for (my $i=0; $i<$emptycols; $i++) {
4051: $output .= '<td> </td>';
4052: }
4053: }
4054: $output .= &Apache::loncommon::end_data_table_row().
4055: &Apache::loncommon::end_data_table();
4056: }
4057: } elsif ($item eq 'limit') {
4058: my ($crslimit,$selflimit,$nolimit);
4059: my $cid = $env{'request.course.id'};
4060: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4061: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4062: my $nolimit = ' checked="checked" ';
4063: if ($currlim eq 'allstudents') {
4064: $crslimit = ' checked="checked" ';
4065: $selflimit = ' ';
4066: $nolimit = ' ';
4067: } elsif ($currlim eq 'selfenrolled') {
4068: $crslimit = ' ';
4069: $selflimit = ' checked="checked" ';
4070: $nolimit = ' ';
4071: } else {
4072: $crslimit = ' ';
4073: $selflimit = ' ';
4074: }
4075: $output .= '<table><tr><td><label>'.
1.278 raeburn 4076: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4077: &mt('No limit').'</label></td><td><label>'.
4078: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4079: &mt('Limit by total students').'</label></td><td><label>'.
4080: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4081: &mt('Limit by total self-enrolled students').
4082: '</td></tr><tr>'.
4083: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4084: (' 'x3).&mt('Maximum number allowed: ').
4085: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4086: }
4087: $output .= &Apache::lonhtmlcommon::row_closure(1);
4088: }
4089: }
4090: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4091: '<br /><input type="button" name="selfenrollconf" value="'
1.282 ! schafran 4092: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4093: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4094: $r->print($output);
4095: return;
4096: }
4097:
1.277 raeburn 4098: sub display_selfenroll_queue {
4099: my ($r,$context,$permission,$cnum,$cdom) = @_;
4100: my $namespace = 'selfenrollrequests';
4101: my ($output,%queue_by_date);
4102: my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
4103: if (keys(%requesthash) > 0) {
4104: $r->print('<form method="post" name="changequeue" action="/adm/createuser" />'.
4105: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4106: '<input type="hidden" name="state" value="done" />'.
4107: &Apache::loncommon::start_data_table().
4108: &Apache::loncommon::start_data_table_header_row().
4109: '<th>'.&mt('Action').'</th>'.
4110: '<th>'.&mt('Requestor').'</th>'.
4111: '<th>'.&mt('Section').'</th>'.
4112: '<th>'.&mt('Date requested').'</th>'.
4113: &Apache::loncommon::end_data_table_header_row());
4114: foreach my $item (keys(%requesthash)) {
4115: my ($timestamp,$usec) = split(/:/,$requesthash{$item});
4116: if (exists($queue_by_date{$timestamp})) {
4117: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
4118: push(@{$queue_by_date{$timestamp}},$item.':'.$usec);
4119: }
4120: } else {
4121: @{$queue_by_date{$timestamp}} = ($item.':'.$usec);
4122: }
4123: }
4124: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
4125: my $count = 0;
4126: foreach my $item (@sortedtimes) {
4127: if (ref($queue_by_date{$item}) eq 'ARRAY') {
4128: foreach my $request (sort(@{$queue_by_date{$item}})) {
4129: my ($puname,$pudom,$pusec) = split(/:/,$request);
4130: my $showsec = $pusec;
4131: if ($showsec eq '') {
4132: $showsec = &mt('none');
4133: }
4134: my $namelink = &Apache::loncommon::aboutmewrapper(
4135: &Apache::loncommon::plainname($puname,$pudom),
4136: $puname,$pudom);
4137: $r->print(&Apache::loncommon::start_data_table_row().
4138: '<td><span class="LC_nobreak"><label>'.
4139: '<input type="checkbox" value="'.$count.':'.$puname.':'.$pudom.':'.$pusec.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
4140: '<span class="LC_nobreak"><label>'.
4141: '<input type="checkbox" value="'.$puname.':'.$pudom.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
4142: '<td>'.$namelink.'</td>'.
4143: '<td>'.$showsec.'</td>'.
4144: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
4145: &Apache::loncommon::end_data_table_row());
4146: $count ++;
4147: }
4148: }
4149: }
4150: $r->print(&Apache::loncommon::end_data_table().
4151: '<input type="submit" name="processqueue" value="'.&mt('Save').'" /></form>');
4152: } else {
4153: $r->print(&mt('There are currently no enrollment requests.'));
4154: }
4155: return;
4156: }
4157:
4158: sub update_selfenroll_queue {
4159: my ($r,$context,$permission,$cid,$cnum,$cdom) = @_;
4160: my @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
4161: my @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
4162: my $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
4163: my $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
4164: my $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4165: my $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4166: my $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4167: my $namespace = 'selfenrollrequests';
4168: my ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
4169: my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
4170: my $coursedesc = $env{'course.'.$cid.'.description'};
4171: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
4172: my $hostname = &Apache::lonnet::hostname($chome);
4173: my $protocol = $Apache::lonnet::protocol{$chome};
4174: $protocol = 'http' if ($protocol ne 'https');
1.280 raeburn 4175: my (@existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,
4176: @enrollerrors,@warn_approves,@warn_rejects);
1.277 raeburn 4177: my $now = time;
4178: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
4179: my $approvedmsg = [{
4180: mt => 'Your request for enrollment has been approved.',
4181: },
4182: {
4183: mt => 'Visit [_1], to log-in and access the course',
4184: args => [$protocol.'://'.$hostname],
4185: }];
4186:
4187: my $rejectedmsg = [{
4188: mt => 'Your request for enrollment has not been approved.',
4189: }];
4190: foreach my $item (sort {$a <=> $b} @approvals) {
4191: my ($num,$uname,$udom,$usec) = split(/:/,$item);
4192: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
4193: if ($uhome ne 'no_host') {
4194: if (exists($requesthash{$uname.':'.$udom})) {
4195:
4196: if (exists($classlist->{$uname.':'.$udom})) {
4197: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
4198: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
4199: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
4200: push(@existing,$uname.':'.$udom);
4201: next;
4202: }
4203: }
4204: }
4205: } else {
4206: push(@missingreq,$uname.':'.$udom);
4207: next;
4208: }
4209: if (!grep(/^\Q$item\E$/,@rejections)) {
4210: if ($limit eq 'allstudents') {
4211: if ($stucounts->{$limit} >= $cap) {
4212: push(@limitexceeded,$uname.':'.$udom);
4213: last;
4214: }
4215: } elsif ($limit eq 'selfenrolled') {
4216: if ($stucounts->{$limit} >= $cap) {
4217: push(@limitexceeded,$uname.':'.$udom);
4218: last;
4219: }
4220: }
4221: my $result =
4222: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
4223: if ($result eq 'ok') {
4224: push(@enrolled,$uname.':'.$udom);
4225: $stucounts->{'allstudents'} ++;
4226: $stucounts->{'selfenrolled'} ++;
4227: &Apache::selfenroll::send_notification($uname.':'.$udom,$approvedmsg,$cid,
4228: $coursedesc,$now,'enroller',$sender);
1.280 raeburn 4229: my %userrequest = (
4230: $cdom.'_'.$cnum => {
4231: timestamp => $now,
4232: section => $usec,
4233: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
4234: status => 'approved',
4235: }
4236: );
4237: my $userresult =
4238: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
4239: if ($userresult ne 'ok') {
4240: push(@warn_approves,$uname.':'.$udom);
4241: }
1.277 raeburn 4242: } else {
4243: push(@enrollerrors,$uname.':'.$udom);
4244: }
4245: }
4246: } else {
4247: push(@invalidusers,$uname.':'.$udom);
4248: }
4249: }
4250: my @changes = (@enrolled,@rejections);
4251: if (@rejections) {
4252: foreach my $user (@rejections) {
4253: &Apache::selfenroll::send_notification($user,$rejectedmsg,$cid,
4254: $coursedesc,$now,'enroller',$sender);
1.280 raeburn 4255: my ($uname,$udom) = split(/:/,$user);
4256: my %userrequest = (
4257: $cdom.'_'.$cnum => {
4258: timestamp => $now,
4259: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
4260: status => 'rejected',
4261: }
4262: );
4263: my $userresult =
4264: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
4265: if ($userresult ne 'ok') {
4266: push(@warn_rejects,$user);
4267: }
1.277 raeburn 4268: }
4269: }
4270: if (@changes) {
4271: my $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
4272: if ($delresult eq 'ok') {
4273: my $namelink =
4274: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
4275: my $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
4276: my ($approvedlist,$rejectedlist);
1.279 raeburn 4277: if (@enrolled) {
1.277 raeburn 4278: $approvedlist = join("\n",@enrolled);
4279: $r->print('<p>'.&mt('The following were enrolled in the course:').'<ul>');
4280: foreach my $user (@enrolled) {
4281: my ($uname,$udom) = split(/:/,$user);
4282: my $userlink =
4283: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
4284: $r->print('<li>'.$userlink.'</li>');
4285: }
4286: $r->print('</ul></p>');
4287: }
4288: if (@rejections) {
4289: $rejectedlist = join("\n",@rejections);
4290: $r->print('<p>'.&mt('The following enrollment requests were rejected:').'<ul>');
4291: foreach my $user (@rejections) {
4292: $r->print('<li>'.$user.'</li>');
4293: }
4294: $r->print('</ul></p>');
4295: }
4296: &Apache::selfenroll::send_notification($notifylist,$chgmsg,$cid,
4297: $coursedesc,$now,'managers',
4298: $sender,$approvedlist,$rejectedlist);
4299: }
4300: }
4301: if (@existing) {
4302: $r->print('<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>');
4303: foreach my $user (@existing) {
4304: $r->print('<li>'.$user.'</li>');
4305: }
4306: $r->print('</ul></p>');
4307: }
4308: if (@missingreq) {
4309: $r->print('<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>');
4310: foreach my $user (@missingreq) {
4311: $r->print('<li>'.$user.'</li>');
4312: }
4313: $r->print('</ul></p>');
4314: }
4315: if (@invalidusers) {
4316: $r->print('<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>');
4317: foreach my $user (@invalidusers) {
4318: $r->print('<li>'.$user.'</li>');
4319: }
4320: $r->print('</ul></p>');
4321: }
4322: if (@limitexceeded) {
4323: $r->print('<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>');
4324: foreach my $user (@limitexceeded) {
4325: $r->print('<li>'.$user.'</li>');
4326: }
4327: $r->print('</ul></p>');
4328: }
4329: if (@enrollerrors) {
4330: $r->print('<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>');
4331: foreach my $user (@enrollerrors) {
4332: $r->print('<li>'.$user.'</li>');
4333: }
4334: $r->print('</ul></p>');
4335: }
1.280 raeburn 4336: if (@warn_approves) {
4337: $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
4338: foreach my $user (@warn_approves) {
4339: $r->print('<li>'.$user.'</li>');
4340: }
4341: $r->print('</ul></p>');
4342: }
4343: if (@warn_rejects) {
4344: $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
4345: foreach my $user (@warn_rejects) {
4346: $r->print('<li>'.$user.'</li>');
4347: }
4348: $r->print('</ul></p>');
4349: }
1.277 raeburn 4350: return;
4351: }
4352:
4353: sub get_student_counts {
4354: my ($cdom,$cnum) = @_;
4355: my (%idx,%stucounts);
4356: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
4357: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
4358: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
4359: while (my ($student,$data) = each(%$classlist)) {
4360: if (($data->[$idx{'status'}] eq 'Active') ||
4361: ($data->[$idx{'status'}] eq 'Future')) {
4362: if ($data->[$idx{'type'}] eq 'selfenroll') {
4363: $stucounts{'selfenroll'} ++;
4364: }
4365: $stucounts{'allstudents'} ++;
4366: }
4367: }
4368: return (\%stucounts,\%idx,$classlist);
4369: }
4370:
1.256 raeburn 4371: sub visible_in_cat {
4372: my ($cdom,$cnum) = @_;
4373: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4374: my ($cathash,%settable,@vismsgs,$cansetvis);
4375: my %visactions = &Apache::lonlocal::texthash(
4376: vis => 'Your course currently appears in the Course Catalog for this domain.',
4377: 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.',
4378: miss => 'Your course does not currently appear in the Course Catalog for this domain.',
4379: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4380: 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 4381: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4382: take => 'Take the following action to ensure the course appears in the Catalog:',
4383: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4384: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4385: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4386: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4387: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4388: 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',
4389: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4390: );
1.261 raeburn 4391: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4392: $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>"');
4393: $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 4394: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4395: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4396: $settable{'togglecats'} = 1;
4397: }
4398: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4399: $settable{'categorize'} = 1;
4400: }
4401: $cathash = $domconf{'coursecategories'}{'cats'};
4402: }
1.260 raeburn 4403: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4404: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4405: } elsif ($settable{'togglecats'}) {
4406: $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 4407: } elsif ($settable{'categorize'}) {
1.256 raeburn 4408: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4409: } else {
4410: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4411: }
4412:
4413: my %currsettings =
4414: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4415: $cdom,$cnum);
4416: my $visible = 0;
4417: if ($currsettings{'internal.coursecode'} ne '') {
4418: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4419: $cathash = $domconf{'coursecategories'}{'cats'};
4420: if (ref($cathash) eq 'HASH') {
4421: if ($cathash->{'instcode::0'} eq '') {
4422: push(@vismsgs,'dc_addinst');
4423: } else {
4424: $visible = 1;
4425: }
4426: } else {
4427: $visible = 1;
4428: }
4429: } else {
4430: $visible = 1;
4431: }
4432: } else {
4433: if (ref($cathash) eq 'HASH') {
4434: if ($cathash->{'instcode::0'} ne '') {
4435: push(@vismsgs,'dc_instcode');
4436: }
4437: } else {
4438: push(@vismsgs,'dc_instcode');
4439: }
4440: }
4441: if ($currsettings{'categories'} ne '') {
4442: my $cathash;
4443: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4444: $cathash = $domconf{'coursecategories'}{'cats'};
4445: if (ref($cathash) eq 'HASH') {
4446: if (keys(%{$cathash}) == 0) {
4447: push(@vismsgs,'dc_catalog');
4448: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
4449: push(@vismsgs,'dc_categories');
4450: } else {
4451: my @currcategories = split('&',$currsettings{'categories'});
4452: my $matched = 0;
4453: foreach my $cat (@currcategories) {
4454: if ($cathash->{$cat} ne '') {
4455: $visible = 1;
4456: $matched = 1;
4457: last;
4458: }
4459: }
4460: if (!$matched) {
1.260 raeburn 4461: if ($settable{'categorize'}) {
1.256 raeburn 4462: push(@vismsgs,'chgcat');
4463: } else {
4464: push(@vismsgs,'dc_chgcat');
4465: }
4466: }
4467: }
4468: }
4469: }
4470: } else {
4471: if (ref($cathash) eq 'HASH') {
4472: if ((keys(%{$cathash}) > 1) ||
4473: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 4474: if ($settable{'categorize'}) {
1.256 raeburn 4475: push(@vismsgs,'addcat');
4476: } else {
4477: push(@vismsgs,'dc_addcat');
4478: }
4479: }
4480: }
4481: }
4482: if ($currsettings{'hidefromcat'} eq 'yes') {
4483: $visible = 0;
4484: if ($settable{'togglecats'}) {
4485: unshift(@vismsgs,'unhide');
4486: } else {
4487: unshift(@vismsgs,'dc_unhide')
4488: }
4489: }
4490: return ($visible,$cansetvis,\@vismsgs,\%visactions);
4491: }
4492:
1.241 raeburn 4493: sub new_selfenroll_dom_row {
4494: my ($newdom,$num) = @_;
4495: my $domdesc = &Apache::lonnet::domain($newdom);
4496: my $output;
4497: if ($domdesc ne '') {
4498: $output .= &Apache::loncommon::start_data_table_row()
4499: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
4500: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 4501: .'" value="'.$newdom.'" /></span><br />'
4502: .'<span class="LC_nobreak"><label><input type="checkbox" '
4503: .'name="selfenroll_activate" value="'.$num.'" '
4504: .'onchange="javascript:update_types('
4505: ."'selfenroll_activate','$num'".');" />'
4506: .&mt('Activate').'</label></span></td>';
1.241 raeburn 4507: my @currinsttypes;
4508: $output .= '<td>'.&mt('User types:').'<br />'
4509: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
4510: .&Apache::loncommon::end_data_table_row();
4511: }
4512: return $output;
4513: }
4514:
4515: sub selfenroll_inst_types {
4516: my ($num,$currdom,$currinsttypes) = @_;
4517: my $output;
4518: my $numinrow = 4;
4519: my $count = 0;
4520: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 4521: my $othervalue = 'any';
1.241 raeburn 4522: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 4523: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 4524: $othervalue = 'other';
4525: }
1.241 raeburn 4526: $output .= '<table><tr>';
4527: foreach my $type (@{$types}) {
4528: if (($count > 0) && ($count%$numinrow == 0)) {
4529: $output .= '</tr><tr>';
4530: }
4531: if (defined($usertypes->{$type})) {
1.257 raeburn 4532: my $esc_type = &escape($type);
1.241 raeburn 4533: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 4534: $esc_type.'" ';
1.241 raeburn 4535: if (ref($currinsttypes) eq 'ARRAY') {
4536: if (@{$currinsttypes} > 0) {
1.249 raeburn 4537: if (grep(/^any$/,@{$currinsttypes})) {
4538: $output .= 'checked="checked"';
1.257 raeburn 4539: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 4540: $output .= 'checked="checked"';
4541: }
1.249 raeburn 4542: } else {
4543: $output .= 'checked="checked"';
1.241 raeburn 4544: }
4545: }
4546: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
4547: }
4548: $count ++;
4549: }
4550: if (($count > 0) && ($count%$numinrow == 0)) {
4551: $output .= '</tr><tr>';
4552: }
1.249 raeburn 4553: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 4554: if (ref($currinsttypes) eq 'ARRAY') {
4555: if (@{$currinsttypes} > 0) {
1.249 raeburn 4556: if (grep(/^any$/,@{$currinsttypes})) {
4557: $output .= ' checked="checked"';
4558: } elsif ($othervalue eq 'other') {
4559: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
4560: $output .= ' checked="checked"';
4561: }
1.241 raeburn 4562: }
1.249 raeburn 4563: } else {
4564: $output .= ' checked="checked"';
1.241 raeburn 4565: }
1.249 raeburn 4566: } else {
4567: $output .= ' checked="checked"';
1.241 raeburn 4568: }
4569: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
4570: }
4571: return $output;
4572: }
4573:
1.237 raeburn 4574: sub selfenroll_date_forms {
4575: my ($startform,$endform) = @_;
4576: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 4577: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 4578: 'LC_oddrow_value')."\n".
4579: $startform."\n".
4580: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 4581: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 4582: 'LC_oddrow_value')."\n".
4583: $endform."\n".
4584: &Apache::lonhtmlcommon::row_closure(1).
4585: &Apache::lonhtmlcommon::end_pick_box();
4586: return $output;
4587: }
4588:
1.239 raeburn 4589: sub print_userchangelogs_display {
4590: my ($r,$context,$permission) = @_;
4591: my $formname = 'roleslog';
4592: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4593: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4594: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
4595: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
4596:
4597: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
4598: my %saveable_parameters = ('show' => 'scalar',);
4599: &Apache::loncommon::store_course_settings('roles_log',
4600: \%saveable_parameters);
4601: &Apache::loncommon::restore_course_settings('roles_log',
4602: \%saveable_parameters);
4603: # set defaults
4604: my $now = time();
4605: my $defstart = $now - (7*24*3600); #7 days ago
4606: my %defaults = (
4607: page => '1',
4608: show => '10',
4609: role => 'any',
4610: chgcontext => 'any',
4611: rolelog_start_date => $defstart,
4612: rolelog_end_date => $now,
4613: );
4614: my $more_records = 0;
4615:
4616: # set current
4617: my %curr;
4618: foreach my $item ('show','page','role','chgcontext') {
4619: $curr{$item} = $env{'form.'.$item};
4620: }
4621: my ($startdate,$enddate) =
4622: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
4623: $curr{'rolelog_start_date'} = $startdate;
4624: $curr{'rolelog_end_date'} = $enddate;
4625: foreach my $key (keys(%defaults)) {
4626: if ($curr{$key} eq '') {
4627: $curr{$key} = $defaults{$key};
4628: }
4629: }
1.248 raeburn 4630: my (%whodunit,%changed,$version);
4631: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
4632: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
1.239 raeburn 4633: my $showntablehdr = 0;
4634: my $tablehdr = &Apache::loncommon::start_data_table().
4635: &Apache::loncommon::start_data_table_header_row().
4636: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
4637: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
4638: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
4639: &Apache::loncommon::end_data_table_header_row();
4640: my ($minshown,$maxshown);
1.255 raeburn 4641: $minshown = 1;
1.239 raeburn 4642: my $count = 0;
4643: if ($curr{'show'} ne &mt('all')) {
4644: $maxshown = $curr{'page'} * $curr{'show'};
4645: if ($curr{'page'} > 1) {
4646: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
4647: }
4648: }
4649: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
4650: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
4651: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
4652: if ($curr{'show'} ne &mt('all')) {
4653: if ($count >= $curr{'page'} * $curr{'show'}) {
4654: $more_records = 1;
4655: last;
4656: }
4657: }
4658: if ($curr{'role'} ne 'any') {
4659: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
4660: }
4661: if ($curr{'chgcontext'} ne 'any') {
4662: if ($curr{'chgcontext'} eq 'selfenroll') {
4663: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
4664: } else {
4665: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
4666: }
4667: }
4668: $count ++;
4669: next if ($count < $minshown);
4670: if (!$showntablehdr) {
4671: $r->print($tablehdr);
4672: $showntablehdr = 1;
4673: }
4674: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
4675: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
4676: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
4677: }
4678: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
4679: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
4680: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
4681: }
4682: my $sec = $roleslog{$id}{'logentry'}{'section'};
4683: if ($sec eq '') {
4684: $sec = &mt('None');
4685: }
4686: my ($rolestart,$roleend);
4687: if ($roleslog{$id}{'delflag'}) {
4688: $rolestart = &mt('deleted');
4689: $roleend = &mt('deleted');
4690: } else {
4691: $rolestart = $roleslog{$id}{'logentry'}{'start'};
4692: $roleend = $roleslog{$id}{'logentry'}{'end'};
4693: if ($rolestart eq '' || $rolestart == 0) {
4694: $rolestart = &mt('No start date');
4695: } else {
4696: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
4697: }
4698: if ($roleend eq '' || $roleend == 0) {
4699: $roleend = &mt('No end date');
4700: } else {
4701: $roleend = &Apache::lonlocal::locallocaltime($roleend);
4702: }
4703: }
4704: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
4705: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
4706: $chgcontext = 'selfenroll';
4707: }
4708: my %lt = &rolechg_contexts();
4709: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
4710: $chgcontext = $lt{$chgcontext};
4711: }
4712: $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");
4713: }
4714: if ($showntablehdr) {
4715: $r->print(&Apache::loncommon::end_data_table().'<br />');
4716: if (($curr{'page'} > 1) || ($more_records)) {
4717: $r->print('<table><tr>');
4718: if ($curr{'page'} > 1) {
4719: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
4720: }
4721: if ($more_records) {
4722: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
4723: }
4724: $r->print('</tr></table>');
4725: $r->print(<<"ENDSCRIPT");
4726: <script type="text/javascript">
4727: function chgPage(caller) {
4728: if (caller == 'previous') {
4729: document.$formname.page.value --;
4730: }
4731: if (caller == 'next') {
4732: document.$formname.page.value ++;
4733: }
4734: document.$formname.submit();
4735: return;
4736: }
4737: </script>
4738: ENDSCRIPT
4739: }
4740: } else {
4741: $r->print(&mt('There are no records to display'));
4742: }
4743: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
4744: '<input type="hidden" name="action" value="changelogs" /></form>');
4745: return;
4746: }
4747:
4748: sub role_display_filter {
1.248 raeburn 4749: my ($formname,$cdom,$cnum,$curr,$version) = @_;
1.239 raeburn 4750: my $context = 'course';
4751: my $nolink = 1;
4752: my $output = '<table><tr><td valign="top">'.
4753: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
4754: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
4755: (&mt('all'),5,10,20,50,100,1000,10000)).
4756: '</td><td> </td>';
4757: my $startform =
4758: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
4759: $curr->{'rolelog_start_date'},undef,
4760: undef,undef,undef,undef,undef,undef,$nolink);
4761: my $endform =
4762: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
4763: $curr->{'rolelog_end_date'},undef,
4764: undef,undef,undef,undef,undef,undef,$nolink);
4765: my %lt = &rolechg_contexts();
4766: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
4767: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
4768: $endform.'</td></tr></table></td><td> </td>'.
4769: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
4770: '<select name="role"><option value="any"';
4771: if ($curr->{'role'} eq 'any') {
4772: $output .= ' selected="selected"';
4773: }
4774: $output .= '>'.&mt('Any').'</option>'."\n";
4775: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
4776: foreach my $role (@roles) {
4777: my $plrole;
4778: if ($role eq 'cr') {
4779: $plrole = &mt('Custom Role');
4780: } else {
4781: $plrole=&Apache::lonnet::plaintext($role);
4782: }
4783: my $selstr = '';
4784: if ($role eq $curr->{'role'}) {
4785: $selstr = ' selected="selected"';
4786: }
4787: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
4788: }
4789: $output .= '</select></td><td> </td><td valign="top"><b>'.
4790: &mt('Context:').'</b><br /><select name="chgcontext">';
4791: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
4792: my $selstr = '';
4793: if ($curr->{'chgcontext'} eq $chgtype) {
4794: $output .= $selstr = ' selected="selected"';
4795: }
4796: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
4797: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
4798: }
4799: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 4800: }
1.239 raeburn 4801: $output .= '</select></td><td> </td><td valign="middle"><input type="submit" value="'.
1.248 raeburn 4802: &mt('Update Display').'" /></tr></table>'.
4803: '<span class="LC_roleslog_note">'.
4804: &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
4805: if ($version) {
4806: $output .= ' '.&mt('This server is version [_3].','<b>','</b>',$version); }
4807: $output .= '</span><hr noshade><br />';
1.239 raeburn 4808: return $output;
4809: }
4810:
4811: sub rolechg_contexts {
4812: my %lt = &Apache::lonlocal::texthash (
4813: any => 'Any',
4814: auto => 'Automated enrollment',
4815: updatenow => 'Roster Update',
4816: createcourse => 'Course Creation',
4817: course => 'User Management in course',
4818: domain => 'User Management in domain',
4819: selfenroll => 'Self-enrolled',
4820: );
4821: return %lt;
4822: }
4823:
1.27 matthew 4824: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 4825: sub user_search_result {
1.221 raeburn 4826: my ($context,$srch) = @_;
1.160 raeburn 4827: my %allhomes;
4828: my %inst_matches;
4829: my %srch_results;
1.181 raeburn 4830: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 4831: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 4832: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 4833: $response = &mt('Invalid search.');
4834: }
4835: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
4836: $response = &mt('Invalid search.');
4837: }
1.177 raeburn 4838: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 4839: $response = &mt('Invalid search.');
4840: }
4841: if ($srch->{'srchterm'} eq '') {
4842: $response = &mt('You must enter a search term.');
4843: }
1.183 raeburn 4844: if ($srch->{'srchterm'} =~ /^\s+$/) {
4845: $response = &mt('Your search term must contain more than just spaces.');
4846: }
1.160 raeburn 4847: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
4848: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 4849: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 4850: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
4851: }
4852: }
4853: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
4854: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 4855: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 4856: my $unamecheck = $srch->{'srchterm'};
4857: if ($srch->{'srchtype'} eq 'contains') {
4858: if ($unamecheck !~ /^\w/) {
4859: $unamecheck = 'a'.$unamecheck;
4860: }
4861: }
4862: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 4863: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
4864: }
1.160 raeburn 4865: }
4866: }
1.180 raeburn 4867: if ($response ne '') {
4868: $response = '<span class="LC_warning">'.$response.'</span>';
4869: }
1.160 raeburn 4870: if ($srch->{'srchin'} eq 'instd') {
4871: my $instd_chk = &directorysrch_check($srch);
4872: if ($instd_chk ne 'ok') {
1.180 raeburn 4873: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
4874: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 4875: }
4876: }
4877: if ($response ne '') {
1.180 raeburn 4878: return ($currstate,$response);
1.160 raeburn 4879: }
4880: if ($srch->{'srchby'} eq 'uname') {
4881: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
4882: if ($env{'form.forcenew'}) {
4883: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
4884: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4885: if ($uhome eq 'no_host') {
4886: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 4887: my $showdom = &display_domain_info($env{'request.role.domain'});
4888: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 4889: } else {
1.179 raeburn 4890: $currstate = 'modify';
1.160 raeburn 4891: }
4892: } else {
1.179 raeburn 4893: $currstate = 'modify';
1.160 raeburn 4894: }
4895: } else {
4896: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 4897: if ($srch->{'srchtype'} eq 'exact') {
4898: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4899: if ($uhome eq 'no_host') {
1.179 raeburn 4900: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4901: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4902: } else {
1.179 raeburn 4903: $currstate = 'modify';
1.162 raeburn 4904: }
4905: } else {
4906: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4907: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4908: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4909: }
4910: } else {
1.167 albertel 4911: my $courseusers = &get_courseusers();
1.162 raeburn 4912: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 4913: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 4914: $currstate = 'modify';
1.162 raeburn 4915: } else {
1.179 raeburn 4916: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4917: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4918: }
1.160 raeburn 4919: } else {
1.167 albertel 4920: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 4921: my ($cuname,$cudomain) = split(/:/,$user);
4922: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 4923: my $matched = 0;
4924: if ($srch->{'srchtype'} eq 'begins') {
4925: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
4926: $matched = 1;
4927: }
4928: } else {
4929: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
4930: $matched = 1;
4931: }
4932: }
4933: if ($matched) {
1.167 albertel 4934: $srch_results{$user} =
4935: {&Apache::lonnet::get('environment',
4936: ['firstname',
4937: 'lastname',
1.194 albertel 4938: 'permanentemail'],
4939: $cudomain,$cuname)};
1.162 raeburn 4940: }
4941: }
4942: }
1.179 raeburn 4943: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4944: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4945: }
4946: }
4947: }
4948: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4949: $currstate = 'query';
1.160 raeburn 4950: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4951: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4952: if ($dirsrchres eq 'ok') {
4953: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4954: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4955: } else {
4956: my $showdom = &display_domain_info($srch->{'srchdomain'});
4957: $response = '<span class="LC_warning">'.
4958: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4959: '</span><br />'.
4960: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4961: '<br /><br />';
4962: }
1.160 raeburn 4963: }
4964: } else {
4965: if ($srch->{'srchin'} eq 'dom') {
4966: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4967: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4968: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4969: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 4970: my $courseusers = &get_courseusers();
4971: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 4972: my ($uname,$udom) = split(/:/,$user);
4973: my %names = &Apache::loncommon::getnames($uname,$udom);
4974: my %emails = &Apache::loncommon::getemails($uname,$udom);
4975: if ($srch->{'srchby'} eq 'lastname') {
4976: if ((($srch->{'srchtype'} eq 'exact') &&
4977: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 4978: (($srch->{'srchtype'} eq 'begins') &&
4979: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 4980: (($srch->{'srchtype'} eq 'contains') &&
4981: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
4982: $srch_results{$user} = {firstname => $names{'firstname'},
4983: lastname => $names{'lastname'},
4984: permanentemail => $emails{'permanentemail'},
4985: };
4986: }
4987: } elsif ($srch->{'srchby'} eq 'lastfirst') {
4988: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 4989: $srchlast =~ s/\s+$//;
4990: $srchfirst =~ s/^\s+//;
1.160 raeburn 4991: if ($srch->{'srchtype'} eq 'exact') {
4992: if (($names{'lastname'} eq $srchlast) &&
4993: ($names{'firstname'} eq $srchfirst)) {
4994: $srch_results{$user} = {firstname => $names{'firstname'},
4995: lastname => $names{'lastname'},
4996: permanentemail => $emails{'permanentemail'},
4997:
4998: };
4999: }
1.177 raeburn 5000: } elsif ($srch->{'srchtype'} eq 'begins') {
5001: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5002: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5003: $srch_results{$user} = {firstname => $names{'firstname'},
5004: lastname => $names{'lastname'},
5005: permanentemail => $emails{'permanentemail'},
5006: };
5007: }
5008: } else {
1.160 raeburn 5009: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5010: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5011: $srch_results{$user} = {firstname => $names{'firstname'},
5012: lastname => $names{'lastname'},
5013: permanentemail => $emails{'permanentemail'},
5014: };
5015: }
5016: }
5017: }
5018: }
1.179 raeburn 5019: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5020: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5021: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5022: $currstate = 'query';
1.160 raeburn 5023: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5024: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5025: if ($dirsrchres eq 'ok') {
5026: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5027: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5028: } else {
5029: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5030: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5031: '</span><br />'.
5032: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5033: '<br /><br />';
5034: }
1.160 raeburn 5035: }
5036: }
1.179 raeburn 5037: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5038: }
5039:
5040: sub directorysrch_check {
5041: my ($srch) = @_;
5042: my $can_search = 0;
5043: my $response;
5044: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5045: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5046: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5047: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5048: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5049: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5050: }
5051: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5052: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5053: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5054: }
5055: my @usertypes = split(/:/,$env{'environment.inststatus'});
5056: if (!@usertypes) {
5057: push(@usertypes,'default');
5058: }
5059: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5060: foreach my $type (@usertypes) {
5061: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5062: $can_search = 1;
5063: last;
5064: }
5065: }
5066: }
5067: if (!$can_search) {
5068: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5069: my @longtypes;
5070: foreach my $item (@usertypes) {
1.229 raeburn 5071: if (defined($insttypes->{$item})) {
5072: push (@longtypes,$insttypes->{$item});
5073: } elsif ($item eq 'default') {
5074: push (@longtypes,&mt('other'));
5075: }
1.160 raeburn 5076: }
5077: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5078: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5079: }
1.160 raeburn 5080: } else {
5081: $can_search = 1;
5082: }
5083: } else {
1.180 raeburn 5084: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5085: }
5086: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5087: uname => 'username',
1.160 raeburn 5088: lastfirst => 'last name, first name',
1.167 albertel 5089: lastname => 'last name',
1.172 raeburn 5090: contains => 'contains',
1.178 raeburn 5091: exact => 'as exact match to',
5092: begins => 'begins with',
1.160 raeburn 5093: );
5094: if ($can_search) {
5095: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5096: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5097: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5098: }
5099: } else {
1.180 raeburn 5100: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5101: }
5102: }
5103: if ($can_search) {
1.178 raeburn 5104: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5105: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5106: return 'ok';
5107: } else {
1.180 raeburn 5108: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5109: }
5110: } else {
5111: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5112: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5113: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5114: return 'ok';
5115: } else {
1.180 raeburn 5116: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5117: }
1.160 raeburn 5118: }
5119: }
5120: }
5121:
5122: sub get_courseusers {
5123: my %advhash;
1.167 albertel 5124: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5125: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5126: foreach my $role (sort(keys(%coursepersonnel))) {
5127: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5128: if (!exists($classlist->{$user})) {
5129: $classlist->{$user} = [];
5130: }
1.160 raeburn 5131: }
5132: }
1.167 albertel 5133: return $classlist;
1.160 raeburn 5134: }
5135:
5136: sub build_search_response {
1.221 raeburn 5137: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5138: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5139: my %names = (
5140: 'uname' => 'username',
5141: 'lastname' => 'last name',
5142: 'lastfirst' => 'last name, first name',
5143: 'crs' => 'this course',
1.180 raeburn 5144: 'dom' => 'LON-CAPA domain: ',
5145: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5146: );
5147:
5148: my %single = (
1.180 raeburn 5149: begins => 'A match',
1.160 raeburn 5150: contains => 'A match',
1.180 raeburn 5151: exact => 'An exact match',
1.160 raeburn 5152: );
5153: my %nomatch = (
1.180 raeburn 5154: begins => 'No match',
1.160 raeburn 5155: contains => 'No match',
1.180 raeburn 5156: exact => 'No exact match',
1.160 raeburn 5157: );
5158: if (keys(%srch_results) > 1) {
1.179 raeburn 5159: $currstate = 'select';
1.160 raeburn 5160: } else {
5161: if (keys(%srch_results) == 1) {
1.179 raeburn 5162: $currstate = 'modify';
1.180 raeburn 5163: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5164: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5165: $response .= &display_domain_info($srch->{'srchdomain'});
5166: }
1.160 raeburn 5167: } else {
1.180 raeburn 5168: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
5169: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5170: $response .= &display_domain_info($srch->{'srchdomain'});
5171: }
5172: $response .= '</span>';
1.160 raeburn 5173: if ($srch->{'srchin'} ne 'alc') {
5174: $forcenewuser = 1;
5175: my $cansrchinst = 0;
5176: if ($srch->{'srchdomain'}) {
5177: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5178: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5179: if ($domconfig{'directorysrch'}{'available'}) {
5180: $cansrchinst = 1;
5181: }
5182: }
5183: }
1.180 raeburn 5184: if ((($srch->{'srchby'} eq 'lastfirst') ||
5185: ($srch->{'srchby'} eq 'lastname')) &&
5186: ($srch->{'srchin'} eq 'dom')) {
5187: if ($cansrchinst) {
5188: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5189: }
5190: }
1.180 raeburn 5191: if ($srch->{'srchin'} eq 'crs') {
5192: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5193: }
5194: }
5195: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 5196: my $cancreate =
5197: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
5198: if ($cancreate) {
5199: my $showdom = &display_domain_info($env{'request.role.domain'});
1.266 bisitz 5200: $response .= '<br /><br />'
5201: .'<b>'.&mt('To add a new user:').'</b>'
5202: .'<br />'
5203: .&mt("(You can only create new users in your current role's domain - [_1])"
5204: ,'<span class="LC_cusr_emph">'.$env{'request.role.domain'}.'</span>')
5205: .'<ul><li>'
5206: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5207: .'</li><li>'
5208: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5209: .'</li><li>'
5210: .&mt('Provide the proposed username')
5211: .'</li><li>'
5212: .&mt("Click 'Search'")
5213: .'</li></ul><br />';
1.221 raeburn 5214: } else {
5215: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.266 bisitz 5216: $response .= '<br /><br />'
5217: .&mt("You are not authorized to create new users in your current role's domain - [_1]."
5218: ,'<span class="LC_cusr_emph">'.$env{'request.role.domain'}.'</span>')
5219: .'<br />'
5220: .&mt('Contact the [_1]helpdesk[_2] if you need to create a new user.'
5221: ,' <a'.$helplink.'>'
5222: ,'</a>')
5223: .'<br /><br />';
1.221 raeburn 5224: }
1.160 raeburn 5225: }
5226: }
5227: }
1.179 raeburn 5228: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5229: }
5230:
1.180 raeburn 5231: sub display_domain_info {
5232: my ($dom) = @_;
5233: my $output = $dom;
5234: if ($dom ne '') {
5235: my $domdesc = &Apache::lonnet::domain($dom,'description');
5236: if ($domdesc ne '') {
5237: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5238: }
5239: }
5240: return $output;
5241: }
5242:
1.160 raeburn 5243: sub crumb_utilities {
5244: my %elements = (
5245: crtuser => {
5246: srchterm => 'text',
1.172 raeburn 5247: srchin => 'selectbox',
1.160 raeburn 5248: srchby => 'selectbox',
5249: srchtype => 'selectbox',
5250: srchdomain => 'selectbox',
5251: },
1.207 raeburn 5252: crtusername => {
5253: srchterm => 'text',
5254: srchdomain => 'selectbox',
5255: },
1.160 raeburn 5256: docustom => {
5257: rolename => 'selectbox',
5258: newrolename => 'textbox',
5259: },
1.179 raeburn 5260: studentform => {
5261: srchterm => 'text',
5262: srchin => 'selectbox',
5263: srchby => 'selectbox',
5264: srchtype => 'selectbox',
5265: srchdomain => 'selectbox',
5266: },
1.160 raeburn 5267: );
5268:
5269: my $jsback .= qq|
5270: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5271: if (typeof prevphase == 'undefined') {
5272: formname.phase.value = '';
5273: }
5274: else {
5275: formname.phase.value = prevphase;
5276: }
5277: if (typeof prevstate == 'undefined') {
5278: formname.currstate.value = '';
5279: }
5280: else {
5281: formname.currstate.value = prevstate;
5282: }
1.160 raeburn 5283: formname.submit();
5284: }
5285: |;
5286: return ($jsback,\%elements);
5287: }
5288:
1.26 matthew 5289: sub course_level_table {
1.89 raeburn 5290: my (%inccourses) = @_;
1.26 matthew 5291: my $table = '';
1.62 www 5292: # Custom Roles?
5293:
1.190 raeburn 5294: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5295: my %lt=&Apache::lonlocal::texthash(
5296: 'exs' => "Existing sections",
5297: 'new' => "Define new section",
5298: 'ssd' => "Set Start Date",
5299: 'sed' => "Set End Date",
1.131 raeburn 5300: 'crl' => "Course Level",
1.89 raeburn 5301: 'act' => "Activate",
5302: 'rol' => "Role",
5303: 'ext' => "Extent",
1.113 raeburn 5304: 'grs' => "Section",
1.89 raeburn 5305: 'sta' => "Start",
5306: 'end' => "End"
5307: );
1.62 www 5308:
1.135 raeburn 5309: foreach my $protectedcourse (sort( keys(%inccourses))) {
5310: my $thiscourse=$protectedcourse;
1.26 matthew 5311: $thiscourse=~s:_:/:g;
5312: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
5313: my $area=$coursedata{'description'};
1.119 raeburn 5314: my $type=$coursedata{'type'};
1.135 raeburn 5315: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5316: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5317: my %sections_count;
1.101 albertel 5318: if (defined($env{'request.course.id'})) {
5319: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5320: %sections_count =
5321: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5322: }
5323: }
1.213 raeburn 5324: my @roles = &Apache::lonuserutils::roles_by_context('course');
5325: foreach my $role (@roles) {
1.221 raeburn 5326: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 5327: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 5328: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5329: $plrole,\%sections_count,\%lt);
5330: } elsif ($env{'request.course.sec'} ne '') {
5331: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5332: $env{'request.course.sec'})) {
5333: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5334: $plrole,\%sections_count,\%lt);
1.26 matthew 5335: }
5336: }
5337: }
1.221 raeburn 5338: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
5339: foreach my $cust (sort keys %customroles) {
5340: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5341: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5342: $cust,\%sections_count,\%lt);
5343: }
1.62 www 5344: }
1.26 matthew 5345: }
5346: return '' if ($table eq ''); # return nothing if there is nothing
5347: # in the table
1.188 raeburn 5348: my $result;
5349: if (!$env{'request.course.id'}) {
5350: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5351: }
5352: $result .=
1.136 raeburn 5353: &Apache::loncommon::start_data_table().
5354: &Apache::loncommon::start_data_table_header_row().
5355: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5356: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5357: &Apache::loncommon::end_data_table_header_row().
5358: $table.
5359: &Apache::loncommon::end_data_table();
1.26 matthew 5360: return $result;
5361: }
1.88 raeburn 5362:
1.221 raeburn 5363: sub course_level_row {
5364: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5365: my $row = &Apache::loncommon::start_data_table_row().
5366: ' <td><input type="checkbox" name="act_'.
5367: $protectedcourse.'_'.$role.'" /></td>'."\n".
5368: ' <td>'.$plrole.'</td>'."\n".
5369: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 5370: if ($role eq 'cc') {
1.222 raeburn 5371: $row .= '<td> </td>';
1.221 raeburn 5372: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5373: $row .= ' <td><input type="hidden" value="'.
5374: $env{'request.course.sec'}.'" '.
5375: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5376: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5377: } else {
5378: if (ref($sections_count) eq 'HASH') {
5379: my $currsec =
5380: &Apache::lonuserutils::course_sections($sections_count,
5381: $protectedcourse.'_'.$role);
1.222 raeburn 5382: $row .= '<td><table class="LC_createuser">'."\n".
5383: '<tr class="LC_section_row">'."\n".
5384: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
5385: $currsec.'</td>'."\n".
5386: ' <td> </td>'."\n".
5387: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 5388: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
5389: '" value="" />'.
5390: '<input type="hidden" '.
5391: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 5392: '</tr></table></td>'."\n";
1.221 raeburn 5393: } else {
1.222 raeburn 5394: $row .= '<td><input type="text" size="10" '.
5395: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 5396: }
5397: }
1.222 raeburn 5398: $row .= <<ENDTIMEENTRY;
5399: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 5400: <a href=
5401: "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 5402: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 5403: <a href=
5404: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
5405: ENDTIMEENTRY
1.222 raeburn 5406: $row .= &Apache::loncommon::end_data_table_row();
5407: return $row;
1.221 raeburn 5408: }
5409:
1.88 raeburn 5410: sub course_level_dc {
5411: my ($dcdom) = @_;
1.190 raeburn 5412: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 5413: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 5414: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
5415: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 5416: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 5417: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 5418: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
5419: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 5420: my %lt=&Apache::lonlocal::texthash(
5421: 'rol' => "Role",
1.113 raeburn 5422: 'grs' => "Section",
1.88 raeburn 5423: 'exs' => "Existing sections",
5424: 'new' => "Define new section",
5425: 'sta' => "Start",
5426: 'end' => "End",
5427: 'ssd' => "Set Start Date",
5428: 'sed' => "Set End Date"
5429: );
1.131 raeburn 5430: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 5431: &Apache::loncommon::start_data_table().
5432: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 5433: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 5434: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 5435: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 5436: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 5437: '<td><select name="role">'."\n";
1.213 raeburn 5438: foreach my $role (@roles) {
1.135 raeburn 5439: my $plrole=&Apache::lonnet::plaintext($role);
5440: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 5441: }
5442: if ( keys %customroles > 0) {
1.135 raeburn 5443: foreach my $cust (sort keys %customroles) {
1.101 albertel 5444: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 5445: '_'.$env{'user.name'}.'_'.$cust;
5446: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 5447: }
5448: }
5449: $otheritems .= '</select></td><td>'.
5450: '<table border="0" cellspacing="0" cellpadding="0">'.
5451: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
5452: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
5453: '<td> </td>'.
5454: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 5455: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 5456: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 5457: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 5458: '</tr></table></td>';
5459: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 5460: <td><input type="hidden" name="start" value='' />
1.88 raeburn 5461: <a href=
5462: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 5463: <td><input type="hidden" name="end" value='' />
1.88 raeburn 5464: <a href=
5465: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
5466: ENDTIMEENTRY
1.136 raeburn 5467: $otheritems .= &Apache::loncommon::end_data_table_row().
5468: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 5469: return $cb_jscript.$header.$hiddenitems.$otheritems;
5470: }
5471:
1.237 raeburn 5472: sub update_selfenroll_config {
1.241 raeburn 5473: my ($r,$context,$permission) = @_;
1.237 raeburn 5474: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 5475: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 5476: my (%changes,%warning);
5477: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5478: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 5479: my $curr_types;
1.237 raeburn 5480: if (ref($row) eq 'ARRAY') {
5481: foreach my $item (@{$row}) {
5482: if ($item eq 'enroll_dates') {
5483: my (%currenrolldate,%newenrolldate);
5484: foreach my $type ('start','end') {
5485: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
5486: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
5487: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
5488: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
5489: }
5490: }
5491: } elsif ($item eq 'access_dates') {
5492: my (%currdate,%newdate);
5493: foreach my $type ('start','end') {
5494: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
5495: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
5496: if ($newdate{$type} ne $currdate{$type}) {
5497: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
5498: }
5499: }
1.241 raeburn 5500: } elsif ($item eq 'types') {
5501: $curr_types =
5502: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5503: if ($env{'form.selfenroll_all'}) {
5504: if ($curr_types ne '*') {
5505: $changes{'internal.selfenroll_types'} = '*';
5506: } else {
5507: next;
5508: }
5509: } else {
1.249 raeburn 5510: my %currdoms;
1.241 raeburn 5511: my @entries = split(/;/,$curr_types);
5512: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 5513: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 5514: my $newnum = 0;
1.249 raeburn 5515: my @latesttypes;
5516: foreach my $num (@activations) {
5517: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
5518: if (@types > 0) {
1.241 raeburn 5519: @types = sort(@types);
5520: my $typestr = join(',',@types);
1.249 raeburn 5521: my $typedom = $env{'form.selfenroll_dom_'.$num};
5522: $latesttypes[$newnum] = $typedom.':'.$typestr;
5523: $currdoms{$typedom} = 1;
1.241 raeburn 5524: $newnum ++;
5525: }
5526: }
1.249 raeburn 5527: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
5528: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
5529: if (@types > 0) {
5530: @types = sort(@types);
5531: my $typestr = join(',',@types);
5532: my $typedom = $env{'form.selfenroll_dom_'.$j};
5533: $latesttypes[$newnum] = $typedom.':'.$typestr;
5534: $currdoms{$typedom} = 1;
5535: $newnum ++;
5536: }
5537: }
5538: }
5539: if ($env{'form.selfenroll_newdom'} ne '') {
5540: my $typedom = $env{'form.selfenroll_newdom'};
5541: if ((!defined($currdoms{$typedom})) &&
5542: (&Apache::lonnet::domain($typedom) ne '')) {
5543: my $typestr;
5544: my ($othertitle,$usertypes,$types) =
5545: &Apache::loncommon::sorted_inst_types($typedom);
5546: my $othervalue = 'any';
5547: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5548: if (@{$types} > 0) {
1.257 raeburn 5549: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 5550: $othervalue = 'other';
1.258 raeburn 5551: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 5552: }
5553: $typestr = $othervalue;
5554: } else {
5555: $typestr = $othervalue;
5556: }
5557: $latesttypes[$newnum] = $typedom.':'.$typestr;
5558: $newnum ++ ;
5559: }
5560: }
1.241 raeburn 5561: my $selfenroll_types = join(';',@latesttypes);
5562: if ($selfenroll_types ne $curr_types) {
5563: $changes{'internal.selfenroll_types'} = $selfenroll_types;
5564: }
5565: }
1.276 raeburn 5566: } elsif ($item eq 'limit') {
5567: my $newlimit = $env{'form.selfenroll_limit'};
5568: my $newcap = $env{'form.selfenroll_cap'};
5569: $newcap =~s/\s+//g;
5570: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
5571: $currlimit = 'none' if ($currlimit eq '');
5572: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
5573: if ($newlimit ne $currlimit) {
5574: if ($newlimit ne 'none') {
5575: if ($newcap =~ /^\d+$/) {
5576: if ($newcap ne $currcap) {
5577: $changes{'internal.selfenroll_cap'} = $newcap;
5578: }
5579: $changes{'internal.selfenroll_limit'} = $newlimit;
5580: } else {
5581: $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.');
5582: }
5583: } elsif ($currcap ne '') {
5584: $changes{'internal.selfenroll_cap'} = '';
5585: $changes{'internal.selfenroll_limit'} = $newlimit;
5586: }
5587: } elsif ($currlimit ne 'none') {
5588: if ($newcap =~ /^\d+$/) {
5589: if ($newcap ne $currcap) {
5590: $changes{'internal.selfenroll_cap'} = $newcap;
5591: }
5592: } else {
5593: $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.');
5594: }
5595: }
5596: } elsif ($item eq 'approval') {
5597: my (@currnotified,@newnotified);
5598: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
5599: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
5600: if ($currnotifylist ne '') {
5601: @currnotified = split(/,/,$currnotifylist);
5602: @currnotified = sort(@currnotified);
5603: }
5604: my $newapproval = $env{'form.selfenroll_approval'};
5605: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
5606: @newnotified = sort(@newnotified);
5607: if ($newapproval ne $currapproval) {
5608: $changes{'internal.selfenroll_approval'} = $newapproval;
5609: if (!$newapproval) {
5610: if ($currnotifylist ne '') {
5611: $changes{'internal.selfenroll_notifylist'} = '';
5612: }
5613: } else {
5614: my @differences =
5615: &compare_arrays(\@currnotified,\@newnotified);
5616: if (@differences > 0) {
5617: if (@newnotified > 0) {
5618: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
5619: } else {
5620: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
5621: }
5622: }
5623: }
5624: } else {
5625: my @differences = &compare_arrays(\@currnotified,\@newnotified);
5626: if (@differences > 0) {
5627: if (@newnotified > 0) {
5628: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
5629: } else {
5630: $changes{'internal.selfenroll_notifylist'} = '';
5631: }
5632: }
5633: }
1.237 raeburn 5634: } else {
5635: my $curr_val =
5636: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5637: my $newval = $env{'form.selfenroll_'.$item};
5638: if ($item eq 'section') {
5639: $newval = $env{'form.sections'};
1.241 raeburn 5640: if (defined($curr_groups{$newval})) {
1.237 raeburn 5641: $newval = $curr_val;
5642: $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');
5643: } elsif ($newval eq 'all') {
5644: $newval = $curr_val;
1.274 bisitz 5645: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 5646: }
5647: if ($newval eq '') {
5648: $newval = 'none';
5649: }
5650: }
5651: if ($newval ne $curr_val) {
5652: $changes{'internal.selfenroll_'.$item} = $newval;
5653: }
1.241 raeburn 5654: }
1.237 raeburn 5655: }
5656: if (keys(%warning) > 0) {
5657: foreach my $item (@{$row}) {
5658: if (exists($warning{$item})) {
5659: $r->print($warning{$item}.'<br />');
5660: }
5661: }
5662: }
5663: if (keys(%changes) > 0) {
5664: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
5665: if ($putresult eq 'ok') {
5666: if ((exists($changes{'internal.selfenroll_types'})) ||
5667: (exists($changes{'internal.selfenroll_start_date'})) ||
5668: (exists($changes{'internal.selfenroll_end_date'}))) {
5669: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
5670: $cnum,undef,undef,'Course');
5671: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
5672: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
5673: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
5674: if (exists($changes{'internal.'.$item})) {
5675: $crsinfo{$env{'request.course.id'}}{$item} =
5676: $changes{'internal.'.$item};
5677: }
5678: }
5679: my $crsputresult =
5680: &Apache::lonnet::courseidput($cdom,\%crsinfo,
5681: $chome,'notime');
5682: }
5683: }
5684: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
5685: foreach my $item (@{$row}) {
5686: my $title = $item;
5687: if (ref($lt) eq 'HASH') {
5688: $title = $lt->{$item};
5689: }
5690: if ($item eq 'enroll_dates') {
5691: foreach my $type ('start','end') {
5692: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
5693: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 5694: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 5695: $title,$type,$newdate).'</li>');
5696: }
5697: }
5698: } elsif ($item eq 'access_dates') {
5699: foreach my $type ('start','end') {
5700: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
5701: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 5702: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 5703: $title,$type,$newdate).'</li>');
5704: }
5705: }
1.276 raeburn 5706: } elsif ($item eq 'limit') {
5707: if ((exists($changes{'internal.selfenroll_limit'})) ||
5708: (exists($changes{'internal.selfenroll_cap'}))) {
5709: my ($newval,$newcap);
5710: if ($changes{'internal.selfenroll_cap'} ne '') {
5711: $newcap = $changes{'internal.selfenroll_cap'}
5712: } else {
5713: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
5714: }
5715: if ($changes{'internal.selfenroll_limit'} eq 'none') {
5716: $newval = &mt('No limit');
5717: } elsif ($changes{'internal.selfenroll_limit'} eq
5718: 'allstudents') {
5719: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
5720: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
5721: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
5722: } else {
5723: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
5724: if ($currlimit eq 'allstudents') {
5725: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
5726: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
5727: $newval = &mt('New self-enrollment no longer allowed when total umber of self-enrolled students reaches [_1].',$newcap);
5728: }
5729: }
5730: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
5731: }
5732: } elsif ($item eq 'approval') {
5733: if ((exists($changes{'internal.selfenroll_approval'})) ||
5734: (exists($changes{'internal.selfenroll_notifylist'}))) {
5735: my ($newval,$newnotify);
5736: if (exists($changes{'internal.selfenroll_notifylist'})) {
5737: $newnotify = $changes{'internal.selfenroll_notifylist'};
5738: } else {
5739: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
5740: }
5741: if ($changes{'internal.selfenroll_approval'}) {
5742: $newval = &mt('Yes');
5743: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
5744: $newval = &mt('No');
5745: } else {
5746: my $currapproval =
5747: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
5748: if ($currapproval) {
5749: $newval = &mt('Yes');
5750: } else {
5751: $newval = &mt('No');
5752: }
5753: }
5754: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
5755: if ($newnotify) {
1.277 raeburn 5756: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 5757: } else {
1.277 raeburn 5758: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 5759: }
5760: $r->print('</li>'."\n");
5761: }
1.237 raeburn 5762: } else {
5763: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 5764: my $newval = $changes{'internal.selfenroll_'.$item};
5765: if ($item eq 'types') {
5766: if ($newval eq '') {
5767: $newval = &mt('None');
5768: } elsif ($newval eq '*') {
5769: $newval = &mt('Any user in any domain');
5770: }
1.245 raeburn 5771: } elsif ($item eq 'registered') {
5772: if ($newval eq '1') {
5773: $newval = &mt('Yes');
5774: } elsif ($newval eq '0') {
5775: $newval = &mt('No');
5776: }
1.241 raeburn 5777: }
1.244 bisitz 5778: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 5779: }
5780: }
5781: }
5782: $r->print('</ul>');
5783: my %newenvhash;
5784: foreach my $key (keys(%changes)) {
5785: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
5786: }
1.238 raeburn 5787: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 5788: } else {
5789: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
5790: }
5791: } else {
1.249 raeburn 5792: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 5793: }
5794: } else {
1.249 raeburn 5795: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 5796: }
1.256 raeburn 5797: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5798: if (ref($visactions) eq 'HASH') {
5799: if (!$visible) {
5800: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
5801: '<br />');
5802: if (ref($vismsgs) eq 'ARRAY') {
5803: $r->print('<br />'.$visactions->{'take'}.'<ul>');
5804: foreach my $item (@{$vismsgs}) {
5805: $r->print('<li>'.$visactions->{$item}.'</li>');
5806: }
5807: $r->print('</ul>');
5808: }
5809: $r->print($cansetvis);
5810: }
5811: }
1.237 raeburn 5812: return;
5813: }
5814:
1.276 raeburn 5815: sub compare_arrays {
5816: my ($arrayref1,$arrayref2) = @_;
5817: my (@difference,%count);
5818: @difference = ();
5819: %count = ();
5820: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
5821: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
5822: foreach my $element (keys(%count)) {
5823: if ($count{$element} == 1) {
5824: push(@difference,$element);
5825: }
5826: }
5827: }
5828: return @difference;
5829: }
5830:
1.237 raeburn 5831: sub get_selfenroll_titles {
1.276 raeburn 5832: my @row = ('types','registered','enroll_dates','access_dates','section',
5833: 'approval','limit');
1.237 raeburn 5834: my %lt = &Apache::lonlocal::texthash (
5835: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 5836: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 5837: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 5838: access_dates => 'Course access dates assigned to self-enrolling users',
5839: section => 'Section assigned to self-enrolling users',
1.276 raeburn 5840: approval => 'Self-enrollment requests need approval?',
5841: limit => 'Enrollment limit',
1.237 raeburn 5842: );
5843: return (\@row,\%lt);
5844: }
5845:
1.27 matthew 5846: #---------------------------------------------- end functions for &phase_two
1.29 matthew 5847:
5848: #--------------------------------- functions for &phase_two and &phase_three
5849:
5850: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 5851:
5852: 1;
5853: __END__
1.2 www 5854:
5855:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>