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