Fixes to restore Postgres compatibility.

This commit is contained in:
JT Smith 2002-08-17 20:00:08 +00:00
parent 64218127cb
commit dc247baefd
9 changed files with 76 additions and 40 deletions

View file

@ -44,6 +44,7 @@ sub _deleteReplyTree {
#-------------------------------------------------------------------
sub _duplicateReplyTree {
my ($sth, %data, $newMessageId);
tie %data, 'Tie::CPHash';
$sth = WebGUI::SQL->read("select * from discussion where pid=$_[0] order by messageId");
while (%data = $sth->hash) {
$newMessageId = getNextId("messageId");
@ -137,6 +138,7 @@ sub denyPost {
#-------------------------------------------------------------------
sub duplicate {
my ($sth, %data, $newMessageId, $oldSubId, $newSubId);
tie %data, 'Tie::CPHash';
$oldSubId = $_[2] || 0;
$newSubId = $_[3] || 0;
$sth = WebGUI::SQL->read("select * from discussion where wobjectId=$_[0] and pid=0 and subId=$oldSubId order by messageId");
@ -312,7 +314,7 @@ sub postSave {
($session{form}{mid},$session{form}{wid},$session{form}{sid},$rid,$pid,$session{user}{userId},"
.quote($username).", '$status')");
} elsif ($session{setting}{addEditStampToPosts}) {
$session{form}{message} = "\n --- (Edited at ".localtime(time)." by $session{user}{username}) --- \n\n"
$session{form}{message} = "\n --- (Edited at ".epochToHuman(time())." by $session{user}{username}) --- \n\n"
.$session{form}{message};
}
WebGUI::SQL->write("update discussion set subject=".quote($session{form}{subject}).",
@ -515,6 +517,7 @@ sub showReplyTree {
#-------------------------------------------------------------------
sub showThreads {
my ($sth, %data, $html, $sql);
tie %data, 'Tie::CPHash';
$sql = "select * from discussion where wobjectId=$session{form}{wid}";
$sql .= " and subId=$session{form}{sid}" if ($session{form}{sid});
$sql .= " and (status='Approved' or userId=$session{user}{userId})";

View file

@ -78,6 +78,19 @@ sub fatalError {
print '<br>'.$session{setting}{companyEmail};
print '<br>'.$session{setting}{companyURL};
}
print '<h3>Session Variables</h3><table bgcolor="#ffffff" style="color: #000000; font-size: 10pt; font-family: helvetica;">';
while (my ($section, $hash) = each %session) {
while (my ($key, $value) = each %$hash) {
if (ref $value eq 'ARRAY') {
$value = '['.join(', ',@$value).']';
} elsif (ref $value eq 'HASH') {
$value = '{'.join(', ',map {"$_ => $value->{$_}"} keys %$value).'}';
}
print '<tr><td align="right"><b>'.$section.'.'.$key.':</b></td><td>'.$value.'</td>';
}
print '<tr height=10><td>&nbsp;</td><td>&nbsp</td></tr>';
}
print '</table>';
exit;
}

View file

@ -34,7 +34,7 @@ sub process {
foreach $macro (keys %{$session{macro}}) {
$cmd = "WebGUI::Macro::".$macro."::process";
$output = eval{&$cmd($output)};
WebGUI::ErrorHandler::fatalError("Processing failed on macro: $macro.") if($@);
WebGUI::ErrorHandler::fatalError("Processing failed on macro: $macro: ".$@) if($@);
}
return $output;
}

View file

@ -271,7 +271,15 @@ sub hash {
=cut
sub hashRef {
return $_[0]->{_sth}->fetchrow_hashref() or WebGUI::ErrorHandler::fatalError("Couldn't fetch hashref. ".$_[0]->{_sth}->errstr);
my ($hashRef, %hash);
$hashRef = $_[0]->{_sth}->fetchrow_hashref();
tie %hash, 'Tie::CPHash';
if (defined $hashRef) {
%hash = %{$hashRef};
return \%hash;
} else {
return $hashRef;
}
}
@ -375,10 +383,13 @@ sub quickHash {
=cut
sub quickHashRef {
my ($sth, %hash);
tie %hash, "Tie::CPHash";
%hash = $_[0]->quickHash($_[1],$_[2]);
return \%hash;
my ($sth, $data);
$sth = WebGUI::SQL->new($_[1],$_[2]);
$data = $sth->hashRef;
$sth->finish;
if (defined $data) {
return $data;
}
}
#-------------------------------------------------------------------

View file

@ -277,12 +277,19 @@ sub get {
=item keyValue
An integer containing the key value.
An integer containing the key value. If key value is equal to "new"
or null, then an empty hashRef containing only keyName=>"new" will
be returned to avoid strict errors.
=cut
sub getCollateral {
return WebGUI::SQL->quickHashRef("select * from $_[1] where $_[2]=".quote($_[3]));
my ($class, $tableName, $keyName, $keyValue) = @_;
if ($keyValue eq "new" || $keyValue eq "") {
return {$keyName=>"new"};
} else {
return WebGUI::SQL->quickHashRef("select * from $tableName where $keyName=".quote($keyValue));
}
}
@ -729,6 +736,11 @@ sub www_editSave {
$startDate = setToEpoch($session{form}{startDate}) || $session{page}{startDate};
$endDate = setToEpoch($session{form}{endDate}) || $session{page}{endDate};
$session{form}{description} = WebGUI::HTML::cleanSegment($session{form}{description});
$session{form}{karmaPerPost} ||= 0;
$session{form}{groupToPost} ||= 2;
$session{form}{editTimeout} = WebGUI::DateTime::intervalToSeconds($session{form}{editTimeout_interval},$session{form}{editTimeout_units}) || 0;
$session{form}{groupToModerate} ||= 3;
$session{form}{moderationType} ||= "after";
$_[0]->set({
title=>$title,
displayTitle=>$session{form}{displayTitle},
@ -740,7 +752,7 @@ sub www_editSave {
karmaPerPost=>$session{form}{karmaPerPost},
groupToPost=>$session{form}{groupToPost},
groupToModerate=>$session{form}{groupToModerate},
editTimeout=>WebGUI::DateTime::intervalToSeconds($session{form}{editTimeout_interval},$session{form}{editTimeout_units}),
editTimeout=>$session{form}{editTimeout},
moderationType=>$session{form}{moderationType}
});
return "";

View file

@ -242,8 +242,9 @@ sub www_editDownload {
if (WebGUI::Privilege::canEditPage()) {
if ($session{form}{did} eq "") {
$session{form}{did} = "new";
} else {
%download = WebGUI::SQL->quickHash("select * from DownloadManager_file where downloadId='$session{form}{did}'");
}
%download = WebGUI::SQL->quickHash("select * from DownloadManager_file where downloadId='$session{form}{did}'");
$output .= helpIcon(2,$namespace);
$output .= '<h1>'.WebGUI::International::get(10,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;

View file

@ -199,6 +199,7 @@ sub www_unlockThread {
#-------------------------------------------------------------------
sub www_view {
my ($sth, %data, $html, $i, $pn, $lastId, @last, $replies);
tie %data, 'Tie::CPHash';
if ($session{form}{pn} < 1) {
$pn = 0;
} else {

View file

@ -527,8 +527,7 @@ sub www_editBenefit {
$output .= '<h1>'.WebGUI::International::get(53,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{bid} = "new" if ($session{form}{bid} eq "");
$f->hidden("bid",$session{form}{bid});
$f->hidden("bid",$data->{productBenefitId});
$f->hidden("func","editBenefitSave");
$benefits = WebGUI::SQL->buildHashRef("select benefit,benefit from Product_benefit order by benefit");
$f->combo("benefit",$benefits,WebGUI::International::get(51,$namespace),[$data->{benefits}]);
@ -570,8 +569,7 @@ sub www_editFeature {
$output .= '<h1>'.WebGUI::International::get(22,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{fid} = "new" if ($session{form}{fid} eq "");
$f->hidden("fid",$session{form}{fid});
$f->hidden("fid",$data->{productFeatureId});
$f->hidden("func","editFeatureSave");
$features = WebGUI::SQL->buildHashRef("select feature,feature from Product_feature order by feature");
$f->combo("feature",$features,WebGUI::International::get(23,$namespace),[$data->{feature}]);
@ -613,8 +611,7 @@ sub www_editSpecification {
$output .= '<h1>'.WebGUI::International::get(25,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{sid} = "new" if ($session{form}{sid} eq "");
$f->hidden("sid",$session{form}{sid});
$f->hidden("sid",$data->{productSpecificationId});
$f->hidden("func","editSpecificationSave");
$hashRef = WebGUI::SQL->buildHashRef("select name,name from Product_specification order by name");
$f->combo("name",$hashRef,WebGUI::International::get(26,$namespace),[$data->{name}]);
@ -662,8 +659,7 @@ sub www_editTemplate {
$output .= '<h1>'.WebGUI::International::get(58,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{tid} = "new" if ($session{form}{tid} eq "");
$f->hidden("tid",$session{form}{tid});
$f->hidden("tid",$data->{productTemplateId});
$f->hidden("func","editTemplateSave");
$f->text("name",WebGUI::International::get(59,$namespace),$data->{name});
$f->HTMLArea("template",WebGUI::International::get(60,$namespace),$data->{template},'','','',($session{setting}{textAreaRows}+10));

View file

@ -428,36 +428,36 @@ sub www_editSave {
#-------------------------------------------------------------------
sub www_editSubmission {
my ($output, %submission, $f, @submission, $sth);
tie %submission, 'Tie::CPHash';
%submission = WebGUI::SQL->quickHash("select * from UserSubmission_submission where submissionId='$session{form}{sid}'");
if ($session{form}{sid} eq "new") {
$submission{convertCarriageReturns} = 1;
$submission{userId} = $session{user}{userId};
my ($output, $submission, $f, @submission, $sth);
$submission = $_[0]->getCollateral("UserSubmission_submission","submissionId",$session{form}{sid});
if ($submission->{submissionId} eq "new") {
$submission->{convertCarriageReturns} = 1;
$submission->{userId} = $session{user}{userId};
}
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToContribute"))
|| $submission{userId} == $session{user}{userId}
|| $submission->{userId} == $session{user}{userId}
|| WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"))) {
$output = '<h1>'.WebGUI::International::get(19,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$session{form}{wid});
$f->hidden("sid",$session{form}{sid});
$f->hidden("sid",$submission->{submissionId});
$f->hidden("func","editSubmissionSave");
$f->text("title",WebGUI::International::get(35,$namespace),$submission{title});
$f->HTMLArea("content",WebGUI::International::get(31,$namespace),$submission{content});
if ($submission{image} ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteImage&wid='.$session{form}{wid}.'&sid='.$session{form}{sid}).'">'
$f->text("title",WebGUI::International::get(35,$namespace),$submission->{title});
$f->HTMLArea("content",WebGUI::International::get(31,$namespace),$submission->{content});
if ($submission->{image} ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteImage&wid='.$session{form}{wid}.'&sid='.$submission->{submissionId}).'">'
.WebGUI::International::get(391).'</a>',WebGUI::International::get(32,$namespace));
} else {
$f->file("image",WebGUI::International::get(32,$namespace));
}
if ($submission{attachment} ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid}.'&sid='.$session{form}{sid}).'">'
if ($submission->{attachment} ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid}
.'&sid='.$submission->{submissionId}).'">'
.WebGUI::International::get(391).'</a>',WebGUI::International::get(33,$namespace));
} else {
$f->file("attachment",WebGUI::International::get(33,$namespace));
}
$f->yesNo("convertCarriageReturns",WebGUI::International::get(34,$namespace),$submission{convertCarriageReturns},
$f->yesNo("convertCarriageReturns",WebGUI::International::get(34,$namespace),$submission->{convertCarriageReturns},
'',' &nbsp; '.WebGUI::International::get(38,$namespace));
$f->submit;
$output .= $f->print;
@ -470,12 +470,11 @@ sub www_editSubmission {
#-------------------------------------------------------------------
sub www_editSubmissionSave {
my ($sqlAdd,$owner,$image,$attachment,$title,$u);
($owner) = WebGUI::SQL->quickArray("select userId from UserSubmission_submission where submissionId='$session{form}{sid}'");
if ($owner == $session{user}{userId}
|| ($session{form}{sid} eq "new" && WebGUI::Privilege::isInGroup($_[0]->get("groupToContribute")))
|| WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"))) {
if ($session{form}{sid} eq "new") {
my ($sqlAdd,$submission,$image,$attachment,$title,$u);
$submission = $_[0]->getCollateral("UserSubmission_submission","submissionId",$session{form}{sid});
if ($submission->{owner} == $session{user}{userId} || ($submission->{submissionId} eq "new"
&& WebGUI::Privilege::isInGroup($_[0]->get("groupToContribute"))) || WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"))) {
if ($submission->{submissionId} eq "new") {
$session{form}{sid} = getNextId("submissionId");
WebGUI::SQL->write("insert into UserSubmission_submission (wobjectId,submissionId,userId,username)
values (".$_[0]->get("wobjectId").",$session{form}{sid},$session{user}{userId},".quote($session{user}{username}).")");