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