Annotation of loncom/interface/lontiny.pm, revision 1.8.2.3
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Extract domain, courseID, and symb from a shortened URL,
3: # and switch role to a role in designated course.
4: #
1.8.2.3 ! raeburn 5: # $Id: lontiny.pm,v 1.8.2.2 2022/05/27 18:10:44 raeburn Exp $
1.1 raeburn 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29:
30: package Apache::lontiny;
31:
32: use strict;
33: use Apache::Constants qw(:common :http);
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonhtmlcommon;
37: use Apache::lonroles;
1.5 raeburn 38: use Apache::lonuserstate;
39: use Apache::lonnavmaps;
1.1 raeburn 40: use Apache::lonlocal;
41: use LONCAPA qw(:DEFAULT :match);
42:
43: sub handler {
44: my $r = shift;
45: my %user;
46: my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
1.6 raeburn 47: if ($handle ne '') {
1.5 raeburn 48: my $lonidsdir=$r->dir_config('lonIDsDir');
49: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.1 raeburn 50: if ($r->uri =~ m{^/tiny/($match_domain)/(\w+)$}) {
51: my ($cdom,$key) = ($1,$2);
52: if (&Apache::lonnet::domain($cdom) ne '') {
53: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
54: my $tinyurl;
55: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
56: if (defined($cached)) {
57: $tinyurl = $result;
58: } else {
59: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
60: if ($currtiny{$key} ne '') {
61: $tinyurl = $currtiny{$key};
62: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
63: }
64: }
65: if ($tinyurl) {
66: my ($cnum,$symb) = split(/\&/,$tinyurl);
67: if ($cnum =~ /^$match_courseid$/) {
68: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
69: if ($chome ne 'no_host') {
1.8 raeburn 70: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['ttoken']);
1.8.2.3 ! raeburn 71: my ($linkprot,$linkprotuser,$linkprotexit,$ltoken);
! 72: if ($env{'form.ttoken'}) {
! 73: my %link_info = &Apache::lonnet::tmpget($env{'form.ttoken'});
! 74: if ($link_info{'origurl'} eq $r->uri) {
! 75: if ($link_info{'ltoken'}) {
! 76: $ltoken = $link_info{'ltoken'};
! 77: my %ltoken_info = &Apache::lonnet::tmpget($link_info{'ltoken'});
! 78: $linkprot = $ltoken_info{'linkprot'};
! 79: $linkprotuser = $ltoken_info{'linkprotuser'};
! 80: $linkprotexit = $ltoken_info{'linkprotexit'};
! 81: } elsif ($link_info{'linkprot'}) {
! 82: $linkprot = $link_info{'linkprot'};
! 83: if ($link_info{'linkprotuser'}) {
! 84: $linkprotuser = $link_info{'linkprotuser'};
! 85: }
! 86: if ($link_info{'linkprotexit'}) {
! 87: $linkprotexit = $link_info{'linkprotexit'};
! 88: }
! 89: }
! 90: }
! 91: }
1.5 raeburn 92: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1.8 raeburn 93: # Check for ttoken
94: my $newlauncher = &launch_check($r->uri,$symb);
1.5 raeburn 95: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb);
96: if (&Apache::lonnet::is_on_map($url)) {
97: my $realuri;
98: if ((&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) &&
99: (!$env{'request.role.adv'})) {
100: $env{'user.error.msg'}=$r->uri.':bre:1:1:Access to resource denied';
101: return HTTP_NOT_ACCEPTABLE;
102: }
103: if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) &&
104: (!$env{'request.role.adv'})) {
105: $realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url));
106: if (($url =~ /\.sequence$/) &&
107: ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
108: $realuri .= '?navmap=1';
109: } else {
110: $realuri .= '?symb='.&Apache::lonenc::encrypted($symb);
111: }
112: } else {
113: $realuri = &Apache::lonnet::clutter($url);
114: if (($url =~ /\.sequence$/) &&
115: ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
116: $realuri .= '?navmap=1';
117: } else {
118: $realuri .= '?symb='.$symb;
119: }
120: }
121: my $update;
122: # Check if course needs to be re-initialized
1.7 raeburn 123: if ($newlauncher) {
1.5 raeburn 124: $update = 1;
1.7 raeburn 125: } else {
126: my $loncaparev = $r->dir_config('lonVersion');
127: my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
128: if ($result eq 'update') {
129: $update = 1;
130: } elsif (!-e $env{'request.course.fn'}.'.db') {
131: $update = 1;
132: } elsif (!$env{'request.role.adv'}) {
133: my $navmap = Apache::lonnavmaps::navmap->new();
134: if (ref($navmap)) {
135: my $res = $navmap->getBySymb($symb);
136: if (ref($res)) {
137: my ($enc_in_bighash,$enc_in_parm);
138: $enc_in_bighash = $res->encrypted();
139: if (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) {
140: $enc_in_parm = 1;
141: }
142: if ($enc_in_bighash ne $enc_in_parm) {
143: $update = 1;
144: }
1.5 raeburn 145: }
146: }
147: }
148: }
149: if ($update) {
150: my ($furl,$ferr)=
151: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
152: if ($ferr) {
153: $env{'user.error.msg'}=$r->uri.':bre:0:0:Course not initialized';
154: $env{'user.reinit'} = 1;
155: return HTTP_NOT_ACCEPTABLE;
156: }
157: }
158: my $host = $r->headers_in->get('Host');
159: if (!$host) {
160: $r->internal_redirect($realuri);
161: return OK;
162: } else {
163: my $protocol = 'http';
164: if ($r->get_server_port == 443) {
165: $protocol = 'https';
1.1 raeburn 166: }
1.5 raeburn 167: my $location = $protocol.'://'.$host.$realuri;
168: $r->headers_out->set(Location => $location);
169: return REDIRECT;
1.1 raeburn 170: }
171: }
1.5 raeburn 172: } else {
173: my %crsenv = &Apache::lonnet::coursedescription("$cdom/$cnum");
174: my @possroles = ('in','ta','ep','st','cr','ad');
175: if ($crsenv{'type'} eq 'Community') {
176: unshift(@possroles,'co');
177: } else {
178: unshift(@possroles,'cc');
179: }
1.8.2.3 ! raeburn 180: my %roleshash =
! 181: &Apache::lonnet::get_my_roles($env{'user.uname'},$env{'user.domain'},
! 182: 'userroles',['previous','active','future'],
! 183: \@possroles,[$cdom],1);
! 184: my (%possroles,$hassection,%active,%expired,%future);
1.5 raeburn 185: if (keys(%roleshash)) {
1.8.2.3 ! raeburn 186: my $now = time;
1.5 raeburn 187: foreach my $entry (keys(%roleshash)) {
188: if ($entry =~ /^\Q$cnum:$cdom:\E([^:]+):([^:]*)$/) {
1.8.2.3 ! raeburn 189: my ($role,$sec) = ($1,$2);
! 190: $possroles{$role} = $sec;
! 191: if ($sec ne '') {
1.5 raeburn 192: $hassection = 1;
193: }
1.8.2.3 ! raeburn 194: my ($tstart,$tend)=split(/\:/,$roleshash{$entry});
! 195: my $status = 'active';
! 196: if (($tend) && ($tend<=$now)) {
! 197: $status = 'previous';
! 198: }
! 199: if (($tstart) && ($now<$tstart)) {
! 200: $status = 'future';
! 201: }
! 202: if ($status eq 'active') {
! 203: $active{$role} = $sec;
! 204: } elsif ($status eq 'previous') {
! 205: $expired{$tend} = $role.':'.$sec;
! 206: } elsif ($status eq 'future') {
! 207: $future{$tstart} = $role.':'.$sec;
! 208: }
1.5 raeburn 209: }
1.4 raeburn 210: }
211: }
1.8.2.3 ! raeburn 212: my @allposs = keys(%active);
1.5 raeburn 213: if (@allposs == 0) {
1.8.2.3 ! raeburn 214: &show_roles($r,\%crsenv,\%active,'','',\%future,\%expired,$linkprot,$linkprotuser,$linkprotexit,$ltoken);
1.5 raeburn 215: } elsif (@allposs == 1) {
216: my $newrole = "$allposs[0]./$cdom/$cnum";
217: $newrole = "$allposs[0]./$cdom/$cnum";
218: if ($possroles{$allposs[0]} ne '') {
219: $newrole .= "/$possroles{$allposs[0]}";
1.1 raeburn 220: }
221: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.8.2.3 ! raeburn 222: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.8 raeburn 223: if ($env{'form.ttoken'}) {
224: $destination .= '&ttoken='.$env{'form.ttoken'};
225: }
1.8.2.3 ! raeburn 226: &do_redirect($r,$destination,$linkprot);
! 227: } elsif (@allposs > 1) {
1.5 raeburn 228: if (grep(/^(cc|co)$/,@allposs)) {
229: my $newrole;
230: if (exists($possroles{'cc'})) {
231: $newrole = 'cc';
232: } else {
233: $newrole = 'co';
234: }
235: $newrole .= "./$cdom/$cnum";
236: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.8.2.3 ! raeburn 237: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.8 raeburn 238: if ($env{'form.ttoken'}) {
239: $destination .= '&ttoken='.$env{'form.ttoken'};
240: }
1.8.2.3 ! raeburn 241: &do_redirect($r,$destination,$linkprot);
1.5 raeburn 242: } else {
243: my $hascustom;
244: if (grep(/^cr\//,@allposs)) {
245: $hascustom = 1;
246: }
1.8.2.3 ! raeburn 247: &show_roles($r,\%crsenv,\%active,$hassection,$hascustom);
1.1 raeburn 248: }
249: }
1.5 raeburn 250: return OK;
1.1 raeburn 251: }
252: }
253: }
254: }
255: }
256: }
257: &generic_error($r);
258: return OK;
259: } else {
260: return FORBIDDEN;
261: }
262: }
263:
1.7 raeburn 264: sub launch_check {
1.8 raeburn 265: my ($linkuri,$symb) = @_;
1.8.2.3 ! raeburn 266: my ($linkprotector,$linkproturi,$linkprotexit,$linkkey,$newlauncher);
1.8 raeburn 267: if ($env{'form.ttoken'}) {
268: my %link_info = &Apache::lonnet::tmpget($env{'form.ttoken'});
269: &Apache::lonnet::tmpdel($env{'form.ttoken'});
270: delete($env{'form.ttoken'});
1.8.2.2 raeburn 271: if ($link_info{'ltoken'}) {
272: unless (($link_info{'linkprot'}) || ($link_info{'linkkey'} ne '')) {
273: my %ltoken_info = &Apache::lonnet::tmpget($link_info{'ltoken'});
274: if ($ltoken_info{'linkprot'}) {
275: $link_info{'linkprot'} = $ltoken_info{'linkprot'};
276: } elsif ($ltoken_info{'linkkey'} ne '') {
277: $link_info{'linkkey'} = $ltoken_info{'linkkey'};
278: }
279: }
1.8.2.3 ! raeburn 280: &Apache::lonnet::tmpdel($link_info{'ltoken'});
1.8.2.2 raeburn 281: }
1.7 raeburn 282: if ($link_info{'linkprot'}) {
283: ($linkprotector,$linkproturi) = split(/:/,$link_info{'linkprot'},2);
284: if ($env{'user.linkprotector'}) {
285: my @protectors = split(/,/,$env{'user.linkprotector'});
286: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
287: push(@protectors,$linkprotector);
288: @protectors = sort { $a <=> $b } @protectors;
289: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
290: }
291: } else {
292: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
293: }
294: if ($env{'user.linkproturi'}) {
295: my @proturis = split(/,/,$env{'user.linkproturi'});
296: unless(grep(/^\Q$linkproturi\E$/,@proturis)) {
297: push(@proturis,$linkproturi);
298: @proturis = sort(@proturis);
299: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
300: }
301: } else {
302: &Apache::lonnet::appenv({'user.linkproturi' => $linkproturi});
303: }
1.8.2.3 ! raeburn 304: if ($link_info{'linkprotexit'}) {
! 305: $linkprotexit = $link_info{'linkprotexit'};
! 306: }
1.8 raeburn 307: } elsif ($link_info{'linkkey'} ne '') {
308: $linkkey = $link_info{'linkkey'};
309: my $keyedlinkuri = $linkuri;
310: if ($env{'user.deeplinkkey'} ne '') {
311: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
312: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
313: push(@linkkeys,$linkkey);
314: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
315: }
316: } else {
317: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
318: }
319: if ($env{'user.keyedlinkuri'}) {
320: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
321: unless (grep(/^\Q$keyedlinkuri\E$/,@keyeduris)) {
322: push(@keyeduris,$keyedlinkuri);
323: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
324: }
325: } else {
326: &Apache::lonnet::appenv({'user.keyedlinkuri' => $keyedlinkuri});
327: }
1.7 raeburn 328: }
1.8 raeburn 329: if ($link_info{'checklaunch'}) {
330: $newlauncher = 1;
1.7 raeburn 331: }
1.8 raeburn 332: }
333: my $currdeeplinklogin = $env{'request.deeplink.login'};
334: my $deeplink;
335: if ($symb =~ /\.(page|sequence)$/) {
336: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]);
337: my $navmap = Apache::lonnavmaps::navmap->new();
338: if (ref($navmap)) {
339: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
1.7 raeburn 340: }
1.8 raeburn 341: } else {
342: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
1.7 raeburn 343: }
1.8 raeburn 344: if ($deeplink ne '') {
345: my $disallow;
1.8.2.3 ! raeburn 346: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
1.8 raeburn 347: if (($protect ne 'none') && ($protect ne '')) {
348: my ($acctype,$item) = split(/:/,$protect);
349: if ($acctype =~ /lti(c|d)$/) {
350: my $ltitype = $1;
351: if ($linkprotector) {
352: unless ($linkprotector.':'.$linkproturi eq $item.$ltitype.':'.$linkuri) {
353: $disallow = 1;
354: }
355: } else {
356: $disallow = 1;
1.7 raeburn 357: }
1.8 raeburn 358: } elsif ($acctype eq 'key') {
359: if ($linkkey ne '') {
360: unless ($linkkey eq $item) {
361: $disallow = 1;
1.7 raeburn 362: }
1.8 raeburn 363: } else {
364: $disallow = 1;
1.7 raeburn 365: }
1.8 raeburn 366: }
367: }
368: if ($disallow) {
369: if ($currdeeplinklogin eq $linkuri) {
370: &Apache::lonnet::delenv('request.deeplink.login');
1.8.2.2 raeburn 371: if ($env{'request.deeplink.target'} ne '') {
372: &Apache::lonnet::delenv('request.deeplink.target');
373: }
1.8.2.3 ! raeburn 374: if ($env{'request.linkprot'} ne '') {
! 375: &Apache::lonnet::delenv('request.linkprot');
! 376: }
! 377: if ($env{'request.linkprotexit'} ne '') {
! 378: &Apache::lonnet::delenv('request.linkprotexit');
! 379: }
1.8 raeburn 380: }
381: } else {
382: unless ($currdeeplinklogin eq $linkuri) {
383: if (($linkprotector) || ($linkkey ne '')) {
384: if ($linkprotector) {
385: &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
386: } elsif ($env{'request.linkprot'}) {
1.8.2.3 ! raeburn 387: &Apache::lonnet::delenv('request.linkprot');
! 388: }
! 389: if ($linkprotexit) {
! 390: &Apache::lonnet::appenv({'request.linkprotexit' => $linkprotexit});
! 391: } elsif ($env{'request.linkprotexit'}) {
! 392: &Apache::lonnet::delenv('request.linkprotexit');
1.7 raeburn 393: }
1.8 raeburn 394: if ($linkkey ne '') {
395: &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
396: } elsif ($env{'request.linkkey'} ne '') {
1.8.2.3 ! raeburn 397: &Apache::lonnet::delenv('request.linkkey');
1.7 raeburn 398: }
1.8 raeburn 399: $newlauncher = 1;
1.7 raeburn 400: }
401: }
402: &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
1.8.2.2 raeburn 403: if ($target ne '') {
404: &Apache::lonnet::appenv({'request.deeplink.target' => $target});
405: } elsif ($env{'request.deeplink.target'} ne '') {
406: &Apache::lonnet::delenv('request.deeplink.target');
407: }
1.7 raeburn 408: }
409: } else {
410: if ($linkprotector) {
411: &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
1.8 raeburn 412: } elsif ($env{'request.linkprot'}) {
1.8.2.3 ! raeburn 413: &Apache::lonnet::delenv('request.linkprot');
! 414: }
! 415: if ($linkprotexit) {
! 416: &Apache::lonnet::appenv({'request.linkprotexit' => $linkprotexit});
! 417: } elsif ($env{'request.linkprotexit'}) {
! 418: &Apache::lonnet::delenv('request.linkprotexit');
1.8 raeburn 419: }
420: if ($linkkey ne '') {
1.7 raeburn 421: &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
1.8 raeburn 422: } else {
1.8.2.3 ! raeburn 423: &Apache::lonnet::delenv('request.linkkey');
1.7 raeburn 424: }
1.8 raeburn 425: &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
1.8.2.2 raeburn 426: if ($env{'request.deeplink.target'} ne '') {
427: &Apache::lonnet::delenv('request.deeplink.target');
428: }
1.7 raeburn 429: }
430: return $newlauncher;
431: }
432:
1.1 raeburn 433: sub do_redirect {
1.8.2.3 ! raeburn 434: my ($r,$destination,$linkprot) = @_;
1.2 raeburn 435: my $windowname = 'loncapaclient';
1.1 raeburn 436: my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
437: my $args = {'bread_crumbs' => [{'href' => '','text' => 'Role initialization'},],};
1.8.2.3 ! raeburn 438: if ($linkprot) {
! 439: $args = {'only_body' => 1,
! 440: 'redirect' => [0,$destination],};
! 441: }
1.1 raeburn 442: &Apache::loncommon::content_type($r,'text/html');
443: $r->send_http_header;
1.8.2.3 ! raeburn 444: if ($linkprot) {
! 445: $r->print(&Apache::loncommon::start_page('Valid link','',$args).
! 446: &Apache::loncommon::end_page());
! 447: } else {
! 448: $r->print(&Apache::loncommon::start_page('Valid link',$header,$args).
! 449: &Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";').
! 450: '<h1>'.&mt('Welcome').'</h1>'.
! 451: '<p>'.&mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>').'</p><p>'.
! 452: '<a href="'.$destination.'">'.&mt('Continue').'</a></p>'.
! 453: &Apache::loncommon::end_page());
! 454: }
1.1 raeburn 455: return;
456: }
457:
458: sub show_roles {
1.8.2.3 ! raeburn 459: my ($r,$crsenv,$possroles,$hassection,$hascustom,$futureroles,$expiredroles,$linkprot,$linkprotuser,$linkprotexit,$ltoken) = @_;
1.1 raeburn 460: my ($crsdesc,$crstype,$cdom,$cnum,$header,$title,$preamble,$datatable,$js,$args);
461: if (ref($crsenv) eq 'HASH') {
462: $crsdesc = $crsenv->{'description'};
463: $crstype = $crsenv->{'type'};
464: $cdom = $crsenv->{'domain'};
465: $cnum = $crsenv->{'num'};
466: }
467: if ($crstype eq '') {
468: $crstype = 'Course';
469: }
470: my $lc_crstype = lc($crstype);
471: if ($crsdesc ne '') {
472: $header = &mt("The page you requested belongs to the following $lc_crstype: [_1]",
473: '<i>'.$crsdesc.'</i>');
474: }
475: if (ref($possroles) eq 'HASH') {
476: if (keys(%{$possroles}) > 0) {
477: $args = {'bread_crumbs' => [{'href' => '','text' => "Choose role in $lc_crstype"},],};
1.8.2.3 ! raeburn 478: if ($linkprot) {
! 479: $args = {'only_body' => 1};
! 480: }
1.1 raeburn 481: $title = 'Choose a role'; #Do not localize.
482: if ($crstype eq 'Community') {
483: $preamble = &mt('You have the following active roles in this community:');
484: } else {
485: $preamble = &mt('You have the following active roles in this course:');
486: }
487: $datatable = '<form name="" action="/adm/roles">'.
1.8 raeburn 488: '<input type="hidden" name="newrole" value="" />'."\n".
489: '<input type="hidden" name="selectrole" value="1" />'."\n".
1.8.2.3 ! raeburn 490: '<input type="hidden" name="destinationurl" value="'.&HTML::Entities::encode($r->uri,'&<>"').'" />'."\n";
1.8 raeburn 491: if ($env{'form.ttoken'}) {
492: $datatable .= '<input type="hidden" name="ttoken" value="'.$env{'form.ttoken'}.'" />'."\n";
493: }
494: $datatable .= &Apache::loncommon::start_data_table().
495: &Apache::loncommon::start_data_table_header_row().
496: '<th></th><th>'.&mt('User role').'</th>';
1.1 raeburn 497: if ($hassection) {
498: $datatable .= '<th>'.&mt('Section').'</th>';
499: }
500: if ($hascustom) {
501: $datatable .= '<th>'.&mt('Information').'</th>';
502: }
503: $datatable .= &Apache::loncommon::end_data_table_header_row();
504: my @available = sort(keys(%{$possroles}));
505: foreach my $role ('ad','in','ta','ep','st','cr') {
506: foreach my $key (@available) {
507: if ($key =~ m{^$role($|/)}) {
508: my $trolecode = "$key./$cdom/$cnum";
509: my $rolename = &Apache::lonnet::plaintext($key,$crstype,$cdom.'_'.$cnum);
510: my $sec = $possroles->{$key};
511: if ($sec ne '') {
512: $trolecode .= '/'.$sec;
513: }
514: my $buttonname=$trolecode;
515: $buttonname=~s/\W//g;
516: $datatable .= &Apache::loncommon::start_data_table_row().
517: '<td><input name="'.$buttonname.'" type="button" value="'.
518: &mt('Select').'" onclick="javascript:enterrole(this.form,'.
519: "'$trolecode','$buttonname'".');" /></td>';
520: if ($key =~ /^cr\//) {
521: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$key);
522: $datatable .= '<td><span class="LC_nobreak">'.$rolename.'</span></td>';
523: if ($hassection) {
524: $datatable .= '<td>'.$sec.'</td>';
525: }
526: $datatable.= '<td><span class="LC_fontsize_small LC_cusr_emph">'.
527: &mt('Custom role defined by [_1]',$rauthor.':'.$rdomain).
528: '</td>';
529: } else {
530: if ($hassection) {
531: $datatable .= '<td>'.$rolename.'</td>';
532: if ($hascustom) {
533: $datatable .= '<td colspan="2">'.$sec.'</td>';
534: } else {
535: $datatable .= '<td>'.$sec.'</td>';
536: }
537: } elsif ($hascustom) {
538: $datatable .= '<td colspan="2">'.$rolename.'</td>';
539: } else {
540: $datatable .= '<td>'.$rolename.'</td>';
541: }
542: }
543: $datatable .= &Apache::loncommon::end_data_table_row();
544: }
545: }
546: }
547: $datatable .= &Apache::loncommon::end_data_table().
548: '</form>';
549: my $standby = &mt('Role selected. Please stand by.');
550: $js = <<"ENDJS";
551: <script type="text/javascript">
552: // <![CDATA[
553:
554: active=true;
555:
556: function enterrole (thisform,rolecode,buttonname) {
557: if (active) {
558: active=false;
559: document.title='$standby';
560: window.status='$standby';
561: thisform.newrole.value=rolecode;
562: thisform.submit();
563: } else {
564: alert('$standby');
565: }
566: }
567:
568: // ]]>
569: </script>
570: ENDJS
571: } else {
1.8.2.3 ! raeburn 572: if ($linkprot) {
! 573: $title = 'No access';
! 574: $preamble = '<p>'.&mt('Access unavailable for this LON-CAPA content.').'</p>';
! 575: $args->{'only_body'} = 1;
! 576: } else {
! 577: $title = 'No active role';
! 578: $preamble = '<p>'.&mt("You have no active roles in this $lc_crstype so the page is currently unavailable to you.").'</p>';
! 579: $args = {'bread_crumbs' => [{'href' => '','text' => 'Role status'},],};
! 580: }
! 581: $header = &mt('No access for: [_1]','<b>'.&Apache::loncommon::plainname($env{'user.name'},
! 582: $env{'user.domain'}).'</b>');
! 583: if ((ref($futureroles) eq 'HASH') && (keys(%{$futureroles}) > 0)) {
! 584: my @future = sort { $a <=> $b } (keys(%{$futureroles}));
! 585: $preamble .= '<p>'.&mt('Access will begin: [_1].',&Apache::lonlocal::locallocaltime($future[0])).
! 586: ' '.&mt('Please try again then.').'</p>';
! 587: } elsif ((ref($expiredroles) eq 'HASH') && (keys(%{$expiredroles}) > 0)) {
! 588: my @expired = sort { $b <=> $a } (keys(%{$expiredroles}));
! 589: $preamble .= '<p>'.&mt('Access ended: [_1].',&Apache::lonlocal::locallocaltime($expired[0])).'</p>';
! 590: } elsif ($linkprot) {
! 591: if ($linkprotuser) {
! 592: my ($uname,$udom) = split(/:/,$linkprotuser,2);
! 593: $preamble .= '<p>'.&mt('As you followed a link from another system, while logged into that other system with the username: [_1], it is recommended that you contact your instructor.','<i>'.$uname.'</i>').'</p>';
! 594: } else {
! 595: my $relogin;
! 596: my %data = (
! 597: origurl => $r->uri,
! 598: linkprot => $linkprot,
! 599: linkprotexit => $linkprotexit,
! 600: );
! 601: my $token =
! 602: &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'retry');
! 603: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
! 604: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
! 605: $relogin = '/adm/relaunch?rtoken='.$token;
! 606: }
! 607: $preamble .= '<p>'.&mt('You might try logging in with a different username and/or domain.').' '.
! 608: &mt('You are currently logged in as: [_1] in domain: [_2]',
! 609: '<i>'.$env{'user.name'}.'</i>','<i>'.$env{'user.domain'}.'</i>').'</p>';
! 610: if ($relogin) {
! 611: $preamble .= '<p>'.&mt('[_1]Log-in again[_2]','<a href="'.$relogin.'" target="_self">','</a>').'</p>';
! 612: }
! 613: }
! 614: }
! 615: if ($env{'form.ttoken'}) {
! 616: &Apache::lonnet::tmpdel($env{'form.ttoken'});
! 617: }
! 618: if ($ltoken) {
! 619: &Apache::lonnet::tmpdel($ltoken);
! 620: }
1.1 raeburn 621: }
622: }
623: &Apache::loncommon::content_type($r,'text/html');
624: $r->send_http_header;
625: $r->print(&Apache::loncommon::start_page($title,$js,$args).
626: '<h3>'.$header.'</h3>'.
627: '<div>'.$preamble.'</div>'.
628: $datatable.
629: &Apache::loncommon::end_page());
630: return;
631: }
632:
633: sub generic_error {
634: my ($r) = @_;
1.3 raeburn 635: my $continuelink;
1.8.2.1 raeburn 636: my $linktext;
637: if ($env{'user.adv'}) {
638: $linktext = &mt('Continue to your roles page');
639: } else {
640: $linktext = &mt('Continue to your courses page');
1.1 raeburn 641: }
1.8.2.1 raeburn 642: $continuelink='<a href="/adm/roles">'.$linktext.'</a>';
1.1 raeburn 643: my $msg = &mt('The page you requested does not exist.');
644: &Apache::loncommon::content_type($r,'text/html');
645: $r->send_http_header;
646: my $args = {'bread_crumbs' => [{'href' => '','text' => 'Link status'},],};
647: $r->print(&Apache::loncommon::start_page('Invalid URL',undef,$args).
648: '<div class="LC_error">'.$msg.'</div>'.
649: '<p>'.$continuelink.'</p>'.
650: &Apache::loncommon::end_page());
651: return;
652: }
653:
654: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>