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