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