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