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