Annotation of loncom/interface/londocs.pm, revision 1.314.2.6
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.314.2.6! raeburn 4: # $Id: londocs.pm,v 1.314.2.5 2009/03/18 21:57:58 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'}) {
1.314.2.6! raeburn 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/})) {
1.314.2.6! raeburn 1325: &Apache::lonnet::delenv('docs.markedcopy');
1.289 albertel 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;
1.314.2.5 raeburn 1891: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.287 albertel 1892: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1.142 raeburn 1893: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113 albertel 1894: my $symb=&Apache::lonnet::symbclean(
1.50 www 1895: &Apache::lonnet::declutter('uploaded/'.
1.174 albertel 1896: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1897: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1.50 www 1898: '.sequence').
1899: '___'.$residx.'___'.
1.113 albertel 1900: &Apache::lonnet::declutter($url));
1901: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1902: $url=&Apache::lonnet::clutter($url);
1.127 albertel 1903: if ($url=~/^\/*uploaded\//) {
1904: $url=~/\.(\w+)$/;
1905: my $embstyle=&Apache::loncommon::fileembstyle($1);
1906: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1907: $url='/adm/wrapper'.$url;
1908: } elsif ($embstyle eq 'ssi') {
1909: #do nothing with these
1910: } elsif ($url!~/\.(sequence|page)$/) {
1911: $url='/adm/coursedocs/showdoc'.$url;
1912: }
1.145 albertel 1913: } elsif ($url=~m|^/ext/|) {
1914: $url='/adm/wrapper'.$url;
1.287 albertel 1915: $external = 1;
1.127 albertel 1916: }
1.241 www 1917: if (&Apache::lonnet::symbverify($symb,$url)) {
1918: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1919: } else {
1920: $url='';
1921: }
1.152 albertel 1922: if ($container eq 'page') {
1.174 albertel 1923: my $symb=$env{'form.pagesymb'};
1.152 albertel 1924:
1925: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.228 www 1926: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1.152 albertel 1927: }
1.50 www 1928: }
1.296 albertel 1929: my ($parameterset,$rand_order_text) = (' ', ' ');
1.216 albertel 1930: if ($isfolder || $extension eq 'sequence') {
1.228 www 1931: my $foldername=&escape($foldertitle);
1.174 albertel 1932: my $folderpath=$env{'form.folderpath'};
1.114 albertel 1933: if ($folderpath) { $folderpath.='&' };
1.242 www 1934: # Append randompick number, hidden, and encrypted with ":" to foldername,
1935: # so it gets transferred between levels
1.245 albertel 1936: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
1.242 www 1937: 'parameter_randompick'))[0]
1.245 albertel 1938: .':'.((&LONCAPA::map::getparameter($orderidx,
1.242 www 1939: 'parameter_hiddenresource'))[0]=~/^yes$/i)
1.245 albertel 1940: .':'.((&LONCAPA::map::getparameter($orderidx,
1.296 albertel 1941: 'parameter_encrypturl'))[0]=~/^yes$/i)
1942: .':'.((&LONCAPA::map::getparameter($orderidx,
1943: 'parameter_randomorder'))[0]=~/^yes$/i);
1.228 www 1944: $url.='folderpath='.&escape($folderpath).$cpinfo;
1.147 matthew 1945: $parameterset='<label>'.&mt('Randomly Pick: ').
1.292 albertel 1946: '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
1.245 albertel 1947: (&LONCAPA::map::getparameter($orderidx,
1.147 matthew 1948: 'parameter_randompick'))[0].
1.165 www 1949: '" />'.
1.285 albertel 1950: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
1.296 albertel 1951: my $ro_set=
1952: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1953: $rand_order_text ='
1.314.2.1 raeburn 1954: <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 1955: }
1.142 raeburn 1956: if ($ispage) {
1.228 www 1957: my $pagename=&escape($pagetitle);
1.142 raeburn 1958: my $pagepath;
1.174 albertel 1959: my $folderpath=$env{'form.folderpath'};
1.142 raeburn 1960: if ($folderpath) { $pagepath = $folderpath.'&' };
1961: $pagepath.=$pagearg.'&'.$pagename;
1.174 albertel 1962: my $symb=$env{'form.pagesymb'};
1.152 albertel 1963: if (!$symb) {
1964: my $path='uploaded/'.
1.174 albertel 1965: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1966: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1.152 albertel 1967: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1968: $residx,
1969: $path.$pagearg.'.page');
1970: }
1.228 www 1971: $url.='pagepath='.&escape($pagepath).
1.282 albertel 1972: '&pagesymb='.&escape($symb).$cpinfo;
1.142 raeburn 1973: }
1.287 albertel 1974: if ($external) {
1975: my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
1976: $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
1977: } else {
1978: undef($external);
1979: }
1.285 albertel 1980: $line.='
1981: <td class="LC_docs_entry_icon">
1.287 albertel 1982: '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
1.285 albertel 1983: </td>
1984: <td class="LC_docs_entry_title">
1.287 albertel 1985: '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
1.285 albertel 1986: </td>";
1.120 www 1987: if (($allowed) && ($folder!~/^supplemental/)) {
1988: my %lt=&Apache::lonlocal::texthash(
1989: 'hd' => 'Hidden',
1.165 www 1990: 'ec' => 'URL hidden');
1.122 www 1991: my $enctext=
1.245 albertel 1992: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1.122 www 1993: my $hidtext=
1.245 albertel 1994: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120 www 1995: $line.=(<<ENDPARMS);
1.285 albertel 1996: <td class="LC_docs_entry_parameter">
1.286 albertel 1997: $form_start
1.292 albertel 1998: <label><input type="checkbox" name="hiddenresource_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.286 albertel 1999: $form_end
1.285 albertel 2000: </td>
2001: <td class="LC_docs_entry_parameter">
1.286 albertel 2002: $form_start
1.292 albertel 2003: <label><input type="checkbox" name="encrypturl_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.286 albertel 2004: $form_end
1.285 albertel 2005: </td>
1.296 albertel 2006: <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
1.286 albertel 2007: <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
1.120 www 2008: ENDPARMS
1.119 www 2009: }
1.286 albertel 2010: $line.="</tr>";
1.8 www 2011: return $line;
2012: }
2013:
1.27 www 2014: # ---------------------------------------------------------------- tie the hash
2015:
2016: sub tiehash {
1.136 albertel 2017: my ($mode)=@_;
1.27 www 2018: $hashtied=0;
1.174 albertel 2019: if ($env{'request.course.fn'}) {
1.136 albertel 2020: if ($mode eq 'write') {
1.174 albertel 2021: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136 albertel 2022: &GDBM_WRCREAT(),0640)) {
2023: $hashtied=2;
2024: }
2025: } else {
1.174 albertel 2026: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136 albertel 2027: &GDBM_READER(),0640)) {
1.27 www 2028: $hashtied=1;
1.136 albertel 2029: }
2030: }
1.27 www 2031: }
2032: }
2033:
2034: sub untiehash {
2035: if ($hashtied) { untie %hash; }
2036: $hashtied=0;
1.221 albertel 2037: return OK;
1.27 www 2038: }
2039:
1.29 www 2040: # --------------------------------------------------------------- check on this
2041:
2042: sub checkonthis {
2043: my ($r,$url,$level,$title)=@_;
1.228 www 2044: $url=&unescape($url);
1.29 www 2045: $alreadyseen{$url}=1;
2046: $r->rflush();
1.41 www 2047: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108 albertel 2048: $r->print("\n<br />");
1.313 bisitz 2049: if ($level==0) {
2050: $r->print("<br />");
2051: }
1.29 www 2052: for (my $i=0;$i<=$level*5;$i++) {
2053: $r->print(' ');
2054: }
2055: $r->print('<a href="'.$url.'" target="cat">'.
2056: ($title?$title:$url).'</a> ');
2057: if ($url=~/^\/res\//) {
2058: my $result=&Apache::lonnet::repcopy(
2059: &Apache::lonnet::filelocation('',$url));
1.172 raeburn 2060: if ($result eq 'ok') {
1.313 bisitz 2061: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.29 www 2062: $r->rflush();
1.34 www 2063: &Apache::lonnet::countacc($url);
2064: $url=~/\.(\w+)$/;
2065: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2066: $r->print('<br />');
2067: $r->rflush();
2068: for (my $i=0;$i<=$level*5;$i++) {
2069: $r->print(' ');
2070: }
1.313 bisitz 2071: $r->print('- '.&mt('Rendering:').' ');
1.170 www 2072: my ($errorcount,$warningcount)=split(/:/,
2073: &Apache::lonnet::ssi_body($url,
1.173 albertel 2074: ('grade_target'=>'web',
2075: 'return_only_error_and_warning_counts' => 1)));
1.170 www 2076: if (($errorcount) ||
2077: ($warningcount)) {
2078: if ($errorcount) {
1.283 albertel 2079: $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.
1.313 bisitz 2080: &mt('[quant,_1,error]',$errorcount).'</span>');
1.34 www 2081: }
1.170 www 2082: if ($warningcount) {
1.283 albertel 2083: $r->print('<span class="LC_warning">'.
1.313 bisitz 2084: &mt('[quant,_1,warning]',$warningcount).'</span>');
1.34 www 2085: }
2086: } else {
1.283 albertel 2087: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.34 www 2088: }
2089: $r->rflush();
2090: }
1.29 www 2091: my $dependencies=
2092: &Apache::lonnet::metadata($url,'dependencies');
2093: foreach (split(/\,/,$dependencies)) {
2094: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
2095: &checkonthis($r,$_,$level+1);
2096: }
2097: }
1.172 raeburn 2098: } elsif ($result eq 'unavailable') {
1.283 albertel 2099: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
1.172 raeburn 2100: } elsif ($result eq 'not_found') {
1.100 www 2101: unless ($url=~/\$/) {
1.313 bisitz 2102: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
1.100 www 2103: } else {
1.283 albertel 2104: $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');
1.100 www 2105: }
1.29 www 2106: } else {
1.283 albertel 2107: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
1.29 www 2108: }
1.313 bisitz 2109: }
2110: }
1.29 www 2111: }
2112:
1.1 www 2113:
1.75 www 2114: #
1.208 albertel 2115: # ----------------------------------------------------------------- List Symbs
2116: #
2117: sub list_symbs {
1.224 albertel 2118: my ($r) = @_;
2119:
1.314.2.4 raeburn 2120: my $type = &Apache::loncommon::course_type();
1.224 albertel 2121: $r->print(&Apache::loncommon::start_page('Symb List'));
1.257 www 2122: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
1.224 albertel 2123: my $navmap = Apache::lonnavmaps::navmap->new();
1.314.2.4 raeburn 2124: if (!defined($navmap)) {
2125: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2126: '<div class="LC_error">'.
2127: &mt('Unable to retrieve information about course contents').
2128: '</div>');
2129: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
2130: } else {
2131: $r->print("<pre>\n");
2132: foreach my $res ($navmap->retrieveResources()) {
2133: $r->print($res->compTitle()."\t".$res->symb()."\n");
2134: }
2135: $r->print("\n</pre>\n");
1.224 albertel 2136: }
2137: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
1.208 albertel 2138: }
2139:
2140:
2141: #
1.75 www 2142: # -------------------------------------------------------------- Verify Content
2143: #
2144: sub verifycontent {
1.224 albertel 2145: my ($r) = @_;
1.230 albertel 2146: my $type = &Apache::loncommon::course_type();
1.26 www 2147: my $loaderror=&Apache::lonnet::overloaderror($r);
2148: if ($loaderror) { return $loaderror; }
1.229 raeburn 2149: $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
1.257 www 2150: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
1.27 www 2151: $hashtied=0;
1.30 www 2152: undef %alreadyseen;
2153: %alreadyseen=();
1.27 www 2154: &tiehash();
2155: foreach (keys %hash) {
1.140 www 2156: if ($hash{$_}=~/\.(page|sequence)$/) {
1.228 www 2157: if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
1.283 albertel 2158: $r->print('<hr /><span class="LC_error">'.
1.230 albertel 2159: &mt('The following sequence or page is included more than once in your '.$type.': ').
1.283 albertel 2160: &unescape($hash{$_}).'</span><br />'.
1.140 www 2161: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2162: }
2163: }
1.228 www 2164: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
1.29 www 2165: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 2166: }
2167: }
2168: &untiehash();
1.108 albertel 2169: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2170: &mt('Return to DOCS').'</a>');
1.75 www 2171: }
2172:
1.192 www 2173:
1.75 www 2174: # -------------------------------------------------------------- Check Versions
2175:
1.192 www 2176: sub devalidateversioncache {
2177: my $src=shift;
2178: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2179: &Apache::lonnet::clutter($src));
2180: }
2181:
1.75 www 2182: sub checkversions {
1.224 albertel 2183: my ($r) = @_;
1.230 albertel 2184: my $type = &Apache::loncommon::course_type();
1.229 raeburn 2185: $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
1.257 www 2186: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
1.89 www 2187: my $header='';
2188: my $startsel='';
2189: my $monthsel='';
2190: my $weeksel='';
2191: my $daysel='';
2192: my $allsel='';
2193: my %changes=();
2194: my $starttime=0;
1.91 www 2195: my $haschanged=0;
1.92 www 2196: my %setversions=&Apache::lonnet::dump('resourceversions',
1.174 albertel 2197: $env{'course.'.$env{'request.course.id'}.'.domain'},
2198: $env{'course.'.$env{'request.course.id'}.'.num'});
1.92 www 2199:
2200: $hashtied=0;
2201: &tiehash();
2202: my %newsetversions=();
1.174 albertel 2203: if ($env{'form.setmostrecent'}) {
1.91 www 2204: $haschanged=1;
1.92 www 2205: foreach (keys %hash) {
2206: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 2207: $newsetversions{$1}='mostrecent';
1.192 www 2208: &devalidateversioncache($1);
1.92 www 2209: }
2210: }
1.174 albertel 2211: } elsif ($env{'form.setcurrent'}) {
1.91 www 2212: $haschanged=1;
1.92 www 2213: foreach (keys %hash) {
2214: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 2215: my $getvers=&Apache::lonnet::getversion($1);
2216: if ($getvers>0) {
2217: $newsetversions{$1}=$getvers;
1.192 www 2218: &devalidateversioncache($1);
1.93 www 2219: }
1.92 www 2220: }
2221: }
1.174 albertel 2222: } elsif ($env{'form.setversions'}) {
1.91 www 2223: $haschanged=1;
1.174 albertel 2224: foreach (keys %env) {
1.92 www 2225: if ($_=~/^form\.set_version_(.+)$/) {
2226: my $src=$1;
1.174 albertel 2227: if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
2228: $newsetversions{$src}=$env{$_};
1.192 www 2229: &devalidateversioncache($src);
1.92 www 2230: }
2231: }
2232: }
1.91 www 2233: }
2234: if ($haschanged) {
1.92 www 2235: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1.174 albertel 2236: $env{'course.'.$env{'request.course.id'}.'.domain'},
2237: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.272 albertel 2238: $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
1.92 www 2239: } else {
1.283 albertel 2240: $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
1.92 www 2241: }
1.136 albertel 2242: &mark_hash_old();
1.91 www 2243: }
1.136 albertel 2244: &changewarning($r,'');
1.174 albertel 2245: if ($env{'form.timerange'} eq 'all') {
1.89 www 2246: # show all documents
1.230 albertel 2247: $header=&mt('All Documents in '.$type);
1.91 www 2248: $allsel=1;
1.90 www 2249: foreach (keys %hash) {
2250: if ($_=~/^ids\_(\/res\/.+)$/) {
2251: my $src=$1;
2252: $changes{$src}=1;
2253: }
2254: }
1.89 www 2255: } else {
2256: # show documents which changed
2257: %changes=&Apache::lonnet::dump
1.174 albertel 2258: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2259: $env{'course.'.$env{'request.course.id'}.'.num'});
1.89 www 2260: my $firstkey=(keys %changes)[0];
2261: unless ($firstkey=~/^error\:/) {
1.174 albertel 2262: unless ($env{'form.timerange'}) {
2263: $env{'form.timerange'}=604800;
1.89 www 2264: }
1.174 albertel 2265: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
1.89 www 2266: .&mt('seconds');
1.174 albertel 2267: if ($env{'form.timerange'}==-1) {
1.89 www 2268: $seltext='since start of course';
2269: $startsel='selected';
1.174 albertel 2270: $env{'form.timerange'}=time;
1.89 www 2271: }
1.174 albertel 2272: $starttime=time-$env{'form.timerange'};
2273: if ($env{'form.timerange'}==2592000) {
1.89 www 2274: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2275: $monthsel='selected';
1.174 albertel 2276: } elsif ($env{'form.timerange'}==604800) {
1.89 www 2277: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2278: $weeksel='selected';
1.174 albertel 2279: } elsif ($env{'form.timerange'}==86400) {
1.89 www 2280: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2281: $daysel='selected';
2282: }
2283: $header=&mt('Content changed').' '.$seltext;
2284: } else {
2285: $header=&mt('No content modifications yet.');
2286: }
2287: }
1.92 www 2288: %setversions=&Apache::lonnet::dump('resourceversions',
1.174 albertel 2289: $env{'course.'.$env{'request.course.id'}.'.domain'},
2290: $env{'course.'.$env{'request.course.id'}.'.num'});
1.89 www 2291: my %lt=&Apache::lonlocal::texthash
1.229 raeburn 2292: ('st' => 'Version changes since start of '.$type,
1.88 www 2293: 'lm' => 'Version changes since last Month',
2294: 'lw' => 'Version changes since last Week',
2295: 'sy' => 'Version changes since Yesterday',
1.91 www 2296: 'al' => 'All Resources (possibly large output)',
1.88 www 2297: 'sd' => 'Display',
1.84 www 2298: 'fi' => 'File',
2299: 'md' => 'Modification Date',
1.87 www 2300: 'mr' => 'Most recently published Version',
1.229 raeburn 2301: 've' => 'Version used in '.$type,
2302: 'vu' => 'Set Version to be used in '.$type,
2303: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
1.91 www 2304: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2305: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84 www 2306: 'di' => 'Differences');
1.89 www 2307: $r->print(<<ENDHEADERS);
1.31 www 2308: <form action="/adm/coursedocs" method="post">
1.91 www 2309: <input type="hidden" name="versions" value="1" />
2310: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2311: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31 www 2312: <select name="timerange">
1.88 www 2313: <option value='all' $allsel>$lt{'al'}</option>
1.84 www 2314: <option value="-1" $startsel>$lt{'st'}</option>
2315: <option value="2592000" $monthsel>$lt{'lm'}</option>
2316: <option value="604800" $weeksel>$lt{'lw'}</option>
2317: <option value="86400" $daysel>$lt{'sy'}</option>
1.31 www 2318: </select>
1.91 www 2319: <input type="submit" name="display" value="$lt{'sd'}" />
1.89 www 2320: <h3>$header</h3>
1.91 www 2321: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103 matthew 2322: <table border="0">
1.31 www 2323: ENDHEADERS
1.91 www 2324: foreach (sort keys %changes) {
1.89 www 2325: if ($changes{$_}>$starttime) {
2326: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
2327: my $currentversion=&Apache::lonnet::getversion($_);
1.93 www 2328: if ($currentversion<0) {
2329: $currentversion=&mt('Could not be determined.');
2330: }
1.89 www 2331: my $linkurl=&Apache::lonnet::clutter($_);
2332: $r->print(
1.103 matthew 2333: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91 www 2334: &Apache::lonnet::gettitle($linkurl).
1.103 matthew 2335: '</b></font></td></tr>'.
2336: '<tr><td> </td>'.
2337: '<td colspan="4">'.
2338: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2339: '</a></td></tr>'.
2340: '<tr><td></td>'.
2341: '<td title="'.$lt{'md'}.'">'.
1.102 matthew 2342: &Apache::lonlocal::locallocaltime(
2343: &Apache::lonnet::metadata($root.'.'.$extension,
2344: 'lastrevisiondate')
2345: ).
1.103 matthew 2346: '</td>'.
1.284 albertel 2347: '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
1.103 matthew 2348: '<font size="+1">'.$currentversion.'</font>'.
1.284 albertel 2349: '</span></td>'.
2350: '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.
1.103 matthew 2351: '<font size="+1">');
1.87 www 2352: # Used in course
1.89 www 2353: my $usedversion=$hash{'version_'.$linkurl};
1.93 www 2354: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89 www 2355: $r->print($usedversion);
2356: } else {
2357: $r->print($currentversion);
2358: }
1.284 albertel 2359: $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
2360: '<span class="LC_nobreak">Use: ');
1.87 www 2361: # Set version
1.92 www 2362: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89 www 2363: 'set_version_'.$linkurl,
1.136 albertel 2364: ('select_form_order' =>
2365: ['',1..$currentversion,'mostrecent'],
2366: '' => '',
1.93 www 2367: 'mostrecent' => 'most recent',
1.89 www 2368: map {$_,$_} (1..$currentversion))));
1.284 albertel 2369: $r->print('</span></td></tr><tr><td></td>');
1.89 www 2370: my $lastold=1;
2371: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2372: my $url=$root.'.'.$prevvers.'.'.$extension;
2373: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2374: $starttime) {
2375: $lastold=$prevvers;
2376: }
2377: }
1.103 matthew 2378: #
2379: # Code to figure out how many version entries should go in
2380: # each of the four columns
2381: my $entries_per_col = 0;
2382: my $num_entries = ($currentversion-$lastold);
2383: if ($num_entries % 4 == 0) {
2384: $entries_per_col = $num_entries/4;
2385: } else {
2386: $entries_per_col = $num_entries/4 + 1;
2387: }
2388: my $entries_count = 0;
2389: $r->print('<td valign="top"><font size="-2">');
2390: my $cols_output = 1;
1.32 www 2391: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89 www 2392: my $url=$root.'.'.$prevvers.'.'.$extension;
1.284 albertel 2393: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
1.91 www 2394: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103 matthew 2395: &Apache::lonlocal::locallocaltime(
2396: &Apache::lonnet::metadata($url,
2397: 'lastrevisiondate')
2398: ).
1.91 www 2399: ')');
1.89 www 2400: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33 www 2401: $r->print(' <a href="/adm/diff?filename='.
1.89 www 2402: &Apache::lonnet::clutter($root.'.'.$extension).
2403: '&versionone='.$prevvers.
2404: '">'.&mt('Diffs').'</a>');
2405: }
1.284 albertel 2406: $r->print('</span><br />');
1.103 matthew 2407: if (++$entries_count % $entries_per_col == 0) {
2408: $r->print('</font></td>');
2409: if ($cols_output != 4) {
2410: $r->print('<td valign="top"><font size="-2">');
2411: $cols_output++;
2412: }
2413: }
1.89 www 2414: }
1.103 matthew 2415: while($cols_output++ < 4) {
2416: $r->print('</font></td><td><font>')
2417: }
2418: $r->print('</font></td></tr>'."\n");
1.89 www 2419: }
2420: }
1.92 www 2421: $r->print('</table></form>');
1.89 www 2422: $r->print('<h1>'.&mt('Done').'.</h1>');
2423:
2424: &untiehash();
1.75 www 2425: }
2426:
1.136 albertel 2427: sub mark_hash_old {
2428: my $retie_hash=0;
2429: if ($hashtied) {
2430: $retie_hash=1;
2431: &untiehash();
2432: }
2433: &tiehash('write');
2434: $hash{'old'}=1;
2435: &untiehash();
2436: if ($retie_hash) { &tiehash(); }
2437: }
2438:
2439: sub is_hash_old {
2440: my $untie_hash=0;
2441: if (!$hashtied) {
2442: $untie_hash=1;
2443: &tiehash();
2444: }
2445: my $return=$hash{'old'};
2446: if ($untie_hash) { &untiehash(); }
2447: return $return;
2448: }
2449:
1.91 www 2450: sub changewarning {
1.177 albertel 2451: my ($r,$postexec,$message,$url)=@_;
1.136 albertel 2452: if (!&is_hash_old()) { return; }
1.150 albertel 2453: my $pathvar='folderpath';
1.228 www 2454: my $path=&escape($env{'form.folderpath'});
1.177 albertel 2455: if (!defined($url)) {
2456: if (defined($env{'form.pagepath'})) {
2457: $pathvar='pagepath';
1.228 www 2458: $path=&escape($env{'form.pagepath'});
2459: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
1.177 albertel 2460: }
2461: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2462: }
1.230 albertel 2463: my $course_type = &Apache::loncommon::course_type();
1.177 albertel 2464: if (!defined($message)) {
2465: $message='Changes will become active for your current session after [_1], or the next time you log in.';
1.150 albertel 2466: }
1.185 www 2467: $r->print("\n\n".
1.286 albertel 2468: '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
1.185 www 2469: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.177 albertel 2470: '<input type="hidden" name="orgurl" value="'.$url.
1.283 albertel 2471: '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.
1.177 albertel 2472: &mt($message,' <input type="hidden" name="'.
2473: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.230 albertel 2474: &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
1.283 albertel 2475: $help{'Caching'}.'</span></h3></form>'."\n\n");
1.91 www 2476: }
2477:
1.257 www 2478: # =========================================== Breadcrumbs for special functions
2479:
2480: sub init_breadcrumbs {
2481: my ($form,$text)=@_;
2482: &Apache::lonhtmlcommon::clear_breadcrumbs();
2483: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
1.297 albertel 2484: text=>"Edit ".&Apache::loncommon::course_type(),
1.257 www 2485: faq=>273,
2486: bug=>'Instructor Interface',
2487: help => 'Docs_Adding_Course_Doc'});
2488: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2489: text=>$text,
2490: faq=>273,
2491: bug=>'Instructor Interface'});
2492: }
2493:
1.75 www 2494: # ================================================================ Main Handler
2495: sub handler {
2496: my $r = shift;
1.82 www 2497: &Apache::loncommon::content_type($r,'text/html');
1.75 www 2498: $r->send_http_header;
2499: return OK if $r->header_only;
1.230 albertel 2500: my $type = &Apache::loncommon::course_type();
1.75 www 2501:
2502: # --------------------------------------------- Initialize help topics for this
1.209 albertel 2503: foreach ('Adding_Course_Doc','Main_Course_Documents',
2504: 'Adding_External_Resource','Navigate_Content',
2505: 'Adding_Folders','Docs_Overview', 'Load_Map',
2506: 'Supplemental','Score_Upload_Form','Adding_Pages',
2507: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2508: 'Check_Resource_Versions','Verify_Content') {
2509: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
2510: }
1.75 www 2511: # Composite help files
2512: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2513: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2514: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2515: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86 albertel 2516: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2517: 'Option_Response_Simple');
1.75 www 2518: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2519: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2520: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
2521: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.255 raeburn 2522: $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.75 www 2523: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142 raeburn 2524:
1.209 albertel 2525: # does this user have privileges to modify docs
2526: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2527: if ($allowed && $env{'form.verify'}) {
1.257 www 2528: &init_breadcrumbs('verify','Verify Content');
1.75 www 2529: &verifycontent($r);
1.209 albertel 2530: } elsif ($allowed && $env{'form.listsymbs'}) {
1.257 www 2531: &init_breadcrumbs('listsymbs','List Symbs');
1.208 albertel 2532: &list_symbs($r);
1.247 www 2533: } elsif ($allowed && $env{'form.docslog'}) {
1.257 www 2534: &init_breadcrumbs('docslog','Show Log');
1.247 www 2535: &docs_change_log($r);
1.209 albertel 2536: } elsif ($allowed && $env{'form.versions'}) {
1.257 www 2537: &init_breadcrumbs('versions','Check/Set Resource Versions');
1.75 www 2538: &checkversions($r);
1.209 albertel 2539: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.257 www 2540: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
1.75 www 2541: &dumpcourse($r);
1.209 albertel 2542: } elsif ($allowed && $env{'form.exportcourse'}) {
1.257 www 2543: &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
1.138 raeburn 2544: &exportcourse($r);
1.26 www 2545: } else {
1.7 www 2546: # is this a standard course?
2547:
1.174 albertel 2548: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.155 raeburn 2549: my $forcestandard = 0;
1.15 www 2550: my $forcesupplement;
2551: my $script='';
1.19 www 2552: my $showdoc=0;
1.142 raeburn 2553: my $containertag;
2554: my $uploadtag;
1.15 www 2555: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.224 albertel 2556: ['folderpath','pagepath',
1.281 albertel 2557: 'pagesymb']);
1.307 www 2558: # No folderpath, no pagepath, see if we have something stored
2559: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2560: &Apache::loncommon::restore_course_settings('docs_folderpath',
2561: {'folderpath' => 'scalar'});
2562: }
2563: if (!$env{'form.folderpath'}) {
2564: &Apache::loncommon::restore_course_settings('docs_folderpath',
2565: {'pagepath' => 'scalar'});
2566: }
2567: if ($env{'form.pagepath'}) {
2568: $env{'form.folderpath'}='';
2569: }
1.309 raeburn 2570: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2571: $env{'form.folderpath'} = 'supplemental&'.
2572: &escape(&mt('Supplemental '.$type.' Documents')).'&'.
2573: $env{'form.folderpath'};
2574: }
1.307 www 2575: &Apache::loncommon::store_course_settings('docs_folderpath',
2576: {'pagepath' => 'scalar',
2577: 'folderpath' => 'scalar'});
1.174 albertel 2578: if ($env{'form.folderpath'}) {
2579: my (@folderpath)=split('&',$env{'form.folderpath'});
1.228 www 2580: $env{'form.foldername'}=&unescape(pop(@folderpath));
1.174 albertel 2581: $env{'form.folder'}=pop(@folderpath);
2582: }
2583: if ($env{'form.pagepath'}) {
2584: my (@pagepath)=split('&',$env{'form.pagepath'});
1.228 www 2585: $env{'form.pagename'}=&unescape(pop(@pagepath));
1.174 albertel 2586: $env{'form.folder'}=pop(@pagepath);
1.156 albertel 2587: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2588: '<input type="hidden" name="pagesymb" value="" />';
1.282 albertel 2589: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2590: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
1.142 raeburn 2591: }
1.21 www 2592: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127 albertel 2593: $showdoc='/'.$1;
1.21 www 2594: }
2595: unless ($showdoc) { # got called from remote
1.237 albertel 2596: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
1.209 albertel 2597: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
1.155 raeburn 2598: $forcestandard = 1;
2599: }
1.174 albertel 2600: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
1.7 www 2601:
1.15 www 2602: if ($allowed) {
2603: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2604: $script=&Apache::lonratedt::editscript('simple');
2605: }
2606: } else { # got called in sequence from course
2607: $allowed=0;
1.3 www 2608: }
1.4 www 2609:
2610: # get course data
1.174 albertel 2611: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2612: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.4 www 2613:
1.225 albertel 2614: # get personal data
1.174 albertel 2615: my $uname=$env{'user.name'};
2616: my $udom=$env{'user.domain'};
1.245 albertel 2617: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
1.14 www 2618:
1.8 www 2619: # graphics settings
1.4 www 2620:
1.176 albertel 2621: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
1.8 www 2622:
1.224 albertel 2623: if ($allowed) {
2624: $script .= &editing_js($udom,$uname);
1.171 www 2625: }
1.42 www 2626: # -------------------------------------------------------------------- Body tag
1.224 albertel 2627: $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
1.229 raeburn 2628: $r->print(&Apache::loncommon::start_page("$type Documents", $script,
1.225 albertel 2629: {'force_register' => $showdoc,}).
1.233 albertel 2630: &Apache::loncommon::help_open_menu('','',273,'RAT'));
1.224 albertel 2631:
1.188 raeburn 2632: my %allfiles = ();
2633: my %codebase = ();
2634: my ($upload_result,$upload_output);
2635: if ($allowed) {
1.264 albertel 2636: if (($env{'form.uploaddoc.filename'}) &&
2637: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.188 raeburn 2638: # Process file upload - phase one - upload and parse primary file.
1.298 albertel 2639: undef($hadchanges);
1.190 albertel 2640: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2641: $coursedom,\%allfiles,
1.194 raeburn 2642: \%codebase,$1);
1.298 albertel 2643: if ($hadchanges) {
2644: &mark_hash_old();
2645: }
1.188 raeburn 2646: if ($upload_result eq 'phasetwo') {
2647: $r->print($upload_output);
2648: }
2649: } elsif ($env{'form.phasetwo'}) {
2650: my %newname = ();
2651: my %origname = ();
2652: my %attribs = ();
2653: my $updateflag = 0;
2654: my $residx = $env{'form.newidx'};
1.228 www 2655: my $primary_url = &unescape($env{'form.primaryurl'});
1.188 raeburn 2656: # Process file upload - phase two - gather secondary files.
2657: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2658: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2659: my $javacodebase;
2660: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
1.228 www 2661: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
1.188 raeburn 2662: if (exists($env{'form.embedded_codebase_'.$i})) {
1.228 www 2663: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
1.188 raeburn 2664: $origname{$i} =~ s#^\Q$javacodebase\E/##;
2665: }
2666: my @attributes = ();
2667: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2668: @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
2669: } else {
2670: @attributes = ($env{'form.embedded_attrib_'.$i});
2671: }
2672: foreach (@attributes) {
1.228 www 2673: push(@{$attribs{$i}},&unescape($_));
1.188 raeburn 2674: }
2675: if ($javacodebase) {
2676: $codebase{$i} = $javacodebase;
2677: $codebase{$i} =~ s#/$##;
2678: $updateflag = 1;
2679: }
2680: }
2681: unless ($newname{$i} eq $origname{$i}) {
2682: $updateflag = 1;
2683: }
2684: }
2685: # Process file upload - phase three - modify primary file
2686: if ($updateflag) {
2687: my ($content,$rtncode);
2688: my $updateflag = 0;
2689: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2690: if ($getstatus eq 'ok') {
2691: foreach my $item (keys %newname) {
2692: if ($newname{$item} ne $origname{$item}) {
2693: my $attrib_regexp = '';
2694: if (@{$attribs{$item}} > 1) {
2695: $attrib_regexp = join('|',@{$attribs{$item}});
2696: } else {
2697: $attrib_regexp = $attribs{$item}[0];
2698: }
2699: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
2700: }
2701: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
2702: }
2703: if (exists($codebase{$item})) {
1.224 albertel 2704: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
1.188 raeburn 2705: }
2706: }
2707: # Save edited file.
2708: my $saveresult;
2709: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2710: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.191 raeburn 2711: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
1.188 raeburn 2712: } else {
2713: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
2714: }
2715: }
2716: }
2717: }
2718:
2719: unless ($showdoc || $upload_result eq 'phasetwo') {
1.81 www 2720: # -----------------------------------------------------------------------------
2721: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 2722: 'uplm' => 'Upload a new main '.lc($type).' document',
2723: 'upls' => 'Upload a new supplemental '.lc($type).' document',
1.168 www 2724: 'impp' => 'Import a document',
2725: 'pubd' => 'Published documents',
1.181 www 2726: 'copm' => 'All documents out of a published map into this folder',
1.81 www 2727: 'spec' => 'Special documents',
2728: 'upld' => 'Upload Document',
2729: 'srch' => 'Search',
2730: 'impo' => 'Import',
1.232 www 2731: 'book' => 'Import Bookmarks',
1.81 www 2732: 'selm' => 'Select Map',
2733: 'load' => 'Load Map',
1.186 www 2734: 'reco' => 'Recover Deleted Resources',
1.81 www 2735: 'newf' => 'New Folder',
1.142 raeburn 2736: 'newp' => 'New Composite Page',
1.81 www 2737: 'extr' => 'External Resource',
2738: 'syll' => 'Syllabus',
2739: 'navc' => 'Navigate Contents',
2740: 'sipa' => 'Simple Page',
2741: 'sipr' => 'Simple Problem',
1.219 www 2742: 'drbx' => 'Drop Box',
1.81 www 2743: 'scuf' => 'Score Upload Form',
2744: 'bull' => 'Bulletin Board',
1.96 sakharuk 2745: 'mypi' => 'My Personal Info',
1.255 raeburn 2746: 'grpo' => 'Group Files',
1.294 raeburn 2747: 'rost' => 'Course Roster',
1.101 www 2748: 'abou' => 'About User',
1.110 raeburn 2749: 'imsf' => 'Import IMS package',
1.96 sakharuk 2750: 'file' => 'File',
2751: 'title' => 'Title',
1.188 raeburn 2752: 'comment' => 'Comment',
2753: 'parse' => 'If HTML file, upload embedded images/multimedia files'
1.81 www 2754: );
2755: # -----------------------------------------------------------------------------
1.42 www 2756: if ($allowed) {
1.281 albertel 2757: &update_paste_buffer($coursenum,$coursedom);
1.74 www 2758: my $dumpbut=&dumpbutton();
1.138 raeburn 2759: my $exportbut=&exportbutton();
1.88 www 2760: my %lt=&Apache::lonlocal::texthash(
2761: 'vc' => 'Verify Content',
2762: 'cv' => 'Check/Set Resource Versions',
1.208 albertel 2763: 'ls' => 'List Symbs',
1.247 www 2764: 'sl' => 'Show Log'
1.88 www 2765: );
1.118 albertel 2766:
1.174 albertel 2767: my $folderpath=$env{'form.folderpath'};
1.118 albertel 2768: if (!$folderpath) {
1.174 albertel 2769: if ($env{'form.folder'} eq '' ||
2770: $env{'form.folder'} eq 'supplemental') {
1.118 albertel 2771: $folderpath='default&'.
1.230 albertel 2772: &escape(&mt('Main '.$type.' Documents'));
1.118 albertel 2773: }
2774: }
1.174 albertel 2775: unless ($env{'form.pagepath'}) {
1.142 raeburn 2776: $containertag = '<input type="hidden" name="folderpath" value="" />';
1.282 albertel 2777: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.142 raeburn 2778: }
2779:
1.42 www 2780: $r->print(<<ENDCOURSEVERIFY);
1.36 www 2781: <form name="renameform" method="post" action="/adm/coursedocs">
1.283 albertel 2782: <input type="hidden" name="title" />
2783: <input type="hidden" name="cmd" />
2784: <input type="hidden" name="markcopy" />
2785: <input type="hidden" name="copyfolder" />
2786: $containertag
1.36 www 2787: </form>
1.39 www 2788: <form name="simpleedit" method="post" action="/adm/coursedocs">
1.283 albertel 2789: <input type="hidden" name="importdetail" value="" />
2790: $uploadtag
1.39 www 2791: </form>
1.26 www 2792: <form action="/adm/coursedocs" method="post" name="courseverify">
1.283 albertel 2793: <div class="LC_docs_course_commands">
2794:
2795: <div>
2796: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
2797: </div>
2798: <div>
2799: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
2800: </div>
2801: $dumpbut
2802: $exportbut
2803: <div>
2804: <input type="submit" name="listsymbs" value="$lt{'ls'}" />
2805: </div>
2806: <div>
2807: <input type="hidden" name="folder" value="$env{'form.folder'}" />
2808: <input type="submit" name="docslog" value="$lt{'sl'}" />
2809: </div>
2810: </div>
1.25 www 2811: </form>
1.283 albertel 2812: <div style="clear: both; height: 0px;"> </div>
1.25 www 2813: ENDCOURSEVERIFY
1.74 www 2814: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.230 albertel 2815: &mt('Editing the Table of Contents for your '.$type)));
1.25 www 2816: }
1.17 www 2817: # --------------------------------------------------------- Standard documents
1.293 albertel 2818: $r->print('<table class="LC_docs_documents">');
2819:
1.7 www 2820: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.285 albertel 2821: $r->print('<tr><td class="LC_docs_document">');
1.116 albertel 2822: # '<h2>'.&mt('Main Course Documents').
2823: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.174 albertel 2824: my $folder=$env{'form.folder'};
1.117 albertel 2825: if ($folder eq '' || $folder eq 'supplemental') {
1.112 raeburn 2826: $folder='default';
1.230 albertel 2827: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
1.293 albertel 2828: $uploadtag = '<input type="hidden" name="folderpath" value="'.
2829: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.112 raeburn 2830: }
1.51 www 2831: my $postexec='';
2832: if ($folder eq 'default') {
1.286 albertel 2833: $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');
1.51 www 2834: } else {
1.117 albertel 2835: #$postexec='self.close();';
1.51 www 2836: }
1.40 www 2837: $hadchanges=0;
1.292 albertel 2838: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,
1.309 raeburn 2839: $upload_output,$type);
1.292 albertel 2840: if ($error) {
2841: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
2842: }
1.40 www 2843: if ($hadchanges) {
1.136 albertel 2844: &mark_hash_old()
1.40 www 2845: }
1.136 albertel 2846: &changewarning($r,$postexec);
1.16 www 2847: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2848: '.sequence';
1.142 raeburn 2849: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2850: '.page';
1.186 www 2851: my $container='sequence';
2852: if ($env{'form.pagepath'}) {
2853: $container='page';
2854: }
2855: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
1.8 www 2856: $r->print(<<ENDFORM);
1.285 albertel 2857: <table class="LC_docs_adddocs">
2858: <tr>
2859: <th>$lt{'uplm'}</th>
2860: <th>$lt{'impp'}</th>
2861: <th>$lt{'spec'}</th>
1.11 www 2862: </tr>
1.285 albertel 2863: <tr>
2864: <td>
1.96 sakharuk 2865: $lt{'file'}:<br />
1.182 albertel 2866: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.286 albertel 2867: <input type="file" name="uploaddoc" size="40" />
1.8 www 2868: <br />
1.96 sakharuk 2869: $lt{'title'}:<br />
1.286 albertel 2870: <input type="text" size="50" name="comment" />
1.142 raeburn 2871: $uploadtag
1.286 albertel 2872: <input type="hidden" name="cmd" value="upload_default" />
1.188 raeburn 2873: <br />
1.284 albertel 2874: <span class="LC_nobreak">
1.190 albertel 2875: <label>$lt{'parse'}?
1.306 www 2876: <input type="checkbox" name="parserflag" checked="checked" />
1.190 albertel 2877: </label>
1.284 albertel 2878: </span>
1.188 raeburn 2879: <br />
2880: <br />
1.284 albertel 2881: <span class="LC_nobreak">
1.286 albertel 2882: <input type="submit" value="$lt{'upld'}" />
1.60 albertel 2883: $help{'Uploading_From_Harddrive'}
1.284 albertel 2884: </span>
1.60 albertel 2885: </form>
1.11 www 2886: </td>
1.285 albertel 2887: <td>
1.39 www 2888: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.168 www 2889: $lt{'pubd'}<br />
1.142 raeburn 2890: $uploadtag
1.286 albertel 2891: <input type="button" onClick="javascript:groupsearch()" value="$lt{'srch'}" />
1.232 www 2892: <br />
1.284 albertel 2893: <span class="LC_nobreak">
1.286 albertel 2894: <input type="button" onClick="javascript:groupimport();" value="$lt{'impo'}" />
1.58 albertel 2895: $help{'Importing_LON-CAPA_Resource'}
1.284 albertel 2896: </span>
1.232 www 2897: <br />
1.286 albertel 2898: <input type="button" onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
2899: <hr />
1.59 www 2900: <p>
1.181 www 2901: $lt{'copm'}<br />
1.282 albertel 2902: <input type="text" size="40" name="importmap" /><br />
1.286 albertel 2903: <span class="LC_nobreak"><input type="button"
1.52 www 2904: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.282 albertel 2905: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
1.284 albertel 2906: $help{'Load_Map'}</span>
1.59 www 2907: </p>
1.52 www 2908: </form>
1.186 www 2909: <hr />
2910: <form action="/adm/groupsort" method="post" name="recover">
1.232 www 2911: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
1.186 www 2912: </form>
1.142 raeburn 2913: ENDFORM
1.174 albertel 2914: unless ($env{'form.pagepath'}) {
1.168 www 2915: $r->print(<<ENDFORM);
2916: <hr />
2917: <form action="/adm/coursedocs" method="post" name="newext">
2918: $uploadtag
1.256 albertel 2919: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2920: <span class="LC_nobreak">
1.168 www 2921: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2922: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.284 albertel 2923: </span>
1.168 www 2924: </form>
1.214 www 2925: <br /><form action="/adm/imsimportdocs" method="post" name="ims">
1.168 www 2926: <input type="hidden" name="folder" value="$folder" />
2927: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2928: </form>
2929: ENDFORM
2930: }
1.285 albertel 2931: $r->print('</td><td>');
1.174 albertel 2932: unless ($env{'form.pagepath'}) {
1.282 albertel 2933: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.142 raeburn 2934: $r->print(<<ENDFORM);
1.214 www 2935: <br /><form action="/adm/coursedocs" method="post" name="newfolder">
1.282 albertel 2936: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 2937: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2938: <span class="LC_nobreak">
1.16 www 2939: <input name="newfolder" type="button"
2940: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2941: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.284 albertel 2942: </span>
1.11 www 2943: </form>
1.214 www 2944: <br /><form action="/adm/coursedocs" method="post" name="newpage">
1.282 albertel 2945: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 2946: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2947: <span class="LC_nobreak">
1.142 raeburn 2948: <input name="newpage" type="button"
2949: onClick="javascript:makenewpage(this.form,'$pageseq');"
2950: value="$lt{'newp'}" />$help{'Adding_Pages'}
1.284 albertel 2951: </span>
1.142 raeburn 2952: </form>
1.214 www 2953: <br /><form action="/adm/coursedocs" method="post" name="newsyl">
1.142 raeburn 2954: $uploadtag
1.256 albertel 2955: <input type="hidden" name="importdetail"
1.305 bisitz 2956: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.284 albertel 2957: <span class="LC_nobreak">
1.81 www 2958: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2959: $help{'Syllabus'}
1.284 albertel 2960: </span>
1.58 albertel 2961: </form>
1.214 www 2962: <br /><form action="/adm/coursedocs" method="post" name="newnav">
1.142 raeburn 2963: $uploadtag
1.256 albertel 2964: <input type="hidden" name="importdetail"
1.305 bisitz 2965: value="$lt{'navc'}=/adm/navmaps" />
1.284 albertel 2966: <span class="LC_nobreak">
1.81 www 2967: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47 www 2968: $help{'Navigate_Content'}
1.284 albertel 2969: </span>
1.22 www 2970: </form>
1.214 www 2971: <br /><form action="/adm/coursedocs" method="post" name="newsmppg">
1.142 raeburn 2972: $uploadtag
1.256 albertel 2973: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2974: <span class="LC_nobreak">
1.81 www 2975: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65 bowersj2 2976: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.284 albertel 2977: </span>
1.55 www 2978: </form>
1.214 www 2979: <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142 raeburn 2980: $uploadtag
1.256 albertel 2981: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2982: <span class="LC_nobreak">
1.81 www 2983: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65 bowersj2 2984: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.284 albertel 2985: </span>
1.62 www 2986: </form>
1.219 www 2987: <br /><form action="/adm/coursedocs" method="post" name="newdropbox">
2988: $uploadtag
1.256 albertel 2989: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2990: <span class="LC_nobreak">
1.219 www 2991: <input name="newdropbox" type="button" value="$lt{'drbx'}"
2992: onClick="javascript:makedropbox();" />
1.284 albertel 2993: </span>
1.219 www 2994: </form>
1.214 www 2995: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 2996: $uploadtag
1.256 albertel 2997: <input type="hidden" name="importdetail" value="" />
1.284 albertel 2998: <span class="LC_nobreak">
1.81 www 2999: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62 www 3000: onClick="javascript:makeexamupload();" />
1.66 bowersj2 3001: $help{'Score_Upload_Form'}
1.284 albertel 3002: </span>
1.22 www 3003: </form>
1.214 www 3004: <br /><form action="/adm/coursedocs" method="post" name="newbul">
1.142 raeburn 3005: $uploadtag
1.256 albertel 3006: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3007: <span class="LC_nobreak">
1.81 www 3008: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22 www 3009: onClick="javascript:makebulboard();" />
1.65 bowersj2 3010: $help{'Bulletin Board'}
1.284 albertel 3011: </span>
1.58 albertel 3012: </form>
1.214 www 3013: <br /><form action="/adm/coursedocs" method="post" name="newaboutme">
1.142 raeburn 3014: $uploadtag
1.256 albertel 3015: <input type="hidden" name="importdetail"
3016: value="$plainname=/adm/$udom/$uname/aboutme" />
1.284 albertel 3017: <span class="LC_nobreak">
1.81 www 3018: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 3019: $help{'My Personal Info'}
1.284 albertel 3020: </span>
1.101 www 3021: </form>
1.214 www 3022: <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142 raeburn 3023: $uploadtag
1.256 albertel 3024: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3025: <span class="LC_nobreak">
1.101 www 3026: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
3027: onClick="javascript:makeabout();" />
1.284 albertel 3028: </span>
1.182 albertel 3029: </form>
1.255 raeburn 3030: <br /><form action="/adm/coursedocs" method="post" name="newgroupfiles">
3031: $uploadtag
1.256 albertel 3032: <input type="hidden" name="importdetail"
1.305 bisitz 3033: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.284 albertel 3034: <span class="LC_nobreak">
1.255 raeburn 3035: <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
3036: $help{'Group Files'}
1.284 albertel 3037: </span>
1.255 raeburn 3038: </form>
1.294 raeburn 3039: <br /><form action="/adm/coursedocs" method="post" name="newroster">
3040: $uploadtag
3041: <input type="hidden" name="importdetail"
1.305 bisitz 3042: value="$lt{'rost'}=/adm/viewclasslist" />
1.294 raeburn 3043: <span class="LC_nobreak">
3044: <input name="newroster" type="submit" value="$lt{'rost'}" />
3045: $help{'Course Roster'}
3046: </span>
3047: </form>
1.142 raeburn 3048: ENDFORM
3049: }
1.174 albertel 3050: if ($env{'form.pagepath'}) {
1.142 raeburn 3051: $r->print(<<ENDBLOCK);
3052: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
3053: $uploadtag
1.256 albertel 3054: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3055: <span class="LC_nobreak">
1.142 raeburn 3056: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
3057: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.284 albertel 3058: </span>
1.142 raeburn 3059: </form>
1.214 www 3060: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 3061: $uploadtag
1.256 albertel 3062: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3063: <span class="LC_nobreak">
1.142 raeburn 3064: <input name="newexamupload" type="button" value="$lt{'scuf'}"
3065: onClick="javascript:makeexamupload();" />
3066: $help{'Score_Upload_Form'}
1.284 albertel 3067: </span>
1.182 albertel 3068: </form>
1.142 raeburn 3069: ENDBLOCK
3070: }
3071: $r->print('</td></tr>'."\n".
3072: '</table>');
1.24 www 3073: $r->print('</td></tr>');
1.7 www 3074: }
3075: # ----------------------------------------------------- Supplemental documents
3076: if (!$forcestandard) {
1.285 albertel 3077: $r->print('<tr><td class="LC_docs_document">');
1.116 albertel 3078: # '<h2>'.&mt('Supplemental Course Documents').
3079: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.174 albertel 3080: my $folder=$env{'form.folder'};
1.117 albertel 3081: unless ($folder=~/^supplemental/) {
1.116 albertel 3082: $folder='supplemental';
1.117 albertel 3083: }
3084: if ($folder =~ /^supplemental$/ &&
1.309 raeburn 3085: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3086: $env{'form.folderpath'} = 'supplemental&'.
3087: &escape(&mt('Supplemental '.$type.' Documents'));
1.116 albertel 3088: }
1.309 raeburn 3089: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
1.292 albertel 3090: if ($error) {
3091: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3092: }
1.8 www 3093: if ($allowed) {
1.282 albertel 3094: my $folderseq=
3095: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3096: '.sequence';
1.17 www 3097:
1.282 albertel 3098: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3099: $r->print(<<ENDSUPFORM);
1.285 albertel 3100: <table class="LC_docs_adddocs"><tr>
3101: <th>$lt{'upls'}</th>
3102: <th>$lt{'spec'}</th>
1.17 www 3103: </tr>
1.285 albertel 3104: <tr><td>
1.10 www 3105: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.286 albertel 3106: <input type="file" name="uploaddoc" size="40" />
1.196 raeburn 3107: <br />
3108: <br />
1.284 albertel 3109: <span class="LC_nobreak">
1.196 raeburn 3110: <label>$lt{'parse'}?
3111: <input type="checkbox" name="parserflag" />
3112: </label>
1.284 albertel 3113: </span>
1.196 raeburn 3114: <br /><br />
3115: $lt{'comment'}:<br />
1.4 www 3116: <textarea cols=50 rows=4 name='comment'>
3117: </textarea>
1.115 albertel 3118: <br />
1.282 albertel 3119: <input type="hidden" name="folderpath" value="$path" />
1.286 albertel 3120: <input type="hidden" name="cmd" value="upload_supplemental" />
1.284 albertel 3121: <span class="LC_nobreak">
1.286 albertel 3122: <input type="submit" value="$lt{'upld'}" />
1.58 albertel 3123: $help{'Uploading_From_Harddrive'}
1.284 albertel 3124: </span>
1.58 albertel 3125: </form>
1.17 www 3126: </td>
1.285 albertel 3127: <td>
1.18 www 3128: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.282 albertel 3129: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3130: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3131: <span class="LC_nobreak">
1.17 www 3132: <input name="newfolder" type="button"
3133: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 3134: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.284 albertel 3135: </span>
1.17 www 3136: </form>
1.214 www 3137: <br /><form action="/adm/coursedocs" method="post" name="supnewext">
1.282 albertel 3138: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3139: <input type="hidden" name="importdetail" value="" />
1.284 albertel 3140: <span class="LC_nobreak">
1.18 www 3141: <input name="newext" type="button"
3142: onClick="javascript:makenewext('supnewext');"
1.81 www 3143: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.284 albertel 3144: </span>
1.17 www 3145: </form>
1.214 www 3146: <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">
1.282 albertel 3147: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3148: <input type="hidden" name="importdetail"
3149: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.284 albertel 3150: <span class="LC_nobreak">
1.81 www 3151: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 3152: $help{'Syllabus'}
1.284 albertel 3153: </span>
1.58 albertel 3154: </form>
1.214 www 3155: <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.282 albertel 3156: <input type="hidden" name="folderpath" value="$path" />
1.256 albertel 3157: <input type="hidden" name="importdetail"
3158: value="$plainname=/adm/$udom/$uname/aboutme" />
1.284 albertel 3159: <span class="LC_nobreak">
1.81 www 3160: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 3161: $help{'My Personal Info'}
1.284 albertel 3162: </span>
1.58 albertel 3163: </form>
1.17 www 3164: </td></tr>
1.24 www 3165: </table></td></tr>
1.8 www 3166: ENDSUPFORM
3167: }
1.7 www 3168: }
1.286 albertel 3169: $r->print('</table>');
1.18 www 3170: if ($allowed) {
1.287 albertel 3171: $r->print('
3172: <form method="post" name="extimport" action="/adm/coursedocs">
3173: <input type="hidden" name="title" />
3174: <input type="hidden" name="url" />
3175: <input type="hidden" name="useform" />
3176: <input type="hidden" name="residx" />
3177: </form>');
1.18 www 3178: }
1.19 www 3179: } else {
1.188 raeburn 3180: unless ($upload_result eq 'phasetwo') {
1.19 www 3181: # -------------------------------------------------------- This is showdoc mode
1.188 raeburn 3182: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.141 albertel 3183: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.286 albertel 3184: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3185: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.188 raeburn 3186: }
1.19 www 3187: }
1.26 www 3188: }
1.224 albertel 3189: $r->print(&Apache::loncommon::end_page());
1.26 www 3190: return OK;
1.1 www 3191: }
3192:
1.224 albertel 3193:
3194: sub editing_js {
3195: my ($udom,$uname) = @_;
3196: my $now = time();
1.302 bisitz 3197: my %lt = &Apache::lonlocal::texthash(
3198: p_mnf => 'Name of New Folder',
3199: t_mnf => 'New Folder',
3200: p_mnp => 'Name of New Page',
3201: t_mnp => 'New Page',
1.305 bisitz 3202: p_mxu => 'Title for the Uploaded Score',
3203: p_msp => 'Title for the Page',
3204: p_msb => 'Title for the Problem',
3205: p_mdb => 'Title for the Drop Box',
3206: p_mbb => 'Title for the Bulletin Board',
1.302 bisitz 3207: p_mab => "Enter user:domain for User's 'About Me' Page",
3208: p_mab2 => "About [_99]",
3209: p_mab_alrt1 => 'Not a valid user:domain',
3210: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3211: p_chn => 'New Title',
3212: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3213: p_rmr2a => 'Remove[_99]',
3214: p_rmr2b => '?[_99]',
1.303 raeburn 3215: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3216: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.302 bisitz 3217: p_ctr2a => 'Cut[_98]',
3218: p_ctr2b => '?[_98]'
3219: );
1.224 albertel 3220:
3221: return <<ENDNEWSCRIPT;
3222: function makenewfolder(targetform,folderseq) {
1.302 bisitz 3223: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
1.224 albertel 3224: if (foldername) {
1.236 albertel 3225: targetform.importdetail.value=escape(foldername)+"="+folderseq;
1.224 albertel 3226: targetform.submit();
3227: }
3228: }
3229:
3230: function makenewpage(targetform,folderseq) {
1.302 bisitz 3231: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
1.224 albertel 3232: if (pagename) {
1.236 albertel 3233: targetform.importdetail.value=escape(pagename)+"="+folderseq;
1.224 albertel 3234: targetform.submit();
3235: }
3236: }
3237:
3238: function makenewext(targetname) {
3239: this.document.forms.extimport.useform.value=targetname;
1.287 albertel 3240: this.document.forms.extimport.title.value='';
3241: this.document.forms.extimport.url.value='';
3242: this.document.forms.extimport.residx.value='';
3243: window.open('/adm/rat/extpickframe.html');
3244: }
3245:
3246: function edittext(targetname,residx,title,url) {
3247: this.document.forms.extimport.useform.value=targetname;
3248: this.document.forms.extimport.residx.value=residx;
3249: this.document.forms.extimport.url.value=url;
3250: this.document.forms.extimport.title.value=title;
1.224 albertel 3251: window.open('/adm/rat/extpickframe.html');
3252: }
3253:
3254: function makeexamupload() {
1.302 bisitz 3255: var title=prompt('$lt{"p_mxu"}');
1.224 albertel 3256: if (title) {
3257: this.document.forms.newexamupload.importdetail.value=
1.236 albertel 3258: escape(title)+'=/res/lib/templates/examupload.problem';
1.224 albertel 3259: this.document.forms.newexamupload.submit();
3260: }
3261: }
3262:
3263: function makesmppage() {
1.302 bisitz 3264: var title=prompt('$lt{"p_msp"}');
1.224 albertel 3265: if (title) {
3266: this.document.forms.newsmppg.importdetail.value=
1.236 albertel 3267: escape(title)+'=/adm/$udom/$uname/$now/smppg';
1.224 albertel 3268: this.document.forms.newsmppg.submit();
3269: }
3270: }
3271:
3272: function makesmpproblem() {
1.302 bisitz 3273: var title=prompt('$lt{"p_msb"}');
1.224 albertel 3274: if (title) {
3275: this.document.forms.newsmpproblem.importdetail.value=
1.236 albertel 3276: escape(title)+'=/res/lib/templates/simpleproblem.problem';
1.224 albertel 3277: this.document.forms.newsmpproblem.submit();
3278: }
3279: }
3280:
3281: function makedropbox() {
1.302 bisitz 3282: var title=prompt('$lt{"p_mdb"}');
1.224 albertel 3283: if (title) {
3284: this.document.forms.newdropbox.importdetail.value=
1.236 albertel 3285: escape(title)+'=/res/lib/templates/DropBox.problem';
1.224 albertel 3286: this.document.forms.newdropbox.submit();
3287: }
3288: }
3289:
3290: function makebulboard() {
1.302 bisitz 3291: var title=prompt('$lt{"p_mbb"}');
1.224 albertel 3292: if (title) {
3293: this.document.forms.newbul.importdetail.value=
1.236 albertel 3294: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
1.224 albertel 3295: this.document.forms.newbul.submit();
3296: }
3297: }
3298:
3299: function makeabout() {
1.303 raeburn 3300: var user=prompt("$lt{'p_mab'}");
1.224 albertel 3301: if (user) {
3302: var comp=new Array();
1.236 albertel 3303: comp=user.split(':');
1.224 albertel 3304: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3305: if ((comp[0]) && (comp[1])) {
3306: this.document.forms.newaboutsomeone.importdetail.value=
1.302 bisitz 3307: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.224 albertel 3308: this.document.forms.newaboutsomeone.submit();
3309: } else {
1.302 bisitz 3310: alert("$lt{'p_mab_alrt1'}");
1.224 albertel 3311: }
3312: } else {
1.302 bisitz 3313: alert("$lt{'p_mab_alrt2'}");
1.224 albertel 3314: }
3315: }
3316: }
3317:
3318: function makeims() {
3319: var caller = document.forms.ims.folder.value;
3320: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3321: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3322: newWindow.location.href = newlocation;
3323: }
3324:
3325:
3326: function finishpick() {
3327: var title=this.document.forms.extimport.title.value;
3328: var url=this.document.forms.extimport.url.value;
3329: var form=this.document.forms.extimport.useform.value;
1.287 albertel 3330: var residx=this.document.forms.extimport.residx.value;
3331: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.224 albertel 3332: }
3333:
3334: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.302 bisitz 3335: var title=prompt('$lt{"p_chn"}',oldtitle);
1.224 albertel 3336: if (title) {
1.281 albertel 3337: this.document.forms.renameform.markcopy.value=-1;
1.224 albertel 3338: this.document.forms.renameform.title.value=title;
3339: this.document.forms.renameform.cmd.value='rename_'+index;
3340: if (container == 'sequence') {
3341: this.document.forms.renameform.folderpath.value=folderpath;
3342: }
3343: if (container == 'page') {
3344: this.document.forms.renameform.pagepath.value=folderpath;
3345: this.document.forms.renameform.pagesymb.value=pagesymb;
3346: }
3347: this.document.forms.renameform.submit();
3348: }
3349: }
3350:
1.291 albertel 3351: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.302 bisitz 3352: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
1.281 albertel 3353: this.document.forms.renameform.markcopy.value=-1;
1.224 albertel 3354: this.document.forms.renameform.cmd.value='del_'+index;
3355: if (container == 'sequence') {
3356: this.document.forms.renameform.folderpath.value=folderpath;
3357: }
3358: if (container == 'page') {
3359: this.document.forms.renameform.pagepath.value=folderpath;
3360: this.document.forms.renameform.pagesymb.value=pagesymb;
3361: }
3362: this.document.forms.renameform.submit();
3363: }
3364: }
3365:
1.291 albertel 3366: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.303 raeburn 3367: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
1.224 albertel 3368: this.document.forms.renameform.cmd.value='cut_'+index;
3369: this.document.forms.renameform.markcopy.value=index;
1.281 albertel 3370: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
1.224 albertel 3371: if (container == 'sequence') {
3372: this.document.forms.renameform.folderpath.value=folderpath;
3373: }
3374: if (container == 'page') {
3375: this.document.forms.renameform.pagepath.value=folderpath;
3376: this.document.forms.renameform.pagesymb.value=pagesymb;
3377: }
3378: this.document.forms.renameform.submit();
3379: }
3380: }
3381:
1.281 albertel 3382: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.224 albertel 3383: this.document.forms.renameform.markcopy.value=index;
1.281 albertel 3384: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
1.224 albertel 3385: if (container == 'sequence') {
3386: this.document.forms.renameform.folderpath.value=folderpath;
3387: }
3388: if (container == 'page') {
3389: this.document.forms.renameform.pagepath.value=folderpath;
3390: this.document.forms.renameform.pagesymb.value=pagesymb;
3391: }
3392: this.document.forms.renameform.submit();
3393: }
3394:
3395: ENDNEWSCRIPT
3396: }
1.1 www 3397: 1;
3398: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>