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