1: # The LearningOnline Network
2: # Simple Page Editor
3: #
4: # $Id: lonsimplepage.pm,v 1.100 2012/11/17 00:05:50 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::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);
92:
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'},['forceedit',
126: 'register','ref']);
127: # --------------------------------------------------------------- Force Student
128: my ($forceedit,$forcestudent);
129: $forceedit = $env{'form.forceedit'};
130: if (!$forceedit) {
131: $forcestudent=1;
132: }
133:
134: my $refarg;
135: if ($env{'form.ref'}) {
136: $refarg = '&ref='.$env{'form.ref'};
137: }
138:
139: my %syllabus=&Apache::lonnet::dump($db_name,$dom,$crs);
140:
141: # --------------------------------------- There is such a user, get environment
142: my ($registered,$group_view_perm,$group_edit_perm,$group_home_view,
143: $group_home_edit,$has_group_access);
144: my $brcrum = [];
145: if ($group eq '') {
146: $registered = $env{'form.register'};
147: } else {
148: unless ($env{'form.ref'} eq 'grouplist') {
149: $registered = $env{'form.register'};
150: }
151: $group_view_perm =
152: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
153: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
154: $group_edit_perm =
155: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
156: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
157: $group_home_view = &Apache::lonnet::allowed('vgh',
158: $env{'request.course.id'}.'/'.$group);
159: $group_home_edit = &Apache::lonnet::allowed('mgh',
160: $env{'request.course.id'}.'/'.$group);
161: if ($group_view_perm || $group_edit_perm || $group_home_view ||
162: $group_home_edit || &Apache::longroup::check_group_access($group)) {
163: $has_group_access = 1;
164: if (($env{'form.ref'} eq 'grouplist') && ($target ne 'tex') &&
165: (!$registered)) {
166: $brcrum = &grouppage_breadcrumbs($dom,$crs,$group,$group_desc);
167: }
168: }
169: }
170:
171: if ($target ne 'tex') {
172: my $title = ($group eq '')? 'Simple Course Page':'Simple Group Page';
173: my $start_page =
174: &Apache::loncommon::start_page($title,undef,
175: {'domain' => $dom,
176: 'group' => $group,
177: 'bread_crumbs' => $brcrum,
178: 'force_register' => $registered,
179: });
180: $r->print($start_page);
181: }
182:
183: if ($group ne '') {
184: if ($has_group_access) {
185: if ((!$group_home_edit) && (!$group_home_view) &&
186: (!$group_view_perm) && (!$group_edit_perm)) {
187: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
188: if ($env{'form.grade_target'} ne 'tex') {
189: $r->print(&Apache::loncommon::end_page());
190: } else {
191: $r->print('\end{document}');
192: }
193: return OK;
194: }
195: } else {
196: my $msg =
197: &mt('You do not currently have rights to view this group.');
198: if ($target ne 'tex') {
199: $r->print('<p class="LC_warning">'.$msg.'</p>'.
200: &Apache::loncommon::end_page());
201: } else {
202: $r->print('\textbf{'.$msg.'}\end{document}');
203: }
204: return OK;
205: }
206: my ($blocked,$blocktext) =
207: &Apache::loncommon::blocking_status('groups');
208: if ($blocked) {
209: $r->print($blocktext);
210: $r->print(&Apache::loncommon::end_page());
211: return OK;
212: }
213: }
214:
215: my $allowed;
216:
217: if ($group ne '') {
218: $allowed = $group_edit_perm;
219: if (!$allowed) {
220: $allowed = $group_home_edit;
221: }
222: } else {
223: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
224: }
225:
226: if ($forcestudent or $target eq 'tex') { $allowed=0; }
227:
228: if (($env{'form.uploaddoc.filename'} and $target ne 'tex') &&
229: ($env{'form.storeupl'}) && ($allowed)) {
230: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
231: if ($syllabus{'uploaded.photourl'}) {
232: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
233: }
234: if ($group ne '') {
235: $syllabus{'uploaded.photourl'}=&Apache::lonnet::userfileupload(
236: 'uploaddoc','coursedoc',"grouppage/$group");
237: } else {
238: $syllabus{'uploaded.photourl'}=
239: &Apache::lonnet::userfileupload('uploaddoc','coursedoc','simplepage');
240: }
241: }
242: $syllabus{'uploaded.lastmodified'}=time;
243: &Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
244: }
245: # if ($allowed && $env{'form.delupl'}) {
246: # if ($syllabus{'uploaded.photourl'}) {
247: # &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
248: # delete($syllabus{'uploaded.photourl'});
249: # &Apache::lonnet::del('simplepage',['uploaded.photourl']);
250: # }
251: # }
252: if (($allowed) && ($env{'form.storesyl'})) {
253: foreach my $syl_field (keys(%syllabusfields)) {
254: my $field=$env{'form.'.$syl_field};
255: chomp($field);
256: $field=~s/\s+$//s;
257: $field=~s/^\s+//s;
258: $field=~s/\<br\s*\/*\>$//s;
259: $field=&Apache::lonfeedback::clear_out_html($field,1);
260: $syllabus{$syl_field}=$field;
261: }
262: $syllabus{'uploaded.lastmodified'}=time;
263: &Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
264: }
265:
266: #---Print help Text
267: if($target ne 'tex'){
268: if ($allowed) {
269: $r->print(&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')));
270: }
271: }
272:
273: # ---------------------------------------------------------------- Get syllabus
274: if ((($syllabus{'uploaded.lastmodified'}) &&
275: (($group ne '' && ($group_home_view || $group_edit_perm ||
276: $group_view_perm)) || ($group eq ''))) || ($allowed)) {
277: #Print the title
278: my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');
279: if ($target ne 'tex') {
280: if ($allowed) {
281: }
282: $r->print('<h2>'.$titletext.'</h2>');
283: } else {
284: my $safeinit;
285: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$titletext.'</h1>'));
286: }
287: if ($allowed) {
288: if ($env{'form.grade_target'} ne 'tex') {
289: #editbox for title
290: $r->print('<form method="post" action="" enctype="multipart/form-data">'."\n".
291: '<input type="hidden" register="'.$registered.'" />');
292: &Apache::lontemplate::print_start_template($r,&mt('Title'),'LC_Box');
293: $r->print($titletext);
294: $r->print("<br /><div>");
295: &Apache::lontemplate::print_textarea_template($r, $syllabus{'aaa_title'},
296: 'aaa_title', Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
297: &Apache::lontemplate::print_saveall_template($r);
298: $r->print("</div>");
299: &Apache::lontemplate::print_end_template($r);
300: } else {
301: my $safeinit;
302: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{'aaa_title'},$safeinit));
303: }
304: }
305:
306: #print the image
307: my $image='';
308: if ($syllabus{'uploaded.photourl'}) {
309: &Apache::lonnet::allowuploaded('/adm/smppg',
310: $syllabus{'uploaded.photourl'});
311:
312: $image='<img src="'.$syllabus{'uploaded.photourl'}
313: .'" alt="'.&mt('Image').'" />';
314: if ($target eq 'tex') {
315: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
316: }
317: }
318:
319: if ($allowed) {
320: &Apache::lontemplate::print_start_template($r, &mt('Upload a Photo'),'LC_Box');
321: $r->print($image);
322: $r->print("<br /><br />");
323: $r->print(
324: '<input type="hidden" name="forceedit" value="edit" />'.
325: '<input type="file" name="uploaddoc" size="50" />'.
326: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
327: '<input type="hidden" name="forceedit" value="edit" />');
328: &Apache::lontemplate::print_end_template($r);
329:
330:
331: # if ($syllabus{'uploaded.photourl'}) {
332: # $r->print('<input type="submit" name="delupl"'
333: # .' value="'.&mt('Delete Photo').'" />');
334: # }
335: }
336: #Image in Student view and printout.
337: else {
338: $r->print($image);
339: }
340:
341: my $links_handler = sub {
342: my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed) = @_;
343: if ($group ne '') {
344: my %data = %{$data_ref};
345: my %fields = %{$fields_ref};
346: $r->print('<br /><input type="hidden" name="'.$field.
347: '" value="'.$data{$field}.'" />');
348: &display_group_links($r, $target, $group, 'edit', $refarg, %groupinfo);
349: $r->print('<br />');
350: }
351: };
352: my $title_handler = sub {};
353: my %custom_handlers = (
354: 'abb_links' => $links_handler,
355: 'aaa_title' => $title_handler
356: );
357: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
358: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers, $group);
359:
360: if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
361: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive().
362: '</form>');
363: }
364:
365: } else {
366: if ($group ne '') {
367: &display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
368: } else {
369: my $text=&mt('No page information provided.');
370: if ($target ne 'tex') {
371: $r->print('<p class="LC_info">'.$text.'</p>');
372: } else {
373: $r->print($text)
374: }
375: }
376: }
377: if ($env{'form.grade_target'} ne 'tex') {
378: $r->print(&Apache::loncommon::end_page());
379: } else {
380: $r->print('\end{document}');
381: }
382: return OK;
383: }
384:
385: sub display_group_links {
386: my ($r,$target,$group,$context,$refarg,%groupinfo) = @_;
387: my @available = ();
388: my %menu = ();
389: %{$menu{'email'}} = (
390: text => 'Group Message',
391: href => '/adm/email?compose=group&group='.$group.
392: $refarg,
393: );
394: %{$menu{'discussion'}} = (
395: text => 'Discussion Boards',
396: href => '/adm/groupboards?group='.$group.$refarg,
397: );
398: %{$menu{'chat'}} = (
399: text => 'Group Chat Room',
400: href => "javascript:group_chat('$group')",
401: );
402: %{$menu{'files'}} = (
403: text => 'Group Portfolio',
404: href => '/adm/coursegrp_portfolio?group='.$group.
405: $refarg,
406: );
407: %{$menu{'roster'}} = (
408: text => 'Membership Roster',
409: href => '/adm/grouproster?group='.$group.$refarg,
410: );
411: foreach my $tool (sort(keys(%menu))) {
412: if ($groupinfo{functions}{$tool} eq 'on') {
413: push(@available,$tool);
414: }
415: }
416: if (@available > 0) {
417: my $output = '';
418: if ($target eq 'tex') {
419: $output = '<table cellspacing="4" cellpadding="4">';
420: } else {
421: $output = &Apache::loncommon::start_data_table();
422: }
423: foreach my $tool (@available) {
424: if ($target eq 'tex') {
425: $output .= '<tr><td>'.&mt($menu{$tool}{text}).'</td></tr>';
426: } else {
427: $output .= &Apache::loncommon::start_data_table_row()
428: .'<td><a href="'.$menu{$tool}{href}.'">'
429: .&mt($menu{$tool}{text}).'</a></td>'
430: .&Apache::loncommon::end_data_table_row();
431: }
432: }
433: if ($target eq 'tex') {
434: $output .= '</table>';
435: } else {
436: $output .= &Apache::loncommon::end_data_table();
437: }
438: if ($target eq 'tex') {
439: $r->print(&Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'<br /><br />'.$output));
440: } else {
441: $r->print('<h3>'.&mt('Available Group Tools').'</h3>'.$output);
442: }
443: } else {
444: my $output;
445: if ($context eq 'edit') {
446: $output = &mt('No group functionality.');
447: } else {
448: $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>');
449: }
450: if ($target eq 'tex') {
451: $r->print(&Apache::lonxml::xmlparse($r,'tex',$output));
452: } else {
453: $r->print($output);
454: }
455: }
456: }
457:
458: sub grouppage_breadcrumbs {
459: my ($cdom,$cnum,$group,$description) = @_;
460: &Apache::lonhtmlcommon::clear_breadcrumbs();
461: return [{href=>"/adm/coursegroups",
462: text=>"Groups",
463: title=>"Display Groups"},
464: {href=>"/adm/$cdom/$cnum/$group/smppg?ref=grouplist",
465: text=>&mt('Group:')." $description",
466: title=>"Go to group's home page"},
467: ];
468: }
469:
470: 1;
471: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>