Added Download Manager wobject.
This commit is contained in:
parent
a566656055
commit
a9b81dc63f
5 changed files with 464 additions and 654 deletions
|
|
@ -56,6 +56,13 @@ delete from widget where namespace='LinkList';
|
|||
alter table LinkList_link change widgetId wobjectId int not null;
|
||||
alter table LinkList change widgetId wobjectId int not null;
|
||||
|
||||
insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, startDate, endDate) select widgetId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, dateAdded, 1336444487 from widget where namespace='DownloadManager';
|
||||
delete from widget where namespace='DownloadManager';
|
||||
alter table DownloadManager change widgetId wobjectId int not null;
|
||||
alter table DownloadManager_file change widgetId wobjectId int not null;
|
||||
delete from International where helpId=13 and namespace='DownloadManager';
|
||||
INSERT INTO international VALUES (22,'DownloadManager','English','Proceed to add download?');
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ sub file {
|
|||
=item value
|
||||
|
||||
The default value(s) for this form element. This should be passed
|
||||
as an array reference.
|
||||
as an array reference. Defaults to "7" (Everyone).
|
||||
|
||||
=item size
|
||||
|
||||
|
|
@ -359,6 +359,7 @@ sub group {
|
|||
$name = shift;
|
||||
$label = shift;
|
||||
$value = shift;
|
||||
$value = [7] if ($value eq ""); #doing long form otherwise arrayRef didn't work
|
||||
$size = shift || 1;
|
||||
$multiple = shift;
|
||||
$multiple = ' multiple="1" ' if ($multiple);
|
||||
|
|
@ -1180,7 +1181,7 @@ sub yesNo {
|
|||
$class = shift;
|
||||
$name = shift;
|
||||
$label = shift;
|
||||
$value = shift;
|
||||
$value = shift || 0;
|
||||
$extras = shift;
|
||||
$subtext = shift;
|
||||
$output = '<input type="radio" name="'.$name.'" value="1"';
|
||||
|
|
|
|||
|
|
@ -1,651 +0,0 @@
|
|||
package WebGUI::Widget::DownloadManager;
|
||||
|
||||
our $namespace = "DownloadManager";
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2002 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Shortcut;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Widget;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _reorderDownloads {
|
||||
my ($sth, $i, $did);
|
||||
$sth = WebGUI::SQL->read("select downloadId from DownloadManager_file where widgetId=$_[0] order by sequenceNumber");
|
||||
while (($did) = $sth->array) {
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber='$i' where downloadId=$did");
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my (%data, $file, $newWidgetId, $pageId, %row, $sth, $newDownloadId);
|
||||
tie %data, 'Tie::CPHash';
|
||||
%data = getProperties($namespace,$_[0]);
|
||||
$pageId = $_[1] || $data{pageId};
|
||||
$newWidgetId = create(
|
||||
$pageId,
|
||||
$namespace,
|
||||
$data{title},
|
||||
$data{displayTitle},
|
||||
$data{description},
|
||||
$data{processMacros},
|
||||
$data{templatePosition}
|
||||
);
|
||||
WebGUI::SQL->write("insert into DownloadManager values ($newWidgetId, $data{paginateAfter}, $data{displayThumbnails})");
|
||||
$sth = WebGUI::SQL->read("select * from DownloadManager_file where widgetId=$_[0]");
|
||||
while (%row = $sth->hash) {
|
||||
$newDownloadId = getNextId("downloadId");
|
||||
$file = WebGUI::Attachment->new($row{downloadFile},$_[0],$row{downloadId});
|
||||
$file->copy($newWidgetId,$newDownloadId);
|
||||
$file = WebGUI::Attachment->new($row{alternateVersion1},$_[0],$row{downloadId});
|
||||
$file->copy($newWidgetId,$newDownloadId);
|
||||
$file = WebGUI::Attachment->new($row{alternateVersion2},$_[0],$row{downloadId});
|
||||
$file->copy($newWidgetId,$newDownloadId);
|
||||
WebGUI::SQL->write("insert into DownloadManager_file values ($newDownloadId, $newWidgetId, ".
|
||||
quote($row{fileTitle}).", ".quote($row{downloadFile}).", $row{groupToView}, ".
|
||||
quote($row{briefSynopsis}).", $row{dateUploaded}, $row{sequenceNumber}, ".
|
||||
quote($row{alternateVersion1}).", ".quote($row{alternateVersion2}).")");
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
purgeWidget($_[0],$_[1],$namespace);
|
||||
WebGUI::SQL->write("delete from DownloadManager_file where widgetId=$_[0]");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub widgetName {
|
||||
return WebGUI::International::get(1,$namespace);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_add {
|
||||
my ($output, %hash);
|
||||
tie %hash,'Tie::IxHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = helpLink(1,$namespace);
|
||||
$output .= '<h1>'.WebGUI::International::get(2,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("widget",$namespace);
|
||||
$output .= WebGUI::Form::hidden("func","addSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(99),
|
||||
WebGUI::Form::text("title",20,30,widgetName())
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(174),
|
||||
WebGUI::Form::checkbox("displayTitle",1,1)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(175),
|
||||
WebGUI::Form::checkbox("processMacros",1,1)
|
||||
);
|
||||
%hash = WebGUI::Widget::getPositions();
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(363),
|
||||
WebGUI::Form::selectList("templatePosition",\%hash)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(85),
|
||||
WebGUI::Form::textArea("description",'',50,5,1)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(20,$namespace),
|
||||
WebGUI::Form::text("paginateAfter",20,30,50)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(21,$namespace),
|
||||
WebGUI::Form::checkbox("displayThumbnails",1,1)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(3,$namespace),
|
||||
WebGUI::Form::checkbox("proceed",1,1)
|
||||
);
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addSave {
|
||||
my ($widgetId);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$widgetId = create(
|
||||
$session{page}{pageId},
|
||||
$session{form}{widget},
|
||||
$session{form}{title},
|
||||
$session{form}{displayTitle},
|
||||
$session{form}{description},
|
||||
$session{form}{processMacros},
|
||||
$session{form}{templatePosition}
|
||||
);
|
||||
WebGUI::SQL->write("insert into DownloadManager values ($widgetId, '$session{form}{paginateAfter}', '$session{form}{displayThumbnails}')");
|
||||
if ($session{form}{proceed} == 1) {
|
||||
$session{form}{wid} = $widgetId;
|
||||
return www_addDownload();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addDownload {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output .= '<h1>'.WebGUI::International::get(4,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("func","addDownloadSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(6,$namespace),
|
||||
WebGUI::Form::file("downloadFile")
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(17,$namespace),
|
||||
WebGUI::Form::file("alternateVersion1")
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(18,$namespace),
|
||||
WebGUI::Form::file("alternateVersion2")
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(5,$namespace),
|
||||
WebGUI::Form::text("fileTitle",20,128,WebGUI::International::get(5,$namespace))
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(8,$namespace),
|
||||
WebGUI::Form::text("briefSynopsis",50,256)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(7,$namespace),
|
||||
WebGUI::Form::groupList("groupToView",2)
|
||||
);
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addDownloadSave {
|
||||
my ($downloadId,$file,$alt1,$alt2,$sequenceNumber);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$downloadId = getNextId("downloadId");
|
||||
$file = WebGUI::Attachment->new("",$session{form}{wid},$downloadId);
|
||||
$file->save("downloadFile");
|
||||
$alt1 = WebGUI::Attachment->new("",$session{form}{wid},$downloadId);
|
||||
$alt1->save("alternateVersion1");
|
||||
$alt2 = WebGUI::Attachment->new("",$session{form}{wid},$downloadId);
|
||||
$alt2->save("alternateVersion2");
|
||||
($sequenceNumber) = WebGUI::SQL->quickArray("select count(*) from DownloadManager_file where widgetId=$session{form}{wid}");
|
||||
$sequenceNumber++;
|
||||
WebGUI::SQL->write("insert into DownloadManager_file values (".
|
||||
$downloadId.
|
||||
", ".$session{form}{wid}.
|
||||
", ".quote($session{form}{fileTitle}).
|
||||
", ".quote($file->getFilename).
|
||||
", '$session{form}{groupToView}'".
|
||||
", ".quote($session{form}{briefSynopsis}).
|
||||
", ".time().
|
||||
", ".$sequenceNumber.
|
||||
", ".quote($alt1->getFilename).
|
||||
", ".quote($alt2->getFilename).
|
||||
")");
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copy {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
duplicate($session{form}{wid});
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteFile {
|
||||
my ($delete);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
if ($session{form}{alt} == 1) {
|
||||
$delete = "alternateVersion1";
|
||||
} elsif ($session{form}{alt} == 2) {
|
||||
$delete = "alternateVersion2";
|
||||
} else {
|
||||
$delete = "downloadFile";
|
||||
}
|
||||
WebGUI::SQL->write("update DownloadManager_file set $delete='' where downloadId=$session{form}{did}");
|
||||
return www_editDownload();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteDownload {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= WebGUI::International::get(12,$namespace).'<p>';
|
||||
$output .= '<div align="center">'.
|
||||
'<a href="'.WebGUI::URL::page('func=deleteDownloadConfirm&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('func=edit&wid='.$session{form}{wid}).'">'.
|
||||
WebGUI::International::get(45).'</a></div>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteDownloadConfirm {
|
||||
my ($output, $file);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$file->deleteNode;
|
||||
WebGUI::SQL->write("delete from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
_reorderDownloads($session{form}{wid});
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_download {
|
||||
my (%download, $file);
|
||||
tie %download,'Tie::CPHash';
|
||||
%download = WebGUI::SQL->quickHash("select * from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
if (WebGUI::Privilege::isInGroup($download{groupToView})) {
|
||||
if ($session{form}{alternateVersion} == 1) {
|
||||
$file = WebGUI::Attachment->new($download{alternateVersion1},
|
||||
$session{form}{wid},
|
||||
$session{form}{did});
|
||||
} elsif ($session{form}{alternateVersion} == 2) {
|
||||
$file = WebGUI::Attachment->new($download{alternateVersion2},
|
||||
$session{form}{wid},
|
||||
$session{form}{did});
|
||||
} else {
|
||||
$file = WebGUI::Attachment->new($download{downloadFile},
|
||||
$session{form}{wid},
|
||||
$session{form}{did});
|
||||
}
|
||||
$session{header}{redirect} = WebGUI::Session::httpRedirect($file->getURL);
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my ($output, %data, %hash, @array, $sth, @download);
|
||||
tie %data, 'Tie::CPHash';
|
||||
tie %hash, 'Tie::IxHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
%data = getProperties($namespace,$session{form}{wid});
|
||||
$output .= helpLink(1,$namespace);
|
||||
$output .= '<h1>'.WebGUI::International::get(9,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("func","editSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(99),
|
||||
WebGUI::Form::text("title",20,30,$data{title})
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(174),
|
||||
WebGUI::Form::checkbox("displayTitle","1",$data{displayTitle})
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(175),
|
||||
WebGUI::Form::checkbox("processMacros","1",
|
||||
$data{processMacros})
|
||||
);
|
||||
%hash = WebGUI::Widget::getPositions();
|
||||
$array[0] = $data{templatePosition};
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(363),
|
||||
WebGUI::Form::selectList("templatePosition",\%hash,\@array)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(85),
|
||||
WebGUI::Form::textArea("description",$data{description},50,5,1)
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(20,$namespace),
|
||||
WebGUI::Form::text("paginateAfter",20,30,$data{paginateAfter})
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(21,$namespace),
|
||||
WebGUI::Form::checkbox("displayThumbnails","1",$data{displayThumbnails})
|
||||
);
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
$output .= '<p><a href="'.WebGUI::URL::page('func=addDownload&wid='.$session{form}{wid})
|
||||
.'">'.WebGUI::International::get(11,$namespace).'</a><p>';
|
||||
$output .= '<table border=1 cellpadding=3 cellspacing=0>';
|
||||
$sth = WebGUI::SQL->read("select downloadId,fileTitle from DownloadManager_file where widgetId='$session{form}{wid}' order by sequenceNumber");
|
||||
while (@download = $sth->array) {
|
||||
$output .= '<tr><td><a href="'.
|
||||
WebGUI::URL::page('func=editDownload&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.'"><img src="'.
|
||||
$session{setting}{lib}.'/edit.gif" border=0></a><a href="'.
|
||||
WebGUI::URL::page('func=deleteDownload&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.'"><img src="'.
|
||||
$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.
|
||||
WebGUI::URL::page('func=moveDownloadUp&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.'"><img src="'.
|
||||
$session{setting}{lib}.'/upArrow.gif" border=0></a><a href="'.
|
||||
WebGUI::URL::page('func=moveDownloadDown&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.'"><img src="'.$session{setting}{lib}.
|
||||
'/downArrow.gif" border=0></a></td><td>'.$download[1].'</td><tr>';
|
||||
}
|
||||
$sth->finish;
|
||||
$output .= '</table>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
update();
|
||||
WebGUI::SQL->write("update DownloadManager set paginateAfter='$session{form}{paginateAfter}', displayThumbnails='$session{form}{displayThumbnails}' where widgetId=$session{form}{wid}");
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editDownload {
|
||||
my ($output, %download);
|
||||
tie %download,'Tie::CPHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
%download = WebGUI::SQL->quickHash("select * from DownloadManager_file where downloadId='$session{form}{did}'");
|
||||
$output .= '<h1>'.WebGUI::International::get(10,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("did",$session{form}{did});
|
||||
$output .= WebGUI::Form::hidden("func","editDownloadSave");
|
||||
$output .= '<table>';
|
||||
if ($download{downloadFile} ne "") {
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(6,$namespace),
|
||||
'<a href="'.WebGUI::URL::page('func=deleteFile&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(13,$namespace).'</a>
|
||||
');
|
||||
} else {
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(6,$namespace),
|
||||
WebGUI::Form::file("downloadFile")
|
||||
);
|
||||
}
|
||||
if ($download{alternateVersion1} ne "") {
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(17,$namespace),
|
||||
'<a href="'.WebGUI::URL::page('func=deleteFile&alt=1&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(13,$namespace).'</a>
|
||||
');
|
||||
} else {
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(17,$namespace),
|
||||
WebGUI::Form::file("alternateVersion1")
|
||||
);
|
||||
}
|
||||
if ($download{alternateVersion2} ne "") {
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(18,$namespace),
|
||||
'<a href="'.WebGUI::URL::page('func=deleteFile&alt=2&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(13,$namespace).'</a>
|
||||
');
|
||||
} else {
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(18,$namespace),
|
||||
WebGUI::Form::file("alternateVersion2")
|
||||
);
|
||||
}
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(5,$namespace),
|
||||
WebGUI::Form::text("fileTitle",20,128,$download{fileTitle})
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(8,$namespace),
|
||||
WebGUI::Form::text("briefSynopsis",50,256,$download{briefSynopsis})
|
||||
);
|
||||
$output .= tableFormRow(
|
||||
WebGUI::International::get(7,$namespace),
|
||||
WebGUI::Form::groupList("groupToView",$download{groupToView})
|
||||
);
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editDownloadSave {
|
||||
my ($file, $alt1, $alt2, $sqlAdd);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$file->save("downloadFile");
|
||||
if ($file->getFilename ne "") {
|
||||
$sqlAdd = ', downloadFile='.quote($file->getFilename);
|
||||
}
|
||||
$alt1 = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$alt1->save("alternateVersion1");
|
||||
if ($alt1->getFilename ne "") {
|
||||
$sqlAdd .= ', alternateVersion1='.quote($alt1->getFilename);
|
||||
}
|
||||
$alt2 = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$alt2->save("alternateVersion2");
|
||||
if ($alt2->getFilename ne "") {
|
||||
$sqlAdd = ', alternateVersion2='.quote($alt2->getFilename);
|
||||
}
|
||||
WebGUI::SQL->write("update DownloadManager_file set ".
|
||||
" downloadId=".$session{form}{did}.
|
||||
", widgetId=".$session{form}{wid}.
|
||||
", fileTitle=".quote($session{form}{fileTitle}).
|
||||
$sqlAdd.
|
||||
", groupToView='$session{form}{groupToView}'".
|
||||
", briefSynopsis=".quote($session{form}{briefSynopsis}).
|
||||
", dateUploaded=".time().
|
||||
" where downloadId=".$session{form}{did}
|
||||
);
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveDownloadDown {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
@data = WebGUI::SQL->quickArray("select downloadId from DownloadManager_file where widgetId=$session{form}{wid} and sequenceNumber=$thisSeq+1 group by widgetId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber+1 where downloadId=$session{form}{did}");
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber-1 where downloadId=$data[0]");
|
||||
}
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveDownloadUp {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
@data = WebGUI::SQL->quickArray("select downloadId from DownloadManager_file where widgetId=$session{form}{wid} and sequenceNumber=$thisSeq-1 group by widgetId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber-1 where downloadId=$session{form}{did}");
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber+1 where downloadId=$data[0]");
|
||||
}
|
||||
return www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my ($url, @row, $head, $searchForm, $i, $p, $search, %data, @test, $file, $alt1, $alt2, $output, $sth,
|
||||
%download, $flag, $sort, $sortDirection);
|
||||
tie %download, 'Tie::CPHash';
|
||||
tie %data, 'Tie::CPHash';
|
||||
%data = getProperties($namespace,$_[0]);
|
||||
if (defined %data) {
|
||||
$url = WebGUI::URL::page();
|
||||
if ($data{displayTitle} == 1) {
|
||||
$output .= '<h1>'.$data{title}.'</h1>';
|
||||
}
|
||||
if ($data{description} ne "") {
|
||||
$output .= $data{description}.'<p>';
|
||||
}
|
||||
$searchForm = formHeader();
|
||||
$searchForm .= WebGUI::Form::text("keyword",20,50);
|
||||
$searchForm .= WebGUI::Form::submit(WebGUI::International::get(170));
|
||||
$searchForm .= '</form>';
|
||||
$head = '<table cellpadding="3" cellspacing="1" border="0" width="100%">';
|
||||
if ($session{form}{keyword} ne "") {
|
||||
$search = " and (fileTitle like '%".$session{form}{keyword}.
|
||||
"%' or downloadFile like '%".$session{form}{keyword}.
|
||||
"%' or alternateVersion1 like '%".$session{form}{keyword}.
|
||||
"%' or alternateVersion2 like '%".$session{form}{keyword}.
|
||||
"%' or briefSynopsis like '%".$session{form}{keyword}."%') ";
|
||||
$url = WebGUI::URL::append($url,"keyword=".$session{form}{keyword});
|
||||
}
|
||||
if ($session{form}{sort} ne "") {
|
||||
$sort = " order by ".$session{form}{sort};
|
||||
$url = WebGUI::URL::append($url,"sort=".$session{form}{sort});
|
||||
} else {
|
||||
$sort = " order by sequenceNumber";
|
||||
}
|
||||
if ($session{form}{sortDirection} ne "") {
|
||||
$sortDirection = $session{form}{sortDirection};
|
||||
$url = WebGUI::URL::append($url,"sortDirection=".$session{form}{sortDirection});
|
||||
}
|
||||
$head .= '<tr><td class="tableHeader">'.
|
||||
sortByColumn("fileTitle",WebGUI::International::get(14,$namespace)).
|
||||
'</td><td class="tableHeader">'.
|
||||
sortByColumn("briefSynopsis",WebGUI::International::get(15,$namespace)).
|
||||
'</td><td class="tableHeader">'.
|
||||
sortByColumn("dateUploaded",WebGUI::International::get(16,$namespace)).
|
||||
'</td></tr>';
|
||||
$sth = WebGUI::SQL->read("select * from DownloadManager_file where widgetId=$_[0] $search $sort $sortDirection");
|
||||
while (%download = $sth->hash) {
|
||||
if (WebGUI::Privilege::isInGroup($download{groupToView})) {
|
||||
$file = WebGUI::Attachment->new($download{downloadFile},
|
||||
$_[0], $download{downloadId});
|
||||
$row[$i] = '<tr><td class="tableData" valign="top">';
|
||||
$row[$i] .= '<a href="'.WebGUI::URL::page('func=download&wid='.$_[0].
|
||||
'&did='.$download{downloadId}).'"><img src="'.$file->getIcon.
|
||||
'" border=0 width=16 height=16 align="middle">'.
|
||||
$download{fileTitle}.' ('.$file->getType.')</a>';
|
||||
if ($download{alternateVersion1}) {
|
||||
$alt1 = WebGUI::Attachment->new($download{alternateVersion1},
|
||||
$_[0], $download{downloadId});
|
||||
$row[$i] .= ' · <a href="'.WebGUI::URL::page('func=download&wid='.
|
||||
$_[0].'&did='.$download{downloadId}.'&alternateVersion=1')
|
||||
.'"><img src="'.$alt1->getIcon.
|
||||
'" border=0 width=16 height=16 align="middle">('.
|
||||
$alt1->getType.')</a>';
|
||||
}
|
||||
if ($download{alternateVersion2}) {
|
||||
$alt2 = WebGUI::Attachment->new($download{alternateVersion2},
|
||||
$_[0], $download{downloadId});
|
||||
$row[$i] .= ' · <a href="'.WebGUI::URL::page('func=download&wid='.
|
||||
$_[0].'&did='.$download{downloadId}.'&alternateVersion=2')
|
||||
.'"><img src="'.$alt2->getIcon.
|
||||
'" border=0 width=16 height=16 align="middle">('.
|
||||
$alt2->getType.')</a>';
|
||||
}
|
||||
$row[$i] .= '</td><td class="tableData" valign="top">';
|
||||
if ($data{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},"%M/%D/%y").'</td>'.
|
||||
'</tr>';
|
||||
$flag = 1;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
unless ($flag) {
|
||||
$head .= '<tr><td class="tableData" colspan="3">'.
|
||||
WebGUI::International::get(19,$namespace).'</td></tr>';
|
||||
}
|
||||
$p = WebGUI::Paginator->new($url,\@row,$data{paginateAfter});
|
||||
$output .= $searchForm if ($p->getNumberOfPages > 1);
|
||||
$output .= $head;
|
||||
$output .= $p->getPage($session{form}{pn});
|
||||
$output .= '</table>';
|
||||
$output .= $p->getBarTraditional($session{form}{pn});
|
||||
if ($data{processMacros} == 1) {
|
||||
$output = WebGUI::Macro::process($output);
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
|
@ -406,7 +406,7 @@ sub www_edit {
|
|||
$f->hidden("wid",$_[0]->get("wobjectId"));
|
||||
$f->hidden("namespace",$_[0]->get("namespace")) if ($_[0]->get("wobjectId") eq "new");
|
||||
$f->hidden("func","editSave");
|
||||
$f->submit;
|
||||
$f->submit if ($_[0]->get("wobjectId") ne "new");
|
||||
$f->readOnly($_[0]->get("wobjectId"),WebGUI::International::get(499));
|
||||
$f->text("title",WebGUI::International::get(99),$title);
|
||||
$f->yesNo("displayTitle",WebGUI::International::get(174),$displayTitle);
|
||||
|
|
|
|||
453
lib/WebGUI/Wobject/DownloadManager.pm
Normal file
453
lib/WebGUI/Wobject/DownloadManager.pm
Normal file
|
|
@ -0,0 +1,453 @@
|
|||
package WebGUI::Wobject::DownloadManager;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2002 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Wobject);
|
||||
our $namespace = "DownloadManager";
|
||||
our $name = WebGUI::International::get(1,$namespace);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _reorderDownloads {
|
||||
my ($sth, $i, $did);
|
||||
$sth = WebGUI::SQL->read("select downloadId from DownloadManager_file where wobjectId=$_[0] order by sequenceNumber");
|
||||
while (($did) = $sth->array) {
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber='$i' where downloadId=$did");
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($file, $w, %row, $sth, $newDownloadId);
|
||||
tie %row, 'Tie::CPHash';
|
||||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$w = WebGUI::Wobject::DownloadManager->new({wobjectId=>$w,namespace=>$namespace});
|
||||
$w->set({
|
||||
paginateAfter=>$_[0]->get("paginateAfter"),
|
||||
displayThumbnails=>$_[0]->get("displayThumbnails")
|
||||
});
|
||||
$sth = WebGUI::SQL->read("select * from DownloadManager_file where wobjectId=".$_[0]->get("wobjectId"));
|
||||
while (%row = $sth->hash) {
|
||||
$newDownloadId = getNextId("downloadId");
|
||||
$file = WebGUI::Attachment->new($row{downloadFile},$_[0]->get("wobjectId"),$row{downloadId});
|
||||
$file->copy($w->get("wobjectId"),$newDownloadId);
|
||||
$file = WebGUI::Attachment->new($row{alternateVersion1},$_[0]->get("wobjectId"),$row{downloadId});
|
||||
$file->copy($w->get("wobjectId"),$newDownloadId);
|
||||
$file = WebGUI::Attachment->new($row{alternateVersion2},$_[0]->get("wobjectId"),$row{downloadId});
|
||||
$file->copy($w->get("wobjectId"),$newDownloadId);
|
||||
WebGUI::SQL->write("insert into DownloadManager_file values ($newDownloadId, ".$w->get("wobjectId").", ".
|
||||
quote($row{fileTitle}).", ".quote($row{downloadFile}).", $row{groupToView}, ".
|
||||
quote($row{briefSynopsis}).", $row{dateUploaded}, $row{sequenceNumber}, ".
|
||||
quote($row{alternateVersion1}).", ".quote($row{alternateVersion2}).")");
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub new {
|
||||
my ($self, $class, $property);
|
||||
$class = shift;
|
||||
$property = shift;
|
||||
$self = WebGUI::Wobject->new($property);
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
WebGUI::SQL->write("delete from DownloadManager_file where wobjectId=$_[0]");
|
||||
$_[0]->SUPER::purge();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub set {
|
||||
$_[0]->SUPER::set($_[1],[qw(paginateAfter displayThumbnails)]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copy {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->duplicate;
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteFile {
|
||||
my ($delete);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
if ($session{form}{alt} == 1) {
|
||||
$delete = "alternateVersion1";
|
||||
} elsif ($session{form}{alt} == 2) {
|
||||
$delete = "alternateVersion2";
|
||||
} else {
|
||||
$delete = "downloadFile";
|
||||
}
|
||||
WebGUI::SQL->write("update DownloadManager_file set $delete='' where downloadId=$session{form}{did}");
|
||||
return $_[0]->www_editDownload();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteDownload {
|
||||
my ($output);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= WebGUI::International::get(12,$namespace).'<p>';
|
||||
$output .= '<div align="center">'.
|
||||
'<a href="'.WebGUI::URL::page('func=deleteDownloadConfirm&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('func=edit&wid='.$session{form}{wid}).'">'.
|
||||
WebGUI::International::get(45).'</a></div>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteDownloadConfirm {
|
||||
my ($output, $file);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$file->deleteNode;
|
||||
WebGUI::SQL->write("delete from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
_reorderDownloads($session{form}{wid});
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_download {
|
||||
my (%download, $file);
|
||||
tie %download,'Tie::CPHash';
|
||||
%download = WebGUI::SQL->quickHash("select * from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
if (WebGUI::Privilege::isInGroup($download{groupToView})) {
|
||||
if ($session{form}{alternateVersion} == 1) {
|
||||
$file = WebGUI::Attachment->new($download{alternateVersion1},
|
||||
$session{form}{wid},
|
||||
$session{form}{did});
|
||||
} elsif ($session{form}{alternateVersion} == 2) {
|
||||
$file = WebGUI::Attachment->new($download{alternateVersion2},
|
||||
$session{form}{wid},
|
||||
$session{form}{did});
|
||||
} else {
|
||||
$file = WebGUI::Attachment->new($download{downloadFile},
|
||||
$session{form}{wid},
|
||||
$session{form}{did});
|
||||
}
|
||||
$session{header}{redirect} = WebGUI::Session::httpRedirect($file->getURL);
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my ($output, $f, %hash, @array, $sth, @download, $paginateAfter, $proceed);
|
||||
tie %hash, 'Tie::IxHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
if ($_[0]->get("wobjectId") eq "new") {
|
||||
$proceed = 1;
|
||||
}
|
||||
$output .= helpIcon(1,$namespace);
|
||||
$output .= '<h1>'.WebGUI::International::get(9,$namespace).'</h1>';
|
||||
$paginateAfter = $_[0]->get("paginateAfter") || 50;
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$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);
|
||||
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
|
||||
unless ($_[0]->get("wobjectId") eq "new") {
|
||||
$output .= '<p><a href="'.WebGUI::URL::page('func=editDownload&did=new&wid='.$_[0]->get("wobjectId"))
|
||||
.'">'.WebGUI::International::get(11,$namespace).'</a><p>';
|
||||
$sth = WebGUI::SQL->read("select downloadId,fileTitle from DownloadManager_file where wobjectId='$session{form}{wid}' order by sequenceNumber");
|
||||
$output .='<table>';
|
||||
while (@download = $sth->array) {
|
||||
$output .= '<tr><td>'
|
||||
.deleteIcon('func=deleteDownload&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.editIcon('func=editDownload&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.moveUpIcon('func=moveDownloadUp&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.moveDownIcon('func=moveDownloadDown&wid='.$session{form}{wid}.'&did='.$download[0])
|
||||
.'</td><td>'.$download[1].'</td></tr>';
|
||||
}
|
||||
$sth->finish;
|
||||
$output .= '</table>';
|
||||
}
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->SUPER::www_editSave();
|
||||
$_[0]->set({
|
||||
paginateAfter=>$session{form}{paginateAfter},
|
||||
displayThumbnails=>$session{form}{displayThumbnails}
|
||||
});
|
||||
if ($session{form}{proceed}) {
|
||||
$_[0]->www_editDownload();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editDownload {
|
||||
my ($output, %download, $f);
|
||||
tie %download,'Tie::CPHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
if ($session{form}{did} eq "") {
|
||||
$session{form}{did} = "new";
|
||||
}
|
||||
%download = WebGUI::SQL->quickHash("select * from DownloadManager_file where downloadId='$session{form}{did}'");
|
||||
$output .= '<h1>'.WebGUI::International::get(10,$namespace).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->hidden("wid",$_[0]->get("wobjectId"));
|
||||
$f->hidden("did",$session{form}{did});
|
||||
$f->hidden("func","editDownloadSave");
|
||||
$f->text("fileTitle",WebGUI::International::get(5,$namespace),$download{fileTitle});
|
||||
if ($download{downloadFile} ne "") {
|
||||
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteFile&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.WebGUI::International::get(391).
|
||||
'</a>',WebGUI::International::get(6,$namespace));
|
||||
} else {
|
||||
$f->file("downloadFile",WebGUI::International::get(6,$namespace));
|
||||
}
|
||||
if ($download{alternateVersion1} ne "") {
|
||||
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteFile&alt=1&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(391).'</a>',WebGUI::International::get(17,$namespace));
|
||||
} else {
|
||||
$f->file("alternateVersion1",WebGUI::International::get(17,$namespace));
|
||||
}
|
||||
if ($download{alternateVersion2} ne "") {
|
||||
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteFile&alt=2&wid='.
|
||||
$session{form}{wid}.'&did='.$session{form}{did}).'">'.
|
||||
WebGUI::International::get(391).'</a>',WebGUI::International::get(18,$namespace));
|
||||
} else {
|
||||
$f->file("alernateVersion2",WebGUI::International::get(18,$namespace));
|
||||
}
|
||||
$f->text("briefSynopsis",WebGUI::International::get(8,$namespace),$download{briefSynopsis});
|
||||
$f->group("groupToView",WebGUI::International::get(7,$namespace),[$download{groupToView}]);
|
||||
$f->yesNo("proceed",WebGUI::International::get(22,$namespace));
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editDownloadSave {
|
||||
my ($file, $alt1, $alt2, $sqlAdd, $seq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
if ($session{form}{did} eq "new") {
|
||||
$session{form}{did} = getNextId("downloadId");
|
||||
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from DownloadManager_file where wobjectId=".$_[0]->get("wobjectId"));
|
||||
WebGUI::SQL->write("insert into DownloadManager_file (wobjectId,downloadId,sequenceNumber)
|
||||
values (".$_[0]->get("wobjectId").",$session{form}{did},".($seq+1).")");
|
||||
}
|
||||
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$file->save("downloadFile");
|
||||
if ($file->getFilename ne "") {
|
||||
$sqlAdd = ', downloadFile='.quote($file->getFilename);
|
||||
}
|
||||
$alt1 = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$alt1->save("alternateVersion1");
|
||||
if ($alt1->getFilename ne "") {
|
||||
$sqlAdd .= ', alternateVersion1='.quote($alt1->getFilename);
|
||||
}
|
||||
$alt2 = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
|
||||
$alt2->save("alternateVersion2");
|
||||
if ($alt2->getFilename ne "") {
|
||||
$sqlAdd = ', alternateVersion2='.quote($alt2->getFilename);
|
||||
}
|
||||
WebGUI::SQL->write("update DownloadManager_file set ".
|
||||
"fileTitle=".quote($session{form}{fileTitle}).
|
||||
$sqlAdd.
|
||||
", groupToView='$session{form}{groupToView}'".
|
||||
", briefSynopsis=".quote($session{form}{briefSynopsis}).
|
||||
", dateUploaded=".time().
|
||||
" where downloadId=".$session{form}{did}
|
||||
);
|
||||
if ($session{form}{proceed}) {
|
||||
$session{form}{did} = "new";
|
||||
$_[0]->www_editDownload();
|
||||
} else {
|
||||
return $_[0]->www_edit();
|
||||
}
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveDownloadDown {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
@data = WebGUI::SQL->quickArray("select downloadId from DownloadManager_file where wobjectId=$session{form}{wid} and sequenceNumber=$thisSeq+1 group by wobjectId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber+1 where downloadId=$session{form}{did}");
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber-1 where downloadId=$data[0]");
|
||||
}
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveDownloadUp {
|
||||
my (@data, $thisSeq);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from DownloadManager_file where downloadId=$session{form}{did}");
|
||||
@data = WebGUI::SQL->quickArray("select downloadId from DownloadManager_file where wobjectId=$session{form}{wid} and sequenceNumber=$thisSeq-1 group by wobjectId");
|
||||
if ($data[0] ne "") {
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber-1 where downloadId=$session{form}{did}");
|
||||
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber=sequenceNumber+1 where downloadId=$data[0]");
|
||||
}
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my ($url, @row, $head, $searchForm, $i, $p, $search, @test, $file, $alt1, $alt2, $output, $sth,
|
||||
%download, $flag, $sort, $sortDirection);
|
||||
tie %download, 'Tie::CPHash';
|
||||
$url = WebGUI::URL::page();
|
||||
$output = $_[0]->displayTitle;
|
||||
$output .= $_[0]->description;
|
||||
$searchForm = WebGUI::HTMLForm->new(1);
|
||||
$searchForm->text("keyword",'',$session{form}{keyword});
|
||||
$searchForm->submit(WebGUI::International::get(170));
|
||||
$head = '<table cellpadding="3" cellspacing="1" border="0" width="100%">';
|
||||
if ($session{form}{keyword} ne "") {
|
||||
$search = " and (fileTitle like '%".$session{form}{keyword}.
|
||||
"%' or downloadFile like '%".$session{form}{keyword}.
|
||||
"%' or alternateVersion1 like '%".$session{form}{keyword}.
|
||||
"%' or alternateVersion2 like '%".$session{form}{keyword}.
|
||||
"%' or briefSynopsis like '%".$session{form}{keyword}."%') ";
|
||||
$url = WebGUI::URL::append($url,"keyword=".$session{form}{keyword});
|
||||
}
|
||||
if ($session{form}{sort} ne "") {
|
||||
$sort = " order by ".$session{form}{sort};
|
||||
$url = WebGUI::URL::append($url,"sort=".$session{form}{sort});
|
||||
} else {
|
||||
$sort = " order by sequenceNumber";
|
||||
}
|
||||
if ($session{form}{sortDirection} ne "") {
|
||||
$sortDirection = $session{form}{sortDirection};
|
||||
$url = WebGUI::URL::append($url,"sortDirection=".$session{form}{sortDirection});
|
||||
}
|
||||
$head .= '<tr><td class="tableHeader">'.
|
||||
sortByColumn("fileTitle",WebGUI::International::get(14,$namespace)).
|
||||
'</td><td class="tableHeader">'.
|
||||
sortByColumn("briefSynopsis",WebGUI::International::get(15,$namespace)).
|
||||
'</td><td class="tableHeader">'.
|
||||
sortByColumn("dateUploaded",WebGUI::International::get(16,$namespace)).
|
||||
'</td></tr>';
|
||||
$sth = WebGUI::SQL->read("select * from DownloadManager_file where wobjectId=".$_[0]->get("wobjectId")." $search $sort $sortDirection");
|
||||
while (%download = $sth->hash) {
|
||||
if (WebGUI::Privilege::isInGroup($download{groupToView})) {
|
||||
$file = WebGUI::Attachment->new($download{downloadFile},
|
||||
$_[0]->get("wobjectId"), $download{downloadId});
|
||||
$row[$i] = '<tr><td class="tableData" valign="top">';
|
||||
$row[$i] .= '<a href="'.WebGUI::URL::page('func=download&wid='.$_[0]->get("wobjectId").
|
||||
'&did='.$download{downloadId}).'">'.$download{fileTitle}.'</a> · <a href="'.
|
||||
WebGUI::URL::page('func=download&wid='.
|
||||
$_[0]->get("wobjectId").'&did='.$download{downloadId}).'"><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{downloadId});
|
||||
$row[$i] .= ' · <a href="'.WebGUI::URL::page('func=download&wid='.
|
||||
$_[0]->get("wobjectId").'&did='.$download{downloadId}.'&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{downloadId});
|
||||
$row[$i] .= ' · <a href="'.WebGUI::URL::page('func=download&wid='.
|
||||
$_[0]->get("wobjectId").'&did='.$download{downloadId}.'&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++;
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
unless ($flag) {
|
||||
$head .= '<tr><td class="tableData" colspan="3">'.
|
||||
WebGUI::International::get(19,$namespace).'</td></tr>';
|
||||
}
|
||||
$p = WebGUI::Paginator->new($url,\@row,$_[0]->get("paginateAfter"));
|
||||
$output .= $searchForm->print if ($p->getNumberOfPages > 1);
|
||||
$output .= $head;
|
||||
$output .= $p->getPage($session{form}{pn});
|
||||
$output .= '</table>';
|
||||
$output .= $p->getBarTraditional($session{form}{pn});
|
||||
return $_[0]->processMacros($output);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue