Made changes to the database and added models to support options. Next is permissions
git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@797 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
326
db/schema.sql
326
db/schema.sql
@@ -25,9 +25,9 @@
|
|||||||
-- REVISIT <AP>: 20090511
|
-- REVISIT <AP>: 20090511
|
||||||
-- By not specifying the database, the script can
|
-- By not specifying the database, the script can
|
||||||
-- make the determination of which one to use.
|
-- make the determination of which one to use.
|
||||||
-- DROP DATABASE IF EXISTS `property_manager`;
|
DROP DATABASE IF EXISTS `property_manager`;
|
||||||
-- CREATE DATABASE `property_manager`;
|
CREATE DATABASE `property_manager`;
|
||||||
-- USE `property_manager`;
|
USE `property_manager`;
|
||||||
|
|
||||||
|
|
||||||
-- ######################################################################
|
-- ######################################################################
|
||||||
@@ -241,7 +241,7 @@ CREATE TABLE `pmgr_contacts_methods` (
|
|||||||
-- ######################################################################
|
-- ######################################################################
|
||||||
-- ######################################################################
|
-- ######################################################################
|
||||||
-- ##
|
-- ##
|
||||||
-- ## GROUPS
|
-- ## GROUPS / USERS
|
||||||
-- ##
|
-- ##
|
||||||
|
|
||||||
|
|
||||||
@@ -256,59 +256,15 @@ CREATE TABLE `pmgr_groups` (
|
|||||||
-- code may not be userful
|
-- code may not be userful
|
||||||
`code` VARCHAR(12) NOT NULL, -- User style "id"
|
`code` VARCHAR(12) NOT NULL, -- User style "id"
|
||||||
`name` VARCHAR(80) NOT NULL,
|
`name` VARCHAR(80) NOT NULL,
|
||||||
|
|
||||||
|
-- Lower ranks are given higher priority
|
||||||
|
`rank` SMALLINT UNSIGNED NOT NULL DEFAULT 100,
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- TABLE pmgr_group_options
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_group_options`;
|
|
||||||
CREATE TABLE `pmgr_group_options` (
|
|
||||||
`group_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
`name` VARCHAR(50) NOT NULL,
|
|
||||||
`value` VARCHAR(255) NOT NULL,
|
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`group_id`, `name`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- TABLE pmgr_group_permissions
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_group_permissions`;
|
|
||||||
CREATE TABLE `pmgr_group_permissions` (
|
|
||||||
`group_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
`name` CHAR(30) NOT NULL,
|
|
||||||
`access` ENUM('ALLOWED',
|
|
||||||
'DENIED',
|
|
||||||
'FORCED')
|
|
||||||
NOT NULL DEFAULT 'ALLOWED',
|
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`group_id`, `name`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ######################################################################
|
|
||||||
-- ##
|
|
||||||
-- ## USERS
|
|
||||||
-- ##
|
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
@@ -334,18 +290,208 @@ CREATE TABLE `pmgr_users` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ##
|
||||||
|
-- ## OPTIONS
|
||||||
|
-- ##
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_options
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_options`;
|
||||||
|
CREATE TABLE `pmgr_options` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(50) NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
UNIQUE KEY `name_key` (`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_option_values
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_option_values`;
|
||||||
|
CREATE TABLE `pmgr_option_values` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`option_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`value` VARCHAR(255) NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_default_options
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_default_options`;
|
||||||
|
CREATE TABLE `pmgr_default_options` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`option_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_group_options
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_group_options`;
|
||||||
|
CREATE TABLE `pmgr_group_options` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`group_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`option_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
KEY `group_key` (`group_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- TABLE pmgr_user_options
|
-- TABLE pmgr_user_options
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_user_options`;
|
DROP TABLE IF EXISTS `pmgr_user_options`;
|
||||||
CREATE TABLE `pmgr_user_options` (
|
CREATE TABLE `pmgr_user_options` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
`user_id` INT(10) UNSIGNED NOT NULL,
|
`user_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`name` VARCHAR(50) NOT NULL,
|
`option_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`value` VARCHAR(255) NOT NULL,
|
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
KEY `user_key` (`user_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
PRIMARY KEY (`user_id`, `name`)
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_site_options
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_site_options`;
|
||||||
|
CREATE TABLE `pmgr_site_options` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`site_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`option_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
KEY `site_key` (`site_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ##
|
||||||
|
-- ## PERMISSIONS
|
||||||
|
-- ##
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_permissions
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_permissions`;
|
||||||
|
CREATE TABLE `pmgr_permissions` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` VARCHAR(50) NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
UNIQUE KEY `name_key` (`name`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_permission_values
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_permission_values`;
|
||||||
|
CREATE TABLE `pmgr_permission_values` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`permission_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`access` ENUM('ALLOW',
|
||||||
|
'DENY')
|
||||||
|
NOT NULL DEFAULT 'DENY',
|
||||||
|
`level` SMALLINT UNSIGNED DEFAULT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_default_permissions
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_default_permissions`;
|
||||||
|
CREATE TABLE `pmgr_default_permissions` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`permission_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_group_permissions
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_group_permissions`;
|
||||||
|
CREATE TABLE `pmgr_group_permissions` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`group_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`permission_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
KEY `group_key` (`group_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_user_permissions
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_user_permissions`;
|
||||||
|
CREATE TABLE `pmgr_user_permissions` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`user_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`permission_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
KEY `user_key` (`user_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_site_permissions
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_site_permissions`;
|
||||||
|
CREATE TABLE `pmgr_site_permissions` (
|
||||||
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`site_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`permission_value_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
KEY `site_key` (`site_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
@@ -380,46 +526,6 @@ CREATE TABLE `pmgr_sites` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- TABLE pmgr_site_options
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_site_options`;
|
|
||||||
CREATE TABLE `pmgr_site_options` (
|
|
||||||
`site_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
`name` VARCHAR(50) NOT NULL,
|
|
||||||
`value` VARCHAR(255) NOT NULL,
|
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`site_id`, `name`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- ----------------------------------------------------------------------
|
|
||||||
-- TABLE pmgr_site_memberships
|
|
||||||
--
|
|
||||||
-- Which users are allowed to access which sites,
|
|
||||||
-- and under which set of group permissions (possibly multiple)
|
|
||||||
|
|
||||||
-- SELECT U.id, P.name, MAX(P.access)
|
|
||||||
-- FROM pmgr_users U
|
|
||||||
-- LEFT JOIN pmgr_site_membership M ON M.user_id = U.id
|
|
||||||
-- LEFT JOIN pmgr_groups G ON G.id = M.group_id
|
|
||||||
-- LEFT JOIN pmgr_group_permissions P ON P.group_id = G.id
|
|
||||||
-- GROUP BY U.id, P.name
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_site_memberships`;
|
|
||||||
CREATE TABLE `pmgr_site_memberships` (
|
|
||||||
`site_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
`user_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
`group_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`site_id`, `user_id`, `group_id`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- TABLE pmgr_site_areas
|
-- TABLE pmgr_site_areas
|
||||||
@@ -437,6 +543,38 @@ CREATE TABLE `pmgr_site_areas` (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ######################################################################
|
||||||
|
-- ##
|
||||||
|
-- ## MEMBERSHIPS
|
||||||
|
-- ##
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- TABLE pmgr_memberships
|
||||||
|
--
|
||||||
|
-- Which users are allowed to access which sites,
|
||||||
|
-- and under which set of group permissions (possibly multiple)
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pmgr_memberships`;
|
||||||
|
CREATE TABLE `pmgr_memberships` (
|
||||||
|
`site_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`user_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`group_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`site_id`, `user_id`, `group_id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- ######################################################################
|
-- ######################################################################
|
||||||
-- ######################################################################
|
-- ######################################################################
|
||||||
-- ######################################################################
|
-- ######################################################################
|
||||||
|
|||||||
419
db/scratch.sql
419
db/scratch.sql
@@ -157,3 +157,422 @@ WHERE
|
|||||||
-- catch other types not considered in this query
|
-- catch other types not considered in this query
|
||||||
OR T.type NOT IN ('RECEIPT', 'CREDIT_NOTE', 'INVOICE', 'PAYMENT')
|
OR T.type NOT IN ('RECEIPT', 'CREDIT_NOTE', 'INVOICE', 'PAYMENT')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- #################################################################
|
||||||
|
-- ## USER / GROUP
|
||||||
|
|
||||||
|
INSERT INTO pmgr_groups (`code`, `name`, `rank`)
|
||||||
|
VALUES('Owner', 'Owner Group', 25);
|
||||||
|
SET @o_gid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_groups (`code`, `name`, `rank`)
|
||||||
|
VALUES('Admin', 'Admin Group', 50);
|
||||||
|
SET @a_gid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_groups (`code`, `name`, `rank`)
|
||||||
|
VALUES('Manager', 'Manager Group', 75);
|
||||||
|
SET @m_gid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_groups (`code`, `name`)
|
||||||
|
VALUES('Temp', 'Temporary Help');
|
||||||
|
SET @t_gid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_users (`code`, `login`, `contact_id`)
|
||||||
|
VALUES('AP', 'abijah', 0);
|
||||||
|
SET @a_uid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_users (`code`, `login`, `contact_id`)
|
||||||
|
VALUES('SK', 'shirley', 0);
|
||||||
|
SET @s_uid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_users (`code`, `login`, `contact_id`)
|
||||||
|
VALUES('DE', 'dan', 0);
|
||||||
|
SET @d_uid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_users (`code`, `login`, `contact_id`)
|
||||||
|
VALUES('KD', 'kevin', 0);
|
||||||
|
SET @k_uid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_sites (`code`, `name`)
|
||||||
|
VALUES('VSS', 'Valley Storage');
|
||||||
|
SET @v_sid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO pmgr_sites (`code`, `name`)
|
||||||
|
VALUES('FAKE', 'Fake Site');
|
||||||
|
SET @f_sid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
-- Site Membership
|
||||||
|
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@v_sid, @a_uid, @o_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@v_sid, @a_uid, @a_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@v_sid, @a_uid, @m_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@v_sid, @s_uid, @m_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@v_sid, @d_uid, @t_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@f_sid, @s_uid, @a_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@f_sid, @s_uid, @m_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@f_sid, @k_uid, @o_gid);
|
||||||
|
INSERT INTO pmgr_site_memberships (`site_id`, `user_id`, `group_id`)
|
||||||
|
VALUES(@f_sid, @d_uid, @t_gid);
|
||||||
|
|
||||||
|
|
||||||
|
-- Options
|
||||||
|
|
||||||
|
INSERT INTO pmgr_options (`name`) VALUES ('theme');
|
||||||
|
SET @t_oid = LAST_INSERT_ID();
|
||||||
|
INSERT INTO pmgr_options (`name`) VALUES ('menu');
|
||||||
|
SET @m_oid = LAST_INSERT_ID();
|
||||||
|
|
||||||
|
-- Default Option Values
|
||||||
|
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@t_oid, 'blue');
|
||||||
|
INSERT INTO pmgr_default_options (`option_value_id`) VALUES(LAST_INSERT_ID());
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@m_oid, 'basic');
|
||||||
|
INSERT INTO pmgr_default_options (`option_value_id`) VALUES(LAST_INSERT_ID());
|
||||||
|
|
||||||
|
-- Group options
|
||||||
|
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@t_oid, 'gold');
|
||||||
|
INSERT INTO pmgr_group_options (`group_id`, `option_value_id`)
|
||||||
|
VALUES(@o_gid, LAST_INSERT_ID());
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@t_oid, 'silver');
|
||||||
|
INSERT INTO pmgr_group_options (`group_id`, `option_value_id`)
|
||||||
|
VALUES(@a_gid, LAST_INSERT_ID());
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@t_oid, 'red');
|
||||||
|
INSERT INTO pmgr_group_options (`group_id`, `option_value_id`)
|
||||||
|
VALUES(@m_gid, LAST_INSERT_ID());
|
||||||
|
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@m_oid, 'advanced');
|
||||||
|
INSERT INTO pmgr_group_options (`group_id`, `option_value_id`)
|
||||||
|
VALUES(@o_gid, LAST_INSERT_ID());
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@m_oid, 'advanced');
|
||||||
|
INSERT INTO pmgr_group_options (`group_id`, `option_value_id`)
|
||||||
|
VALUES(@a_gid, LAST_INSERT_ID());
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@m_oid, 'restricted');
|
||||||
|
INSERT INTO pmgr_group_options (`group_id`, `option_value_id`)
|
||||||
|
VALUES(@t_gid, LAST_INSERT_ID());
|
||||||
|
|
||||||
|
-- User Options
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@m_oid, 'special');
|
||||||
|
INSERT INTO pmgr_user_options (`user_id`, `option_value_id`)
|
||||||
|
VALUES(@s_uid, LAST_INSERT_ID());
|
||||||
|
|
||||||
|
-- Site Options
|
||||||
|
INSERT INTO pmgr_option_values (`option_id`, `value`) VALUES (@t_oid, 'site-theme');
|
||||||
|
INSERT INTO pmgr_site_options (`site_id`, `option_value_id`)
|
||||||
|
VALUES(@f_sid, LAST_INSERT_ID());
|
||||||
|
|
||||||
|
|
||||||
|
-- SELECT U.id, P.name, MAX(P.access)
|
||||||
|
-- FROM pmgr_users U
|
||||||
|
-- LEFT JOIN pmgr_site_membership M ON M.user_id = U.id
|
||||||
|
-- LEFT JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
-- LEFT JOIN pmgr_group_permissions P ON P.group_id = G.id
|
||||||
|
-- GROUP BY U.id, P.name
|
||||||
|
|
||||||
|
|
||||||
|
-- User access to site
|
||||||
|
SELECT U.id, U.login, COUNT(G.id) AS 'groups', MIN(G.rank) AS highest_rank
|
||||||
|
FROM pmgr_users U
|
||||||
|
JOIN pmgr_site_memberships M ON M.user_id = U.id
|
||||||
|
JOIN pmgr_sites S ON S.id = M.site_id
|
||||||
|
JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
WHERE S.code = 'VSS'
|
||||||
|
GROUP BY U.id
|
||||||
|
|
||||||
|
|
||||||
|
-- User Options
|
||||||
|
SELECT O.id, O.name, O.default,
|
||||||
|
GROUP_CONCAT(Uopt.value) AS 'value', COUNT(U.id) AS 'count'
|
||||||
|
FROM pmgr_options O
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.option_id = O.id
|
||||||
|
LEFT JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
WHERE U.id = 1
|
||||||
|
GROUP BY O.id
|
||||||
|
|
||||||
|
-- Group Options
|
||||||
|
SELECT O.id, O.name, O.default,
|
||||||
|
GROUP_CONCAT(Gopt.value) AS 'value', COUNT(G.id) AS 'count'
|
||||||
|
FROM pmgr_options O
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.option_id = O.id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = Gopt.group_id
|
||||||
|
WHERE G.id = 1
|
||||||
|
GROUP BY O.id
|
||||||
|
|
||||||
|
|
||||||
|
-- Site Options
|
||||||
|
SELECT O.id, O.name, O.default,
|
||||||
|
GROUP_CONCAT(Sopt.value) AS 'value', COUNT(S.id) AS 'count'
|
||||||
|
FROM pmgr_options O
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.option_id = O.id
|
||||||
|
LEFT JOIN pmgr_sites S ON S.id = Sopt.site_id
|
||||||
|
WHERE S.id = 1
|
||||||
|
GROUP BY O.id
|
||||||
|
|
||||||
|
|
||||||
|
-- Option value for member & site
|
||||||
|
SELECT O.id, O.name, O.default,
|
||||||
|
S.id AS site_id, Sopt.value,
|
||||||
|
G.id AS group_id, Gopt.value,
|
||||||
|
U.id AS user_id, Uopt.value
|
||||||
|
FROM pmgr_options O
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.option_id = O.id
|
||||||
|
LEFT JOIN pmgr_sites S ON S.id = Sopt.site_id
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.option_id = O.id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = Gopt.group_id
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.option_id = O.id
|
||||||
|
LEFT JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
WHERE O.name = 'theme'
|
||||||
|
--GROUP BY O.id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Option value for member & site
|
||||||
|
-- 1) User
|
||||||
|
SET @sid = 1;
|
||||||
|
SET @uid = 1;
|
||||||
|
SET @oid = 1;
|
||||||
|
SELECT O.name, U.id, Uopt.value
|
||||||
|
FROM pmgr_options O
|
||||||
|
JOIN pmgr_user_options Uopt ON Uopt.option_id = O.id
|
||||||
|
JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
-- JOIN pmgr_site_memberships M ON M.user_id = U.id
|
||||||
|
-- JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
-- JOIN pmgr_sites S ON S.id = M.site_id
|
||||||
|
WHERE -- S.id = @sid AND
|
||||||
|
U.id = @uid AND O.id = @oid
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 2) Group
|
||||||
|
SELECT O.name, G.rank, G.id, Gopt.value
|
||||||
|
FROM pmgr_options O
|
||||||
|
JOIN pmgr_group_options Gopt ON Gopt.option_id = O.id
|
||||||
|
JOIN pmgr_groups G ON G.id = Gopt.group_id
|
||||||
|
JOIN pmgr_site_memberships M ON M.group_id = G.id
|
||||||
|
JOIN pmgr_users U ON U.id = M.user_id
|
||||||
|
JOIN pmgr_sites S ON S.id = M.site_id
|
||||||
|
WHERE S.id = @sid AND U.id = @uid AND O.id = @oid
|
||||||
|
ORDER BY G.rank
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 3) Site
|
||||||
|
SELECT O.name, S.id, Sopt.value
|
||||||
|
FROM pmgr_options O
|
||||||
|
JOIN pmgr_site_options Sopt ON Sopt.option_id = O.id
|
||||||
|
JOIN pmgr_sites S ON S.id = Sopt.site_id
|
||||||
|
-- JOIN pmgr_site_memberships M ON M.site_id = S.id
|
||||||
|
-- JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
-- JOIN pmgr_users U ON U.id = M.user_id
|
||||||
|
WHERE S.id = @sid
|
||||||
|
-- AND U.id = @uid
|
||||||
|
AND O.id = @oid
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 3) Default
|
||||||
|
SELECT O.name, O.default AS 'value'
|
||||||
|
FROM pmgr_options O
|
||||||
|
WHERE O.id = @oid
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- User Permissions
|
||||||
|
|
||||||
|
|
||||||
|
-- Group Permissions
|
||||||
|
|
||||||
|
-- All option values, in order
|
||||||
|
SELECT O.name, V.value,
|
||||||
|
U.id AS uid, G.id AS gid, S.id as sid,
|
||||||
|
Dopt.id AS did, G.rank
|
||||||
|
FROM pmgr_option_values V
|
||||||
|
JOIN pmgr_options O ON O.id = V.option_id
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_default_options Dopt ON Dopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = Gopt.group_id
|
||||||
|
LEFT JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
LEFT JOIN pmgr_sites S ON S.id = Sopt.site_id
|
||||||
|
WHERE O.id = @oid
|
||||||
|
ORDER BY IF(U.id IS NOT NULL, 1,
|
||||||
|
IF (G.id IS NOT NULL, 2,
|
||||||
|
IF (S.id IS NOT NULL, 3, 4))) ASC,
|
||||||
|
IF (G.id IS NOT NULL, G.rank, 0) ASC
|
||||||
|
|
||||||
|
|
||||||
|
-- Option values relevant to the user and site, in order
|
||||||
|
SELECT O.name, V.value,
|
||||||
|
U.id AS uid, G.id AS gid, S.id as sid,
|
||||||
|
Dopt.id AS did, G.rank
|
||||||
|
FROM pmgr_option_values V
|
||||||
|
JOIN pmgr_options O ON O.id = V.option_id
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_default_options Dopt ON Dopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = Gopt.group_id
|
||||||
|
LEFT JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
LEFT JOIN pmgr_sites S ON S.id = Sopt.site_id
|
||||||
|
JOIN pmgr_site_memberships M ON M.user_id = U.id AND M.site_id = S.id
|
||||||
|
WHERE S.id = @sid AND U.id = @uid AND O.id = @oid
|
||||||
|
ORDER BY IF(U.id IS NOT NULL, 1,
|
||||||
|
IF (G.id IS NOT NULL, 2,
|
||||||
|
IF (S.id IS NOT NULL, 3, 4))) ASC,
|
||||||
|
IF (G.id IS NOT NULL, G.rank, 0) ASC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SET @sid = 1;
|
||||||
|
SET @uid = 1;
|
||||||
|
SET @oid = 1;
|
||||||
|
SELECT O.name, V.value,
|
||||||
|
U.id AS uid,
|
||||||
|
-- G.id AS gid,
|
||||||
|
S.id as sid,
|
||||||
|
Dopt.id AS did
|
||||||
|
-- G.rank
|
||||||
|
FROM pmgr_option_values V
|
||||||
|
JOIN pmgr_options O ON O.id = V.option_id
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.option_value_id = V.id
|
||||||
|
-- LEFT JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
-- LEFT JOIN pmgr_group_options Gopt ON Gopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_default_options Dopt ON Dopt.option_value_id = V.id
|
||||||
|
-- LEFT JOIN pmgr_groups G ON G.id = Gopt.group_id
|
||||||
|
LEFT JOIN pmgr_users U ON U.id = Uopt.user_id
|
||||||
|
LEFT JOIN pmgr_sites S ON S.id = Sopt.site_id
|
||||||
|
JOIN pmgr_site_memberships M ON M.user_id = U.id -- AND M.site_id = S.id
|
||||||
|
WHERE -- S.id = @sid AND U.id = @uid AND
|
||||||
|
O.id = @oid
|
||||||
|
ORDER BY IF(U.id IS NOT NULL, 1,
|
||||||
|
-- IF (G.id IS NOT NULL, 2,
|
||||||
|
IF (S.id IS NOT NULL, 3, 4)) -- ) ASC,
|
||||||
|
-- IF (G.id IS NOT NULL, G.rank, 0) ASC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ------------------------------------------------------------
|
||||||
|
-- ------------------------------------------------------------
|
||||||
|
-- ------------------------------------------------------------
|
||||||
|
-- Working version (without defaults)
|
||||||
|
SET @sid = 1;
|
||||||
|
SET @uid = 1;
|
||||||
|
SET @oid = 1;
|
||||||
|
SELECT O.name, O.id AS oid, V.value, V.id AS vid,
|
||||||
|
U.id AS uid,
|
||||||
|
G.id AS gid,
|
||||||
|
S.id AS sid,
|
||||||
|
-- Dopt.id AS did
|
||||||
|
G.rank
|
||||||
|
FROM pmgr_users U
|
||||||
|
JOIN pmgr_site_memberships M ON M.user_id = U.id
|
||||||
|
JOIN pmgr_sites S ON S.id = M.site_id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.user_id = U.id
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.group_id = G.id
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.site_id = S.id
|
||||||
|
LEFT JOIN pmgr_option_values V ON (V.id = Uopt.option_value_id OR
|
||||||
|
V.id = Gopt.option_value_id OR
|
||||||
|
V.id = Sopt.option_value_id)
|
||||||
|
JOIN pmgr_options O ON O.id = V.option_id
|
||||||
|
WHERE S.id = @sid AND U.id = @uid AND O.id = @oid
|
||||||
|
ORDER BY IF(U.id IS NOT NULL, 1,
|
||||||
|
IF (G.id IS NOT NULL, 2,
|
||||||
|
IF (S.id IS NOT NULL, 3, 4))) ASC,
|
||||||
|
IF (G.id IS NOT NULL, G.rank, 0) ASC
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SET @sid = 1;
|
||||||
|
SET @uid = 1;
|
||||||
|
SET @oid = 1;
|
||||||
|
SELECT O.name, O.id AS oid, V.value, V.id AS vid,
|
||||||
|
U.id AS uid,
|
||||||
|
G.id AS gid,
|
||||||
|
S.id AS sid,
|
||||||
|
-- Dopt.id AS did
|
||||||
|
G.rank
|
||||||
|
FROM pmgr_options O
|
||||||
|
LEFT JOIN pmgr_option_values V ON V.option_id = O.id
|
||||||
|
-- Now have the option and all possible values
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.option_value_id = V.id
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.option_value_id = V.id
|
||||||
|
-- Now have the user/group/site that each value applies to
|
||||||
|
LEFT JOIN pmgr_users U U ON Uopt.user_id = U.id OR Uopt.user_id IS NULL
|
||||||
|
-- Now restricted to our user
|
||||||
|
JOIN pmgr_site_memberships M ON M.user_id = U.id
|
||||||
|
JOIN pmgr_sites S ON S.id = M.site_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ON O.id = V.option_id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
LEFT JOIN pmgr_option_values V ON (V.id = Uopt.option_value_id OR
|
||||||
|
V.id = Gopt.option_value_id OR
|
||||||
|
V.id = Sopt.option_value_id)
|
||||||
|
JOIN
|
||||||
|
WHERE S.id = @sid AND U.id = @uid AND O.id = @oid
|
||||||
|
ORDER BY IF(U.id IS NOT NULL, 1,
|
||||||
|
IF (G.id IS NOT NULL, 2,
|
||||||
|
IF (S.id IS NOT NULL, 3, 4))) ASC,
|
||||||
|
IF (G.id IS NOT NULL, G.rank, 0) ASC
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SET @sid = 1;
|
||||||
|
SET @uid = 1;
|
||||||
|
SET @oid = 1;
|
||||||
|
SELECT O.name, O.id AS oid, V.value, V.id AS vid,
|
||||||
|
U.id AS uid,
|
||||||
|
G.id AS gid,
|
||||||
|
S.id AS sid,
|
||||||
|
-- Dopt.id AS did
|
||||||
|
G.rank
|
||||||
|
FROM pmgr_options O LEFT JOIN pmgr_option_values V ON V.option_id = O.id,
|
||||||
|
pmgr_users U
|
||||||
|
JOIN pmgr_site_memberships M ON M.user_id = U.id
|
||||||
|
JOIN pmgr_sites S ON S.id = M.site_id
|
||||||
|
LEFT JOIN pmgr_groups G ON G.id = M.group_id
|
||||||
|
LEFT JOIN pmgr_user_options Uopt ON Uopt.user_id = U.id
|
||||||
|
LEFT JOIN pmgr_group_options Gopt ON Gopt.group_id = G.id
|
||||||
|
LEFT JOIN pmgr_site_options Sopt ON Sopt.site_id = S.id,
|
||||||
|
WHERE S.id = @sid AND U.id = @uid AND O.id = @oid
|
||||||
|
AND (V.id = Uopt.option_value_id OR
|
||||||
|
V.id = Gopt.option_value_id OR
|
||||||
|
V.id = Sopt.option_value_id)
|
||||||
|
ORDER BY IF(U.id IS NOT NULL, 1,
|
||||||
|
IF (G.id IS NOT NULL, 2,
|
||||||
|
IF (S.id IS NOT NULL, 3, 4))) ASC,
|
||||||
|
IF (G.id IS NOT NULL, G.rank, 0) ASC
|
||||||
|
;
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ deny from all
|
|||||||
|
|
||||||
# Now allow local access
|
# Now allow local access
|
||||||
# Localhost
|
# Localhost
|
||||||
allow from 127.0.0
|
# allow from 127.0.0
|
||||||
# Local subnet
|
# Local subnet
|
||||||
allow from 192.168.7
|
# allow from 192.168.7
|
||||||
|
|
||||||
# Provide a mechanism for user authentication
|
# Provide a mechanism for user authentication
|
||||||
AuthType Digest
|
AuthType Digest
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ class AppModel extends Model {
|
|||||||
var $useNullForEmpty = true;
|
var $useNullForEmpty = true;
|
||||||
var $formatDateFields = true;
|
var $formatDateFields = true;
|
||||||
|
|
||||||
|
// Loaded related models with no association
|
||||||
|
var $knows = array();
|
||||||
|
var $app_knows = array('Option');
|
||||||
|
|
||||||
// Default Log Level, if not specified at the function level
|
// Default Log Level, if not specified at the function level
|
||||||
var $default_log_level = 5;
|
var $default_log_level = 5;
|
||||||
|
|
||||||
@@ -58,16 +62,35 @@ class AppModel extends Model {
|
|||||||
var $max_log_level;
|
var $max_log_level;
|
||||||
|
|
||||||
|
|
||||||
// REVISIT <AP>: 20090730
|
/**************************************************************************
|
||||||
// Why is this constructor crashing?
|
**************************************************************************
|
||||||
// Clearly it's in some sort of infinite
|
**************************************************************************
|
||||||
// loop, but it seems the correct way
|
* function: __construct
|
||||||
// to have a constructor call the parent...
|
*/
|
||||||
|
|
||||||
|
function __construct($id = false, $table = null, $ds = null) {
|
||||||
|
parent::__construct($id, $table, $ds);
|
||||||
|
|
||||||
|
$this->knows = array_merge($this->app_knows, $this->knows);
|
||||||
|
//$this->pr(1, array('knows' => $this->knows));
|
||||||
|
foreach ($this->knows as $alias => $modelName) {
|
||||||
|
if (is_numeric($alias)) {
|
||||||
|
$alias = $modelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't overwrite any existing alias
|
||||||
|
if (!empty($this->{$alias}) || get_class($this) == $alias)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$model = array('class' => $modelName, 'alias' => $alias);
|
||||||
|
if (PHP5) {
|
||||||
|
$this->{$alias} = ClassRegistry::init($model);
|
||||||
|
} else {
|
||||||
|
$this->{$alias} =& ClassRegistry::init($model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* function __construct() { */
|
|
||||||
/* parent::__construct(); */
|
|
||||||
/* $this->prClassLevel(5, 'Model'); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -81,7 +104,8 @@ class AppModel extends Model {
|
|||||||
$caller = array_shift($trace);
|
$caller = array_shift($trace);
|
||||||
$caller = array_shift($trace);
|
$caller = array_shift($trace);
|
||||||
if (empty($class))
|
if (empty($class))
|
||||||
$class = $caller['class'];
|
$class = get_class($this);
|
||||||
|
$this->pr(50, compact('class', 'level'));
|
||||||
$this->class_log_level[$class] = $level;
|
$this->class_log_level[$class] = $level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +114,10 @@ class AppModel extends Model {
|
|||||||
$caller = array_shift($trace);
|
$caller = array_shift($trace);
|
||||||
$caller = array_shift($trace);
|
$caller = array_shift($trace);
|
||||||
if (empty($class))
|
if (empty($class))
|
||||||
$class = $caller['class'];
|
$class = get_class($this);
|
||||||
if (empty($function))
|
if (empty($function))
|
||||||
$function = $caller['function'];
|
$function = $caller['function'];
|
||||||
|
$this->pr(50, compact('class', 'function', 'level'));
|
||||||
$this->function_log_level["{$class}-{$function}"] = $level;
|
$this->function_log_level["{$class}-{$function}"] = $level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +305,9 @@ class AppModel extends Model {
|
|||||||
if (preg_match("/^_/", $name) && !$all)
|
if (preg_match("/^_/", $name) && !$all)
|
||||||
unset($vars[$name]);
|
unset($vars[$name]);
|
||||||
}
|
}
|
||||||
pr($vars);
|
//$vars['class'] = get_class_vars(get_class($this));
|
||||||
|
|
||||||
|
$this->pr(1, $vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -480,8 +507,8 @@ class AppModel extends Model {
|
|||||||
return date('Y-m-d', strtotime($dateString));
|
return date('Y-m-d', strtotime($dateString));
|
||||||
}
|
}
|
||||||
|
|
||||||
function INTERNAL_ERROR($msg, $depth = 0) {
|
function INTERNAL_ERROR($msg, $depth = 0, $force_stop = false) {
|
||||||
INTERNAL_ERROR($msg, false, $depth+1);
|
INTERNAL_ERROR($msg, $force_stop, $depth+1);
|
||||||
echo $this->requestAction(array('controller' => 'accounts',
|
echo $this->requestAction(array('controller' => 'accounts',
|
||||||
'action' => 'render_empty'),
|
'action' => 'render_empty'),
|
||||||
array('return', 'bare' => false)
|
array('return', 'bare' => false)
|
||||||
|
|||||||
21
site/models/default_option.php
Normal file
21
site/models/default_option.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
class DefaultOption extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo =
|
||||||
|
array('OptionValue',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
function values($name = null) {
|
||||||
|
$this->prEnter(compact('name'));
|
||||||
|
|
||||||
|
$query = array();
|
||||||
|
$this->queryInit($query);
|
||||||
|
|
||||||
|
$query['link']['DefaultOption'] = array();
|
||||||
|
$query['link']['DefaultOption']['type'] = 'INNER';
|
||||||
|
$query['link']['DefaultOption']['fields'] = array();
|
||||||
|
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
site/models/group.php
Normal file
38
site/models/group.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
class Group extends AppModel {
|
||||||
|
|
||||||
|
var $hasMany =
|
||||||
|
array('GroupOption',
|
||||||
|
'Membership',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $knows =
|
||||||
|
array('User',
|
||||||
|
'Site',
|
||||||
|
);
|
||||||
|
|
||||||
|
static $current_group_ids;
|
||||||
|
function currentGroupIds() {
|
||||||
|
if (empty(self::$current_group_ids))
|
||||||
|
self::$current_group_ids = $this->groupIds();
|
||||||
|
|
||||||
|
if (empty(self::$current_group_ids))
|
||||||
|
// We must force a stop here, since this is typically
|
||||||
|
// called very early on, and so will cause a recursive
|
||||||
|
// crash as we try to render the internal error and
|
||||||
|
// again stumble on this problem.
|
||||||
|
$this->INTERNAL_ERROR('INVALID MEMBERSHIP', 0, true);
|
||||||
|
|
||||||
|
return self::$current_group_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function groupIds($user_id = null, $site_id = null) {
|
||||||
|
if (empty($user_id))
|
||||||
|
$user_id = $this->User->currentUserId();
|
||||||
|
if (empty($site_id))
|
||||||
|
$site_id = $this->Site->currentSiteId();
|
||||||
|
|
||||||
|
return $this->Membership->memberGroups($user_id, $site_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
25
site/models/group_option.php
Normal file
25
site/models/group_option.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
class GroupOption extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo =
|
||||||
|
array('Group',
|
||||||
|
'OptionValue',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
function values($ids, $name = null) {
|
||||||
|
$this->prEnter(compact('id', 'name'));
|
||||||
|
|
||||||
|
$query = array();
|
||||||
|
$this->queryInit($query);
|
||||||
|
|
||||||
|
$query['link']['GroupOption'] = array();
|
||||||
|
$query['link']['GroupOption']['fields'] = array();
|
||||||
|
$query['link']['GroupOption']['Group'] = array();
|
||||||
|
$query['link']['GroupOption']['Group']['fields'] = array();
|
||||||
|
$query['conditions'][] = array('Group.id' => $ids);
|
||||||
|
$query['order'][] = 'Group.rank';
|
||||||
|
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
site/models/membership.php
Normal file
37
site/models/membership.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
class Membership extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo =
|
||||||
|
array('User',
|
||||||
|
'Site',
|
||||||
|
'Group'
|
||||||
|
);
|
||||||
|
|
||||||
|
function memberGroups($user_id, $site_id) {
|
||||||
|
$this->prEnter(compact('user_id', 'site_id'));
|
||||||
|
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$groups = $this->find('all', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('group_id'),
|
||||||
|
'conditions' => array(array('user_id' => $user_id),
|
||||||
|
array('site_id' => $site_id)),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
if (empty($groups))
|
||||||
|
return $this->prReturn(null);
|
||||||
|
|
||||||
|
$group_ids = array();
|
||||||
|
foreach ($groups AS $group)
|
||||||
|
$group_ids[] = $group['Membership']['group_id'];
|
||||||
|
|
||||||
|
return $this->prReturn($group_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
function memberOf($user_id, $site_id) {
|
||||||
|
$groups = $this->memberGroups($user_id, $site_id);
|
||||||
|
return (!empty($groups));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
62
site/models/option.php
Normal file
62
site/models/option.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
class Option extends AppModel {
|
||||||
|
|
||||||
|
var $hasMany =
|
||||||
|
array('OptionValue',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $knows =
|
||||||
|
array('User', 'Site', 'Group');
|
||||||
|
|
||||||
|
|
||||||
|
function getAll($name) {
|
||||||
|
$this->prClassLevel(30);
|
||||||
|
/* //$this->OptionValue->prClassLevel(30); */
|
||||||
|
/* $this->Group->Membership->prClassLevel(30); */
|
||||||
|
/* $this->OptionValue->SiteOption->prClassLevel(30); */
|
||||||
|
/* $this->OptionValue->UserOption->prClassLevel(30); */
|
||||||
|
/* $this->OptionValue->GroupOption->prClassLevel(30); */
|
||||||
|
/* $this->OptionValue->DefaultOption->prClassLevel(30); */
|
||||||
|
$this->prEnter(compact('name'));
|
||||||
|
|
||||||
|
$site_id = $this->Site->currentSiteId();
|
||||||
|
$user_id = $this->User->currentUserId();
|
||||||
|
$group_ids = $this->Group->currentGroupIds();
|
||||||
|
|
||||||
|
/* $site_id = 2; */
|
||||||
|
/* $user_id = 4; */
|
||||||
|
/* $group_ids = $this->Group->groupIds($user_id, $site_id); */
|
||||||
|
|
||||||
|
$values = array();
|
||||||
|
|
||||||
|
if (!empty($site_id))
|
||||||
|
$values =
|
||||||
|
array_merge($values,
|
||||||
|
$this->OptionValue->SiteOption->values($site_id, $name));
|
||||||
|
|
||||||
|
if (!empty($user_id))
|
||||||
|
$values =
|
||||||
|
array_merge($values,
|
||||||
|
$this->OptionValue->UserOption->values($user_id, $name));
|
||||||
|
|
||||||
|
if (!empty($group_ids))
|
||||||
|
$values =
|
||||||
|
array_merge($values,
|
||||||
|
$this->OptionValue->GroupOption->values($group_ids, $name));
|
||||||
|
|
||||||
|
$values =
|
||||||
|
array_merge($values,
|
||||||
|
$this->OptionValue->DefaultOption->values($name));
|
||||||
|
|
||||||
|
return $this->prReturn($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get($name) {
|
||||||
|
$this->prEnter(compact('name'));
|
||||||
|
$values = $this->getAll($name);
|
||||||
|
if (empty($values))
|
||||||
|
return null;
|
||||||
|
return $this->prReturn($values[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
site/models/option_value.php
Normal file
35
site/models/option_value.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
class OptionValue extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo =
|
||||||
|
array('Option',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany =
|
||||||
|
array('UserOption',
|
||||||
|
'SiteOption',
|
||||||
|
'GroupOption',
|
||||||
|
'DefaultOption',
|
||||||
|
);
|
||||||
|
|
||||||
|
function values($name = null, $query = null) {
|
||||||
|
$this->prEnter(compact('name', 'query'));
|
||||||
|
$this->queryInit($query);
|
||||||
|
|
||||||
|
$query['link']['Option'] = array();
|
||||||
|
|
||||||
|
if (!empty($name)) {
|
||||||
|
$query['conditions'][] = array('Option.name' => $name);
|
||||||
|
$query['link']['Option']['fields'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$values = array();
|
||||||
|
foreach ($this->find('all', $query) AS $result)
|
||||||
|
$values[] = $result['OptionValue']['value'];
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
return $this->prReturn($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,16 +1,37 @@
|
|||||||
<?php
|
<?php
|
||||||
class Site extends AppModel {
|
class Site extends AppModel {
|
||||||
|
|
||||||
var $name = 'Site';
|
var $hasMany =
|
||||||
var $validate = array(
|
array('SiteArea',
|
||||||
'id' => array('numeric'),
|
'SiteOption',
|
||||||
'name' => array('notempty')
|
'Membership',
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
static $current_site_id;
|
||||||
'SiteArea',
|
|
||||||
'SiteOption',
|
|
||||||
);
|
|
||||||
|
|
||||||
|
function currentSiteId() {
|
||||||
|
if (!empty(self::$current_site_id))
|
||||||
|
return self::$current_site_id;
|
||||||
|
|
||||||
|
// REVISIT <AP>: 20090827
|
||||||
|
// Must get the actual site
|
||||||
|
$code = 'VSS';
|
||||||
|
|
||||||
|
$site = $this->find
|
||||||
|
('first',
|
||||||
|
array('recursive' => -1,
|
||||||
|
'conditions' => compact('code')));
|
||||||
|
|
||||||
|
if (!empty($site['Site']['id']))
|
||||||
|
self::$current_site_id = $site['Site']['id'];
|
||||||
|
else
|
||||||
|
// We must force a stop here, since this is typically
|
||||||
|
// called very early on, and so will cause a recursive
|
||||||
|
// crash as we try to render the internal error and
|
||||||
|
// again stumble on this problem.
|
||||||
|
$this->INTERNAL_ERROR('UNKNOWN SITE', 0, true);
|
||||||
|
|
||||||
|
return self::$current_site_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
24
site/models/site_option.php
Normal file
24
site/models/site_option.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
class SiteOption extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo =
|
||||||
|
array('Site',
|
||||||
|
'OptionValue',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
function values($id, $name = null) {
|
||||||
|
$this->prEnter(compact('id', 'name'));
|
||||||
|
|
||||||
|
$query = array();
|
||||||
|
$this->queryInit($query);
|
||||||
|
|
||||||
|
$query['link']['SiteOption'] = array();
|
||||||
|
$query['link']['SiteOption']['fields'] = array();
|
||||||
|
$query['link']['SiteOption']['Site'] = array();
|
||||||
|
$query['link']['SiteOption']['Site']['fields'] = array();
|
||||||
|
$query['conditions'][] = array('Site.id' => $id);
|
||||||
|
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
site/models/user.php
Normal file
37
site/models/user.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
class User extends AppModel {
|
||||||
|
|
||||||
|
var $hasMany =
|
||||||
|
array('UserOption',
|
||||||
|
'Membership',
|
||||||
|
);
|
||||||
|
|
||||||
|
static $current_user_id;
|
||||||
|
|
||||||
|
function currentUserId() {
|
||||||
|
if (!empty(self::$current_user_id))
|
||||||
|
return self::$current_user_id;
|
||||||
|
|
||||||
|
if (!empty($_SERVER['REMOTE_USER']))
|
||||||
|
$login = $_SERVER['REMOTE_USER'];
|
||||||
|
else
|
||||||
|
$login = null;
|
||||||
|
|
||||||
|
$user = $this->find
|
||||||
|
('first',
|
||||||
|
array('recursive' => -1,
|
||||||
|
'conditions' => compact('login')));
|
||||||
|
|
||||||
|
if (!empty($user['User']['id']))
|
||||||
|
self::$current_user_id = $user['User']['id'];
|
||||||
|
else
|
||||||
|
// We must force a stop here, since this is typically
|
||||||
|
// called very early on, and so will cause a recursive
|
||||||
|
// crash as we try to render the internal error and
|
||||||
|
// again stumble on this problem.
|
||||||
|
$this->INTERNAL_ERROR('UNKNOWN USER', 0, true);
|
||||||
|
|
||||||
|
return self::$current_user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
site/models/user_option.php
Normal file
24
site/models/user_option.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
class UserOption extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo =
|
||||||
|
array('User',
|
||||||
|
'OptionValue',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
function values($id, $name = null) {
|
||||||
|
$this->prEnter(compact('id', 'name'));
|
||||||
|
|
||||||
|
$query = array();
|
||||||
|
$this->queryInit($query);
|
||||||
|
|
||||||
|
$query['link']['UserOption'] = array();
|
||||||
|
$query['link']['UserOption']['fields'] = array();
|
||||||
|
$query['link']['UserOption']['User'] = array();
|
||||||
|
$query['link']['UserOption']['User']['fields'] = array();
|
||||||
|
$query['conditions'][] = array('User.id' => $id);
|
||||||
|
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user