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