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