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