Annotation of loncom/interface/londocs.pm, revision 1.314.2.4
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.314.2.4! raeburn 4: # $Id: londocs.pm,v 1.314.2.3 2008/12/21 15:48:43 raeburn Exp $
1.1 www 5: #
1.3 www 6: # Copyright Michigan State University Board of Trustees
1.1 www 7: #
1.3 www 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1 www 9: #
1.3 www 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.
1.1 www 14: #
1.3 www 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:
1.2 www 29: package Apache::londocs;
1.1 www 30:
31: use strict;
1.28 www 32: use Apache::Constants qw(:common :http);
1.158 raeburn 33: use Apache::imsexport;
1.4 www 34: use Apache::lonnet;
35: use Apache::loncommon;
1.245 albertel 36: use LONCAPA::map();
37: use Apache::lonratedt();
1.15 www 38: use Apache::lonxml;
1.244 albertel 39: use Apache::lonclonecourse;
1.138 raeburn 40: use Apache::lonnavmaps;
1.38 www 41: use HTML::Entities;
1.27 www 42: use GDBM_File;
1.81 www 43: use Apache::lonlocal;
1.143 raeburn 44: use Cwd;
1.264 albertel 45: use LONCAPA qw(:DEFAULT :match);
1.7 www 46:
1.8 www 47: my $iconpath;
1.7 www 48:
1.27 www 49: my %hash;
50:
51: my $hashtied;
1.29 www 52: my %alreadyseen=();
1.27 www 53:
1.40 www 54: my $hadchanges;
55:
1.47 www 56: # Available help topics
57:
58: my %help=();
59:
1.245 albertel 60: # Mapread read maps into LONCAPA::map:: global arrays
1.10 www 61: # @order and @resources, determines status
1.7 www 62: # sets @order - pointer to resources in right order
63: # sets @resources - array with the resources with correct idx
64: #
65:
66: sub mapread {
67: my ($coursenum,$coursedom,$map)=@_;
68: return
1.245 albertel 69: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
70: $map);
1.7 www 71: }
72:
73: sub storemap {
74: my ($coursenum,$coursedom,$map)=@_;
1.104 albertel 75: my ($outtext,$errtext)=
1.245 albertel 76: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map,1);
1.104 albertel 78: if ($errtext) { return ($errtext,2); }
79:
80: $hadchanges=1;
81: return ($errtext,0);
1.7 www 82: }
83:
1.74 www 84: # ----------------------------------------- Return hash with valid author names
85:
86: sub authorhosts {
87: my %outhash=();
88: my $home=0;
89: my $other=0;
1.174 albertel 90: foreach (keys %env) {
1.74 www 91: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
92: my $role=$1;
93: my $realm=$2;
1.174 albertel 94: my ($start,$end)=split(/\./,$env{$_});
1.74 www 95: if (($start) && ($start>time)) { next; }
96: if (($end) && (time>$end)) { next; }
97: my $ca; my $cd;
98: if ($1 eq 'au') {
1.174 albertel 99: $ca=$env{'user.name'};
100: $cd=$env{'user.domain'};
1.74 www 101: } else {
1.264 albertel 102: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
1.74 www 103: }
1.107 albertel 104: my $allowed=0;
105: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
106: my @ids=&Apache::lonnet::current_machine_ids();
107: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
108: if ($allowed) {
1.74 www 109: $home++;
110: $outhash{'home_'.$ca.'@'.$cd}=1;
111: } else {
1.107 albertel 112: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
1.74 www 113: $other++;
114: }
115: }
116: }
117: return ($home,$other,%outhash);
118: }
119: # ------------------------------------------------------ Generate "dump" button
120:
121: sub dumpbutton {
122: my ($home,$other,%outhash)=&authorhosts();
1.230 albertel 123: my $type = &Apache::loncommon::course_type();
1.74 www 124: if ($home+$other==0) { return ''; }
125: if ($home) {
1.283 albertel 126: return '<div>'.
1.81 www 127: '<input type="submit" name="dumpcourse" value="'.
1.230 albertel 128: &mt('Dump '.$type.' DOCS to Construction Space').'" />'.
1.283 albertel 129: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').
130: '</div>';
1.74 www 131: } else {
1.283 albertel 132: return '<div>'.
1.230 albertel 133: &mt('Dump '.$type.
1.283 albertel 134: ' DOCS to Construction Space: available on other servers').
135: '</div>';
1.74 www 136: }
137: }
138:
1.164 albertel 139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
142: return $title;
143: }
1.74 www 144: # -------------------------------------------------------- Actually dump course
145:
146: sub dumpcourse {
1.224 albertel 147: my ($r) = @_;
1.230 albertel 148: my $type = &Apache::loncommon::course_type();
149: $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
150: '<form name="dumpdoc" method="post">');
1.257 www 151: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));
1.74 www 152: my ($home,$other,%outhash)=&authorhosts();
1.75 www 153: unless ($home) { return ''; }
1.174 albertel 154: my $origcrsid=$env{'request.course.id'};
1.76 www 155: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
1.174 albertel 156: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.76 www 157: # Do the dumping
1.174 albertel 158: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
159: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
1.87 www 160: $r->print('<h3>'.&mt('Copying Files').'</h3>');
1.174 albertel 161: my $title=$env{'form.authorfolder'};
1.164 albertel 162: $title=&clean($title);
1.79 www 163: my %replacehash=();
1.174 albertel 164: foreach (keys %env) {
1.79 www 165: if ($_=~/^form\.namefor\_(.+)/) {
1.174 albertel 166: $replacehash{$1}=$env{$_};
1.79 www 167: }
168: }
1.174 albertel 169: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
1.79 www 170: $crs=~s/\_/\//g;
171: foreach (keys %replacehash) {
172: my $newfilename=$title.'/'.$replacehash{$_};
1.205 albertel 173: $newfilename=~s/\.(\w+)$//;
174: my $ext=$1;
1.164 albertel 175: $newfilename=&clean($newfilename);
1.205 albertel 176: $newfilename.='.'.$ext;
1.79 www 177: my @dirs=split(/\//,$newfilename);
178: my $path='/home/'.$ca.'/public_html';
179: my $makepath=$path;
180: my $fail=0;
181: for (my $i=0;$i<$#dirs;$i++) {
182: $makepath.='/'.$dirs[$i];
183: unless (-e $makepath) {
184: unless(mkdir($makepath,0777)) { $fail=1; }
185: }
186: }
187: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
188: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
189: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
1.244 albertel 190: print $fh &Apache::lonclonecourse::rewritefile(
191: &Apache::lonclonecourse::readfile($env{'request.course.id'},$_),
1.79 www 192: (%replacehash,$crs => '')
193: );
194: } else {
195: print $fh
1.244 albertel 196: &Apache::lonclonecourse::readfile($env{'request.course.id'},$_);
1.79 www 197: }
198: $fh->close();
199: } else {
200: $fail=1;
201: }
202: if ($fail) {
1.283 albertel 203: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
1.79 www 204: } else {
1.283 albertel 205: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.79 www 206: }
207: }
1.76 www 208: } else {
209: # Input form
210: unless ($home==1) {
211: $r->print(
1.81 www 212: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
1.76 www 213: }
214: foreach (sort keys %outhash) {
215: if ($_=~/^home_(.+)$/) {
216: if ($home==1) {
217: $r->print(
218: '<input type="hidden" name="authorspace" value="'.$1.'" />');
219: } else {
1.133 www 220: $r->print('<option value="'.$1.'">'.$1.' - '.
221: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
1.76 www 222: }
223: }
224: }
225: unless ($home==1) {
226: $r->print('</select>');
227: }
228: my $title=$origcrsdata{'description'};
1.227 albertel 229: $title=~s/[\/\s]+/\_/gs;
1.164 albertel 230: $title=&clean($title);
1.314 bisitz 231: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
232: .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
1.76 www 233: &tiehash();
1.314 bisitz 234: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
235: .&Apache::loncommon::start_data_table()
236: .&Apache::loncommon::start_data_table_header_row()
237: .'<th>'.&mt('Internal Filename').'</th>'
238: .'<th>'.&mt('Title').'</th>'
239: .'<th>'.&mt('Save as ...').'</th>'
240: .&Apache::loncommon::end_data_table_header_row());
1.244 albertel 241: foreach (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
1.314 bisitz 242: $r->print(&Apache::loncommon::start_data_table_row()
243: .'<td>'.$_.'</td>');
1.78 www 244: my ($ext)=($_=~/\.(\w+)$/);
245: my $title=$hash{'title_'.$hash{
246: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
247: $r->print('<td>'.($title?$title:' ').'</td>');
1.235 albertel 248: if (!$title) {
1.78 www 249: $title=$_;
1.235 albertel 250: } else {
251: $title=~s|/|_|g;
1.78 www 252: }
253: $title=~s/\.(\w+)$//;
1.164 albertel 254: $title=&clean($title);
1.78 www 255: $title.='.'.$ext;
1.314 bisitz 256: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td>"
257: .&Apache::loncommon::end_data_table_row());
1.76 www 258: }
1.314 bisitz 259: $r->print(&Apache::loncommon::end_data_table());
1.76 www 260: &untiehash();
261: $r->print(
1.314 bisitz 262: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $type DOCS").'" /></p></form>');
1.75 www 263: }
1.74 www 264: }
1.76 www 265:
1.138 raeburn 266: # ------------------------------------------------------ Generate "export" button
267:
268: sub exportbutton {
1.230 albertel 269: my $type = &Apache::loncommon::course_type();
1.283 albertel 270: return '<div>'.
1.138 raeburn 271: '<input type="submit" name="exportcourse" value="'.
1.230 albertel 272: &mt('Export '.$type.' to IMS').'" />'.
1.283 albertel 273: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'</div>';
1.138 raeburn 274: }
275:
276: sub exportcourse {
277: my $r=shift;
1.230 albertel 278: my $type = &Apache::loncommon::course_type();
1.138 raeburn 279: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
1.174 albertel 280: $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
1.138 raeburn 281: my $numdisc = keys %discussiontime;
282: my $navmap = Apache::lonnavmaps::navmap->new();
1.314.2.4! raeburn 283: if (!defined($navmap)) {
! 284: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package').
! 285: '<h2>IMS Export Failed</h2>'.
! 286: '<div class="LC_error">'.
! 287: &mt('Unable to retrieve information about course contents').
! 288: '</div><a href="/adm/coursedocs">'.&mt('Return to Course Editor').'</a>');
! 289: &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
! 290: return;
! 291: }
1.138 raeburn 292: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
293: my $curRes;
1.143 raeburn 294: my $outcome;
1.138 raeburn 295:
296: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
297: ['finishexport']);
1.174 albertel 298: if ($env{'form.finishexport'}) {
1.138 raeburn 299: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
300: ['archive','discussion']);
301:
1.175 albertel 302: my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
303: my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
1.143 raeburn 304: if (@exportitems == 0 && @discussions == 0) {
305: $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created. Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';
306: } else {
307: my $now = time;
308: my %symbs;
309: my $manifestok = 0;
310: my $imsresources;
311: my $tempexport;
312: my $copyresult;
313: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
314: if ($manifestok) {
1.157 raeburn 315: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
1.143 raeburn 316: close($ims_manifest);
317:
318: #Create zip file in prtspool
319: my $imszipfile = '/prtspool/'.
1.174 albertel 320: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.143 raeburn 321: time.'_'.rand(1000000000).'.zip';
322: my $cwd = &Cwd::getcwd();
323: my $imszip = '/home/httpd/'.$imszipfile;
324: chdir $tempexport;
325: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
326: close(OUTPUT);
327: chdir $cwd;
1.230 albertel 328: $outcome .= &mt('Download the zip file from <a href="[_1]">IMS '.lc($type).' archive</a><br />',$imszipfile,);
1.143 raeburn 329: if ($copyresult) {
1.312 bisitz 330: $outcome .= &mt('The following errors occurred during export - [_1]',$copyresult);
1.138 raeburn 331: }
1.143 raeburn 332: } else {
1.312 bisitz 333: $outcome = '<br />'.&mt('Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.').'<br />';
1.138 raeburn 334: }
335: }
1.229 raeburn 336: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
1.257 www 337: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
1.143 raeburn 338: $r->print($outcome);
1.224 albertel 339: $r->print(&Apache::loncommon::end_page());
1.138 raeburn 340: } else {
341: my $display;
342: $display = '<form name="exportdoc" method="post">'."\n";
1.230 albertel 343: $display .= &mt('Choose which items you wish to export from your '.$type.'.<br /><br />');
1.138 raeburn 344: $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
345: '<tr><td><fieldset><legend> <b>Content items</b></legend>'.
346: '<input type="button" value="check all" '.
347: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
348: ' <input type="button" value="uncheck all"'.
349: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
350: '<td> </td><td> </td>'.
351: '<td align="right"><fieldset><legend> <b>Discussion posts'.
352: '</b></legend><input type="button" value="check all"'.
353: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
354: ' <input type="button" value="uncheck all"'.
355: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
356: '</tr></table>';
357: my $curRes;
358: my $depth = 0;
359: my $count = 0;
360: my $boards = 0;
361: my $startcount = 5;
362: my %parent = ();
363: my %children = ();
364: my $lastcontainer = $startcount;
365: my @bgcolors = ('#F6F6F6','#FFFFFF');
366: $display .= '<table cellspacing="0"><tr>'.
367: '<td><b>Export content item?<br /></b></td><td> </td><td align="right">'."\n";
368: if ($numdisc > 0) {
369: $display.='<b>Export discussion posts?</b>'."\n";
370: }
371: $display.=' </td></tr>';
372: while ($curRes = $it->next()) {
373: if (ref($curRes)) {
374: $count ++;
375: }
376: if ($curRes == $it->BEGIN_MAP()) {
377: $depth++;
378: $parent{$depth} = $lastcontainer;
379: }
380: if ($curRes == $it->END_MAP()) {
381: $depth--;
382: $lastcontainer = $parent{$depth};
383: }
384: if (ref($curRes)) {
385: my $symb = $curRes->symb();
1.158 raeburn 386: my $ressymb = $symb;
1.264 albertel 387: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
1.158 raeburn 388: unless ($ressymb =~ m|adm/wrapper/adm|) {
389: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
390: }
391: }
1.138 raeburn 392: my $color = $count%2;
393: $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
394: '<input type="checkbox" name="archive" value="'.$count.'" ';
395: if (($curRes->is_sequence()) || ($curRes->is_page())) {
396: my $checkitem = $count + $boards + $startcount;
397: $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
398: }
399: $display .= ' />'."\n";
400: for (my $i=0; $i<$depth; $i++) {
1.282 albertel 401: $display .= '<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" /><img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" />'."\n";
1.138 raeburn 402: }
403: if ($curRes->is_sequence()) {
404: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
405: $lastcontainer = $count + $startcount + $boards;
406: } elsif ($curRes->is_page()) {
407: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
408: $lastcontainer = $count + $startcount + $boards;
409: }
410: my $currelem = $count+$boards+$startcount;
411: $children{$parent{$depth}} .= $currelem.':';
412: $display .= ' '.$curRes->title().'</td>';
1.158 raeburn 413: if ($discussiontime{$ressymb} > 0) {
1.138 raeburn 414: $boards ++;
415: $currelem = $count+$boards+$startcount;
416: $display .= '<td> </td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" /> </td>'."\n";
417: } else {
418: $display .= '<td colspan="2"> </td>'."\n";
419: }
420: }
421: }
422: my $scripttag = qq|
423: <script>
424:
425: function checkAll(field) {
1.158 raeburn 426: if (field.length > 0) {
427: for (i = 0; i < field.length; i++) {
428: field[i].checked = true ;
429: }
430: } else {
431: field.checked = true
432: }
1.138 raeburn 433: }
1.158 raeburn 434:
1.138 raeburn 435: function uncheckAll(field) {
1.158 raeburn 436: if (field.length > 0) {
437: for (i = 0; i < field.length; i++) {
438: field[i].checked = false ;
439: }
440: } else {
441: field.checked = false ;
442: }
1.138 raeburn 443: }
444:
445: function propagateCheck(item) {
446: if (document.exportdoc.elements[item].checked == true) {
447: containerCheck(item)
448: }
449: }
450:
451: function containerCheck(item) {
452: document.exportdoc.elements[item].checked = true
453: var numitems = $count + $boards + $startcount
454: var parents = new Array(numitems)
455: for (var i=$startcount; i<numitems; i++) {
456: parents[i] = new Array
457: }
458: |;
459:
460: foreach my $container (sort { $a <=> $b } keys %children) {
461: my @contents = split/:/,$children{$container};
462: for (my $i=0; $i<@contents; $i ++) {
463: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
464: }
465: }
466:
467: $scripttag .= qq|
468: if (parents[item].length > 0) {
469: for (var j=0; j<parents[item].length; j++) {
470: containerCheck(parents[item][j])
471: }
472: }
473: }
474:
475: </script>
476: |;
1.229 raeburn 477: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package',
1.224 albertel 478: $scripttag));
1.257 www 479: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
1.224 albertel 480: $r->print($display.'</table>'.
1.138 raeburn 481: '<p><input type="hidden" name="finishexport" value="1">'.
482: '<input type="submit" name="exportcourse" value="'.
1.314.2.4! raeburn 483: &mt('Export '.$type.' DOCS').'" /></p></form>');
1.138 raeburn 484: }
485: }
486:
1.143 raeburn 487: sub create_ims_store {
488: my ($now,$manifestok,$outcome,$tempexport) = @_;
489: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
490: my $ims_manifest;
491: if (!-e $$tempexport) {
492: mkdir($$tempexport,0700);
493: }
494: $$tempexport .= '/'.$now;
495: if (!-e $$tempexport) {
496: mkdir($$tempexport,0700);
497: }
1.174 albertel 498: $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
1.143 raeburn 499: if (!-e $$tempexport) {
500: mkdir($$tempexport,0700);
501: }
1.159 raeburn 502: if (!-e "$$tempexport/resources") {
503: mkdir("$$tempexport/resources",0700);
504: }
1.143 raeburn 505: # open manifest file
506: my $manifest = '/imsmanifest.xml';
507: my $manifestfilename = $$tempexport.$manifest;
508: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
509: $$manifestok=1;
510: print $ims_manifest
511: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
512: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
513: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
514: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
1.174 albertel 515: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
1.143 raeburn 516: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
517: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
1.199 raeburn 518: ' <metadata>
519: <schema></schema>
520: <imsmd:lom>
521: <imsmd:general>
522: <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
523: <imsmd:title>
524: <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
525: </imsmd:title>
526: </imsmd:general>
527: </imsmd:lom>
528: </metadata>'."\n".
1.174 albertel 529: ' <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
530: ' <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
1.143 raeburn 531: ' structure="hierarchical">'."\n".
1.199 raeburn 532: ' <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
1.143 raeburn 533: } else {
534: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
535: ;
536: }
537: return $ims_manifest;
538: }
539:
540: sub build_package {
541: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
542: # first iterator to look for dependencies
543: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
544: my $curRes;
545: my $count = 0;
546: my $depth = 0;
547: my $lastcontainer = 0;
548: my %parent = ();
549: my @dependencies = ();
1.174 albertel 550: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
551: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.143 raeburn 552: while ($curRes = $it->next()) {
553: if (ref($curRes)) {
554: $count ++;
555: }
556: if ($curRes == $it->BEGIN_MAP()) {
557: $depth++;
558: $parent{$depth} = $lastcontainer;
559: }
560: if ($curRes == $it->END_MAP()) {
561: $depth--;
562: $lastcontainer = $parent{$depth};
563: }
564: if (ref($curRes)) {
565: if ($curRes->is_sequence() || $curRes->is_page()) {
566: $lastcontainer = $count;
567: }
568: if (grep/^$count$/,@$exportitems) {
569: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
570: }
571: }
572: }
573: # second iterator to build manifest and store resources
574: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
575: $depth = 0;
576: my $prevdepth;
577: $count = 0;
578: my $imsresources;
579: my $pkgdepth;
1.157 raeburn 580: while ($curRes = $it->next()) {
581: if ($curRes == $it->BEGIN_MAP()) {
582: $prevdepth = $depth;
583: $depth++;
584: }
585: if ($curRes == $it->END_MAP()) {
1.143 raeburn 586: $prevdepth = $depth;
1.157 raeburn 587: $depth--;
588: }
589:
590: if (ref($curRes)) {
591: $count ++;
592: if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
593: my $symb = $curRes->symb();
594: my $isvisible = 'true';
595: my $resourceref;
596: if ($curRes->randomout()) {
597: $isvisible = 'false';
598: }
599: unless ($curRes->is_sequence()) {
1.174 albertel 600: $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
1.157 raeburn 601: }
1.199 raeburn 602: my $step = $prevdepth - $depth;
603: if (($step >= 0) && ($count > 1)) {
604: while ($step >= 0) {
605: print $ims_manifest "\n".' </item>'."\n";
606: $step --;
607: }
1.157 raeburn 608: }
609: $prevdepth = $depth;
1.143 raeburn 610:
1.157 raeburn 611: my $itementry =
1.174 albertel 612: '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
1.143 raeburn 613: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
614: '<title>'.$curRes->title().'</title>';
1.157 raeburn 615: print $ims_manifest "\n".$itementry;
1.143 raeburn 616:
1.157 raeburn 617: unless ($curRes->is_sequence()) {
618: my $content_file;
619: my @hrefs = ();
620: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
621: if ($content_file) {
622: $imsresources .= "\n".
1.174 albertel 623: ' <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
1.143 raeburn 624: '" type="webcontent" href="'.$content_file.'">'."\n".
625: ' <file href="'.$content_file.'" />'."\n";
1.157 raeburn 626: foreach (@hrefs) {
627: $imsresources .=
1.143 raeburn 628: ' <file href="'.$_.'" />'."\n";
1.157 raeburn 629: }
1.158 raeburn 630: if (grep/^$count$/,@$discussions) {
631: my $ressymb = $symb;
632: my $mode;
1.264 albertel 633: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
1.158 raeburn 634: unless ($ressymb =~ m|adm/wrapper/adm|) {
635: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
636: }
637: $mode = 'board';
638: }
639: my %extras = (
640: caller => 'imsexport',
1.159 raeburn 641: tempexport => $tempexport.'/resources',
1.158 raeburn 642: count => $count
643: );
644: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
645: }
1.157 raeburn 646: $imsresources .= ' </resource>'."\n";
1.143 raeburn 647: }
648: }
1.157 raeburn 649: $pkgdepth = $depth;
1.143 raeburn 650: }
651: }
652: }
1.157 raeburn 653: while ($pkgdepth > 0) {
1.143 raeburn 654: print $ims_manifest " </item>\n";
655: $pkgdepth --;
656: }
657: my $resource_text = qq|
658: </organization>
659: </organizations>
660: <resources>
661: $imsresources
662: </resources>
663: </manifest>
664: |;
665: print $ims_manifest $resource_text;
666: }
667:
668: sub get_dependencies {
669: my ($exportitems,$parent,$depth,$dependencies) = @_;
670: if ($depth > 1) {
1.157 raeburn 671: if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
1.143 raeburn 672: push @$dependencies, $$parent{$depth};
673: if ($depth > 2) {
674: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
675: }
676: }
677: }
678: }
679:
680: sub process_content {
681: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
682: my $content_type;
683: my $message;
1.158 raeburn 684: my @uploads = ();
1.157 raeburn 685: if ($curRes->is_sequence()) {
686: $content_type = 'sequence';
687: } elsif ($curRes->is_page()) {
688: $content_type = 'page'; # need to handle individual items in pages.
1.143 raeburn 689: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
690: $content_type = 'syllabus';
1.158 raeburn 691: my $contents = &Apache::imsexport::templatedpage($content_type);
692: if ($contents) {
693: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
694: }
1.157 raeburn 695: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
1.143 raeburn 696: $content_type = 'external';
1.158 raeburn 697: my $title = $curRes->title;
698: my $contents = &Apache::imsexport::external($symb,$title);
699: if ($contents) {
700: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
701: }
1.143 raeburn 702: } elsif ($symb =~ m-adm/navmaps$-) {
703: $content_type = 'navmap';
1.158 raeburn 704: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
1.143 raeburn 705: $content_type = 'simplepage';
1.158 raeburn 706: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
707: if ($contents) {
708: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
709: }
710: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
1.143 raeburn 711: $content_type = 'simpleproblem';
1.158 raeburn 712: my $contents = &Apache::imsexport::simpleproblem($symb);
713: if ($contents) {
714: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
715: }
1.188 raeburn 716: } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
1.158 raeburn 717: $content_type = 'examupload';
1.264 albertel 718: } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
1.143 raeburn 719: $content_type = 'bulletinboard';
1.158 raeburn 720: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
721: if ($contents) {
722: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
723: }
724: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
1.143 raeburn 725: $content_type = 'aboutme';
1.158 raeburn 726: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
727: if ($contents) {
728: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
729: }
1.157 raeburn 730: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
731: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.162 raeburn 732: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
1.143 raeburn 733: my $canedit = 0;
1.174 albertel 734: if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) {
1.143 raeburn 735: $canedit= 1;
736: }
1.200 raeburn 737: # only include problem code where current user is author
1.143 raeburn 738: if ($canedit) {
1.157 raeburn 739: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
1.143 raeburn 740: } else {
1.157 raeburn 741: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
1.143 raeburn 742: }
1.162 raeburn 743: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
744: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.143 raeburn 745: }
1.158 raeburn 746: if (@uploads > 0) {
747: foreach my $item (@uploads) {
748: my $uploadmsg = '';
1.159 raeburn 749: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
1.158 raeburn 750: if ($uploadmsg) {
751: $$copyresult .= $uploadmsg."\n";
752: }
753: }
754: }
1.157 raeburn 755: if ($message) {
756: $$copyresult .= $message."\n";
757: }
1.143 raeburn 758: }
759:
760: sub replicate_content {
1.157 raeburn 761: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
1.159 raeburn 762: my ($map,$ind,$url);
763: if ($caller eq 'templateupload') {
764: $url = $symb;
765: $url =~ s#//#/#g;
766: } else {
767: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
768: }
1.143 raeburn 769: my $content;
770: my $filename;
771: my $repstatus;
1.157 raeburn 772: my $content_name;
773: if ($url =~ m-/([^/]+)$-) {
1.143 raeburn 774: $filename = $1;
775: if (!-e $tempexport.'/resources') {
776: mkdir($tempexport.'/resources',0700);
777: }
1.157 raeburn 778: if (!-e $tempexport.'/resources/'.$count) {
1.143 raeburn 779: mkdir($tempexport.'/resources/'.$count,0700);
780: }
1.157 raeburn 781: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
1.143 raeburn 782: my $copiedfile;
783: if ($copiedfile = Apache::File->new('>'.$destination)) {
784: my $content;
1.157 raeburn 785: if ($caller eq 'resource') {
1.197 raeburn 786: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
787: my $filepath = &Apache::lonnet::filelocation($respath,$url);
788: $content = &Apache::lonnet::getfile($filepath);
1.143 raeburn 789: if ($content eq -1) {
790: $$message = 'Could not copy file '.$filename;
791: } else {
1.197 raeburn 792: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
1.143 raeburn 793: $repstatus = 'ok';
794: }
1.162 raeburn 795: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
1.143 raeburn 796: my $rtncode;
1.157 raeburn 797: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
798: if ($repstatus eq 'ok') {
799: if ($url =~ /\.html?$/i) {
1.197 raeburn 800: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
1.157 raeburn 801: }
802: } else {
1.197 raeburn 803: $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
1.143 raeburn 804: }
1.162 raeburn 805: } elsif ($caller eq 'noedit') {
806: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
807: $repstatus = 'ok';
808: $content = 'Not the owner of this resource';
1.143 raeburn 809: }
810: if ($repstatus eq 'ok') {
811: print $copiedfile $content;
812: }
813: close($copiedfile);
814: } else {
1.197 raeburn 815: $$message = 'Could not open destination file for '.$filename."<br />\n";
1.143 raeburn 816: }
817: } else {
1.197 raeburn 818: $$message = 'Could not determine name of file for '.$symb."<br />\n";
1.143 raeburn 819: }
1.157 raeburn 820: if ($repstatus eq 'ok') {
1.198 raeburn 821: $content_name = 'resources/'.$count.'/'.$filename;
1.157 raeburn 822: }
823: return $content_name;
824: }
825:
826: sub extract_media {
1.197 raeburn 827: my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
1.198 raeburn 828: my ($dirpath,$container);
1.197 raeburn 829: my %allfiles = ();
830: my %codebase = ();
1.198 raeburn 831: if ($url =~ m-(.*/)([^/]+)$-) {
832: $dirpath = $1;
833: $container = $2;
834: } else {
835: $dirpath = $url;
836: $container = '';
837: }
1.308 raeburn 838: &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
1.197 raeburn 839: foreach my $embed_file (keys(%allfiles)) {
840: my $filename;
841: if ($embed_file =~ m#([^/]+)$#) {
842: $filename = $1;
843: } else {
844: $filename = $embed_file;
845: }
846: my $newname = 'res/'.$filename;
847: my ($rtncode,$embed_content,$repstatus);
848: my $embed_url;
849: if ($embed_file =~ m-^/-) {
850: $embed_url = $embed_file; # points to absolute path
851: } else {
852: if ($embed_file =~ m-https?://-) {
853: next; # points to url
854: } else {
1.198 raeburn 855: $embed_url = $dirpath.$embed_file; # points to relative path
1.197 raeburn 856: }
857: }
858: if ($caller eq 'resource') {
859: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
860: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
861: $embed_content = &Apache::lonnet::getfile($embed_path);
862: unless ($embed_content eq -1) {
863: $repstatus = 'ok';
864: }
865: } elsif ($caller eq 'uploaded') {
866:
867: $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
868: }
869: if ($repstatus eq 'ok') {
870: my $destination = $tempexport.'/resources/'.$count.'/res';
871: if (!-e "$destination") {
872: mkdir($destination,0755);
873: }
874: $destination .= '/'.$filename;
875: my $copiedfile;
876: if ($copiedfile = Apache::File->new('>'.$destination)) {
877: print $copiedfile $embed_content;
1.198 raeburn 878: push @{$href}, 'resources/'.$count.'/res/'.$filename;
1.197 raeburn 879: my $attrib_regexp = '';
880: if (@{$allfiles{$embed_file}} > 1) {
881: $attrib_regexp = join('|',@{$allfiles{$embed_file}});
882: } else {
883: $attrib_regexp = $allfiles{$embed_file}[0];
884: }
885: $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
1.198 raeburn 886: if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
1.197 raeburn 887: $$content =~ s#\Q$embed_file\E#$newname#gi;
888: }
889: }
890: } else {
891: $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
892: }
893: }
1.157 raeburn 894: return;
1.143 raeburn 895: }
1.74 www 896:
1.158 raeburn 897: sub store_template {
898: my ($contents,$tempexport,$count,$content_type) = @_;
899: if ($contents) {
1.159 raeburn 900: if ($tempexport) {
901: if (!-e $tempexport.'/resources') {
902: mkdir($tempexport.'/resources',0700);
903: }
904: if (!-e $tempexport.'/resources/'.$count) {
905: mkdir($tempexport.'/resources/'.$count,0700);
906: }
907: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
908: my $storetemplate;
909: if ($storetemplate = Apache::File->new('>'.$destination)) {
910: print $storetemplate $contents;
911: close($storetemplate);
912: }
913: if ($content_type eq 'external') {
1.198 raeburn 914: return 'resources/'.$count.'/'.$content_type.'.html';
1.159 raeburn 915: } else {
1.198 raeburn 916: return 'resources/'.$count.'/'.$content_type.'.xml';
1.159 raeburn 917: }
1.158 raeburn 918: }
919: }
920: }
921:
1.73 bowersj2 922: # Imports the given (name, url) resources into the course
923: # coursenum, coursedom, and folder must precede the list
924: sub group_import {
1.277 albertel 925: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
926:
927: while (@files) {
1.287 albertel 928: my ($name, $url, $residx) = @{ shift(@files) };
1.277 albertel 929: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
930: && ($caller eq 'londocs')
931: && (!&Apache::lonnet::stat_file($url))) {
932:
1.142 raeburn 933: my $errtext = '';
934: my $fatal = 0;
935: my $newmapstr = '<map>'."\n".
936: '<resource id="1" src="" type="start"></resource>'."\n".
937: '<link from="1" to="2" index="1"></link>'."\n".
938: '<resource id="2" src="" type="finish"></resource>'."\n".
939: '</map>';
1.174 albertel 940: $env{'form.output'}=$newmapstr;
1.189 albertel 941: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1.142 raeburn 942: 'output',$1.$2);
943: if ($result != m|^/uploaded/|) {
1.312 bisitz 944: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1.142 raeburn 945: $fatal = 2;
946: }
947: if ($fatal) {
948: return ($errtext,$fatal);
949: }
950: }
1.73 bowersj2 951: if ($url) {
1.288 albertel 952: if (!$residx
953: || defined($LONCAPA::map::zombies[$residx])) {
954: $residx = &LONCAPA::map::getresidx($url,$residx);
955: push(@LONCAPA::map::order, $residx);
1.287 albertel 956: }
1.73 bowersj2 957: my $ext = 'false';
1.263 albertel 958: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.273 albertel 959: $url = &LONCAPA::map::qtunescape($url);
960: $name = &LONCAPA::map::qtunescape($name);
1.287 albertel 961: $LONCAPA::map::resources[$residx] =
962: join(':', ($name, $url, $ext, 'normal', 'res'));
1.73 bowersj2 963: }
964: }
1.142 raeburn 965: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73 bowersj2 966: }
967:
1.114 albertel 968: sub breadcrumbs {
1.309 raeburn 969: my ($where,$allowed,$type)=@_;
1.114 albertel 970: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142 raeburn 971: my (@folders);
1.174 albertel 972: if ($env{'form.pagepath'}) {
973: @folders = split('&',$env{'form.pagepath'});
1.142 raeburn 974: } else {
1.174 albertel 975: @folders=split('&',$env{'form.folderpath'});
1.142 raeburn 976: }
1.116 albertel 977: my $folderpath;
1.168 www 978: my $cpinfo='';
1.251 www 979: my $plain='';
1.242 www 980: my $randompick=-1;
981: my $isencrypted=0;
982: my $ishidden=0;
1.296 albertel 983: my $is_random_order=0;
1.116 albertel 984: while (@folders) {
985: my $folder=shift(@folders);
1.309 raeburn 986: my $foldername=shift(@folders);
1.116 albertel 987: if ($folderpath) {$folderpath.='&';}
988: $folderpath.=$folder.'&'.$foldername;
989: my $url='/adm/coursedocs?folderpath='.
1.228 www 990: &escape($folderpath);
1.296 albertel 991: my $name=&unescape($foldername);
992: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
993: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
994: if ($1 ne '') {
1.242 www 995: $randompick=$1;
996: } else {
997: $randompick=-1;
998: }
999: if ($2) { $ishidden=1; }
1000: if ($3) { $isencrypted=1; }
1.296 albertel 1001: if ($4 ne '') { $is_random_order = 1; }
1.309 raeburn 1002: if ($folder eq 'supplemental') {
1003: if ($allowed) {
1004: $name = &mt('Supplemental '.$type.' Documents');
1005: } else {
1006: $name = &mt($type.' Documents');
1007: }
1008: }
1.114 albertel 1009: &Apache::lonhtmlcommon::add_breadcrumb(
1.168 www 1010: {'href'=>$url.$cpinfo,
1.242 www 1011: 'title'=>$name,
1.117 albertel 1012: 'text'=>'<font size="+1">'.
1.266 albertel 1013: $name.'</font>',
1014: 'no_mt'=>1,
1.117 albertel 1015: });
1.251 www 1016: $plain.=$name.' > ';
1.114 albertel 1017: }
1.251 www 1018: $plain=~s/\>\;\s*$//;
1.242 www 1019: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.296 albertel 1020: 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
1.114 albertel 1021: }
1022:
1.247 www 1023: sub log_docs {
1024: return &Apache::lonnet::instructor_log('docslog',@_);
1025: }
1026:
1027: {
1028: my @oldresources=();
1029: my @oldorder=();
1030: my $parmidx;
1031: my %parmaction=();
1032: my %parmvalue=();
1.249 www 1033: my $changedflag;
1.247 www 1034:
1035: sub snapshotbefore {
1.248 albertel 1036: @oldresources=@LONCAPA::map::resources;
1037: @oldorder=@LONCAPA::map::order;
1.247 www 1038: $parmidx=undef;
1039: %parmaction=();
1040: %parmvalue=();
1.249 www 1041: $changedflag=0;
1.247 www 1042: }
1043:
1044: sub remember_parms {
1045: my ($idx,$parameter,$action,$value)=@_;
1046: $parmidx=$idx;
1047: $parmaction{$parameter}=$action;
1048: $parmvalue{$parameter}=$value;
1.249 www 1049: $changedflag=1;
1.247 www 1050: }
1051:
1052: sub log_differences {
1.251 www 1053: my ($plain)=@_;
1.260 www 1054: my %storehash=('folder' => $plain,
1055: 'currentfolder' => $env{'form.folder'});
1.247 www 1056: if ($parmidx) {
1057: $storehash{'parameter_res'}=$oldresources[$parmidx];
1058: foreach my $parm (keys %parmaction) {
1059: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1060: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1061: }
1062: }
1063: my $maxidx=$#oldresources;
1.248 albertel 1064: if ($#LONCAPA::map::resources>$#oldresources) {
1065: $maxidx=$#LONCAPA::map::resources;
1.247 www 1066: }
1067: for (my $idx=0; $idx<=$maxidx; $idx++) {
1068: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1069: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1070: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1.249 www 1071: $changedflag=1;
1.247 www 1072: }
1073: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1.252 www 1074: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1075: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1.249 www 1076: $changedflag=1;
1.247 www 1077: }
1078: }
1.251 www 1079: $storehash{'maxidx'}=$maxidx;
1.249 www 1080: if ($changedflag) { &log_docs(\%storehash); }
1.247 www 1081: }
1082: }
1083:
1084:
1085: #
1086: # Docs Change Log
1087: #
1088: sub docs_change_log {
1089: my ($r)=@_;
1.260 www 1090: my $folder=$env{'form.folder'};
1.247 www 1091: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1092: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1093: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1094: $env{'course.'.$env{'request.course.id'}.'.domain'},
1095: $env{'course.'.$env{'request.course.id'}.'.num'});
1.254 albertel 1096:
1.247 www 1097: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1.254 albertel 1098:
1.247 www 1099: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1100: '<input type="hidden" name="docslog" value="1" />');
1.254 albertel 1101:
1.247 www 1102: my %saveable_parameters = ('show' => 'scalar',);
1103: &Apache::loncommon::store_course_settings('docs_log',
1104: \%saveable_parameters);
1105: &Apache::loncommon::restore_course_settings('docs_log',
1106: \%saveable_parameters);
1107: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.254 albertel 1108: my %lt=('hiddenresource' => 'Resources hidden',
1109: 'encrypturl' => 'URL hidden',
1110: 'randompick' => 'Randomly pick',
1.296 albertel 1111: 'randomorder' => 'Randomly ordered',
1.254 albertel 1112: 'set' => 'set to',
1113: 'del' => 'deleted');
1.259 www 1114: $r->print(&Apache::loncommon::display_filter().
1.260 www 1115: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1.247 www 1116: '<input type="submit" value="'.&mt('Display').'" /></form>');
1117: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1.251 www 1118: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1119: &mt('After').'</th>'.
1.247 www 1120: &Apache::loncommon::end_data_table_header_row());
1121: my $shown=0;
1122: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1.260 www 1123: if ($env{'form.displayfilter'} eq 'currentfolder') {
1124: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1125: }
1.247 www 1126: my @changes=keys(%{$docslog{$id}{'logentry'}});
1.261 www 1127: if ($env{'form.displayfilter'} eq 'containing') {
1128: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1129: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1130: foreach my $key (@changes) {
1131: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1132: }
1133: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1134: }
1.247 www 1135: my $count = 0;
1136: my $time =
1137: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1138: my $plainname =
1139: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1140: $docslog{$id}{'exe_udom'});
1141: my $about_me_link =
1142: &Apache::loncommon::aboutmewrapper($plainname,
1143: $docslog{$id}{'exe_uname'},
1144: $docslog{$id}{'exe_udom'});
1145: my $send_msg_link='';
1146: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1147: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1148: $send_msg_link ='<br />'.
1149: &Apache::loncommon::messagewrapper(&mt('Send message'),
1150: $docslog{$id}{'exe_uname'},
1151: $docslog{$id}{'exe_udom'});
1152: }
1153: $r->print(&Apache::loncommon::start_data_table_row());
1154: $r->print('<td>'.$time.'</td>
1155: <td>'.$about_me_link.
1156: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1157: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1.249 www 1158: $send_msg_link.'</td><td>'.
1.251 www 1159: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1160: # Before
1161: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1162: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1163: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1164: if ($oldname ne $newname) {
1.252 www 1165: $r->print(&LONCAPA::map::qtescape($oldname));
1.251 www 1166: }
1167: }
1.252 www 1168: $r->print('<ul>');
1169: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1170: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1171: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1172: }
1173: }
1174: $r->print('</ul>');
1.251 www 1175: # After
1176: $r->print('</td><td>');
1177:
1178: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1179: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1180: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1.279 albertel 1181: if ($oldname ne '' && $oldname ne $newname) {
1.252 www 1182: $r->print(&LONCAPA::map::qtescape($newname));
1.251 www 1183: }
1184: }
1.252 www 1185: $r->print('<ul>');
1186: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1187: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1188: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1189: }
1190: }
1191: $r->print('</ul>');
1192: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1193: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.296 albertel 1194: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1.252 www 1195: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.254 albertel 1196: $r->print('<li>'.
1197: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1198: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1199: .'</li>');
1.252 www 1200: }
1201: }
1202: $r->print('</ul>');
1203: }
1.251 www 1204: # End
1205: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1.247 www 1206: $shown++;
1207: if (!($env{'form.show'} eq &mt('all')
1208: || $shown<=$env{'form.show'})) { last; }
1209: }
1210: $r->print(&Apache::loncommon::end_data_table());
1211: }
1212:
1.281 albertel 1213: sub update_paste_buffer {
1214: my ($coursenum,$coursedom) = @_;
1215:
1216: return if (!defined($env{'form.markcopy'}));
1217: return if (!defined($env{'form.copyfolder'}));
1218: return if ($env{'form.markcopy'} < 0);
1219:
1220: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1221: $env{'form.copyfolder'});
1222:
1223: return if ($fatal);
1224:
1225: # Mark for copying
1226: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1227: if (&is_supplemental_title($title)) {
1.311 raeburn 1228: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1.281 albertel 1229: ($title) = &parse_supplemental_title($title);
1.311 raeburn 1230: } elsif ($env{'docs.markedcopy_supplemental'}) {
1231: &Apache::lonnet::delenv('docs\\.markedcopy_supplemental');
1.281 albertel 1232: }
1.287 albertel 1233: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1234:
1.304 raeburn 1235: &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
1236: 'docs.markedcopy_url' => $url});
1.281 albertel 1237: delete($env{'form.markcopy'});
1238: }
1239:
1240: sub print_paste_buffer {
1241: my ($r,$container) = @_;
1242: return if (!defined($env{'docs.markedcopy_url'}));
1243:
1244: $r->print(<<ENDPASTE);
1.286 albertel 1245: <form name="pasteform" action="/adm/coursedocs" method="post"><p>
1.281 albertel 1246: ENDPASTE
1247: $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');
1248:
1249: my $type;
1.287 albertel 1250: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1.281 albertel 1251: $type = &mt('External Resource');
1.287 albertel 1252: $r->print($type.': '.
1253: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
1254: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
1.281 albertel 1255: } else {
1256: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1.299 albertel 1257: my $icon = &Apache::loncommon::icon($extension);
1258: if ($extension eq 'sequence' &&
1259: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
1260: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1261: $icon .= '/folder_closed.gif';
1262: }
1.301 albertel 1263: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1.287 albertel 1264: $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
1.281 albertel 1265: }
1266: if ($container eq 'page') {
1.286 albertel 1267: $r->print('
1268: <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
1269: <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
1270: ');
1.281 albertel 1271: } else {
1.286 albertel 1272: $r->print('
1273: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1274: ');
1.281 albertel 1275: }
1.286 albertel 1276: $r->print('</p></form>');
1.281 albertel 1277: }
1278:
1.289 albertel 1279: sub do_paste_from_buffer {
1.311 raeburn 1280: my ($coursenum,$coursedom,$folder) = @_;
1.292 albertel 1281:
1282: return 0 if (!$env{'form.pastemarked'});
1283:
1.289 albertel 1284: # paste resource to end of list
1285: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
1286: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
1287: # Maps need to be copied first
1288: if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
1289: $title=&mt('Copy of').' '.$title;
1.314.2.3 raeburn 1290: my $newid=$$.int(rand(100)).time;
1.314.2.2 raeburn 1291: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1292: if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
1293: my $path = $1;
1294: my $prefix = $2;
1295: my $ancestor = $3;
1296: if (length($ancestor) > 10) {
1297: $ancestor = substr($ancestor,-10,10);
1298: }
1299: $oldid = $path.$prefix.$ancestor;
1300: }
1301: my $counter = 0;
1302: my $newurl=$oldid.$newid.'.'.$ext;
1303: my $is_unique = &uniqueness_check($newurl);
1304: while (!$is_unique && $counter < 100) {
1305: $counter ++;
1306: $newid ++;
1307: $newurl = $oldid.$newid;
1308: $is_unique = &uniqueness_check($newurl);
1309: }
1310: if (!$is_unique) {
1311: if ($url=~/\.page$/) {
1312: return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
1313: } else {
1314: return &mt('Paste failed: an error occurred creating a unique URL for the folder');
1315: }
1316: }
1.289 albertel 1317: my $storefn=$newurl;
1318: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1319: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1320: &Apache::lonnet::getfile($url));
1321: $url = $newurl;
1322: }
1.290 albertel 1323: # published maps can only exists once, so remove it from paste buffer when done
1.289 albertel 1324: if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
1325: &Apache::lonnet::delenv('docs\\.markedcopy');
1326: }
1.290 albertel 1327: if ($url=~ m{/smppg$}) {
1328: my $db_name = &Apache::lonsimplepage::get_db_name($url);
1329: if ($db_name =~ /^smppage_/) {
1330: #simple pages, need to copy the db contents to a new one.
1331: my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
1332: my $now = time();
1333: $db_name =~ s{_\d*$ }{_$now}x;
1334: my $result=&Apache::lonnet::put($db_name,\%contents,
1335: $coursedom,$coursenum);
1336: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1337: $title=&mt('Copy of').' '.$title;
1338: }
1339: }
1.289 albertel 1340: $title = &LONCAPA::map::qtunescape($title);
1341: my $ext='false';
1342: if ($url=~m{^http(|s)://}) { $ext='true'; }
1343: $url = &LONCAPA::map::qtunescape($url);
1344: # Now insert the URL at the bottom
1345: my $newidx = &LONCAPA::map::getresidx($url);
1.311 raeburn 1346: if ($env{'docs.markedcopy_supplemental'}) {
1347: if ($folder =~ /^supplemental/) {
1348: $title = $env{'docs.markedcopy_supplemental'};
1349: } else {
1350: (undef,undef,$title) =
1351: &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1352: }
1353: } else {
1354: if ($folder=~/^supplemental/) {
1355: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1356: $env{'user.domain'}.'___&&&___'.$title;
1357: }
1358: }
1359:
1.289 albertel 1360: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1361: push(@LONCAPA::map::order, $newidx);
1362: # Store the result
1.292 albertel 1363: }
1364:
1.314.2.2 raeburn 1365: sub uniqueness_check {
1366: my ($newurl) = @_;
1367: my $unique = 1;
1368: foreach my $res (@LONCAPA::map::order) {
1369: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1370: $url=&LONCAPA::map::qtescape($url);
1371: if ($newurl eq $url) {
1372: $unique = 0;
1373: last;
1374: }
1375: }
1376: return $unique;
1377: }
1378:
1.292 albertel 1379: my %parameter_type = ( 'randompick' => 'int_pos',
1380: 'hiddenresource' => 'string_yesno',
1.296 albertel 1381: 'encrypturl' => 'string_yesno',
1382: 'randomorder' => 'string_yesno',);
1.292 albertel 1383: my $valid_parameters_re = join('|',keys(%parameter_type));
1384: # set parameters
1385: sub update_parameter {
1386:
1387: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1388:
1389: my $which = $env{'form.changeparms'};
1390: my $idx = $env{'form.setparms'};
1391: if ($env{'form.'.$which.'_'.$idx}) {
1392: my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
1393: : 'yes';
1394: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
1395: $parameter_type{$which});
1396: &remember_parms($idx,$which,'set',$value);
1397: } else {
1398: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1399:
1400: &remember_parms($idx,$which,'del');
1401: }
1402: return 1;
1403: }
1404:
1405:
1406: sub handle_edit_cmd {
1407: my ($coursenum,$coursedom) =@_;
1408:
1409: my ($cmd,$idx)=split('_',$env{'form.cmd'});
1410:
1411: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1412: my ($title, $url, @rrest) = split(':', $ratstr);
1413:
1414: if ($cmd eq 'del') {
1415: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1416: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1417: &Apache::lonnet::removeuploadedurl($url);
1418: } else {
1419: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1420: }
1421: splice(@LONCAPA::map::order, $idx, 1);
1422:
1423: } elsif ($cmd eq 'cut') {
1424: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1425: splice(@LONCAPA::map::order, $idx, 1);
1426:
1427: } elsif ($cmd eq 'up'
1428: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1429: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1430:
1431: } elsif ($cmd eq 'down'
1432: && defined($LONCAPA::map::order[$idx+1])) {
1433: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1434:
1435: } elsif ($cmd eq 'rename') {
1436:
1437: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
1438: if ($comment=~/\S/) {
1439: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1440: $comment.':'.join(':', $url, @rrest);
1441: }
1442: # Devalidate title cache
1443: my $renamed_url=&LONCAPA::map::qtescape($url);
1444: &Apache::lonnet::devalidate_title_cache($renamed_url);
1445: } else {
1446: return 0;
1447: }
1448: return 1;
1.289 albertel 1449: }
1450:
1.7 www 1451: sub editor {
1.309 raeburn 1452: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
1.292 albertel 1453:
1454: my $container= ($env{'form.pagepath'}) ? 'page'
1455: : 'sequence';
1456:
1457: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1458: $folder.'.'.$container);
1459: return $errtext if ($fatal);
1460:
1.245 albertel 1461: if ($#LONCAPA::map::order<1) {
1462: my $idx=&LONCAPA::map::getresidx();
1.178 www 1463: if ($idx<=0) { $idx=1; }
1.245 albertel 1464: $LONCAPA::map::order[0]=$idx;
1465: $LONCAPA::map::resources[$idx]='';
1.17 www 1466: }
1.281 albertel 1467:
1.296 albertel 1468: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
1.309 raeburn 1469: &breadcrumbs($folder,$allowed,$type);
1.242 www 1470: $r->print($breadcrumbtrail);
1.292 albertel 1471:
1.7 www 1472: # ------------------------------------------------------------ Process commands
1.121 www 1473:
1.16 www 1474: # ---------------- if they are for this folder and user allowed to make changes
1.292 albertel 1475: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1.123 www 1476: # set parameters and change order
1.292 albertel 1477: &snapshotbefore();
1478:
1479: if (&update_parameter()) {
1480: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1481: return $errtext if ($fatal);
1482: }
1.121 www 1483:
1.292 albertel 1484: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
1.123 www 1485: # change order
1.292 albertel 1486: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
1487: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
1488:
1489: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1490: return $errtext if ($fatal);
1491: }
1492:
1493: if ($env{'form.pastemarked'}) {
1.311 raeburn 1494: &do_paste_from_buffer($coursenum,$coursedom,$folder);
1.292 albertel 1495: ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
1496: return $errtext if ($fatal);
1497: }
1498:
1499: $r->print($upload_output);
1500:
1501: if (&handle_edit_cmd()) {
1502: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1503: return $errtext if ($fatal);
1504: }
1505: # Group import/search
1506: if ($env{'form.importdetail'}) {
1507: my @imports;
1508: foreach (split(/\&/,$env{'form.importdetail'})) {
1509: if (defined($_)) {
1510: my ($name,$url,$residx)=
1511: map {&unescape($_)} split(/\=/,$_);
1512: push(@imports, [$name, $url, $residx]);
1.123 www 1513: }
1.247 www 1514: }
1.292 albertel 1515: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1516: $container,'londocs',@imports);
1517: return $errtext if ($fatal);
1518: }
1519: # Loading a complete map
1520: if ($env{'form.loadmap'}) {
1521: if ($env{'form.importmap'}=~/\w/) {
1522: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1523: my ($title,$url,$ext,$type)=split(/\:/,$res);
1524: my $idx=&LONCAPA::map::getresidx($url);
1525: $LONCAPA::map::resources[$idx]=$res;
1526: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1.168 www 1527: }
1.104 albertel 1528: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1529: $folder.'.'.$container);
1.292 albertel 1530: return $errtext if ($fatal);
1531: } else {
1532: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1533:
1534: }
1.281 albertel 1535: }
1.292 albertel 1536: &log_differences($plain);
1537: }
1.16 www 1538: # ---------------------------------------------------------------- End commands
1.7 www 1539: # ---------------------------------------------------------------- Print screen
1.292 albertel 1540: my $idx=0;
1541: my $shown=0;
1.296 albertel 1542: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.292 albertel 1543: $r->print('<p>'.&mt('Parameters').':<ul>'.
1544: ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
1545: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1546: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1547: '</ul></p>');
1548: }
1549: if ($randompick>=0) {
1550: $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');
1551: }
1.296 albertel 1552: if ($is_random_order) {
1553: $r->print('<p>'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'</p>');
1554: }
1.292 albertel 1555: $r->print('<table class="LC_docs_editor">');
1556: foreach my $res (@LONCAPA::map::order) {
1557: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1558: $name=&LONCAPA::map::qtescape($name);
1559: $url=&LONCAPA::map::qtescape($url);
1560: unless ($name) { $name=(split(/\//,$url))[-1]; }
1561: unless ($name) { $idx++; next; }
1562: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,
1563: $coursenum));
1564: $idx++;
1565: $shown++;
1566: }
1567: unless ($shown) {
1568: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1.7 www 1569: }
1.292 albertel 1570: $r->print("\n</table>\n");
1.310 raeburn 1571: if ($allowed) {
1572: &print_paste_buffer($r,$container);
1573: }
1.292 albertel 1574: return;
1.7 www 1575: }
1.1 www 1576:
1.188 raeburn 1577: sub process_file_upload {
1.194 raeburn 1578: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1.188 raeburn 1579: # upload a file, if present
1580: my $parseaction;
1.190 albertel 1581: if ($env{'form.parserflag'}) {
1.188 raeburn 1582: $parseaction = 'parse';
1583: }
1584: my $phase_status;
1585: my $folder=$env{'form.folder'};
1.194 raeburn 1586: if ($folder eq '') {
1.188 raeburn 1587: $folder='default';
1588: }
1.194 raeburn 1589: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1.188 raeburn 1590: my $errtext='';
1591: my $fatal=0;
1592: my $container='sequence';
1593: if ($env{'form.pagepath'}) {
1594: $container='page';
1595: }
1596: ($errtext,$fatal)=
1597: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.245 albertel 1598: if ($#LONCAPA::map::order<1) {
1599: $LONCAPA::map::order[0]=1;
1600: $LONCAPA::map::resources[1]='';
1.188 raeburn 1601: }
1602: if ($fatal) {
1603: return 'failed';
1604: }
1605: my $destination = 'docs/';
1.194 raeburn 1606: if ($folder =~ /^supplemental/) {
1607: $destination = 'supplemental/';
1608: }
1609: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188 raeburn 1610: $destination .= 'default/';
1.194 raeburn 1611: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1612: $destination .= $2.'/';
1.188 raeburn 1613: }
1614: # this is for a course, not a user, so set coursedoc flag
1615: # probably the only place in the system where this should be "1"
1.245 albertel 1616: my $newidx=&LONCAPA::map::getresidx();
1.188 raeburn 1617: $destination .= $newidx;
1.190 albertel 1618: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1619: $parseaction,$allfiles,
1620: $codebase);
1.188 raeburn 1621: my $ext='false';
1.287 albertel 1622: if ($url=~m{^http://}) { $ext='true'; }
1.270 albertel 1623: $url = &LONCAPA::map::qtunescape($url);
1.188 raeburn 1624: my $comment=$env{'form.comment'};
1.270 albertel 1625: $comment = &LONCAPA::map::qtunescape($comment);
1.188 raeburn 1626: if ($folder=~/^supplemental/) {
1627: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1628: $env{'user.domain'}.'___&&&___'.$comment;
1629: }
1630:
1.245 albertel 1631: $LONCAPA::map::resources[$newidx]=
1632: $comment.':'.$url.':'.$ext.':normal:res';
1633: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1.190 albertel 1634: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1635: $folder.'.'.$container);
1.188 raeburn 1636: if ($fatal) {
1.283 albertel 1637: $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
1.188 raeburn 1638: return 'failed';
1639: } else {
1640: if ($parseaction eq 'parse') {
1.190 albertel 1641: my $total_embedded = keys(%{$allfiles});
1.188 raeburn 1642: if ($total_embedded > 0) {
1643: my $num = 0;
1.269 albertel 1644: my $state = '
1.282 albertel 1645: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1.269 albertel 1646: <input type="hidden" name="cmd" value="upload_embedded" />
1.188 raeburn 1647: <input type="hidden" name="newidx" value="'.$newidx.'" />
1.228 www 1648: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1.188 raeburn 1649: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1.269 albertel 1650: $phase_status = 'phasetwo';
1651:
1652: $$upload_output .=
1653: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1.308 raeburn 1654: &Apache::loncommon::ask_for_embedded_content(
1655: '/adm/coursedocs',$state,$allfiles,$codebase);
1.188 raeburn 1656: } else {
1657: $$upload_output .= 'No embedded items identified<br />';
1658: }
1659: }
1660: }
1661: }
1662: return $phase_status;
1663: }
1664:
1665: sub process_secondary_uploads {
1666: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1667: my $folder=$env{'form.folder'};
1668: my $destination = 'docs/';
1.195 raeburn 1669: if ($folder =~ /^supplemental/) {
1670: $destination = 'supplemental/';
1671: }
1672: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188 raeburn 1673: $destination .= 'default/';
1.195 raeburn 1674: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1.217 raeburn 1675: $destination .= $2.'/';
1.188 raeburn 1676: }
1677: $destination .= $newidx;
1678: my ($url,$filename);
1679: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1.265 albertel 1680: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1.188 raeburn 1681: return $filename;
1682: }
1683:
1.281 albertel 1684: sub is_supplemental_title {
1685: my ($title) = @_;
1686: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1687: }
1688:
1689: sub parse_supplemental_title {
1690: my ($title) = @_;
1691:
1692: my ($foldertitle,$renametitle);
1693: if ($title =~ /&&&/) {
1694: $title = &HTML::Entites::decode($title);
1695: }
1696: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1697: $renametitle=$4;
1698: my ($time,$uname,$udom) = ($1,$2,$3);
1699: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1700: my $name = &Apache::loncommon::plainname($uname,$udom);
1701: $name = &HTML::Entities::encode($name,'"<>&\'');
1702: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1703: $name.': <br />'.$foldertitle;
1704: }
1705: if (wantarray) {
1706: return ($title,$foldertitle,$renametitle);
1707: }
1708: return $title;
1709: }
1710:
1.8 www 1711: # --------------------------------------------------------------- An entry line
1712:
1713: sub entryline {
1.112 raeburn 1714: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.281 albertel 1715:
1716: my ($foldertitle,$pagetitle,$renametitle);
1717: if (&is_supplemental_title($title)) {
1718: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1719: $pagetitle = $foldertitle;
1720: } else {
1721: $title=&HTML::Entities::encode($title,'"<>&\'');
1722: $renametitle=$title;
1723: $foldertitle=$title;
1724: $pagetitle=$title;
1725: }
1726:
1.245 albertel 1727: my $orderidx=$LONCAPA::map::order[$index];
1.281 albertel 1728:
1729:
1.222 albertel 1730: $renametitle=~s/\\/\\\\/g;
1.38 www 1731: $renametitle=~s/\"\;/\\\"/g;
1.286 albertel 1732: $renametitle=~s/ /%20/g;
1.8 www 1733: my $line='<tr>';
1.286 albertel 1734: my ($form_start,$form_end);
1.8 www 1735: # Edit commands
1.280 albertel 1736: my ($container, $type, $esc_path, $path, $symb);
1.174 albertel 1737: if ($env{'form.folderpath'}) {
1.280 albertel 1738: $type = 'folder';
1.142 raeburn 1739: $container = 'sequence';
1.282 albertel 1740: $esc_path=&escape($env{'form.folderpath'});
1741: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.174 albertel 1742: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1.120 www 1743: }
1.174 albertel 1744: if ($env{'form.pagepath'}) {
1.280 albertel 1745: $type = $container = 'page';
1746: $esc_path=&escape($path = $env{'form.pagepath'});
1.282 albertel 1747: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1.280 albertel 1748: $symb=&escape($env{'form.pagesymb'});
1.142 raeburn 1749: }
1.168 www 1750: my $cpinfo='';
1.109 albertel 1751: if ($allowed) {
1.123 www 1752: my $incindex=$index+1;
1753: my $selectbox='';
1.168 www 1754: if (($folder!~/^supplemental/) &&
1.245 albertel 1755: ($#LONCAPA::map::order>0) &&
1.168 www 1756: ((split(/\:/,
1.245 albertel 1757: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1.168 www 1758: ne '') &&
1759: ((split(/\:/,
1.245 albertel 1760: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.168 www 1761: ne '')) {
1.123 www 1762: $selectbox=
1.124 www 1763: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123 www 1764: '<select name="newpos" onChange="this.form.submit()">';
1.245 albertel 1765: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1.123 www 1766: if ($i==$incindex) {
1767: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1768: } else {
1769: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1770: }
1771: }
1772: $selectbox.='</select>';
1773: }
1.119 www 1774: my %lt=&Apache::lonlocal::texthash(
1775: 'up' => 'Move Up',
1.109 albertel 1776: 'dw' => 'Move Down',
1777: 'rm' => 'Remove',
1.171 www 1778: 'ct' => 'Cut',
1.168 www 1779: 'rn' => 'Rename',
1780: 'cp' => 'Copy');
1.211 www 1781: my $nocopy=0;
1.268 www 1782: my $nocut=0;
1.211 www 1783: if ($url=~/\.(page|sequence)$/) {
1.289 albertel 1784: if ($url =~ m{/res/}) {
1785: # no copy for published maps
1786: $nocopy = 1;
1787: } else {
1.300 albertel 1788: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
1.289 albertel 1789: my ($title,$url,$ext,$type)=split(/\:/,$_);
1790: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1791: $nocopy=1;
1792: last;
1793: }
1.211 www 1794: }
1795: }
1796: }
1.268 www 1797: if ($url=~/^\/res\/lib\/templates\//) {
1798: $nocopy=1;
1799: $nocut=1;
1800: }
1.211 www 1801: my $copylink=' ';
1.267 www 1802: my $cutlink=' ';
1.280 albertel 1803:
1.291 albertel 1804: my $skip_confirm = 0;
1805: if ( $folder =~ /^supplemental/
1806: || ($url =~ m{( /smppg$
1807: |/syllabus$
1808: |/aboutme$
1809: |/navmaps$
1810: |/bulletinboard$
1811: |\.html$
1812: |^/adm/wrapper/ext)}x)) {
1813: $skip_confirm = 1;
1814: }
1815:
1.280 albertel 1816: if (!$nocopy) {
1817: $copylink=(<<ENDCOPY);
1.284 albertel 1818: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
1.211 www 1819: ENDCOPY
1.280 albertel 1820: }
1821: if (!$nocut) {
1822: $cutlink=(<<ENDCUT);
1.291 albertel 1823: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
1.267 www 1824: ENDCUT
1.280 albertel 1825: }
1.286 albertel 1826: $form_start = (<<END);
1827: <form action="/adm/coursedocs" method="post">
1.280 albertel 1828: <input type="hidden" name="${type}path" value="$path" />
1829: <input type="hidden" name="${type}symb" value="$symb" />
1830: <input type="hidden" name="setparms" value="$orderidx" />
1831: <input type="hidden" name="changeparms" value="0" />
1.286 albertel 1832: END
1833: $form_end = '</form>';
1834: $line.=(<<END);
1.280 albertel 1835: <td>
1.285 albertel 1836: <table class="LC_docs_entry_move">
1.280 albertel 1837: <tr>
1.285 albertel 1838: <td>
1.282 albertel 1839: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'><img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" /></a>
1.280 albertel 1840: </td>
1841: </tr>
1842: <tr>
1.285 albertel 1843: <td>
1.282 albertel 1844: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'><img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" /></a>
1.280 albertel 1845: </td>
1846: </tr>
1847: </table>
1848: </td>
1849: <td>
1.286 albertel 1850: $form_start
1.280 albertel 1851: $selectbox
1.286 albertel 1852: $form_end
1.280 albertel 1853: </td>
1.285 albertel 1854: <td class="LC_docs_entry_commands">
1.291 albertel 1855: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1.267 www 1856: $cutlink
1.284 albertel 1857: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
1.211 www 1858: $copylink
1.280 albertel 1859: </td>
1.142 raeburn 1860: END
1.280 albertel 1861:
1.8 www 1862: }
1.16 www 1863: # Figure out what kind of a resource this is
1864: my ($extension)=($url=~/\.(\w+)$/);
1865: my $uploaded=($url=~/^\/*uploaded\//);
1.97 albertel 1866: my $icon=&Apache::loncommon::icon($url);
1.17 www 1867: my $isfolder=0;
1.142 raeburn 1868: my $ispage=0;
1.114 albertel 1869: my $folderarg;
1.142 raeburn 1870: my $pagearg;
1871: my $pagefile;
1.16 www 1872: if ($uploaded) {
1.135 albertel 1873: if ($extension eq 'sequence') {
1874: $icon=$iconpath.'/folder_closed.gif';
1.264 albertel 1875: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1.135 albertel 1876: $url='/adm/coursedocs?';
1877: $folderarg=$1;
1878: $isfolder=1;
1.142 raeburn 1879: } elsif ($extension eq 'page') {
1880: $icon=$iconpath.'/page.gif';
1.264 albertel 1881: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1.142 raeburn 1882: $pagearg=$1;
1883: $url='/adm/coursedocs?';
1884: $ispage=1;
1.135 albertel 1885: } else {
1886: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1887: }
1.16 www 1888: }
1.287 albertel 1889:
1890: my $orig_url = $url;
1891: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1.142 raeburn 1892: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113 albertel 1893: my $symb=&Apache::lonnet::symbclean(
1.50 www 1894: &Apache::lonnet::declutter('uploaded/'.
1.174 albertel 1895: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1896: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1.50 www 1897: '.sequence').
1898: '___'.$residx.'___'.
1.113 albertel 1899: &Apache::lonnet::declutter($url));
1900: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1901: $url=&Apache::lonnet::clutter($url);
1.127 albertel 1902: if ($url=~/^\/*uploaded\//) {
1903: $url=~/\.(\w+)$/;
1904: my $embstyle=&Apache::loncommon::fileembstyle($1);
1905: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1906: $url='/adm/wrapper'.$url;
1907: } elsif ($embstyle eq 'ssi') {
1908: #do nothing with these
1909: } elsif ($url!~/\.(sequence|page)$/) {
1910: $url='/adm/coursedocs/showdoc'.$url;
1911: }
1.145 albertel 1912: } elsif ($url=~m|^/ext/|) {
1913: $url='/adm/wrapper'.$url;
1.287 albertel 1914: $external = 1;
1.127 albertel 1915: }
1.241 www 1916: if (&Apache::lonnet::symbverify($symb,$url)) {
1917: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1918: } else {
1919: $url='';
1920: }
1.152 albertel 1921: if ($container eq 'page') {
1.174 albertel 1922: my $symb=$env{'form.pagesymb'};
1.152 albertel 1923:
1924: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.228 www 1925: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1.152 albertel 1926: }
1.50 www 1927: }
1.296 albertel 1928: my ($parameterset,$rand_order_text) = (' ', ' ');
1.216 albertel 1929: if ($isfolder || $extension eq 'sequence') {
1.228 www 1930: my $foldername=&escape($foldertitle);
1.174 albertel 1931: my $folderpath=$env{'form.folderpath'};
1.114 albertel 1932: if ($folderpath) { $folderpath.='&' };
1.242 www 1933: # Append randompick number, hidden, and encrypted with ":" to foldername,
1934: # so it gets transferred between levels
1.245 albertel 1935: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
1.242 www 1936: 'parameter_randompick'))[0]
1.245 albertel 1937: .':'.((&LONCAPA::map::getparameter($orderidx,
1.242 www 1938: 'parameter_hiddenresource'))[0]=~/^yes$/i)
1.245 albertel 1939: .':'.((&LONCAPA::map::getparameter($orderidx,
1.296 albertel 1940: 'parameter_encrypturl'))[0]=~/^yes$/i)
1941: .':'.((&LONCAPA::map::getparameter($orderidx,
1942: 'parameter_randomorder'))[0]=~/^yes$/i);
1.228 www 1943: $url.='folderpath='.&escape($folderpath).$cpinfo;
1.147 matthew 1944: $parameterset='<label>'.&mt('Randomly Pick: ').
1.292 albertel 1945: '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
1.245 albertel 1946: (&LONCAPA::map::getparameter($orderidx,
1.147 matthew 1947: 'parameter_randompick'))[0].
1.165 www 1948: '" />'.
1.285 albertel 1949: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
1.296 albertel 1950: my $ro_set=
1951: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1952: $rand_order_text ='
1.314.2.1 raeburn 1953: <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onClick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
1.114 albertel 1954: }
1.142 raeburn 1955: if ($ispage) {
1.228 www 1956: my $pagename=&escape($pagetitle);
1.142 raeburn 1957: my $pagepath;
1.174 albertel 1958: my $folderpath=$env{'form.folderpath'};
1.142 raeburn 1959: if ($folderpath) { $pagepath = $folderpath.'&' };
1960: $pagepath.=$pagearg.'&'.$pagename;
1.174 albertel 1961: my $symb=$env{'form.pagesymb'};
1.152 albertel 1962: if (!$symb) {
1963: my $path='uploaded/'.
1.174 albertel 1964: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1965: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1.152 albertel 1966: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1967: $residx,
1968: $path.$pagearg.'.page');
1969: }
1.228 www 1970: $url.='pagepath='.&escape($pagepath).
1.282 albertel 1971: '&pagesymb='.&escape($symb).$cpinfo;
1.142 raeburn 1972: }
1.287 albertel 1973: if ($external) {
1974: my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
1975: $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
1976: } else {
1977: undef($external);
1978: }
1.285 albertel 1979: $line.='
1980: <td class="LC_docs_entry_icon">
1.287 albertel 1981: '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
1.285 albertel 1982: </td>
1983: <td class="LC_docs_entry_title">
1.287 albertel 1984: '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
1.285 albertel 1985: </td>";
1.120 www 1986: if (($allowed) && ($folder!~/^supplemental/)) {
1987: my %lt=&Apache::lonlocal::texthash(
1988: 'hd' => 'Hidden',
1.165 www 1989: 'ec' => 'URL hidden');
1.122 www 1990: my $enctext=
1.245 albertel 1991: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1.122 www 1992: my $hidtext=
1.245 albertel 1993: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120 www 1994: $line.=(<<ENDPARMS);
1.285 albertel 1995: <td class="LC_docs_entry_parameter">
1.286 albertel 1996: $form_start
1.292 albertel 1997: <label><input type="checkbox" name="hiddenresource_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.286 albertel 1998: $form_end
1.285 albertel 1999: </td>
2000: <td class="LC_docs_entry_parameter">
1.286 albertel 2001: $form_start
1.292 albertel 2002: <label><input type="checkbox" name="encrypturl_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.286 albertel 2003: $form_end
1.285 albertel 2004: </td>
1.296 albertel 2005: <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
1.286 albertel 2006: <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
1.120 www 2007: ENDPARMS
1.119 www 2008: }
1.286 albertel 2009: $line.="</tr>";
1.8 www 2010: return $line;
2011: }
2012:
1.27 www 2013: # ---------------------------------------------------------------- tie the hash
2014:
2015: sub tiehash {
1.136 albertel 2016: my ($mode)=@_;
1.27 www 2017: $hashtied=0;
1.174 albertel 2018: if ($env{'request.course.fn'}) {
1.136 albertel 2019: if ($mode eq 'write') {
1.174 albertel 2020: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136 albertel 2021: &GDBM_WRCREAT(),0640)) {
2022: $hashtied=2;
2023: }
2024: } else {
1.174 albertel 2025: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136 albertel 2026: &GDBM_READER(),0640)) {
1.27 www 2027: $hashtied=1;
1.136 albertel 2028: }
2029: }
1.27 www 2030: }
2031: }
2032:
2033: sub untiehash {
2034: if ($hashtied) { untie %hash; }
2035: $hashtied=0;
1.221 albertel 2036: return OK;
1.27 www 2037: }
2038:
1.29 www 2039: # --------------------------------------------------------------- check on this
2040:
2041: sub checkonthis {
2042: my ($r,$url,$level,$title)=@_;
1.228 www 2043: $url=&unescape($url);
1.29 www 2044: $alreadyseen{$url}=1;
2045: $r->rflush();
1.41 www 2046: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108 albertel 2047: $r->print("\n<br />");
1.313 bisitz 2048: if ($level==0) {
2049: $r->print("<br />");
2050: }
1.29 www 2051: for (my $i=0;$i<=$level*5;$i++) {
2052: $r->print(' ');
2053: }
2054: $r->print('<a href="'.$url.'" target="cat">'.
2055: ($title?$title:$url).'</a> ');
2056: if ($url=~/^\/res\//) {
2057: my $result=&Apache::lonnet::repcopy(
2058: &Apache::lonnet::filelocation('',$url));
1.172 raeburn 2059: if ($result eq 'ok') {
1.313 bisitz 2060: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.29 www 2061: $r->rflush();
1.34 www 2062: &Apache::lonnet::countacc($url);
2063: $url=~/\.(\w+)$/;
2064: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2065: $r->print('<br />');
2066: $r->rflush();
2067: for (my $i=0;$i<=$level*5;$i++) {
2068: $r->print(' ');
2069: }
1.313 bisitz 2070: $r->print('- '.&mt('Rendering:').' ');
1.170 www 2071: my ($errorcount,$warningcount)=split(/:/,
2072: &Apache::lonnet::ssi_body($url,
1.173 albertel 2073: ('grade_target'=>'web',
2074: 'return_only_error_and_warning_counts' => 1)));
1.170 www 2075: if (($errorcount) ||
2076: ($warningcount)) {
2077: if ($errorcount) {
1.283 albertel 2078: $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.
1.313 bisitz 2079: &mt('[quant,_1,error]',$errorcount).'</span>');
1.34 www 2080: }
1.170 www 2081: if ($warningcount) {
1.283 albertel 2082: $r->print('<span class="LC_warning">'.
1.313 bisitz 2083: &mt('[quant,_1,warning]',$warningcount).'</span>');
1.34 www 2084: }
2085: } else {
1.283 albertel 2086: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.34 www 2087: }
2088: $r->rflush();
2089: }
1.29 www 2090: my $dependencies=
2091: &Apache::lonnet::metadata($url,'dependencies');
2092: foreach (split(/\,/,$dependencies)) {
2093: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
2094: &checkonthis($r,$_,$level+1);
2095: }
2096: }
1.172 raeburn 2097: } elsif ($result eq 'unavailable') {
1.283 albertel 2098: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
1.172 raeburn 2099: } elsif ($result eq 'not_found') {
1.100 www 2100: unless ($url=~/\$/) {
1.313 bisitz 2101: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
1.100 www 2102: } else {
1.283 albertel 2103: $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');
1.100 www 2104: }
1.29 www 2105: } else {
1.283 albertel 2106: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
1.29 www 2107: }
1.313 bisitz 2108: }
2109: }
1.29 www 2110: }
2111:
1.1 www 2112:
1.75 www 2113: #
1.208 albertel 2114: # ----------------------------------------------------------------- List Symbs
2115: #
2116: sub list_symbs {
1.224 albertel 2117: my ($r) = @_;
2118:
1.314.2.4! raeburn 2119: my $type = &Apache::loncommon::course_type();
1.224 albertel 2120: $r->print(&Apache::loncommon::start_page('Symb List'));
1.257 www 2121: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
1.224 albertel 2122: my $navmap = Apache::lonnavmaps::navmap->new();
1.314.2.4! raeburn 2123: if (!defined($navmap)) {
! 2124: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
! 2125: '<div class="LC_error">'.
! 2126: &mt('Unable to retrieve information about course contents').
! 2127: '</div>');
! 2128: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
! 2129: } else {
! 2130: $r->print("<pre>\n");
! 2131: foreach my $res ($navmap->retrieveResources()) {
! 2132: $r->print($res->compTitle()."\t".$res->symb()."\n");
! 2133: }
! 2134: $r->print("\n</pre>\n");
1.224 albertel 2135: }
2136: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
1.208 albertel 2137: }
2138:
2139:
2140: #
1.75 www 2141: # -------------------------------------------------------------- Verify Content
2142: #
2143: sub verifycontent {
1.224 albertel 2144: my ($r) = @_;
1.230 albertel 2145: my $type = &Apache::loncommon::course_type();
1.26 www 2146: my $loaderror=&Apache::lonnet::overloaderror($r);
2147: if ($loaderror) { return $loaderror; }
1.229 raeburn 2148: $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
1.257 www 2149: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
1.27 www 2150: $hashtied=0;
1.30 www 2151: undef %alreadyseen;
2152: %alreadyseen=();
1.27 www 2153: &tiehash();
2154: foreach (keys %hash) {
1.140 www 2155: if ($hash{$_}=~/\.(page|sequence)$/) {
1.228 www 2156: if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
1.283 albertel 2157: $r->print('<hr /><span class="LC_error">'.
1.230 albertel 2158: &mt('The following sequence or page is included more than once in your '.$type.': ').
1.283 albertel 2159: &unescape($hash{$_}).'</span><br />'.
1.140 www 2160: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2161: }
2162: }
1.228 www 2163: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
1.29 www 2164: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 2165: }
2166: }
2167: &untiehash();
1.108 albertel 2168: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2169: &mt('Return to DOCS').'</a>');
1.75 www 2170: }
2171:
1.192 www 2172:
1.75 www 2173: # -------------------------------------------------------------- Check Versions
2174:
1.192 www 2175: sub devalidateversioncache {
2176: my $src=shift;
2177: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2178: &Apache::lonnet::clutter($src));
2179: }
2180:
1.75 www 2181: sub checkversions {
1.224 albertel 2182: my ($r) = @_;
1.230 albertel 2183: my $type = &Apache::loncommon::course_type();
1.229 raeburn 2184: $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
1.257 www 2185: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
1.89 www 2186: my $header='';
2187: my $startsel='';
2188: my $monthsel='';
2189: my $weeksel='';
2190: my $daysel='';
2191: my $allsel='';
2192: my %changes=();
2193: my $starttime=0;
1.91 www 2194: my $haschanged=0;
1.92 www 2195: my %setversions=&Apache::lonnet::dump('resourceversions',
1.174 albertel 2196: $env{'course.'.$env{'request.course.id'}.'.domain'},
2197: $env{'course.'.$env{'request.course.id'}.'.num'});
1.92 www 2198:
2199: $hashtied=0;
2200: &tiehash();
2201: my %newsetversions=();
1.174 albertel 2202: if ($env{'form.setmostrecent'}) {
1.91 www 2203: $haschanged=1;
1.92 www 2204: foreach (keys %hash) {
2205: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 2206: $newsetversions{$1}='mostrecent';
1.192 www 2207: &devalidateversioncache($1);
1.92 www 2208: }
2209: }
1.174 albertel 2210: } elsif ($env{'form.setcurrent'}) {
1.91 www 2211: $haschanged=1;
1.92 www 2212: foreach (keys %hash) {
2213: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 2214: my $getvers=&Apache::lonnet::getversion($1);
2215: if ($getvers>0) {
2216: $newsetversions{$1}=$getvers;
1.192 www 2217: &devalidateversioncache($1);
1.93 www 2218: }
1.92 www 2219: }
2220: }
1.174 albertel 2221: } elsif ($env{'form.setversions'}) {
1.91 www 2222: $haschanged=1;
1.174 albertel 2223: foreach (keys %env) {
1.92 www 2224: if ($_=~/^form\.set_version_(.+)$/) {
2225: my $src=$1;
1.174 albertel 2226: if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
2227: $newsetversions{$src}=$env{$_};
1.192 www 2228: &devalidateversioncache($src);
1.92 www 2229: }
2230: }
2231: }
1.91 www 2232: }
2233: if ($haschanged) {
1.92 www 2234: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1.174 albertel 2235: $env{'course.'.$env{'request.course.id'}.'.domain'},
2236: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.272 albertel 2237: $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
1.92 www 2238: } else {
1.283 albertel 2239: $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
1.92 www 2240: }
1.136 albertel 2241: &mark_hash_old();
1.91 www 2242: }
1.136 albertel 2243: &changewarning($r,'');
1.174 albertel 2244: if ($env{'form.timerange'} eq 'all') {
1.89 www 2245: # show all documents
1.230 albertel 2246: $header=&mt('All Documents in '.$type);
1.91 www 2247: $allsel=1;
1.90 www 2248: foreach (keys %hash) {
2249: if ($_=~/^ids\_(\/res\/.+)$/) {
2250: my $src=$1;
2251: $changes{$src}=1;
2252: }
2253: }
1.89 www 2254: } else {
2255: # show documents which changed
2256: %changes=&Apache::lonnet::dump
1.174 albertel 2257: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2258: $env{'course.'.$env{'request.course.id'}.'.num'});
1.89 www 2259: my $firstkey=(keys %changes)[0];
2260: unless ($firstkey=~/^error\:/) {
1.174 albertel 2261: unless ($env{'form.timerange'}) {
2262: $env{'form.timerange'}=604800;
1.89 www 2263: }
1.174 albertel 2264: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
1.89 www 2265: .&mt('seconds');
1.174 albertel 2266: if ($env{'form.timerange'}==-1) {
1.89 www 2267: $seltext='since start of course';
2268: $startsel='selected';
1.174 albertel 2269: $env{'form.timerange'}=time;
1.89 www 2270: }
1.174 albertel 2271: $starttime=time-$env{'form.timerange'};
2272: if ($env{'form.timerange'}==2592000) {
1.89 www 2273: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2274: $monthsel='selected';
1.174 albertel 2275: } elsif ($env{'form.timerange'}==604800) {
1.89 www 2276: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2277: $weeksel='selected';
1.174 albertel 2278: } elsif ($env{'form.timerange'}==86400) {
1.89 www 2279: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2280: $daysel='selected';
2281: }
2282: $header=&mt('Content changed').' '.$seltext;
2283: } else {
2284: $header=&mt('No content modifications yet.');
2285: }
2286: }
1.92 www 2287: %setversions=&Apache::lonnet::dump('resourceversions',
1.174 albertel 2288: $env{'course.'.$env{'request.course.id'}.'.domain'},
2289: $env{'course.'.$env{'request.course.id'}.'.num'});
1.89 www 2290: my %lt=&Apache::lonlocal::texthash
1.229 raeburn 2291: ('st' => 'Version changes since start of '.$type,
1.88 www 2292: 'lm' => 'Version changes since last Month',
2293: 'lw' => 'Version changes since last Week',
2294: 'sy' => 'Version changes since Yesterday',
1.91 www 2295: 'al' => 'All Resources (possibly large output)',
1.88 www 2296: 'sd' => 'Display',
1.84 www 2297: 'fi' => 'File',
2298: 'md' => 'Modification Date',
1.87 www 2299: 'mr' => 'Most recently published Version',
1.229 raeburn 2300: 've' => 'Version used in '.$type,
2301: 'vu' => 'Set Version to be used in '.$type,
2302: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
1.91 www 2303: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2304: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84 www 2305: 'di' => 'Differences');
1.89 www 2306: $r->print(<<ENDHEADERS);
1.31 www 2307: <form action="/adm/coursedocs" method="post">
1.91 www 2308: <input type="hidden" name="versions" value="1" />
2309: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2310: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31 www 2311: <select name="timerange">
1.88 www 2312: <option value='all' $allsel>$lt{'al'}</option>
1.84 www 2313: <option value="-1" $startsel>$lt{'st'}</option>
2314: <option value="2592000" $monthsel>$lt{'lm'}</option>
2315: <option value="604800" $weeksel>$lt{'lw'}</option>
2316: <option value="86400" $daysel>$lt{'sy'}</option>
1.31 www 2317: </select>
1.91 www 2318: <input type="submit" name="display" value="$lt{'sd'}" />
1.89 www 2319: <h3>$header</h3>
1.91 www 2320: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103 matthew 2321: <table border="0">
1.31 www 2322: ENDHEADERS
1.91 www 2323: foreach (sort keys %changes) {
1.89 www 2324: if ($changes{$_}>$starttime) {
2325: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
2326: my $currentversion=&Apache::lonnet::getversion($_);
1.93 www 2327: if ($currentversion<0) {
2328: $currentversion=&mt('Could not be determined.');
2329: }
1.89 www 2330: my $linkurl=&Apache::lonnet::clutter($_);
2331: $r->print(
1.103 matthew 2332: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91 www 2333: &Apache::lonnet::gettitle($linkurl).
1.103 matthew 2334: '</b></font></td></tr>'.
2335: '<tr><td> </td>'.
2336: '<td colspan="4">'.
2337: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2338: '</a></td></tr>'.
2339: '<tr><td></td>'.
2340: '<td title="'.$lt{'md'}.'">'.
1.102 matthew 2341: &Apache::lonlocal::locallocaltime(
2342: &Apache::lonnet::metadata($root.'.'.$extension,
2343: 'lastrevisiondate')
2344: ).
1.103 matthew 2345: '</td>'.
1.284 albertel 2346: '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
1.103 matthew 2347: '<font size="+1">'.$currentversion.'</font>'.
1.284 albertel 2348: '</span></td>'.
2349: '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.
1.103 matthew 2350: '<font size="+1">');
1.87 www 2351: # Used in course
1.89 www 2352: my $usedversion=$hash{'version_'.$linkurl};
1.93 www 2353: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89 www 2354: $r->print($usedversion);
2355: } else {
2356: $r->print($currentversion);
2357: }
1.284 albertel 2358: $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
2359: '<span class="LC_nobreak">Use: ');
1.87 www 2360: # Set version
1.92 www 2361: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89 www 2362: 'set_version_'.$linkurl,
1.136 albertel 2363: ('select_form_order' =>
2364: ['',1..$currentversion,'mostrecent'],
2365: '' => '',
1.93 www 2366: 'mostrecent' => 'most recent',
1.89 www 2367: map {$_,$_} (1..$currentversion))));
1.284 albertel 2368: $r->print('</span></td></tr><tr><td></td>');
1.89 www 2369: my $lastold=1;
2370: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2371: my $url=$root.'.'.$prevvers.'.'.$extension;
2372: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2373: $starttime) {
2374: $lastold=$prevvers;
2375: }
2376: }
1.103 matthew 2377: #
2378: # Code to figure out how many version entries should go in
2379: # each of the four columns
2380: my $entries_per_col = 0;
2381: my $num_entries = ($currentversion-$lastold);
2382: if ($num_entries % 4 == 0) {
2383: $entries_per_col = $num_entries/4;
2384: } else {
2385: $entries_per_col = $num_entries/4 + 1;
2386: }
2387: my $entries_count = 0;
2388: $r->print('<td valign="top"><font size="-2">');
2389: my $cols_output = 1;
1.32 www 2390: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89 www 2391: my $url=$root.'.'.$prevvers.'.'.$extension;
1.284 albertel 2392: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
1.91 www 2393: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103 matthew 2394: &Apache::lonlocal::locallocaltime(
2395: &Apache::lonnet::metadata($url,
2396: 'lastrevisiondate')
2397: ).
1.91 www 2398: ')');
1.89 www 2399: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33 www 2400: $r->print(' <a href="/adm/diff?filename='.
1.89 www 2401: &Apache::lonnet::clutter($root.'.'.$extension).
2402: '&versionone='.$prevvers.
2403: '">'.&mt('Diffs').'</a>');
2404: }
1.284 albertel 2405: $r->print('</span><br />');
1.103 matthew 2406: if (++$entries_count % $entries_per_col == 0) {
2407: $r->print('</font></td>');
2408: if ($cols_output != 4) {
2409: $r->print('<td valign="top"><font size="-2">');
2410: $cols_output++;
2411: }
2412: }
1.89 www 2413: }
1.103 matthew 2414: while($cols_output++ < 4) {
2415: $r->print('</font></td><td><font>')
2416: }
2417: $r->print('</font></td></tr>'."\n");
1.89 www 2418: }
2419: }
1.92 www 2420: $r->print('</table></form>');
1.89 www 2421: $r->print('<h1>'.&mt('Done').'.</h1>');
2422:
2423: &untiehash();
1.75 www 2424: }
2425:
1.136 albertel 2426: sub mark_hash_old {
2427: my $retie_hash=0;
2428: if ($hashtied) {
2429: $retie_hash=1;
2430: &untiehash();
2431: }
2432: &tiehash('write');
2433: $hash{'old'}=1;
2434: &untiehash();
2435: if ($retie_hash) { &tiehash(); }
2436: }
2437:
2438: sub is_hash_old {
2439: my $untie_hash=0;
2440: if (!$hashtied) {
2441: $untie_hash=1;
2442: &tiehash();
2443: }
2444: my $return=$hash{'old'};
2445: if ($untie_hash) { &untiehash(); }
2446: return $return;
2447: }
2448:
1.91 www 2449: sub changewarning {
1.177 albertel 2450: my ($r,$postexec,$message,$url)=@_;
1.136 albertel 2451: if (!&is_hash_old()) { return; }
1.150 albertel 2452: my $pathvar='folderpath';
1.228 www 2453: my $path=&escape($env{'form.folderpath'});
1.177 albertel 2454: if (!defined($url)) {
2455: if (defined($env{'form.pagepath'})) {
2456: $pathvar='pagepath';
1.228 www 2457: $path=&escape($env{'form.pagepath'});
2458: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
1.177 albertel 2459: }
2460: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2461: }
1.230 albertel 2462: my $course_type = &Apache::loncommon::course_type();
1.177 albertel 2463: if (!defined($message)) {
2464: $message='Changes will become active for your current session after [_1], or the next time you log in.';
1.150 albertel 2465: }
1.185 www 2466: $r->print("\n\n".
1.286 albertel 2467: '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
1.185 www 2468: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.177 albertel 2469: '<input type="hidden" name="orgurl" value="'.$url.
1.283 albertel 2470: '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.
1.177 albertel 2471: &mt($message,' <input type="hidden" name="'.
2472: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.230 albertel 2473: &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
1.283 albertel 2474: $help{'Caching'}.'</span></h3></form>'."\n\n");
1.91 www 2475: }
2476:
1.257 www 2477: # =========================================== Breadcrumbs for special functions
2478:
2479: sub init_breadcrumbs {
2480: my ($form,$text)=@_;
2481: &Apache::lonhtmlcommon::clear_breadcrumbs();
2482: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
1.297 albertel 2483: text=>"Edit ".&Apache::loncommon::course_type(),
1.257 www 2484: faq=>273,
2485: bug=>'Instructor Interface',
2486: help => 'Docs_Adding_Course_Doc'});
2487: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2488: text=>$text,
2489: faq=>273,
2490: bug=>'Instructor Interface'});
2491: }
2492:
1.75 www 2493: # ================================================================ Main Handler
2494: sub handler {
2495: my $r = shift;
1.82 www 2496: &Apache::loncommon::content_type($r,'text/html');
1.75 www 2497: $r->send_http_header;
2498: return OK if $r->header_only;
1.230 albertel 2499: my $type = &Apache::loncommon::course_type();
1.75 www 2500:
2501: # --------------------------------------------- Initialize help topics for this
1.209 albertel 2502: foreach ('Adding_Course_Doc','Main_Course_Documents',
2503: 'Adding_External_Resource','Navigate_Content',
2504: 'Adding_Folders','Docs_Overview', 'Load_Map',
2505: 'Supplemental','Score_Upload_Form','Adding_Pages',
2506: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2507: 'Check_Resource_Versions','Verify_Content') {
2508: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
2509: }
1.75 www 2510: # Composite help files
2511: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2512: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2513: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2514: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86 albertel 2515: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2516: 'Option_Response_Simple');
1.75 www 2517: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2518: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2519: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
2520: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.255 raeburn 2521: $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.75 www 2522: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142 raeburn 2523:
1.209 albertel 2524: # does this user have privileges to modify docs
2525: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2526: if ($allowed && $env{'form.verify'}) {
1.257 www 2527: &init_breadcrumbs('verify','Verify Content');
1.75 www 2528: &verifycontent($r);
1.209 albertel 2529: } elsif ($allowed && $env{'form.listsymbs'}) {
1.257 www 2530: &init_breadcrumbs('listsymbs','List Symbs');
1.208 albertel 2531: &list_symbs($r);
1.247 www 2532: } elsif ($allowed && $env{'form.docslog'}) {
1.257 www 2533: &init_breadcrumbs('docslog','Show Log');
1.247 www 2534: &docs_change_log($r);
1.209 albertel 2535: } elsif ($allowed && $env{'form.versions'}) {
1.257 www 2536: &init_breadcrumbs('versions','Check/Set Resource Versions');
1.75 www 2537: &checkversions($r);
1.209 albertel 2538: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.257 www 2539: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
1.75 www 2540: &dumpcourse($r);
1.209 albertel 2541: } elsif ($allowed && $env{'form.exportcourse'}) {
1.257 www 2542: &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
1.138 raeburn 2543: &exportcourse($r);
1.26 www 2544: } else {
1.7 www 2545: # is this a standard course?
2546:
1.174 albertel 2547: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.155 raeburn 2548: my $forcestandard = 0;
1.15 www 2549: my $forcesupplement;
2550: my $script='';
1.19 www 2551: my $showdoc=0;
1.142 raeburn 2552: my $containertag;
2553: my $uploadtag;
1.15 www 2554: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.224 albertel 2555: ['folderpath','pagepath',
1.281 albertel 2556: 'pagesymb']);
1.307 www 2557: # No folderpath, no pagepath, see if we have something stored
2558: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2559: &Apache::loncommon::restore_course_settings('docs_folderpath',
2560: {'folderpath' => 'scalar'});
2561: }
2562: if (!$env{'form.folderpath'}) {
2563: &Apache::loncommon::restore_course_settings('docs_folderpath',
2564: {'pagepath' => 'scalar'});
2565: }
2566: if ($env{'form.pagepath'}) {
2567: $env{'form.folderpath'}='';
2568: }
1.309 raeburn 2569: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2570: $env{'form.folderpath'} = 'supplemental&'.
2571: &escape(&mt('Supplemental '.$type.' Documents')).'&'.
2572: $env{'form.folderpath'};
2573: }
1.307 www 2574: &Apache::loncommon::store_course_settings('docs_folderpath',
2575: {'pagepath' => 'scalar',
2576: 'folderpath' => 'scalar'});
1.174 albertel 2577: if ($env{'form.folderpath'}) {
2578: my (@folderpath)=split('&',$env{'form.folderpath'});
1.228 www 2579: $env{'form.foldername'}=&unescape(pop(@folderpath));
1.174 albertel 2580: $env{'form.folder'}=pop(@folderpath);
2581: }
2582: if ($env{'form.pagepath'}) {
2583: my (@pagepath)=split('&',$env{'form.pagepath'});
1.228 www 2584: $env{'form.pagename'}=&unescape(pop(@pagepath));
1.174 albertel 2585: $env{'form.folder'}=pop(@pagepath);
1.156 albertel 2586: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2587: '<input type="hidden" name="pagesymb" value="" />';
1.282 albertel 2588: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2589: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
1.142 raeburn 2590: }
1.21 www 2591: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127 albertel 2592: $showdoc='/'.$1;
1.21 www 2593: }
2594: unless ($showdoc) { # got called from remote
1.237 albertel 2595: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
1.209 albertel 2596: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
1.155 raeburn 2597: $forcestandard = 1;
2598: }
1.174 albertel 2599: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
1.7 www 2600:
1.15 www 2601: if ($allowed) {
2602: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2603: $script=&Apache::lonratedt::editscript('simple');
2604: }
2605: } else { # got called in sequence from course
2606: $allowed=0;
1.3 www 2607: }
1.4 www 2608:
2609: # get course data
1.174 albertel 2610: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2611: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.4 www 2612:
1.225 albertel 2613: # get personal data
1.174 albertel 2614: my $uname=$env{'user.name'};
2615: my $udom=$env{'user.domain'};
1.245 albertel 2616: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
1.14 www 2617:
1.8 www 2618: # graphics settings
1.4 www 2619:
1.176 albertel 2620: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
1.8 www 2621:
1.224 albertel 2622: if ($allowed) {
2623: $script .= &editing_js($udom,$uname);
1.171 www 2624: }
1.42 www 2625: # -------------------------------------------------------------------- Body tag
1.224 albertel 2626: $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
1.229 raeburn 2627: $r->print(&Apache::loncommon::start_page("$type Documents", $script,
1.225 albertel 2628: {'force_register' => $showdoc,}).
1.233 albertel 2629: &Apache::loncommon::help_open_menu('','',273,'RAT'));
1.224 albertel 2630:
1.188 raeburn 2631: my %allfiles = ();
2632: my %codebase = ();
2633: my ($upload_result,$upload_output);
2634: if ($allowed) {
1.264 albertel 2635: if (($env{'form.uploaddoc.filename'}) &&
2636: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.188 raeburn 2637: # Process file upload - phase one - upload and parse primary file.
1.298 albertel 2638: undef($hadchanges);
1.190 albertel 2639: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2640: $coursedom,\%allfiles,
1.194 raeburn 2641: \%codebase,$1);
1.298 albertel 2642: if ($hadchanges) {
2643: &mark_hash_old();
2644: }
1.188 raeburn 2645: if ($upload_result eq 'phasetwo') {
2646: $r->print($upload_output);
2647: }
2648: } elsif ($env{'form.phasetwo'}) {
2649: my %newname = ();
2650: my %origname = ();
2651: my %attribs = ();
2652: my $updateflag = 0;
2653: my $residx = $env{'form.newidx'};
1.228 www 2654: my $primary_url = &unescape($env{'form.primaryurl'});
1.188 raeburn 2655: # Process file upload - phase two - gather secondary files.
2656: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2657: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2658: my $javacodebase;
2659: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
1.228 www 2660: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
1.188 raeburn 2661: if (exists($env{'form.embedded_codebase_'.$i})) {
1.228 www 2662: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
1.188 raeburn 2663: $origname{$i} =~ s#^\Q$javacodebase\E/##;
2664: }
2665: my @attributes = ();
2666: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2667: @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
2668: } else {
2669: @attributes = ($env{'form.embedded_attrib_'.$i});
2670: }
2671: foreach (@attributes) {
1.228 www 2672: push(@{$attribs{$i}},&unescape($_));
1.188 raeburn 2673: }
2674: if ($javacodebase) {
2675: $codebase{$i} = $javacodebase;
2676: $codebase{$i} =~ s#/$##;
2677: $updateflag = 1;
2678: }
2679: }
2680: unless ($newname{$i} eq $origname{$i}) {
2681: $updateflag = 1;
2682: }
2683: }
2684: # Process file upload - phase three - modify primary file
2685: if ($updateflag) {
2686: my ($content,$rtncode);
2687: my $updateflag = 0;
2688: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2689: if ($getstatus eq 'ok') {
2690: foreach my $item (keys %newname) {
2691: if ($newname{$item} ne $origname{$item}) {
2692: my $attrib_regexp = '';
2693: if (@{$attribs{$item}} > 1) {
2694: $attrib_regexp = join('|',@{$attribs{$item}});
2695: } else {
2696: $attrib_regexp = $attribs{$item}[0];
2697: }
2698: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
2699: }
2700: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
2701: }
2702: if (exists($codebase{$item})) {
1.224 albertel 2703: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
1.188 raeburn 2704: }
2705: }
2706: # Save edited file.
2707: my $saveresult;
2708: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2709: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.191 raeburn 2710: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
1.188 raeburn 2711: } else {
2712: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
2713: }
2714: }
2715: }
2716: }
2717:
2718: unless ($showdoc || $upload_result eq 'phasetwo') {
1.81 www 2719: # -----------------------------------------------------------------------------
2720: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 2721: 'uplm' => 'Upload a new main '.lc($type).' document',
2722: 'upls' => 'Upload a new supplemental '.lc($type).' document',
1.168 www 2723: 'impp' => 'Import a document',
2724: 'pubd' => 'Published documents',
1.181 www 2725: 'copm' => 'All documents out of a published map into this folder',
1.81 www 2726: 'spec' => 'Special documents',
2727: 'upld' => 'Upload Document',
2728: 'srch' => 'Search',
2729: 'impo' => 'Import',
1.232 www 2730: 'book' => 'Import Bookmarks',
1.81 www 2731: 'selm' => 'Select Map',
2732: 'load' => 'Load Map',
1.186 www 2733: 'reco' => 'Recover Deleted Resources',
1.81 www 2734: 'newf' => 'New Folder',
1.142 raeburn 2735: 'newp' => 'New Composite Page',
1.81 www 2736: 'extr' => 'External Resource',
2737: 'syll' => 'Syllabus',
2738: 'navc' => 'Navigate Contents',
2739: 'sipa' => 'Simple Page',
2740: 'sipr' => 'Simple Problem',
1.219 www 2741: 'drbx' => 'Drop Box',
1.81 www 2742: 'scuf' => 'Score Upload Form',
2743: 'bull' => 'Bulletin Board',
1.96 sakharuk 2744: 'mypi' => 'My Personal Info',
1.255 raeburn 2745: 'grpo' => 'Group Files',
1.294 raeburn 2746: 'rost' => 'Course Roster',
1.101 www 2747: 'abou' => 'About User',
1.110 raeburn 2748: 'imsf' => 'Import IMS package',
1.96 sakharuk 2749: 'file' => 'File',
2750: 'title' => 'Title',
1.188 raeburn 2751: 'comment' => 'Comment',
2752: 'parse' => 'If HTML file, upload embedded images/multimedia files'
1.81 www 2753: );
2754: # -----------------------------------------------------------------------------
1.42 www 2755: if ($allowed) {
1.281 albertel 2756: &update_paste_buffer($coursenum,$coursedom);
1.74 www 2757: my $dumpbut=&dumpbutton();
1.138 raeburn 2758: my $exportbut=&exportbutton();
1.88 www 2759: my %lt=&Apache::lonlocal::texthash(
2760: 'vc' => 'Verify Content',
2761: 'cv' => 'Check/Set Resource Versions',
1.208 albertel 2762: 'ls' => 'List Symbs',
1.247 www 2763: 'sl' => 'Show Log'
1.88 www 2764: );
1.118 albertel 2765:
1.174 albertel 2766: my $folderpath=$env{'form.folderpath'};
1.118 albertel 2767: if (!$folderpath) {
1.174 albertel 2768: if ($env{'form.folder'} eq '' ||
2769: $env{'form.folder'} eq 'supplemental') {
1.118 albertel 2770: $folderpath='default&'.
1.230 albertel 2771: &escape(&mt('Main '.$type.' Documents'));
1.118 albertel 2772: }
2773: }
1.174 albertel 2774: unless ($env{'form.pagepath'}) {
1.142 raeburn 2775: $containertag = '<input type="hidden" name="folderpath" value="" />';
1.282 albertel 2776: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.142 raeburn 2777: }
2778:
1.42 www 2779: $r->print(<<ENDCOURSEVERIFY);
1.36 www 2780: <form name="renameform" method="post" action="/adm/coursedocs">
1.283 albertel 2781: <input type="hidden" name="title" />
2782: <input type="hidden" name="cmd" />
2783: <input type="hidden" name="markcopy" />
2784: <input type="hidden" name="copyfolder" />
2785: $containertag
1.36 www 2786: </form>
1.39 www 2787: <form name="simpleedit" method="post" action="/adm/coursedocs">
1.283 albertel 2788: <input type="hidden" name="importdetail" value="" />
2789: $uploadtag
1.39 www 2790: </form>
1.26 www 2791: <form action="/adm/coursedocs" method="post" name="courseverify">
1.283 albertel 2792: <div class="LC_docs_course_commands">
2793:
2794: <div>
2795: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
2796: </div>
2797: <div>
2798: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
2799: </div>
2800: $dumpbut
2801: $exportbut
2802: <div>
2803: <input type="submit" name="listsymbs" value="$lt{'ls'}" />
2804: </div>
2805: <div>
2806: <input type="hidden" name="folder" value="$env{'form.folder'}" />
2807: <input type="submit" name="docslog" value="$lt{'sl'}" />
2808: </div>
2809: </div>
1.25 www 2810: </form>
1.283 albertel 2811: <div style="clear: both; height: 0px;"> </div>
1.25 www 2812: ENDCOURSEVERIFY
1.74 www 2813: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.230 albertel 2814: &mt('Editing the Table of Contents for your '.$type)));
1.25 www 2815: }
1.17 www 2816: # --------------------------------------------------------- Standard documents
1.293 albertel 2817: $r->print('<table class="LC_docs_documents">');
2818:
1.7 www 2819: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.285 albertel 2820: $r->print('<tr><td class="LC_docs_document">');
1.116 albertel 2821: # '<h2>'.&mt('Main Course Documents').
2822: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.174 albertel 2823: my $folder=$env{'form.folder'};
1.117 albertel 2824: if ($folder eq '' || $folder eq 'supplemental') {
1.112 raeburn 2825: $folder='default';
1.230 albertel 2826: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
1.293 albertel 2827: $uploadtag = '<input type="hidden" name="folderpath" value="'.
2828: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.112 raeburn 2829: }
1.51 www 2830: my $postexec='';
2831: if ($folder eq 'default') {
1.286 albertel 2832: $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');
1.51 www 2833: } else {
1.117 albertel 2834: #$postexec='self.close();';
1.51 www 2835: }
1.40 www 2836: $hadchanges=0;
1.292 albertel 2837: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,
1.309 raeburn 2838: $upload_output,$type);
1.292 albertel 2839: if ($error) {
2840: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
2841: }
1.40 www 2842: if ($hadchanges) {
1.136 albertel 2843: &mark_hash_old()
1.40 www 2844: }
1.136 albertel 2845: &changewarning($r,$postexec);
1.16 www 2846: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2847: '.sequence';
1.142 raeburn 2848: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2849: '.page';
1.186 www 2850: my $container='sequence';
2851: if ($env{'form.pagepath'}) {
2852: $container='page';
2853: }
2854: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
1.8 www 2855: $r->print(<<ENDFORM);
1.285 albertel 2856: <table class="LC_docs_adddocs">
2857: <tr>
2858: <th>$lt{'uplm'}</th>
2859: <th>$lt{'impp'}</th>
2860: <th>$lt{'spec'}</th>
1.11 www 2861: </tr>
1.285 albertel 2862: <tr>
2863: <td>
1.96 sakharuk 2864: $lt{'file'}:<br />
1.182 albertel 2865: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.286 albertel 2866: <input type="file" name="uploaddoc" size="40" />
1.8 www 2867: <br />
1.96 sakharuk 2868: $lt{'title'}:<br />
1.286 albertel 2869: <input type="text" size="50" name="comment" />
1.142 raeburn 2870: $uploadtag
1.286 albertel 2871: <input type="hidden" name="cmd" value="upload_default" />
1.188 raeburn 2872: <br />
1.284 albertel 2873: <span class="LC_nobreak">
1.190 albertel 2874: <label>$lt{'parse'}?
1.306 www 2875: <input type="checkbox" name="parserflag" checked="checked" />
1.190 albertel 2876: </label>
1.284 albertel 2877: </span>
1.188 raeburn 2878: <br />
2879: <br />
1.284 albertel 2880: <span class="LC_nobreak">
1.286 albertel 2881: <input type="submit" value="$lt{'upld'}" />
1.60 albertel 2882: $help{'Uploading_From_Harddrive'}
1.284 albertel 2883: </span>
1.60 albertel 2884: </form>
1.11 www 2885: </td>
1.285 albertel 2886: <td>
1.39 www 2887: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.168 www 2888: $lt{'pubd'}<br />
1.142 raeburn 2889: $uploadtag
1.286 albertel 2890: <input type="button" onClick="javascript:groupsearch()" value="$lt{'srch'}" />
1.232 www 2891: <br />
1.284 albertel 2892: <span class="LC_nobreak">
1.286 albertel 2893: <input type="button" onClick="javascript:groupimport();" value="$lt{'impo'}" />
1.58 albertel 2894: $help{'Importing_LON-CAPA_Resource'}
1.284 albertel 2895: </span>
1.232 www 2896: <br />
1.286 albertel 2897: <input type="button" onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
2898: <hr />
1.59 www 2899: <p>
1.181 www 2900: $lt{'copm'}<br />
1.282 albertel 2901: <input type="text" size="40" name="importmap" /><br />
1.286 albertel 2902: <span class="LC_nobreak"><input type="button"
1.52 www 2903: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.282 albertel 2904: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
1.284 albertel 2905: $help{'Load_Map'}</span>
1.59 www 2906: </p>
1.52 www 2907: </form>
1.186 www 2908: <hr />
2909: <form action="/adm/groupsort" method="post" name="recover">
1.232 www 2910: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
1.186 www 2911: </form>
1.142 raeburn 2912: ENDFORM
1.174 albertel 2913: unless ($env{'form.pagepath'}) {
1.168 www 2914: $r->print(<<ENDFORM);
2915: <hr />
2916: <form action="/adm/coursedocs" method="post" name="newext">
2917: $uploadtag
1.256 albertel 2918: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2919: <span class="LC_nobreak">
1.168 www 2920: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2921: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.284 albertel 2922: </span>
1.168 www 2923: </form>
1.214 www 2924: <br /><form action="/adm/imsimportdocs" method="post" name="ims">
1.168 www 2925: <input type="hidden" name="folder" value="$folder" />
2926: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2927: </form>
2928: ENDFORM
2929: }
1.285 albertel 2930: $r->print('</td><td>');
1.174 albertel 2931: unless ($env{'form.pagepath'}) {
1.282 albertel 2932: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.142 raeburn 2933: $r->print(<<ENDFORM);
1.214 www 2934: <br /><form action="/adm/coursedocs" method="post" name="newfolder">
1.282 albertel 2935: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 2936: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2937: <span class="LC_nobreak">
1.16 www 2938: <input name="newfolder" type="button"
2939: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2940: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.284 albertel 2941: </span>
1.11 www 2942: </form>
1.214 www 2943: <br /><form action="/adm/coursedocs" method="post" name="newpage">
1.282 albertel 2944: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 2945: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2946: <span class="LC_nobreak">
1.142 raeburn 2947: <input name="newpage" type="button"
2948: onClick="javascript:makenewpage(this.form,'$pageseq');"
2949: value="$lt{'newp'}" />$help{'Adding_Pages'}
1.284 albertel 2950: </span>
1.142 raeburn 2951: </form>
1.214 www 2952: <br /><form action="/adm/coursedocs" method="post" name="newsyl">
1.142 raeburn 2953: $uploadtag
1.256 albertel 2954: <input type="hidden" name="importdetail"
1.305 bisitz 2955: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.284 albertel 2956: <span class="LC_nobreak">
1.81 www 2957: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2958: $help{'Syllabus'}
1.284 albertel 2959: </span>
1.58 albertel 2960: </form>
1.214 www 2961: <br /><form action="/adm/coursedocs" method="post" name="newnav">
1.142 raeburn 2962: $uploadtag
1.256 albertel 2963: <input type="hidden" name="importdetail"
1.305 bisitz 2964: value="$lt{'navc'}=/adm/navmaps" />
1.284 albertel 2965: <span class="LC_nobreak">
1.81 www 2966: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47 www 2967: $help{'Navigate_Content'}
1.284 albertel 2968: </span>
1.22 www 2969: </form>
1.214 www 2970: <br /><form action="/adm/coursedocs" method="post" name="newsmppg">
1.142 raeburn 2971: $uploadtag
1.256 albertel 2972: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2973: <span class="LC_nobreak">
1.81 www 2974: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65 bowersj2 2975: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.284 albertel 2976: </span>
1.55 www 2977: </form>
1.214 www 2978: <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142 raeburn 2979: $uploadtag
1.256 albertel 2980: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2981: <span class="LC_nobreak">
1.81 www 2982: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65 bowersj2 2983: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.284 albertel 2984: </span>
1.62 www 2985: </form>
1.219 www 2986: <br /><form action="/adm/coursedocs" method="post" name="newdropbox">
2987: $uploadtag
1.256 albertel 2988: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2989: <span class="LC_nobreak">
1.219 www 2990: <input name="newdropbox" type="button" value="$lt{'drbx'}"
2991: onClick="javascript:makedropbox();" />
1.284 albertel 2992: </span>
1.219 www 2993: </form>
1.214 www 2994: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 2995: $uploadtag
1.256 albertel 2996: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2997: <span class="LC_nobreak">
1.81 www 2998: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62 www 2999: onClick="javascript:makeexamupload();" />
1.66 bowersj2 3000: $help{'Score_Upload_Form'}
1.284 albertel 3001: </span>
1.22 www 3002: </form>
1.214 www 3003: <br /><form action="/adm/coursedocs" method="post" name="newbul">
1.142 raeburn 3004: $uploadtag
1.256 albertel 3005: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3006: <span class="LC_nobreak">
1.81 www 3007: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22 www 3008: onClick="javascript:makebulboard();" />
1.65 bowersj2 3009: $help{'Bulletin Board'}
1.284 albertel 3010: </span>
1.58 albertel 3011: </form>
1.214 www 3012: <br /><form action="/adm/coursedocs" method="post" name="newaboutme">
1.142 raeburn 3013: $uploadtag
1.256 albertel 3014: <input type="hidden" name="importdetail"
3015: value="$plainname=/adm/$udom/$uname/aboutme" />
1.284 albertel 3016: <span class="LC_nobreak">
1.81 www 3017: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 3018: $help{'My Personal Info'}
1.284 albertel 3019: </span>
1.101 www 3020: </form>
1.214 www 3021: <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142 raeburn 3022: $uploadtag
1.256 albertel 3023: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3024: <span class="LC_nobreak">
1.101 www 3025: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
3026: onClick="javascript:makeabout();" />
1.284 albertel 3027: </span>
1.182 albertel 3028: </form>
1.255 raeburn 3029: <br /><form action="/adm/coursedocs" method="post" name="newgroupfiles">
3030: $uploadtag
1.256 albertel 3031: <input type="hidden" name="importdetail"
1.305 bisitz 3032: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.284 albertel 3033: <span class="LC_nobreak">
1.255 raeburn 3034: <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
3035: $help{'Group Files'}
1.284 albertel 3036: </span>
1.255 raeburn 3037: </form>
1.294 raeburn 3038: <br /><form action="/adm/coursedocs" method="post" name="newroster">
3039: $uploadtag
3040: <input type="hidden" name="importdetail"
1.305 bisitz 3041: value="$lt{'rost'}=/adm/viewclasslist" />
1.294 raeburn 3042: <span class="LC_nobreak">
3043: <input name="newroster" type="submit" value="$lt{'rost'}" />
3044: $help{'Course Roster'}
3045: </span>
3046: </form>
1.142 raeburn 3047: ENDFORM
3048: }
1.174 albertel 3049: if ($env{'form.pagepath'}) {
1.142 raeburn 3050: $r->print(<<ENDBLOCK);
3051: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
3052: $uploadtag
1.256 albertel 3053: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3054: <span class="LC_nobreak">
1.142 raeburn 3055: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
3056: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.284 albertel 3057: </span>
1.142 raeburn 3058: </form>
1.214 www 3059: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 3060: $uploadtag
1.256 albertel 3061: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3062: <span class="LC_nobreak">
1.142 raeburn 3063: <input name="newexamupload" type="button" value="$lt{'scuf'}"
3064: onClick="javascript:makeexamupload();" />
3065: $help{'Score_Upload_Form'}
1.284 albertel 3066: </span>
1.182 albertel 3067: </form>
1.142 raeburn 3068: ENDBLOCK
3069: }
3070: $r->print('</td></tr>'."\n".
3071: '</table>');
1.24 www 3072: $r->print('</td></tr>');
1.7 www 3073: }
3074: # ----------------------------------------------------- Supplemental documents
3075: if (!$forcestandard) {
1.285 albertel 3076: $r->print('<tr><td class="LC_docs_document">');
1.116 albertel 3077: # '<h2>'.&mt('Supplemental Course Documents').
3078: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.174 albertel 3079: my $folder=$env{'form.folder'};
1.117 albertel 3080: unless ($folder=~/^supplemental/) {
1.116 albertel 3081: $folder='supplemental';
1.117 albertel 3082: }
3083: if ($folder =~ /^supplemental$/ &&
1.309 raeburn 3084: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3085: $env{'form.folderpath'} = 'supplemental&'.
3086: &escape(&mt('Supplemental '.$type.' Documents'));
1.116 albertel 3087: }
1.309 raeburn 3088: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
1.292 albertel 3089: if ($error) {
3090: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3091: }
1.8 www 3092: if ($allowed) {
1.282 albertel 3093: my $folderseq=
3094: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3095: '.sequence';
1.17 www 3096:
1.282 albertel 3097: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3098: $r->print(<<ENDSUPFORM);
1.285 albertel 3099: <table class="LC_docs_adddocs"><tr>
3100: <th>$lt{'upls'}</th>
3101: <th>$lt{'spec'}</th>
1.17 www 3102: </tr>
1.285 albertel 3103: <tr><td>
1.10 www 3104: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.286 albertel 3105: <input type="file" name="uploaddoc" size="40" />
1.196 raeburn 3106: <br />
3107: <br />
1.284 albertel 3108: <span class="LC_nobreak">
1.196 raeburn 3109: <label>$lt{'parse'}?
3110: <input type="checkbox" name="parserflag" />
3111: </label>
1.284 albertel 3112: </span>
1.196 raeburn 3113: <br /><br />
3114: $lt{'comment'}:<br />
1.4 www 3115: <textarea cols=50 rows=4 name='comment'>
3116: </textarea>
1.115 albertel 3117: <br />
1.282 albertel 3118: <input type="hidden" name="folderpath" value="$path" />
1.286 albertel 3119: <input type="hidden" name="cmd" value="upload_supplemental" />
1.284 albertel 3120: <span class="LC_nobreak">
1.286 albertel 3121: <input type="submit" value="$lt{'upld'}" />
1.58 albertel 3122: $help{'Uploading_From_Harddrive'}
1.284 albertel 3123: </span>
1.58 albertel 3124: </form>
1.17 www 3125: </td>
1.285 albertel 3126: <td>
1.18 www 3127: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.282 albertel 3128: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3129: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3130: <span class="LC_nobreak">
1.17 www 3131: <input name="newfolder" type="button"
3132: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 3133: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.284 albertel 3134: </span>
1.17 www 3135: </form>
1.214 www 3136: <br /><form action="/adm/coursedocs" method="post" name="supnewext">
1.282 albertel 3137: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3138: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3139: <span class="LC_nobreak">
1.18 www 3140: <input name="newext" type="button"
3141: onClick="javascript:makenewext('supnewext');"
1.81 www 3142: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.284 albertel 3143: </span>
1.17 www 3144: </form>
1.214 www 3145: <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">
1.282 albertel 3146: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3147: <input type="hidden" name="importdetail"
3148: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.284 albertel 3149: <span class="LC_nobreak">
1.81 www 3150: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 3151: $help{'Syllabus'}
1.284 albertel 3152: </span>
1.58 albertel 3153: </form>
1.214 www 3154: <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.282 albertel 3155: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3156: <input type="hidden" name="importdetail"
3157: value="$plainname=/adm/$udom/$uname/aboutme" />
1.284 albertel 3158: <span class="LC_nobreak">
1.81 www 3159: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 3160: $help{'My Personal Info'}
1.284 albertel 3161: </span>
1.58 albertel 3162: </form>
1.17 www 3163: </td></tr>
1.24 www 3164: </table></td></tr>
1.8 www 3165: ENDSUPFORM
3166: }
1.7 www 3167: }
1.286 albertel 3168: $r->print('</table>');
1.18 www 3169: if ($allowed) {
1.287 albertel 3170: $r->print('
3171: <form method="post" name="extimport" action="/adm/coursedocs">
3172: <input type="hidden" name="title" />
3173: <input type="hidden" name="url" />
3174: <input type="hidden" name="useform" />
3175: <input type="hidden" name="residx" />
3176: </form>');
1.18 www 3177: }
1.19 www 3178: } else {
1.188 raeburn 3179: unless ($upload_result eq 'phasetwo') {
1.19 www 3180: # -------------------------------------------------------- This is showdoc mode
1.188 raeburn 3181: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.141 albertel 3182: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.286 albertel 3183: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3184: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.188 raeburn 3185: }
1.19 www 3186: }
1.26 www 3187: }
1.224 albertel 3188: $r->print(&Apache::loncommon::end_page());
1.26 www 3189: return OK;
1.1 www 3190: }
3191:
1.224 albertel 3192:
3193: sub editing_js {
3194: my ($udom,$uname) = @_;
3195: my $now = time();
1.302 bisitz 3196: my %lt = &Apache::lonlocal::texthash(
3197: p_mnf => 'Name of New Folder',
3198: t_mnf => 'New Folder',
3199: p_mnp => 'Name of New Page',
3200: t_mnp => 'New Page',
1.305 bisitz 3201: p_mxu => 'Title for the Uploaded Score',
3202: p_msp => 'Title for the Page',
3203: p_msb => 'Title for the Problem',
3204: p_mdb => 'Title for the Drop Box',
3205: p_mbb => 'Title for the Bulletin Board',
1.302 bisitz 3206: p_mab => "Enter user:domain for User's 'About Me' Page",
3207: p_mab2 => "About [_99]",
3208: p_mab_alrt1 => 'Not a valid user:domain',
3209: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3210: p_chn => 'New Title',
3211: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3212: p_rmr2a => 'Remove[_99]',
3213: p_rmr2b => '?[_99]',
1.303 raeburn 3214: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3215: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.302 bisitz 3216: p_ctr2a => 'Cut[_98]',
3217: p_ctr2b => '?[_98]'
3218: );
1.224 albertel 3219:
3220: return <<ENDNEWSCRIPT;
3221: function makenewfolder(targetform,folderseq) {
1.302 bisitz 3222: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
1.224 albertel 3223: if (foldername) {
1.236 albertel 3224: targetform.importdetail.value=escape(foldername)+"="+folderseq;
1.224 albertel 3225: targetform.submit();
3226: }
3227: }
3228:
3229: function makenewpage(targetform,folderseq) {
1.302 bisitz 3230: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
1.224 albertel 3231: if (pagename) {
1.236 albertel 3232: targetform.importdetail.value=escape(pagename)+"="+folderseq;
1.224 albertel 3233: targetform.submit();
3234: }
3235: }
3236:
3237: function makenewext(targetname) {
3238: this.document.forms.extimport.useform.value=targetname;
1.287 albertel 3239: this.document.forms.extimport.title.value='';
3240: this.document.forms.extimport.url.value='';
3241: this.document.forms.extimport.residx.value='';
3242: window.open('/adm/rat/extpickframe.html');
3243: }
3244:
3245: function edittext(targetname,residx,title,url) {
3246: this.document.forms.extimport.useform.value=targetname;
3247: this.document.forms.extimport.residx.value=residx;
3248: this.document.forms.extimport.url.value=url;
3249: this.document.forms.extimport.title.value=title;
1.224 albertel 3250: window.open('/adm/rat/extpickframe.html');
3251: }
3252:
3253: function makeexamupload() {
1.302 bisitz 3254: var title=prompt('$lt{"p_mxu"}');
1.224 albertel 3255: if (title) {
3256: this.document.forms.newexamupload.importdetail.value=
1.236 albertel 3257: escape(title)+'=/res/lib/templates/examupload.problem';
1.224 albertel 3258: this.document.forms.newexamupload.submit();
3259: }
3260: }
3261:
3262: function makesmppage() {
1.302 bisitz 3263: var title=prompt('$lt{"p_msp"}');
1.224 albertel 3264: if (title) {
3265: this.document.forms.newsmppg.importdetail.value=
1.236 albertel 3266: escape(title)+'=/adm/$udom/$uname/$now/smppg';
1.224 albertel 3267: this.document.forms.newsmppg.submit();
3268: }
3269: }
3270:
3271: function makesmpproblem() {
1.302 bisitz 3272: var title=prompt('$lt{"p_msb"}');
1.224 albertel 3273: if (title) {
3274: this.document.forms.newsmpproblem.importdetail.value=
1.236 albertel 3275: escape(title)+'=/res/lib/templates/simpleproblem.problem';
1.224 albertel 3276: this.document.forms.newsmpproblem.submit();
3277: }
3278: }
3279:
3280: function makedropbox() {
1.302 bisitz 3281: var title=prompt('$lt{"p_mdb"}');
1.224 albertel 3282: if (title) {
3283: this.document.forms.newdropbox.importdetail.value=
1.236 albertel 3284: escape(title)+'=/res/lib/templates/DropBox.problem';
1.224 albertel 3285: this.document.forms.newdropbox.submit();
3286: }
3287: }
3288:
3289: function makebulboard() {
1.302 bisitz 3290: var title=prompt('$lt{"p_mbb"}');
1.224 albertel 3291: if (title) {
3292: this.document.forms.newbul.importdetail.value=
1.236 albertel 3293: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
1.224 albertel 3294: this.document.forms.newbul.submit();
3295: }
3296: }
3297:
3298: function makeabout() {
1.303 raeburn 3299: var user=prompt("$lt{'p_mab'}");
1.224 albertel 3300: if (user) {
3301: var comp=new Array();
1.236 albertel 3302: comp=user.split(':');
1.224 albertel 3303: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3304: if ((comp[0]) && (comp[1])) {
3305: this.document.forms.newaboutsomeone.importdetail.value=
1.302 bisitz 3306: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.224 albertel 3307: this.document.forms.newaboutsomeone.submit();
3308: } else {
1.302 bisitz 3309: alert("$lt{'p_mab_alrt1'}");
1.224 albertel 3310: }
3311: } else {
1.302 bisitz 3312: alert("$lt{'p_mab_alrt2'}");
1.224 albertel 3313: }
3314: }
3315: }
3316:
3317: function makeims() {
3318: var caller = document.forms.ims.folder.value;
3319: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3320: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3321: newWindow.location.href = newlocation;
3322: }
3323:
3324:
3325: function finishpick() {
3326: var title=this.document.forms.extimport.title.value;
3327: var url=this.document.forms.extimport.url.value;
3328: var form=this.document.forms.extimport.useform.value;
1.287 albertel 3329: var residx=this.document.forms.extimport.residx.value;
3330: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.224 albertel 3331: }
3332:
3333: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.302 bisitz 3334: var title=prompt('$lt{"p_chn"}',oldtitle);
1.224 albertel 3335: if (title) {
1.281 albertel 3336: this.document.forms.renameform.markcopy.value=-1;
1.224 albertel 3337: this.document.forms.renameform.title.value=title;
3338: this.document.forms.renameform.cmd.value='rename_'+index;
3339: if (container == 'sequence') {
3340: this.document.forms.renameform.folderpath.value=folderpath;
3341: }
3342: if (container == 'page') {
3343: this.document.forms.renameform.pagepath.value=folderpath;
3344: this.document.forms.renameform.pagesymb.value=pagesymb;
3345: }
3346: this.document.forms.renameform.submit();
3347: }
3348: }
3349:
1.291 albertel 3350: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.302 bisitz 3351: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
1.281 albertel 3352: this.document.forms.renameform.markcopy.value=-1;
1.224 albertel 3353: this.document.forms.renameform.cmd.value='del_'+index;
3354: if (container == 'sequence') {
3355: this.document.forms.renameform.folderpath.value=folderpath;
3356: }
3357: if (container == 'page') {
3358: this.document.forms.renameform.pagepath.value=folderpath;
3359: this.document.forms.renameform.pagesymb.value=pagesymb;
3360: }
3361: this.document.forms.renameform.submit();
3362: }
3363: }
3364:
1.291 albertel 3365: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.303 raeburn 3366: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
1.224 albertel 3367: this.document.forms.renameform.cmd.value='cut_'+index;
3368: this.document.forms.renameform.markcopy.value=index;
1.281 albertel 3369: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
1.224 albertel 3370: if (container == 'sequence') {
3371: this.document.forms.renameform.folderpath.value=folderpath;
3372: }
3373: if (container == 'page') {
3374: this.document.forms.renameform.pagepath.value=folderpath;
3375: this.document.forms.renameform.pagesymb.value=pagesymb;
3376: }
3377: this.document.forms.renameform.submit();
3378: }
3379: }
3380:
1.281 albertel 3381: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.224 albertel 3382: this.document.forms.renameform.markcopy.value=index;
1.281 albertel 3383: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
1.224 albertel 3384: if (container == 'sequence') {
3385: this.document.forms.renameform.folderpath.value=folderpath;
3386: }
3387: if (container == 'page') {
3388: this.document.forms.renameform.pagepath.value=folderpath;
3389: this.document.forms.renameform.pagesymb.value=pagesymb;
3390: }
3391: this.document.forms.renameform.submit();
3392: }
3393:
3394: ENDNEWSCRIPT
3395: }
1.1 www 3396: 1;
3397: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>