File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.46: download - view: text, annotated - select for diffs
Thu Jul 20 15:03:01 2006 UTC (17 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, HEAD
Display of group tools links was not occurring for user with 'mdg' privilege in one particular case.  Now displayed.

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonsimplepage.pm,v 1.46 2006/07/20 15:03:01 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:                 ($_ eq 'abb_links' && $group ne '')) {
  263: 		my $message=$syllabus{$_};
  264: 		&Apache::lonfeedback::newline_to_br(\$message);
  265: 		$message
  266: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  267: 		if ($allowed) {
  268: 		    $message=&Apache::lonspeller::markeduptext($message);
  269: 		}
  270: 		$message=&Apache::lontexconvert::msgtexconverted($message);
  271:                 if ($_ eq 'abb_links' && $group ne '') {
  272:                     $r->print('<br /><input type="hidden" name="'.$_.
  273:                                           '" value="'.$syllabus{$_}.'" />');
  274:                     &display_group_links($r,$target,$group,'edit',$refarg,
  275:                                          %groupinfo);
  276:                     $r->print('<br />');
  277:                 } elsif ($_ eq 'aaa_title') {
  278:                     if ($target ne 'tex') {
  279:                         $r->print('<h1>'.$message.'</h1>');
  280:                     } else {
  281:                         my $safeinit;
  282:                         $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
  283:                     }
  284:                     if ($allowed) {
  285:                         if ($env{'form.grade_target'} ne 'tex') {
  286:                             $r->print(
  287:                                       '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  288:                                       $syllabus{$_}.
  289:                                       '</textarea><input type="submit" name="storesyl" value="Store" />');
  290:                         } else {
  291:                             my $safeinit;
  292:                             $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  293:                         }
  294:                     }
  295:                 } else {
  296: 		    if (($_ ne 'bbb_content') || ($allowed)) {
  297: 			if ($target ne 'tex') {
  298: 			    $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  299: 			} else {
  300: 			    my $safeinit;
  301: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
  302: 			}
  303: 		    }
  304: 		    if ($target ne 'tex') {
  305: 			$r->print('<blockquote>'.
  306: 				  $message.'</blockquote>');
  307: 		    } else {
  308: 			my $safeinit;
  309: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
  310: 		    }
  311: 		    if ($allowed) {
  312: 			if ($target ne 'tex') {
  313: 			    $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
  314: 				      $syllabus{$_}.
  315: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
  316: 			} else {
  317: 			    my $safeinit;
  318: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  319: 			}
  320: 		    }
  321: 		}
  322: 	    }
  323: 	}
  324: 	if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
  325: 	    $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
  326: 		      ('bbb_content').'</form>');
  327: 	}
  328: 	if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
  329:     } else {
  330:         if ($group ne '') {
  331:             &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
  332:         } else {
  333: 	    $r->print(&mt('<p>No page information provided.</p>'));
  334:         }
  335:     }
  336:     if ($env{'form.grade_target'} ne 'tex') {
  337: 	$r->print(&Apache::loncommon::end_page());
  338:     } else {
  339: 	$r->print('\end{document}');
  340:     }
  341:     return OK;
  342: }
  343: 
  344: sub display_group_links {
  345:     my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
  346:     my @available = ();
  347:     my %menu = ();
  348:     %{$menu{'email'}} = (
  349:                         text => 'Group e-mail',
  350:                         href => '/adm/email?compose=group&amp;group='.$group.
  351:                                 $refarg,
  352:                       );
  353:     %{$menu{'discussion'}} = (
  354:                         text => 'Discussion Boards',
  355:                         href => '/adm/groupboards?group='.$group.$refarg,
  356:                       );
  357:     %{$menu{'chat'}} = (
  358:                         text => 'Group chat',
  359:                         href => "javascript:group_chat('$group')",
  360:                       );
  361:     %{$menu{'files'}} = (
  362:                         text => 'File repository',
  363:                         href => '/adm/coursegrp_portfolio?group='.$group.
  364:                                 $refarg,
  365:                       );
  366:     %{$menu{'roster'}} = (
  367:                         text => 'Membership roster',
  368:                         href => '/adm/grouproster?group='.$group.$refarg,
  369:                       );
  370:     foreach my $tool (sort(keys(%menu))) {
  371:         if ($groupinfo{functions}{$tool} eq 'on') {
  372:             push(@available,$tool);
  373:         }
  374:     }
  375:     if (@available > 0) {
  376:         my $output = '<table cellspacing="4" cellpadding="4"><tr>';
  377:         foreach my $tool (@available) {
  378:             if ($target eq 'tex') {
  379:                 $output .= '<td>'.&mt($menu{$tool}{text}).'</td>';
  380:             } else {
  381:                 $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
  382:                            $menu{$tool}{text}.'</a></td>';
  383:             }
  384:         }
  385:         $output .= '</tr></table>';
  386:         if ($target eq 'tex') {
  387:             $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
  388:         } else {
  389:             $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
  390:         }
  391:     } else {
  392:         my $output;
  393:         if ($context eq 'edit') {
  394:             $output = &mt('No group functionality.');
  395:         } else {  
  396:             $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'}));
  397:         }
  398:         if ($target eq 'tex') {
  399:             $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
  400:         } else {
  401:             $r->print($output);
  402:         }
  403:     }
  404: }
  405: 
  406: sub grouppage_breadcrumbs {
  407:     my ($cdom,$cnum,$group,$description) = @_;
  408:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  409:     &Apache::lonhtmlcommon::add_breadcrumb
  410:         ({href=>"/adm/coursegroups",
  411:           text=>"Groups",
  412:           title=>"Display Groups"},
  413:         {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
  414:           text=>"Group: $description",
  415:           title=>"Go to group's home page"},
  416:         );
  417:     my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group page - [_1]',
  418:                                                            $description));
  419:     return $output;
  420: }
  421: 
  422: 1;
  423: __END__

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