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