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