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