1: # The LearningOnline Network
2: # Simple Page Editor
3: #
4: # $Id: lonsimplepage.pm,v 1.44 2006/07/08 01:12:53 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: use Apache::longroup;
41: use LONCAPA;
42:
43: sub handler {
44: my $r = shift;
45: &Apache::loncommon::content_type($r,'text/html');
46: $r->send_http_header;
47: return OK if $r->header_only;
48: my $target=$env{'form.grade_target'};
49: # ------------------------------------------------------------ Print the screen
50: if ($target eq 'tex') {
51: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
52: }
53: my (undef,undef,$udom,$uname,$marker,$caller)=split(/\//,$r->uri);
54: # Is this even in a course?
55: unless ($env{'request.course.id'}) {
56: if ($target ne 'tex') {
57: &Apache::loncommon::simple_error_page($r,'','Not in a course');
58: } else {
59: $r->print('\textbf{Not in a course}\end{document}');
60: }
61: return OK;
62: }
63:
64: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
65: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
66: my $grp_view_permission = &Apache::lonnet::allowed('vcg',
67: $env{'request.course.id'});
68: my ($namespace,$group,$grp_desc);
69:
70: my %curr_group = ();
71: my %groupinfo = ();
72: if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
73: $marker =~ s/\W//g;
74: $group = $marker;
75: my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
76: if (!%curr_groups) {
77: &Apache::loncommon::simple_error_page($r,'','Invalid group name');
78: return OK;
79: }
80: %groupinfo =
81: &Apache::longroup::get_group_settings($curr_groups{$group});
82: $grp_desc = &unescape($groupinfo{'description'});
83: $namespace = 'grppage_'.$group;
84: } else {
85: $marker=~s/\D//g;
86: $namespace = 'smppage_'.$marker;
87: }
88:
89: if (!$marker) {
90: &Apache::loncommon::simple_error_page($r,'','Invalid call');
91: return OK;
92: }
93:
94: # --------------------------------------------------------- The syllabus fields
95: my %syllabusfields=&Apache::lonlocal::texthash(
96: 'aaa_title' => 'Page Title',
97: 'bbb_content' => 'Content',
98: 'ccc_webreferences' => 'Web References');
99: if ($group ne '') {
100: $syllabusfields{'abb_links'} = &mt('Functionality');
101: }
102:
103:
104: # ------------------------------------------------------------ Get query string
105: &Apache::loncommon::get_unprocessed_cgi
106: ($ENV{'QUERY_STRING'},['forcestudent','forceedit',
107: 'register','ref']);
108: # --------------------------------------------------------------- Force Student
109: my $forcestudent='';
110: if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
111: my $forceedit='';
112: if ($env{'form.forceedit'}) { $forceedit='edit'; }
113:
114:
115: my %syllabus=&Apache::lonnet::dump($namespace,$dom,$crs);
116:
117: # --------------------------------------- There is such a user, get environment
118:
119: if ($target ne 'tex') {
120: my $title = 'Course Page';
121: if ($group ne '') {
122: $title = 'Group Page';
123: }
124: my $start_page =
125: &Apache::loncommon::start_page($title,undef,
126: {'function' => $forcestudent,
127: 'domain' => $dom,
128: 'force_register' =>
129: $env{'form.register'},});
130: $r->print($start_page);
131: }
132:
133: if ($group ne '') {
134: if (($grp_view_permission) ||
135: (&Apache::longroup::check_group_access($caller))) {
136: if ((!&Apache::lonnet::allowed('vgh',
137: $env{'request.course.id'}.'/'.$marker))
138: && (!&Apache::lonnet::allowed('mdg',
139: $env{'request.course.id'}.'/'.$marker))) {
140: if ($env{'form.ref'} eq 'grouplist') {
141: my $gpterm = &Apache::loncommon::group_term();
142: my $ucgpterm = $gpterm;
143: $ucgpterm =~ s/^(\w)/uc($1)/e;
144: $r->print(&grouppage_breadcrumbs($dom,$crs,$group,$gpterm,
145: $ucgpterm,$grp_desc));
146: }
147: &display_group_links($r,$target,$marker,'view',%groupinfo);
148: return OK;
149: }
150: } else {
151: my $msg =
152: &mt('You do not currently have rights to view this group.');
153: if ($target ne 'tex') {
154: $r->print("<p>$msg</p>".
155: &Apache::loncommon::end_page());
156: } else {
157: $r->print('\textbf{'.$msg.'}\end{document}');
158: }
159: return OK;
160: }
161: }
162:
163: my $allowed;
164: if ($group ne '') {
165: $allowed = &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
166: if (!$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' && $group ne '') {
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 $refarg;
321: if ($env{'form.ref'} eq 'grouplist') {
322: $refarg = '&ref=grouplist';
323: }
324: my @available = ();
325: my %menu = ();
326: %{$menu{'email'}} = (
327: text => 'Group e-mail',
328: href => '/adm/email?compose=group&group='.$marker.
329: $refarg,
330: );
331: %{$menu{'discussion'}} = (
332: text => 'Discussion Boards',
333: href => '/adm/groupboards?group='.$marker.$refarg,
334: );
335: %{$menu{'chat'}} = (
336: text => 'Group chat',
337: href => "javascript:group_chat('$marker')",
338: );
339: %{$menu{'files'}} = (
340: text => 'File repository',
341: href => '/adm/coursegrp_portfolio?group='.$marker.$refarg,
342: );
343: %{$menu{'roster'}} = (
344: text => 'Membership roster',
345: href => '/adm/grouproster?group='.$marker.$refarg,
346: );
347: foreach my $tool (sort(keys(%menu))) {
348: if ($groupinfo{functions}{$tool} eq 'on') {
349: push(@available,$tool);
350: }
351: }
352: if (@available > 0) {
353: my $output = '<table cellspacing="4" cellpadding="4"><tr>';
354: foreach my $tool (@available) {
355: if ($target eq 'tex') {
356: $output .= '<td>'.$menu{$tool}{text}.'</td>';
357: } else {
358: $output .= '<td><a href="'.$menu{$tool}{href}.'">'.
359: $menu{$tool}{text}.'</a></td>';
360: }
361: }
362: $output .= '</tr></table>';
363: if ($target eq 'tex') {
364: $r->print(&Apache::lonxml::xmlparse($r,'tex','Available functions<br /><br />'.$output));
365: } else {
366: $r->print('<h3>Functions</h3>'.$output);
367: }
368: } else {
369: my $output;
370: if ($context eq 'edit') {
371: $output = 'No group functionality';
372: } else {
373: $output = 'No group functionality (e.g., e-mail, discussion, chat or file upload) is currently available to you in this group: '.$marker;
374: }
375: if ($target eq 'tex') {
376: $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
377: } else {
378: $r->print($output);
379: }
380: }
381: }
382:
383: sub grouppage_breadcrumbs {
384: my ($cdom,$cnum,$group,$gpterm,$ucgpterm,$description) = @_;
385: &Apache::lonhtmlcommon::clear_breadcrumbs();
386: &Apache::lonhtmlcommon::add_breadcrumb
387: ({href=>"/adm/coursegroups",
388: text=>"$ucgpterm".'s',
389: title=>"Display $ucgpterm".'s'},
390: {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
391: text=>"$ucgpterm: $description",
392: title=>"Go to group's home page"},
393: );
394: my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] page - [_2]',$gpterm,$description));
395: return $output;
396: }
397:
398: 1;
399: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>