116 lines
3.2 KiB
Perl
116 lines
3.2 KiB
Perl
# Selima Website Content Management System
|
|
# FormFunc.pm: The form-related functions.
|
|
|
|
# Copyright (c) 2003-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: 2003-03-24
|
|
|
|
package Selima::FormFunc;
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
use base qw(Exporter);
|
|
use vars qw(@EXPORT @EXPORT_OK);
|
|
BEGIN {
|
|
@EXPORT = qw(get_or_post curform is_form form_type);
|
|
@EXPORT_OK = @EXPORT;
|
|
# Prototype declaration
|
|
sub get_or_post();
|
|
sub curform();
|
|
sub is_form(;$);
|
|
sub form_type();
|
|
}
|
|
|
|
use Selima::Cache qw(:formfunc);
|
|
use Selima::CallForm;
|
|
use Selima::DataVars qw(:env :input);
|
|
|
|
# get_or_post: whether we should look for form data from $GET or $POST
|
|
sub get_or_post() {
|
|
local ($_, %_);
|
|
return $FormFunc_get_or_post if defined $FormFunc_get_or_post;
|
|
$_ = $IS_MODPERL? ($IS_MP2?
|
|
Apache2::RequestUtil->request->method: Apache->request->method):
|
|
$ENV{"REQUEST_METHOD"};
|
|
return ($FormFunc_get_or_post = $_ eq "POST"? $POST: $GET);
|
|
}
|
|
|
|
# curform: Obtain the current form, either from the sent form or
|
|
# from the suspended form
|
|
sub curform() {
|
|
local ($_, %_);
|
|
|
|
return $FormFunc_curform if defined $FormFunc_curform;
|
|
|
|
$FormFunc_curform = get_or_post;
|
|
$FormFunc_curform = retrieve_form
|
|
if defined $FormFunc_curform->param("formid");
|
|
|
|
return $FormFunc_curform;
|
|
}
|
|
|
|
# is_form: whether this is a form
|
|
sub is_form(;$) {
|
|
local ($_, %_);
|
|
my ($isform, $FORM);
|
|
$isform = $_[0];
|
|
|
|
# Use "isform" to alter the cache
|
|
if (defined $isform) {
|
|
# A status is provided
|
|
if (ref $isform eq "HASH") {
|
|
$FormFunc_isform = $$isform{"isform"}? 1: 0
|
|
if exists $$isform{"isform"};
|
|
# A scalar value
|
|
} else {
|
|
$FormFunc_isform = $isform? 1: 0;
|
|
}
|
|
}
|
|
|
|
# Return the cache
|
|
return $FormFunc_isform if defined $FormFunc_isform;
|
|
|
|
# Obtain the current form
|
|
$FORM = curform;
|
|
# No valid form infomation
|
|
return ($FormFunc_isform = 0) if !defined $FORM->param("form");
|
|
# "isform" was specified
|
|
if ( defined $FORM->param("status")
|
|
&& exists ${$FORM->param("status")}{"isform"}) {
|
|
return ($FormFunc_isform = ${$FORM->param("status")}{"isform"}? 1: 0);
|
|
}
|
|
|
|
return ($FormFunc_isform = 1);
|
|
}
|
|
|
|
# form_type: Return the form name (new, cur, del, listpref... etc)
|
|
sub form_type() {
|
|
local ($_, %_);
|
|
|
|
# Return the cache
|
|
return $FormFunc_formtype if defined $FormFunc_formtype;
|
|
|
|
# Obtain the current form
|
|
$_ = curform;
|
|
# Form type specified in arguments
|
|
return ($FormFunc_formtype = $_->param("form"))
|
|
if defined $_->param("form");
|
|
# No form source is found
|
|
return ($FormFunc_formtype = -1);
|
|
}
|
|
|
|
return 1;
|