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