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