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