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