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