File:
[LON-CAPA] /
loncom /
interface /
portfolio.pm
Revision
1.163:
download - view:
text,
annotated -
select for diffs
Tue Sep 19 14:02:42 2006 UTC (17 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
When "aboutme" page is called for a course, link to listing of group portfolio files is available. Page containing listing now separates files by group, and includes working links to files (with metadata CAT button).
1: # The LearningOnline Network
2: # portfolio browser
3: #
4: # $Id: portfolio.pm,v 1.163 2006/09/19 14:02:42 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::portfolio;
30: use strict;
31: use Apache::Constants qw(:common :http);
32: use Apache::loncommon;
33: use Apache::lonnet;
34: use Apache::lontexconvert;
35: use Apache::lonfeedback;
36: use Apache::lonlocal;
37: use Apache::lonnet;
38: use Apache::longroup;
39: use Apache::lonhtmlcommon;
40: use HTML::Entities;
41: use LONCAPA;
42:
43: sub group_args {
44: my $output;
45: if (defined($env{'form.group'})) {
46: $output .= '&group='.$env{'form.group'};
47: if (defined($env{'form.ref'})) {
48: $output .= '&ref='.$env{'form.ref'};
49: }
50: }
51: return $output;
52: }
53:
54: sub group_form_data {
55: my $output;
56: if (defined($env{'form.group'})) {
57: $output = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
58: if (exists($env{'form.ref'})) {
59: $output .= '<input type="hidden" name="ref" value="'.
60: $env{'form.ref'}.'" />';
61: }
62: }
63: return $output;
64: }
65:
66: # receives a file name and path stub from username/userfiles/portfolio/
67: # returns an anchor tag consisting encoding filename and currentpath
68: sub make_anchor {
69: my ($url, $anchor_fields, $inner_text) = @_;
70: if ($$anchor_fields{'continue'} ne 'true') {$$anchor_fields{'continue'} = 'false'};
71: my $anchor = '<a href="'.$url.'?';
72: foreach my $field_name (keys(%$anchor_fields)) {
73: $anchor .= $field_name.'='.$$anchor_fields{$field_name}.'&';
74: }
75: $anchor =~ s/&$//;
76: $anchor .= &group_args();
77: $anchor .= '">'.$inner_text.'</a>';
78: return $anchor;
79: }
80:
81: my $dirptr=16384;
82: sub display_common {
83: my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload)=@_;
84: my $namespace = &get_namespace();
85: my $port_path = &get_port_path();
86: if ($can_upload) {
87: my $groupitem = &group_form_data();
88:
89: my $iconpath= $r->dir_config('lonIconsURL') . "/";
90: my %text=&Apache::lonlocal::texthash(
91: 'upload' => 'Upload',
92: 'upload_label' =>
93: 'Upload file to current directory:',
94: 'createdir' => 'Create Subdirectory',
95: 'createdir_label' =>
96: 'Create subdirectory in current directory:');
97: my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
98: $r->print(<<"TABLE");
99: <table id="LC_portfolio_actions">
100: <tr id="LC_portfolio_upload">
101: <td class="LC_label">
102: $text{'upload_label'}
103: </td>
104: <td class="LC_value">
105: <form method="post" enctype="multipart/form-data" action="$escuri">
106: $groupitem
107: <input name="uploaddoc" type="file" />
108: <input type="hidden" name="currentpath" value="$current_path" />
109: <input type="hidden" name="action" value="$env{"form.action"}" />
110: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
111: <input type="hidden" name="mode" value="$env{"form.mode"}" />
112: <input type="submit" name="storeupl" value="$text{'upload'}" />
113: </form>
114: </td>
115: </tr>
116: <tr id="LC_portfolio_createdir">
117: <td class="LC_label">
118: $text{'createdir_label'}
119: </td>
120: <td class="LC_value">
121: <form method="post" action="$escuri">
122: <input name="newdir" type="input" />$groupitem
123: <input type="hidden" name="currentpath" value="$current_path" />
124: <input type="hidden" name="action" value="$env{"form.action"}" />
125: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
126: <input type="hidden" name="mode" value="$env{"form.mode"}" />
127: <input type="submit" name="createdir" value="$text{'createdir'}" />
128: </form>
129: </td>
130: </tr>
131: </table>
132: TABLE
133: }
134: my @tree = split (/\//,$current_path);
135: my %anchor_fields = (
136: 'selectfile' => $port_path,
137: 'currentpath' => '/',
138: 'mode' => $env{"form.mode"},
139: 'fieldname' => $env{"form.fieldname"},
140: 'continue' => $env{"form.continue"}
141: );
142: $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
143: if (@tree > 1){
144: my $newCurrentPath = '';
145: for (my $i = 1; $i< @tree; $i++){
146: $newCurrentPath .= $tree[$i].'/';
147: my %anchor_fields = (
148: 'selectfile' => $tree[$i],
149: 'currentpath' => '/',
150: 'mode' => $env{"form.mode"},
151: 'fieldname' => $env{"form.fieldname"},
152: 'continue' => $env{"form.continue"}
153: );
154: $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
155: }
156: }
157: $r->print('</span>');
158: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
159: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.&group_args());
160: $r->print('">'.
161: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
162: 'this.form.submit();'));
163: $r->print("</form>");
164: }
165:
166: sub display_directory_line {
167: my ($r,$select_mode, $filename, $mtime, $size, $css_class,
168: $line, $access_controls, $curr_access, $now, $version_flag,
169: $href_location, $url, $current_path, $access_admin_text, $versions)=@_;
170:
171: my $fullpath = &prepend_group($current_path.$filename);
172: $r->print('<tr class="'.$css_class.'">');
173: $r->print($line); # contains first two cells of table
174: my $lock_info;
175: if ($version_flag) { # versioned can't be versioned, so TRUE when root file
176: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
177: $r->print('<td>'.$version_flag.'</td>');
178: } else { # this is a graded or handed back file
179: my ($user,$domain) = &get_name_dom();
180: my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
181: if (defined($$permissions_hash{$fullpath})) {
182: foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
183: if (ref($array_item) eq 'ARRAY') {
184: if ($$array_item[-1] eq 'handback') {
185: $lock_info = 'Handback';
186: } elsif ($$array_item[-1] eq 'graded') {
187: $lock_info = 'Graded';
188: }
189: }
190: }
191: }
192: if ($lock_info) {
193: my %anchor_fields = ('lockinfo' => $fullpath);
194: if ($versions) { # hold the folder open
195: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($fullpath);
196: $fname =~ s|^/||;
197: $anchor_fields{'showversions'} = $fname.'.'.$extension;
198: }
199: $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
200: }
201: $r->print('<td colspan="2">'.$lock_info.'</td>');
202: }
203: # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
204: $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>');
205: $r->print('<td>'.$size.'</td>');
206: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
207: if ($select_mode ne 'true') {
208: $r->print('<td><span style="white-space: nowrap">'.
209: &mt($curr_access).' ');
210: my %anchor_fields = (
211: 'access' => $filename,
212: 'currentpath' => $current_path
213: );
214: $r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
215: }
216: $r->print('</tr>'.$/);
217: }
218:
219: sub display_directory {
220: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
221: $can_modify,$can_delete,$can_setacl)=@_;
222: my $iconpath= $r->dir_config('lonIconsURL') . "/";
223: my $display_out;
224: my $select_mode;
225: my $checked_files;
226: my $port_path = &get_port_path();
227: my ($uname,$udom) = &get_name_dom();
228: my $access_admin_text = &mt('View Status');
229: if ($can_setacl) {
230: $access_admin_text = &mt('View/Change Status');
231: }
232:
233: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
234: $uname);
235: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
236: $current_permissions,$group);
237: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
238: my $now = time;
239: if ($env{"form.mode"} eq 'selectfile'){
240: &select_files($r);
241: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
242: $select_mode = 'true';
243: }
244: if ($is_empty && ($current_path ne '/') && $can_delete) {
245: $display_out = '<form method="post" action="'.$url.'">'.
246: &group_form_data().
247: '<input type="hidden" name="action" value="deletedir" />'.
248: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
249: '<input type="hidden" name="selectfile" value="" />'.
250: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
251: '</form>';
252:
253: $r->print($display_out);
254: return;
255: }
256: if ($select_mode eq 'true') {
257: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
258: $r->print('<table id="LC_browser">'.
259: '<tr><th>Select</th><th> </th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
260: } else {
261: $r->print('<form method="post" action="'.$url.'">');
262: $r->print('<table id="LC_browser">'.
263: '<tr><th colspan="2">Actions</th><th> </th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th><th>Current Access Status</th></tr>');
264: }
265: $r->print("\n".&group_form_data()."\n");
266:
267: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
268: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
269: my @dir_lines;
270: my %versioned;
271: foreach my $dir_line (sort
272: {
273: my ($afile)=split('&',$a,2);
274: my ($bfile)=split('&',$b,2);
275: return (lc($afile) cmp lc($bfile));
276: } (@$dir_list)) {
277: #$strip holds directory/file name
278: #$dom
279: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
280: $filename =~ s/\s+$//;
281: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
282: if ($version) {
283: my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
284: push(@{ $versioned{$fullpath} },
285: [$filename,$dom,$testdir,$size,$mtime,$obs,]);
286: } else {
287: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
288: }
289: }
290: foreach my $dir_line (@dir_lines) {
291: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
292: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
293: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
294: my $version_flag;
295: my $show_versions;
296: my $fullpath = &prepend_group($current_path.$filename);
297: if ($env{'form.showversions'} =~ /$filename/) {
298: $show_versions = 'true';
299: }
300: if (exists($versioned{$fullpath})) {
301: my %anchor_fields = (
302: 'selectfile' => $fullpath,
303: 'continue' => 'false',
304: 'currentpath' => $current_path,
305: );
306: if ($show_versions) {
307: # Must preserve other possible showversion files
308: my $version_remainder = $env{'form.showversions'};
309: $version_remainder =~ s/$filename//g;
310: $anchor_fields{'showversions'} = $version_remainder;
311: $version_flag = &make_anchor('portfolio',\%anchor_fields,
312: '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
313: } else {
314: # allow multiple files to show versioned
315: $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
316: $version_flag = &make_anchor('portfolio',\%anchor_fields,
317: '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
318: }
319: } else {
320: $version_flag = ' ';
321: }
322: if ($dirptr&$testdir) {
323: my $colspan='colspan="2"';
324: if ($select_mode eq 'true'){
325: undef($colspan);
326: }
327: $r->print('<tr class="LC_browser_folder"><td '.$colspan.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_closed.gif" /></td>');
328: $r->print('<td>Go to ...</td>');
329: my %anchor_fields = (
330: 'selectfile' => $filename.'/',
331: 'currentpath' => $current_path.$filename.'/',
332: 'mode' => $env{"form.mode"},
333: 'fieldname' => $env{"form.fieldname"},
334: 'continue' => $env{"form.continue"}
335: );
336: $r->print('<td>'.$version_flag.'</td><td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>');
337: $r->print('</tr>');
338: } else {
339: my $css_class = 'LC_browser_file';
340: my $line;
341: if ($select_mode eq 'true') {
342: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
343: if ($$checked_files{$filename} eq 'selected') {
344: $line.=" checked ";
345: }
346: $line.=' /></td>';
347: } else {
348: if (exists $locked_files{$fullpath}) {
349: my %anchor_fields = (
350: 'lockinfo' => $fullpath
351: );
352: $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,'Locked').'</td>';
353: $css_class= 'LC_browser_file_locked';
354: } else {
355: if (!$can_modify) {
356: $line .= '<td colspan="2">';
357: } else {
358: $line .= '<td>';
359: }
360: if ($can_delete) {
361: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
362: }
363: if ($can_modify) {
364: my $cat='<img class="LC_icon" alt="'.&mt('Catalog Information').
365: '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
366: my %anchor_fields = (
367: 'rename' => $filename,
368: currentpath => $current_path
369: );
370: $line .= &make_anchor($url,\%anchor_fields,'Rename');
371: $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
372: # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
373: }
374: $line .= '</td>';
375: }
376: }
377: my $curr_access;
378: if ($select_mode ne 'true') {
379: my $pub_access = 0;
380: my $guest_access = 0;
381: my $cond_access = 0;
382: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
383: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
384: if (($now > $start) && (!$end || $end > $now)) {
385: if ($scope eq 'public') {
386: $pub_access = 1;
387: } elsif ($scope eq 'guest') {
388: $guest_access = 1;
389: } else {
390: $cond_access = 1;
391: }
392: }
393: }
394: if (!$pub_access && !$guest_access && !$cond_access) {
395: $curr_access = &mt('Private');
396: } else {
397: my @allaccesses;
398: if ($pub_access) {
399: push(@allaccesses,&mt('Public'));
400: }
401: if ($guest_access) {
402: push(@allaccesses,&mt('Passphrase-protected'));
403: }
404: if ($cond_access) {
405: push(@allaccesses,&mt('Conditional'));
406: }
407: $curr_access = join('+ ',@allaccesses);
408: }
409: }
410: &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line,
411: \%access_controls, $curr_access,$now, $version_flag, $href_location,
412: $url, $current_path, $access_admin_text);
413: if ($show_versions) {
414: foreach my $dir_line (@{ $versioned{$fullpath} }) {
415: my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
416: @$dir_line;
417: $line = '<td colspan="2"> </td>';
418: &display_directory_line($r,$select_mode, $v_filename, $mtime, $size,
419: $css_class, $line, \%access_controls, $curr_access, $now,
420: undef, $href_location, $url, $current_path, $access_admin_text, 1);
421: }
422: }
423: }
424: }
425: }
426: if ($select_mode eq 'true') {
427: $r->print('</table>
428: <input type="hidden" name="continue" value="true" />
429: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
430: <input type="hidden" name="mode" value="selectfile" />
431: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
432: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
433: <input type="hidden" name="currentpath" value="'.$current_path.'" />
434: </form>');
435: } else {
436: $r->print('</table>');
437: if ($can_delete) {
438: $r->print('
439: <input type="submit" name="doit" value="Delete Checked Files" />
440: <input type="hidden" name="action" value="delete" />
441: <input type="hidden" name="currentpath" value="'.$current_path.'" />
442: </form>'
443: );
444: }
445: }
446: }
447:
448: sub open_form {
449: my ($r,$url)=@_;
450: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
451: $r->print('<form name="portform" method="post" action="'.$url.'">');
452: $r->print('<input type="hidden" name="action" value="'.
453: $env{'form.action'}.'" />');
454: $r->print('<input type="hidden" name="confirmed" value="1" />');
455: foreach (@files) {
456: $r->print('<input type="hidden" name="selectfile" value="'.
457: $_.'" />');
458: }
459: $r->print('<input type="hidden" name="currentpath" value="'.
460: $env{'form.currentpath'}.'" />');
461: }
462:
463: sub close_form {
464: my ($r,$url,$button_text)=@_;
465: if (!defined($button_text)) {
466: $button_text = {
467: 'continue' => &mt('Continue'),
468: 'cancel' => &mt('Cancel'),
469: };
470: }
471: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
472: $r->print(&group_form_data().'</p></form>');
473: $r->print('<form action="'.$url.'" method="post">
474: <p>
475: <input type="hidden" name="currentpath" value="'.
476: $env{'form.currentpath'}.'" />'.
477: &group_form_data());
478: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
479: </p></form>');
480: }
481:
482: sub display_file {
483: my ($path,$filename)=@_;
484: my $display_file_text;
485: my $file_start='<span class="LC_filename">';
486: my $file_end='</span>';
487: if (!defined($path)) { $path=$env{'form.currentpath'}; }
488: if (!defined($filename)) {
489: $filename=$env{'form.selectfile'};
490: $display_file_text = $file_start.$path.$filename.$file_end;
491: } elsif (ref($filename) eq "ARRAY") {
492: foreach my $file (@$filename) {
493: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
494: }
495: } elsif (ref($filename) eq "SCALAR") {
496: $display_file_text = $file_start.$path.$$filename.$file_end;
497: } else {
498: $display_file_text = $file_start.$path.$filename.$file_end;
499: }
500: return $display_file_text;
501: }
502:
503: sub done {
504: my ($message,$url)=@_;
505: unless (defined $message) {
506: $message='Done';
507: }
508: my %anchor_fields = (
509: 'showversions' => $env{'form.showversions'},
510: 'currentpath' => $env{'form.currentpath'},
511: 'fieldname' => $env{'form.fieldname'},
512: 'mode' => $env{'form.mode'}
513: );
514: my $result = '<h3>'.&make_anchor($url,\%anchor_fields,&mt($message)).'</h3>';
515: return $result;
516: }
517:
518: sub delete {
519: my ($r,$url)=@_;
520: my @check;
521: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
522: $file_name = &prepend_group($file_name);
523: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
524: my ($uname,$udom) = &get_name_dom();
525: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
526: $r->print ("The file is locked and cannot be deleted.<br />");
527: $r->print(&done('Back',$url));
528: } else {
529: if (scalar(@files)) {
530: &open_form($r,$url);
531: $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
532: &close_form($r,$url);
533: } else {
534: $r->print("No file was checked to delete.<br />");
535: $r->print(&done(undef,$url));
536: }
537: }
538: }
539:
540: sub delete_confirmed {
541: my ($r,$url)=@_;
542: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
543: my $result;
544: my ($uname,$udom) = &get_name_dom();
545: my $port_path = &get_port_path();
546: foreach my $delete_file (@files) {
547: $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
548: $env{'form.currentpath'}.
549: $delete_file);
550: if ($result ne 'ok') {
551: $r->print('<span class="LC_error"> An error occured ('.$result.
552: ') while trying to delete '.&display_file(undef, $delete_file).'</span><br />');
553: }
554: }
555: $r->print(&done(undef,$url));
556: }
557:
558: sub delete_dir {
559: my ($r,$url)=@_;
560: &open_form($r,$url);
561: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
562: &close_form($r,$url);
563: }
564:
565: sub delete_dir_confirmed {
566: my ($r,$url)=@_;
567: my $directory_name = $env{'form.currentpath'};
568: $directory_name =~ s|/$||; # remove any trailing slash
569: my ($uname,$udom) = &get_name_dom();
570: my $namespace = &get_namespace();
571: my $port_path = &get_port_path();
572: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
573: $directory_name);
574:
575: if ($result ne 'ok') {
576: $r->print('<span class="LC_error"> An error occured (dir) ('.$result.
577: ') while trying to delete '.$directory_name.'</span><br />');
578: } else {
579: # now remove from recent
580: # $r->print('<br /> removing '.$directory_name.'<br /');
581: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
582: my @dirs = split m!/!, $directory_name;
583:
584: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
585: $directory_name='/';
586: for (my $i=1; $i < (@dirs - 1); $i ++){
587: $directory_name .= $dirs[$i].'/';
588: }
589: $env{'form.currentpath'} = $directory_name;
590: }
591: $r->print(&done(undef,$url));
592: }
593:
594: sub rename {
595: my ($r,$url)=@_;
596: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
597: my ($uname,$udom) = &get_name_dom();
598: $file_name = &prepend_group($file_name);
599: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
600: $r->print ("The file is locked and cannot be renamed.<br />");
601: $r->print(&done(undef,$url));
602: } else {
603: &open_form($r,$url);
604: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
605: <input name="filenewname" type="input" size="50" />?</p>');
606: &close_form($r,$url);
607: }
608: }
609:
610: sub rename_confirmed {
611: my ($r,$url)=@_;
612: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
613: my ($uname,$udom) = &get_name_dom();
614: my $port_path = &get_port_path();
615: if ($filenewname eq '') {
616: $r->print('<span class="LC_error">'.
617: &mt("Error: no valid filename was provided to rename to.").
618: '</span><br />');
619: $r->print(&done(undef,$url));
620: return;
621: }
622: my $result=
623: &Apache::lonnet::renameuserfile($uname,$udom,
624: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
625: $port_path.$env{'form.currentpath'}.$filenewname);
626: if ($result ne 'ok') {
627: $r->print('<span class="LC_error">'.
628: &mt('An errror occured ([_1]) while trying to rename [_2]'
629: .' to [_3]',$result,&display_file(),
630: &display_file('',$filenewname)).'</span><br />');
631: }
632: if ($filenewname ne $env{'form.filenewname'}) {
633: $r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
634: '<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
635: '<strong>'.&display_file('',$filenewname).'</strong>'));
636: }
637: $r->print(&done(undef,$url));
638: }
639:
640: sub display_access {
641: my ($r,$url,$group,$can_setacl,$port_path) = @_;
642: my ($uname,$udom) = &get_name_dom();
643: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
644: $file_name = &prepend_group($file_name);
645: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
646: $uname);
647: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
648: my $aclcount = keys(%access_controls);
649: my $header = '<h3>'.&mt('Allowing others to retrieve file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>';
650: my $info .= &mt('Access to this file by others can be set to be one or more of the following types: public, passphrase-protected or conditional.');
651: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
652: $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
653: $info .= '</li><li>'.&mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').'<br />';
654: $info .= &mt('The conditions can include affiliation with a particular course or group, or a user account in a specific domain.').'<br />';
655: $info .= &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
656: if ($group eq '') {
657: $info .= (&mt("A listing of files viewable without log-in is available at: <a href='/adm/$udom/$uname/aboutme/portfolio'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio</a>.<br />For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:<br /><a href='/adm/$udom/$uname/aboutme'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme</a><br />"));
658: }
659:
660: if ($can_setacl) {
661: &open_form($r,$url);
662: $r->print($header.$info);
663: &access_setting_table($r,$access_controls{$file_name});
664: my $button_text = {
665: 'continue' => &mt('Proceed'),
666: 'cancel' => &mt('Back to directory listing'),
667: };
668: &close_form($r,$url,$button_text);
669: } else {
670: $r->print($header);
671: if ($aclcount) {
672: $r->print($info);
673: }
674: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
675: }
676: }
677:
678: sub view_access_settings {
679: my ($r,$url,$access_controls,$aclcount) = @_;
680: my ($showstart,$showend);
681: my %todisplay;
682: foreach my $key (sort(keys(%{$access_controls}))) {
683: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
684: $todisplay{$scope}{$key} = $$access_controls{$key};
685: }
686: if ($aclcount) {
687: $r->print(&mt('<h4>Current access controls defined for this file:</h4>'));
688: $r->print(&Apache::loncommon::start_data_table());
689: $r->print(&Apache::loncommon::start_data_table_header_row());
690: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
691: '</th><th>'.&mt('Additional information').'</th>');
692: $r->print(&Apache::loncommon::end_data_table_header_row());
693: my $count = 1;
694: my $chg = 'none';
695: &build_access_summary($r,$count,$chg,%todisplay);
696: $r->print(&Apache::loncommon::end_data_table());
697: } else {
698: $r->print(&mt('No access control settings currently exist for this file.<br />' ));
699: }
700: my %anchor_fields = (
701: 'currentpath' => $env{'form.currentpath'}
702: );
703: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory listing')));
704: return;
705: }
706:
707: sub build_access_summary {
708: my ($r,$count,$chg,%todisplay) = @_;
709: my ($showstart,$showend);
710: my %scope_desc = (
711: public => 'Public',
712: guest => 'Passphrase-protected',
713: domains => 'Conditional: domain-based',
714: users => 'Conditional: user-based',
715: course => 'Conditional: course-based',
716: group => 'Conditional: group-based',
717: );
718: my @allscopes = ('public','guest','domains','users','course','group');
719: foreach my $scope (@allscopes) {
720: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
721: next;
722: }
723: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
724: if ($count) {
725: $r->print(&Apache::loncommon::start_data_table_row());
726: }
727: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
728: my $content = $todisplay{$scope}{$key};
729: if ($chg eq 'delete') {
730: $showstart = &mt('Deleted');
731: $showend = $showstart;
732: } else {
733: $showstart = localtime($start);
734: if ($end == 0) {
735: $showend = &mt('No end date');
736: } else {
737: $showend = localtime($end);
738: }
739: }
740: $r->print('<td>'.&mt($scope_desc{$scope}));
741: if (($scope eq 'course') || ($scope eq 'group')) {
742: if ($chg ne 'delete') {
743: my $cid = $content->{'domain'}.'_'.$content->{'number'};
744: my %course_description = &Apache::lonnet::coursedescription($cid);
745: $r->print('<br />('.$course_description{'description'}.')');
746: }
747: }
748: $r->print('</td><td>'.&mt('Start: ').$showstart.
749: '<br />'.&mt('End: ').$showend.'</td><td>');
750: if ($chg ne 'delete') {
751: if ($scope eq 'guest') {
752: $r->print(&mt('Passphrase').': '.$content->{'password'});
753: } elsif ($scope eq 'course' || $scope eq 'group') {
754: $r->print('<table><tr>');
755: $r->print('<th>'.&mt('Roles').'</th><th>'.
756: &mt('Access').'</th><th>'.
757: &mt('Sections').'</th>');
758: if ($scope eq 'course') {
759: $r->print('<th>'.&mt('Groups').'</th>');
760: } else {
761: $r->print('<th>'.&mt('Teams').'</th>');
762: }
763: $r->print('</tr>');
764: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
765: $r->print('<tr>');
766: foreach my $item ('role','access','section','group') {
767: $r->print('<td>');
768: if ($item eq 'role') {
769: my $ucscope = $scope;
770: $ucscope =~ s/^(\w)/uc($1)/e;
771: my $role_output;
772: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
773: if ($role eq 'all') {
774: $role_output .= $role.',';
775: } elsif ($role =~ /^cr/) {
776: $role_output .= (split('/',$role))[3].',';
777: } else {
778: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
779: }
780: }
781: $role_output =~ s/,$//;
782: $r->print($role_output);
783: } else {
784: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
785: }
786: $r->print('</tr>');
787: }
788: $r->print("</table>");
789: }
790: $r->print("</tr></table>");
791: } elsif ($scope eq 'domains') {
792: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
793: } elsif ($scope eq 'users') {
794: my $curr_user_list = &sort_users($content->{'users'});
795: $r->print(&mt('Users: ').$curr_user_list);
796: } else {
797: $r->print(' ');
798: }
799: } else {
800: $r->print(' ');
801: }
802: $r->print('</td>');
803: $r->print(&Apache::loncommon::end_data_table_row());
804: $count ++;
805: }
806: }
807: }
808:
809:
810: sub update_access {
811: my ($r,$url,$group,$port_path) = @_;
812: my $totalprocessed = 0;
813: my %processing;
814: my %title = (
815: 'activate' => 'New control(s) added',
816: 'delete' => 'Existing control(s) deleted',
817: 'update' => 'Existing control(s) modified',
818: );
819: my $changes;
820: foreach my $chg (sort(keys(%title))) {
821: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
822: $totalprocessed += @{$processing{$chg}};
823: foreach my $num (@{$processing{$chg}}) {
824: my $scope = $env{'form.scope_'.$num};
825: my ($start,$end) = &get_dates_from_form($num);
826: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
827: if ($chg eq 'delete') {
828: $$changes{$chg}{$newkey} = 1;
829: } else {
830: $$changes{$chg}{$newkey} =
831: &build_access_record($num,$scope,$start,$end,$chg);
832: }
833: }
834: }
835: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
836: $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
837: $port_path.$file_name).'</h3>'."\n");
838: $file_name = &prepend_group($file_name);
839: my ($uname,$udom) = &get_name_dom();
840: my ($errors,$outcome,$deloutcome,$new_values,$translation);
841: if ($totalprocessed) {
842: ($outcome,$deloutcome,$new_values,$translation) =
843: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
844: $uname);
845: }
846: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
847: $uname);
848: my %access_controls =
849: &Apache::lonnet::get_access_controls($current_permissions,
850: $group,$file_name);
851: if ($totalprocessed) {
852: if ($outcome eq 'ok') {
853: my $updated_controls = $access_controls{$file_name};
854: my ($showstart,$showend);
855: $r->print(&Apache::loncommon::start_data_table());
856: $r->print(&Apache::loncommon::start_data_table_header_row());
857: $r->print('<th>'.&mt('Type of change').'</th><th>'.
858: &mt('Access control').'</th><th>'.&mt('Dates available').
859: '</th><th>'.&mt('Additional information').'</th>');
860: $r->print(&Apache::loncommon::end_data_table_header_row());
861: foreach my $chg (sort(keys(%processing))) {
862: if (@{$processing{$chg}} > 0) {
863: if ($chg eq 'delete') {
864: if (!($deloutcome eq 'ok')) {
865: $errors .='<span class="LC_error">'.
866: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
867: '</span>';
868: next;
869: }
870: }
871: my $numchgs = @{$processing{$chg}};
872: $r->print(&Apache::loncommon::start_data_table_row());
873: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
874: '.</td>');
875: my $count = 0;
876: my %todisplay;
877: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
878: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
879: my $newkey = $key;
880: if ($chg eq 'activate') {
881: $newkey =~ s/^(\d+)/$$translation{$1}/;
882: }
883: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
884: }
885: &build_access_summary($r,$count,$chg,%todisplay);
886: }
887: }
888: $r->print(&Apache::loncommon::end_data_table());
889: } else {
890: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
891: $errors .= '<span class="LC_error">'.
892: &mt('A problem occurred storing access control settings: [_1]',$outcome).
893: '</span>';
894: }
895: }
896: if ($errors) {
897: $r->print($errors);
898: }
899: }
900: my $allnew = 0;
901: my $totalnew = 0;
902: my $status = 'new';
903: my ($firstitem,$lastitem);
904: foreach my $newitem ('course','group','domains','users') {
905: $allnew += $env{'form.new'.$newitem};
906: }
907: if ($allnew > 0) {
908: my $now = time;
909: my $then = $now + (60*60*24*180); # six months approx.
910: &open_form($r,$url);
911: foreach my $newitem ('course','group','domains','users') {
912: if ($env{'form.new'.$newitem} > 0) {
913: $r->print('<br />'.&mt('Add new <b>[_1]-based</b> access control for portfolio file: <b>[_2]</b>',$newitem,$env{'form.currentpath'}.$env{'form.selectfile'}).'<br /><br />');
914: $firstitem = $totalnew;
915: $lastitem = $totalnew + $env{'form.new'.$newitem};
916: $totalnew = $lastitem;
917: my @numbers;
918: for (my $i=$firstitem; $i<$lastitem; $i++) {
919: push (@numbers,$i);
920: }
921: &display_access_row($r,$status,$newitem,\@numbers,
922: $access_controls{$file_name},$now,$then);
923: }
924: }
925: &close_form($r,$url);
926: } else {
927: my %anchor_fields = (
928: 'currentpath' => $env{'form.currentpath'},
929: 'access' => $env{'form.selectfile'}
930: );
931: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
932: delete $anchor_fields{'access'};
933: $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory listing')));
934: }
935: return;
936: }
937:
938: sub build_access_record {
939: my ($num,$scope,$start,$end,$chg) = @_;
940: my $record = {
941: type => $scope,
942: time => {
943: start => $start,
944: end => $end
945: },
946: };
947:
948: if ($scope eq 'guest') {
949: $record->{'password'} = $env{'form.password'};
950: } elsif (($scope eq 'course') || ($scope eq 'group')) {
951: $record->{'domain'} = $env{'form.crsdom_'.$num};
952: $record->{'number'} = $env{'form.crsnum_'.$num};
953: my @role_ids;
954: my @delete_role_ids =
955: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
956: my @preserves =
957: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
958: if (@delete_role_ids) {
959: foreach my $id (@preserves) {
960: if (grep {$_ = $id} (@delete_role_ids)) {
961: next;
962: }
963: push(@role_ids,$id);
964: }
965: } else {
966: push(@role_ids,@preserves);
967: }
968:
969: my $next_id = $env{'form.add_role_'.$num};
970: if ($next_id) {
971: push(@role_ids,$next_id);
972: }
973:
974: foreach my $id (@role_ids) {
975: my (@roles,@accesses,@sections,@groups);
976: if (($id == $next_id) && ($chg eq 'update')) {
977: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
978: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
979: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
980: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
981: } else {
982: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
983: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
984: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
985: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
986: }
987: $record->{'roles'}{$id}{'role'} = \@roles;
988: $record->{'roles'}{$id}{'access'} = \@accesses;
989: $record->{'roles'}{$id}{'section'} = \@sections;
990: $record->{'roles'}{$id}{'group'} = \@groups;
991: }
992: } elsif ($scope eq 'domains') {
993: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
994: $record->{'dom'} = \@doms;
995: } elsif ($scope eq 'users') {
996: my $userlist = $env{'form.users_'.$num};
997: $userlist =~ s/\s+//sg;
998: my %userhash = map { ($_,1) } (split(/,/,$userlist));
999: foreach my $user (keys(%userhash)) {
1000: my ($uname,$udom) = split(/:/,$user);
1001: push(@{$record->{'users'}}, {
1002: 'uname' => $uname,
1003: 'udom' => $udom
1004: });
1005: }
1006: }
1007: return $record;
1008: }
1009:
1010: sub get_dates_from_form {
1011: my ($id) = @_;
1012: my $startdate;
1013: my $enddate;
1014: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1015: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1016: if ( exists ($env{'form.noend_'.$id}) ) {
1017: $enddate = 0;
1018: }
1019: return ($startdate,$enddate);
1020: }
1021:
1022: sub sort_users {
1023: my ($users) = @_;
1024: my @curr_users = map {
1025: $_->{'uname'}.':'.$_->{'udom'}
1026: } (@{$users});
1027: my $curr_user_list = join(",\n",sort(@curr_users));
1028: return $curr_user_list;
1029: }
1030:
1031: sub access_setting_table {
1032: my ($r,$access_controls) = @_;
1033: my ($public,$publictext);
1034: $publictext = &mt('Off');
1035: my ($guest,$guesttext);
1036: $guesttext = &mt('Off');
1037: my @courses = ();
1038: my @groups = ();
1039: my @domains = ();
1040: my @users = ();
1041: my $now = time;
1042: my $then = $now + (60*60*24*180); # six months approx.
1043: my ($num,$scope,$publicnum,$guestnum);
1044: my (%acl_count,%end,%start);
1045: foreach my $key (sort(keys(%{$access_controls}))) {
1046: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1047: if ($scope eq 'public') {
1048: $public = $key;
1049: $publicnum = $num;
1050: $publictext = &acl_status($start{$key},$end{$key},$now);
1051: } elsif ($scope eq 'guest') {
1052: $guest=$key;
1053: $guestnum = $num;
1054: $guesttext = &acl_status($start{$key},$end{$key},$now);
1055: } elsif ($scope eq 'course') {
1056: push(@courses,$key);
1057: } elsif ($scope eq 'group') {
1058: push(@groups,$key);
1059: } elsif ($scope eq 'domains') {
1060: push(@domains,$key);
1061: } elsif ($scope eq 'users') {
1062: push(@users,$key);
1063: }
1064: $acl_count{$scope} ++;
1065: }
1066: $r->print('<table border="0"><tr><td valign="top">');
1067: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1068: $r->print(&Apache::loncommon::start_data_table());
1069: $r->print(&Apache::loncommon::start_data_table_header_row());
1070: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1071: $r->print(&Apache::loncommon::end_data_table_header_row());
1072: $r->print(&Apache::loncommon::start_data_table_row());
1073: if ($public) {
1074: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1075: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
1076: } else {
1077: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1078: &dateboxes('0',$now,$then).'</td>');
1079: }
1080: $r->print(&Apache::loncommon::end_data_table_row());
1081: $r->print(&Apache::loncommon::end_data_table());
1082: $r->print('</td><td width="40"> </td><td valign="top">');
1083: $r->print('<h3>'.&mt('Passphrase-protected access:').' '.$guesttext.'</h3>');
1084: $r->print(&Apache::loncommon::start_data_table());
1085: $r->print(&Apache::loncommon::start_data_table_header_row());
1086: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1087: '</th><th>'. &mt('Passphrase').'</th>');
1088: $r->print(&Apache::loncommon::end_data_table_header_row());
1089: $r->print(&Apache::loncommon::start_data_table_row());
1090: my $passwd;
1091: if ($guest) {
1092: $passwd = $$access_controls{$guest}{'password'};
1093: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1094: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
1095: } else {
1096: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1097: &dateboxes('1',$now,$then).'</td>');
1098: }
1099: $r->print('<td><input type="text" size="15" name="password" value="'.
1100: $passwd.'" /></td>');
1101: $r->print(&Apache::loncommon::end_data_table_row());
1102: $r->print(&Apache::loncommon::end_data_table());
1103: $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
1104: &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
1105: $r->print('</td><td> </td><td valign="top">');
1106: &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
1107: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
1108: if (@courses > 0 || @groups > 0) {
1109: $r->print('<td colspan="3" valign="top">');
1110: } else {
1111: $r->print('<td valign="top">');
1112: }
1113: &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1114: $r->print('</td>');
1115: if (@courses > 0 || @groups > 0) {
1116: $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
1117: } else {
1118: $r->print('<td> </td><td valign="top">');
1119: }
1120: &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
1121: $r->print('</td></tr></table>');
1122: }
1123:
1124: sub acl_status {
1125: my ($start,$end,$now) = @_;
1126: if ($start > $now) {
1127: return &mt('Inactive');
1128: }
1129: if ($end && $end<$now) {
1130: return &mt('Inactive');
1131: }
1132: return &mt('Active');
1133: }
1134:
1135: sub access_element {
1136: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1137: my $title = $type;
1138: $title =~ s/s$//;
1139: $title =~ s/^(\w)/uc($1)/e;
1140: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
1141: if ($$acl_count{$type}) {
1142: $r->print($$acl_count{$type}.' ');
1143: if ($$acl_count{$type} > 1) {
1144: $r->print(&mt('conditions'));
1145: } else {
1146: $r->print(&mt('condition'));
1147: }
1148: } else {
1149: $r->print(&mt('Off'));
1150: }
1151: $r->print('</h3>');
1152: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1153: return;
1154: }
1155:
1156: sub display_access_row {
1157: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1158: if (@{$items} > 0) {
1159: my @all_doms;
1160: my $colspan = 3;
1161: my $uctype = $type;
1162: $uctype =~ s/^(\w)/uc($1)/e;
1163: $r->print(&Apache::loncommon::start_data_table());
1164: $r->print(&Apache::loncommon::start_data_table_header_row());
1165: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1166: &mt('Dates available').'</th>');
1167: if (($type eq 'course') || ($type eq 'group')) {
1168: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
1169: '</th>');
1170: $colspan ++;
1171: } elsif ($type eq 'domains') {
1172: @all_doms = &Apache::loncommon::get_domains();
1173: }
1174: $r->print(&Apache::loncommon::end_data_table_header_row());
1175: foreach my $key (@{$items}) {
1176: $r->print(&Apache::loncommon::start_data_table_row());
1177: if (($type eq 'course') || ($type eq 'group')) {
1178: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1179: } elsif ($type eq 'domains') {
1180: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1181: $then);
1182: } elsif ($type eq 'users') {
1183: &users_row($r,$status,$key,$access_controls,$now,$then);
1184: }
1185: $r->print(&Apache::loncommon::end_data_table_row());
1186: }
1187: if ($status eq 'old') {
1188: $r->print(&Apache::loncommon::start_data_table_row());
1189: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1190: '</td>');
1191: $r->print(&Apache::loncommon::end_data_table_row());
1192: }
1193: $r->print(&Apache::loncommon::end_data_table());
1194: } else {
1195: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
1196: &additional_item($type));
1197: }
1198: return;
1199: }
1200:
1201: sub course_js {
1202: return qq|
1203: <script type="text/javascript">
1204: function setRoleOptions(caller,num,cdom,cnum,type) {
1205: addIndexnum = getCallerIndex(caller);
1206: updateIndexnum = getIndex('update',num);
1207: if (caller.checked) {
1208: document.portform.elements[updateIndexnum].checked = true;
1209: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1210: var title = 'Roles_Chooser';
1211: var options = 'scrollbars=1,resizable=1,menubar=0';
1212: options += ',width=700,height=600';
1213: rolebrowser = open(url,title,options,'1');
1214: rolebrowser.focus();
1215: } else {
1216: for (var j=0;j<5;j++) {
1217: document.portform.elements[addIndexnum+j].value = '';
1218: }
1219: }
1220: }
1221:
1222: function getCallerIndex(caller) {
1223: for (var i=0;i<document.portform.elements.length;i++) {
1224: if (document.portform.elements[i] == caller) {
1225: return i;
1226: }
1227: }
1228: return -1;
1229: }
1230:
1231: function getIndex(name,value) {
1232: for (var i=0;i<document.portform.elements.length;i++) {
1233: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1234: return i;
1235: }
1236: }
1237: return -1;
1238: }
1239:
1240: </script>
1241: |;
1242: }
1243:
1244: sub course_row {
1245: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1246: my $content;
1247: my $defdom = $env{'user.domain'};
1248: if ($status eq 'old') {
1249: $content = $$access_controls{$item};
1250: $defdom = $content->{'domain'};
1251: }
1252: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1253: .&course_js();
1254: my $crsgrptext = 'Groups';
1255: if ($type eq 'group') {
1256: $crsgrptext = 'Teams';
1257: }
1258: my $uctype = $type;
1259: $uctype =~ s/^(\w)/uc($1)/e;
1260: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1261: $type);
1262: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1263: if ($status eq 'old') {
1264: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1265: my %course_description = &Apache::lonnet::coursedescription($cid);
1266: $r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
1267: } elsif ($status eq 'new') {
1268: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,undef,undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1269: }
1270: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1271: $r->print('<td><table><tr>');
1272: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1273: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1274: &mt($crsgrptext).'</th></tr>');
1275: if ($status eq 'old') {
1276: my $max_id = 0;
1277: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1278: if ($role_id > $max_id) {
1279: $max_id = $role_id;
1280: }
1281: $max_id ++;
1282: my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
1283: $r->print('<tr><td><span style="white-space: nowrap"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
1284: }
1285: $r->print('</table><br />'.&mt('Add a roles-based condition').' <input type="checkbox" name ="add_role_'.$num.'" onClick="javascript:setRoleOptions(this,'."'$num','$content->{'domain'}','$content->{'number'}','$uctype'".')" value="'.$max_id.'" /><input type="hidden" name="role_'.$num.'_'.$max_id.'" /><input type="hidden" name="access_'.$num.'_'.$max_id.'" /><input type="hidden" name="section_'.$num.'_'.$max_id.'" /><input type="hidden" name="group_'.$num.'_'.$max_id.'" /></td>');
1286: } elsif ($status eq 'new') {
1287: my $role_id = 1;
1288: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1289: $r->print('<tr><td><input type="checkbox" name="add_role_'.$num.'" value="'.$role_id.'" checked="checked" />'.&mt('Add').'<input type="hidden" name="grplist_'.$num.'_'.$role_id.'" /></td>'.$role_selects);
1290: $r->print('</tr></table></td>');
1291: }
1292: return;
1293: }
1294:
1295: sub domains_row {
1296: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1297: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1298: 'domains');
1299: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1300: ' <option value="">'.&mt('Please select').'</option>';
1301: if ($status eq 'old') {
1302: my $content = $$access_controls{$item};
1303: foreach my $dom (@{$all_doms}) {
1304: if ((@{$content->{'dom'}} > 0)
1305: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1306: $dom_select .= '<option value="'.$dom.'" selected>'.
1307: $dom.'</option>';
1308: } else {
1309: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1310: }
1311: }
1312: } else {
1313: foreach my $dom (@{$all_doms}) {
1314: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1315: }
1316: }
1317: $dom_select .= '</select>';
1318: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1319: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1320: }
1321:
1322: sub users_row {
1323: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1324: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1325: 'users');
1326: my $curr_user_list;
1327: if ($status eq 'old') {
1328: my $content = $$access_controls{$item};
1329: $curr_user_list = &sort_users($content->{'users'});
1330: }
1331: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt("Format for users' username:domain information:").'<br /><tt>sparty:msu,illini:uiuc ... etc.</tt><br /><textarea name="users_'.$num.'" cols="30" rows="5">'.$curr_user_list.'</textarea></td><td>'.&dateboxes($num,$start,$end).'</td>');
1332: }
1333:
1334: sub additional_item {
1335: my ($type) = @_;
1336: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1337: return $output;
1338: }
1339:
1340: sub actionbox {
1341: my ($status,$num,$scope) = @_;
1342: my $output = '<span style="white-space: nowrap"><label>';
1343: if ($status eq 'new') {
1344: $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
1345: &mt('Activate');
1346: } else {
1347: $output .= '<input type="checkbox" name="delete" value="'.$num.
1348: '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
1349: '<label><input type="checkbox" name="update" value="'.
1350: $num.'" />'.&mt('Update');
1351: }
1352: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1353: return $output;
1354: }
1355:
1356: sub dateboxes {
1357: my ($num,$start,$end) = @_;
1358: my $noend;
1359: if ($end == 0) {
1360: $noend = 'checked="checked"';
1361: }
1362: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1363: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1364: undef,undef,1);
1365: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1366: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1367: undef,undef,1). ' <span style="white-space: nowrap"><label>'.
1368: '<input type="checkbox" name="noend_'.
1369: $num.'" '.$noend.' />'.&mt('No end date').
1370: '</label></span>';
1371:
1372: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1373: return $output;
1374: }
1375:
1376: sub unpack_acc_key {
1377: my ($acc_key) = @_;
1378: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1379: return ($num,$scope,$end,$start);
1380: }
1381:
1382: sub set_identifiers {
1383: my ($status,$item,$now,$then,$scope) = @_;
1384: if ($status eq 'old') {
1385: return(&unpack_acc_key($item));
1386: } else {
1387: return($item,$scope,$then,$now);
1388: }
1389: }
1390:
1391: sub role_selectors {
1392: my ($num,$role_id,$status,$type,$content,$caller) = @_;
1393: my ($output,$cdom,$cnum,$longid);
1394: if ($caller eq 'display') {
1395: $longid = '_'.$num.'_'.$role_id;
1396: if ($status eq 'new') {
1397: foreach my $item ('role','access','section','group') {
1398: $output .= '<td><select name="'.$item.$longid.'">'.
1399: '<option value="">'.&mt('Pick [_1] first',$type).
1400: '</option></select></td>';
1401: }
1402: return $output;
1403: } else {
1404: $cdom = $$content{'domain'};
1405: $cnum = $$content{'number'};
1406: }
1407: } elsif ($caller eq 'rolepicker') {
1408: $cdom = $env{'form.cdom'};
1409: $cnum = $env{'form.cnum'};
1410: }
1411: my $uctype = $type;
1412: $uctype =~ s/^(\w)/uc($1)/e;
1413: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1414: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
1415: if (!@{$sections}) {
1416: @{$sections} = ('none');
1417: } else {
1418: unshift(@{$sections},('all','none'));
1419: }
1420: if (!@{$groups}) {
1421: @{$groups} = ('none');
1422: } else {
1423: unshift(@{$groups},('all','none'));
1424: }
1425: my @allacesses = sort(keys(%{$accesshash}));
1426: my (%sectionhash,%grouphash);
1427: foreach my $sec (@{$sections}) {
1428: $sectionhash{$sec} = $sec;
1429: }
1430: foreach my $grp (@{$groups}) {
1431: $grouphash{$grp} = $grp;
1432: }
1433: my %lookup = (
1434: 'role' => $rolehash,
1435: 'access' => $accesshash,
1436: 'section' => \%sectionhash,
1437: 'group' => \%grouphash,
1438: );
1439: my @allaccesses = sort(keys(%{$accesshash}));
1440: my %allitems = (
1441: 'role' => $allroles,
1442: 'access' => \@allaccesses,
1443: 'section' => $sections,
1444: 'group' => $groups,
1445: );
1446: foreach my $item ('role','access','section','group') {
1447: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1448: foreach my $entry (@{$allitems{$item}}) {
1449: if ($caller eq 'display') {
1450: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1451: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1452: $output .= ' <option value="'.$entry.'" selected>'.
1453: $lookup{$item}{$entry}.'</option>';
1454: next;
1455: }
1456: }
1457: $output .= ' <option value="'.$entry.'">'.
1458: $lookup{$item}{$entry}.'</option>';
1459: }
1460: $output .= '</select>';
1461: }
1462: $output .= '</td>';
1463: return $output;
1464: }
1465:
1466: sub role_options_window {
1467: my ($r) = @_;
1468: my $cdom = $env{'form.cdom'};
1469: my $cnum = $env{'form.cnum'};
1470: my $type = $env{'form.type'};
1471: my $addindex = $env{'form.setroles'};
1472: my $grouptitle = 'Groups';
1473: if ($type eq 'Group') {
1474: $grouptitle = 'Teams';
1475: }
1476: my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
1477: $r->print(<<"END_SCRIPT");
1478: <script type="text/javascript">
1479: function setRoles() {
1480: var addidx = $addindex+1;
1481: for (var i=0; i<4; i++) {
1482: var copylist = '';
1483: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1484: if (document.rolepicker.elements[i].options[j].selected) {
1485: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1486: }
1487: }
1488: copylist = copylist.substr(0,copylist.length-1);
1489: opener.document.portform.elements[addidx+i].value = copylist;
1490: }
1491: self.close();
1492: }
1493: </script>
1494: END_SCRIPT
1495: $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
1496: $r->print('<form name="rolepicker" action="/adm/portfolio" method="post"><table><tr><th>'.&mt('Roles').'</th><th>'.&mt('[_1] status',$type).'</th><th>'.&mt('Sections').'</th><th>'.&mt($grouptitle).'</th></tr><tr>'.$role_selects.'</tr></table><br /><input type="button" name="rolepickbutton" value="Save selections" onclick="setRoles()" />');
1497: return;
1498: }
1499:
1500: sub select_files {
1501: my ($r) = @_;
1502: if ($env{'form.continue'} eq 'true') {
1503: # here we update the selections for the currentpath
1504: # eventually, have to handle removing those not checked, but . . .
1505: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1506: if (scalar(@items)){
1507: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1508: }
1509: } else {
1510: #empty the file for a fresh start
1511: &Apache::lonnet::clear_selected_files($env{'user.name'});
1512: }
1513: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1514: my $java_files = join ",", @files;
1515: if ($java_files) {
1516: $java_files.=',';
1517: }
1518: my $javascript =(<<ENDSMP);
1519: <script type="text/javascript">
1520: function finishSelect() {
1521: ENDSMP
1522: $javascript .= 'fileList = "'.$java_files.'";';
1523: $javascript .= (<<ENDSMP);
1524: for (i=0;i<document.forms.checkselect.length;i++) {
1525: if (document.forms.checkselect[i].checked){
1526: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1527: }
1528: }
1529: opener.document.forms.lonhomework.$env{'form.fieldname'}.value=fileList;
1530: self.close();
1531: }
1532: </script>
1533: ENDSMP
1534: $r->print($javascript);
1535: $r->print("<h1>Select portfolio files</h1>
1536: Check as many as you wish in response to the problem.<br />");
1537: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1538: if (@otherfiles) {
1539: $r->print("<strong>Files selected from other directories:</strong><br />");
1540: foreach my $file (@otherfiles) {
1541: $r->print($file."<br />");
1542: }
1543: }
1544: }
1545:
1546: sub upload {
1547: my ($r,$url,$group)=@_;
1548: my $fname=$env{'form.uploaddoc.filename'};
1549: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1550: my $disk_quota = 20000; # expressed in k
1551: if (defined($group)) {
1552: my $grp_quota = &get_group_quota($group); # quota expressed in k
1553: if ($grp_quota ne '') {
1554: $disk_quota = $grp_quota;
1555: } else {
1556: $disk_quota = 0;
1557: }
1558: }
1559: $fname=&Apache::lonnet::clean_filename($fname);
1560:
1561: my $portfolio_root=&get_portfolio_root();
1562: my ($uname,$udom) = &get_name_dom();
1563: my $port_path = &get_port_path();
1564: # Fixme --- Move the checking for existing file to LOND error return
1565: my @dir_list=&get_dir_list($portfolio_root);
1566: my $found_file = 0;
1567: my $locked_file = 0;
1568: foreach my $line (@dir_list) {
1569: my ($file_name)=split(/\&/,$line,2);
1570: if ($file_name eq $fname){
1571: $file_name = $env{'form.currentpath'}.$file_name;
1572: $file_name = &prepend_group($file_name);
1573: $found_file = 1;
1574: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1575: $locked_file = 1;
1576: }
1577: }
1578: }
1579: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1580: if (($current_disk_usage + $filesize) > $disk_quota){
1581: $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
1582: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1583: $r->print(&done('Back',$url));
1584: }
1585: elsif ($found_file){
1586: if ($locked_file){
1587: $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
1588: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1589: $r->print(&done('Back',$url));
1590: } else {
1591: $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
1592: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1593: $r->print(&done('Back',$url));
1594: }
1595: } else {
1596: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1597: $port_path.$env{'form.currentpath'});
1598: if ($result !~ m|^/uploaded/|) {
1599: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1600: ') while trying to upload '.&display_file().'</span><br />');
1601: $r->print(&done('Back',$url));
1602: } else {
1603: $r->print(&done(undef,$url));
1604: }
1605: }
1606: }
1607:
1608: sub lock_info {
1609: my ($r,$url,$group) = @_;
1610: my ($uname,$udom) = &get_name_dom();
1611: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1612: $uname);
1613: my $file_name = $env{'form.lockinfo'};
1614: $file_name = &prepend_group($file_name);
1615: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1616: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1617: next if (ref($array_item) ne 'ARRAY');
1618:
1619: my $filetext;
1620: if (defined($group)) {
1621: $filetext = '<strong>'.$env{'form.lockinfo'}.
1622: '</strong> (group: '.$group.')';
1623: } else {
1624: $filetext = '<strong>'.$file_name.'</strong>';
1625: }
1626:
1627: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1628: '</strong><br />';
1629: if ($$array_item[-1] eq 'graded') {
1630: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1631: $filetext,$title));
1632: } elsif ($$array_item[-1] eq 'handback') {
1633: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
1634: $filetext,$title));
1635: } else {
1636: # submission style lock
1637: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1638: $filetext,$title));
1639: }
1640: my %course_description =
1641: &Apache::lonnet::coursedescription($$array_item[1]);
1642: if ( $course_description{'description'} ne '') {
1643: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1644: $course_description{'description'}));
1645: }
1646: }
1647: }
1648: $r->print(&done('Back',$url));
1649: return 'ok';
1650: }
1651:
1652: sub createdir {
1653: my ($r,$url)=@_;
1654: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1655: if ($newdir eq '') {
1656: $r->print('<span class="LC_error">'.
1657: &mt("Error: no directory name was provided.").
1658: '</span><br />');
1659: $r->print(&done(undef,$url));
1660: return;
1661: }
1662: my $portfolio_root = &get_portfolio_root();
1663: my @dir_list=&get_dir_list($portfolio_root);
1664: my $found_file = 0;
1665: foreach my $line (@dir_list) {
1666: my ($filename)=split(/\&/,$line,2);
1667: if ($filename eq $newdir){
1668: $found_file = 1;
1669: }
1670: }
1671: if ($found_file){
1672: $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
1673: ' </strong>a file or directory by that name already exists.</span><br />');
1674: } else {
1675: my ($uname,$udom) = &get_name_dom();
1676: my $port_path = &get_port_path();
1677: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1678: $port_path.$env{'form.currentpath'}.$newdir);
1679: if ($result ne 'ok') {
1680: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1681: ') while trying to create a new directory '.&display_file().'</span><br />');
1682: }
1683: }
1684: if ($newdir ne $env{'form.newdir'}) {
1685: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1686: }
1687: $r->print(&done(undef,$url));
1688: }
1689:
1690: sub get_portfolio_root {
1691: my ($udom,$uname,$group) = @_;
1692: if (!(defined($udom)) || !(defined($uname))) {
1693: ($uname,$udom) = &get_name_dom();
1694: }
1695: my $path = '/userfiles/portfolio';
1696: if (!defined($group)) {
1697: if (defined($env{'form.group'})) {
1698: $group = $env{'form.group'};
1699: }
1700: }
1701: if (defined($group)) {
1702: $path = '/userfiles/groups/'.$group.'/portfolio';
1703: }
1704: return (&Apache::loncommon::propath($udom,$uname).$path);
1705: }
1706:
1707: sub get_group_quota {
1708: my ($group) = @_;
1709: my $group_quota;
1710: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1711: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1712: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
1713: if (%curr_groups) {
1714: my %group_info = &Apache::longroup::get_group_settings(
1715: $curr_groups{$group});
1716: $group_quota = $group_info{'quota'}; #expressed in Mb
1717: if ($group_quota) {
1718: $group_quota = 1000 * $group_quota; #expressed in k
1719: }
1720: }
1721: return $group_quota;
1722: }
1723:
1724: sub get_dir_list {
1725: my ($portfolio_root) = @_;
1726: my ($uname,$udom) = &get_name_dom();
1727: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1728: $udom,$uname,$portfolio_root);
1729: }
1730:
1731: sub get_name_dom {
1732: my ($uname,$udom);
1733: if (defined($env{'form.group'})) {
1734: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1735: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1736: } else {
1737: $udom = $env{'user.domain'};
1738: $uname = $env{'user.name'};
1739: }
1740: return ($uname,$udom);
1741: }
1742:
1743: sub prepend_group {
1744: my ($filename) = @_;
1745: if (defined($env{'form.group'})) {
1746: $filename = $env{'form.group'}.$filename;
1747: }
1748: return $filename;
1749: }
1750:
1751: sub get_namespace {
1752: my $namespace = 'portfolio';
1753: if (defined($env{'form.group'})) {
1754: my ($uname,$udom) = &get_name_dom();
1755: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1756: }
1757: return $namespace;
1758: }
1759:
1760: sub get_port_path {
1761: my $port_path;
1762: if (defined($env{'form.group'})) {
1763: $port_path = "groups/$env{'form.group'}/portfolio";
1764: } else {
1765: $port_path = 'portfolio';
1766: }
1767: return $port_path;
1768: }
1769:
1770: sub missing_priv {
1771: my ($r,$url,$priv) = @_;
1772: my $longtext = {
1773: upload => 'upload files',
1774: delete => 'delete files',
1775: rename => 'rename files',
1776: setacl => 'set access controls for files',
1777: };
1778: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
1779: my $rtnlink = '<a href="'.$url;
1780: if ($url =~ /\?/) {
1781: $rtnlink .= '&';
1782: } else {
1783: $rtnlink .= '?';
1784: }
1785: $rtnlink .= 'currentpath='.$escpath;
1786: $r->print(&mt('<h3>Action disallowed</h3>'));
1787: $r->print(&mt('You do not have sufficient privileges to [_1] ',
1788: $longtext->{$priv}));
1789: if (defined($env{'form.group'})) {
1790: $r->print(&mt("in the group's file repository."));
1791: $rtnlink .= &group_args()
1792: } else {
1793: $r->print(&mt('in this portfolio.'));
1794: }
1795: $rtnlink .= '">'.&mt('Return to directory listing page').'</a>';
1796: $r->print('<br />'.$rtnlink);
1797: $r->print(&Apache::loncommon::end_page());
1798: return;
1799: }
1800:
1801: sub coursegrp_portfolio_header {
1802: my ($cdom,$cnum,$grp_desc)=@_;
1803: my $gpterm = &Apache::loncommon::group_term();
1804: my $ucgpterm = $gpterm;
1805: $ucgpterm =~ s/^(\w)/uc($1)/e;
1806: if ($env{'form.ref'}) {
1807: &Apache::lonhtmlcommon::add_breadcrumb
1808: ({href=>"/adm/coursegroups",
1809: text=>"Groups",
1810: title=>"Course Groups"});
1811: }
1812: &Apache::lonhtmlcommon::add_breadcrumb
1813: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1814: text=>"$ucgpterm: $grp_desc",
1815: title=>"Go to group's home page"},
1816: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1817: text=>"Group Portfolio",
1818: title=>"Display group portfolio"});
1819: my $output = &Apache::lonhtmlcommon::breadcrumbs(
1820: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
1821: return $output;
1822: }
1823:
1824:
1825: sub handler {
1826: # this handles file management
1827: my $r = shift;
1828: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1829: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
1830: 'fieldname','mode','rename','continue','group','access','setnum',
1831: 'cnum','cdom','type','setroles','showversions','ref']);
1832: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1833: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
1834: $url = $1.$2;
1835: $caller = $2;
1836: }
1837: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1838: if ($caller eq 'coursegrp_portfolio') {
1839: # Needs to be in a course
1840: if (! ($env{'request.course.fn'})) {
1841: # Not in a course
1842: $env{'user.error.msg'}=
1843: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
1844: return HTTP_NOT_ACCEPTABLE;
1845: }
1846: my $earlyout = 0;
1847: my $view_permission =
1848: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1849: $env{'form.group'} =~ s/\W//g;
1850: $group = $env{'form.group'};
1851: if ($group) {
1852: ($uname,$udom) = &get_name_dom();
1853: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1854: $group);
1855: if (%curr_groups) {
1856: my %grp_content = &Apache::longroup::get_group_settings(
1857: $curr_groups{$group});
1858: $grp_desc = &unescape($grp_content{'description'});
1859: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
1860: $env{'request.course.id'}.'/'.$group))) {
1861: $portfolio_root = &get_portfolio_root();
1862: } else {
1863: $r->print('You do not have the privileges required to access the shared files space for this group.');
1864: $earlyout = 1;
1865: }
1866: } else {
1867: $r->print('Not a valid group for this course');
1868: $earlyout = 1;
1869: }
1870: $title = &mt('Group files').' for '.$group;
1871: } else {
1872: $r->print('Invalid group');
1873: $earlyout = 1;
1874: }
1875: if ($earlyout) { return OK; }
1876: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1877: $can_modify = 1;
1878: $can_delete = 1;
1879: $can_upload = 1;
1880: $can_setacl = 1;
1881: } else {
1882: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
1883: $can_setacl = 1;
1884: }
1885: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
1886: $can_upload = 1;
1887: }
1888: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
1889: $can_modify = 1;
1890: }
1891: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
1892: $can_delete = 1;
1893: }
1894: }
1895: } else {
1896: ($uname,$udom) = &get_name_dom();
1897: $portfolio_root = &get_portfolio_root();
1898: $title = &mt('Portfolio Manager');
1899: $can_modify = 1;
1900: $can_delete = 1;
1901: $can_upload = 1;
1902: $can_setacl = 1;
1903: }
1904:
1905: my $port_path = &get_port_path();
1906: &Apache::loncommon::no_cache($r);
1907: &Apache::loncommon::content_type($r,'text/html');
1908: $r->send_http_header;
1909: # Give the LON-CAPA page header
1910: if ($env{"form.mode"} eq 'selectfile'){
1911: $r->print(&Apache::loncommon::start_page($title,undef,
1912: {'only_body' => 1}));
1913: } elsif ($env{'form.action'} eq 'rolepicker') {
1914: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
1915: {'no_nav_bar' => 1, }));
1916: } else {
1917: $r->print(&Apache::loncommon::start_page($title));
1918: }
1919: $r->rflush();
1920: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1921: $r->print('<span class="LC_error">'.
1922: 'No file was selected to upload.'.
1923: 'To upload a file, click <strong>Browse...</strong>'.
1924: ', select a file, then click <strong>Upload</strong>.'.
1925: '</span>');
1926: }
1927: if ($env{'form.meta'}) {
1928: &open_form($r,$url);
1929: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1930: $r->print('Edit the meta data<br />');
1931: &close_form($r,$url);
1932: }
1933: if ($env{'form.store'}) {
1934: }
1935:
1936: if ($env{'form.uploaddoc.filename'}) {
1937: if ($can_upload) {
1938: &upload($r,$url,$group);
1939: } else {
1940: &missing_priv($r,$url,'upload');
1941: }
1942: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1943: if ($can_delete) {
1944: &delete_confirmed($r,$url);
1945: } else {
1946: &missing_priv($r,$url,'delete');
1947: }
1948: } elsif ($env{'form.action'} eq 'delete') {
1949: if ($can_delete) {
1950: &delete($r,$url);
1951: } else {
1952: &missing_priv($r,$url,'delete');
1953: }
1954: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1955: if ($can_delete) {
1956: &delete_dir_confirmed($r,$url);
1957: } else {
1958: &missing_priv($r,$url,'delete');
1959: }
1960: } elsif ($env{'form.action'} eq 'deletedir') {
1961: if ($can_delete) {
1962: &delete_dir($r,$url);
1963: } else {
1964: &missing_priv($r,$url,'delete');
1965: }
1966: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1967: if ($can_modify) {
1968: &rename_confirmed($r,$url);
1969: } else {
1970: &missing_priv($r,$url,'rename');
1971: }
1972: } elsif ($env{'form.rename'}) {
1973: $env{'form.selectfile'} = $env{'form.rename'};
1974: $env{'form.action'} = 'rename';
1975: if ($can_modify) {
1976: &rename($r,$url);
1977: } else {
1978: &missing_priv($r,$url,'rename');
1979: }
1980: } elsif ($env{'form.access'}) {
1981: $env{'form.selectfile'} = $env{'form.access'};
1982: $env{'form.action'} = 'chgaccess';
1983: &display_access($r,$url,$group,$can_setacl,$port_path);
1984: } elsif ($env{'form.action'} eq 'chgaccess') {
1985: if ($can_setacl) {
1986: &update_access($r,$url,$group,$port_path);
1987: } else {
1988: &missing_priv($r,$url,'setacl');
1989: }
1990: } elsif ($env{'form.action'} eq 'rolepicker') {
1991: if ($can_setacl) {
1992: &role_options_window($r);
1993: } else {
1994: &missing_priv($r,$url,'setacl');
1995: }
1996: } elsif ($env{'form.createdir'}) {
1997: if ($can_upload) {
1998: &createdir($r,$url);
1999: } else {
2000: &missing_priv($r,$url,'upload');
2001: }
2002: } elsif ($env{'form.lockinfo'}) {
2003: &lock_info($r,$url,$group);
2004: } else {
2005: my $current_path='/';
2006: if ($env{'form.currentpath'}) {
2007: $current_path = $env{'form.currentpath'};
2008: }
2009: if ($caller eq 'coursegrp_portfolio') {
2010: &Apache::lonhtmlcommon::clear_breadcrumbs();
2011: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
2012: }
2013: my @dir_list=&get_dir_list($portfolio_root);
2014: if ($dir_list[0] eq 'no_such_dir'){
2015: # two main reasons for this:
2016: # 1) never been here, so directory structure not created
2017: # 2) back-button navigation after deleting a directory
2018: if ($current_path eq '/'){
2019: &Apache::lonnet::mkdiruserfile($uname,$udom,
2020: &get_port_path());
2021: } else {
2022: # some directory that snuck in get rid of the directory
2023: # from the recent pulldown, just in case
2024: &Apache::lonhtmlcommon::remove_recent('portfolio',
2025: [$current_path]);
2026: $current_path = '/'; # force it back to the root
2027: }
2028: # now grab the directory list again, for the first time
2029: @dir_list=&Apache::lonnet::dirlist($current_path,
2030: $udom,$uname,$portfolio_root);
2031: }
2032: # need to know if directory is empty so it can be removed if desired
2033: my $is_empty=(@dir_list == 2);
2034: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
2035: $can_upload);
2036: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
2037: $can_upload,$can_modify,$can_delete,$can_setacl);
2038: $r->print(&Apache::loncommon::end_page());
2039: }
2040: return OK;
2041: }
2042:
2043: 1;
2044: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>