File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.90: download - view: text, annotated - select for diffs
Tue Dec 15 20:48:53 2009 UTC (14 years, 5 months ago) by amueller
Branches: MAIN
CVS tags: HEAD
-XHTML conformance.

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonsimplepage.pm,v 1.90 2009/12/15 20:48:53 amueller Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonsimplepage;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::loncommon;
   34: use Apache::lontemplate;
   35: use Apache::lonnet;
   36: use Apache::lontexconvert;
   37: use Apache::lonfeedback;
   38: use Apache::lonlocal;
   39: use Apache::lonprintout;
   40: use Apache::lonxml;
   41: use Apache::longroup;
   42: use HTML::Entities();
   43: use LONCAPA;
   44: 
   45: sub get_db_name {
   46:     my ($url) = @_;
   47:     my ($udom,$uname,$marker)=(split(m{/},$url))[2,3,4];
   48:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   49:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   50: 
   51:     my $db_name;
   52: 
   53:     if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
   54:         $marker =~ s/\W//g;
   55:         $db_name = 'grppage_'.$marker;
   56:     } else {
   57:         $marker=~s/\D//g;
   58:         $db_name = 'smppage_'.$marker;
   59:     }
   60:     return if (!defined($marker));
   61: 
   62:     return $db_name;
   63: }
   64: 
   65: sub handler {
   66:     my $r = shift;
   67:     &Apache::loncommon::content_type($r,'text/html');
   68:     $r->send_http_header;
   69:     return OK if $r->header_only;
   70:     my $target=$env{'form.grade_target'};
   71: # ------------------------------------------------------------ Print the screen
   72:     if ($target eq 'tex') {
   73:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   74:     }
   75: 
   76: # Is this even in a course?
   77:     unless ($env{'request.course.id'}) {
   78:         if ($target ne 'tex') {
   79:             &Apache::loncommon::simple_error_page($r,'','Not in a course');
   80:         } else {
   81:             $r->print('\textbf{Not in a course}\end{document}');
   82:         }
   83:         return OK;
   84:     }
   85: 
   86:     my $db_name = &get_db_name($r->uri);
   87: 
   88:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   89:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   90:     my ($group,$group_desc,$group_home_view,$group_home_edit,
   91:         $group_view_perm,$group_edit_perm);
   92:     my %curr_group = ();
   93:     my %groupinfo = ();
   94:     if ($db_name =~ /^grppage_/) {
   95:         $group = (split(m{/},$r->uri))[4];
   96:         $group =~ s/\W//g;
   97:         my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
   98:         if (!%curr_groups) {
   99:             &Apache::loncommon::simple_error_page($r,'','Invalid group name');
  100:             return OK;
  101:         }
  102:         %groupinfo =
  103:         &Apache::longroup::get_group_settings($curr_groups{$group});
  104:         $group_desc = &unescape($groupinfo{'description'});
  105:     }
  106: 
  107:     if (!$db_name) {
  108:         &Apache::loncommon::simple_error_page($r,'','Invalid call');
  109:         return OK;
  110:     }
  111: 
  112: # --------------------------------------------------------- The syllabus fields
  113:     my %syllabusfields=&Apache::lonlocal::texthash(
  114:        'aaa_title'         => 'Page Title',
  115:        'bbb_content'       => 'Content',
  116:        'ccc_webreferences' => 'Web References');
  117:     if ($group ne '') {
  118:         $syllabusfields{'abb_links'} = &mt('Available Group Tools');
  119:     }
  120: 
  121: 
  122: # ------------------------------------------------------------ Get query string
  123:     &Apache::loncommon::get_unprocessed_cgi
  124:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit',
  125:                                                'register','ref']);
  126: # --------------------------------------------------------------- Force Student
  127:     my $forcestudent='';
  128:     if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
  129:     my $forceedit='';
  130:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
  131: 
  132:     my $refarg;
  133:     if ($env{'form.ref'}) {
  134:         $refarg = '&ref='.$env{'form.ref'};
  135:     }
  136: 
  137:     my %syllabus=&Apache::lonnet::dump($db_name,$dom,$crs);
  138: 
  139: # --------------------------------------- There is such a user, get environment
  140: 
  141:     if ($target ne 'tex') {
  142:         my $title = 'Simple Course Page';
  143:         if ($group ne '') {
  144:             $title = 'Simple Group Page';
  145:         }
  146:         my $start_page =
  147:         &Apache::loncommon::start_page($title,undef,
  148:                        {'function'       => $forcestudent,
  149:                         'domain'         => $dom,
  150:                         'force_register' =>
  151:                         $env{'form.register'},});
  152:         $r->print($start_page);
  153:     }
  154: 
  155:     if ($group ne '') {
  156:         my $group_view_perm =
  157:                &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
  158:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  159:         $group_edit_perm =
  160:                &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
  161:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  162:         $group_home_view = &Apache::lonnet::allowed('vgh',
  163:                                          $env{'request.course.id'}.'/'.$group);
  164:         $group_home_edit = &Apache::lonnet::allowed('mgh',
  165:                                          $env{'request.course.id'}.'/'.$group);
  166:         if ($group_view_perm || $group_edit_perm || $group_home_view ||
  167:             $group_home_edit || &Apache::longroup::check_group_access($group)) {
  168:             if (($env{'form.ref'} eq 'grouplist') && ($target ne 'tex')) {
  169:                 $r->print(&grouppage_breadcrumbs($dom,$crs,$group,$group_desc));
  170:             }
  171:             if ((!$group_home_edit) && (!$group_home_view) &&
  172:                 (!$group_view_perm) && (!$group_edit_perm)) {
  173:                 &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
  174:                 if ($env{'form.grade_target'} ne 'tex') {
  175:                     $r->print(&Apache::loncommon::end_page());
  176:                 } else {
  177:                     $r->print('\end{document}');
  178:                 }
  179:                 return OK;
  180:             }
  181:         } else {
  182:             my $msg =
  183:             &mt('You do not currently have rights to view this group.');
  184:             if ($target ne 'tex') {
  185:                 $r->print('<p class="LC_warning">'.$msg.'</p>'.
  186:                 &Apache::loncommon::end_page());
  187:             } else {
  188:                 $r->print('\textbf{'.$msg.'}\end{document}');
  189:             }
  190:             return OK;
  191:         }
  192:         my ($blocked,$blocktext) =
  193:              &Apache::loncommon::blocking_status('groups');
  194:         if ($blocked) {
  195:             $r->print($blocktext);
  196:             $r->print(&Apache::loncommon::end_page());
  197:             return OK;
  198:         }
  199:     }
  200: 
  201:     my $allowed;
  202: 
  203:     if ($group ne '') {
  204:         $allowed  = $group_edit_perm;
  205:         if (!$allowed) {
  206:             $allowed = $group_home_edit;
  207:         }
  208:     } else {
  209:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  210:     }
  211:     my $privileged=$allowed;
  212:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  213:         $forcestudent='student';
  214:     }
  215: 
  216:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
  217: 
  218:     if (($env{'form.uploaddoc.filename'} and $target ne 'tex') &&
  219:     ($env{'form.storeupl'}) && ($allowed)) {
  220:         if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  221:             if ($syllabus{'uploaded.photourl'}) {
  222:                 &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  223:             }
  224:             if ($group ne '') {
  225:                 $syllabus{'uploaded.photourl'}=&Apache::lonnet::userfileupload(
  226:                                               'uploaddoc',1,"grouppage/$group");
  227:             } else {
  228:                 $syllabus{'uploaded.photourl'}=
  229:                 &Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
  230:             }
  231:         }
  232:         $syllabus{'uploaded.lastmodified'}=time;
  233:         &Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
  234:     }
  235: #    if ($allowed && $env{'form.delupl'}) {
  236: #        if ($syllabus{'uploaded.photourl'}) {
  237: #            &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  238: #            delete($syllabus{'uploaded.photourl'});
  239: #            &Apache::lonnet::del('simplepage',['uploaded.photourl']);
  240: #        }
  241: #    }
  242:     if (($allowed) && ($env{'form.storesyl'})) {
  243:         foreach my $syl_field (keys(%syllabusfields)) {
  244:             my $field=$env{'form.'.$syl_field};
  245:             chomp($field);
  246:             $field=~s/\s+$//s;
  247:             $field=~s/^\s+//s;
  248:             $field=~s/\<br\s*\/*\>$//s;
  249:             $field=&Apache::lonfeedback::clear_out_html($field,1);
  250:             $syllabus{$syl_field}=$field;
  251:         }
  252:         $syllabus{'uploaded.lastmodified'}=time;
  253:         &Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
  254:     }
  255: 
  256: #---Print Function
  257:     if ($target ne 'tex') {
  258:         if ($allowed || $privileged) {
  259:             my $functions=&Apache::lonhtmlcommon::start_funclist();
  260:             if ($allowed) {
  261:                 $functions.=&Apache::lonhtmlcommon::add_item_funclist(
  262:                                 '<a href="'.$r->uri.'?forcestudent=1">'
  263:                                .&mt('Show Student View').'</a>'
  264:                                .&Apache::loncommon::help_open_topic(
  265:                                     'Uploaded_Templates_PublicView'));
  266:             } elsif ($privileged) {
  267:                 my $edittext = &mt('Edit');
  268:                     if ($group ne '') {
  269:                     $edittext = &mt('Edit Group Homepage');
  270:                 }
  271:                 $functions.=&Apache::lonhtmlcommon::add_item_funclist(
  272:                                 '<a href="'.$r->uri.'?forceedit=edit'.$refarg.'">'
  273:                                .$edittext.'</a>');
  274:                 if ($group ne '') {
  275:                     if ($group_edit_perm) {
  276:                         $functions.=&Apache::lonhtmlcommon::add_item_funclist(
  277:                                         '<a href="/adm/coursegroups'
  278:                                        .'?action=modify&amp;refpage=grouplist'
  279:                                        .'&amp;state=pick_task&amp;groupname='
  280:                                        .$group.'">'
  281:                                        .&mt('Edit Group Settings')
  282:                                        .'</a>');
  283:                        }
  284:                     }
  285:             }
  286:             $functions.=&Apache::lonhtmlcommon::end_funclist();
  287:             $r->print(&Apache::loncommon::head_subbox($functions));
  288:         }
  289:     }
  290: 
  291: #---Print help Text
  292:     if($target ne 'tex'){
  293:         if ($allowed) {
  294:             $r->print(&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')));
  295:         }
  296:     }
  297: 
  298: # ---------------------------------------------------------------- Get syllabus
  299:     if ((($syllabus{'uploaded.lastmodified'}) &&
  300:          (($group ne '' && ($group_home_view || $group_edit_perm ||
  301:            $group_view_perm)) || ($group eq ''))) || ($allowed)) {
  302:         #Print the title
  303:         my $titletext=$syllabus{'aaa_title'};
  304:         if ($target ne 'tex') {
  305:             if ($allowed) {
  306:             }
  307:             $r->print('<h2>'.$titletext.'</h2>');
  308:         } else {
  309:             my $safeinit;
  310:             $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$titletext.'</h1>'));
  311:         }
  312:         if ($allowed) {
  313:             if ($env{'form.grade_target'} ne 'tex') {
  314:                 #editbox for title
  315:                 $r->print('<form method="post" action="" enctype="multipart/form-data">');
  316:                 &Apache::lontemplate::print_template($r, &mt('Title'), $titletext, $allowed, 'LC_Box');
  317:                 &Apache::lontemplate::print_editbox_template($r,$syllabus{'aaa_title'},'aaa_title');
  318:             } else {
  319:                 my $safeinit;
  320:                 $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{'aaa_title'},$safeinit));
  321:             }
  322:         }
  323: 
  324:         #print the image
  325:         my $image;
  326:         if ($syllabus{'uploaded.photourl'}) {
  327:             &Apache::lonnet::allowuploaded('/adm/smppg',
  328:                     $syllabus{'uploaded.photourl'});
  329: 
  330:             $image='<img src="'.$syllabus{'uploaded.photourl'}
  331:                   .'" alt="'.&mt('Image').'" />';
  332:             if ($target eq 'tex') {
  333:                 $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  334:             }
  335:         }
  336: 
  337:         if ($allowed) {
  338:             $r->print('<input type="hidden" name="forceedit" value="edit" />');
  339:             my $upload_photo_label = &mt('Upload a Photo');
  340:             my $upload_button_label = &mt('Upload');
  341: 
  342:             my $content_for_upload_photo=<<"UPLOAD_PHOTO";
  343:                   <input type="file" name="uploaddoc" size="50" />
  344:                   <input type="submit" name="storeupl" value="$upload_button_label" />
  345:                   <input type="hidden" name="forceedit" value="edit" />
  346: UPLOAD_PHOTO
  347:             &Apache::lontemplate::print_template($r, $upload_photo_label,$content_for_upload_photo,$allowed, 'LC_Box');
  348: 
  349: #            if ($syllabus{'uploaded.photourl'}) {
  350: #                $r->print('<input type="submit" name="delupl"'
  351: #                         .' value="'.&mt('Delete Photo').'" />');
  352: #            }
  353:         }
  354:         if ($allowed) {
  355:             $r->print($image.'<div class="LC_footer_clear">&nbsp;</div>');
  356:         }
  357:         if (!$allowed) {$r->print($image); }
  358: 
  359:         foreach my $field (sort(keys(%syllabusfields))) {
  360:             if (($syllabus{$field}) || ($allowed) ||
  361:                 ($field eq 'abb_links' && $group ne '')) {
  362:                 my $message=$syllabus{$field};
  363:                 if (!&Apache::lonfeedback::contains_block_html($message)) {
  364:                		&Apache::lonfeedback::newline_to_br(\$message);
  365:                	}
  366:                 $message=~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  367:                 if ($allowed) {
  368:                     $message=&Apache::lonspeller::markeduptext($message);
  369:                 }
  370:                 if ($target ne 'tex') {
  371:                     $message=&Apache::lontexconvert::msgtexconverted($message);
  372:                 }
  373:                 if ($field eq 'abb_links' && $group ne '') {
  374:                     $r->print('<br /><input type="hidden" name="'.$field.
  375:                                           '" value="'.$syllabus{$field}.'" />');
  376:                     &display_group_links($r,$target,$group,'edit',$refarg,
  377:                                     %groupinfo);
  378:                     $r->print('<br />');
  379:                 } elsif ($field eq 'aaa_title') {
  380:                     next;
  381:                 } else {
  382:                     if ($target ne 'tex') {
  383:                         if ($allowed) {
  384:                         }
  385:                         &Apache::lontemplate::print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
  386:                     } else {
  387:                         my $safeinit;
  388:                         $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$field}.'</h3>'));
  389:                         $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
  390:                     }
  391:                     if ($allowed) {
  392:                         if ($target ne 'tex') {
  393:                             &Apache::lontemplate::print_editbox_template($r,$syllabus{$field},$field);
  394:                         } else {
  395:                             my $safeinit;
  396:                             $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$field},$safeinit));
  397:                         }
  398:                     }
  399:                 }
  400:             }
  401:         }
  402:         if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
  403:             $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
  404:                 ('bbb_content').'</form>');
  405:         }
  406: 
  407:     } else {
  408:         if ($group ne '') {
  409:             &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
  410:         } else {
  411:             my $text=&mt('No page information provided.');
  412:             if ($target ne 'tex') {
  413:                 $r->print('<p class="LC_info">'.$text.'</p>');
  414:             } else {
  415:             $r->print($text)
  416:             }
  417:         }
  418:     }
  419:     if ($env{'form.grade_target'} ne 'tex') {
  420:         $r->print(&Apache::loncommon::end_page());
  421:     } else {
  422:         $r->print('\end{document}');
  423:     }
  424:     return OK;
  425: }
  426: 
  427: sub display_group_links {
  428:     my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
  429:     my @available = ();
  430:     my %menu = ();
  431:     %{$menu{'email'}} = (
  432:                         text => 'Group Message',
  433:                         href => '/adm/email?compose=group&amp;group='.$group.
  434:                                 $refarg,
  435:                       );
  436:     %{$menu{'discussion'}} = (
  437:                         text => 'Discussion Boards',
  438:                         href => '/adm/groupboards?group='.$group.$refarg,
  439:                       );
  440:     %{$menu{'chat'}} = (
  441:                         text => 'Group Chat Room',
  442:                         href => "javascript:group_chat('$group')",
  443:                       );
  444:     %{$menu{'files'}} = (
  445:                         text => 'Group Portfolio',
  446:                         href => '/adm/coursegrp_portfolio?group='.$group.
  447:                                 $refarg,
  448:                       );
  449:     %{$menu{'roster'}} = (
  450:                         text => 'Membership Roster',
  451:                         href => '/adm/grouproster?group='.$group.$refarg,
  452:                       );
  453:     foreach my $tool (sort(keys(%menu))) {
  454:         if ($groupinfo{functions}{$tool} eq 'on') {
  455:             push(@available,$tool);
  456:         }
  457:     }
  458:     if (@available > 0) {
  459:         my $output = '';
  460:         if ($target eq 'tex') {
  461:             $output = '<table cellspacing="4" cellpadding="4">';
  462:         } else {
  463:             $output = &Apache::loncommon::start_data_table();
  464:         }
  465:         foreach my $tool (@available) {
  466:             if ($target eq 'tex') {
  467:                 $output .= '<tr><td>'.&mt($menu{$tool}{text}).'</td></tr>';
  468:             } else {
  469:                 $output .= &Apache::loncommon::start_data_table_row()
  470:                           .'<td><a href="'.$menu{$tool}{href}.'">'
  471:                           .&mt($menu{$tool}{text}).'</a></td>'
  472:                           .&Apache::loncommon::end_data_table_row();
  473:             }
  474:         }
  475:         if ($target eq 'tex') {
  476:             $output .= '</table>';
  477:         } else {
  478:             $output .= &Apache::loncommon::end_data_table();
  479:         }
  480:         if ($target eq 'tex') {
  481:             $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
  482:         } else {
  483:             $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
  484:         }
  485:     } else {
  486:         my $output;
  487:         if ($context eq 'edit') {
  488:             $output = &mt('No group functionality.');
  489:         } else {
  490:             $output = &mt('No group functionality (e.g., e-mail, discussion, chat room or file upload) is currently available to you in this group: [_1].','<b>'.&unescape($groupinfo{'description'}).'</b>');
  491:         }
  492:         if ($target eq 'tex') {
  493:             $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
  494:         } else {
  495:             $r->print($output);
  496:         }
  497:     }
  498: }
  499: 
  500: sub grouppage_breadcrumbs {
  501:     my ($cdom,$cnum,$group,$description) = @_;
  502:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  503:     &Apache::lonhtmlcommon::add_breadcrumb
  504:         ({href=>"/adm/coursegroups",
  505:           text=>"Groups",
  506:           title=>"Display Groups"},
  507:         {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
  508:           text=>&mt('Group:')." $description",
  509:           title=>"Go to group's home page"},
  510:         );
  511:     my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group page - [_1]',
  512:                                                            $description));
  513:     return $output;
  514: }
  515: 
  516: 1;
  517: __END__

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