Annotation of loncom/interface/londocs.pm, revision 1.16
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.16 ! www 4: # $Id: londocs.pm,v 1.15 2002/09/02 15:27:08 www 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;
32: use Apache::Constants qw(:common);
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.7 www 38:
1.8 www 39: my $iconpath;
1.7 www 40:
41: # Mapread read maps into lonratedt::global arrays
1.10 www 42: # @order and @resources, determines status
1.7 www 43: # sets @order - pointer to resources in right order
44: # sets @resources - array with the resources with correct idx
45: #
46:
47: sub mapread {
48: my ($coursenum,$coursedom,$map)=@_;
49: return
50: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
51: $map);
52: }
53:
54: sub storemap {
55: my ($coursenum,$coursedom,$map)=@_;
56: return
57: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15 www 58: $map,1);
1.7 www 59: }
60:
61: sub editor {
62: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.10 www 63: my $errtext='';
64: my $fatal=0;
65: ($errtext,$fatal)=
1.7 www 66: &mapread($coursenum,$coursedom,$folder.'.sequence');
67: if ($fatal) {
68: $r->print('<p><font color="red">'.$errtext.'</font></p>');
69: } else {
70: # ------------------------------------------------------------ Process commands
1.16 ! www 71: # ---------------- if they are for this folder and user allowed to make changes
! 72: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.10 www 73: # upload a file, if present
74: if (($ENV{'form.uploaddoc.filename'}) &&
75: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
76: if ($folder=~/^$1/) {
77: # this is for a course, not a user, so set coursedoc flag
78: # probably the only place in the system where this should be "1"
79: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
80: my $ext='false';
81: if ($url=~/^http\:\/\//) { $ext='true'; }
82: $url=~s/\:/\:/g;
83: my $comment=$ENV{'form.comment'};
84: $comment=~s/\</\<\;/g;
85: $comment=~s/\>/\>\;/g;
86: $comment=~s/\:/\:/g;
87: my $newidx=$#Apache::lonratedt::resources+1;
88: $Apache::lonratedt::resources[$newidx]=
89: $comment.':'.$url.':'.$ext.':normal:res';
90: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
91: $newidx;
92: &storemap($coursenum,$coursedom,$folder.'.sequence');
93: }
94: }
1.8 www 95: if ($ENV{'form.cmd'}) {
1.10 www 96: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
97: if ($cmd eq 'del') {
98: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
99: $Apache::lonratedt::order[$i]=
100: $Apache::lonratedt::order[$i+1];
101: }
102: $#Apache::lonratedt::order--;
103: } elsif ($cmd eq 'up') {
104: my $i=$Apache::lonratedt::order[$idx-1];
105: $Apache::lonratedt::order[$idx-1]=
106: $Apache::lonratedt::order[$idx];
107: $Apache::lonratedt::order[$idx]=$i;
108: } elsif ($cmd eq 'down') {
109: my $i=$Apache::lonratedt::order[$idx+1];
110: $Apache::lonratedt::order[$idx+1]=
111: $Apache::lonratedt::order[$idx];
112: $Apache::lonratedt::order[$idx]=$i;
113: }
114: # Store the changed version
115: &storemap($coursenum,$coursedom,$folder.'.sequence');
1.8 www 116: }
1.11 www 117: # Group import/search
118: if ($ENV{'form.importdetail'}) {
119: foreach (split(/\&/,$ENV{'form.importdetail'})) {
120: if (defined($_)) {
121: my ($name,$url)=split(/\=/,$_);
122: $name=&Apache::lonnet::unescape($name);
123: $url=&Apache::lonnet::unescape($url);
124: if ($url) {
125: my $idx=$#Apache::lonratedt::resources+1;
126: $Apache::lonratedt::order
127: [$#Apache::lonratedt::order+1]=$idx;
128: my $ext='false';
129: if ($url=~/^http\:\/\//) { $ext='true'; }
130: $url=~s/\:/\:/g;
131: $Apache::lonratedt::resources[$idx]=
132: $name.':'.$url.':'.$ext.':normal:res';
133: }
134: }
135: }
136: # Store the changed version
137: &storemap($coursenum,$coursedom,$folder.'.sequence');
138: }
1.16 ! www 139: }
! 140: # ---------------------------------------------------------------- End commands
1.7 www 141: # ---------------------------------------------------------------- Print screen
1.10 www 142: my $idx=0;
143: $r->print('<table>');
144: foreach (@Apache::lonratedt::order) {
145: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
146: unless ($name) { $name=(split(/\//,$url))[-1]; }
147: unless ($name) { $name='EMPTY'; }
148: $r->print(&entryline($idx,$name,$url,$folder,$allowed));
149: $idx++;
150: }
151: $r->print('</table>');
1.7 www 152: }
153: }
1.1 www 154:
1.8 www 155: # --------------------------------------------------------------- An entry line
156:
157: sub entryline {
158: my ($index,$title,$url,$folder,$allowed)=@_;
159: my $line='<tr>';
160: # Edit commands
161: if ($allowed) {
162: $line.=(<<END);
163: <td><table border='0' cellspacing='0' cellpadding='0'>
164: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
165: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
166: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
167: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
168: </table></td><td>
169: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
170: END
171: }
1.16 ! www 172: # Figure out what kind of a resource this is
! 173: my ($extension)=($url=~/\.(\w+)$/);
! 174: my $uploaded=($url=~/^\/*uploaded\//);
! 175: my $icon='unknown';
! 176: if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
! 177: $icon=$extension;
1.10 www 178: }
1.16 ! www 179: if ($uploaded) {
! 180: if ($extension eq 'sequence') {
! 181: $icon='folder_closed';
! 182: $url=~/\/(\w+)\.sequence/;
! 183: $url='/adm/coursedocs?folder='.$1;
! 184: } else {
! 185: $url=&Apache::lonnet::tokenwrapper($url);
! 186: }
! 187: }
! 188: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="/adm/lonIcons/'.
! 189: $icon.'.gif" border="0"></a></td>';
1.8 www 190: # Title
191: $title=&Apache::lonnet::unescape($title);
192: if ($title=~
193: /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
194: ) { $title='<i>'.localtime($1).'</i> '.$2.' at '.$3.': <br>'.
195: &Apache::lontexconvert::msgtexconverted($4);
196: }
1.16 ! www 197: $line.="<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.8 www 198: $line.='</tr>';
199: return $line;
200: }
201:
202: # ================================================================ Main Handler
1.1 www 203: sub handler {
204: my $r = shift;
205: $r->content_type('text/html');
206: $r->send_http_header;
207: return OK if $r->header_only;
208:
1.7 www 209: # is this a standard course?
210:
211: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.15 www 212: my $forcestandard;
213: my $forcesupplement;
214: my $script='';
215: my $allowed;
216: my $events='';
217: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
218: ['folder','showdoc']);
219: unless ($ENV{'form.showdoc'}) { # got called from remote
220: $forcestandard=($ENV{'form.folder'}=~/^default_/);
221: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 222:
1.4 www 223: # does this user have privileges to post, etc?
1.15 www 224: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
225: if ($allowed) {
226: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
227: $script=&Apache::lonratedt::editscript('simple');
228: }
229: } else { # got called in sequence from course
230: $allowed=0;
231: $forcestandard=1;
232: $forcesupplement=0;
233: $script=&Apache::&Apache::lonxml::registerurl(1,undef);
234: $events='onLoad="'.&Apache::lonxml::loadevents.
235: '" onUnload="'.&Apache::lonxml::unloadevents.'"';
1.3 www 236: }
1.4 www 237:
238: # get course data
239: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
240: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
241:
1.14 www 242: # get personal data
243:
244: my $uname=$ENV{'user.name'};
245: my $udom=$ENV{'user.domain'};
246: my $plainname=&Apache::lonnet::escape(
247: &Apache::loncommon::plainname($uname,$udom));
248:
1.8 www 249: # graphics settings
1.4 www 250:
1.8 www 251: $iconpath = $r->dir_config('lonIconsURL') . "/";
252:
1.4 www 253: # print screen
1.1 www 254: $r->print(<<ENDDOCUMENT);
255: <html>
256: <head>
257: <title>The LearningOnline Network with CAPA</title>
1.16 ! www 258: <script>
! 259: $script
! 260:
! 261: function makenewfolder(targetform,folderseq) {
! 262: var foldername=prompt('Name of New Folder','New Folder');
! 263: if (foldername) {
! 264: targetform.importdetail.value=foldername+"="+folderseq;
! 265: targetform.submit();
! 266: }
! 267: }
! 268:
! 269: function makenewext(targetform) {
! 270: }
! 271: </script>
1.1 www 272: </head>
1.4 www 273: ENDDOCUMENT
1.15 www 274: $r->print(&Apache::loncommon::bodytag('Course Documents','',$events));
1.7 www 275: # --------------------------------------------------0------ Standard documents
276: if (($standard) && ($allowed) && (!$forcesupplement)) {
277: $r->print('<h2>Main Course Documents</h2>');
278: my $folder=$ENV{'form.folder'};
1.10 www 279: unless ($folder=~/^default/) { $folder='default'; }
1.7 www 280: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.16 ! www 281: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
! 282: '.sequence';
1.8 www 283: $r->print(<<ENDFORM);
1.16 ! www 284: <table cellspacing=2><tr>
! 285: <th bgcolor="#DDDDDD">Upload a new main course document</th>
! 286: <th bgcolor="#DDDDDD">Import a published document</th>
! 287: <th bgcolor="#DDDDDD">Special documents</th>
1.11 www 288: </tr>
1.16 ! www 289: <tr><td bgcolor="#DDDDDD">
1.11 www 290: File:<br />
1.10 www 291: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.8 www 292: <input type="file" name="uploaddoc" size="50">
293: <br />
1.11 www 294: Title:<br />
295: <input type="text" size="50" name="comment">
1.8 www 296: <input type="hidden" name="folder" value="$folder">
1.10 www 297: <input type="hidden" name="cmd" value="upload_default">
1.8 www 298: <input type="submit" value="Upload Document">
299: </form>
1.11 www 300: </td>
1.16 ! www 301: <td bgcolor="#DDDDDD">
1.11 www 302: <form action="/adm/coursedocs" method="post" name="simpleedit">
1.16 ! www 303: <input type="hidden" name="folder" value="$folder">
1.11 www 304: <input type=hidden name="importdetail" value="">
305: <input type=button onClick=
1.16 ! www 306: "javascript:groupsearch()" value="Search">
1.11 www 307: <input type=button onClick=
1.16 ! www 308: "javascript:groupimport();" value="Import">
1.11 www 309: </form>
1.16 ! www 310: </td><td bgcolor="#DDDDDD">
1.11 www 311: <form action="/adm/coursedocs" method="post" name="newfolder">
1.16 ! www 312: <input type="hidden" name="folder" value="$folder">
1.13 www 313: <input type=hidden name="importdetail" value="">
1.16 ! www 314: <input name="newfolder" type="button"
! 315: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.11 www 316: value="New Folder" />
317: </form>
318: <form action="/adm/coursedocs" method="post" name="newext">
1.16 ! www 319: <input type="hidden" name="folder" value="$folder">
1.13 www 320: <input type=hidden name="importdetail" value="">
1.16 ! www 321: <input name="newext" type="button" onClick="javascript:makenewext(this.form);"
1.11 www 322: value="External Resource" />
323: </form>
324: <form action="/adm/coursedocs" method="post" name="newsyl">
1.16 ! www 325: <input type="hidden" name="folder" value="$folder">
1.14 www 326: <input type=hidden name="importdetail"
327: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
328: <input name="newsyl" type="submit" value="Syllabus" />
1.15 www 329: </form>
330: <form action="/adm/coursedocs" method="post" name="newsyl">
331: <input type=hidden name="importdetail"
332: value="Navigate Content=/adm/navmaps">
333: <input name="newsyl" type="submit" value="Navigate Content" />
1.12 www 334: </form>
335: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.16 ! www 336: <input type="hidden" name="folder" value="$folder">
1.14 www 337: <input type=hidden name="importdetail"
338: value="$plainname=/adm/$udom/$uname/aboutme">
1.16 ! www 339: <input name="newaboutme" type="submit" value="My Personal Info" />
1.11 www 340: </form>
341: </td></tr>
342: </table>
1.8 www 343: ENDFORM
1.7 www 344: $r->print('<hr />');
345: }
346: # ----------------------------------------------------- Supplemental documents
347: if (!$forcestandard) {
348: $r->print('<h2>Supplemental Course Documents</h2>');
349: my $folder=$ENV{'form.folder'};
1.10 www 350: unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7 www 351: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 352: if ($allowed) {
353: $r->print(<<ENDSUPFORM);
354: <h3>Post a new supplemental course document</h3>
1.10 www 355: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.4 www 356: <input type="file" name="uploaddoc" size="50">
357: <br />Comment:<br />
358: <textarea cols=50 rows=4 name='comment'>
359: </textarea>
1.8 www 360: <input type="hidden" name="folder" value="$folder">
1.10 www 361: <input type="hidden" name="cmd" value="upload_supplemental">
1.3 www 362: <input type="submit" value="Upload Document">
363: </form>
1.8 www 364: ENDSUPFORM
365: }
1.7 www 366: }
367:
1.4 www 368: $r->print('</body></html>');
1.1 www 369: return OK;
370: }
371:
372: 1;
373: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>