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