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