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