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