Annotation of loncom/interface/loncreateuser.pm, revision 1.297
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.297 ! bisitz 4: # $Id: loncreateuser.pm,v 1.296 2009/06/30 14:02:33 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.293 bisitz 2103: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2104: .'<br />'
2105: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2106: .'<br />'."\n";
1.203 raeburn 2107: }
2108: }
2109: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2110: my $checkhash;
2111: my $checks = { 'id' => 1 };
2112: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2113: { 'newuser' => $newuser,
2114: 'id' => $env{'form.cid'},
2115: };
2116: &Apache::loncommon::user_rule_check($checkhash,$checks,
2117: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2118: if (ref($alerts{'id'}) eq 'HASH') {
2119: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2120: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2121: }
2122: }
2123: }
1.286 raeburn 2124: my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
2125: $inststatus,$newinststatus,$oldisdefault,$newisdefault,$olddefquotatext,
2126: $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext,
2127: $oldinststatuses,$newinststatuses);
1.149 raeburn 2128: my ($defquota,$settingstatus) =
2129: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.286 raeburn 2130: my ($showquota,$showtools,$showrequestcourses,$showinststatus);
1.220 raeburn 2131: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2132: $showquota = 1;
2133: }
1.267 raeburn 2134: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
2135: $showtools = 1;
2136: }
1.275 raeburn 2137: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
2138: $showrequestcourses = 1;
2139: }
1.286 raeburn 2140: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
2141: $showinststatus = 1;
2142: }
1.267 raeburn 2143: my (%changeHash,%changed);
1.286 raeburn 2144: $oldinststatus = $userenv{'inststatus'};
2145: if ($oldinststatus eq '') {
2146: $oldinststatuses = $othertitle;
2147: } else {
2148: if (ref($usertypes) eq 'HASH') {
2149: $oldinststatuses = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
2150: } else {
2151: $oldinststatuses = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
2152: }
2153: }
2154: $changeHash{'inststatus'} = $userenv{'inststatus'};
2155: my %canmodify_inststatus = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},['inststatus'],\@userroles);
2156: if ($canmodify_inststatus{'inststatus'}) {
2157: if (exists($env{'form.inststatus'})) {
2158: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2159: if (@inststatuses > 0) {
2160: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2161: $changeHash{'inststatus'} = $newinststatus;
2162: if ($newinststatus ne $oldinststatus) {
2163: $changed{'inststatus'} = $newinststatus;
2164: }
2165: if (ref($usertypes) eq 'HASH') {
2166: $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
2167: } else {
2168: $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
2169: }
2170: } else {
2171: $newinststatus = '';
2172: $changeHash{'inststatus'} = $newinststatus;
2173: $newinststatuses = $othertitle;
2174: if ($newinststatus ne $oldinststatus) {
2175: $changed{'inststatus'} = $changeHash{'inststatus'};
2176: }
2177: }
2178: }
2179: }
1.204 raeburn 2180: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 2181: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 2182: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 2183: if ($env{'form.customquota'} == 1) {
2184: if ($env{'form.portfolioquota'} eq '') {
2185: $newportfolioquota = 0;
2186: } else {
2187: $newportfolioquota = $env{'form.portfolioquota'};
2188: $newportfolioquota =~ s/[^\d\.]//g;
2189: }
1.204 raeburn 2190: if ($newportfolioquota != $oldportfolioquota) {
1.267 raeburn 2191: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 2192: }
1.149 raeburn 2193: } else {
1.267 raeburn 2194: $changed{'quota'} = "a_admin('',\%changeHash);
1.149 raeburn 2195: $newportfolioquota = $defquota;
1.284 bisitz 2196: $newisdefault = 1;
1.134 raeburn 2197: }
2198: } else {
1.204 raeburn 2199: $oldisdefault = 1;
1.149 raeburn 2200: $oldportfolioquota = $defquota;
2201: if ($env{'form.customquota'} == 1) {
2202: if ($env{'form.portfolioquota'} eq '') {
2203: $newportfolioquota = 0;
2204: } else {
2205: $newportfolioquota = $env{'form.portfolioquota'};
2206: $newportfolioquota =~ s/[^\d\.]//g;
2207: }
1.267 raeburn 2208: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.149 raeburn 2209: } else {
2210: $newportfolioquota = $defquota;
1.204 raeburn 2211: $newisdefault = 1;
1.149 raeburn 2212: }
2213: }
1.204 raeburn 2214: if ($oldisdefault) {
2215: $olddefquotatext = &get_defaultquota_text($settingstatus);
2216: }
2217: if ($newisdefault) {
2218: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 2219: }
1.275 raeburn 2220: &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv,
2221: \%changeHash,\%changed,\%newaccess,\%newaccesstext);
1.279 raeburn 2222: &tool_changes('requestcourses',\@requestcourses,\%oldaccess,\%oldaccesstext,
1.275 raeburn 2223: \%userenv, \%changeHash,\%changed,\%newaccess,\%newaccesstext);
1.206 raeburn 2224: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
2225: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
2226: $env{'form.clastname'} ne $userenv{'lastname'} ||
2227: $env{'form.cgeneration'} ne $userenv{'generation'} ||
2228: $env{'form.cid'} ne $userenv{'id'} ||
2229: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 2230: $namechanged = 1;
2231: }
1.267 raeburn 2232: if (($namechanged) || (keys(%changed) > 0)) {
1.101 albertel 2233: $changeHash{'firstname'} = $env{'form.cfirstname'};
2234: $changeHash{'middlename'} = $env{'form.cmiddlename'};
2235: $changeHash{'lastname'} = $env{'form.clastname'};
2236: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 2237: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 2238: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 2239: my ($chgresult,$namechgresult);
2240: if (keys(%changed) > 0) {
2241: $chgresult =
1.204 raeburn 2242: &Apache::lonnet::put('environment',\%changeHash,
2243: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2244: if ($chgresult eq 'ok') {
2245: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2246: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2247: my %newenvhash;
2248: foreach my $key (keys(%changed)) {
1.275 raeburn 2249: if (($key eq 'official') || ($key eq 'unofficial')) {
1.279 raeburn 2250: $newenvhash{'environment.requestcourses.'.$key} =
2251: $changeHash{'requestcourses.'.$key};
2252: if ($changeHash{'requestcourses.'.$key} ne '') {
2253: $newenvhash{'environment.canrequest.'.$key} =
2254: $changeHash{'requestcourses.'.$key};
2255: } else {
2256: $newenvhash{'environment.canrequest.'.$key} =
2257: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2258: $key,'reload','requestcourses');
2259: }
1.275 raeburn 2260: } elsif ($key ne 'quota') {
1.270 raeburn 2261: $newenvhash{'environment.tools.'.$key} =
2262: $changeHash{'tools.'.$key};
1.279 raeburn 2263: if ($changeHash{'tools.'.$key} ne '') {
2264: $newenvhash{'environment.availabletools.'.$key} =
2265: $changeHash{'tools.'.$key};
2266: } else {
2267: $newenvhash{'environment.availabletools.'.$key} =
2268: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, $key,'reload','tools');
2269: }
1.270 raeburn 2270: }
2271: }
1.271 raeburn 2272: if (keys(%newenvhash)) {
2273: &Apache::lonnet::appenv(\%newenvhash);
2274: }
1.267 raeburn 2275: }
2276: }
1.204 raeburn 2277: }
2278: if ($namechanged) {
2279: # Make the change
2280: $namechgresult =
2281: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2282: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2283: $changeHash{'firstname'},$changeHash{'middlename'},
2284: $changeHash{'lastname'},$changeHash{'generation'},
2285: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 2286: %userupdate = (
2287: lastname => $env{'form.clastname'},
2288: middlename => $env{'form.cmiddlename'},
2289: firstname => $env{'form.cfirstname'},
2290: generation => $env{'form.cgeneration'},
2291: id => $env{'form.cid'},
2292: );
1.204 raeburn 2293: }
2294: if (($namechanged && $namechgresult eq 'ok') ||
1.267 raeburn 2295: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2296: # Tell the user we changed the name
1.73 sakharuk 2297: my %lt=&Apache::lonlocal::texthash(
1.284 bisitz 2298: 'uic' => 'User Information Changed',
2299: 'frst' => 'First Name',
2300: 'mddl' => 'Middle Name',
2301: 'lst' => 'Last Name',
2302: 'gen' => 'Generation',
2303: 'id' => 'Student/Employee ID',
2304: 'mail' => 'Permanent e-mail address',
2305: 'disk' => 'Disk space allocated to portfolio files',
2306: 'blog' => 'Blog Availability',
2307: 'aboutme' => 'Personal Information Page Availability',
2308: 'portfolio' => 'Portfolio Availability',
2309: 'official' => 'Can Request Official Courses',
2310: 'unofficial' => 'Can Request Unofficial Courses',
1.286 raeburn 2311: 'inststatus' => "Affiliation",
1.284 bisitz 2312: 'prvs' => 'Previous Value:',
2313: 'chto' => 'Changed To:'
1.73 sakharuk 2314: );
1.201 raeburn 2315: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
2316: &Apache::loncommon::start_data_table().
2317: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 2318: $r->print(<<"END");
1.201 raeburn 2319: <th> </th>
1.73 sakharuk 2320: <th>$lt{'frst'}</th>
2321: <th>$lt{'mddl'}</th>
2322: <th>$lt{'lst'}</th>
1.134 raeburn 2323: <th>$lt{'gen'}</th>
1.196 raeburn 2324: <th>$lt{'id'}</th>
1.173 raeburn 2325: <th>$lt{'mail'}</th>
1.201 raeburn 2326: END
1.286 raeburn 2327: if ($showinststatus) {
2328: $r->print("
2329: <th>$lt{'inststatus'}</th>\n");
2330: }
1.275 raeburn 2331: if ($showrequestcourses) {
2332: foreach my $item (@requestcourses) {
2333: $r->print("
2334: <th>$lt{$item}</th>\n");
2335: }
2336: }
1.220 raeburn 2337: if ($showquota) {
2338: $r->print("
2339: <th>$lt{'disk'}</th>\n");
2340: }
1.267 raeburn 2341: if ($showtools) {
2342: foreach my $item (@usertools) {
2343: $r->print("
2344: <th>$lt{$item}</th>\n");
2345: }
2346: }
1.201 raeburn 2347: $r->print(&Apache::loncommon::end_data_table_header_row().
2348: &Apache::loncommon::start_data_table_row());
2349: $r->print(<<"END");
2350: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 2351: <td>$userenv{'firstname'} </td>
2352: <td>$userenv{'middlename'} </td>
2353: <td>$userenv{'lastname'} </td>
1.134 raeburn 2354: <td>$userenv{'generation'} </td>
1.196 raeburn 2355: <td>$userenv{'id'}</td>
1.160 raeburn 2356: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 2357: END
1.286 raeburn 2358: if ($showinststatus) {
2359: $r->print("
2360: <td>$oldinststatuses</td>\n");
2361: }
1.275 raeburn 2362: if ($showrequestcourses) {
2363: foreach my $item (@requestcourses) {
2364: $r->print("
2365: <td>$oldaccess{$item} $oldaccesstext{$item}</td>\n");
2366: }
2367: }
1.220 raeburn 2368: if ($showquota) {
2369: $r->print("
2370: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
2371: }
1.267 raeburn 2372: if ($showtools) {
2373: foreach my $item (@usertools) {
2374: $r->print("
2375: <td>$oldaccess{$item} $oldaccesstext{$item} </td>\n");
2376: }
2377: }
1.201 raeburn 2378: $r->print(&Apache::loncommon::end_data_table_row().
2379: &Apache::loncommon::start_data_table_row());
2380: $r->print(<<"END");
1.267 raeburn 2381: <td><span class="LC_nobreak"><b>$lt{'chto'}</b></span></td>
1.101 albertel 2382: <td>$env{'form.cfirstname'} </td>
2383: <td>$env{'form.cmiddlename'} </td>
2384: <td>$env{'form.clastname'} </td>
1.134 raeburn 2385: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 2386: <td>$env{'form.cid'} </td>
1.160 raeburn 2387: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 2388: END
1.286 raeburn 2389: if ($showinststatus) {
2390: $r->print("
2391: <td>$newinststatuses</td>\n");
2392: }
1.275 raeburn 2393: if ($showrequestcourses) {
2394: foreach my $item (@requestcourses) {
2395: $r->print("
2396: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2397: }
2398: }
1.220 raeburn 2399: if ($showquota) {
2400: $r->print("
2401: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
2402: }
1.267 raeburn 2403: if ($showtools) {
2404: foreach my $item (@usertools) {
2405: $r->print("
2406: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2407: }
2408: }
1.201 raeburn 2409: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 2410: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 2411: if ($env{'form.cid'} ne $userenv{'id'}) {
2412: &Apache::lonnet::idput($env{'form.ccdomain'},
2413: ($env{'form.ccuname'} => $env{'form.cid'}));
2414: if (($recurseid) &&
2415: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2416: my $idresult =
2417: &Apache::lonuserutils::propagate_id_change(
2418: $env{'form.ccuname'},$env{'form.ccdomain'},
2419: \%userupdate);
2420: $r->print('<br />'.$idresult.'<br />');
2421: }
1.196 raeburn 2422: }
1.149 raeburn 2423: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2424: ($env{'form.ccuname'} eq $env{'user.name'})) {
2425: my %newenvhash;
2426: foreach my $key (keys(%changeHash)) {
2427: $newenvhash{'environment.'.$key} = $changeHash{$key};
2428: }
1.238 raeburn 2429: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2430: }
1.28 matthew 2431: } else { # error occurred
1.188 raeburn 2432: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2433: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2434: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2435: }
1.101 albertel 2436: } else { # End of if ($env ... ) logic
1.275 raeburn 2437: # They did not want to change the users name, quota, tool availability,
2438: # or ability to request creation of courses,
1.267 raeburn 2439: # but we can still tell them what the name and quota and availabilities are
1.73 sakharuk 2440: my %lt=&Apache::lonlocal::texthash(
1.275 raeburn 2441: 'id' => "Student/Employee ID",
1.284 bisitz 2442: 'mail' => "Permanent e-mail address",
1.275 raeburn 2443: 'disk' => "Disk space allocated to user's portfolio files",
2444: 'blog' => "Blog Availability",
1.285 weissno 2445: 'aboutme' => "Personal Information Page Availability",
1.275 raeburn 2446: 'portfolio' => "Portfolio Availability",
2447: 'official' => "Can Request Official Courses",
2448: 'unofficial' => "Can Request Unofficial Course",
1.286 raeburn 2449: 'inststatus' => "Affiliation",
1.73 sakharuk 2450: );
1.134 raeburn 2451: $r->print(<<"END");
1.196 raeburn 2452: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2453: END
1.204 raeburn 2454: if ($userenv{'permanentemail'} ne '') {
2455: $r->print('<br />['.$lt{'mail'}.': '.
2456: $userenv{'permanentemail'}.']');
1.134 raeburn 2457: }
1.286 raeburn 2458: if ($showinststatus) {
2459: $r->print('<br />['.$lt{'inststatus'}.': '.$oldinststatuses.']');
2460: }
1.275 raeburn 2461: if ($showrequestcourses) {
2462: foreach my $item (@requestcourses) {
2463: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2464: $newaccesstext{$item}.']'."\n");
2465: }
2466: }
1.267 raeburn 2467: if ($showtools) {
2468: foreach my $item (@usertools) {
2469: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2470: $newaccesstext{$item}.']'."\n");
2471: }
2472: }
1.220 raeburn 2473: if ($showquota) {
1.267 raeburn 2474: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
1.220 raeburn 2475: $olddefquotatext.']');
2476: }
2477: $r->print('</h4>');
1.28 matthew 2478: }
1.206 raeburn 2479: if (@mod_disallowed) {
2480: my ($rolestr,$contextname);
2481: if (@longroles > 0) {
2482: $rolestr = join(', ',@longroles);
2483: } else {
2484: $rolestr = &mt('No roles');
2485: }
2486: if ($context eq 'course') {
2487: $contextname = &mt('course');
2488: } elsif ($context eq 'author') {
2489: $contextname = &mt('co-author');
2490: }
2491: $r->print(&mt('The following fields were not updated: ').'<ul>');
2492: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2493: foreach my $field (@mod_disallowed) {
2494: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2495: }
1.207 raeburn 2496: $r->print('</ul>');
2497: if (@mod_disallowed == 1) {
2498: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
2499: } else {
2500: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
2501: }
1.292 bisitz 2502: my $helplink = 'javascript:helpMenu('."'display'".')';
2503: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
2504: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
2505: ,'<a href="'.$helplink.'">','</a>')
2506: .'<br />');
1.206 raeburn 2507: }
1.259 bisitz 2508: $r->print('<span class="LC_warning">'
2509: .$no_forceid_alert
2510: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
2511: .'</span>');
1.4 www 2512: }
1.220 raeburn 2513: if ($env{'form.action'} eq 'singlestudent') {
1.239 raeburn 2514: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
2515: $r->print('<p><a href="javascript:backPage(document.userupdate)">'.
2516: &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2517: } else {
1.239 raeburn 2518: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2519: if ($namechanged) {
1.220 raeburn 2520: if ($context eq 'course') {
2521: if (@userroles > 0) {
1.225 raeburn 2522: if ((@rolechanges == 0) ||
2523: (!(grep(/^st$/,@rolechanges)))) {
2524: if (grep(/^st$/,@userroles)) {
2525: my $classlistupdated =
2526: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2527: $cnum,$env{'form.ccdomain'},
2528: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2529: }
1.220 raeburn 2530: }
2531: }
2532: }
2533: }
1.226 raeburn 2534: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2535: $env{'form.ccdomain'});
2536: if ($env{'form.popup'}) {
2537: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2538: } else {
1.246 bisitz 2539: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2540: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2541: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2542: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2543: }
1.220 raeburn 2544: }
2545: $r->print(&Apache::loncommon::end_page());
2546: }
2547:
1.275 raeburn 2548: sub tool_changes {
2549: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
2550: $changed,$newaccess,$newaccesstext) = @_;
2551: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
2552: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
2553: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
2554: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
2555: return;
2556: }
2557: foreach my $tool (@{$usertools}) {
2558: if ($userenv->{$context.'.'.$tool} ne '') {
2559: $oldaccess->{$tool} = &mt('custom');
2560: if ($userenv->{$context.'.'.$tool}) {
2561: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
2562: } else {
2563: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
2564: }
1.279 raeburn 2565: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.275 raeburn 2566: if ($env{'form.custom'.$tool} == 1) {
1.279 raeburn 2567: if ($env{'form.'.$context.'_'.$tool} ne $userenv->{$context.'.'.$tool}) {
1.275 raeburn 2568: $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool},
2569: $changeHash,$context);
2570: if ($changed->{$tool}) {
2571: $newaccess->{$tool} = &mt('custom');
2572: if ($env{'form.'.$context.'_'.$tool}) {
2573: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2574: } else {
2575: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2576: }
2577: } else {
2578: $newaccess->{$tool} = $oldaccess->{$tool};
2579: if ($userenv->{$context.'.'.$tool}) {
2580: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2581: } else {
2582: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2583: }
2584: }
2585: } else {
2586: $newaccess->{$tool} = $oldaccess->{$tool};
2587: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
2588: }
2589: } else {
2590: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
2591: if ($changed->{$tool}) {
2592: $newaccess->{$tool} = &mt('default');
2593: } else {
2594: $newaccess->{$tool} = $oldaccess->{$tool};
2595: if ($userenv->{$context.'.'.$tool}) {
2596: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2597: } else {
2598: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2599: }
2600: }
2601: }
2602: } else {
2603: $oldaccess->{$tool} = &mt('default');
2604: if ($env{'form.custom'.$tool} == 1) {
2605: $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool},
2606: $changeHash,$context);
2607: if ($changed->{$tool}) {
2608: $newaccess->{$tool} = &mt('custom');
2609: if ($env{'form.'.$context.'_'.$tool}) {
2610: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2611: } else {
2612: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2613: }
2614: } else {
2615: $newaccess->{$tool} = $oldaccess->{$tool};
2616: }
2617: } else {
2618: $newaccess->{$tool} = $oldaccess->{$tool};
2619: }
2620: }
2621: }
2622: return;
2623: }
2624:
1.220 raeburn 2625: sub update_roles {
1.239 raeburn 2626: my ($r,$context) = @_;
1.4 www 2627: my $now=time;
1.225 raeburn 2628: my @rolechanges;
1.220 raeburn 2629: my %disallowed;
1.73 sakharuk 2630: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2631: foreach my $key (keys (%env)) {
2632: next if (! $env{$key});
1.190 raeburn 2633: next if ($key eq 'form.action');
1.27 matthew 2634: # Revoke roles
1.135 raeburn 2635: if ($key=~/^form\.rev/) {
2636: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2637: # Revoke standard role
1.170 albertel 2638: my ($scope,$role) = ($1,$2);
2639: my $result =
2640: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2641: $env{'form.ccuname'},
1.239 raeburn 2642: $scope,$role,'','',$context);
1.170 albertel 2643: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2644: $role,$scope,'<b>'.$result.'</b>').'<br />');
2645: if ($role eq 'st') {
1.202 raeburn 2646: my $result =
1.198 raeburn 2647: &Apache::lonuserutils::classlist_drop($scope,
2648: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2649: $now);
1.170 albertel 2650: $r->print($result);
1.53 www 2651: }
1.225 raeburn 2652: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2653: push(@rolechanges,$role);
2654: }
1.196 raeburn 2655: }
1.195 raeburn 2656: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2657: # Revoke custom role
1.113 raeburn 2658: $r->print(&mt('Revoking custom role:').
1.139 albertel 2659: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2660: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 2661: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 2662: '</b><br />');
1.225 raeburn 2663: if (!grep(/^cr$/,@rolechanges)) {
2664: push(@rolechanges,'cr');
2665: }
1.64 www 2666: }
1.135 raeburn 2667: } elsif ($key=~/^form\.del/) {
2668: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2669: # Delete standard role
1.170 albertel 2670: my ($scope,$role) = ($1,$2);
2671: my $result =
2672: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2673: $env{'form.ccuname'},
1.239 raeburn 2674: $scope,$role,$now,0,1,'',
2675: $context);
1.170 albertel 2676: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2677: '<b>'.$result.'</b>').'<br />');
2678: if ($role eq 'st') {
1.202 raeburn 2679: my $result =
1.198 raeburn 2680: &Apache::lonuserutils::classlist_drop($scope,
2681: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2682: $now);
1.170 albertel 2683: $r->print($result);
1.81 albertel 2684: }
1.225 raeburn 2685: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2686: push(@rolechanges,$role);
2687: }
1.116 raeburn 2688: }
1.139 albertel 2689: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2690: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2691: # Delete custom role
1.294 bisitz 2692: $r->print(&mt('Deleting custom role [_1] by [_2] in [_3]',
2693: $rolename,$rnam.':'.$rdom,$url).': <b>'.
1.116 raeburn 2694: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2695: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 2696: 0,1,$context).'</b><br />');
1.225 raeburn 2697: if (!grep(/^cr$/,@rolechanges)) {
2698: push(@rolechanges,'cr');
2699: }
1.116 raeburn 2700: }
1.135 raeburn 2701: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2702: my $udom = $env{'form.ccdomain'};
2703: my $uname = $env{'form.ccuname'};
1.116 raeburn 2704: # Re-enable standard role
1.135 raeburn 2705: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2706: my $url = $1;
2707: my $role = $2;
2708: my $logmsg;
2709: my $output;
2710: if ($role eq 'st') {
1.141 albertel 2711: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2712: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2713: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2714: if ($result eq 'refused' && $logmsg) {
2715: $output = $logmsg;
2716: } else {
2717: $output = "Error: $result\n";
2718: }
1.89 raeburn 2719: } else {
2720: $output = &mt('Assigning').' '.$role.' in '.$url.
2721: &mt('starting').' '.localtime($now).
2722: ': <br />'.$logmsg.'<br />'.
2723: &mt('Add to classlist').': <b>ok</b><br />';
2724: }
2725: }
2726: } else {
1.101 albertel 2727: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 2728: $env{'form.ccuname'},$url,$role,0,$now,'','',
2729: $context);
1.266 bisitz 2730: $output = &mt('Re-enabling [_1] in [_2]: [_3]',
2731: $role,$url,'<b>'.$result.'</b>').'<br />';
1.27 matthew 2732: }
1.89 raeburn 2733: $r->print($output);
1.225 raeburn 2734: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2735: push(@rolechanges,$role);
2736: }
1.113 raeburn 2737: }
1.116 raeburn 2738: # Re-enable custom role
1.139 albertel 2739: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2740: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2741: my $result = &Apache::lonnet::assigncustomrole(
2742: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 2743: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.294 bisitz 2744: $r->print(&mt('Re-enabling custom role [_1] by [_2] in [_3]: [_4]',
2745: $rolename,$rnam.':'.$rdom,$url,'<b>'.$result.'</b>').'<br />');
1.225 raeburn 2746: if (!grep(/^cr$/,@rolechanges)) {
2747: push(@rolechanges,'cr');
2748: }
1.116 raeburn 2749: }
1.135 raeburn 2750: } elsif ($key=~/^form\.act/) {
1.101 albertel 2751: my $udom = $env{'form.ccdomain'};
2752: my $uname = $env{'form.ccuname'};
1.141 albertel 2753: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2754: # Activate a custom role
1.83 albertel 2755: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2756: my $url='/'.$one.'/'.$two;
2757: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2758:
1.101 albertel 2759: my $start = ( $env{'form.start_'.$full} ?
2760: $env{'form.start_'.$full} :
1.88 raeburn 2761: $now );
1.101 albertel 2762: my $end = ( $env{'form.end_'.$full} ?
2763: $env{'form.end_'.$full} :
1.88 raeburn 2764: 0 );
2765:
2766: # split multiple sections
2767: my %sections = ();
1.101 albertel 2768: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2769: if ($num_sections == 0) {
1.240 raeburn 2770: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2771: } else {
1.114 albertel 2772: my %curr_groups =
1.117 raeburn 2773: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2774: foreach my $sec (sort {$a cmp $b} keys %sections) {
2775: if (($sec eq 'none') || ($sec eq 'all') ||
2776: exists($curr_groups{$sec})) {
2777: $disallowed{$sec} = $url;
2778: next;
2779: }
2780: my $securl = $url.'/'.$sec;
1.240 raeburn 2781: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2782: }
2783: }
1.225 raeburn 2784: if (!grep(/^cr$/,@rolechanges)) {
2785: push(@rolechanges,'cr');
2786: }
1.142 raeburn 2787: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2788: # Activate roles for sections with 3 id numbers
2789: # set start, end times, and the url for the class
1.83 albertel 2790: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2791: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2792: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2793: $now );
1.101 albertel 2794: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2795: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2796: 0 );
1.83 albertel 2797: my $url='/'.$one.'/'.$two;
1.88 raeburn 2798: my $type = 'three';
2799: # split multiple sections
2800: my %sections = ();
1.101 albertel 2801: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2802: if ($num_sections == 0) {
1.240 raeburn 2803: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2804: } else {
1.114 albertel 2805: my %curr_groups =
1.117 raeburn 2806: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2807: my $emptysec = 0;
2808: foreach my $sec (sort {$a cmp $b} keys %sections) {
2809: $sec =~ s/\W//g;
1.113 raeburn 2810: if ($sec ne '') {
2811: if (($sec eq 'none') || ($sec eq 'all') ||
2812: exists($curr_groups{$sec})) {
2813: $disallowed{$sec} = $url;
2814: next;
2815: }
1.88 raeburn 2816: my $securl = $url.'/'.$sec;
1.240 raeburn 2817: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 2818: } else {
2819: $emptysec = 1;
2820: }
2821: }
2822: if ($emptysec) {
1.240 raeburn 2823: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2824: }
1.225 raeburn 2825: }
2826: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2827: push(@rolechanges,$three);
2828: }
1.135 raeburn 2829: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2830: # Activate roles for sections with two id numbers
2831: # set start, end times, and the url for the class
1.101 albertel 2832: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2833: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2834: $now );
1.101 albertel 2835: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2836: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2837: 0 );
1.225 raeburn 2838: my $one = $1;
2839: my $two = $2;
2840: my $url='/'.$one.'/';
1.88 raeburn 2841: # split multiple sections
2842: my %sections = ();
1.225 raeburn 2843: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2844: if ($num_sections == 0) {
1.240 raeburn 2845: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2846: } else {
2847: my $emptysec = 0;
2848: foreach my $sec (sort {$a cmp $b} keys %sections) {
2849: if ($sec ne '') {
2850: my $securl = $url.'/'.$sec;
1.240 raeburn 2851: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 2852: } else {
2853: $emptysec = 1;
2854: }
2855: }
2856: if ($emptysec) {
1.240 raeburn 2857: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2858: }
2859: }
1.225 raeburn 2860: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2861: push(@rolechanges,$two);
2862: }
1.64 www 2863: } else {
1.190 raeburn 2864: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2865: }
1.113 raeburn 2866: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 2867: $r->print('<p class="LC_warning">');
1.113 raeburn 2868: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 2869: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 2870: } else {
1.274 bisitz 2871: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 2872: }
1.274 bisitz 2873: $r->print('</p><p>'
2874: .&mt('Please [_1]go back[_2] and choose a different section name.'
2875: ,'<a href="javascript:history.go(-1)'
2876: ,'</a>')
2877: .'</p><br />'
2878: );
1.113 raeburn 2879: }
2880: }
1.101 albertel 2881: } # End of foreach (keys(%env))
1.75 www 2882: # Flush the course logs so reverse user roles immediately updated
2883: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2884: if (@rolechanges == 0) {
1.193 raeburn 2885: $r->print(&mt('No roles to modify'));
2886: }
1.225 raeburn 2887: return @rolechanges;
1.220 raeburn 2888: }
2889:
2890: sub enroll_single_student {
1.239 raeburn 2891: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
1.220 raeburn 2892: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2893:
2894: # Remove non alphanumeric values from section
2895: $env{'form.sections'}=~s/\W//g;
2896:
2897: # Clean out any old student roles the user has in this class.
2898: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2899: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2900: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2901: my $enroll_result =
2902: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2903: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2904: $env{'form.cmiddlename'},$env{'form.clastname'},
2905: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 2906: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 2907: if ($enroll_result =~ /^ok/) {
2908: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2909: if ($env{'form.sections'} ne '') {
2910: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2911: }
2912: my ($showstart,$showend);
2913: if ($startdate <= $now) {
2914: $showstart = &mt('Access starts immediately');
2915: } else {
2916: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2917: }
2918: if ($enddate == 0) {
2919: $showend = &mt('ends: no ending date');
2920: } else {
2921: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2922: }
2923: $r->print('.<br />'.$showstart.'; '.$showend);
2924: if ($startdate <= $now && !$newuser) {
2925: $r->print("<p> ".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."</p>");
2926: }
2927: } else {
2928: $r->print(&mt('unable to enroll').": ".$enroll_result);
2929: }
2930: return;
1.188 raeburn 2931: }
2932:
1.204 raeburn 2933: sub get_defaultquota_text {
2934: my ($settingstatus) = @_;
2935: my $defquotatext;
2936: if ($settingstatus eq '') {
2937: $defquotatext = &mt('(default)');
2938: } else {
2939: my ($usertypes,$order) =
2940: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2941: if ($usertypes->{$settingstatus} eq '') {
2942: $defquotatext = &mt('(default)');
2943: } else {
2944: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2945: }
2946: }
2947: return $defquotatext;
2948: }
2949:
1.188 raeburn 2950: sub update_result_form {
2951: my ($uhome) = @_;
2952: my $outcome =
2953: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2954: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2955: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2956: }
1.207 raeburn 2957: if ($env{'form.origname'} ne '') {
2958: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2959: }
1.160 raeburn 2960: foreach my $item ('sortby','seluname','seludom') {
2961: if (exists($env{'form.'.$item})) {
1.188 raeburn 2962: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2963: }
2964: }
1.188 raeburn 2965: if ($uhome eq 'no_host') {
2966: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2967: }
2968: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2969: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2970: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2971: '</form>';
2972: return $outcome;
1.4 www 2973: }
2974:
1.149 raeburn 2975: sub quota_admin {
2976: my ($setquota,$changeHash) = @_;
2977: my $quotachanged;
2978: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2979: # Current user has quota modification privileges
1.267 raeburn 2980: if (ref($changeHash) eq 'HASH') {
2981: $quotachanged = 1;
2982: $changeHash->{'portfolioquota'} = $setquota;
2983: }
1.149 raeburn 2984: }
2985: return $quotachanged;
2986: }
2987:
1.267 raeburn 2988: sub tool_admin {
1.275 raeburn 2989: my ($tool,$settool,$changeHash,$context) = @_;
2990: my $canchange = 0;
1.279 raeburn 2991: if ($context eq 'requestcourses') {
1.275 raeburn 2992: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
2993: $canchange = 1;
2994: }
2995: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
2996: # Current user has quota modification privileges
2997: $canchange = 1;
2998: }
1.267 raeburn 2999: my $toolchanged;
1.275 raeburn 3000: if ($canchange) {
1.267 raeburn 3001: if (ref($changeHash) eq 'HASH') {
3002: $toolchanged = 1;
1.275 raeburn 3003: $changeHash->{$context.'.'.$tool} = $settool;
1.267 raeburn 3004: }
3005: }
3006: return $toolchanged;
3007: }
3008:
1.88 raeburn 3009: sub build_roles {
1.89 raeburn 3010: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3011: my $num_sections = 0;
3012: if ($sectionstr=~ /,/) {
3013: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3014: if ($role eq 'st') {
3015: $secnums[0] =~ s/\W//g;
3016: $$sections{$secnums[0]} = 1;
3017: $num_sections = 1;
3018: } else {
3019: foreach my $sec (@secnums) {
3020: $sec =~ ~s/\W//g;
1.150 banghart 3021: if (!($sec eq "")) {
1.89 raeburn 3022: if (exists($$sections{$sec})) {
3023: $$sections{$sec} ++;
3024: } else {
3025: $$sections{$sec} = 1;
3026: $num_sections ++;
3027: }
1.88 raeburn 3028: }
3029: }
3030: }
3031: } else {
3032: $sectionstr=~s/\W//g;
3033: unless ($sectionstr eq '') {
3034: $$sections{$sectionstr} = 1;
3035: $num_sections ++;
3036: }
3037: }
1.129 albertel 3038:
1.88 raeburn 3039: return $num_sections;
3040: }
3041:
1.58 www 3042: # ========================================================== Custom Role Editor
3043:
3044: sub custom_role_editor {
1.160 raeburn 3045: my ($r) = @_;
1.101 albertel 3046: my $rolename=$env{'form.rolename'};
1.58 www 3047:
1.59 www 3048: if ($rolename eq 'make new role') {
1.101 albertel 3049: $rolename=$env{'form.newrolename'};
1.59 www 3050: }
3051:
1.63 www 3052: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 3053:
1.190 raeburn 3054: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 3055: &print_username_entry_form($r);
3056: return;
3057: }
1.153 banghart 3058: # ------------------------------------------------------- What can be assigned?
3059: my %full=();
3060: my %courselevel=();
3061: my %courselevelcurrent=();
1.61 www 3062: my $syspriv='';
3063: my $dompriv='';
3064: my $coursepriv='';
1.153 banghart 3065: my $body_top;
1.150 banghart 3066: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 3067: my ($rdummy,$roledef)=
3068: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3069: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3070: $body_top .= '<h2>';
1.59 www 3071: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3072: $body_top .= &mt('Existing Role').' "';
1.61 www 3073: # ------------------------------------------------- Get current role privileges
3074: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 3075: } else {
1.153 banghart 3076: $body_top .= &mt('New Role').' "';
1.59 www 3077: $roledef='';
3078: }
1.153 banghart 3079: $body_top .= $rolename.'"</h2>';
1.135 raeburn 3080: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3081: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3082: if (!$restrict) { $restrict='F'; }
1.60 www 3083: $courselevel{$priv}=$restrict;
1.61 www 3084: if ($coursepriv=~/\:$priv/) {
3085: $courselevelcurrent{$priv}=1;
3086: }
1.60 www 3087: $full{$priv}=1;
3088: }
3089: my %domainlevel=();
1.61 www 3090: my %domainlevelcurrent=();
1.135 raeburn 3091: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3092: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3093: if (!$restrict) { $restrict='F'; }
1.60 www 3094: $domainlevel{$priv}=$restrict;
1.61 www 3095: if ($dompriv=~/\:$priv/) {
3096: $domainlevelcurrent{$priv}=1;
3097: }
1.60 www 3098: $full{$priv}=1;
3099: }
1.61 www 3100: my %systemlevel=();
3101: my %systemlevelcurrent=();
1.135 raeburn 3102: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3103: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3104: if (!$restrict) { $restrict='F'; }
1.61 www 3105: $systemlevel{$priv}=$restrict;
3106: if ($syspriv=~/\:$priv/) {
3107: $systemlevelcurrent{$priv}=1;
3108: }
3109: $full{$priv}=1;
3110: }
1.160 raeburn 3111: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 3112: my $button_code = "\n";
1.153 banghart 3113: my $head_script = "\n";
3114: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 3115: my @template_roles = ("cc","in","ta","ep","st");
3116: foreach my $role (@template_roles) {
3117: $head_script .= &make_script_template($role);
1.264 bisitz 3118: $button_code .= &make_button_code($role).' ';
1.154 banghart 3119: }
1.160 raeburn 3120: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 3121: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 3122: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3123: ({href=>"javascript:backPage(document.form1,'pickrole','')",
3124: text=>"Pick custom role",
1.160 raeburn 3125: faq=>282,bug=>'Instructor Interface',},
3126: {href=>"javascript:backPage(document.form1,'','')",
3127: text=>"Edit custom role",
3128: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3129: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3130: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3131:
1.153 banghart 3132: $r->print($body_top);
1.73 sakharuk 3133: my %lt=&Apache::lonlocal::texthash(
3134: 'prv' => "Privilege",
1.131 raeburn 3135: 'crl' => "Course Level",
1.73 sakharuk 3136: 'dml' => "Domain Level",
1.150 banghart 3137: 'ssl' => "System Level");
1.264 bisitz 3138:
3139: $r->print('<div>'
3140: .'<form action=""><fieldset>'
3141: .'<legend>'.&mt('Select a Template').'</legend>'
3142: .$button_code
3143: .'</fieldset></form>'
3144: .'</div>'
3145: );
3146:
1.61 www 3147: $r->print(<<ENDCCF);
1.160 raeburn 3148: <form name="form1" method="post">
1.61 www 3149: <input type="hidden" name="phase" value="set_custom_roles" />
3150: <input type="hidden" name="rolename" value="$rolename" />
3151: ENDCCF
1.135 raeburn 3152: $r->print(&Apache::loncommon::start_data_table().
3153: &Apache::loncommon::start_data_table_header_row().
3154: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
3155: '</th><th>'.$lt{'ssl'}.'</th>'.
3156: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 3157: foreach my $priv (sort keys %full) {
3158: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 3159: $r->print(&Apache::loncommon::start_data_table_row().
3160: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 3161: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
3162: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3163: '</td><td>'.
1.288 bisitz 3164: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
3165: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3166: '</td><td>'.
1.288 bisitz 3167: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
3168: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.135 raeburn 3169: '</td>'.
3170: &Apache::loncommon::end_data_table_row());
1.60 www 3171: }
1.135 raeburn 3172: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 3173: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 3174: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 3175: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 3176: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.282 schafran 3177: '<input type="submit" value="'.&mt('Save').'" /></form>'.
1.110 albertel 3178: &Apache::loncommon::end_page());
1.61 www 3179: }
1.153 banghart 3180: # --------------------------------------------------------
3181: sub make_script_template {
3182: my ($role) = @_;
3183: my %full_c=();
3184: my %full_d=();
3185: my %full_s=();
3186: my $return_script;
3187: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3188: my ($priv,$restrict)=split(/\&/,$item);
3189: $full_c{$priv}=1;
3190: }
3191: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3192: my ($priv,$restrict)=split(/\&/,$item);
3193: $full_d{$priv}=1;
3194: }
1.154 banghart 3195: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 3196: my ($priv,$restrict)=split(/\&/,$item);
3197: $full_s{$priv}=1;
3198: }
3199: $return_script .= 'function set_'.$role.'() {'."\n";
3200: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
3201: my %role_c;
1.155 banghart 3202: foreach my $priv (@temp) {
1.153 banghart 3203: my ($priv_item, $dummy) = split(/\&/,$priv);
3204: $role_c{$priv_item} = 1;
3205: }
1.269 raeburn 3206: my %role_d;
3207: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
3208: foreach my $priv(@temp) {
3209: my ($priv_item, $dummy) = split(/\&/,$priv);
3210: $role_d{$priv_item} = 1;
3211: }
3212: my %role_s;
3213: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
3214: foreach my $priv(@temp) {
3215: my ($priv_item, $dummy) = split(/\&/,$priv);
3216: $role_s{$priv_item} = 1;
3217: }
1.153 banghart 3218: foreach my $priv_item (keys(%full_c)) {
3219: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3220: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
3221: (exists($role_s{$priv}))) {
1.153 banghart 3222: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
3223: } else {
3224: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
3225: }
3226: }
1.154 banghart 3227: foreach my $priv_item (keys(%full_d)) {
3228: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3229: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 3230: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
3231: } else {
3232: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
3233: }
3234: }
3235: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 3236: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 3237: if (exists($role_s{$priv})) {
3238: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
3239: } else {
3240: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
3241: }
1.153 banghart 3242: }
3243: $return_script .= '}'."\n";
1.154 banghart 3244: return ($return_script);
3245: }
3246: # ----------------------------------------------------------
3247: sub make_button_code {
3248: my ($role) = @_;
3249: my $label = &Apache::lonnet::plaintext($role);
1.264 bisitz 3250: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 3251: return ($button_code);
1.153 banghart 3252: }
1.61 www 3253: # ---------------------------------------------------------- Call to definerole
3254: sub set_custom_role {
1.240 raeburn 3255: my ($r,$context) = @_;
1.101 albertel 3256: my $rolename=$env{'form.rolename'};
1.63 www 3257: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 3258: if (!$rolename) {
1.190 raeburn 3259: &custom_role_editor($r);
1.61 www 3260: return;
3261: }
1.160 raeburn 3262: my ($jsback,$elements) = &crumb_utilities();
3263: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
3264:
3265: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
3266: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3267: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
3268: text=>"Pick custom role",
1.160 raeburn 3269: faq=>282,bug=>'Instructor Interface',},
3270: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
3271: text=>"Edit custom role",
3272: faq=>282,bug=>'Instructor Interface',},
3273: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
3274: text=>"Result",
3275: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3276: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3277: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3278:
1.61 www 3279: my ($rdummy,$roledef)=
1.110 albertel 3280: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
3281:
1.61 www 3282: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 3283: $r->print('<h3>');
1.61 www 3284: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 3285: $r->print(&mt('Existing Role').' "');
1.61 www 3286: } else {
1.73 sakharuk 3287: $r->print(&mt('New Role').' "');
1.61 www 3288: $roledef='';
3289: }
1.188 raeburn 3290: $r->print($rolename.'"</h3>');
1.61 www 3291: # ------------------------------------------------------- What can be assigned?
3292: my $sysrole='';
3293: my $domrole='';
3294: my $courole='';
3295:
1.135 raeburn 3296: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3297: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3298: if (!$restrict) { $restrict=''; }
3299: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 3300: $courole.=':'.$item;
1.61 www 3301: }
3302: }
3303:
1.135 raeburn 3304: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3305: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3306: if (!$restrict) { $restrict=''; }
3307: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 3308: $domrole.=':'.$item;
1.61 www 3309: }
3310: }
3311:
1.135 raeburn 3312: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3313: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3314: if (!$restrict) { $restrict=''; }
3315: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 3316: $sysrole.=':'.$item;
1.61 www 3317: }
3318: }
1.63 www 3319: $r->print('<br />Defining Role: '.
1.61 www 3320: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 3321: if ($env{'request.course.id'}) {
3322: my $url='/'.$env{'request.course.id'};
1.63 www 3323: $url=~s/\_/\//g;
1.73 sakharuk 3324: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 3325: &Apache::lonnet::assigncustomrole($env{'user.domain'},
3326: $env{'user.name'},
1.63 www 3327: $url,
1.101 albertel 3328: $env{'user.domain'},
3329: $env{'user.name'},
1.240 raeburn 3330: $rolename,undef,undef,undef,$context));
1.63 www 3331: }
1.190 raeburn 3332: $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160 raeburn 3333: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 3334: $r->print(&Apache::loncommon::end_page());
1.58 www 3335: }
3336:
1.2 www 3337: # ================================================================ Main Handler
3338: sub handler {
3339: my $r = shift;
3340: if ($r->header_only) {
1.68 www 3341: &Apache::loncommon::content_type($r,'text/html');
1.2 www 3342: $r->send_http_header;
3343: return OK;
3344: }
1.190 raeburn 3345: my $context;
3346: if ($env{'request.course.id'}) {
3347: $context = 'course';
3348: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 3349: $context = 'author';
1.190 raeburn 3350: } else {
3351: $context = 'domain';
3352: }
3353: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 3354: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
3355: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 3356: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 3357: if ($env{'form.action'} ne 'dateselect') {
3358: &Apache::lonhtmlcommon::add_breadcrumb
3359: ({href=>"/adm/createuser",
1.289 droeschl 3360: text=>"User Management",
3361: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'});
1.202 raeburn 3362: }
1.289 droeschl 3363: #SD Following files not added to help, because the corresponding .tex-files seem to
3364: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 3365: my ($permission,$allowed) =
3366: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 3367: if (!$allowed) {
3368: $env{'user.error.msg'}=
3369: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
3370: "or view user status.";
3371: return HTTP_NOT_ACCEPTABLE;
3372: }
3373:
3374: &Apache::loncommon::content_type($r,'text/html');
3375: $r->send_http_header;
3376:
3377: # Main switch on form.action and form.state, as appropriate
3378: if (! exists($env{'form.action'})) {
3379: $r->print(&header());
3380: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 3381: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3382: $r->print(&Apache::loncommon::end_page());
3383: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
3384: $r->print(&header());
3385: &Apache::lonhtmlcommon::add_breadcrumb
3386: ({href=>'/adm/createuser?action=upload&state=',
3387: text=>"Upload Users List"});
3388: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 3389: 'Course_Create_Class_List'));
1.190 raeburn 3390: $r->print('<form name="studentform" method="post" '.
3391: 'enctype="multipart/form-data" '.
3392: ' action="/adm/createuser">'."\n");
3393: if (! exists($env{'form.state'})) {
3394: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3395: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 3396: &Apache::lonuserutils::print_upload_manager_form($r,$context,
3397: $permission);
1.190 raeburn 3398: } elsif ($env{'form.state'} eq 'enrolling') {
3399: if ($env{'form.datatoken'}) {
1.221 raeburn 3400: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 3401: }
3402: } else {
3403: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3404: }
3405: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 3406: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
3407: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 3408: my $phase = $env{'form.phase'};
3409: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 3410: &Apache::loncreateuser::restore_prev_selections();
3411: my $srch;
3412: foreach my $item (@search) {
3413: $srch->{$item} = $env{'form.'.$item};
3414: }
1.207 raeburn 3415: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
3416: ($phase eq 'createnewuser')) {
3417: if ($env{'form.phase'} eq 'createnewuser') {
3418: my $response;
3419: if ($env{'form.srchterm'} !~ /^$match_username$/) {
3420: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 3421: $env{'form.phase'} = '';
1.207 raeburn 3422: &print_username_entry_form($r,$context,$response,$srch);
3423: } else {
3424: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
3425: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
3426: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3427: $srch,$response,$context,
3428: $permission);
1.207 raeburn 3429: }
3430: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 3431: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 3432: &user_search_result($context,$srch);
1.190 raeburn 3433: if ($env{'form.currstate'} eq 'modify') {
3434: $currstate = $env{'form.currstate'};
3435: }
3436: if ($currstate eq 'select') {
3437: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 3438: \@search,$context);
1.190 raeburn 3439: } elsif ($currstate eq 'modify') {
3440: my ($ccuname,$ccdomain);
3441: if (($srch->{'srchby'} eq 'uname') &&
3442: ($srch->{'srchtype'} eq 'exact')) {
3443: $ccuname = $srch->{'srchterm'};
3444: $ccdomain= $srch->{'srchdomain'};
3445: } else {
3446: my @matchedunames = keys(%{$results});
3447: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
3448: }
3449: $ccuname =&LONCAPA::clean_username($ccuname);
3450: $ccdomain=&LONCAPA::clean_domain($ccdomain);
3451: if ($env{'form.forcenewuser'}) {
3452: $response = '';
3453: }
3454: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3455: $srch,$response,$context,
3456: $permission);
1.190 raeburn 3457: } elsif ($currstate eq 'query') {
3458: &print_user_query_page($r,'createuser');
3459: } else {
1.229 raeburn 3460: $env{'form.phase'} = '';
1.207 raeburn 3461: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 3462: $forcenewuser);
3463: }
3464: } elsif ($env{'form.phase'} eq 'userpicked') {
3465: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
3466: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 3467: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 3468: $context,$permission);
1.190 raeburn 3469: }
3470: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 3471: &update_user_data($r,$context);
1.190 raeburn 3472: } else {
1.207 raeburn 3473: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 3474: }
3475: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
3476: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 3477: &set_custom_role($r,$context);
1.190 raeburn 3478: } else {
3479: &custom_role_editor($r);
3480: }
1.207 raeburn 3481: } elsif (($env{'form.action'} eq 'listusers') &&
3482: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 3483: if ($env{'form.phase'} eq 'bulkchange') {
3484: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 3485: ({href=>'/adm/createuser?action=listusers',
3486: text=>"List Users"},
3487: {href=>"/adm/createuser",
3488: text=>"Result"});
1.202 raeburn 3489: my $setting = $env{'form.roletype'};
3490: my $choice = $env{'form.bulkaction'};
3491: $r->print(&header());
1.221 raeburn 3492: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 3493: 'Course_View_Class_List'));
1.202 raeburn 3494: if ($permission->{'cusr'}) {
3495: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 3496: $r->print(&Apache::loncommon::end_page());
3497: } else {
3498: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 3499: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 3500: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3501: }
3502: } else {
3503: &Apache::lonhtmlcommon::add_breadcrumb
3504: ({href=>'/adm/createuser?action=listusers',
3505: text=>"List Users"});
3506: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
3507: my $formname = 'studentform';
3508: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
3509: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
3510: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
3511: $formname);
3512: $jscript .= &verify_user_display();
3513: my $js = &add_script($jscript).$cb_jscript;
3514: my $loadcode =
3515: &Apache::lonuserutils::course_selector_loadcode($formname);
3516: if ($loadcode ne '') {
3517: $r->print(&header($js,{'onload' => $loadcode,}));
3518: } else {
3519: $r->print(&header($js));
3520: }
1.191 raeburn 3521: } else {
1.202 raeburn 3522: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 3523: }
1.202 raeburn 3524: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3525: 'Course_View_Class_List'));
1.202 raeburn 3526: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3527: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3528: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3529: }
1.213 raeburn 3530: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3531: $r->print(&header());
3532: &Apache::lonhtmlcommon::add_breadcrumb
3533: ({href=>'/adm/createuser?action=drop',
3534: text=>"Drop Students"});
3535: if (!exists($env{'form.state'})) {
3536: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3537: 'Course_Drop_Student'));
3538:
3539: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
3540: } elsif ($env{'form.state'} eq 'done') {
3541: &Apache::lonhtmlcommon::add_breadcrumb
3542: ({href=>'/adm/createuser?action=drop',
3543: text=>"Result"});
3544: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3545: 'Course_Drop_Student'));
3546: &Apache::lonuserutils::update_user_list($r,$context,undef,
3547: $env{'form.action'});
3548: }
3549: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3550: } elsif ($env{'form.action'} eq 'dateselect') {
3551: if ($permission->{'cusr'}) {
3552: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 3553: &Apache::lonuserutils::date_section_selector($context,
3554: $permission).
1.202 raeburn 3555: &Apache::loncommon::end_page());
3556: } else {
3557: $r->print(&header().
3558: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
3559: &Apache::loncommon::end_page());
3560: }
1.237 raeburn 3561: } elsif ($env{'form.action'} eq 'selfenroll') {
3562: $r->print(&header());
3563: &Apache::lonhtmlcommon::add_breadcrumb
3564: ({href=>'/adm/createuser?action=selfenroll',
3565: text=>"Configure Self-enrollment"});
3566: if (!exists($env{'form.state'})) {
3567: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
3568: 'Course_Self_Enrollment'));
1.241 raeburn 3569: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 3570: &print_selfenroll_menu($r,$context,$permission);
3571: } elsif ($env{'form.state'} eq 'done') {
3572: &Apache::lonhtmlcommon::add_breadcrumb
3573: ({href=>'/adm/createuser?action=selfenroll',
3574: text=>"Result"});
3575: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
3576: 'Course_Self_Enrollment'));
1.241 raeburn 3577: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
3578: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 3579: }
3580: $r->print(&Apache::loncommon::end_page());
1.277 raeburn 3581: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
3582: $r->print(&header());
3583: &Apache::lonhtmlcommon::add_breadcrumb
3584: ({href=>'/adm/createuser?action=selfenrollqueue',
3585: text=>"Enrollment requests"});
3586: my $cid = $env{'request.course.id'};
3587: my $cdom = $env{'course.'.$cid.'.domain'};
3588: my $cnum = $env{'course.'.$cid.'.num'};
3589: if (!exists($env{'form.state'})) {
3590: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests',
3591: 'Course_SelfEnrollment_Approval'));
3592: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
3593: &display_selfenroll_queue($r,$context,$permission,$cnum,$cdom);
3594: } elsif ($env{'form.state'} eq 'done') {
3595: &Apache::lonhtmlcommon::add_breadcrumb
3596: ({href=>'/adm/createuser?action=selfenrollqueue',
3597: text=>"Result"});
3598: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result',
3599: 'Course_Self_Enrollment'));
3600: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
3601: &update_selfenroll_queue($r,$context,$permission,$cid,$cnum,$cdom);
3602: }
3603: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 3604: } elsif ($env{'form.action'} eq 'changelogs') {
3605: $r->print(&header());
3606: &Apache::lonhtmlcommon::add_breadcrumb
3607: ({href=>'/adm/createuser?action=changelogs',
3608: text=>"User Management Logs"});
3609: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
3610: 'Course_User_Logs'));
3611: &print_userchangelogs_display($r,$context,$permission);
3612: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 3613: } else {
3614: $r->print(&header());
1.202 raeburn 3615: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 3616: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3617: $r->print(&Apache::loncommon::end_page());
3618: }
3619: return OK;
3620: }
3621:
3622: sub header {
1.202 raeburn 3623: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 3624: my $start_page;
3625: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 3626: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 3627: } else {
1.202 raeburn 3628: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 3629: }
3630: return $start_page;
3631: }
1.2 www 3632:
1.191 raeburn 3633: sub add_script {
3634: my ($js) = @_;
3635: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
3636: }
3637:
1.202 raeburn 3638: sub verify_user_display {
3639: my $output = <<"END";
3640:
3641: function display_update() {
3642: document.studentform.action.value = 'listusers';
3643: document.studentform.phase.value = 'display';
3644: document.studentform.submit();
3645: }
3646:
3647: END
3648: return $output;
3649:
3650: }
3651:
1.190 raeburn 3652: ###############################################################
3653: ###############################################################
3654: # Menu Phase One
3655: sub print_main_menu {
1.208 raeburn 3656: my ($permission,$context) = @_;
3657: my %links = (
3658: domain => {
3659: upload => 'Upload a File of Users',
1.221 raeburn 3660: singleuser => 'Add/Modify a Single User',
1.208 raeburn 3661: listusers => 'Manage Multiple Users',
3662: },
3663: author => {
3664: upload => 'Upload a File of Co-authors',
1.221 raeburn 3665: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 3666: listusers => 'Display Co-authors and Manage Multiple Users',
3667: },
3668: course => {
1.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: }
1.297 ! bisitz 4025: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 4026: if ($item eq 'types') {
4027: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 4028: my $showdomdesc = 1;
4029: my $includeempty = 1;
4030: my $num = 0;
4031: $output .= &Apache::loncommon::start_data_table().
4032: &Apache::loncommon::start_data_table_row()
4033: .'<td colspan="2"><span class="LC_nobreak"><label>'
4034: .&mt('Any user in any domain:')
4035: .' <input type="radio" name="selfenroll_all" value="1" ';
4036: if ($curr_types eq '*') {
4037: $output .= ' checked="checked" ';
4038: }
1.249 raeburn 4039: $output .= 'onchange="javascript:update_types('.
4040: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
4041: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 4042: if ($curr_types ne '*') {
4043: $output .= ' checked="checked" ';
4044: }
1.249 raeburn 4045: $output .= ' onchange="javascript:update_types('.
4046: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
4047: &Apache::loncommon::end_data_table_row().
4048: &Apache::loncommon::end_data_table().
4049: &mt('Or').'<br />'.
4050: &Apache::loncommon::start_data_table();
1.241 raeburn 4051: my %currdoms;
1.249 raeburn 4052: if ($curr_types eq '') {
1.241 raeburn 4053: $output .= &new_selfenroll_dom_row($cdom,'0');
4054: } elsif ($curr_types ne '*') {
4055: my @entries = split(/;/,$curr_types);
4056: if (@entries > 0) {
4057: foreach my $entry (@entries) {
4058: my ($currdom,$typestr) = split(/:/,$entry);
4059: $currdoms{$currdom} = 1;
4060: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 4061: my @currinsttypes = split(',',$typestr);
1.241 raeburn 4062: $output .= &Apache::loncommon::start_data_table_row()
4063: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
4064: .' '.$domdesc.' ('.$currdom.')'
4065: .'</b><input type="hidden" name="selfenroll_dom_'.$num
4066: .'" value="'.$currdom.'" /></span><br />'
4067: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 4068: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 4069: .&mt('Delete').'</label></span></td>';
1.249 raeburn 4070: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 4071: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
4072: .&Apache::loncommon::end_data_table_row();
4073: $num ++;
4074: }
4075: }
4076: }
1.249 raeburn 4077: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 4078: if ($curr_types eq '*') {
1.249 raeburn 4079: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 4080: } elsif ($curr_types eq '') {
1.249 raeburn 4081: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 4082: }
4083: $output .= &Apache::loncommon::start_data_table_row()
4084: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
4085: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
4086: $includeempty,$showdomdesc)
4087: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
4088: .'</td>'.&Apache::loncommon::end_data_table_row()
4089: .&Apache::loncommon::end_data_table();
1.237 raeburn 4090: } elsif ($item eq 'registered') {
4091: my ($regon,$regoff);
4092: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
4093: $regon = ' checked="checked" ';
4094: $regoff = ' ';
4095: } else {
4096: $regon = ' ';
4097: $regoff = ' checked="checked" ';
4098: }
4099: $output .= '<label>'.
1.245 raeburn 4100: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 4101: &mt('Yes').'</label> <label>'.
1.245 raeburn 4102: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 4103: &mt('No').'</label>';
1.237 raeburn 4104: } elsif ($item eq 'enroll_dates') {
4105: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
4106: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
4107: if ($starttime eq '') {
4108: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4109: }
4110: if ($endtime eq '') {
4111: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4112: }
4113: my $startform =
4114: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
4115: undef,undef,undef,undef,undef,undef,undef,$nolink);
4116: my $endform =
4117: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
4118: undef,undef,undef,undef,undef,undef,undef,$nolink);
4119: $output .= &selfenroll_date_forms($startform,$endform);
4120: } elsif ($item eq 'access_dates') {
4121: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
4122: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
4123: if ($starttime eq '') {
4124: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4125: }
4126: if ($endtime eq '') {
4127: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4128: }
4129: my $startform =
4130: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
4131: undef,undef,undef,undef,undef,undef,undef,$nolink);
4132: my $endform =
4133: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
4134: undef,undef,undef,undef,undef,undef,undef,$nolink);
4135: $output .= &selfenroll_date_forms($startform,$endform);
4136: } elsif ($item eq 'section') {
4137: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
4138: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4139: my $newsecval;
4140: if ($currsec ne 'none' && $currsec ne '') {
4141: if (!defined($sections_count{$currsec})) {
4142: $newsecval = $currsec;
4143: }
4144: }
4145: my $sections_select =
4146: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
4147: $output .= '<table class="LC_createuser">'."\n".
4148: '<tr class="LC_section_row">'."\n".
4149: '<td align="center">'.&mt('Existing sections')."\n".
4150: '<br />'.$sections_select.'</td><td align="center">'.
4151: &mt('New section').'<br />'."\n".
4152: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
4153: '<input type="hidden" name="sections" value="" />'."\n".
4154: '<input type="hidden" name="state" value="done" />'."\n".
4155: '</td></tr></table>'."\n";
1.276 raeburn 4156: } elsif ($item eq 'approval') {
4157: my ($appon,$appoff);
4158: my $cid = $env{'request.course.id'};
4159: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4160: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4161: $appon = ' checked="checked" ';
4162: $appoff = ' ';
4163: } else {
4164: $appon = ' ';
4165: $appoff = ' checked="checked" ';
4166: }
4167: $output .= '<label>'.
4168: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4169: &mt('Yes').'</label> <label>'.
4170: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4171: &mt('No').'</label>';
4172: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4173: my (@ccs,%notified);
4174: if ($advhash{'cc'}) {
4175: @ccs = split(/,/,$advhash{'cc'});
4176: }
4177: if ($currnotified) {
4178: foreach my $current (split(/,/,$currnotified)) {
4179: $notified{$current} = 1;
4180: if (!grep(/^\Q$current\E$/,@ccs)) {
4181: push(@ccs,$current);
4182: }
4183: }
4184: }
4185: if (@ccs) {
1.277 raeburn 4186: $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 4187: &Apache::loncommon::start_data_table_row();
4188: my $count = 0;
4189: my $numcols = 4;
4190: foreach my $cc (sort(@ccs)) {
4191: my $notifyon;
4192: my ($ccuname,$ccudom) = split(/:/,$cc);
4193: if ($notified{$cc}) {
4194: $notifyon = ' checked="checked" ';
4195: }
4196: if ($count && !$count%$numcols) {
4197: $output .= &Apache::loncommon::end_data_table_row().
4198: &Apache::loncommon::start_data_table_row()
4199: }
4200: $output .= '<td><span class="LC_nobreak"><label>'.
4201: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4202: &Apache::loncommon::plainname($ccuname,$ccudom).
4203: '</label></span></td>';
4204: $count;
4205: }
4206: my $rem = $count%$numcols;
4207: if ($rem) {
4208: my $emptycols = $numcols - $rem;
4209: for (my $i=0; $i<$emptycols; $i++) {
4210: $output .= '<td> </td>';
4211: }
4212: }
4213: $output .= &Apache::loncommon::end_data_table_row().
4214: &Apache::loncommon::end_data_table();
4215: }
4216: } elsif ($item eq 'limit') {
4217: my ($crslimit,$selflimit,$nolimit);
4218: my $cid = $env{'request.course.id'};
4219: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4220: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4221: my $nolimit = ' checked="checked" ';
4222: if ($currlim eq 'allstudents') {
4223: $crslimit = ' checked="checked" ';
4224: $selflimit = ' ';
4225: $nolimit = ' ';
4226: } elsif ($currlim eq 'selfenrolled') {
4227: $crslimit = ' ';
4228: $selflimit = ' checked="checked" ';
4229: $nolimit = ' ';
4230: } else {
4231: $crslimit = ' ';
4232: $selflimit = ' ';
4233: }
4234: $output .= '<table><tr><td><label>'.
1.278 raeburn 4235: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4236: &mt('No limit').'</label></td><td><label>'.
4237: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4238: &mt('Limit by total students').'</label></td><td><label>'.
4239: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4240: &mt('Limit by total self-enrolled students').
4241: '</td></tr><tr>'.
4242: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4243: (' 'x3).&mt('Maximum number allowed: ').
4244: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4245: }
4246: $output .= &Apache::lonhtmlcommon::row_closure(1);
4247: }
4248: }
4249: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4250: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 4251: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4252: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4253: $r->print($output);
4254: return;
4255: }
4256:
1.277 raeburn 4257: sub display_selfenroll_queue {
4258: my ($r,$context,$permission,$cnum,$cdom) = @_;
4259: my $namespace = 'selfenrollrequests';
4260: my ($output,%queue_by_date);
4261: my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
4262: if (keys(%requesthash) > 0) {
4263: $r->print('<form method="post" name="changequeue" action="/adm/createuser" />'.
4264: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4265: '<input type="hidden" name="state" value="done" />'.
4266: &Apache::loncommon::start_data_table().
4267: &Apache::loncommon::start_data_table_header_row().
4268: '<th>'.&mt('Action').'</th>'.
4269: '<th>'.&mt('Requestor').'</th>'.
4270: '<th>'.&mt('Section').'</th>'.
4271: '<th>'.&mt('Date requested').'</th>'.
4272: &Apache::loncommon::end_data_table_header_row());
4273: foreach my $item (keys(%requesthash)) {
4274: my ($timestamp,$usec) = split(/:/,$requesthash{$item});
4275: if (exists($queue_by_date{$timestamp})) {
4276: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
4277: push(@{$queue_by_date{$timestamp}},$item.':'.$usec);
4278: }
4279: } else {
4280: @{$queue_by_date{$timestamp}} = ($item.':'.$usec);
4281: }
4282: }
4283: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
4284: my $count = 0;
4285: foreach my $item (@sortedtimes) {
4286: if (ref($queue_by_date{$item}) eq 'ARRAY') {
4287: foreach my $request (sort(@{$queue_by_date{$item}})) {
4288: my ($puname,$pudom,$pusec) = split(/:/,$request);
4289: my $showsec = $pusec;
4290: if ($showsec eq '') {
4291: $showsec = &mt('none');
4292: }
4293: my $namelink = &Apache::loncommon::aboutmewrapper(
4294: &Apache::loncommon::plainname($puname,$pudom),
4295: $puname,$pudom);
4296: $r->print(&Apache::loncommon::start_data_table_row().
4297: '<td><span class="LC_nobreak"><label>'.
4298: '<input type="checkbox" value="'.$count.':'.$puname.':'.$pudom.':'.$pusec.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
4299: '<span class="LC_nobreak"><label>'.
4300: '<input type="checkbox" value="'.$puname.':'.$pudom.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
4301: '<td>'.$namelink.'</td>'.
4302: '<td>'.$showsec.'</td>'.
4303: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
4304: &Apache::loncommon::end_data_table_row());
4305: $count ++;
4306: }
4307: }
4308: }
4309: $r->print(&Apache::loncommon::end_data_table().
4310: '<input type="submit" name="processqueue" value="'.&mt('Save').'" /></form>');
4311: } else {
4312: $r->print(&mt('There are currently no enrollment requests.'));
4313: }
4314: return;
4315: }
4316:
4317: sub update_selfenroll_queue {
4318: my ($r,$context,$permission,$cid,$cnum,$cdom) = @_;
4319: my @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
4320: my @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
4321: my $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
4322: my $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
4323: my $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4324: my $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4325: my $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4326: my $namespace = 'selfenrollrequests';
4327: my ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
4328: my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
4329: my $coursedesc = $env{'course.'.$cid.'.description'};
4330: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
4331: my $hostname = &Apache::lonnet::hostname($chome);
4332: my $protocol = $Apache::lonnet::protocol{$chome};
4333: $protocol = 'http' if ($protocol ne 'https');
1.280 raeburn 4334: my (@existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,
4335: @enrollerrors,@warn_approves,@warn_rejects);
1.277 raeburn 4336: my $now = time;
4337: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
4338: my $approvedmsg = [{
4339: mt => 'Your request for enrollment has been approved.',
4340: },
4341: {
4342: mt => 'Visit [_1], to log-in and access the course',
4343: args => [$protocol.'://'.$hostname],
4344: }];
4345:
4346: my $rejectedmsg = [{
4347: mt => 'Your request for enrollment has not been approved.',
4348: }];
4349: foreach my $item (sort {$a <=> $b} @approvals) {
4350: my ($num,$uname,$udom,$usec) = split(/:/,$item);
4351: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
4352: if ($uhome ne 'no_host') {
4353: if (exists($requesthash{$uname.':'.$udom})) {
4354:
4355: if (exists($classlist->{$uname.':'.$udom})) {
4356: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
4357: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
4358: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
4359: push(@existing,$uname.':'.$udom);
4360: next;
4361: }
4362: }
4363: }
4364: } else {
4365: push(@missingreq,$uname.':'.$udom);
4366: next;
4367: }
4368: if (!grep(/^\Q$item\E$/,@rejections)) {
4369: if ($limit eq 'allstudents') {
4370: if ($stucounts->{$limit} >= $cap) {
4371: push(@limitexceeded,$uname.':'.$udom);
4372: last;
4373: }
4374: } elsif ($limit eq 'selfenrolled') {
4375: if ($stucounts->{$limit} >= $cap) {
4376: push(@limitexceeded,$uname.':'.$udom);
4377: last;
4378: }
4379: }
4380: my $result =
4381: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
4382: if ($result eq 'ok') {
4383: push(@enrolled,$uname.':'.$udom);
4384: $stucounts->{'allstudents'} ++;
4385: $stucounts->{'selfenrolled'} ++;
4386: &Apache::selfenroll::send_notification($uname.':'.$udom,$approvedmsg,$cid,
4387: $coursedesc,$now,'enroller',$sender);
1.280 raeburn 4388: my %userrequest = (
4389: $cdom.'_'.$cnum => {
4390: timestamp => $now,
4391: section => $usec,
4392: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
4393: status => 'approved',
4394: }
4395: );
4396: my $userresult =
4397: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
4398: if ($userresult ne 'ok') {
4399: push(@warn_approves,$uname.':'.$udom);
4400: }
1.277 raeburn 4401: } else {
4402: push(@enrollerrors,$uname.':'.$udom);
4403: }
4404: }
4405: } else {
4406: push(@invalidusers,$uname.':'.$udom);
4407: }
4408: }
4409: my @changes = (@enrolled,@rejections);
4410: if (@rejections) {
4411: foreach my $user (@rejections) {
4412: &Apache::selfenroll::send_notification($user,$rejectedmsg,$cid,
4413: $coursedesc,$now,'enroller',$sender);
1.280 raeburn 4414: my ($uname,$udom) = split(/:/,$user);
4415: my %userrequest = (
4416: $cdom.'_'.$cnum => {
4417: timestamp => $now,
4418: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
4419: status => 'rejected',
4420: }
4421: );
4422: my $userresult =
4423: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
4424: if ($userresult ne 'ok') {
4425: push(@warn_rejects,$user);
4426: }
1.277 raeburn 4427: }
4428: }
4429: if (@changes) {
4430: my $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
4431: if ($delresult eq 'ok') {
4432: my $namelink =
4433: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
4434: my $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
4435: my ($approvedlist,$rejectedlist);
1.279 raeburn 4436: if (@enrolled) {
1.277 raeburn 4437: $approvedlist = join("\n",@enrolled);
4438: $r->print('<p>'.&mt('The following were enrolled in the course:').'<ul>');
4439: foreach my $user (@enrolled) {
4440: my ($uname,$udom) = split(/:/,$user);
4441: my $userlink =
4442: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
4443: $r->print('<li>'.$userlink.'</li>');
4444: }
4445: $r->print('</ul></p>');
4446: }
4447: if (@rejections) {
4448: $rejectedlist = join("\n",@rejections);
4449: $r->print('<p>'.&mt('The following enrollment requests were rejected:').'<ul>');
4450: foreach my $user (@rejections) {
4451: $r->print('<li>'.$user.'</li>');
4452: }
4453: $r->print('</ul></p>');
4454: }
4455: &Apache::selfenroll::send_notification($notifylist,$chgmsg,$cid,
4456: $coursedesc,$now,'managers',
4457: $sender,$approvedlist,$rejectedlist);
4458: }
4459: }
4460: if (@existing) {
4461: $r->print('<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>');
4462: foreach my $user (@existing) {
4463: $r->print('<li>'.$user.'</li>');
4464: }
4465: $r->print('</ul></p>');
4466: }
4467: if (@missingreq) {
4468: $r->print('<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>');
4469: foreach my $user (@missingreq) {
4470: $r->print('<li>'.$user.'</li>');
4471: }
4472: $r->print('</ul></p>');
4473: }
4474: if (@invalidusers) {
4475: $r->print('<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>');
4476: foreach my $user (@invalidusers) {
4477: $r->print('<li>'.$user.'</li>');
4478: }
4479: $r->print('</ul></p>');
4480: }
4481: if (@limitexceeded) {
4482: $r->print('<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>');
4483: foreach my $user (@limitexceeded) {
4484: $r->print('<li>'.$user.'</li>');
4485: }
4486: $r->print('</ul></p>');
4487: }
4488: if (@enrollerrors) {
4489: $r->print('<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>');
4490: foreach my $user (@enrollerrors) {
4491: $r->print('<li>'.$user.'</li>');
4492: }
4493: $r->print('</ul></p>');
4494: }
1.280 raeburn 4495: if (@warn_approves) {
4496: $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
4497: foreach my $user (@warn_approves) {
4498: $r->print('<li>'.$user.'</li>');
4499: }
4500: $r->print('</ul></p>');
4501: }
4502: if (@warn_rejects) {
4503: $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
4504: foreach my $user (@warn_rejects) {
4505: $r->print('<li>'.$user.'</li>');
4506: }
4507: $r->print('</ul></p>');
4508: }
1.277 raeburn 4509: return;
4510: }
4511:
4512: sub get_student_counts {
4513: my ($cdom,$cnum) = @_;
4514: my (%idx,%stucounts);
4515: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
4516: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
4517: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
4518: while (my ($student,$data) = each(%$classlist)) {
4519: if (($data->[$idx{'status'}] eq 'Active') ||
4520: ($data->[$idx{'status'}] eq 'Future')) {
4521: if ($data->[$idx{'type'}] eq 'selfenroll') {
4522: $stucounts{'selfenroll'} ++;
4523: }
4524: $stucounts{'allstudents'} ++;
4525: }
4526: }
4527: return (\%stucounts,\%idx,$classlist);
4528: }
4529:
1.256 raeburn 4530: sub visible_in_cat {
4531: my ($cdom,$cnum) = @_;
4532: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4533: my ($cathash,%settable,@vismsgs,$cansetvis);
4534: my %visactions = &Apache::lonlocal::texthash(
4535: vis => 'Your course currently appears in the Course Catalog for this domain.',
4536: 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.',
4537: miss => 'Your course does not currently appear in the Course Catalog for this domain.',
4538: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4539: 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 4540: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4541: take => 'Take the following action to ensure the course appears in the Catalog:',
4542: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4543: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4544: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4545: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4546: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4547: 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',
4548: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4549: );
1.261 raeburn 4550: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4551: $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>"');
4552: $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 4553: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4554: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4555: $settable{'togglecats'} = 1;
4556: }
4557: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4558: $settable{'categorize'} = 1;
4559: }
4560: $cathash = $domconf{'coursecategories'}{'cats'};
4561: }
1.260 raeburn 4562: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4563: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4564: } elsif ($settable{'togglecats'}) {
4565: $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 4566: } elsif ($settable{'categorize'}) {
1.256 raeburn 4567: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4568: } else {
4569: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4570: }
4571:
4572: my %currsettings =
4573: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4574: $cdom,$cnum);
4575: my $visible = 0;
4576: if ($currsettings{'internal.coursecode'} ne '') {
4577: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4578: $cathash = $domconf{'coursecategories'}{'cats'};
4579: if (ref($cathash) eq 'HASH') {
4580: if ($cathash->{'instcode::0'} eq '') {
4581: push(@vismsgs,'dc_addinst');
4582: } else {
4583: $visible = 1;
4584: }
4585: } else {
4586: $visible = 1;
4587: }
4588: } else {
4589: $visible = 1;
4590: }
4591: } else {
4592: if (ref($cathash) eq 'HASH') {
4593: if ($cathash->{'instcode::0'} ne '') {
4594: push(@vismsgs,'dc_instcode');
4595: }
4596: } else {
4597: push(@vismsgs,'dc_instcode');
4598: }
4599: }
4600: if ($currsettings{'categories'} ne '') {
4601: my $cathash;
4602: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4603: $cathash = $domconf{'coursecategories'}{'cats'};
4604: if (ref($cathash) eq 'HASH') {
4605: if (keys(%{$cathash}) == 0) {
4606: push(@vismsgs,'dc_catalog');
4607: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
4608: push(@vismsgs,'dc_categories');
4609: } else {
4610: my @currcategories = split('&',$currsettings{'categories'});
4611: my $matched = 0;
4612: foreach my $cat (@currcategories) {
4613: if ($cathash->{$cat} ne '') {
4614: $visible = 1;
4615: $matched = 1;
4616: last;
4617: }
4618: }
4619: if (!$matched) {
1.260 raeburn 4620: if ($settable{'categorize'}) {
1.256 raeburn 4621: push(@vismsgs,'chgcat');
4622: } else {
4623: push(@vismsgs,'dc_chgcat');
4624: }
4625: }
4626: }
4627: }
4628: }
4629: } else {
4630: if (ref($cathash) eq 'HASH') {
4631: if ((keys(%{$cathash}) > 1) ||
4632: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 4633: if ($settable{'categorize'}) {
1.256 raeburn 4634: push(@vismsgs,'addcat');
4635: } else {
4636: push(@vismsgs,'dc_addcat');
4637: }
4638: }
4639: }
4640: }
4641: if ($currsettings{'hidefromcat'} eq 'yes') {
4642: $visible = 0;
4643: if ($settable{'togglecats'}) {
4644: unshift(@vismsgs,'unhide');
4645: } else {
4646: unshift(@vismsgs,'dc_unhide')
4647: }
4648: }
4649: return ($visible,$cansetvis,\@vismsgs,\%visactions);
4650: }
4651:
1.241 raeburn 4652: sub new_selfenroll_dom_row {
4653: my ($newdom,$num) = @_;
4654: my $domdesc = &Apache::lonnet::domain($newdom);
4655: my $output;
4656: if ($domdesc ne '') {
4657: $output .= &Apache::loncommon::start_data_table_row()
4658: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
4659: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 4660: .'" value="'.$newdom.'" /></span><br />'
4661: .'<span class="LC_nobreak"><label><input type="checkbox" '
4662: .'name="selfenroll_activate" value="'.$num.'" '
4663: .'onchange="javascript:update_types('
4664: ."'selfenroll_activate','$num'".');" />'
4665: .&mt('Activate').'</label></span></td>';
1.241 raeburn 4666: my @currinsttypes;
4667: $output .= '<td>'.&mt('User types:').'<br />'
4668: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
4669: .&Apache::loncommon::end_data_table_row();
4670: }
4671: return $output;
4672: }
4673:
4674: sub selfenroll_inst_types {
4675: my ($num,$currdom,$currinsttypes) = @_;
4676: my $output;
4677: my $numinrow = 4;
4678: my $count = 0;
4679: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 4680: my $othervalue = 'any';
1.241 raeburn 4681: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 4682: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 4683: $othervalue = 'other';
4684: }
1.241 raeburn 4685: $output .= '<table><tr>';
4686: foreach my $type (@{$types}) {
4687: if (($count > 0) && ($count%$numinrow == 0)) {
4688: $output .= '</tr><tr>';
4689: }
4690: if (defined($usertypes->{$type})) {
1.257 raeburn 4691: my $esc_type = &escape($type);
1.241 raeburn 4692: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 4693: $esc_type.'" ';
1.241 raeburn 4694: if (ref($currinsttypes) eq 'ARRAY') {
4695: if (@{$currinsttypes} > 0) {
1.249 raeburn 4696: if (grep(/^any$/,@{$currinsttypes})) {
4697: $output .= 'checked="checked"';
1.257 raeburn 4698: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 4699: $output .= 'checked="checked"';
4700: }
1.249 raeburn 4701: } else {
4702: $output .= 'checked="checked"';
1.241 raeburn 4703: }
4704: }
4705: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
4706: }
4707: $count ++;
4708: }
4709: if (($count > 0) && ($count%$numinrow == 0)) {
4710: $output .= '</tr><tr>';
4711: }
1.249 raeburn 4712: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 4713: if (ref($currinsttypes) eq 'ARRAY') {
4714: if (@{$currinsttypes} > 0) {
1.249 raeburn 4715: if (grep(/^any$/,@{$currinsttypes})) {
4716: $output .= ' checked="checked"';
4717: } elsif ($othervalue eq 'other') {
4718: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
4719: $output .= ' checked="checked"';
4720: }
1.241 raeburn 4721: }
1.249 raeburn 4722: } else {
4723: $output .= ' checked="checked"';
1.241 raeburn 4724: }
1.249 raeburn 4725: } else {
4726: $output .= ' checked="checked"';
1.241 raeburn 4727: }
4728: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
4729: }
4730: return $output;
4731: }
4732:
1.237 raeburn 4733: sub selfenroll_date_forms {
4734: my ($startform,$endform) = @_;
4735: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 4736: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 4737: 'LC_oddrow_value')."\n".
4738: $startform."\n".
4739: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 4740: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 4741: 'LC_oddrow_value')."\n".
4742: $endform."\n".
4743: &Apache::lonhtmlcommon::row_closure(1).
4744: &Apache::lonhtmlcommon::end_pick_box();
4745: return $output;
4746: }
4747:
1.239 raeburn 4748: sub print_userchangelogs_display {
4749: my ($r,$context,$permission) = @_;
4750: my $formname = 'roleslog';
4751: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4752: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4753: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
4754: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
4755:
4756: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
4757: my %saveable_parameters = ('show' => 'scalar',);
4758: &Apache::loncommon::store_course_settings('roles_log',
4759: \%saveable_parameters);
4760: &Apache::loncommon::restore_course_settings('roles_log',
4761: \%saveable_parameters);
4762: # set defaults
4763: my $now = time();
4764: my $defstart = $now - (7*24*3600); #7 days ago
4765: my %defaults = (
4766: page => '1',
4767: show => '10',
4768: role => 'any',
4769: chgcontext => 'any',
4770: rolelog_start_date => $defstart,
4771: rolelog_end_date => $now,
4772: );
4773: my $more_records = 0;
4774:
4775: # set current
4776: my %curr;
4777: foreach my $item ('show','page','role','chgcontext') {
4778: $curr{$item} = $env{'form.'.$item};
4779: }
4780: my ($startdate,$enddate) =
4781: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
4782: $curr{'rolelog_start_date'} = $startdate;
4783: $curr{'rolelog_end_date'} = $enddate;
4784: foreach my $key (keys(%defaults)) {
4785: if ($curr{$key} eq '') {
4786: $curr{$key} = $defaults{$key};
4787: }
4788: }
1.248 raeburn 4789: my (%whodunit,%changed,$version);
4790: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
4791: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
1.239 raeburn 4792: my $showntablehdr = 0;
4793: my $tablehdr = &Apache::loncommon::start_data_table().
4794: &Apache::loncommon::start_data_table_header_row().
4795: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
4796: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
4797: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
4798: &Apache::loncommon::end_data_table_header_row();
4799: my ($minshown,$maxshown);
1.255 raeburn 4800: $minshown = 1;
1.239 raeburn 4801: my $count = 0;
4802: if ($curr{'show'} ne &mt('all')) {
4803: $maxshown = $curr{'page'} * $curr{'show'};
4804: if ($curr{'page'} > 1) {
4805: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
4806: }
4807: }
4808: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
4809: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
4810: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
4811: if ($curr{'show'} ne &mt('all')) {
4812: if ($count >= $curr{'page'} * $curr{'show'}) {
4813: $more_records = 1;
4814: last;
4815: }
4816: }
4817: if ($curr{'role'} ne 'any') {
4818: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
4819: }
4820: if ($curr{'chgcontext'} ne 'any') {
4821: if ($curr{'chgcontext'} eq 'selfenroll') {
4822: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
4823: } else {
4824: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
4825: }
4826: }
4827: $count ++;
4828: next if ($count < $minshown);
4829: if (!$showntablehdr) {
4830: $r->print($tablehdr);
4831: $showntablehdr = 1;
4832: }
4833: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
4834: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
4835: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
4836: }
4837: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
4838: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
4839: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
4840: }
4841: my $sec = $roleslog{$id}{'logentry'}{'section'};
4842: if ($sec eq '') {
4843: $sec = &mt('None');
4844: }
4845: my ($rolestart,$roleend);
4846: if ($roleslog{$id}{'delflag'}) {
4847: $rolestart = &mt('deleted');
4848: $roleend = &mt('deleted');
4849: } else {
4850: $rolestart = $roleslog{$id}{'logentry'}{'start'};
4851: $roleend = $roleslog{$id}{'logentry'}{'end'};
4852: if ($rolestart eq '' || $rolestart == 0) {
4853: $rolestart = &mt('No start date');
4854: } else {
4855: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
4856: }
4857: if ($roleend eq '' || $roleend == 0) {
4858: $roleend = &mt('No end date');
4859: } else {
4860: $roleend = &Apache::lonlocal::locallocaltime($roleend);
4861: }
4862: }
4863: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
4864: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
4865: $chgcontext = 'selfenroll';
4866: }
4867: my %lt = &rolechg_contexts();
4868: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
4869: $chgcontext = $lt{$chgcontext};
4870: }
4871: $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");
4872: }
4873: if ($showntablehdr) {
4874: $r->print(&Apache::loncommon::end_data_table().'<br />');
4875: if (($curr{'page'} > 1) || ($more_records)) {
4876: $r->print('<table><tr>');
4877: if ($curr{'page'} > 1) {
4878: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
4879: }
4880: if ($more_records) {
4881: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
4882: }
4883: $r->print('</tr></table>');
4884: $r->print(<<"ENDSCRIPT");
4885: <script type="text/javascript">
4886: function chgPage(caller) {
4887: if (caller == 'previous') {
4888: document.$formname.page.value --;
4889: }
4890: if (caller == 'next') {
4891: document.$formname.page.value ++;
4892: }
4893: document.$formname.submit();
4894: return;
4895: }
4896: </script>
4897: ENDSCRIPT
4898: }
4899: } else {
4900: $r->print(&mt('There are no records to display'));
4901: }
4902: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
4903: '<input type="hidden" name="action" value="changelogs" /></form>');
4904: return;
4905: }
4906:
4907: sub role_display_filter {
1.248 raeburn 4908: my ($formname,$cdom,$cnum,$curr,$version) = @_;
1.239 raeburn 4909: my $context = 'course';
4910: my $nolink = 1;
4911: my $output = '<table><tr><td valign="top">'.
4912: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
4913: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
4914: (&mt('all'),5,10,20,50,100,1000,10000)).
4915: '</td><td> </td>';
4916: my $startform =
4917: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
4918: $curr->{'rolelog_start_date'},undef,
4919: undef,undef,undef,undef,undef,undef,$nolink);
4920: my $endform =
4921: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
4922: $curr->{'rolelog_end_date'},undef,
4923: undef,undef,undef,undef,undef,undef,$nolink);
4924: my %lt = &rolechg_contexts();
4925: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
4926: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
4927: $endform.'</td></tr></table></td><td> </td>'.
4928: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
4929: '<select name="role"><option value="any"';
4930: if ($curr->{'role'} eq 'any') {
4931: $output .= ' selected="selected"';
4932: }
4933: $output .= '>'.&mt('Any').'</option>'."\n";
4934: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
4935: foreach my $role (@roles) {
4936: my $plrole;
4937: if ($role eq 'cr') {
4938: $plrole = &mt('Custom Role');
4939: } else {
4940: $plrole=&Apache::lonnet::plaintext($role);
4941: }
4942: my $selstr = '';
4943: if ($role eq $curr->{'role'}) {
4944: $selstr = ' selected="selected"';
4945: }
4946: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
4947: }
4948: $output .= '</select></td><td> </td><td valign="top"><b>'.
4949: &mt('Context:').'</b><br /><select name="chgcontext">';
4950: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
4951: my $selstr = '';
4952: if ($curr->{'chgcontext'} eq $chgtype) {
4953: $output .= $selstr = ' selected="selected"';
4954: }
4955: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
4956: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
4957: }
4958: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 4959: }
1.239 raeburn 4960: $output .= '</select></td><td> </td><td valign="middle"><input type="submit" value="'.
1.248 raeburn 4961: &mt('Update Display').'" /></tr></table>'.
4962: '<span class="LC_roleslog_note">'.
4963: &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
4964: if ($version) {
4965: $output .= ' '.&mt('This server is version [_3].','<b>','</b>',$version); }
1.296 bisitz 4966: $output .= '</span><hr /><br />';
1.239 raeburn 4967: return $output;
4968: }
4969:
4970: sub rolechg_contexts {
4971: my %lt = &Apache::lonlocal::texthash (
4972: any => 'Any',
4973: auto => 'Automated enrollment',
4974: updatenow => 'Roster Update',
4975: createcourse => 'Course Creation',
4976: course => 'User Management in course',
4977: domain => 'User Management in domain',
4978: selfenroll => 'Self-enrolled',
4979: );
4980: return %lt;
4981: }
4982:
1.27 matthew 4983: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 4984: sub user_search_result {
1.221 raeburn 4985: my ($context,$srch) = @_;
1.160 raeburn 4986: my %allhomes;
4987: my %inst_matches;
4988: my %srch_results;
1.181 raeburn 4989: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 4990: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 4991: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 4992: $response = &mt('Invalid search.');
4993: }
4994: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
4995: $response = &mt('Invalid search.');
4996: }
1.177 raeburn 4997: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 4998: $response = &mt('Invalid search.');
4999: }
5000: if ($srch->{'srchterm'} eq '') {
5001: $response = &mt('You must enter a search term.');
5002: }
1.183 raeburn 5003: if ($srch->{'srchterm'} =~ /^\s+$/) {
5004: $response = &mt('Your search term must contain more than just spaces.');
5005: }
1.160 raeburn 5006: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5007: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5008: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5009: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5010: }
5011: }
5012: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5013: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5014: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5015: my $unamecheck = $srch->{'srchterm'};
5016: if ($srch->{'srchtype'} eq 'contains') {
5017: if ($unamecheck !~ /^\w/) {
5018: $unamecheck = 'a'.$unamecheck;
5019: }
5020: }
5021: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5022: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5023: }
1.160 raeburn 5024: }
5025: }
1.180 raeburn 5026: if ($response ne '') {
5027: $response = '<span class="LC_warning">'.$response.'</span>';
5028: }
1.160 raeburn 5029: if ($srch->{'srchin'} eq 'instd') {
5030: my $instd_chk = &directorysrch_check($srch);
5031: if ($instd_chk ne 'ok') {
1.180 raeburn 5032: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5033: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5034: }
5035: }
5036: if ($response ne '') {
1.180 raeburn 5037: return ($currstate,$response);
1.160 raeburn 5038: }
5039: if ($srch->{'srchby'} eq 'uname') {
5040: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5041: if ($env{'form.forcenew'}) {
5042: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5043: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5044: if ($uhome eq 'no_host') {
5045: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5046: my $showdom = &display_domain_info($env{'request.role.domain'});
5047: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5048: } else {
1.179 raeburn 5049: $currstate = 'modify';
1.160 raeburn 5050: }
5051: } else {
1.179 raeburn 5052: $currstate = 'modify';
1.160 raeburn 5053: }
5054: } else {
5055: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 5056: if ($srch->{'srchtype'} eq 'exact') {
5057: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5058: if ($uhome eq 'no_host') {
1.179 raeburn 5059: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5060: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5061: } else {
1.179 raeburn 5062: $currstate = 'modify';
1.162 raeburn 5063: }
5064: } else {
5065: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5066: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5067: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5068: }
5069: } else {
1.167 albertel 5070: my $courseusers = &get_courseusers();
1.162 raeburn 5071: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 5072: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 5073: $currstate = 'modify';
1.162 raeburn 5074: } else {
1.179 raeburn 5075: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5076: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5077: }
1.160 raeburn 5078: } else {
1.167 albertel 5079: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 5080: my ($cuname,$cudomain) = split(/:/,$user);
5081: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 5082: my $matched = 0;
5083: if ($srch->{'srchtype'} eq 'begins') {
5084: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
5085: $matched = 1;
5086: }
5087: } else {
5088: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
5089: $matched = 1;
5090: }
5091: }
5092: if ($matched) {
1.167 albertel 5093: $srch_results{$user} =
5094: {&Apache::lonnet::get('environment',
5095: ['firstname',
5096: 'lastname',
1.194 albertel 5097: 'permanentemail'],
5098: $cudomain,$cuname)};
1.162 raeburn 5099: }
5100: }
5101: }
1.179 raeburn 5102: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5103: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5104: }
5105: }
5106: }
5107: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5108: $currstate = 'query';
1.160 raeburn 5109: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5110: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5111: if ($dirsrchres eq 'ok') {
5112: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5113: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5114: } else {
5115: my $showdom = &display_domain_info($srch->{'srchdomain'});
5116: $response = '<span class="LC_warning">'.
5117: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5118: '</span><br />'.
5119: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5120: '<br /><br />';
5121: }
1.160 raeburn 5122: }
5123: } else {
5124: if ($srch->{'srchin'} eq 'dom') {
5125: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5126: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5127: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5128: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 5129: my $courseusers = &get_courseusers();
5130: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 5131: my ($uname,$udom) = split(/:/,$user);
5132: my %names = &Apache::loncommon::getnames($uname,$udom);
5133: my %emails = &Apache::loncommon::getemails($uname,$udom);
5134: if ($srch->{'srchby'} eq 'lastname') {
5135: if ((($srch->{'srchtype'} eq 'exact') &&
5136: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 5137: (($srch->{'srchtype'} eq 'begins') &&
5138: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 5139: (($srch->{'srchtype'} eq 'contains') &&
5140: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
5141: $srch_results{$user} = {firstname => $names{'firstname'},
5142: lastname => $names{'lastname'},
5143: permanentemail => $emails{'permanentemail'},
5144: };
5145: }
5146: } elsif ($srch->{'srchby'} eq 'lastfirst') {
5147: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 5148: $srchlast =~ s/\s+$//;
5149: $srchfirst =~ s/^\s+//;
1.160 raeburn 5150: if ($srch->{'srchtype'} eq 'exact') {
5151: if (($names{'lastname'} eq $srchlast) &&
5152: ($names{'firstname'} eq $srchfirst)) {
5153: $srch_results{$user} = {firstname => $names{'firstname'},
5154: lastname => $names{'lastname'},
5155: permanentemail => $emails{'permanentemail'},
5156:
5157: };
5158: }
1.177 raeburn 5159: } elsif ($srch->{'srchtype'} eq 'begins') {
5160: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5161: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5162: $srch_results{$user} = {firstname => $names{'firstname'},
5163: lastname => $names{'lastname'},
5164: permanentemail => $emails{'permanentemail'},
5165: };
5166: }
5167: } else {
1.160 raeburn 5168: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5169: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5170: $srch_results{$user} = {firstname => $names{'firstname'},
5171: lastname => $names{'lastname'},
5172: permanentemail => $emails{'permanentemail'},
5173: };
5174: }
5175: }
5176: }
5177: }
1.179 raeburn 5178: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5179: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5180: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5181: $currstate = 'query';
1.160 raeburn 5182: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5183: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5184: if ($dirsrchres eq 'ok') {
5185: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5186: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5187: } else {
5188: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5189: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5190: '</span><br />'.
5191: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5192: '<br /><br />';
5193: }
1.160 raeburn 5194: }
5195: }
1.179 raeburn 5196: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5197: }
5198:
5199: sub directorysrch_check {
5200: my ($srch) = @_;
5201: my $can_search = 0;
5202: my $response;
5203: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5204: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5205: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5206: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5207: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5208: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5209: }
5210: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5211: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5212: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5213: }
5214: my @usertypes = split(/:/,$env{'environment.inststatus'});
5215: if (!@usertypes) {
5216: push(@usertypes,'default');
5217: }
5218: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5219: foreach my $type (@usertypes) {
5220: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5221: $can_search = 1;
5222: last;
5223: }
5224: }
5225: }
5226: if (!$can_search) {
5227: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5228: my @longtypes;
5229: foreach my $item (@usertypes) {
1.229 raeburn 5230: if (defined($insttypes->{$item})) {
5231: push (@longtypes,$insttypes->{$item});
5232: } elsif ($item eq 'default') {
5233: push (@longtypes,&mt('other'));
5234: }
1.160 raeburn 5235: }
5236: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5237: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5238: }
1.160 raeburn 5239: } else {
5240: $can_search = 1;
5241: }
5242: } else {
1.180 raeburn 5243: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5244: }
5245: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5246: uname => 'username',
1.160 raeburn 5247: lastfirst => 'last name, first name',
1.167 albertel 5248: lastname => 'last name',
1.172 raeburn 5249: contains => 'contains',
1.178 raeburn 5250: exact => 'as exact match to',
5251: begins => 'begins with',
1.160 raeburn 5252: );
5253: if ($can_search) {
5254: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5255: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5256: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5257: }
5258: } else {
1.180 raeburn 5259: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5260: }
5261: }
5262: if ($can_search) {
1.178 raeburn 5263: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5264: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5265: return 'ok';
5266: } else {
1.180 raeburn 5267: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5268: }
5269: } else {
5270: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5271: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5272: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5273: return 'ok';
5274: } else {
1.180 raeburn 5275: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5276: }
1.160 raeburn 5277: }
5278: }
5279: }
5280:
5281: sub get_courseusers {
5282: my %advhash;
1.167 albertel 5283: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5284: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5285: foreach my $role (sort(keys(%coursepersonnel))) {
5286: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5287: if (!exists($classlist->{$user})) {
5288: $classlist->{$user} = [];
5289: }
1.160 raeburn 5290: }
5291: }
1.167 albertel 5292: return $classlist;
1.160 raeburn 5293: }
5294:
5295: sub build_search_response {
1.221 raeburn 5296: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5297: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5298: my %names = (
5299: 'uname' => 'username',
5300: 'lastname' => 'last name',
5301: 'lastfirst' => 'last name, first name',
5302: 'crs' => 'this course',
1.180 raeburn 5303: 'dom' => 'LON-CAPA domain: ',
5304: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5305: );
5306:
5307: my %single = (
1.180 raeburn 5308: begins => 'A match',
1.160 raeburn 5309: contains => 'A match',
1.180 raeburn 5310: exact => 'An exact match',
1.160 raeburn 5311: );
5312: my %nomatch = (
1.180 raeburn 5313: begins => 'No match',
1.160 raeburn 5314: contains => 'No match',
1.180 raeburn 5315: exact => 'No exact match',
1.160 raeburn 5316: );
5317: if (keys(%srch_results) > 1) {
1.179 raeburn 5318: $currstate = 'select';
1.160 raeburn 5319: } else {
5320: if (keys(%srch_results) == 1) {
1.179 raeburn 5321: $currstate = 'modify';
1.180 raeburn 5322: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5323: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5324: $response .= &display_domain_info($srch->{'srchdomain'});
5325: }
1.160 raeburn 5326: } else {
1.180 raeburn 5327: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
5328: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5329: $response .= &display_domain_info($srch->{'srchdomain'});
5330: }
5331: $response .= '</span>';
1.160 raeburn 5332: if ($srch->{'srchin'} ne 'alc') {
5333: $forcenewuser = 1;
5334: my $cansrchinst = 0;
5335: if ($srch->{'srchdomain'}) {
5336: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5337: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5338: if ($domconfig{'directorysrch'}{'available'}) {
5339: $cansrchinst = 1;
5340: }
5341: }
5342: }
1.180 raeburn 5343: if ((($srch->{'srchby'} eq 'lastfirst') ||
5344: ($srch->{'srchby'} eq 'lastname')) &&
5345: ($srch->{'srchin'} eq 'dom')) {
5346: if ($cansrchinst) {
5347: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5348: }
5349: }
1.180 raeburn 5350: if ($srch->{'srchin'} eq 'crs') {
5351: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5352: }
5353: }
5354: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 5355: my $cancreate =
5356: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
5357: if ($cancreate) {
5358: my $showdom = &display_domain_info($env{'request.role.domain'});
1.266 bisitz 5359: $response .= '<br /><br />'
5360: .'<b>'.&mt('To add a new user:').'</b>'
5361: .'<br />'
5362: .&mt("(You can only create new users in your current role's domain - [_1])"
5363: ,'<span class="LC_cusr_emph">'.$env{'request.role.domain'}.'</span>')
5364: .'<ul><li>'
5365: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5366: .'</li><li>'
5367: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5368: .'</li><li>'
5369: .&mt('Provide the proposed username')
5370: .'</li><li>'
5371: .&mt("Click 'Search'")
5372: .'</li></ul><br />';
1.221 raeburn 5373: } else {
5374: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.266 bisitz 5375: $response .= '<br /><br />'
5376: .&mt("You are not authorized to create new users in your current role's domain - [_1]."
5377: ,'<span class="LC_cusr_emph">'.$env{'request.role.domain'}.'</span>')
5378: .'<br />'
1.292 bisitz 5379: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 5380: ,' <a'.$helplink.'>'
5381: ,'</a>')
5382: .'<br /><br />';
1.221 raeburn 5383: }
1.160 raeburn 5384: }
5385: }
5386: }
1.179 raeburn 5387: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5388: }
5389:
1.180 raeburn 5390: sub display_domain_info {
5391: my ($dom) = @_;
5392: my $output = $dom;
5393: if ($dom ne '') {
5394: my $domdesc = &Apache::lonnet::domain($dom,'description');
5395: if ($domdesc ne '') {
5396: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5397: }
5398: }
5399: return $output;
5400: }
5401:
1.160 raeburn 5402: sub crumb_utilities {
5403: my %elements = (
5404: crtuser => {
5405: srchterm => 'text',
1.172 raeburn 5406: srchin => 'selectbox',
1.160 raeburn 5407: srchby => 'selectbox',
5408: srchtype => 'selectbox',
5409: srchdomain => 'selectbox',
5410: },
1.207 raeburn 5411: crtusername => {
5412: srchterm => 'text',
5413: srchdomain => 'selectbox',
5414: },
1.160 raeburn 5415: docustom => {
5416: rolename => 'selectbox',
5417: newrolename => 'textbox',
5418: },
1.179 raeburn 5419: studentform => {
5420: srchterm => 'text',
5421: srchin => 'selectbox',
5422: srchby => 'selectbox',
5423: srchtype => 'selectbox',
5424: srchdomain => 'selectbox',
5425: },
1.160 raeburn 5426: );
5427:
5428: my $jsback .= qq|
5429: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5430: if (typeof prevphase == 'undefined') {
5431: formname.phase.value = '';
5432: }
5433: else {
5434: formname.phase.value = prevphase;
5435: }
5436: if (typeof prevstate == 'undefined') {
5437: formname.currstate.value = '';
5438: }
5439: else {
5440: formname.currstate.value = prevstate;
5441: }
1.160 raeburn 5442: formname.submit();
5443: }
5444: |;
5445: return ($jsback,\%elements);
5446: }
5447:
1.26 matthew 5448: sub course_level_table {
1.89 raeburn 5449: my (%inccourses) = @_;
1.26 matthew 5450: my $table = '';
1.62 www 5451: # Custom Roles?
5452:
1.190 raeburn 5453: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5454: my %lt=&Apache::lonlocal::texthash(
5455: 'exs' => "Existing sections",
5456: 'new' => "Define new section",
5457: 'ssd' => "Set Start Date",
5458: 'sed' => "Set End Date",
1.131 raeburn 5459: 'crl' => "Course Level",
1.89 raeburn 5460: 'act' => "Activate",
5461: 'rol' => "Role",
5462: 'ext' => "Extent",
1.113 raeburn 5463: 'grs' => "Section",
1.89 raeburn 5464: 'sta' => "Start",
5465: 'end' => "End"
5466: );
1.62 www 5467:
1.135 raeburn 5468: foreach my $protectedcourse (sort( keys(%inccourses))) {
5469: my $thiscourse=$protectedcourse;
1.26 matthew 5470: $thiscourse=~s:_:/:g;
5471: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
5472: my $area=$coursedata{'description'};
1.119 raeburn 5473: my $type=$coursedata{'type'};
1.135 raeburn 5474: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5475: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5476: my %sections_count;
1.101 albertel 5477: if (defined($env{'request.course.id'})) {
5478: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5479: %sections_count =
5480: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5481: }
5482: }
1.213 raeburn 5483: my @roles = &Apache::lonuserutils::roles_by_context('course');
5484: foreach my $role (@roles) {
1.221 raeburn 5485: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 5486: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 5487: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5488: $plrole,\%sections_count,\%lt);
5489: } elsif ($env{'request.course.sec'} ne '') {
5490: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5491: $env{'request.course.sec'})) {
5492: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5493: $plrole,\%sections_count,\%lt);
1.26 matthew 5494: }
5495: }
5496: }
1.221 raeburn 5497: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
5498: foreach my $cust (sort keys %customroles) {
5499: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5500: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5501: $cust,\%sections_count,\%lt);
5502: }
1.62 www 5503: }
1.26 matthew 5504: }
5505: return '' if ($table eq ''); # return nothing if there is nothing
5506: # in the table
1.188 raeburn 5507: my $result;
5508: if (!$env{'request.course.id'}) {
5509: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5510: }
5511: $result .=
1.136 raeburn 5512: &Apache::loncommon::start_data_table().
5513: &Apache::loncommon::start_data_table_header_row().
5514: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5515: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5516: &Apache::loncommon::end_data_table_header_row().
5517: $table.
5518: &Apache::loncommon::end_data_table();
1.26 matthew 5519: return $result;
5520: }
1.88 raeburn 5521:
1.221 raeburn 5522: sub course_level_row {
5523: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5524: my $row = &Apache::loncommon::start_data_table_row().
5525: ' <td><input type="checkbox" name="act_'.
5526: $protectedcourse.'_'.$role.'" /></td>'."\n".
5527: ' <td>'.$plrole.'</td>'."\n".
5528: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 5529: if ($role eq 'cc') {
1.222 raeburn 5530: $row .= '<td> </td>';
1.221 raeburn 5531: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5532: $row .= ' <td><input type="hidden" value="'.
5533: $env{'request.course.sec'}.'" '.
5534: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5535: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5536: } else {
5537: if (ref($sections_count) eq 'HASH') {
5538: my $currsec =
5539: &Apache::lonuserutils::course_sections($sections_count,
5540: $protectedcourse.'_'.$role);
1.222 raeburn 5541: $row .= '<td><table class="LC_createuser">'."\n".
5542: '<tr class="LC_section_row">'."\n".
5543: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
5544: $currsec.'</td>'."\n".
5545: ' <td> </td>'."\n".
5546: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 5547: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
5548: '" value="" />'.
5549: '<input type="hidden" '.
5550: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 5551: '</tr></table></td>'."\n";
1.221 raeburn 5552: } else {
1.222 raeburn 5553: $row .= '<td><input type="text" size="10" '.
5554: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 5555: }
5556: }
1.222 raeburn 5557: $row .= <<ENDTIMEENTRY;
5558: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 5559: <a href=
5560: "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 5561: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 5562: <a href=
5563: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
5564: ENDTIMEENTRY
1.222 raeburn 5565: $row .= &Apache::loncommon::end_data_table_row();
5566: return $row;
1.221 raeburn 5567: }
5568:
1.88 raeburn 5569: sub course_level_dc {
5570: my ($dcdom) = @_;
1.190 raeburn 5571: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 5572: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 5573: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
5574: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 5575: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 5576: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 5577: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
5578: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 5579: my %lt=&Apache::lonlocal::texthash(
5580: 'rol' => "Role",
1.113 raeburn 5581: 'grs' => "Section",
1.88 raeburn 5582: 'exs' => "Existing sections",
5583: 'new' => "Define new section",
5584: 'sta' => "Start",
5585: 'end' => "End",
5586: 'ssd' => "Set Start Date",
5587: 'sed' => "Set End Date"
5588: );
1.131 raeburn 5589: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 5590: &Apache::loncommon::start_data_table().
5591: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 5592: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 5593: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 5594: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 5595: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 5596: '<td><select name="role">'."\n";
1.213 raeburn 5597: foreach my $role (@roles) {
1.135 raeburn 5598: my $plrole=&Apache::lonnet::plaintext($role);
5599: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 5600: }
5601: if ( keys %customroles > 0) {
1.135 raeburn 5602: foreach my $cust (sort keys %customroles) {
1.101 albertel 5603: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 5604: '_'.$env{'user.name'}.'_'.$cust;
5605: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 5606: }
5607: }
5608: $otheritems .= '</select></td><td>'.
5609: '<table border="0" cellspacing="0" cellpadding="0">'.
5610: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
5611: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
5612: '<td> </td>'.
5613: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 5614: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 5615: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 5616: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 5617: '</tr></table></td>';
5618: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 5619: <td><input type="hidden" name="start" value='' />
1.88 raeburn 5620: <a href=
5621: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 5622: <td><input type="hidden" name="end" value='' />
1.88 raeburn 5623: <a href=
5624: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
5625: ENDTIMEENTRY
1.136 raeburn 5626: $otheritems .= &Apache::loncommon::end_data_table_row().
5627: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 5628: return $cb_jscript.$header.$hiddenitems.$otheritems;
5629: }
5630:
1.237 raeburn 5631: sub update_selfenroll_config {
1.241 raeburn 5632: my ($r,$context,$permission) = @_;
1.237 raeburn 5633: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 5634: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 5635: my (%changes,%warning);
5636: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5637: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 5638: my $curr_types;
1.237 raeburn 5639: if (ref($row) eq 'ARRAY') {
5640: foreach my $item (@{$row}) {
5641: if ($item eq 'enroll_dates') {
5642: my (%currenrolldate,%newenrolldate);
5643: foreach my $type ('start','end') {
5644: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
5645: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
5646: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
5647: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
5648: }
5649: }
5650: } elsif ($item eq 'access_dates') {
5651: my (%currdate,%newdate);
5652: foreach my $type ('start','end') {
5653: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
5654: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
5655: if ($newdate{$type} ne $currdate{$type}) {
5656: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
5657: }
5658: }
1.241 raeburn 5659: } elsif ($item eq 'types') {
5660: $curr_types =
5661: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5662: if ($env{'form.selfenroll_all'}) {
5663: if ($curr_types ne '*') {
5664: $changes{'internal.selfenroll_types'} = '*';
5665: } else {
5666: next;
5667: }
5668: } else {
1.249 raeburn 5669: my %currdoms;
1.241 raeburn 5670: my @entries = split(/;/,$curr_types);
5671: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 5672: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 5673: my $newnum = 0;
1.249 raeburn 5674: my @latesttypes;
5675: foreach my $num (@activations) {
5676: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
5677: if (@types > 0) {
1.241 raeburn 5678: @types = sort(@types);
5679: my $typestr = join(',',@types);
1.249 raeburn 5680: my $typedom = $env{'form.selfenroll_dom_'.$num};
5681: $latesttypes[$newnum] = $typedom.':'.$typestr;
5682: $currdoms{$typedom} = 1;
1.241 raeburn 5683: $newnum ++;
5684: }
5685: }
1.249 raeburn 5686: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
5687: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
5688: if (@types > 0) {
5689: @types = sort(@types);
5690: my $typestr = join(',',@types);
5691: my $typedom = $env{'form.selfenroll_dom_'.$j};
5692: $latesttypes[$newnum] = $typedom.':'.$typestr;
5693: $currdoms{$typedom} = 1;
5694: $newnum ++;
5695: }
5696: }
5697: }
5698: if ($env{'form.selfenroll_newdom'} ne '') {
5699: my $typedom = $env{'form.selfenroll_newdom'};
5700: if ((!defined($currdoms{$typedom})) &&
5701: (&Apache::lonnet::domain($typedom) ne '')) {
5702: my $typestr;
5703: my ($othertitle,$usertypes,$types) =
5704: &Apache::loncommon::sorted_inst_types($typedom);
5705: my $othervalue = 'any';
5706: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5707: if (@{$types} > 0) {
1.257 raeburn 5708: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 5709: $othervalue = 'other';
1.258 raeburn 5710: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 5711: }
5712: $typestr = $othervalue;
5713: } else {
5714: $typestr = $othervalue;
5715: }
5716: $latesttypes[$newnum] = $typedom.':'.$typestr;
5717: $newnum ++ ;
5718: }
5719: }
1.241 raeburn 5720: my $selfenroll_types = join(';',@latesttypes);
5721: if ($selfenroll_types ne $curr_types) {
5722: $changes{'internal.selfenroll_types'} = $selfenroll_types;
5723: }
5724: }
1.276 raeburn 5725: } elsif ($item eq 'limit') {
5726: my $newlimit = $env{'form.selfenroll_limit'};
5727: my $newcap = $env{'form.selfenroll_cap'};
5728: $newcap =~s/\s+//g;
5729: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
5730: $currlimit = 'none' if ($currlimit eq '');
5731: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
5732: if ($newlimit ne $currlimit) {
5733: if ($newlimit ne 'none') {
5734: if ($newcap =~ /^\d+$/) {
5735: if ($newcap ne $currcap) {
5736: $changes{'internal.selfenroll_cap'} = $newcap;
5737: }
5738: $changes{'internal.selfenroll_limit'} = $newlimit;
5739: } else {
5740: $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.');
5741: }
5742: } elsif ($currcap ne '') {
5743: $changes{'internal.selfenroll_cap'} = '';
5744: $changes{'internal.selfenroll_limit'} = $newlimit;
5745: }
5746: } elsif ($currlimit ne 'none') {
5747: if ($newcap =~ /^\d+$/) {
5748: if ($newcap ne $currcap) {
5749: $changes{'internal.selfenroll_cap'} = $newcap;
5750: }
5751: } else {
5752: $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.');
5753: }
5754: }
5755: } elsif ($item eq 'approval') {
5756: my (@currnotified,@newnotified);
5757: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
5758: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
5759: if ($currnotifylist ne '') {
5760: @currnotified = split(/,/,$currnotifylist);
5761: @currnotified = sort(@currnotified);
5762: }
5763: my $newapproval = $env{'form.selfenroll_approval'};
5764: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
5765: @newnotified = sort(@newnotified);
5766: if ($newapproval ne $currapproval) {
5767: $changes{'internal.selfenroll_approval'} = $newapproval;
5768: if (!$newapproval) {
5769: if ($currnotifylist ne '') {
5770: $changes{'internal.selfenroll_notifylist'} = '';
5771: }
5772: } else {
5773: my @differences =
1.295 raeburn 5774: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 5775: if (@differences > 0) {
5776: if (@newnotified > 0) {
5777: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
5778: } else {
5779: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
5780: }
5781: }
5782: }
5783: } else {
1.295 raeburn 5784: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 5785: if (@differences > 0) {
5786: if (@newnotified > 0) {
5787: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
5788: } else {
5789: $changes{'internal.selfenroll_notifylist'} = '';
5790: }
5791: }
5792: }
1.237 raeburn 5793: } else {
5794: my $curr_val =
5795: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5796: my $newval = $env{'form.selfenroll_'.$item};
5797: if ($item eq 'section') {
5798: $newval = $env{'form.sections'};
1.241 raeburn 5799: if (defined($curr_groups{$newval})) {
1.237 raeburn 5800: $newval = $curr_val;
5801: $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');
5802: } elsif ($newval eq 'all') {
5803: $newval = $curr_val;
1.274 bisitz 5804: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 5805: }
5806: if ($newval eq '') {
5807: $newval = 'none';
5808: }
5809: }
5810: if ($newval ne $curr_val) {
5811: $changes{'internal.selfenroll_'.$item} = $newval;
5812: }
1.241 raeburn 5813: }
1.237 raeburn 5814: }
5815: if (keys(%warning) > 0) {
5816: foreach my $item (@{$row}) {
5817: if (exists($warning{$item})) {
5818: $r->print($warning{$item}.'<br />');
5819: }
5820: }
5821: }
5822: if (keys(%changes) > 0) {
5823: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
5824: if ($putresult eq 'ok') {
5825: if ((exists($changes{'internal.selfenroll_types'})) ||
5826: (exists($changes{'internal.selfenroll_start_date'})) ||
5827: (exists($changes{'internal.selfenroll_end_date'}))) {
5828: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
5829: $cnum,undef,undef,'Course');
5830: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
5831: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
5832: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
5833: if (exists($changes{'internal.'.$item})) {
5834: $crsinfo{$env{'request.course.id'}}{$item} =
5835: $changes{'internal.'.$item};
5836: }
5837: }
5838: my $crsputresult =
5839: &Apache::lonnet::courseidput($cdom,\%crsinfo,
5840: $chome,'notime');
5841: }
5842: }
5843: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
5844: foreach my $item (@{$row}) {
5845: my $title = $item;
5846: if (ref($lt) eq 'HASH') {
5847: $title = $lt->{$item};
5848: }
5849: if ($item eq 'enroll_dates') {
5850: foreach my $type ('start','end') {
5851: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
5852: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 5853: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 5854: $title,$type,$newdate).'</li>');
5855: }
5856: }
5857: } elsif ($item eq 'access_dates') {
5858: foreach my $type ('start','end') {
5859: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
5860: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 5861: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 5862: $title,$type,$newdate).'</li>');
5863: }
5864: }
1.276 raeburn 5865: } elsif ($item eq 'limit') {
5866: if ((exists($changes{'internal.selfenroll_limit'})) ||
5867: (exists($changes{'internal.selfenroll_cap'}))) {
5868: my ($newval,$newcap);
5869: if ($changes{'internal.selfenroll_cap'} ne '') {
5870: $newcap = $changes{'internal.selfenroll_cap'}
5871: } else {
5872: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
5873: }
5874: if ($changes{'internal.selfenroll_limit'} eq 'none') {
5875: $newval = &mt('No limit');
5876: } elsif ($changes{'internal.selfenroll_limit'} eq
5877: 'allstudents') {
5878: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
5879: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
5880: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
5881: } else {
5882: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
5883: if ($currlimit eq 'allstudents') {
5884: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
5885: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
5886: $newval = &mt('New self-enrollment no longer allowed when total umber of self-enrolled students reaches [_1].',$newcap);
5887: }
5888: }
5889: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
5890: }
5891: } elsif ($item eq 'approval') {
5892: if ((exists($changes{'internal.selfenroll_approval'})) ||
5893: (exists($changes{'internal.selfenroll_notifylist'}))) {
5894: my ($newval,$newnotify);
5895: if (exists($changes{'internal.selfenroll_notifylist'})) {
5896: $newnotify = $changes{'internal.selfenroll_notifylist'};
5897: } else {
5898: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
5899: }
5900: if ($changes{'internal.selfenroll_approval'}) {
5901: $newval = &mt('Yes');
5902: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
5903: $newval = &mt('No');
5904: } else {
5905: my $currapproval =
5906: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
5907: if ($currapproval) {
5908: $newval = &mt('Yes');
5909: } else {
5910: $newval = &mt('No');
5911: }
5912: }
5913: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
5914: if ($newnotify) {
1.277 raeburn 5915: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 5916: } else {
1.277 raeburn 5917: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 5918: }
5919: $r->print('</li>'."\n");
5920: }
1.237 raeburn 5921: } else {
5922: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 5923: my $newval = $changes{'internal.selfenroll_'.$item};
5924: if ($item eq 'types') {
5925: if ($newval eq '') {
5926: $newval = &mt('None');
5927: } elsif ($newval eq '*') {
5928: $newval = &mt('Any user in any domain');
5929: }
1.245 raeburn 5930: } elsif ($item eq 'registered') {
5931: if ($newval eq '1') {
5932: $newval = &mt('Yes');
5933: } elsif ($newval eq '0') {
5934: $newval = &mt('No');
5935: }
1.241 raeburn 5936: }
1.244 bisitz 5937: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 5938: }
5939: }
5940: }
5941: $r->print('</ul>');
5942: my %newenvhash;
5943: foreach my $key (keys(%changes)) {
5944: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
5945: }
1.238 raeburn 5946: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 5947: } else {
5948: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
5949: }
5950: } else {
1.249 raeburn 5951: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 5952: }
5953: } else {
1.249 raeburn 5954: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 5955: }
1.256 raeburn 5956: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5957: if (ref($visactions) eq 'HASH') {
5958: if (!$visible) {
5959: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
5960: '<br />');
5961: if (ref($vismsgs) eq 'ARRAY') {
5962: $r->print('<br />'.$visactions->{'take'}.'<ul>');
5963: foreach my $item (@{$vismsgs}) {
5964: $r->print('<li>'.$visactions->{$item}.'</li>');
5965: }
5966: $r->print('</ul>');
5967: }
5968: $r->print($cansetvis);
5969: }
5970: }
1.237 raeburn 5971: return;
5972: }
5973:
5974: sub get_selfenroll_titles {
1.276 raeburn 5975: my @row = ('types','registered','enroll_dates','access_dates','section',
5976: 'approval','limit');
1.237 raeburn 5977: my %lt = &Apache::lonlocal::texthash (
5978: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 5979: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 5980: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 5981: access_dates => 'Course access dates assigned to self-enrolling users',
5982: section => 'Section assigned to self-enrolling users',
1.276 raeburn 5983: approval => 'Self-enrollment requests need approval?',
5984: limit => 'Enrollment limit',
1.237 raeburn 5985: );
5986: return (\@row,\%lt);
5987: }
5988:
1.27 matthew 5989: #---------------------------------------------- end functions for &phase_two
1.29 matthew 5990:
5991: #--------------------------------- functions for &phase_two and &phase_three
5992:
5993: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 5994:
5995: 1;
5996: __END__
1.2 www 5997:
5998:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>