File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.49: download - view: text, annotated - select for diffs
Mon Dec 11 03:49:12 2006 UTC (17 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_3_X, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_99_1, version_2_2_99_0, HEAD
Group homepages not displayed in a course with active block conditions, if 'groups' condirion included, unless user has 'evb' privilege in the course.

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonsimplepage.pm,v 1.49 2006/12/11 03:49:12 raeburn 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::lonnet;
   35: use Apache::lontexconvert;
   36: use Apache::lonfeedback;
   37: use Apache::lonlocal;
   38: use Apache::lonprintout;
   39: use Apache::lonxml;
   40: use Apache::longroup;
   41: use HTML::Entities();
   42: use LONCAPA;
   43: 
   44: sub handler {
   45:     my $r = shift;
   46:     &Apache::loncommon::content_type($r,'text/html');
   47:     $r->send_http_header;
   48:     return OK if $r->header_only;
   49:     my $target=$env{'form.grade_target'};
   50: # ------------------------------------------------------------ Print the screen
   51:     if ($target eq 'tex') {
   52: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   53:     } 
   54:     my (undef,undef,$udom,$uname,$marker)=split(/\//,$r->uri);
   55: # Is this even in a course?
   56:     unless ($env{'request.course.id'}) {
   57: 	if ($target ne 'tex') {
   58: 	    &Apache::loncommon::simple_error_page($r,'','Not in a course');
   59: 	} else {
   60: 	    $r->print('\textbf{Not in a course}\end{document}');
   61: 	}
   62: 	return OK;
   63:     }
   64: 
   65:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   66:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   67:     my ($namespace,$group,$group_desc,$group_home_view,$group_home_edit,
   68:         $group_view_perm,$group_edit_perm);
   69:     my %curr_group = ();
   70:     my %groupinfo = ();
   71:     if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
   72:         $marker =~ s/\W//g;
   73:         $group = $marker;
   74:         my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
   75:         if (!%curr_groups) {
   76: 	    &Apache::loncommon::simple_error_page($r,'','Invalid group name');
   77: 	    return OK;
   78:         }
   79:         %groupinfo = 
   80: 	    &Apache::longroup::get_group_settings($curr_groups{$group});
   81:         $group_desc = &unescape($groupinfo{'description'});
   82:         $namespace = 'grppage_'.$group;
   83:     } else {
   84:         $marker=~s/\D//g;
   85:         $namespace = 'smppage_'.$marker;
   86:     }
   87: 
   88:     if (!$marker) {
   89: 	&Apache::loncommon::simple_error_page($r,'','Invalid call');
   90: 	return OK;
   91:     }
   92: 
   93: # --------------------------------------------------------- The syllabus fields
   94:     my %syllabusfields=&Apache::lonlocal::texthash(
   95:        'aaa_title'         => 'Page Title',
   96:        'bbb_content'       => 'Content',
   97:        'ccc_webreferences' => 'Web References');
   98:     if ($group ne '') {
   99:         $syllabusfields{'abb_links'} = &mt('Available Group Tools');
  100:     }
  101: 
  102: 
  103: # ------------------------------------------------------------ Get query string
  104:     &Apache::loncommon::get_unprocessed_cgi
  105:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit',
  106:                                                'register','ref']);
  107: # --------------------------------------------------------------- Force Student
  108:     my $forcestudent='';
  109:     if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
  110:     my $forceedit='';
  111:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
  112: 
  113:     my $refarg;
  114:     if ($env{'form.ref'}) {
  115:         $refarg = '&ref='.$env{'form.ref'};
  116:     }
  117:    
  118:     my %syllabus=&Apache::lonnet::dump($namespace,$dom,$crs);
  119:        
  120: # --------------------------------------- There is such a user, get environment
  121: 
  122:     if ($target ne 'tex') {
  123:         my $title = 'Course Page';
  124:         if ($group ne '') {
  125:             $title = 'Group Page';
  126:         }
  127: 	my $start_page = 
  128: 	    &Apache::loncommon::start_page($title,undef,
  129: 					   {'function'       => $forcestudent,
  130: 					    'domain'         => $dom,
  131: 					    'force_register' =>
  132: 						$env{'form.register'},});
  133: 	$r->print($start_page);
  134:     }
  135: 
  136:     if ($group ne '') {
  137:         my $group_view_perm =
  138:                &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
  139:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  140:         $group_edit_perm =
  141:                &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
  142:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  143:         $group_home_view = &Apache::lonnet::allowed('vgh',
  144:                                          $env{'request.course.id'}.'/'.$group);
  145:         $group_home_edit = &Apache::lonnet::allowed('mgh',
  146:                                          $env{'request.course.id'}.'/'.$group);
  147:         if ($group_view_perm || $group_edit_perm || $group_home_view || 
  148:             $group_home_edit || &Apache::longroup::check_group_access($group)) {
  149:             if (($env{'form.ref'} eq 'grouplist') && ($target ne 'tex')) {
  150:                 $r->print(&grouppage_breadcrumbs($dom,$crs,$group,$group_desc));
  151:             }
  152:             if ((!$group_home_edit) && (!$group_home_view) && 
  153:                 (!$group_view_perm) && (!$group_edit_perm)) {
  154:                 &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
  155:                 if ($env{'form.grade_target'} ne 'tex') {
  156:                     $r->print(&Apache::loncommon::end_page());
  157:                 } else {
  158:                     $r->print('\end{document}');
  159:                 }
  160:                 return OK;
  161:             }
  162:         } else {
  163: 	    my $msg = 
  164: 		&mt('You do not currently have rights to view this group.');
  165:             if ($target ne 'tex') {
  166:                 $r->print("<p>$msg</p>".
  167: 			  &Apache::loncommon::end_page());
  168:             } else {
  169:                 $r->print('\textbf{'.$msg.'}\end{document}');
  170:             }
  171: 	    return OK;
  172:         }
  173:         my ($blocked,$blocktext) = 
  174:              &Apache::loncommon::blocking_status('groups');
  175:         if ($blocked) {
  176:             $r->print($blocktext);
  177:             $r->print(&Apache::loncommon::end_page());
  178:             return OK;
  179:         }
  180:     }
  181: 
  182:     my $allowed;
  183:     
  184:     if ($group ne '') {
  185:         $allowed  = $group_edit_perm;
  186:         if (!$allowed) {
  187:             $allowed = $group_home_edit; 
  188:         }
  189:     } else { 
  190:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  191:     }
  192:     my $privileged=$allowed;
  193:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  194: 	$forcestudent='student';
  195:     }
  196: 
  197:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
  198: 
  199:     if ($allowed) {
  200: 	$r->print('<p>'.
  201: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?forcestudent=1'.$refarg.'"><font size="+1">'.&mt('Show Student View').'</font></a>'.
  202: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  203:     } elsif ($privileged and $target ne 'tex') {
  204:         my $edittext = &mt('Edit');
  205:         if ($group ne '') {
  206:             $edittext = &mt('Edit Group Homepage');
  207:         }
  208: 	$r->print('<a href="'.$r->uri.'?forceedit=edit'.$refarg.'"><font size="+1">'.$edittext.'</font></a>');
  209:         if ($group ne '') {
  210:             if ($group_edit_perm) {
  211:                 $r->print('&nbsp;&nbsp;&nbsp;<font size="+1">'.
  212:                '<a href="/adm/coursegroups?action=modify&amp;refpage=grouplist'.
  213:                '&amp;state=pick_task&amp;groupname='.$group.'">'.
  214:                &mt('Edit Group Settings').'</a></font>');
  215:             }
  216:         }    
  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($namespace,\%syllabus,$dom,$crs);
  234:     }
  235:     if (($allowed) && ($env{'form.storesyl'})) {
  236: 	foreach my $syl_field (keys(%syllabusfields)) {
  237: 	    my $field=$env{'form.'.$syl_field};
  238: 	    chomp($field);
  239: 	    $field=~s/\s+$//s;
  240: 	    $field=~s/^\s+//s;
  241: 	    $field=~s/\<br\s*\/*\>$//s;
  242: 	    $field=&Apache::lonfeedback::clear_out_html($field,1);
  243: 	    $syllabus{$syl_field}=$field;
  244: 	}
  245: 	$syllabus{'uploaded.lastmodified'}=time;
  246: 	&Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
  247:     }
  248: 
  249: # ---------------------------------------------------------------- Get syllabus
  250:     if ((($syllabus{'uploaded.lastmodified'}) && 
  251:          (($group ne '' && ($group_home_view || $group_edit_perm ||  
  252:            $group_view_perm)) || ($group eq ''))) || ($allowed)) {
  253: 	if ($syllabus{'uploaded.photourl'}) {
  254: 	    &Apache::lonnet::allowuploaded('/adm/smppg',
  255: 					   $syllabus{'uploaded.photourl'});
  256: 	    
  257: 	    my $image='<img src="'.$syllabus{'uploaded.photourl'}.'"
  258:                             align="right" />';
  259: 	    if ($target eq 'tex') {
  260: 		$image=&Apache::lonxml::xmlparse($r,'tex',$image);
  261: 	    }
  262: 	    $r->print($image);
  263: 	}
  264: 	if ($allowed) {
  265: 	    $r->print(
  266: 		      '<form method="post" enctype="multipart/form-data">'.
  267: 		      '<input type="hidden" name="forceedit" value="edit" />'.
  268: 		      '<h3>Upload a Photo</h3>'.
  269: 		      '<input type="file" name="uploaddoc" size="50">'.
  270: 		      '<input type="submit" name="storeupl" value="Upload">'.
  271: 		      '</form><form method="post">');
  272: 	}
  273: 	foreach my $field (sort(keys(%syllabusfields))) {
  274: 	    if (($syllabus{$field}) || ($allowed) || 
  275:                 ($field eq 'abb_links' && $group ne '')) {
  276: 		my $message=$syllabus{$field};
  277: 		&Apache::lonfeedback::newline_to_br(\$message);
  278: 		$message
  279: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  280: 		if ($allowed) {
  281: 		    $message=&Apache::lonspeller::markeduptext($message);
  282: 		}
  283: 		$message=&Apache::lontexconvert::msgtexconverted($message);
  284:                 if ($field eq 'abb_links' && $group ne '') {
  285:                     $r->print('<br /><input type="hidden" name="'.$field.
  286:                                           '" value="'.$syllabus{$field}.'" />');
  287:                     &display_group_links($r,$target,$group,'edit',$refarg,
  288:                                          %groupinfo);
  289:                     $r->print('<br />');
  290:                 } elsif ($field eq 'aaa_title') {
  291:                     if ($target ne 'tex') {
  292:                         $r->print('<h1>'.$message.'</h1>');
  293:                     } else {
  294:                         my $safeinit;
  295:                         $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
  296:                     }
  297:                     if ($allowed) {
  298:                         if ($env{'form.grade_target'} ne 'tex') {
  299:                             $r->print(
  300:                                       '<br />Title<br /><textarea cols="80" rows="2" name="'.$field.'">'.
  301:                                       &HTML::Entities::encode($syllabus{$field},'"&<>').
  302:                                       '</textarea><input type="submit" name="storesyl" value="Store" />');
  303:                         } else {
  304:                             my $safeinit;
  305:                             $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$field},$safeinit));
  306:                         }
  307:                     }
  308:                 } else {
  309: 		    if (($field ne 'bbb_content') || ($allowed)) {
  310: 			if ($target ne 'tex') {
  311: 			    $r->print('<h3>'.$syllabusfields{$field}.'</h3>');
  312: 			} else {
  313: 			    my $safeinit;
  314: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$field}.'</h3>'));
  315: 			}
  316: 		    }
  317: 		    if ($target ne 'tex') {
  318: 			$r->print('<blockquote>'.
  319: 				  $message.'</blockquote>');
  320: 		    } else {
  321: 			my $safeinit;
  322: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
  323: 		    }
  324: 		    if ($allowed) {
  325: 			if ($target ne 'tex') {
  326: 			    $r->print('<br /><textarea cols="80" rows="24" name="'.$field.'" id="'.$field.'">'.
  327:                                       &HTML::Entities::encode($syllabus{$field},'"&<>').
  328: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
  329: 			} else {
  330: 			    my $safeinit;
  331: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$field},$safeinit));
  332: 			}
  333: 		    }
  334: 		}
  335: 	    }
  336: 	}
  337: 	if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
  338: 	    $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
  339: 		      ('bbb_content').'</form>');
  340: 	}
  341: 	if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
  342:     } else {
  343:         if ($group ne '') {
  344:             &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
  345:         } else {
  346: 	    $r->print(&mt('<p>No page information provided.</p>'));
  347:         }
  348:     }
  349:     if ($env{'form.grade_target'} ne 'tex') {
  350: 	$r->print(&Apache::loncommon::end_page());
  351:     } else {
  352: 	$r->print('\end{document}');
  353:     }
  354:     return OK;
  355: }
  356: 
  357: sub display_group_links {
  358:     my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
  359:     my @available = ();
  360:     my %menu = ();
  361:     %{$menu{'email'}} = (
  362:                         text => 'Group e-mail',
  363:                         href => '/adm/email?compose=group&amp;group='.$group.
  364:                                 $refarg,
  365:                       );
  366:     %{$menu{'discussion'}} = (
  367:                         text => 'Discussion Boards',
  368:                         href => '/adm/groupboards?group='.$group.$refarg,
  369:                       );
  370:     %{$menu{'chat'}} = (
  371:                         text => 'Group chat',
  372:                         href => "javascript:group_chat('$group')",
  373:                       );
  374:     %{$menu{'files'}} = (
  375:                         text => 'File repository',
  376:                         href => '/adm/coursegrp_portfolio?group='.$group.
  377:                                 $refarg,
  378:                       );
  379:     %{$menu{'roster'}} = (
  380:                         text => 'Membership roster',
  381:                         href => '/adm/grouproster?group='.$group.$refarg,
  382:                       );
  383:     foreach my $tool (sort(keys(%menu))) {
  384:         if ($groupinfo{functions}{$tool} eq 'on') {
  385:             push(@available,$tool);
  386:         }
  387:     }
  388:     if (@available > 0) {
  389:         my $output = '<table cellspacing="4" cellpadding="4"><tr>';
  390:         foreach my $tool (@available) {
  391:             if ($target eq 'tex') {
  392:                 $output .= '<td>'.&mt($menu{$tool}{text}).'</td>';
  393:             } else {
  394:                 $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
  395:                            $menu{$tool}{text}.'</a></td>';
  396:             }
  397:         }
  398:         $output .= '</tr></table>';
  399:         if ($target eq 'tex') {
  400:             $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
  401:         } else {
  402:             $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
  403:         }
  404:     } else {
  405:         my $output;
  406:         if ($context eq 'edit') {
  407:             $output = &mt('No group functionality.');
  408:         } else {  
  409:             $output = &mt('No group functionality (e.g., e-mail, discussion, chat or file upload) is currently available to you in this group: <b>[_1]</b>.',&unescape($groupinfo{'description'}));
  410:         }
  411:         if ($target eq 'tex') {
  412:             $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
  413:         } else {
  414:             $r->print($output);
  415:         }
  416:     }
  417: }
  418: 
  419: sub grouppage_breadcrumbs {
  420:     my ($cdom,$cnum,$group,$description) = @_;
  421:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  422:     &Apache::lonhtmlcommon::add_breadcrumb
  423:         ({href=>"/adm/coursegroups",
  424:           text=>"Groups",
  425:           title=>"Display Groups"},
  426:         {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
  427:           text=>"Group: $description",
  428:           title=>"Go to group's home page"},
  429:         );
  430:     my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group page - [_1]',
  431:                                                            $description));
  432:     return $output;
  433: }
  434: 
  435: 1;
  436: __END__

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