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