File:  [LON-CAPA] / loncom / interface / lontiny.pm
Revision 1.8.2.2: download - view: text, annotated - select for diffs
Fri May 27 18:10:44 2022 UTC (2 years, 1 month ago) by raeburn
Branches: version_2_11_4_msu
- For 2.11.4 (modified)
  Include changes in rev. 1.9 and rev. 1.10

    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: #
    5: # $Id: lontiny.pm,v 1.8.2.2 2022/05/27 18:10:44 raeburn Exp $
    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;
   38: use Apache::lonuserstate;
   39: use Apache::lonnavmaps;
   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);
   47:     if ($handle ne '') {
   48:         my $lonidsdir=$r->dir_config('lonIDsDir');
   49:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   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') {
   70:                             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['ttoken']);
   71:                             if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
   72:                                 # Check for ttoken
   73:                                 my $newlauncher = &launch_check($r->uri,$symb);
   74:                                 my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb);
   75:                                 if (&Apache::lonnet::is_on_map($url)) {
   76:                                     my $realuri;
   77:                                     if ((&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) &&
   78:                                         (!$env{'request.role.adv'})) {
   79:                                         $env{'user.error.msg'}=$r->uri.':bre:1:1:Access to resource denied';
   80:                                         return HTTP_NOT_ACCEPTABLE;
   81:                                     }
   82:                                     if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) &&
   83:                                         (!$env{'request.role.adv'})) {
   84:                                         $realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url));
   85:                                         if (($url =~ /\.sequence$/) &&
   86:                                             ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
   87:                                             $realuri .= '?navmap=1';
   88:                                         } else {
   89:                                             $realuri .= '?symb='.&Apache::lonenc::encrypted($symb);
   90:                                         }
   91:                                     } else {
   92:                                         $realuri = &Apache::lonnet::clutter($url);
   93:                                         if (($url =~ /\.sequence$/) &&
   94:                                             ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
   95:                                             $realuri .= '?navmap=1';
   96:                                         } else {
   97:                                             $realuri .= '?symb='.$symb;
   98:                                         }
   99:                                     }
  100:                                     my $update;
  101:                                     # Check if course needs to be re-initialized
  102:                                     if ($newlauncher) {
  103:                                         $update = 1;
  104:                                     } else {
  105:                                         my $loncaparev = $r->dir_config('lonVersion');
  106:                                         my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
  107:                                         if ($result eq 'update') {
  108:                                             $update = 1;
  109:                                         } elsif (!-e $env{'request.course.fn'}.'.db') {
  110:                                             $update = 1;
  111:                                         } elsif (!$env{'request.role.adv'}) {
  112:                                             my $navmap = Apache::lonnavmaps::navmap->new();
  113:                                             if (ref($navmap)) {
  114:                                                 my $res = $navmap->getBySymb($symb);
  115:                                                 if (ref($res)) {
  116:                                                     my ($enc_in_bighash,$enc_in_parm);
  117:                                                     $enc_in_bighash = $res->encrypted();
  118:                                                     if (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) {
  119:                                                         $enc_in_parm = 1;
  120:                                                     }
  121:                                                     if ($enc_in_bighash ne $enc_in_parm) {
  122:                                                         $update = 1;
  123:                                                     }
  124:                                                 }
  125:                                             }
  126:                                         }
  127:                                     }
  128:                                     if ($update) {
  129:                                         my ($furl,$ferr)=
  130:                                             &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  131:                                         if ($ferr) {
  132:                                             $env{'user.error.msg'}=$r->uri.':bre:0:0:Course not initialized';
  133:                                             $env{'user.reinit'} = 1;
  134:                                             return HTTP_NOT_ACCEPTABLE;
  135:                                         }
  136:                                     }
  137:                                     my $host = $r->headers_in->get('Host');
  138:                                     if (!$host) {
  139:                                         $r->internal_redirect($realuri);
  140:                                         return OK;
  141:                                     } else {
  142:                                         my $protocol = 'http';
  143:                                         if ($r->get_server_port == 443) {
  144:                                             $protocol = 'https';
  145:                                         }
  146:                                         my $location = $protocol.'://'.$host.$realuri;
  147:                                         $r->headers_out->set(Location => $location);
  148:                                         return REDIRECT;
  149:                                     }
  150:                                 }
  151:                             } else {
  152:                                 my %crsenv = &Apache::lonnet::coursedescription("$cdom/$cnum");
  153:                                 my @possroles = ('in','ta','ep','st','cr','ad');
  154:                                 if ($crsenv{'type'} eq 'Community') {
  155:                                     unshift(@possroles,'co');
  156:                                 } else {
  157:                                     unshift(@possroles,'cc');
  158:                                 }
  159:                                 my %roleshash = &Apache::lonnet::get_my_roles($env{'user.uname'},
  160:                                                                               $env{'user.domain'},
  161:                                                                               'userroles',undef,
  162:                                                                               \@possroles,[$cdom],1);
  163:                                 my (%possroles,$hassection);
  164:                                 if (keys(%roleshash)) {
  165:                                     foreach my $entry (keys(%roleshash)) {
  166:                                         if ($entry =~ /^\Q$cnum:$cdom:\E([^:]+):([^:]*)$/) {
  167:                                             $possroles{$1} = $2;
  168:                                             if ($2 ne '') {
  169:                                                 $hassection = 1;
  170:                                             }
  171:                                         }
  172:                                     }
  173:                                 }
  174:                                 my @allposs = keys(%possroles);
  175:                                 if (@allposs == 0) {
  176:                                     &show_roles($r,\%crsenv,\%possroles);
  177:                                 } elsif (@allposs == 1) {
  178:                                     my $newrole = "$allposs[0]./$cdom/$cnum";
  179:                                     $newrole = "$allposs[0]./$cdom/$cnum";
  180:                                     if ($possroles{$allposs[0]} ne '') {
  181:                                         $newrole .= "/$possroles{$allposs[0]}"; 
  182:                                     }
  183:                                     my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
  184:                                                        '&destinationurl='.&HTML::Entities::encode($r->uri);
  185:                                     if ($env{'form.ttoken'}) {
  186:                                         $destination .= '&ttoken='.$env{'form.ttoken'};
  187:                                     }
  188:                                     &do_redirect($r,$destination);
  189:                                 } elsif (keys(%possroles) > 1) {
  190:                                     if (grep(/^(cc|co)$/,@allposs)) {
  191:                                         my $newrole;
  192:                                         if (exists($possroles{'cc'})) {
  193:                                             $newrole = 'cc';
  194:                                         } else {
  195:                                             $newrole = 'co';
  196:                                         }
  197:                                         $newrole .= "./$cdom/$cnum";
  198:                                         my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'.
  199:                                                            '&destinationurl='.&HTML::Entities::encode($r->uri);
  200:                                         if ($env{'form.ttoken'}) {
  201:                                             $destination .= '&ttoken='.$env{'form.ttoken'};
  202:                                         }
  203:                                         &do_redirect($r,$destination);
  204:                                     } else {
  205:                                         my $hascustom;
  206:                                         if (grep(/^cr\//,@allposs)) {
  207:                                             $hascustom = 1;
  208:                                         }
  209:                                         &show_roles($r,\%crsenv,\%possroles,$hassection,$hascustom);
  210:                                     }
  211:                                 }
  212:                                 return OK;
  213:                             }
  214:                         }
  215:                     }
  216:                 }
  217:             }
  218:         }
  219:         &generic_error($r);
  220:         return OK;
  221:     } else {
  222:         return FORBIDDEN;
  223:     }
  224: }
  225: 
  226: sub launch_check {
  227:     my ($linkuri,$symb) = @_;
  228:     my ($linkprotector,$linkproturi,$linkkey,$newlauncher);
  229:     if ($env{'form.ttoken'}) {
  230:         my %link_info = &Apache::lonnet::tmpget($env{'form.ttoken'});
  231:         &Apache::lonnet::tmpdel($env{'form.ttoken'});
  232:         delete($env{'form.ttoken'});
  233:         if ($link_info{'ltoken'}) {
  234:             unless (($link_info{'linkprot'}) || ($link_info{'linkkey'} ne '')) {
  235:                 my %ltoken_info = &Apache::lonnet::tmpget($link_info{'ltoken'});
  236:                 if ($ltoken_info{'linkprot'}) {
  237:                     $link_info{'linkprot'} = $ltoken_info{'linkprot'};
  238:                 } elsif ($ltoken_info{'linkkey'} ne '') {
  239:                     $link_info{'linkkey'} = $ltoken_info{'linkkey'};
  240:                 }
  241:             }
  242:             &Apache::lonnet::tmpdel($env{'form.ltoken'});
  243:             delete($env{'form.ltoken'});
  244:         }
  245:         if ($link_info{'linkprot'}) {
  246:             ($linkprotector,$linkproturi) = split(/:/,$link_info{'linkprot'},2);
  247:             if ($env{'user.linkprotector'}) {
  248:                 my @protectors = split(/,/,$env{'user.linkprotector'});
  249:                 unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
  250:                     push(@protectors,$linkprotector);
  251:                     @protectors = sort { $a <=> $b } @protectors;
  252:                     &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
  253:                 }
  254:             } else {
  255:                 &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
  256:             }
  257:             if ($env{'user.linkproturi'}) {
  258:                 my @proturis = split(/,/,$env{'user.linkproturi'});
  259:                 unless(grep(/^\Q$linkproturi\E$/,@proturis)) {
  260:                     push(@proturis,$linkproturi);
  261:                     @proturis = sort(@proturis);
  262:                     &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
  263:                 }
  264:             } else {
  265:                 &Apache::lonnet::appenv({'user.linkproturi' => $linkproturi});
  266:             }
  267:         } elsif ($link_info{'linkkey'} ne '') {
  268:             $linkkey = $link_info{'linkkey'};
  269:             my $keyedlinkuri = $linkuri;
  270:             if ($env{'user.deeplinkkey'} ne '') {
  271:                 my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
  272:                 unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
  273:                     push(@linkkeys,$linkkey);
  274:                     &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
  275:                 }
  276:             } else {
  277:                 &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
  278:             }
  279:             if ($env{'user.keyedlinkuri'}) {
  280:                 my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
  281:                 unless (grep(/^\Q$keyedlinkuri\E$/,@keyeduris)) {
  282:                     push(@keyeduris,$keyedlinkuri);
  283:                     &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
  284:                 }
  285:             } else {
  286:                 &Apache::lonnet::appenv({'user.keyedlinkuri' => $keyedlinkuri});
  287:             }
  288:         }
  289:         if ($link_info{'checklaunch'}) {
  290:             $newlauncher = 1;
  291:         }
  292:     }
  293:     my $currdeeplinklogin = $env{'request.deeplink.login'};
  294:     my $deeplink;
  295:     if ($symb =~ /\.(page|sequence)$/) {
  296:         my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]);
  297:         my $navmap = Apache::lonnavmaps::navmap->new();
  298:         if (ref($navmap)) {
  299:             $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
  300:         }
  301:     } else {
  302:         $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
  303:     }
  304:     if ($deeplink ne '') {
  305:         my $disallow;
  306:         my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
  307:         if (($protect ne 'none') && ($protect ne '')) {
  308:             my ($acctype,$item) = split(/:/,$protect);
  309:             if ($acctype =~ /lti(c|d)$/) {
  310:                 my $ltitype = $1;
  311:                 if ($linkprotector) {
  312:                     unless ($linkprotector.':'.$linkproturi eq $item.$ltitype.':'.$linkuri) {
  313:                         $disallow = 1;
  314:                     }
  315:                 } else {
  316:                     $disallow = 1;
  317:                 }
  318:             } elsif ($acctype eq 'key') {
  319:                 if ($linkkey ne '') {
  320:                     unless ($linkkey eq $item) {
  321:                         $disallow = 1;
  322:                     }
  323:                 } else {
  324:                     $disallow = 1;
  325:                 }
  326:             }
  327:         }
  328:         if ($disallow) {
  329:             if ($currdeeplinklogin eq $linkuri) {
  330:                 &Apache::lonnet::delenv('request.deeplink.login');
  331:                 if ($env{'request.deeplink.target'} ne '') {
  332:                     &Apache::lonnet::delenv('request.deeplink.target');
  333:                 }
  334:             }
  335:         } else {
  336:             unless ($currdeeplinklogin eq $linkuri) {
  337:                 if (($linkprotector) || ($linkkey ne '')) {
  338:                     if ($linkprotector) {
  339:                         &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
  340:                     } elsif ($env{'request.linkprot'}) {
  341:                         &Apache::lonnet::delenv({'request.linkprot'});
  342:                     }
  343:                     if ($linkkey ne '') {
  344:                         &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
  345:                     } elsif ($env{'request.linkkey'} ne '') {
  346:                         &Apache::lonnet::delenv({'request.linkkey'});
  347:                     }
  348:                     $newlauncher = 1;
  349:                 }
  350:             }
  351:             &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
  352:             if ($target ne '') {
  353:                 &Apache::lonnet::appenv({'request.deeplink.target' => $target});
  354:             } elsif ($env{'request.deeplink.target'} ne '') {
  355:                 &Apache::lonnet::delenv('request.deeplink.target');
  356:             }
  357:         }
  358:     } else {
  359:         if ($linkprotector) {
  360:             &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi});
  361:         } elsif ($env{'request.linkprot'}) {
  362:             &Apache::lonnet::delenv({'request.linkprot'});
  363:         }
  364:         if ($linkkey ne '') {
  365:             &Apache::lonnet::appenv({'request.linkkey' => $linkkey});
  366:         } else {
  367:             &Apache::lonnet::delenv({'request.linkkey'});
  368:         }
  369:         &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri});
  370:         if ($env{'request.deeplink.target'} ne '') {
  371:             &Apache::lonnet::delenv('request.deeplink.target');
  372:         }
  373:     }
  374:     return $newlauncher;
  375: }
  376: 
  377: sub do_redirect {
  378:     my ($r,$destination) = @_;
  379:     my $windowname = 'loncapaclient';
  380:     my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
  381:     my $args = {'bread_crumbs' => [{'href' => '','text' => 'Role initialization'},],};
  382:     &Apache::loncommon::content_type($r,'text/html');
  383:     $r->send_http_header;
  384:     $r->print(&Apache::loncommon::start_page('Valid link',$header,$args).
  385:               &Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";').
  386:               '<h1>'.&mt('Welcome').'</h1>'.
  387:               '<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>'.
  388:               '<a href="'.$destination.'">'.&mt('Continue').'</a></p>'.
  389:               &Apache::loncommon::end_page());
  390:     return;
  391: }
  392: 
  393: sub show_roles {
  394:     my ($r,$crsenv,$possroles,$hassection,$hascustom) = @_;
  395:     &Apache::loncommon::content_type($r,'text/html');
  396:     $r->send_http_header;
  397:     my ($crsdesc,$crstype,$cdom,$cnum,$header,$title,$preamble,$datatable,$js,$args);
  398:     if (ref($crsenv) eq 'HASH') {
  399:         $crsdesc = $crsenv->{'description'};
  400:         $crstype = $crsenv->{'type'};
  401:         $cdom = $crsenv->{'domain'};
  402:         $cnum = $crsenv->{'num'};
  403:     }
  404:     if ($crstype eq '') {
  405:         $crstype = 'Course';
  406:     }
  407:     my $lc_crstype = lc($crstype);
  408:     if ($crsdesc ne '') {
  409:         $header = &mt("The page you requested belongs to the following $lc_crstype: [_1]",
  410:                       '<i>'.$crsdesc.'</i>');
  411:     }
  412:     if (ref($possroles) eq 'HASH') {
  413:         if (keys(%{$possroles}) > 0) {
  414:             $args = {'bread_crumbs' => [{'href' => '','text' => "Choose role in $lc_crstype"},],};
  415:             $title = 'Choose a role'; #Do not localize.
  416:             if ($crstype eq 'Community') {
  417:                 $preamble = &mt('You have the following active roles in this community:');
  418:             } else { 
  419:                 $preamble = &mt('You have the following active roles in this course:');
  420:             }
  421:             $datatable = '<form name="" action="/adm/roles">'.
  422:                          '<input type="hidden" name="newrole" value="" />'."\n".
  423:                          '<input type="hidden" name="selectrole" value="1" />'."\n".
  424:                          '<input type="hidden" name="destinationurl" value="'.$r->uri.'" />'."\n";
  425:             if ($env{'form.ttoken'}) {
  426:                 $datatable .= '<input type="hidden" name="ttoken" value="'.$env{'form.ttoken'}.'" />'."\n";
  427:             }
  428:             $datatable .= &Apache::loncommon::start_data_table().
  429:                           &Apache::loncommon::start_data_table_header_row().
  430:                           '<th></th><th>'.&mt('User role').'</th>';
  431:             if ($hassection) {
  432:                 $datatable .= '<th>'.&mt('Section').'</th>';
  433:             }
  434:             if ($hascustom) {
  435:                 $datatable .= '<th>'.&mt('Information').'</th>';
  436:             }
  437:             $datatable .= &Apache::loncommon::end_data_table_header_row();
  438:             my @available = sort(keys(%{$possroles}));
  439:             foreach my $role ('ad','in','ta','ep','st','cr') {
  440:                 foreach my $key (@available) {
  441:                     if ($key =~ m{^$role($|/)}) {
  442:                         my $trolecode = "$key./$cdom/$cnum";
  443:                         my $rolename = &Apache::lonnet::plaintext($key,$crstype,$cdom.'_'.$cnum);
  444:                         my $sec = $possroles->{$key};
  445:                         if ($sec ne '') {
  446:                             $trolecode .= '/'.$sec;
  447:                         }
  448:                         my $buttonname=$trolecode;
  449:                         $buttonname=~s/\W//g;
  450:                         $datatable .= &Apache::loncommon::start_data_table_row().
  451:                                       '<td><input name="'.$buttonname.'" type="button" value="'.
  452:                                       &mt('Select').'" onclick="javascript:enterrole(this.form,'.
  453:                                       "'$trolecode','$buttonname'".');" /></td>';
  454:                         if ($key =~ /^cr\//) {
  455:                             my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$key);
  456:                             $datatable .= '<td><span class="LC_nobreak">'.$rolename.'</span></td>';
  457:                             if ($hassection) {
  458:                                 $datatable .= '<td>'.$sec.'</td>';
  459:                             }
  460:                             $datatable.= '<td><span class="LC_fontsize_small LC_cusr_emph">'.
  461:                                           &mt('Custom role defined by [_1]',$rauthor.':'.$rdomain).
  462:                                           '</td>';
  463:                         } else {
  464:                             if ($hassection) {
  465:                                 $datatable .= '<td>'.$rolename.'</td>';
  466:                                 if ($hascustom) {
  467:                                     $datatable .= '<td colspan="2">'.$sec.'</td>';
  468:                                 } else {
  469:                                     $datatable .= '<td>'.$sec.'</td>';
  470:                                 }
  471:                             } elsif ($hascustom) {
  472:                                 $datatable .= '<td colspan="2">'.$rolename.'</td>';
  473:                             } else {
  474:                                 $datatable .= '<td>'.$rolename.'</td>';
  475:                             }
  476:                         }
  477:                         $datatable .= &Apache::loncommon::end_data_table_row();
  478:                     }
  479:                 }
  480:             }
  481:             $datatable .= &Apache::loncommon::end_data_table().
  482:                           '</form>';
  483:             my $standby = &mt('Role selected. Please stand by.');
  484:             $js = <<"ENDJS";
  485: <script type="text/javascript">
  486: // <![CDATA[
  487: 
  488: active=true;
  489: 
  490: function enterrole (thisform,rolecode,buttonname) {
  491:     if (active) {
  492:         active=false;
  493:         document.title='$standby';
  494:         window.status='$standby';
  495:         thisform.newrole.value=rolecode;
  496:         thisform.submit();
  497:     } else {
  498:        alert('$standby');
  499:     }
  500: }
  501: 
  502: // ]]>
  503: </script>
  504: ENDJS
  505:         } else {
  506:             $title = 'No active role';
  507:             $preamble = &mt("You have no active roles in this $lc_crstype so the page is currently unavailable to you.");
  508:             $args = {'bread_crumbs' => [{'href' => '','text' => 'Role status'},],};
  509:         }
  510:     }
  511:     &Apache::loncommon::content_type($r,'text/html');
  512:     $r->send_http_header;
  513:     $r->print(&Apache::loncommon::start_page($title,$js,$args).
  514:               '<h3>'.$header.'</h3>'.
  515:               '<div>'.$preamble.'</div>'.
  516:               $datatable.
  517:               &Apache::loncommon::end_page());
  518:     return;
  519: }
  520: 
  521: sub generic_error {
  522:     my ($r) = @_;
  523:     my $continuelink;
  524:     my $linktext;
  525:     if ($env{'user.adv'}) {
  526:         $linktext = &mt('Continue to your roles page');
  527:     } else {
  528:         $linktext = &mt('Continue to your courses page');
  529:     }
  530:     $continuelink='<a href="/adm/roles">'.$linktext.'</a>';
  531:     my $msg = &mt('The page you requested does not exist.');
  532:     &Apache::loncommon::content_type($r,'text/html');
  533:     $r->send_http_header;
  534:     my $args = {'bread_crumbs' => [{'href' => '','text' => 'Link status'},],};
  535:     $r->print(&Apache::loncommon::start_page('Invalid URL',undef,$args).
  536:               '<div class="LC_error">'.$msg.'</div>'.
  537:               '<p>'.$continuelink.'</p>'.
  538:               &Apache::loncommon::end_page());
  539:     return;
  540: }
  541: 
  542: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>