Annotation of loncom/interface/portfolio.pm, revision 1.118
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) = @_;
516: my $totalprocessed = 0;
517: my %processing;
518: my %title = (
1.108 raeburn 519: 'activate' => 'New control(s) added',
520: 'delete' => 'Existing control(s) deleted',
521: 'update' => 'Existing control(s) modified',
1.104 raeburn 522: );
1.108 raeburn 523: my $changes;
1.104 raeburn 524: foreach my $chg (sort(keys(%title))) {
525: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
526: $totalprocessed += @{$processing{$chg}};
527: foreach my $num (@{$processing{$chg}}) {
528: my $scope = $env{'form.scope_'.$num};
529: my ($start,$end) = &get_dates_from_form($num);
530: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
531: if ($chg eq 'delete') {
532: $$changes{$chg}{$newkey} = 1;
533: } else {
534: $$changes{$chg}{$newkey} =
1.108 raeburn 535: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 536: }
537: }
538: }
539: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.108 raeburn 540: $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',
541: $file_name).'</h3>'."\n");
1.104 raeburn 542: $file_name = &prepend_group($file_name,$group);
543: my ($uname,$udom) = &get_name_dom($group);
544: my ($errors,$outcome,$deloutcome,$new_values,$translation);
545: if ($totalprocessed) {
546: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 547: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
548: $uname);
1.104 raeburn 549: }
1.108 raeburn 550: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
551: $uname);
1.109 albertel 552: my %access_controls =
553: &Apache::lonnet::get_access_controls($current_permissions,
554: $group,$file_name);
1.104 raeburn 555: if ($totalprocessed) {
556: if ($outcome eq 'ok') {
557: my $updated_controls = $access_controls{$file_name};
558: my ($showstart,$showend);
559: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 560: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 561: $r->print('<th>'.&mt('Type of change').'</th><th>'.
562: &mt('Access control').'</th><th>'.&mt('Dates available').
563: '</th><th>'.&mt('Additional information').'</th>');
1.110 albertel 564: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 565: foreach my $chg (sort(keys(%processing))) {
566: if (@{$processing{$chg}} > 0) {
567: if ($chg eq 'delete') {
568: if (!($deloutcome eq 'ok')) {
1.116 albertel 569: $errors .='<span class="LC_error">'.
570: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
571: '</span>';
1.104 raeburn 572: next;
573: }
574: }
575: my $numchgs = @{$processing{$chg}};
576: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 577: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
578: '.</td>');
1.104 raeburn 579: my $count = 0;
580: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
581: if ($count) {
582: $r->print(&Apache::loncommon::start_data_table_row());
583: }
1.108 raeburn 584: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 585: my $newkey = $key;
586: if ($chg eq 'activate') {
587: $newkey =~ s/^(\d+)/$$translation{$1}/;
588: }
1.109 albertel 589: my $content = $$updated_controls{$newkey};
1.104 raeburn 590: if ($chg eq 'delete') {
591: $showstart = &mt('Deleted');
592: $showend = $showstart;
593: } else {
594: $showstart = localtime($start);
595: if ($end == 0) {
596: $showend = &mt('No end date');
597: } else {
598: $showend = localtime($end);
599: }
600: }
1.108 raeburn 601: $r->print('<td>'.&mt($scope));
602: if (($scope eq 'course') || ($scope eq 'group')) {
603: if ($chg ne 'delete') {
1.109 albertel 604: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 605: my %course_description = &Apache::lonnet::coursedescription($cid);
606: $r->print('<br />('.$course_description{'description'}.')');
607: }
608: }
609: $r->print('</td><td>'.&mt('Start: ').$showstart.
610: '<br />'.&mt('End: ').$showend.'</td><td>');
611: if ($chg ne 'delete') {
612: if ($scope eq 'guest') {
1.109 albertel 613: $r->print(&mt('Password').': '.$content->{'password'});
1.108 raeburn 614: } elsif ($scope eq 'course' || $scope eq 'group') {
1.118 ! albertel 615: $r->print('<table><tr>');
1.108 raeburn 616: $r->print('<th>'.&mt('Roles').'</th><th>'.
617: &mt('Access').'</th><th>'.
618: &mt('Sections').'</th>');
619: if ($scope eq 'course') {
620: $r->print('<th>'.&mt('Groups').'</th>');
621: } else {
622: $r->print('<th>'.&mt('Teams').'</th>');
623: }
624: $r->print('</tr>');
1.109 albertel 625: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
1.108 raeburn 626: $r->print('<tr>');
627: foreach my $item ('role','access','section','group') {
628: $r->print('<td>');
629: if ($item eq 'role') {
630: my $ucscope = $scope;
631: $ucscope =~ s/^(\w)/uc($1)/;
632: my $role_output;
1.109 albertel 633: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
1.108 raeburn 634: if ($role eq 'all') {
635: $role_output .= $role.',';
636: } elsif ($role =~ /^cr/) {
637: $role_output .= (split('/',$role))[3].',';
638: } else {
639: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
640: }
641: }
642: $role_output =~ s/,$//;
643: $r->print($role_output);
644: } else {
1.109 albertel 645: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
1.108 raeburn 646: }
647: $r->print('</td>');
648: }
649: }
650: $r->print(&Apache::loncommon::end_data_table_row());
651: $r->print(&Apache::loncommon::end_data_table());
652: } elsif ($scope eq 'domains') {
1.109 albertel 653: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1.108 raeburn 654: } elsif ($scope eq 'users') {
1.109 albertel 655: my $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 656: $r->print(&mt('Users: ').$curr_user_list);
657: } else {
658: $r->print(' ');
659: }
660: } else {
661: $r->print(' ');
662: }
663: $r->print('</td>');
1.104 raeburn 664: $r->print(&Apache::loncommon::end_data_table_row());
665: $count ++;
666: }
667: }
668: }
669: $r->print(&Apache::loncommon::end_data_table());
670: } else {
671: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1.116 albertel 672: $errors .= '<span class="LC_error">'.
673: &mt('A problem occurred storing access control settings: [_1]',$outcome).
674: '</span>';
1.104 raeburn 675: }
676: }
677: if ($errors) {
678: $r->print($errors);
679: }
680: }
1.108 raeburn 681: my $allnew = 0;
682: my $totalnew = 0;
683: my $status = 'new';
684: my ($firstitem,$lastitem);
685: foreach my $newitem ('course','group','domains','users') {
686: $allnew += $env{'form.new'.$newitem};
687: }
688: if ($allnew > 0) {
689: my $now = time;
690: my $then = $now + (60*60*24*180); # six months approx.
691: &open_form($r,$url,$group);
692: foreach my $newitem ('course','group','domains','users') {
693: if ($env{'form.new'.$newitem} > 0) {
694: $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 />');
695: $firstitem = $totalnew;
696: $lastitem = $totalnew + $env{'form.new'.$newitem};
697: $totalnew = $lastitem;
698: my @numbers;
699: for (my $i=$firstitem; $i<$lastitem; $i++) {
700: push (@numbers,$i);
701: }
702: &display_access_row($r,$status,$newitem,\@numbers,
703: $access_controls{$file_name},$now,$then);
704: }
705: }
706: &close_form($r,$url,$group);
707: } else {
708: $r->print('<br /><a href="'.$url.'?access='.$env{'form.selectfile'}.
1.113 albertel 709: '&currentpath='.$env{'form.currentpath'}.'">'.
1.108 raeburn 710: &mt('Display all access settings for this file').'</a>');
711: }
1.104 raeburn 712: return;
713: }
714:
715: sub build_access_record {
1.108 raeburn 716: my ($num,$scope,$start,$end,$chg) = @_;
1.109 albertel 717: my $record = {
718: type => $scope,
719: time => {
720: start => $start,
721: end => $end
722: },
723: };
724:
725: if ($scope eq 'guest') {
726: $record->{'password'} = $env{'form.password'};
1.108 raeburn 727: } elsif (($scope eq 'course') || ($scope eq 'group')) {
1.109 albertel 728: $record->{'domain'} = $env{'form.crsdom_'.$num};
729: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 730: my @role_ids;
1.109 albertel 731: my @delete_role_ids =
732: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
733: my @preserves =
734: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
735: if (@delete_role_ids) {
736: foreach my $id (@preserves) {
737: if (grep {$_ = $id} (@delete_role_ids)) {
738: next;
739: }
740: push(@role_ids,$id);
741: }
742: } else {
743: push(@role_ids,@preserves);
744: }
745:
746: my $next_id = $env{'form.add_role_'.$num};
747: if ($next_id) {
748: push(@role_ids,$next_id);
749: }
750:
1.108 raeburn 751: foreach my $id (@role_ids) {
752: my (@roles,@accesses,@sections,@groups);
753: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 754: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 755: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
756: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 757: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 758: } else {
759: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
760: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
761: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
762: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
763: }
1.109 albertel 764: $record->{'roles'}{$id}{'role'} = \@roles;
765: $record->{'roles'}{$id}{'access'} = \@accesses;
766: $record->{'roles'}{$id}{'section'} = \@sections;
767: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 768: }
769: } elsif ($scope eq 'domains') {
770: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 771: $record->{'dom'} = \@doms;
1.108 raeburn 772: } elsif ($scope eq 'users') {
773: my $userlist = $env{'form.users_'.$num};
1.109 albertel 774: $userlist =~ s/\s+//sg;
775: my %userhash = map { ($_,1) } (split(/,/,$userlist));
776: foreach my $user (keys(%userhash)) {
1.108 raeburn 777: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 778: push(@{$record->{'users'}}, {
779: 'uname' => $uname,
780: 'udom' => $udom
781: });
782: }
1.108 raeburn 783: }
1.104 raeburn 784: return $record;
785: }
786:
787: sub get_dates_from_form {
788: my ($id) = @_;
789: my $startdate;
790: my $enddate;
791: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
792: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
793: if ( exists ($env{'form.noend_'.$id}) ) {
794: $enddate = 0;
795: }
796: return ($startdate,$enddate);
797: }
798:
1.108 raeburn 799: sub sort_users {
1.109 albertel 800: my ($users) = @_;
801: my @curr_users = map {
802: $_->{'uname'}.':'.$_->{'udom'}
803: } (@{$users});
804: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 805: return $curr_user_list;
806: }
807:
1.104 raeburn 808: sub access_setting_table {
809: my ($r,$access_controls) = @_;
810: my ($public,$publictext);
1.108 raeburn 811: $publictext = &mt('Off');
1.104 raeburn 812: my ($guest,$guesttext);
1.108 raeburn 813: $guesttext = &mt('Off');
1.104 raeburn 814: my @courses = ();
815: my @groups = ();
816: my @domains = ();
817: my @users = ();
818: my $now = time;
819: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 820: my ($num,$scope,$publicnum,$guestnum);
821: my (%acl_count,%end,%start);
1.104 raeburn 822: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 823: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 824: if ($scope eq 'public') {
825: $public = $key;
1.108 raeburn 826: $publicnum = $num;
827: $publictext = &acl_status($start{$key},$end{$key},$now);
828: } elsif ($scope eq 'guest') {
829: $guest=$key;
830: $guestnum = $num;
831: $guesttext = &acl_status($start{$key},$end{$key},$now);
832: } elsif ($scope eq 'course') {
833: push(@courses,$key);
834: } elsif ($scope eq 'group') {
835: push(@groups,$key);
836: } elsif ($scope eq 'domains') {
837: push(@domains,$key);
838: } elsif ($scope eq 'users') {
839: push(@users,$key);
1.104 raeburn 840: }
1.108 raeburn 841: $acl_count{$scope} ++;
1.104 raeburn 842: }
1.108 raeburn 843: $r->print('<table border="0"><tr><td valign="top">');
844: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1.104 raeburn 845: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 846: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 847: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 albertel 848: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 849: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 850: if ($public) {
851: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
852: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
853: } else {
854: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
855: &dateboxes('0',$now,$then).'</td>');
856: }
857: $r->print(&Apache::loncommon::end_data_table_row());
858: $r->print(&Apache::loncommon::end_data_table());
859: $r->print('</td><td width="40"> </td><td valign="top">');
860: $r->print('<h3>'.&mt('Password-protected access:').' '.$guesttext.'</h3>');
1.104 raeburn 861: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 862: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 863: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
864: '</th><th>'. &mt('Password').'</th>');
1.110 albertel 865: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 866: $r->print(&Apache::loncommon::start_data_table_row());
867: my $passwd;
868: if ($guest) {
1.109 albertel 869: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 870: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
871: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
872: } else {
873: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
874: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 875: }
1.108 raeburn 876: $r->print('<td><input type="text" size="15" name="password" value="'.
877: $passwd.'" /></td>');
1.104 raeburn 878: $r->print(&Apache::loncommon::end_data_table_row());
879: $r->print(&Apache::loncommon::end_data_table());
1.108 raeburn 880: $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
881: &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
882: $r->print('</td><td> </td><td valign="top">');
883: &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
884: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
885: if (@courses > 0 || @groups > 0) {
886: $r->print('<td colspan="3" valign="top">');
887: } else {
888: $r->print('<td valign="top">');
889: }
890: &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1.104 raeburn 891: $r->print('</td>');
1.108 raeburn 892: if (@courses > 0 || @groups > 0) {
893: $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
894: } else {
895: $r->print('<td> </td><td valign="top">');
896: }
897: &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
898: $r->print('</td></tr></table>');
899: }
900:
901: sub acl_status {
902: my ($start,$end,$now) = @_;
903: if ($start > $now) {
904: return &mt('Inactive');
905: }
906: if ($end && $end<$now) {
907: return &mt('Inactive');
908: }
909: return &mt('Active');
910: }
911:
912: sub access_element {
913: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
914: my $title = $type;
915: $title =~ s/s$//;
916: $title =~ s/^(\w)/uc($1)/e;
917: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
918: if ($$acl_count{$type}) {
919: $r->print($$acl_count{$type}.' ');
920: if ($$acl_count{$type} > 1) {
921: $r->print(&mt('conditions'));
922: } else {
923: $r->print(&mt('condition'));
924: }
925: } else {
926: $r->print(&mt('Off'));
927: }
928: $r->print('</h3>');
929: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
930: return;
931: }
932:
933: sub display_access_row {
934: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
935: if (@{$items} > 0) {
936: my @all_doms;
937: my $colspan = 3;
938: my $uctype = $type;
939: $uctype =~ s/^(\w)/uc($1)/e;
940: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 941: $r->print(&Apache::loncommon::start_data_table_header_row());
942: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1.108 raeburn 943: &mt('Dates available').'</th>');
944: if (($type eq 'course') || ($type eq 'group')) {
945: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
946: '</th>');
947: $colspan ++;
948: } elsif ($type eq 'domains') {
949: @all_doms = &Apache::loncommon::get_domains();
950: }
1.110 albertel 951: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 952: foreach my $key (@{$items}) {
1.118 ! albertel 953: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 954: if (($type eq 'course') || ($type eq 'group')) {
1.118 ! albertel 955: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1.108 raeburn 956: } elsif ($type eq 'domains') {
957: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
958: $then);
959: } elsif ($type eq 'users') {
960: &users_row($r,$status,$key,$access_controls,$now,$then);
961: }
1.118 ! albertel 962: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 963: }
964: if ($status eq 'old') {
1.111 albertel 965: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 966: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
967: '</td>');
1.111 albertel 968: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 969: }
970: $r->print(&Apache::loncommon::end_data_table());
971: } else {
972: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
973: &additional_item($type));
974: }
975: return;
976: }
977:
1.110 albertel 978: sub course_js {
979: return qq|
1.108 raeburn 980: <script type="text/javascript">
981: function setRoleOptions(caller,num,cdom,cnum,type) {
982: addIndexnum = getCallerIndex(caller);
983: updateIndexnum = getIndex('update',num);
984: if (caller.checked) {
985: document.portform.elements[updateIndexnum].checked = true;
986: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
987: var title = 'Roles_Chooser';
988: var options = 'scrollbars=1,resizable=1,menubar=0';
989: options += ',width=700,height=600';
990: rolebrowser = open(url,title,options,'1');
991: rolebrowser.focus();
992: } else {
993: for (var j=0;j<5;j++) {
994: document.portform.elements[addIndexnum+j].value = '';
995: }
996: }
997: }
998:
999: function getCallerIndex(caller) {
1000: for (var i=0;i<document.portform.elements.length;i++) {
1001: if (document.portform.elements[i] == caller) {
1002: return i;
1003: }
1004: }
1005: return -1;
1006: }
1007:
1008: function getIndex(name,value) {
1009: for (var i=0;i<document.portform.elements.length;i++) {
1010: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1011: return i;
1012: }
1013: }
1014: return -1;
1015: }
1016:
1017: </script>
1.110 albertel 1018: |;
1019: }
1020:
1021: sub course_row {
1.118 ! albertel 1022: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1023: my $content;
1.110 albertel 1024: my $defdom = $env{'user.domain'};
1025: if ($status eq 'old') {
1.115 raeburn 1026: $content = $$access_controls{$item};
1027: $defdom = $content->{'domain'};
1.110 albertel 1028: }
1029: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1030: .&course_js();
1.108 raeburn 1031: my $crsgrptext = 'Groups';
1032: if ($type eq 'group') {
1033: $crsgrptext = 'Teams';
1034: }
1035: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1036: $type);
1.110 albertel 1037: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1038: if ($status eq 'old') {
1.115 raeburn 1039: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1040: my %course_description = &Apache::lonnet::coursedescription($cid);
1.115 raeburn 1041: $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 1042: } elsif ($status eq 'new') {
1043: my $uctype = $type;
1044: $uctype =~ s/^(\w)/uc($1)/e;
1045: $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>');
1046: }
1047: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1.118 ! albertel 1048: $r->print('<td><table><tr>');
1.108 raeburn 1049: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1050: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1051: &mt($crsgrptext).'</th></tr>');
1052: if ($status eq 'old') {
1053: my $max_id = 0;
1.115 raeburn 1054: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1.108 raeburn 1055: if ($role_id > $max_id) {
1056: $max_id = $role_id;
1057: }
1058: $max_id ++;
1.115 raeburn 1059: my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
1.112 albertel 1060: $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 1061: }
1.115 raeburn 1062: $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 1063: } elsif ($status eq 'new') {
1064: my $role_id = 1;
1065: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1066: $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);
1067: $r->print('</tr></table></td>');
1068: }
1069: return;
1070: }
1071:
1072: sub domains_row {
1073: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1074: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1075: 'domains');
1.112 albertel 1076: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1.108 raeburn 1077: ' <option value="">'.&mt('Please select').'</option>';
1078: if ($status eq 'old') {
1.109 albertel 1079: my $content = $$access_controls{$item};
1080: foreach my $dom (@{$all_doms}) {
1081: if ((@{$content->{'dom'}} > 0)
1082: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1083: $dom_select .= '<option value="'.$dom.'" selected>'.
1084: $dom.'</option>';
1085: } else {
1086: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1087: }
1088: }
1089: } else {
1090: foreach my $dom (@{$all_doms}) {
1091: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1092: }
1093: }
1.112 albertel 1094: $dom_select .= '</select>';
1.108 raeburn 1095: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1096: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1097: }
1098:
1099: sub users_row {
1100: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1101: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1102: 'users');
1103: my $curr_user_list;
1104: if ($status eq 'old') {
1.109 albertel 1105: my $content = $$access_controls{$item};
1106: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1107: }
1108: $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>');
1109: }
1110:
1111: sub additional_item {
1112: my ($type) = @_;
1113: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1114: return $output;
1115: }
1116:
1117: sub actionbox {
1118: my ($status,$num,$scope) = @_;
1.112 albertel 1119: my $output = '<span style="white-space: nowrap"><label>';
1.108 raeburn 1120: if ($status eq 'new') {
1121: $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
1122: &mt('Activate');
1123: } else {
1124: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.112 albertel 1125: '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
1.108 raeburn 1126: '<label><input type="checkbox" name="update" value="'.
1127: $num.'" />'.&mt('Update');
1128: }
1.112 albertel 1129: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1.108 raeburn 1130: return $output;
1131: }
1132:
1133: sub dateboxes {
1134: my ($num,$start,$end) = @_;
1135: my $noend;
1136: if ($end == 0) {
1137: $noend = 'checked="checked"';
1138: }
1139: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1140: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1141: undef,undef,1);
1142: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1143: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.112 albertel 1144: undef,undef,1). ' <span style="white-space: nowrap"><label>'.
1.108 raeburn 1145: '<input type="checkbox" name="noend_'.
1146: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1147: '</label></span>';
1.108 raeburn 1148:
1149: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1150: return $output;
1151: }
1152:
1153: sub unpack_acc_key {
1154: my ($acc_key) = @_;
1155: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1156: return ($num,$scope,$end,$start);
1157: }
1158:
1159: sub set_identifiers {
1160: my ($status,$item,$now,$then,$scope) = @_;
1161: if ($status eq 'old') {
1162: return(&unpack_acc_key($item));
1163: } else {
1164: return($item,$scope,$then,$now);
1165: }
1166: }
1167:
1168: sub role_selectors {
1169: my ($num,$role_id,$status,$type,$content,$caller) = @_;
1170: my ($output,$cdom,$cnum,$longid);
1171: if ($caller eq 'display') {
1172: $longid = '_'.$num.'_'.$role_id;
1173: if ($status eq 'new') {
1174: foreach my $item ('role','access','section','group') {
1175: $output .= '<td><select name="'.$item.$longid.'">'.
1176: '<option value="">'.&mt('Pick [_1] first',$type).
1177: '</option></select></td>';
1178: }
1179: return $output;
1180: } else {
1181: $cdom = $$content{'domain'};
1182: $cnum = $$content{'number'};
1183: }
1184: } elsif ($caller eq 'rolepicker') {
1185: $cdom = $env{'form.cdom'};
1186: $cnum = $env{'form.cnum'};
1187: }
1188: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1189: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$type);
1190: if (!@{$sections}) {
1191: @{$sections} = ('none');
1192: } else {
1193: unshift(@{$sections},('all','none'));
1194: }
1195: if (!@{$groups}) {
1196: @{$groups} = ('none');
1197: } else {
1198: unshift(@{$groups},('all','none'));
1199: }
1200: my @allacesses = sort(keys(%{$accesshash}));
1201: my (%sectionhash,%grouphash);
1202: foreach my $sec (@{$sections}) {
1203: $sectionhash{$sec} = $sec;
1204: }
1205: foreach my $grp (@{$groups}) {
1206: $grouphash{$grp} = $grp;
1207: }
1208: my %lookup = (
1209: 'role' => $rolehash,
1210: 'access' => $accesshash,
1211: 'section' => \%sectionhash,
1212: 'group' => \%grouphash,
1213: );
1214: my @allaccesses = sort(keys(%{$accesshash}));
1215: my %allitems = (
1216: 'role' => $allroles,
1217: 'access' => \@allaccesses,
1218: 'section' => $sections,
1219: 'group' => $groups,
1220: );
1221: foreach my $item ('role','access','section','group') {
1222: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1223: foreach my $entry (@{$allitems{$item}}) {
1224: if ($caller eq 'display') {
1225: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1226: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1227: $output .= ' <option value="'.$entry.'" selected>'.
1228: $lookup{$item}{$entry}.'</option>';
1229: next;
1230: }
1231: }
1232: $output .= ' <option value="'.$entry.'">'.
1233: $lookup{$item}{$entry}.'</option>';
1234: }
1235: $output .= '</select>';
1236: }
1237: $output .= '</td>';
1238: return $output;
1239: }
1240:
1241: sub role_options_window {
1242: my ($r) = @_;
1243: my $cdom = $env{'form.cdom'};
1244: my $cnum = $env{'form.cnum'};
1245: my $type = $env{'form.type'};
1246: my $addindex = $env{'form.setroles'};
1247: my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
1248: $r->print(<<"END_SCRIPT");
1249: <script type="text/javascript">
1250: function setRoles() {
1251: var addidx = $addindex+1;
1252: for (var i=0; i<4; i++) {
1253: var copylist = '';
1254: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1255: if (document.rolepicker.elements[i].options[j].selected) {
1256: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1257: }
1258: }
1259: copylist = copylist.substr(0,copylist.length-1);
1260: opener.document.portform.elements[addidx+i].value = copylist;
1261: }
1262: self.close();
1263: }
1264: </script>
1265: END_SCRIPT
1266: $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
1267: $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()" />');
1268: return;
1.104 raeburn 1269: }
1270:
1.47 banghart 1271: sub select_files {
1.104 raeburn 1272: my ($r,$group) = @_;
1.82 albertel 1273: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1274: # here we update the selections for the currentpath
1275: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1276: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1277: if (scalar(@items)){
1.85 banghart 1278: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1279: }
1.62 banghart 1280: } else {
1281: #empty the file for a fresh start
1.83 banghart 1282: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1283: }
1.82 albertel 1284: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1285: my $java_files = join ",", @files;
1286: if ($java_files) {
1287: $java_files.=',';
1.60 banghart 1288: }
1.63 banghart 1289: my $javascript =(<<ENDSMP);
1.113 albertel 1290: <script type="text/javascript">
1.48 banghart 1291: function finishSelect() {
1.62 banghart 1292: ENDSMP
1.63 banghart 1293: $javascript .= 'fileList = "'.$java_files.'";';
1294: $javascript .= (<<ENDSMP);
1.49 banghart 1295: for (i=0;i<document.forms.checkselect.length;i++) {
1296: if (document.forms.checkselect[i].checked){
1.54 banghart 1297: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1298: }
1299: }
1300: opener.document.forms.lonhomework.
1301: ENDSMP
1.82 albertel 1302: $javascript .= $env{'form.fieldname'};
1.63 banghart 1303: $javascript .= (<<ENDSMP);
1.49 banghart 1304: .value=fileList;
1.48 banghart 1305: self.close();
1306: }
1307: </script>
1308: ENDSMP
1.63 banghart 1309: $r->print($javascript);
1.47 banghart 1310: $r->print("<h1>Select portfolio files</h1>
1.88 albertel 1311: Check as many as you wish in response to the problem.<br />");
1312: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1313: if (@otherfiles) {
1314: $r->print("<strong>Files selected from other directories:</strong><br />");
1315: foreach my $file (@otherfiles) {
1316: $r->print($file."<br />");
1317: }
1.60 banghart 1318: }
1.47 banghart 1319: }
1.24 albertel 1320: sub upload {
1.94 raeburn 1321: my ($r,$url,$group)=@_;
1.82 albertel 1322: my $fname=$env{'form.uploaddoc.filename'};
1323: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 1324: my $disk_quota = 20000; # expressed in k
1.34 banghart 1325: $fname=&Apache::lonnet::clean_filename($fname);
1.94 raeburn 1326:
1327: my $portfolio_root=&get_portfolio_root($group);
1328: my ($uname,$udom) = &get_name_dom($group);
1329: my $port_path = &get_port_path($group);
1.38 banghart 1330: # Fixme --- Move the checking for existing file to LOND error return
1.94 raeburn 1331: my @dir_list=&get_dir_list($portfolio_root,$group);
1.34 banghart 1332: my $found_file = 0;
1.76 banghart 1333: my $locked_file = 0;
1.33 banghart 1334: foreach my $line (@dir_list) {
1.76 banghart 1335: my ($file_name)=split(/\&/,$line,2);
1336: if ($file_name eq $fname){
1.102 raeburn 1337: $file_name = $env{'form.currentpath'}.$file_name;
1338: $file_name = &prepend_group($file_name,$group);
1.33 banghart 1339: $found_file = 1;
1.102 raeburn 1340: if (defined($group)) {
1341: $file_name = $group.'/'.$file_name;
1342: }
1343: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1344: $locked_file = 1;
1345: }
1.33 banghart 1346: }
1347: }
1.94 raeburn 1348: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1.87 albertel 1349: if (($current_disk_usage + $filesize) > $disk_quota){
1.116 albertel 1350: $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
1.38 banghart 1351: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.94 raeburn 1352: $r->print(&done('Back',$url,$group));
1.38 banghart 1353: }
1.76 banghart 1354: elsif ($found_file){
1355: if ($locked_file){
1.116 albertel 1356: $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 1357: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1.94 raeburn 1358: $r->print(&done('Back',$url,$group));
1.76 banghart 1359: } else {
1.116 albertel 1360: $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 1361: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1362: $r->print(&done('Back',$url,$group));
1.76 banghart 1363: }
1.33 banghart 1364: } else {
1365: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.94 raeburn 1366: $port_path.$env{'form.currentpath'});
1.33 banghart 1367: if ($result !~ m|^/uploaded/|) {
1.116 albertel 1368: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1369: ') while trying to upload '.&display_file().'</span><br />');
1.94 raeburn 1370: $r->print(&done('Back',$url,$group));
1.76 banghart 1371: } else {
1.94 raeburn 1372: $r->print(&done(undef,$url,$group));
1.33 banghart 1373: }
1.25 albertel 1374: }
1375: }
1.80 banghart 1376: sub lock_info {
1.94 raeburn 1377: my ($r,$url,$group) = @_;
1378: my ($uname,$udom) = &get_name_dom($group);
1.102 raeburn 1379: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1380: $uname);
1.84 banghart 1381: my $file_name = $env{'form.lockinfo'};
1.102 raeburn 1382: $file_name = &prepend_group($file_name,$group);
1383: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1384: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1385: if (ref($array_item) eq 'ARRAY') {
1386: my $filetext;
1387: if (defined($group)) {
1388: $filetext = '<strong>'.$env{'form.lockinfo'}.
1389: '</strong> (group: '.$group.')';
1390: } else {
1391: $filetext = '<strong>'.$file_name.'</strong>';
1392: }
1393: $r->print(&mt('[_1] was submitted in response to problem: ',
1394: $filetext).
1395: '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1396: '</strong><br />');
1397: my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
1398: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1399: $course_description{'description'}));
1400: # $r->print('the third is '.$$array_item[2].'<br>');
1401: # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
1.85 banghart 1402: }
1.102 raeburn 1403: }
1.84 banghart 1404: }
1.94 raeburn 1405: $r->print(&done('Back',$url,$group));
1.80 banghart 1406: return 'ok';
1407: }
1.25 albertel 1408: sub createdir {
1.94 raeburn 1409: my ($r,$url,$group)=@_;
1.82 albertel 1410: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 1411: if ($newdir eq '') {
1.116 albertel 1412: $r->print('<span class="LC_error">'.
1.37 banghart 1413: &mt("Error: no directory name was provided.").
1.116 albertel 1414: '</span><br />');
1.94 raeburn 1415: $r->print(&done(undef,$url,$group));
1.37 banghart 1416: return;
1.94 raeburn 1417: }
1418: my $portfolio_root = &get_portfolio_root($group);
1419: my @dir_list=&get_dir_list($portfolio_root,$group);
1.37 banghart 1420: my $found_file = 0;
1421: foreach my $line (@dir_list) {
1422: my ($filename)=split(/\&/,$line,2);
1423: if ($filename eq $newdir){
1424: $found_file = 1;
1425: }
1426: }
1427: if ($found_file){
1.116 albertel 1428: $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
1429: ' </strong>a file or directory by that name already exists.</span><br />');
1.37 banghart 1430: } else {
1.94 raeburn 1431: my ($uname,$udom) = &get_name_dom($group);
1432: my $port_path = &get_port_path($group);
1433: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1434: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 1435: if ($result ne 'ok') {
1.116 albertel 1436: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1437: ') while trying to create a new directory '.&display_file().'</span><br />');
1.37 banghart 1438: }
1.24 albertel 1439: }
1.82 albertel 1440: if ($newdir ne $env{'form.newdir'}) {
1441: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 1442: }
1.94 raeburn 1443: $r->print(&done(undef,$url,$group));
1444: }
1445:
1446: sub get_portfolio_root {
1447: my ($group) = @_;
1448: my ($portfolio_root,$udom,$uname,$path);
1449: ($uname,$udom) = &get_name_dom($group);
1450: if (defined($group)) {
1451: $path = '/userfiles/groups/'.$group.'/portfolio';
1452: } else {
1453: $path = '/userfiles/portfolio';
1454: }
1455: return (&Apache::loncommon::propath($udom,$uname).$path);
1456: }
1457:
1458: sub get_dir_list {
1459: my ($portfolio_root,$group) = @_;
1460: my ($uname,$udom) = &get_name_dom($group);
1461: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1462: $udom,$uname,$portfolio_root);
1463: }
1464:
1465: sub get_name_dom {
1466: my ($group) = @_;
1467: my ($uname,$udom);
1468: if (defined($group)) {
1469: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1470: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1471: } else {
1472: $udom = $env{'user.domain'};
1473: $uname = $env{'user.name'};
1474: }
1475: return ($uname,$udom);
1476: }
1477:
1.102 raeburn 1478: sub prepend_group {
1479: my ($filename,$group) = @_;
1480: if (defined($group)) {
1481: $filename = $group.'/'.$filename;
1482: }
1483: return $filename;
1484: }
1485:
1.94 raeburn 1486: sub get_namespace {
1487: my ($group) = @_;
1488: my $namespace = 'portfolio';
1489: if (defined($group)) {
1490: my ($uname,$udom) = &get_name_dom($group);
1491: $namespace .= '_'.$udom.'_'.$uname.'_'.$group;
1492: }
1493: return $namespace;
1494: }
1495:
1496: sub get_port_path {
1497: my ($group) = @_;
1498: my $port_path;
1499: if (defined($group)) {
1500: $port_path = "groups/$group/portfolio";
1501: } else {
1502: $port_path = 'portfolio';
1503: }
1504: return $port_path;
1.24 albertel 1505: }
1506:
1507: sub handler {
1508: # this handles file management
1509: my $r = shift;
1.73 banghart 1510: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 1511: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
1512: 'fieldname','mode','rename','continue','group','access','setnum',
1513: 'cnum','cdom','type','setroles']);
1.94 raeburn 1514: my ($uname,$udom,$portfolio_root,$url,$group,$caller,$title);
1515: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
1516: $url = $1.$2;
1517: $caller = $2;
1518: }
1519: if ($caller eq 'coursegrp_portfolio') {
1520: # Needs to be in a course
1521: if (! ($env{'request.course.fn'})) {
1522: # Not in a course
1523: $env{'user.error.msg'}=
1524: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
1525: return HTTP_NOT_ACCEPTABLE;
1526: }
1527: my $earlyout = 0;
1528: my $view_permission = &Apache::lonnet::allowed('vcg',
1529: $env{'request.course.id'});
1530: $group = $env{'form.group'};
1531: $group =~ s/\W//g;
1532: if ($group) {
1533: ($uname,$udom) = &get_name_dom($group);
1.99 raeburn 1534: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 1535: $group);
1536: if (%curr_groups) {
1.94 raeburn 1537: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
1538: $env{'request.course.id'}.'/'.$group))) {
1539: $portfolio_root = &get_portfolio_root($group);
1540: } else {
1.116 albertel 1541: $r->print('You do not have the privileges required to access the shared files space for this group.');
1.94 raeburn 1542: $earlyout = 1;
1543: }
1544: } else {
1545: $r->print('Not a valid group for this course');
1546: $earlyout = 1;
1547: }
1548: $title = &mt('Group files').' for '.$group;
1549: } else {
1550: $r->print('Invalid group');
1551: $earlyout = 1;
1552: }
1553: if ($earlyout) { return OK; }
1554: } else {
1555: ($uname,$udom) = &get_name_dom();
1556: $portfolio_root = &get_portfolio_root();
1557: $title = &mt('Portfolio Manager');
1558: }
1559:
1.24 albertel 1560: &Apache::loncommon::no_cache($r);
1561: &Apache::loncommon::content_type($r,'text/html');
1562: $r->send_http_header;
1563: # Give the LON-CAPA page header
1.82 albertel 1564: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 1565: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 1566: {'only_body' => 1}));
1.108 raeburn 1567: } elsif ($env{'form.action'} eq 'rolepicker') {
1568: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
1569: {'no_nav_bar' => 1, }));
1.74 banghart 1570: } else {
1.97 albertel 1571: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 1572: }
1.24 albertel 1573: $r->rflush();
1.88 albertel 1574: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.116 albertel 1575: $r->print('<span class="LC_error">'.
1576: 'No file was selected to upload.'.
1577: 'To upload a file, click <strong>Browse...</strong>'.
1578: ', select a file, then click <strong>Upload</strong>.'.
1579: '</span>');
1.40 banghart 1580: }
1.82 albertel 1581: if ($env{'form.meta'}) {
1.94 raeburn 1582: &open_form($r,$url);
1.82 albertel 1583: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 1584: $r->print('Edit the meta data<br />');
1.94 raeburn 1585: &close_form($r,$url,$group);
1.70 banghart 1586: }
1.82 albertel 1587: if ($env{'form.store'}) {
1.70 banghart 1588: }
1589:
1.82 albertel 1590: if ($env{'form.uploaddoc.filename'}) {
1.94 raeburn 1591: &upload($r,$url,$group);
1.82 albertel 1592: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.94 raeburn 1593: &delete_confirmed($r,$url,$group);
1.82 albertel 1594: } elsif ($env{'form.action'} eq 'delete') {
1.94 raeburn 1595: &delete($r,$url,$group);
1.82 albertel 1596: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.94 raeburn 1597: &delete_dir_confirmed($r,$url,$group);
1.82 albertel 1598: } elsif ($env{'form.action'} eq 'deletedir'){
1.94 raeburn 1599: &delete_dir($r,$url,$group);
1.82 albertel 1600: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.94 raeburn 1601: &rename_confirmed($r,$url,$group);
1.82 albertel 1602: } elsif ($env{'form.rename'}) {
1603: $env{'form.selectfile'} = $env{'form.rename'};
1604: $env{'form.action'} = 'rename';
1.94 raeburn 1605: &rename($r,$url,$group);
1.104 raeburn 1606: } elsif ($env{'form.access'}) {
1607: $env{'form.selectfile'} = $env{'form.access'};
1608: $env{'form.action'} = 'chgaccess';
1609: &display_access($r,$url,$group);
1610: } elsif ($env{'form.action'} eq 'chgaccess') {
1611: &update_access($r,$url,$group);
1.108 raeburn 1612: } elsif ($env{'form.action'} eq 'rolepicker') {
1613: &role_options_window($r);
1.82 albertel 1614: } elsif ($env{'form.createdir'}) {
1.94 raeburn 1615: &createdir($r,$url,$group);
1.82 albertel 1616: } elsif ($env{'form.lockinfo'}) {
1.94 raeburn 1617: &lock_info($r,$url,$group);
1.24 albertel 1618: } else {
1619: my $current_path='/';
1.82 albertel 1620: if ($env{'form.currentpath'}) {
1621: $current_path = $env{'form.currentpath'};
1.24 albertel 1622: }
1.94 raeburn 1623: my @dir_list=&get_dir_list($portfolio_root,$group);
1.46 albertel 1624: if ($dir_list[0] eq 'no_such_dir'){
1625: # two main reasons for this:
1626: # 1) never been here, so directory structure not created
1627: # 2) back-button navigation after deleting a directory
1628: if ($current_path eq '/'){
1.100 albertel 1629: &Apache::lonnet::mkdiruserfile($uname,$udom,
1630: &get_port_path($group));
1.46 albertel 1631: } else {
1632: # some directory that snuck in get rid of the directory
1633: # from the recent pulldown, just in case
1634: &Apache::lonhtmlcommon::remove_recent('portfolio',
1635: [$current_path]);
1636: $current_path = '/'; # force it back to the root
1637: }
1638: # now grab the directory list again, for the first time
1639: @dir_list=&Apache::lonnet::dirlist($current_path,
1.94 raeburn 1640: $udom,$uname,$portfolio_root);
1.43 banghart 1641: }
1.46 albertel 1642: # need to know if directory is empty so it can be removed if desired
1643: my $is_empty=(@dir_list == 2);
1.94 raeburn 1644: &display_common($r,$url,$current_path,$is_empty,\@dir_list,$group);
1645: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group);
1.95 albertel 1646: $r->print(&Apache::loncommon::end_page());
1.30 banghart 1647: }
1.90 albertel 1648: return OK;
1.2 banghart 1649: }
1.1 banghart 1650: 1;
1651: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>