Annotation of loncom/interface/lontiny.pm, revision 1.23
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.23 ! raeburn 5: # $Id: lontiny.pm,v 1.22 2024/02/10 14:12:32 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.19 raeburn 71: my ($linkprot,$linkprotuser,$linkprotexit,$ltoken,$linkprotpbid,$linkprotpburl);
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.19 raeburn 81: $linkprotpbid = $ltoken_info{'linkprotpbid'};
1.20 raeburn 82: $linkprotpburl = $ltoken_info{'linkprotpburl'};
1.11 raeburn 83: } elsif ($link_info{'linkprot'}) {
84: $linkprot = $link_info{'linkprot'};
85: if ($link_info{'linkprotuser'}) {
86: $linkprotuser = $link_info{'linkprotuser'};
87: }
1.12 raeburn 88: if ($link_info{'linkprotexit'}) {
89: $linkprotexit = $link_info{'linkprotexit'};
90: }
1.19 raeburn 91: if ($link_info{'linkprotpbid'}) {
92: $linkprotpbid = $link_info{'linkprotpbid'};
93: }
94: if ($link_info{'linkprotpburl'}) {
95: $linkprotpburl = $link_info{'linkprotpburl'};
96: }
1.11 raeburn 97: }
98: }
99: }
1.5 raeburn 100: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1.8 raeburn 101: # Check for ttoken
1.23 ! raeburn 102: my $newlauncher = &launch_check($r->uri,$symb,$cdom,$cnum);
1.5 raeburn 103: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb);
104: if (&Apache::lonnet::is_on_map($url)) {
105: my $realuri;
106: if ((&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) &&
107: (!$env{'request.role.adv'})) {
108: $env{'user.error.msg'}=$r->uri.':bre:1:1:Access to resource denied';
109: return HTTP_NOT_ACCEPTABLE;
110: }
111: if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) &&
112: (!$env{'request.role.adv'})) {
113: $realuri = &Apache::lonenc::encrypted(&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='.&Apache::lonenc::encrypted($symb);
119: }
120: } else {
121: $realuri = &Apache::lonnet::clutter($url);
122: if (($url =~ /\.sequence$/) &&
123: ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
124: $realuri .= '?navmap=1';
125: } else {
126: $realuri .= '?symb='.$symb;
127: }
128: }
1.17 raeburn 129: my ($update,$reinitresult);
1.5 raeburn 130: # Check if course needs to be re-initialized
1.7 raeburn 131: if ($newlauncher) {
1.5 raeburn 132: $update = 1;
1.7 raeburn 133: } else {
134: my $loncaparev = $r->dir_config('lonVersion');
1.17 raeburn 135: ($reinitresult,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
136: if (($reinitresult eq 'main') || ($reinitresult eq 'both')) {
1.7 raeburn 137: $update = 1;
138: } elsif (!-e $env{'request.course.fn'}.'.db') {
139: $update = 1;
140: } elsif (!$env{'request.role.adv'}) {
141: my $navmap = Apache::lonnavmaps::navmap->new();
142: if (ref($navmap)) {
143: my $res = $navmap->getBySymb($symb);
144: if (ref($res)) {
145: my ($enc_in_bighash,$enc_in_parm);
146: $enc_in_bighash = $res->encrypted();
147: if (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) {
148: $enc_in_parm = 1;
149: }
150: if ($enc_in_bighash ne $enc_in_parm) {
151: $update = 1;
152: }
1.5 raeburn 153: }
154: }
155: }
156: }
157: if ($update) {
158: my ($furl,$ferr)=
159: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
160: if ($ferr) {
161: $env{'user.error.msg'}=$r->uri.':bre:0:0:Course not initialized';
162: $env{'user.reinit'} = 1;
163: return HTTP_NOT_ACCEPTABLE;
164: }
165: }
1.17 raeburn 166: if (($reinitresult eq 'both') || ($reinitresult eq 'supp')) {
167: my $possdel;
168: if ($reinitresult eq 'supp') {
169: $possdel = 1;
170: }
1.18 raeburn 171: my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom,'',$possdel);
1.17 raeburn 172: unless ($refs_updated) {
173: &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental,$possdel);
174: }
175: }
1.5 raeburn 176: my $host = $r->headers_in->get('Host');
177: if (!$host) {
178: $r->internal_redirect($realuri);
179: return OK;
180: } else {
181: my $protocol = 'http';
182: if ($r->get_server_port == 443) {
183: $protocol = 'https';
1.1 raeburn 184: }
1.5 raeburn 185: my $location = $protocol.'://'.$host.$realuri;
186: $r->headers_out->set(Location => $location);
187: return REDIRECT;
1.1 raeburn 188: }
189: }
1.5 raeburn 190: } else {
191: my %crsenv = &Apache::lonnet::coursedescription("$cdom/$cnum");
192: my @possroles = ('in','ta','ep','st','cr','ad');
193: if ($crsenv{'type'} eq 'Community') {
194: unshift(@possroles,'co');
195: } else {
196: unshift(@possroles,'cc');
197: }
1.11 raeburn 198: my %roleshash =
199: &Apache::lonnet::get_my_roles($env{'user.uname'},$env{'user.domain'},
200: 'userroles',['previous','active','future'],
201: \@possroles,[$cdom],1);
202: my (%possroles,$hassection,%active,%expired,%future);
1.5 raeburn 203: if (keys(%roleshash)) {
1.11 raeburn 204: my $now = time;
1.5 raeburn 205: foreach my $entry (keys(%roleshash)) {
206: if ($entry =~ /^\Q$cnum:$cdom:\E([^:]+):([^:]*)$/) {
1.11 raeburn 207: my ($role,$sec) = ($1,$2);
208: $possroles{$role} = $sec;
209: if ($sec ne '') {
1.5 raeburn 210: $hassection = 1;
211: }
1.11 raeburn 212: my ($tstart,$tend)=split(/\:/,$roleshash{$entry});
213: my $status = 'active';
214: if (($tend) && ($tend<=$now)) {
215: $status = 'previous';
216: }
217: if (($tstart) && ($now<$tstart)) {
218: $status = 'future';
219: }
220: if ($status eq 'active') {
221: $active{$role} = $sec;
222: } elsif ($status eq 'previous') {
223: $expired{$tend} = $role.':'.$sec;
224: } elsif ($status eq 'future') {
225: $future{$tstart} = $role.':'.$sec;
226: }
1.5 raeburn 227: }
1.4 raeburn 228: }
229: }
1.11 raeburn 230: my @allposs = keys(%active);
1.5 raeburn 231: if ($env{'request.lti.login'}) {
232: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
233: if ($env{'request.lti.target'} eq '') {
234: if ($env{'form.ltitarget'} eq 'iframe') {
235: &Apache::lonnet::appenv({'request.lti.target' => 'iframe'});
236: delete($env{'form.ltitarget'});
1.4 raeburn 237: }
1.5 raeburn 238: }
239: if ($env{'form.selectrole'}) {
240: foreach my $role (@allposs) {
241: my $newrole = "$role./$cdom/$cnum";
242: if ($possroles{$allposs[0]} ne '') {
243: $newrole .= "/$possroles{$role}";
244: }
245: if ($env{"form.$newrole"}) {
246: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.11 raeburn 247: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.5 raeburn 248: if ($env{'form.ltitarget'} eq 'iframe') {
249: $destination .= '<itarget=iframe';
250: }
251: &do_redirect($r,$destination);
252: return OK;
1.4 raeburn 253: }
254: }
255: }
256: }
1.5 raeburn 257: if (@allposs == 0) {
1.19 raeburn 258: &show_roles($r,\%crsenv,\%active,'','',\%future,\%expired,$linkprot,$linkprotuser,
259: $linkprotexit,$linkprotpbid,$linkprotpburl,$ltoken);
1.5 raeburn 260: } elsif (@allposs == 1) {
261: my $newrole = "$allposs[0]./$cdom/$cnum";
262: $newrole = "$allposs[0]./$cdom/$cnum";
263: if ($possroles{$allposs[0]} ne '') {
1.11 raeburn 264: $newrole .= "/$possroles{$allposs[0]}";
1.1 raeburn 265: }
266: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.11 raeburn 267: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.8 raeburn 268: if ($env{'form.ttoken'}) {
269: $destination .= '&ttoken='.$env{'form.ttoken'};
270: }
1.11 raeburn 271: &do_redirect($r,$destination,$linkprot);
1.16 raeburn 272: } elsif (@allposs > 1) {
1.5 raeburn 273: if (grep(/^(cc|co)$/,@allposs)) {
274: my $newrole;
275: if (exists($possroles{'cc'})) {
276: $newrole = 'cc';
277: } else {
278: $newrole = 'co';
279: }
280: $newrole .= "./$cdom/$cnum";
281: my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
1.11 raeburn 282: '&destinationurl='.&HTML::Entities::encode($r->uri,'&<>"');
1.8 raeburn 283: if ($env{'form.ttoken'}) {
284: $destination .= '&ttoken='.$env{'form.ttoken'};
285: }
1.11 raeburn 286: &do_redirect($r,$destination,$linkprot);
1.5 raeburn 287: } else {
288: my $hascustom;
289: if (grep(/^cr\//,@allposs)) {
290: $hascustom = 1;
291: }
1.16 raeburn 292: &show_roles($r,\%crsenv,\%active,$hassection,$hascustom);
1.1 raeburn 293: }
294: }
1.5 raeburn 295: return OK;
1.1 raeburn 296: }
297: }
298: }
299: }
300: }
301: }
302: &generic_error($r);
303: return OK;
304: } else {
305: return FORBIDDEN;
306: }
307: }
308:
1.7 raeburn 309: sub launch_check {
1.23 ! raeburn 310: my ($linkuri,$symb,$cdom,$cnum) = @_;
1.21 raeburn 311: my ($linkprotector,$linkproturi,$linkprotexit,$linkprotpbid,$linkprotpburl,
312: $linkkey,$newlauncher,$prevlaunch);
1.8 raeburn 313: if ($env{'form.ttoken'}) {
314: my %link_info = &Apache::lonnet::tmpget($env{'form.ttoken'});
315: &Apache::lonnet::tmpdel($env{'form.ttoken'});
316: delete($env{'form.ttoken'});
1.10 raeburn 317: if ($link_info{'ltoken'}) {
318: unless (($link_info{'linkprot'}) || ($link_info{'linkkey'} ne '')) {
319: my %ltoken_info = &Apache::lonnet::tmpget($link_info{'ltoken'});
320: if ($ltoken_info{'linkprot'}) {
321: $link_info{'linkprot'} = $ltoken_info{'linkprot'};
322: } elsif ($ltoken_info{'linkkey'} ne '') {
323: $link_info{'linkkey'} = $ltoken_info{'linkkey'};
324: }
325: }
1.11 raeburn 326: &Apache::lonnet::tmpdel($link_info{'ltoken'});
1.10 raeburn 327: }
1.7 raeburn 328: if ($link_info{'linkprot'}) {
329: ($linkprotector,$linkproturi) = split(/:/,$link_info{'linkprot'},2);
330: if ($env{'user.linkprotector'}) {
331: my @protectors = split(/,/,$env{'user.linkprotector'});
332: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
333: push(@protectors,$linkprotector);
334: @protectors = sort { $a <=> $b } @protectors;
335: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
336: }
337: } else {
338: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
339: }
340: if ($env{'user.linkproturi'}) {
341: my @proturis = split(/,/,$env{'user.linkproturi'});
342: unless(grep(/^\Q$linkproturi\E$/,@proturis)) {
343: push(@proturis,$linkproturi);
344: @proturis = sort(@proturis);
345: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
346: }
347: } else {
348: &Apache::lonnet::appenv({'user.linkproturi' => $linkproturi});
349: }
1.15 raeburn 350: if ($link_info{'linkprotexit'}) {
351: $linkprotexit = $link_info{'linkprotexit'};
352: }
1.19 raeburn 353: if ($link_info{'linkprotpbid'}) {
354: $linkprotpbid = $link_info{'linkprotpbid'};
355: }
356: if ($link_info{'linkprotpburl'}) {
357: $linkprotpburl = $link_info{'linkprotpburl'};
358: }
1.8 raeburn 359: } elsif ($link_info{'linkkey'} ne '') {
360: $linkkey = $link_info{'linkkey'};
361: my $keyedlinkuri = $linkuri;
362: if ($env{'user.deeplinkkey'} ne '') {
363: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
364: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
365: push(@linkkeys,$linkkey);
366: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
367: }
368: } else {
369: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
370: }
371: if ($env{'user.keyedlinkuri'}) {
372: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
373: unless (grep(/^\Q$keyedlinkuri\E$/,@keyeduris)) {
374: push(@keyeduris,$keyedlinkuri);
375: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
376: }
377: } else {
378: &Apache::lonnet::appenv({'user.keyedlinkuri' => $keyedlinkuri});
379: }
1.7 raeburn 380: }
1.8 raeburn 381: if ($link_info{'checklaunch'}) {
382: $newlauncher = 1;
1.7 raeburn 383: }
1.21 raeburn 384: if ($link_info{'prevlaunch'} ne '') {
385: $prevlaunch = $link_info{'prevlaunch'};
386: }
1.8 raeburn 387: }
388: my $currdeeplinklogin = $env{'request.deeplink.login'};
389: my $deeplink;
390: if ($symb =~ /\.(page|sequence)$/) {
391: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]);
392: my $navmap = Apache::lonnavmaps::navmap->new();
393: if (ref($navmap)) {
394: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
1.7 raeburn 395: }
1.8 raeburn 396: } else {
397: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
1.7 raeburn 398: }
1.8 raeburn 399: if ($deeplink ne '') {
400: my $disallow;
1.15 raeburn 401: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
1.8 raeburn 402: if (($protect ne 'none') && ($protect ne '')) {
403: my ($acctype,$item) = split(/:/,$protect);
404: if ($acctype =~ /lti(c|d)$/) {
405: my $ltitype = $1;
406: if ($linkprotector) {
407: unless ($linkprotector.':'.$linkproturi eq $item.$ltitype.':'.$linkuri) {
408: $disallow = 1;
409: }
410: } else {
411: $disallow = 1;
1.7 raeburn 412: }
1.8 raeburn 413: } elsif ($acctype eq 'key') {
414: if ($linkkey ne '') {
415: unless ($linkkey eq $item) {
416: $disallow = 1;
1.7 raeburn 417: }
1.8 raeburn 418: } else {
419: $disallow = 1;
1.7 raeburn 420: }
1.8 raeburn 421: }
422: }
423: if ($disallow) {
424: if ($currdeeplinklogin eq $linkuri) {
425: &Apache::lonnet::delenv('request.deeplink.login');
1.10 raeburn 426: if ($env{'request.deeplink.target'} ne '') {
427: &Apache::lonnet::delenv('request.deeplink.target');
428: }
1.15 raeburn 429: if ($env{'request.linkprot'} ne '') {
430: &Apache::lonnet::delenv('request.linkprot');
431: }
432: if ($env{'request.linkprotexit'} ne '') {
433: &Apache::lonnet::delenv('request.linkprotexit');
434: }
1.19 raeburn 435: if ($env{'request.linkprotpbid'} ne '') {
436: &Apache::lonnet::delenv('request.linkprotpbid');
437: }
438: if ($env{'request.linkprotpburl'} ne '') {
439: &Apache::lonnet::delenv('request.linkprotpburl');
440: }
1.8 raeburn 441: }
442: } else {
1.22 raeburn 443: unless ($currdeeplinklogin eq $linkuri) {
1.8 raeburn 444: if (($linkprotector) || ($linkkey ne '')) {
1.22 raeburn 445: $newlauncher = 1;
446: }
447: }
448: if ($linkprotector) {
449: &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
1.23 ! raeburn 450: if ($linkprotpburl && $linkprotpbid) {
! 451: my ($res,$error) = &store_passback_info($cdom,$cnum,$linkuri,$linkprotector,
! 452: $scope,$symb,$linkprotpbid,$linkprotpburl,
! 453: $currdeeplinklogin);
! 454: }
1.22 raeburn 455: } elsif ($env{'request.linkprot'}) {
456: &Apache::lonnet::delenv('request.linkprot');
457: }
458: if ($linkkey ne '') {
459: &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
460: } elsif ($env{'request.linkkey'} ne '') {
461: &Apache::lonnet::delenv('request.linkkey');
462: }
463: if (($linkprotector) || ($linkkey ne '')) {
464: if ($linkprotexit ne $env{'request.linkprotexit'}) {
1.15 raeburn 465: if ($linkprotexit) {
466: &Apache::lonnet::appenv({'request.linkprotexit' => $linkprotexit});
467: } elsif ($env{'request.linkprotexit'}) {
468: &Apache::lonnet::delenv('request.linkprotexit');
469: }
1.22 raeburn 470: }
471: if ($linkprotpbid ne $env{'request.linkprotpbid'}) {
1.19 raeburn 472: if ($linkprotpbid) {
473: &Apache::lonnet::appenv({'request.linkprotpbid' => $linkprotpbid});
474: } elsif ($env{'request.linkprotpbid'}) {
475: &Apache::lonnet::delenv('request.linkprotpbid');
476: }
1.22 raeburn 477: }
478: if ($linkprotpburl ne $env{'request.linkprotpburl'}) {
1.19 raeburn 479: if ($linkprotpburl) {
480: &Apache::lonnet::appenv({'request.linkprotpburl' => $linkprotpburl});
481: } elsif ($env{'request.linkprotpburl'}) {
482: &Apache::lonnet::delenv('request.linkprotpburl');
483: }
1.22 raeburn 484: }
485: } elsif ($prevlaunch) {
486: foreach my $requestkey ('linkprotpbid','linkprotpburl','linkprotexit') {
487: if ($env{"request.$requestkey"}) {
488: &Apache::lonnet::delenv("request.$requestkey");
1.7 raeburn 489: }
490: }
491: }
492: &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
1.9 raeburn 493: if ($target ne '') {
494: &Apache::lonnet::appenv({'request.deeplink.target' => $target});
1.10 raeburn 495: } elsif ($env{'request.deeplink.target'} ne '') {
496: &Apache::lonnet::delenv('request.deeplink.target');
1.9 raeburn 497: }
1.7 raeburn 498: }
499: } else {
500: if ($linkprotector) {
501: &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
1.8 raeburn 502: } elsif ($env{'request.linkprot'}) {
1.14 raeburn 503: &Apache::lonnet::delenv('request.linkprot');
1.8 raeburn 504: }
1.15 raeburn 505: if ($linkprotexit) {
506: &Apache::lonnet::appenv({'request.linkprotexit' => $linkprotexit});
507: } elsif ($env{'request.linkprotexit'}) {
508: &Apache::lonnet::delenv('request.linkprotexit');
509: }
1.19 raeburn 510: if ($linkprotpbid) {
511: &Apache::lonnet::appenv({'request.linkprotpbid' => $linkprotpbid});
512: } elsif ($env{'request.linkprotpbid'}) {
513: &Apache::lonnet::delenv('request.linkprotpbid');
514: }
515: if ($linkprotpburl) {
516: &Apache::lonnet::appenv({'request.linkprotpburl' => $linkprotpburl});
517: } elsif ($env{'request.linkprotpburl'}) {
518: &Apache::lonnet::delenv('request.linkprotpburl');
519: }
1.8 raeburn 520: if ($linkkey ne '') {
1.7 raeburn 521: &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
1.8 raeburn 522: } else {
1.13 raeburn 523: &Apache::lonnet::delenv('request.linkkey');
1.7 raeburn 524: }
1.8 raeburn 525: &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
1.10 raeburn 526: if ($env{'request.deeplink.target'} ne '') {
527: &Apache::lonnet::delenv('request.deeplink.target');
528: }
1.7 raeburn 529: }
530: return $newlauncher;
531: }
532:
1.23 ! raeburn 533: #
! 534: # Store linkprotpburl and linkprotpbid in user's nohist_$cid_linkprot_pb.db
! 535: # $linkuri\0$linkprotector\0$scope = [$linkprotpbid,$linkprotpburl]
! 536: # Separately store $symb in course's nohist_linkprot_passback.db
! 537: # which should trigger passback:
! 538: # $symb => {$linkuri\0$linkprotector\0$scope => 1};
! 539: #
! 540:
! 541: sub store_passback_info {
! 542: my ($cdom,$cnum,$linkuri,$linkprotector,$scope,$symb,
! 543: $linkprotpbid,$linkprotpburl,$currdeeplinklogin) = @_;
! 544: my $key = join("\0",($linkuri,$linkprotector,$scope));
! 545: my $namespace = 'nohist_'.$cdom.'_'.$cnum.'_linkprot_pb';
! 546: if ($linkuri eq $currdeeplinklogin) {
! 547: my %pbinfo = &Apache::lonnet::get($namespace,[$key]);
! 548: if (ref($pbinfo{$key}) eq 'ARRAY') {
! 549: if (($pbinfo{$key}[0] eq $linkprotpbid) &&
! 550: ($pbinfo{$key}[1] eq $linkprotpburl)) {
! 551: return ('ok');
! 552: }
! 553: }
! 554: }
! 555: my $now = time;
! 556: my $result = &Apache::lonnet::cput($namespace,{$key => [$linkprotpbid,$linkprotpburl]});
! 557: my $error;
! 558: if (($result eq 'ok') || ($result eq 'con_delayed')) {
! 559: $namespace = 'nohist_linkprot_passback';
! 560: my %triggers = &Apache::lonnet::get($namespace,[$symb],$cdom,$cnum);
! 561: my $newtrigger;
! 562: if ((exists($triggers{$symb})) && (ref($triggers{$symb}) eq 'HASH')) {
! 563: unless (exists($triggers{$symb}{$key})) {
! 564: $newtrigger = 1;
! 565: }
! 566: } else {
! 567: $newtrigger = 1;
! 568: }
! 569: if ($newtrigger) {
! 570: my ($lockhash,$tries,$gotlock);
! 571: $lockhash = {
! 572: lock => $env{'user.name'}.
! 573: ':'.$env{'user.domain'},
! 574: };
! 575: $tries = 0;
! 576: $gotlock = &Apache::lonnet::newput($namespace,$lockhash,$cdom,$cnum);
! 577: while (($gotlock ne 'ok') && ($tries<10)) {
! 578: $tries ++;
! 579: sleep (0.1);
! 580: $gotlock = &Apache::lonnet::newput($namespace,$lockhash,$cdom,$cnum);
! 581: }
! 582: if ($gotlock eq 'ok') {
! 583: %triggers = &Apache::lonnet::get($namespace,[$symb],$cdom,$cnum);
! 584: $triggers{$symb}{$key} = 1;
! 585: $result = &Apache::lonnet::cput($namespace,{$symb => $triggers{$symb}},$cdom,$cnum);
! 586: my $dellockoutcome = &Apache::lonnet::del($namespace,['lock'],$cdom,$cnum);
! 587: } else {
! 588: $error = 'nolock';
! 589: }
! 590: }
! 591: }
! 592: return ($result,$error);
! 593: }
! 594:
1.1 raeburn 595: sub do_redirect {
1.11 raeburn 596: my ($r,$destination,$linkprot) = @_;
1.2 raeburn 597: my $windowname = 'loncapaclient';
598: if ($env{'request.lti.login'}) {
599: $windowname .= 'lti';
600: }
1.1 raeburn 601: my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
602: my $args = {'bread_crumbs' => [{'href' => '','text' => 'Role initialization'},],};
1.11 raeburn 603: if ($linkprot) {
604: $args = {'only_body' => 1,
605: 'redirect' => [0,$destination],};
606: }
1.1 raeburn 607: &Apache::loncommon::content_type($r,'text/html');
608: $r->send_http_header;
1.11 raeburn 609: if ($linkprot) {
610: $r->print(&Apache::loncommon::start_page('Valid link','',$args).
611: &Apache::loncommon::end_page());
612: } else {
613: $r->print(&Apache::loncommon::start_page('Valid link',$header,$args).
614: &Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";').
615: '<h1>'.&mt('Welcome').'</h1>'.
616: '<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>'.
617: '<a href="'.$destination.'">'.&mt('Continue').'</a></p>'.
618: &Apache::loncommon::end_page());
619: }
1.1 raeburn 620: return;
621: }
622:
623: sub show_roles {
1.19 raeburn 624: my ($r,$crsenv,$possroles,$hassection,$hascustom,$futureroles,$expiredroles,
625: $linkprot,$linkprotuser,$linkprotexit,$linkprotpbid,$linkprotpburl,$ltoken) = @_;
1.1 raeburn 626: my ($crsdesc,$crstype,$cdom,$cnum,$header,$title,$preamble,$datatable,$js,$args);
627: if (ref($crsenv) eq 'HASH') {
628: $crsdesc = $crsenv->{'description'};
629: $crstype = $crsenv->{'type'};
630: $cdom = $crsenv->{'domain'};
631: $cnum = $crsenv->{'num'};
632: }
633: if ($crstype eq '') {
634: $crstype = 'Course';
635: }
636: my $lc_crstype = lc($crstype);
637: if ($crsdesc ne '') {
638: $header = &mt("The page you requested belongs to the following $lc_crstype: [_1]",
639: '<i>'.$crsdesc.'</i>');
640: }
641: if (ref($possroles) eq 'HASH') {
642: if (keys(%{$possroles}) > 0) {
643: $args = {'bread_crumbs' => [{'href' => '','text' => "Choose role in $lc_crstype"},],};
1.11 raeburn 644: if ($linkprot) {
645: $args = {'only_body' => 1};
646: }
1.1 raeburn 647: $title = 'Choose a role'; #Do not localize.
648: if ($crstype eq 'Community') {
649: $preamble = &mt('You have the following active roles in this community:');
650: } else {
651: $preamble = &mt('You have the following active roles in this course:');
652: }
653: $datatable = '<form name="" action="/adm/roles">'.
1.8 raeburn 654: '<input type="hidden" name="newrole" value="" />'."\n".
655: '<input type="hidden" name="selectrole" value="1" />'."\n".
1.11 raeburn 656: '<input type="hidden" name="destinationurl" value="'.&HTML::Entities::encode($r->uri,'&<>"').'" />'."\n";
1.8 raeburn 657: if ($env{'form.ttoken'}) {
658: $datatable .= '<input type="hidden" name="ttoken" value="'.$env{'form.ttoken'}.'" />'."\n";
659: }
660: $datatable .= &Apache::loncommon::start_data_table().
661: &Apache::loncommon::start_data_table_header_row().
662: '<th></th><th>'.&mt('User role').'</th>';
1.1 raeburn 663: if ($hassection) {
664: $datatable .= '<th>'.&mt('Section').'</th>';
665: }
666: if ($hascustom) {
667: $datatable .= '<th>'.&mt('Information').'</th>';
668: }
669: $datatable .= &Apache::loncommon::end_data_table_header_row();
670: my @available = sort(keys(%{$possroles}));
671: foreach my $role ('ad','in','ta','ep','st','cr') {
672: foreach my $key (@available) {
673: if ($key =~ m{^$role($|/)}) {
674: my $trolecode = "$key./$cdom/$cnum";
675: my $rolename = &Apache::lonnet::plaintext($key,$crstype,$cdom.'_'.$cnum);
676: my $sec = $possroles->{$key};
677: if ($sec ne '') {
678: $trolecode .= '/'.$sec;
679: }
680: my $buttonname=$trolecode;
681: $buttonname=~s/\W//g;
682: $datatable .= &Apache::loncommon::start_data_table_row().
683: '<td><input name="'.$buttonname.'" type="button" value="'.
684: &mt('Select').'" onclick="javascript:enterrole(this.form,'.
685: "'$trolecode','$buttonname'".');" /></td>';
686: if ($key =~ /^cr\//) {
687: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$key);
688: $datatable .= '<td><span class="LC_nobreak">'.$rolename.'</span></td>';
689: if ($hassection) {
690: $datatable .= '<td>'.$sec.'</td>';
691: }
692: $datatable.= '<td><span class="LC_fontsize_small LC_cusr_emph">'.
693: &mt('Custom role defined by [_1]',$rauthor.':'.$rdomain).
694: '</td>';
695: } else {
696: if ($hassection) {
697: $datatable .= '<td>'.$rolename.'</td>';
698: if ($hascustom) {
699: $datatable .= '<td colspan="2">'.$sec.'</td>';
700: } else {
701: $datatable .= '<td>'.$sec.'</td>';
702: }
703: } elsif ($hascustom) {
704: $datatable .= '<td colspan="2">'.$rolename.'</td>';
705: } else {
706: $datatable .= '<td>'.$rolename.'</td>';
707: }
708: }
709: $datatable .= &Apache::loncommon::end_data_table_row();
710: }
711: }
712: }
713: $datatable .= &Apache::loncommon::end_data_table().
714: '</form>';
715: my $standby = &mt('Role selected. Please stand by.');
716: $js = <<"ENDJS";
717: <script type="text/javascript">
718: // <![CDATA[
719:
720: active=true;
721:
722: function enterrole (thisform,rolecode,buttonname) {
723: if (active) {
724: active=false;
725: document.title='$standby';
726: window.status='$standby';
727: thisform.newrole.value=rolecode;
728: thisform.submit();
729: } else {
730: alert('$standby');
731: }
732: }
733:
734: // ]]>
735: </script>
736: ENDJS
737: } else {
1.11 raeburn 738: if ($linkprot) {
739: $title = 'No access';
740: $preamble = '<p>'.&mt('Access unavailable for this LON-CAPA content.').'</p>';
741: $args->{'only_body'} = 1;
742: } else {
743: $title = 'No active role';
744: $preamble = '<p>'.&mt("You have no active roles in this $lc_crstype so the page is currently unavailable to you.").'</p>';
745: $args = {'bread_crumbs' => [{'href' => '','text' => 'Role status'},],};
746: }
747: $header = &mt('No access for: [_1]','<b>'.&Apache::loncommon::plainname($env{'user.name'},
748: $env{'user.domain'}).'</b>');
749: if ((ref($futureroles) eq 'HASH') && (keys(%{$futureroles}) > 0)) {
750: my @future = sort { $a <=> $b } (keys(%{$futureroles}));
751: $preamble .= '<p>'.&mt('Access will begin: [_1].',&Apache::lonlocal::locallocaltime($future[0])).
752: ' '.&mt('Please try again then.').'</p>';
753: } elsif ((ref($expiredroles) eq 'HASH') && (keys(%{$expiredroles}) > 0)) {
754: my @expired = sort { $b <=> $a } (keys(%{$expiredroles}));
755: $preamble .= '<p>'.&mt('Access ended: [_1].',&Apache::lonlocal::locallocaltime($expired[0])).'</p>';
756: } elsif ($linkprot) {
757: if ($linkprotuser) {
758: my ($uname,$udom) = split(/:/,$linkprotuser,2);
759: $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>';
760: } else {
761: my $relogin;
762: my %data = (
763: origurl => $r->uri,
764: linkprot => $linkprot,
1.12 raeburn 765: linkprotexit => $linkprotexit,
1.19 raeburn 766: linkprotpbid => $linkprotpbid,
767: linkprotpburl => $linkprotpburl,
1.11 raeburn 768: );
769: my $token =
770: &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'retry');
771: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
772: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
773: $relogin = '/adm/relaunch?rtoken='.$token;
774: }
775: $preamble .= '<p>'.&mt('You might try logging in with a different username and/or domain.').' '.
776: &mt('You are currently logged in as: [_1] in domain: [_2]',
777: '<i>'.$env{'user.name'}.'</i>','<i>'.$env{'user.domain'}.'</i>').'</p>';
778: if ($relogin) {
779: $preamble .= '<p>'.&mt('[_1]Log-in again[_2]','<a href="'.$relogin.'" target="_self">','</a>').'</p>';
780: }
781: }
782: }
783: if ($env{'form.ttoken'}) {
784: &Apache::lonnet::tmpdel($env{'form.ttoken'});
785: }
786: if ($ltoken) {
787: &Apache::lonnet::tmpdel($ltoken);
788: }
1.1 raeburn 789: }
790: }
791: &Apache::loncommon::content_type($r,'text/html');
792: $r->send_http_header;
793: $r->print(&Apache::loncommon::start_page($title,$js,$args).
794: '<h3>'.$header.'</h3>'.
795: '<div>'.$preamble.'</div>'.
796: $datatable.
797: &Apache::loncommon::end_page());
798: return;
799: }
800:
801: sub generic_error {
802: my ($r) = @_;
1.3 raeburn 803: my $continuelink;
804: unless ($env{'request.lti.login'}) {
805: my $linktext;
806: if ($env{'user.adv'}) {
807: $linktext = &mt('Continue to your roles page');
808: } else {
809: $linktext = &mt('Continue to your courses page');
810: }
811: $continuelink='<a href="/adm/roles">'.$linktext.'</a>';
1.1 raeburn 812: }
813: my $msg = &mt('The page you requested does not exist.');
814: &Apache::loncommon::content_type($r,'text/html');
815: $r->send_http_header;
816: my $args = {'bread_crumbs' => [{'href' => '','text' => 'Link status'},],};
817: $r->print(&Apache::loncommon::start_page('Invalid URL',undef,$args).
818: '<div class="LC_error">'.$msg.'</div>'.
819: '<p>'.$continuelink.'</p>'.
820: &Apache::loncommon::end_page());
821: return;
822: }
823:
824: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>