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