Initial commit.
This commit is contained in:
93
htdocs/emandy/magicat/lib/perl5/Selima/emandy/Items.pm
Normal file
93
htdocs/emandy/magicat/lib/perl5/Selima/emandy/Items.pm
Normal file
@@ -0,0 +1,93 @@
|
||||
# Mandy Wu's Website
|
||||
# Items.pm: The data record related subroutines.
|
||||
|
||||
# Copyright (c) 2006-2018 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Author: imacat <imacat@mail.imacat.idv.tw>
|
||||
# First written: 2006-11-14
|
||||
|
||||
package Selima::emandy::Items;
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(Exporter);
|
||||
use vars qw(@EXPORT @EXPORT_OK);
|
||||
BEGIN {
|
||||
@EXPORT = qw();
|
||||
push @EXPORT, qw(mtrltype_title mtrltype_options);
|
||||
@EXPORT_OK = @EXPORT;
|
||||
# Prototype declaration
|
||||
sub mtrltype_title($);
|
||||
sub mtrltype_options($);
|
||||
}
|
||||
|
||||
use Selima::ChkFunc;
|
||||
use Selima::CommText;
|
||||
use Selima::DataVars qw($DBH :l10n :lninfo);
|
||||
use Selima::EchoForm;
|
||||
use Selima::GetLang;
|
||||
use Selima::LnInfo;
|
||||
|
||||
# mtrltype_title: Obtain a material type title
|
||||
sub mtrltype_title($) {
|
||||
local ($_, %_);
|
||||
my ($sn, $sql, $sth, $row);
|
||||
$sn = $_[0];
|
||||
# Bounce if there is any problem with $sn
|
||||
return t_notset if !defined $sn;
|
||||
|
||||
# Check the serial number first
|
||||
return t_na if !check_sn $sn;
|
||||
|
||||
# Query
|
||||
$sql = "SELECT title FROM mtrltype"
|
||||
. " WHERE sn=$sn;\n";
|
||||
$sth = $DBH->prepare($sql);
|
||||
$sth->execute;
|
||||
|
||||
# Not found
|
||||
return t_na unless $sth->rows == 1;
|
||||
|
||||
# Found
|
||||
return ${$sth->fetch}[0];
|
||||
}
|
||||
|
||||
# mtrltype_options: Obtain a material type options list
|
||||
sub mtrltype_options($) {
|
||||
local ($_, %_);
|
||||
my ($value, $sql, $thiscol, $defcol, $content);
|
||||
$value = $_[0];
|
||||
|
||||
# Unilingual
|
||||
if (@ALL_LINGUAS == 1) {
|
||||
$content = "title AS content";
|
||||
# Multilingual
|
||||
} else {
|
||||
$thiscol = "title_" . getlang(LN_DATABASE);
|
||||
# Default language
|
||||
if (getlang eq $DEFAULT_LANG) {
|
||||
$content = "$thiscol AS content";
|
||||
# Fall back to the default language
|
||||
} else {
|
||||
$defcol = "title_" . ln($DEFAULT_LANG, LN_DATABASE);
|
||||
$content = "COALESCE($thiscol, $defcol) AS content";
|
||||
}
|
||||
}
|
||||
$sql = "SELECT sn AS value, $content FROM mtrltype"
|
||||
. " ORDER BY ord;\n";
|
||||
return opt_list $sql, $value;
|
||||
}
|
||||
|
||||
return 1;
|
||||
Reference in New Issue
Block a user