1: # Copyright Michigan State University Board of Trustees
2: #
3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
4: #
5: # LON-CAPA is free software; you can redistribute it and/or modify
6: # it under the terms of the GNU General Public License as published by
7: # the Free Software Foundation; either version 2 of the License, or
8: # (at your option) any later version.
9: #
10: # LON-CAPA is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with LON-CAPA; if not, write to the Free Software
17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: #
19: # /home/httpd/html/adm/gpl.txt
20: #
21: # http://www.lon-capa.org/
22: #
23:
24: package Apache::portfolio;
25: use strict;
26: use Apache::Constants qw(:common :http);
27: use Apache::loncommon;
28: use Apache::lonnet;
29: use Apache::lontexconvert;
30: use Apache::lonfeedback;
31: use Apache::lonlocal;
32:
33: # receives a file name and path stub from username/userfiles/portfolio/
34: # returns an anchor tag consisting encoding filename and currentpath
35: sub make_anchor {
36: my ($filename, $current_path, $current_mode, $field_name) = @_;
37: my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'¤tpath='.$current_path.'&mode='.$current_mode.'&fieldname='.$field_name.'">'.$filename.'</a>';
38: return $anchor;
39: }
40: my $dirptr=16384;
41: sub display_common {
42: my ($r,$current_path,$is_empty,$dir_list)=@_;
43: my $iconpath= $r->dir_config('lonIconsURL') . "/";
44: $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
45: $r->print('<td bgcolor="#ccddaa" align="center">');
46: my $displayOut = '<form method="post" enctype="multipart/form-data">';
47: $displayOut .= '<input name="uploaddoc" type="file" />'.
48: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
49: '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
50: '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
51: '<input type="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'.
52: '<input type="submit" name="storeupl" value="Upload" />'.
53: '</form>';
54: $r->print($displayOut);
55: $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
56: $displayOut = '<form method="post">';
57: $displayOut .= '<input name="newdir" type="input" />'.
58: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
59: '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
60: '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
61: '<input type="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'.
62: '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
63: '</form>';
64: $r->print($displayOut);
65: $r->print('</td></tr></table>');
66: my @tree = split (/\//,$current_path);
67: $r->print('<font size="+2">'.&make_anchor('portfolio','/',$ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
68: if (@tree > 1){
69: my $newCurrentPath = '';
70: for (my $i = 1; $i< @tree; $i++){
71: $newCurrentPath .= $tree[$i].'/';
72: $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
73: }
74: }
75: $r->print('</font>');
76: &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
77: $r->print('<br /><form method=post action="/adm/portfolio?mode='.$ENV{"form.mode"}.'&fieldname='.$ENV{"form.fieldname"}.'">'.
78: &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
79: 'this.form.submit();'));
80: $r->print("</form>");
81: }
82: sub display_directory {
83: my ($r,$current_path,$is_empty,$dir_list)=@_;
84: my $iconpath= $r->dir_config('lonIconsURL') . "/";
85: my $display_out;
86: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($ENV{'user.domain'},$ENV{'user.name'});
87: if ($is_empty && ($current_path ne '/')) {
88: $display_out = '<form method="post" action="/adm/portfolio">'.
89: '<input type="hidden" name="action" value="deletedir" />'.
90: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
91: '<input type="hidden" name="selectfile" value="" />'.
92: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
93: '</form>';
94:
95: $r->print($display_out);
96: return;
97: }
98: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
99: '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
100: my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
101: $r->print('<form method="post" action="/adm/portfolio">');
102: foreach my $line (sort
103: {
104: my ($afile)=split('&',$a,2);
105: my ($bfile)=split('&',$b,2);
106: return (lc($afile) cmp lc($bfile));
107: } (@$dir_list)) {
108: #$strip holds directory/file name
109: #$dom
110: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
111: if (($filename ne '.') && ($filename ne '..')) {
112: if ($dirptr&$testdir) {
113: $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
114: $r->print('<td>Go to ...</td>');
115: $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>');
116: $r->print('</tr>');
117: } else {
118: $r->print('<tr bgcolor="#CCCCFF">');
119: if (exists $locked_files{$current_path.$filename}){
120: $r->print('<td colspan="2">Locked</td>');
121: } else {
122: $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
123: <a href="/adm/portfolio?rename='.$filename.'&currentpath='.$current_path.'">Rename</a></td>
124: <td><a href="/adm/portfolio?meta='.$filename.'&currentpath='.$current_path.'">Meta</a>
125: </td>');
126: }
127: $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
128: $r->print('<td><a href="'.$href_location.$filename.'">'.
129: $filename.'</a></td>');
130: $r->print('<td>'.$size.'</td>');
131: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
132: $r->print('</tr>');
133: }
134: }
135: }
136: # <tr bgcolor="#FFAA99"> pink bg
137: # <tr bgcolor="#CCCCFF"> blue bg
138: # $r->print(&display_directory($current_path, $currentFile, @dir_list));
139: # $r->print('</td>><td>');
140: # $r->print(&display_actions($current_path, $currentFile, $isEmpty));
141: $r->print('</table>
142: <input type="submit" name="doit" value="Delete Checked Files" />
143: <input type="hidden" name="action" value="delete" />
144: <input type="hidden" name="currentpath" value="'.$current_path.'" />
145: </form>');
146: }
147: sub display_file_select {
148: my ($r,$current_path,$is_empty,$dir_list)=@_;
149: my $iconpath= $r->dir_config('lonIconsURL') . "/";
150: my $display_out;
151: my $checked_files = &Apache::lonnet::files_in_path($ENV{'user.name'}, $ENV{'form.currentpath'});
152: if ($is_empty && ($current_path ne '/')) {
153: $display_out = '<form method="post" action="/adm/portfolio">'.
154: '<input type="hidden" name="action" value="deletedir" />'.
155: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
156: '<input type="hidden" name="selectfile" value="" />'.
157: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
158:
159: '</form>';
160:
161: $r->print($display_out);
162: return;
163: }
164: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
165: '<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
166: my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
167: $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
168: foreach my $line (sort
169: {
170: my ($afile)=split('&',$a,2);
171: my ($bfile)=split('&',$b,2);
172: return (lc($afile) cmp lc($bfile));
173: } (@$dir_list)) {
174: #$strip holds directory/file name
175: #$dom
176: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
177: $filename =~ s/\s+$//;
178: if (($filename ne '.') && ($filename ne '..')) {
179: if ($dirptr&$testdir) {
180: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
181: $r->print('<td>Go to ...</td>');
182: $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>');
183: $r->print('</tr>');
184: } else {
185: $r->print('<tr bgcolor="#CCCCFF">');
186: $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'"');
187: if ($$checked_files{$filename} eq 'selected') {
188: $r->print("CHECKED");
189: }
190: $r->print('></td>');
191: $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
192: $r->print('<td><a href="'.$href_location.$filename.'">'.
193: $filename.'</a></td>');
194: $r->print('<td>'.$size.'</td>');
195: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
196: $r->print('</tr>');
197: }
198: }
199: }
200: $r->print('</table>
201: <input type="hidden" name="continue" value="true">
202: <input type="hidden" name="fieldname" value="'.$ENV{'form.fieldname'}.'">
203: <input type="hidden" name="mode" value="selectfile">
204: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
205: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
206: <input type="hidden" name="currentpath" value="'.$current_path.'" />
207: </form>');
208: }
209: sub prettyinput {
210: my ($type,$value,$fieldname,$formname,
211: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
212: if (! defined($size)) {
213: $size = 80;
214: }
215: # Language
216: if ($type eq 'language') {
217: return &Apache::lonmeta::selectbox($fieldname,
218: $value,
219: \&Apache::loncommon::languagedescription,
220: (&Apache::loncommon::languageids)).
221: &relatedfield(0,$relatedsearchflag,$relatedsep);
222: }
223: # Copyright
224: if ($type eq 'copyright') {
225: return &Apache::lonmeta::selectbox($fieldname,
226: $value,
227: \&Apache::loncommon::copyrightdescription,
228: (&Apache::loncommon::copyrightids)).
229: &relatedfield(0,$relatedsearchflag,$relatedsep);
230: }
231: # Source Copyright
232: if ($type eq 'sourceavail') {
233: return &Apache::lonmeta::selectbox($fieldname,
234: $value,
235: \&Apache::loncommon::source_copyrightdescription,
236: (&Apache::loncommon::source_copyrightids)).
237: &relatedfield(0,$relatedsearchflag,$relatedsep);
238: }
239: # Gradelevels
240: if (($type eq 'lowestgradelevel') ||
241: ($type eq 'highestgradelevel')) {
242: return &Apache::loncommon::select_level_form($value,$fieldname).
243: &relatedfield(0,$relatedsearchflag,$relatedsep);
244: }
245: # Obsolete
246: if ($type eq 'obsolete') {
247: return '<input type="checkbox" name="'.$fieldname.'"'.
248: ($value?' checked="1"':'').' />'.
249: &relatedfield(0,$relatedsearchflag,$relatedsep);
250: }
251: # Obsolete replacement file
252: if ($type eq 'obsoletereplacement') {
253: return '<input type="text" name="'.$fieldname.
254: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
255: "('".$formname."','".$fieldname."'".
256: ",'')\">".&mt('Select').'</a>'.
257: &relatedfield(0,$relatedsearchflag,$relatedsep);
258: }
259: # Customdistribution file
260: if ($type eq 'customdistributionfile') {
261: return '<input type="text" name="'.$fieldname.
262: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
263: "('".$formname."','".$fieldname."'".
264: ",'rights')\">".&mt('Select').'</a>'.
265: &relatedfield(0,$relatedsearchflag,$relatedsep);
266: }
267: # Source Customdistribution file
268: if ($type eq 'sourcerights') {
269: return '<input type="text" name="'.$fieldname.
270: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
271: "('".$formname."','".$fieldname."'".
272: ",'rights')\">".&mt('Select').'</a>'.
273: &relatedfield(0,$relatedsearchflag,$relatedsep);
274: }
275: # Dates
276: if (($type eq 'creationdate') ||
277: ($type eq 'lastrevisiondate')) {
278: return
279: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
280: &relatedfield(0,$relatedsearchflag,$relatedsep);
281: }
282: # No pretty input found
283: $value=~s/^\s+//gs;
284: $value=~s/\s+$//gs;
285: $value=~s/\s+/ /gs;
286: $value=~s/\"/\"\;/gs;
287: return
288: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
289: 'value="'.$value.'" />'.
290: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
291: $relatedvalue);
292: }
293:
294: sub relatedfield {
295: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
296: if (! $relatedsearchflag) {
297: return '';
298: }
299: if (! defined($relatedsep)) {
300: $relatedsep=' ';
301: }
302: if (! $show) {
303: return $relatedsep.' ';
304: }
305: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
306: ($relatedvalue?' checked="1"':'').' />';
307: }
308:
309:
310: # The field names
311: sub fieldnames {
312: return &Apache::lonlocal::texthash
313: (
314: 'title' => 'Title',
315: 'author' =>'Author(s)',
316: 'authorspace' => 'Author Space',
317: 'modifyinguser' => 'Last Modifying User',
318: 'subject' => 'Subject',
319: 'keywords' => 'Keyword(s)',
320: 'notes' => 'Notes',
321: 'abstract' => 'Abstract',
322: 'lowestgradelevel' => 'Lowest Grade Level',
323: 'highestgradelevel' => 'Highest Grade Level',
324: 'standards' => 'Standards',
325: 'mime' => 'MIME Type',
326: 'language' => 'Language',
327: 'creationdate' => 'Creation Date',
328: 'lastrevisiondate' => 'Last Revision Date',
329: 'owner' => 'Publisher/Owner',
330: 'copyright' => 'Copyright/Distribution',
331: 'customdistributionfile' => 'Custom Distribution File',
332: 'sourceavail' => 'Source Available',
333: 'sourcerights' => 'Source Custom Distribution File',
334: 'obsolete' => 'Obsolete',
335: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
336: 'count' => 'Network-wide number of accesses (hits)',
337: 'course' => 'Network-wide number of courses using resource',
338: 'course_list' => 'Network-wide courses using resource',
339: 'sequsage' => 'Number of resources using or importing resource',
340: 'sequsage_list' => 'Resources using or importing resource',
341: 'goto' => 'Number of resources that follow this resource in maps',
342: 'goto_list' => 'Resources that follow this resource in maps',
343: 'comefrom' => 'Number of resources that lead up to this resource in maps',
344: 'comefrom_list' => 'Resources that lead up to this resource in maps',
345: 'clear' => 'Material presented in clear way',
346: 'depth' => 'Material covered with sufficient depth',
347: 'helpful' => 'Material is helpful',
348: 'correct' => 'Material appears to be correct',
349: 'technical' => 'Resource is technically correct',
350: 'avetries' => 'Average number of tries till solved',
351: 'stdno' => 'Total number of students who have worked on this problem',
352: 'difficulty' => 'Degree of difficulty',
353: 'disc' => 'Degree of discrimination',
354: 'dependencies' => 'Resources used by this resource',
355: );
356: }
357:
358: sub edit_meta_data {
359: my ($r,$uri) = @_;
360: # Construction Space Call
361: # Header
362: my $disuri=$uri;
363: my $fn=&Apache::lonnet::filelocation('',$uri);
364: $disuri=~s/^\/\~/\/priv\//;
365: $disuri=~s/\.meta$//;
366: my $target=$uri;
367: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
368: $target=~s/\.meta$//;
369: $r->print('<script language="JavaScript">'.
370: &Apache::loncommon::browser_and_searcher_javascript().
371: '</script>');
372: my %lt=&fieldnames();
373: my $output;
374: foreach ('author','title','subject','keywords','abstract','notes',
375: 'copyright','customdistributionfile','language',
376: 'standards',
377: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
378: 'obsolete','obsoletereplacement') {
379: if (defined($ENV{'form.new_'.$_})) {
380: $Apache::lonpublisher::metadatafields{$_}=
381: $ENV{'form.new_'.$_};
382: }
383: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
384: $Apache::lonpublisher::metadatafields{'copyright'}=
385: 'default';
386: }
387: $output.=('<p>'.$lt{$_}.': '.
388: &prettyinput($_,
389: $Apache::lonpublisher::metadatafields{$_},
390: 'new_'.$_,'defaultmeta').'</p>');
391: }
392: return $output;
393: }
394: sub open_form {
395: my ($r)=@_;
396: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
397: $r->print('<form method="post" action="/adm/portfolio">');
398: $r->print('<input type="hidden" name="action" value="'.
399: $ENV{'form.action'}.'" />');
400: $r->print('<input type="hidden" name="confirmed" value="1" />');
401: foreach (@files) {
402: $r->print('<input type="hidden" name="selectfile" value="'.
403: $_.'" />');
404: }
405: $r->print('<input type="hidden" name="currentpath" value="'.
406: $ENV{'form.currentpath'}.'" />');
407: }
408:
409: sub close_form {
410: my ($r)=@_;
411: $r->print('<p><input type="submit" value="'.&mt('Continue').
412: '" /></p></form>');
413: $r->print('<form action="/adm/portfolio" method="POST">
414: <p>
415: <input type="hidden" name="currentpath" value="'.
416: $ENV{'form.currentpath'}.'" />
417: <input type="submit" value="'.&mt('Cancel').'" />
418: </p></form>');
419:
420: }
421:
422: sub display_file {
423: my ($path,$filename)=@_;
424: my $display_file_text;
425: if (!defined($path)) { $path=$ENV{'form.currentpath'}; }
426: if (!defined($filename)) {
427: $filename=$ENV{'form.selectfile'};
428: $display_file_text = '<tt>'.$path.$filename.'</tt>';
429: } elsif (ref($filename) eq "ARRAY") {
430: foreach (@$filename) {
431: $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
432: }
433: } elsif (ref($filename) eq "SCALAR") {
434: $display_file_text = '<tt>'.$path.$filename.'</tt>';
435: }
436: return $display_file_text;
437: }
438:
439: sub done {
440: return ('<h3><a href="/adm/portfolio?currentpath='.
441: $ENV{'form.currentpath'}.
442: '&fieldname='.$ENV{'form.fieldname'}.
443: '&mode='.$ENV{'form.mode'}.
444: '">'.&mt('Done').'</a></h3>');
445: }
446:
447: sub delete {
448: my ($r)=@_;
449: my @check;
450: my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
451: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
452:
453: if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
454: $r->print ("The file is locked and cannot be deleted.<br />");
455: $r->print(&done());
456: } else {
457: if (scalar(@files)) {
458: &open_form($r);
459: $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
460: &close_form($r);
461: } else {
462: $r->print("No file was checked to delete.<br />");
463: $r->print(&done());
464: }
465: }
466: }
467:
468: sub delete_confirmed {
469: my ($r)=@_;
470: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
471: my $result;
472: foreach my $delete_file (@files) {
473: $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
474: $ENV{'user.domain'},'portfolio'.
475: $ENV{'form.currentpath'}.
476: $delete_file);
477: if ($result ne 'ok') {
478: $r->print('<font color="red"> An error occured ('.$result.
479: ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
480: }
481: }
482: $r->print(&done());
483: }
484:
485: sub delete_dir {
486: my ($r)=@_;
487: &open_form($r);
488: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
489: &close_form($r);
490: }
491:
492: sub delete_dir_confirmed {
493: my ($r)=@_;
494: my $directory_name = $ENV{'form.currentpath'};
495: $directory_name =~ m/\/$/;
496: $directory_name = $`;
497: my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
498: $ENV{'user.domain'},'portfolio'.
499: $directory_name);
500:
501: if ($result ne 'ok') {
502: $r->print('<font color="red"> An error occured (dir) ('.$result.
503: ') while trying to delete '.$directory_name.'</font><br />');
504: } else {
505: # now remove from recent
506: # $r->print('<br /> removing '.$directory_name.'<br /');
507: &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
508: my @dirs = split m!/!, $directory_name;
509:
510: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
511: $directory_name='/';
512: for (my $i=1; $i < (@dirs - 1); $i ++){
513: $directory_name .= $dirs[$i].'/';
514: }
515: $ENV{'form.currentpath'} = $directory_name;
516: }
517: $r->print(&done());
518: }
519:
520: sub rename {
521: my ($r)=@_;
522: my $file_name = $ENV{'form.currentpath'}.$ENV{'form.rename'};
523: if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'}) eq 'true') {
524: $r->print ("The file is locked and cannot be renamed.<br />");
525: $r->print(&done());
526: } else {
527: &open_form($r);
528: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
529: <input name="filenewname" type="input" size="50" />?</p>');
530: &close_form($r);
531: }
532: }
533:
534: sub rename_confirmed {
535: my ($r)=@_;
536: my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
537: if ($filenewname eq '') {
538: $r->print('<font color="red">'.
539: &mt("Error: no valid filename was provided to rename to.").
540: '</font><br />');
541: $r->print(&done());
542: return;
543: }
544: my $result=
545: &Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
546: 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
547: 'portfolio'.$ENV{'form.currentpath'}.$filenewname);
548: if ($result ne 'ok') {
549: $r->print('<font color="red"> An errror occured ('.$result.
550: ') while trying to rename '.&display_file().' to '.
551: &display_file(undef,$filenewname).'</font><br />');
552: }
553: if ($filenewname ne $ENV{'form.filenewname'}) {
554: $r->print("The new file name was changed from:<br /><strong>".$ENV{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
555: }
556: $r->print(&done());
557: }
558: sub select_files {
559: my ($r)=@_;
560: if ($ENV{'form.continue'} eq 'true') {
561: # here we update the selections for the currentpath
562: # eventually, have to handle removing those not checked, but . . .
563: my @items=&Apache::loncommon::get_env_multiple('form.selectfile');
564: &Apache::lonnet::save_selected_files($ENV{'user.name'}, $ENV{'form.currentpath'}, @items);
565: } else {
566: if ($ENV{'form.currentpath'} eq '/') {
567: #empty the file for a fresh start
568: # &Apache::lonnet::clear_selected_files($ENV{'user.name'});
569: }
570: }
571: my @files = &Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'});
572: my $java_files = join ",", @files;
573: if ($java_files) {
574: $java_files.=',';
575: }
576: my $javascript =(<<ENDSMP);
577: <script language='javascript'>
578: function finishSelect() {
579: ENDSMP
580: $javascript .= 'fileList = "'.$java_files.'";';
581: $javascript .= (<<ENDSMP);
582: for (i=0;i<document.forms.checkselect.length;i++) {
583: if (document.forms.checkselect[i].checked){
584: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
585: }
586: }
587: opener.document.forms.lonhomework.
588: ENDSMP
589: $javascript .= $ENV{'form.fieldname'};
590: $javascript .= (<<ENDSMP);
591: .value=fileList;
592: self.close();
593: }
594: </script>
595: ENDSMP
596: $r->print($javascript);
597: $r->print("<h1>Select portfolio files</h1>
598: Check as many as you wish in response to the essay problem.<br />");
599: $r->print("<strong>Files selected from other directories:</strong><br />");
600: foreach (&Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'})) {
601: $r->print($_."<br />");
602: }
603: }
604: sub upload {
605: my ($r)=@_;
606: my $fname=$ENV{'form.uploaddoc.filename'};
607: my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
608: my $disk_quota = 20000; # expressed in k
609: $fname=&Apache::lonnet::clean_filename($fname);
610: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
611: $ENV{'user.name'}).
612: '/userfiles/portfolio';
613: # Fixme --- Move the checking for existing file to LOND error return
614: my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
615: $ENV{'user.domain'},
616: $ENV{'user.name'},$portfolio_root);
617: my $found_file = 0;
618: foreach my $line (@dir_list) {
619: my ($filename)=split(/\&/,$line,2);
620: if ($filename eq $fname){
621: $found_file = 1;
622: }
623: }
624: my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
625: if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
626: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
627: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
628: }
629: elsif ($found_file){
630: $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'.
631: '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
632: } else {
633: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
634: 'portfolio'.$ENV{'form.currentpath'});
635: if ($result !~ m|^/uploaded/|) {
636: $r->print('<font color="red"> An errror occured ('.$result.
637: ') while trying to upload '.&display_file().'</font><br />');
638: }
639: }
640: $r->print(&done());
641: }
642:
643: sub createdir {
644: my ($r)=@_;
645: my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
646: if ($newdir eq '') {
647: $r->print('<font color="red">'.
648: &mt("Error: no directory name was provided.").
649: '</font><br />');
650: $r->print(&done());
651: return;
652: }
653: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
654: $ENV{'user.name'}).
655: '/userfiles/portfolio';
656: my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
657: $ENV{'user.domain'},
658: $ENV{'user.name'},$portfolio_root);
659: my $found_file = 0;
660: foreach my $line (@dir_list) {
661: my ($filename)=split(/\&/,$line,2);
662: if ($filename eq $newdir){
663: $found_file = 1;
664: }
665: }
666: if ($found_file){
667: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
668: ' </strong>a file or directory by that name already exists.</font><br />');
669: } else {
670: my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
671: $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
672: if ($result ne 'ok') {
673: $r->print('<font color="red"> An errror occured ('.$result.
674: ') while trying to create a new directory '.&display_file().'</font><br />');
675: }
676: }
677: if ($newdir ne $ENV{'form.newdir'}) {
678: $r->print("The new directory name was changed from:<br /><strong>".$ENV{'form.newdir'}."</strong> to <strong>$newdir </strong>");
679: }
680: $r->print(&done());
681: }
682:
683: sub handler {
684: # this handles file management
685: my $r = shift;
686: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
687: $ENV{'user.name'}).
688: '/userfiles/portfolio';
689: &Apache::loncommon::no_cache($r);
690: &Apache::loncommon::content_type($r,'text/html');
691: $r->send_http_header;
692: # Give the LON-CAPA page header
693: $r->print('<html><head><title>'.
694: &mt('Portfolio Manager').
695: "</title></head>\n".
696: &Apache::loncommon::bodytag('Portfolio Manager'));
697: $r->rflush();
698: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
699: ['selectfile','currentpath','meta',
700: 'currentfile','action','fieldname','mode','rename']);
701: if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
702: $r->print('<font color="red"> No file was selected to upload.'.
703: 'To upload a file, click <strong>Browse...</strong>'.
704: ', select a file, then click <strong>Upload</strong>,</font>');
705: }
706: if ($ENV{'form.meta'}) {
707: &open_form($r);
708: $r->print(&edit_meta_data($r, $ENV{'form.currentpath'}.$ENV{'form.selectfile'}));
709: $r->print('Edit the meta data<br />');
710: &close_form($r);
711: }
712: if ($ENV{'form.store'}) {
713: }
714:
715: if ($ENV{'form.uploaddoc.filename'}) {
716: &upload($r);
717: } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
718: &delete_confirmed($r);
719: } elsif ($ENV{'form.action'} eq 'delete') {
720: &delete($r);
721: } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
722: &delete_dir_confirmed($r);
723: } elsif ($ENV{'form.action'} eq 'deletedir'){
724: &delete_dir($r);
725: } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
726: &rename_confirmed($r);
727: } elsif ($ENV{'form.rename'}) {
728: $ENV{'form.selectfile'} = $ENV{'form.rename'};
729: $ENV{'form.action'} = 'rename';
730: &rename($r);
731: } elsif ($ENV{'form.createdir'}) {
732: &createdir($r);
733: } else {
734: my $current_path='/';
735: if ($ENV{'form.currentpath'}) {
736: $current_path = $ENV{'form.currentpath'};
737: }
738: my @dir_list=&Apache::lonnet::dirlist($current_path,
739: $ENV{'user.domain'},
740: $ENV{'user.name'},$portfolio_root);
741: if ($dir_list[0] eq 'no_such_dir'){
742: # two main reasons for this:
743: # 1) never been here, so directory structure not created
744: # 2) back-button navigation after deleting a directory
745: if ($current_path eq '/'){
746: &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
747: $ENV{'user.domain'},'portfolio');
748: } else {
749: # some directory that snuck in get rid of the directory
750: # from the recent pulldown, just in case
751: &Apache::lonhtmlcommon::remove_recent('portfolio',
752: [$current_path]);
753: $current_path = '/'; # force it back to the root
754: }
755: # now grab the directory list again, for the first time
756: @dir_list=&Apache::lonnet::dirlist($current_path,
757: $ENV{'user.domain'},
758: $ENV{'user.name'},$portfolio_root);
759: }
760: # need to know if directory is empty so it can be removed if desired
761: my $is_empty=(@dir_list == 2);
762: &display_common($r,$current_path,$is_empty,\@dir_list);
763: if ($ENV{"form.mode"} eq 'selectfile'){
764: &select_files($r);
765: &display_file_select($r,$current_path,$is_empty,\@dir_list);
766: } else {
767: &display_directory($r,$current_path,$is_empty,\@dir_list);
768: }
769: $r->print("</body>\n</html>\n");
770: return OK;
771: }
772: }
773: 1;
774: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>