Annotation of loncom/interface/lonsyllabus.pm, revision 1.129
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.129 ! raeburn 4: # $Id: lonsyllabus.pm,v 1.128 2013/05/19 15:48:51 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::lonsyllabus;
30:
31: use strict;
1.70 amueller 32: use Apache::lontemplate;
1.1 www 33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
1.5 www 36: use Apache::lontexconvert;
1.11 www 37: use Apache::lonfeedback;
1.19 www 38: use Apache::lonannounce;
1.23 www 39: use Apache::lonlocal;
1.32 www 40: use Apache::lonhtmlcommon;
1.38 www 41: use Apache::lonspeller();
1.54 albertel 42: use HTML::Entities();
1.1 www 43:
44: sub handler {
45: my $r = shift;
1.46 www 46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK if $r->header_only;
1.45 www 49:
1.46 www 50: my $target=$env{'form.grade_target'};
1.45 www 51: # --------------------------------------------------- Get course info from URL
52: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 53: # ------------------------------------------------------------ Get query string
54: &Apache::loncommon::get_unprocessed_cgi
1.116 raeburn 55: ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
1.115 raeburn 56: 'folderpath','title']);
1.45 www 57: # ----------------------------------------------------- Is this even a course?
58: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
59: if ($homeserver eq 'no_host') {
60: &Apache::loncommon::content_type($r,'text/html');
61: $r->send_http_header;
1.106 faziophi 62: &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91 amueller 63: 'No syllabus available');
1.45 www 64: return OK;
1.113 raeburn 65: } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
66: &Apache::loncommon::content_type($r,'text/html');
67: $r->send_http_header;
68: &Apache::loncommon::simple_error_page($r,'No syllabus available',
69: 'The course/community for which the syllabus was requested does not exist.');
70: return OK;
1.45 www 71: }
72: # ------------------------------------- There is such a course, get environment
73: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.125 raeburn 74: my $crstype = &Apache::loncommon::course_type();
1.46 www 75:
1.1 www 76: # ------------------------------------------------------------ Print the screen
1.49 albertel 77:
78: if ($target eq 'tex') {
1.91 amueller 79: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.86 bisitz 80: }
1.117 raeburn 81:
82: # --------------------------------------------------------------- Force Student
83: my ($forceedit,$forcestudent);
84: if ($env{'form.forceedit'}) { $forceedit=1; }
85: if (!$forceedit) {
86: $forcestudent=1;
87: }
88:
89: # --------------------------------------------------------------- Check Privileges
90: my $allowed = 0;
91: if ($env{'user.environment'}) {
92: # does this user have privileges to post, etc?
93: if ($env{'request.course.id'}
94: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
95: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
96: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
97: if ($forcestudent or $target eq 'tex') { $allowed=0; }
98: }
99: }
100:
1.46 www 101: # -------------------------------------------------- Let's see who handles this
1.117 raeburn 102: my $external=$courseenv{'externalsyllabus'};
103: my $uploaded=$courseenv{'uploadedsyllabus'};
1.122 raeburn 104: my $minimal=$courseenv{'minimalsyllabus'};
1.49 albertel 105:
1.122 raeburn 106: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
107: my $item;
108: if ($minimal =~/\w/) {
109: if ($external =~ m{\Q$minimal\E$}) {
110: undef($external);
111: }
112: $item = $minimal;
113: } elsif ($uploaded =~/\w/) {
114: if ($external =~ m{\Q$uploaded\E$}) {
115: undef($external);
116: }
117: $item = $uploaded;
1.117 raeburn 118: }
119: unless ($allowed && $forceedit) {
1.122 raeburn 120: my $file=&Apache::lonnet::filelocation("",$item);
1.125 raeburn 121: if ($file =~ /\.(tex|x?html?)$/) {
122: my $filetype = $1;
1.117 raeburn 123: my $filecontents=&Apache::lonnet::getfile($file);
124: if ($filecontents eq -1) {
125: $r->print(&mt('Syllabus file unavailable'));
1.125 raeburn 126: } elsif ($filetype eq 'tex') {
127: my $result = &Apache::lontexconvert::converted(\$filecontents,
128: $env{'form.texengine'});
129: my %args;
130: &get_breadcrumbs($cdom,$cnum,$crstype,\%args);
131: $r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args).
132: $result.
133: &Apache::loncommon::end_page());
134: } else {
1.117 raeburn 135: my %mystyle;
136: &Apache::structuretags::reset_problem_globals();
137: my $oldfile = $env{'request.filename'};
1.122 raeburn 138: $env{'request.filename'} = $item;
1.125 raeburn 139: my $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
140: '',%mystyle);
1.117 raeburn 141: &Apache::structuretags::reset_problem_globals();
142: &Apache::lonhomework::finished_parsing();
143: $env{'request.filename'} = $oldfile;
144: &Apache::lonxml::add_messages(\$result);
145: $r->print($result);
146: }
147: } else {
1.122 raeburn 148: $r->print(&Apache::lonwrapper::wrapper($item));
1.117 raeburn 149: }
150: return OK;
151: }
152: } elsif ($external=~/\w/) {
153: unless ($allowed && $forceedit) {
154: $r->print(&Apache::lonwrapper::wrapper($external));
155: return OK;
156: }
1.90 amueller 157: }
1.42 www 158:
1.120 raeburn 159:
1.46 www 160: # ------------------------------ The buck stops here: internal syllabus display
1.5 www 161: # --------------------------------------------------------- The syllabus fields
1.23 www 162: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 163: 'aaa_instructorinfo' => 'Instructor Information',
164: 'bbb_description' => 'Course Description',
165: 'ccc_prereq' => 'Prerequisites',
1.7 www 166: 'cdc_classhours' => 'Class Hours',
1.5 www 167: 'ddd_officehours' => 'Office Hours',
168: 'eee_helproom' => 'Helproom Hours',
1.7 www 169: 'efe_projectinfo' => 'Project Information',
1.5 www 170: 'fff_examinfo' => 'Exam Information',
1.7 www 171: 'fgf_deadlines' => 'Deadlines',
1.5 www 172: 'ggg_grading' => 'Grading Information',
1.7 www 173: 'hhh_readings' => 'Readings',
174: 'iii_coursepack' => 'Coursepack',
175: 'jjj_weblinks' => 'Web Links',
1.9 www 176: 'kkk_textbook' => 'Textbook',
177: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.121 raeburn 178: # ---------------------------------------------------------- Load syllabus info
179: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
180: my ($output,%displayfields,%noshow);
1.65 raeburn 181:
1.121 raeburn 182: # This handler might be called anonymously ...
183: # ----------------------------------------------------- Only if not public call
184: if ($allowed) {
1.122 raeburn 185: if (($env{'form.choice'} =~ /^(template|minimal|url|file)$/) ||
1.121 raeburn 186: ($env{'form.phase'} =~ /^(upload|check)_embedded$/)) {
187: my $earlyout;
1.122 raeburn 188: ($earlyout,$uploaded,$external,$minimal,$output) =
189: &save_changes($cnum,$cdom,$uploaded,$external,$minimal,
190: \%syllabus,\%syllabusfields,\%courseenv);
191: if (($env{'form.choice'} eq 'minimal') &&
192: ($minimal eq "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html")) {
193: delete($env{'form.symb'});
194: delete($env{'request.symb'});
195: $r->internal_redirect("$minimal?editmode=1&forceedit=1");
196: return OK;
197: }
1.121 raeburn 198: if ($earlyout) {
199: if ($target ne 'tex') {
200: &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,
201: \%syllabus,\%syllabusfields);
1.122 raeburn 202: $r->print($output.
203: &Apache::loncommon::end_page());
1.121 raeburn 204: }
205: return OK;
1.90 amueller 206: }
1.65 raeburn 207: }
208: }
1.121 raeburn 209: if ($target ne 'tex') {
210: &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,\%syllabus,
211: \%syllabusfields);
212: $r->print($output);
1.117 raeburn 213: }
214:
1.121 raeburn 215: # -------------------------------------------- Determine which fields are shown
1.117 raeburn 216:
1.121 raeburn 217: if ($syllabus{'uploaded.fields'}) {
218: if ($syllabus{'uploaded.fields'} eq 'none') {
219: foreach my $field (keys(%syllabusfields)) {
220: $displayfields{$field} = ' style="display:none;"';
221: $noshow{$field} = 1;
1.117 raeburn 222: }
223: } else {
1.121 raeburn 224: my %included;
225: map { $included{$_} = 1; } split(/,/,$syllabus{'uploaded.fields'});
226: foreach my $field (keys(%syllabusfields)) {
227: my ($prefix) = split(/_/,$field);
228: if ($included{$prefix}) {
229: $displayfields{$field} = ' style="display:block;"';
1.117 raeburn 230: } else {
1.121 raeburn 231: $displayfields{$field} = ' style="display:none;"';
232: $noshow{$field} = 1;
1.117 raeburn 233: }
234: }
235: }
1.121 raeburn 236: } else {
1.117 raeburn 237: foreach my $field (keys(%syllabusfields)) {
238: if ($syllabus{$field} ne '') {
239: $displayfields{$field} = ' style="display:block;"';
240: } else {
241: $displayfields{$field} = ' style="display:none;"';
242: }
1.90 amueller 243: }
1.4 www 244: }
1.85 bisitz 245:
1.113 raeburn 246: if ($allowed) {
247: #---------------------------------- Print External URL Syllabus Info if editing
248: if ($target ne 'tex') {
249: my $protocol = $Apache::lonnet::protocol{$homeserver};
250: $protocol = 'http' if ($protocol ne 'https');
1.119 raeburn 251: my $link = $protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri;
252: $r->print('<div class="LC_left_float">'
253: .'<span class="LC_help_open_topic LC_info">'
254: .'<span class="LC_info">'
255: .&mt('Public link (no log-in): [_1]','<tt>'.$link.'</tt>')
256: .' </span>'.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
257: .'</span>'
1.121 raeburn 258: .'</div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n");
1.117 raeburn 259: my $lonhost = $r->dir_config('lonHostID');
1.122 raeburn 260: $r->print(&chooser($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,
261: \%syllabusfields,\%syllabus));
1.93 bisitz 262: }
1.109 bisitz 263: } else {
1.113 raeburn 264: #--------------------------------------------- Print last update unless editing
265: my $lastmod=$syllabus{'uploaded.lastmodified'};
266: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
267: my $who;
268: if ($syllabus{'uploaded.lastmodified'}) {
269: if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
270: $who = &Apache::loncommon::aboutmewrapper(
271: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
272: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
273: $syllabus{'uploaded.domain'});
274: } else {
275: # Public user?
276: # Only display name of user, but no link to personal information page
277: $who = &Apache::loncommon::plainname(
278: $syllabus{'uploaded.name'},
279: $syllabus{'uploaded.domain'});
280: }
281: }
282: if ($target ne 'tex') {
283: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
284: $lastmod . ' '.
285: ($who ? &mt('by').' '.$who
286: : '' ) .
287: '</div>' );
288: } else {
289: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
290: ($who? &mt('by').'\\\\ '.
291: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
292: :'')
293: .'\\\\');
294: }
1.109 bisitz 295: }
296:
1.113 raeburn 297: #-------------------------------------------------------------- Print Headtitle
1.90 amueller 298: if ($target ne 'tex') {
1.117 raeburn 299: my $display = 'block';
1.122 raeburn 300: if ($external || $uploaded || $minimal) {
1.117 raeburn 301: $display = 'none';
302: }
303: $r->print('<div class="LC_Box" id="template" style="display: '.$display.'">'.
1.113 raeburn 304: '<h2 class="LC_hcell">'.$courseenv{'description'}.'</h2>');
305: if ($allowed) {
1.121 raeburn 306: $r->print('<div style="margin: 0; float:left;">'.
307: '<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
308: '</div>');
1.113 raeburn 309: # Print Help Text if editing at right side of screen
1.121 raeburn 310: $r->print('<div style="margin: 0; float:right;">'.
311: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
312: '</div><br clear="all" />');
1.113 raeburn 313: } else {
314: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
315: }
1.90 amueller 316: } else {
1.91 amueller 317: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
318: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90 amueller 319: }
1.80 neumanie 320: # -------------------------------------------------------- Get course personnel
1.121 raeburn 321: my $hidepersonnel;
322: if (($syllabus{'uploaded.fields'}) &&
323: (($syllabus{'uploaded.fields'} eq 'none') ||
324: ($syllabus{'uploaded.fields'} !~ /000/))) {
325: $hidepersonnel = 1;
326: }
1.80 neumanie 327: if ($target ne 'tex') {
1.121 raeburn 328: if ($allowed) {
329: my $display = ' style="display:block;"';
330: if ($hidepersonnel) {
331: $display = ' style="display:none;"';
332: }
333: &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box',
334: 'box_000_showpeople',$display);
1.127 raeburn 335: $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));
1.121 raeburn 336: &Apache::lontemplate::print_end_template($r);
1.91 amueller 337: } else {
1.121 raeburn 338: unless ($hidepersonnel) {
339: &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box');
1.127 raeburn 340: $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));
1.121 raeburn 341: &Apache::lontemplate::print_end_template($r);
1.91 amueller 342: }
343: }
1.121 raeburn 344: } else {
345: unless ($hidepersonnel) {
1.127 raeburn 346: $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,%syllabus));
1.91 amueller 347: }
1.80 neumanie 348: }
1.79 neumanie 349: # -------------------------------------------------------------- Announcements?
350: my $day = &Apache::lonannounce::showday(time,2,
1.91 amueller 351: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.121 raeburn 352: my $hidefeeds;
353: if (($syllabus{'uploaded.fields'}) &&
354: (($syllabus{'uploaded.fields'} eq 'none') ||
355: ($syllabus{'uploaded.fields'} !~ /111/))) {
356: $hidefeeds = 1;
357: }
1.80 neumanie 358: if ($target ne 'tex') {
1.91 amueller 359: if ($allowed) {
1.117 raeburn 360: my $display = ' style="display:block;"';
1.121 raeburn 361: if ($hidefeeds) {
1.117 raeburn 362: $display = ' style="display:none;"';
363: }
364: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box',
1.121 raeburn 365: 'box_111_showrssfeeds',$display);
1.120 raeburn 366: my ($numfeeds,$hiddenfeeds,$rsslinktext);
1.121 raeburn 367: my $feeds=&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit,\$numfeeds,
368: \$hiddenfeeds);
1.120 raeburn 369: if ($numfeeds) {
370: $r->print($feeds);
371: $rsslinktext = &mt('New RSS Feed or Blog');
372: } else {
373: my $msg = '<br />'.
374: &mt("RSS Feeds and Blogs item is not included in a student's view of the syllabus.");
375: if ($hiddenfeeds) {
376: $r->print('<p class="LC_info">'.
377: &mt('All feeds currently hidden').
378: $msg.
379: '</p>');
380: } else {
381: $r->print('<p class="LC_info">'.
382: &mt('No current feeds').
383: $msg.
384: '</p>');
385: }
386: $rsslinktext = &mt('Manage Course RSS Feeds/Blogs');
387: if ($crstype eq 'Community') {
388: $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs');
389: }
390: }
1.91 amueller 391: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
1.120 raeburn 392: $r->print( '<a href="'.$editurl.'">'.$rsslinktext.'</a>');
1.91 amueller 393: &Apache::lontemplate::print_end_template($r);
1.117 raeburn 394: } else {
1.121 raeburn 395: unless ($hidefeeds) {
1.120 raeburn 396: my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit);
397: if ($feeds ne '') {
1.117 raeburn 398: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.120 raeburn 399: $r->print($feeds);
1.117 raeburn 400: &Apache::lontemplate::print_end_template($r);
401: }
402: }
1.91 amueller 403: }
1.79 neumanie 404: } else {
1.91 amueller 405: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86 bisitz 406: }
1.79 neumanie 407: # ---------------------------------------------------------------- Get syllabus
1.86 bisitz 408: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.106 faziophi 409: my $url_include_handler = sub {
1.117 raeburn 410: my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
1.106 faziophi 411: my %data = %{$data_ref};
412: my %fields = %{$fields_ref};
413: my $urls=$message;
414: $message='';
415: foreach my $filelink (split(/\n/,$urls)) {
416: my $output='';
417: # embed style?
418: my ($curfext)=($filelink=~/\.([^\.]+)$/);
419: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
420: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
421: $output=&Apache::lonnet::ssi_body($filelink);
422: } elsif ($embstyle eq 'img') {# embed as an image
423: $output='<img src="'.$filelink.'" />';
424: }
425: if ($output ne '') {
426: if ($target ne 'tex') {
427: $message.='<p>'.$output.'</p>';
428: } else {
429: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
430: }
431: }
432: }
433: if ($allowed) {
434: &Apache::lonfeedback::newline_to_br(\$urls);
435: &Apache::lontemplate::print_start_template($r,$fields{$field}.
1.117 raeburn 436: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box',
437: 'box_'.$field,$display);
1.106 faziophi 438: $r->print($urls);
439: $r->print("<br /><div>");
440: &Apache::lontemplate::print_textarea_template($r, $data{$field},
441: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
442: &Apache::lontemplate::print_saveall_template($r);
443: $r->print("</div>");
444: &Apache::lontemplate::print_end_template($r);
1.86 bisitz 445:
1.106 faziophi 446: } else {
447: $r->print($message);
448: }
449: };
450: my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
1.110 raeburn 451: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
1.117 raeburn 452: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
1.121 raeburn 453: undef,\%displayfields,\%noshow);
1.90 amueller 454: if ($allowed) {
1.129 ! raeburn 455: $r->print('</div></form>'.
1.110 raeburn 456: &Apache::lonhtmlcommon::htmlareaselectactive());
1.90 amueller 457: }
1.4 www 458: } else {
1.112 bisitz 459: if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
1.91 amueller 460: $r->print(&mt('No syllabus information provided.'));
461: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 462: }
1.86 bisitz 463: if ($target ne 'tex') {
1.65 raeburn 464: if ($env{'form.backto'} eq 'coursecatalog') {
465: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 466: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 467: '</form>');
468: }
1.91 amueller 469: $r->print(&Apache::loncommon::end_page());
1.48 albertel 470: } else {
1.91 amueller 471: $r->print('\end{document}');
1.48 albertel 472: }
1.1 www 473: return OK;
1.86 bisitz 474: }
1.1 www 475:
1.121 raeburn 476: sub print_header {
477: my ($r,$cnum,$cdom,$crstype,$allowed,$forceedit,$syllabus,$syllabusfields) = @_;
478: return unless ((ref($syllabus) eq 'HASH') || (ref($syllabusfields) eq 'HASH'));
479: # ----------------------------------------------------------------- Make header
480: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
481: my $js;
482: if ($env{'form.backto'} eq 'coursecatalog') {
483: $js .= <<"ENDSCRIPT";
484:
485: <script type="text/javascript">
486: // <![CDATA[
487:
488: function ToCatalog(caller) {
489: numidx = getIndexByName('coursenum');
490: if (numidx > -1) {
491: if (caller != 'details') {
492: document.backtocat.elements[numidx].value = '';
493: }
494: }
495: document.backtocat.submit();
496: }
497:
498: function getIndexByName(item) {
499: for (var i=0;i<document.backtocat.elements.length;i++) {
500: if (document.backtocat.elements[i].name == item) {
501: return i;
502: }
503: }
504: return -1;
505: }
506:
507: // ]]>
508: </script>
509:
510: ENDSCRIPT
511: }
512: if ($allowed && $forceedit) {
513: my $check_uncheck = &Apache::loncommon::check_uncheck_jscript();
514: my @fieldnames = sort(keys(%{$syllabusfields}));
515: unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
516: my (@checked,@unchecked);
517: if ($syllabus->{'uploaded.fields'} eq 'none') {
518: my $lastidx = scalar(@fieldnames)-1;
519: @unchecked = (0..$lastidx);
520: } elsif ($syllabus->{'uploaded.fields'}) {
521: my %included;
522: map { $included{$_} = 1; } split(/,/,$syllabus->{'uploaded.fields'});
523: for (my $i=0; $i<@fieldnames; $i++) {
524: my ($prefix) = split(/_/,$fieldnames[$i]);
525: if ($included{$prefix}) {
526: push(@checked,$i);
527: } else {
528: push(@unchecked,$i);
529: }
530: }
531: } else {
532: @checked = (0,1);
533: for (my $i=2; $i<@fieldnames; $i++) {
534: if ($syllabus->{$fieldnames[$i]}) {
535: push(@checked,$i);
536: } else {
537: push(@unchecked,$i);
538: }
539: }
540: }
541: my $fieldstr = "var fields = new Array('".join("','",@fieldnames)."');";
542: my $checkedstr = "var include = new Array('".join("','",@checked)."');";
543: my $uncheckedstr = "var exclude = new Array('".join("','",@unchecked)."');";
544: my $invurl = &mt('Invalid URL');
545: my $urlregexp = <<'ENDREGEXP';
546: /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
547: ENDREGEXP
548:
549: $js .= <<"ENDSCRIPT";
550:
551: <script type="text/javascript">
552: // <![CDATA[
553:
554: function toggleEditor(pick) {
1.122 raeburn 555: var choices = new Array('template','minimal','url','file','templatebox');
1.121 raeburn 556: for (var i=0; i<choices.length; i++) {
557: if (((choices[i] == 'templatebox') && (pick == 'template')) ||
558: (choices[i] == pick)) {
559: document.getElementById(choices[i]).style.display='block';
560: } else {
561: document.getElementById(choices[i]).style.display='none';
562: }
563: }
564: return;
565: }
566:
567: var regexp = $urlregexp;
568:
569: function extUrlPreview(caller) {
570: if (document.getElementById(caller)) {
571: var url = document.getElementById(caller).value;
572: if (regexp.test(url)) {
573: openMyModal(url,500,400,'yes');
574: } else {
575: alert("$invurl");
576: }
577: }
578: }
579:
580: function toggleBox(name,caller) {
581: if (name == 'all') {
582: if (document.syllabus.showfield.length > 0) {
583: for (var i=0; i<document.syllabus.showfield.length; i++) {
584: if (document.syllabus.showfield[i].checked) {
585: if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
586: document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='block';
587: }
588: } else {
589: if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
590: document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='none';
591: }
592: }
593: }
594: }
595: } else {
596: if (caller.checked) {
597: if (document.getElementById('box_'+caller.value)) {
598: document.getElementById('box_'+caller.value).style.display='block';
599: }
600: } else {
601: if (document.getElementById('box_'+caller.value)) {
602: document.getElementById('box_'+caller.value).style.display='none';
603: }
604: }
605: }
606: return;
607: }
608:
609: function setTemplateBoxes() {
610: $fieldstr
611: $checkedstr
612: $uncheckedstr
613: if (include.length > 0) {
614: for (var i=0; i<include.length; i++) {
615: if (document.getElementById('showfield_'+include[i])) {
616: document.getElementById('showfield_'+include[i]).checked = true;
617: if (document.getElementById('box_'+fields[include[i]])) {
618: document.getElementById('box_'+fields[include[i]]).style.display='block';
619: }
620: }
621: }
622: }
623: if (exclude.length > 0) {
624: for (var i=0; i<exclude.length; i++) {
625: if (document.getElementById('showfield_'+exclude[i])) {
626: document.getElementById('showfield_'+exclude[i]).checked = false;
627: if (document.getElementById('box_'+fields[exclude[i]])) {
628: document.getElementById('box_'+fields[exclude[i]]).style.display='none';
629: }
630: }
631: }
632: }
633: return;
634: }
635:
636: $check_uncheck
637:
638: // ]]>
639: </script>
640:
641: ENDSCRIPT
642: }
643: my $args = {'function' => undef,
644: 'domain' => $cdom};
645: my $forcereg;
646: if ($env{'form.register'}) {
647: $forcereg = 1;
648: $args->{'force_register'} = $forcereg;
649: }
650: if ($env{'form.backto'} eq 'coursecatalog') {
651: &Apache::lonhtmlcommon::clear_breadcrumbs();
652: my $brcrum = [{href=>"javascript:ToCatalog();",
653: text=>&mt('Course/Community Catalog'),
654: no_mt=>1}
655: ];
656: if ($env{'form.coursenum'} ne '') {
657: push(@{$brcrum},
658: {href=>"javascript:ToCatalog('details')",
659: text=>"Course details"});
660: }
661: push(@{$brcrum},
662: {href=>$r->uri,
663: text=>"Course syllabus"});
664: $args->{'bread_crumbs'} = $brcrum;
1.125 raeburn 665: } else {
666: &get_breadcrumbs($cdom,$cnum,$crstype,$args);
667: }
668: if ($allowed) {
669: my %loaditem = (
670: onload => 'setTemplateBoxes();',
671: );
672: $args->{'add_entries'} = \%loaditem;
673: }
674: my $start_page =
675: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
676: if ($start_page) {
677: $r->print($start_page);
678: }
679: }
680:
681: sub get_breadcrumbs{
682: my ($cdom,$cnum,$crstype,$args) = @_;
683: return unless (ref($args) eq 'HASH');
684: if ($env{'form.folderpath'} =~ /^supplemental/) {
1.121 raeburn 685: my $title = $env{'form.title'};
686: if ($title eq '') {
687: $title = &mt('Syllabus');
688: }
689: my $brcrum =
690: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
691: if (ref($brcrum) eq 'ARRAY') {
692: $args->{'bread_crumbs'} = $brcrum;
693: }
694: } else {
695: if ((&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus"))
696: && (($env{'form.symb'}) || ($env{'form.register'}))) {
697: &Apache::lonhtmlcommon::clear_breadcrumbs();
698: } else {
699: $args->{'bread_crumbs'} = [
700: {'href' => "/public/$cdom/$cnum/syllabus",
701: 'text' => 'Syllabus'},
702: ];
703: }
704: }
1.125 raeburn 705: return;
1.121 raeburn 706: }
707:
1.117 raeburn 708: sub chooser {
1.122 raeburn 709: my ($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,$fields,$values) = @_;
1.117 raeburn 710: my %lt = &Apache::lonlocal::texthash(
711: 'type' => 'Syllabus Type',
712: 'url' => 'External URL',
1.122 raeburn 713: 'file' => 'Uploaded file',
714: 'minimal' => 'Minimal template',
715: 'template' => 'Standard template',
1.117 raeburn 716: 'templateboxes' => 'Choose template items ... ',
717: 'curr' => 'Current:',
718: 'rep' => 'Replace:',
719: 'upl' => 'Upload:',
720: 'pr' => 'Preview',
721: 'save' => 'Save',
1.122 raeburn 722: 'sved' => 'Save and Edit',
723: 'chourl' => 'External URL',
1.117 raeburn 724: 'chofile' => 'Uploaded syllabus file',
725: 'parse' => 'Upload embedded images/multimedia files if HTML file',
726: );
727: my %checked = (
728: file => '',
1.122 raeburn 729: minimal => '',
1.117 raeburn 730: url => '',
731: template => '',
732: );
733: my %display = (
734: file => 'none',
1.122 raeburn 735: minimal => 'none',
1.117 raeburn 736: url => 'none',
737: templatebox => 'none',
738: );
739: my $check = ' checked="checked" ';
740: if ($uploaded) {
741: $checked{'file'} = $check;
742: $display{'file'} = 'block';
743: } elsif ($external) {
744: $checked{'url'} = $check;
745: $display{'url'} = 'block';
1.122 raeburn 746: } elsif ($minimal) {
747: $checked{'minimal'} = $check;
748: $display{'minimal'} = 'block';
1.117 raeburn 749: } else {
750: $checked{'template'} = $check;
751: $checked{'templatebox'} = $check;
752: $display{'templatebox'} = 'block';
753: }
754:
755: my $output =
756: '<form name="syllabus" method="post" enctype="multipart/form-data" action="">'."\n".
757: '<input type="hidden" name="forceedit" value="1" />'."\n".
758: '<div class="LC_left_float"><fieldset><legend>'.$lt{'type'}.'</legend>';
1.122 raeburn 759: foreach my $item ('minimal','template','url','file') {
1.117 raeburn 760: $output .= '<label><input type="radio" name="choice" value="'.$item.'" '.$checked{$item}.' onclick="toggleEditor('."'$item'".')" />'.
761: $lt{$item}.'</label><br />';
762: }
763: $output .= '</fieldset></div>'."\n".
764: '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
765: '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
766: '<a href="javascript:extUrlPreview('."'syllabusurl'".');">'.$lt{'pr'}.'</a></span> '."\n".
767: '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" />'."\n".
768: ' <input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
769: '</fieldset></div>'."\n".
1.122 raeburn 770: '<div id="minimal" class="LC_left_float" style="display: '.$display{'minimal'}.'">'."\n".
771: '<fieldset><legend>'.$lt{'minimal'}.'</legend>';
772: if ($minimal) {
773: my ($absurl,$filename,$depbutton) = &syllabus_file_info($minimal,$cnum,$cdom,$lonhost,'minimal');
774: $output .= '<a href="javascript:extUrlPreview('."'currminimal'".');">'.$lt{'pr'}.'</a>'.
775: '<input type="hidden" name="minimalfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currminimal" />'.
776: $depbutton;
777: } else {
778: $output .= &mt('Title of Syllabus Page:').' '.
779: '<input type="text" id="minimaltitle" name="syllabustitle" value="'.&mt('Syllabus').'" size="30" />'."\n".
780: ' <input type="submit" name="storeminimal" value="'.$lt{'sved'}.'" />'."\n";
781: }
782: $output .= '</fieldset></div>'."\n".
783: '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'">'."\n".
784: '<fieldset><legend>'.$lt{'file'}.'</legend>';
1.117 raeburn 785: if ($uploaded) {
1.122 raeburn 786: my ($absurl,$filename,$depbutton) = &syllabus_file_info($uploaded,$cnum,$cdom,$lonhost,'file');
1.117 raeburn 787: $output .= '<span class="LC_nobreak">'.$lt{'curr'}.' '.
788: '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118 raeburn 789: '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
790: '<br /><br />'.$lt{'rep'};
1.117 raeburn 791: } else {
792: $output .= $lt{'upl'};
793: }
794: $output .= '<br />'."\n".
795: '<span class="LC_nobreak">'.
796: '<input type="file" name="syllabusfile" size="55" />'."\n".
797: ' <input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
798: '</span><br />'.
799: '<label>'.
800: '<input type="checkbox" name="parserflag" checked="checked" />'.
801: $lt{'parse'}.
802: '</label>'.
803: '</fieldset></div>'.
804: '<div id="templatebox" class="LC_left_float" style="display: '.
805: $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
806: ' <input type="button" value="'.&mt('check all').'" '.
807: 'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
808: (' 'x2).
809: '<input type="button" value="'.&mt('uncheck all').'" '.
810: 'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
811: '</legend>'.
812: &fields_check_uncheck($fields,$values).
1.121 raeburn 813: '</fieldset><br />'.
814: '<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'.
1.117 raeburn 815: '</div>';
1.121 raeburn 816: $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.117 raeburn 817: return $output;
818: }
819:
1.122 raeburn 820: sub syllabus_file_info {
821: my ($item,$cnum,$cdom,$lonhost,$context) = @_;
822: my $protocol = $Apache::lonnet::protocol{$lonhost};
823: $protocol = 'http' if ($protocol ne 'https');
824: my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item;
825: my ($filename) = ($item =~ m{([^/]+)$});
826: my $file=&Apache::lonnet::filelocation("",$item);
1.125 raeburn 827: my ($depbutton,$filetype,$editable);
828: if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) {
829: $filetype=$1;
830: }
831: if ($filetype) {
832: unless ($filetype eq 'tex') {
833: $filetype='html';
834: }
835: }
836: if ($filetype eq 'html') {
1.122 raeburn 837: my $filecontents=&Apache::lonnet::getfile($file);
838: unless ($filecontents eq -1) {
839: my $mm = new File::MMagic;
840: my $mimetype = $mm->checktype_contents($filecontents);
841: if ($mimetype eq 'text/html') {
842: my (%codebase,%allfiles);
843: my $parse_result = &Apache::lonnet::extract_embedded_items($item,\%allfiles,
844: \%codebase,\$filecontents);
845: my $actionurl = "/public/$cdom/$cnum/syllabus";
846: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
847: &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
848: \%codebase,
849: {'context' => 'rewrites',
850: 'ignore_remote_references' => 1,});
1.125 raeburn 851: $editable = 1;
1.122 raeburn 852: }
853: }
854: }
1.125 raeburn 855: $depbutton = (' ' x 3).
856: &editfile_button($item,$context,$editable).
857: &editbutton_js();
1.122 raeburn 858: return ($absurl,$filename,$depbutton);
859: }
860:
1.117 raeburn 861: sub fields_check_uncheck {
862: my ($fields,$values) = @_;
863: return unless ((ref($fields) eq 'HASH') && (ref($values) eq 'HASH'));
864: my $numinrow = 4;
865: my $table;
866: my @fieldnames = sort(keys(%{$fields}));
1.121 raeburn 867: unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
1.117 raeburn 868: my $numfields = scalar(@fieldnames);
1.121 raeburn 869: my %included;
870: if (($values->{'uploaded.fields'}) && ($values->{'uploaded.fields'} ne 'none')) {
871: map { $included{$_} = 1; } split(/,/,$values->{'uploaded.fields'});
872: }
1.117 raeburn 873: for (my $i=0; $i<$numfields; $i++) {
1.121 raeburn 874: my ($name,$checked);
875: if ($fieldnames[$i] eq '000_showpeople') {
876: $name = &mt('Personnel');
877: } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117 raeburn 878: $name = &mt('RSS Feeds and Blogs');
1.121 raeburn 879: } else {
880: $name = $fields->{$fieldnames[$i]};
881: }
882: if ($values->{'uploaded.fields'}) {
883: unless ($values->{'uploaded.fields'} eq 'none') {
884: my ($prefix) = split(/_/,$fieldnames[$i]);
885: if ($included{$prefix}) {
886: $checked = ' checked="checked"';
887: }
888: }
889: } else {
890: if ($fieldnames[$i] eq '000_showpeople') {
891: $checked = ' checked="checked"';
892: } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117 raeburn 893: $checked = ' checked="checked"';
1.121 raeburn 894: } else {
895: if ($values->{$fieldnames[$i]} ne '') {
896: $checked = ' checked="checked"';
897: }
1.117 raeburn 898: }
899: }
900: my $rem = $i%($numinrow);
901: if ($rem == 0) {
1.121 raeburn 902: if (($i > 0) && ($i < $numfields)) {
1.117 raeburn 903: $table .= '</tr>';
904: }
1.121 raeburn 905: if ($i < $numfields) {
1.117 raeburn 906: $table .= '<tr>';
907: }
908: }
1.121 raeburn 909: if ($i == $numfields-1) {
910: my $rem = $numfields%($numinrow);
911: my $colsleft = $numinrow - $rem;
912: if ($colsleft > 1) {
913: $table .= '<td colspan="'.$colsleft.'">';
914: } else {
915: $table .= '</td>';
916: }
917: } else {
918: $table .= '<td>';
919: }
1.117 raeburn 920: $table .=
1.121 raeburn 921: '<label><input type="checkbox" name="showfield" value="'.$fieldnames[$i].'" '.
1.117 raeburn 922: $checked.' id="showfield_'.$i.'" onclick="javascript:toggleBox('."'$fieldnames[$i]',this".');" />'.
923: $name.'</label></td>'."\n";
924: }
925: if ($table ne '') {
926: my $rem = $numfields%($numinrow);
927: my $colsleft = $numinrow - $rem;
928: if ($colsleft > 1 ) {
929: $table .= '<td colspan="'.$colsleft.'"> </td>';
930: } elsif ($colsleft == 1) {
931: $table .= '<td> </td>';
932: }
933: $table = '<table>'.$table.'</tr></table>';
934: }
935: return $table;
936: }
937:
1.121 raeburn 938: sub get_personnel {
1.127 raeburn 939: my ($r,$target,$cdom,$cnum,$allowed,$crstype,$syllabus) = @_;
940: my (%hiddenroles,%hiddenusers);
941: if (ref($syllabus) eq 'HASH') {
942: if (ref($syllabus->{'personnel'}) eq 'HASH') {
943: if ($syllabus->{'personnel'}{'hiderole'}) {
944: map { $hiddenroles{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hiderole'});
945: }
946: if ($syllabus->{'personnel'}{'hideuser'}) {
947: map { $hiddenusers{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hideuser'});
948: }
949: }
950: }
1.121 raeburn 951: my $output;
1.127 raeburn 952: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
1.121 raeburn 953: if ($target ne 'tex') {
1.127 raeburn 954: if ($allowed) {
955: $r->print(&Apache::loncommon::start_data_table().
956: &Apache::loncommon::start_data_table_header_row().
957: '<th>'.&mt('Role hidden?').'</th><th>'.&mt('Role').'</th>'.
958: '<th>'.&mt('Personnel (hidden if checked)').'</th>'.
959: &Apache::loncommon::end_data_table_header_row());
960: } else {
961: $r->print(&Apache::lonhtmlcommon::start_pick_box());
962: }
1.121 raeburn 963: } else {
964: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
965: }
966: my @personnel=sort(keys(%coursepersonnel));
967: my $lastpers=$personnel[$#personnel];
968: foreach my $element (@personnel) {
1.127 raeburn 969: unless ($allowed) {
970: next if ($hiddenroles{$element})
971: }
972: my ($role,$sec);
973: if ($element =~ /:/) {
974: ($role,$sec) = split(/:/,$element);
975: } else {
976: $role = $element;
977: }
978: my $roletext = &Apache::lonnet::plaintext($role,$crstype);
979: if ($sec) {
980: $roletext .=' ('.&Apache::lonlocal::mt('Section [_1]',$sec).')';
981: }
1.121 raeburn 982: if ($target ne 'tex') {
1.127 raeburn 983: if ($allowed) {
984: my $checked;
985: if ($hiddenroles{$element}) {
986: $checked = ' checked="checked"';
987: }
988: $r->print(&Apache::loncommon::start_data_table_row().
989: '<td>'.
990: '<input type="checkbox" name="hiderole" value="'.$element.'" '.
991: $checked.' />'.
992: '</td><td>'.$roletext.'</td><td>');
993: } else {
994: $r->print(&Apache::lonhtmlcommon::row_title($roletext));
995: }
1.121 raeburn 996: } else {
1.127 raeburn 997: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$roletext).' & ');
1.121 raeburn 998: }
999: my @coursepersonlist;
1000: foreach my $user (split(/\,/,$coursepersonnel{$element})) {
1001: my ($puname,$pudom)=split(/\:/,$user);
1002: if ($target ne 'tex') {
1003: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
1.127 raeburn 1004: my $checked;
1005: if ($hiddenusers{$element.'&'.$puname.':'.$pudom}) {
1006: $checked = ' checked="checked"';
1007: }
1008: if ($allowed) {
1009: my $item = '<span class="LC_nobreak"><label>'.
1.129 ! raeburn 1010: '<input type="checkbox" name="hideuser" value="'.$element.'&'.$puname.':'.$pudom.'"'.$checked.' />'.
1.127 raeburn 1011: &Apache::loncommon::aboutmewrapper($courseperson
1012: ,
1013: $puname,$pudom).
1014: '</label>'.(' 'x2).'</span> ';
1015: push(@coursepersonlist,$item);
1016:
1.121 raeburn 1017: } else {
1.127 raeburn 1018: next if ($hiddenusers{$element.'&'.$puname.':'.$pudom});
1019: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
1020: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
1021: push(@coursepersonlist,$courseperson);
1022: } else {
1023: push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
1024: $puname,$pudom));
1025: }
1.121 raeburn 1026: }
1027: } else {
1028: push(@coursepersonlist,&Apache::loncommon::plainname($puname,
1029: $pudom).' ');
1030: }
1031: }
1.127 raeburn 1032: if ($allowed) {
1033: $r->print(join('',@coursepersonlist));
1034: } else {
1035: $r->print(join(', ',@coursepersonlist));
1036: }
1.121 raeburn 1037: if ($target ne 'tex') {
1.127 raeburn 1038: if ($allowed) {
1.129 ! raeburn 1039: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1.127 raeburn 1040: } else {
1041: my $lastclose=$element eq $lastpers?1:0;
1042: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1043: }
1.121 raeburn 1044: } else {
1045: $r->print('\\\\ \hline');
1046: }
1047: }
1048: if ($target ne 'tex') {
1.127 raeburn 1049: if ($allowed) {
1050: $r->print(&Apache::loncommon::end_data_table());
1051: } else {
1052: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1053: }
1.121 raeburn 1054: } else {
1055: $r->print('\end{tabular}\\\\');
1056: }
1057: return;
1058: }
1059:
1060: sub save_changes {
1.122 raeburn 1061: my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
1.121 raeburn 1062: my ($earlyout,$output);
1063: unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH')) {
1.122 raeburn 1064: return ($earlyout,$uploaded,$external,$minimal,$output);
1.121 raeburn 1065: }
1.128 raeburn 1066: if (($env{'form.deleteuploaded_file'}) || ($env{'form.deleteuploaded_minimal'})) {
1.122 raeburn 1067: my %storehash;
1068: if (($env{'form.choice'} eq 'file') &&
1.128 raeburn 1069: ($env{'form.deleteuploaded_file'}) && ($uploaded =~ /\w/)) {
1.122 raeburn 1070: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
1071: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
1072: $storehash{'uploadedsyllabus'} = '';
1073: $storehash{'externalsyllabus'} = '';
1074: my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1075: undef($uploaded);
1076: undef($external);
1077: } elsif (($env{'form.choice'} eq 'minimal') &&
1.128 raeburn 1078: ($env{'form.deleteuploaded_minimal'}) && ($minimal =~ /\w/)) {
1.122 raeburn 1079: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
1080: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
1081: $storehash{'externalsyllabus'} = '';
1082: $storehash{'minimalsyllabus'} = '';
1083: my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1084: undef($external);
1085: undef($minimal);
1086: }
1087: } elsif ($env{'form.choice'} eq 'template') {
1.121 raeburn 1088: #store what the user typed in to the template
1089: my @shown = &Apache::loncommon::get_env_multiple('form.showfield');
1090: $syllabus->{'uploaded.fields'} = '';
1091: if (@shown == 0) {
1092: $syllabus->{'uploaded.fields'} = 'none';
1093: } else {
1094: foreach my $field (sort(@shown)) {
1095: if (($field eq '000_showpeople') ||
1096: ($field eq '111_showrssfeeds') ||
1097: ($syllabusfields->{$field})) {
1098: my ($prefix) = split(/_/,$field);
1099: $syllabus->{'uploaded.fields'} .= $prefix.',';
1100: }
1.127 raeburn 1101: if ($field eq '000_showpeople') {
1102: my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser');
1103: my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole');
1104: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
1105: my %personnel;
1106: foreach my $key (keys(%coursepersonnel)) {
1107: map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key});
1108: }
1109: %{$syllabus->{'personnel'}} = ();
1110: $syllabus->{'personnel'}{'hideuser'} = '';
1111: $syllabus->{'personnel'}{'hiderole'} = '';
1112: foreach my $role (@hideroles) {
1113: if (exists($personnel{$role})) {
1114: $syllabus->{'personnel'}{'hiderole'} .= $role.',';
1115: }
1116: }
1117: foreach my $item (@hideusers) {
1118: my ($role,$user) = split(/\&/,$item);
1119: if (ref($personnel{$role}) eq 'HASH') {
1120: if ($personnel{$role}{$user}) {
1121: $syllabus->{'personnel'}{'hideuser'} .= $item.',';
1122: }
1123: }
1124: }
1125: $syllabus->{'personnel'}{'hideuser'} =~ s/,$//;
1126: $syllabus->{'personnel'}{'hiderole'} =~ s/,$//;
1127: }
1.121 raeburn 1128: }
1129: $syllabus->{'uploaded.fields'} =~ s/,$//;
1130: }
1131: foreach my $syl_field (keys(%{$syllabusfields})) {
1132: my $field=$env{'form.'.$syl_field};
1133: chomp($field);
1134: $field=~s/\s+$//s;
1135: $field=~s/^\s+//s;
1136: $field=~s/\<br\s*\/*\>$//s;
1137: $field=&Apache::lonfeedback::clear_out_html($field,1);
1138: #here it will be stored
1139: $syllabus->{$syl_field}=$field;
1140: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
1141: my $field='';
1142: foreach my $value (split(/\n/,$syllabus->{$syl_field})) {
1143: my $url=$value;
1144: # get rid of leading and trailing spaces
1145: $url=~s/^\s+//;
1146: $url=~s/\s+$//;
1147: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
1148: my $host = $1;
1149: my $remainder=$2;
1150: # remove the hostname from internal URLs
1151: my $hostname = &Apache::lonnet::hostname($host);
1152: my %all_hostnames = &Apache::lonnet::all_hostnames();
1153: foreach my $possible_host (keys(%all_hostnames)) {
1154: if ($possible_host =~ /\Q$hostname\E/i) {
1155: $url=$remainder;
1156: }
1157: }
1158: }
1159: # norm internal URLs
1160: unless ($url=~/^https?\:/) {
1161: $url=&Apache::lonnet::clutter($url);
1162: }
1163: # re-assemble field
1164: if ($url) {
1165: $field.=$url."\n";
1166: }
1167: }
1168: $syllabus->{$syl_field}=$field;
1169: }
1170: }
1171: my $now = time;
1172: $syllabus->{'uploaded.domain'}=$env{'user.domain'};
1173: $syllabus->{'uploaded.name'}=$env{'user.name'};
1174: $syllabus->{'uploaded.lastmodified'} = $now;
1175: my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
1176: if ($putres eq 'ok') {
1.123 raeburn 1177: ($uploaded,$minimal,$external) =
1178: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1179: $minimal,$external);
1.121 raeburn 1180: $output = '<div>'.
1181: &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
1182: '</div>';
1183: } else {
1184: $output = '<div class="LC_error">'.
1185: &mt('An error occurred storing the template: [_1]',$putres).
1186: '</div>';
1187: }
1188: } elsif ($env{'form.choice'} eq 'url') {
1189: if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
1190: if ($env{'form.externalsyllabus'} eq $external) {
1191: $output = '<div class="LC_info">'.
1192: &mt('External URL unchanged.').
1193: '</div>';
1.123 raeburn 1194: ($uploaded,$minimal,$external) =
1195: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1196: $minimal,$external);
1.121 raeburn 1197: } else {
1198: $external=$env{'form.externalsyllabus'};
1199: $external =~ s/(`)//g;
1200: my $putres =
1201: &Apache::lonnet::put('environment',{externalsyllabus=>$external},
1202: $cdom,$cnum);
1203: if ($putres eq 'ok') {
1204: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
1205: $output = '<div>'.
1206: &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
1207: '</div>';
1.123 raeburn 1208: ($uploaded,$minimal,$external) =
1209: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1210: $minimal,$external);
1.121 raeburn 1211: } else {
1212: $output = '<div class="LC_error">'.
1213: &mt('An error occurred storing the external URL: [_1]',$putres).
1214: '</div>';
1215: }
1216: }
1217: } else {
1218: $output = '<div class="LC_error">'.
1219: &mt('External URL not saved -- invalid URL.').
1220: '</div>';
1221: }
1.122 raeburn 1222: } elsif (($env{'form.choice'} eq 'file') || ($env{'form.choice'} eq 'minimal')) {
1.121 raeburn 1223: # Process file upload - phase one - upload and parse primary file.
1.122 raeburn 1224: my ($upload_result,$uploadphase,$url,$needlink,$error,$errormsg);
1225: if ($env{'form.choice'} eq 'file') {
1226: if ($env{'form.syllabusfile.filename'}) {
1227: my %allfiles = ();
1228: my %codebase = ();
1229: ($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
1230: \%allfiles,\%codebase);
1231: } else {
1232: $output = '<div class="LC_info">';
1233: &mt('No file uploaded').
1234: '</div>';
1235: }
1236: } elsif ($env{'form.choice'} eq 'minimal') {
1237: my $title = $env{'form.syllabustitle'};
1238: $title =~ s{`}{}g;
1239: $title=~s/^\s+//;
1240: $title=~s/\s+$//;
1241: if ($title eq '') {
1242: $title = &mt('Syllabus');
1243: }
1244: my $initialtext = &mt('Replace with your own content.');
1245: my $newhtml = <<END;
1246: <html>
1247: <head>
1248: <title>$title</title>
1249: </head>
1250: <body bgcolor="#ffffff">
1251: <h2>$title</h2>
1252: $initialtext
1253: </body>
1254: </html>
1255: END
1256: $env{'form.output'}=$newhtml;
1257: $url =
1258: &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
1259: 'portfolio/syllabus/loncapa.html');
1260: }
1261: if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
1.123 raeburn 1262: my $exturl = &home_http_host($cdom,$cnum);
1263: if ($exturl) {
1264: $exturl .= $url;
1.122 raeburn 1265: }
1266: my %storehash;
1267: if ($env{'form.choice'} eq 'minimal') {
1268: $storehash{'minimalsyllabus'} = $url;
1269: } else {
1270: $storehash{'uploadedsyllabus'} = $url;
1271: }
1272: if ($exturl) {
1273: $storehash{'externalsyllabus'} = $exturl;
1274: if ($exturl =~ /\.(html?|txt|js|css)$/) {
1275: $exturl .= '?inhibitmenu=yes';
1276: }
1277: } else {
1278: $storehash{'externalsyllabus'} = '',
1279: }
1280: my $putres =
1281: &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1282: if ($putres eq 'ok') {
1283: &Apache::lonnet::make_public_indefinitely($url);
1284: foreach my $key (keys(%storehash)) {
1285: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash{$key}});
1286: }
1287: if ($env{'form.choice'} eq 'minimal') {
1288: $minimal = $url;
1.121 raeburn 1289: } else {
1.122 raeburn 1290: $uploaded = $url;
1.121 raeburn 1291: }
1.122 raeburn 1292: if ($needlink) {
1293: $output .= &return_to_editor($cdom,$cnum);
1294: $earlyout = 1;
1.121 raeburn 1295: }
1.123 raeburn 1296: ($uploaded,$minimal,$external) =
1297: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1298: $minimal,$external);
1.122 raeburn 1299: } else {
1300: $error = 1;
1301: $errormsg = $putres;
1302: }
1303: } else {
1304: $error = 1;
1305: }
1306: if ($error) {
1307: $output = '<div class="LC_error">';
1308: if ($env{'form.choice'} eq 'minimal') {
1309: $output = &mt('An error occurred creating the minimal template file [_1]',$errormsg);
1310: } else {
1311: $output = &mt('An error occurred storing the uploaded file [_1]',$errormsg);
1.121 raeburn 1312: }
1.122 raeburn 1313: $output .= '</div>';
1.121 raeburn 1314: }
1315: } elsif ($env{'form.phase'} eq 'upload_embedded') {
1316: # Process file upload - phase two - upload embedded objects
1317: my $uploadphase = 'check_embedded';
1318: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
1319: my $state = &embedded_form_elems($uploadphase,$primaryurl);
1320: my $url_root = '/uploaded/'.$cdom.'/'.$cnum;
1321: my $actionurl = "/public/$cdom/$cnum/syllabus";
1322: my ($result,$flag,$numpathchgs) =
1323: &Apache::loncommon::upload_embedded('syllabus','portfolio/syllabus',
1324: $cnum,$cdom,'/userfiles',$url_root,undef,undef,undef,$state,
1325: $actionurl);
1326: unless ($numpathchgs) {
1327: my $modres =
1328: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1329: $cnum,$cdom,
1330: '/userfiles',$env{'form.primaryurl'});
1331: $result .= $modres;
1332: }
1.122 raeburn 1333: $output = $result.&return_to_editor($cdom,$cnum);
1.121 raeburn 1334: $earlyout = 1;
1335: } elsif ($env{'form.phase'} eq 'check_embedded') {
1336: # Process file upload - phase three - modify references in HTML file
1337: my $uploadphase = 'modified_orightml';
1338: my $result =
1339: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1340: $cnum,$cdom,
1341: '/userfiles',$env{'form.primaryurl'});
1.122 raeburn 1342: $output = $result.&return_to_editor($cdom,$cnum);
1.121 raeburn 1343: $earlyout = 1;
1344: }
1.122 raeburn 1345: return ($earlyout,$uploaded,$external,$minimal,$output);
1.121 raeburn 1346: }
1347:
1.123 raeburn 1348: sub update_syllabus_env {
1.124 raeburn 1349: my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_;
1.125 raeburn 1350: return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH');
1.123 raeburn 1351: my $now = time;
1352: my (@envkeys,%storehash);
1353: if ($saved eq 'template') {
1354: if ($uploaded) {
1355: push(@envkeys,'uploaded');
1356: }
1357: if ($minimal) {
1358: push(@envkeys,'minimal');
1359: }
1360: if ($external) {
1361: push(@envkeys,'external');
1362: }
1363: $storehash{'updatedsyllabus'} = $now;
1364: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now
1365: });
1366:
1367: } elsif ($saved eq 'url') {
1368: my $prefix = &home_http_host($cdom,$cnum);
1369: if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) {
1370: my $file = $1;
1371: if ($file eq 'loncapa.html') {
1372: if ($uploaded) {
1373: push(@envkeys,'uploaded');
1374: }
1375: } elsif ($minimal) {
1376: push(@envkeys,'minimal');
1377: }
1378: } else {
1379: if ($uploaded) {
1380: push(@envkeys,'uploaded');
1381: }
1382: if ($minimal) {
1383: push(@envkeys,'minimal');
1384: }
1385: }
1386: } elsif ($saved eq 'file') {
1387: if ($minimal) {
1388: push(@envkeys,'minimal');
1389: }
1390: } elsif ($saved eq 'minimal') {
1391: if ($uploaded) {
1392: push(@envkeys,'uploaded');
1393: }
1394: }
1395: if (@envkeys > 0) {
1396: foreach my $item (@envkeys) {
1397: my $key = $item.'syllabus';
1398: if ($courseenv->{$key}) {
1399: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
1400: $storehash{$key} = '';
1401: }
1402: if ($item eq 'uploaded') {
1403: undef($uploaded);
1404: }
1405: if ($item eq 'external') {
1406: undef($external);
1407: }
1408: if ($item eq 'minimal') {
1409: undef($minimal);
1410: }
1411: }
1412: }
1413: if (keys(%storehash) > 0) {
1414: &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1415: }
1416: return ($uploaded,$minimal,$external);
1417: }
1418:
1419: sub home_http_host {
1420: my ($cdom,$cnum) = @_;
1421: my $home=&Apache::lonnet::homeserver($cnum,$cdom);
1422: if ($home ne 'no_host') {
1423: my $protocol = $Apache::lonnet::protocol{$home};
1424: $protocol = 'http' if ($protocol ne 'https');
1.125 raeburn 1425: return $protocol.'://'.$home;
1.123 raeburn 1426: }
1427: return;
1428: }
1429:
1.117 raeburn 1430: sub process_upload {
1431: my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
1432: my ($parseaction,$showupload,$mimetype);
1433: my $dest = 'portfolio/syllabus';
1434: if ($env{'form.parserflag'}) {
1435: $parseaction = 'parse';
1436: }
1437: my $url=&Apache::lonnet::userfileupload('syllabusfile','syllabus',$dest,
1438: $parseaction,$allfiles,
1439: $codebase,undef,undef,undef,undef,
1440: undef,undef,\$mimetype);
1441: if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/([^/]+)$}) {
1442: my $stored = $1;
1443: $showupload = '<p>'.&mt('Uploaded [_1]',
1444: '<span class="LC_filename">'.$stored.'</span>').
1445: '</p>';
1446: } else {
1447: my ($filename) = ($env{'form.syllabusfile.filename'} =~ m{([^/]+)$});
1448: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.
1449: &mt('Unable to save file [_1].',
1450: '<span class="LC_filename">'.$filename.'</span>').
1451: '</div>';
1452: return ();
1453: }
1454: my $needlink;
1455: if (($parseaction eq 'parse') && ($mimetype eq 'text/html')) {
1456: $$upload_output = $showupload;
1457: my $total_embedded = scalar(keys(%{$allfiles}));
1458: if ($total_embedded > 0) {
1459: my $uploadphase = 'upload_embedded';
1460: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
1461: my $state = &embedded_form_elems($uploadphase,$primaryurl);
1462: my $actionurl = "/public/$cdom/$cnum/syllabus";
1463: my ($embedded,$num,$numpathchanges,$existing);
1464: ($embedded,$num,$numpathchanges,$existing) =
1465: &Apache::loncommon::ask_for_embedded_content($actionurl,$state,
1466: $allfiles,$codebase,
1467: {'error_on_invalid_names' => 1,
1468: 'ignore_remote_references' => 1,});
1469: if ($embedded) {
1470: $needlink = 1;
1471: if ($num) {
1472: $$upload_output .=
1473: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
1474: } elsif ($numpathchanges) {
1475: $$upload_output .= $embedded;
1476: } else {
1477: $$upload_output .= $embedded;
1478: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1479: $cnum,$cdom,'/userfiles',$url);
1480: }
1481: } else {
1482: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
1483: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1484: $cnum,$cdom,'/userfiles',$url);
1485:
1486: }
1487: } else {
1488: $$upload_output .= &mt('No embedded items identified').'<br />';
1489: }
1490: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1491: }
1492: return ($url,$needlink);
1493: }
1494:
1495: sub embedded_form_elems {
1496: my ($phase,$primaryurl) = @_;
1497: return <<STATE;
1498: <input type="hidden" name="forceedit" value="1" />
1499: <input type="hidden" name="cmd" value="upload_embedded" />
1500: <input type="hidden" name="phase" value="$phase" />
1501: <input type="hidden" name="primaryurl" value="$primaryurl" />
1502: STATE
1503: }
1504:
1505: sub return_to_editor {
1506: my ($cdom,$cnum) = @_;
1507: my $actionurl = "/public/$cdom/$cnum/syllabus";
1508: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'.
1509: '<input type="hidden" name="forceedit" value="1" />'."\n".
1510: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
1511: '</a></p>';
1512: }
1513:
1.118 raeburn 1514: sub editfile_button {
1.125 raeburn 1515: my ($url,$context,$editable) = @_;
1.122 raeburn 1516: my $edittext=&mt('Edit');
1517: my $deltext=&mt('Delete');
1.125 raeburn 1518: my $output;
1519: if ($editable) {
1520: $output = '
1521: <input type="button" value="'.$edittext.'" onclick="javascript:gotoeditor('."'$url'".');" name="edit_'.$context.'" />
1522: ';
1523: }
1524: $output .= '
1525: <input type="button" value="'.$deltext.'" onclick="javascript:dodelete('."'$context'".');" name="del_'.$context.'" />
1.128 raeburn 1526: <input type="hidden" value="" name="deleteuploaded_'.$context.'" id="deleteuploaded_'.$context.'" />
1.125 raeburn 1527: ';
1528: return $output;
1.118 raeburn 1529: }
1530:
1531: sub editbutton_js {
1.126 raeburn 1532: my %lt = &Apache::lonlocal::texthash(
1533: min => 'Are you sure you want to delete the contents of the syllabus template?',
1534: file => 'Are you sure you want to delete the uploaded syllabus file?',
1535: noundo => 'This action cannot be reversed.'
1536: );
1.118 raeburn 1537: return <<ENDJS;
1538: <script type="text/javascript">
1539: // <![CDATA[
1.122 raeburn 1540: function gotoeditor(url) {
1541: document.location.href = url+'?editmode=1&forceedit=1';
1542: }
1543: function dodelete(caller,url) {
1.128 raeburn 1544: if (document.getElementById('deleteuploaded_'+caller)) {
1545: document.getElementById('deleteuploaded_'+caller).value=1;
1546: if (caller == 'minimal') {
1547: if (confirm("$lt{'min'}"+"\\n"+"$lt{'noundo'}")) {
1548: document.syllabus.submit();
1549: }
1.126 raeburn 1550: }
1.128 raeburn 1551: if (caller == 'file') {
1552: if (confirm("$lt{'file'}"+"\\n"+"$lt{'noundo'}")) {
1553: document.syllabus.submit();
1554: }
1.126 raeburn 1555: }
1556: }
1557: return;
1.118 raeburn 1558: }
1559: // ]]>
1560: </script>
1561: ENDJS
1562: }
1563:
1.1 www 1564: 1;
1565: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>