// Copyright: Copyright (C) 2005-2011 Pristine Communications // Set the include path if (!defined("INCPATH_SET")) { require_once dirname(__FILE__) . "/incpath.inc.php"; } // Referenced subroutines require_once "monica/actlog.inc.php"; require_once "monica/addcol.inc.php"; require_once "monica/cgiemu.inc.php"; require_once "monica/chkpriv.inc.php"; require_once "monica/commtext.inc.php"; require_once "monica/geoip.inc.php"; require_once "monica/getlang.inc.php"; require_once "monica/gettext.inc.php"; require_once "monica/guest.inc.php"; require_once "monica/hires.inc.php"; require_once "monica/http.inc.php"; require_once "monica/links.inc.php"; require_once "monica/lninfo.inc.php"; require_once "monica/login.inc.php"; require_once "monica/logout.inc.php"; require_once "monica/news.inc.php"; require_once "monica/pic.inc.php"; require_once "monica/requri.inc.php"; require_once "monica/scptpriv.inc.php"; require_once "monica/sql.inc.php"; require_once "monica/unicode.inc.php"; require_once "monica/username.inc.php"; require_once "monica/userpref.inc.php"; require_once "monica/usrconst.inc.php"; // Settings // BaseProcessor: Base form processor class class BaseProcessor { // Accessible by other processors public $_sn = null; protected $_form = array(); protected $_cur = array(); protected $_req = array(); protected $_table = null; protected $_type = null; protected $_step = null; protected $_cols = null; protected $_pres = array(); protected $_subs = array(); protected $_is_sql = true; protected $_update_timestamp = true; protected $_modified = null; protected $_curshown = null; protected $_newshown = null; // __construct: Initialize the processor function __construct(&$form, $table = null) { $this->_form =& $form; $this->_table = $table; $this->_pres = array(); $this->_subs = array(); if (!is_null($this->_form("form"))) { $this->_type = $this->_form["form"]; } if (!is_null($this->_form("step"))) { $this->_step = $this->_form["step"]; } if (!is_null($this->_form("sn"))) { $this->_sn = $this->_form["sn"]; } // The current item if (array_key_exists("CURRENT", $GLOBALS)) { $this->_cur =& $GLOBALS["CURRENT"]; } // The user request if (array_key_exists("REQUEST", $GLOBALS)) { $this->_req =& $GLOBALS["REQUEST"]; } return; } // process: Process the form, fully function process() { // Submitted but not confirmed yet if (is_null($this->_form("confirm"))) { return array("preview"=>true); } // Save the column deposit $this->_save_cols(); // Not modified if (!$this->_modified()) { return $this->_ret_status(); } // Begin the SQL transaction if ($this->_is_sql) { sql_begin(); } // Update the columns $this->_update_cols(); // Rebuild a limited part of pages $this->_rebuild_partial_pages(); // Send mails $this->_send_mails(); // Perform tasks other than column updates $this->_other_tasks(); // Commit the SQL transaction if ($this->_is_sql) { sql_commit(); } // Log and return the process status $this->_actlog(); return $this->_ret_status(); } ///////////////////////// // Methods belows are private. Do not call them directly. // Override them when needed. ///////////////////////// // _save_cols: Save the column deposit function _save_cols() { if (is_null($this->_type)) { return; } switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); break; } return; } // _update_cols: Update the columns function _update_cols() { // Run the pre-processing sub-processors for ($i = 0; $i < count($this->_pres); $i++) { if ($this->_pres[$i]->_modified()) { $this->_pres[$i]->_update_cols(); } } // Process the update if ($this->_is_sql && !is_null($this->_type)) { switch ($this->_type) { // A form to create a new item case "new": if (!is_null($this->_cols)) { $insert = "INSERT INTO " . $this->_table . " " . $this->_cols->ret($this->_update_timestamp) . ";\n"; gsql_query($insert); } break; // A form to edit a current item case "cur": if (!is_null($this->_cols) && !is_null($this->_sn)) { $update = "UPDATE " . $this->_table . " " . $this->_cols->ret($this->_update_timestamp) . " WHERE sn=" . $this->_sn . ";\n"; gsql_query($update); } break; // A form to delete a current item case "del": if (!is_null($this->_sn)) { $delete = "DELETE FROM " . $this->_table . " WHERE sn=" . $this->_sn . ";\n"; gsql_query($delete); } break; } } // Run the sub-processors for ($i = 0; $i < count($this->_subs); $i++) { if ($this->_subs[$i]->_modified()) { $this->_subs[$i]->_update_cols(); } } return; } // _rebuild_partial_pages: Rebuild a limited part of pages // Empty by default. Put page building code here. function _rebuild_partial_pages() { return; } // _send_mails: Send the mails // Empty by default. function _send_mails() { return; } // _other_tasks: Perform tasks other than column updates // Empty by default. function _other_tasks() { return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a record with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the record with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the record with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This record was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This record has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This record has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This record has been successfully deleted."), "isform"=>false); } } // _form: Return a specific form value // Return null if that column is empty function _form($name) { return array_key_exists($name, $this->_form)? $this->_form[$name]: null; } // _mcur: Return a specific current value, for use in e-mail notification // Return (blank) if that column is empty // Override it to obtain certain values for certain columns function _mcur($name) { return array_key_exists($name, $this->_cur) && !is_null($this->_cur[$name]) && $this->_cur[$name] != ""? $this->_cur[$name]: t_blank(); } // _mform: Return a specific form value, for use in e-mail notification // Return (blank) if that column is empty // Override it to obtain certain values for certain columns function _mform($name) { return array_key_exists($name, $this->_form) && !is_null($this->_form[$name]) && $this->_form[$name] != ""? $this->_form[$name]: t_blank(); } ///////////////////////// // Methods belows are private. Do not call them directly. // Do not override them, either. ///////////////////////// // _modified: If the item is modified function _modified() { // Modification status checked before if (!is_null($this->_modified)) { return $this->_modified; } // Return true for addition and deletion processors if (!is_null($this->_type) && $this->_type != "cur") { $this->_modified = true; return $this->_modified; } // Return true if the columns are modified if (!is_null($this->_cols) && $this->_cols->modified()) { $this->_modified = true; return $this->_modified; } // Return true if any of the subprocessors is modified for ($i = 0; $i < count($this->_pres); $i++) { if ($this->_pres[$i]->_modified()) { $this->_modified = true; return $this->_modified; } } for ($i = 0; $i < count($this->_subs); $i++) { if ($this->_subs[$i]->_modified()) { $this->_modified = true; return $this->_modified; } } // Not modified $this->_modified = false; return $this->_modified; } // _zhsync: Automatic Traditional Chinese to Simplified Chinese conversion function _zhsync() { // Get the available languages list global $ALL_LINGUAS; // Skip unless multilingual if (count($ALL_LINGUAS) == 1) { return; } // Skip unless we are in Traditional Chinese, and there is Simplified Chinese if (getlang() != "zh-tw" || !in_array("zh-cn", $ALL_LINGUAS)) { return; } switch ($this->_type) { // A form to create a new item case "new": foreach (sql_cols_ml($this->_table) as $col) { if (!is_null($this->_form($col))) { $this->_cols->addstr($col . "_zhcn", trad_to_simp($this->_form[$col])); } } break; // A form to edit a current item case "cur": foreach (sql_cols_ml($this->_table) as $col) { if (!is_null($this->_form($col))) { $this->_cols->addstr($col . "_zhcn", trad_to_simp($this->_form[$col]), $this->_cur[$col . "_zhcn"]); } } break; } } // _new_sn: Generate a new random serial number for an SQL table function _new_sn() { // S/N is always 9 digits do { // Generate a random serial number $sn = mt_rand(100000000, 999999999); // Check if this serial number exists $select = "SELECT sn FROM " . $this->_table . " WHERE sn=$sn;\n"; $result = sql_query($select); } while (sql_num_rows($result) > 0); return $sn; } // _req_hostport: Find the host-port of the POSTer, to be used in the e-mail. // This may not be the same as myself, since user may pass to // an SSL handler from a non-SSL form. function _req_hostport() { // Cache the resuit static $cache; // Return the cache if (isset($cache)) { return $cache; } if (!is_null($this->_form("referer"))) { $ref = $this->_form["referer"]; } elseif (array_key_exists("HTTP_REFERER", $_SERVER)) { $ref = $_SERVER["HTTP_REFERER"]; } if ( isset($ref) && substr($ref, -strlen(REQUEST_PATH)) == REQUEST_PATH) { $cache = substr($ref, 0, -strlen(REQUEST_PATH)); } else { $cache = REQUEST_HOSTPORT; } return $cache; } } // BaseCategoryProcessor: Base category form processor class class BaseCategoryProcessor extends BaseProcessor { // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This category was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This category has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This category has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This category has been successfully deleted."), "isform"=>false); } } } // BaseCategorizationProcessor: Base categorization record form processor class class BaseCategorizationProcessor extends BaseProcessor { // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This categorization record was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This categorization record has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This categorization record has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This categorization record has been successfully deleted."), "isform"=>false); } } } // DeletionProcessor: Deletion form processor class // Deletion condition is the value of the "cond" column in the form class DeletionProcessor extends BaseProcessor { protected $_cond = null; // __construct: Initialize the processor function __construct(&$form, $table = null) { $form["form"] = "del"; parent::__construct($form, $table); $this->_cond = $this->_form["cond"]; } // _update_cols: Update the columns function _update_cols() { // Process the update $delete = "DELETE FROM " . $this->_table . " WHERE " . $this->_cond . ";\n"; gsql_query($delete); return; } } // ListPreferenceProcessor: List preference form processor class class ListPreferenceProcessor extends BaseProcessor { protected $_names = array(); // __construct: Initialize the processor function __construct(&$form, $table = null) { parent::__construct($form, $table); if (is_guest()) { $this->_is_sql = false; } $this->_names = array("listsize", "listcols"); } // process: Process the form, fully function process() { // Use the parent processor for ordinary users // Users without Cookies turned on may have an empty log-in S/N if (!is_null(get_login_sn()) && !is_guest()) { return parent::process(); } // Guest preferences are saved in $_SESSION if (!array_key_exists("userpref", $_SESSION)) { $_SESSION["userpref"] = array(); } if (!array_key_exists($this->_form["domain"], $_SESSION["userpref"])) { $_SESSION["userpref"][$this->_form["domain"]] = array(); } foreach ($this->_names as $name) { $_SESSION["userpref"][$this->_form["domain"]][$name] = $this->_prefval($name); } return; } // _save_cols: Save the column deposit function _save_cols() { for ($i = 0; $i < count($this->_names); $i++) { // Obtain the preference value $val = $this->_prefval($this->_names[$i]); // Only update if value is different if (userpref($this->_names[$i], $this->_form["domain"]) == $val) { continue; } // Check if there is already an existing user preference $select = "SELECT * FROM userpref" . " WHERE usr=" . get_login_sn() . " AND domain='" . sql_esctext($this->_form["domain"]) . "'" . " AND name='" . sql_esctext($this->_names[$i]) . "';\n"; $result = sql_query($select); // There is an existing user preference if (sql_num_rows($result) == 1) { $row = sql_fetch_assoc($result); unset($GLOBALS["CURRENT"]); $GLOBALS["CURRENT"] = array( "sn" => $row["sn"], "usr" => $row["usr"], "domain" => $row["domain"], "name" => $row["name"], "value" => $row["value"], ); unset($FORM); $FORM = array(); $FORM["form"] = "cur"; $FORM["sn"] = $row["sn"]; $FORM["usr"] = get_login_sn(); $FORM["domain"] = $this->_form("domain"); $FORM["name"] = $this->_names[$i]; $FORM["value"] = $val; $processor = new UserPreferenceProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; unset($GLOBALS["CURRENT"]); if (!is_null($this->_cur)) { $GLOBALS["CURRENT"] =& $this->_cur; } // There is no existing user preference } else { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["usr"] = get_login_sn(); $FORM["domain"] = $this->_form("domain"); $FORM["name"] = $this->_names[$i]; $FORM["value"] = $val; $processor = new UserPreferenceProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } } return; } // _actlog: Log the activity function _actlog() { // Run the sub-processors for ($i = 0; $i < count($this->_subs); $i++) { if ($this->_subs[$i]->_modified()) { $this->_subs[$i]->_actlog(); } } } // _prefval: Obtain the preference value function _prefval($name) { // Specified if (!is_null($this->_form($name))) { return $this->_form[$name]; } // No need to check the validility. Invalids are simply ignored. $cols = array(); foreach (array_keys($this->_form) as $key) { if (preg_match("/^" . $name . "_(.+)$/", $key, $m)) { $cols[] = $m[1]; } } // Compose the preference value return implode(" ", $cols); } } // UserProcessor: User form processor class class UserProcessor extends BaseProcessor { // If it is a user editing herself (return from confirmation mail) public $_is_self = false; // If we should update the groups public $_no_set_groups = false; // If we need to purge the user's password public $_purge_passwd = null; // __construct: Initialize the processor function __construct(&$form, $table = "users") { parent::__construct($form, $table); // Non-super-users editing herself are not allowed to update the groups if (!is_null($this->_sn) && !is_su() && $this->_sn == get_login_sn()) { $this->_no_set_groups = true; } } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); if ($this->_is_self && is_null(get_login_sn())) { $this->_cols->login = $this->_sn; } $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("id", $this->_form("id")); $this->_cols->addpass("passwd", $this->_purge_passwd(), $this->_form("passwd")); $this->_cols->addstr("name", $this->_form("name")); $this->_cols->addbool("disabled", $this->_form("disabled")); // Find the changed items if (!$this->_no_set_groups) { $additems = array(); for ($i = 0; !is_null($this->_form("supgroup$i" . "sn")); $i++) { if (!is_null($this->_form("supgroup$i"))) { $additems[] = $this->_form["supgroup$i" . "sn"]; } } // Super users can set the super-user privilege if (is_su()) { // Super user privilege is added if (!is_null($this->_form("su"))) { $additems[] = su_group_sn(); } } foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $item; $FORM["member"] = $this->_sn; $processor = new UserMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } } break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); if ($this->_is_self && is_null(get_login_sn())) { $this->_cols->login = $this->_sn; } // Skip for non-super-user editing a super-user if (!(!is_su() && $this->_cur["su"])) { $this->_cols->addstr("id", $this->_form("id"), $this->_cur["id"]); $this->_cols->addpass("passwd", $this->_purge_passwd(), $this->_form("passwd"), $this->_cur["passwd"]); } $this->_cols->addstr("name", $this->_form("name"), $this->_cur["name"]); // Skip for non-super-user editing herself or a super-user if (!(!is_su() && ($this->_cur["su"] || $this->_sn == get_login_sn()))) { $this->_cols->addbool("disabled", $this->_form("disabled"), $this->_cur["disabled"]); } if (!is_null($this->_form("failsreset"))) { $this->_cols->addnum("fails", 0, $this->_cur["fails"]); } // Find the changed items if (!$this->_no_set_groups) { $olditems = array(); $newitems = array(); for ($i = 0; array_key_exists("supgroup$i" . "sn", $this->_cur); $i++) { $olditems[] = $this->_cur["supgroup$i" . "sn"]; } for ($i = 0; !is_null($this->_form("supgroup$i" . "sn")); $i++) { if (!is_null($this->_form("supgroup$i"))) { $newitems[] = $this->_form["supgroup$i" . "sn"]; } } $delitems = array_values(array_diff($olditems, $newitems)); $additems = array_values(array_diff($newitems, $olditems)); // Super users can set the super-user privilege if (is_su()) { // Super user privilege is added if (!$this->_cur["su"] && !is_null($this->_form("su"))) { $additems[] = su_group_sn(); // Super user privilege is removed } elseif ($this->_cur["su"] && is_null($this->_form("su"))) { $delitems[] = su_group_sn(); } } foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $item; $FORM["member"] = $this->_sn; $processor = new UserMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } if (count($delitems) > 0) { for ($i = 0; $i < count($delitems); $i++) { $delitems[$i] = "grp=" . $delitems[$i]; } $cond = implode(" OR ", $delitems); if (count($delitems) > 1) { $cond = "($cond)"; } unset($FORM); $FORM = array(); $FORM["cond"] = $cond . " AND member=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "usermem"); } } break; // A form to delete a current item case "del": // Find the changed items if ($this->_cur["supgroupcount"] > 0) { unset($FORM); $FORM = array(); $FORM["cond"] = "member=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "usermem"); } unset($FORM); $FORM = array(); $FORM["cond"] = "usr=" . $this->_sn; $this->_pres[] = new DeletionProcessor($FORM, "userpref"); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a user account " . $this->_form["id"] . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the user account " . (!is_null($this->_form("id"))? $this->_form["id"]: $this->_cur["id"]) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the user account " . $this->_cur["id"] . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This user account was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This user account has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This user account has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This user account has been successfully deleted."), "isform"=>false); } } // _purge_passwd: If we need to purge the password of the user function _purge_passwd() { // Checked before if (!is_null($this->_purge_passwd)) { return $this->_purge_passwd; } // Purge password for guests if (!$this->_no_set_groups) { for ($i = 0; !is_null($this->_form("supgroup$i" . "sn")); $i++) { // Skip unselected groups if (is_null($this->_form("supgroup$i"))) { continue; } // Check if this is the guest group if (groupid($this->_form["supgroup$i" . "sn"]) == GUEST_GROUP) { $this->_purge_passwd = true; return true; } } } // No guest group was found $this->_purge_passwd = false; return false; } } // GroupProcessor: Group form processor class class GroupProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "groups") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("id", $this->_form("id")); $this->_cols->addstr("dsc", $this->_form("dsc")); // Find the changed items $additems = array(); for ($i = 0; !is_null($this->_form("subuser$i" . "sn")); $i++) { if (!is_null($this->_form("subuser$i"))) { $additems[] = $this->_form["subuser$i" . "sn"]; } } foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $this->_sn; $FORM["member"] = $item; $processor = new UserMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } $additems = array(); for ($i = 0; !is_null($this->_form("subgroup$i" . "sn")); $i++) { if (!is_null($this->_form("subgroup$i"))) { $additems[] = $this->_form["subgroup$i" . "sn"]; } } foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $this->_sn; $FORM["member"] = $item; $processor = new GroupMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } $additems = array(); for ($i = 0; !is_null($this->_form("supgroup$i" . "sn")); $i++) { if (!is_null($this->_form("supgroup$i"))) { $additems[] = $this->_form["supgroup$i" . "sn"]; } } foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $item; $FORM["member"] = $this->_sn; $processor = new GroupMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); // Skip for a non-super-user editing a super-user group if (!(!is_su() && $this->_sn == su_group_sn())) { $this->_cols->addstr("id", $this->_form("id"), $this->_cur["id"]); } $this->_cols->addstr("dsc", $this->_form("dsc"), $this->_cur["dsc"]); // Find the changed items $olditems = array(); $newitems = array(); // Skip for a non-super-user editing a super-user group if (!(!is_su() && $this->_sn == su_group_sn())) { for ($i = 0; array_key_exists("subuser$i" . "sn", $this->_cur); $i++) { $olditems[] = $this->_cur["subuser$i" . "sn"]; } for ($i = 0; !is_null($this->_form("subuser$i" . "sn")); $i++) { if (!is_null($this->_form("subuser$i"))) { $newitems[] = $this->_form["subuser$i" . "sn"]; } } } $delitems = array_values(array_diff($olditems, $newitems)); $additems = array_values(array_diff($newitems, $olditems)); foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $this->_sn; $FORM["member"] = $item; $processor = new UserMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } if (count($delitems) > 0) { for ($i = 0; $i < count($delitems); $i++) { $delitems[$i] = "member=" . $delitems[$i]; } $cond = implode(" OR ", $delitems); if (count($delitems) > 1) { $cond = "($cond)"; } unset($FORM); $FORM = array(); $FORM["cond"] = $cond . " AND grp=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "usermem"); } $olditems = array(); $newitems = array(); // Skip for a non-super-user editing a super-user group if (!(!is_su() && $this->_sn == su_group_sn())) { for ($i = 0; array_key_exists("subgroup$i" . "sn", $this->_cur); $i++) { $olditems[] = $this->_cur["subgroup$i" . "sn"]; } for ($i = 0; !is_null($this->_form("subgroup$i" . "sn")); $i++) { if (!is_null($this->_form("subgroup$i"))) { $newitems[] = $this->_form["subgroup$i" . "sn"]; } } } $delitems = array_values(array_diff($olditems, $newitems)); $additems = array_values(array_diff($newitems, $olditems)); foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $this->_sn; $FORM["member"] = $item; $processor = new GroupMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } if (count($delitems) > 0) { for ($i = 0; $i < count($delitems); $i++) { $delitems[$i] = "member=" . $delitems[$i]; } $cond = implode(" OR ", $delitems); if (count($delitems) > 1) { $cond = "($cond)"; } unset($FORM); $FORM = array(); $FORM["cond"] = $cond . " AND grp=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "groupmem"); } $olditems = array(); $newitems = array(); // Skip for a non-super-user editing a super-user group if (!(!is_su() && $this->_sn == su_group_sn())) { for ($i = 0; array_key_exists("supgroup$i" . "sn", $this->_cur); $i++) { $olditems[] = $this->_cur["supgroup$i" . "sn"]; } for ($i = 0; !is_null($this->_form("supgroup$i" . "sn")); $i++) { if (!is_null($this->_form("supgroup$i"))) { $newitems[] = $this->_form["supgroup$i" . "sn"]; } } } $delitems = array_values(array_diff($olditems, $newitems)); $additems = array_values(array_diff($newitems, $olditems)); foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["grp"] = $item; $FORM["member"] = $this->_sn; $processor = new GroupMembershipProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } if (count($delitems) > 0) { for ($i = 0; $i < count($delitems); $i++) { $delitems[$i] = "grp=" . $delitems[$i]; } $cond = implode(" OR ", $delitems); if (count($delitems) > 1) { $cond = "($cond)"; } unset($FORM); $FORM = array(); $FORM["cond"] = $cond . " AND member=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "groupmem"); } break; // A form to delete a current item case "del": // Find the changed items if ($this->_cur["subusercount"] > 0) { unset($FORM); $FORM = array(); $FORM["cond"] = "grp=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "usermem"); } if ($this->_cur["subgroupcount"] + $this->_cur["supgroupcount"] > 0) { unset($FORM); $FORM = array(); $FORM["cond"] = "grp=" . $this->_sn . " OR member=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "groupmem"); } break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a group " . $this->_form["id"] . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the group " . $this->_form["id"] . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the group " . $this->_cur["id"] . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This group was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This group has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This group has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This group has been successfully deleted."), "isform"=>false); } } } // UserMembershipProcessor: User membership form processor class class UserMembershipProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "usermem") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addnum("grp", $this->_form("grp")); $this->_cols->addnum("member", $this->_form("member")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addnum("grp", $this->_form("grp"), $this->_cur["grp"]); $this->_cols->addnum("member", $this->_form("member"), $this->_cur["member"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a user membership record " . userid($this->_form["member"]) . " in group " . groupid($this->_form["grp"]) . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the user membership record " . userid($this->_form["member"]) . " in group " . groupid($this->_form["grp"]) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the user membership record " . userid($this->_cur["member"]) . " in group " . groupid($this->_cur["grp"]) . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This membership record was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This membership record has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This membership record has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This membership record has been successfully deleted."), "isform"=>false); } } } // GroupMembershipProcessor Group membership form processor class class GroupMembershipProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "groupmem") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addnum("grp", $this->_form("grp")); $this->_cols->addnum("member", $this->_form("member")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addnum("grp", $this->_form("grp"), $this->_cur["grp"]); $this->_cols->addnum("member", $this->_form("member"), $this->_cur["member"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a group membership record " . groupid($this->_form["member"]) . " in group " . groupid($this->_form["grp"]) . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the group membership record " . groupid($this->_form["member"]) . " in group " . groupid($this->_form["grp"]) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the group membership record " . groupid($this->_cur["member"]) . " in group " . groupid($this->_cur["grp"]) . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This membership record was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This membership record has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This membership record has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This membership record has been successfully deleted."), "isform"=>false); } } } // ScriptPrivilegeProcessor: Script privilege form processor class class ScriptPrivilegeProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "scptpriv") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("script", $this->_form("script")); $this->_cols->addnum("grp", $this->_form("grp")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addstr("script", $this->_form("script"), $this->_cur["script"]); $this->_cols->addnum("grp", $this->_form("grp"), $this->_cur["grp"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a script privilege record " . $this->_form["script"] . " for group " . groupid($this->_form["grp"]) . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the script privilege record " . $this->_form["script"] . " for group " . groupid($this->_form["grp"]) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the script privilege record " . $this->_cur["script"] . " for group " . groupid($this->_cur["grp"]) . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This script privilege record was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This script privilege record has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This script privilege record has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This script privilege record has been successfully deleted."), "isform"=>false); } } } // UserPreferenceProcessor: User preference form processor class class UserPreferenceProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "userpref") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { if ($this->_type != "del") { // Set the "everyone" user if ( !is_null($this->_form("everyone")) && $this->_form["everyone"] == "true") { unset($this->_form["usr"]); } // Set the "everywhere" domain if ( !is_null($this->_form("everywhere")) && $this->_form["everywhere"] == "true") { unset($this->_form["domain"]); } } switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addnum("usr", $this->_form("usr")); $this->_cols->addstr("domain", $this->_form("domain")); $this->_cols->addstr("name", $this->_form("name")); $this->_cols->addstr_empty("value", $this->_form("value")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addnum("usr", $this->_form("usr"), $this->_cur["usr"]); $this->_cols->addstr("domain", $this->_form("domain"), $this->_cur["domain"]); $this->_cols->addstr("name", $this->_form("name"), $this->_cur["name"]); $this->_cols->addstr_empty("value", $this->_form("value"), $this->_cur["value"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": if ( !is_null($this->_form("everyone")) && $this->_form["everyone"] == "true") { $user = "everyone"; } elseif (is_null($this->_form("usr"))) { $user = "everyone"; } else { $user = userid($this->_form["usr"]); } if ( !is_null($this->_form("everywhere")) && $this->_form["everywhere"] == "true") { $domain = "everywhere"; } elseif (is_null($this->_form("domain"))) { $domain = "everywhere"; } else { $domain = $this->_form["domain"]; } return gactlog("Create a user preference \"" . $this->_form["name"] . "\"" . " of $user for $domain" . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": if ( !is_null($this->_form("everyone")) && $this->_form["everyone"] == "true") { $user = "everyone"; } elseif (is_null($this->_form("usr"))) { $user = "everyone"; } else { $user = userid($this->_form["usr"]); } if ( !is_null($this->_form("everywhere")) && $this->_form["everywhere"] == "true") { $domain = "everywhere"; } elseif (is_null($this->_form("domain"))) { $domain = "everywhere"; } else { $domain = $this->_form["domain"]; } return gactlog("Update the user preference \"" . $this->_form["name"] . "\"" . " of $user for $domain" . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": $user = !is_null($this->_cur["usr"])? userid($this->_cur["usr"]): "everyone"; $domain = !is_null($this->_cur["domain"])? $this->_cur["domain"]: "everywhere"; return gactlog("Delete the user preference \"" . $this->_cur["name"] . "\"" . " of $user for $domain" . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This user preference was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This user preference has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This user preference has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This user preference has been successfully deleted."), "isform"=>false); } } } // UserRequestProcessor: User request form processor class class UserRequestProcessor extends BaseProcessor { public $_expire_is_expr = false; // __construct: Initialize the processor function __construct(&$form, $table = "userreq") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { if ($this->_type != "del") { // Set the "anonymous" user if ( !is_null($this->_form("anonymous")) && $this->_form["anonymous"] == "true") { unset($this->_form["usr"]); } } switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); // Anonymous user joining the member if ( is_null(get_login_sn()) && in_array($this->_form["type"], array("join", "rstpwd"))) { $this->_cols->login = usersn(ANONYMOUS_USER); } $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("type", $this->_form("type")); $this->_cols->addnum("usr", $this->_form("usr")); $this->_cols->addstr("args", $this->_form("args")); if ($this->_expire_is_expr) { $this->_cols->addexpr("expire", $this->_form("expire")); } else { $this->_cols->adddate("expire", $this->_form("expire")); } break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addstr("type", $this->_form("type"), $this->_cur["type"]); $this->_cols->addnum("usr", $this->_form("usr"), $this->_cur["usr"]); $this->_cols->addstr("args", $this->_form("args"), $this->_cur["args"]); if ($this->_expire_is_expr) { $this->_cols->addexpr("expire", $this->_form("expire")); } else { $this->_cols->adddate("expire", $this->_form("expire"), $this->_cur["expire"]); } break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": if ( !is_null($this->_form("anonymous")) && $this->_form["anonymous"] == "true") { $user = "anonymous"; } elseif (is_null($this->_form("usr"))) { $user = "anonymous"; } else { $user = userid($this->_form["usr"]); } return gactlog("Create a user request " . $this->_form["type"] . " from $user" . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": if ( !is_null($this->_form("anonymous")) && $this->_form["anonymous"] == "true") { $user = "anonymous"; } elseif (is_null($this->_form("usr"))) { $user = "anonymous"; } else { $user = userid($this->_form["usr"]); } return gactlog("Update the user request " . $this->_form["type"] . " from $user" . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": $user = !is_null($this->_cur["usr"])? userid($this->_cur["usr"]): "anonymous"; return gactlog("Delete the user request " . $this->_cur["type"] . " from $user" . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This user request was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This user request has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This user request has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This user request has been successfully deleted."), "isform"=>false); } } } // BasePageProcessor: Base page form processor class class BasePageProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "pages") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { // Get the available languages list global $ALL_LINGUAS; // Obtain the picture deposit $PICS =& pic_deposit(); switch ($this->_type) { // A form to create a new item case "new": // Set the picture information if (!is_null($this->_form("pic"))) { $picratio = $PICS[$this->_form("pic")]["ratio"]; $piccap = $this->_form("piccap"); $picpos = $this->_form("picpos"); } else { $picratio = null; $piccap = null; $picpos = null; } $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("path", $this->_form("path")); $this->_cols->addnum("ord", $this->_form("ord")); $this->_cols->addstr("title", $this->_form("title")); $this->_cols->addstr("body", $this->_form("body")); $this->_cols->addstr("kw", $this->_form("kw")); $this->_cols->addpic("pic", $this->_form("pic")); $this->_cols->addnum("picratio", $picratio); $this->_cols->addstr("piccap", $piccap); $this->_cols->addstr("picpos", $picpos); $this->_cols->addbool("html", $this->_form("html")); $this->_cols->addbool("hid", $this->_form("hid")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addstr("path", $this->_form("path"), $this->_cur["path"]); $this->_cols->addnum("ord", $this->_form("ord"), $this->_cur["ord"]); $this->_cols->addstr("title", $this->_form("title"), $this->_cur["title"]); $this->_cols->addstr("body", $this->_form("body"), $this->_cur["body"]); $this->_cols->addstr("kw", $this->_form("kw"), $this->_cur["kw"]); // Special rules to update the picture $this->_cols->addpic("pic", $this->_form("pic"), $this->_cur["pic"]); // Delete everything about this picture if (is_null($this->_form("pic"))) { $this->_cols->addstr("picratio", null, $this->_cur["picratio"]); if (count($ALL_LINGUAS) > 1) { for ($l = 0; $l < count($ALL_LINGUAS); $l++) { $lndb = ln($ALL_LINGUAS[$l], LN_DATABASE); $this->_cols->addstr("piccap_$lndb", null, $this->_cur["piccap_$lndb"]); } } else { $this->_cols->addstr("piccap", null, $this->_cur["piccap"]); } $this->_cols->addstr("picpos", null, $this->_cur["picpos"]); // Normal processing } else { $picratio = $PICS[$this->_form("pic")]["ratio"]; $this->_cols->addnum("picratio", $picratio, $this->_cur["picratio"]); $this->_cols->addstr("piccap", $this->_form("piccap"), $this->_cur["piccap"]); $this->_cols->addstr("picpos", $this->_form("picpos"), $this->_cur["picpos"]); } $this->_cols->addbool("html", $this->_form("html"), $this->_cur["html"]); $this->_cols->addbool("hid", $this->_form("hid"), $this->_cur["hid"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a page at " . $this->_form["path"] . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the page at " . $this->_form["path"] . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the page at " . $this->_cur["path"] . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This page was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This page has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This page has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This page has been successfully deleted."), "isform"=>false); } } // _remove_curfile: Remove the unwanted pages // This has to be explicitly run from _rebuild_partial_pages() function _remove_curfile() { // Nothing to remove if there is no current page if ($this->_type == "new" || $this->_cur["hid"]) { return; // A current page to be deleted or hidden } elseif ( $this->_type == "del" || !is_null($this->_form("hid"))) { grmoldpage($this->_cur["path"]); // A shown page update with a new page path to check with } else { grmoldpage($this->_cur["path"], $this->_form["path"]); } return; } // _remove_curpic: Remove the unwanted picture // This has to be explicitly run from _rebuild_partial_pages() function _remove_curpic() { // Nothing to remove if there is no current picture if ( $this->_type == "new" || $this->_cur["hid"] || is_null($this->_cur["pic"])) { return; } $pathpat = DOC_ROOT . PAGEPIC_PATH . "/" . $this->_sn . ".%s"; // A current picture to be deleted, hidden or removed if ( $this->_type == "del" || !is_null($this->_form("hid")) || !array_key_exists("pic", $this->_form)) { foreach ($GLOBALS["PIC_VALID_SUFS"] as $suf) { $file = sprintf($pathpat, $suf); if (file_exists($file)) { gunlink($file); } } // A shown picture update } else { $PICS =& pic_deposit(); $curpic =& $PICS[$this->_cur["pic"]]; $curpic =& resize_pic($curpic, $curpic["ratio"]); $newpic =& $PICS[$this->_form["pic"]]; $newpic =& resize_pic($newpic, $newpic["ratio"]); // Skip when having the same type (and hence file name suffix) if ($curpic["type"] == $newpic["type"]) { return; } $newfile = sprintf($pathpat, $GLOBALS["PIC_TYPESUF_MAP"][$newpic["type"]]); foreach ($GLOBALS["PIC_VALID_SUFS"] as $suf) { $file = sprintf($pathpat, $suf); if (file_exists($file) && $file != $newfile) { gunlink($file); } } } return; } } // BaseNewsProcessor: Base news form processor class class BaseNewsProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "news") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { // Get the available languages list global $ALL_LINGUAS; // Obtain the picture deposit $PICS =& pic_deposit(); switch ($this->_type) { // A form to create a new item case "new": // Set the picture information if (!is_null($this->_form("pic"))) { $picratio = $PICS[$this->_form("pic")]["ratio"]; $piccap = $this->_form("piccap"); $picpos = $this->_form("picpos"); } else { $picratio = null; $piccap = null; $picpos = null; } $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->adddate("date", $this->_form("date")); $this->_cols->addnum("ord", $this->_form("ord")); $this->_cols->addstr("title", $this->_form("title")); $this->_cols->addstr("body", $this->_form("body")); $this->_cols->addstr("kw", $this->_form("kw")); $this->_cols->addpic("pic", $this->_form("pic")); $this->_cols->addnum("picratio", $picratio); $this->_cols->addstr("piccap", $piccap); $this->_cols->addstr("picpos", $picpos); $this->_cols->addbool("html", $this->_form("html")); $this->_cols->addbool("hid", $this->_form("hid")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->adddate("date", $this->_form("date"), $this->_cur["date"]); $this->_cols->addnum("ord", $this->_form("ord"), $this->_cur["ord"]); $this->_cols->addstr("title", $this->_form("title"), $this->_cur["title"]); $this->_cols->addstr("body", $this->_form("body"), $this->_cur["body"]); $this->_cols->addstr("kw", $this->_form("kw"), $this->_cur["kw"]); // Special rules to update the picture $this->_cols->addpic("pic", $this->_form("pic"), $this->_cur["pic"]); // Delete everything about this picture if (is_null($this->_form("pic"))) { $this->_cols->addstr("picratio", null, $this->_cur["picratio"]); if (count($ALL_LINGUAS) > 1) { for ($l = 0; $l < count($ALL_LINGUAS); $l++) { $lndb = ln($ALL_LINGUAS[$l], LN_DATABASE); $this->_cols->addstr("piccap_$lndb", null, $this->_cur["piccap_$lndb"]); } } else { $this->_cols->addstr("piccap", null, $this->_cur["piccap"]); } $this->_cols->addstr("picpos", null, $this->_cur["picpos"]); // Normal processing } else { $picratio = $PICS[$this->_form("pic")]["ratio"]; $this->_cols->addnum("picratio", $picratio, $this->_cur["picratio"]); $this->_cols->addstr("piccap", $this->_form("piccap"), $this->_cur["piccap"]); $this->_cols->addstr("picpos", $this->_form("picpos"), $this->_cur["picpos"]); } $this->_cols->addbool("html", $this->_form("html"), $this->_cur["html"]); $this->_cols->addbool("hid", $this->_form("hid"), $this->_cur["hid"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a news article " . newsid_compose($this->_form["date"], $this->_form["ord"]) . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the news article " . newsid_compose($this->_form["date"], $this->_form["ord"]) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the news article " . newsid_compose($this->_cur["date"], $this->_cur["ord"]) . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This news article was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This news article has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This news article has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This news article has been successfully deleted."), "isform"=>false); } } // _remove_curpic: Remove the unwanted picture // This has to be explicitly run from _rebuild_partial_pages() function _remove_curpic() { // Nothing to remove if there is no current picture if ( $this->_type == "new" || $this->_cur["hid"] || is_null($this->_cur["pic"])) { return; } $pathpat = DOC_ROOT . NEWSPIC_PATH . "/" . $this->_sn . ".%s"; // A current picture to be deleted, hidden or removed if ( $this->_type == "del" || !is_null($this->_form("hid")) || is_null($this->_form("pic"))) { foreach ($GLOBALS["PIC_VALID_SUFS"] as $suf) { $file = sprintf($pathpat, $suf); if (file_exists($file)) { gunlink($file); } } // A shown picture update } else { $PICS =& pic_deposit(); $curpic =& $PICS[$this->_cur["pic"]]; $curpic =& resize_pic($curpic, $curpic["ratio"]); $newpic =& $PICS[$this->_form["pic"]]; $newpic =& resize_pic($newpic, $newpic["ratio"]); // Skip when having the same type (and hence file name suffix) if ($curpic["type"] == $newpic["type"]) { return; } $newfile = sprintf($pathpat, $GLOBALS["PIC_TYPESUF_MAP"][$newpic["type"]]); foreach ($GLOBALS["PIC_VALID_SUFS"] as $suf) { $file = sprintf($pathpat, $suf); if (file_exists($file) && $file != $newfile) { gunlink($file); } } } return; } } // CountryProcessor: Country form processor class class CountryProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "country") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("id", $this->_form("id")); $this->_cols->addstr("name", $this->_form("name")); $this->_cols->addbool("special", $this->_form("special")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addstr("id", $this->_form("id"), $this->_cur["id"]); $this->_cols->addstr("name", $this->_form("name"), $this->_cur["name"]); $this->_cols->addbool("special", $this->_form("special"), $this->_cur["special"]); break; } return; } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a country " . $this->_form["id"] . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the country " . $this->_form["id"] . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the country " . $this->_cur["id"] . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This country was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This country has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This country has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This country has been successfully deleted."), "isform"=>false); } } } // PictureProcessor: Picture form processor class class PictureProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = null) { parent::__construct($form, $table); $this->_modified = true; } // _other_tasks: Perform tasks other than column updates function _other_tasks() { // Obtain the picture deposit $PICS =& pic_deposit(); switch ($this->_type) { // A form to create a new item case "new": $PICS[$this->_form["pic"]]["ratio"] = $this->_form("ratio"); $PICS[$this->_form["pic"]]["ratio_input"] = number_format($this->_form["ratio"], 2); $cols = array(); // Add the columns $selurl = $this->_form["caller"]; $cols[] = "formid=" . urlencode($this->_form["cformid"]); $cols[] = "selsn=" . urlencode($this->_form["pic"]); $url = $this->_form["caller"] . "?" . implode("&", $cols); http_303($url); // No return // A form to edit a current item case "cur": $PICS[$this->_form["pic"]]["ratio"] = $this->_form("ratio"); $PICS[$this->_form["pic"]]["ratio_input"] = number_format($this->_form["ratio"], 2); $cols = array(); // Add the columns $selurl = $this->_form["caller"]; $cols[] = "formid=" . urlencode($this->_form["cformid"]); $cols[] = "selsn=" . urlencode($this->_form["pic"]); $url = $this->_form["caller"] . "?" . implode("&", $cols); http_303($url); // No return } } } // RebuildProcessor: Rebuild form processor class class RebuildProcessor extends BaseProcessor { protected $_t_start = null; protected $_t_end = null; // __construct: Initialize the processor function __construct(&$form, $table = null) { parent::__construct($form, $table); $this->_modified = true; } // _other_tasks: Perform tasks other than column updates function _other_tasks() { // Rebuild the pages $this->_t_start = time_hires(); call_user_func("rebuild_" . $this->_form["type"]); $this->_t_end = time_hires(); } // _actlog: Log the activity function _actlog() { return gactlog("Rebuild pages of type \"" . $this->_form["type"] . "\"."); } // _ret_status: Return the process status function _ret_status() { return array("msg"=>NC_("The specified web pages have been successfully rebuilt. (%0.3f seconds)"), "margs"=>array($this->_t_end-$this->_t_start)); } } // LogInProcessor: Log in form processor class class LogInProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "users") { $form["form"] = "cur"; parent::__construct($form, $table); $this->_sn = $this->_cur["sn"]; $this->_update_timestamp = false; } // _save_cols: Save the column deposit function _save_cols() { // Look up the host name $host = gethostbyaddr($_SERVER["REMOTE_ADDR"]); if ($host == $_SERVER["REMOTE_ADDR"]) { $host = null; } $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); // Add the visits count $this->_cols->addexpr("visits", "visits+1"); // Record the timestamp and the remote IP $this->_cols->addexpr("visited", "now()"); $this->_cols->addstr("ip", $_SERVER["REMOTE_ADDR"], $this->_cur["ip"]); $this->_cols->addstr("host", $host, $this->_cur["host"]); $this->_cols->addstr("ct", geoiplookup(), $this->_cur["ct"]); // Reset the fail login count $this->_cols->addnum("fails", 0); return; } // _other_tasks: Perform tasks other than column updates function _other_tasks() { // Register the logged-in id $_SESSION["usersn"] = $this->_sn; // Set the log-in information upd_login_info(); // Remember the user $_SESSION["remember"] = !is_null($this->_form("remember")); // Reset the by-login data deposit unset($_SESSION["bylogin"]); } // _actlog: Log the activity function _actlog() { // Log the guest log in, too return actlog("Log in with s/n " . $this->_sn . "."); } // _ret_status: Return the process status function _ret_status() { return array("msg"=>NC_("Welcome, %s!"), "margs"=>array("_USERNAME"), "isform"=>false); } } // LogOutProcessor: Log out form processor class class LogOutProcessor extends BaseProcessor { protected $_is_admin = null; protected $_userid = null; // __construct: Initialize the processor function __construct(&$form, $table = null) { parent::__construct($form, $table); $this->_sn = get_login_sn(); $this->_is_sql = false; $this->_modified = true; $this->_is_admin = is_guest()? is_admin_script(): is_admin(); } // _save_cols: Save the column deposit // Make it a null function function _save_cols() { return; } // _other_tasks: Perform tasks other than column updates function _other_tasks() { $this->_userid = get_login_id(); logout(); } // _actlog: Log the activity function _actlog() { // Log the guest log out, too return actlog("Log out with s/n " . $this->_sn . ".", $this->_userid); } // _ret_status: Return the process status function _ret_status() { return array("msg"=>NC_("You have successfully logged out."), "isform"=>false, "is_admin"=>$this->_is_admin); } } // BaseLinkCategoryProcessor: Base link category form processor class class BaseLinkCategoryProcessor extends BaseCategoryProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "linkcat") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { if ($this->_type != "del") { // Set the "topmost" parent if ( !is_null($this->_form("topmost")) && $this->_form["topmost"] == "true") { unset($this->_form["parent"]); } } switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addnum("parent", $this->_form("parent")); $this->_cols->addstr("id", $this->_form("id")); $this->_cols->addnum("ord", $this->_form("ord")); $this->_cols->addstr("title", $this->_form("title")); $this->_cols->addstr("kw", $this->_form("kw")); $this->_cols->addbool("hid", $this->_form("hid")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addnum("parent", $this->_form("parent"), $this->_cur["parent"]); $this->_cols->addstr("id", $this->_form("id"), $this->_cur["id"]); $this->_cols->addnum("ord", $this->_form("ord"), $this->_cur["ord"]); $this->_cols->addstr("title", $this->_form("title"), $this->_cur["title"]); $this->_cols->addstr("kw", $this->_form("kw"), $this->_cur["kw"]); $this->_cols->addbool("hid", $this->_form("hid"), $this->_cur["hid"]); break; } return; } // _update_cols: Update the columns function _update_cols() { $this->_curshown = $this->_shown_parts(); parent::_update_cols(); } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a link category " . linkcat_path($this->_sn) . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the link category " . linkcat_path($this->_sn) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the link category " . $this->_cur["path"] . " with s/n " . $this->_sn . "."); } } // _remove_curfile: Remove the unwanted page function _remove_curfile() { // Remove the unwanted category files foreach (array_diff($this->_curshown["catspath"], $this->_newshown["catspath"]) as $page) { grmoldpage("/links$page"); } return; } // _shown_parts: Obtain the shown parts function _shown_parts() { $shown = links_shown_parts(); // Check if myself is shown $select = "SELECT sn FROM linkcat" . " WHERE sn=" . $this->_sn . " AND linkcat_isshown(sn, hid, parent);\n"; $result = sql_query($select); $shown["self"] = (sql_num_rows($result) > 0); return $shown; } } // BaseLinkProcessor: Base link form processor class class BaseLinkProcessor extends BaseProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "links") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addstr("title", $this->_form("title")); $this->_cols->addurl("url", $this->_form("url")); $this->_cols->addstr("dsc", $this->_form("dsc")); $this->_cols->addbool("hid", $this->_form("hid")); // Find the changed items $additems = array(); for ($i = 0; !is_null($this->_form("cat$i")); $i++) { if ($this->_form["cat$i"] != "") { $additems[] = $this->_form["cat$i"]; } } foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["cat"] = $item; $FORM["link"] = $this->_sn; $processor = new BaseLinkCategorizationProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addstr("title", $this->_form("title"), $this->_cur["title"]); $this->_cols->addurl("url", $this->_form("url"), $this->_cur["url"]); $this->_cols->addstr("dsc", $this->_form("dsc"), $this->_cur["dsc"]); $this->_cols->addbool("hid", $this->_form("hid"), $this->_cur["hid"]); // Find the changed items $olditems = array(); $newitems = array(); for ($i = 0; $i < $this->_cur["catcount"]; $i++) { $olditems[] = $this->_cur["cat$i"]; } for ($i = 0; !is_null($this->_form("cat$i")); $i++) { if ($this->_form["cat$i"] != "") { $newitems[] = $this->_form["cat$i"]; } } $delitems = array_values(array_diff($olditems, $newitems)); $additems = array_values(array_diff($newitems, $olditems)); foreach ($additems as $item) { unset($FORM); $FORM = array(); $FORM["form"] = "new"; $FORM["cat"] = $item; $FORM["link"] = $this->_sn; $processor = new BaseLinkCategorizationProcessor($FORM); $processor->_save_cols(); $this->_subs[] = $processor; } if (count($delitems) > 0) { for ($i = 0; $i < count($delitems); $i++) { $delitems[$i] = "cat=" . $delitems[$i]; } $cond = implode(" OR ", $delitems); if (count($delitems) > 1) { $cond = "($cond)"; } unset($FORM); $FORM = array(); $FORM["cond"] = $cond . " AND link=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "linkcatz"); } break; // A form to delete a current item case "del": // Find the changed items if ($this->_cur["catcount"] > 0) { unset($FORM); $FORM = array(); $FORM["cond"] = "link=" . $this->_sn; $this->_subs[] = new DeletionProcessor($FORM, "linkcatz"); } break; } return; } // _update_cols: Update the columns function _update_cols() { $this->_curshown = $this->_shown_parts(); parent::_update_cols(); } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a related link " . $this->_form["url"] . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the related link " . $this->_form["url"] . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the related link " . $this->_cur["url"] . " with s/n " . $this->_sn . "."); } } // _ret_status: Return the process status function _ret_status() { if (!$this->_modified()) { return array("msg"=>NC_("This related link was not modified."), "isform"=>false); } switch ($this->_type) { // A form to create a new item case "new": return array("msg"=>NC_("This related link has been successfully added."), "isform"=>false); // A form to edit a current item case "cur": return array("msg"=>NC_("This related link has been successfully updated."), "isform"=>false); // A form to delete a current item case "del": return array("msg"=>NC_("This related link has been successfully deleted."), "isform"=>false); } } // _remove_curfile: Remove the unwanted page function _remove_curfile() { // Remove the unwanted category files foreach (array_diff($this->_curshown["catspath"], $this->_newshown["catspath"]) as $page) { grmoldpage("/links$page"); } return; } // _shown_parts: Obtain the shown parts function _shown_parts() { return links_shown_parts(); } } // BaseLinkCategorizationProcessor: Base link categorization form processor class class BaseLinkCategorizationProcessor extends BaseCategorizationProcessor { // __construct: Initialize the processor function __construct(&$form, $table = "linkcatz") { parent::__construct($form, $table); } // _save_cols: Save the column deposit function _save_cols() { switch ($this->_type) { // A form to create a new item case "new": $this->_sn = $this->_new_sn(); $this->_cols = new AddCol($this->_table, ADDCOL_INSERT); $this->_cols->addnum("sn", $this->_sn); $this->_cols->addnum("cat", $this->_form("cat")); $this->_cols->addnum("link", $this->_form("link")); break; // A form to edit a current item case "cur": $this->_cols = new AddCol($this->_table, ADDCOL_UPDATE); $this->_cols->addnum("cat", $this->_form("cat"), $this->_cur["cat"]); $this->_cols->addnum("link", $this->_form("link"), $this->_cur["link"]); break; } return; } // _update_cols: Update the columns function _update_cols() { $this->_curshown = $this->_shown_parts(); parent::_update_cols(); } // _actlog: Log the activity function _actlog() { switch ($this->_type) { // A form to create a new item case "new": return gactlog("Create a link categorization record " . link_url($this->_form["link"]) . " in category " . linkcat_path($this->_form["cat"]) . " with s/n " . $this->_sn . "."); // A form to edit a current item case "cur": return gactlog("Update the link categorization record " . link_url($this->_form["link"]) . " in category " . linkcat_path($this->_form["cat"]) . " with s/n " . $this->_sn . "."); // A form to delete a current item case "del": return gactlog("Delete the link categorization record " . link_url($this->_cur["link"]) . " in category " . linkcat_path($this->_cur["cat"]) . " with s/n " . $this->_sn . "."); } } // _remove_curfile: Remove the unwanted page function _remove_curfile() { // Remove the unwanted category files foreach (array_diff($this->_curshown["catspath"], $this->_newshown["catspath"]) as $page) { grmoldpage("/links$page"); } return; } // _shown_parts: Obtain the shown parts function _shown_parts() { return links_shown_parts(); } } ?>