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