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