Annotation of loncom/interface/lonsimplepage.pm, revision 1.43

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

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