/** * Modify a policy * @ingroup POLICY_MANAGEMENT * * @param $policyid [in] Policy id * @param $ID [in] ID * @param $rateid [in] rateid for a rate * @param $title [in] Title of policy * @param $language [in] Language used for the policy * @param $description [in] Description for the policy */ function modify_policy($policyid, $ID, $rateid, $title, $language, $description) { global $conn; if (!$conn) { $conn = connect_Hotel_db(HOST, USER, PASS, DB, PORT); } if (!$conn) { return 0; } if (!$policyid) { add_policy($ID, $rateid, $title, $language, $description); } else { $sql = "update policy set "; $sql .= "ID = '" . $ID . "',"; $sql .= "rateid = '" . $rateid . "',"; $sql .= "title = '" . $title . "',"; $sql .= "language = '" . $language . "',"; $sql .= "description = '" . $description . "'"; $sql .= " where idpolicy = '" . $policyid . "'"; //print $sql."<br/>"; $stmt = $conn->prepare($sql); $results = $stmt->execute(); $stmt->fetch(); $stmt = NULL; } return 1; }
function add_domain($domain_name) { global $dbh; global $logger; if (get_domain_id($domain_name) != 0) { $logger->warning("Attempt to add duplicate domain:" . $domain_name); return 0; } // get default autocreation policy $default_policies = get_default_domain_policies(); $default_autocreation_policy = $default_policies['autocreation']; $default_transport = $default_policies['transport']; $routing_domain = substr($domain_name, 1); // Add the domain to the maia_domains table $sth = $dbh->prepare("INSERT INTO maia_domains (domain, enable_user_autocreation, routing_domain, transport) VALUES (?,?,?,?)"); $sth->execute(array($domain_name, $default_autocreation_policy, $routing_domain, $default_transport)); if (PEAR::isError($sth)) { die($sth->getMessage()); } $sth->free(); $sth = $dbh->prepare("SELECT id FROM maia_domains WHERE domain = ?"); $res = $sth->execute(array($domain_name)); if (PEAR::isError($sth)) { die($sth->getMessage()); } if ($row = $res->fetchrow()) { $domain_id = $row["id"]; } $sth->free(); // Add a new policy for the domain, based on the // system defaults. $policy_id = add_policy($domain_name); // Add the domain address to the users table $primary_email_id = add_address_to_user($policy_id, $domain_name, 0, $domain_id); $default_user_config = get_maia_user_row(get_user_id("@.", "@.")); // Add a domain default user to the maia_users table $sth = $dbh->prepare("INSERT INTO maia_users (user_name, primary_email_id, reminders, discard_ham, theme_id) VALUES (?, ?, 'N', ?, ?)"); $sth->execute(array($domain_name, $primary_email_id, $default_user_config["discard_ham"], $default_user_config["theme_id"])); if (PEAR::isError($sth)) { die($sth->getMessage()); } $sth->free(); $sth = $dbh->prepare("SELECT id FROM maia_users WHERE user_name = ?"); $res = $sth->execute(array($domain_name)); if (PEAR::isError($sth)) { die($sth->getMessage()); } if ($row = $res->fetchrow()) { $maia_user_id = $row["id"]; } $sth->free(); // Update the users table to link the e-mail address back to the domain $sth = $dbh->prepare("UPDATE users SET maia_user_id = ? WHERE id = ?"); $sth->execute(array($maia_user_id, $primary_email_id)); if (PEAR::isError($sth)) { die($sth->getMessage()); } return $domain_id; }
function add_email_address_to_user($uid, $email) { global $dbh; // Add a new policy for this user $policy_id = add_policy($email); // Add the user's e-mail address to the amavisd users table $new_address_id = add_address_to_user($policy_id, $email, $uid, 0); return $new_address_id; }