Annotation of loncom/interface/lontiny.pm, revision 1.16
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.16 ! raeburn 5: # $Id: lontiny.pm,v 1.15 2022/07/02 19:55:15 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.12 raeburn 71: my ($linkprot,$linkprotuser,$linkprotexit,$ltoken);
1.11 raeburn 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'};
1.12 raeburn 80: $linkprotexit = $ltoken_info{'linkprotexit'};
1.11 raeburn 81: } elsif ($link_info{'linkprot'}) {
82: $linkprot = $link_info{'linkprot'};
83: if ($link_info{'linkprotuser'}) {
84: $linkprotuser = $link_info{'linkprotuser'};
85: }
1.12 raeburn 86: if ($link_info{'linkprotexit'}) {
87: $linkprotexit = $link_info{'linkprotexit'};
88: }
1.11 raeburn 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.11 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.11 raeburn 186: my $now = time;
1.5 raeburn 187: foreach my $entry (keys(%roleshash)) {
188: if ($entry =~ /^\Q$cnum:$cdom:\E([^:]+):([^:]*)$/) {
1.11 raeburn 189: my ($role,$sec) = ($1,$2);
190: $possroles{$role} = $sec;
191: if ($sec ne '') {
1.5 raeburn 192: $hassection = 1;
193: }
1.11 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.11 raeburn 212: my @allposs = keys(%active);
1.5 raeburn 213: if ($env{'request.lti.login'}) {
214: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
215: if ($env{'request.lti.target'} eq '') {
216: if ($env{'form.ltitarget'} eq 'iframe') {
217: &Apache::lonnet::appenv({'request.lti.target' => 'iframe'});
218: delete($env{'form.ltitarget'});
1.4 raeburn 219: }
1.5 raeburn 220: }
221: if ($env{'form.selectrole'}) {
222: foreach my $role (@allposs) {
223: my $newrole = "$role./$cdom/$cnum";
224: if ($possroles{$allposs[0]} ne '') {
225: $newrole .= "/$possroles{$role}";
226: }
227: if ($env{"form.$newrole"}) {
228: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.11 raeburn 229: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.5 raeburn 230: if ($env{'form.ltitarget'} eq 'iframe') {
231: $destination .= '<itarget=iframe';
232: }
233: &do_redirect($r,$destination);
234: return OK;
1.4 raeburn 235: }
236: }
237: }
238: }
1.5 raeburn 239: if (@allposs == 0) {
1.12 raeburn 240: &show_roles($r,\%crsenv,\%active,'','',\%future,\%expired,$linkprot,$linkprotuser,$linkprotexit,$ltoken);
1.5 raeburn 241: } elsif (@allposs == 1) {
242: my $newrole = "$allposs[0]./$cdom/$cnum";
243: $newrole = "$allposs[0]./$cdom/$cnum";
244: if ($possroles{$allposs[0]} ne '') {
1.11 raeburn 245: $newrole .= "/$possroles{$allposs[0]}";
1.1 raeburn 246: }
247: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.11 raeburn 248: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.8 raeburn 249: if ($env{'form.ttoken'}) {
250: $destination .= '&ttoken='.$env{'form.ttoken'};
251: }
1.11 raeburn 252: &do_redirect($r,$destination,$linkprot);
1.16 ! raeburn 253: } elsif (@allposs > 1) {
1.5 raeburn 254: if (grep(/^(cc|co)$/,@allposs)) {
255: my $newrole;
256: if (exists($possroles{'cc'})) {
257: $newrole = 'cc';
258: } else {
259: $newrole = 'co';
260: }
261: $newrole .= "./$cdom/$cnum";
262: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.11 raeburn 263: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.8 raeburn 264: if ($env{'form.ttoken'}) {
265: $destination .= '&ttoken='.$env{'form.ttoken'};
266: }
1.11 raeburn 267: &do_redirect($r,$destination,$linkprot);
1.5 raeburn 268: } else {
269: my $hascustom;
270: if (grep(/^cr\//,@allposs)) {
271: $hascustom = 1;
272: }
1.16 ! raeburn 273: &show_roles($r,\%crsenv,\%active,$hassection,$hascustom);
1.1 raeburn 274: }
275: }
1.5 raeburn 276: return OK;
1.1 raeburn 277: }
278: }
279: }
280: }
281: }
282: }
283: &generic_error($r);
284: return OK;
285: } else {
286: return FORBIDDEN;
287: }
288: }
289:
1.7 raeburn 290: sub launch_check {
1.8 raeburn 291: my ($linkuri,$symb) = @_;
1.15 raeburn 292: my ($linkprotector,$linkproturi,$linkprotexit,$linkkey,$newlauncher);
1.8 raeburn 293: if ($env{'form.ttoken'}) {
294: my %link_info = &Apache::lonnet::tmpget($env{'form.ttoken'});
295: &Apache::lonnet::tmpdel($env{'form.ttoken'});
296: delete($env{'form.ttoken'});
1.10 raeburn 297: if ($link_info{'ltoken'}) {
298: unless (($link_info{'linkprot'}) || ($link_info{'linkkey'} ne '')) {
299: my %ltoken_info = &Apache::lonnet::tmpget($link_info{'ltoken'});
300: if ($ltoken_info{'linkprot'}) {
301: $link_info{'linkprot'} = $ltoken_info{'linkprot'};
302: } elsif ($ltoken_info{'linkkey'} ne '') {
303: $link_info{'linkkey'} = $ltoken_info{'linkkey'};
304: }
305: }
1.11 raeburn 306: &Apache::lonnet::tmpdel($link_info{'ltoken'});
1.10 raeburn 307: }
1.7 raeburn 308: if ($link_info{'linkprot'}) {
309: ($linkprotector,$linkproturi) = split(/:/,$link_info{'linkprot'},2);
310: if ($env{'user.linkprotector'}) {
311: my @protectors = split(/,/,$env{'user.linkprotector'});
312: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
313: push(@protectors,$linkprotector);
314: @protectors = sort { $a <=> $b } @protectors;
315: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
316: }
317: } else {
318: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
319: }
320: if ($env{'user.linkproturi'}) {
321: my @proturis = split(/,/,$env{'user.linkproturi'});
322: unless(grep(/^\Q$linkproturi\E$/,@proturis)) {
323: push(@proturis,$linkproturi);
324: @proturis = sort(@proturis);
325: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
326: }
327: } else {
328: &Apache::lonnet::appenv({'user.linkproturi' => $linkproturi});
329: }
1.15 raeburn 330: if ($link_info{'linkprotexit'}) {
331: $linkprotexit = $link_info{'linkprotexit'};
332: }
1.8 raeburn 333: } elsif ($link_info{'linkkey'} ne '') {
334: $linkkey = $link_info{'linkkey'};
335: my $keyedlinkuri = $linkuri;
336: if ($env{'user.deeplinkkey'} ne '') {
337: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
338: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
339: push(@linkkeys,$linkkey);
340: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
341: }
342: } else {
343: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
344: }
345: if ($env{'user.keyedlinkuri'}) {
346: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
347: unless (grep(/^\Q$keyedlinkuri\E$/,@keyeduris)) {
348: push(@keyeduris,$keyedlinkuri);
349: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
350: }
351: } else {
352: &Apache::lonnet::appenv({'user.keyedlinkuri' => $keyedlinkuri});
353: }
1.7 raeburn 354: }
1.8 raeburn 355: if ($link_info{'checklaunch'}) {
356: $newlauncher = 1;
1.7 raeburn 357: }
1.8 raeburn 358: }
359: my $currdeeplinklogin = $env{'request.deeplink.login'};
360: my $deeplink;
361: if ($symb =~ /\.(page|sequence)$/) {
362: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]);
363: my $navmap = Apache::lonnavmaps::navmap->new();
364: if (ref($navmap)) {
365: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
1.7 raeburn 366: }
1.8 raeburn 367: } else {
368: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
1.7 raeburn 369: }
1.8 raeburn 370: if ($deeplink ne '') {
371: my $disallow;
1.15 raeburn 372: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
1.8 raeburn 373: if (($protect ne 'none') && ($protect ne '')) {
374: my ($acctype,$item) = split(/:/,$protect);
375: if ($acctype =~ /lti(c|d)$/) {
376: my $ltitype = $1;
377: if ($linkprotector) {
378: unless ($linkprotector.':'.$linkproturi eq $item.$ltitype.':'.$linkuri) {
379: $disallow = 1;
380: }
381: } else {
382: $disallow = 1;
1.7 raeburn 383: }
1.8 raeburn 384: } elsif ($acctype eq 'key') {
385: if ($linkkey ne '') {
386: unless ($linkkey eq $item) {
387: $disallow = 1;
1.7 raeburn 388: }
1.8 raeburn 389: } else {
390: $disallow = 1;
1.7 raeburn 391: }
1.8 raeburn 392: }
393: }
394: if ($disallow) {
395: if ($currdeeplinklogin eq $linkuri) {
396: &Apache::lonnet::delenv('request.deeplink.login');
1.10 raeburn 397: if ($env{'request.deeplink.target'} ne '') {
398: &Apache::lonnet::delenv('request.deeplink.target');
399: }
1.15 raeburn 400: if ($env{'request.linkprot'} ne '') {
401: &Apache::lonnet::delenv('request.linkprot');
402: }
403: if ($env{'request.linkprotexit'} ne '') {
404: &Apache::lonnet::delenv('request.linkprotexit');
405: }
1.8 raeburn 406: }
407: } else {
408: unless ($currdeeplinklogin eq $linkuri) {
409: if (($linkprotector) || ($linkkey ne '')) {
410: if ($linkprotector) {
411: &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
412: } elsif ($env{'request.linkprot'}) {
1.14 raeburn 413: &Apache::lonnet::delenv('request.linkprot');
1.7 raeburn 414: }
1.15 raeburn 415: if ($linkprotexit) {
416: &Apache::lonnet::appenv({'request.linkprotexit' => $linkprotexit});
417: } elsif ($env{'request.linkprotexit'}) {
418: &Apache::lonnet::delenv('request.linkprotexit');
419: }
1.8 raeburn 420: if ($linkkey ne '') {
421: &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
422: } elsif ($env{'request.linkkey'} ne '') {
1.13 raeburn 423: &Apache::lonnet::delenv('request.linkkey');
1.7 raeburn 424: }
1.8 raeburn 425: $newlauncher = 1;
1.7 raeburn 426: }
427: }
428: &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
1.9 raeburn 429: if ($target ne '') {
430: &Apache::lonnet::appenv({'request.deeplink.target' => $target});
1.10 raeburn 431: } elsif ($env{'request.deeplink.target'} ne '') {
432: &Apache::lonnet::delenv('request.deeplink.target');
1.9 raeburn 433: }
1.7 raeburn 434: }
435: } else {
436: if ($linkprotector) {
437: &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
1.8 raeburn 438: } elsif ($env{'request.linkprot'}) {
1.14 raeburn 439: &Apache::lonnet::delenv('request.linkprot');
1.8 raeburn 440: }
1.15 raeburn 441: if ($linkprotexit) {
442: &Apache::lonnet::appenv({'request.linkprotexit' => $linkprotexit});
443: } elsif ($env{'request.linkprotexit'}) {
444: &Apache::lonnet::delenv('request.linkprotexit');
445: }
1.8 raeburn 446: if ($linkkey ne '') {
1.7 raeburn 447: &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
1.8 raeburn 448: } else {
1.13 raeburn 449: &Apache::lonnet::delenv('request.linkkey');
1.7 raeburn 450: }
1.8 raeburn 451: &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
1.10 raeburn 452: if ($env{'request.deeplink.target'} ne '') {
453: &Apache::lonnet::delenv('request.deeplink.target');
454: }
1.7 raeburn 455: }
456: return $newlauncher;
457: }
458:
1.1 raeburn 459: sub do_redirect {
1.11 raeburn 460: my ($r,$destination,$linkprot) = @_;
1.2 raeburn 461: my $windowname = 'loncapaclient';
462: if ($env{'request.lti.login'}) {
463: $windowname .= 'lti';
464: }
1.1 raeburn 465: my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
466: my $args = {'bread_crumbs' => [{'href' => '','text' => 'Role initialization'},],};
1.11 raeburn 467: if ($linkprot) {
468: $args = {'only_body' => 1,
469: 'redirect' => [0,$destination],};
470: }
1.1 raeburn 471: &Apache::loncommon::content_type($r,'text/html');
472: $r->send_http_header;
1.11 raeburn 473: if ($linkprot) {
474: $r->print(&Apache::loncommon::start_page('Valid link','',$args).
475: &Apache::loncommon::end_page());
476: } else {
477: $r->print(&Apache::loncommon::start_page('Valid link',$header,$args).
478: &Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";').
479: '<h1>'.&mt('Welcome').'</h1>'.
480: '<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>'.
481: '<a href="'.$destination.'">'.&mt('Continue').'</a></p>'.
482: &Apache::loncommon::end_page());
483: }
1.1 raeburn 484: return;
485: }
486:
487: sub show_roles {
1.12 raeburn 488: my ($r,$crsenv,$possroles,$hassection,$hascustom,$futureroles,$expiredroles,$linkprot,$linkprotuser,$linkprotexit,$ltoken) = @_;
1.1 raeburn 489: my ($crsdesc,$crstype,$cdom,$cnum,$header,$title,$preamble,$datatable,$js,$args);
490: if (ref($crsenv) eq 'HASH') {
491: $crsdesc = $crsenv->{'description'};
492: $crstype = $crsenv->{'type'};
493: $cdom = $crsenv->{'domain'};
494: $cnum = $crsenv->{'num'};
495: }
496: if ($crstype eq '') {
497: $crstype = 'Course';
498: }
499: my $lc_crstype = lc($crstype);
500: if ($crsdesc ne '') {
501: $header = &mt("The page you requested belongs to the following $lc_crstype: [_1]",
502: '<i>'.$crsdesc.'</i>');
503: }
504: if (ref($possroles) eq 'HASH') {
505: if (keys(%{$possroles}) > 0) {
506: $args = {'bread_crumbs' => [{'href' => '','text' => "Choose role in $lc_crstype"},],};
1.11 raeburn 507: if ($linkprot) {
508: $args = {'only_body' => 1};
509: }
1.1 raeburn 510: $title = 'Choose a role'; #Do not localize.
511: if ($crstype eq 'Community') {
512: $preamble = &mt('You have the following active roles in this community:');
513: } else {
514: $preamble = &mt('You have the following active roles in this course:');
515: }
516: $datatable = '<form name="" action="/adm/roles">'.
1.8 raeburn 517: '<input type="hidden" name="newrole" value="" />'."\n".
518: '<input type="hidden" name="selectrole" value="1" />'."\n".
1.11 raeburn 519: '<input type="hidden" name="destinationurl" value="'.&HTML::Entities::encode($r->uri,'&<>"').'" />'."\n";
1.8 raeburn 520: if ($env{'form.ttoken'}) {
521: $datatable .= '<input type="hidden" name="ttoken" value="'.$env{'form.ttoken'}.'" />'."\n";
522: }
523: $datatable .= &Apache::loncommon::start_data_table().
524: &Apache::loncommon::start_data_table_header_row().
525: '<th></th><th>'.&mt('User role').'</th>';
1.1 raeburn 526: if ($hassection) {
527: $datatable .= '<th>'.&mt('Section').'</th>';
528: }
529: if ($hascustom) {
530: $datatable .= '<th>'.&mt('Information').'</th>';
531: }
532: $datatable .= &Apache::loncommon::end_data_table_header_row();
533: my @available = sort(keys(%{$possroles}));
534: foreach my $role ('ad','in','ta','ep','st','cr') {
535: foreach my $key (@available) {
536: if ($key =~ m{^$role($|/)}) {
537: my $trolecode = "$key./$cdom/$cnum";
538: my $rolename = &Apache::lonnet::plaintext($key,$crstype,$cdom.'_'.$cnum);
539: my $sec = $possroles->{$key};
540: if ($sec ne '') {
541: $trolecode .= '/'.$sec;
542: }
543: my $buttonname=$trolecode;
544: $buttonname=~s/\W//g;
545: $datatable .= &Apache::loncommon::start_data_table_row().
546: '<td><input name="'.$buttonname.'" type="button" value="'.
547: &mt('Select').'" onclick="javascript:enterrole(this.form,'.
548: "'$trolecode','$buttonname'".');" /></td>';
549: if ($key =~ /^cr\//) {
550: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$key);
551: $datatable .= '<td><span class="LC_nobreak">'.$rolename.'</span></td>';
552: if ($hassection) {
553: $datatable .= '<td>'.$sec.'</td>';
554: }
555: $datatable.= '<td><span class="LC_fontsize_small LC_cusr_emph">'.
556: &mt('Custom role defined by [_1]',$rauthor.':'.$rdomain).
557: '</td>';
558: } else {
559: if ($hassection) {
560: $datatable .= '<td>'.$rolename.'</td>';
561: if ($hascustom) {
562: $datatable .= '<td colspan="2">'.$sec.'</td>';
563: } else {
564: $datatable .= '<td>'.$sec.'</td>';
565: }
566: } elsif ($hascustom) {
567: $datatable .= '<td colspan="2">'.$rolename.'</td>';
568: } else {
569: $datatable .= '<td>'.$rolename.'</td>';
570: }
571: }
572: $datatable .= &Apache::loncommon::end_data_table_row();
573: }
574: }
575: }
576: $datatable .= &Apache::loncommon::end_data_table().
577: '</form>';
578: my $standby = &mt('Role selected. Please stand by.');
579: $js = <<"ENDJS";
580: <script type="text/javascript">
581: // <![CDATA[
582:
583: active=true;
584:
585: function enterrole (thisform,rolecode,buttonname) {
586: if (active) {
587: active=false;
588: document.title='$standby';
589: window.status='$standby';
590: thisform.newrole.value=rolecode;
591: thisform.submit();
592: } else {
593: alert('$standby');
594: }
595: }
596:
597: // ]]>
598: </script>
599: ENDJS
600: } else {
1.11 raeburn 601: if ($linkprot) {
602: $title = 'No access';
603: $preamble = '<p>'.&mt('Access unavailable for this LON-CAPA content.').'</p>';
604: $args->{'only_body'} = 1;
605: } else {
606: $title = 'No active role';
607: $preamble = '<p>'.&mt("You have no active roles in this $lc_crstype so the page is currently unavailable to you.").'</p>';
608: $args = {'bread_crumbs' => [{'href' => '','text' => 'Role status'},],};
609: }
610: $header = &mt('No access for: [_1]','<b>'.&Apache::loncommon::plainname($env{'user.name'},
611: $env{'user.domain'}).'</b>');
612: if ((ref($futureroles) eq 'HASH') && (keys(%{$futureroles}) > 0)) {
613: my @future = sort { $a <=> $b } (keys(%{$futureroles}));
614: $preamble .= '<p>'.&mt('Access will begin: [_1].',&Apache::lonlocal::locallocaltime($future[0])).
615: ' '.&mt('Please try again then.').'</p>';
616: } elsif ((ref($expiredroles) eq 'HASH') && (keys(%{$expiredroles}) > 0)) {
617: my @expired = sort { $b <=> $a } (keys(%{$expiredroles}));
618: $preamble .= '<p>'.&mt('Access ended: [_1].',&Apache::lonlocal::locallocaltime($expired[0])).'</p>';
619: } elsif ($linkprot) {
620: if ($linkprotuser) {
621: my ($uname,$udom) = split(/:/,$linkprotuser,2);
622: $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>';
623: } else {
624: my $relogin;
625: my %data = (
626: origurl => $r->uri,
627: linkprot => $linkprot,
1.12 raeburn 628: linkprotexit => $linkprotexit,
1.11 raeburn 629: );
630: my $token =
631: &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'retry');
632: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
633: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
634: $relogin = '/adm/relaunch?rtoken='.$token;
635: }
636: $preamble .= '<p>'.&mt('You might try logging in with a different username and/or domain.').' '.
637: &mt('You are currently logged in as: [_1] in domain: [_2]',
638: '<i>'.$env{'user.name'}.'</i>','<i>'.$env{'user.domain'}.'</i>').'</p>';
639: if ($relogin) {
640: $preamble .= '<p>'.&mt('[_1]Log-in again[_2]','<a href="'.$relogin.'" target="_self">','</a>').'</p>';
641: }
642: }
643: }
644: if ($env{'form.ttoken'}) {
645: &Apache::lonnet::tmpdel($env{'form.ttoken'});
646: }
647: if ($ltoken) {
648: &Apache::lonnet::tmpdel($ltoken);
649: }
1.1 raeburn 650: }
651: }
652: &Apache::loncommon::content_type($r,'text/html');
653: $r->send_http_header;
654: $r->print(&Apache::loncommon::start_page($title,$js,$args).
655: '<h3>'.$header.'</h3>'.
656: '<div>'.$preamble.'</div>'.
657: $datatable.
658: &Apache::loncommon::end_page());
659: return;
660: }
661:
662: sub generic_error {
663: my ($r) = @_;
1.3 raeburn 664: my $continuelink;
665: unless ($env{'request.lti.login'}) {
666: my $linktext;
667: if ($env{'user.adv'}) {
668: $linktext = &mt('Continue to your roles page');
669: } else {
670: $linktext = &mt('Continue to your courses page');
671: }
672: $continuelink='<a href="/adm/roles">'.$linktext.'</a>';
1.1 raeburn 673: }
674: my $msg = &mt('The page you requested does not exist.');
675: &Apache::loncommon::content_type($r,'text/html');
676: $r->send_http_header;
677: my $args = {'bread_crumbs' => [{'href' => '','text' => 'Link status'},],};
678: $r->print(&Apache::loncommon::start_page('Invalid URL',undef,$args).
679: '<div class="LC_error">'.$msg.'</div>'.
680: '<p>'.$continuelink.'</p>'.
681: &Apache::loncommon::end_page());
682: return;
683: }
684:
685: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>