Annotation of loncom/interface/portfolio.pm, revision 1.109
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.101 www 34: use lib '/home/httpd/lib/perl';
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.94 raeburn 43: my $anchor = '<a href="'.$url.'?selectfile='.$filename.'¤tpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name;
44: if (defined($group)) {
45: $anchor .= '&group='.$group;
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:');
66: $r->print(<<"TABLE");
67: <table border="0" cellspacing="2" cellpadding="2">
68: <form method="post" enctype="multipart/form-data">
69: <tr valign="middle">
70: <td bgcolor="#ccddaa" align="right">
71: $text{'upload_label'}
72: </td>
1.94 raeburn 73: <td bgcolor="#ccddaa" align="left">$groupitem
1.88 albertel 74: <input name="uploaddoc" type="file" />
75: <input type="hidden" name="currentpath" value="$current_path" />
76: <input type="hidden" name="action" value="$env{"form.action"}" />
77: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
78: <input type="hidden" name="mode" value="$env{"form.mode"}" />
79: <input type="submit" name="storeupl" value="$text{'upload'}" />
80: </td>
81: </tr>
82: </form>
83: <form method="post">
84: <tr>
85: <td bgcolor="#ccddaa" align="right">
86: $text{'createdir_label'}
87: </td>
88: <td bgcolor="#ccddaa" align="left">
1.94 raeburn 89: <input name="newdir" type="input" />$groupitem
1.88 albertel 90: <input type="hidden" name="currentpath" value="$current_path" />
91: <input type="hidden" name="action" value="$env{"form.action"}" />
92: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
93: <input type="hidden" name="mode" value="$env{"form.mode"}" />
94: <input type="submit" name="createdir" value="$text{'createdir'}" />
95: </td>
96: </tr>
97: </form>
98: </table>
99: TABLE
1.24 albertel 100: my @tree = split (/\//,$current_path);
1.94 raeburn 101: $r->print('<font size="+2">'.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"},$group).'/');
1.19 banghart 102: if (@tree > 1){
103: my $newCurrentPath = '';
104: for (my $i = 1; $i< @tree; $i++){
105: $newCurrentPath .= $tree[$i].'/';
1.94 raeburn 106: $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"},$group).'/');
1.19 banghart 107: }
108: }
109: $r->print('</font>');
1.94 raeburn 110: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
111: $r->print('<br /><form method=post action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"});
112: if (defined($group)) {
113: $r->print('&group='.$group);
114: }
115: $r->print('">'.
116: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
1.22 albertel 117: 'this.form.submit();'));
1.21 banghart 118: $r->print("</form>");
1.48 banghart 119: }
120: sub display_directory {
1.94 raeburn 121: my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
1.48 banghart 122: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.94 raeburn 123: my ($groupitem,$groupecho);
1.48 banghart 124: my $display_out;
1.77 banghart 125: my $select_mode;
126: my $checked_files;
1.94 raeburn 127: my $port_path = &get_port_path($group);
128: my ($uname,$udom) = &get_name_dom($group);
129: if (defined($group)) {
130: $groupitem = '<input type="hidden" name="group" value="'.$group.'" />';
131: $groupecho = '&group='.$group;
132: }
1.102 raeburn 133: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
134: $uname);
135: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
136: $current_permissions,$group);
137: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
138: my $now = time;
1.82 albertel 139: if ($env{"form.mode"} eq 'selectfile'){
1.77 banghart 140: &select_files($r);
1.94 raeburn 141: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
1.77 banghart 142: $select_mode = 'true';
143: }
1.45 banghart 144: if ($is_empty && ($current_path ne '/')) {
1.94 raeburn 145: $display_out = '<form method="post" action="'.$url.'">'.$groupitem.
1.30 banghart 146: '<input type="hidden" name="action" value="deletedir" />'.
147: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
148: '<input type="hidden" name="selectfile" value="" />'.
149: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
150: '</form>';
151:
1.48 banghart 152: $r->print($display_out);
1.31 albertel 153: return;
154: }
1.77 banghart 155: if ($select_mode eq 'true') {
156: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
157: '<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.94 raeburn 158: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
1.77 banghart 159: } else {
160: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.102 raeburn 161: '<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 162: $r->print('<form method="post" action="'.$url.'">');
163: }
164: if (defined($group)) {
165: $r->print("\n".$groupitem."\n");
1.77 banghart 166: }
1.94 raeburn 167: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
168: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
1.105 banghart 169: my @dir_lines;
170: my %versioned;
1.26 albertel 171: foreach my $line (sort
172: {
173: my ($afile)=split('&',$a,2);
174: my ($bfile)=split('&',$b,2);
175: return (lc($afile) cmp lc($bfile));
176: } (@$dir_list)) {
1.18 banghart 177: #$strip holds directory/file name
178: #$dom
1.23 albertel 179: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.77 banghart 180: $filename =~ s/\s+$//;
1.105 banghart 181: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
182: if ($version) {
183: $versioned{$fname} .= $version.",";
184: }
1.106 albertel 185: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
1.105 banghart 186: }
1.106 albertel 187: foreach my $line (@dir_lines) {
1.105 banghart 188: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$line;
189: my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
1.93 albertel 190: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
1.23 albertel 191: if ($dirptr&$testdir) {
1.77 banghart 192: if ($select_mode eq 'true'){
193: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64 banghart 194: } else {
1.77 banghart 195: $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64 banghart 196: }
1.47 banghart 197: $r->print('<td>Go to ...</td>');
1.94 raeburn 198: $r->print('<td>'.&make_anchor($url,$filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'},$group).'</td>');
1.47 banghart 199: $r->print('</tr>');
200: } else {
201: $r->print('<tr bgcolor="#CCCCFF">');
1.105 banghart 202: my $version_flag;
203: if (exists($versioned{$fname})) {
204: $version_flag = "*";
205: } else {
206: $version_flag = "";
207: }
208: my $fullpath = $current_path.$filename;
1.103 raeburn 209: $fullpath = &prepend_group($fullpath,$group);
1.77 banghart 210: if ($select_mode eq 'true'){
1.102 raeburn 211: $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
1.77 banghart 212: if ($$checked_files{$filename} eq 'selected') {
213: $r->print("CHECKED");
214: }
215: $r->print('></td>');
216: } else {
1.103 raeburn 217: if (exists $locked_files{$fullpath}) {
1.94 raeburn 218: $r->print('<td colspan="2"><a href="'.$url.'?lockinfo='.$current_path.$filename.$groupecho.'">Locked</a></td>');
1.77 banghart 219: } else {
1.89 albertel 220: my $cat='<img alt="'.&mt('Catalog Information').
221: '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
1.77 banghart 222: $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
1.94 raeburn 223: <a href="'.$url.'?rename='.$filename.'&currentpath='.$current_path.$groupecho.'">Rename</a></td>
1.89 albertel 224: <td><a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>
1.77 banghart 225: </td>');
226: }
1.61 banghart 227: }
1.103 raeburn 228: my $curr_access;
229: my $pub_access = 0;
1.108 raeburn 230: my $guest_access = 0;
231: my $cond_access = 0;
1.103 raeburn 232: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
1.108 raeburn 233: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.103 raeburn 234: if (($now > $start) && (!$end || $end > $now)) {
235: if ($scope eq 'public') {
236: $pub_access = 1;
1.108 raeburn 237: } elsif ($scope eq 'guest') {
238: $guest_access = 1;
239: } else {
240: $cond_access = 1;
1.103 raeburn 241: }
242: }
243: }
1.108 raeburn 244: if (!$pub_access && !$guest_access && !$cond_access) {
245: $curr_access = &mt('Private');
1.104 raeburn 246: } else {
1.108 raeburn 247: my @allaccesses;
248: if ($pub_access) {
249: push(@allaccesses,&mt('Public'));
250: }
251: if ($guest_access) {
252: push(@allaccesses,&mt('Password-protected'));
253: }
254: if ($cond_access) {
255: push(@allaccesses,&mt('Conditional'));
256: }
257: $curr_access = join('+ ',@allaccesses);
1.103 raeburn 258: }
1.91 albertel 259: $r->print('<td><img src="'.&Apache::loncommon::icon($filename).'"></td>');
1.47 banghart 260: $r->print('<td><a href="'.$href_location.$filename.'">'.
261: $filename.'</a></td>');
262: $r->print('<td>'.$size.'</td>');
263: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.102 raeburn 264: $r->print('<td><nobr>'.&mt($curr_access).' '.
265: '<a href="'.$url.'?access='.$filename.
266: '&currentpath='.$current_path.$groupecho.
267: '">'.&mt('View/Change').'</a></nobr></td>');
1.47 banghart 268: $r->print('</tr>');
269: }
270: }
271: }
1.77 banghart 272: if ($select_mode eq 'true') {
273: $r->print('</table>
1.60 banghart 274: <input type="hidden" name="continue" value="true">
1.82 albertel 275: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
1.60 banghart 276: <input type="hidden" name="mode" value="selectfile">
277: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48 banghart 278: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
279: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 280: </form>');
281: } else {
282: $r->print('</table>
283: <input type="submit" name="doit" value="Delete Checked Files" />
284: <input type="hidden" name="action" value="delete" />
285: <input type="hidden" name="currentpath" value="'.$current_path.'" />
286: </form>');
287: }
1.47 banghart 288: }
1.72 banghart 289:
1.24 albertel 290: sub open_form {
1.94 raeburn 291: my ($r,$url)=@_;
1.65 banghart 292: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.102 raeburn 293: $r->print('<form name="portform" method="post" action="'.$url.'">');
1.24 albertel 294: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 295: $env{'form.action'}.'" />');
1.24 albertel 296: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 297: foreach (@files) {
298: $r->print('<input type="hidden" name="selectfile" value="'.
299: $_.'" />');
300: }
1.24 albertel 301: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 302: $env{'form.currentpath'}.'" />');
1.24 albertel 303: }
304:
305: sub close_form {
1.108 raeburn 306: my ($r,$url,$group,$button_text)=@_;
307: if (!defined($button_text)) {
308: $button_text = {
309: 'continue' => &mt('Continue'),
310: 'cancel' => &mt('Cancel'),
311: };
312: }
313: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
1.94 raeburn 314: if (defined($group)) {
315: $r->print("\n".'<input type="hidden" name="group" value="'.
316: $group.'" />');
317: }
318: $r->print('</p></form>');
319: $r->print('<form action="'.$url.'" method="POST">
1.24 albertel 320: <p>
321: <input type="hidden" name="currentpath" value="'.
1.94 raeburn 322: $env{'form.currentpath'}.'" />');
323: if (defined($group)) {
324: $r->print("\n".'<input type="hidden" name="group" value="'.
325: $group.'" />');
326: }
1.108 raeburn 327: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
1.94 raeburn 328: </p></form>');
1.24 albertel 329: }
330:
331: sub display_file {
1.27 albertel 332: my ($path,$filename)=@_;
1.65 banghart 333: my $display_file_text;
1.82 albertel 334: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 335: if (!defined($filename)) {
1.82 albertel 336: $filename=$env{'form.selectfile'};
1.65 banghart 337: $display_file_text = '<tt>'.$path.$filename.'</tt>';
338: } elsif (ref($filename) eq "ARRAY") {
339: foreach (@$filename) {
1.66 banghart 340: $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
1.65 banghart 341: }
342: } elsif (ref($filename) eq "SCALAR") {
343: $display_file_text = '<tt>'.$path.$filename.'</tt>';
344: }
345: return $display_file_text;
1.24 albertel 346: }
347:
348: sub done {
1.94 raeburn 349: my ($message,$url,$group)=@_;
1.76 banghart 350: unless (defined $message) {
351: $message='Done';
352: }
1.94 raeburn 353: my $result = '<h3><a href="'.$url.'?currentpath='.
354: $env{'form.currentpath'}.
355: '&fieldname='.$env{'form.fieldname'}.
356: '&mode='.$env{'form.mode'};
357: if (defined($group)) {
358: $result .= '&group='.$group;
359: }
360: $result .= '">'.&mt($message).'</a></h3>';
361: return $result;
1.24 albertel 362: }
363:
364: sub delete {
1.94 raeburn 365: my ($r,$url,$group)=@_;
1.55 banghart 366: my @check;
1.82 albertel 367: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.102 raeburn 368: $file_name = &prepend_group($file_name,$group);
1.65 banghart 369: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.94 raeburn 370: my ($uname,$udom) = &get_name_dom($group);
371: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55 banghart 372: $r->print ("The file is locked and cannot be deleted.<br />");
1.94 raeburn 373: $r->print(&done('Back',$url,$group));
1.55 banghart 374: } else {
1.66 banghart 375: if (scalar(@files)) {
1.94 raeburn 376: &open_form($r,$url);
1.66 banghart 377: $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
1.94 raeburn 378: &close_form($r,$url,$group);
1.66 banghart 379: } else {
380: $r->print("No file was checked to delete.<br />");
1.94 raeburn 381: $r->print(&done(undef,$url,$group));
1.66 banghart 382: }
1.55 banghart 383: }
1.24 albertel 384: }
385:
386: sub delete_confirmed {
1.94 raeburn 387: my ($r,$url,$group)=@_;
1.65 banghart 388: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
389: my $result;
1.94 raeburn 390: my ($uname,$udom) = &get_name_dom($group);
391: my $port_path = &get_port_path($group);
1.65 banghart 392: foreach my $delete_file (@files) {
1.94 raeburn 393: $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.82 albertel 394: $env{'form.currentpath'}.
1.65 banghart 395: $delete_file);
396: if ($result ne 'ok') {
1.30 banghart 397: $r->print('<font color="red"> An error occured ('.$result.
1.65 banghart 398: ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
399: }
1.24 albertel 400: }
1.94 raeburn 401: $r->print(&done(undef,$url,$group));
1.24 albertel 402: }
403:
1.30 banghart 404: sub delete_dir {
1.94 raeburn 405: my ($r,$url,$group)=@_;
406: &open_form($r,$url);
1.30 banghart 407: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
1.94 raeburn 408: &close_form($r,$url,$group);
1.30 banghart 409: }
410:
411: sub delete_dir_confirmed {
1.94 raeburn 412: my ($r,$url,$group)=@_;
1.82 albertel 413: my $directory_name = $env{'form.currentpath'};
1.81 albertel 414: $directory_name =~ s|/$||; # remove any trailing slash
1.94 raeburn 415: my ($uname,$udom) = &get_name_dom($group);
416: my $namespace = &get_namespace($group);
417: my $port_path = &get_port_path($group);
418: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30 banghart 419: $directory_name);
1.32 banghart 420:
1.30 banghart 421: if ($result ne 'ok') {
422: $r->print('<font color="red"> An error occured (dir) ('.$result.
423: ') while trying to delete '.$directory_name.'</font><br />');
1.32 banghart 424: } else {
1.41 banghart 425: # now remove from recent
426: # $r->print('<br /> removing '.$directory_name.'<br /');
1.94 raeburn 427: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32 banghart 428: my @dirs = split m!/!, $directory_name;
429:
430: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
431: $directory_name='/';
432: for (my $i=1; $i < (@dirs - 1); $i ++){
433: $directory_name .= $dirs[$i].'/';
434: }
1.82 albertel 435: $env{'form.currentpath'} = $directory_name;
1.30 banghart 436: }
1.94 raeburn 437: $r->print(&done(undef,$url,$group));
1.30 banghart 438: }
439:
1.24 albertel 440: sub rename {
1.94 raeburn 441: my ($r,$url,$group)=@_;
1.82 albertel 442: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.94 raeburn 443: my ($uname,$udom) = &get_name_dom($group);
1.102 raeburn 444: $file_name = &prepend_group($file_name,$group);
1.94 raeburn 445: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55 banghart 446: $r->print ("The file is locked and cannot be renamed.<br />");
1.94 raeburn 447: $r->print(&done(undef,$url,$group));
1.55 banghart 448: } else {
1.94 raeburn 449: &open_form($r,$url);
1.55 banghart 450: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
451: <input name="filenewname" type="input" size="50" />?</p>');
1.94 raeburn 452: &close_form($r,$url,$group);
1.55 banghart 453: }
1.24 albertel 454: }
455:
456: sub rename_confirmed {
1.94 raeburn 457: my ($r,$url,$group)=@_;
1.82 albertel 458: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.94 raeburn 459: my ($uname,$udom) = &get_name_dom($group);
460: my $port_path = &get_port_path($group);
1.27 albertel 461: if ($filenewname eq '') {
462: $r->print('<font color="red">'.
463: &mt("Error: no valid filename was provided to rename to.").
464: '</font><br />');
1.94 raeburn 465: $r->print(&done(undef,$url,$group));
1.27 albertel 466: return;
467: }
468: my $result=
1.94 raeburn 469: &Apache::lonnet::renameuserfile($uname,$udom,
470: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
471: $port_path.$env{'form.currentpath'}.$filenewname);
1.27 albertel 472: if ($result ne 'ok') {
473: $r->print('<font color="red"> An errror occured ('.$result.
474: ') while trying to rename '.&display_file().' to '.
475: &display_file(undef,$filenewname).'</font><br />');
476: }
1.82 albertel 477: if ($filenewname ne $env{'form.filenewname'}) {
478: $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
1.66 banghart 479: }
1.94 raeburn 480: $r->print(&done(undef,$url,$group));
1.27 albertel 481: }
1.102 raeburn 482:
1.104 raeburn 483: sub display_access {
484: my ($r,$url,$group) = @_;
485: my ($uname,$udom) = &get_name_dom($group);
486: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
487: $file_name = &prepend_group($file_name,$group);
488: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
489: $uname);
490: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
491: &open_form($r,$url);
492: $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',$env{'form.currentpath'}.$env{'form.access'}).'</h3>'."\n");
1.108 raeburn 493: $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 494: &access_setting_table($r,$access_controls{$file_name});
1.108 raeburn 495: my $button_text = {
496: 'continue' => &mt('Proceed'),
497: 'cancel' => &mt('Back to directory listing'),
498: };
499: &close_form($r,$url,$group,$button_text);
1.104 raeburn 500: }
501:
502: sub update_access {
503: my ($r,$url,$group) = @_;
1.108 raeburn 504: my $function = &Apache::loncommon::get_users_function();
505: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
1.104 raeburn 506: my $totalprocessed = 0;
507: my %processing;
508: my %title = (
1.108 raeburn 509: 'activate' => 'New control(s) added',
510: 'delete' => 'Existing control(s) deleted',
511: 'update' => 'Existing control(s) modified',
1.104 raeburn 512: );
1.108 raeburn 513: my $changes;
1.104 raeburn 514: foreach my $chg (sort(keys(%title))) {
515: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
516: $totalprocessed += @{$processing{$chg}};
517: foreach my $num (@{$processing{$chg}}) {
518: my $scope = $env{'form.scope_'.$num};
519: my ($start,$end) = &get_dates_from_form($num);
520: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
521: if ($chg eq 'delete') {
522: $$changes{$chg}{$newkey} = 1;
523: } else {
524: $$changes{$chg}{$newkey} =
1.108 raeburn 525: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 526: }
527: }
528: }
529: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.108 raeburn 530: $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',
531: $file_name).'</h3>'."\n");
1.104 raeburn 532: $file_name = &prepend_group($file_name,$group);
533: my ($uname,$udom) = &get_name_dom($group);
534: my ($errors,$outcome,$deloutcome,$new_values,$translation);
535: if ($totalprocessed) {
536: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 537: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
538: $uname);
1.104 raeburn 539: }
1.108 raeburn 540: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
541: $uname);
1.109 ! albertel 542: my %access_controls =
! 543: &Apache::lonnet::get_access_controls($current_permissions,
! 544: $group,$file_name);
1.104 raeburn 545: if ($totalprocessed) {
546: if ($outcome eq 'ok') {
547: my $updated_controls = $access_controls{$file_name};
548: my ($showstart,$showend);
549: $r->print(&Apache::loncommon::start_data_table());
550: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 551: $r->print('<th>'.&mt('Type of change').'</th><th>'.
552: &mt('Access control').'</th><th>'.&mt('Dates available').
553: '</th><th>'.&mt('Additional information').'</th>');
1.104 raeburn 554: $r->print(&Apache::loncommon::end_data_table_row());
555: foreach my $chg (sort(keys(%processing))) {
556: if (@{$processing{$chg}} > 0) {
557: if ($chg eq 'delete') {
558: if (!($deloutcome eq 'ok')) {
559: $errors .= &mt('A problem occurred deleting access controls: [_1]',$deloutcome);
560: next;
561: }
562: }
563: my $numchgs = @{$processing{$chg}};
564: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 565: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
566: '.</td>');
1.104 raeburn 567: my $count = 0;
568: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
569: if ($count) {
570: $r->print(&Apache::loncommon::start_data_table_row());
571: }
1.108 raeburn 572: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 573: my $newkey = $key;
574: if ($chg eq 'activate') {
575: $newkey =~ s/^(\d+)/$$translation{$1}/;
576: }
1.109 ! albertel 577: my $content = $$updated_controls{$newkey};
1.104 raeburn 578: if ($chg eq 'delete') {
579: $showstart = &mt('Deleted');
580: $showend = $showstart;
581: } else {
582: $showstart = localtime($start);
583: if ($end == 0) {
584: $showend = &mt('No end date');
585: } else {
586: $showend = localtime($end);
587: }
588: }
1.108 raeburn 589: $r->print('<td>'.&mt($scope));
590: if (($scope eq 'course') || ($scope eq 'group')) {
591: if ($chg ne 'delete') {
1.109 ! albertel 592: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 593: my %course_description = &Apache::lonnet::coursedescription($cid);
594: $r->print('<br />('.$course_description{'description'}.')');
595: }
596: }
597: $r->print('</td><td>'.&mt('Start: ').$showstart.
598: '<br />'.&mt('End: ').$showend.'</td><td>');
599: if ($chg ne 'delete') {
600: if ($scope eq 'guest') {
1.109 ! albertel 601: $r->print(&mt('Password').': '.$content->{'password'});
1.108 raeburn 602: } elsif ($scope eq 'course' || $scope eq 'group') {
603: $r->print('<table border="0"><tr bgcol = "'.
604: $tablecolor.'">');
605: $r->print('<th>'.&mt('Roles').'</th><th>'.
606: &mt('Access').'</th><th>'.
607: &mt('Sections').'</th>');
608: if ($scope eq 'course') {
609: $r->print('<th>'.&mt('Groups').'</th>');
610: } else {
611: $r->print('<th>'.&mt('Teams').'</th>');
612: }
613: $r->print('</tr>');
1.109 ! albertel 614: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
1.108 raeburn 615: $r->print('<tr>');
616: foreach my $item ('role','access','section','group') {
617: $r->print('<td>');
618: if ($item eq 'role') {
619: my $ucscope = $scope;
620: $ucscope =~ s/^(\w)/uc($1)/;
621: my $role_output;
1.109 ! albertel 622: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
1.108 raeburn 623: if ($role eq 'all') {
624: $role_output .= $role.',';
625: } elsif ($role =~ /^cr/) {
626: $role_output .= (split('/',$role))[3].',';
627: } else {
628: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
629: }
630: }
631: $role_output =~ s/,$//;
632: $r->print($role_output);
633: } else {
1.109 ! albertel 634: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
1.108 raeburn 635: }
636: $r->print('</td>');
637: }
638: }
639: $r->print(&Apache::loncommon::end_data_table_row());
640: $r->print(&Apache::loncommon::end_data_table());
641: } elsif ($scope eq 'domains') {
1.109 ! albertel 642: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1.108 raeburn 643: } elsif ($scope eq 'users') {
1.109 ! albertel 644: my $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 645: $r->print(&mt('Users: ').$curr_user_list);
646: } else {
647: $r->print(' ');
648: }
649: } else {
650: $r->print(' ');
651: }
652: $r->print('</td>');
1.104 raeburn 653: $r->print(&Apache::loncommon::end_data_table_row());
654: $count ++;
655: }
656: }
657: }
658: $r->print(&Apache::loncommon::end_data_table());
659: } else {
660: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
661: $errors .= &mt('A problem occurred storing access control settings: [_1]',$outcome);
662: }
663: }
664: if ($errors) {
665: $r->print($errors);
666: }
667: }
1.108 raeburn 668: my $allnew = 0;
669: my $totalnew = 0;
670: my $status = 'new';
671: my ($firstitem,$lastitem);
672: foreach my $newitem ('course','group','domains','users') {
673: $allnew += $env{'form.new'.$newitem};
674: }
675: if ($allnew > 0) {
676: my $now = time;
677: my $then = $now + (60*60*24*180); # six months approx.
678: &open_form($r,$url,$group);
679: foreach my $newitem ('course','group','domains','users') {
680: if ($env{'form.new'.$newitem} > 0) {
681: $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 />');
682: $firstitem = $totalnew;
683: $lastitem = $totalnew + $env{'form.new'.$newitem};
684: $totalnew = $lastitem;
685: my @numbers;
686: for (my $i=$firstitem; $i<$lastitem; $i++) {
687: push (@numbers,$i);
688: }
689: &display_access_row($r,$status,$newitem,\@numbers,
690: $access_controls{$file_name},$now,$then);
691: }
692: }
693: &close_form($r,$url,$group);
694: } else {
695: $r->print('<br /><a href="'.$url.'?access='.$env{'form.selectfile'}.
696: '¤tpath='.$env{'form.currentpath'}.'">'.
697: &mt('Display all access settings for this file').'</a>');
698: }
1.104 raeburn 699: return;
700: }
701:
702: sub build_access_record {
1.108 raeburn 703: my ($num,$scope,$start,$end,$chg) = @_;
1.109 ! albertel 704: my $record = {
! 705: type => $scope,
! 706: time => {
! 707: start => $start,
! 708: end => $end
! 709: },
! 710: };
! 711:
! 712: if ($scope eq 'guest') {
! 713: $record->{'password'} = $env{'form.password'};
1.108 raeburn 714: } elsif (($scope eq 'course') || ($scope eq 'group')) {
1.109 ! albertel 715: $record->{'domain'} = $env{'form.crsdom_'.$num};
! 716: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 717: my @role_ids;
1.109 ! albertel 718: my @delete_role_ids =
! 719: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
! 720: my @preserves =
! 721: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
! 722: if (@delete_role_ids) {
! 723: foreach my $id (@preserves) {
! 724: if (grep {$_ = $id} (@delete_role_ids)) {
! 725: next;
! 726: }
! 727: push(@role_ids,$id);
! 728: }
! 729: } else {
! 730: push(@role_ids,@preserves);
! 731: }
! 732:
! 733: my $next_id = $env{'form.add_role_'.$num};
! 734: if ($next_id) {
! 735: push(@role_ids,$next_id);
! 736: }
! 737:
1.108 raeburn 738: foreach my $id (@role_ids) {
739: my (@roles,@accesses,@sections,@groups);
740: if (($id == $next_id) && ($chg eq 'update')) {
1.109 ! albertel 741: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 742: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
743: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 ! albertel 744: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 745: } else {
746: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
747: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
748: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
749: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
750: }
1.109 ! albertel 751: $record->{'roles'}{$id}{'role'} = \@roles;
! 752: $record->{'roles'}{$id}{'access'} = \@accesses;
! 753: $record->{'roles'}{$id}{'section'} = \@sections;
! 754: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 755: }
756: } elsif ($scope eq 'domains') {
757: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 ! albertel 758: $record->{'dom'} = \@doms;
1.108 raeburn 759: } elsif ($scope eq 'users') {
760: my $userlist = $env{'form.users_'.$num};
1.109 ! albertel 761: $userlist =~ s/\s+//sg;
! 762: my %userhash = map { ($_,1) } (split(/,/,$userlist));
! 763: foreach my $user (keys(%userhash)) {
1.108 raeburn 764: my ($uname,$udom) = split(/:/,$user);
1.109 ! albertel 765: push(@{$record->{'users'}}, {
! 766: 'uname' => $uname,
! 767: 'udom' => $udom
! 768: });
! 769: }
1.108 raeburn 770: }
1.104 raeburn 771: return $record;
772: }
773:
774: sub get_dates_from_form {
775: my ($id) = @_;
776: my $startdate;
777: my $enddate;
778: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
779: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
780: if ( exists ($env{'form.noend_'.$id}) ) {
781: $enddate = 0;
782: }
783: return ($startdate,$enddate);
784: }
785:
1.108 raeburn 786: sub sort_users {
1.109 ! albertel 787: my ($users) = @_;
! 788: my @curr_users = map {
! 789: $_->{'uname'}.':'.$_->{'udom'}
! 790: } (@{$users});
! 791: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 792: return $curr_user_list;
793: }
794:
1.104 raeburn 795: sub access_setting_table {
796: my ($r,$access_controls) = @_;
797: my ($public,$publictext);
1.108 raeburn 798: $publictext = &mt('Off');
1.104 raeburn 799: my ($guest,$guesttext);
1.108 raeburn 800: $guesttext = &mt('Off');
1.104 raeburn 801: my @courses = ();
802: my @groups = ();
803: my @domains = ();
804: my @users = ();
805: my $now = time;
806: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 807: my ($num,$scope,$publicnum,$guestnum);
808: my (%acl_count,%end,%start);
1.104 raeburn 809: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 810: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 811: if ($scope eq 'public') {
812: $public = $key;
1.108 raeburn 813: $publicnum = $num;
814: $publictext = &acl_status($start{$key},$end{$key},$now);
815: } elsif ($scope eq 'guest') {
816: $guest=$key;
817: $guestnum = $num;
818: $guesttext = &acl_status($start{$key},$end{$key},$now);
819: } elsif ($scope eq 'course') {
820: push(@courses,$key);
821: } elsif ($scope eq 'group') {
822: push(@groups,$key);
823: } elsif ($scope eq 'domains') {
824: push(@domains,$key);
825: } elsif ($scope eq 'users') {
826: push(@users,$key);
1.104 raeburn 827: }
1.108 raeburn 828: $acl_count{$scope} ++;
1.104 raeburn 829: }
1.108 raeburn 830: $r->print('<table border="0"><tr><td valign="top">');
831: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1.104 raeburn 832: $r->print(&Apache::loncommon::start_data_table());
833: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 834: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.104 raeburn 835: $r->print(&Apache::loncommon::end_data_table_row());
836: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 837: if ($public) {
838: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
839: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
840: } else {
841: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
842: &dateboxes('0',$now,$then).'</td>');
843: }
844: $r->print(&Apache::loncommon::end_data_table_row());
845: $r->print(&Apache::loncommon::end_data_table());
846: $r->print('</td><td width="40"> </td><td valign="top">');
847: $r->print('<h3>'.&mt('Password-protected access:').' '.$guesttext.'</h3>');
1.104 raeburn 848: $r->print(&Apache::loncommon::start_data_table());
849: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 850: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
851: '</th><th>'. &mt('Password').'</th>');
852: $r->print(&Apache::loncommon::end_data_table_row());
853: $r->print(&Apache::loncommon::start_data_table_row());
854: my $passwd;
855: if ($guest) {
1.109 ! albertel 856: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 857: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
858: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
859: } else {
860: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
861: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 862: }
1.108 raeburn 863: $r->print('<td><input type="text" size="15" name="password" value="'.
864: $passwd.'" /></td>');
1.104 raeburn 865: $r->print(&Apache::loncommon::end_data_table_row());
866: $r->print(&Apache::loncommon::end_data_table());
1.108 raeburn 867: $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
868: &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
869: $r->print('</td><td> </td><td valign="top">');
870: &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
871: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
872: if (@courses > 0 || @groups > 0) {
873: $r->print('<td colspan="3" valign="top">');
874: } else {
875: $r->print('<td valign="top">');
876: }
877: &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1.104 raeburn 878: $r->print('</td>');
1.108 raeburn 879: if (@courses > 0 || @groups > 0) {
880: $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
881: } else {
882: $r->print('<td> </td><td valign="top">');
883: }
884: &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
885: $r->print('</td></tr></table>');
886: }
887:
888: sub acl_status {
889: my ($start,$end,$now) = @_;
890: if ($start > $now) {
891: return &mt('Inactive');
892: }
893: if ($end && $end<$now) {
894: return &mt('Inactive');
895: }
896: return &mt('Active');
897: }
898:
899: sub access_element {
900: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
901: my $title = $type;
902: $title =~ s/s$//;
903: $title =~ s/^(\w)/uc($1)/e;
904: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
905: if ($$acl_count{$type}) {
906: $r->print($$acl_count{$type}.' ');
907: if ($$acl_count{$type} > 1) {
908: $r->print(&mt('conditions'));
909: } else {
910: $r->print(&mt('condition'));
911: }
912: } else {
913: $r->print(&mt('Off'));
914: }
915: $r->print('</h3>');
916: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
917: return;
918: }
919:
920: sub display_access_row {
921: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
922: if (@{$items} > 0) {
923: my @all_doms;
924: my $tablecolor;
925: my $colspan = 3;
926: my $uctype = $type;
927: $uctype =~ s/^(\w)/uc($1)/e;
928: $r->print(&Apache::loncommon::start_data_table());
929: $r->print(&Apache::loncommon::start_data_table_row());
930: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</td><th>'.
931: &mt('Dates available').'</th>');
932: if (($type eq 'course') || ($type eq 'group')) {
933: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
934: '</th>');
935: $colspan ++;
936: my $function = &Apache::loncommon::get_users_function();
937: $tablecolor=&Apache::loncommon::designparm($function.'.tabbg');
938: } elsif ($type eq 'domains') {
939: @all_doms = &Apache::loncommon::get_domains();
940: }
941: $r->print(&Apache::loncommon::end_data_table_row());
942: foreach my $key (@{$items}) {
943: if (($type eq 'course') || ($type eq 'group')) {
944: &course_row($r,$status,$type,$key,$access_controls,
945: $tablecolor,$now,$then);
946: } elsif ($type eq 'domains') {
947: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
948: $then);
949: } elsif ($type eq 'users') {
950: &users_row($r,$status,$key,$access_controls,$now,$then);
951: }
952: }
953: $r->print(&Apache::loncommon::end_data_table_row());
954: $r->print(&Apache::loncommon::start_data_table_row());
955: if ($status eq 'old') {
956: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
957: '</td>');
958: }
959: $r->print(&Apache::loncommon::end_data_table());
960: } else {
961: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
962: &additional_item($type));
963: }
964: return;
965: }
966:
967: sub course_row {
968: my ($r,$status,$type,$item,$access_controls,$tablecolor,$now,$then) = @_;
969: my %content;
970: my $defdom = $env{'user.domain'};
971: if ($status eq 'old') {
1.109 ! albertel 972: $defdom = $$access_controls{$item}{'domain'};
1.108 raeburn 973: }
974: $r->print(&Apache::loncommon::coursebrowser_javascript($defdom));
975: $r->print(qq|
976: <script type="text/javascript">
977: function setRoleOptions(caller,num,cdom,cnum,type) {
978: addIndexnum = getCallerIndex(caller);
979: updateIndexnum = getIndex('update',num);
980: if (caller.checked) {
981: document.portform.elements[updateIndexnum].checked = true;
982: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
983: var title = 'Roles_Chooser';
984: var options = 'scrollbars=1,resizable=1,menubar=0';
985: options += ',width=700,height=600';
986: rolebrowser = open(url,title,options,'1');
987: rolebrowser.focus();
988: } else {
989: for (var j=0;j<5;j++) {
990: document.portform.elements[addIndexnum+j].value = '';
991: }
992: }
993: }
994:
995: function getCallerIndex(caller) {
996: for (var i=0;i<document.portform.elements.length;i++) {
997: if (document.portform.elements[i] == caller) {
998: return i;
999: }
1000: }
1001: return -1;
1002: }
1003:
1004: function getIndex(name,value) {
1005: for (var i=0;i<document.portform.elements.length;i++) {
1006: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1007: return i;
1008: }
1009: }
1010: return -1;
1011: }
1012:
1013: </script>
1014: |);
1015: $r->print(&Apache::loncommon::start_data_table_row());
1016: my $crsgrptext = 'Groups';
1017: if ($type eq 'group') {
1018: $crsgrptext = 'Teams';
1019: }
1020: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1021: $type);
1022: $r->print('<td>'.&actionbox($status,$num,$scope).'</td>');
1023: if ($status eq 'old') {
1024: my $cid = $content{'domain'}.'_'.$content{'number'};
1025: my %course_description = &Apache::lonnet::coursedescription($cid);
1026: $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>');
1027: } elsif ($status eq 'new') {
1028: my $uctype = $type;
1029: $uctype =~ s/^(\w)/uc($1)/e;
1030: $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>');
1031: }
1032: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1033: $r->print('<td><table border="0"><tr bgcolor="'.$tablecolor.'">');
1034: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1035: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1036: &mt($crsgrptext).'</th></tr>');
1037: if ($status eq 'old') {
1038: my $max_id = 0;
1039: foreach my $role_id (sort(keys(%{$content{'roles'}}))) {
1040: if ($role_id > $max_id) {
1041: $max_id = $role_id;
1042: }
1043: $max_id ++;
1044: my $role_selects = &role_selectors($num,$role_id,$status,$type,\%content,'display');
1045: $r->print('<tr><td><nobr><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></nobr><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
1046: }
1047: $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>');
1048: } elsif ($status eq 'new') {
1049: my $role_id = 1;
1050: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1051: $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);
1052: $r->print('</tr></table></td>');
1053: }
1054: $r->print(&Apache::loncommon::end_data_table_row());
1055: return;
1056: }
1057:
1058: sub domains_row {
1059: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1060: $r->print(&Apache::loncommon::start_data_table_row());
1061: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1062: 'domains');
1063: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true"/>'.
1064: ' <option value="">'.&mt('Please select').'</option>';
1065: $r->print(&Apache::loncommon::start_data_table_row());
1066: if ($status eq 'old') {
1.109 ! albertel 1067: my $content = $$access_controls{$item};
! 1068: foreach my $dom (@{$all_doms}) {
! 1069: if ((@{$content->{'dom'}} > 0)
! 1070: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1071: $dom_select .= '<option value="'.$dom.'" selected>'.
1072: $dom.'</option>';
1073: } else {
1074: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1075: }
1076: }
1077: } else {
1078: foreach my $dom (@{$all_doms}) {
1079: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1080: }
1081: }
1082: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1083: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1.104 raeburn 1084: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1085: $r->print(&Apache::loncommon::start_data_table_row());
1086: }
1087:
1088: sub users_row {
1089: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1090: $r->print(&Apache::loncommon::start_data_table_row());
1091: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1092: 'users');
1093: my $curr_user_list;
1094: if ($status eq 'old') {
1.109 ! albertel 1095: my $content = $$access_controls{$item};
! 1096: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1097: }
1098: $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>');
1099: $r->print(&Apache::loncommon::end_data_table_row());
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) = @_;
1110: my $output = '<nobr><label>';
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.
1116: '" />'.&mt('Delete').'</label><br /><nobr>'.
1117: '<label><input type="checkbox" name="update" value="'.
1118: $num.'" />'.&mt('Update');
1119: }
1120: $output .= '</label></nobr><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
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,
1135: undef,undef,1). ' <nobr><label>'.
1136: '<input type="checkbox" name="noend_'.
1137: $num.'" '.$noend.' />'.&mt('No end date').
1138: '</label></nobr>';
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.48 banghart 1281: <script language='javascript'>
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>