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