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