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