Templatized Download manager

This commit is contained in:
JT Smith 2002-11-25 22:11:17 +00:00
parent 665f3bdc1e
commit 679a5bc92b
6 changed files with 211 additions and 181 deletions

View file

@ -30,24 +30,12 @@ our $namespace = "FileManager";
our $name = WebGUI::International::get(1,$namespace);
#-------------------------------------------------------------------
# example: sortByColumn(columnToSort,columnLabel);
sub sortByColumn {
my ($output);
$output = '<a href="'.WebGUI::URL::append($_[2],'sort='.$_[0].'&sortDirection=');
if ($session{form}{sortDirection} eq "asc") {
$output .= "desc";
sub _sortByColumn {
if ($session{scratch}{$namespace.".".$_[0]->get("wobjectId").".sortDirection"} eq "asc") {
return WebGUI::URL::append($_[2],'sort='.$_[1]."&sortDirection=desc");
} else {
$output .= "asc";
return WebGUI::URL::append($_[2],'sort='.$_[1]."&sortDirection=asc");
}
$output .= '">'.$_[1].'</a>';
if ($session{form}{sort} eq $_[0]) {
if ($session{form}{sortDirection} eq "desc") {
$output .= ' <img src="'.$session{config}{extras}.'/desc.gif">';
} else {
$output .= ' <img src="'.$session{config}{extras}.'/asc.gif">';
}
}
return $output;
}
@ -59,7 +47,7 @@ sub duplicate {
$w = WebGUI::Wobject::FileManager->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
paginateAfter=>$_[0]->get("paginateAfter"),
displayThumbnails=>$_[0]->get("displayThumbnails")
templateId=>$_[0]->get("templateId")
});
$sth = WebGUI::SQL->read("select * from FileManager_file where wobjectId=".$_[0]->get("wobjectId"));
while (%row = $sth->hash) {
@ -86,7 +74,7 @@ sub purge {
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],[qw(paginateAfter displayThumbnails)]);
$_[0]->SUPER::set($_[1],[qw(paginateAfter templateId)]);
}
#-------------------------------------------------------------------
@ -156,9 +144,22 @@ sub www_edit {
$output .= '<h1>'.WebGUI::International::get(9,$namespace).'</h1>';
$paginateAfter = $_[0]->get("paginateAfter") || 50;
$f = WebGUI::HTMLForm->new;
$f->template(
-name=>"templateId",
-value=>$_[0]->get("templateId"),
-namespace=>$namespace,
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
);
$f->integer("paginateAfter",WebGUI::International::get(20,$namespace),$paginateAfter);
$f->yesNo("displayThumbnails",WebGUI::International::get(21,$namespace),$_[0]->get("displayThumbnails"));
$f->yesNo("proceed",WebGUI::International::get(22,$namespace),$proceed);
if ($_[0]->get("wobjectId") eq "new") {
$f->whatNext(
-options=>{
addQuestion=>WebGUI::International::get(74,$namespace),
backToPage=>WebGUI::International::get(745)
},
-value=>"addQuestion"
);
}
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
return $output;
}
@ -168,7 +169,7 @@ sub www_editSave {
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
$_[0]->SUPER::www_editSave({
paginateAfter=>$session{form}{paginateAfter},
displayThumbnails=>$session{form}{displayThumbnails}
templateId=>$session{form}{templateId}
});
if ($session{form}{proceed}) {
return $_[0]->www_editDownload();
@ -270,93 +271,87 @@ sub www_moveDownloadUp {
#-------------------------------------------------------------------
sub www_view {
my ($url, @row, $i, $p, $file, $constraints, $alt1, $numResults, $alt2, $output, $sth, $head, $sql, %download, $flag, $columns);
tie %download, 'Tie::CPHash';
$numResults = $session{form}{numResults} || $_[0]->get("paginateAfter") || 25;
$url = WebGUI::URL::page();
$url = WebGUI::URL::append($url,"all=$session{form}{all}") if ($session{form}{all});
$url = WebGUI::URL::append($url,"atLeastOne=$session{form}{atLeastOne}") if ($session{form}{atLeastOne});
$url = WebGUI::URL::append($url,"without=$session{form}{without}") if ($session{form}{without});
$url = WebGUI::URL::append($url,"exactPhrase=$session{form}{exactPhrase}") if ($session{form}{exactPhrase});
$url = WebGUI::URL::append($url,"numResults=$numResults");
$columns = '<tr><td class="tableHeader">'.sortByColumn("fileTitle",WebGUI::International::get(14,$namespace),$url).
'</td><td class="tableHeader">'.sortByColumn("briefSynopsis",WebGUI::International::get(15,$namespace),$url).
'</td><td class="tableHeader">'.sortByColumn("dateUploaded",WebGUI::International::get(16,$namespace),$url).
'</td></tr>';
$url = WebGUI::URL::append($url,"sortDirection=$session{form}{sortDirection}") if ($session{form}{sortDirection});
$url = WebGUI::URL::append($url,"sort=$session{form}{sort}") if ($session{form}{sort});
my ($sortDirection, %var, @fileloop, $files, $sort, $file, $p, $file1, $file2, $file3, $constraints,
$url, $numResults, $sql, $flag);
$url = WebGUI::URL::page("func=view&wid=".$_[0]->get("wobjectId"));
WebGUI::Session::setScratch($namespace.".".$_[0]->get("wobjectId").".sortDirection",$session{form}{sortDirection});
WebGUI::Session::setScratch($namespace.".".$_[0]->get("wobjectId").".sort",$session{form}{sort});
$numResults = $_[0]->get("paginateAfter") || 25;
$var{"titleColumn.label"} = WebGUI::International::get(14,$namespace);
$var{"titleColumn.url"} = $_[0]->_sortByColumn("fileTitle",$url);
$var{"descriptionColumn.label"} = WebGUI::International::get(15,$namespace);
$var{"descriptionColumn.url"} = $_[0]->_sortByColumn("briefSynopsis",$url);
$var{"dateColumn.label"} = WebGUI::International::get(16,$namespace);
$var{"dateColumn.url"} = $_[0]->_sortByColumn("dateUploaded",$url);
$session{form}{sort} = "sequenceNumber" if ($session{form}{sort} eq "");
$var{"search.form"} = WebGUI::Search::form();
$var{"search.url"} = WebGUI::Search::toggleURL();
$var{"search.label"} = WebGUI::International::get(364);
$var{"addfile.url"} = WebGUI::URL::page('func=editDownload&did=new&wid='.$_[0]->get("wobjectId"));
$var{"addfile.label"} = WebGUI::International::get(11,$namespace);
$sql = "select * from FileManager_file where wobjectId=".$_[0]->get("wobjectId")." ";
$constraints = WebGUI::Search::buildConstraints([qw(fileTitle downloadFile alternateVersion1 alternateVersion2 briefSynopsis)]);
$sql .= " and ".$constraints if ($constraints ne "");
$sql .= " order by $session{form}{sort} ";
$sql .= $session{form}{sortDirection};
$output = $_[0]->displayTitle;
$output .= $_[0]->description;
$output = $_[0]->processMacros($output);
if ($session{form}{search}) {
$output .= WebGUI::Search::form({search=>1});
} else {
$head = '<tr><td colspan="3" align="right" class="tableMenu">';
$head .= '<a href="'.WebGUI::URL::page('search=1').'">'.WebGUI::International::get(364).'</a>';
if ($session{var}{adminOn}) {
$head .= ' &middot; <a href="'.WebGUI::URL::page('func=editDownload&did=new&wid='.$_[0]->get("wobjectId"))
.'">'.WebGUI::International::get(11,$namespace).'</a>';
}
$head .= '</td></tr>';
if ($session{scratch}{search}) {
$numResults = $session{scratch}{numResults};
$constraints = WebGUI::Search::buildConstraints(
[qw(fileTitle downloadFile alternateVersion1 alternateVersion2 briefSynopsis)]);
$sql .= " and ".$constraints if ($constraints ne "");
}
$output .= '<table cellpadding="3" cellspacing="1" border="0" width="100%">'.$head.$columns;
$sth = WebGUI::SQL->read($sql);
while (%download = $sth->hash) {
if (WebGUI::Privilege::isInGroup($download{groupToView})) {
$file = WebGUI::Attachment->new($download{downloadFile},
$_[0]->get("wobjectId"), $download{FileManager_fileId});
$row[$i] = '<tr><td class="tableData" valign="top">';
if ($session{var}{adminOn}) {
$row[$i] .= deleteIcon('func=deleteDownload&wid='.$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId})
.editIcon('func=editDownload&wid='.$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId})
.moveUpIcon('func=moveDownloadUp&wid='.$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId})
.moveDownIcon('func=moveDownloadDown&wid='.$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId})
.' ';
}
$row[$i] .= '<a href="'.WebGUI::URL::page('func=download&wid='.$_[0]->get("wobjectId").
'&did='.$download{FileManager_fileId}).'">'.$download{fileTitle}.'</a>&nbsp;&middot;&nbsp;<a href="'.
WebGUI::URL::page('func=download&wid='.
$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId}).'"><img src="'.$file->getIcon.
'" border=0 width=16 height=16 align="middle">'.$file->getType.'/'.$file->getSize.'</a>';
if ($download{alternateVersion1}) {
$alt1 = WebGUI::Attachment->new($download{alternateVersion1},
$_[0]->get("wobjectId"), $download{FileManager_fileId});
$row[$i] .= ' &middot; <a href="'.WebGUI::URL::page('func=download&wid='.
$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId}.'&alternateVersion=1')
.'"><img src="'.$alt1->getIcon.'" border=0 width=16 height=16 align="middle">'.
$alt1->getType.'/'.$alt1->getSize.'</a>';
}
if ($download{alternateVersion2}) {
$alt2 = WebGUI::Attachment->new($download{alternateVersion2},
$_[0]->get("wobjectId"), $download{FileManager_fileId});
$row[$i] .= ' &middot; <a href="'.WebGUI::URL::page('func=download&wid='.
$_[0]->get("wobjectId").'&did='.$download{FileManager_fileId}.'&alternateVersion=2')
.'"><img src="'.$alt2->getIcon.'" border=0 width=16 height=16 align="middle">'.
$alt2->getType.'/'.$alt2->getSize.'</a>';
}
$row[$i] .= '</td><td class="tableData" valign="top">';
if ($_[0]->get("displayThumbnails") && isIn($file->getType, qw(gif jpeg jpg tif tiff png bmp))) {
$row[$i] .= '<img src="'.$file->getThumbnail.'" border=0 align="middle" hspace="3">';
}
$row[$i] .= $download{briefSynopsis}.'</td>'.'<td class="tableData" valign="top">'.
epochToHuman($download{dateUploaded},"%z").'</td></tr>';
$flag = 1;
$i++;
}
$sort = $session{scratch}{$namespace.".".$_[0]->get("wobjectId").".sort"} || "dateUploaded";
$sortDirection = $session{scratch}{$namespace.".".$_[0]->get("wobjectId").".sortDirection"} || "desc";
$sql .= " order by $sort $sortDirection";
$p = WebGUI::Paginator->new($url,[],$numResults);
$p->setDataByQuery($sql);
$files = $p->getPageData;
foreach $file (@$files) {
$file1 = WebGUI::Attachment->new($file->{downloadFile},$_[0]->get("wobjectId"),$file->{FileManager_fileId});
$file2 = WebGUI::Attachment->new($file->{alternateVersion1},$_[0]->get("wobjectId"),$file->{FileManager_fileId});
$file3 = WebGUI::Attachment->new($file->{alternateVersion2},$_[0]->get("wobjectId"),$file->{FileManager_fileId});
push (@fileloop,{
"file.canView"=>WebGUI::Privilege::isInGroup($file->{groupToView}),
"file.controls"=>deleteIcon('func=deleteDownload&wid='.$_[0]->get("wobjectId")
.'&did='.$file->{FileManager_fileId}).editIcon('func=editDownload&wid='.$_[0]->get("wobjectId")
.'&did='.$file->{FileManager_fileId}).moveUpIcon('func=moveDownloadUp&wid='
.$_[0]->get("wobjectId")
.'&did='.$file->{FileManager_fileId}).moveDownIcon('func=moveDownloadDown&wid='
.$_[0]->get("wobjectId").'&did='.$file->{FileManager_fileId}),
"file.title"=>$file->{fileTitle},
"file.version1.name"=>$file1->getFilename,
"file.version1.url"=>$file1->getURL,
"file.version1.icon"=>$file1->getIcon,
"file.version1.size"=>$file1->getSize,
"file.version1.type"=>$file1->getType,
"file.version1.thumbnail"=>$file1->getThumbnail,
"file.version1.isImage"=>$file1->isImage,
"file.version2.name"=>$file2->getFilename,
"file.version2.url"=>$file2->getURL,
"file.version2.icon"=>$file2->getIcon,
"file.version2.size"=>$file2->getSize,
"file.version2.type"=>$file2->getType,
"file.version2.thumbnail"=>$file2->getThumbnail,
"file.version2.isImage"=>$file2->isImage,
"file.version3.name"=>$file3->getFilename,
"file.version3.url"=>$file3->getURL,
"file.version3.icon"=>$file3->getIcon,
"file.version3.size"=>$file3->getSize,
"file.version3.type"=>$file3->getType,
"file.version3.thumbnail"=>$file3->getThumbnail,
"file.version3.isImage"=>$file3->isImage,
"file.description"=>$file->{briefSynopsis},
"file.date"=>epochToHuman($file->{dateUploaded},"%z"),
"file.time"=>epochToHuman($file->{dateUploaded},"%Z")
});
$flag = 1;
}
$sth->finish;
$output .= '<tr><td class="tableData" colspan="3">'.WebGUI::International::get(19,$namespace).'</td></tr>' unless ($flag);
$p = WebGUI::Paginator->new($url,\@row,$numResults);
$output .= $p->getPage($session{form}{pn});
$output .= '</table>';
$output .= $p->getBarTraditional($session{form}{pn});
return $output;
$var{"noresults.message"} = WebGUI::International::get(19,$namespace);
$var{noresults} = !$flag;
$var{file_loop} = \@fileloop;
$var{firstPage} = $p->getFirstPageLink;
$var{lastPage} = $p->getLastPageLink;
$var{nextPage} = $p->getNextPageLink;
$var{pageList} = $p->getPageLinks;
$var{previousPage} = $p->getPreviousPageLink;
$var{multiplePages} = ($p->getNumberOfPages > 1);
return $_[0]->processMacros($_[0]->processTemplate($_[0]->get("templateId"),\%var));
}