1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.131 2004/06/27 16:43:28 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::lonnet;
34: use Apache::loncommon;
35: use Apache::lonratedt;
36: use Apache::lonratsrv;
37: use Apache::lonxml;
38: use Apache::loncreatecourse;
39: use HTML::Entities;
40: use GDBM_File;
41: use Apache::lonlocal;
42:
43: my $iconpath;
44:
45: my %hash;
46:
47: my $hashtied;
48: my %alreadyseen=();
49:
50: my $hadchanges;
51:
52: # Available help topics
53:
54: my %help=();
55:
56: # Mapread read maps into lonratedt::global arrays
57: # @order and @resources, determines status
58: # sets @order - pointer to resources in right order
59: # sets @resources - array with the resources with correct idx
60: #
61:
62: sub mapread {
63: my ($coursenum,$coursedom,$map)=@_;
64: return
65: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
66: $map);
67: }
68:
69: sub storemap {
70: my ($coursenum,$coursedom,$map)=@_;
71: my ($outtext,$errtext)=
72: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map,1);
74: if ($errtext) { return ($errtext,2); }
75:
76: $hadchanges=1;
77: return ($errtext,0);
78: }
79:
80: # ----------------------------------------- Return hash with valid author names
81:
82: sub authorhosts {
83: my %outhash=();
84: my $home=0;
85: my $other=0;
86: foreach (keys %ENV) {
87: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
88: my $role=$1;
89: my $realm=$2;
90: my ($start,$end)=split(/\./,$ENV{$_});
91: if (($start) && ($start>time)) { next; }
92: if (($end) && (time>$end)) { next; }
93: my $ca; my $cd;
94: if ($1 eq 'au') {
95: $ca=$ENV{'user.name'};
96: $cd=$ENV{'user.domain'};
97: } else {
98: ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
99: }
100: my $allowed=0;
101: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
102: my @ids=&Apache::lonnet::current_machine_ids();
103: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
104: if ($allowed) {
105: $home++;
106: $outhash{'home_'.$ca.'@'.$cd}=1;
107: } else {
108: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
109: $other++;
110: }
111: }
112: }
113: return ($home,$other,%outhash);
114: }
115: # ------------------------------------------------------ Generate "dump" button
116:
117: sub dumpbutton {
118: my ($home,$other,%outhash)=&authorhosts();
119: if ($home+$other==0) { return ''; }
120: my $output='</td><td bgcolor="#DDDDCC">';
121: if ($home) {
122: return '</td><td bgcolor="#DDDDCC">'.
123: '<input type="submit" name="dumpcourse" value="'.
124: &mt('Dump Course DOCS to Construction Space').'" />'.
125: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
126: } else {
127: return'</td><td bgcolor="#DDDDCC">'.
128: &mt('Dump Course DOCS to Construction Space: available on other servers');
129: }
130: }
131:
132: # -------------------------------------------------------- Actually dump course
133:
134: sub dumpcourse {
135: my $r=shift;
136: $r->print('<html><head><title>Dump DOCS</title></head>'.
137: &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
138: '<form name="dumpdoc" method="post">');
139: my ($home,$other,%outhash)=&authorhosts();
140: unless ($home) { return ''; }
141: my $origcrsid=$ENV{'request.course.id'};
142: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
143: if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
144: # Do the dumping
145: unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
146: my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
147: $r->print('<h3>'.&mt('Copying Files').'</h3>');
148: my $title=$ENV{'form.authorfolder'};
149: $title=~s/[^\w\/]+/\_/g;
150: my %replacehash=();
151: foreach (keys %ENV) {
152: if ($_=~/^form\.namefor\_(.+)/) {
153: $replacehash{$1}=$ENV{$_};
154: }
155: }
156: my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
157: $crs=~s/\_/\//g;
158: foreach (keys %replacehash) {
159: my $newfilename=$title.'/'.$replacehash{$_};
160: $newfilename=~s/[^\w\/\.]+/\_/g;
161: my @dirs=split(/\//,$newfilename);
162: my $path='/home/'.$ca.'/public_html';
163: my $makepath=$path;
164: my $fail=0;
165: for (my $i=0;$i<$#dirs;$i++) {
166: $makepath.='/'.$dirs[$i];
167: unless (-e $makepath) {
168: unless(mkdir($makepath,0777)) { $fail=1; }
169: }
170: }
171: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
172: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
173: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
174: print $fh &Apache::loncreatecourse::rewritefile(
175: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
176: (%replacehash,$crs => '')
177: );
178: } else {
179: print $fh
180: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
181: }
182: $fh->close();
183: } else {
184: $fail=1;
185: }
186: if ($fail) {
187: $r->print('<font color="red">fail</font>');
188: } else {
189: $r->print('<font color="green">ok</font>');
190: }
191: }
192: } else {
193: # Input form
194: unless ($home==1) {
195: $r->print(
196: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
197: }
198: foreach (sort keys %outhash) {
199: if ($_=~/^home_(.+)$/) {
200: if ($home==1) {
201: $r->print(
202: '<input type="hidden" name="authorspace" value="'.$1.'" />');
203: } else {
204: $r->print('<option value="'.$1.'">'.$_.'</option>');
205: }
206: }
207: }
208: unless ($home==1) {
209: $r->print('</select>');
210: }
211: my $title=$origcrsdata{'description'};
212: $title=~s/\s+/\_/gs;
213: $title=~s/\W//gs;
214: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
215: &tiehash();
216: $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>');
217: foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
218: $r->print('<tr><td>'.$_.'</td>');
219: my ($ext)=($_=~/\.(\w+)$/);
220: my $title=$hash{'title_'.$hash{
221: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
222: $r->print('<td>'.($title?$title:' ').'</td>');
223: unless ($title) {
224: $title=$_;
225: }
226: $title=~s/\.(\w+)$//;
227: $title=~s/\W+/\_/gs;
228: $title.='.'.$ext;
229: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
230: }
231: $r->print("</table>\n");
232: &untiehash();
233: $r->print(
234: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
235: }
236: }
237:
238:
239: # Imports the given (name, url) resources into the course
240: # coursenum, coursedom, and folder must precede the list
241: sub group_import {
242: my $coursenum = shift;
243: my $coursedom = shift;
244: my $folder = shift;
245: while (@_) {
246: my $name = shift;
247: my $url = shift;
248: if ($url) {
249: my $idx = $#Apache::lonratedt::resources + 1;
250: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
251: my $ext = 'false';
252: if ($url=~/^http:\/\//) { $ext = 'true'; }
253: $url =~ s/:/\:/g;
254: $name =~ s/:/\:/g;
255: $Apache::lonratedt::resources[$idx] =
256: join ':', ($name, $url, $ext, 'normal', 'res');
257: }
258: }
259: return &storemap($coursenum, $coursedom, $folder.'.sequence');
260: }
261:
262: sub breadcrumbs {
263: my ($where)=@_;
264: &Apache::lonhtmlcommon::clear_breadcrumbs();
265: my (@folders)=split('&',$ENV{'form.folderpath'});
266: my $folderpath;
267: while (@folders) {
268: my $folder=shift(@folders);
269: my $foldername=shift(@folders);
270: if ($folderpath) {$folderpath.='&';}
271: $folderpath.=$folder.'&'.$foldername;
272: my $url='/adm/coursedocs?folderpath='.
273: &Apache::lonnet::escape($folderpath);
274: &Apache::lonhtmlcommon::add_breadcrumb(
275: {'href'=>$url,
276: 'title'=>&Apache::lonnet::unescape($foldername),
277: 'text'=>'<font size="+1">'.
278: &Apache::lonnet::unescape($foldername).'</font>'
279: });
280:
281:
282: }
283: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,0);
284: }
285:
286: sub editor {
287: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
288:
289: $r->print(&breadcrumbs($folder));
290: my $errtext='';
291: my $fatal=0;
292: ($errtext,$fatal)=
293: &mapread($coursenum,$coursedom,$folder.'.sequence');
294: if ($#Apache::lonratedt::order<1) {
295: $Apache::lonratedt::order[0]=1;
296: $Apache::lonratedt::resources[1]='';
297: }
298: if ($fatal) {
299: $r->print('<p><font color="red">'.$errtext.'</font></p>');
300: } else {
301: # ------------------------------------------------------------ Process commands
302:
303: # ---------------- if they are for this folder and user allowed to make changes
304: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
305: # set parameters and change order
306: if (defined($ENV{'form.setparms'})) {
307: my $idx=$ENV{'form.setparms'};
308: # set parameters
309: if ($ENV{'form.randpick_'.$idx}) {
310: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
311: } else {
312: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
313: }
314: if ($ENV{'form.hidprs_'.$idx}) {
315: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
316: } else {
317: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
318: }
319: if ($ENV{'form.encprs_'.$idx}) {
320: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
321: } else {
322: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
323: }
324:
325: if ($ENV{'form.newpos'}) {
326: # change order
327:
328: my $newpos=$ENV{'form.newpos'}-1;
329: my $currentpos=$ENV{'form.currentpos'}-1;
330: my $i;
331: my @neworder=();
332: if ($newpos>$currentpos) {
333: # moving stuff up
334: for ($i=0;$i<$currentpos;$i++) {
335: $neworder[$i]=$Apache::lonratedt::order[$i];
336: }
337: for ($i=$currentpos;$i<$newpos;$i++) {
338: $neworder[$i]=$Apache::lonratedt::order[$i+1];
339: }
340: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
341: for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
342: $neworder[$i]=$Apache::lonratedt::order[$i];
343: }
344: } else {
345: # moving stuff down
346: for ($i=0;$i<$newpos;$i++) {
347: $neworder[$i]=$Apache::lonratedt::order[$i];
348: }
349: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
350: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
351: $neworder[$i]=$Apache::lonratedt::order[$i-1];
352: }
353: for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
354: $neworder[$i]=$Apache::lonratedt::order[$i];
355: }
356: }
357: @Apache::lonratedt::order=@neworder;
358: }
359: # store the changed version
360:
361: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
362: if ($fatal) {
363: $r->print('<p><font color="red">'.$errtext.'</font></p>');
364: return;
365: }
366:
367: }
368:
369: # upload a file, if present
370: if (($ENV{'form.uploaddoc.filename'}) &&
371: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
372: if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
373: # this is for a course, not a user, so set coursedoc flag
374: # probably the only place in the system where this should be "1"
375: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
376: my $ext='false';
377: if ($url=~/^http\:\/\//) { $ext='true'; }
378: $url=~s/\:/\:/g;
379: my $comment=$ENV{'form.comment'};
380: $comment=~s/\</\<\;/g;
381: $comment=~s/\>/\>\;/g;
382: $comment=~s/\:/\:/g;
383: if ($folder=~/^supplemental/) {
384: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
385: $ENV{'user.domain'}.'___&&&___'.$comment;
386: }
387: my $newidx=$#Apache::lonratedt::resources+1;
388: $Apache::lonratedt::resources[$newidx]=
389: $comment.':'.$url.':'.$ext.':normal:res';
390: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
391: $newidx;
392:
393: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
394: if ($fatal) {
395: $r->print('<p><font color="red">'.$errtext.'</font></p>');
396: return;
397: }
398: }
399: }
400: if ($ENV{'form.cmd'}) {
401: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
402: if ($cmd eq 'del') {
403: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
404: if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
405: &Apache::lonnet::removeuploadedurl($url);
406: }
407: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
408: $Apache::lonratedt::order[$i]=
409: $Apache::lonratedt::order[$i+1];
410: }
411: $#Apache::lonratedt::order--;
412: } elsif ($cmd eq 'up') {
413: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
414: my $i=$Apache::lonratedt::order[$idx-1];
415: $Apache::lonratedt::order[$idx-1]=
416: $Apache::lonratedt::order[$idx];
417: $Apache::lonratedt::order[$idx]=$i;
418: }
419: } elsif ($cmd eq 'down') {
420: if (defined($Apache::lonratedt::order[$idx+1])) {
421: my $i=$Apache::lonratedt::order[$idx+1];
422: $Apache::lonratedt::order[$idx+1]=
423: $Apache::lonratedt::order[$idx];
424: $Apache::lonratedt::order[$idx]=$i;
425: }
426: } elsif ($cmd eq 'rename') {
427: my ($rtitle,@rrest)=split(/\:/,
428: $Apache::lonratedt::resources[
429: $Apache::lonratedt::order[$idx]]);
430: my $comment=
431: &HTML::Entities::decode($ENV{'form.title'});
432: $comment=~s/\</\<\;/g;
433: $comment=~s/\>/\>\;/g;
434: $comment=~s/\:/\:/g;
435: $Apache::lonratedt::resources[
436: $Apache::lonratedt::order[$idx]]=
437: $comment.':'.join(':',@rrest);
438:
439: }
440: # Store the changed version
441: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
442: $folder.'.sequence');
443: if ($fatal) {
444: $r->print('<p><font color="red">'.$errtext.'</font></p>');
445: return;
446: }
447: }
448: # Group import/search
449: if ($ENV{'form.importdetail'}) {
450: my @imports;
451: foreach (split(/\&/,$ENV{'form.importdetail'})) {
452: if (defined($_)) {
453: my ($name,$url)=split(/\=/,$_);
454: $name=&Apache::lonnet::unescape($name);
455: $url=&Apache::lonnet::unescape($url);
456: push @imports, $name, $url;
457: }
458: }
459: # Store the changed version
460: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
461: @imports);
462: if ($fatal) {
463: $r->print('<p><font color="red">'.$errtext.'</font></p>');
464: return;
465: }
466: }
467: # Loading a complete map
468: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
469: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
470: my $idx=$#Apache::lonratedt::resources;
471: $idx++;
472: $Apache::lonratedt::resources[$idx]=$_;
473: $Apache::lonratedt::order
474: [$#Apache::lonratedt::order+1]=$idx;
475: }
476:
477: # Store the changed version
478: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
479: $folder.'.sequence');
480: if ($fatal) {
481: $r->print('<p><font color="red">'.$errtext.'</font></p>');
482: return;
483: }
484: }
485: }
486: # ---------------------------------------------------------------- End commands
487: # ---------------------------------------------------------------- Print screen
488: my $idx=0;
489: $r->print('<table>');
490: foreach (@Apache::lonratedt::order) {
491: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
492: unless ($name) { $name=(split(/\//,$url))[-1]; }
493: unless ($name) { next; }
494: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
495: $idx++;
496: }
497: unless ($idx) {
498: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
499: }
500: $r->print('</table>');
501: }
502: }
503:
504: # --------------------------------------------------------------- An entry line
505:
506: sub entryline {
507: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
508: $title=~s/\&colon\;/\:/g;
509: $title=&HTML::Entities::encode(&HTML::Entities::decode(
510: &Apache::lonnet::unescape($title)),'"<>&\'');
511: my $renametitle=$title;
512: my $foldertitle=$title;
513: my $orderidx=$Apache::lonratedt::order[$index];
514: if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
515: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
516: $renametitle=$4;
517: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
518: &Apache::loncommon::plainname($2,$3).': <br />'.
519: $foldertitle;
520: }
521: $renametitle=~s/\"\;/\\\"/g;
522: my $line='<tr>';
523: # Edit commands
524: my $folderpath;
525: if ($ENV{'form.folderpath'}) {
526: $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
527: # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
528: }
529: if ($allowed) {
530: my $incindex=$index+1;
531: my $selectbox='';
532: if ($folder!~/^supplemental/) {
533: $selectbox=
534: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
535: '<select name="newpos" onChange="this.form.submit()">';
536: for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
537: if ($i==$incindex) {
538: $selectbox.='<option value="" selected="1">('.$i.')</option>';
539: } else {
540: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
541: }
542: }
543: $selectbox.='</select>';
544: }
545: my %lt=&Apache::lonlocal::texthash(
546: 'up' => 'Move Up',
547: 'dw' => 'Move Down',
548: 'rm' => 'Remove',
549: 'rn' => 'Rename');
550: $line.=(<<END);
551: <form name="entry_$index" action="/adm/coursedocs" method="post">
552: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
553: <input type="hidden" name="setparms" value="$orderidx" />
554: <td><table border='0' cellspacing='2' cellpadding='0'>
555: <tr><td bgcolor="#DDDDDD">
556: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
557: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
558: <tr><td bgcolor="#DDDDDD">
559: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
560: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
561: </table></td>
562: <td>$selectbox
563: </td><td bgcolor="#DDDDDD">
564: <a href='javascript:removeres("$folderpath","$index","$renametitle");'>
565: <font size="-2" color="#990000">$lt{'rm'}</font></a>
566: <a href='javascript:changename("$folderpath","$index","$renametitle");'>
567: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
568: END
569: }
570: # Figure out what kind of a resource this is
571: my ($extension)=($url=~/\.(\w+)$/);
572: my $uploaded=($url=~/^\/*uploaded\//);
573: my $icon=&Apache::loncommon::icon($url);
574: my $isfolder=0;
575: my $folderarg;
576: if ($uploaded) {
577: if ($extension eq 'sequence') {
578: $icon=$iconpath.'/folder_closed.gif';
579: $url=~/$coursenum\/([\/\w]+)\.sequence$/;
580: $url='/adm/coursedocs?';
581: $folderarg=$1;
582: $isfolder=1;
583: }
584: }
585: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
586: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/)) {
587: my $symb=&Apache::lonnet::symbclean(
588: &Apache::lonnet::declutter('uploaded/'.
589: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
590: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
591: '.sequence').
592: '___'.$residx.'___'.
593: &Apache::lonnet::declutter($url));
594: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
595: $url=&Apache::lonnet::clutter($url);
596: if ($url=~/^\/*uploaded\//) {
597: $url=~/\.(\w+)$/;
598: my $embstyle=&Apache::loncommon::fileembstyle($1);
599: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
600: $url='/adm/wrapper'.$url;
601: } elsif ($embstyle eq 'ssi') {
602: #do nothing with these
603: } elsif ($url!~/\.(sequence|page)$/) {
604: $url='/adm/coursedocs/showdoc'.$url;
605: }
606: }
607: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
608: }
609: my $parameterset=' ';
610: if ($isfolder) {
611: my $foldername=&Apache::lonnet::escape($foldertitle);
612: my $folderpath=$ENV{'form.folderpath'};
613: if ($folderpath) { $folderpath.='&' };
614: $folderpath.=$folderarg.'&'.$foldername;
615: $url.='folderpath='.&Apache::lonnet::escape($folderpath);
616: $parameterset=&mt('Randomly Pick: ').
617: '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
618: (&Apache::lonratedt::getparameter($orderidx,'parameter_randompick'))[0].'" />';
619: }
620: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
621: '" border="0"></a></td>'.
622: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
623: if (($allowed) && ($folder!~/^supplemental/)) {
624: my %lt=&Apache::lonlocal::texthash(
625: 'hd' => 'Hidden',
626: 'ec' => 'URL hidden',
627: 'sp' => 'Store Parameters');
628: my $enctext=
629: ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
630: my $hidtext=
631: ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
632: $line.=(<<ENDPARMS);
633: <td bgcolor="#BBBBFF"><font size='-2'>
634: <input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</td>
635: <td bgcolor="#BBBBFF"><font size='-2'>
636: <input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</td>
637: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
638: <td bgcolor="#BBBBFF"><font size='-2'>
639: <input type="submit" value="$lt{'sp'}" />
640: </font></td>
641: ENDPARMS
642: }
643: $line.="</form></tr>";
644: return $line;
645: }
646:
647: # ---------------------------------------------------------------- tie the hash
648:
649: sub tiehash {
650: $hashtied=0;
651: if ($ENV{'request.course.fn'}) {
652: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
653: &GDBM_READER(),0640)) {
654: $hashtied=1;
655: }
656: }
657: }
658:
659: sub untiehash {
660: if ($hashtied) { untie %hash; }
661: $hashtied=0;
662: }
663:
664: # --------------------------------------------------------------- check on this
665:
666: sub checkonthis {
667: my ($r,$url,$level,$title)=@_;
668: $alreadyseen{$url}=1;
669: $r->rflush();
670: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
671: $r->print("\n<br />");
672: for (my $i=0;$i<=$level*5;$i++) {
673: $r->print(' ');
674: }
675: $r->print('<a href="'.$url.'" target="cat">'.
676: ($title?$title:$url).'</a> ');
677: if ($url=~/^\/res\//) {
678: my $result=&Apache::lonnet::repcopy(
679: &Apache::lonnet::filelocation('',$url));
680: if ($result==OK) {
681: $r->print('<font color="green">'.&mt('ok').'</font>');
682: $r->rflush();
683: &Apache::lonnet::countacc($url);
684: $url=~/\.(\w+)$/;
685: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
686: $r->print('<br />');
687: $r->rflush();
688: for (my $i=0;$i<=$level*5;$i++) {
689: $r->print(' ');
690: }
691: $r->print('- '.&mt('Rendering').': ');
692: my $oldpath=$ENV{'request.filename'};
693: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
694: &Apache::lonxml::xmlparse($r,'web',
695: &Apache::lonnet::getfile(
696: &Apache::lonnet::filelocation('',$url)));
697: undef($Apache::lonhomework::parsing_a_problem);
698: $ENV{'request.filename'}=$oldpath;
699: if (($Apache::lonxml::errorcount) ||
700: ($Apache::lonxml::warningcount)) {
701: if ($Apache::lonxml::errorcount) {
702: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
703: $Apache::lonxml::errorcount.' '.
704: &mt('error(s)').'</b></font> ');
705: }
706: if ($Apache::lonxml::warningcount) {
707: $r->print('<font color="blue">'.
708: $Apache::lonxml::warningcount.' '.
709: &mt('warning(s)').'</font>');
710: }
711: } else {
712: $r->print('<font color="green">'.&mt('ok').'</font>');
713: }
714: $r->rflush();
715: }
716: my $dependencies=
717: &Apache::lonnet::metadata($url,'dependencies');
718: foreach (split(/\,/,$dependencies)) {
719: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
720: &checkonthis($r,$_,$level+1);
721: }
722: }
723: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
724: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
725: } elsif ($result==HTTP_NOT_FOUND) {
726: unless ($url=~/\$/) {
727: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
728: } else {
729: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
730: }
731: } else {
732: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
733: }
734: }
735: }
736: }
737:
738:
739: #
740: # -------------------------------------------------------------- Verify Content
741: #
742: sub verifycontent {
743: my $r=shift;
744: my $loaderror=&Apache::lonnet::overloaderror($r);
745: if ($loaderror) { return $loaderror; }
746:
747: $r->print('<html><head><title>Verify Content</title></head>'.
748: &Apache::loncommon::bodytag('Verify Course Documents'));
749: $hashtied=0;
750: undef %alreadyseen;
751: %alreadyseen=();
752: &tiehash();
753: foreach (keys %hash) {
754: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
755: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
756: }
757: }
758: &untiehash();
759: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
760: &mt('Return to DOCS').'</a>');
761: }
762:
763: # -------------------------------------------------------------- Check Versions
764:
765: sub checkversions {
766: my $r=shift;
767: $r->print('<html><head><title>Check Versions</title></head>'.
768: &Apache::loncommon::bodytag('Check Course Document Versions'));
769: my $header='';
770: my $startsel='';
771: my $monthsel='';
772: my $weeksel='';
773: my $daysel='';
774: my $allsel='';
775: my %changes=();
776: my $starttime=0;
777: my $haschanged=0;
778: my %setversions=&Apache::lonnet::dump('resourceversions',
779: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
780: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
781:
782: $hashtied=0;
783: &tiehash();
784: my %newsetversions=();
785: if ($ENV{'form.setmostrecent'}) {
786: $haschanged=1;
787: foreach (keys %hash) {
788: if ($_=~/^ids\_(\/res\/.+)$/) {
789: $newsetversions{$1}='mostrecent';
790: }
791: }
792: } elsif ($ENV{'form.setcurrent'}) {
793: $haschanged=1;
794: foreach (keys %hash) {
795: if ($_=~/^ids\_(\/res\/.+)$/) {
796: my $getvers=&Apache::lonnet::getversion($1);
797: if ($getvers>0) {
798: $newsetversions{$1}=$getvers;
799: }
800: }
801: }
802: } elsif ($ENV{'form.setversions'}) {
803: $haschanged=1;
804: foreach (keys %ENV) {
805: if ($_=~/^form\.set_version_(.+)$/) {
806: my $src=$1;
807: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
808: $newsetversions{$src}=$ENV{$_};
809: }
810: }
811: }
812: }
813: if ($haschanged) {
814: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
815: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
816: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
817: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
818: } else {
819: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
820: }
821: &changewarning($r,'');
822: }
823: if ($ENV{'form.timerange'} eq 'all') {
824: # show all documents
825: $header=&mt('All Documents in Course');
826: $allsel=1;
827: foreach (keys %hash) {
828: if ($_=~/^ids\_(\/res\/.+)$/) {
829: my $src=$1;
830: $changes{$src}=1;
831: }
832: }
833: } else {
834: # show documents which changed
835: %changes=&Apache::lonnet::dump
836: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
837: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
838: my $firstkey=(keys %changes)[0];
839: unless ($firstkey=~/^error\:/) {
840: unless ($ENV{'form.timerange'}) {
841: $ENV{'form.timerange'}=604800;
842: }
843: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
844: .&mt('seconds');
845: if ($ENV{'form.timerange'}==-1) {
846: $seltext='since start of course';
847: $startsel='selected';
848: $ENV{'form.timerange'}=time;
849: }
850: $starttime=time-$ENV{'form.timerange'};
851: if ($ENV{'form.timerange'}==2592000) {
852: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
853: $monthsel='selected';
854: } elsif ($ENV{'form.timerange'}==604800) {
855: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
856: $weeksel='selected';
857: } elsif ($ENV{'form.timerange'}==86400) {
858: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
859: $daysel='selected';
860: }
861: $header=&mt('Content changed').' '.$seltext;
862: } else {
863: $header=&mt('No content modifications yet.');
864: }
865: }
866: %setversions=&Apache::lonnet::dump('resourceversions',
867: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
868: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
869: my %lt=&Apache::lonlocal::texthash
870: ('st' => 'Version changes since start of Course',
871: 'lm' => 'Version changes since last Month',
872: 'lw' => 'Version changes since last Week',
873: 'sy' => 'Version changes since Yesterday',
874: 'al' => 'All Resources (possibly large output)',
875: 'sd' => 'Display',
876: 'fi' => 'File',
877: 'md' => 'Modification Date',
878: 'mr' => 'Most recently published Version',
879: 've' => 'Version used in Course',
880: 'vu' => 'Set Version to be used in Course',
881: 'sv' => 'Set Versions to be used in Course according to Selections below',
882: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
883: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
884: 'di' => 'Differences');
885: $r->print(<<ENDHEADERS);
886: <form action="/adm/coursedocs" method="post">
887: <input type="hidden" name="versions" value="1" />
888: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
889: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
890: <select name="timerange">
891: <option value='all' $allsel>$lt{'al'}</option>
892: <option value="-1" $startsel>$lt{'st'}</option>
893: <option value="2592000" $monthsel>$lt{'lm'}</option>
894: <option value="604800" $weeksel>$lt{'lw'}</option>
895: <option value="86400" $daysel>$lt{'sy'}</option>
896: </select>
897: <input type="submit" name="display" value="$lt{'sd'}" />
898: <h3>$header</h3>
899: <input type="submit" name="setversions" value="$lt{'sv'}" />
900: <table border="0">
901: ENDHEADERS
902: foreach (sort keys %changes) {
903: if ($changes{$_}>$starttime) {
904: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
905: my $currentversion=&Apache::lonnet::getversion($_);
906: if ($currentversion<0) {
907: $currentversion=&mt('Could not be determined.');
908: }
909: my $linkurl=&Apache::lonnet::clutter($_);
910: $r->print(
911: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
912: &Apache::lonnet::gettitle($linkurl).
913: '</b></font></td></tr>'.
914: '<tr><td> </td>'.
915: '<td colspan="4">'.
916: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
917: '</a></td></tr>'.
918: '<tr><td></td>'.
919: '<td title="'.$lt{'md'}.'">'.
920: &Apache::lonlocal::locallocaltime(
921: &Apache::lonnet::metadata($root.'.'.$extension,
922: 'lastrevisiondate')
923: ).
924: '</td>'.
925: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
926: '<font size="+1">'.$currentversion.'</font>'.
927: '</nobr></td>'.
928: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
929: '<font size="+1">');
930: # Used in course
931: my $usedversion=$hash{'version_'.$linkurl};
932: if (($usedversion) && ($usedversion ne 'mostrecent')) {
933: $r->print($usedversion);
934: } else {
935: $r->print($currentversion);
936: }
937: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
938: '<nobr>Use: ');
939: # Set version
940: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
941: 'set_version_'.$linkurl,
942: ('' => '',
943: 'mostrecent' => 'most recent',
944: map {$_,$_} (1..$currentversion))));
945: $r->print('</nobr></td></tr><tr><td></td>');
946: my $lastold=1;
947: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
948: my $url=$root.'.'.$prevvers.'.'.$extension;
949: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
950: $starttime) {
951: $lastold=$prevvers;
952: }
953: }
954: #
955: # Code to figure out how many version entries should go in
956: # each of the four columns
957: my $entries_per_col = 0;
958: my $num_entries = ($currentversion-$lastold);
959: if ($num_entries % 4 == 0) {
960: $entries_per_col = $num_entries/4;
961: } else {
962: $entries_per_col = $num_entries/4 + 1;
963: }
964: my $entries_count = 0;
965: $r->print('<td valign="top"><font size="-2">');
966: my $cols_output = 1;
967: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
968: my $url=$root.'.'.$prevvers.'.'.$extension;
969: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
970: '">'.&mt('Version').' '.$prevvers.'</a> ('.
971: &Apache::lonlocal::locallocaltime(
972: &Apache::lonnet::metadata($url,
973: 'lastrevisiondate')
974: ).
975: ')');
976: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
977: $r->print(' <a href="/adm/diff?filename='.
978: &Apache::lonnet::clutter($root.'.'.$extension).
979: '&versionone='.$prevvers.
980: '">'.&mt('Diffs').'</a>');
981: }
982: $r->print('</nobr><br />');
983: if (++$entries_count % $entries_per_col == 0) {
984: $r->print('</font></td>');
985: if ($cols_output != 4) {
986: $r->print('<td valign="top"><font size="-2">');
987: $cols_output++;
988: }
989: }
990: }
991: while($cols_output++ < 4) {
992: $r->print('</font></td><td><font>')
993: }
994: $r->print('</font></td></tr>'."\n");
995: }
996: }
997: $r->print('</table></form>');
998: $r->print('<h1>'.&mt('Done').'.</h1>');
999:
1000: &untiehash();
1001: }
1002:
1003: sub changewarning {
1004: my ($r,$postexec)=@_;
1005: $r->print(
1006: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1007: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1008: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
1009: &Apache::lonnet::escape($ENV{'form.folderpath'}).
1010: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1011: &mt('Changes will become active for your current session after').
1012: ' <input type="hidden" name="'.
1013: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1014: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1015: $help{'Caching'}.'</font></h3></form>');
1016: }
1017:
1018: # ================================================================ Main Handler
1019: sub handler {
1020: my $r = shift;
1021: &Apache::loncommon::content_type($r,'text/html');
1022: $r->send_http_header;
1023: return OK if $r->header_only;
1024:
1025: # --------------------------------------------- Initialize help topics for this
1026: foreach ('Adding_Course_Doc','Main_Course_Documents',
1027: 'Adding_External_Resource','Navigate_Content',
1028: 'Adding_Folders','Docs_Overview', 'Load_Map',
1029: 'Supplemental', 'Score_Upload_Form',
1030: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1031: 'Check_Resource_Versions','Verify_Content') {
1032: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1033: }
1034: # Composite help files
1035: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1036: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1037: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1038: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1039: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1040: 'Option_Response_Simple');
1041: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1042: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1043: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1044: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1045: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1046:
1047: if ($ENV{'form.verify'}) {
1048: &verifycontent($r);
1049: } elsif ($ENV{'form.versions'}) {
1050: &checkversions($r);
1051: } elsif ($ENV{'form.dumpcourse'}) {
1052: &dumpcourse($r);
1053: } else {
1054: # is this a standard course?
1055:
1056: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1057: my $forcestandard;
1058: my $forcesupplement;
1059: my $script='';
1060: my $allowed;
1061: my $events='';
1062: my $showdoc=0;
1063: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1064: ['folderpath']);
1065: if ($ENV{'form.folderpath'}) {
1066: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1067: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1068: $ENV{'form.folder'}=pop(@folderpath);
1069: }
1070: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1071: $showdoc='/'.$1;
1072: }
1073: unless ($showdoc) { # got called from remote
1074: $forcestandard=($ENV{'form.folder'}=~/^default_/);
1075: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1076:
1077: # does this user have privileges to post, etc?
1078: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1079: if ($allowed) {
1080: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1081: $script=&Apache::lonratedt::editscript('simple');
1082: }
1083: } else { # got called in sequence from course
1084: $allowed=0;
1085: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1086: $events='onLoad="'.&Apache::lonmenu::loadevents.
1087: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1088: }
1089:
1090: # get course data
1091: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1092: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1093:
1094: # get personal data
1095:
1096: my $uname=$ENV{'user.name'};
1097: my $udom=$ENV{'user.domain'};
1098: my $plainname=&Apache::lonnet::escape(
1099: &Apache::loncommon::plainname($uname,$udom));
1100:
1101: # graphics settings
1102:
1103: $iconpath = $r->dir_config('lonIconsURL') . "/";
1104:
1105: my $now=time;
1106:
1107: # print screen
1108: $r->print(<<ENDDOCUMENT);
1109: <html>
1110: <head>
1111: <title>The LearningOnline Network with CAPA</title>
1112: <script>
1113: $script
1114: </script>
1115: ENDDOCUMENT
1116: if ($allowed) {
1117: $r->print(<<ENDNEWSCRIPT);
1118: <script>
1119: function makenewfolder(targetform,folderseq) {
1120: var foldername=prompt('Name of New Folder','New Folder');
1121: if (foldername) {
1122: targetform.importdetail.value=foldername+"="+folderseq;
1123: targetform.submit();
1124: }
1125: }
1126:
1127: function makenewext(targetname) {
1128: this.document.forms.extimport.useform.value=targetname;
1129: window.open('/adm/rat/extpickframe.html');
1130: }
1131:
1132: function makeexamupload() {
1133: var title=prompt('Listed Title for the Uploaded Score');
1134: if (title) {
1135: this.document.forms.newexamupload.importdetail.value=
1136: title+'=/res/lib/templates/examupload.problem';
1137: this.document.forms.newexamupload.submit();
1138: }
1139: }
1140:
1141: function makesmppage() {
1142: var title=prompt('Listed Title for the Page');
1143: if (title) {
1144: this.document.forms.newsmppg.importdetail.value=
1145: title+'=/adm/$udom/$uname/$now/smppg';
1146: this.document.forms.newsmppg.submit();
1147: }
1148: }
1149:
1150: function makesmpproblem() {
1151: var title=prompt('Listed Title for the Problem');
1152: if (title) {
1153: this.document.forms.newsmpproblem.importdetail.value=
1154: title+'=/res/lib/templates/simpleproblem.problem';
1155: this.document.forms.newsmpproblem.submit();
1156: }
1157: }
1158:
1159: function makebulboard() {
1160: var title=prompt('Listed Title for the Bulletin Board');
1161: if (title) {
1162: this.document.forms.newbul.importdetail.value=
1163: title+'=/adm/$udom/$uname/$now/bulletinboard';
1164: this.document.forms.newbul.submit();
1165: }
1166: }
1167:
1168: function makeabout() {
1169: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1170: if (user) {
1171: var comp=new Array();
1172: comp=user.split('\@');
1173: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1174: if ((comp[0]) && (comp[1])) {
1175: this.document.forms.newaboutsomeone.importdetail.value=
1176: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1177: this.document.forms.newaboutsomeone.submit();
1178: }
1179: }
1180: }
1181: }
1182:
1183: function makeims() {
1184: var caller = document.forms.ims.folder.value
1185: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1186: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1187: newWindow.location.href = newlocation
1188: }
1189:
1190:
1191: function finishpick() {
1192: var title=this.document.forms.extimport.title.value;
1193: var url=this.document.forms.extimport.url.value;
1194: var form=this.document.forms.extimport.useform.value;
1195: eval
1196: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1197: '";this.document.forms.'+form+'.submit();');
1198: }
1199:
1200: function changename(folderpath,index,oldtitle) {
1201: var title=prompt('New Title',oldtitle);
1202: if (title) {
1203: this.document.forms.renameform.title.value=title;
1204: this.document.forms.renameform.cmd.value='rename_'+index;
1205: this.document.forms.renameform.folderpath.value=folderpath;
1206: this.document.forms.renameform.submit();
1207: }
1208: }
1209:
1210: function removeres(folderpath,index,oldtitle) {
1211: if (confirm('Remove "'+oldtitle+'"?')) {
1212: this.document.forms.renameform.cmd.value='del_'+index;
1213: this.document.forms.renameform.folderpath.value=folderpath;
1214: this.document.forms.renameform.submit();
1215: }
1216: }
1217:
1218: </script>
1219:
1220: ENDNEWSCRIPT
1221: }
1222: # -------------------------------------------------------------------- Body tag
1223: $r->print('</head>'.
1224: &Apache::loncommon::bodytag('Course Documents','',$events,
1225: '','',$showdoc).
1226: &Apache::loncommon::help_open_faq(273).
1227: &Apache::loncommon::help_open_bug('RAT'));
1228: unless ($showdoc) {
1229: # -----------------------------------------------------------------------------
1230: my %lt=&Apache::lonlocal::texthash(
1231: 'uplm' => 'Upload a new main course document',
1232: 'upls' => 'Upload a new supplemental course document',
1233: 'impp' => 'Import a published document',
1234: 'spec' => 'Special documents',
1235: 'upld' => 'Upload Document',
1236: 'srch' => 'Search',
1237: 'impo' => 'Import',
1238: 'selm' => 'Select Map',
1239: 'load' => 'Load Map',
1240: 'newf' => 'New Folder',
1241: 'extr' => 'External Resource',
1242: 'syll' => 'Syllabus',
1243: 'navc' => 'Navigate Contents',
1244: 'sipa' => 'Simple Page',
1245: 'sipr' => 'Simple Problem',
1246: 'scuf' => 'Score Upload Form',
1247: 'bull' => 'Bulletin Board',
1248: 'mypi' => 'My Personal Info',
1249: 'abou' => 'About User',
1250: 'imsf' => 'Import IMS package',
1251: 'file' => 'File',
1252: 'title' => 'Title',
1253: 'comment' => 'Comment'
1254: );
1255: # -----------------------------------------------------------------------------
1256: if ($allowed) {
1257: my $dumpbut=&dumpbutton();
1258: my %lt=&Apache::lonlocal::texthash(
1259: 'vc' => 'Verify Content',
1260: 'cv' => 'Check/Set Resource Versions',
1261: );
1262:
1263: my $folderpath=$ENV{'form.folderpath'};
1264: if (!$folderpath) {
1265: if ($ENV{'form.folder'} eq '' ||
1266: $ENV{'form.folder'} eq 'supplemental') {
1267: $folderpath='default&'.
1268: &Apache::lonnet::escape(&mt('Main Course Documents'));
1269: }
1270: }
1271: $r->print(<<ENDCOURSEVERIFY);
1272: <form name="renameform" method="post" action="/adm/coursedocs">
1273: <input type="hidden" name="title" />
1274: <input type="hidden" name="cmd" />
1275: <input type="hidden" name="folderpath" />
1276: </form>
1277: <form name="simpleedit" method="post" action="/adm/coursedocs">
1278: <input type=hidden name="importdetail" value="">
1279: <input type="hidden" name="folderpath" value="$folderpath" />
1280: </form>
1281: <form action="/adm/coursedocs" method="post" name="courseverify">
1282: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
1283: <tr><td bgcolor="#DDDDCC">
1284: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1285: </td><td bgcolor="#DDDDCC">
1286: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1287: $dumpbut
1288: </td></tr></table>
1289: </form>
1290: ENDCOURSEVERIFY
1291: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1292: &mt('Editing the Table of Contents for your Course')));
1293: }
1294: # --------------------------------------------------------- Standard documents
1295: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1296: if (($standard) && ($allowed) && (!$forcesupplement)) {
1297: $r->print('<tr><td bgcolor="#BBBBBB">');
1298: # '<h2>'.&mt('Main Course Documents').
1299: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1300: my $folder=$ENV{'form.folder'};
1301: if ($folder eq '' || $folder eq 'supplemental') {
1302: $folder='default';
1303: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1304: }
1305: my $postexec='';
1306: if ($folder eq 'default') {
1307: $r->print('<script>this.window.name="loncapaclient";</script>');
1308: } else {
1309: #$postexec='self.close();';
1310: }
1311: $hadchanges=0;
1312: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1313: if ($hadchanges) {
1314: &changewarning($r,$postexec);
1315: }
1316: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
1317: '.sequence';
1318: $r->print(<<ENDFORM);
1319: <table cellspacing=4 cellpadding=4><tr>
1320: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
1321: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
1322: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1323: </tr>
1324: <tr><td bgcolor="#DDDDDD">
1325: $lt{'file'}:<br />
1326: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1327: <input type="file" name="uploaddoc" size="40">
1328: <br />
1329: $lt{'title'}:<br />
1330: <input type="text" size="50" name="comment">
1331: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1332: <input type="hidden" name="cmd" value="upload_default">
1333: <nobr>
1334: <input type="submit" value="$lt{'upld'}">
1335: $help{'Uploading_From_Harddrive'}
1336: </nobr>
1337: </form>
1338: </td>
1339: <td bgcolor="#DDDDDD">
1340: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1341: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1342: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1343: <nobr>
1344: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1345: $help{'Importing_LON-CAPA_Resource'}
1346: </nobr>
1347: <p>
1348: <hr />
1349: <input type="text" size="20" name="importmap"><br />
1350: <nobr><input type=button
1351: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1352: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1353: $help{'Load_Map'}</nobr>
1354: </p>
1355: </form>
1356: </td><td bgcolor="#DDDDDD">
1357: <form action="/adm/coursedocs" method="post" name="newfolder">
1358: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1359: <input type=hidden name="importdetail" value="">
1360: <nobr>
1361: <input name="newfolder" type="button"
1362: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1363: value="$lt{'newf'}" />$help{'Adding_Folders'}
1364: </nobr>
1365: </form>
1366: <form action="/adm/coursedocs" method="post" name="newext">
1367: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1368: <input type=hidden name="importdetail" value="">
1369: <nobr>
1370: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1371: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1372: </nobr>
1373: </form>
1374: <form action="/adm/coursedocs" method="post" name="newsyl">
1375: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1376: <input type=hidden name="importdetail"
1377: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1378: <nobr>
1379: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1380: $help{'Syllabus'}
1381: </nobr>
1382: </form>
1383: <form action="/adm/coursedocs" method="post" name="newnav">
1384: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1385: <input type=hidden name="importdetail"
1386: value="Navigate Content=/adm/navmaps">
1387: <nobr>
1388: <input name="newnav" type="submit" value="$lt{'navc'}" />
1389: $help{'Navigate_Content'}
1390: </nobr>
1391: </form>
1392: <form action="/adm/coursedocs" method="post" name="newsmppg">
1393: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1394: <input type=hidden name="importdetail" value="">
1395: <nobr>
1396: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1397: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1398: </nobr>
1399: </form>
1400: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1401: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1402: <input type=hidden name="importdetail" value="">
1403: <nobr>
1404: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1405: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1406: </nobr>
1407: </form>
1408: <form action="/adm/coursedocs" method="post" name="newexamupload">
1409: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1410: <input type=hidden name="importdetail" value="">
1411: <nobr>
1412: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1413: onClick="javascript:makeexamupload();" />
1414: $help{'Score_Upload_Form'}
1415: </nobr>
1416: </form>
1417: <form action="/adm/coursedocs" method="post" name="newbul">
1418: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1419: <input type=hidden name="importdetail" value="">
1420: <nobr>
1421: <input name="newbulletin" type="button" value="$lt{'bull'}"
1422: onClick="javascript:makebulboard();" />
1423: $help{'Bulletin Board'}
1424: </nobr>
1425: </form>
1426: <form action="/adm/coursedocs" method="post" name="newaboutme">
1427: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1428: <input type=hidden name="importdetail"
1429: value="$plainname=/adm/$udom/$uname/aboutme">
1430: <nobr>
1431: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1432: $help{'My Personal Info'}
1433: </nobr>
1434: </form>
1435: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1436: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1437: <input type=hidden name="importdetail" value="">
1438: <nobr>
1439: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
1440: onClick="javascript:makeabout();" />
1441: </nobr>
1442: </form>
1443: <form action="/adm/imsimportdocs" method="post" name="ims">
1444: <input type="hidden" name="folder" value="$folder" />
1445: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1446: </nobr>
1447: </form>
1448: </td></tr>
1449: </table>
1450: ENDFORM
1451: $r->print('</td></tr>');
1452: }
1453: # ----------------------------------------------------- Supplemental documents
1454: if (!$forcestandard) {
1455: $r->print('<tr><td bgcolor="#BBBBBB">');
1456: # '<h2>'.&mt('Supplemental Course Documents').
1457: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1458: my $folder=$ENV{'form.folder'};
1459: unless ($folder=~/^supplemental/) {
1460: $folder='supplemental';
1461: }
1462: if ($folder =~ /^supplemental$/ &&
1463: $ENV{'form.folderpath'} =~ /^default\&/) {
1464: $ENV{'form.folderpath'}='supplemental&'.
1465: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1466: }
1467: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1468: if ($allowed) {
1469: my $folderseq=
1470: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
1471: '.sequence';
1472:
1473: $r->print(<<ENDSUPFORM);
1474: <table cellspacing=4 cellpadding=4><tr>
1475: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
1476: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1477: </tr>
1478: <tr><td bgcolor="#DDDDDD">
1479: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1480: <input type="file" name="uploaddoc" size="40">
1481: <br />$lt{'comment'}:<br />
1482: <textarea cols=50 rows=4 name='comment'>
1483: </textarea>
1484: <br />
1485: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1486: <input type="hidden" name="cmd" value="upload_supplemental">
1487: <nobr>
1488: <input type="submit" value="$lt{'upld'}">
1489: $help{'Uploading_From_Harddrive'}
1490: </nobr>
1491: </form>
1492: </td>
1493: <td bgcolor="#DDDDDD">
1494: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1495: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1496: <input type=hidden name="importdetail" value="">
1497: <nobr>
1498: <input name="newfolder" type="button"
1499: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1500: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1501: </nobr>
1502: </form>
1503: <form action="/adm/coursedocs" method="post" name="supnewext">
1504: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1505: <input type=hidden name="importdetail" value="">
1506: <nobr>
1507: <input name="newext" type="button"
1508: onClick="javascript:makenewext('supnewext');"
1509: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1510: </nobr>
1511: </form>
1512: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1513: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1514: <input type=hidden name="importdetail"
1515: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1516: <nobr>
1517: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1518: $help{'Syllabus'}
1519: </nobr>
1520: </form>
1521: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1522: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1523: <input type=hidden name="importdetail"
1524: value="$plainname=/adm/$udom/$uname/aboutme">
1525: <nobr>
1526: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1527: $help{'My Personal Info'}
1528: </nobr>
1529: </form>
1530: </td></tr>
1531: </table></td></tr>
1532: ENDSUPFORM
1533: }
1534: }
1535: if ($allowed) {
1536: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
1537: }
1538: $r->print('</table>');
1539: } else {
1540: # -------------------------------------------------------- This is showdoc mode
1541: $r->print("<h1>".&mt('Uploaded Document').'</h1><p>'.
1542: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1543: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1544: }
1545: }
1546: $r->print('</body></html>');
1547: return OK;
1548: }
1549:
1550: 1;
1551: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>