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