File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.45: download - view: text, annotated - select for diffs
Thu Jul 20 03:11:52 2006 UTC (17 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Style - naming.  Caller (grppage) obsolete.  Store uploaded photos in right place. Add "Edit group settings" link for users with mdg priv in course.  Priv checking for roles with section specificity. Ensure vcg and mdg privs see page contents as well as links to group tools. Some &mt().  loncoursegroups - wording changes.  Add breadcrumb for access via "Edit settings" link on group home page.

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

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