1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.136 2004/08/03 20:44:33 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: my ($mode)=@_;
654: $hashtied=0;
655: if ($ENV{'request.course.fn'}) {
656: if ($mode eq 'write') {
657: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
658: &GDBM_WRCREAT(),0640)) {
659: $hashtied=2;
660: }
661: } else {
662: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
663: &GDBM_READER(),0640)) {
664: $hashtied=1;
665: }
666: }
667: }
668: }
669:
670: sub untiehash {
671: if ($hashtied) { untie %hash; }
672: $hashtied=0;
673: }
674:
675: # --------------------------------------------------------------- check on this
676:
677: sub checkonthis {
678: my ($r,$url,$level,$title)=@_;
679: $alreadyseen{$url}=1;
680: $r->rflush();
681: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
682: $r->print("\n<br />");
683: for (my $i=0;$i<=$level*5;$i++) {
684: $r->print(' ');
685: }
686: $r->print('<a href="'.$url.'" target="cat">'.
687: ($title?$title:$url).'</a> ');
688: if ($url=~/^\/res\//) {
689: my $result=&Apache::lonnet::repcopy(
690: &Apache::lonnet::filelocation('',$url));
691: if ($result==OK) {
692: $r->print('<font color="green">'.&mt('ok').'</font>');
693: $r->rflush();
694: &Apache::lonnet::countacc($url);
695: $url=~/\.(\w+)$/;
696: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
697: $r->print('<br />');
698: $r->rflush();
699: for (my $i=0;$i<=$level*5;$i++) {
700: $r->print(' ');
701: }
702: $r->print('- '.&mt('Rendering').': ');
703: my $oldpath=$ENV{'request.filename'};
704: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
705: &Apache::lonxml::xmlparse($r,'web',
706: &Apache::lonnet::getfile(
707: &Apache::lonnet::filelocation('',$url)));
708: undef($Apache::lonhomework::parsing_a_problem);
709: $ENV{'request.filename'}=$oldpath;
710: if (($Apache::lonxml::errorcount) ||
711: ($Apache::lonxml::warningcount)) {
712: if ($Apache::lonxml::errorcount) {
713: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
714: $Apache::lonxml::errorcount.' '.
715: &mt('error(s)').'</b></font> ');
716: }
717: if ($Apache::lonxml::warningcount) {
718: $r->print('<font color="blue">'.
719: $Apache::lonxml::warningcount.' '.
720: &mt('warning(s)').'</font>');
721: }
722: } else {
723: $r->print('<font color="green">'.&mt('ok').'</font>');
724: }
725: $r->rflush();
726: }
727: my $dependencies=
728: &Apache::lonnet::metadata($url,'dependencies');
729: foreach (split(/\,/,$dependencies)) {
730: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
731: &checkonthis($r,$_,$level+1);
732: }
733: }
734: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
735: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
736: } elsif ($result==HTTP_NOT_FOUND) {
737: unless ($url=~/\$/) {
738: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
739: } else {
740: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
741: }
742: } else {
743: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
744: }
745: }
746: }
747: }
748:
749:
750: #
751: # -------------------------------------------------------------- Verify Content
752: #
753: sub verifycontent {
754: my $r=shift;
755: my $loaderror=&Apache::lonnet::overloaderror($r);
756: if ($loaderror) { return $loaderror; }
757:
758: $r->print('<html><head><title>Verify Content</title></head>'.
759: &Apache::loncommon::bodytag('Verify Course Documents'));
760: $hashtied=0;
761: undef %alreadyseen;
762: %alreadyseen=();
763: &tiehash();
764: foreach (keys %hash) {
765: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
766: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
767: }
768: }
769: &untiehash();
770: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
771: &mt('Return to DOCS').'</a>');
772: }
773:
774: # -------------------------------------------------------------- Check Versions
775:
776: sub checkversions {
777: my $r=shift;
778: $r->print('<html><head><title>Check Versions</title></head>'.
779: &Apache::loncommon::bodytag('Check Course Document Versions'));
780: my $header='';
781: my $startsel='';
782: my $monthsel='';
783: my $weeksel='';
784: my $daysel='';
785: my $allsel='';
786: my %changes=();
787: my $starttime=0;
788: my $haschanged=0;
789: my %setversions=&Apache::lonnet::dump('resourceversions',
790: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
791: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
792:
793: $hashtied=0;
794: &tiehash();
795: my %newsetversions=();
796: if ($ENV{'form.setmostrecent'}) {
797: $haschanged=1;
798: foreach (keys %hash) {
799: if ($_=~/^ids\_(\/res\/.+)$/) {
800: $newsetversions{$1}='mostrecent';
801: }
802: }
803: } elsif ($ENV{'form.setcurrent'}) {
804: $haschanged=1;
805: foreach (keys %hash) {
806: if ($_=~/^ids\_(\/res\/.+)$/) {
807: my $getvers=&Apache::lonnet::getversion($1);
808: if ($getvers>0) {
809: $newsetversions{$1}=$getvers;
810: }
811: }
812: }
813: } elsif ($ENV{'form.setversions'}) {
814: $haschanged=1;
815: foreach (keys %ENV) {
816: if ($_=~/^form\.set_version_(.+)$/) {
817: my $src=$1;
818: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
819: $newsetversions{$src}=$ENV{$_};
820: }
821: }
822: }
823: }
824: if ($haschanged) {
825: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
826: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
827: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
828: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
829: } else {
830: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
831: }
832: &mark_hash_old();
833: }
834: &changewarning($r,'');
835: if ($ENV{'form.timerange'} eq 'all') {
836: # show all documents
837: $header=&mt('All Documents in Course');
838: $allsel=1;
839: foreach (keys %hash) {
840: if ($_=~/^ids\_(\/res\/.+)$/) {
841: my $src=$1;
842: $changes{$src}=1;
843: }
844: }
845: } else {
846: # show documents which changed
847: %changes=&Apache::lonnet::dump
848: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
849: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
850: my $firstkey=(keys %changes)[0];
851: unless ($firstkey=~/^error\:/) {
852: unless ($ENV{'form.timerange'}) {
853: $ENV{'form.timerange'}=604800;
854: }
855: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
856: .&mt('seconds');
857: if ($ENV{'form.timerange'}==-1) {
858: $seltext='since start of course';
859: $startsel='selected';
860: $ENV{'form.timerange'}=time;
861: }
862: $starttime=time-$ENV{'form.timerange'};
863: if ($ENV{'form.timerange'}==2592000) {
864: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
865: $monthsel='selected';
866: } elsif ($ENV{'form.timerange'}==604800) {
867: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
868: $weeksel='selected';
869: } elsif ($ENV{'form.timerange'}==86400) {
870: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
871: $daysel='selected';
872: }
873: $header=&mt('Content changed').' '.$seltext;
874: } else {
875: $header=&mt('No content modifications yet.');
876: }
877: }
878: %setversions=&Apache::lonnet::dump('resourceversions',
879: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
880: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
881: my %lt=&Apache::lonlocal::texthash
882: ('st' => 'Version changes since start of Course',
883: 'lm' => 'Version changes since last Month',
884: 'lw' => 'Version changes since last Week',
885: 'sy' => 'Version changes since Yesterday',
886: 'al' => 'All Resources (possibly large output)',
887: 'sd' => 'Display',
888: 'fi' => 'File',
889: 'md' => 'Modification Date',
890: 'mr' => 'Most recently published Version',
891: 've' => 'Version used in Course',
892: 'vu' => 'Set Version to be used in Course',
893: 'sv' => 'Set Versions to be used in Course according to Selections below',
894: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
895: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
896: 'di' => 'Differences');
897: $r->print(<<ENDHEADERS);
898: <form action="/adm/coursedocs" method="post">
899: <input type="hidden" name="versions" value="1" />
900: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
901: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
902: <select name="timerange">
903: <option value='all' $allsel>$lt{'al'}</option>
904: <option value="-1" $startsel>$lt{'st'}</option>
905: <option value="2592000" $monthsel>$lt{'lm'}</option>
906: <option value="604800" $weeksel>$lt{'lw'}</option>
907: <option value="86400" $daysel>$lt{'sy'}</option>
908: </select>
909: <input type="submit" name="display" value="$lt{'sd'}" />
910: <h3>$header</h3>
911: <input type="submit" name="setversions" value="$lt{'sv'}" />
912: <table border="0">
913: ENDHEADERS
914: foreach (sort keys %changes) {
915: if ($changes{$_}>$starttime) {
916: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
917: my $currentversion=&Apache::lonnet::getversion($_);
918: if ($currentversion<0) {
919: $currentversion=&mt('Could not be determined.');
920: }
921: my $linkurl=&Apache::lonnet::clutter($_);
922: $r->print(
923: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
924: &Apache::lonnet::gettitle($linkurl).
925: '</b></font></td></tr>'.
926: '<tr><td> </td>'.
927: '<td colspan="4">'.
928: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
929: '</a></td></tr>'.
930: '<tr><td></td>'.
931: '<td title="'.$lt{'md'}.'">'.
932: &Apache::lonlocal::locallocaltime(
933: &Apache::lonnet::metadata($root.'.'.$extension,
934: 'lastrevisiondate')
935: ).
936: '</td>'.
937: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
938: '<font size="+1">'.$currentversion.'</font>'.
939: '</nobr></td>'.
940: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
941: '<font size="+1">');
942: # Used in course
943: my $usedversion=$hash{'version_'.$linkurl};
944: if (($usedversion) && ($usedversion ne 'mostrecent')) {
945: $r->print($usedversion);
946: } else {
947: $r->print($currentversion);
948: }
949: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
950: '<nobr>Use: ');
951: # Set version
952: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
953: 'set_version_'.$linkurl,
954: ('select_form_order' =>
955: ['',1..$currentversion,'mostrecent'],
956: '' => '',
957: 'mostrecent' => 'most recent',
958: map {$_,$_} (1..$currentversion))));
959: $r->print('</nobr></td></tr><tr><td></td>');
960: my $lastold=1;
961: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
962: my $url=$root.'.'.$prevvers.'.'.$extension;
963: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
964: $starttime) {
965: $lastold=$prevvers;
966: }
967: }
968: #
969: # Code to figure out how many version entries should go in
970: # each of the four columns
971: my $entries_per_col = 0;
972: my $num_entries = ($currentversion-$lastold);
973: if ($num_entries % 4 == 0) {
974: $entries_per_col = $num_entries/4;
975: } else {
976: $entries_per_col = $num_entries/4 + 1;
977: }
978: my $entries_count = 0;
979: $r->print('<td valign="top"><font size="-2">');
980: my $cols_output = 1;
981: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
982: my $url=$root.'.'.$prevvers.'.'.$extension;
983: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
984: '">'.&mt('Version').' '.$prevvers.'</a> ('.
985: &Apache::lonlocal::locallocaltime(
986: &Apache::lonnet::metadata($url,
987: 'lastrevisiondate')
988: ).
989: ')');
990: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
991: $r->print(' <a href="/adm/diff?filename='.
992: &Apache::lonnet::clutter($root.'.'.$extension).
993: '&versionone='.$prevvers.
994: '">'.&mt('Diffs').'</a>');
995: }
996: $r->print('</nobr><br />');
997: if (++$entries_count % $entries_per_col == 0) {
998: $r->print('</font></td>');
999: if ($cols_output != 4) {
1000: $r->print('<td valign="top"><font size="-2">');
1001: $cols_output++;
1002: }
1003: }
1004: }
1005: while($cols_output++ < 4) {
1006: $r->print('</font></td><td><font>')
1007: }
1008: $r->print('</font></td></tr>'."\n");
1009: }
1010: }
1011: $r->print('</table></form>');
1012: $r->print('<h1>'.&mt('Done').'.</h1>');
1013:
1014: &untiehash();
1015: }
1016:
1017: sub mark_hash_old {
1018: my $retie_hash=0;
1019: if ($hashtied) {
1020: $retie_hash=1;
1021: &untiehash();
1022: }
1023: &tiehash('write');
1024: $hash{'old'}=1;
1025: &untiehash();
1026: if ($retie_hash) { &tiehash(); }
1027: }
1028:
1029: sub is_hash_old {
1030: my $untie_hash=0;
1031: if (!$hashtied) {
1032: $untie_hash=1;
1033: &tiehash();
1034: }
1035: my $return=$hash{'old'};
1036: if ($untie_hash) { &untiehash(); }
1037: return $return;
1038: }
1039:
1040: sub changewarning {
1041: my ($r,$postexec)=@_;
1042: if (!&is_hash_old()) { return; }
1043: $r->print(
1044: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1045: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1046: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
1047: &Apache::lonnet::escape($ENV{'form.folderpath'}).
1048: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1049: &mt('Changes will become active for your current session after').
1050: ' <input type="hidden" name="'.
1051: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1052: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1053: $help{'Caching'}.'</font></h3></form>');
1054: }
1055:
1056: # ================================================================ Main Handler
1057: sub handler {
1058: my $r = shift;
1059: &Apache::loncommon::content_type($r,'text/html');
1060: $r->send_http_header;
1061: return OK if $r->header_only;
1062:
1063: # --------------------------------------------- Initialize help topics for this
1064: foreach ('Adding_Course_Doc','Main_Course_Documents',
1065: 'Adding_External_Resource','Navigate_Content',
1066: 'Adding_Folders','Docs_Overview', 'Load_Map',
1067: 'Supplemental', 'Score_Upload_Form',
1068: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1069: 'Check_Resource_Versions','Verify_Content') {
1070: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1071: }
1072: # Composite help files
1073: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1074: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1075: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1076: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1077: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1078: 'Option_Response_Simple');
1079: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1080: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1081: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1082: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1083: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1084:
1085: if ($ENV{'form.verify'}) {
1086: &verifycontent($r);
1087: } elsif ($ENV{'form.versions'}) {
1088: &checkversions($r);
1089: } elsif ($ENV{'form.dumpcourse'}) {
1090: &dumpcourse($r);
1091: } else {
1092: # is this a standard course?
1093:
1094: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1095: my $forcestandard;
1096: my $forcesupplement;
1097: my $script='';
1098: my $allowed;
1099: my $events='';
1100: my $showdoc=0;
1101: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1102: ['folderpath']);
1103: if ($ENV{'form.folderpath'}) {
1104: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1105: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1106: $ENV{'form.folder'}=pop(@folderpath);
1107: }
1108: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1109: $showdoc='/'.$1;
1110: }
1111: unless ($showdoc) { # got called from remote
1112: $forcestandard=($ENV{'form.folder'}=~/^default_/);
1113: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1114:
1115: # does this user have privileges to post, etc?
1116: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1117: if ($allowed) {
1118: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1119: $script=&Apache::lonratedt::editscript('simple');
1120: }
1121: } else { # got called in sequence from course
1122: $allowed=0;
1123: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1124: $events='onLoad="'.&Apache::lonmenu::loadevents.
1125: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1126: }
1127:
1128: # get course data
1129: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1130: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1131:
1132: # get personal data
1133:
1134: my $uname=$ENV{'user.name'};
1135: my $udom=$ENV{'user.domain'};
1136: my $plainname=&Apache::lonnet::escape(
1137: &Apache::loncommon::plainname($uname,$udom));
1138:
1139: # graphics settings
1140:
1141: $iconpath = $r->dir_config('lonIconsURL') . "/";
1142:
1143: my $now=time;
1144:
1145: # print screen
1146: $r->print(<<ENDDOCUMENT);
1147: <html>
1148: <head>
1149: <title>The LearningOnline Network with CAPA</title>
1150: <script>
1151: $script
1152: </script>
1153: ENDDOCUMENT
1154: if ($allowed) {
1155: $r->print(<<ENDNEWSCRIPT);
1156: <script>
1157: function makenewfolder(targetform,folderseq) {
1158: var foldername=prompt('Name of New Folder','New Folder');
1159: if (foldername) {
1160: targetform.importdetail.value=foldername+"="+folderseq;
1161: targetform.submit();
1162: }
1163: }
1164:
1165: function makenewext(targetname) {
1166: this.document.forms.extimport.useform.value=targetname;
1167: window.open('/adm/rat/extpickframe.html');
1168: }
1169:
1170: function makeexamupload() {
1171: var title=prompt('Listed Title for the Uploaded Score');
1172: if (title) {
1173: this.document.forms.newexamupload.importdetail.value=
1174: title+'=/res/lib/templates/examupload.problem';
1175: this.document.forms.newexamupload.submit();
1176: }
1177: }
1178:
1179: function makesmppage() {
1180: var title=prompt('Listed Title for the Page');
1181: if (title) {
1182: this.document.forms.newsmppg.importdetail.value=
1183: title+'=/adm/$udom/$uname/$now/smppg';
1184: this.document.forms.newsmppg.submit();
1185: }
1186: }
1187:
1188: function makesmpproblem() {
1189: var title=prompt('Listed Title for the Problem');
1190: if (title) {
1191: this.document.forms.newsmpproblem.importdetail.value=
1192: title+'=/res/lib/templates/simpleproblem.problem';
1193: this.document.forms.newsmpproblem.submit();
1194: }
1195: }
1196:
1197: function makebulboard() {
1198: var title=prompt('Listed Title for the Bulletin Board');
1199: if (title) {
1200: this.document.forms.newbul.importdetail.value=
1201: title+'=/adm/$udom/$uname/$now/bulletinboard';
1202: this.document.forms.newbul.submit();
1203: }
1204: }
1205:
1206: function makeabout() {
1207: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1208: if (user) {
1209: var comp=new Array();
1210: comp=user.split('\@');
1211: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1212: if ((comp[0]) && (comp[1])) {
1213: this.document.forms.newaboutsomeone.importdetail.value=
1214: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1215: this.document.forms.newaboutsomeone.submit();
1216: }
1217: }
1218: }
1219: }
1220:
1221: function makeims() {
1222: var caller = document.forms.ims.folder.value
1223: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1224: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1225: newWindow.location.href = newlocation
1226: }
1227:
1228:
1229: function finishpick() {
1230: var title=this.document.forms.extimport.title.value;
1231: var url=this.document.forms.extimport.url.value;
1232: var form=this.document.forms.extimport.useform.value;
1233: eval
1234: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1235: '";this.document.forms.'+form+'.submit();');
1236: }
1237:
1238: function changename(folderpath,index,oldtitle) {
1239: var title=prompt('New Title',oldtitle);
1240: if (title) {
1241: this.document.forms.renameform.title.value=title;
1242: this.document.forms.renameform.cmd.value='rename_'+index;
1243: this.document.forms.renameform.folderpath.value=folderpath;
1244: this.document.forms.renameform.submit();
1245: }
1246: }
1247:
1248: function removeres(folderpath,index,oldtitle) {
1249: if (confirm('Remove "'+oldtitle+'"?')) {
1250: this.document.forms.renameform.cmd.value='del_'+index;
1251: this.document.forms.renameform.folderpath.value=folderpath;
1252: this.document.forms.renameform.submit();
1253: }
1254: }
1255:
1256: </script>
1257:
1258: ENDNEWSCRIPT
1259: }
1260: # -------------------------------------------------------------------- Body tag
1261: $r->print('</head>'.
1262: &Apache::loncommon::bodytag('Course Documents','',$events,
1263: '','',$showdoc).
1264: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1265: unless ($showdoc) {
1266: # -----------------------------------------------------------------------------
1267: my %lt=&Apache::lonlocal::texthash(
1268: 'uplm' => 'Upload a new main course document',
1269: 'upls' => 'Upload a new supplemental course document',
1270: 'impp' => 'Import a published document',
1271: 'spec' => 'Special documents',
1272: 'upld' => 'Upload Document',
1273: 'srch' => 'Search',
1274: 'impo' => 'Import',
1275: 'selm' => 'Select Map',
1276: 'load' => 'Load Map',
1277: 'newf' => 'New Folder',
1278: 'extr' => 'External Resource',
1279: 'syll' => 'Syllabus',
1280: 'navc' => 'Navigate Contents',
1281: 'sipa' => 'Simple Page',
1282: 'sipr' => 'Simple Problem',
1283: 'scuf' => 'Score Upload Form',
1284: 'bull' => 'Bulletin Board',
1285: 'mypi' => 'My Personal Info',
1286: 'abou' => 'About User',
1287: 'imsf' => 'Import IMS package',
1288: 'file' => 'File',
1289: 'title' => 'Title',
1290: 'comment' => 'Comment'
1291: );
1292: # -----------------------------------------------------------------------------
1293: if ($allowed) {
1294: my $dumpbut=&dumpbutton();
1295: my %lt=&Apache::lonlocal::texthash(
1296: 'vc' => 'Verify Content',
1297: 'cv' => 'Check/Set Resource Versions',
1298: );
1299:
1300: my $folderpath=$ENV{'form.folderpath'};
1301: if (!$folderpath) {
1302: if ($ENV{'form.folder'} eq '' ||
1303: $ENV{'form.folder'} eq 'supplemental') {
1304: $folderpath='default&'.
1305: &Apache::lonnet::escape(&mt('Main Course Documents'));
1306: }
1307: }
1308: $r->print(<<ENDCOURSEVERIFY);
1309: <form name="renameform" method="post" action="/adm/coursedocs">
1310: <input type="hidden" name="title" />
1311: <input type="hidden" name="cmd" />
1312: <input type="hidden" name="folderpath" />
1313: </form>
1314: <form name="simpleedit" method="post" action="/adm/coursedocs">
1315: <input type=hidden name="importdetail" value="">
1316: <input type="hidden" name="folderpath" value="$folderpath" />
1317: </form>
1318: <form action="/adm/coursedocs" method="post" name="courseverify">
1319: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
1320: <tr><td bgcolor="#DDDDCC">
1321: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1322: </td><td bgcolor="#DDDDCC">
1323: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1324: $dumpbut
1325: </td></tr></table>
1326: </form>
1327: ENDCOURSEVERIFY
1328: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1329: &mt('Editing the Table of Contents for your Course')));
1330: }
1331: # --------------------------------------------------------- Standard documents
1332: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1333: if (($standard) && ($allowed) && (!$forcesupplement)) {
1334: $r->print('<tr><td bgcolor="#BBBBBB">');
1335: # '<h2>'.&mt('Main Course Documents').
1336: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1337: my $folder=$ENV{'form.folder'};
1338: if ($folder eq '' || $folder eq 'supplemental') {
1339: $folder='default';
1340: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1341: }
1342: my $postexec='';
1343: if ($folder eq 'default') {
1344: $r->print('<script>this.window.name="loncapaclient";</script>');
1345: } else {
1346: #$postexec='self.close();';
1347: }
1348: $hadchanges=0;
1349: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1350: if ($hadchanges) {
1351: &mark_hash_old()
1352: }
1353: &changewarning($r,$postexec);
1354: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
1355: '.sequence';
1356: $r->print(<<ENDFORM);
1357: <table cellspacing=4 cellpadding=4><tr>
1358: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
1359: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
1360: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1361: </tr>
1362: <tr><td bgcolor="#DDDDDD">
1363: $lt{'file'}:<br />
1364: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1365: <input type="file" name="uploaddoc" size="40">
1366: <br />
1367: $lt{'title'}:<br />
1368: <input type="text" size="50" name="comment">
1369: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1370: <input type="hidden" name="cmd" value="upload_default">
1371: <nobr>
1372: <input type="submit" value="$lt{'upld'}">
1373: $help{'Uploading_From_Harddrive'}
1374: </nobr>
1375: </form>
1376: </td>
1377: <td bgcolor="#DDDDDD">
1378: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1379: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1380: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1381: <nobr>
1382: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1383: $help{'Importing_LON-CAPA_Resource'}
1384: </nobr>
1385: <p>
1386: <hr />
1387: <input type="text" size="20" name="importmap"><br />
1388: <nobr><input type=button
1389: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1390: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1391: $help{'Load_Map'}</nobr>
1392: </p>
1393: </form>
1394: </td><td bgcolor="#DDDDDD">
1395: <form action="/adm/coursedocs" method="post" name="newfolder">
1396: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1397: <input type=hidden name="importdetail" value="">
1398: <nobr>
1399: <input name="newfolder" type="button"
1400: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1401: value="$lt{'newf'}" />$help{'Adding_Folders'}
1402: </nobr>
1403: </form>
1404: <form action="/adm/coursedocs" method="post" name="newext">
1405: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1406: <input type=hidden name="importdetail" value="">
1407: <nobr>
1408: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1409: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1410: </nobr>
1411: </form>
1412: <form action="/adm/coursedocs" method="post" name="newsyl">
1413: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1414: <input type=hidden name="importdetail"
1415: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1416: <nobr>
1417: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1418: $help{'Syllabus'}
1419: </nobr>
1420: </form>
1421: <form action="/adm/coursedocs" method="post" name="newnav">
1422: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1423: <input type=hidden name="importdetail"
1424: value="Navigate Content=/adm/navmaps">
1425: <nobr>
1426: <input name="newnav" type="submit" value="$lt{'navc'}" />
1427: $help{'Navigate_Content'}
1428: </nobr>
1429: </form>
1430: <form action="/adm/coursedocs" method="post" name="newsmppg">
1431: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1432: <input type=hidden name="importdetail" value="">
1433: <nobr>
1434: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1435: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1436: </nobr>
1437: </form>
1438: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1439: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1440: <input type=hidden name="importdetail" value="">
1441: <nobr>
1442: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1443: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1444: </nobr>
1445: </form>
1446: <form action="/adm/coursedocs" method="post" name="newexamupload">
1447: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1448: <input type=hidden name="importdetail" value="">
1449: <nobr>
1450: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1451: onClick="javascript:makeexamupload();" />
1452: $help{'Score_Upload_Form'}
1453: </nobr>
1454: </form>
1455: <form action="/adm/coursedocs" method="post" name="newbul">
1456: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1457: <input type=hidden name="importdetail" value="">
1458: <nobr>
1459: <input name="newbulletin" type="button" value="$lt{'bull'}"
1460: onClick="javascript:makebulboard();" />
1461: $help{'Bulletin Board'}
1462: </nobr>
1463: </form>
1464: <form action="/adm/coursedocs" method="post" name="newaboutme">
1465: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1466: <input type=hidden name="importdetail"
1467: value="$plainname=/adm/$udom/$uname/aboutme">
1468: <nobr>
1469: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1470: $help{'My Personal Info'}
1471: </nobr>
1472: </form>
1473: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1474: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1475: <input type=hidden name="importdetail" value="">
1476: <nobr>
1477: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
1478: onClick="javascript:makeabout();" />
1479: </nobr>
1480: </form>
1481: <form action="/adm/imsimportdocs" method="post" name="ims">
1482: <input type="hidden" name="folder" value="$folder" />
1483: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1484: </nobr>
1485: </form>
1486: </td></tr>
1487: </table>
1488: ENDFORM
1489: $r->print('</td></tr>');
1490: }
1491: # ----------------------------------------------------- Supplemental documents
1492: if (!$forcestandard) {
1493: $r->print('<tr><td bgcolor="#BBBBBB">');
1494: # '<h2>'.&mt('Supplemental Course Documents').
1495: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1496: my $folder=$ENV{'form.folder'};
1497: unless ($folder=~/^supplemental/) {
1498: $folder='supplemental';
1499: }
1500: if ($folder =~ /^supplemental$/ &&
1501: $ENV{'form.folderpath'} =~ /^default\&/) {
1502: $ENV{'form.folderpath'}='supplemental&'.
1503: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1504: }
1505: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1506: if ($allowed) {
1507: my $folderseq=
1508: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
1509: '.sequence';
1510:
1511: $r->print(<<ENDSUPFORM);
1512: <table cellspacing=4 cellpadding=4><tr>
1513: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
1514: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1515: </tr>
1516: <tr><td bgcolor="#DDDDDD">
1517: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1518: <input type="file" name="uploaddoc" size="40">
1519: <br />$lt{'comment'}:<br />
1520: <textarea cols=50 rows=4 name='comment'>
1521: </textarea>
1522: <br />
1523: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1524: <input type="hidden" name="cmd" value="upload_supplemental">
1525: <nobr>
1526: <input type="submit" value="$lt{'upld'}">
1527: $help{'Uploading_From_Harddrive'}
1528: </nobr>
1529: </form>
1530: </td>
1531: <td bgcolor="#DDDDDD">
1532: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1533: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1534: <input type=hidden name="importdetail" value="">
1535: <nobr>
1536: <input name="newfolder" type="button"
1537: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1538: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1539: </nobr>
1540: </form>
1541: <form action="/adm/coursedocs" method="post" name="supnewext">
1542: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1543: <input type=hidden name="importdetail" value="">
1544: <nobr>
1545: <input name="newext" type="button"
1546: onClick="javascript:makenewext('supnewext');"
1547: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1548: </nobr>
1549: </form>
1550: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1551: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1552: <input type=hidden name="importdetail"
1553: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1554: <nobr>
1555: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1556: $help{'Syllabus'}
1557: </nobr>
1558: </form>
1559: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1560: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1561: <input type=hidden name="importdetail"
1562: value="$plainname=/adm/$udom/$uname/aboutme">
1563: <nobr>
1564: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1565: $help{'My Personal Info'}
1566: </nobr>
1567: </form>
1568: </td></tr>
1569: </table></td></tr>
1570: ENDSUPFORM
1571: }
1572: }
1573: if ($allowed) {
1574: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
1575: }
1576: $r->print('</table>');
1577: } else {
1578: # -------------------------------------------------------- This is showdoc mode
1579: $r->print("<h1>".&mt('Uploaded Document').'</h1><p>'.
1580: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1581: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1582: }
1583: }
1584: $r->print('</body></html>');
1585: return OK;
1586: }
1587:
1588: 1;
1589: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>