// Copyright: Copyright (C) 2004-2013 Pristine Communications
// Set the include path
if (!defined("INCPATH_SET")) {
require_once dirname(__FILE__) . "/incpath.inc.php";
}
// Referenced subroutines
require_once "monica/a2html.inc.php";
require_once "monica/addget.inc.php";
require_once "monica/callform.inc.php";
require_once "monica/chkpriv.inc.php";
require_once "monica/commtext.inc.php";
require_once "monica/country.inc.php";
require_once "monica/echoform.inc.php";
require_once "monica/encrypt.inc.php";
require_once "monica/formfunc.inc.php";
require_once "monica/geoip.inc.php";
require_once "monica/getlang.inc.php";
require_once "monica/gettext.inc.php";
require_once "monica/htmlchar.inc.php";
require_once "monica/https.inc.php";
require_once "monica/links.inc.php";
require_once "monica/lninfo.inc.php";
require_once "monica/login.inc.php";
require_once "monica/markabbr.inc.php";
require_once "monica/pagefunc.inc.php";
require_once "monica/pic.inc.php";
require_once "monica/requri.inc.php";
require_once "monica/sql.inc.php";
require_once "monica/upload.inc.php";
require_once "monica/username.inc.php";
require_once "monica/usrconst.inc.php";
require_once "monica/zh2py.inc.php";
// Settings
define("FORM_RADIO_ONELINE", true);
// BaseForm: Display a form
class BaseForm
{
// Public-accessible attributes
public $title = null;
protected $_status = null;
protected $_type = null;
protected $_type_to_pass = null;
protected $_valid_types = null;
protected $_step = null;
protected $_req = null;
protected $_table = null;
protected $_form = null;
protected $_cur = null;
protected $_sn = null;
protected $_https = null;
protected $_isupload = false;
protected $_prefmsg = array();
protected $_nodelete = false;
protected $_deltext = "Delete it";
protected $_delprompt = "Are you sure you want to delete it? It cannot be recovered.";
protected $_mark = null;
protected $_markcols = null;
protected $_markmsg = null;
protected $_show_form = true;
protected $_show_table = true;
protected $_hidcols = null;
protected $_header_buttons = null;
protected $_footer_buttons = null;
protected $_summary = true;
protected $_class = "defform";
protected $_onsubmit = null;
protected $_colspan = 1;
protected $_defsize = 40;
protected $_procurl = REQUEST_FILE;
protected $_cols = array();
protected $_auto_referer2 = true;
protected $_is_called_form = false;
protected $_caller = null;
protected $_cformid = null;
protected $_preview = false;
protected $_prevmsg = null;
// Attributes to be always automatically generated
protected $_mlcols = array();
protected $_maxlens = array();
protected $_is_first_form = false;
protected $_referer2 = null;
protected $_hostport = null;
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
$this->_status = $status;
if (is_null($args)) {
$args = array();
}
// The form type
if (array_key_exists("type", $args)) {
$this->_type = $args["type"];
} else {
$this->_type = form_type();
}
// The form type to pass to the handler
if (array_key_exists("type_to_pass", $args)) {
$this->_type_to_pass = $args["type_to_pass"];
} else {
$this->_type_to_pass = $this->_type;
}
// The allowed form types
if (array_key_exists("valid_types", $args)) {
$this->_valid_types = $args["valid_types"];
} else {
$this->_valid_types = array("new", "cur", "del");
}
// Check if the form type is valid
if (!in_array($this->_type, $this->_valid_types)) {
trigger_error("unknown form type: \"" . $this->_type . "\"", E_USER_ERROR);
}
// The form step
if (array_key_exists("step", $args)) {
$this->_step = $args["step"];
}
// The request ID.
if (array_key_exists("req", $args)) {
$this->_req = $args["req"];
}
// The manuplating table
if (array_key_exists("table", $args)) {
$this->_table = $args["table"];
} elseif (defined("THIS_TABLE")) {
$this->_table = THIS_TABLE;
}
// The submitted form
if (array_key_exists("form", $args)) {
$this->_form =& $args["form"];
} else {
$this->_form =& retrieve_form();
}
// The current record
if (array_key_exists("current", $args)) {
$this->_cur =& $args["current"];
} elseif (array_key_exists("CURRENT", $GLOBALS)) {
$this->_cur =& $GLOBALS["CURRENT"];
}
if (!is_null($this->_cur) && array_key_exists("sn", $this->_cur)) {
$this->_sn = $this->_cur["sn"];
}
// If we should process with HTTPS/SSL
$this->_https = $this->https($args);
if (is_null($this->_https)) {
$this->_https = false;
}
// If the form contains file uploads (multipart/form-data)
if (array_key_exists("isupload", $args) && $this->_type != "del") {
$this->_isupload = $args["isupload"];
}
// The deletion text
if (array_key_exists("deltext", $args)) {
$this->_deltext = $args["deltext"];
} else {
$this->_deltext = C_("Delete it");
}
// The deletion confirmation prompt
if (array_key_exists("delprompt", $args)) {
$this->_delprompt = $args["delprompt"];
} else {
$this->_delprompt = C_("Are you sure you want to delete it? It cannot be recovered.");
}
// If this record can be deleted
if (array_key_exists("nodelete", $args)) {
$this->_nodelete = $args["nodelete"];
}
// The prefix message to display before the form
if (array_key_exists("prefmsg", $args)) {
$this->_prefmsg = array_merge($this->_prefmsg, $args["prefmsg"]);
}
// The mark
if (array_key_exists("mark", $args)) {
$this->_mark = $args["mark"];
} else {
$this->_mark = C_("*");
}
// The columns to mark
if (array_key_exists("markcols", $args)) {
$this->_markcols = $args["markcols"];
}
// The prompt message for the marked columns
if (array_key_exists("markmsg", $args)) {
$this->_markmsg = $args["markmsg"];
}
// The hidden columns
if (array_key_exists("hidcols", $args)) {
$this->_hidcols = $args["hidcols"];
}
// The buttons to show before and after the form
if (array_key_exists("header_buttons", $args)) {
$this->_header_buttons = $args["header_buttons"];
}
if (array_key_exists("footer_buttons", $args)) {
$this->_footer_buttons = $args["footer_buttons"];
}
// If we should show the form
if (array_key_exists("show_form", $args)) {
$this->_show_form = $args["show_form"];
}
// If we should show the table
if (array_key_exists("show_table", $args)) {
$this->_show_table = $args["show_table"];
}
// The table summary
if (array_key_exists("summary", $args)) {
$this->_summary = $args["summary"];
} else {
switch ($this->_type) {
// A form to create a new item
case "new":
$this->_summary = C_("This table provides you a form to add a new data record.");
break;
// A form to edit a current item
case "cur":
$this->_summary = C_("This table provides you a form to update a current data record.");
break;
// A form to delete a current item
case "del":
$this->_summary = C_("This table provides you a form to delete a data record.");
break;
}
}
// The form class
if (array_key_exists("class", $args)) {
$this->_class = $args["class"];
}
// The onsubmit javascript form checker
if (array_key_exists("onsubmit", $args)) {
$this->_onsubmit = $args["onsubmit"];
}
// The colspan for each normal
cell
if (array_key_exists("colspan", $args)) {
$this->_colspan = $args["colspan"];
}
// The default input box size
if (array_key_exists("defsize", $args)) {
$this->_defsize = $args["defsize"];
}
// The process URL.
if (array_key_exists("procurl", $args)) {
$this->_procurl = $args["procurl"];
} elseif ($this->_https) {
if (defined("VIRTUAL_HOST") && !VIRTUAL_HOST) {
$this->_procurl = "https://" . https_host() . REQUEST_PATH;
} else {
$this->_procurl = "https://" . https_host() . "/" . PACKAGE . REQUEST_PATH;
}
} else {
$this->_procurl = REQUEST_FILE;
}
// The columns to display
if (array_key_exists("cols", $args)) {
$this->_cols = $args["cols"];
} elseif (!is_null($this->_table)) {
$this->_cols = sql_cols($this->_table);
}
// Should we automatically keep our HTTP_REFERER
if (array_key_exists("auto_referer2", $args)) {
$this->_auto_referer2 = $args["auto_referer2"];
}
// The title
if (array_key_exists("title", $args)) {
$this->title = $args["title"];
} else {
switch ($this->_type) {
// A form to create a new item
case "new":
$this->title = C_("Add a New Data Record");
break;
// A form to edit a current item
case "cur":
$this->title = C_("Update a Current Data Record");
break;
// A form to delete a current item
case "del":
$this->title = C_("Delete a Data Record");
break;
}
}
// The preview link
if (array_key_exists("preview", $args)) {
$this->_preview = $args["preview"];
}
if ($this->_preview) {
if (array_key_exists("prevmsg", $args)) {
$this->_prevmsg = $args["prevmsg"];
} else {
$this->_prevmsg = C_("Preview it.");
}
}
// The caller form and form ID.
$CURFORM =& curform();
if ( array_key_exists("caller", $args)
&& array_key_exists("cformid", $args)) {
$this->_is_called_form = true;
$this->_caller = $args["caller"];
$this->_cformid = $args["cformid"];
} elseif ( array_key_exists("caller", $CURFORM)
&& array_key_exists("cformid", $CURFORM)) {
$this->_is_called_form = true;
$this->_caller = $CURFORM["caller"];
$this->_cformid = $CURFORM["cformid"];
}
// Initialize the first form
if (count($this->_form) == 0) {
$this->_is_first_form = true;
if (!is_null($this->_cur)) {
// ...with the current item
$this->_form = $this->_cur;
}
}
if (!is_null($this->_table)) {
$this->_mlcols = sql_cols_ml($this->_table);
$this->_maxlens = sql_col_lens($this->_table);
}
// Check the columns to display
foreach ($this->_cols as $col) {
if (!method_exists($this, "_html_col_$col")) {
trigger_error("Called an undefined form column \"$col\"", E_USER_ERROR);
}
}
// Set the referer2 (the place to return when we finished the form)
if ($this->_is_called_form) {
// Referer specified
$CALLINGFORM =& retrieve_form($this->_cformid);
if (array_key_exists("referer2", $CALLINGFORM)) {
$this->_referer2 = $CALLINGFORM["referer2"];
}
// First form
} elseif ($this->_is_first_form) {
// Referer specified
if (array_key_exists("referer", $CURFORM)) {
$this->_referer2 = $CURFORM["referer"];
// Keep the source referer
} elseif ( $this->_auto_referer2
&& array_key_exists("HTTP_REFERER", $_SERVER)
&& substr($_SERVER["HTTP_REFERER"], 0, strlen(REQUEST_HOSTPORT)+1) == REQUEST_HOSTPORT . "/") {
$this->_referer2 = $_SERVER["HTTP_REFERER"];
}
// A subsequent form
} else {
// Maintain the previous referer2
if (array_key_exists("referer2", $this->_form)) {
$this->_referer2 = $this->_form["referer2"];
}
}
// Remove statid from referer2
if (!is_null($this->_referer2)) {
$this->_referer2 = rem_get_arg($this->_referer2, "statid");
}
// The prefix of where to return after form is processed
// No need to have it if we have a proper referer2 to return to
if (is_null($this->_referer2) && $this->_https) {
$this->_hostport = REQUEST_HOSTPORT;
}
}
// html: Display the HTML form table
function html()
{
// Display the form header
$this->_html_form_header();
// Display the table header
$this->_html_table_header();
// Display each column
foreach ($this->_cols as $col) {
call_user_func(array(&$this, "_html_col_$col"));
}
// Display the table footer
$this->_html_table_footer();
// Display the form footer
$this->_html_form_footer();
return;
}
// https: If we should process with HTTPS/SSL
function https($args = null)
{
// Checked before
if (!is_null($this->_https)) {
return $this->_https;
}
// Already in HTTPS
if (is_https()) {
$this->_https = false;
return $this->_https;
}
// HTTPS specified
if ( !is_null($args)
&& array_key_exists("https", $args)
&& !is_null($args["https"])) {
$this->_https = $args["https"];
settype($this->_https, "boolean");
return $this->_https;
}
// Specified in the current form
$FORM =& curform();
if (array_key_exists("https", $FORM) && $FORM["https"]) {
$this->_https = true;
return $this->_https;
}
// Specified in the GET or POST arguments
$FORM =& get_or_post();
if (array_key_exists("https", $FORM) && $FORM["https"]) {
$this->_https = true;
return $this->_https;
}
// Unable to decide it
return null;
}
/////////////////////////
// Methods below are private. Do not call them directly.
/////////////////////////
/////////////////////////
// Basic form elements
/////////////////////////
// _html_form_header: Display the form header
function _html_form_header()
{
// Don't show the form
if (!$this->_show_form) {
?>
_class)) {
?> class="_class); ?>">
_html_prefix_message();
// Display the preview link
$this->_html_preview_link();
// Display the prompt for the marked columns
$this->_html_mark_prompt();
return;
}
// The meta form information
$meta = new _Form_MetaCols();
$meta->add("hidden", "lang", getlang());
$meta->add("hidden", "charset", getlang(LN_CHARSET));
if (!is_null($this->_type_to_pass)) {
$meta->add("hidden", "form", $this->_type_to_pass);
}
if (!is_null($this->_step)) {
$meta->add("hidden", "step", $this->_step);
}
if (!is_null($this->_sn)) {
$meta->add("hidden", "sn", $this->_sn);
}
if (!is_null($this->_req)) {
$meta->add("hidden", "req", $this->_req);
}
if ($this->_is_called_form) {
$meta->add("hidden", "caller", $this->_caller);
$meta->add("hidden", "cformid", $this->_cformid);
}
if ($this->_https) {
$meta->add("hidden", "https", 1);
$meta->add("hidden", "referer", REQUEST_HOSTPATH);
$meta->add("hidden", session_name(), session_id());
}
if (!is_null($this->_referer2)) {
$meta->add("hidden", "referer2", $this->_referer2);
} elseif (!is_null($this->_hostport)) {
$meta->add("hidden", "hostport", $this->_hostport);
}
if (!is_null($this->_hidcols)) {
for ($i = 0; $i < count($this->_hidcols); $i++) {
$meta->add("hidden", $this->_hidcols[$i]["name"], $this->_hidcols[$i]["value"]);
}
}
// The submit buttons
if (!is_null($this->_header_buttons)) {
foreach ($this->_header_buttons as $button) {
$meta->add("submit", $button["name"], $button["value"]);
}
// Apply the default submit buttons
} else {
switch ($this->_type) {
// A form to create a new item
case "new":
$meta->add("submit", null, C_("Preview"));
$meta->add("submit", "confirm", C_("Confirm and submit"));
break;
// A form to edit a current item
case "cur":
$meta->add("submit", null, C_("Preview"));
$meta->add("submit", "confirm", C_("Confirm and submit"));
if (!$this->_nodelete) {
$meta->add("submit", "del", $this->_deltext);
}
break;
// A form to delete a current item
case "del":
break;
}
}
// Output the form header
?>
_type) {
// A form to create a new item
case "new":
$newalt = C_("Picture preview");
$rows_new = 1;
if ( !is_null($this->_form($col . "pic"))
&& pic_exists($this->_form($col . "pic"))) {
$rows_new = 2;
}
?>
_defsize;
}
$id = ($col == "body"? "fbody": $col);
$hide = C_("Hide");
$show = C_("Show");
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_type) {
// A form to create a new item
case "new":
?>
_colspan();
?>>_val_check($col); ?> />
_colspan(); ?>>_cur[$col]? $true: $false); ?>
_colspan();
?>>_val_check($col); ?> />
_mark($col); echo h_abbr($label); ?>
_colspan(); ?>>_cur[$col]? $true: $false); ?>
_form)
&& $this->_form[$col] == "") {
unset($this->_form[$col]);
}
$choose = C_("Choose");
$delete = C_("Delete");
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_form)
&& $this->_form[$col] == "") {
unset($this->_form[$col]);
}
$choose = C_("Choose");
$delete = C_("Delete");
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_form)
&& $this->_form[$col] == "") {
unset($this->_form[$col]);
}
$choose = C_("Choose");
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_type) {
// A form to create a new item
case "new":
?>
_colspan();
?>>
_colspan(); ?>>_cur[$col])); ?>
_colspan();
?>>
_mark($col); echo h_abbr($label); ?>
_colspan(); ?>>_cur[$col])); ?>
_form); $i++) { }
for ($i--; $i >= 0 && $this->_form["$col$i"] == ""; $i--) { };
$count = $i + 3;
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_html_coltmpl_textarea("addr", C_("Address:"),
C_("Fill in your address here."), null, 3);
}
// _html_col_att: The attachment
function _html_col_att()
{
$this->_html_coltmpl_file("att", C_("Attachment:"));
if ( in_array("attdsc", sql_cols_nl($this->_table))
&& !is_null($this->_form("att"))
&& savefile_exists($this->_form("att"))) {
$this->_html_coltmpl_text("attdsc", C_("Attachment description:"));
}
}
// _html_col_bi_address: The address set: country, address
function _html_col_bi_address()
{
if (getlang(LN_COUNTRY_FIRST)) {
$this->_html_col_country();
$this->_html_col_addr();
} else {
$this->_html_col_addr();
$this->_html_col_country();
}
}
// _html_col_body: The content body
function _html_col_body()
{
$this->_html_coltmpl_textarea("body", C_("Content:"),
C_("Fill in the content here."));
}
// _html_col_city: The city
function _html_col_city()
{
$this->_html_coltmpl_text("city", C_("City:"));
}
// _html_col_content: The content body
function _html_col_content()
{
$this->_html_coltmpl_textarea("content", C_("Content:"),
C_("Fill in the content here."));
}
// _html_col_country: The country
function _html_col_country()
{
// Set the default country to the client country
if ($this->_type == "new" && !array_key_exists("country", $this->_form)) {
$this->_form["country"] = geoiplookup();
}
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_colspan(); ?>>
_colspan(); ?>>_cur["country"])); ?>
_colspan(); ?>>
_mark("country"); echo h_abbr(C_("Country:")); ?>
_colspan(); ?>>_cur["country"])); ?>
_html_coltmpl_ro_datetime("created", C_("Created:"));
}
// _html_col_createdby: The creator
function _html_col_createdby()
{
$this->_html_coltmpl_ro_user("createdby", C_("Created by:"));
}
// _html_col_ct: The country
function _html_col_ct()
{
$this->_html_coltmpl_ro_ct("ct", C_("Country:"));
}
// _html_col_date: The date
function _html_col_date()
{
$this->_html_coltmpl_date("date", C_("Date:"));
}
// _html_col_disabled: Disabled?
function _html_col_disabled()
{
$this->_html_coltmpl_bool("disabled", C_("Disabled?"),
C_("Disabled"), C_("Enabled"), C_("Disable it."));
}
// _html_col_dsc: The description
function _html_col_dsc()
{
$this->_html_coltmpl_textarea("dsc", C_("Description:"),
C_("Fill in the description here."), null, 5);
}
// _html_col_email: The e-mail
function _html_col_email()
{
$this->_html_coltmpl_text("email", C_("E-mail:"));
}
// _html_col_fax: The facsimile number
function _html_col_fax()
{
$this->_html_coltmpl_text("fax", C_("Fax:"));
}
// _html_col_grp: The group
function _html_col_grp()
{
$this->_html_coltmpl_call("grp", C_("Group:"), "groupdsc");
}
// _html_col_hid: Hide?
function _html_col_hid()
{
$this->_html_coltmpl_bool("hid", C_("Hide?"),
C_("Hide it"), C_("Show it"), C_("Hide it currently."));
}
// _html_col_host: The host
function _html_col_host()
{
$this->_html_coltmpl_ro("host", C_("Host:"));
}
// _html_col_html: HTML?
function _html_col_html()
{
$this->_html_coltmpl_bool("html", C_("HTML?"),
C_("HTML"), C_("Plain text"), C_("The submitted content is HTML."));
}
// _html_col_id: The ID.
function _html_col_id()
{
$this->_html_coltmpl_text("id", C_("ID.:"));
}
// _html_col_intro: The introduction
function _html_col_intro()
{
$this->_html_coltmpl_textarea("intro", C_("Introduction:"),
C_("Fill in the introduction here."));
}
// _html_col_ip: The IP
function _html_col_ip()
{
$this->_html_coltmpl_ro("ip", C_("IP:"));
}
// _html_col_kw: The keywords
function _html_col_kw()
{
$this->_html_coltmpl_text("kw", C_("Keywords:"));
}
// _html_col_lang: The language
function _html_col_lang()
{
$this->_html_coltmpl_ro_lang("lang", C_("Language:"));
}
// _html_col_massdel: The list of items for mass deletion
function _html_col_massdel()
{
?>
_cur); $i++) {
?>
_html_coltmpl_text("name", C_("Name:"));
}
// _html_col_ord: The order
function _html_col_ord()
{
// Set the default order to the half of the maximum
if ($this->_is_first_form && $this->_type == "new" && is_null($this->_form("ord"))) {
$this->_form["ord"] = pow(10, $this->_maxlens["ord"]) / 2;
}
$this->_html_coltmpl_text("ord", C_("Order:"), null, $this->_maxlens["ord"]);
}
// _html_col_org: The organization
function _html_col_org()
{
$this->_html_coltmpl_text("org", C_("Organization:"));
}
// _html_col_parent: The parent category
function _html_col_parent()
{
$this->_html_coltmpl_call_null("parent", C_("Parent category:"),
"topmost", C_("At the very top"), $this->_table . "_title");
}
// _html_col_passwd: The password
function _html_col_passwd()
{
$size = $this->_defsize;
$dummy = str_repeat("*", 16);
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_html_coltmpl_text("script", C_("Script:"));
}
// _html_col_sn: The serial number
function _html_col_sn()
{
$this->_html_coltmpl_ro("sn", C_("S/N:"));
}
// _html_col_street: The street
function _html_col_street()
{
$this->_html_coltmpl_text("street", C_("Street:"));
}
// _html_col_subject: The subject
function _html_col_subject()
{
$this->_html_coltmpl_text("subject", C_("Subject:"));
}
// _html_col_tel: The telephone number
function _html_col_tel()
{
$this->_html_coltmpl_text("tel", C_("Telephone:"));
}
// _html_col_tel: The cellular telephone number
function _html_col_telc()
{
$this->_html_coltmpl_text("telc", C_("Tel. (cell.):"));
}
// _html_col_tel: The telephone number at home
function _html_col_telh()
{
$this->_html_coltmpl_text("telh", C_("Tel. (home):"));
}
// _html_col_tel: The telephone number at the office
function _html_col_telo()
{
$this->_html_coltmpl_text("telo", C_("Tel. (office):"));
}
// _html_col_title: The title
function _html_col_title()
{
$this->_html_coltmpl_text("title", C_("Title:"));
}
// _html_col_tri_address: The address set: country, city, street
function _html_col_tri_address()
{
if (getlang(LN_COUNTRY_FIRST)) {
$this->_html_col_country();
$this->_html_col_city();
$this->_html_col_street();
} else {
$this->_html_col_street();
$this->_html_col_city();
$this->_html_col_country();
}
}
// _html_col_value: The preference value
function _html_col_value()
{
$this->_html_coltmpl_text("value", C_("Value:"));
}
// _html_col_visits: The visit count
function _html_col_visits()
{
$this->_html_coltmpl_ro("visits", C_("Visits:"));
}
// _html_col_visited: The last-visited time
function _html_col_visited()
{
$this->_html_coltmpl_ro_datetime("visited", C_("Visited:"));
}
// _html_col_updated: The The last-update time
function _html_col_updated()
{
$this->_html_coltmpl_ro_datetime("updated", C_("Updated:"));
}
// _html_col_updatedby: The last maintainer
function _html_col_updatedby()
{
$this->_html_coltmpl_ro_user("updatedby", C_("Updated by:"));
}
// _html_col_url: The URL.
function _html_col_url()
{
$this->_html_coltmpl_url("url", C_("URL.:"));
}
// _html_col_zip: The zip code
function _html_col_zip()
{
$this->_html_coltmpl_text("zip", C_("Zip code:"), null, 5);
}
/////////////////////////
// Private utility methods. Do not call them directly.
/////////////////////////
// _cval_text: Output a current text value
function _cval_text($col)
{
echo is_null($this->_cur[$col])? h_abbr(t_none()):
h($this->_cur[$col]);
}
// _cval_textarea: Output a current textarea value
function _cval_textarea($col)
{
echo is_null($this->_cur[$col])? h_abbr(t_none()):
a2html($this->_cur[$col]);
}
// _val_text: Output a value
function _val_text($col, $maxcol = null)
{
if (!is_null($maxcol)) {
echo " maxlength=\"" . h($this->_maxlens[$maxcol]) . "\"";
}
if (array_key_exists($col, $this->_form)) {
echo " value=\"" . h($this->_form[$col]) . "\"";
} else {
echo " value=\"\"";
}
}
// _val_scalar: Output a scalar value
function _val_scalar($val, $maxcol = null)
{
if (!is_null($maxcol)) {
echo " maxlength=\"" . h($this->_maxlens[$maxcol]) . "\"";
}
if (!is_null($val)) {
echo " value=\"" . h($val) . "\"";
} else {
echo " value=\"\"";
}
}
// _val_date: Output a date value
function _val_date($col, $maxcol = null)
{
if (!is_null($maxcol)) {
echo " maxlength=\"" . h($this->_maxlens[$maxcol]) . "\"";
}
if (array_key_exists($col, $this->_form)) {
$val = $this->_form[$col];
if (is_numeric($val)) {
$val = date("Y-m-d", $val);
}
echo " value=\"" . h($val) . "\"";
} else {
echo " value=\"\"";
}
}
// _val_textarea: Output a value as a textarea content
function _val_textarea($col, $default)
{
echo array_key_exists($col, $this->_form) && $this->_form[$col] != ""?
h($this->_form[$col]): h($default);
}
// _val_check: Output a value as a checkbox check value
function _val_check($col)
{
if (array_key_exists($col, $this->_form) && $this->_form[$col]) {
echo " checked=\"checked\"";
}
}
// _val_radio: Output a value as a radio check value
function _val_radio($col, $valhere, $is_default = false)
{
// Value set, checked when same value
if (array_key_exists($col, $this->_form)) {
echo " value=\"" . h($valhere) . "\"";
if ($this->_form[$col] == $valhere) {
echo " checked=\"checked\"";
}
// Value not set, checked when default
} else {
echo " value=\"" . h($valhere) . "\"";
if ($is_default) {
echo " checked=\"checked\"";
}
}
}
// _form: Return a specific form value, or null if not exists
function _form($col)
{
if (array_key_exists($col, $this->_form)) {
return $this->_form[$col];
}
return null;
}
// _colspan: Output the colspan phrase
function _colspan($addcols = 0)
{
$colspan = $this->_colspan + $addcols;
// Only output for many columns
if ($colspan > 1) {
?> colspan=""_colspan + $addcols;
$colspan += ($this->_type == "cur")? 2: 1;
// Only output for many columns
if ($colspan > 1) {
?> colspan=""_markcols) || is_null($this->_mark)) {
return;
}
if (in_array($col, $this->_markcols)) {
echo $this->_mark;
}
return;
}
// _delcolcount: Obtain the number of items of a column for the deletion form
function _delcolcount($col)
{
// None-deletion form -- return 0 since the number of items is unknown
if ($this->_type != "del") {
return 0;
}
// Deletion form -- return the number of items
return $this->_cur[$col . "count"];
}
}
// _Form_MetaCols: Manage and output the meta form information
class _Form_MetaCols
{
protected $_cols = array();
// add: Add a column
function add($type, $name, $value)
{
$this->_cols[] = array(
"type" => $type,
"name" => $name,
"value" => $value,
);
return;
}
// out: Output the columns
function out()
{
// Bounce for nothing
if (count($this->_cols) == 0) {
return;
}
$cols = $this->_cols;
// Output the first column
$col = array_shift($cols);
?>_out_attrs($col); ?> />_out_attrs($col); ?> />\"";
} else {
$attrs[] = "value=\"" . h($col["value"]) . "\"";
}
return join(" ", $attrs);
}
}
// UserForm: Display a user form
class UserForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "users";
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this user account");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new user account.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to update a current user account.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a user account.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("id", "passwd", "name",
"disabled", "supgroup");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "id", "passwd", "name",
"disabled", "supgroup",
"admin", "lang", "visits", "visited", "ip", "host", "ct",
"fails",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New User Account");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Update a Current User Account");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a User Account");
break;
}
}
if (!array_key_exists("https", $args)) {
$args["https"] = ($args["type"] != "del");
}
parent::__construct($status, $args);
$this->_maxlens["passwd"] = 100;
if ( $args["type"] == "cur" && !is_su()
&& ($this->_cur["su"] || $this->_sn == get_login_sn())) {
$this->_nodelete = true;
if ($this->_cur["su"]) {
$this->_prefmsg[] = C_("This is a super-user. You can only change parts of her infomation.");
}
}
if ($this->_type == "cur") {
if (array_key_exists("datacount", $this->_cur) && $this->_cur["datacount"] > 0) {
$this->_nodelete = true;
$this->_prefmsg[] = dngettext(COMMONDOMAIN,
"This user has a datum. It cannot be deleted. To delete the user, its datum must first be deleted.",
"This user has data. It cannot be deleted. To delete the user, all of its data must first be deleted.",
$this->_cur["datacount"]);
}
}
// Set all the available belonging groups list
$this->_set_supgroup_list();
}
// _set_supgroup_list: Set all the available belonging groups list
function _set_supgroup_list()
{
// Get the list of checked groups
$checked = array();
for ($i = 0; array_key_exists("supgroup$i" . "sn", $this->_form); $i++) {
if (array_key_exists("supgroup$i", $this->_form)) {
$checked[] = $this->_form["supgroup$i" . "sn"];
}
}
// Remove the old groups list
foreach (array_keys($this->_form) as $col) {
if (substr($col, 0, 8) == "supgroup") {
unset($this->_form[$col]);
}
}
// Get the list of all groups
if (count($GLOBALS["ALL_LINGUAS"]) > 1) {
$lndb = getlang(LN_DATABASE);
if (getlang() == DEFAULT_LANG) {
$title = sql_strcat("id", "' ('", "dsc_$lndb", "')'");
} else {
$lndbdef = ln(DEFAULT_LANG, LN_DATABASE);
$title = sql_strcat("id", "' ('",
"COALESCE(dsc_$lndb, dsc_$lndbdef)", "')'");
}
} else {
$title = sql_strcat("id", "' ('", "dsc", "')'");
}
$select = "SELECT sn AS sn, $title AS title FROM groups"
. " WHERE id!='" . sql_esctext(SU_GROUP) . "'"
. " AND id!='" . sql_esctext(ADMIN_GROUP) . "'"
. " AND id!='" . sql_esctext(ALLUSERS_GROUP) . "'"
. " ORDER BY id;\n";
$result = sql_query($select);
$count = sql_num_rows($result);
for ($i = 0; $i < $count; $i++) {
$row = sql_fetch_assoc($result);
// Set it
$this->_form["supgroup$i" . "sn"] = $row["sn"];
$this->_form["supgroup$i" . "title"] = $row["title"];
if (in_array($row["sn"], $checked)) {
$this->_form["supgroup$i"] = true;
}
}
return;
}
// _html_col_admin: Is the user an administrator?
function _html_col_admin()
{
$this->_html_coltmpl_ro_bool("admin", C_("Administrator?"),
C_("Administrator"), C_("Non-administrator"));
}
// _html_col_disabled: Disabled?
function _html_col_disabled()
{
// Read-only for a non-super-user editing herself or a super-user
if ( $this->_type == "cur" && !is_su()
&& ($this->_cur["su"] || $this->_sn == get_login_sn())) {
$this->_html_coltmpl_ro_bool("disabled", C_("Disabled?"),
C_("Disabled"), C_("Enabled"));
} else {
$this->_html_coltmpl_bool("disabled", C_("Disabled?"),
C_("Disabled"), C_("Enabled"), C_("Disable this user account."));
}
}
// _html_col_id: The user ID.
function _html_col_id()
{
// Read-only for a non-super-user editing a super-user
if ($this->_type == "cur" && !is_su() && $this->_cur["su"]) {
$this->_html_coltmpl_ro("id", C_("User ID.:"));
} else {
$this->_html_coltmpl_text("id", C_("User ID.:"));
}
}
// _html_col_lang: The preferred language
function _html_col_lang()
{
$this->_html_coltmpl_ro_lang("lang", C_("Pref. language:"));
}
// _html_col_name: The user name
function _html_col_name()
{
$this->_html_coltmpl_text("name", C_("Full name:"));
}
// _html_col_passwd: The password
function _html_col_passwd()
{
// Read-only for a non-super-user editing a super-user
if ($this->_type == "cur" && !is_su() && $this->_cur["su"]) {
$dummy = str_repeat("*", $this->_maxlens["passwd"]);
?>
_colspan(); ?>>
_type) {
// A form to create a new item
case "new":
?>
\n";
}
$items[] = ob_get_contents();
ob_end_clean();
}
// Attach the all-users group in any case
if (!is_null(groupsn(ALLUSERS_GROUP))) {
ob_start();
?>
_cur["su"]) {
?> checked="checked" disabled="disabled" />
\n";
}
$items[] = ob_get_contents();
ob_end_clean();
}
// Attach the all-users group in any case
if (!is_null(groupsn(ALLUSERS_GROUP))) {
ob_start();
?>
\n";
}
if (!is_null(groupsn(ALLUSERS_GROUP))) {
$items[] = "
" . group_opt_label(groupsn(ALLUSERS_GROUP)) . "
\n";
}
if (count($items) > 0) {
echo "
\n" . implode("", $items) . "
\n ";
} else {
echo h_abbr(t_none());
} ?>
_type) {
// A form to create a new item
case "new":
// Nothing for a new form
break;
// A form to edit a current item
case "cur":
$locked = false;
if ( defined("MAX_FAIL_LOGINS")
&& MAX_FAIL_LOGINS !== false
&& $this->_form("fails") >= MAX_FAIL_LOGINS) {
$locked = true;
}
if (!$locked) {
?>
_colspan(); ?>>_cval_text("fails");
if ($locked) {
echo h(C_("(Locked)"));
} ?>
_type == "cur" && !is_su() && $this->_cur["sn"] == su_group_sn()) {
$this->_nodelete = true;
$this->_prefmsg[] = C_("This is a super-user group. You can only change parts of its infomation.");
}
}
// _html_col_id: The group ID.
function _html_col_id()
{
// Read-only for a non-super-user editing a super-user group
if ($this->_type == "cur" && !is_su() && $this->_sn == su_group_sn()) {
$this->_html_coltmpl_ro("id", C_("Group ID.:"));
} else {
$this->_html_coltmpl_text("id", C_("Group ID.:"));
}
}
// _html_col_dsc: The description
function _html_col_dsc()
{
$this->_html_coltmpl_text("dsc", C_("Description:"));
}
// _html_col_subuser: The child users
function _html_col_subuser()
{
$submit = C_("Add a user");
switch ($this->_type) {
// A form to create a new item
case "new":
?>
_html_coltmpl_call("member", C_("Member:"), "username");
}
}
// GroupMembershipForm: Display a group membership form
class GroupMembershipForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "groupmem";
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this membership record");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new membership record.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to change a current membership record.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a membership record.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("grp", "member");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "grp", "member",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New Group Membership Record");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Change a Current Group Membership Record");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a Group Membership Record");
break;
}
}
parent::__construct($status, $args);
}
// _html_col_member: The member
function _html_col_member()
{
$this->_html_coltmpl_call("member", C_("Member:"), "groupdsc");
}
}
// UserPreferenceForm: Display a user preference form
class UserPreferenceForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "userpref";
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this user preference");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new user preference.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to modify a current user preference.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a user preference.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("usr", "domain", "name", "value");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "usr", "domain", "name", "value",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New User Preference");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Modify a Current User Preference");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a User Preference");
break;
}
}
parent::__construct($status, $args);
}
// _html_col_usr: The user
function _html_col_usr()
{
$this->_html_coltmpl_call_null("usr", C_("User:"),
"everyone", C_("Everyone"), "username");
}
// _html_col_domain: The domain
function _html_col_domain()
{
$this->_html_coltmpl_text_null("domain", C_("Domain:"),
"everywhere", C_("Everywhere"));
}
}
// ScriptPrivilegeForm: Display a script privilege form
class ScriptPrivilegeForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "scptpriv";
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this script privilege record");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new script privilege record.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to change a current script privilege record.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a script privilege record.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("script", "grp");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "script", "grp",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New Script Privilege Record");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Change a Current Script Privilege Record");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a Script Privilege Record");
break;
}
}
parent::__construct($status, $args);
}
// _html_col_grp: The group
function _html_col_grp()
{
$this->_html_coltmpl_call("grp", C_("Privilege:"), "groupdsc");
}
}
// UserRequestForm: Display a user request form
class UserRequestForm extends BaseForm
{
protected $_types = array();
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "userreq";
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this user request");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new user request.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to update a current user request.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a user request.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("type", "usr", "args", "expire");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "type", "usr", "args", "expire",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New User Request");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Update a Current User Request");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a User Request");
break;
}
}
parent::__construct($status, $args);
$this->_types = array(
array(
"val" => "join",
"title" => C_("Join"),
),
array(
"val" => "chgeml",
"title" => C_("Change e-mail"),
),
array(
"val" => "rstpwd",
"title" => C_("Reset password"),
),
);
}
// _html_col_expire: The expiration time
function _html_col_expire()
{
$this->_html_coltmpl_datetime("expire", C_("Expiration:"));
}
// _html_col_type: The type
function _html_col_type()
{
$this->_html_coltmpl_radio("type", C_("Type:"), $this->_types);
}
// _html_col_usr: The user
function _html_col_usr()
{
$this->_html_coltmpl_call_null("usr", C_("User:"),
"anonymous", C_("Anonymous"), "username");
}
// _html_col_args: The arguments
function _html_col_args()
{
$this->_html_coltmpl_textarea("args", C_("Arguments:"),
C_("Please fill in the request arguments list here."), null, 3);
}
}
// BaseCategoryForm: Display a base category form
class BaseCategoryForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this category");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new category.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to edit a current category.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a category.");
break;
}
}
parent::__construct($status, $args);
$this->_maxlens["ord"] = 2;
if ($this->_type == "cur") {
if (array_key_exists("scatcount", $this->_cur) && $this->_cur["scatcount"] > 0) {
$this->_nodelete = true;
$this->_prefmsg[] = dngettext(COMMONDOMAIN,
"This category has a subcategory. It cannot be deleted. To delete the category, its subcategory must first be deleted.",
"This category has subcategories. It cannot be deleted. To delete the category, all of its subcategories must first be deleted.",
$this->_cur["scatcount"]);
}
}
}
// _html_col_id: The ID.
function _html_col_id()
{
$this->_html_coltmpl_text("id", C_("ID.:"), null, 8);
}
// _html_col_hid: Hide?
function _html_col_hid()
{
$this->_html_coltmpl_bool("hid", C_("Hide?"),
C_("Hide this category"), C_("Show this category"), C_("Hide this category currently."));
}
}
// BaseCategorizationForm: Display a base categorization record form
class BaseCategorizationForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this categorization record");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new categorization record.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to change a current categorization record.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a categorization record.");
break;
}
}
parent::__construct($status, $args);
}
}
// LinkCategoryForm: Display a link category form
class LinkCategoryForm extends BaseCategoryForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "linkcat";
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("parent", "id", "ord",
"title", "kw", "hid");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "parent", "id", "ord",
"title", "kw", "hid",
"scats", "links",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New Link Category");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Edit a Current Link Category");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a Link Category");
break;
}
}
parent::__construct($status, $args);
$this->_maxlens["ord"] = 2;
if ($this->_type == "cur") {
if (array_key_exists("linkcount", $this->_cur) && $this->_cur["linkcount"] > 0) {
$this->_nodelete = true;
$this->_prefmsg[] = dngettext(COMMONDOMAIN,
"This category has a link. It cannot be deleted. To delete the category, its link must first be deleted.",
"This category has links. It cannot be deleted. To delete the category, all of its links must first be deleted.",
$this->_cur["linkcount"]);
}
}
}
// _html_col_links: The links
function _html_col_links()
{
?>
_html_coltmpl_bool("hid", C_("Hide?"),
C_("Hide this link"), C_("Show this page"), C_("Hide this related link currently."));
}
// _html_col_cats: The categories
function _html_col_cats()
{
$this->_html_coltmpl_select_multi("cat",
dngettext(COMMONDOMAIN, "Category:", "Categories:", $this->_delcolcount("cat")),
"linkcat_options");
}
}
// LinkCategorizationForm: Display a link categorization record form
class LinkCategorizationForm extends BaseCategorizationForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "linkcatz";
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("cat", "link");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "cat", "link",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New Link Categorization Record");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Change a Current Link Categorization Record");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a Link Categorization Record");
break;
}
}
parent::__construct($status, $args);
}
// _html_col_cat: The category
function _html_col_cat()
{
$this->_html_coltmpl_select("cat", C_("Category:"),
"linkcat_options", "linkcat_title");
}
// _html_col_link: The link
function _html_col_link()
{
$this->_html_coltmpl_call("link", C_("Link:"), "link_title");
}
}
// PageForm: Display a page form
class PageForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "pages";
}
if (!array_key_exists("isupload", $args)) {
$args["isupload"] = true;
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this page");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to write a new page.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to edit a current page.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a page.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("path", "ord", "title",
"body", "kw", "pic", "html", "hid");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "path", "ord", "title",
"body", "kw", "pic", "html", "hid",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Write a New Page");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Edit a Current Page");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a Page");
break;
}
}
if (!array_key_exists("preview", $args)) {
$args["preview"] = true;
}
if ($args["preview"] && !array_key_exists("prevmsg", $args)) {
$args["prevmsg"] = C_("Preview this page.");
}
parent::__construct($status, $args);
}
// _html_col_hid: Hide?
function _html_col_hid()
{
$this->_html_coltmpl_bool("hid", C_("Hide?"),
C_("Hide this page"), C_("Show this page"), C_("Hide this page currently."));
}
}
// NewsForm: Display a news form
class NewsForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "news";
}
if (!array_key_exists("isupload", $args)) {
$args["isupload"] = true;
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this news article");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to write a new news article.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to edit a current news article.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a news article.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("date", "title",
"body", "kw", "pic", "html", "hid");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "date", "ord", "title",
"body", "kw", "pic", "html", "hid",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Write a New News Article");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Edit a Current News Article");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a News Article");
break;
}
}
if (!array_key_exists("preview", $args)) {
$args["preview"] = true;
}
if ($args["preview"] && !array_key_exists("prevmsg", $args)) {
$args["prevmsg"] = C_("Preview this news article.");
}
parent::__construct($status, $args);
}
// _html_col_ord: The order
function _html_col_ord()
{
$this->_html_coltmpl_ro("ord", C_("Order:"));
}
// _html_col_hid: Hide?
function _html_col_hid()
{
$this->_html_coltmpl_bool("hid", C_("Hide?"),
C_("Hide this news article"), C_("Show this news article"), C_("Hide this news article currently."));
}
}
// CountryForm: Display a country form
class CountryForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("table", $args)) {
$args["table"] = "country";
}
if (!array_key_exists("deltext", $args)) {
$args["deltext"] = C_("Delete this country record");
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new country record.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to edit a current country record.");
break;
// A form to delete a current item
case "del":
$args["summary"] = C_("This table provides you a form to delete a country record.");
break;
}
}
if (!array_key_exists("cols", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["cols"] = array("id", "name", "special");
break;
// A form to edit a current item
case "cur":
// A form to delete a current item
case "del":
$args["cols"] = array("sn", "id", "name", "special",
"created", "createdby", "updated", "updatedby");
break;
}
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Add a New Country Record");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Edit a Current Country Record");
break;
// A form to delete a current item
case "del":
$args["title"] = C_("Delete a Country Record");
break;
}
}
parent::__construct($status, $args);
}
// _html_col_id: The ID.
function _html_col_id()
{
$this->_html_coltmpl_text("id", C_("ID.:"), null, 2);
}
// _html_col_special: Special record?
function _html_col_special()
{
$this->_html_coltmpl_bool("special", C_("Special?"),
C_("A special record"), C_("A normal country"), C_("This is a special record."));
}
}
// PictureForm: Display a picture form
class PictureForm extends BaseForm
{
// __construct: Initialize the form
function __construct($status = null, $args = null)
{
if (is_null($args)) {
$args = array();
}
if (!array_key_exists("type", $args)) {
$args["type"] = form_type();
}
if (!array_key_exists("valid_types", $args)) {
$args["valid_types"] = array("new", "cur");
}
if (!array_key_exists("isupload", $args)) {
$args["isupload"] = true;
}
if (!array_key_exists("nodelete", $args)) {
$args["nodelete"] = true;
}
if (!array_key_exists("summary", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["summary"] = C_("This table provides you a form to add a new picture.");
break;
// A form to edit a current item
case "cur":
$args["summary"] = C_("This table provides you a form to modify a current picture.");
break;
}
}
if (!array_key_exists("cols", $args)) {
$args["cols"] = array("pic", "ratio", "uppic");
}
if (!array_key_exists("title", $args)) {
switch ($args["type"]) {
// A form to create a new item
case "new":
$args["title"] = C_("Upload a New Picture");
break;
// A form to edit a current item
case "cur":
$args["title"] = C_("Modify a Current Picture");
break;
}
}
parent::__construct($status, $args);
$this->_maxlens["ratio"] = 4;
}
// _html_col_pic: The picture preview
function _html_col_pic()
{
// Obtain the picture deposit
$PICS =& pic_deposit();
switch ($this->_type) {
// A form to create a new item
case "new":
// No display if the picture is not submitted yet
if (is_null($this->_form("pic"))) {
return;
}
?>
_form("ratio"))) {
if (is_numeric($this->_form["ratio"])) {
$this->_form["ratio_input"] = number_format($this->_form["ratio"], 2);
} else {
$this->_form["ratio_input"] = $this->_form["ratio"];
}
}
switch ($this->_type) {
// A form to create a new item
case "new":
// No display if the picture is not submitted yet
if ( is_null($this->_form("pic"))
&& is_null($this->_form("ratio"))) {
return;
}
?>