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