-- Table structure for table `rsc_asc_resource_document`
--

CREATE TABLE `rsc_asc_resource_document` (
  `resource_document_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `resource_id` int(10) unsigned NOT NULL,
  `document_type_id` int(10) unsigned DEFAULT NULL,
  `link_title` varchar(500) DEFAULT NULL,
  `file_name` varchar(500) DEFAULT NULL,
  `file_path` varchar(500) DEFAULT NULL,
  `mime_type` varchar(200) DEFAULT NULL,
  `indexable` bit(1) DEFAULT NULL,
  `url` varchar(500) DEFAULT NULL,
  `compliant508` bit(1) DEFAULT NULL,
  `notes` text,
  `date_uploaded` datetime DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `active` tinyint(1) DEFAULT '0',
  `old_document_id` int(10) DEFAULT NULL,
  `delete_flag` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`resource_document_id`),
  KEY `fk_rsc_asc_resource_document_1` (`document_type_id`),
  KEY `fk_rsc_asc_resource_document_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_document_1` FOREIGN KEY (`document_type_id`) REFERENCES `rsc_lku_document_type` (`document_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_asc_resource_document_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=9313 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_program`
--

CREATE TABLE `rsc_asc_resource_program` (
  `resource_id` int(10) unsigned NOT NULL,
  `program_id` int(10) unsigned NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_id`,`program_id`),
  KEY `fk_rsc_asc_resource_program_1` (`program_id`),
  KEY `fk_rsc_asc_resource_program_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_program_1` FOREIGN KEY (`program_id`) REFERENCES `rsc_tbl_program` (`program_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_asc_resource_program_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_reporting_system`
--

CREATE TABLE `rsc_asc_resource_reporting_system` (
  `resource_id` int(10) unsigned NOT NULL,
  `system_id` int(10) unsigned NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_id`,`system_id`),
  KEY `fk_rsc_asc_resource_reporting_system_1` (`system_id`),
  KEY `fk_rsc_asc_resource_reporting_system_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_reporting_system_1` FOREIGN KEY (`system_id`) REFERENCES `rsc_lku_reporting_system` (`system_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_asc_resource_reporting_system_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_resource`
--

CREATE TABLE `rsc_asc_resource_resource` (
  `resource_id` int(10) unsigned NOT NULL,
  `related_id` int(10) unsigned NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_id`,`related_id`),
  KEY `fk_rsc_asc_resource_resource_1` (`resource_id`),
  KEY `fk_rsc_asc_resource_resource_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_resource_1` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_rsc_asc_resource_resource_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_source`
--

CREATE TABLE `rsc_asc_resource_source` (
  `resource_source_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `resource_id` int(10) unsigned NOT NULL,
  `source_id` int(10) unsigned NOT NULL,
  `source_url` varchar(500) DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_source_id`),
  KEY `fk_rsc_asc_resource_source_1` (`resource_id`),
  KEY `fk_rsc_asc_resource_source_2` (`source_id`),
  CONSTRAINT `fk_rsc_asc_resource_source_1` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_asc_resource_source_2` FOREIGN KEY (`source_id`) REFERENCES `rsc_lku_source` (`source_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=3152 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_sponsor`
--

CREATE TABLE `rsc_asc_resource_sponsor` (
  `resource_id` int(10) unsigned NOT NULL,
  `sponsor_id` int(10) unsigned NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_id`,`sponsor_id`),
  KEY `fk_rsc_asc_resource_sponsor_1` (`sponsor_id`),
  KEY `fk_rsc_asc_resource_sponsor_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_sponsor_1` FOREIGN KEY (`sponsor_id`) REFERENCES `rsc_lku_sponsor` (`sponsor_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_asc_resource_sponsor_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_topic`
--

CREATE TABLE `rsc_asc_resource_topic` (
  `resource_id` int(10) unsigned NOT NULL,
  `topic_id` int(10) unsigned NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_id`,`topic_id`),
  KEY `fk_rsc_asc_resource_topic_1` (`topic_id`),
  KEY `fk_rsc_asc_resource_topic_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_topic_1` FOREIGN KEY (`topic_id`) REFERENCES `rsc_lku_topic` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_rsc_asc_resource_topic_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_asc_resource_type`
--

CREATE TABLE `rsc_asc_resource_type` (
  `resource_id` int(10) unsigned NOT NULL,
  `type_id` int(10) unsigned NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`resource_id`,`type_id`),
  KEY `fk_rsc_asc_resource_type_1` (`type_id`),
  KEY `fk_rsc_asc_resource_type_2` (`resource_id`),
  CONSTRAINT `fk_rsc_asc_resource_type_1` FOREIGN KEY (`type_id`) REFERENCES `rsc_lku_type` (`type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_asc_resource_type_2` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_approver`
--

CREATE TABLE `rsc_lku_approver` (
  `approver_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `approver` varchar(100) NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`approver_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_author`
--

CREATE TABLE `rsc_lku_author` (
  `author_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `author` varchar(500) NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`author_id`)
) ENGINE=InnoDB AUTO_INCREMENT=376 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_category`
--

CREATE TABLE `rsc_lku_category` (
  `category_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `category_name` varchar(256) NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_ccr`
--

CREATE TABLE `rsc_lku_ccr` (
  `ccr_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ccr_name` varchar(256) NOT NULL,
  `ccr_short` varchar(100) DEFAULT NULL,
  `url` varchar(256) DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ccr_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_contact`
--

CREATE TABLE `rsc_lku_contact` (
  `contact_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `contact_name` varchar(100) NOT NULL,
  `contact_phone` varchar(20) DEFAULT NULL,
  `contact_email` varchar(256) DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`contact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=134 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_document_type`
--

CREATE TABLE `rsc_lku_document_type` (
  `document_type_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `document_type` varchar(45) NOT NULL COMMENT 'PDF, Wrod, Excel, Zip, etc ',
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`document_type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_program_category`
--

CREATE TABLE `rsc_lku_program_category` (
  `program_category_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `program_category` varchar(256) NOT NULL COMMENT 'Affordable Housing; Homelessness and HIV/AIDS Assistance; Community Development; Economic Development',
  `parent_category_id` int(10) unsigned DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`program_category_id`),
  KEY `fk_rsc_lku_program_category_1` (`parent_category_id`),
  CONSTRAINT `fk_rsc_lku_program_category_1` FOREIGN KEY (`parent_category_id`) REFERENCES `rsc_lku_program_category` (`program_category_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_program_guide`
--

CREATE TABLE `rsc_lku_program_guide` (
  `tier_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `tier_name` varchar(256) NOT NULL,
  `parent_tier_id` int(10) unsigned DEFAULT NULL,
  `program_id` int(10) unsigned DEFAULT NULL,
  `featured` bit(1) DEFAULT NULL,
  `sort_order` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`tier_id`),
  KEY `fk_rsc_lku_program_guide_2` (`program_id`),
  KEY `fk_rsc_lku_program_guide_1` (`parent_tier_id`),
  CONSTRAINT `fk_rsc_lku_program_guide_1` FOREIGN KEY (`parent_tier_id`) REFERENCES `rsc_lku_program_guide` (`tier_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_rsc_lku_program_guide_2` FOREIGN KEY (`program_id`) REFERENCES `rsc_tbl_program` (`program_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_reporting_system`
--

CREATE TABLE `rsc_lku_reporting_system` (
  `system_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `system_name` varchar(256) NOT NULL,
  `system_short` varchar(100) DEFAULT NULL,
  `url` varchar(256) DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`system_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_source`
--

CREATE TABLE `rsc_lku_source` (
  `source_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `source` varchar(45) NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`source_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_sponsor`
--

CREATE TABLE `rsc_lku_sponsor` (
  `sponsor_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sponsor` varchar(256) NOT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`sponsor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_topic`
--

CREATE TABLE `rsc_lku_topic` (
  `topic_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `topic_name` varchar(255) NOT NULL,
  `topic_short` varchar(100) DEFAULT NULL,
  `parent_topic_id` int(10) unsigned DEFAULT NULL,
  `category_id` int(10) unsigned DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`topic_id`),
  KEY `fk_rsc_lku_topic_1` (`parent_topic_id`),
  CONSTRAINT `fk_rsc_lku_topic_1` FOREIGN KEY (`parent_topic_id`) REFERENCES `rsc_lku_topic` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=341 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_lku_type`
--

CREATE TABLE `rsc_lku_type` (
  `type_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type_name` varchar(256) NOT NULL,
  `description` text,
  `url` varchar(500) DEFAULT NULL,
  `sort_order` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_tbl_program`
--

CREATE TABLE `rsc_tbl_program` (
  `program_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `program_short` varchar(100) NOT NULL,
  `program_description` text,
  `program_url` varchar(256) DEFAULT NULL,
  `parent_program_id` int(10) unsigned DEFAULT NULL,
  `display` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`program_id`),
  KEY `fk_rsc_tbl_program_idx` (`parent_program_id`),
  CONSTRAINT `fk_rsc_tbl_program` FOREIGN KEY (`parent_program_id`) REFERENCES `rsc_tbl_program` (`program_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=60 DEFAULT CHARSET=utf8;

--
-- Table structure for table `rsc_tbl_resources`
--

CREATE TABLE `rsc_tbl_resources` (
  `resource_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `date_published` date DEFAULT NULL,
  `hud_approved` bit(1) DEFAULT NULL,
  `viewcount` bigint(20) NOT NULL DEFAULT '0',
  `TContent_ID` int(10) unsigned NOT NULL,
  `ContentID` char(35) DEFAULT NULL,
  `ContentHistID` char(35) DEFAULT NULL,
  PRIMARY KEY (`resource_id`),
  KEY `fk_rsc_tbl_resources` (`TContent_ID`),
  CONSTRAINT `fk_rsc_tbl_resources` FOREIGN KEY (`TContent_ID`) REFERENCES `tcontent` (`TContent_ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5167 DEFAULT CHARSET=utf8;

--
-- Temporary table structure for view `rsc_vw_active_document`
--

/*!50001 DROP VIEW IF EXISTS `rsc_vw_active_document`*/;
/*!50001 CREATE TABLE `rsc_vw_active_document` (
  `resource_id` tinyint NOT NULL,
  `resource_document_id` tinyint NOT NULL,
  `active` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `rsc_vw_resource_types`
--

/*!50001 DROP VIEW IF EXISTS `rsc_vw_resource_types`*/;
/*!50001 CREATE TABLE `rsc_vw_resource_types` (
  `resource_id` tinyint NOT NULL,
  `type_ids` tinyint NOT NULL,
  `type_names` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `rsc_vw_resources_topics`
--

/*!50001 DROP VIEW IF EXISTS `rsc_vw_resources_topics`*/;
/*!50001 CREATE TABLE `rsc_vw_resources_topics` (
  `resourceID` tinyint NOT NULL,
  `masterNameShort` tinyint NOT NULL,
  `masterNameLong` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `rsc_vw_resourcesdata`
--

/*!50001 DROP VIEW IF EXISTS `rsc_vw_resourcesdata`*/;
/*!50001 CREATE TABLE `rsc_vw_resourcesdata` (
  `resource_id` tinyint NOT NULL,
  `program_ids` tinyint NOT NULL,
  `program_short` tinyint NOT NULL,
  `program_descriptions` tinyint NOT NULL,
  `system_ids` tinyint NOT NULL,
  `system_name` tinyint NOT NULL,
  `ccr_ids` tinyint NOT NULL,
  `ccr_name` tinyint NOT NULL,
  `topic_ids` tinyint NOT NULL,
  `topic_name` tinyint NOT NULL,
  `subtopic_ids` tinyint NOT NULL,
  `subtopic_name` tinyint NOT NULL,
  `type_ids` tinyint NOT NULL,
  `type_name` tinyint NOT NULL,
  `resourcedetailspath` tinyint NOT NULL,
  `source` tinyint NOT NULL,
  `approver` tinyint NOT NULL,
  `author` tinyint NOT NULL,
  `sponsor` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `search_vw_faqs`
--

/*!50001 DROP VIEW IF EXISTS `search_vw_faqs`*/;
/*!50001 CREATE TABLE `search_vw_faqs` (
  `pkid` tinyint NOT NULL,
  `id` tinyint NOT NULL,
  `searchDate` tinyint NOT NULL,
  `urlPath` tinyint NOT NULL,
  `description` tinyint NOT NULL,
  `contentType` tinyint NOT NULL,
  `title` tinyint NOT NULL,
  `updated_date` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `search_vw_news`
--

/*!50001 DROP VIEW IF EXISTS `search_vw_news`*/;
/*!50001 CREATE TABLE `search_vw_news` (
  `pkid` tinyint NOT NULL,
  `id` tinyint NOT NULL,
  `contentType` tinyint NOT NULL,
  `title` tinyint NOT NULL,
  `teaser` tinyint NOT NULL,
  `description` tinyint NOT NULL,
  `searchDate` tinyint NOT NULL,
  `urlPath` tinyint NOT NULL,
  `updated_date` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `search_vw_reports`
--

/*!50001 DROP VIEW IF EXISTS `search_vw_reports`*/;
/*!50001 CREATE TABLE `search_vw_reports` (
  `pkid` tinyint NOT NULL,
  `id` tinyint NOT NULL,
  `contentType` tinyint NOT NULL,
  `title` tinyint NOT NULL,
  `urlPath` tinyint NOT NULL,
  `searchDate` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `search_vw_resources`
--

/*!50001 DROP VIEW IF EXISTS `search_vw_resources`*/;
/*!50001 CREATE TABLE `search_vw_resources` (
  `pkid` tinyint NOT NULL,
  `id` tinyint NOT NULL,
  `searchDate` tinyint NOT NULL,
  `urlPath` tinyint NOT NULL,
  `description` tinyint NOT NULL,
  `contentType` tinyint NOT NULL,
  `title` tinyint NOT NULL,
  `updated_date` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `search_vw_training_classes`
--

/*!50001 DROP VIEW IF EXISTS `search_vw_training_classes`*/;
/*!50001 CREATE TABLE `search_vw_training_classes` (
  `pkid` tinyint NOT NULL,
  `id` tinyint NOT NULL,
  `contentType` tinyint NOT NULL,
  `title` tinyint NOT NULL,
  `teaser` tinyint NOT NULL,
  `description` tinyint NOT NULL,
  `searchDate` tinyint NOT NULL,
  `urlPath` tinyint NOT NULL,
  `startDate` tinyint NOT NULL,
  `endDate` tinyint NOT NULL,
  `timezone` tinyint NOT NULL,
  `trainingTypeId` tinyint NOT NULL,
  `trainingType` tinyint NOT NULL,
  `locationCity` tinyint NOT NULL,
  `locationStateAbbrev` tinyint NOT NULL,
  `location` tinyint NOT NULL,
  `isHudEvent` tinyint NOT NULL,
  `hasResources` tinyint NOT NULL,
  `hasRecording` tinyint NOT NULL,
  `meeting_updated_date` tinyint NOT NULL,
  `event_updated_date` tinyint NOT NULL,
  `resource_updated_date` tinyint NOT NULL,
  `meeting_resource_created_date` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `search_vw_training_courses`
--

/*!50001 DROP VIEW IF EXISTS `search_vw_training_courses`*/;
/*!50001 CREATE TABLE `search_vw_training_courses` (
  `pkid` tinyint NOT NULL,
  `id` tinyint NOT NULL,
  `contentType` tinyint NOT NULL,
  `title` tinyint NOT NULL,
  `teaser` tinyint NOT NULL,
  `description` tinyint NOT NULL,
  `searchDate` tinyint NOT NULL,
  `urlPath` tinyint NOT NULL,
  `startDate` tinyint NOT NULL,
  `endDate` tinyint NOT NULL,
  `timezone` tinyint NOT NULL,
  `trainingTypeId` tinyint NOT NULL,
  `trainingType` tinyint NOT NULL,
  `locationCity` tinyint NOT NULL,
  `locationStateAbbrev` tinyint NOT NULL,
  `location` tinyint NOT NULL,
  `isHudEvent` tinyint NOT NULL,
  `hasResources` tinyint NOT NULL,
  `hasRecording` tinyint NOT NULL,
  `updated_date` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Table structure for table `srv_icons`
--

CREATE TABLE `srv_icons` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `class` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_lku_question_types`
--

CREATE TABLE `srv_lku_question_types` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_lku_result_screen_types`
--

CREATE TABLE `srv_lku_result_screen_types` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_lku_routing_types`
--

CREATE TABLE `srv_lku_routing_types` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `function` varchar(255) DEFAULT NULL,
  `collectionLabel` varchar(255) DEFAULT NULL,
  `showMultiple` bit(1) DEFAULT NULL,
  `defineRouting` bit(1) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_question_options`
--

CREATE TABLE `srv_question_options` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `label` varchar(255) DEFAULT NULL,
  `stringValue` varchar(255) DEFAULT NULL,
  `integerValue` int(11) DEFAULT NULL,
  `booleanValue` bit(1) DEFAULT NULL,
  `correct` bit(1) NOT NULL DEFAULT b'0',
  `active` bit(1) NOT NULL DEFAULT b'1',
  `action` varchar(255) NOT NULL DEFAULT '0',
  `questionid` int(11) DEFAULT NULL,
  `iconid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_optionicon` (`iconid`),
  KEY `fk_optionquestion` (`questionid`),
  CONSTRAINT `fk_optionicon` FOREIGN KEY (`iconid`) REFERENCES `srv_icons` (`id`),
  CONSTRAINT `fk_optionquestion` FOREIGN KEY (`questionid`) REFERENCES `srv_questions` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=74 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_questions`
--

CREATE TABLE `srv_questions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `header` varchar(255) DEFAULT NULL,
  `question` longtext,
  `label` varchar(255) DEFAULT NULL,
  `description` longtext,
  `hint` varchar(255) DEFAULT NULL,
  `tooltip` varchar(255) DEFAULT NULL,
  `required` bit(1) NOT NULL DEFAULT b'1',
  `active` bit(1) NOT NULL DEFAULT b'1',
  `comment` bit(1) NOT NULL DEFAULT b'0',
  `remediation` varchar(255) DEFAULT NULL,
  `sortOrder` int(11) NOT NULL DEFAULT '0',
  `hasCorrectOption` bit(1) NOT NULL DEFAULT b'1',
  `correctAction` varchar(255) DEFAULT NULL,
  `incorrectAction` varchar(255) DEFAULT NULL,
  `screenid` int(11) DEFAULT NULL,
  `questiontypeid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_questionType` (`questiontypeid`),
  KEY `fk_screen` (`screenid`),
  CONSTRAINT `fk_questionType` FOREIGN KEY (`questiontypeid`) REFERENCES `srv_lku_question_types` (`id`),
  CONSTRAINT `fk_screen` FOREIGN KEY (`screenid`) REFERENCES `srv_screen_questions` (`screen_id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_responses`
--

CREATE TABLE `srv_responses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user` varchar(255) DEFAULT NULL,
  `createddate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updateddate` datetime DEFAULT NULL,
  `completeddate` datetime DEFAULT NULL,
  `disposition` bit(1) DEFAULT NULL,
  `organizationName` varchar(255) DEFAULT NULL,
  `orgtypeid` int(10) unsigned DEFAULT NULL,
  `orgid` int(10) unsigned DEFAULT NULL,
  `surveyid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_responseorgtype` (`orgtypeid`),
  KEY `fk_responsesurvey` (`surveyid`),
  KEY `fk_responseorg` (`orgid`),
  CONSTRAINT `fk_responseorg` FOREIGN KEY (`orgid`) REFERENCES `c_torganizations` (`orgid`),
  CONSTRAINT `fk_responseorgtype` FOREIGN KEY (`orgtypeid`) REFERENCES `c_torgtype` (`orgTypeID`),
  CONSTRAINT `fk_responsesurvey` FOREIGN KEY (`surveyid`) REFERENCES `srv_surveys` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_screen_questions`
--

CREATE TABLE `srv_screen_questions` (
  `screen_id` int(11) NOT NULL,
  `color` varchar(255) DEFAULT NULL,
  `surveyid` int(11) DEFAULT NULL,
  PRIMARY KEY (`screen_id`),
  KEY `fk_questionscreensurvey` (`surveyid`),
  KEY `fk_questionscreen` (`screen_id`),
  CONSTRAINT `fk_questionscreen` FOREIGN KEY (`screen_id`) REFERENCES `srv_screens` (`id`),
  CONSTRAINT `fk_questionscreensurvey` FOREIGN KEY (`surveyid`) REFERENCES `srv_surveys` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_screen_result_steps`
--

CREATE TABLE `srv_screen_result_steps` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `body` varchar(255) DEFAULT NULL,
  `resultid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_stepresults` (`resultid`),
  CONSTRAINT `fk_stepresults` FOREIGN KEY (`resultid`) REFERENCES `srv_screen_results` (`screen_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_screen_results`
--

CREATE TABLE `srv_screen_results` (
  `screen_id` int(11) NOT NULL,
  `summary` longtext,
  `body` longtext,
  `stepNote` longtext,
  `showSummary` bit(1) NOT NULL DEFAULT b'0',
  `contactHeader` varchar(255) DEFAULT NULL,
  `contactBlock` longtext,
  `resulttypeid` int(11) DEFAULT NULL,
  `surveyid` int(11) DEFAULT NULL,
  PRIMARY KEY (`screen_id`),
  KEY `fk_resultscreensurvey` (`surveyid`),
  KEY `fk_resultscreen` (`screen_id`),
  KEY `fk_resulttype` (`resulttypeid`),
  CONSTRAINT `fk_resultscreen` FOREIGN KEY (`screen_id`) REFERENCES `srv_screens` (`id`),
  CONSTRAINT `fk_resultscreensurvey` FOREIGN KEY (`surveyid`) REFERENCES `srv_surveys` (`id`),
  CONSTRAINT `fk_resulttype` FOREIGN KEY (`resulttypeid`) REFERENCES `srv_lku_result_screen_types` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_screens`
--

CREATE TABLE `srv_screens` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL,
  `active` bit(1) NOT NULL DEFAULT b'1',
  `sortOrder` int(11) DEFAULT NULL,
  `color` varchar(255) DEFAULT NULL,
  `iconid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_screenicon` (`iconid`),
  CONSTRAINT `fk_screenicon` FOREIGN KEY (`iconid`) REFERENCES `srv_icons` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_surveyaccessrules`
--

CREATE TABLE `srv_surveyaccessrules` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `startingAction` varchar(255) DEFAULT NULL,
  `surveyid` int(11) DEFAULT NULL,
  `orgtypeid` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_accessorg` (`orgtypeid`),
  KEY `fk_accesssurvey` (`surveyid`),
  CONSTRAINT `fk_accessorg` FOREIGN KEY (`orgtypeid`) REFERENCES `c_torgtype` (`orgTypeID`),
  CONSTRAINT `fk_accesssurvey` FOREIGN KEY (`surveyid`) REFERENCES `srv_surveys` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_surveyanswers`
--

CREATE TABLE `srv_surveyanswers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `value` varchar(255) DEFAULT NULL,
  `createddate` datetime DEFAULT NULL,
  `comment` longtext,
  `responseid` int(11) DEFAULT NULL,
  `questionid` int(11) DEFAULT NULL,
  `optionid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_answerOptions` (`optionid`),
  KEY `fk_answerresponse` (`responseid`),
  KEY `fk_answerquestion` (`questionid`),
  CONSTRAINT `fk_answerOptions` FOREIGN KEY (`optionid`) REFERENCES `srv_question_options` (`id`),
  CONSTRAINT `fk_answerquestion` FOREIGN KEY (`questionid`) REFERENCES `srv_questions` (`id`),
  CONSTRAINT `fk_answerresponse` FOREIGN KEY (`responseid`) REFERENCES `srv_responses` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=198 DEFAULT CHARSET=utf8;

--
-- Table structure for table `srv_surveys`
--

CREATE TABLE `srv_surveys` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `description` longtext,
  `showAlerts` bit(1) NOT NULL DEFAULT b'0',
  `showSummary` bit(1) NOT NULL DEFAULT b'0',
  `multipleQuestions` bit(1) NOT NULL DEFAULT b'0',
  `showProgressBar` bit(1) NOT NULL DEFAULT b'1',
  `progressBarPosition` bit(1) NOT NULL DEFAULT b'1',
  `routingtypeid` int(11) DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `fk_surveyroutingtype` (`routingtypeid`),
  CONSTRAINT `fk_surveyroutingtype` FOREIGN KEY (`routingtypeid`) REFERENCES `srv_lku_routing_types` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `state`
--

CREATE TABLE `state` (
  `name` char(40) NOT NULL,
  `abbrev` char(2) NOT NULL,
  `order_by` int(11) DEFAULT '0',
  `region` int(11) DEFAULT NULL,
  PRIMARY KEY (`abbrev`) USING BTREE,
  UNIQUE KEY `ux_state_name` (`name`),
  KEY `state_order_by` (`order_by`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadcampaigns`
--

CREATE TABLE `tadcampaigns` (
  `campaignID` char(35) NOT NULL DEFAULT '',
  `userID` char(35) DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `startDate` datetime DEFAULT NULL,
  `endDate` datetime DEFAULT NULL,
  `isActive` int(10) DEFAULT NULL,
  `notes` longtext,
  PRIMARY KEY (`campaignID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadcreatives`
--

CREATE TABLE `tadcreatives` (
  `creativeID` char(35) NOT NULL DEFAULT '',
  `userID` char(35) DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `creativeType` varchar(50) DEFAULT NULL,
  `fileID` varchar(35) DEFAULT NULL,
  `mediaType` varchar(50) DEFAULT NULL,
  `redirectURL` varchar(200) DEFAULT NULL,
  `altText` varchar(200) DEFAULT NULL,
  `notes` longtext,
  `isActive` int(10) DEFAULT NULL,
  `height` int(10) DEFAULT NULL,
  `width` int(10) DEFAULT NULL,
  `textBody` longtext,
  `target` varchar(10) DEFAULT NULL,
  `title` varchar(200) DEFAULT NULL,
  `linktitle` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`creativeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadipwhitelist`
--

CREATE TABLE `tadipwhitelist` (
  `IP` varchar(50) NOT NULL DEFAULT '',
  `siteID` varchar(50) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadplacementcategoryassign`
--

CREATE TABLE `tadplacementcategoryassign` (
  `placementID` char(35) NOT NULL,
  `categoryID` char(35) NOT NULL,
  PRIMARY KEY (`placementID`,`categoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadplacementdetails`
--

CREATE TABLE `tadplacementdetails` (
  `detailID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `placementID` char(35) NOT NULL DEFAULT '',
  `PlacementType` char(35) NOT NULL DEFAULT '',
  `PlacementValue` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`detailID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadplacements`
--

CREATE TABLE `tadplacements` (
  `placementID` char(35) NOT NULL DEFAULT '',
  `campaignID` char(35) DEFAULT NULL,
  `adZoneID` char(35) DEFAULT NULL,
  `creativeID` char(35) DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `startDate` datetime DEFAULT NULL,
  `endDate` datetime DEFAULT NULL,
  `costPerImp` decimal(18,5) DEFAULT NULL,
  `costPerClick` decimal(18,2) DEFAULT NULL,
  `isExclusive` int(10) DEFAULT NULL,
  `billable` decimal(18,2) DEFAULT NULL,
  `budget` int(10) DEFAULT NULL,
  `isActive` int(10) DEFAULT NULL,
  `notes` longtext,
  `hasCategories` int(11) DEFAULT NULL,
  PRIMARY KEY (`placementID`),
  KEY `IX_ad_hascategories` (`hasCategories`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadstats`
--

CREATE TABLE `tadstats` (
  `statID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `PlacementID` char(35) DEFAULT NULL,
  `StatHour` int(10) DEFAULT NULL,
  `StatDate` datetime DEFAULT NULL,
  `Type` varchar(50) DEFAULT NULL,
  `counter` int(10) DEFAULT NULL,
  PRIMARY KEY (`statID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tadzones`
--

CREATE TABLE `tadzones` (
  `adZoneID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(25) DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `creativeType` varchar(50) DEFAULT NULL,
  `notes` longtext,
  `isActive` int(10) DEFAULT NULL,
  `height` int(10) DEFAULT NULL,
  `width` int(10) DEFAULT NULL,
  PRIMARY KEY (`adZoneID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_amendment`
--

CREATE TABLE `tap_asc_amendment` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `original_wp` int(10) unsigned NOT NULL,
  `amended_wp` int(10) unsigned NOT NULL,
  `version` int(11) NOT NULL,
  `workplan_trail` varchar(500) DEFAULT NULL,
  `parent_wpid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_amendment1` (`original_wp`),
  KEY `fk_tap_asc_amendment2` (`amended_wp`),
  KEY `fk_tap_asc_amendment3` (`parent_wpid`),
  CONSTRAINT `fk_tap_asc_amendment1` FOREIGN KEY (`original_wp`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_amendment2` FOREIGN KEY (`amended_wp`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_amendment3` FOREIGN KEY (`parent_wpid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2210 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_assignment_updatenotice`
--

CREATE TABLE `tap_asc_assignment_updatenotice` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `assignmentid` int(10) unsigned NOT NULL,
  `oldtaprovider` int(10) unsigned NOT NULL,
  `newtaprovider` int(10) unsigned NOT NULL,
  `updatenoticesent` bit(1) NOT NULL DEFAULT b'0',
  `oldesttaprovider` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_document_comment`
--

CREATE TABLE `tap_asc_document_comment` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `documentid` int(10) unsigned NOT NULL,
  `commentid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_document_comment1` (`documentid`),
  KEY `fk_tap_asc_document_comment2` (`commentid`),
  CONSTRAINT `fk_tap_asc_document_comment1` FOREIGN KEY (`documentid`) REFERENCES `tap_tbl_document` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_document_comment2` FOREIGN KEY (`commentid`) REFERENCES `tap_tbl_comments` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1426 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_document_feed`
--

CREATE TABLE `tap_asc_document_feed` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `documentid` int(10) unsigned NOT NULL,
  `feedid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_document_feed1` (`documentid`),
  KEY `fk_tap_asc_document_feed2` (`feedid`),
  CONSTRAINT `fk_tap_asc_document_feed1` FOREIGN KEY (`documentid`) REFERENCES `tap_tbl_document` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_document_feed2` FOREIGN KEY (`feedid`) REFERENCES `tap_tbl_feed` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1897 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_document_request`
--

CREATE TABLE `tap_asc_document_request` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `documentid` int(10) unsigned NOT NULL,
  `requestid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_document_request1` (`documentid`),
  KEY `fk_tap_asc_document_request2` (`requestid`),
  CONSTRAINT `fk_tap_asc_document_request1` FOREIGN KEY (`documentid`) REFERENCES `tap_tbl_document` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_document_request2` FOREIGN KEY (`requestid`) REFERENCES `tap_tbl_request` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=755 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_document_workplan`
--

CREATE TABLE `tap_asc_document_workplan` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `documentid` int(10) unsigned NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  `isdeleted` bit(1) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_document_workplan1` (`documentid`),
  KEY `fk_tap_asc_document_workplan2` (`workplanid`),
  CONSTRAINT `fk_tap_asc_document_workplan1` FOREIGN KEY (`documentid`) REFERENCES `tap_tbl_document` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_document_workplan2` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1589 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_emailtext_emailroles`
--

CREATE TABLE `tap_asc_emailtext_emailroles` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `emailtextid` int(10) unsigned NOT NULL,
  `emailroleid` int(10) unsigned NOT NULL,
  `isCC` bit(1) NOT NULL DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_emailtext_emailroles_key1_idx` (`emailroleid`),
  KEY `fk_tap_asc_emailtext_emailroles_key2_idx` (`emailtextid`),
  CONSTRAINT `fk_tap_asc_emailtext_emailroles_key1` FOREIGN KEY (`emailroleid`) REFERENCES `tap_tbl_emailroles` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_emailtext_emailroles_key2` FOREIGN KEY (`emailtextid`) REFERENCES `tap_tbl_emailtext` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=165 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_feed_recipient`
--

CREATE TABLE `tap_asc_feed_recipient` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `feedid` int(10) unsigned NOT NULL,
  `recipientid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_feed_recipient1` (`feedid`),
  KEY `fk_tap_asc_feed_recipient2` (`recipientid`),
  CONSTRAINT `fk_tap_asc_feed_recipient1` FOREIGN KEY (`feedid`) REFERENCES `tap_tbl_feed` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_feed_recipient2` FOREIGN KEY (`recipientid`) REFERENCES `tap_tbl_recipient` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=60156 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_feed_task`
--

CREATE TABLE `tap_asc_feed_task` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `feedid` int(10) unsigned NOT NULL,
  `taskid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_feed_task1` (`feedid`),
  KEY `fk_tap_asc_feed_task2` (`taskid`),
  CONSTRAINT `fk_tap_asc_feed_task1` FOREIGN KEY (`feedid`) REFERENCES `tap_tbl_feed` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_feed_task2` FOREIGN KEY (`taskid`) REFERENCES `tap_workplan_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=41692 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_goals_workplan`
--

CREATE TABLE `tap_asc_goals_workplan` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `goalid` int(10) unsigned NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_goals_workplan1` (`goalid`),
  KEY `fk_tap_asc_goals_workplan2` (`workplanid`),
  CONSTRAINT `fk_tap_asc_goals_workplan1` FOREIGN KEY (`goalid`) REFERENCES `tap_tbl_goals` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_goals_workplan2` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=13751 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_grantee_state`
--

CREATE TABLE `tap_asc_grantee_state` (
  `granteeid` int(10) unsigned NOT NULL,
  `stateid` char(2) NOT NULL,
  PRIMARY KEY (`granteeid`,`stateid`),
  KEY `fk_tap_asc_grantee_state1` (`granteeid`),
  KEY `fk_tap_asc_grantee_state2` (`stateid`),
  CONSTRAINT `fk_tap_asc_grantee_state1` FOREIGN KEY (`granteeid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_grantee_state2` FOREIGN KEY (`stateid`) REFERENCES `state` (`abbrev`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_monthlystatus_document_feed`
--

CREATE TABLE `tap_asc_monthlystatus_document_feed` (
  `documentid` int(10) unsigned NOT NULL,
  `monthlystatus_feedid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`documentid`,`monthlystatus_feedid`),
  KEY `fk_tap_asc_monthlystatus_doc_feed1` (`documentid`),
  KEY `fk_tap_asc_monthlystatus_doc_feed2` (`monthlystatus_feedid`),
  CONSTRAINT `fk_tap_asc_monthlystatus_doc_feed1` FOREIGN KEY (`documentid`) REFERENCES `tap_tbl_document` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_monthlystatus_feed_recipient`
--

CREATE TABLE `tap_asc_monthlystatus_feed_recipient` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `monthlystatusid` int(10) unsigned NOT NULL,
  `monthlystatus_feedid` int(10) unsigned NOT NULL,
  `recipientname` varchar(255) NOT NULL,
  `origrecipientid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_monthlystatus_feed_recipient1` (`monthlystatus_feedid`),
  KEY `fk_tap_asc_monthlystatus_feed_recipient2` (`monthlystatusid`),
  CONSTRAINT `fk_tap_asc_monthlystatus_feed_recipient1` FOREIGN KEY (`monthlystatusid`) REFERENCES `tap_tbl_monthlystatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=69816 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_monthlystatus_task_feed`
--

CREATE TABLE `tap_asc_monthlystatus_task_feed` (
  `monthlystatus_taskid` int(10) unsigned NOT NULL,
  `monthlystatus_feedid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`monthlystatus_taskid`,`monthlystatus_feedid`),
  KEY `fk_tap_asc_monthlystatus_task_feed1` (`monthlystatus_taskid`),
  KEY `fk_tap_asc_monthlystatus_task_feed2` (`monthlystatus_feedid`),
  CONSTRAINT `fk_tap_asc_monthlystatus_task_feed1` FOREIGN KEY (`monthlystatus_taskid`) REFERENCES `tap_monthlystatus_task_history` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_monthlystatus_task_feed2` FOREIGN KEY (`monthlystatus_feedid`) REFERENCES `tap_monthlystatus_feed_history` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_oncallwp_assignment`
--

CREATE TABLE `tap_asc_oncallwp_assignment` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `assignmentid` int(10) unsigned NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  `association_completed` bit(1) NOT NULL DEFAULT b'0',
  `lastupdated` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_oncallwp_assignment1` (`assignmentid`),
  KEY `fk_tap_asc_oncallwp_assignment2` (`workplanid`),
  CONSTRAINT `fk_tap_asc_oncallwp_assignment1` FOREIGN KEY (`assignmentid`) REFERENCES `tap_tbl_assignment` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_oncallwp_assignment2` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2539 DEFAULT CHARSET=utf8 COMMENT='this table is used to store possible work plans a TA provide';

--
-- Table structure for table `tap_asc_request_topics`
--

CREATE TABLE `tap_asc_request_topics` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `requestid` int(10) unsigned NOT NULL,
  `topicid` int(10) DEFAULT NULL,
  `other_name` varchar(100) DEFAULT NULL,
  `oldtopicid` int(10) DEFAULT NULL,
  `newtopicid` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_request_topics1` (`requestid`),
  KEY `fk_tap_asc_request_topics2` (`topicid`)
) ENGINE=InnoDB AUTO_INCREMENT=12807 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_status_email`
--

CREATE TABLE `tap_asc_status_email` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `newStatusID` int(10) unsigned NOT NULL,
  `oldStatusID` int(10) unsigned DEFAULT NULL,
  `emailid` int(10) unsigned NOT NULL,
  `isHUDAuthor` bit(1) NOT NULL DEFAULT b'0',
  `isAmendment` bit(1) NOT NULL DEFAULT b'0',
  `isVersion` bit(1) NOT NULL DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `tap_asc_status_email_fk_status_idx` (`newStatusID`),
  KEY `tap_asc_status_email_fk_email_idx` (`emailid`),
  CONSTRAINT `tap_asc_status_email_fk_email` FOREIGN KEY (`emailid`) REFERENCES `tap_tbl_emailtext` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `tap_asc_status_email_fk_status` FOREIGN KEY (`newStatusID`) REFERENCES `tap_lku_status` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_taprovider_fundingsource`
--

CREATE TABLE `tap_asc_taprovider_fundingsource` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fundingsourceid` int(10) unsigned NOT NULL,
  `taproviderid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_taprovider_fundingsource1` (`fundingsourceid`),
  KEY `fk_tap_asc_taprovider_fundingsource2` (`taproviderid`),
  CONSTRAINT `fk_tap_asc_taprovider_fundingsource1` FOREIGN KEY (`fundingsourceid`) REFERENCES `tap_lku_fundingsource` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_taprovider_fundingsource2` FOREIGN KEY (`taproviderid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=273 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_task_topics`
--

CREATE TABLE `tap_asc_task_topics` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `topicid` int(10) unsigned NOT NULL,
  `taskid` int(10) unsigned NOT NULL,
  `lastupdated` datetime DEFAULT NULL,
  `updatedby` char(35) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_task_topics1` (`topicid`),
  KEY `fk_tap_asc_task_topics2` (`taskid`),
  CONSTRAINT `fk_tap_asc_task_topics1` FOREIGN KEY (`topicid`) REFERENCES `tap_lku_topics` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_task_topics2` FOREIGN KEY (`taskid`) REFERENCES `tap_workplan_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=89337 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_topic_org`
--

CREATE TABLE `tap_asc_topic_org` (
  `topicid` int(10) unsigned NOT NULL,
  `orgid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`topicid`,`orgid`),
  KEY `fk_tap_asc_topic_org1` (`orgid`),
  KEY `fk_tap_asc_topic_org2` (`topicid`),
  CONSTRAINT `fk_tap_asc_topic_org1` FOREIGN KEY (`orgid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_topic_org2` FOREIGN KEY (`topicid`) REFERENCES `tap_lku_topics` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_trips_task`
--

CREATE TABLE `tap_asc_trips_task` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `tripid` int(10) unsigned NOT NULL,
  `taskid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_trips_task1` (`tripid`),
  KEY `fk_tap_asc_trips_task2` (`taskid`),
  CONSTRAINT `fk_tap_asc_trips_task1` FOREIGN KEY (`tripid`) REFERENCES `tap_tbl_travel_trips` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_trips_task2` FOREIGN KEY (`taskid`) REFERENCES `tap_workplan_task` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=7105 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_trips_transportation`
--

CREATE TABLE `tap_asc_trips_transportation` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `tripid` int(10) unsigned NOT NULL,
  `transportationid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_trips_transportation1` (`tripid`),
  KEY `fk_tap_asc_trips_transportation2` (`transportationid`),
  CONSTRAINT `fk_tap_asc_trips_transportation1` FOREIGN KEY (`tripid`) REFERENCES `tap_tbl_travel_trips` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_trips_transportation2` FOREIGN KEY (`transportationid`) REFERENCES `tap_lku_transportationtype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=7459 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_asc_workplan_fundingsource`
--

CREATE TABLE `tap_asc_workplan_fundingsource` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fundingsourceid` int(10) unsigned NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_asc_workplan_fundingsource1` (`workplanid`),
  KEY `fk_tap_asc_workplan_fundingsource2` (`fundingsourceid`),
  CONSTRAINT `fk_tap_asc_workplan_fundingsource1` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_asc_workplan_fundingsource2` FOREIGN KEY (`fundingsourceid`) REFERENCES `tap_lku_fundingsource` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1247 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_doctype`
--

CREATE TABLE `tap_lku_doctype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `doctype` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_edittype`
--

CREATE TABLE `tap_lku_edittype` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `workplan_edittype` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_feedtype`
--

CREATE TABLE `tap_lku_feedtype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_field`
--

CREATE TABLE `tap_lku_field` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `field_name` varchar(45) DEFAULT NULL,
  `field_description` text,
  `group_name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=latin1;

--
-- Table structure for table `tap_lku_fundingsource`
--

CREATE TABLE `tap_lku_fundingsource` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `shortname` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_goaltype`
--

CREATE TABLE `tap_lku_goaltype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_membertype`
--

CREATE TABLE `tap_lku_membertype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_past_ta`
--

CREATE TABLE `tap_lku_past_ta` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `value` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_pha_designation`
--

CREATE TABLE `tap_lku_pha_designation` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_requeststatus`
--

CREATE TABLE `tap_lku_requeststatus` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `buttontext` varchar(45) DEFAULT NULL,
  `shortname` varchar(45) DEFAULT NULL,
  `sort` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_requesttime`
--

CREATE TABLE `tap_lku_requesttime` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `short_name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_requesttopics`
--

CREATE TABLE `tap_lku_requesttopics` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(300) NOT NULL,
  `active` tinyint(1) DEFAULT '1',
  `parentid` int(10) unsigned DEFAULT NULL,
  `lft` int(10) DEFAULT NULL,
  `rgt` int(10) DEFAULT NULL,
  `sortorder` int(10) DEFAULT '0',
  `oldtopic` int(10) DEFAULT NULL,
  `shortname` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tapr_lku_topics1_idx` (`parentid`),
  KEY `fk_tap_lku_requesttopics_idx1` (`lft`),
  KEY `fk_tap_lku_requesttopics_idx2` (`rgt`),
  CONSTRAINT `fk_tapr_lku_topics1` FOREIGN KEY (`parentid`) REFERENCES `tap_lku_requesttopics` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=119 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_requesttype`
--

CREATE TABLE `tap_lku_requesttype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_status`
--

CREATE TABLE `tap_lku_status` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `status` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_statusupdate`
--

CREATE TABLE `tap_lku_statusupdate` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_subject`
--

CREATE TABLE `tap_lku_subject` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `subjecttype_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_subject_1_idx` (`subjecttype_id`),
  CONSTRAINT `fk_tap_tbl_subject_1` FOREIGN KEY (`subjecttype_id`) REFERENCES `tap_lku_subjecttype` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_subjecttype`
--

CREATE TABLE `tap_lku_subjecttype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_taskstatus`
--

CREATE TABLE `tap_lku_taskstatus` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  `statusOrder` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_tatype`
--

CREATE TABLE `tap_lku_tatype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `sortorder` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_tdhe_aware`
--

CREATE TABLE `tap_lku_tdhe_aware` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `value` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_topics`
--

CREATE TABLE `tap_lku_topics` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `topictype` int(10) unsigned NOT NULL,
  `active` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `fk_tap_lku_topics1` (`topictype`),
  CONSTRAINT `fk_tap_lku_topics1` FOREIGN KEY (`topictype`) REFERENCES `tap_lku_topictype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=107 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_topictype`
--

CREATE TABLE `tap_lku_topictype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_lku_transportationtype`
--

CREATE TABLE `tap_lku_transportationtype` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_monthlystatus_feed_history`
--

CREATE TABLE `tap_monthlystatus_feed_history` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `monthlystatusid` int(10) unsigned NOT NULL,
  `feed` text,
  `feedtype` int(10) unsigned NOT NULL,
  `dateoccured` date DEFAULT NULL,
  `isResolved` bit(1) DEFAULT b'0',
  `resolution` text,
  `resolveddate` datetime DEFAULT NULL,
  `posteddate` datetime DEFAULT NULL,
  `postedby` char(35) DEFAULT NULL,
  `lastupdated` datetime DEFAULT NULL,
  `updateby` char(35) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `tap_monthlystatus_feed_history1` (`updateby`),
  KEY `tap_monthlystatus_feed_history3` (`feedtype`),
  KEY `tap_monthlystatus_feed_history4` (`monthlystatusid`),
  KEY `fk_tap_monthlystatus_feed_history2` (`postedby`),
  CONSTRAINT `fk_tap_monthlystatus_feed_history1` FOREIGN KEY (`updateby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_monthlystatus_feed_history2` FOREIGN KEY (`postedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_monthlystatus_feed_history3` FOREIGN KEY (`feedtype`) REFERENCES `tap_lku_feedtype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_monthlystatus_feed_history4` FOREIGN KEY (`monthlystatusid`) REFERENCES `tap_tbl_monthlystatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=27280 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_monthlystatus_task_history`
--

CREATE TABLE `tap_monthlystatus_task_history` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `monthlystatusid` int(10) unsigned NOT NULL,
  `taskname` varchar(500) NOT NULL,
  `description` text,
  `taskstatus` int(10) unsigned NOT NULL,
  `startdate` date NOT NULL,
  `projectedenddate` date NOT NULL,
  `estimatedbudget` varchar(45) NOT NULL,
  `createddate` datetime NOT NULL,
  `lastupdated` datetime NOT NULL,
  `origtaskid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_monthlystatus_task_history1` (`monthlystatusid`),
  KEY `fk_tap_monthlystatus_task_history2` (`taskstatus`),
  CONSTRAINT `fk_tap_monthlystatus_task_history1` FOREIGN KEY (`monthlystatusid`) REFERENCES `tap_tbl_monthlystatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_monthlystatus_task_history2` FOREIGN KEY (`taskstatus`) REFERENCES `tap_lku_taskstatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=46294 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_task_expectedoutput`
--

CREATE TABLE `tap_task_expectedoutput` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `taskid` int(10) unsigned NOT NULL,
  `description` text,
  `completiondate` datetime NOT NULL,
  `completed` bit(1) NOT NULL DEFAULT b'0',
  `completeddate` datetime DEFAULT NULL,
  `lastupdated` datetime NOT NULL,
  `comment` text,
  `documentID` int(10) unsigned DEFAULT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_task_expectedoutput1` (`taskid`),
  KEY `fk_tap_task_expectedoutput_document_idx` (`documentID`),
  CONSTRAINT `fk_tap_task_expectedoutput1` FOREIGN KEY (`taskid`) REFERENCES `tap_workplan_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_task_expectedoutput_document` FOREIGN KEY (`documentID`) REFERENCES `tap_tbl_document` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=26715 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_task_laborcategory`
--

CREATE TABLE `tap_task_laborcategory` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `laborcategory` varchar(50) NOT NULL,
  `taskid` int(10) unsigned NOT NULL,
  `hours` int(5) NOT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_task_laborcategory1` (`taskid`),
  CONSTRAINT `fk_tap_task_laborcategory1` FOREIGN KEY (`taskid`) REFERENCES `tap_workplan_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=121829 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_assignment`
--

CREATE TABLE `tap_tbl_assignment` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `requestid` int(10) unsigned NOT NULL,
  `taproviderid` int(10) unsigned NOT NULL,
  `scopedescription` text NOT NULL,
  `additionalcomments` varchar(200) DEFAULT NULL,
  `sortorder` int(11) NOT NULL,
  `assignedby` char(35) NOT NULL,
  `noticesent` bit(1) NOT NULL DEFAULT b'0',
  `sentby` char(35) DEFAULT NULL,
  `noticesent_date` datetime DEFAULT NULL,
  `datecreated` datetime NOT NULL,
  `lastupdated` datetime NOT NULL,
  `lastupdatedby` char(35) DEFAULT NULL,
  `tatype` int(10) unsigned NOT NULL,
  `createnew_wp` bit(1) NOT NULL DEFAULT b'0',
  `createnew_outreachwp` bit(1) NOT NULL DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_assignment1` (`taproviderid`),
  KEY `fk_tap_tbl_assignment2` (`requestid`),
  KEY `fk_tap_tbl_assignment4` (`assignedby`),
  KEY `fk_tap_tbl_assignment3` (`sentby`),
  KEY `fk_tap_tbl_assignment5` (`tatype`),
  KEY `fk_tap_tbl_assignment6_idx` (`lastupdatedby`),
  CONSTRAINT `fk_tap_tbl_assignment1` FOREIGN KEY (`taproviderid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_assignment2` FOREIGN KEY (`requestid`) REFERENCES `tap_tbl_request` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_assignment3` FOREIGN KEY (`sentby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_assignment4` FOREIGN KEY (`assignedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_assignment5` FOREIGN KEY (`tatype`) REFERENCES `tap_lku_tatype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_assignment6` FOREIGN KEY (`lastupdatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1146 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_comments`
--

CREATE TABLE `tap_tbl_comments` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `description` text NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  `for_status` int(10) unsigned DEFAULT NULL,
  `hasattachment` bit(1) NOT NULL DEFAULT b'0',
  `comment_type` int(10) unsigned DEFAULT NULL,
  `recommendation_type` int(10) unsigned DEFAULT NULL,
  `enteredby` char(35) NOT NULL,
  `createddate` datetime NOT NULL,
  `lastupdated` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_comments1` (`workplanid`),
  KEY `fk_tap_tbl_comments2` (`for_status`),
  KEY `fk_tap_tbl_comments3` (`enteredby`),
  CONSTRAINT `fk_tap_tbl_comments1` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_comments2` FOREIGN KEY (`for_status`) REFERENCES `tap_lku_status` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_comments3` FOREIGN KEY (`enteredby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=19733 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_document`
--

CREATE TABLE `tap_tbl_document` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `path` varchar(300) NOT NULL,
  `date_uploaded` datetime NOT NULL,
  `mime_type` varchar(200) NOT NULL,
  `uploadedby` char(45) NOT NULL,
  `doctype` int(10) unsigned NOT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_document1` (`uploadedby`),
  KEY `fk_tap_tbl_document2` (`doctype`),
  CONSTRAINT `fk_tap_tbl_document1` FOREIGN KEY (`uploadedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_document2` FOREIGN KEY (`doctype`) REFERENCES `tap_lku_doctype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=6069 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_emailroles`
--

CREATE TABLE `tap_tbl_emailroles` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role` varchar(45) NOT NULL,
  `isHUD` bit(1) NOT NULL DEFAULT b'0',
  `isTA` bit(1) NOT NULL DEFAULT b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_emailtext`
--

CREATE TABLE `tap_tbl_emailtext` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `emailType` varchar(20) DEFAULT NULL,
  `emailsubject` varchar(255) NOT NULL,
  `emailtitle` varchar(255) NOT NULL,
  `emailbody` text NOT NULL,
  `emailfooter` text,
  `emailSuccessText` varchar(90) DEFAULT NULL,
  `addressLocation` varchar(45) DEFAULT 'default',
  `addressTab` varchar(45) DEFAULT 'tabs-1',
  `commentText` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_feed`
--

CREATE TABLE `tap_tbl_feed` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `feed` text,
  `workplanid` int(10) unsigned NOT NULL,
  `feedtype` int(10) unsigned NOT NULL,
  `dateoccured` date DEFAULT NULL,
  `isResolved` bit(1) DEFAULT NULL,
  `resolution` text,
  `resolveddate` datetime DEFAULT NULL,
  `posteddate` datetime NOT NULL,
  `postedby` char(35) NOT NULL,
  `lastupdated` datetime DEFAULT NULL,
  `updatedby` char(35) DEFAULT NULL,
  `inmonthlystatus` bit(1) NOT NULL DEFAULT b'1',
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_feed1` (`feedtype`),
  KEY `fk_tap_tbl_feed2` (`postedby`),
  KEY `fk_tap_tbl_feed3` (`updatedby`),
  KEY `fk_tap_tbl_feed4` (`workplanid`),
  CONSTRAINT `fk_tap_tbl_feed1` FOREIGN KEY (`feedtype`) REFERENCES `tap_lku_feedtype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_feed2` FOREIGN KEY (`postedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_feed3` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_feed4` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=34547 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_goals`
--

CREATE TABLE `tap_tbl_goals` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `goaltype` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_goals1` (`goaltype`),
  CONSTRAINT `fk_tap_tbl_goals1` FOREIGN KEY (`goaltype`) REFERENCES `tap_lku_goaltype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_keypersonnel`
--

CREATE TABLE `tap_tbl_keypersonnel` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `title` varchar(50) DEFAULT NULL,
  `taskid` int(10) unsigned NOT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tbl_keypersonnel_1_idx` (`taskid`),
  CONSTRAINT `fk_tbl_keypersonnel_1` FOREIGN KEY (`taskid`) REFERENCES `tap_workplan_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=49713 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_monlthystatus_details`
--

CREATE TABLE `tap_tbl_monlthystatus_details` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `monthlystatusid` int(10) unsigned NOT NULL,
  `statusupdate_type` int(10) unsigned NOT NULL,
  `statusupdate` varchar(300) NOT NULL,
  `sortorder` int(11) NOT NULL,
  `entereddate` datetime NOT NULL,
  `enteredby` char(35) NOT NULL,
  `lastupdated` datetime DEFAULT NULL,
  `updatedby` char(35) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_monlthystatus_details1` (`monthlystatusid`),
  KEY `fk_tap_tbl_monlthystatus_details2` (`statusupdate_type`),
  KEY `fk_tap_tbl_monlthystatus_details3` (`enteredby`),
  KEY `fk_tap_tbl_monlthystatus_details4` (`updatedby`),
  CONSTRAINT `fk_tap_tbl_monlthystatus_details1` FOREIGN KEY (`monthlystatusid`) REFERENCES `tap_tbl_monthlystatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_monlthystatus_details2` FOREIGN KEY (`statusupdate_type`) REFERENCES `tap_lku_statusupdate` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_monlthystatus_details3` FOREIGN KEY (`enteredby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_monlthystatus_details4` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=20753 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_monthlystatus`
--

CREATE TABLE `tap_tbl_monthlystatus` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `monthyear` date NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  `hudsubmitted` bit(1) NOT NULL DEFAULT b'0',
  `createddate` datetime NOT NULL,
  `createdby` char(35) NOT NULL,
  `submitteddate` datetime DEFAULT NULL,
  `submittedby` char(35) DEFAULT NULL,
  `lastupdated` datetime DEFAULT NULL,
  `updatedby` char(35) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_monthlystatus1` (`workplanid`),
  KEY `fk_tap_tbl_monthlystatus2` (`createdby`),
  KEY `fk_tap_tbl_monthlystatus3` (`submittedby`),
  KEY `fk_tap_tbl_monthlystatus4` (`updatedby`),
  CONSTRAINT `fk_tap_tbl_monthlystatus1` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_monthlystatus2` FOREIGN KEY (`createdby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_monthlystatus3` FOREIGN KEY (`submittedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_monthlystatus4` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=11697 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_outcome`
--

CREATE TABLE `tap_tbl_outcome` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `workplanid` int(10) unsigned NOT NULL,
  `title` varchar(100) NOT NULL,
  `description` text NOT NULL,
  `createddate` datetime NOT NULL,
  `createdby` char(35) NOT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  `isdeleted` bit(1) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_outcome1` (`workplanid`),
  KEY `fk_tap_tbl_outcome2` (`createdby`),
  CONSTRAINT `fk_tap_tbl_outcome1` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_outcome2` FOREIGN KEY (`createdby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=6863 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_people`
--

CREATE TABLE `tap_tbl_people` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `workplanid` int(10) unsigned NOT NULL,
  `userid` char(35) NOT NULL,
  `membertypeid` int(10) unsigned NOT NULL,
  `lastupdated` datetime DEFAULT NULL,
  `updatedby` char(35) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_people1` (`workplanid`),
  KEY `fk_tap_tbl_people2` (`userid`),
  KEY `fk_tap_tbl_people3` (`membertypeid`),
  KEY `fk_tap_tbl_people4` (`updatedby`),
  CONSTRAINT `fk_tap_tbl_people1` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_people2` FOREIGN KEY (`userid`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_people3` FOREIGN KEY (`membertypeid`) REFERENCES `tap_lku_membertype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_people4` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=15364 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_recipient`
--

CREATE TABLE `tap_tbl_recipient` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `requestid` int(10) unsigned DEFAULT NULL,
  `workplanid` int(10) unsigned DEFAULT NULL COMMENT 'this colunm was added to include wp_recipents',
  `fieldofficeid` int(10) unsigned NOT NULL,
  `state` char(2) NOT NULL,
  `granteeid` int(10) unsigned DEFAULT NULL,
  `coc_no` char(10) DEFAULT NULL,
  `recipientTypeID` int(10) DEFAULT '4',
  `sortorder` int(11) NOT NULL,
  `createddate` datetime NOT NULL,
  `pha_designation` int(10) unsigned DEFAULT NULL,
  `tdhe_aware` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_recipient1` (`requestid`),
  KEY `fk_tap_tbl_recipient2` (`fieldofficeid`),
  KEY `fk_tap_tbl_recipient3` (`granteeid`),
  KEY `fk_tap_tbl_recipient4` (`state`),
  KEY `fk_tap_tbl_recipient5` (`workplanid`),
  KEY `fk_tap_tbl_recipient6_idx` (`coc_no`),
  KEY `fk_tap_tbl_recipient7_idx` (`pha_designation`),
  KEY `fk_tap_tbl_recipient8_idx` (`tdhe_aware`),
  CONSTRAINT `fk_tap_tbl_recipient1` FOREIGN KEY (`requestid`) REFERENCES `tap_tbl_request` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_recipient2` FOREIGN KEY (`fieldofficeid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_recipient3` FOREIGN KEY (`granteeid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_recipient4` FOREIGN KEY (`state`) REFERENCES `state` (`abbrev`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_recipient5` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_recipient6` FOREIGN KEY (`coc_no`) REFERENCES `c_tcoc` (`coc_no`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_recipient7` FOREIGN KEY (`pha_designation`) REFERENCES `tap_lku_pha_designation` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=13186 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_request`
--

CREATE TABLE `tap_tbl_request` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `requesttypeid` int(10) unsigned NOT NULL DEFAULT '1',
  `subject` varchar(250) DEFAULT NULL,
  `problem_details` longtext,
  `assistance_needed` longtext,
  `intended_result` longtext,
  `description` text,
  `statusid` int(10) unsigned NOT NULL DEFAULT '1',
  `tatype` int(10) unsigned DEFAULT NULL,
  `decisionsummary` text,
  `requestor_fname` varchar(45) NOT NULL,
  `requestor_lname` varchar(45) NOT NULL,
  `requestor_firm` int(10) NOT NULL,
  `requestor_firm_name` varchar(100) DEFAULT NULL,
  `request_timeid` int(10) unsigned DEFAULT NULL,
  `time_explanation` text,
  `reportingsystem_description` text,
  `crosscutting_description` text,
  `programmanagement_description` text,
  `created_date` datetime NOT NULL,
  `createdby` char(35) NOT NULL,
  `statusupdated` datetime DEFAULT NULL,
  `statusupdatedby` char(35) DEFAULT NULL,
  `lastupdate` datetime DEFAULT NULL,
  `updatedby` char(35) DEFAULT NULL,
  `is_system_generated` bit(1) NOT NULL DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_request1` (`tatype`),
  KEY `fk_tap_tbl_request2` (`createdby`),
  KEY `fk_tap_tbl_request3` (`statusid`),
  KEY `fk_tap_tbl_request4` (`request_timeid`),
  KEY `fk_tap_tbl_request5` (`statusupdatedby`),
  KEY `fk_tap_tbl_request6` (`updatedby`),
  CONSTRAINT `fk_tap_tbl_request1` FOREIGN KEY (`tatype`) REFERENCES `tap_lku_tatype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request2` FOREIGN KEY (`createdby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request3` FOREIGN KEY (`statusid`) REFERENCES `tap_lku_requeststatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request4` FOREIGN KEY (`request_timeid`) REFERENCES `tap_lku_requesttime` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request5` FOREIGN KEY (`statusupdatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request6` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2960 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_request_background`
--

CREATE TABLE `tap_tbl_request_background` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `requestid` int(10) unsigned NOT NULL,
  `consulted_fo` tinyint(2) DEFAULT '0',
  `consulted_fo_comments` text,
  `past_ta` tinyint(2) DEFAULT '0',
  `reviewed_hud_info` tinyint(2) DEFAULT '0',
  `reviewed_hud_info_materials` varchar(300) DEFAULT NULL,
  `received_ta_another_entity` tinyint(2) DEFAULT '0',
  `received_ta_another_entity_desc` text,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_request_background1_idx` (`requestid`),
  CONSTRAINT `fk_tap_tbl_request_background1` FOREIGN KEY (`requestid`) REFERENCES `tap_tbl_request` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=562 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_request_consulted_fo`
--

CREATE TABLE `tap_tbl_request_consulted_fo` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `backgroundid` int(10) unsigned NOT NULL,
  `fieldoffice_rep_name` varchar(150) DEFAULT NULL,
  `fieldofficeid` int(10) unsigned DEFAULT NULL,
  `consultation_date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_request_consulted_fo1_idx` (`backgroundid`),
  KEY `fk_tap_tbl_request_consulted_fo2_idx` (`fieldofficeid`),
  CONSTRAINT `fk_tap_tbl_request_consulted_fo1` FOREIGN KEY (`backgroundid`) REFERENCES `tap_tbl_request_background` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request_consulted_fo2` FOREIGN KEY (`fieldofficeid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_request_past_ta`
--

CREATE TABLE `tap_tbl_request_past_ta` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `backgroundid` int(10) unsigned NOT NULL,
  `orgname` varchar(150) DEFAULT NULL,
  `daterange` varchar(100) DEFAULT NULL,
  `ta_type_topic` text,
  `continuing_need` text,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_request_past_ta1_idx` (`backgroundid`),
  CONSTRAINT `fk_tap_tbl_request_past_ta1` FOREIGN KEY (`backgroundid`) REFERENCES `tap_tbl_request_background` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=143 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_request_poc`
--

CREATE TABLE `tap_tbl_request_poc` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `requestid` int(10) unsigned NOT NULL,
  `userID` char(35) DEFAULT NULL,
  `firstName` varchar(50) DEFAULT NULL,
  `lastName` varchar(50) DEFAULT NULL,
  `state` char(2) DEFAULT NULL,
  `title` varchar(100) DEFAULT NULL,
  `email` varchar(50) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `orgtype` varchar(100) DEFAULT NULL,
  `orgid` int(10) unsigned DEFAULT NULL,
  `orgname` varchar(255) DEFAULT NULL,
  `coc_no` char(10) DEFAULT NULL,
  `orgtypeOtherText` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_request_poc1_idx` (`orgtype`),
  KEY `fk_tap_tbl_request_poc2_idx` (`orgid`),
  KEY `fk_tap_tbl_request_poc3_idx` (`requestid`),
  KEY `fk_tap_tbl_request_poc4_idx` (`userID`),
  CONSTRAINT `fk_tap_tbl_request_poc2` FOREIGN KEY (`orgid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_request_poc3` FOREIGN KEY (`requestid`) REFERENCES `tap_tbl_request` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=562 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_request_status_history`
--

CREATE TABLE `tap_tbl_request_status_history` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `requestid` int(10) unsigned NOT NULL,
  `statusid` int(10) unsigned NOT NULL,
  `additionalcomments` text,
  `updateddate` datetime NOT NULL,
  `updatedby` char(35) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `tap_requeststatus_history1` (`requestid`),
  KEY `tap_requeststatus_history2` (`statusid`),
  KEY `tap_requeststatus_history3` (`updatedby`),
  CONSTRAINT `fk_tap_requeststatus_history1` FOREIGN KEY (`requestid`) REFERENCES `tap_tbl_request` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_requeststatus_history2` FOREIGN KEY (`statusid`) REFERENCES `tap_lku_requeststatus` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_requeststatus_history3` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4732 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_teamleads`
--

CREATE TABLE `tap_tbl_teamleads` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fname` varchar(100) DEFAULT NULL,
  `lname` varchar(100) NOT NULL,
  `title` varchar(100) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `ext` varchar(10) DEFAULT NULL,
  `email` varchar(200) NOT NULL,
  `workplan_id` int(10) unsigned NOT NULL,
  `parent_id` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_teamleads_1_idx` (`workplan_id`),
  CONSTRAINT `fk_tap_teamleads_1` FOREIGN KEY (`workplan_id`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3853 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_travel_trips`
--

CREATE TABLE `tap_tbl_travel_trips` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `num_of_people` varchar(50) NOT NULL,
  `num_of_daysperperson` varchar(50) NOT NULL,
  `trip_comments` text,
  `travel_id` int(10) unsigned NOT NULL,
  `lastupdated` datetime NOT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_trips_1_idx` (`travel_id`),
  CONSTRAINT `fk_tap_trips_1` FOREIGN KEY (`travel_id`) REFERENCES `tap_tbl_workplan_travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6076 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_version`
--

CREATE TABLE `tap_tbl_version` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `description` varchar(45) DEFAULT NULL,
  `field_id` int(10) unsigned DEFAULT NULL,
  `group_name` varchar(200) DEFAULT NULL,
  `edited_workplan_id` int(10) unsigned DEFAULT NULL,
  `latest_approved_workplan_id` int(10) unsigned DEFAULT NULL,
  `teamleads_id` int(10) unsigned DEFAULT NULL,
  `workplan_travel_id` int(10) unsigned DEFAULT NULL,
  `workplan_goals` int(10) unsigned DEFAULT NULL,
  `expected_outcomes_id` int(10) unsigned DEFAULT NULL,
  `task_id` int(10) unsigned DEFAULT NULL,
  `expected_output_id` int(10) unsigned DEFAULT NULL,
  `edited_date` datetime DEFAULT NULL,
  `edited_by` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_version_idx` (`field_id`),
  KEY `fk_tap_tbl_version1_idx` (`edited_workplan_id`),
  KEY `fk_tap_tbl_version2_idx` (`latest_approved_workplan_id`),
  KEY `fk_tap_tbl_version_2_idx` (`teamleads_id`),
  KEY `fk_tap_tbl_version_4_idx` (`workplan_travel_id`),
  KEY `fk_tap_tbl_version_5_idx` (`expected_outcomes_id`),
  KEY `fk_tap_tbl_version_6_idx` (`task_id`),
  KEY `fk_tap_tbl_version_7_idx` (`workplan_goals`),
  CONSTRAINT `fk_tap_tbl_version` FOREIGN KEY (`field_id`) REFERENCES `tap_lku_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_1` FOREIGN KEY (`edited_workplan_id`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_2` FOREIGN KEY (`latest_approved_workplan_id`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_3` FOREIGN KEY (`teamleads_id`) REFERENCES `tap_tbl_teamleads` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_4` FOREIGN KEY (`workplan_travel_id`) REFERENCES `tap_tbl_workplan_travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_5` FOREIGN KEY (`expected_outcomes_id`) REFERENCES `tap_tbl_outcome` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_6` FOREIGN KEY (`task_id`) REFERENCES `tap_workplan_task` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tap_tbl_version_7` FOREIGN KEY (`workplan_goals`) REFERENCES `tap_asc_goals_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=37967 DEFAULT CHARSET=latin1;

--
-- Table structure for table `tap_tbl_workplan`
--

CREATE TABLE `tap_tbl_workplan` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `assignmentid` int(10) unsigned DEFAULT NULL,
  `status` int(10) unsigned NOT NULL,
  `taproviderid` int(10) unsigned NOT NULL,
  `name_granteeid` int(10) unsigned DEFAULT NULL,
  `name_coc_no` char(10) DEFAULT NULL,
  `tatype` int(10) unsigned NOT NULL,
  `workplan_name` varchar(250) DEFAULT NULL,
  `periodofperformance` varchar(50) DEFAULT NULL,
  `startdate` date DEFAULT NULL,
  `enddate` date DEFAULT NULL,
  `fundingsource` int(10) DEFAULT NULL,
  `coop` varchar(50) DEFAULT NULL,
  `workplan_num` varchar(50) DEFAULT NULL,
  `taprojectscope` text,
  `isAmendment` bit(1) NOT NULL DEFAULT b'0',
  `hasAmendment` bit(1) NOT NULL DEFAULT b'0',
  `created_date` datetime NOT NULL,
  `lastupdated` datetime NOT NULL,
  `createdby` char(35) NOT NULL,
  `updatedby` char(35) DEFAULT NULL,
  `hud_submitted` bit(1) NOT NULL DEFAULT b'0',
  `submitteddate` datetime DEFAULT NULL,
  `approveddate` datetime DEFAULT NULL,
  `closeddate` datetime DEFAULT NULL,
  `workplan_summary` text COMMENT 'for workplan summary-DirectTAType',
  `subject_id` int(10) unsigned DEFAULT NULL,
  `edittype_id` int(10) DEFAULT NULL,
  `isVersion` bit(1) NOT NULL DEFAULT b'0',
  `hasVersion` bit(1) NOT NULL DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `fk_tap_tbl_workplan1` (`assignmentid`),
  KEY `fk_tap_tbl_workplan2` (`status`),
  KEY `fk_tap_tbl_workplan3` (`name_granteeid`),
  KEY `fk_tap_tbl_workplan4` (`tatype`),
  KEY `fk_tap_tbl_workplan5` (`createdby`),
  KEY `fk_tap_tbl_workplan6` (`updatedby`),
  KEY `fk_tap_tbl_workplan7` (`taproviderid`),
  KEY `fk_tap_tbl_workplan_idx` (`name_coc_no`),
  KEY `fk_tap_tbl_workplan8_idx` (`subject_id`),
  KEY `fk_tap_tbl_workplan9_idx` (`edittype_id`),
  CONSTRAINT `fk_tap_tbl_workplan` FOREIGN KEY (`name_coc_no`) REFERENCES `c_tcoc` (`coc_no`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan1` FOREIGN KEY (`assignmentid`) REFERENCES `tap_tbl_assignment` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan2` FOREIGN KEY (`status`) REFERENCES `tap_lku_status` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan3` FOREIGN KEY (`name_granteeid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan4` FOREIGN KEY (`tatype`) REFERENCES `tap_lku_tatype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan5` FOREIGN KEY (`createdby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan6` FOREIGN KEY (`updatedby`) REFERENCES `tusers` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan7` FOREIGN KEY (`taproviderid`) REFERENCES `c_torganizations` (`orgid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan8` FOREIGN KEY (`subject_id`) REFERENCES `tap_lku_subject` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_tbl_workplan9` FOREIGN KEY (`edittype_id`) REFERENCES `tap_lku_edittype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=4800 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_tbl_workplan_travel`
--

CREATE TABLE `tap_tbl_workplan_travel` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `budget` varchar(50) NOT NULL,
  `workplan_id` int(10) unsigned NOT NULL,
  `createddate` datetime NOT NULL,
  `lastupdated` datetime NOT NULL,
  `parent_travelid` int(10) unsigned DEFAULT NULL,
  `isdeleted` bit(1) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_travel_1_idx` (`workplan_id`),
  CONSTRAINT `fk_tap_travel_1` FOREIGN KEY (`workplan_id`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1482 DEFAULT CHARSET=utf8;

--
-- Temporary table structure for view `tap_vw_federal_goals_export`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_federal_goals_export`*/;
/*!50001 CREATE TABLE `tap_vw_federal_goals_export` (
  `workplanid` tinyint NOT NULL,
  `federal_goalid` tinyint NOT NULL,
  `federal_goalname` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_getcocs`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_getcocs`*/;
/*!50001 CREATE TABLE `tap_vw_getcocs` (
  `id` tinyint NOT NULL,
  `cocNoticesent_date` tinyint NOT NULL,
  `coc_nos` tinyint NOT NULL,
  `cocnames` tinyint NOT NULL,
  `cocFieldOffice` tinyint NOT NULL,
  `cocFieldOffices` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_getgrantees`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_getgrantees`*/;
/*!50001 CREATE TABLE `tap_vw_getgrantees` (
  `id` tinyint NOT NULL,
  `granteeNoticesent_date` tinyint NOT NULL,
  `grantees` tinyint NOT NULL,
  `granteenames` tinyint NOT NULL,
  `fieldOffice` tinyint NOT NULL,
  `granteFieldOffices` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_gethmis`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_gethmis`*/;
/*!50001 CREATE TABLE `tap_vw_gethmis` (
  `id` tinyint NOT NULL,
  `hmisNoticesent_date` tinyint NOT NULL,
  `hmiss` tinyint NOT NULL,
  `hmisnames` tinyint NOT NULL,
  `hmisFieldOffice` tinyint NOT NULL,
  `hmisFieldOffices` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_gettasktablesubquery`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_gettasktablesubquery`*/;
/*!50001 CREATE TABLE `tap_vw_gettasktablesubquery` (
  `taskID` tinyint NOT NULL,
  `taskname` tinyint NOT NULL,
  `task_description` tinyint NOT NULL,
  `estimatedbudget` tinyint NOT NULL,
  `taskStartDate` tinyint NOT NULL,
  `taskEndDate` tinyint NOT NULL,
  `taskPoP` tinyint NOT NULL,
  `workplanid` tinyint NOT NULL,
  `laborcategory_id` tinyint NOT NULL,
  `laborcategory` tinyint NOT NULL,
  `laborhours` tinyint NOT NULL,
  `laborinfo` tinyint NOT NULL,
  `labor` tinyint NOT NULL,
  `topicID` tinyint NOT NULL,
  `topicname` tinyint NOT NULL,
  `keypersonnel_id` tinyint NOT NULL,
  `keypersonnel_name` tinyint NOT NULL,
  `keypersonnel_title` tinyint NOT NULL,
  `keypersonnelinfo` tinyint NOT NULL,
  `keypersonnel` tinyint NOT NULL,
  `output_id` tinyint NOT NULL,
  `output_title` tinyint NOT NULL,
  `output_description` tinyint NOT NULL,
  `outputinfo` tinyint NOT NULL,
  `output` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_hud_goals_export`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_hud_goals_export`*/;
/*!50001 CREATE TABLE `tap_vw_hud_goals_export` (
  `workplanid` tinyint NOT NULL,
  `hud_goalid` tinyint NOT NULL,
  `hud_goalname` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_outcomes_export`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_outcomes_export`*/;
/*!50001 CREATE TABLE `tap_vw_outcomes_export` (
  `workplanid` tinyint NOT NULL,
  `outcome_id` tinyint NOT NULL,
  `outcome_info` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_recipientgrantees`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_recipientgrantees`*/;
/*!50001 CREATE TABLE `tap_vw_recipientgrantees` (
  `recipientid` tinyint NOT NULL,
  `recipientTypeID` tinyint NOT NULL,
  `sortorder` tinyint NOT NULL,
  `recipientTypeSort` tinyint NOT NULL,
  `granteeid` tinyint NOT NULL,
  `granteename` tinyint NOT NULL,
  `fieldOffice` tinyint NOT NULL,
  `granteeFieldOffice` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanFOR`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanFOR`*/;
/*!50001 CREATE TABLE `tap_vw_workplanFOR` (
  `id` tinyint NOT NULL,
  `UserID` tinyint NOT NULL,
  `Fname` tinyint NOT NULL,
  `Lname` tinyint NOT NULL,
  `orgname` tinyint NOT NULL,
  `attributeValue` tinyint NOT NULL,
  `email` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanFORlist`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanFORlist`*/;
/*!50001 CREATE TABLE `tap_vw_workplanFORlist` (
  `id` tinyint NOT NULL,
  `Field_Office_Reviewers` tinyint NOT NULL,
  `Field_Office_Reviewers_w_Role` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanPOR`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanPOR`*/;
/*!50001 CREATE TABLE `tap_vw_workplanPOR` (
  `id` tinyint NOT NULL,
  `UserID` tinyint NOT NULL,
  `email` tinyint NOT NULL,
  `mobilephone` tinyint NOT NULL,
  `lastupdated` tinyint NOT NULL,
  `UpdatedByName` tinyint NOT NULL,
  `orgid` tinyint NOT NULL,
  `Program_Office_Reviewers_Name` tinyint NOT NULL,
  `Program_Office` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanPORlist`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanPORlist`*/;
/*!50001 CREATE TABLE `tap_vw_workplanPORlist` (
  `id` tinyint NOT NULL,
  `Program_Office_Reviewers` tinyint NOT NULL,
  `Program_Office_Reviewers_Name` tinyint NOT NULL,
  `Program_Office` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanVersionData`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanVersionData`*/;
/*!50001 CREATE TABLE `tap_vw_workplanVersionData` (
  `parent_wpid` tinyint NOT NULL,
  `versionTrail` tinyint NOT NULL,
  `latestliveid` tinyint NOT NULL,
  `versionData` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplangrantees`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplangrantees`*/;
/*!50001 CREATE TABLE `tap_vw_workplangrantees` (
  `wpID` tinyint NOT NULL,
  `recipientid` tinyint NOT NULL,
  `recipientTypeID` tinyint NOT NULL,
  `sortorder` tinyint NOT NULL,
  `recipientTypeSort` tinyint NOT NULL,
  `granteeid` tinyint NOT NULL,
  `granteestate` tinyint NOT NULL,
  `granteename` tinyint NOT NULL,
  `fieldOffice` tinyint NOT NULL,
  `granteeFieldOffice` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplangranteeslist`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplangranteeslist`*/;
/*!50001 CREATE TABLE `tap_vw_workplangranteeslist` (
  `wpid` tinyint NOT NULL,
  `granteeName` tinyint NOT NULL,
  `granteestate` tinyint NOT NULL,
  `fieldOfficeName` tinyint NOT NULL,
  `granteeFieldOfficeNames` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanhighestversion_approved`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanhighestversion_approved`*/;
/*!50001 CREATE TABLE `tap_vw_workplanhighestversion_approved` (
  `parent_wpid` tinyint NOT NULL,
  `latestversioncreated_approved` tinyint NOT NULL,
  `approveddate` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanlasteddates`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanlasteddates`*/;
/*!50001 CREATE TABLE `tap_vw_workplanlasteddates` (
  `parent_wpid` tinyint NOT NULL,
  `maxapproveddate` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanlastestliveversion`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanlastestliveversion`*/;
/*!50001 CREATE TABLE `tap_vw_workplanlastestliveversion` (
  `parent_wpid` tinyint NOT NULL,
  `latestliveid` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanorgs2`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanorgs2`*/;
/*!50001 CREATE TABLE `tap_vw_workplanorgs2` (
  `wpID` tinyint NOT NULL,
  `grantees` tinyint NOT NULL,
  `granteeNoticesent_date` tinyint NOT NULL,
  `granteenames` tinyint NOT NULL,
  `fieldOffice` tinyint NOT NULL,
  `granteFieldOffices` tinyint NOT NULL,
  `coc_nos` tinyint NOT NULL,
  `cocNoticesent_date` tinyint NOT NULL,
  `cocnames` tinyint NOT NULL,
  `cocFieldOffice` tinyint NOT NULL,
  `cocFieldOffices` tinyint NOT NULL,
  `hmisID` tinyint NOT NULL,
  `hmisNoticesent_date` tinyint NOT NULL,
  `hmisnames` tinyint NOT NULL,
  `hmisFieldOffice` tinyint NOT NULL,
  `hmisFieldOffices` tinyint NOT NULL,
  `granteename` tinyint NOT NULL,
  `fieldOfficeName` tinyint NOT NULL,
  `granteFieldOfficeNames` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplansearchgrantees`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplansearchgrantees`*/;
/*!50001 CREATE TABLE `tap_vw_workplansearchgrantees` (
  `granteeid` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanstatuslatestdates`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanstatuslatestdates`*/;
/*!50001 CREATE TABLE `tap_vw_workplanstatuslatestdates` (
  `wpid` tinyint NOT NULL,
  `submittedToGTM` tinyint NOT NULL,
  `submittedToGTR` tinyint NOT NULL,
  `submittedModificationDate` tinyint NOT NULL,
  `GTMApprovalDate` tinyint NOT NULL,
  `GTRApprovalDate` tinyint NOT NULL,
  `PutOnHoldDate` tinyint NOT NULL,
  `holdRemovedDate` tinyint NOT NULL,
  `canceledDate` tinyint NOT NULL,
  `cancelationRemovedDate` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanstatuslatestdates_getdata`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanstatuslatestdates_getdata`*/;
/*!50001 CREATE TABLE `tap_vw_workplanstatuslatestdates_getdata` (
  `wpid` tinyint NOT NULL,
  `submittedToGTM` tinyint NOT NULL,
  `submittedToGTR` tinyint NOT NULL,
  `submittedModificationDate` tinyint NOT NULL,
  `GTMApprovalDate` tinyint NOT NULL,
  `GTRApprovalDate` tinyint NOT NULL,
  `PutOnHoldDate` tinyint NOT NULL,
  `holdRemovedDate` tinyint NOT NULL,
  `canceledDate` tinyint NOT NULL,
  `cancelationRemovedDate` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `tap_vw_workplanversions`
--

/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanversions`*/;
/*!50001 CREATE TABLE `tap_vw_workplanversions` (
  `parent_wpid` tinyint NOT NULL,
  `versionTrail` tinyint NOT NULL,
  `versionData` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Table structure for table `tap_workplan_task`
--

CREATE TABLE `tap_workplan_task` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `taskname` varchar(100) NOT NULL,
  `description` text NOT NULL,
  `startdate` date NOT NULL,
  `enddate` date NOT NULL,
  `workplanid` int(10) unsigned NOT NULL,
  `estimatedbudget` varchar(45) NOT NULL,
  `createddate` datetime NOT NULL,
  `lastupdated` datetime NOT NULL,
  `task_status` int(10) unsigned NOT NULL,
  `original_taskid` int(11) DEFAULT NULL,
  `parent_taskid` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tap_workplan_task1` (`workplanid`),
  KEY `fk_tap_workplan_task2` (`task_status`),
  CONSTRAINT `fk_tap_workplan_task1` FOREIGN KEY (`workplanid`) REFERENCES `tap_tbl_workplan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_tap_workplan_task2` FOREIGN KEY (`task_status`) REFERENCES `tap_lku_taskstatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=18437 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tap_workplan_task_number`
--

CREATE TABLE `tap_workplan_task_number` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `workplan_id` int(10) unsigned NOT NULL,
  `task_id` int(10) unsigned NOT NULL,
  `task_number` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_tap_workplan_task_number_1` (`task_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20332 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tapprovalactions`
--

CREATE TABLE `tapprovalactions` (
  `parentID` char(35) DEFAULT '',
  `groupID` char(35) DEFAULT '',
  `comments` text,
  `actionType` varchar(50) DEFAULT '',
  `requestID` char(35) DEFAULT '',
  `created` datetime DEFAULT NULL,
  `actiontID` char(35) NOT NULL DEFAULT '',
  `chainID` char(35) DEFAULT '',
  `userID` char(35) DEFAULT '',
  `siteID` varchar(25) DEFAULT '',
  PRIMARY KEY (`actiontID`),
  KEY `IX_tapprovalactions_groupID` (`groupID`),
  KEY `IX_tapprovalactions_requestID` (`requestID`),
  KEY `IX_tapprovalactions_chainID` (`chainID`),
  KEY `IX_tapprovalactions_userID` (`userID`),
  KEY `IX_tapprovalactions_siteID` (`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tapprovalassignments`
--

CREATE TABLE `tapprovalassignments` (
  `siteID` varchar(25) DEFAULT '',
  `assignmentID` char(35) NOT NULL DEFAULT '',
  `exemptID` text,
  `contentID` char(35) DEFAULT '',
  `chainID` char(35) DEFAULT '',
  PRIMARY KEY (`assignmentID`),
  KEY `IX_tapprovalassignments_siteID` (`siteID`),
  KEY `IX_tapprovalassignments_contentID` (`contentID`),
  KEY `IX_tapprovalassignments_chainID` (`chainID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tapprovalchains`
--

CREATE TABLE `tapprovalchains` (
  `lastupdate` datetime DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `description` text,
  `created` datetime DEFAULT NULL,
  `siteID` varchar(25) DEFAULT '',
  `lastupdatebyid` char(35) DEFAULT NULL,
  `lastupdateby` varchar(50) DEFAULT NULL,
  `chainID` char(35) NOT NULL DEFAULT '',
  PRIMARY KEY (`chainID`),
  KEY `IX_tapprovalchains_siteID` (`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tapprovalmemberships`
--

CREATE TABLE `tapprovalmemberships` (
  `siteID` varchar(25) DEFAULT '',
  `membershipID` char(35) NOT NULL DEFAULT '',
  `groupID` char(35) DEFAULT '',
  `orderno` int(10) DEFAULT '1',
  `created` datetime DEFAULT NULL,
  `chainID` char(35) DEFAULT '',
  PRIMARY KEY (`membershipID`),
  KEY `IX_tapprovalmemberships_groupID` (`groupID`),
  KEY `IX_tapprovalmemberships_chainID` (`chainID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tapprovalrequests`
--

CREATE TABLE `tapprovalrequests` (
  `groupID` char(35) DEFAULT '',
  `requestID` char(35) NOT NULL DEFAULT '',
  `created` datetime DEFAULT NULL,
  `status` varchar(50) DEFAULT 'Pending',
  `chainID` char(35) DEFAULT '',
  `userID` char(35) DEFAULT '',
  `siteID` varchar(25) DEFAULT '',
  `contentHistID` char(35) DEFAULT '',
  PRIMARY KEY (`requestID`),
  KEY `IX_tapprovalrequests_groupID` (`groupID`),
  KEY `IX_tapprovalrequests_userID` (`userID`),
  KEY `IX_tapprovalrequests_siteID` (`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tapr_lku_topics`
--

CREATE TABLE `tapr_lku_topics` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(300) NOT NULL,
  `topictype` int(10) unsigned NOT NULL,
  `active` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `fk_tapr_tbl_topics1` (`topictype`)
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcaptcha`
--

CREATE TABLE `tcaptcha` (
  `LetterID` int(10) NOT NULL DEFAULT '0',
  `Letter` char(1) DEFAULT NULL,
  `ImageFile` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tchangesetcategoryassign`
--

CREATE TABLE `tchangesetcategoryassign` (
  `siteid` varchar(25) DEFAULT '',
  `assignmentid` char(35) NOT NULL DEFAULT '',
  `categoryid` char(35) DEFAULT '',
  `changesetid` char(35) DEFAULT '',
  PRIMARY KEY (`assignmentid`),
  KEY `IX_tchangesetcategoryassign_siteid` (`siteid`),
  KEY `IX_tchangesetcategoryassign_categoryid` (`categoryid`),
  KEY `IX_tchangesetcategoryassign_changesetid` (`changesetid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tchangesetrollback`
--

CREATE TABLE `tchangesetrollback` (
  `siteID` varchar(25) DEFAULT '',
  `changesetID` char(35) DEFAULT '',
  `changesetHistID` char(35) DEFAULT '',
  `rollbackID` char(35) NOT NULL DEFAULT '',
  `previousHistID` char(35) DEFAULT '',
  PRIMARY KEY (`rollbackID`),
  KEY `IX_tchangesetrollback_siteID` (`siteID`),
  KEY `IX_tchangesetrollback_changesetID` (`changesetID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tchangesets`
--

CREATE TABLE `tchangesets` (
  `changesetID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(25) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `description` longtext,
  `created` datetime DEFAULT NULL,
  `publishDate` datetime DEFAULT NULL,
  `published` tinyint(3) DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `lastUpdateByID` char(35) DEFAULT NULL,
  `remoteID` varchar(255) DEFAULT NULL,
  `remotePubDate` datetime DEFAULT NULL,
  `remoteSourceURL` varchar(255) DEFAULT NULL,
  `closeDate` datetime DEFAULT NULL,
  PRIMARY KEY (`changesetID`),
  KEY `IX_tchangesets_siteID` (`siteID`),
  KEY `IX_tchangesets_publishDate` (`publishDate`),
  KEY `IX_tchangesets_remoteID` (`remoteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tchangesettagassign`
--

CREATE TABLE `tchangesettagassign` (
  `siteid` varchar(25) DEFAULT '',
  `assignmentid` char(35) NOT NULL DEFAULT '',
  `changesetid` char(35) DEFAULT '',
  `tag` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`assignmentid`),
  KEY `IX_tchangesettagassign_siteid` (`siteid`),
  KEY `IX_tchangesettagassign_changesetid` (`changesetid`),
  KEY `IX_tchangesettagassign_tag` (`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclassextend`
--

CREATE TABLE `tclassextend` (
  `subTypeID` char(35) NOT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `baseTable` varchar(50) DEFAULT NULL,
  `baseKeyField` varchar(50) DEFAULT NULL,
  `dataTable` varchar(50) DEFAULT NULL,
  `type` varchar(50) DEFAULT NULL,
  `subType` varchar(50) DEFAULT NULL,
  `isActive` tinyint(3) DEFAULT NULL,
  `notes` longtext,
  `lastUpdate` datetime DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(100) DEFAULT NULL,
  `hasSummary` tinyint(4) DEFAULT '1',
  `hasBody` tinyint(4) DEFAULT '1',
  `description` longtext,
  `availableSubTypes` longtext,
  `iconclass` varchar(50) DEFAULT NULL,
  `hasAssocFile` tinyint(4) DEFAULT '1',
  `hasConfigurator` int(10) DEFAULT '1',
  PRIMARY KEY (`subTypeID`),
  KEY `IX_extend_type` (`type`,`subType`),
  KEY `IX_extend_siteID` (`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclassextendattributes`
--

CREATE TABLE `tclassextendattributes` (
  `attributeID` int(11) NOT NULL AUTO_INCREMENT,
  `extendSetID` char(35) DEFAULT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `label` text,
  `hint` text,
  `type` varchar(100) DEFAULT NULL,
  `orderno` int(11) DEFAULT NULL,
  `isActive` tinyint(3) DEFAULT NULL,
  `required` varchar(50) DEFAULT NULL,
  `validation` varchar(50) DEFAULT NULL,
  `regex` text,
  `message` text,
  `defaultValue` varchar(100) DEFAULT NULL,
  `optionList` longtext,
  `optionLabelList` longtext,
  PRIMARY KEY (`attributeID`),
  KEY `Index_2` (`extendSetID`),
  KEY `IX_extend_attr_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=291 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclassextenddata`
--

CREATE TABLE `tclassextenddata` (
  `dataID` int(11) NOT NULL AUTO_INCREMENT,
  `baseID` char(35) NOT NULL,
  `attributeID` int(11) NOT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `attributeValue` longtext,
  `remoteID` varchar(35) DEFAULT NULL,
  `datetimevalue` datetime DEFAULT NULL,
  `numericvalue` float DEFAULT NULL,
  `stringvalue` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`dataID`),
  KEY `Index_2` (`baseID`),
  KEY `Index_3` (`attributeID`),
  KEY `IX_extend_remoteID1` (`remoteID`),
  KEY `IX_extend_date1` (`datetimevalue`),
  KEY `IX_extend_numeric1` (`numericvalue`),
  KEY `IX_extend_string1` (`stringvalue`)
) ENGINE=InnoDB AUTO_INCREMENT=1068307 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclassextenddatauseractivity`
--

CREATE TABLE `tclassextenddatauseractivity` (
  `dataID` int(11) NOT NULL AUTO_INCREMENT,
  `baseID` char(35) NOT NULL,
  `attributeID` int(11) NOT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `attributeValue` longtext,
  `remoteID` varchar(35) DEFAULT NULL,
  `datetimevalue` datetime DEFAULT NULL,
  `numericvalue` float DEFAULT NULL,
  `stringvalue` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`dataID`),
  KEY `Index_2` (`baseID`),
  KEY `Index_3` (`attributeID`),
  KEY `IX_extend_remote2` (`remoteID`),
  KEY `IX_extend_date2` (`datetimevalue`),
  KEY `IX_extend_numeric2` (`numericvalue`),
  KEY `IX_extend_string2` (`stringvalue`)
) ENGINE=InnoDB AUTO_INCREMENT=2812384 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclassextendrcsets`
--

CREATE TABLE `tclassextendrcsets` (
  `subTypeID` varchar(35) DEFAULT '',
  `name` varchar(50) NOT NULL DEFAULT '',
  `siteID` varchar(25) DEFAULT '',
  `relatedContentSetID` char(35) NOT NULL DEFAULT '',
  `orderNo` int(10) DEFAULT NULL,
  `availableSubTypes` text,
  PRIMARY KEY (`relatedContentSetID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclassextendsets`
--

CREATE TABLE `tclassextendsets` (
  `extendSetID` char(35) NOT NULL,
  `subTypeID` char(35) DEFAULT NULL,
  `categoryID` longtext,
  `siteID` varchar(25) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `orderno` int(11) DEFAULT NULL,
  `isActive` tinyint(3) DEFAULT NULL,
  `container` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`extendSetID`),
  KEY `Index_2` (`subTypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclustercommands`
--

CREATE TABLE `tclustercommands` (
  `commandID` char(35) NOT NULL DEFAULT '',
  `instanceID` char(35) DEFAULT NULL,
  `command` longtext,
  `created` datetime DEFAULT NULL,
  PRIMARY KEY (`commandID`),
  KEY `IX_tclustercommands_instanceID` (`instanceID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tclusterpeers`
--

CREATE TABLE `tclusterpeers` (
  `instanceID` char(35) NOT NULL DEFAULT '',
  PRIMARY KEY (`instanceID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontent`
--

CREATE TABLE `tcontent` (
  `TContent_ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `SiteID` varchar(25) DEFAULT NULL,
  `ModuleID` char(35) DEFAULT NULL,
  `ParentID` char(35) DEFAULT NULL,
  `ContentID` char(35) DEFAULT NULL,
  `ContentHistID` char(35) DEFAULT NULL,
  `RemoteID` varchar(255) DEFAULT NULL,
  `remoteurl` text,
  `RemotePubDate` varchar(50) DEFAULT NULL,
  `remotesourceurl` text,
  `remotesource` text,
  `Credits` varchar(255) DEFAULT NULL,
  `FileID` char(35) DEFAULT NULL,
  `Template` varchar(50) DEFAULT NULL,
  `Type` varchar(25) DEFAULT NULL,
  `subType` varchar(25) DEFAULT NULL,
  `Active` tinyint(3) DEFAULT '0',
  `OrderNo` int(10) DEFAULT NULL,
  `Title` varchar(255) DEFAULT NULL,
  `MenuTitle` varchar(255) DEFAULT NULL,
  `Summary` longtext,
  `Filename` varchar(255) DEFAULT NULL,
  `metadesc` text,
  `metakeywords` text,
  `Body` longtext,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `lastUpdateByID` varchar(50) DEFAULT NULL,
  `DisplayStart` datetime DEFAULT NULL,
  `DisplayStop` datetime DEFAULT NULL,
  `Display` tinyint(3) DEFAULT NULL,
  `Approved` tinyint(3) DEFAULT NULL,
  `IsNav` tinyint(3) DEFAULT NULL,
  `Restricted` tinyint(3) DEFAULT NULL,
  `restrictgroups` text,
  `Target` varchar(50) DEFAULT NULL,
  `targetparams` text,
  `responseChart` tinyint(3) DEFAULT NULL,
  `responseMessage` longtext,
  `responsesendto` text,
  `responsedisplayfields` text,
  `moduleassign` text,
  `displayTitle` tinyint(3) DEFAULT NULL,
  `notes` text,
  `inheritObjects` varchar(25) DEFAULT NULL,
  `isFeature` tinyint(3) DEFAULT NULL,
  `ReleaseDate` datetime DEFAULT NULL,
  `IsLocked` tinyint(3) DEFAULT NULL,
  `nextN` int(10) DEFAULT NULL,
  `sortBy` varchar(50) DEFAULT NULL,
  `sortDirection` varchar(50) DEFAULT NULL,
  `featureStart` datetime DEFAULT NULL,
  `featureStop` datetime DEFAULT NULL,
  `forceSSL` tinyint(3) NOT NULL DEFAULT '0',
  `audience` text,
  `keypoints` text,
  `searchExclude` tinyint(3) DEFAULT NULL,
  `path` text,
  `tags` text,
  `doCache` tinyint(3) DEFAULT NULL,
  `urltitle` varchar(255) DEFAULT NULL,
  `htmltitle` text,
  `created` datetime DEFAULT NULL,
  `mobileExclude` tinyint(3) DEFAULT NULL,
  `changesetID` char(35) DEFAULT NULL,
  `imageSize` varchar(50) DEFAULT NULL,
  `imageHeight` varchar(15) DEFAULT NULL,
  `imageWidth` varchar(15) DEFAULT NULL,
  `childTemplate` varchar(50) DEFAULT NULL,
  `majorVersion` int(11) DEFAULT NULL,
  `minorVersion` int(11) DEFAULT NULL,
  `expires` datetime DEFAULT NULL,
  `displayInterval` varchar(20) DEFAULT NULL,
  `sourceID` char(35) DEFAULT NULL,
  PRIMARY KEY (`TContent_ID`),
  KEY `IX_TContent` (`ContentID`),
  KEY `IX_TContent_1` (`ContentHistID`),
  KEY `IX_TContent_2` (`SiteID`),
  KEY `IX_TContent_3` (`ParentID`),
  KEY `IX_TContent_4` (`RemoteID`),
  KEY `IX_TContent_5` (`ModuleID`),
  KEY `IX_tcontent_mobileExclude` (`mobileExclude`),
  KEY `IX_tcontent_changesetID` (`changesetID`),
  KEY `IX_tcontent_urltitle` (`urltitle`),
  KEY `IX_tcontent_displaystart` (`DisplayStart`),
  KEY `IX_tcontent_displaystop` (`DisplayStop`),
  KEY `IX_tcontent_approved` (`Approved`),
  KEY `IX_tcontent_active` (`Active`),
  KEY `IX_tcontent_display` (`Display`),
  KEY `IX_tcontent_isfeature` (`isFeature`),
  KEY `IX_tcontent_type` (`Type`),
  KEY `IX_tcontent_filename` (`Filename`),
  KEY `IX_tcontent_title` (`Title`),
  KEY `IX_tcontent_subtype` (`subType`),
  KEY `IX_tcontent_isnav` (`IsNav`)
) ENGINE=InnoDB AUTO_INCREMENT=94512 DEFAULT CHARSET=utf8;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`mysite_cms`@`%`*/ /*!50003 TRIGGER tcontent_delete
AFTER DELETE ON tcontent
FOR EACH ROW 
BEGIN 
	/*log the ID only if the active version no longer exists */ 
	IF NOT EXISTS (select contentid from tcontent where active = 1 and display = 1 and approved = 1 and contentID = Old.contentID) THEN
		IF Old.subType in ('News','Report') THEN
			INSERT INTO delete_log(deleted_id, deleted_date, deleted_table, deleted_type)
			VALUES (Old.ContentID, now(), 'tcontent', lcase(Old.subType));
		ELSEIF Old.subType='FAQ' THEN
			/* insert the faqID that the content is associated with */
			INSERT INTO delete_log(deleted_id, deleted_date, deleted_table, deleted_type)
			SELECT f.id, now(), 'tcontent', 'faqs'
			FROM faq_tbl_faqs f
			WHERE f.ContentID = Old.ContentID;
		END IF;
	END IF;
END */;;
DELIMITER ;

--
-- Table structure for table `tcontentassignments`
--

CREATE TABLE `tcontentassignments` (
  `contentID` char(35) NOT NULL DEFAULT '',
  `contentHistID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(25) NOT NULL DEFAULT '',
  `userID` char(35) NOT NULL DEFAULT '',
  `type` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`contentID`,`contentHistID`,`siteID`,`userID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentcategories`
--

CREATE TABLE `tcontentcategories` (
  `categoryID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(25) DEFAULT NULL,
  `parentID` char(35) DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `lastUpdateBy` varchar(50) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `notes` longtext,
  `isInterestGroup` int(10) DEFAULT NULL,
  `isActive` int(10) DEFAULT NULL,
  `isOpen` int(10) DEFAULT NULL,
  `sortBy` varchar(50) DEFAULT NULL,
  `sortDirection` varchar(50) DEFAULT NULL,
  `restrictGroups` varchar(255) DEFAULT NULL,
  `path` longtext,
  `remoteID` varchar(255) DEFAULT NULL,
  `remoteSourceURL` varchar(255) DEFAULT NULL,
  `remotePubDate` datetime DEFAULT NULL,
  `urltitle` varchar(255) DEFAULT NULL,
  `filename` varchar(255) DEFAULT NULL,
  `isfeatureable` int(10) DEFAULT NULL,
  `abbreviation` varchar(255) DEFAULT NULL,
  `shortName` varchar(255) DEFAULT NULL,
  `masterURL` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`categoryID`),
  KEY `IX_TContentCategories` (`siteID`),
  KEY `IX_category_remoteID` (`remoteID`),
  KEY `IX_tcontentcategories_name` (`name`),
  KEY `IX_tcontentcategories_urltitle` (`urltitle`),
  KEY `IX_tcontentcategories_parentid` (`parentID`),
  KEY `IX_tcontentcategories_filename` (`filename`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentcategoryassign`
--

CREATE TABLE `tcontentcategoryassign` (
  `contentHistID` char(35) NOT NULL DEFAULT '',
  `categoryID` char(35) NOT NULL DEFAULT '',
  `contentID` char(35) DEFAULT NULL,
  `isFeature` int(10) DEFAULT NULL,
  `orderno` int(10) DEFAULT NULL,
  `siteID` varchar(50) DEFAULT NULL,
  `featureStart` datetime DEFAULT NULL,
  `featureStop` datetime DEFAULT NULL,
  PRIMARY KEY (`contentHistID`,`categoryID`),
  KEY `IX_tcontentcategoryassign_isfeature` (`isFeature`),
  KEY `IX_tcontentcategoryassign_featurestart` (`featureStart`),
  KEY `IX_tcontentcategoryassign_featurestop` (`featureStop`),
  KEY `IX_tcontentcategoryassign_contentID` (`contentID`),
  KEY `IX_tcontentcategoryassign_categoryID` (`categoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentcommentcommenters`
--

CREATE TABLE `tcontentcommentcommenters` (
  `name` varchar(50) DEFAULT NULL,
  `remoteID` varchar(50) DEFAULT NULL,
  `commenterID` char(35) NOT NULL DEFAULT '',
  `email` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`commenterID`),
  KEY `IX_tcontentcommentcommenters_remoteID` (`remoteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentcomments`
--

CREATE TABLE `tcontentcomments` (
  `commentid` char(35) NOT NULL DEFAULT '',
  `contentid` char(35) DEFAULT NULL,
  `contenthistid` char(35) DEFAULT NULL,
  `url` varchar(255) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `comments` longtext,
  `entered` datetime DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `siteid` varchar(25) DEFAULT NULL,
  `ip` varchar(50) DEFAULT NULL,
  `isApproved` tinyint(3) DEFAULT '0',
  `subscribe` tinyint(3) DEFAULT NULL,
  `userID` char(35) DEFAULT NULL,
  `parentID` char(35) DEFAULT NULL,
  `path` longtext,
  `remoteID` char(35) DEFAULT NULL,
  `flagCount` int(10) DEFAULT '0',
  `isSpam` int(10) DEFAULT '0',
  `isDeleted` int(10) DEFAULT '0',
  PRIMARY KEY (`commentid`),
  KEY `IX_TContentComments` (`contentid`),
  KEY `IX_tcontentcomments_parentID` (`parentID`),
  KEY `IX_tcontentcomments_remoteid` (`remoteID`),
  KEY `IX_tcontentcomments_entered` (`entered`),
  KEY `IX_tcontentcomments_userid` (`userID`),
  KEY `IX_tcontentcomments_siteid` (`siteid`),
  KEY `IX_tcontentcomments_flagCount` (`flagCount`),
  KEY `IX_tcontentcomments_isSpam` (`isSpam`),
  KEY `IX_tcontentcomments_isDeleted` (`isDeleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentdisplaytitleapprovals`
--

CREATE TABLE `tcontentdisplaytitleapprovals` (
  `contentid` char(35) NOT NULL DEFAULT '',
  `isApproved` tinyint(3) DEFAULT NULL,
  `email` varchar(150) DEFAULT NULL,
  `siteid` varchar(25) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontenteventreminders`
--

CREATE TABLE `tcontenteventreminders` (
  `contentId` char(35) NOT NULL DEFAULT '',
  `siteId` varchar(35) NOT NULL DEFAULT '',
  `email` varchar(200) NOT NULL DEFAULT '',
  `RemindDate` datetime DEFAULT NULL,
  `RemindHour` int(10) DEFAULT NULL,
  `RemindMinute` int(10) DEFAULT NULL,
  `RemindInterval` int(10) DEFAULT NULL,
  `isSent` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentfeedadvancedparams`
--

CREATE TABLE `tcontentfeedadvancedparams` (
  `paramID` char(35) NOT NULL DEFAULT '',
  `feedID` char(35) NOT NULL DEFAULT '',
  `param` decimal(18,0) DEFAULT NULL,
  `relationship` varchar(50) DEFAULT NULL,
  `field` varchar(100) DEFAULT NULL,
  `condition` varchar(50) DEFAULT NULL,
  `criteria` varchar(200) DEFAULT NULL,
  `dataType` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`paramID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentfeeditems`
--

CREATE TABLE `tcontentfeeditems` (
  `feedID` char(35) NOT NULL DEFAULT '',
  `itemID` char(35) NOT NULL DEFAULT '',
  `type` varchar(50) DEFAULT NULL,
  KEY `IX_tcontentfeeditems_feedid` (`feedID`),
  KEY `IX_tcontentfeeditems_itemid` (`itemID`),
  KEY `IX_tcontentfeeditems_type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentfeeds`
--

CREATE TABLE `tcontentfeeds` (
  `feedID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(35) DEFAULT NULL,
  `parentID` char(35) DEFAULT NULL,
  `name` varchar(250) DEFAULT NULL,
  `isActive` tinyint(3) DEFAULT NULL,
  `isPublic` tinyint(3) DEFAULT NULL,
  `isDefault` tinyint(3) DEFAULT NULL,
  `isFeaturesOnly` tinyint(3) DEFAULT NULL,
  `description` longtext,
  `maxItems` int(10) DEFAULT NULL,
  `allowHTML` tinyint(3) DEFAULT NULL,
  `lang` varchar(50) DEFAULT NULL,
  `lastUpdateBy` varchar(100) DEFAULT NULL,
  `lastUpdate` datetime DEFAULT NULL,
  `dateCreated` datetime DEFAULT NULL,
  `restricted` tinyint(3) DEFAULT NULL,
  `restrictGroups` longtext,
  `version` varchar(50) DEFAULT NULL,
  `channelLink` varchar(250) DEFAULT NULL,
  `Type` varchar(50) DEFAULT NULL,
  `sortBy` varchar(50) DEFAULT NULL,
  `sortDirection` varchar(50) DEFAULT NULL,
  `nextN` int(10) DEFAULT NULL,
  `displayName` tinyint(3) DEFAULT NULL,
  `displayRatings` tinyint(3) DEFAULT NULL,
  `displayComments` tinyint(3) DEFAULT NULL,
  `altName` varchar(250) DEFAULT NULL,
  `remoteID` varchar(255) DEFAULT NULL,
  `remoteSourceURL` varchar(255) DEFAULT NULL,
  `remotePubDate` datetime DEFAULT NULL,
  `imageSize` varchar(50) DEFAULT NULL,
  `imageHeight` varchar(15) DEFAULT NULL,
  `imageWidth` varchar(15) DEFAULT NULL,
  `displayList` longtext,
  `showNavOnly` tinyint(3) DEFAULT NULL,
  `showExcludeSearch` tinyint(3) DEFAULT NULL,
  `viewalllink` varchar(255) DEFAULT NULL,
  `viewalllabel` varchar(100) DEFAULT NULL,
  `cssclass` varchar(255) DEFAULT NULL,
  `autoimport` tinyint(4) DEFAULT '0',
  `isLocked` tinyint(4) DEFAULT '0',
  `contentpoolid` text,
  `useCategoryIntersect` int(10) DEFAULT NULL,
  PRIMARY KEY (`feedID`),
  KEY `IX_TContentFeeds` (`siteID`),
  KEY `IX_feed_remoteID` (`remoteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentfilemetadata`
--

CREATE TABLE `tcontentfilemetadata` (
  `contentid` char(35) DEFAULT '',
  `exif` text,
  `siteID` varchar(25) DEFAULT '',
  `remoteID` varchar(255) DEFAULT NULL,
  `contenthistid` char(35) DEFAULT '',
  `caption` text,
  `altText` varchar(255) DEFAULT NULL,
  `fileid` char(35) DEFAULT '',
  `remoteSourceURL` varchar(255) DEFAULT NULL,
  `remotePubDate` datetime DEFAULT NULL,
  `credits` text,
  `remoteURL` varchar(255) DEFAULT NULL,
  `metaID` char(35) NOT NULL DEFAULT '',
  `remoteSource` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`metaID`),
  KEY `IX_tcontentfilemetadata_contentid` (`contentid`),
  KEY `IX_tcontentfilemetadata_remoteID` (`remoteID`),
  KEY `IX_tcontentfilemetadata_contenthistid` (`contenthistid`),
  KEY `IX_tcontentfilemetadata_fileid` (`fileid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentfilenamearchive`
--

CREATE TABLE `tcontentfilenamearchive` (
  `siteID` varchar(25) DEFAULT '',
  `contentID` char(35) DEFAULT '',
  `filename` varchar(255) DEFAULT NULL,
  `archiveid` char(35) NOT NULL DEFAULT '',
  PRIMARY KEY (`archiveid`),
  KEY `IX_tcontentfilenamearchive_siteID` (`siteID`),
  KEY `IX_tcontentfilenamearchive_contentID` (`contentID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentobjects`
--

CREATE TABLE `tcontentobjects` (
  `ContentHistID` char(35) NOT NULL DEFAULT '',
  `ObjectID` varchar(100) NOT NULL DEFAULT '',
  `Object` varchar(50) NOT NULL DEFAULT '',
  `ContentID` char(35) DEFAULT NULL,
  `Name` varchar(255) DEFAULT NULL,
  `OrderNo` int(10) NOT NULL DEFAULT '0',
  `SiteID` varchar(25) DEFAULT NULL,
  `ColumnID` int(10) NOT NULL DEFAULT '0',
  `Params` longtext,
  PRIMARY KEY (`ContentHistID`,`ObjectID`,`Object`,`ColumnID`,`OrderNo`),
  KEY `IX_TContentObjects` (`SiteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentpublicsubmissionapprovals`
--

CREATE TABLE `tcontentpublicsubmissionapprovals` (
  `contentID` char(35) NOT NULL DEFAULT '',
  `isApproved` int(10) unsigned NOT NULL,
  `email` varchar(150) NOT NULL,
  `siteID` varchar(25) NOT NULL,
  PRIMARY KEY (`contentID`,`siteID`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentratings`
--

CREATE TABLE `tcontentratings` (
  `contentID` char(35) NOT NULL DEFAULT '',
  `userID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(35) NOT NULL DEFAULT '',
  `rate` int(10) DEFAULT NULL,
  `entered` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`contentID`,`userID`,`siteID`),
  KEY `IDX_ENTERED` (`entered`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentrelated`
--

CREATE TABLE `tcontentrelated` (
  `contentHistID` char(35) NOT NULL DEFAULT '',
  `relatedID` char(35) NOT NULL DEFAULT '',
  `contentID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(25) NOT NULL DEFAULT '',
  `relatedContentSetID` varchar(35) DEFAULT NULL,
  `orderNo` int(10) DEFAULT NULL,
  `relatedContentID` int(10) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`relatedContentID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentsourcemaps`
--

CREATE TABLE `tcontentsourcemaps` (
  `siteid` varchar(25) DEFAULT '',
  `sourceid` char(35) DEFAULT '',
  `contenthistid` char(35) DEFAULT '',
  `mapid` char(35) NOT NULL DEFAULT '',
  `created` datetime DEFAULT NULL,
  `contentid` char(35) DEFAULT '',
  PRIMARY KEY (`mapid`),
  KEY `IX_tcontentsourcemaps_siteid` (`siteid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontentstats`
--

CREATE TABLE `tcontentstats` (
  `contentID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(25) NOT NULL DEFAULT '',
  `views` int(10) unsigned NOT NULL DEFAULT '0',
  `rating` float NOT NULL DEFAULT '0',
  `totalVotes` int(10) unsigned NOT NULL DEFAULT '0',
  `upVotes` int(10) unsigned NOT NULL DEFAULT '0',
  `downVotes` int(10) unsigned NOT NULL DEFAULT '0',
  `comments` int(10) unsigned NOT NULL DEFAULT '0',
  `majorVersion` int(11) DEFAULT NULL,
  `minorVersion` int(11) DEFAULT NULL,
  `lockID` char(35) DEFAULT NULL,
  `lockType` varchar(50) DEFAULT NULL,
  `disableComments` int(10) DEFAULT '0',
  PRIMARY KEY (`contentID`,`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tcontenttags`
--

CREATE TABLE `tcontenttags` (
  `tagID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `contentID` char(35) NOT NULL,
  `contentHistID` char(35) NOT NULL,
  `siteID` varchar(25) NOT NULL,
  `tag` varchar(100) NOT NULL,
  `taggroup` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`tagID`),
  KEY `Index_2` (`contentHistID`),
  KEY `Index_3` (`siteID`),
  KEY `Index_4` (`contentID`),
  KEY `Index_5` (`tag`)
) ENGINE=InnoDB AUTO_INCREMENT=71 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tdirectories`
--

CREATE TABLE `tdirectories` (
  `dirID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(35) DEFAULT NULL,
  `subdir` varchar(255) DEFAULT NULL,
  `editfilename` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`dirID`),
  KEY `IX_tdirectories_siteID` (`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `temailreturnstats`
--

CREATE TABLE `temailreturnstats` (
  `emailID` char(35) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `url` mediumtext,
  `created` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `temails`
--

CREATE TABLE `temails` (
  `EmailID` char(35) NOT NULL DEFAULT '',
  `siteid` varchar(25) DEFAULT NULL,
  `Subject` varchar(255) DEFAULT NULL,
  `BodyText` longtext,
  `BodyHtml` longtext,
  `CreatedDate` datetime DEFAULT NULL,
  `DeliveryDate` datetime DEFAULT NULL,
  `status` tinyint(3) DEFAULT NULL,
  `GroupList` longtext,
  `LastUpdateBy` varchar(50) DEFAULT NULL,
  `LastUpdateByID` varchar(35) DEFAULT NULL,
  `NumberSent` int(10) NOT NULL DEFAULT '0',
  `ReplyTo` varchar(50) DEFAULT NULL,
  `format` varchar(50) DEFAULT NULL,
  `fromLabel` varchar(50) DEFAULT NULL,
  `isDeleted` tinyint(1) NOT NULL DEFAULT '0',
  `template` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`EmailID`),
  KEY `IX_TEmails` (`siteid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `temailstats`
--

CREATE TABLE `temailstats` (
  `EmailID` char(35) DEFAULT NULL,
  `Email` char(100) DEFAULT NULL,
  `emailOpen` int(10) NOT NULL DEFAULT '0',
  `returnClick` int(10) NOT NULL DEFAULT '0',
  `bounce` int(10) NOT NULL DEFAULT '0',
  `sent` int(10) NOT NULL DEFAULT '0',
  `Created` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tfiles`
--

CREATE TABLE `tfiles` (
  `fileID` char(35) NOT NULL DEFAULT '',
  `contentID` char(35) DEFAULT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `moduleID` char(35) DEFAULT NULL,
  `filename` varchar(200) DEFAULT NULL,
  `image` longblob,
  `imageSmall` longblob,
  `imageMedium` longblob,
  `fileSize` int(10) DEFAULT NULL,
  `contentType` varchar(100) DEFAULT NULL,
  `contentSubType` varchar(200) DEFAULT NULL,
  `fileExt` varchar(50) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `deleted` tinyint(3) DEFAULT NULL,
  `caption` text,
  `credits` varchar(255) DEFAULT NULL,
  `alttext` varchar(255) DEFAULT NULL,
  `remoteID` varchar(255) DEFAULT NULL,
  `remoteURL` varchar(255) DEFAULT NULL,
  `remotePubDate` datetime DEFAULT NULL,
  `remoteSource` varchar(255) DEFAULT NULL,
  `remoteSourceURL` varchar(255) DEFAULT NULL,
  `exif` text,
  PRIMARY KEY (`fileID`),
  KEY `IX_tfiles_siteid` (`siteID`),
  KEY `IX_tfiles_contentid` (`contentID`),
  KEY `IX_tfiles_remoteid` (`remoteID`),
  KEY `IX_tfiles_moduleid` (`moduleID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tformresponsepackets`
--

CREATE TABLE `tformresponsepackets` (
  `ResponseID` char(35) NOT NULL DEFAULT '',
  `FormID` char(35) DEFAULT NULL,
  `SiteID` varchar(25) DEFAULT NULL,
  `FieldList` longtext,
  `Data` longtext,
  `Entered` datetime DEFAULT NULL,
  PRIMARY KEY (`ResponseID`),
  KEY `IX_TFormResponsePackets` (`FormID`,`SiteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tformresponsequestions`
--

CREATE TABLE `tformresponsequestions` (
  `responseID` char(35) DEFAULT NULL,
  `formID` char(35) DEFAULT NULL,
  `formField` varchar(50) DEFAULT NULL,
  `formValue` longtext,
  `pollValue` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `timagesizes`
--

CREATE TABLE `timagesizes` (
  `sizeID` char(35) NOT NULL DEFAULT '',
  `siteID` varchar(35) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `height` varchar(10) DEFAULT NULL,
  `width` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`sizeID`),
  KEY `IX_timagesizes_siteID` (`siteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `timezone`
--

CREATE TABLE `timezone` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `value` varchar(50) NOT NULL,
  `zone` varchar(45) NOT NULL,
  `sort_order` int(10) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `value_idx` (`value`),
  KEY `name_idx` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=395 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_asc_gallery_toolkit`
--

CREATE TABLE `tk_asc_gallery_toolkit` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `gallery_id` int(10) NOT NULL,
  `toolkits_id` int(10) NOT NULL,
  `date_created` date DEFAULT NULL,
  `date_updated` date DEFAULT NULL,
  `sortorder` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `tk_asc_gallery_toolkit_1` (`gallery_id`),
  KEY `tk_asc_gallery_toolkit_2` (`toolkits_id`),
  CONSTRAINT `tk_asc_gallery_toolkit_1` FOREIGN KEY (`gallery_id`) REFERENCES `tk_tbl_gallery` (`gallery_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `tk_asc_gallery_toolkit_2` FOREIGN KEY (`toolkits_id`) REFERENCES `tk_tbl_toolkits` (`toolkits_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_asc_resource`
--

CREATE TABLE `tk_asc_resource` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `resource_id` int(10) unsigned NOT NULL,
  `toolkits_id` int(10) NOT NULL,
  `topic_id` int(10) DEFAULT NULL,
  `Display` tinyint(4) DEFAULT NULL,
  `markDelete` tinyint(4) DEFAULT NULL,
  `subtopic_id` int(10) DEFAULT NULL,
  `sortorder` int(10) DEFAULT NULL,
  `date_created` date DEFAULT NULL,
  `date_updated` date DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tk_asc_resource_1` (`toolkits_id`),
  KEY `fk_tk_asc_resource_2` (`topic_id`),
  KEY `fk_tk_asc_resource_3` (`subtopic_id`),
  KEY `fk_tk_asc_resource_4` (`resource_id`),
  CONSTRAINT `fk_tk_asc_resource_1` FOREIGN KEY (`toolkits_id`) REFERENCES `tk_tbl_toolkits` (`toolkits_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_asc_resource_2` FOREIGN KEY (`topic_id`) REFERENCES `tk_tbl_topics` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_asc_resource_3` FOREIGN KEY (`subtopic_id`) REFERENCES `tk_tbl_subtopics` (`subtopic_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_asc_resource_4` FOREIGN KEY (`resource_id`) REFERENCES `rsc_tbl_resources` (`resource_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2518 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_lku_type`
--

CREATE TABLE `tk_lku_type` (
  `typeid` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`typeid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_tbl_gallery`
--

CREATE TABLE `tk_tbl_gallery` (
  `gallery_id` int(10) NOT NULL AUTO_INCREMENT,
  `typeid` int(10) NOT NULL,
  `program_id` int(10) unsigned DEFAULT NULL,
  `system_id` int(10) unsigned DEFAULT NULL,
  `ccr_id` int(10) unsigned DEFAULT NULL,
  `TContent_ID` int(10) unsigned DEFAULT NULL,
  `ContentID` char(35) DEFAULT NULL,
  `grouplabel` varchar(100) DEFAULT NULL,
  `additionalDesc` text,
  PRIMARY KEY (`gallery_id`),
  KEY `fk_tk_tbl_gallery1` (`typeid`),
  KEY `fk_tk_tbl_gallery2` (`program_id`),
  KEY `fk_tk_tbl_gallery3` (`system_id`),
  KEY `fk_tk_tbl_gallery4` (`ccr_id`),
  KEY `fk_tk_tbl_gallery_5` (`ContentID`),
  CONSTRAINT `fk_tk_tbl_gallery_1` FOREIGN KEY (`typeid`) REFERENCES `tk_lku_type` (`typeid`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_tbl_gallery_2` FOREIGN KEY (`program_id`) REFERENCES `rsc_tbl_program` (`program_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_tbl_gallery_3` FOREIGN KEY (`system_id`) REFERENCES `rsc_lku_reporting_system` (`system_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_tbl_gallery_4` FOREIGN KEY (`ccr_id`) REFERENCES `rsc_lku_ccr` (`ccr_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_tbl_subtopics`
--

CREATE TABLE `tk_tbl_subtopics` (
  `subtopic_id` int(10) NOT NULL AUTO_INCREMENT,
  `subtopic_name` varchar(300) NOT NULL,
  `new_subtopic_name` varchar(300) DEFAULT NULL,
  `topic_id` int(10) NOT NULL,
  `Display` tinyint(4) DEFAULT NULL,
  `markDelete` tinyint(4) DEFAULT NULL,
  `sortorder` int(10) DEFAULT NULL,
  `date_created` date NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`subtopic_id`),
  KEY `fk_tk_tbl_subtopics` (`topic_id`),
  CONSTRAINT `fk_tk_tbl_subtopics` FOREIGN KEY (`topic_id`) REFERENCES `tk_tbl_topics` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=254 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_tbl_toolkits`
--

CREATE TABLE `tk_tbl_toolkits` (
  `toolkits_id` int(10) NOT NULL AUTO_INCREMENT,
  `date_published` date DEFAULT NULL,
  `TContent_ID` int(10) unsigned DEFAULT NULL,
  `ContentID` char(35) DEFAULT NULL,
  `typeid` int(10) DEFAULT NULL,
  `program_id` int(10) unsigned DEFAULT NULL,
  `system_id` int(10) unsigned DEFAULT NULL,
  `ccr_id` int(10) unsigned DEFAULT NULL,
  `grouplabel` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`toolkits_id`),
  KEY `fk_tk_tbl_toolkits_1` (`typeid`),
  KEY `fk_tk_tbl_toolkits_2` (`program_id`),
  KEY `fk_tk_tbl_toolkits_3` (`system_id`),
  KEY `fk_tk_tbl_toolkits_4` (`ccr_id`),
  KEY `fk_tk_tbl_toolkits_1_idx` (`ContentID`),
  CONSTRAINT `fk_tk_tbl_toolkits_2` FOREIGN KEY (`typeid`) REFERENCES `tk_lku_type` (`typeid`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_tbl_toolkits_3` FOREIGN KEY (`ccr_id`) REFERENCES `rsc_lku_ccr` (`ccr_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_tbl_toolkits_4` FOREIGN KEY (`system_id`) REFERENCES `rsc_lku_reporting_system` (`system_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_tk_tbl_toolkits_5` FOREIGN KEY (`program_id`) REFERENCES `rsc_tbl_program` (`program_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=102 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tk_tbl_topics`
--

CREATE TABLE `tk_tbl_topics` (
  `topic_id` int(10) NOT NULL AUTO_INCREMENT,
  `topic_name` varchar(300) NOT NULL,
  `topic_description` text,
  `new_topic_name` varchar(300) DEFAULT NULL,
  `new_topic_description` text,
  `toolkits_id` int(10) NOT NULL,
  `markDelete` tinyint(1) DEFAULT '0',
  `Display` tinyint(1) DEFAULT '0',
  `date_created` date NOT NULL,
  `date_updated` datetime NOT NULL,
  `sortorder` int(10) NOT NULL,
  PRIMARY KEY (`topic_id`),
  KEY `fk_tk_tbl_topics` (`toolkits_id`),
  CONSTRAINT `fk_tk_tbl_topics` FOREIGN KEY (`toolkits_id`) REFERENCES `tk_tbl_toolkits` (`toolkits_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=449 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tmailinglist`
--

CREATE TABLE `tmailinglist` (
  `MLID` char(35) DEFAULT NULL,
  `SiteID` varchar(25) DEFAULT NULL,
  `Name` varchar(50) DEFAULT NULL,
  `Description` longtext,
  `LastUpdate` datetime DEFAULT NULL,
  `isPurge` int(10) DEFAULT NULL,
  `isPublic` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tmailinglistmembers`
--

CREATE TABLE `tmailinglistmembers` (
  `MLID` char(35) DEFAULT NULL,
  `Email` varchar(100) DEFAULT NULL,
  `SiteID` varchar(25) DEFAULT NULL,
  `fname` varchar(50) DEFAULT NULL,
  `lname` varchar(50) DEFAULT NULL,
  `company` varchar(50) DEFAULT NULL,
  `isVerified` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tpermissions`
--

CREATE TABLE `tpermissions` (
  `ContentID` char(35) DEFAULT NULL,
  `GroupID` char(35) DEFAULT NULL,
  `SiteID` varchar(25) DEFAULT NULL,
  `Type` varchar(50) DEFAULT NULL,
  KEY `IX_tpermissions_siteid` (`SiteID`),
  KEY `IX_tpermissions_contentid` (`ContentID`),
  KEY `IX_tpermissions_type` (`Type`),
  KEY `IX_tpermissions_groupid` (`GroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tplugindisplayobjects`
--

CREATE TABLE `tplugindisplayobjects` (
  `objectID` char(35) NOT NULL DEFAULT '',
  `moduleID` char(35) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `location` varchar(50) DEFAULT NULL,
  `displayObjectFile` varchar(200) DEFAULT NULL,
  `displaymethod` varchar(100) DEFAULT NULL,
  `docache` varchar(5) DEFAULT NULL,
  `configuratorInit` varchar(50) DEFAULT NULL,
  `configuratorJS` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`objectID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tplugins`
--

CREATE TABLE `tplugins` (
  `pluginID` int(11) NOT NULL AUTO_INCREMENT,
  `moduleID` char(35) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `provider` varchar(100) DEFAULT NULL,
  `providerURL` varchar(100) DEFAULT NULL,
  `category` varchar(50) DEFAULT NULL,
  `version` varchar(50) DEFAULT NULL,
  `deployed` tinyint(3) DEFAULT NULL,
  `package` varchar(100) DEFAULT NULL,
  `directory` varchar(100) DEFAULT NULL,
  `loadPriority` int(10) DEFAULT NULL,
  PRIMARY KEY (`pluginID`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tpluginscripts`
--

CREATE TABLE `tpluginscripts` (
  `scriptID` char(35) NOT NULL DEFAULT '',
  `moduleID` char(35) DEFAULT NULL,
  `runat` varchar(50) DEFAULT NULL,
  `scriptfile` varchar(200) DEFAULT NULL,
  `docache` varchar(5) DEFAULT NULL,
  PRIMARY KEY (`scriptID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tpluginsettings`
--

CREATE TABLE `tpluginsettings` (
  `moduleID` char(35) NOT NULL DEFAULT '',
  `name` varchar(100) NOT NULL DEFAULT '',
  `settingValue` longtext,
  PRIMARY KEY (`moduleID`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `trazunasettings`
--

CREATE TABLE `trazunasettings` (
  `hostName` varchar(50) NOT NULL,
  `siteID` varchar(25) DEFAULT '',
  `settingsID` char(35) NOT NULL DEFAULT '',
  `damPath` varchar(250) DEFAULT NULL,
  `servertype` varchar(50) NOT NULL DEFAULT 'local',
  `hostID` varchar(50) NOT NULL,
  `apiKey` varchar(50) NOT NULL,
  PRIMARY KEY (`settingsID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tredirects`
--

CREATE TABLE `tredirects` (
  `redirectID` char(35) NOT NULL DEFAULT '',
  `URL` mediumtext,
  `created` datetime DEFAULT NULL,
  PRIMARY KEY (`redirectID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tsessiontracking`
--

CREATE TABLE `tsessiontracking` (
  `trackingID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `contentID` char(35) DEFAULT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `userid` char(35) DEFAULT NULL,
  `remote_addr` varchar(50) DEFAULT NULL,
  `server_name` varchar(50) DEFAULT NULL,
  `query_string` mediumtext,
  `referer` varchar(255) DEFAULT NULL,
  `user_agent` varchar(200) DEFAULT NULL,
  `script_name` varchar(200) DEFAULT NULL,
  `urlToken` varchar(130) NOT NULL DEFAULT '',
  `entered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `country` varchar(50) DEFAULT NULL,
  `lang` varchar(50) DEFAULT NULL,
  `locale` varchar(50) DEFAULT NULL,
  `keywords` varchar(200) DEFAULT NULL,
  `originalUrlToken` varchar(130) DEFAULT NULL,
  `fname` varchar(50) DEFAULT NULL,
  `lname` varchar(50) DEFAULT NULL,
  `company` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`trackingID`),
  KEY `IDX_ENTERED` (`entered`),
  KEY `IX_TSessionTracking` (`siteID`),
  KEY `IX_TSessionTracking_1` (`contentID`),
  KEY `IX_TSessionTracking_2` (`urlToken`),
  KEY `IX_TSessionTracking_3` (`userid`)
) ENGINE=InnoDB AUTO_INCREMENT=5265686 DEFAULT CHARSET=utf8;

--
-- Table structure for table `tsettings`
--

CREATE TABLE `tsettings` (
  `siteid` varchar(25) NOT NULL DEFAULT '',
  `Site` varchar(50) DEFAULT NULL,
  `MaxNestLevel` int(10) DEFAULT NULL,
  `PageLimit` int(10) DEFAULT NULL,
  `Locking` varchar(50) DEFAULT NULL,
  `domain` varchar(255) DEFAULT NULL,
  `exportLocation` varchar(100) DEFAULT NULL,
  `FileDir` varchar(50) DEFAULT NULL,
  `Contact` varchar(50) DEFAULT NULL,
  `MailserverIP` varchar(50) DEFAULT NULL,
  `MailServerUsername` varchar(50) DEFAULT NULL,
  `MailServerPassword` varchar(50) DEFAULT NULL,
  `EmailBroadcaster` int(10) DEFAULT NULL,
  `Extranet` int(10) DEFAULT NULL,
  `ExtranetPublicReg` int(10) DEFAULT NULL,
  `ExtranetPublicRegNotify` varchar(255) DEFAULT NULL,
  `ExtranetSSL` int(10) DEFAULT NULL,
  `Cache` int(10) DEFAULT NULL,
  `ViewDepth` int(10) DEFAULT NULL,
  `NextN` int(10) DEFAULT NULL,
  `DataCollection` int(10) DEFAULT NULL,
  `columnCount` int(10) DEFAULT NULL,
  `columnNames` text,
  `primaryColumn` int(10) DEFAULT NULL,
  `publicSubmission` int(10) DEFAULT NULL,
  `AdManager` int(10) DEFAULT NULL,
  `archiveDate` datetime DEFAULT NULL,
  `contactName` varchar(50) DEFAULT NULL,
  `contactAddress` varchar(50) DEFAULT NULL,
  `contactCity` varchar(50) DEFAULT NULL,
  `contactState` varchar(50) DEFAULT NULL,
  `contactZip` varchar(50) DEFAULT NULL,
  `contactEmail` varchar(100) DEFAULT NULL,
  `contactPhone` varchar(50) DEFAULT NULL,
  `privateUserPoolID` varchar(50) DEFAULT NULL,
  `publicUserPoolID` varchar(50) DEFAULT NULL,
  `advertiserUserPoolID` varchar(50) DEFAULT NULL,
  `orderNo` int(10) DEFAULT NULL,
  `emailBroadcasterLimit` int(10) NOT NULL DEFAULT '0',
  `feedManager` int(10) DEFAULT NULL,
  `displayPoolID` varchar(50) DEFAULT NULL,
  `galleryMainScaleBy` varchar(50) DEFAULT NULL,
  `galleryMainScale` int(10) DEFAULT NULL,
  `gallerySmallScaleBy` varchar(50) DEFAULT NULL,
  `gallerySmallScale` int(10) DEFAULT NULL,
  `galleryMediumScaleBy` varchar(50) DEFAULT NULL,
  `galleryMediumScale` int(10) DEFAULT NULL,
  `sendLoginScript` longtext,
  `mailingListConfirmScript` longtext,
  `publicSubmissionApprovalScript` longtext,
  `reminderScript` longtext,
  `loginURL` varchar(255) DEFAULT NULL,
  `editProfileURL` varchar(255) DEFAULT NULL,
  `CommentApprovalDefault` tinyint(3) DEFAULT NULL,
  `deploy` tinyint(3) DEFAULT NULL,
  `lastDeployment` datetime DEFAULT NULL,
  `accountActivationScript` longtext,
  `googleAPIKey` varchar(100) DEFAULT NULL,
  `useDefaultSMTPServer` tinyint(3) DEFAULT NULL,
  `theme` varchar(50) DEFAULT NULL,
  `mailserverSMTPPort` varchar(5) DEFAULT NULL,
  `mailserverPOPPort` varchar(5) DEFAULT NULL,
  `mailserverTLS` varchar(5) DEFAULT NULL,
  `mailserverSSL` varchar(5) DEFAULT NULL,
  `siteLocale` varchar(50) DEFAULT NULL,
  `domainAlias` longtext,
  `cacheCapacity` int(10) DEFAULT NULL,
  `cacheFreeMemoryThreshold` int(10) DEFAULT NULL,
  `tagline` varchar(255) DEFAULT NULL,
  `hasChangesets` tinyint(3) DEFAULT NULL,
  `baseID` char(35) DEFAULT NULL,
  `enforcePrimaryDomain` tinyint(4) DEFAULT '0',
  `enforceChangesets` tinyint(4) DEFAULT '0',
  `smallImageHeight` varchar(20) DEFAULT NULL,
  `smallImageWidth` varchar(20) DEFAULT NULL,
  `mediumImageHeight` varchar(20) DEFAULT NULL,
  `mediumImageWidth` varchar(20) DEFAULT NULL,
  `largeImageHeight` varchar(20) DEFAULT NULL,
  `largeImageWidth` varchar(20) DEFAULT NULL,
  `contentApprovalScript` longtext,
  `contentRejectionScript` longtext,
  `hasComments` int(10) DEFAULT '0',
  `hasLockableNodes` int(10) DEFAULT '0',
  `enableLockdown` varchar(255) DEFAULT NULL,
  `customTagGroups` varchar(255) DEFAULT NULL,
  `filePoolID` varchar(25) DEFAULT NULL,
  `categoryPoolID` varchar(25) DEFAULT NULL,
  `contentPoolID` text,
  PRIMARY KEY (`siteid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tsystemobjects`
--

CREATE TABLE `tsystemobjects` (
  `Object` varchar(50) DEFAULT NULL,
  `SiteID` varchar(25) DEFAULT NULL,
  `Name` varchar(50) DEFAULT NULL,
  `OrderNo` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `ttrash`
--

CREATE TABLE `ttrash` (
  `objectID` char(35) NOT NULL,
  `parentID` char(35) NOT NULL,
  `siteID` varchar(25) NOT NULL,
  `objectClass` varchar(50) NOT NULL,
  `objectType` varchar(50) NOT NULL,
  `objectSubType` varchar(50) NOT NULL,
  `objectLabel` varchar(255) NOT NULL,
  `objectstring` longtext,
  `deletedDate` datetime DEFAULT NULL,
  `deletedBy` varchar(50) NOT NULL,
  `deleteid` char(35) DEFAULT NULL,
  `orderno` int(10) DEFAULT NULL,
  PRIMARY KEY (`objectID`),
  KEY `IX_ttrash_deleteddate` (`deletedDate`),
  KEY `IX_ttrash_siteid` (`siteID`),
  KEY `IX_ttrash_objecttype` (`objectClass`),
  KEY `IX_ttrash_parentid` (`parentID`),
  KEY `IX_ttrash_deleteid` (`deleteid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tuseraddresses`
--

CREATE TABLE `tuseraddresses` (
  `addressID` char(35) NOT NULL DEFAULT '',
  `userID` char(35) DEFAULT NULL,
  `siteID` varchar(25) DEFAULT NULL,
  `addressName` varchar(50) DEFAULT NULL,
  `address1` varchar(50) DEFAULT NULL,
  `address2` varchar(50) DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  `state` varchar(50) DEFAULT NULL,
  `zip` varchar(50) DEFAULT NULL,
  `country` varchar(50) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `fax` varchar(50) DEFAULT NULL,
  `isPrimary` tinyint(3) DEFAULT NULL,
  `addressNotes` longtext,
  `addressURL` varchar(200) DEFAULT NULL,
  `longitude` float DEFAULT NULL,
  `latitude` float DEFAULT NULL,
  `addressEmail` varchar(100) DEFAULT NULL,
  `hours` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`addressID`),
  KEY `Index_2` (`longitude`),
  KEY `Index_3` (`latitude`),
  KEY `Index_4` (`userID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tuserremotesessions`
--

CREATE TABLE `tuserremotesessions` (
  `userID` char(35) NOT NULL DEFAULT '',
  `authToken` char(32) DEFAULT NULL,
  `data` text,
  `created` datetime DEFAULT NULL,
  `lastAccessed` datetime NOT NULL,
  PRIMARY KEY (`userID`),
  KEY `tuserremotesessions_authtoken` (`authToken`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tusers`
--

CREATE TABLE `tusers` (
  `UserID` char(35) NOT NULL DEFAULT '',
  `GroupName` varchar(50) DEFAULT NULL,
  `Fname` varchar(50) DEFAULT NULL,
  `Lname` varchar(50) DEFAULT NULL,
  `UserName` varchar(50) DEFAULT NULL,
  `Password` varchar(100) DEFAULT NULL,
  `PasswordCreated` datetime DEFAULT NULL,
  `Email` varchar(50) DEFAULT NULL,
  `Company` varchar(50) DEFAULT NULL,
  `JobTitle` varchar(50) DEFAULT NULL,
  `mobilePhone` varchar(50) DEFAULT NULL,
  `Website` varchar(255) DEFAULT NULL,
  `Type` int(10) DEFAULT NULL,
  `subType` varchar(50) DEFAULT NULL,
  `Ext` int(10) DEFAULT NULL,
  `ContactForm` longtext,
  `Admin` int(10) DEFAULT NULL,
  `S2` int(10) DEFAULT NULL,
  `LastLogin` datetime DEFAULT NULL,
  `LastUpdate` datetime DEFAULT NULL,
  `LastUpdateBy` varchar(50) DEFAULT NULL,
  `LastUpdateByID` varchar(35) DEFAULT NULL,
  `Perm` tinyint(3) DEFAULT NULL,
  `InActive` tinyint(3) DEFAULT NULL,
  `isPublic` int(10) DEFAULT NULL,
  `SiteID` varchar(50) DEFAULT NULL,
  `Subscribe` int(10) DEFAULT NULL,
  `notes` longtext,
  `description` longtext,
  `interests` longtext,
  `keepPrivate` tinyint(3) DEFAULT NULL,
  `photoFileID` varchar(35) DEFAULT NULL,
  `IMName` varchar(100) DEFAULT NULL,
  `IMService` varchar(50) DEFAULT NULL,
  `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `remoteID` varchar(35) DEFAULT NULL,
  `tags` longtext,
  `tablist` varchar(255) DEFAULT NULL,
  `mysite_misc` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`UserID`),
  UNIQUE KEY `unique_username` (`UserName`),
  KEY `tusers_groupname` (`GroupName`),
  KEY `tusers_mysite_misc` (`mysite_misc`),
  KEY `IX_tusers_type` (`Type`),
  KEY `IX_tusers_subtype` (`subType`),
  KEY `IX_tusers_remoteid` (`remoteID`),
  KEY `IX_tusers_siteid` (`SiteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tusersfavorites`
--

CREATE TABLE `tusersfavorites` (
  `favoriteID` char(35) NOT NULL DEFAULT '',
  `userID` char(35) NOT NULL DEFAULT '',
  `favoriteName` varchar(100) DEFAULT NULL,
  `favorite` mediumtext,
  `type` varchar(30) NOT NULL DEFAULT '',
  `siteID` varchar(35) DEFAULT NULL,
  `dateCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `columnNumber` int(10) DEFAULT NULL,
  `rowNumber` int(10) DEFAULT NULL,
  `maxRSSItems` int(10) DEFAULT NULL,
  PRIMARY KEY (`favoriteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tusersinterests`
--

CREATE TABLE `tusersinterests` (
  `userID` char(35) NOT NULL DEFAULT '',
  `categoryID` char(35) NOT NULL DEFAULT '',
  PRIMARY KEY (`userID`,`categoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tusersmemb`
--

CREATE TABLE `tusersmemb` (
  `UserID` char(35) NOT NULL DEFAULT '',
  `GroupID` char(35) NOT NULL DEFAULT '',
  PRIMARY KEY (`UserID`,`GroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tuserstags`
--

CREATE TABLE `tuserstags` (
  `tagID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `userID` char(35) NOT NULL,
  `siteID` varchar(25) NOT NULL,
  `tag` varchar(100) NOT NULL,
  PRIMARY KEY (`tagID`),
  KEY `Index_2` (`userID`),
  KEY `Index_3` (`siteID`),
  KEY `Index_4` (`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tuserstrikes`
--

CREATE TABLE `tuserstrikes` (
  `username` varchar(100) NOT NULL DEFAULT '',
  `strikes` int(10) DEFAULT NULL,
  `lastAttempt` datetime NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `um_lku_hudrole`
--

CREATE TABLE `um_lku_hudrole` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  `sort` int(10) unsigned DEFAULT NULL,
  `orgtypes` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `um_mv_userprofile`
--

CREATE TABLE `um_mv_userprofile` (
  `userid` char(35) NOT NULL,
  `username` varchar(50) NOT NULL,
  `fname` varchar(50) NOT NULL,
  `lname` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `city` varchar(50) DEFAULT NULL,
  `state` char(2) DEFAULT NULL,
  `zip` varchar(50) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `inactive` tinyint(3) DEFAULT NULL,
  `lastlogin` datetime DEFAULT NULL,
  `orgid` varchar(45) DEFAULT NULL,
  `organization` varchar(500) DEFAULT NULL,
  `orgtype` varchar(100) DEFAULT NULL,
  `orgtype_other` varchar(100) DEFAULT NULL,
  `coc_no` varchar(500) DEFAULT NULL,
  `hmis_type` varchar(200) DEFAULT NULL,
  `pha_orgrole` varchar(45) DEFAULT NULL,
  `affiliated_grantees_orgid` varchar(3000) DEFAULT NULL,
  `affiliated_grantees` text,
  `hud_fo_type` varchar(50) DEFAULT NULL,
  `system_admin` tinyint(3) DEFAULT NULL,
  `aaq` varchar(100) DEFAULT NULL,
  `coc_checkup` varchar(100) DEFAULT NULL,
  `event_space` varchar(100) DEFAULT NULL,
  `grantees` varchar(100) DEFAULT NULL,
  `iec` varchar(100) DEFAULT NULL,
  `na` varchar(100) DEFAULT NULL,
  `na_ta` text,
  `lms` varchar(100) DEFAULT NULL,
  `report_mgmt` varchar(100) DEFAULT NULL,
  `resources` varchar(100) DEFAULT NULL,
  `ta_mgmt` varchar(100) DEFAULT NULL,
  `ta_mgmt_ta` text,
  `training_event` varchar(100) DEFAULT NULL,
  `um` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`userid`),
  KEY `um_mv_userprofile_idx1` (`affiliated_grantees_orgid`(255))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Temporary table structure for view `um_vw_aaq_useraccess`
--

/*!50001 DROP VIEW IF EXISTS `um_vw_aaq_useraccess`*/;
/*!50001 CREATE TABLE `um_vw_aaq_useraccess` (
  `userid` tinyint NOT NULL,
  `BRAC` tinyint NOT NULL,
  `CDBG` tinyint NOT NULL,
  `CoC` tinyint NOT NULL,
  `ConPlan` tinyint NOT NULL,
  `DRGR` tinyint NOT NULL,
  `Environmental Review` tinyint NOT NULL,
  `ESG` tinyint NOT NULL,
  `e-snaps` tinyint NOT NULL,
  `HDX` tinyint NOT NULL,
  `HMIS` tinyint NOT NULL,
  `HOME` tinyint NOT NULL,
  `HOPWA` tinyint NOT NULL,
  `HUD-VASH` tinyint NOT NULL,
  `IDIS` tinyint NOT NULL,
  `Legacy Homeless Programs` tinyint NOT NULL,
  `NSP` tinyint NOT NULL,
  `Title V` tinyint NOT NULL,
  `VHPD` tinyint NOT NULL,
  `General Public` tinyint NOT NULL,
  `Albuquerque Field Office` tinyint NOT NULL,
  `Anchorage Field Office` tinyint NOT NULL,
  `Atlanta Regional Office` tinyint NOT NULL,
  `Baltimore Field Office` tinyint NOT NULL,
  `Birmingham Field Office` tinyint NOT NULL,
  `Boston Regional Office` tinyint NOT NULL,
  `Buffalo Field Office` tinyint NOT NULL,
  `Chicago Regional Office` tinyint NOT NULL,
  `Columbia Field Office` tinyint NOT NULL,
  `Columbus Field Office` tinyint NOT NULL,
  `Denver Regional Office` tinyint NOT NULL,
  `Detroit Field Office` tinyint NOT NULL,
  `Ft. Worth Regional Office` tinyint NOT NULL,
  `Greensboro Field Office` tinyint NOT NULL,
  `Hartford Field Office` tinyint NOT NULL,
  `Honolulu Field Office` tinyint NOT NULL,
  `Houston Field Office` tinyint NOT NULL,
  `Indianapolis Field Office` tinyint NOT NULL,
  `Jackson Field Office` tinyint NOT NULL,
  `Jacksonville Field Office` tinyint NOT NULL,
  `Kansas City Regional Office` tinyint NOT NULL,
  `Knoxville Field Office` tinyint NOT NULL,
  `Little Rock Field Office` tinyint NOT NULL,
  `Los Angeles Field Office` tinyint NOT NULL,
  `Louisville Field Office` tinyint NOT NULL,
  `Miami Field Office` tinyint NOT NULL,
  `Milwaukee Field Office` tinyint NOT NULL,
  `Minneapolis Field Office` tinyint NOT NULL,
  `New Orleans Field Office` tinyint NOT NULL,
  `New York Regional Office` tinyint NOT NULL,
  `Newark Field Office` tinyint NOT NULL,
  `Oklahoma City Field Office` tinyint NOT NULL,
  `Omaha Field Office` tinyint NOT NULL,
  `Philadelphia Regional Office` tinyint NOT NULL,
  `Pittsburgh Field Office` tinyint NOT NULL,
  `Portland Field Office` tinyint NOT NULL,
  `Richmond Field Office` tinyint NOT NULL,
  `San Antonio Field Office` tinyint NOT NULL,
  `San Francisco Regional Office` tinyint NOT NULL,
  `San Juan (Caribbean) Field Office` tinyint NOT NULL,
  `Seattle Regional Office` tinyint NOT NULL,
  `St. Louis Field Office` tinyint NOT NULL,
  `Washington DC Office` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `um_vw_aaq_useraccess_subquery`
--

/*!50001 DROP VIEW IF EXISTS `um_vw_aaq_useraccess_subquery`*/;
/*!50001 CREATE TABLE `um_vw_aaq_useraccess_subquery` (
  `userid` tinyint NOT NULL,
  `sort_order` tinyint NOT NULL,
  `group_name` tinyint NOT NULL,
  `role_name` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `um_vw_aaq_useraccess_subquery2`
--

/*!50001 DROP VIEW IF EXISTS `um_vw_aaq_useraccess_subquery2`*/;
/*!50001 CREATE TABLE `um_vw_aaq_useraccess_subquery2` (
  `userid` tinyint NOT NULL,
  `BRAC` tinyint NOT NULL,
  `CDBG` tinyint NOT NULL,
  `CoC` tinyint NOT NULL,
  `ConPlan` tinyint NOT NULL,
  `DRGR` tinyint NOT NULL,
  `Environmental Review` tinyint NOT NULL,
  `ESG` tinyint NOT NULL,
  `e-snaps` tinyint NOT NULL,
  `FederalReporting.gov` tinyint NOT NULL,
  `HDX` tinyint NOT NULL,
  `HMIS` tinyint NOT NULL,
  `HOME` tinyint NOT NULL,
  `HOPWA` tinyint NOT NULL,
  `HUD-VASH` tinyint NOT NULL,
  `IDIS` tinyint NOT NULL,
  `Legacy Homeless Programs` tinyint NOT NULL,
  `NSP` tinyint NOT NULL,
  `RHSP` tinyint NOT NULL,
  `Section 108` tinyint NOT NULL,
  `Title V` tinyint NOT NULL,
  `VHPD` tinyint NOT NULL,
  `General Public` tinyint NOT NULL,
  `Albuquerque Field Office` tinyint NOT NULL,
  `Anchorage Field Office` tinyint NOT NULL,
  `Atlanta Regional Office` tinyint NOT NULL,
  `Baltimore Field Office` tinyint NOT NULL,
  `Birmingham Field Office` tinyint NOT NULL,
  `Boston Regional Office` tinyint NOT NULL,
  `Buffalo Field Office` tinyint NOT NULL,
  `Chicago Regional Office` tinyint NOT NULL,
  `Columbia Field Office` tinyint NOT NULL,
  `Columbus Field Office` tinyint NOT NULL,
  `Denver Regional Office` tinyint NOT NULL,
  `Detroit Field Office` tinyint NOT NULL,
  `Ft. Worth Regional Office` tinyint NOT NULL,
  `Greensboro Field Office` tinyint NOT NULL,
  `Hartford Field Office` tinyint NOT NULL,
  `Honolulu Field Office` tinyint NOT NULL,
  `Houston Field Office` tinyint NOT NULL,
  `Indianapolis Field Office` tinyint NOT NULL,
  `Jackson Field Office` tinyint NOT NULL,
  `Jacksonville Field Office` tinyint NOT NULL,
  `Kansas City Regional Office` tinyint NOT NULL,
  `Knoxville Field Office` tinyint NOT NULL,
  `Little Rock Field Office` tinyint NOT NULL,
  `Los Angeles Field Office` tinyint NOT NULL,
  `Louisville Field Office` tinyint NOT NULL,
  `Miami Field Office` tinyint NOT NULL,
  `Milwaukee Field Office` tinyint NOT NULL,
  `Minneapolis Field Office` tinyint NOT NULL,
  `New Orleans Field Office` tinyint NOT NULL,
  `New York Regional Office` tinyint NOT NULL,
  `Newark Field Office` tinyint NOT NULL,
  `Oklahoma City Field Office` tinyint NOT NULL,
  `Omaha Field Office` tinyint NOT NULL,
  `Philadelphia Regional Office` tinyint NOT NULL,
  `Pittsburgh Field Office` tinyint NOT NULL,
  `Portland Field Office` tinyint NOT NULL,
  `Richmond Field Office` tinyint NOT NULL,
  `San Antonio Field Office` tinyint NOT NULL,
  `San Francisco Regional Office` tinyint NOT NULL,
  `San Juan (Caribbean) Field Office` tinyint NOT NULL,
  `Seattle Regional Office` tinyint NOT NULL,
  `St. Louis Field Office` tinyint NOT NULL,
  `Washington DC Office` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Temporary table structure for view `um_vw_userorg`
--

/*!50001 DROP VIEW IF EXISTS `um_vw_userorg`*/;
/*!50001 CREATE TABLE `um_vw_userorg` (
  `UserID` tinyint NOT NULL,
  `username` tinyint NOT NULL,
  `email` tinyint NOT NULL,
  `orgid` tinyint NOT NULL,
  `orgname` tinyint NOT NULL
) ENGINE=MyISAM */;

--
-- Dumping routines for database 'mysite_cms'
--
/*!50003 DROP FUNCTION IF EXISTS `fn_workdays` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` FUNCTION `fn_workdays`(`first_date` DATE, `second_date` DATE) RETURNS int(11)
    DETERMINISTIC
BEGIN
  DECLARE start_date DATE;
  DECLARE end_date DATE;
  DECLARE diff INT;

  IF (first_date < second_date) THEN
    SET start_date = first_date;
    SET end_date = second_date;
  ELSE
    SET start_date = second_date;
    SET end_date = first_date;
  END IF;

  SET diff = DATEDIFF(end_date, start_date);

 RETURN (CASE WHEN DAYNAME(start_date) not in ('Saturday', 'Sunday') && DAYNAME(end_date) = 'Saturday' THEN diff
               WHEN DAYNAME(start_date) not in ('Saturday', 'Sunday') && DAYNAME(end_date) = 'Sunday' THEN (diff - 2)

               WHEN DAYNAME(start_date) = 'Saturday' && DAYNAME(end_date) = 'Sunday' THEN (diff - 1)
               WHEN DAYNAME(start_date) = 'Saturday' && DAYNAME(end_date) = 'Saturday' THEN (diff + 1)
               WHEN DAYNAME(start_date) = 'Sunday' && DAYNAME(end_date) in ('Saturday', 'Sunday') THEN (diff + 1)

               WHEN DAYNAME(start_date) = 'Saturday' && DAYNAME(end_date) not in ('Saturday', 'Sunday') THEN (diff -1)
               WHEN DAYNAME(start_date) = 'Sunday' && DAYNAME(end_date) not in ('Saturday', 'Sunday') THEN (diff + 1)

               WHEN DAYNAME(start_date) not in ('Saturday', 'Sunday') && DAYNAME(end_date) not in ('Saturday', 'Sunday')
                    && WEEKDAY(start_date) > WEEKDAY(end_date) THEN (diff - 2)
               ELSE diff END)
    - (FLOOR(diff / 7) * 2)
    - (CASE WHEN DAYNAME(start_date) = 'Sunday' THEN 1 ELSE 0 END)
    - (CASE WHEN DAYNAME(end_date) = 'Saturday' THEN 1 ELSE 0 END);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `iec_fn_get_annual_base_pay` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` FUNCTION `iec_fn_get_annual_base_pay`(
    wage_type varchar(16), 
    hourly_wage float(10,2),
    hours_per_week float(10,2),
    weeks_per_year int,
    salary float(10,2)
) RETURNS float(10,2)
    DETERMINISTIC
begin
    declare weeks_in_year int;
    declare annual_base_pay float(10,2);

    set weeks_in_year = 52;

    if wage_type = 'hourly' then
        set annual_base_pay = hourly_wage * hours_per_week * weeks_per_year;
    end if;

    if wage_type = 'annual' then
        set annual_base_pay = salary;
    end if;

    return ifnull(annual_base_pay, 0);
end ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `iec_fn_get_bump_over_time` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` FUNCTION `iec_fn_get_bump_over_time`(
    wage_type varchar(16), 
    bump_type varchar(16), 
    start_date timestamp, 
    bump_amount float(10,2),
    hourly_wage float(10,2),
    hours_per_week float(10,2),
    weeks_per_year int,
    salary float(10,2)
) RETURNS float(10,2)
    DETERMINISTIC
begin
    declare weeks_in_year int;
    declare bump_week_count int;
    declare bump_over_timespan float(10,2);

    set weeks_in_year = 52;

    set bump_week_count = iec_fn_get_bump_week_count(start_date);

    if wage_type = 'hourly' then
        set bump_over_timespan = bump_amount * hours_per_week * weeks_per_year * bump_week_count / weeks_in_year;
        if bump_type = 'cola' then
            set bump_over_timespan = bump_over_timespan * hourly_wage / 100;
        end if;
    end if;

    if wage_type = 'annual' then
        set bump_over_timespan = bump_amount * bump_week_count / weeks_in_year;
        if bump_type = 'cola' then
            set bump_over_timespan = bump_over_timespan * salary / 100;
        end if;
    end if;

    return ifnull(bump_over_timespan, 0);
end ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `iec_fn_get_bump_week_count` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` FUNCTION `iec_fn_get_bump_week_count`(start_date timestamp) RETURNS float(10,8)
    DETERMINISTIC
begin
    declare bump_week_count float(10,8);
    declare weeks_in_year int;
    declare a_year_from_now date;
    declare bump_days int;
    
    set weeks_in_year = 52;
    set a_year_from_now = current_date() + INTERVAL weeks_in_year WEEK;
    set bump_days = datediff( a_year_from_now, start_date );
    set bump_week_count = bump_days / 7;

    if bump_week_count > weeks_in_year then
        set bump_week_count = weeks_in_year; 
    end if;
    if bump_week_count < 0 then
        set bump_week_count = 0; 
    end if;

    return bump_week_count;
end ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `iec_fn_get_total_annual_wages` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` FUNCTION `iec_fn_get_total_annual_wages`(
    wage_type varchar(16), 
    bump_type varchar(16), 
    raise_start_date timestamp, 
    cola_start_date timestamp, 
    raise_amount float(10,2),
    cola_amount float(10,2),
    hourly_wage float(10,2),
    hours_per_week float(10,2),
    weeks_per_year int,
    salary float(10,2),
    annual_overtime float(10,2)
) RETURNS float(10,2)
    DETERMINISTIC
begin
    declare annual_bump float(10,2);
    declare annual_base_pay float(10,2);
    declare total_annual_wages float(10,2);
    declare bump_start_date timestamp;
    declare bump_amount float(10,2);

    if bump_type = 'raise' then
        set bump_start_date = raise_start_date;
        if wage_type = 'annual' then
            set bump_amount = raise_amount - salary;
        else
            set bump_amount = raise_amount - hourly_wage;
        end if;    
    end if;
    if bump_type = 'cola' then
        set bump_start_date = cola_start_date;
        set bump_amount = cola_amount;
    end if;
        
    
    set annual_bump = 
        iec_fn_get_bump_over_time(
            wage_type, 
            bump_type, 
            bump_start_date, 
            bump_amount, 
            hourly_wage, 
            hours_per_week, 
            weeks_per_year, 
            salary 
        );

    set annual_base_pay = 
        iec_fn_get_annual_base_pay (
            wage_type, 
            hourly_wage, 
            hours_per_week, 
            weeks_per_year, 
            salary 
        );

    set total_annual_wages = annual_bump + annual_base_pay + annual_overtime;

    return total_annual_wages;
end ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_Amendworkplan` */;
DELIMITER ;;
CREATE DEFINER=`jeiholzer`@`%` PROCEDURE `sp_Amendworkplan`(IN wpid INT,IN currentuser varchar(40), OUT editedWPID INT)
    READS SQL DATA
BEGIN

  
  DECLARE workplanid_val integer;
  DECLARE rr_requestID_val integer;
  DECLARE rr_recipientID_val integer;
  DECLARE ra_requestID_val integer;
  DECLARE ra_assignmentID_val integer;
  DECLARE goalid_val integer;
  DECLARE goalname_val VARCHAR(200);
  DECLARE wp_taskid_val integer;
  DECLARE wp_tripid_val integer;
  DECLARE wp_parenttripid_val integer;
  DECLARE wp_oldwptripid_val integer;
  DECLARE wp_docid_val integer;
  DECLARE wp_currentdocumentid_val integer;
  DECLARE wpMaxVersion INT DEFAULT 0;
  DECLARE workplan_trail_val VARCHAR(400) DEFAULT NULL;
  DECLARE _output TEXT;
  DECLARE _output2 TEXT;
  DECLARE _output3 TEXT;
  DECLARE parentwpid integer;
  DECLARE assignmentid_val integer;   
  DECLARE association_val integer;
  
recipient_block: begin

  
  
  
  
  
  INSERT INTO tap_tbl_workplan (assignmentid, status,taproviderid, name_granteeid,name_coc_no,tatype,workplan_name,periodofperformance,startdate,enddate,fundingsource,coop,workplan_num,taprojectscope,created_date,lastupdated,createdby,updatedby,workplan_summary,subject_id,isVersion,hasVersion)
    SELECT assignmentid, '9' as status,taproviderid, name_granteeid,name_coc_no,tatype,workplan_name,periodofperformance,startdate,enddate,fundingsource,coop,workplan_num,taprojectscope,now(),now(),currentuser,currentuser,workplan_summary,subject_id,1 as isVersion,0 as hasVersion FROM tap_tbl_workplan WHERE id=wpid;

  set @newWorkPlanID=LAST_INSERT_ID();

  
  

    
    INSERT INTO tap_tbl_recipient (workplanid,fieldofficeid,state,granteeid,coc_no,sortorder,createddate)
      SELECT @newWorkPlanID,fieldofficeid,state,granteeid,coc_no,sortorder,now() 
      FROM tap_tbl_recipient 
      WHERE workplanid=wpid;

    
    
    select @newWorkPlanID;
    

  

END recipient_block;
    
    

     

goal_block: begin

  
  DECLARE wp_goal_done BOOLEAN;
  DECLARE goal_loop_cntr INT DEFAULT 0;
  DECLARE goal_num_rows INT DEFAULT 0;

  
  DECLARE wp_goal_cur CURSOR FOR

    SELECT goalid
    
    FROM tap_asc_goals_workplan  
    WHERE workplanid = wpid;

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET wp_goal_done =1;

  
  OPEN wp_goal_cur;
  
  
  wp_goal_loop: LOOP

    FETCH  wp_goal_cur
    INTO   goalid_val;

    
    IF wp_goal_done THEN
        CLOSE wp_goal_cur;
        LEAVE wp_goal_loop;
    END IF;
   
   INSERT INTO tap_asc_goals_workplan (goalid,workplanid)
    SELECT goalid, @newWorkPlanID
    FROM tap_asc_goals_workplan
               where workplanid=wpid and goalid = goalid_val;
    
 
  
  
  

    
    
    
    
    
  END LOOP wp_goal_loop;

END goal_block;

     

  
  UPDATE tap_tbl_workplan SET
    hasVersion = 1
  WHERE
    id = wpid;
  
  
      SELECT (a.parent_wpid) INTO parentwpid
      FROM tap_asc_amendment a
      INNER JOIN tap_tbl_workplan wp ON (wp.id = a.original_wp or wp.id = a.amended_wp)
      WHERE wp.id = wpid
      ORDER BY a.id desc limit 1;
      
 IF parentwpid = 0 THEN
   
  SELECT (a.version) INTO wpMaxVersion
  FROM tap_asc_amendment a
  INNER JOIN tap_tbl_workplan wp ON (wp.id = a.original_wp or wp.id = a.amended_wp)
  WHERE wp.id = wpid
  ORDER BY a.id desc limit 1;

  SELECT (a.workplan_trail) INTO workplan_trail_val
  FROM tap_asc_amendment a
  INNER JOIN tap_tbl_workplan wp ON (wp.id = a.original_wp or wp.id = a.amended_wp)
  WHERE wp.id = wpid
  ORDER BY a.id desc limit 1;

ELSE

  
  SELECT (a.version) INTO wpMaxVersion
  FROM tap_asc_amendment a
  INNER JOIN tap_tbl_workplan wp ON (wp.id = a.original_wp or wp.id = a.amended_wp)
  WHERE a.parent_wpid = parentwpid
  ORDER BY a.id desc limit 1;

  SELECT (a.workplan_trail) INTO workplan_trail_val
  FROM tap_asc_amendment a
  INNER JOIN tap_tbl_workplan wp ON (wp.id = a.original_wp or wp.id = a.amended_wp)
  WHERE a.parent_wpid = parentwpid
  ORDER BY a.id desc limit 1;
  
 END IF;

  IF wpMaxVersion = 0 THEN
    SET @new_workplan_trail=CONCAT(wpid,',',@newWorkPlanID);
    
    SET wpMaxVersion = 1;
    SET parentwpid = wpid;
  ELSE
    
      SELECT (a.parent_wpid) INTO parentwpid
      FROM tap_asc_amendment a
      INNER JOIN tap_tbl_workplan wp ON (wp.id = a.original_wp or wp.id = a.amended_wp)
      WHERE wp.id = wpid
      ORDER BY a.id desc limit 1;
    set @new_workplan_trail=CONCAT(workplan_trail_val,',',@newWorkPlanID);
    SET parentwpid = parentwpid;
  END IF;
  
  INSERT INTO tap_asc_amendment (original_wp,amended_wp,version,workplan_trail,parent_wpid)
  VALUES (wpid,@newWorkPlanID,(wpMaxVersion+1),@new_workplan_trail, parentwpid);

  
  INSERT INTO tap_tbl_outcome (workplanid, title, description, createddate, createdby,parent_id)
    SELECT @newWorkPlanID, title, description, now(), currentuser,id
    FROM tap_tbl_outcome
               where workplanid=wpid
			   and isdeleted IS NULL;
    
  
  INSERT INTO tap_tbl_people (workplanid, userid, membertypeid, lastupdated, updatedby)
    SELECT @newWorkPlanID, userid, membertypeid, lastupdated, updatedby
    FROM tap_tbl_people
               WHERE workplanid=wpid;

  INSERT INTO tap_tbl_teamleads (fname,lname,title,phone,ext,email,workplan_id,parent_id)
    SELECT  fname, lname,title,phone,ext,email,@newWorkPlanID,id
    FROM tap_tbl_teamleads
               WHERE workplan_id=wpid;	
  
   INSERT INTO tap_tbl_comments (description,workplanid, for_status, enteredby,createddate,lastupdated)
  VALUES
  (
  'Work Plan Edits Started'
  ,@newWorkPlanID
  ,9
  ,currentuser
  ,now()
  ,now()
  );
  
   
  INSERT INTO tap_tbl_feed
                                                                                          (feed,
                                                                                          workplanid,
                                                                                          feedtype,
                                                                                          dateoccured,
                                                                                          posteddate,
                                                                                          postedby
                                                                                          )
                                                                                          VALUES
  (
  'Work Plan Edits Started'
  ,wpid
  ,5
  ,now()
  ,now()
  ,currentuser
  );

     
wp_task_block: begin

  
  DECLARE wp_task_done BOOLEAN;
  DECLARE wp_task_loop_cntr INT DEFAULT 0;
  DECLARE wp_task_num_rows INT DEFAULT 0;

  
  DECLARE wp_task_cur CURSOR FOR

  SELECT wt.id
  FROM tap_workplan_task wt
  WHERE wt.workplanid = wpid;

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET wp_task_done =1;

	
  
  OPEN wp_task_cur;
  
  
  wp_task_loop: LOOP

    FETCH  wp_task_cur
    INTO   wp_taskid_val;   

    
    IF wp_task_done THEN
        CLOSE wp_task_cur;
       LEAVE wp_task_loop;
    END IF;

  
  INSERT INTO tap_workplan_task (taskname, description, startdate,enddate,workplanid,estimatedbudget,createddate,lastupdated,task_status,parent_taskid,original_taskid)
    SELECT taskname, description, startdate,enddate,@newWorkPlanID,estimatedbudget,now(),now(),task_status,id, Case when original_taskid is NULL then id Else original_taskid end AS Origtaskid
    FROM tap_workplan_task
               WHERE workplanid=wpid AND id=wp_taskid_val;
  
  set @new_wpTaskID=LAST_INSERT_ID();
  
  INSERT INTO tap_task_expectedoutput (title, taskid, description, completiondate, completed, completeddate, lastupdated, parent_id)
    SELECT eo.title, @new_wpTaskID, eo.description, eo.completiondate, eo.completed, eo.completeddate, now(), eo.id
    FROM tap_task_expectedoutput eo
    INNER JOIN tap_workplan_task wt ON wt.id = eo.taskid 
    WHERE wt.workplanid = wpid AND wt.id=wp_taskid_val;
  
  INSERT INTO tap_task_laborcategory (laborcategory, taskid, hours, parent_id)
    SELECT lc.laborcategory, @new_wpTaskID, lc.hours, lc.id
    FROM tap_task_laborcategory lc
    INNER JOIN tap_workplan_task wt ON wt.id = lc.taskid 
    WHERE wt.workplanid = wpid AND wt.id=wp_taskid_val;

	INSERT INTO tap_tbl_keypersonnel (name, title, taskid, parent_id)
    SELECT kp.name, kp.title, @new_wpTaskID, kp.id
    FROM tap_tbl_keypersonnel kp
    INNER JOIN tap_workplan_task wt ON wt.id = kp.taskid 
    WHERE wt.workplanid = wpid AND wt.id=wp_taskid_val;


INSERT INTO tap_asc_task_topics (topicid,taskid)
SELECT tt.topicid, @new_wpTaskID
    FROM tap_asc_task_topics tt
    INNER JOIN tap_workplan_task wt ON wt.id = tt.taskid 
    WHERE wt.workplanid = wpid AND wt.id=wp_taskid_val;
    
INSERT INTO tap_workplan_task_number (workplan_id, task_id, task_number)
SELECT  @newWorkPlanID, @new_wpTaskID, task_number
	FROM tap_workplan_task_number 
	WHERE workplan_id = wpid 
		and task_id = wp_taskid_val;

    
    
    
    
  END LOOP wp_task_loop;

END wp_task_block;

	INSERT INTO tap_tbl_workplan_travel (budget, workplan_id, createddate, lastupdated, parent_travelid)
		SELECT  budget, @newWorkPlanID, now(), now(), id
		FROM tap_tbl_workplan_travel
               WHERE workplan_id = wpid
			   AND (isdeleted = 0 OR isdeleted IS NULL);
     
	set @new_wpTravelID=LAST_INSERT_ID();
   
	INSERT INTO tap_tbl_travel_trips (num_of_people, num_of_daysperperson, trip_comments, travel_id, lastupdated, parent_id)
		SELECT  wptrips.num_of_people, wptrips.num_of_daysperperson, wptrips.trip_comments, @new_wpTravelID, now(), wptrips.id
		FROM tap_tbl_travel_trips wptrips
			INNER JOIN tap_tbl_workplan_travel wptr
				on wptr.id = wptrips.travel_id
		WHERE wptr.workplan_id = wpid
		AND (wptr.isdeleted = 0 OR wptr.isdeleted IS NULL);
    
wp_trip_block: begin
	DECLARE wp_trip_done BOOLEAN;

	DECLARE wp_trip_cur CURSOR FOR
		SELECT wptrips.id
				, wptrips.parent_id
		FROM tap_tbl_travel_trips wptrips
			INNER JOIN tap_tbl_workplan_travel wptr
				on wptr.id = wptrips.travel_id
		WHERE wptr.workplan_id = @newWorkPlanID
		AND (wptr.isdeleted = 0 OR wptr.isdeleted IS NULL);
	
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET wp_trip_done = 1;
	
	OPEN wp_trip_cur;
	wp_trip_loop: LOOP
		FETCH  wp_trip_cur
		INTO   wp_tripid_val,
				wp_parenttripid_val;
		
		
		IF wp_trip_done THEN
			CLOSE wp_trip_cur;
			LEAVE wp_trip_loop;
		END IF;
	
		SET _output = CONCAT(",",wp_tripid_val);
		SELECT _output;
		
		SET _output2 = CONCAT(",",wp_parenttripid_val);
		SELECT _output2;
		
			INSERT INTO tap_asc_trips_transportation (tripid, transportationid)
				SELECT  wp_tripid_val, wptran.transportationid
				FROM tap_asc_trips_transportation wptran
					INNER JOIN tap_tbl_travel_trips wptrips
						on wptran.tripid = wptrips.id
					INNER JOIN tap_tbl_workplan_travel wptr
						on wptr.id = wptrips.travel_id
				WHERE wptr.workplan_id = wpid
					AND wptrips.id = wp_parenttripid_val
					AND (wptr.isdeleted = 0 OR wptr.isdeleted IS NULL);
			
	
			INSERT INTO tap_asc_trips_task (tripid, taskid)
				SELECT DISTINCT
						wp_tripid_val
						, twt.id
				FROM tap_workplan_task twt
					INNER JOIN tap_tbl_workplan ttw
						on twt.workplanid = ttw.id
					INNER JOIN tap_tbl_workplan_travel wptr
						on wptr.workplan_id = ttw.id
					INNER JOIN tap_tbl_travel_trips wptrips
						on wptrips.travel_id = wptr.id
				WHERE ttw.id = @newWorkPlanID
				AND wptrips.id = wp_tripid_val
				AND (wptr.isdeleted = 0 OR wptr.isdeleted IS NULL)
				AND parent_taskid in (SELECT DISTINCT 
												twt.id
										FROM tap_workplan_task twt
											INNER JOIN tap_tbl_workplan ttw
												on twt.workplanid = ttw.id
											INNER JOIN tap_tbl_workplan_travel wptr
												on wptr.workplan_id = ttw.id
											INNER JOIN tap_tbl_travel_trips wptrips
												on wptrips.travel_id = wptr.id
											INNER JOIN tap_asc_trips_task tatt
												on tatt.taskid = twt.id
										WHERE ttw.id = wpid
										AND tatt.tripid = wp_parenttripid_val
										AND (wptr.isdeleted = 0 OR wptr.isdeleted IS NULL));
							
	END LOOP wp_trip_loop;
END wp_trip_block;


     
	
    
wp_document_block: begin
	DECLARE wp_document_done BOOLEAN;

	DECLARE wp_document_cur CURSOR FOR
		SELECT d.id as parentDocID
		FROM tap_tbl_document d
		INNER JOIN tap_asc_document_workplan wpd
			ON wpd.documentid = d.id
		INNER JOIN tap_tbl_workplan ttw
			ON ttw.id = wpd.workplanid
		WHERE ttw.id = wpid AND wpd.isdeleted IS NULL;
		
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET wp_document_done = 1;
	
	OPEN wp_document_cur;
	wp_document_loop: LOOP
		FETCH  wp_document_cur
		INTO   wp_docid_val;
		
		
		IF wp_document_done THEN
			CLOSE wp_document_cur;
			LEAVE wp_document_loop;
		END IF;
	
		SET _output3 = CONCAT(",",wp_docid_val);
		SELECT _output3;
		
		INSERT INTO tap_tbl_document (name, path, date_uploaded, mime_type, uploadedby, doctype, parent_id)
			SELECT  d.name, d.path, d.date_uploaded, d.mime_type, d.uploadedby, d.doctype, d.id
			FROM  tap_tbl_document d
			WHERE d.id = wp_docid_val;
			
		select max(id) into wp_currentdocumentid_val from tap_tbl_document;
		
		INSERT INTO tap_asc_document_workplan (documentid, workplanid)
			VALUES(wp_currentdocumentid_val, @newWorkPlanID);
							
	END LOOP wp_document_loop;
END wp_document_block;
    
	INSERT INTO tap_asc_workplan_fundingsource(fundingsourceid, workplanid)
		SELECT tawf.fundingsourceid, @newWorkPlanID
		FROM tap_asc_workplan_fundingsource tawf
		WHERE tawf.workplanid = wpid;

oncallasc_block: begin

  
  DECLARE wp_oncallwp_assignment BOOLEAN;
  DECLARE asc_loop_cntr INT DEFAULT 0;
  
  
  DECLARE wp_asc_cur CURSOR FOR

    SELECT ascwp.assignmentid, association_completed
        FROM tap_tbl_workplan wp
        INNER JOIN tap_asc_oncallwp_assignment ascwp ON ascwp.workplanid = wp.id
        WHERE wp.id=wpid;

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET wp_oncallwp_assignment =1;

  
  OPEN wp_asc_cur;
    
  wp_asc_loop: LOOP

    FETCH  wp_asc_cur
    INTO   assignmentid_val,   
           association_val;

    
    IF wp_oncallwp_assignment THEN
        CLOSE wp_asc_cur;
        LEAVE wp_asc_loop;
    END IF;

  
  INSERT INTO tap_asc_oncallwp_assignment (assignmentid, workplanid,association_completed)
     values (assignmentid_val, @newWorkPlanID, association_val);
  
  END LOOP wp_asc_loop;

END oncallasc_block;

     

SET editedWPID = @newWorkPlanID;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_CheckLearnerProfile` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_CheckLearnerProfile`(IN userid varchar(40), OUT hasLearnerProfile boolean)
    READS SQL DATA
BEGIN

  
  DECLARE registration_result integer;
  DECLARE group_result integer;
  SET @hasLearnerProfile = 0;
  
  SELECT count(user_id) INTO registration_result
	FROM lms_tbl_registration
	WHERE user_id = userid;
  
  SELECT count(u.UserID) INTO group_result
  FROM tusers u
	JOIN tusersmemb m on m.userid = u.userid
	JOIN tusers g on g.userid = m.groupid
	WHERE u.userid = userid
	AND g.groupName = 'HUD Exchange Learn';
  
  IF registration_result > 0 AND group_result > 0 THEN
    SET @hasLearnerProfile = 1;
  ELSE
    SET @hasLearnerProfile = 0;
  END IF;
  
  
  
  SET hasLearnerProfile = @hasLearnerProfile;
  
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_coc_updateCoCJurisdiction` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_coc_updateCoCJurisdiction`()
BEGIN
DECLARE done INT DEFAULT FALSE;
declare b INT;
declare cocNo INT;
declare cur1 CURSOR for SELECT id FROM gt_asc_grantee_jurisdiction j where year > (SELECT max(year) FROM gt_vw_coc_year where coc_no = j.coc_no);

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

open cur1;

read_loop: LOOP
	fetch cur1 into b;
if done then
	leave read_loop;
end if;

set @cocNo = (select coc_no from gt_asc_grantee_jurisdiction where id = b);

update gt_asc_grantee_jurisdiction 
set year = (SELECT max(year) FROM gt_vw_coc_year  where coc_no = @cocNo)
where id = b AND coc_no is not null;


end loop;
close cur1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_coc_updateGranteeJurisdiction` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_coc_updateGranteeJurisdiction`()
BEGIN
DECLARE done INT DEFAULT FALSE;
declare b INT;
declare cur1 CURSOR for SELECT id FROM gt_asc_grantee_jurisdiction where year > (SELECT max(year) FROM gt_vw_coc_year where coc_no = coc_no);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

open cur1;

read_loop: LOOP
	fetch cur1 into b;
if done then
	leave read_loop;
end if;

update gt_asc_grantee_jurisdiction 
set year = (SELECT max(year) FROM gt_vw_coc_year where coc_no = coc_no)
where id = b AND coc_no is not null;


end loop;
close cur1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_DeleteAmendment` */;
DELIMITER ;;
CREATE DEFINER=`mkim`@`%` PROCEDURE `sp_DeleteAmendment`(IN wpid INT, OUT parentID INT)
    READS SQL DATA
BEGIN

  DECLARE originalwpID_val INT; 
  DECLARE originalID INT DEFAULT 0;
  DECLARE wp_newdocID_val integer;
  DECLARE _output TEXT;
  
  	DELETE FROM tap_asc_trips_transportation
	where tripid IN (SELECT wptrips.id
						FROM tap_tbl_travel_trips wptrips
							INNER JOIN tap_tbl_workplan_travel wptrvl
								on wptrips.travel_id = wptrvl.id
						WHERE wptrvl.workplan_id = wpid);
						
	DELETE FROM tap_asc_trips_task
	where tripid IN (SELECT wptrips.id
						FROM tap_tbl_travel_trips wptrips
							INNER JOIN tap_tbl_workplan_travel wptrvl
								on wptrips.travel_id = wptrvl.id
						WHERE wptrvl.workplan_id = wpid);
	
	DELETE FROM tap_tbl_travel_trips
	where travel_id IN (SELECT id
							FROM tap_tbl_workplan_travel
							WHERE workplan_id = wpid);
	
	DELETE FROM tap_tbl_workplan_travel where workplan_id = wpid;
	
	
wp_document_block: begin
	DECLARE wp_document_done BOOLEAN;

	DECLARE wp_document_cur CURSOR FOR
		SELECT documentid
		FROM tap_asc_document_workplan
		WHERE workplanid = wpid;
		
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET wp_document_done = 1;
	
	OPEN wp_document_cur;
	wp_document_loop: LOOP
		FETCH  wp_document_cur
		INTO   wp_newdocID_val;
		
		
		IF wp_document_done THEN
			CLOSE wp_document_cur;
			LEAVE wp_document_loop;
		END IF;
	
		SET _output = CONCAT(",",wp_newdocID_val);
		SELECT _output;
		
		DELETE FROM tap_asc_document_workplan where workplanid = wpid and documentid = wp_newdocID_val;
		DELETE FROM tap_tbl_document where id = wp_newdocID_val;
							
	END LOOP wp_document_loop;
END wp_document_block;
	
	
  DELETE FROM tap_task_expectedoutput 
  WHERE taskid IN (SELECT id
					FROM tap_workplan_task
					WHERE workplanid = wpid);
  
  DELETE FROM tap_task_laborcategory 
  WHERE taskid IN (SELECT id
					FROM tap_workplan_task
					WHERE workplanid = wpid);
  
  DELETE FROM tap_asc_task_topics 
  WHERE taskid IN (SELECT id
					FROM tap_workplan_task
					WHERE workplanid = wpid);

  DELETE FROM tap_asc_document_comment 
  WHERE commentid IN (SELECT id
						FROM tap_tbl_comments 
						WHERE workplanid = wpid);

  DELETE FROM tap_tbl_keypersonnel 
  where taskid IN (SELECT id
						FROM tap_workplan_task 
						WHERE workplanid = wpid);

		SET originalwpID_val = (SELECT original_wp FROM tap_asc_amendment WHERE amended_wp = wpid);
		DELETE FROM tap_asc_document_workplan where workplanid = wpid;
		DELETE FROM tap_asc_amendment where amended_wp = wpid;
		DELETE FROM tap_asc_goals_workplan where workplanid = wpid;
		DELETE FROM tap_tbl_recipient where workplanid = wpid;
		
		DELETE FROM tap_tbl_comments where workplanid = wpid;
		DELETE FROM tap_tbl_outcome where workplanid = wpid;
		DELETE FROM tap_tbl_people where workplanid = wpid;
		DELETE FROM tap_tbl_feed where workplanid = wpid;
		DELETE FROM tap_workplan_task where workplanid = wpid;
    
    DELETE FROM tap_tbl_version where edited_workplan_id = wpid;
    DELETE FROM tap_tbl_teamleads where workplan_id = wpid;
        
		DELETE FROM tap_asc_oncallwp_assignment where workplanid = wpid;
		DELETE FROM tap_asc_workplan_fundingsource where workplanid = wpid;
		DELETE FROM tap_tbl_workplan where id = wpid;
  
  set originalID = originalwpID_val;

  IF NOT originalID = 0 THEN
  update tap_tbl_workplan 
        set hasamendment = 0,
			hasVersion = 0
        where id = originalwpID_val;  
  END IF ;
  
	SET parentID = originalwpID_val;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_grantee_updateGranteeJurisdiction` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_grantee_updateGranteeJurisdiction`()
BEGIN
DECLARE done INT DEFAULT FALSE;
declare b INT;
declare granteeNo INT;
declare cur1 CURSOR for SELECT id FROM gt_asc_grantee_jurisdiction j where year > (SELECT max(year) FROM gt_vw_grantee_year where grantee_id = j.grantee_id);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

open cur1;

read_loop: LOOP
	fetch cur1 into b;
if done then
	leave read_loop;
end if;

set @granteeNo = (select grantee_id from gt_asc_grantee_jurisdiction where id = b);

update gt_asc_grantee_jurisdiction 
set year = (SELECT max(year) FROM gt_vw_grantee_year where grantee_id = @granteeNo)
where id = b AND grantee_ID is not null;


end loop;
close cur1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_CoC` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_CoC`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	IF char_length(_year) = 0 THEN
		SELECT DISTINCT SUBSTRING(c.code, 1, 6) as filter_value
			, c.label as filter_label
		FROM rpt_coc c
			INNER JOIN rpt_report r on c.code = r.coc and status = 'published'
		WHERE 
			SUBSTRING_INDEX(c.code, '-', 1) = _state
		ORDER BY filter_value;
	ELSE
		SELECT DISTINCT SUBSTRING(c.code, 1, 6) as filter_value
			, c.label as filter_label
		FROM rpt_coc c
			INNER JOIN rpt_report r on c.code = r.coc and status = 'published'
		WHERE SUBSTRING_INDEX(c.code, '-', 1) = _state
			AND year(r.periodEnd) = _year
		ORDER BY filter_value;
	END IF;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_DateCurrYearEach` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_DateCurrYearEach`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT
		  cast(YEAR(periodEnd) AS char) AS filter_value
		, CONCAT('All ', cast(YEAR(periodEnd) AS char)) AS filter_label
		, MAKEDATE(YEAR(periodEnd),366) AS periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
		and periodEnd IS NOT NULL
	UNION
	SELECT DISTINCT 
		  cast(periodEnd AS char) AS filter_value
		, CONCAT('&nbsp;&nbsp;&nbsp;', Date_FORMAT(periodend, '%M %e, %Y')) AS filter_label	
		, periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
		and periodEnd IS NOT NULL
	UNION
	SELECT DISTINCT 
		  cast(fiscalYear AS char) AS filter_value
		, cast(fiscalYear AS char) AS filter_label	
		, MAKEDATE(fiscalYear,366) AS periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
		and fiscalYear not in (SELECT DISTINCT year(periodEnd) 
								FROM rpt_report
								WHERE program = _program
									and `group` = _group
									and `status` = 'published'
									and periodEnd IS NOT NULL
							  )
	ORDER BY periodEnd desc;
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_DateEach` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_DateEach`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN
	IF _program = 'HOME' and _group = 'Exp' THEN
		SELECT DISTINCT 
			  cast(periodEnd AS char) AS filter_value
			, cast( Date_FORMAT(periodend, '%M %e, %Y') AS char) AS filter_label	
			, periodEnd
		FROM rpt_report
		WHERE program = _program
			and `group` = _group
			and `status` = 'published'
			and periodEnd IS NOT NULL
			and fiscalYear = _year
		ORDER BY periodEnd desc;

	ELSE
		SELECT DISTINCT 
			  cast(periodEnd AS char) AS filter_value
			, cast( Date_FORMAT(periodend, '%M %e, %Y') AS char) AS filter_label	
			, periodEnd
		FROM rpt_report
		WHERE program = _program
			and `group` = _group
			and `status` = 'published'
			and periodEnd IS NOT NULL
		ORDER BY periodEnd desc;
	END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_DateYearDeadline` */;
DELIMITER ;;
CREATE DEFINER=`cpinkston`@`%` PROCEDURE `sp_rpt_getFilter_DateYearDeadline`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT concat(group_concat(report_year ORDER BY report_year DESC), ',0') filter_value, filter_label
	FROM (
			
			(select distinct (year(periodend)) report_year, 'Current Reports' filter_label
			FROM rpt_report
			WHERE program = _program
				and `group` = _group
				and `status` = 'published'
				and periodEnd IS NOT NULL
			order by 1 desc
			limit 2)

			UNION
			
			
			(select distinct (year(periodend)) report_year, 'Historical Reports' filter_label
			FROM rpt_report
			WHERE program = _program
				and `group` = _group
				and `status` = 'published'
				and periodEnd IS NOT NULL
			order by 1 desc
			limit 2, 100)
	) reportYearDeadline
	GROUP BY filter_label

	UNION 

	
	(SELECT DISTINCT
		  cast(YEAR(periodEnd) AS char) AS filter_value
		, CONCAT('&nbsp;&nbsp;&nbsp;&nbsp;', 
				cast(YEAR(periodEnd) AS char), 
				' Commitment & CHDO Reservation, and ',
				cast(YEAR(periodEnd)-3 AS char),
				' Disbursement Requirements') AS filter_label
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
		and periodEnd IS NOT NULL
	ORDER BY periodEnd desc) 

	ORDER BY filter_value desc, filter_label desc
	;



END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_DateYearEach` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_DateYearEach`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT
		  cast(YEAR(periodEnd) AS char) AS filter_value
		, CONCAT('All ', cast(YEAR(periodEnd) AS char)) AS filter_label
		, MAKEDATE(YEAR(periodEnd),366) AS periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
		and periodEnd IS NOT NULL
	UNION
	SELECT DISTINCT 
		  cast(periodEnd AS char) AS filter_value
		, CONCAT('&nbsp;&nbsp;&nbsp;', Date_FORMAT(periodend, '%M %e, %Y')) AS filter_label	
		, periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
		and periodEnd IS NOT NULL
	ORDER BY periodEnd desc, filter_value;
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_DateYearQuarter` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_DateYearQuarter`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT
		  cast(YEAR(periodEnd) AS char) AS filter_value
		, CONCAT('All ', cast(YEAR(periodEnd) AS char)) AS filter_label
		, MAKEDATE(YEAR(periodEnd),366) AS periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
	UNION
	SELECT DISTINCT 
		  cast(periodEnd AS char) AS filter_value
		, CASE
			WHEN MONTH(periodEnd) <=3 THEN CONCAT('&nbsp;&nbsp;&nbsp;Q1 ', cast(YEAR(periodEnd) AS char)) 
			WHEN MONTH(periodEnd) > 3 AND MONTH(periodEnd) <=6 THEN CONCAT('&nbsp;&nbsp;&nbsp;Q2 ', cast(YEAR(periodEnd) AS char)) 
			WHEN MONTH(periodEnd) > 6 AND MONTH(periodEnd) <=9 THEN CONCAT('&nbsp;&nbsp;&nbsp;Q3 ', cast(YEAR(periodEnd) AS char)) 
			WHEN MONTH(periodEnd) > 9 AND MONTH(periodEnd) <=12 THEN CONCAT('&nbsp;&nbsp;&nbsp;Q4 ', cast(YEAR(periodEnd) AS char)) 		
			END
			AS filter_label	
		, periodEnd
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
	ORDER BY periodEnd desc;
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_FiscalYear` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_FiscalYear`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT 
		fiscalYear AS filter_value
		, CASE 
			WHEN periodEnd IS NOT NULL THEN CONCAT('FY ', fiscalYear, ' or Earlier Expiring Funds')
			ELSE CONCAT('FY ', fiscalYear, '  Expired Funds')
		END AS filter_label	
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
	ORDER BY fiscalYear DESC, filter_label;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_Grantee` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_Grantee`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN
	IF _scope = 'GranteeForm' OR _scope = 'GranteeComp' THEN
		SELECT DISTINCT g.code as filter_value
				, g.name as filter_label
		FROM rpt_grantee g
		INNER JOIN rpt_report r ON g.code = r.grantee
		WHERE SUBSTRING_INDEX(g.code, '-', -1) = _state
			AND r.status = 'published'
			AND r.program = _program
			AND r.`group` = _group
			AND r.scope = _scope
		ORDER BY filter_label;
	ELSEIF _granteetype = '1' OR _granteetype = '2' OR _granteetype = '3' THEN
		SELECT DISTINCT g.code as filter_value
				, g.name as filter_label
		FROM rpt_grantee g
		INNER JOIN rpt_report r ON g.code = r.grantee
		WHERE SUBSTRING_INDEX(g.code, '-', -1) = _state
			AND r.status = 'published'
			AND r.program = _program
			AND r.`group` = _group
			AND r.grantType = _granteetype
		ORDER BY filter_label;
	ELSE
		SELECT DISTINCT g.code as filter_value
			, g.name as filter_label
		FROM rpt_grantee g
		INNER JOIN rpt_report r ON g.code = r.grantee
		WHERE SUBSTRING_INDEX(g.code, '-', -1) = _state
			AND r.status = 'published'
			AND r.program = _program
			AND r.`group` = _group
		ORDER BY filter_label;
	END IF;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_GranteeType` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_GranteeType`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT code as filter_value
		, label as filter_label
	FROM rpt_grant_type
	ORDER BY filter_value;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_ReportType` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_ReportType`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT code as filter_value
		, label as filter_label
	FROM rpt_report_type
	WHERE program = _program
	AND `group` = _group
	ORDER BY filter_value;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_Scope` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_Scope`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT filter_value, filter_label
	FROM rpt_filter_scope 
	WHERE program = _program
		and `group` = _group
	ORDER BY position;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_ScopeTypeEach` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_ScopeTypeEach`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT code as filter_value
		, CASE code
			WHEN 'PJRanking' THEN 'All PJ Rankings'
			ELSE code
		END
		AS filter_label
		, 1 as groupsort
		, code as groupname
	FROM rpt_report_type
	WHERE program = 'HOME'
	AND `group` = 'Snap'
	UNION 
	SELECT s.code as filter_value
		, CONCAT('&nbsp;&nbsp;&nbsp;', s.label) as filter_label
		
		, 2 as groupsort
		, 'PJRanking' AS groupname
	FROM rpt_scope s 
	JOIN rpt_type t on s.code = t.scope
	WHERE t.program = 'HOME'
	AND t.`group` = 'Snap'
	AND t.label like '%Ranking%'
	ORDER BY groupname desc, groupsort, filter_label;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_Sort` */;
DELIMITER ;;
CREATE DEFINER=`mkim`@`%` PROCEDURE `sp_rpt_getFilter_Sort`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN
	IF _program = 'HOME' and _group = 'Deadline' THEN
		SELECT code as filter_value
			, label as filter_label
		FROM rpt_sort
		WHERE code in ('PJ', 'FO')
		ORDER BY filter_value desc;
	ELSEIF _program = 'HOME' and _group = 'DeadlineGS' THEN
		SELECT code as filter_value
			, label as filter_label
		FROM rpt_sort
		WHERE code in ('PJ', 'FO')
		ORDER BY filter_value desc;
	ELSEIF _program = 'HOME' and _group = 'ES' THEN
		SELECT code as filter_value
			, label as filter_label
		FROM rpt_sort
		WHERE code in ('PJ', 'State')
		ORDER BY filter_value;
	ELSE
		SELECT code as filter_value
			, label as filter_label
		FROM rpt_sort
		ORDER BY filter_value;
	END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_State` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_State`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT Distinct s.code as filter_value
		, s.label as filter_label
	FROM rpt_state s
	ORDER BY s.label;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_ToolType` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_ToolType`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT code as filter_value
		, label as filter_label
	FROM rpt_tool_type
	ORDER BY filter_value;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_Year` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_Year`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT YEAR(periodEnd) as filter_value
		, YEAR(periodEnd) as filter_label
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
	ORDER BY periodEnd desc;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getFilter_YearRange` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getFilter_YearRange`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _state varchar(2)
								, IN _scope varchar(15)
								, IN _granteetype varchar(15)
								, IN _year varchar(4))
BEGIN

	SELECT DISTINCT YEAR(periodEnd) as filter_value
		, CONCAT(cast(YEAR(periodEnd) as char), '-', cast(YEAR(periodEnd)+1 as char)) as filter_label
	FROM rpt_report
	WHERE program = _program
		and `group` = _group
		and `status` = 'published'
	ORDER BY periodEnd desc;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getReports` */;
DELIMITER ;;
CREATE DEFINER=`jeiholzer`@`%` PROCEDURE `sp_rpt_getReports`(IN _program varchar(40)
								, IN _group varchar(40)
								, IN _start INT
								, IN _limit INT
								, IN _filter_Year varchar(4)
								, IN _filter_YearRange varchar(4)
								, IN _filter_Scope varchar(45)
								, IN _filter_State varchar(10)
								, IN _filter_CoC varchar(15)
								, IN _filter_Grantee varchar(15)
								, IN _filter_GranteeType varchar(10)
								, IN _filter_DateEach varchar(10)
								, IN _filter_DateYearQuarter varchar(10)
								, IN _filter_DateYearEach varchar(10)
								, IN _filter_ToolType varchar(50)
								, IN _filter_ScopeTypeEach varchar(50)
								, IN _filter_DateCurrYearEach varchar(10)
								, IN _filter_FiscalYear varchar(10)
								, IN _filter_DateYearDeadline varchar(200)
								, IN _filter_Sort varchar(10)
								, IN _filter_ReportType varchar(15))
    READS SQL DATA
BEGIN

    DECLARE _result integer;
	DECLARE _statement_cnt TEXT;
	DECLARE _statement_record TEXT;
	DECLARE _statement TEXT;
	
	SET _statement_cnt = "SELECT count(r.filename) AS total ";
	SET _statement_record = "SELECT CONCAT('/resource/reportmanagement/published/', filename) AS urlpath 
								, CONCAT('/resource/reportmanagement/published/', filename) AS url	-- to be deleted after Railo migration
								, CASE 
									WHEN r.program = 'CoC' and r.group = 'GIS' THEN
										CONCAT(' ', YEAR(periodEnd), ' ', tt.label, ' - ', s.label, case when tt.code = 'ShapeFile' then ' CoCs' else '' end)
									WHEN r.program = 'CoC' THEN
										CONCAT(' ', YEAR(periodEnd), ' ', t.label, case when c.label <> '' then concat(' - ', c.label) when s.label <> '' then concat(' - ', s.label) else '' end)
									WHEN r.program = 'HOPWA' THEN
										CONCAT(YEAR(periodEND), '-', YEAR(periodEND)+1, ' ', t.label, CASE WHEN g.name is not null then  concat(' - ', g.name) ELSE '' end)
									WHEN r.program = 'NSP' THEN
										CONCAT(t.label
											, CASE WHEN gt.label is not null then concat(' - ', gt.label, ' Grantee') else '' end 
											, CASE WHEN g.name is not null then  concat(' - ', g.name) else '' end
											, CASE WHEN r.`group` = 'QPR' then concat(' - ', case when MONTH(periodEnd) <=3 THEN concat('Q1 ', YEAR(periodEnd)) 
																								when MONTH(periodEnd) >3 AND MONTH(periodEnd) <=6 THEN concat('Q2 ', YEAR(periodEnd))
																								when MONTH(periodEnd) >6 AND MONTH(periodEnd) <=9 THEN concat('Q3 ', YEAR(periodEnd))
																								else concat('Q4 ', YEAR(periodEnd))
																								end ) 
												when r.periodEnd is not null then concat(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')) 
												else '' end
												)
									WHEN r.program = 'HOME' or r.program = 'HTF' THEN
										CONCAT( CASE WHEN r.`group` = 'IncomeLmts' or r.`group` = 'RentLimits' THEN CONCAT(YEAR(periodend), ' ')
													 ELSE ''
												END
											, t.label
											, CASE 
												WHEN r.`group` = 'Dash' THEN CONCAT(IFNULL(CONCAT(' - ', g.name), ''), 
																					IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), '')
																					)
												WHEN r.`group` = 'Vacant' THEN CONCAT(' - ', s.label, IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), ''))
												WHEN r.`group` = 'Open' THEN CONCAT(' - ', s.label, IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), ''))
												WHEN r.`group` = 'Snap' and r.scope = 'PJ' THEN CONCAT(IFNULL(CONCAT(' - ', g.name), ''), 
																										IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), ''))
												WHEN r.`group` = 'Snap' and r.scope <> 'PJ' THEN IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), '')
												WHEN r.`group` = 'Prod' THEN IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), '')
												WHEN r.`group` = 'Act' THEN CONCAT(' - ', s.label, IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), ''))
												WHEN r.`group` = 'ActHB' THEN IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), '')
												WHEN r.`group` = 'Cancel' and r.periodend is NOT NULL THEN IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), '')
												WHEN r.`group` = 'Cancel' and r.periodend is NULL THEN IFNULL(CONCAT(' - ', fiscalYear), '')
												WHEN r.`group` = 'Exp' THEN CONCAT(' - FY ',
																					r.fiscalYear, 
																					CASE 
																						WHEN periodEnd IS NOT NULL THEN ' or Earlier Expiring Funds'
																						ELSE '  Expired Funds'
																					END, 
																					' - All States', 
																						IFNULL(CONCAT(' - ', DATE_FORMAT(periodEnd,'%M %e, %Y')), ''))
												WHEN r.`group` = 'Deadline' THEN CONCAT(' - ', 
																						cast(YEAR(periodEnd) AS char), 
																						' Commitment & CHDO Reservation, and ',
																						cast(YEAR(periodEnd)-3 AS char),
																						' Disbursement Requirements',
																						' - ',
																						hs.label) 
												WHEN r.`group` = 'DeadlineGS' THEN CONCAT(' - ', 
																						cast(YEAR(periodEnd) AS char), 
																						' Commitment, ',
                                                                                        cast(YEAR(periodEnd) AS char), 
																						' CHDO Reservation, and ',
																						cast(YEAR(periodEnd) AS char),
																						' Disbursement Requirements',
																						' - ',
																						hs.label)                                                                                         
												WHEN r.`group` = 'ES' THEN CONCAT(' - ', 
																				DATE_FORMAT(periodEnd,'%M %e, %Y'), 
																				' - ',
																				hs.label) 
												WHEN r.`group` = 'IncomeLmts' or r.`group` = 'RentLimits' THEN IFNULL(CONCAT(' - ', s.label), '' )
												ELSE ''
											  END
										)
									WHEN r.program = 'CDBG' THEN
										CONCAT(t.label, IFNULL(CONCAT(' - ', g.name), ''), ' - PY', year(periodEnd))
									WHEN r.program = 'CPD' THEN
										CONCAT(r.program, ' ', rt.label, IFNULL(CONCAT(' - ', g.name), ''))
									ELSE
										t.label 
									END AS report_display_name  
								, SUBSTRING_INDEX(filename, '.', -1) as doctype";

	SET @PROGRAM = _program; 
	SET @GROUP = _group; 
	SET @START = _start; 
	SET @LIMIT = _limit; 
	
	SET _statement = "
		FROM rpt_report r 
		JOIN rpt_type t on r.program = t.program
						and r.`group` = t.`group`
						and r.scope = t.scope
		JOIN rpt_scope sc on sc.code = r.scope
		LEFT JOIN rpt_coc c on c.code = r.coc
		LEFT JOIN rpt_grantee g on g.code = r.grantee
		LEFT JOIN rpt_state s on s.code = r.state
		LEFT JOIN rpt_grant_type gt on gt.code = r.grantType
		LEFT JOIN rpt_tool_type tt on r.tooltype = tt.code
		LEFT JOIN rpt_sort hs on r.sort = hs.code
		LEFT JOIN rpt_filter_scope fs on r.program = fs.program
									  and r.`group` = fs.`group`
									  and r.scope = fs.filter_value
		LEFT JOIN rpt_report_type rt on r.program = rt.program
									and r.`group` = rt.`group`
									and r.reportType = rt.code
		WHERE r.status = 'published'
			AND r.program =  ?
			AND r.group =  ? ";

	IF _filter_Year <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.periodEnd like '", _filter_Year, "%' ");
	END IF;
	IF _filter_YearRange <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.periodEnd like '", _filter_YearRange, "%' ");
	END IF;

	IF _filter_Scope <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.scope like '", _filter_Scope, "%' ");
	END IF;

	IF _filter_State <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.state = '", _filter_State, "' ");
	END IF;

	IF _filter_CoC <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.coc LIKE '", _filter_CoC, "%' ");
	END IF;

	IF _filter_Grantee <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.grantee = '", _filter_Grantee, "' ");
	END IF;
	IF _filter_GranteeType <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.grantType = '", _filter_GranteeType, "' ");
	END IF;
				
	IF _filter_DateEach <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.periodEnd LIKE '", _filter_DateEach, "%' ");
	END IF;
	IF _filter_DateYearQuarter <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.periodEnd LIKE '", _filter_DateYearQuarter, "%' ");
	END IF;
	IF _filter_DateYearEach <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.periodEnd LIKE '", _filter_DateYearEach, "%' ");
	END IF;
	IF _filter_DateCurrYearEach <> '' THEN
		IF date(_filter_DateCurrYearEach) IS NOT NULL THEN 
			SET _statement = CONCAT(_statement, "AND r.periodEnd LIKE '", _filter_DateCurrYearEach, "%' ");
		ELSE
			SET _statement = CONCAT(_statement, "AND r.fiscalYear = '", _filter_DateCurrYearEach, "' ");
		END IF;
	END IF;

	IF _filter_DateYearDeadline <> '' THEN
		SET _statement = CONCAT(_statement, "AND year(r.periodEnd) IN (", _filter_DateYearDeadline, ") ");
	END IF;

	IF _filter_ToolType <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.toolType = '", _filter_ToolType, "' ");
	END IF;

	IF _filter_ScopeTypeEach <> '' THEN
		IF _filter_ScopeTypeEach = 'Snapshot' THEN
			SET _statement = CONCAT(_statement, "AND r.scope = 'PJ' ");
		ELSEIF _filter_ScopeTypeEach = 'PJRanking' THEN
			SET _statement = CONCAT(_statement, "AND r.scope <> 'PJ' ");
		ELSE 
			SET _statement = CONCAT(_statement, "AND r.scope = '", _filter_ScopeTypeEach, "' ");
		END IF;
	END IF;

	IF _filter_FiscalYear <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.fiscalyear = '", _filter_FiscalYear, "' ");
	END IF;

	IF _filter_Sort <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.sort = '", _filter_Sort, "' ");
	END IF;

	IF _filter_ReportType <> '' THEN
		SET _statement = CONCAT(_statement, "AND r.reportType = '", _filter_ReportType, "' ");
	END IF;


	SET @stmt_cnt = CONCAT(_statement_cnt, _statement);
	PREPARE STMT_cnt FROM @stmt_cnt;
	EXECUTE STMT_cnt USING @PROGRAM, @GROUP;
	DEALLOCATE PREPARE STMT_cnt;

	SET _statement = CONCAT(_statement, "ORDER BY r.periodEnd DESC ");
	
	CASE
		WHEN _program = 'HOPWA' AND _group = 'Perf' THEN 
			SET _statement = CONCAT(_statement, ", sc.sort, g.name ");
		WHEN _program = 'NSP' AND _group = 'Snap' THEN 
			SET _statement = CONCAT(_statement, ", sc.sort, r.grantType, g.name ");
		WHEN _program = 'NSP' AND _group = 'Prod' THEN 
			SET _statement = CONCAT(_statement, ", r.grantType, sc.sort, s.label ");
		WHEN _program = 'NSP' AND _group = 'NIC' THEN 
			SET _statement = CONCAT(_statement, ", g.name ");
		WHEN _program = 'NSP' AND _group = 'QPR' THEN 
			SET _statement = CONCAT(_statement, ", g.name , gt.label ");
		WHEN _program = 'NSP' AND _group = 'AP' THEN 
			SET _statement = CONCAT(_statement, ", g.name ");
		WHEN _program = 'CoC' AND _group = 'PopSub' THEN 
			SET _statement = CONCAT(_statement, ", sc.sort, s.label, c.label ");
		WHEN _program = 'CoC' AND _group = 'HIC' THEN 
			SET _statement = CONCAT(_statement, ", sc.sort, s.label, c.label ");
		WHEN _program = 'CoC' AND _group = 'Dash' THEN 
			SET _statement = CONCAT(_statement, ", c.label ");
		WHEN _program = 'CoC' AND _group = 'AwardComp' THEN 
			SET _statement = CONCAT(_statement, ", sc.sort, s.label, c.label ");
		WHEN _program = 'CoC' AND _group = 'GIS' THEN 
			SET _statement = CONCAT(_statement, ", s.label, r.tooltype ");
		WHEN _program = 'HOME' AND _group = 'Dash' THEN 
			SET _statement = CONCAT(_statement, ", g.name ");
		WHEN _program = 'HOME' AND _group = 'Vacant' THEN 
			SET _statement = CONCAT(_statement, ", s.label ");
		WHEN _program = 'HOME' AND _group = 'Open' THEN 
			SET _statement = CONCAT(_statement, ", s.label ");
		WHEN _program = 'HOME' AND _group = 'Snap' THEN 
			SET _statement = CONCAT(_statement, ", t.label DESC, g.name ");
		WHEN _program = 'HOME' AND _group = 'Act' THEN 
			SET _statement = CONCAT(_statement, ", s.label ");
		WHEN _program = 'HOME' AND _group = 'Cancel' THEN 
			SET _statement = CONCAT(_statement, ", r.fiscalYear DESC ");
		WHEN _program = 'HOME' AND _group = 'Exp' THEN 
			SET _statement = CONCAT(_statement, ", r.fiscalYear DESC ");
		WHEN _program = 'HOME' AND _group = 'Deadline' THEN 
			SET _statement = CONCAT(_statement, ", r.sort DESC ");
		WHEN _program = 'HOME' AND _group = 'DeadlineGS' THEN 
			SET _statement = CONCAT(_statement, ", r.sort DESC ");
		WHEN _program = 'HOME' AND _group = 'ES' THEN 
			SET _statement = CONCAT(_statement, ", r.sort ");
		WHEN _program = 'HOME' AND _group = 'IncomeLmts' THEN 
			SET _statement = CONCAT(_statement, ", r.group, s.label ");
		WHEN _program = 'HOME' AND _group = 'RentLimits' THEN 
			SET _statement = CONCAT(_statement, ", r.group, s.label ");
		WHEN _program = 'CDBG' AND _group = 'Expend' THEN 
			SET _statement = CONCAT(_statement, ", year(periodEnd) DESC, fs.position, g.name ");
		WHEN _program = 'CDBG' AND _group != 'Expend' THEN 
			SET _statement = CONCAT(_statement, ", year(periodEnd) DESC, g.name ");
		WHEN _program = 'CPD' THEN 
			SET _statement = CONCAT(_statement, ", g.name, rt.label ");
		WHEN _program = 'HTF' AND _group = 'IncomeLmts' THEN 
			SET _statement = CONCAT(_statement, ", r.group, s.label ");
		WHEN _program = 'HTF' AND _group = 'RentLimits' THEN 
			SET _statement = CONCAT(_statement, ", r.group, s.label ");
		ELSE 
			BEGIN
			END;
	END CASE;

	SET _statement = CONCAT(_statement, "LIMIT ?, ? ");

	SET @stmt = CONCAT(_statement_record, _statement);
	PREPARE STMT FROM @stmt; 	
	EXECUTE STMT USING @PROGRAM, @GROUP, @START, @LIMIT;
	DEALLOCATE PREPARE STMT;

	SELECT @stmt as stmt;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_rpt_getReports_admin` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_rpt_getReports_admin`(IN _program varchar(10)
								, IN _group varchar(10)
								, IN _scope varchar(15)
								, IN _status varchar(15)
								, IN _start INT
								, IN _limit INT
								,IN _order varchar(20))
    READS SQL DATA
BEGIN


    DECLARE _result integer;
	DECLARE _statement_cnt TEXT;
	DECLARE _statement_record TEXT;
	DECLARE _statement TEXT;
	
	IF _order IS NULL OR _order = '' THEN
		SET _order = ' uploadDate DESC';
	END IF;

	SET _statement_cnt = "SELECT count(r.filename) AS total ";
	SET _statement_record = "SELECT r.filename
									, r.basepath
									, r.status 
									, r.uploadDate
									, r.publishDate
									, r.message ";
	SET _statement = "FROM rpt_report r 
						WHERE status = '";
	SET _statement = concat(_statement, _status, "'");
	
	IF _program = 'other' THEN
		SET _statement = CONCAT(_statement, " AND (	r.program IS NULL OR r.`group` IS NULL OR r.scope IS NULL) ");
	ELSE
		IF _program <> '' THEN
			SET _statement = CONCAT(_statement, " AND r.program = '", _program, "' ");
		END IF;

		IF _group <> '' THEN
			SET _statement = CONCAT(_statement, " AND r.`group` = '", _group, "' ");
		END IF;

		IF _scope <> '' THEN
			SET _statement = CONCAT(_statement, " AND r.scope = '", _scope, "' ");
		END IF;
	END IF;

	SET @START = _start; 
	SET @LIMIT = _limit; 
	
	SET @stmt_cnt = CONCAT(_statement_cnt, _statement);
	PREPARE STMT_cnt FROM @stmt_cnt;
	EXECUTE STMT_cnt;
	DEALLOCATE PREPARE STMT_cnt;

	SET _statement = CONCAT(_statement, "ORDER BY ", _order, " ");
	SET _statement = CONCAT(_statement, "LIMIT ?, ?");

	SET @stmt = CONCAT(_statement_record, _statement);
	PREPARE STMT FROM @stmt; 	
	EXECUTE STMT USING @START, @LIMIT;
	DEALLOCATE PREPARE STMT;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_searchAAQ` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_searchAAQ`(
 IN questionID varchar(10),
 IN dateFrom varchar(256),
 IN dateTo varchar(256),
 IN ansSubmitted INT,
 IN searchText TEXT,
 IN statusID INT,
 IN questionOlder INT,
 IN questionInactive INT,
 IN questionViaPhone INT,
 IN qstnpool INT,
 IN poolTypeId INT,
 IN relatedprog INT,
 IN primaryprog INT,
 IN current_group INT,
 IN groupID INT,
 IN firmID INT,
 IN current_firm INT,
 IN requestor INT,
 IN filter_stateAbbrev varchar(10),
 IN city varchar(10),
 IN fieldoffice INT,
 IN filter_granteeID INT,
 IN startIndex INT,
 IN results_per_page INT
)
BEGIN

declare _statement varchar(5000);
set _statement = "SELECT distinct 
				q.id as id
				,replace(q.question, '\r\n', '<br />') as question
				,st.name as statusName
				,CONCAT_WS('', tu.Fname, ' ', tu.Lname) AS assignee_fullName
                ,torg_assignee.orgname as assignee_orgname
				,tblTopic.name as TopicName
				,SubT.name as SubTopicName
				,s.abbrev state
				,q.fieldoffice_id
				,lc.name city
				,co.orgname as GranteeName
				,rt.name as Granteetype
				,DATE_FORMAT(q.create_date,'%m/%d/%Y') as CD
				,DATE_FORMAT(q.update_date,'%m/%d/%Y') as update_date
				,(select fn_workdays(CURDATE(),(select update_date from aaq_tbl_question where id=q.id AND status_id IN (1,2,3,4)) )) as daysInactive
				,(select fn_workdays(update_date,create_date) from aaq_tbl_question where id=q.id and status_id IN (1,2,3,4)) as daysOpen
				,CASE WHEN q.status_id = 5 THEN DATE_FORMAT(q.update_date,'%m/%d/%Y') ELSE '' END as dateAnswered
				,CASE WHEN q.status_id = 5 THEN 
					(
					SELECT sub_ans.answer FROM aaq_tbl_answer sub_ans
					WHERE sub_ans.question_id = q.id
					order by sub_ans.update_date desc limit 1
					) ELSE '' END as answer
				,CASE WHEN q.status_id = 5 THEN cast(fn_workdays(q.update_date,q.create_date) as char charset utf8) ELSE '' END as responseTime
				,rt.name as requestorType
        , CASE WHEN q.requestor_type_id = 2 OR q.requestor_type_id = 3 
                -- Subgrantee, Prospective Grantee
                    THEN concat(torg_rAffiliation.orgname, ', ', torg_rAffiliation.grantee_state)
            END as requestorAffiliation

        , CASE WHEN q.requestor_type_id = 1 OR q.requestor_type_id = 5 OR q.requestor_type_id = 6
                -- HUD Grantee, TA, HUD Employee
                    THEN torg_rAffiliation.orgname
            WHEN q.requestor_type_id = 2 OR q.requestor_type_id = 3 
                -- Subgrantee, Prospective Grantee
                    THEN q.requestor_org_name
            WHEN q.requestor_type_id = 7
                -- Other
                    THEN q.requestor_type_other
            END as requestorFirmName
				,q.requestor_fname
				,q.requestor_lname
				,CONCAT_WS('', q.requestor_fname, ' ', q.requestor_lname) AS requestor_fullName
				,q.requestor_email
				,q.requestor_phone
				,lc.id
				,lc.name as rcountyname
				,gs.granteeid
				,q.pool_id
				,pool.acronym as pool_short
				,pool.name as pool_long
                ,case 
					when pool.acronym IS NULL
					then pool.name
					else pool.acronym
					end as pool
				,q.create_date
			FROM
			aaq_tbl_question q 
			INNER JOIN aaq_lku_status st on q.status_id = st.id
			INNER JOIN state s on s.abbrev = q.requestor_stateid
			INNER JOIN lku_county lc on q.requestor_countyid = lc.id
			INNER JOIN aaq_lku_requestor_type rt on q.requestor_type_id = rt.id
			INNER JOIN c_torganizations co on q.fieldoffice_id = co.orgid
			LEFT OUTER JOIN c_torganizations torg_rname on q.requestor_org_id = torg_rname.orgid
			LEFT OUTER JOIN c_torganizations torg_rAffiliation on q.requestor_org_id = torg_rAffiliation.orgid
			LEFT OUTER JOIN c_torganizations torg_assignee on q.assignee_org_id = torg_assignee.orgid
			INNER JOIN aaq_lku_pool pool on q.pool_id = pool.id
			LEFT OUTER JOIN aaq_lku_subtopic SubT on q.subtopic_id = SubT.id
			LEFT OUTER JOIN aaq_lku_topic tblTopic on SubT.topic_id = tblTopic.id
			LEFT OUTER JOIN aaq_asc_grantee_state gs on q.requestor_org_id = gs.granteeid
			LEFT OUTER JOIN aaq_asc_question_programs gp on q.id = gp.question_id
			LEFT OUTER JOIN aaq_tbl_question_history qh on q.id = qh.question_id 
			LEFT OUTER JOIN aaq_tbl_assignment_history  assignment on assignment.question_id = q.id		    
			LEFT OUTER JOIN aaq_tbl_answer tbla on tbla.question_id = q.id
			LEFT OUTER JOIN tusers tu on q.assignee_id = tu.UserID
            LEFT OUTER JOIN tusers tus on assignment.assignee_id = tus.userID where 1=1";
		
			if(questionID is not null) then
				SET _statement = CONCAT(_statement, ' AND q.id = ', questionID);
			end if;

			if(questionID IS NULL AND dateFrom IS NULL AND dateTO IS NULL) then
				if(ansSubmitted = 1) then
					SET _statement = CONCAT(_statement, ' AND q.status_id is not null ');
				elseif(ansSubmitted = 2) then
					SET _statement = CONCAT(_statement, ' AND q.id = 5');
				elseif(ansSubmitted = 3) then
					SET _statement = CONCAT(_statement, ' AND q.id = 6');
				end if;
			elseif(questionID is null and dateFrom is not null and dateTo is not null) then 
				if(ansSubmitted = 1) then
					SET _statement = CONCAT(_statement,' AND q.create_date BETWEEN ', "'",dateFrom,"'");
					SET _statement = CONCAT(_statement, ' AND ', "'",dateTo,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id is not null ');
				end if;
				if(ansSubmitted = 2) then
					SET _statement = CONCAT(_statement, ' AND tbla.update_date BETWEEN ', "'",dateFrom,"'");
					SET _statement = CONCAT(_statement, ' AND  ', "'",dateTo,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id = 5 ');
				end if;
				if(ansSubmitted = 3) then
					SET _statement = CONCAT(_statement, ' AND tbla.update_date BETWEEN ', "'",dateFrom,"'");
					SET _statement = CONCAT(_statement, ' AND ', "'",dateTo,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id = 6 ');
				end if;
			elseif(questionID is null and (dateFrom is not null and dateTo is null)) then 
				if(ansSubmitted = 1) then
					SET _statement = CONCAT(_statement,' AND q.create_date >= ', "'",dateFrom,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id is not null ');
				end if;
				if(ansSubmitted = 2) then
					SET _statement = CONCAT(_statement,' AND tbla.update_date >= ', "'",dateFrom,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id = 5 ');
				end if;
				if(ansSubmitted = 3) then
					SET _statement = CONCAT(_statement,' AND q.update_date >= ', "'",dateFrom,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id = 6 ');
				end if;
			elseif(questionID is null and (dateFrom is null and dateTo is not null)) then 
				if(ansSubmitted = 1) then
					SET _statement = CONCAT(_statement,' AND q.create_date <= ', "'",dateTo,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id is not null ');
				end if;
				if(ansSubmitted = 2) then
					SET _statement = CONCAT(_statement,' AND tbla.update_date <= ', "'",dateTo,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id = 5 ');
				end if;
				if(ansSubmitted = 3) then
					SET _statement = CONCAT(_statement,' AND q.update_date <= ', "'",dateTo,"'");
					SET _statement = CONCAT(_statement, ' AND q.status_id = 6 ');
				end if;
			end if;
			
			if(searchText is not null) then
				SET _statement = CONCAT(_statement,' AND (q.question like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR q.requestor_fname like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR q.requestor_lname like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR q.requestor_email like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR tus.fname like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR tus.lname like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR tu.fname like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR tu.lname like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR CONCAT_WS('' '', q.requestor_fname, '' '', q.requestor_lname) Like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR CONCAT_WS('' '', tu.fname, '' '', tu.lname) Like ', "'%",searchText,"%'");
				SET _statement = CONCAT(_statement, ' OR CONCAT_WS('' '', tus.fname, '' '', tus.lname) Like ', "'%",searchText,"%')");
			end if;

			if(questionOlder  = 1) then
				SET _statement = CONCAT(_statement,' AND DATEDIFF(now(),q.create_date) > 2 ');
			end if;

			if(questionInactive  = 1) then
				SET _statement = CONCAT(_statement,' AND DATEDIFF(now(),q.update_date ) > 2 ');
			end if;

			if(questionViaPhone = 1) then
				SET _statement = CONCAT(_statement,' AND tbla.answer_by_phone IS NOT NULL ');
			end if;

			if(statusID is not null) then
				SET _statement = CONCAT(_statement, ' AND q.status_id = ', statusID);
			end if;

			if(qstnpool is not null) then
				SET _statement = CONCAT(_statement, ' AND q.pool_id = ', qstnpool);
				if(poolTypeID is not null and poolTypeID = 1) then
					if(relatedprog is not null) then
						SET _statement = CONCAT(_statement, ' AND  q.related_program_id = ', relatedprog);
					end if;
				elseif(poolTypeID is not null and poolTypeID = 2) then
					if(primaryprog is not null) then
						SET _statement = CONCAT(_statement, ' AND  q.related_program_id = ', primaryprog);
					end if;
					if(relatedprog is not null) then
						SET _statement = CONCAT(_statement, ' AND gp.program_id = ', relatedprog);
					end if;
					
				elseif(poolTypeID is not null and poolTypeID = 3) then
					if(relatedprog is not null) then
						SET _statement = CONCAT(_statement, ' AND q.related_program_id = ', relatedprog);
					end if;
				end if;

			end if;

			if(groupID is not null) then
				if(current_group is not null) then
					if(current_group = 1) then
						SET _statement = CONCAT(_statement, ' AND q.group_id = ', groupID);
					else
						SET _statement = CONCAT(_statement, ' AND assignment.group_id = ', groupID);
					end if;
				end if;
			end if;

			if(firmID is not null) then
				if(current_firm is not null) then
					if(current_firm = 1) then
						SET _statement = CONCAT(_statement, ' AND q.assignee_org_id = ', firmID);
					else
						SET _statement = CONCAT(_statement, ' AND assignment.assignee_org_id = ', groupID);
						SET _statement = CONCAT(_statement, ' OR q.assignee_org_id = ', firmID);
					end if;
				end if;
			end if;
			
			if(requestor is not null) then
				SET _statement = CONCAT(_statement, ' AND  q.requestor_type_id = ', requestor);
			end if;

			if(filter_stateAbbrev is not null) then
				SET _statement = CONCAT(_statement, ' AND  q.requestor_stateid = ', filter_stateAbbrev);
				if(city is not null) then
					SET _statement = CONCAT(_statement, ' AND lc.id = ', city);
				end if;
				if(fieldoffice is not null) then
					SET _statement = CONCAT(_statement, ' AND q.fieldoffice_id = ', fieldoffice);
					if(filter_granteeID is not null) then
						SET _statement = CONCAT(_statement, ' AND gs.granteeid = ', filter_granteeID);
					end if;
				end if;
			end if;
			
			SET _statement = CONCAT(_statement, ' ORDER BY q.update_date DESC');
			if(startIndex is not null AND results_per_page is not null) then
				SET _statement = CONCAT(_statement, ' LIMIT ', startIndex);
				SET _statement = CONCAT(_statement,  ', ',results_per_page);
			end if;

			

			set @stmt = _statement;
			prepare stmt from @stmt;
			execute stmt;
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_um_users_groups` */;
DELIMITER ;;
CREATE DEFINER=`cbirdsong`@`localhost` PROCEDURE `sp_um_users_groups`(IN _useraccess varchar(100) 
									, IN _userid char(35) 
									, IN _userorgid varchar(10) 
									, IN _status varchar(2)
									, IN _component varchar(100)
									, IN _groupid char(35)
									, IN _orgtype varchar(20)
									, IN _orgid varchar(10)
									, IN _username varchar(200)
									, IN _lastname varchar(200)
									, IN _firstname varchar(200)
									, IN _email varchar(200) )
BEGIN

	SET @view = NULL;
	SET @sql = NULL;
	SET SESSION group_concat_max_len = 100000000;

	if ( _useraccess IN ('admin', 'hq', 'fo', 'ta') ) 
		AND (
			_useraccess = 'admin'
			OR (_useraccess IN ('hq', 'fo', 'ta')  AND _userorgid <> '') 
		) then

		SET @view = 'SELECT DISTINCT
					u.userid
					, u.username
					, u.fname
					, u.lname
					, u.email
					, case when (u.inactive = 0) then \'active\' else \'inactive\' end as status
					, u.lastlogin 
					, case when g.groupname = \'Admin\' then 0
						when g.groupname like \'Income Calculator%\'
							or g.groupname like \'HUD Exchange Learn\' then 1
						when g.groupname like \'Ask A Question%\' then 3
						else 2 end as column_order
					, case when SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'Admin\' then
							\'System Administrator\'
						else
						SUBSTRING_INDEX(g.groupname, \' / \', 1) end as group_name 
					, group_concat( distinct
						(
						case when SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'Admin\' THEN \'System Administrator\'
						when SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'Ask A Question\' THEN \'Member\'
						when SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'HUD Exchange Learn\' THEN \'User\'
						when SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'Income Calculator\'
								and replace( SUBSTRING_INDEX(g.groupname, \' / \', -2), \' /\', \'\') = \'Income Calculator\' THEN \'User\'
						when SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'Income Calculator\'
								and replace( SUBSTRING_INDEX(g.groupname, \' / \', -2), \' /\', \'\') = \'Income Calculator Admin\' THEN \'Admin\'
						else
							replace(
								SUBSTRING_INDEX(g.groupname, \' / \', -2)
								, \' /\'
								, \'\'
							)
						end  
						) SEPARATOR \'\n\'
						)
						as role_name 
					, org.attributeValue as Organization ';

		if _component = 'Ask A Question' then
			SET @view = CONCAT(@view, ' , case when ur.pool_id is null then 2 else 1 end as aaqsort
										, ifnull( ifnull(qp.acronym, replace(qp.name, \',\', \'\')), REPLACE(fo.orgname, \',\', \'\')) as aaq
										, concat(r.name, \'/\', p.name) as aaqaccess');

		end if;

			SET @view = CONCAT(@view, ' from tusersmemb m 
				join tusers u on u.userid = m.userid
				join tusers g on g.userid = m.groupid ');

				if _groupid <> '' then
					SET @view = CONCAT(@view, ' AND g.userid = \'', _groupid,'\'');
				end if;
			
			
			SET @view = CONCAT(@view, '
				LEFT JOIN tclassextenddatauseractivity org on org.baseid = m.userid AND org.attributeID = (SELECT attributeID FROM tclassextendattributes WHERE name = \'organization_name\') ');

			
			if _orgtype <> '' or _useraccess <> 'admin' then
				SET @view = CONCAT(@view, '
					JOIN tclassextenddatauseractivity ot on ot.baseID = u.UserID');
				if _orgtype <> '' then
				SET @view = CONCAT(@view, '
					AND FIND_IN_SET(\'', _orgtype, '\', ot.attributeValue) ');
				end if;
				if _useraccess <> 'admin' and _useraccess <> _orgtype then
				SET @view = CONCAT(@view, '
					AND FIND_IN_SET(\'', _useraccess, '\', ot.attributeValue) ');
				end if;
				SET @view = CONCAT(@view, '
					JOIN tclassextendattributes ota on ota.attributeID = ot.attributeID and ota.name = \'orgtype\'');
			end if;

			
			if _orgid <> '' or _useraccess <> 'admin' then
				SET @view = CONCAT(@view, '
					JOIN tclassextenddatauseractivity orgid on orgid.baseID = u.UserID');
				if _orgid <> '' then
					SET @view = CONCAT(@view, '
						AND FIND_IN_SET(\'', _orgid, '\', orgid.attributeValue)');
				end if;
				if _useraccess <> 'admin' and _userorgid <> _orgid then
					SET @view = CONCAT(@view, '
						AND FIND_IN_SET(\'', _userorgid, '\', orgid.attributeValue)');
				end if;
						
				SET @view = CONCAT(@view, '
					JOIN tclassextendattributes orgida on orgida.attributeID = orgid.attributeID and orgida.name = \'orgid\'');
			end if;
			
		

		if _component = 'Ask A Question' then
			SET @view = CONCAT(@view, '
				left JOIN aaq_tbl_user_role ur on ur.user_id = m.userid
				left join aaq_lku_role r on r.id = ur.role_id
				left join aaq_lku_permission p on p.id = ur.permission_id
				left join aaq_lku_pool qp on qp.id = ur.pool_id
				left join c_torganizations fo on fo.orgid = ur.fieldoffice_id
			');
		end if;

			SET @view = CONCAT(@view, ' WHERE u.siteID = \'mysite\'
											AND	u.type = 2
											AND (u.username <> \'admin\')
											AND (u.username <> \'mysiteadmin\') 
											 ');
		
		if _useraccess <> 'admin' then
			SET @view = CONCAT(@view, '
				AND u.isPublic = 1
				AND u.userID <> \'_userid\'');
		end if;

		if _username <> '' then
			SET @view = CONCAT(@view, ' AND u.username LIKE \'%', _username, '%\'');
		end if;

		if _lastname <> '' then
			SET @view = CONCAT(@view, ' AND u.lname LIKE \'%', _lastname, '%\'');
		end if;

		if _firstname <> '' then
			SET @view = CONCAT(@view, ' AND u.fname LIKE \'%', _firstname, '%\'');
		end if;

		if _email <> '' then
			SET @view = CONCAT(@view, ' AND u.email LIKE \'%', _email, '%\'');
		end if;

		if _status <> '' then
			SET @view = CONCAT(@view, ' AND u.inactive = ', _status);
		end if;

		if _component <> '' then
			
			SET @view = CONCAT(@view, ' AND SUBSTRING_INDEX(g.groupname, \' / \', 1) = \'', _component, '\'');
		end if;

		
		SET @view = CONCAT(@view, ' group by username, group_name');



		if _component = 'Ask A Question' then
			SET @component = CONCAT( 'SELECT
						  CONCAT_ws(\',\', 
							\'case when group_name = \'\'Ask A Question\'\' then role_name else null end AS `Ask A Question`\',
							GROUP_CONCAT(DISTINCT
							CONCAT(
								  \'case when aaq = \'\'\',
								  aaq,
								  \'\'\' then aaqaccess else NULL end AS `\',
								  aaq, \'`\' 
								) order by aaqsort, aaq
							  )
							) INTO @sql
						FROM (', @view, ') v');
		else
			SET @component = CONCAT( 'SELECT
						  GROUP_CONCAT(DISTINCT
							CONCAT(
							  \'case when group_name = \'\'\',
							  group_name,
							  \'\'\' then role_name else NULL end AS `\',
							  group_name, \'`\' 
							) order by column_order, group_name
						  ) INTO @sql
						FROM (', @view, ') v');
		end if;

		PREPARE stmt FROM @component;
		EXECUTE stmt;
		DEALLOCATE PREPARE stmt;
	
	end if; 

	if @sql is not null then
		SET @sql = CONCAT('SELECT username as `User_Name`
								, fname as `First_Name`
								, lname as `Last_Name`
								, email as `Email`
								, Organization
								, status as `Status`
								, lastlogin as `Last_Login`
								, ', @sql, ' 
								, userid
						  from (', @view, ') v
						  group by username');

		PREPARE stmt FROM @sql;
		EXECUTE stmt;
		DEALLOCATE PREPARE stmt;
	end if;
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `tap_getAllAssignmentInfo` */;
DELIMITER ;;
CREATE DEFINER=`mkim`@`%` PROCEDURE `tap_getAllAssignmentInfo`(
	IN assignmentid INT
	, OUT currentTAProviderFirm VARCHAR(255)
	, OUT oldTAProviderFirm VARCHAR(255)
)
BEGIN

DECLARE currentTATypeID int;
DECLARE currentTAProviderID int;
DECLARE oldTAProviderID int;


SELECT 
	tta.tatype 
	, tta.taproviderid
	, taau.oldtaprovider
	, providerFirm.orgname
	, OLDproviderFirm.orgname
INTO
	currentTATypeID
	, currentTAProviderID
	, oldTAProviderID
	, currentTAProviderFirm
	, oldTAProviderFirm
FROM
	tap_tbl_assignment tta
INNER JOIN
	c_torganizations providerFirm
ON
	providerFirm.orgid = tta.taproviderid
LEFT JOIN
	tap_asc_assignment_updatenotice taau
ON
	taau.assignmentid = tta.id
LEFT JOIN
	c_torganizations OLDproviderFirm
ON
	OLDproviderFirm.orgid = taau.oldtaprovider

WHERE
	tta.id = assignmentid
;	


IF find_in_set(currentTATypeID, '2,3')
THEN
	/* OnCall and Outreach workplans */    
	SELECT
		tta.id as assignmentid
		, tta.requestid
		, tta.taproviderid
		, org.orgname
		, org.orgid
		, tta.scopedescription
		, replace(scopedescription , '\n', '<br />') scopedescription_formatted
		, tta.noticesent
		, tta.tatype as tatypeid
		, tatype.name as tatype
		, tta.createnew_wp
		, tta.createnew_outreachwp
		, tta.assignedby
		, assignedBy.fname as assignedByFname
		, assignedBy.lname as assignedByLname
		, wp.id as workplanid
		, wp.status
		, if(IsNull(wp.name_granteeid), concat(tc.coc_no, ' - ', tc.coc_name) , cto.orgname) as granteename
		, wp.periodofperformance
		, wp.tatype
        /* hud_submitted field is not entirely reliable as a subset of old data doesn't have this set
			Hence use submitteddate */
        , case 
			when amd.parent_wpid is not null then !isnull(origwp.submitteddate)	/*parent's submitted date*/
            else !isnull(wp.submitteddate)
		  end hud_submitted
		, Date_format(tta.noticesent_date,'%m/%d/%Y') as noticesent_date
		, Date_format(tta.datecreated,'%m/%d/%Y') as datecreated
		, Date_format(tta.lastupdated,'%m/%d/%Y') as lastupdated
		, tta.lastupdatedby
		, lastupdatedBy.fname as lastupdatedByFname
		, lastupdatedBy.lname as lastupdatedByLname
		, tta.sentby
		, sentBy.fname as sentByFname
		, sentBy.lname as sentByLname
	FROM  tap_tbl_assignment tta
		inner join tap_lku_tatype tatype on tatype.id = tta.tatype
		inner join c_torganizations as org on org.orgid = tta.taproviderid
		left join tap_asc_oncallwp_assignment ocwpa ON ocwpa.assignmentid = tta.id  and ocwpa.association_completed = 1 
        left join tap_tbl_workplan wp on wp.id = ocwpa.workplanid 
        /*get original workplan if this is an amendment */
        left join tap_asc_amendment amd on wp.id = amd.amended_wp
        left join tap_tbl_workplan origwp on amd.parent_wpid = origwp.id
        
		left join c_tcoc tc on tc.coc_no = wp.name_coc_no
		left join c_torganizations cto on cto.orgid = wp.name_granteeid
		INNER JOIN tusers assignedBy ON assignedBy.userid = tta.assignedby
		LEFT JOIN tusers lastupdatedBy ON lastupdatedBy.userid = tta.lastupdatedby
		LEFT JOIN tusers sentBy ON sentBy.userid = tta.sentby
	WHERE tta.id = assignmentid
	ORDER BY tta.id ASC
	;
    
    /* Funding Sources */
	SELECT 	Distinct
		A.fundingsourceid, 
		CONCAT(latestliveidwp.workplan_name, '-', A.fundingsource_name) as name,
		latestliveidwp.id as workplanid, 
		A.assignmentid, 
		A.fundingsource, 
		A.tatype,
		A.workplan_num			
	FROM (
			SELECT DISTINCT 
				fs.id as fundingsourceid
				, fs.name as fundingsource_name
				, CONCAT(wp.workplan_name, '-', fs.name) as name
				, workplanid
				, aswp.assignmentid
				, wp.fundingsource
				, wp.tatype
				, wp.workplan_num
			FROM 
				tap_asc_oncallwp_assignment aswp
			INNER JOIN
				tap_tbl_workplan wp 
			ON 
				wp.id = aswp.workplanid
			INNER JOIN
				tap_tbl_assignment a 
			ON 
				aswp.assignmentid = a.id
			INNER JOIN
				tap_lku_fundingsource fs 
			ON 
				fs.id= wp.fundingsource
			WHERE
				aswp.assignmentid = assignmentid
			AND
				wp.approveddate is not null
		) A
		JOIN tap_tbl_workplan as latestliveidwp					
		LEFT JOIN tap_vw_workplanVersionData as tvwvd 
			ON Find_in_set(A.workplanid, tvwvd.versionTrail)					
		WHERE
			CASE
				WHEN IsNull(tvwvd.latestliveid) 
				THEN latestliveidwp.id = A.workplanid
				ELSE latestliveidwp.id = tvwvd.latestliveid
			END
	;
ELSE
	/*Workplans other than OnCall and Outreach*/
	SELECT
		tta.id as assignmentid
		, tta.requestid
		, tta.taproviderid
		, org.orgname
		, org.orgid
		, tta.scopedescription
		, replace(scopedescription , '\n', '<br />') scopedescription_formatted
		, tta.noticesent
		, tta.tatype as tatypeid
		, tatype.name as tatype
		, tta.createnew_wp
		, tta.createnew_outreachwp
		, tta.assignedby
		, assignedBy.fname as assignedByFname
		, assignedBy.lname as assignedByLname
		, wp.id as workplanid
		, wp.status
		, if(IsNull(wp.name_granteeid), concat(tc.coc_no, ' - ', tc.coc_name) , cto.orgname) as granteename
		, wp.periodofperformance
		, wp.tatype
		, wp.hud_submitted
		, Date_format(tta.noticesent_date,'%m/%d/%Y') as noticesent_date
		, Date_format(tta.datecreated,'%m/%d/%Y') as datecreated
		, Date_format(tta.lastupdated,'%m/%d/%Y') as lastupdated
		, tta.lastupdatedby
		, lastupdatedBy.fname as lastupdatedByFname
		, lastupdatedBy.lname as lastupdatedByLname
		, tta.sentby
		, sentBy.fname as sentByFname
		, sentBy.lname as sentByLname
	FROM 
		tap_tbl_assignment tta
		inner join 
			tap_lku_tatype tatype 
		on 
			tatype.id = tta.tatype
		inner join 
			c_torganizations as org 
		on 
			org.orgid = tta.taproviderid
		left join 
			tap_tbl_workplan wp
		on 
			(
				-- wp.status !=7
			-- AND
				wp.assignmentid = tta.id 
			and 
				wp.isAmendment=0
			and wp.isVersion = 0
			)
		left join
			c_tcoc tc
		on
			tc.coc_no = wp.name_coc_no
		left join
			c_torganizations cto
		on
			cto.orgid = wp.name_granteeid
		INNER JOIN tusers assignedBy ON assignedBy.userid = tta.assignedby
		LEFT JOIN tusers lastupdatedBy ON lastupdatedBy.userid = tta.lastupdatedby
		LEFT JOIN tusers sentBy ON sentBy.userid = tta.sentby
	WHERE
		tta.id = assignmentid
	ORDER BY
		tta.id ASC
	;

	/* Funding Sources */
	SELECT DISTINCT
		tawf.fundingsourceid
		, fs.name
		, wp.id
		, wp.assignmentid
		, taa.parent_wpid
	FROM 
		tap_asc_workplan_fundingsource tawf
	INNER JOIN 
		tap_tbl_workplan wp 
	ON
		wp.id = tawf.workplanid
	LEFT OUTER JOIN
		tap_asc_amendment taa
	ON
		wp.id = taa.amended_wp
	INNER JOIN 
		tap_tbl_assignment a 
	ON
		wp.assignmentid = a.id
	INNER JOIN
		tap_lku_fundingsource fs 
	ON
		fs.id = tawf.fundingsourceid
	WHERE
		wp.assignmentid = assignmentid
	AND
		wp.status !=7
	AND
		taa.parent_wpid is null
	;
END IF;

/* Current TA Providers */
SELECT 
	u.UserID
	, u.username
	, CONCAT(u.Fname,' ', u.Lname) as Name
	, u.email
	,orgid
	, orgname
	,u.mobilephone
FROM tusers u
	JOIN 
		tusersmemb sm 
	ON 
		sm.UserID = u.UserID
	LEFT OUTER JOIN (
		select 
			baseid
			, attributeValue
			, tclassextendattributes.attributeid
		from 
			tclassextenddatauseractivity
			inner join 
				tclassextendattributes
			on (
					tclassextenddatauseractivity.attributeID = tclassextendattributes.attributeID
				and 
					name = 'orgid'
				)
		where 
			attributeValue is not null
	) as ta
		on ta.baseID = u.UserID
	JOIN 
		tusers g 
	ON (
			g.UserID = sm.GroupID 
		AND 
			g.groupName = 'TA Management System / TA Provider / Manager'
		)
	JOIN 
		c_torganizations o 
	ON 
		o.orgid = ta.attributeValue
WHERE
	orgid =  currentTAProviderID
AND
	u.inactive = 0
ORDER BY
	u.Lname
;

/* Old TA Providers */
SELECT 
	u.UserID
	, u.username
	, CONCAT(u.Fname,' ', u.Lname) as Name
	, u.email
	,orgid
	, orgname
	,u.mobilephone
FROM tusers u
	JOIN 
		tusersmemb sm 
	ON 
		sm.UserID = u.UserID
	LEFT OUTER JOIN (
		select 
			baseid
			, attributeValue
			, tclassextendattributes.attributeid
		from 
			tclassextenddatauseractivity
			inner join 
				tclassextendattributes
			on (
					tclassextenddatauseractivity.attributeID = tclassextendattributes.attributeID
				and 
					name = 'orgid'
				)
		where 
			attributeValue is not null
	) as ta
		on ta.baseID = u.UserID
	JOIN 
		tusers g 
	ON (
			g.UserID = sm.GroupID 
		AND 
			g.groupName = 'TA Management System / TA Provider / Manager'
		)
	JOIN 
		c_torganizations o 
	ON 
		o.orgid = ta.attributeValue
WHERE
	orgid =  oldTAProviderID
AND
	u.inactive = 0
ORDER BY
	u.Lname
;


END ;;
DELIMITER ;

--
-- Final view structure for view `cal_vw_classes`
--

/*!50001 DROP TABLE IF EXISTS `cal_vw_classes`*/;
/*!50001 DROP VIEW IF EXISTS `cal_vw_classes`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `cal_vw_classes` AS select `e`.`id` AS `eventID`,`e`.`isHUD` AS `isHudEvent`,`e`.`event_type_id` AS `courseTypeID`,`e`.`name` AS `courseName`,`m`.`id` AS `classID`,`m`.`server_start` AS `serverStart`,`m`.`server_end` AS `serverEnd`,`m`.`timezone_start` AS `classStart`,`m`.`timezone_end` AS `classEnd`,`m`.`timezone_display` AS `timezone`,`e`.`teaser` AS `courseTeaser`,`l`.`id` AS `locationID`,`l`.`city` AS `locationCity`,`l`.`state_abbrev` AS `locationStateAbbrev`,`l`.`city` AS `city`,`l`.`state_abbrev` AS `stateAbbrev`,`et`.`description` AS `courseType`,`m`.`name` AS `className`,`m`.`summary` AS `classSummary`,`m`.`description` AS `classDescription`,`m`.`LMS_class_id` AS `lmsClassID`,(select group_concat(`h`.`name` separator ',') from (`cal_tbl_host` `h` join `cal_asc_event_host` `eh`) where ((`eh`.`event_id` = `e`.`id`) and (`h`.`id` = `eh`.`host_id`)) order by `h`.`name`) AS `hosts`,(case when (isnull(`e`.`LMS_course_id`) and (`m`.`status` = 'Active')) then 1 when ((`e`.`LMS_course_id` is not null) and (`e`.`status` = 'Active') and (`m`.`status` = 'Active')) then 1 else 0 end) AS `isPublished`,(case when (`e`.`LMS_course_id` is not null) then `m`.`SESUrl` else `e`.`SESUrl` end) AS `SESUrl`,(case when isnull(`m`.`location_id`) then 1 else 0 end) AS `isOnline` from ((`cal_tbl_event` `e` join `cal_lku_event_type` `et`) join (`cal_tbl_meeting` `m` left join `cal_tbl_location` `l` on((`l`.`id` = `m`.`location_id`)))) where ((`m`.`event_id` = `e`.`id`) and (`et`.`id` = `e`.`event_type_id`) and (`m`.`status` <> 'Archived') and (`m`.`isPrivateClass` = 0)) */;

--
-- Final view structure for view `cal_vw_courses`
--

/*!50001 DROP TABLE IF EXISTS `cal_vw_courses`*/;
/*!50001 DROP VIEW IF EXISTS `cal_vw_courses`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `cal_vw_courses` AS select distinct `e`.`id` AS `courseID`,(select group_concat(distinct `cal_asc_event_topic`.`topic_type_id` separator ',') from `cal_asc_event_topic` where (`cal_asc_event_topic`.`event_id` = `e`.`id`)) AS `topicTypeList`,(select group_concat(cast(concat(`cal_asc_event_topic`.`topic_type_id`,':',`cal_asc_event_topic`.`topic_id`) as char charset utf8) separator ',') from `cal_asc_event_topic` where (`cal_asc_event_topic`.`event_id` = `e`.`id`)) AS `topicList`,`e`.`event_type_id` AS `courseTypeID`,`e`.`name` AS `courseName`,`e`.`teaser` AS `courseTeaser`,cast(`e`.`isFeaturedCourse` as signed) AS `isFeaturedCourse`,`e`.`created_date` AS `createdDate`,`e`.`updated_date` AS `lastUpdated`,`e`.`LMS_course_type` AS `lmsCourseType`,`e`.`LMS_course_cd` AS `LMSCourseCd`,`et`.`description` AS `courseType`,`e`.`SESUrl` AS `courseSESUrl`,(case when (`e`.`status` = 'Active') then 1 else 0 end) AS `isPublished`,0 AS `isLearningPlan`,`e`.`posted_on_date` AS `postedDate`,`e`.`description` AS `courseDescription`,cast(`e`.`isHUD` as signed) AS `isHUD`,`e`.`updated_date` AS `updated_date` from ((`cal_tbl_event` `e` left join `cal_tbl_meeting` `m` on((`m`.`event_id` = `e`.`id`))) left join `cal_lku_event_type` `et` on((`et`.`id` = `e`.`event_type_id`))) where ((`e`.`LMS_course_id` is not null) and (`e`.`status` <> 'Archived') and (`e`.`isHybridCourse` = 0) and (`e`.`isLearningPlanOnly` <> 1)) union select distinct `lp`.`id` AS `courseID`,(select group_concat(distinct `aet`.`topic_type_id` separator ',') from (`cal_asc_event_topic` `aet` join `cal_asc_learning_plan_event` `lpe`) where ((`lpe`.`learning_plan_id` = `lp`.`id`) and (`aet`.`event_id` = `lpe`.`event_id`))) AS `topicTypeList`,(select group_concat(cast(concat(`aet`.`topic_type_id`,':',`aet`.`topic_id`) as char charset utf8) separator ',') from (`cal_asc_event_topic` `aet` join `cal_asc_learning_plan_event` `lpe`) where ((`lpe`.`learning_plan_id` = `lp`.`id`) and (`aet`.`event_id` = `lpe`.`event_id`))) AS `topicList`,2 AS `courseTypeID`,`lp`.`name` AS `courseName`,`lp`.`summary` AS `courseTeaser`,`lp`.`isFeaturedCourse` AS `isFeaturedCourse`,`lp`.`created_date` AS `createdDate`,`lp`.`updated_date` AS `lastUpdated`,'OLT' AS `lmsCourseType`,NULL AS `LMSCourseCd`,'Self-Paced Online Training' AS `courseType`,`lp`.`SESUrl` AS `courseSESUrl`,(case when (`lp`.`status` = 'Active') then 1 else 0 end) AS `isPublished`,1 AS `isLearningPlan`,`lp`.`posted_on_date` AS `postedDate`,`lp`.`description` AS `courseDescription`,cast(0 as signed) AS `isHUD`,`lp`.`updated_date` AS `updated_date` from `cal_tbl_learning_plan` `lp` where (`lp`.`status` <> 'Archived') */;

--
-- Final view structure for view `cal_vw_deadline_topics`
--

/*!50001 DROP TABLE IF EXISTS `cal_vw_deadline_topics`*/;
/*!50001 DROP VIEW IF EXISTS `cal_vw_deadline_topics`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `cal_vw_deadline_topics` AS (select `dt`.`deadline_id` AS `deadlineID`,`dt`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`dt`.`topic_id` AS `topicID`,`p`.`program_short` AS `topicAcronym`,`p`.`program_description` AS `topicName`,(case when (`p`.`program_short` = '') then `p`.`program_description` else concat(`p`.`program_short`,'-',`p`.`program_description`) end) AS `topicFullName` from ((`cal_asc_deadline_topic` `dt` join `cal_lku_topic_type` `tt`) join `rsc_tbl_program` `p`) where ((`tt`.`id` = `dt`.`topic_type_id`) and (`tt`.`id` = 1) and (`p`.`program_id` = `dt`.`topic_id`))) union (select `dt`.`deadline_id` AS `deadlineID`,`dt`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`dt`.`topic_id` AS `topicID`,(case when (`rs`.`system_id` = 1) then NULL else `rs`.`system_short` end) AS `topicAcronym`,(case when (`rs`.`system_id` = 1) then 'eCon Planning Suite' else `rs`.`system_name` end) AS `topicName`,(case when (`rs`.`system_short` = '') then `rs`.`system_name` else concat(`rs`.`system_short`,'-',`rs`.`system_name`) end) AS `topicFullName` from ((`cal_asc_deadline_topic` `dt` join `cal_lku_topic_type` `tt`) join `rsc_lku_reporting_system` `rs`) where ((`tt`.`id` = `dt`.`topic_type_id`) and (`tt`.`id` = 3) and (`rs`.`system_id` = `dt`.`topic_id`))) union (select `dt`.`deadline_id` AS `deadlineID`,`dt`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`dt`.`topic_id` AS `topicID`,`cc`.`ccr_short` AS `topicAcronym`,`cc`.`ccr_name` AS `topicName`,(case when (`cc`.`ccr_short` = '') then `cc`.`ccr_name` else concat(`cc`.`ccr_short`,'-',`cc`.`ccr_name`) end) AS `topicFullName` from ((`cal_asc_deadline_topic` `dt` join `cal_lku_topic_type` `tt`) join `rsc_lku_ccr` `cc`) where ((`tt`.`id` = `dt`.`topic_type_id`) and (`tt`.`id` = 2) and (`cc`.`ccr_id` = `dt`.`topic_id`))) union (select `dt`.`deadline_id` AS `deadlineID`,`dt`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`dt`.`topic_id` AS `topicID`,NULL AS `topicAcronym`,`at`.`topic_name` AS `topicName`,`at`.`topic_name` AS `topicFullName` from ((`cal_asc_deadline_topic` `dt` join `cal_lku_topic_type` `tt`) join `rsc_lku_topic` `at`) where ((`tt`.`id` = `dt`.`topic_type_id`) and (`tt`.`id` = 4) and (`at`.`topic_id` = `dt`.`topic_id`))) union (select `dt`.`deadline_id` AS `deadlineID`,`dt`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`dt`.`topic_id` AS `topicID`,NULL AS `topicAcronym`,`pm`.`topic_name` AS `topicName`,`pm`.`topic_name` AS `topicFullName` from ((`cal_asc_deadline_topic` `dt` join `cal_lku_topic_type` `tt`) join `rsc_lku_topic` `pm`) where ((`tt`.`id` = `dt`.`topic_type_id`) and (`tt`.`id` = 5) and (`pm`.`topic_id` = `dt`.`topic_id`))) */;

--
-- Final view structure for view `cal_vw_deadlines`
--

/*!50001 DROP TABLE IF EXISTS `cal_vw_deadlines`*/;
/*!50001 DROP VIEW IF EXISTS `cal_vw_deadlines`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `cal_vw_deadlines` AS select `d`.`id` AS `deadlineID`,`d`.`name` AS `name`,`d`.`start_date` AS `startDate`,`d`.`end_date` AS `endDate`,`d`.`description` AS `description`,`d`.`url` AS `deadlineUrl`,`d`.`url_link_display` AS `url_link_display`,`d`.`display` AS `isPublished`,`d`.`updated_date` AS `lastUpdated` from `cal_tbl_deadline` `d` */;

--
-- Final view structure for view `cal_vw_event_topics`
--

/*!50001 DROP TABLE IF EXISTS `cal_vw_event_topics`*/;
/*!50001 DROP VIEW IF EXISTS `cal_vw_event_topics`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `cal_vw_event_topics` AS select `et`.`event_id` AS `eventID`,`et`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`et`.`topic_id` AS `topicID`,`p`.`program_short` AS `topicAcronym`,`p`.`program_description` AS `topicName`,(case when (`p`.`program_short` = '') then `p`.`program_description` else concat(`p`.`program_short`,'-',`p`.`program_description`) end) AS `topicFullName`,`tt`.`order_by` AS `order_by`,(case when (`cat`.`masterNameShort` <> '') then `cat`.`masterNameShort` else `cat`.`masterNameLong` end) AS `masterNameShort`,`cat`.`masterNameLong` AS `masterNameLong` from (((`cal_asc_event_topic` `et` join `cal_lku_topic_type` `tt` on(((`tt`.`id` = `et`.`topic_type_id`) and (`tt`.`id` = 1)))) join `rsc_tbl_program` `p` on((`p`.`program_id` = `et`.`topic_id`))) join `c_tcategories` `cat` on((`p`.`program_id` = `cat`.`rsc_programID`))) union select `et`.`event_id` AS `eventID`,`et`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`et`.`topic_id` AS `topicID`,(case when (`rs`.`system_id` = 1) then NULL else `rs`.`system_short` end) AS `topicAcronym`,(case when (`rs`.`system_id` = 1) then 'eCon Planning Suite' else `rs`.`system_name` end) AS `topicName`,(case when (`rs`.`system_short` = '') then `rs`.`system_name` else concat(`rs`.`system_short`,'-',`rs`.`system_name`) end) AS `topicFullName`,`tt`.`order_by` AS `order_by`,(case when (`cat`.`masterNameShort` <> '') then `cat`.`masterNameShort` else `cat`.`masterNameLong` end) AS `masterNameShort`,`cat`.`masterNameLong` AS `masterNameLong` from (((`cal_asc_event_topic` `et` join `cal_lku_topic_type` `tt` on(((`tt`.`id` = `et`.`topic_type_id`) and (`tt`.`id` = 3)))) join `rsc_lku_reporting_system` `rs` on((`rs`.`system_id` = `et`.`topic_id`))) join `c_tcategories` `cat` on((`rs`.`system_id` = `cat`.`rsc_reportID`))) union select `et`.`event_id` AS `eventID`,`et`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`et`.`topic_id` AS `topicID`,`cc`.`ccr_short` AS `topicAcronym`,`cc`.`ccr_name` AS `topicName`,(case when (`cc`.`ccr_short` = '') then `cc`.`ccr_name` else concat(`cc`.`ccr_short`,'-',`cc`.`ccr_name`) end) AS `topicFullName`,`tt`.`order_by` AS `order_by`,(case when (`cat`.`masterNameShort` <> '') then `cat`.`masterNameShort` else `cat`.`masterNameLong` end) AS `masterNameShort`,`cat`.`masterNameLong` AS `masterNameLong` from (((`cal_asc_event_topic` `et` join `cal_lku_topic_type` `tt` on(((`tt`.`id` = `et`.`topic_type_id`) and (`tt`.`id` = 2)))) join `rsc_lku_ccr` `cc` on((`cc`.`ccr_id` = `et`.`topic_id`))) join `c_tcategories` `cat` on((`cc`.`ccr_id` = `cat`.`rsc_ccrID`))) union select `et`.`event_id` AS `eventID`,`et`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`et`.`topic_id` AS `topicID`,NULL AS `topicAcronym`,`at`.`topic_name` AS `topicName`,`at`.`topic_name` AS `topicFullName`,`tt`.`order_by` AS `order_by`,NULL AS `masterNameShort`,`at`.`topic_name` AS `masterNameLong` from ((`cal_asc_event_topic` `et` join `cal_lku_topic_type` `tt` on(((`tt`.`id` = `et`.`topic_type_id`) and (`tt`.`id` = 4)))) join `rsc_lku_topic` `at` on((`at`.`topic_id` = `et`.`topic_id`))) union select `et`.`event_id` AS `eventID`,`et`.`topic_type_id` AS `topicTypeID`,`tt`.`type` AS `topicTypeName`,`et`.`topic_id` AS `topicID`,NULL AS `topicAcronym`,`pm`.`topic_name` AS `topicName`,`pm`.`topic_name` AS `topicFullName`,`tt`.`order_by` AS `order_by`,NULL AS `masterNameShort`,`pm`.`topic_name` AS `masterNameLong` from ((`cal_asc_event_topic` `et` join `cal_lku_topic_type` `tt` on(((`tt`.`id` = `et`.`topic_type_id`) and (`tt`.`id` = 5)))) join `rsc_lku_topic` `pm` on((`pm`.`topic_id` = `et`.`topic_id`))) order by `order_by`,`topicName` */;

--
-- Final view structure for view `cal_vw_nonhud_events`
--

/*!50001 DROP TABLE IF EXISTS `cal_vw_nonhud_events`*/;
/*!50001 DROP VIEW IF EXISTS `cal_vw_nonhud_events`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `cal_vw_nonhud_events` AS select `e`.`id` AS `eventID`,`e`.`name` AS `name`,`e`.`description` AS `description`,`e`.`updated_date` AS `lastUpdated`,`m`.`server_start` AS `serverStart`,`m`.`server_end` AS `serverEnd`,`m`.`timezone_start` AS `classStart`,`m`.`timezone_end` AS `classEnd`,`e`.`status` AS `status`,`e`.`event_type_id` AS `eventTypeID`,(case when (`e`.`status` = 'Active') then 1 else 0 end) AS `isPublished` from (`cal_tbl_event` `e` join `cal_tbl_meeting` `m`) where (isnull(`e`.`LMS_course_id`) and (`m`.`event_id` = `e`.`id`)) */;

--
-- Final view structure for view `faq_vw_getsearchtitles`
--

/*!50001 DROP TABLE IF EXISTS `faq_vw_getsearchtitles`*/;
/*!50001 DROP VIEW IF EXISTS `faq_vw_getsearchtitles`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `faq_vw_getsearchtitles` AS select distinct `fpm`.`contentID` AS `contentID`,`fpm`.`id` AS `id`,substring_index(`fpm`.`nodePath`,',',1) AS `rootID`,(select `tcd2`.`attributeValue` from (`tclassextenddata` `tcd2` join `tclassextendattributes` `tca2` on((`tcd2`.`attributeID` = `tca2`.`attributeID`))) where ((`tcd2`.`baseID` = (select `t`.`ContentHistID` from `tcontent` `t` where (`t`.`ContentID` = substring_index(`fpm`.`nodePath`,',',1)) order by `t`.`TContent_ID` desc limit 1)) and (`tca2`.`name` = 'faqSearchLabel'))) AS `searchLabel` from `faq_parent_mapping` `fpm` */;

--
-- Final view structure for view `faq_vw_relatedprograms`
--

/*!50001 DROP TABLE IF EXISTS `faq_vw_relatedprograms`*/;
/*!50001 DROP VIEW IF EXISTS `faq_vw_relatedprograms`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `faq_vw_relatedprograms` AS select `p`.`contentID` AS `contentID`,group_concat(`l`.`filterText` separator ',') AS `filters` from ((`faq_parent_mapping` `p` left join `faq_asc_parent_filters` `pf` on((`pf`.`parentID` = `p`.`id`))) left join `faq_lku_filters` `l` on((`l`.`id` = `pf`.`filterID`))) group by `p`.`contentID` */;

--
-- Final view structure for view `gt_vw_coc_page`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_coc_page`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_coc_page`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_coc_page` AS select `d`.`attributeValue` AS `coc_no`,`c`.`Filename` AS `filename` from ((((`tclassextend` `e` join `tclassextendsets` `es` on((`es`.`subTypeID` = `e`.`subTypeID`))) join `tclassextendattributes` `a` on((`a`.`extendSetID` = `es`.`extendSetID`))) join `tclassextenddata` `d` on((`d`.`attributeID` = `a`.`attributeID`))) join `tcontent` `c` on((`c`.`ContentHistID` = `d`.`baseID`))) where ((`c`.`Active` = 1) and (`c`.`Approved` = 1) and (`c`.`Display` = 1) and (`e`.`subType` = 'CoC')) */;

--
-- Final view structure for view `gt_vw_coc_report`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_coc_report`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_coc_report`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_coc_report` AS select concat('/reports/',`r`.`filename`) AS `path`,(case when ((`r`.`program` = 'CoC') and (`r`.`group` = 'GIS')) then concat(' ',year(`r`.`periodEnd`),' ',`tt`.`label`,' - ',`r`.`state`,(case when (`tt`.`code` = 'ShapeFile') then ' CoCs' else '' end)) when (`r`.`program` = 'CoC') then concat(' ',year(`r`.`periodEnd`),' ',`t`.`label`,(case when (`c`.`label` <> '') then concat(' - ',`c`.`label`) when (`s`.`label` <> '') then concat(' - ',`s`.`label`) else '' end)) when (`r`.`program` = 'HOPWA') then concat(year(`r`.`periodEnd`),'-',(year(`r`.`periodEnd`) + 1),' ',`t`.`label`,(case when (`g`.`name` is not null) then concat(' - ',`g`.`name`) else '' end)) when (`r`.`program` = 'NSP') then concat(`t`.`label`,(case when (`gt`.`label` is not null) then concat(' - ',`gt`.`label`,' Grantee') else '' end),(case when (`g`.`name` is not null) then concat(' - ',`g`.`name`) else '' end),(case when (`r`.`group` = 'QPR') then concat(' - ',(case when (month(`r`.`periodEnd`) <= 3) then concat('Q1 ',year(`r`.`periodEnd`)) when ((month(`r`.`periodEnd`) > 3) and (month(`r`.`periodEnd`) <= 6)) then concat('Q2 ',year(`r`.`periodEnd`)) when ((month(`r`.`periodEnd`) > 6) and (month(`r`.`periodEnd`) <= 9)) then concat('Q3 ',year(`r`.`periodEnd`)) else concat('Q4 ',year(`r`.`periodEnd`)) end)) when (`r`.`periodEnd` is not null) then concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')) else '' end)) when (`r`.`program` = 'HOME') then concat(`t`.`label`,(case when (`r`.`group` = 'Dash') then concat(ifnull(concat(' - ',`g`.`name`),''),ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Vacant') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Open') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when ((`r`.`group` = 'Snap') and (`r`.`scope` = 'PJ')) then concat(ifnull(concat(' - ',`g`.`name`),''),ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when ((`r`.`group` = 'Snap') and (`r`.`scope` <> 'PJ')) then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when (`r`.`group` = 'Prod') then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when (`r`.`group` = 'Act') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'ActHB') then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when ((`r`.`group` = 'Cancel') and (`r`.`periodEnd` is not null)) then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when ((`r`.`group` = 'Cancel') and isnull(`r`.`periodEnd`)) then ifnull(concat(' - ',`r`.`fiscalYear`),'') when (`r`.`group` = 'Exp') then concat(' - FY ',`r`.`fiscalYear`,(case when (`r`.`periodEnd` is not null) then ' or Earlier Expiring Funds' else '  Expired Funds' end),' - All States',ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) else '' end)) when (`r`.`program` = 'CDBG') then concat(`t`.`label`,ifnull(concat(' - ',`g`.`name`),''),' - PY',year(`r`.`periodEnd`)) when (`r`.`program` = 'CPD') then concat(`t`.`label`,' ',`rt`.`label`,ifnull(concat(' - ',`g`.`name`),'')) else `t`.`label` end) AS `report_display_name`,substring_index(`r`.`filename`,'.',-(1)) AS `doctype`,year(`r`.`periodEnd`) AS `year`,`r`.`periodEnd` AS `periodEnd`,left(`r`.`COC`,6) AS `coc_no` from ((((((((`rpt_report` `r` join `rpt_type` `t` on(((`r`.`program` = `t`.`program`) and (`r`.`group` = `t`.`group`) and (`r`.`scope` = `t`.`scope`)))) join `rpt_scope` `sc` on((`sc`.`code` = `r`.`scope`))) left join `rpt_coc` `c` on((`c`.`code` = `r`.`COC`))) left join `rpt_grantee` `g` on((`g`.`code` = `r`.`grantee`))) left join `rpt_state` `s` on((`s`.`code` = `r`.`state`))) left join `rpt_grant_type` `gt` on((`gt`.`code` = `r`.`grantType`))) left join `rpt_tool_type` `tt` on((`r`.`toolType` = `tt`.`code`))) left join `rpt_report_type` `rt` on(((`r`.`program` = `rt`.`program`) and (`r`.`group` = `rt`.`group`) and (`r`.`reportType` = `rt`.`code`)))) where ((`r`.`status` = 'published') and (`r`.`program` = 'CoC') and (`r`.`COC` is not null)) */;

--
-- Final view structure for view `gt_vw_coc_year`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_coc_year`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_coc_year`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_coc_year` AS select distinct `c`.`coc_no` AS `coc_no`,`a`.`year` AS `year` from (`c_tcoc` `c` join `gt_tbl_award` `a` on((`a`.`coc_no` = `c`.`coc_no`))) union select distinct `c`.`coc_no` AS `coc_no`,`j`.`year` AS `year` from (`c_tcoc` `c` join `gt_tbl_coc_map` `j` on((`j`.`coc_no` = `c`.`coc_no`))) union select distinct `c`.`coc_no` AS `coc_no`,year(`r`.`periodEnd`) AS `year` from (`c_tcoc` `c` join `rpt_report` `r` on((left(`r`.`COC`,6) = `c`.`coc_no`))) where ((`r`.`periodEnd` is not null) and (`r`.`status` = 'published')) order by `coc_no`,`year` desc */;

--
-- Final view structure for view `gt_vw_grantee_page`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_grantee_page`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_grantee_page`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_grantee_page` AS select `d`.`attributeValue` AS `grantee_id`,`c`.`Filename` AS `filename`,`c`.`lastUpdate` AS `lastUpdate` from ((((`tclassextend` `e` join `tclassextendsets` `es` on((`es`.`subTypeID` = `e`.`subTypeID`))) join `tclassextendattributes` `a` on((`a`.`extendSetID` = `es`.`extendSetID`))) join `tclassextenddata` `d` on((`d`.`attributeID` = `a`.`attributeID`))) join `tcontent` `c` on((`c`.`ContentHistID` = `d`.`baseID`))) where ((`c`.`Active` = 1) and (`c`.`Approved` = 1) and (`c`.`Display` = 1) and (`e`.`subType` = 'Grantee')) */;

--
-- Final view structure for view `gt_vw_grantee_program`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_grantee_program`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_grantee_program`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_grantee_program` AS select `gt_asc_grantee_jurisdiction`.`grantee_id` AS `grantee_id`,`gt_asc_grantee_jurisdiction`.`program_id` AS `program_id` from `gt_asc_grantee_jurisdiction` where ((`gt_asc_grantee_jurisdiction`.`grantee_id` is not null) and (`gt_asc_grantee_jurisdiction`.`program_id` is not null)) union select `gt_tbl_award`.`grantee_id` AS `grantee_id`,`gt_tbl_award`.`program_id` AS `program_id` from `gt_tbl_award` where ((`gt_tbl_award`.`grantee_id` is not null) and (`gt_tbl_award`.`program_id` is not null)) union select distinct `gt_vw_grantee_report_year`.`grantee_id` AS `grantee_id`,`gt_vw_grantee_report_year`.`program_id` AS `program_id` from `gt_vw_grantee_report_year` where ((`gt_vw_grantee_report_year`.`grantee_id` is not null) and (`gt_vw_grantee_report_year`.`program_id` is not null)) order by `grantee_id`,`program_id` */;

--
-- Final view structure for view `gt_vw_grantee_program_year`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_grantee_program_year`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_grantee_program_year`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_grantee_program_year` AS select `gt_tbl_award`.`grantee_id` AS `grantee_id`,`gt_tbl_award`.`year` AS `year`,`gt_tbl_award`.`program_id` AS `program_id` from `gt_tbl_award` where ((`gt_tbl_award`.`grantee_id` is not null) and (`gt_tbl_award`.`program_id` is not null) and (`gt_tbl_award`.`year` is not null)) union select `gt_vw_grantee_report_year`.`grantee_id` AS `grantee_id`,`gt_vw_grantee_report_year`.`year` AS `year`,`gt_vw_grantee_report_year`.`program_id` AS `program_id` from `gt_vw_grantee_report_year` where ((`gt_vw_grantee_report_year`.`grantee_id` is not null) and (`gt_vw_grantee_report_year`.`program_id` is not null) and (`gt_vw_grantee_report_year`.`year` is not null)) union select `gt_tbl_grantee_map`.`grantee_id` AS `grantee_id`,`gt_tbl_grantee_map`.`program_id` AS `program_id`,`gt_tbl_grantee_map`.`year` AS `year` from `gt_tbl_grantee_map` order by `grantee_id`,`year`,`program_id` */;

--
-- Final view structure for view `gt_vw_grantee_report`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_grantee_report`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_grantee_report`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_grantee_report` AS select concat('/reports/',`r`.`filename`) AS `path`,(case when ((`r`.`program` = 'CoC') and (`r`.`group` = 'GIS')) then concat(' ',year(`r`.`periodEnd`),' ',`tt`.`label`,' - ',`r`.`state`,(case when (`tt`.`code` = 'ShapeFile') then ' CoCs' else '' end)) when (`r`.`program` = 'CoC') then concat(' ',year(`r`.`periodEnd`),' ',`t`.`label`,(case when (`c`.`label` <> '') then concat(' - ',`c`.`label`) when (`s`.`label` <> '') then concat(' - ',`s`.`label`) else '' end)) when (`r`.`program` = 'HOPWA') then concat(year(`r`.`periodEnd`),'-',(year(`r`.`periodEnd`) + 1),' ',`t`.`label`,(case when (`g`.`name` is not null) then concat(' - ',`g`.`name`) else '' end)) when (`r`.`program` = 'NSP') then concat(`t`.`label`,(case when (`gt`.`label` is not null) then concat(' - ',`gt`.`label`,' Grantee') else '' end),(case when (`g`.`name` is not null) then concat(' - ',`g`.`name`) else '' end),(case when (`r`.`group` = 'QPR') then concat(' - ',(case when (month(`r`.`periodEnd`) <= 3) then concat('Q1 ',year(`r`.`periodEnd`)) when ((month(`r`.`periodEnd`) > 3) and (month(`r`.`periodEnd`) <= 6)) then concat('Q2 ',year(`r`.`periodEnd`)) when ((month(`r`.`periodEnd`) > 6) and (month(`r`.`periodEnd`) <= 9)) then concat('Q3 ',year(`r`.`periodEnd`)) else concat('Q4 ',year(`r`.`periodEnd`)) end)) when (`r`.`periodEnd` is not null) then concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')) else '' end)) when (`r`.`program` = 'HOME') then concat(`t`.`label`,(case when (`r`.`group` = 'Dash') then concat(ifnull(concat(' - ',`g`.`name`),''),ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Vacant') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Open') then concat(' - ',`s`.`label`,convert(convert(ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') using utf8) using utf8)) when ((`r`.`group` = 'Snap') and (`r`.`scope` = 'PJ')) then concat(ifnull(concat(' - ',`g`.`name`),''),ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when ((`r`.`group` = 'Snap') and (`r`.`scope` <> 'PJ')) then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when (`r`.`group` = 'Prod') then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when (`r`.`group` = 'Act') then concat(' - ',`s`.`label`,convert(convert(ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') using utf8) using utf8)) when (`r`.`group` = 'ActHB') then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when ((`r`.`group` = 'Cancel') and (`r`.`periodEnd` is not null)) then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when ((`r`.`group` = 'Cancel') and isnull(`r`.`periodEnd`)) then ifnull(concat(' - ',`r`.`fiscalYear`),'') when (`r`.`group` = 'Exp') then concat(' - FY ',`r`.`fiscalYear`,(case when (`r`.`periodEnd` is not null) then ' or Earlier Expiring Funds' else '  Expired Funds' end),' - All States',ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) else '' end)) when (`r`.`program` = 'CDBG') then concat(`t`.`label`,ifnull(concat(' - ',`g`.`name`),''),' - PY',year(`r`.`periodEnd`)) when (`r`.`program` = 'CPD') then concat(`t`.`label`,' ',`rt`.`label`,ifnull(concat(' - ',`g`.`name`),'')) else `t`.`label` end) AS `report_display_name`,substring_index(`r`.`filename`,'.',-(1)) AS `doctype`,year(`r`.`periodEnd`) AS `year`,`r`.`periodEnd` AS `periodEnd`,left(`r`.`COC`,6) AS `coc_no`,`r`.`grantee` AS `grantee`,ifnull(`o`.`orgid`,`ao`.`orgid`) AS `grantee_id`,`r`.`program` AS `program`,`p`.`id` AS `program_id` from ((((((((((((`rpt_report` `r` join `rpt_type` `t` on(((`r`.`program` = `t`.`program`) and (`r`.`group` = `t`.`group`) and (`r`.`scope` = `t`.`scope`)))) join `rpt_scope` `sc` on((`sc`.`code` = `r`.`scope`))) left join `rpt_coc` `c` on((`c`.`code` = `r`.`COC`))) left join `rpt_grantee` `g` on((`g`.`code` = `r`.`grantee`))) left join `rpt_state` `s` on((`s`.`code` = `r`.`state`))) left join `rpt_grant_type` `gt` on((`gt`.`code` = `r`.`grantType`))) left join `rpt_tool_type` `tt` on((`r`.`toolType` = `tt`.`code`))) left join `c_torganizations` `o` on(((`o`.`grantee_code` = `r`.`grantee`) and (`o`.`active` = 1)))) left join `c_torganizations` `io` on(((`io`.`grantee_code` = `r`.`grantee`) and (`io`.`active` = 0)))) left join `c_torganizations` `ao` on((`ao`.`orgid` = `io`.`change_to_orgid`))) join `gt_lku_program` `p` on((`p`.`program_code` = `r`.`program`))) left join `rpt_report_type` `rt` on(((`r`.`program` = `rt`.`program`) and (`r`.`group` = `rt`.`group`) and (`r`.`reportType` = `rt`.`code`)))) where (`r`.`status` = 'published') */;

--
-- Final view structure for view `gt_vw_grantee_report_year`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_grantee_report_year`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_grantee_report_year`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_grantee_report_year` AS select year(`r`.`periodEnd`) AS `year`,ifnull(`o`.`orgid`,`ao`.`orgid`) AS `grantee_id`,`p`.`id` AS `program_id` from ((((`rpt_report` `r` join `gt_lku_program` `p` on((`p`.`program_code` = `r`.`program`))) left join `c_torganizations` `o` on(((`o`.`grantee_code` = `r`.`grantee`) and (`o`.`active` = 1)))) left join `c_torganizations` `io` on(((`io`.`grantee_code` = `r`.`grantee`) and (`io`.`active` = 0)))) left join `c_torganizations` `ao` on((`ao`.`orgid` = `io`.`change_to_orgid`))) where ((`r`.`status` = 'published') and (`r`.`grantee` is not null) and (`r`.`grantee` <> '')) */;

--
-- Final view structure for view `gt_vw_grantee_year`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_grantee_year`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_grantee_year`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_grantee_year` AS select distinct `g`.`orgid` AS `grantee_id`,`g`.`orgname` AS `grantee_name`,`a`.`year` AS `year` from (`c_torganizations` `g` join `gt_tbl_award` `a` on((`a`.`grantee_id` = `g`.`orgid`))) union select distinct `g`.`orgid` AS `grantee_id`,`g`.`orgname` AS `grantee_name`,`j`.`year` AS `year` from (`c_torganizations` `g` join `gt_tbl_grantee_map` `j` on((`j`.`grantee_id` = `g`.`orgid`))) union select distinct `g`.`orgid` AS `grantee_id`,`g`.`orgname` AS `grantee_name`,year(`r`.`periodEnd`) AS `year` from (`c_torganizations` `g` join `rpt_report` `r` on((`r`.`grantee` = `g`.`grantee_code`))) where ((`r`.`periodEnd` is not null) and (`r`.`status` = 'published') and (`g`.`active` = 1)) union select distinct `ag`.`orgid` AS `grantee_id`,`ag`.`orgname` AS `grantee_name`,year(`r`.`periodEnd`) AS `year` from ((`c_torganizations` `ag` join `c_torganizations` `ig` on((`ig`.`change_to_orgid` = `ag`.`orgid`))) join `rpt_report` `r` on((`r`.`grantee` = `ig`.`grantee_code`))) where ((`r`.`periodEnd` is not null) and (`r`.`status` = 'published')) order by `grantee_id`,`year` desc */;

--
-- Final view structure for view `gt_vw_hopwa_locations`
--

/*!50001 DROP TABLE IF EXISTS `gt_vw_hopwa_locations`*/;
/*!50001 DROP VIEW IF EXISTS `gt_vw_hopwa_locations`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `gt_vw_hopwa_locations` AS select `g`.`orgid` AS `grantee_id`,`g`.`orgname` AS `grantee_name`,`l`.`street` AS `street`,`l`.`city` AS `city`,`l`.`state` AS `state`,`l`.`zip` AS `zip` from (`gt_tbl_grantee_location` `l` join `c_torganizations` `g` on((`g`.`orgid` = `l`.`grantee_id`))) where ((`l`.`program_id` = 8) and (`l`.`active` = 1) and (`g`.`active` = 1)) */;

--
-- Final view structure for view `na_vw_nadashboard`
--

/*!50001 DROP TABLE IF EXISTS `na_vw_nadashboard`*/;
/*!50001 DROP VIEW IF EXISTS `na_vw_nadashboard`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `na_vw_nadashboard` AS select `na`.`id` AS `naid`,`na`.`firm_id` AS `firm_id`,`na`.`state_id` AS `state_id`,`state`.`stateid` AS `state`,`na`.`grantee_id` AS `grantee_id`,`ta`.`orgname` AS `lead_taprovider`,`g`.`orgname` AS `grantee`,`na`.`create_date` AS `create_date`,`s`.`name` AS `status`,`s`.`id` AS `statusid`,`nas`.`update_date` AS `update_date`,group_concat(distinct concat(`u`.`Fname`,' ',`u`.`Lname`) order by `u`.`Lname` ASC separator '<br /><br />') AS `ta_team_lead` from (((((((`na_tbl_needs_assessment` `na` left join `na_vw_nadashboard_status` `nas` on((`nas`.`na_id` = `na`.`id`))) left join `na_lku_status` `s` on((`s`.`id` = `nas`.`status_id`))) left join `c_torganizations` `ta` on((`ta`.`orgid` = `na`.`firm_id`))) join `c_torganizations` `g` on((`g`.`orgid` = `na`.`grantee_id`))) join `na_asc_grantee_state` `state` on((`state`.`granteeid` = `g`.`orgid`))) left join `na_asc_primary_team_member` `m` on(((`m`.`na_id` = `na`.`id`) and (`m`.`member_type` = 'TA Team Lead')))) left join `tusers` `u` on((`u`.`UserID` = `m`.`member_id`))) where (1 = 1) group by `na`.`id` order by `nas`.`update_date` desc */;

--
-- Final view structure for view `na_vw_nadashboard_status`
--

/*!50001 DROP TABLE IF EXISTS `na_vw_nadashboard_status`*/;
/*!50001 DROP VIEW IF EXISTS `na_vw_nadashboard_status`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `na_vw_nadashboard_status` AS select `ns`.`na_id` AS `na_id`,`ns`.`status_id` AS `status_id`,`s`.`name` AS `statusName`,`ns`.`id` AS `id`,`ns`.`comments` AS `comments`,`ns`.`update_date` AS `update_date` from ((`na_tbl_needs_assessment` `na` left join `na_asc_na_status` `ns` on((`na`.`id` = `ns`.`na_id`))) join `na_lku_status` `s` on((`s`.`id` = `ns`.`status_id`))) group by `ns`.`id` order by `ns`.`update_date` desc */;

--
-- Final view structure for view `rpt_vw_categories`
--

/*!50001 DROP TABLE IF EXISTS `rpt_vw_categories`*/;
/*!50001 DROP VIEW IF EXISTS `rpt_vw_categories`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rpt_vw_categories` AS select (case when (`c_tcategories`.`masterNameShort` <> '') then `c_tcategories`.`masterNameShort` else `c_tcategories`.`masterNameLong` end) AS `category_short`,`c_tcategories`.`masterNameLong` AS `category_long`,(case when (`c_tcategories`.`masterNameShort` <> '') then concat(`c_tcategories`.`masterNameShort`,': ',`c_tcategories`.`masterNameLong`) else `c_tcategories`.`masterNameLong` end) AS `category_display` from `c_tcategories` */;

--
-- Final view structure for view `rpt_vw_published_rpt_report`
--

/*!50001 DROP TABLE IF EXISTS `rpt_vw_published_rpt_report`*/;
/*!50001 DROP VIEW IF EXISTS `rpt_vw_published_rpt_report`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rpt_vw_published_rpt_report` AS select concat('reports_',`r`.`filename`) AS `pkid`,`r`.`filename` AS `filename`,`r`.`uploadDate` AS `uploadDate`,`r`.`publishDate` AS `publishDate`,`r`.`program` AS `program`,`r`.`status` AS `status`,cast(concat_ws('','resource/reportmanagement/published/',replace(replace(`r`.`filename`,'%','%25'),'+','%2B')) as char charset utf8) AS `urlPath`,'Reports' AS `contentType`,(case when ((`r`.`program` = 'CoC') and (`r`.`group` = 'GIS')) then concat(year(`r`.`periodEnd`),' ',`tt`.`label`,' - ',`s`.`label`,(case when (`tt`.`code` = 'ShapeFile') then ' CoCs' else '' end)) when (`r`.`program` = 'CoC') then concat(year(`r`.`periodEnd`),' ',`t`.`label`,(case when (`c`.`label` <> '') then concat(' - ',`c`.`label`) when (`s`.`label` <> '') then concat(' - ',`s`.`label`) else '' end)) when (`r`.`program` = 'HOPWA') then concat(year(`r`.`periodEnd`),'-',(year(`r`.`periodEnd`) + 1),' ',`t`.`label`,(case when (`g`.`name` is not null) then concat(' - ',`g`.`name`) else '' end)) when (`r`.`program` = 'NSP') then concat(`t`.`label`,(case when (`gt`.`label` is not null) then concat(' - ',`gt`.`label`,' Grantee') else '' end),(case when (`g`.`name` is not null) then concat(' - ',`g`.`name`) else '' end),(case when (`r`.`group` = 'QPR') then concat(' - ',(case when (month(`r`.`periodEnd`) <= 3) then concat('Q1 ',year(`r`.`periodEnd`)) when ((month(`r`.`periodEnd`) > 3) and (month(`r`.`periodEnd`) <= 6)) then concat('Q2 ',year(`r`.`periodEnd`)) when ((month(`r`.`periodEnd`) > 6) and (month(`r`.`periodEnd`) <= 9)) then concat('Q3 ',year(`r`.`periodEnd`)) else concat('Q4 ',year(`r`.`periodEnd`)) end)) when (`r`.`periodEnd` is not null) then concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')) else '' end)) when (`r`.`program` = 'HOME') then concat((case when ((`r`.`group` = 'IncomeLmts') or (`r`.`group` = 'RentLimits')) then concat(year(`r`.`periodEnd`),' ') else '' end),`t`.`label`,(case when (`r`.`group` = 'Dash') then concat(ifnull(concat(' - ',`g`.`name`),''),ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Vacant') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Open') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when ((`r`.`group` = 'Snap') and (`r`.`scope` = 'PJ')) then concat(ifnull(concat(' - ',`g`.`name`),''),ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when ((`r`.`group` = 'Snap') and (`r`.`scope` <> 'PJ')) then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when (`r`.`group` = 'Prod') then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when (`r`.`group` = 'Act') then concat(' - ',`s`.`label`,ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'ActHB') then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when ((`r`.`group` = 'Cancel') and (`r`.`periodEnd` is not null)) then ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'') when ((`r`.`group` = 'Cancel') and isnull(`r`.`periodEnd`)) then ifnull(concat(' - ',`r`.`fiscalYear`),'') when (`r`.`group` = 'Exp') then concat(' - FY ',`r`.`fiscalYear`,(case when (`r`.`periodEnd` is not null) then ' or Earlier Expiring Funds' else '  Expired Funds' end),' - All States',ifnull(concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y')),'')) when (`r`.`group` = 'Deadline') then concat(' - ',cast(year(`r`.`periodEnd`) as char charset utf8),' Commitment & CHDO Reservation, and ',cast((year(`r`.`periodEnd`) - 3) as char charset utf8),' Disbursement Requirements',' - ',`hs`.`label`) when (`r`.`group` = 'ES') then concat(' - ',date_format(`r`.`periodEnd`,'%M %e, %Y'),' - ',`hs`.`label`) when ((`r`.`group` = 'IncomeLmts') or (`r`.`group` = 'RentLimits')) then ifnull(concat(' - ',`s`.`label`),'') else '' end)) when (`r`.`program` = 'CDBG') then concat(`t`.`label`,ifnull(concat(' - ',`g`.`name`),''),' - PY',year(`r`.`periodEnd`)) when (`r`.`program` = 'CPD') then concat(`r`.`program`,' ',`rt`.`label`,ifnull(concat(' - ',`g`.`name`),'')) else `t`.`label` end) AS `title` from ((((((((`rpt_report` `r` join `rpt_type` `t` on(((`r`.`program` = `t`.`program`) and (`r`.`group` = `t`.`group`) and (`r`.`scope` = `t`.`scope`)))) left join `rpt_coc` `c` on((`c`.`code` = `r`.`COC`))) left join `rpt_grantee` `g` on((`g`.`code` = `r`.`grantee`))) left join `rpt_state` `s` on((`s`.`code` = `r`.`state`))) left join `rpt_grant_type` `gt` on((`gt`.`code` = `r`.`grantType`))) left join `rpt_tool_type` `tt` on((`r`.`toolType` = `tt`.`code`))) left join `rpt_sort` `hs` on((`r`.`sort` = `hs`.`code`))) left join `rpt_report_type` `rt` on(((`r`.`program` = `rt`.`program`) and (`r`.`group` = `rt`.`group`) and (`r`.`reportType` = `rt`.`code`)))) where (`r`.`status` = 'published') group by `r`.`filename` */;

--
-- Final view structure for view `rpt_vw_published_rptreport_err_conplan`
--

/*!50001 DROP TABLE IF EXISTS `rpt_vw_published_rptreport_err_conplan`*/;
/*!50001 DROP VIEW IF EXISTS `rpt_vw_published_rptreport_err_conplan`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rpt_vw_published_rptreport_err_conplan` AS select `vw_rpt`.`pkid` AS `pkid`,`vw_rpt`.`filename` AS `filename`,`vw_rpt`.`uploadDate` AS `uploadDate`,`vw_rpt`.`publishDate` AS `publishDate`,`vw_rpt`.`urlPath` AS `urlPath`,`vw_rpt`.`contentType` AS `contentType`,`vw_rpt`.`title` AS `title` from `rpt_vw_published_rpt_report` `vw_rpt` union select concat('errreports_',`err`.`filename`) AS `pkid`,`err`.`filename` AS `filename`,`err`.`uploadDate` AS `uploadDate`,`err`.`publishDate` AS `publishDate`,cast(concat_ws('','resource/reportmanagement/published/',replace(replace(`err`.`filename`,'%','%25'),'+','%2B')) as char charset utf8) AS `urlPath`,'Reports' AS `contentType`,concat(`err`.`projectName`,', ',`err`.`city`,', ',`err`.`state`) AS `title` from `rpt_environmental_review_record` `err` where ((`err`.`status` = 'published') and ((to_days(`err`.`removalDate`) - to_days(curdate())) >= 0)) union select concat('conplanreports_',`c`.`filename`) AS `pkid`,`c`.`filename` AS `filename`,`c`.`uploaded_date` AS `uploaded_date`,`c`.`published_date` AS `publishDate`,concat('https://files.mysite.com/reports/conplans/',replace(replace(`c`.`filename`,'%','%25'),'+','%2B')) AS `urlPath`,'Reports' AS `contentType`,(case when ((`c`.`report_type` = 'CONPL') and (`c`.`program_year` = `c`.`end_year`) and (`c`.`owner_grantee_type` = 'CNSRT')) then concat(`c`.`program_year`,' Cnrst Con Plan - ',`og`.`name`,', ',`og`.`state_abbrev`) when ((`c`.`report_type` = 'CONPL') and (`c`.`program_year` = `c`.`end_year`)) then concat(`c`.`program_year`,' ',`gt`.`name`,' Con Plan - ',`og`.`name`,', ',`og`.`state_abbrev`) when ((`c`.`report_type` = 'CONPL') and (`c`.`program_year` <> `c`.`end_year`) and (`c`.`owner_grantee_type` = 'CNSRT')) then concat(`c`.`program_year`,'-',`c`.`end_year`,' Cnrst Con Plan - ',`og`.`name`,', ',`og`.`state_abbrev`) when ((`c`.`report_type` = 'CONPL') and (`c`.`program_year` <> `c`.`end_year`)) then concat(`c`.`program_year`,'-',`c`.`end_year`,' ',`gt`.`name`,' Con Plan - ',`og`.`name`,', ',`og`.`state_abbrev`) when (`c`.`report_type` = 'AAP00') then concat(`c`.`program_year`,' Stand Alone Action Plan - ',`og`.`name`,', ',`og`.`state_abbrev`) when (`c`.`report_type` = 'AAPCP') then concat(`c`.`program_year`,' Associated Action Plan - ',`og`.`name`,', ',`og`.`state_abbrev`) else concat(`c`.`program_year`,' CAPER - ',`og`.`name`,', ',`og`.`state_abbrev`) end) AS `title` from ((`rpt_tbl_conplan` `c` left join `rpt_lku_grantee_type` `gt` on((`gt`.`abbeviation` = `c`.`owner_grantee_type`))) left join `rpt_lku_conplan_grantee` `og` on((`og`.`idis_id` = `c`.`owner_grantee_idis_id`))) where (`c`.`status` = 'Published') */;

--
-- Final view structure for view `rpt_vw_rptreport_err_conplan_topics`
--

/*!50001 DROP TABLE IF EXISTS `rpt_vw_rptreport_err_conplan_topics`*/;
/*!50001 DROP VIEW IF EXISTS `rpt_vw_rptreport_err_conplan_topics`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rpt_vw_rptreport_err_conplan_topics` AS select `vw`.`filename` AS `filename`,`mcat`.`category_short` AS `topicAcronym`,`mcat`.`category_long` AS `topicLongName`,`mcat`.`category_display` AS `topic` from (`rpt_vw_published_rpt_report` `vw` left join `rpt_vw_categories` `mcat` on((case when (`vw`.`program` = 'CDBG') then (`mcat`.`category_long` in ('CDBG Entitlement Program','CDBG HUD Administered Non-Entitled Counties in Hawaii Program','CDBG Insular Areas Program','CDBG State Program')) when (`vw`.`program` = 'CPD') then ((`mcat`.`category_long` in ('CDBG Entitlement Program','CDBG HUD Administered Non-Entitled Counties in Hawaii Program','CDBG Insular Areas Program','CDBG State Program')) or (`mcat`.`category_short` in ('HOME','HOPWA','ESG'))) else (`vw`.`program` = `mcat`.`category_short`) end))) union select `err`.`filename` AS `filename`,`mcat`.`category_short` AS `topicAcronym`,`mcat`.`category_long` AS `topicLongName`,`mcat`.`category_display` AS `topic` from (`rpt_environmental_review_record` `err` left join `rpt_vw_categories` `mcat` on((`mcat`.`category_long` = 'Environmental Review'))) union select `c`.`filename` AS `filename`,`mcat`.`category_short` AS `topicAcronym`,`mcat`.`category_long` AS `topicLongName`,`mcat`.`category_display` AS `topic` from (`rpt_tbl_conplan` `c` left join `rpt_vw_categories` `mcat` on((`mcat`.`category_long` = 'Consolidated Plan/eCon Planning Suite'))) */;

--
-- Final view structure for view `rsc_vw_active_document`
--

/*!50001 DROP TABLE IF EXISTS `rsc_vw_active_document`*/;
/*!50001 DROP VIEW IF EXISTS `rsc_vw_active_document`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rsc_vw_active_document` AS select `r`.`resource_id` AS `resource_id`,`d`.`resource_document_id` AS `resource_document_id`,`d`.`active` AS `active` from ((`rsc_tbl_resources` `r` join `tcontent` `t` on((`r`.`ContentID` = `t`.`ContentID`))) join `rsc_asc_resource_document` `d` on((`d`.`resource_id` = `r`.`resource_id`))) where (`t`.`Display` = 1) */;

--
-- Final view structure for view `rsc_vw_resource_types`
--

/*!50001 DROP TABLE IF EXISTS `rsc_vw_resource_types`*/;
/*!50001 DROP VIEW IF EXISTS `rsc_vw_resource_types`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rsc_vw_resource_types` AS select `rtype`.`resource_id` AS `resource_id`,group_concat(distinct cast(`rtype`.`type_id` as char charset utf8) separator ' | ') AS `type_ids`,group_concat(distinct replace(`lk_rtype`.`type_name`,',','') separator ',') AS `type_names` from (`rsc_asc_resource_type` `rtype` join `rsc_lku_type` `lk_rtype` on((`rtype`.`type_id` = `lk_rtype`.`type_id`))) group by `rtype`.`resource_id` */;

--
-- Final view structure for view `rsc_vw_resources_topics`
--

/*!50001 DROP TABLE IF EXISTS `rsc_vw_resources_topics`*/;
/*!50001 DROP VIEW IF EXISTS `rsc_vw_resources_topics`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rsc_vw_resources_topics` AS select `rp`.`resource_id` AS `resourceID`,(case when (`cat`.`masterNameShort` <> '') then `cat`.`masterNameShort` else `cat`.`masterNameLong` end) AS `masterNameShort`,`cat`.`masterNameLong` AS `masterNameLong` from ((`rsc_asc_resource_program` `rp` join `rsc_tbl_program` `program` on((`rp`.`program_id` = `program`.`program_id`))) join `c_tcategories` `cat` on((`program`.`program_id` = `cat`.`rsc_programID`))) union select `rs`.`resource_id` AS `resourceID`,(case when (`cat`.`masterNameShort` <> '') then `cat`.`masterNameShort` else `cat`.`masterNameLong` end) AS `masterNameShort`,`cat`.`masterNameLong` AS `masterNameLong` from ((`rsc_asc_resource_reporting_system` `rs` join `rsc_lku_reporting_system` `system` on((`rs`.`system_id` = `system`.`system_id`))) join `c_tcategories` `cat` on((`system`.`system_id` = `cat`.`rsc_reportID`))) union select `rc`.`resource_id` AS `resourceID`,(case when (`cat`.`masterNameShort` <> '') then `cat`.`masterNameShort` else `cat`.`masterNameLong` end) AS `masterNameShort`,`cat`.`masterNameLong` AS `masterNameLong` from ((`rsc_asc_resource_ccr` `rc` join `rsc_lku_ccr` `ccr` on((`rc`.`ccr_id` = `ccr`.`ccr_id`))) join `c_tcategories` `cat` on((`ccr`.`ccr_id` = `cat`.`rsc_ccrID`))) union select `rt`.`resource_id` AS `resourceID`,NULL AS `masterNameShort`,`t`.`topic_name` AS `masterNameLong` from ((`rsc_asc_resource_topic` `rt` join `rsc_lku_topic` `st` on((`rt`.`topic_id` = `st`.`topic_id`))) join `rsc_lku_topic` `t` on((`st`.`parent_topic_id` = `t`.`topic_id`))) order by `masterNameLong` */;

--
-- Final view structure for view `rsc_vw_resourcesdata`
--

/*!50001 DROP TABLE IF EXISTS `rsc_vw_resourcesdata`*/;
/*!50001 DROP VIEW IF EXISTS `rsc_vw_resourcesdata`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rsc_vw_resourcesdata` AS select `r`.`resource_id` AS `resource_id`,group_concat(distinct cast(`rp`.`program_id` as char charset utf8) separator '|') AS `program_ids`,group_concat(distinct if((length(`p`.`program_short`) > 0),`p`.`program_short`,`p`.`program_description`) separator ' | ') AS `program_short`,group_concat(distinct `p`.`program_description` separator ' | ') AS `program_descriptions`,group_concat(distinct cast(`rrs`.`system_id` as char charset utf8) separator '|') AS `system_ids`,group_concat(distinct `lk_rs`.`system_name` separator ' | ') AS `system_name`,group_concat(distinct cast(`rccr`.`ccr_id` as char charset utf8) separator '|') AS `ccr_ids`,group_concat(distinct `lk_ccr`.`ccr_name` separator ' | ') AS `ccr_name`,group_concat(distinct cast(`lk_topic`.`topic_id` as char charset utf8) separator '|') AS `topic_ids`,group_concat(distinct `lk_topic`.`topic_name` separator ' | ') AS `topic_name`,group_concat(distinct cast(`rt`.`topic_id` as char charset utf8) separator '|') AS `subtopic_ids`,group_concat(distinct `lk_subTopic`.`topic_name` separator ' | ') AS `subtopic_name`,group_concat(distinct cast(`rtype`.`type_id` as char charset utf8) separator '|') AS `type_ids`,group_concat(distinct `lk_rtype`.`type_name` separator ' | ') AS `type_name`,cast(concat_ws('','https://hudexchange.info/',`tc`.`Filename`) as char charset utf8) AS `resourcedetailspath`,group_concat(distinct cast(`lk_source`.`source` as char charset utf8) separator ' | ') AS `source`,group_concat(distinct cast(`lk_apr`.`approver` as char charset utf8) separator ' | ') AS `approver`,group_concat(distinct cast(`lk_auth`.`author` as char charset utf8) separator ' | ') AS `author`,group_concat(distinct cast(`lku_sponsor`.`sponsor` as char charset utf8) separator ' | ') AS `sponsor` from ((((((((((((((((((((`rsc_tbl_resources` `r` join `tcontent` `tc` on((`tc`.`TContent_ID` = `r`.`TContent_ID`))) left join `rsc_asc_resource_program` `rp` on((`rp`.`resource_id` = `r`.`resource_id`))) left join `rsc_tbl_program` `p` on((`rp`.`program_id` = `p`.`program_id`))) left join `rsc_asc_resource_reporting_system` `rrs` on((`rrs`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_reporting_system` `lk_rs` on((`rrs`.`system_id` = `lk_rs`.`system_id`))) left join `rsc_asc_resource_ccr` `rccr` on((`rccr`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_ccr` `lk_ccr` on((`rccr`.`ccr_id` = `lk_ccr`.`ccr_id`))) left join `rsc_asc_resource_topic` `rt` on((`rt`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_topic` `lk_subTopic` on(((`rt`.`topic_id` = `lk_subTopic`.`topic_id`) and (`lk_subTopic`.`parent_topic_id` is not null)))) left join `rsc_lku_topic` `lk_topic` on(((`lk_topic`.`topic_id` = `lk_subTopic`.`parent_topic_id`) and isnull(`lk_topic`.`parent_topic_id`)))) left join `rsc_asc_resource_type` `rtype` on((`rtype`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_type` `lk_rtype` on((`rtype`.`type_id` = `lk_rtype`.`type_id`))) left join `rsc_asc_resource_source` `r_source` on((`r_source`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_source` `lk_source` on((`r_source`.`source_id` = `lk_source`.`source_id`))) left join `rsc_asc_resource_approver` `rapr` on((`rapr`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_approver` `lk_apr` on((`rapr`.`approver_id` = `lk_apr`.`approver_id`))) left join `rsc_asc_resource_author` `rauth` on((`rauth`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_author` `lk_auth` on((`rauth`.`author_id` = `lk_auth`.`author_id`))) left join `rsc_asc_resource_sponsor` `rsponsor` on((`rsponsor`.`resource_id` = `r`.`resource_id`))) left join `rsc_lku_sponsor` `lku_sponsor` on((`rsponsor`.`sponsor_id` = `lku_sponsor`.`sponsor_id`))) group by `r`.`resource_id` */;

--
-- Final view structure for view `search_vw_faqs`
--

/*!50001 DROP TABLE IF EXISTS `search_vw_faqs`*/;
/*!50001 DROP VIEW IF EXISTS `search_vw_faqs`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `search_vw_faqs` AS select concat('faqs_',`f`.`id`) AS `pkid`,`f`.`id` AS `id`,`f`.`publisheddate` AS `searchDate`,`f`.`url` AS `urlPath`,`f`.`answer` AS `description`,'FAQs' AS `contentType`,`f`.`questionshort` AS `title`,`tc`.`lastUpdate` AS `updated_date` from (`faq_tbl_faqs` `f` join `tcontent` `tc` on((`f`.`contentid` = `tc`.`ContentID`))) where ((`tc`.`Type` = 'Page') and (`tc`.`subType` = 'FAQ') and (`tc`.`Active` = 1) and (`tc`.`Display` = 1) and (`tc`.`Approved` = 1)) */;

--
-- Final view structure for view `search_vw_news`
--

/*!50001 DROP TABLE IF EXISTS `search_vw_news`*/;
/*!50001 DROP VIEW IF EXISTS `search_vw_news`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `search_vw_news` AS select distinct concat('news_',`tc`.`ContentID`) AS `pkid`,`tc`.`ContentID` AS `id`,'News' AS `contentType`,`tc`.`Title` AS `title`,`tc`.`Summary` AS `teaser`,`tc`.`Body` AS `description`,`tc`.`ReleaseDate` AS `searchDate`,`tc`.`Filename` AS `urlPath`,`tc`.`lastUpdate` AS `updated_date` from `tcontent` `tc` where ((`tc`.`subType` = 'News') and (`tc`.`ReleaseDate` <= now()) and (`tc`.`Active` = 1) and (`tc`.`Display` = 1) and (`tc`.`Approved` = 1)) */;

--
-- Final view structure for view `search_vw_reports`
--

/*!50001 DROP TABLE IF EXISTS `search_vw_reports`*/;
/*!50001 DROP VIEW IF EXISTS `search_vw_reports`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `search_vw_reports` AS select concat('reports_',`tc`.`ContentID`) AS `pkid`,`tc`.`ContentID` AS `id`,'Reports' AS `contentType`,`tc`.`Title` AS `title`,`tc`.`Filename` AS `urlPath`,`tc`.`lastUpdate` AS `searchDate` from `tcontent` `tc` where ((`tc`.`subType` = 'Report') and (`tc`.`Active` = 1) and (`tc`.`Display` = 1) and (`tc`.`Approved` = 1)) */;

--
-- Final view structure for view `search_vw_resources`
--

/*!50001 DROP TABLE IF EXISTS `search_vw_resources`*/;
/*!50001 DROP VIEW IF EXISTS `search_vw_resources`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `search_vw_resources` AS select concat('resources_',`r`.`resource_id`) AS `pkid`,`r`.`resource_id` AS `id`,`r`.`date_published` AS `searchDate`,`tc`.`Filename` AS `urlPath`,`tc`.`Body` AS `description`,(case when if((find_in_set('Fact Sheets and FAQs',`rt`.`type_names`) > 0),1,0) then 'FAQs' else 'Resources' end) AS `contentType`,`tc`.`Title` AS `title`,`tc`.`lastUpdate` AS `updated_date` from ((`rsc_tbl_resources` `r` join `tcontent` `tc` on((`r`.`ContentID` = `tc`.`ContentID`))) left join `rsc_vw_resource_types` `rt` on((`rt`.`resource_id` = `r`.`resource_id`))) where ((`tc`.`Active` = 1) and (`tc`.`Display` = 1) and (`tc`.`Approved` = 1)) */;

--
-- Final view structure for view `search_vw_training_classes`
--

/*!50001 DROP TABLE IF EXISTS `search_vw_training_classes`*/;
/*!50001 DROP VIEW IF EXISTS `search_vw_training_classes`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `search_vw_training_classes` AS select concat('trainingclass_',`m`.`id`) AS `pkid`,`m`.`id` AS `id`,'Training Materials' AS `contentType`,`m`.`name` AS `title`,`m`.`summary` AS `teaser`,`m`.`description` AS `description`,`m`.`timezone_start` AS `searchDate`,(case when (`e`.`LMS_course_id` is not null) then `m`.`SESUrl` else `e`.`SESUrl` end) AS `urlPath`,`m`.`timezone_start` AS `startDate`,`m`.`timezone_end` AS `endDate`,`m`.`timezone_display` AS `timezone`,`e`.`event_type_id` AS `trainingTypeId`,`et`.`description` AS `trainingType`,`loc`.`city` AS `locationCity`,`state`.`abbrev` AS `locationStateAbbrev`,(case when isnull(`state`.`name`) then 'Online' else `state`.`name` end) AS `location`,`e`.`isHUD` AS `isHudEvent`,(case when (count(`res`.`id`) > 0) then 1 else 0 end) AS `hasResources`,(case when (sum(ifnull(`res`.`isRecording`,0)) > 0) then 1 else 0 end) AS `hasRecording`,`m`.`updated_date` AS `meeting_updated_date`,`e`.`updated_date` AS `event_updated_date`,`res`.`updated_date` AS `resource_updated_date`,`mr`.`created_date` AS `meeting_resource_created_date` from (((((((`cal_tbl_meeting` `m` join `cal_tbl_event` `e` on((`m`.`event_id` = `e`.`id`))) join `cal_lku_event_type` `et` on((`e`.`event_type_id` = `et`.`id`))) left join `cal_tbl_location` `loc` on((`loc`.`id` = `m`.`location_id`))) left join `state` on((`loc`.`state_abbrev` = `state`.`abbrev`))) left join `cal_asc_meeting_resource` `mr` on((`m`.`id` = `mr`.`meeting_id`))) left join `cal_tbl_resource` `res` on((`mr`.`resource_id` = `res`.`id`))) left join `cal_lku_resource_type` `rt` on(((`rt`.`id` = `res`.`resource_type_id`) and (`rt`.`id` <> 3)))) where ((1 = 1) and (`m`.`isPrivateClass` = 0) and (`m`.`status` <> 'Archived') and ((isnull(`e`.`LMS_course_id`) and (`m`.`status` = 'Active')) or ((`e`.`LMS_course_id` is not null) and (`e`.`status` = 'Active') and (`m`.`status` = 'Active')))) group by `m`.`id` */;

--
-- Final view structure for view `search_vw_training_courses`
--

/*!50001 DROP TABLE IF EXISTS `search_vw_training_courses`*/;
/*!50001 DROP VIEW IF EXISTS `search_vw_training_courses`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mysite_cms`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `search_vw_training_courses` AS select (case `e`.`isLearningPlan` when 0 then concat('trainingcourse_',`e`.`courseID`) else concat('traininglp_',`e`.`courseID`) end) AS `pkid`,`e`.`courseID` AS `id`,'Training Materials' AS `contentType`,`e`.`courseName` AS `title`,`e`.`courseTeaser` AS `teaser`,`e`.`courseDescription` AS `description`,`e`.`postedDate` AS `searchDate`,`e`.`courseSESUrl` AS `urlPath`,NULL AS `startDate`,NULL AS `endDate`,NULL AS `timezone`,`e`.`courseTypeID` AS `trainingTypeId`,`e`.`courseType` AS `trainingType`,NULL AS `locationCity`,NULL AS `locationStateAbbrev`,'Online' AS `location`,`e`.`isHUD` AS `isHudEvent`,(case when (count(`res`.`id`) > 0) then 1 else 0 end) AS `hasResources`,0 AS `hasRecording`,`e`.`updated_date` AS `updated_date` from ((`cal_vw_courses` `e` left join `cal_asc_event_resource` `er` on((`e`.`courseID` = `er`.`event_id`))) left join `cal_tbl_resource` `res` on((`er`.`resource_id` = `res`.`id`))) where ((1 = 1) and (`e`.`courseTypeID` = 2) and (`e`.`isPublished` = 1)) group by `e`.`courseID` */;

--
-- Final view structure for view `tap_vw_federal_goals_export`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_federal_goals_export`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_federal_goals_export`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_federal_goals_export` AS select `ttw`.`id` AS `workplanid`,group_concat(distinct `ttg`.`id` separator ',') AS `federal_goalid`,group_concat(distinct `ttg`.`name` separator ';') AS `federal_goalname` from ((`tap_tbl_goals` `ttg` join `tap_asc_goals_workplan` `twg` on((`ttg`.`id` = `twg`.`goalid`))) join `tap_tbl_workplan` `ttw` on((`twg`.`workplanid` = `ttw`.`id`))) where (`ttg`.`goaltype` = 2) group by `ttw`.`id` */;

--
-- Final view structure for view `tap_vw_getcocs`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_getcocs`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_getcocs`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_getcocs` AS select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `cocNoticesent_date`,group_concat(`recipient`.`coc_no` separator '; ') AS `coc_nos`,group_concat(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) separator '; ') AS `cocnames`,group_concat(`fo`.`orgname` separator '; ') AS `cocFieldOffice`,group_concat(concat(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`),' - ',`fo`.`orgname`) separator '; ') AS `cocFieldOffices` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) where ((`wp`.`tatype` not in (2,3)) and (`assign`.`id` is not null)) group by `wp`.`id` union select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `cocNoticesent_date`,group_concat(`recipient`.`coc_no` separator '; ') AS `coc_nos`,group_concat(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) separator '; ') AS `cocnames`,group_concat(`fo`.`orgname` separator '; ') AS `cocFieldOffice`,group_concat(concat(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`),' - ',`fo`.`orgname`) separator '; ') AS `cocFieldOffices` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) left join `tap_tbl_recipient` `recipient` on((`recipient`.`workplanid` = `wp`.`id`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) where ((`wp`.`tatype` not in (2,3)) and isnull(`assign`.`id`)) group by `wp`.`id` union select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `cocNoticesent_date`,group_concat(`recipient`.`coc_no` separator '; ') AS `coc_nos`,group_concat(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) separator '; ') AS `cocnames`,group_concat(`fo`.`orgname` separator '; ') AS `cocFieldOffice`,group_concat(concat(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`),' - ',`fo`.`orgname`) separator '; ') AS `cocFieldOffices` from (((((`tap_tbl_workplan` `wp` left join `tap_asc_oncallwp_assignment` `a` on((`a`.`workplanid` = `wp`.`id`))) left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `a`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) where ((`wp`.`tatype` in (2,3)) and (`a`.`association_completed` = 1)) group by `wp`.`id` union select `wp`.`id` AS `id`,'' AS `cocNoticesent_date`,'' AS `coc_nos`,'' AS `cocnames`,'' AS `cocFieldOffice`,'' AS `cocFieldOffices` from `tap_tbl_workplan` `wp` where ((`wp`.`tatype` in (2,3)) and (not(`wp`.`id` in (select distinct `tap_asc_oncallwp_assignment`.`workplanid` from `tap_asc_oncallwp_assignment` where (`tap_asc_oncallwp_assignment`.`association_completed` = 1))))) group by `wp`.`id` */;

--
-- Final view structure for view `tap_vw_getgrantees`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_getgrantees`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_getgrantees`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_getgrantees` AS select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `granteeNoticesent_date`,group_concat(`recipient`.`granteeid` separator '; ') AS `grantees`,group_concat(`cto`.`orgname` separator '; ') AS `granteenames`,group_concat(`fo`.`orgname` separator '; ') AS `fieldOffice`,group_concat(concat(`cto`.`orgname`,' - ',`fo`.`orgname`) separator '; ') AS `granteFieldOffices` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) where ((`wp`.`tatype` not in (2,3)) and (`assign`.`id` is not null) and (`recipient`.`recipientTypeID` = 4)) group by `wp`.`id` union select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `granteeNoticesent_date`,group_concat(`recipient`.`granteeid` separator '; ') AS `grantees`,group_concat(`cto`.`orgname` separator '; ') AS `granteenames`,group_concat(`fo`.`orgname` separator '; ') AS `fieldOffice`,group_concat(concat(`cto`.`orgname`,' - ',`fo`.`orgname`) separator '; ') AS `granteFieldOffices` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) left join `tap_tbl_recipient` `recipient` on((`recipient`.`workplanid` = `wp`.`id`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) where ((`wp`.`tatype` not in (2,3)) and isnull(`assign`.`id`) and (`recipient`.`recipientTypeID` = 4)) group by `wp`.`id` union select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `granteeNoticesent_date`,group_concat(`recipient`.`granteeid` separator '; ') AS `grantees`,group_concat(`cto`.`orgname` separator '; ') AS `granteenames`,group_concat(`fo`.`orgname` separator '; ') AS `fieldOffice`,group_concat(concat(`cto`.`orgname`,' - ',`fo`.`orgname`) separator '; ') AS `granteFieldOffices` from (((((`tap_tbl_workplan` `wp` left join `tap_asc_oncallwp_assignment` `a` on((`a`.`workplanid` = `wp`.`id`))) left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `a`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) where ((`wp`.`tatype` in (2,3)) and (`a`.`association_completed` = 1) and (`recipient`.`recipientTypeID` = 4)) group by `wp`.`id` union select `wp`.`id` AS `id`,'' AS `granteeNoticesent_date`,'' AS `grantees`,'' AS `granteenames`,'' AS `fieldOffice`,'' AS `granteFieldOffices` from `tap_tbl_workplan` `wp` where ((`wp`.`tatype` in (2,3)) and (not(`wp`.`id` in (select distinct `tap_asc_oncallwp_assignment`.`workplanid` from `tap_asc_oncallwp_assignment` where (`tap_asc_oncallwp_assignment`.`association_completed` = 1))))) group by `wp`.`id` */;

--
-- Final view structure for view `tap_vw_gethmis`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_gethmis`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_gethmis`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_gethmis` AS select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `hmisNoticesent_date`,group_concat(`recipient`.`granteeid` separator '; ') AS `hmiss`,group_concat(`cto`.`orgname` separator '; ') AS `hmisnames`,group_concat(`fo`.`orgname` separator '; ') AS `hmisFieldOffice`,group_concat(concat(`cto`.`orgname`,' - ',`fo`.`orgname`) separator '; ') AS `hmisFieldOffices` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) where ((`wp`.`tatype` not in (2,3)) and (`assign`.`id` is not null) and (`recipient`.`recipientTypeID` = 7)) group by `wp`.`id` union select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `hmisNoticesent_date`,group_concat(`recipient`.`granteeid` separator '; ') AS `hmiss`,group_concat(`cto`.`orgname` separator '; ') AS `hmisnames`,group_concat(`fo`.`orgname` separator '; ') AS `hmisFieldOffice`,group_concat(concat(`cto`.`orgname`,' - ',`fo`.`orgname`) separator '; ') AS `hmisFieldOffices` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) left join `tap_tbl_recipient` `recipient` on((`recipient`.`workplanid` = `wp`.`id`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) where ((`wp`.`tatype` not in (2,3)) and isnull(`assign`.`id`) and (`recipient`.`recipientTypeID` = 7)) group by `wp`.`id` union select `wp`.`id` AS `id`,group_concat(`assign`.`noticesent_date` separator '; ') AS `hmisNoticesent_date`,group_concat(`recipient`.`granteeid` separator '; ') AS `hmiss`,group_concat(`cto`.`orgname` separator '; ') AS `hmisnames`,group_concat(`fo`.`orgname` separator '; ') AS `hmisFieldOffice`,group_concat(concat(`cto`.`orgname`,' - ',`fo`.`orgname`) separator '; ') AS `hmisFieldOffices` from (((((`tap_tbl_workplan` `wp` left join `tap_asc_oncallwp_assignment` `a` on((`a`.`workplanid` = `wp`.`id`))) left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `a`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) where ((`wp`.`tatype` in (2,3)) and (`a`.`association_completed` = 1) and (`recipient`.`recipientTypeID` = 7)) group by `wp`.`id` union select `wp`.`id` AS `id`,'' AS `hmisNoticesent_date`,'' AS `hmiss`,'' AS `hmisnames`,'' AS `hmisFieldOffice`,'' AS `hmisFieldOffices` from `tap_tbl_workplan` `wp` where ((`wp`.`tatype` in (2,3)) and (not(`wp`.`id` in (select distinct `tap_asc_oncallwp_assignment`.`workplanid` from `tap_asc_oncallwp_assignment` where (`tap_asc_oncallwp_assignment`.`association_completed` = 1))))) group by `wp`.`id` */;

--
-- Final view structure for view `tap_vw_gettasktablesubquery`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_gettasktablesubquery`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_gettasktablesubquery`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_gettasktablesubquery` AS select `twt`.`id` AS `taskID`,`twt`.`taskname` AS `taskname`,`twt`.`description` AS `task_description`,`twt`.`estimatedbudget` AS `estimatedbudget`,`twt`.`startdate` AS `taskStartDate`,`twt`.`enddate` AS `taskEndDate`,convert(concat(`twt`.`startdate`,' - ',`twt`.`enddate`) using utf8) AS `taskPoP`,`twt`.`workplanid` AS `workplanid`,(select convert(group_concat(distinct `ttlabor`.`id` separator ',') using utf8) AS `laborcategory_id` from `tap_task_laborcategory` `ttlabor` where (`ttlabor`.`taskid` = `twt`.`id`) group by `ttlabor`.`taskid`) AS `laborcategory_id`,(select convert(group_concat(`ttlabor`.`laborcategory` separator ',') using utf8) AS `laborcategory` from `tap_task_laborcategory` `ttlabor` where (`ttlabor`.`taskid` = `twt`.`id`) group by `ttlabor`.`taskid`) AS `laborcategory`,(select convert(group_concat(`ttlabor`.`hours` separator ',') using utf8) AS `laborhours` from `tap_task_laborcategory` `ttlabor` where (`ttlabor`.`taskid` = `twt`.`id`) group by `ttlabor`.`taskid`) AS `laborhours`,(select convert(group_concat(concat(`ttlabor`.`laborcategory`,'^',`ttlabor`.`hours`) separator ',') using utf8) AS `laborinfo` from `tap_task_laborcategory` `ttlabor` where (`ttlabor`.`taskid` = `twt`.`id`) group by `ttlabor`.`taskid`) AS `laborinfo`,(select convert(group_concat(distinct concat(`ttlabor`.`id`,' ^ ',`ttlabor`.`laborcategory`,' ^ ',`ttlabor`.`hours`) separator ',') using utf8) AS `labor` from `tap_task_laborcategory` `ttlabor` where (`ttlabor`.`taskid` = `twt`.`id`) group by `ttlabor`.`taskid`) AS `labor`,(select convert(group_concat(distinct `tatt`.`topicid` separator ',') using utf8) AS `topicid` from `tap_asc_task_topics` `tatt` where (`tatt`.`taskid` = `twt`.`id`) group by `tatt`.`taskid`) AS `topicID`,(select convert(group_concat(distinct `lkptopic`.`name` separator ',') using utf8) AS `topicname` from (`tap_asc_task_topics` `tatt` join `tap_lku_topics` `lkptopic` on((`lkptopic`.`id` = `tatt`.`topicid`))) where (`tatt`.`taskid` = `twt`.`id`) group by `tatt`.`taskid`) AS `topicname`,(select convert(group_concat(distinct `ttkeypersonnel`.`id` separator ',') using utf8) AS `keypersonnel_id` from `tap_tbl_keypersonnel` `ttkeypersonnel` where (`ttkeypersonnel`.`taskid` = `twt`.`id`) group by `ttkeypersonnel`.`taskid`) AS `keypersonnel_id`,(select convert(group_concat(`ttkeypersonnel`.`name` separator ',') using utf8) AS `keypersonnel_name` from `tap_tbl_keypersonnel` `ttkeypersonnel` where (`ttkeypersonnel`.`taskid` = `twt`.`id`) group by `ttkeypersonnel`.`taskid`) AS `keypersonnel_name`,(select convert(group_concat(`ttkeypersonnel`.`title` separator ',') using utf8) AS `keypersonnel_title` from `tap_tbl_keypersonnel` `ttkeypersonnel` where (`ttkeypersonnel`.`taskid` = `twt`.`id`) group by `ttkeypersonnel`.`taskid`) AS `keypersonnel_title`,(select convert(group_concat(concat(`ttkeypersonnel`.`name`,'^',`ttkeypersonnel`.`title`) separator '$') using utf8) AS `keypersonnelinfo` from `tap_tbl_keypersonnel` `ttkeypersonnel` where (`ttkeypersonnel`.`taskid` = `twt`.`id`) group by `ttkeypersonnel`.`taskid`) AS `keypersonnelinfo`,(select convert(group_concat(distinct concat(`ttkeypersonnel`.`id`,'^',`ttkeypersonnel`.`name`,'^',`ttkeypersonnel`.`title`) separator ',') using utf8) AS `keypersonnel` from `tap_tbl_keypersonnel` `ttkeypersonnel` where (`ttkeypersonnel`.`taskid` = `twt`.`id`) group by `ttkeypersonnel`.`taskid`) AS `keypersonnel`,(select convert(group_concat(distinct `ttoutput`.`id` separator ',') using utf8) AS `output_id` from `tap_task_expectedoutput` `ttoutput` where (`ttoutput`.`taskid` = `twt`.`id`) group by `ttoutput`.`taskid`) AS `output_id`,(select convert(group_concat(`ttoutput`.`title` separator ',') using utf8) AS `output_title` from `tap_task_expectedoutput` `ttoutput` where (`ttoutput`.`taskid` = `twt`.`id`) group by `ttoutput`.`taskid`) AS `output_title`,(select convert(group_concat(`ttoutput`.`description` separator ',') using utf8) AS `output_description` from `tap_task_expectedoutput` `ttoutput` where (`ttoutput`.`taskid` = `twt`.`id`) group by `ttoutput`.`taskid`) AS `output_description`,(select convert(group_concat(concat(`ttoutput`.`title`,'^',`ttoutput`.`description`) separator '$') using utf8) AS `outputinfo` from `tap_task_expectedoutput` `ttoutput` where (`ttoutput`.`taskid` = `twt`.`id`) group by `ttoutput`.`taskid`) AS `outputinfo`,(select convert(group_concat(distinct concat(`ttoutput`.`id`,'^',`ttoutput`.`title`,'^',`ttoutput`.`description`) separator ',') using utf8) AS `output` from `tap_task_expectedoutput` `ttoutput` where (`ttoutput`.`taskid` = `twt`.`id`) group by `ttoutput`.`taskid`) AS `output` from `tap_workplan_task` `twt` */;

--
-- Final view structure for view `tap_vw_hud_goals_export`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_hud_goals_export`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_hud_goals_export`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_hud_goals_export` AS select `ttw`.`id` AS `workplanid`,group_concat(distinct `ttg`.`id` separator ',') AS `hud_goalid`,group_concat(distinct `ttg`.`name` separator ';') AS `hud_goalname` from ((`tap_tbl_goals` `ttg` join `tap_asc_goals_workplan` `twg` on((`ttg`.`id` = `twg`.`goalid`))) join `tap_tbl_workplan` `ttw` on((`twg`.`workplanid` = `ttw`.`id`))) where (`ttg`.`goaltype` = 1) group by `ttw`.`id` */;

--
-- Final view structure for view `tap_vw_outcomes_export`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_outcomes_export`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_outcomes_export`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_outcomes_export` AS select `ttw`.`id` AS `workplanid`,group_concat(distinct `tto`.`id` order by `tto`.`id` ASC separator ',') AS `outcome_id`,group_concat(concat(`tto`.`title`,':',`tto`.`description`) order by `tto`.`id` ASC separator '^') AS `outcome_info` from (`tap_tbl_workplan` `ttw` join `tap_tbl_outcome` `tto` on((`tto`.`workplanid` = `ttw`.`id`))) group by `ttw`.`id` */;

--
-- Final view structure for view `tap_vw_recipientgrantees`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_recipientgrantees`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_recipientgrantees`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_recipientgrantees` AS select `recipient`.`id` AS `recipientid`,`recipient`.`recipientTypeID` AS `recipientTypeID`,`recipient`.`sortorder` AS `sortorder`,(case when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 4)) then 1 when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 7)) then 3 else 2 end) AS `recipientTypeSort`,(case when (`cto`.`orgname` is not null) then cast(`recipient`.`granteeid` as char charset utf8) else `ctc`.`coc_no` end) AS `granteeid`,(case when (`cto`.`orgname` is not null) then `cto`.`orgname` else concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) end) AS `granteename`,`fo`.`orgname` AS `fieldOffice`,(case when (`cto`.`orgname` is not null) then concat(ifnull(`cto`.`orgname`,''),' - ',ifnull(`fo`.`orgname`,'')) when (`ctc`.`coc_no` is not null) then concat(ifnull(`ctc`.`coc_no`,''),' - ',ifnull(`fo`.`orgname`,'')) else NULL end) AS `granteeFieldOffice` from (((`tap_tbl_recipient` `recipient` left join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) left join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) left join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) order by (case when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 4)) then 1 when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 7)) then 3 else 2 end),`recipient`.`recipientTypeID`,`recipient`.`sortorder`,`recipient`.`id` */;

--
-- Final view structure for view `tap_vw_workplanFOR`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanFOR`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanFOR`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanFOR` AS select distinct `wp`.`id` AS `id`,`u`.`UserID` AS `UserID`,`u`.`Fname` AS `Fname`,`u`.`Lname` AS `Lname`,`o`.`orgname` AS `orgname`,`eua`.`attributeValue` AS `attributeValue`,`u`.`Email` AS `email` from (((((((((((`tusers` `u` join `tusersmemb` `sm` on((`sm`.`UserID` = `u`.`UserID`))) join `tusers` `g` on(((`g`.`UserID` = `sm`.`GroupID`) and (`g`.`GroupName` = 'TA Management System / HUD / Member')))) join `tclassextenddatauseractivity` `eua` on(((`eua`.`baseID` = `u`.`UserID`) and (`eua`.`attributeValue` = 'Field Office Reviewer')))) join `tclassextendattributes` `ea` on(((`ea`.`attributeID` = `eua`.`attributeID`) and (`ea`.`name` = 'hudrole')))) join `tclassextenddatauseractivity` `eua2` on(((`eua2`.`baseID` = `u`.`UserID`) and (`eua2`.`attributeValue` is not null)))) join `tclassextendattributes` `ea2` on(((`ea2`.`attributeID` = `eua2`.`attributeID`) and (`ea2`.`name` = 'orgid')))) join `c_torganizations` `o` on((`o`.`orgid` = `eua2`.`attributeValue`))) left join `tap_tbl_recipient` `rpt` on((`rpt`.`fieldofficeid` = `o`.`orgid`))) left join `tap_tbl_request` `q` on((`q`.`id` = `rpt`.`requestid`))) left join `tap_tbl_assignment` `asgn` on((`asgn`.`requestid` = `q`.`id`))) left join `tap_tbl_workplan` `wp` on(((`wp`.`assignmentid` = `asgn`.`id`) or (`wp`.`id` = `rpt`.`workplanid`)))) where ((`u`.`InActive` = 0) and (`wp`.`id` is not null)) order by `u`.`Email`,`o`.`orgname`,`u`.`Fname`,`u`.`Lname` */;

--
-- Final view structure for view `tap_vw_workplanFORlist`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanFORlist`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanFORlist`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanFORlist` AS select `a`.`id` AS `id`,group_concat(`a`.`Fname`,' ',`a`.`Lname`,' - ',`a`.`orgname` separator '; ') AS `Field_Office_Reviewers`,group_concat(`a`.`Fname`,' ',`a`.`Lname`,' - ',`a`.`orgname`,', ',`a`.`attributeValue` separator '; ') AS `Field_Office_Reviewers_w_Role` from `tap_vw_workplanFOR` `a` group by `a`.`id` */;

--
-- Final view structure for view `tap_vw_workplanPOR`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanPOR`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanPOR`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanPOR` AS select `ppl`.`workplanid` AS `id`,`u`.`UserID` AS `UserID`,`u`.`Email` AS `email`,`u`.`mobilePhone` AS `mobilephone`,`ppl`.`lastupdated` AS `lastupdated`,concat(`ub`.`Fname`,' ',`ub`.`Lname`) AS `UpdatedByName`,`o`.`orgid` AS `orgid`,concat(`u`.`Fname`,' ',`u`.`Lname`) AS `Program_Office_Reviewers_Name`,(case when isnull(`o`.`orgshortname`) then `o`.`orgname` else `o`.`orgshortname` end) AS `Program_Office` from ((((((`tusers` `u` join `tap_tbl_people` `sm` on((`sm`.`userid` = `u`.`UserID`))) join `tap_tbl_people` `ppl` on((`sm`.`id` = `ppl`.`id`))) left join `tusers` `ub` on((`ppl`.`updatedby` = `ub`.`UserID`))) join `tclassextenddatauseractivity` `eua` on(((`eua`.`baseID` = `u`.`UserID`) and (`eua`.`attributeValue` is not null)))) join `tclassextendattributes` `ea` on(((`ea`.`attributeID` = `eua`.`attributeID`) and (`ea`.`name` = 'orgid')))) join `c_torganizations` `o` on((`o`.`orgid` = `eua`.`attributeValue`))) where ((`ppl`.`membertypeid` = 7) and (`u`.`InActive` = 0)) order by `o`.`orgname`,`u`.`Fname`,`u`.`Lname` */;

--
-- Final view structure for view `tap_vw_workplanPORlist`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanPORlist`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanPORlist`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanPORlist` AS select `a`.`id` AS `id`,group_concat(`a`.`Program_Office`,' - ',`a`.`Program_Office_Reviewers_Name` order by `a`.`Program_Office` ASC,`a`.`Program_Office_Reviewers_Name` ASC separator '; ') AS `Program_Office_Reviewers`,group_concat(`a`.`Program_Office_Reviewers_Name` order by `a`.`Program_Office_Reviewers_Name` ASC separator '; ') AS `Program_Office_Reviewers_Name`,group_concat(distinct `a`.`Program_Office` order by `a`.`Program_Office` ASC separator '; ') AS `Program_Office` from `tap_vw_workplanPOR` `a` group by `a`.`id` */;

--
-- Final view structure for view `tap_vw_workplanVersionData`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanVersionData`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanVersionData`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanVersionData` AS select `taa`.`parent_wpid` AS `parent_wpid`,`versions`.`versionTrail` AS `versionTrail`,`latestlive`.`latestversioncreated_approved` AS `latestliveid`,`versions`.`versionData` AS `versionData` from ((`tap_asc_amendment` `taa` left join `tap_vw_workplanversions` `versions` on((`versions`.`parent_wpid` = `taa`.`parent_wpid`))) left join `tap_vw_workplanhighestversion_approved` `latestlive` on((`taa`.`parent_wpid` = `latestlive`.`parent_wpid`))) group by `taa`.`parent_wpid` */;

--
-- Final view structure for view `tap_vw_workplangrantees`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplangrantees`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplangrantees`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplangrantees` AS select `wp`.`id` AS `wpID`,`recipient`.`id` AS `recipientid`,`recipient`.`recipientTypeID` AS `recipientTypeID`,`recipient`.`sortorder` AS `sortorder`,(case when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 4)) then 1 when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 7)) then 3 else 2 end) AS `recipientTypeSort`,(case when (`cto`.`orgname` is not null) then `recipient`.`granteeid` else `ctc`.`coc_no` end) AS `granteeid`,(case when (`cto`.`orgname` is not null) then `cto`.`grantee_state` else `ctc`.`state_id` end) AS `granteestate`,(case when (`cto`.`orgname` is not null) then `cto`.`orgname` else concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) end) AS `granteename`,`fo`.`orgname` AS `fieldOffice`,(case when (`cto`.`orgname` is not null) then concat(ifnull(`cto`.`orgname`,''),' - ',ifnull(`fo`.`orgname`,'')) when (`ctc`.`coc_no` is not null) then concat(ifnull(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`),''),' - ',ifnull(`fo`.`orgname`,'')) else NULL end) AS `granteeFieldOffice` from (((((`tap_tbl_workplan` `wp` join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) left join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) left join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) left join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) where (`wp`.`tatype` not in (2,3)) union select `wp`.`id` AS `wpID`,`recipient`.`id` AS `recipientid`,`recipient`.`recipientTypeID` AS `recipientTypeID`,`recipient`.`sortorder` AS `sortorder`,(case when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 4)) then 1 when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 7)) then 3 else 2 end) AS `recipientTypeSort`,(case when (`cto`.`orgname` is not null) then `recipient`.`granteeid` else `ctc`.`coc_no` end) AS `granteeid`,(case when (`cto`.`orgname` is not null) then `cto`.`grantee_state` else `ctc`.`state_id` end) AS `granteestate`,(case when (`cto`.`orgname` is not null) then `cto`.`orgname` else concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) end) AS `granteename`,`fo`.`orgname` AS `fieldOffice`,(case when (`cto`.`orgname` is not null) then concat(ifnull(`cto`.`orgname`,''),' - ',ifnull(`fo`.`orgname`,'')) when (`ctc`.`coc_no` is not null) then concat(ifnull(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`),''),' - ',ifnull(`fo`.`orgname`,'')) else NULL end) AS `granteeFieldOffice` from ((((`tap_tbl_workplan` `wp` left join `tap_tbl_recipient` `recipient` on((`recipient`.`workplanid` = `wp`.`id`))) left join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) left join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) left join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) where ((`wp`.`tatype` not in (2,3)) and isnull(`wp`.`assignmentid`)) union select `wp`.`id` AS `wpID`,`recipient`.`id` AS `recipientid`,`recipient`.`recipientTypeID` AS `recipientTypeID`,`recipient`.`sortorder` AS `sortorder`,(case when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 4)) then 1 when ((`cto`.`orgname` is not null) and (`recipient`.`recipientTypeID` = 7)) then 3 else 2 end) AS `recipientTypeSort`,(case when (`cto`.`orgname` is not null) then `recipient`.`granteeid` else `ctc`.`coc_no` end) AS `granteeid`,(case when (`cto`.`orgname` is not null) then `cto`.`grantee_state` else `ctc`.`state_id` end) AS `granteestate`,(case when (`cto`.`orgname` is not null) then `cto`.`orgname` else concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`) end) AS `granteename`,`fo`.`orgname` AS `fieldOffice`,(case when (`cto`.`orgname` is not null) then concat(ifnull(`cto`.`orgname`,''),' - ',ifnull(`fo`.`orgname`,'')) when (`ctc`.`coc_no` is not null) then concat(ifnull(concat(`ctc`.`coc_no`,' - ',`ctc`.`coc_name`),''),' - ',ifnull(`fo`.`orgname`,'')) else NULL end) AS `granteeFieldOffice` from ((((((`tap_tbl_workplan` `wp` left join `tap_asc_oncallwp_assignment` `a` on((`a`.`workplanid` = `wp`.`id`))) left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `a`.`assignmentid`))) left join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) left join `c_torganizations` `fo` on((`fo`.`orgid` = `recipient`.`fieldofficeid`))) left join `c_torganizations` `cto` on((`cto`.`orgid` = `recipient`.`granteeid`))) left join `c_tcoc` `ctc` on((`ctc`.`coc_no` = `recipient`.`coc_no`))) where ((`wp`.`tatype` in (2,3)) and (`a`.`association_completed` = 1)) union select `wp`.`id` AS `wpID`,NULL AS `recipientid`,NULL AS `recipientTypeID`,NULL AS `sortorder`,2 AS `recipientTypeSort`,NULL AS `granteeid`,NULL AS `granteestate`,NULL AS `granteename`,NULL AS `fieldOffice`,NULL AS `granteeFieldOffice` from `tap_tbl_workplan` `wp` where ((not(exists(select `assignment`.`workplanid` from `tap_asc_oncallwp_assignment` `assignment` where ((`assignment`.`association_completed` = 1) and (`assignment`.`workplanid` = `wp`.`id`))))) and (`wp`.`tatype` in (2,3))) */;

--
-- Final view structure for view `tap_vw_workplangranteeslist`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplangranteeslist`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplangranteeslist`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplangranteeslist` AS select `tap_vw_workplangrantees`.`wpID` AS `wpid`,group_concat(distinct `tap_vw_workplangrantees`.`granteename` order by `tap_vw_workplangrantees`.`granteename` ASC separator ';') AS `granteeName`,group_concat(distinct `tap_vw_workplangrantees`.`granteestate` order by `tap_vw_workplangrantees`.`granteestate` ASC separator ';') AS `granteestate`,group_concat(distinct `tap_vw_workplangrantees`.`fieldOffice` order by `tap_vw_workplangrantees`.`fieldOffice` ASC separator ';') AS `fieldOfficeName`,group_concat(distinct `tap_vw_workplangrantees`.`granteeFieldOffice` order by `tap_vw_workplangrantees`.`granteename` ASC separator ';') AS `granteeFieldOfficeNames` from `tap_vw_workplangrantees` group by `tap_vw_workplangrantees`.`wpID` */;

--
-- Final view structure for view `tap_vw_workplanhighestversion_approved`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanhighestversion_approved`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanhighestversion_approved`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanhighestversion_approved` AS select distinct `a`.`parent_wpid` AS `parent_wpid`,max(`wp`.`id`) AS `latestversioncreated_approved`,`wp`.`approveddate` AS `approveddate` from (`tap_tbl_workplan` `wp` join `tap_asc_amendment` `a` on(((`a`.`original_wp` = `wp`.`id`) or (`a`.`amended_wp` = `wp`.`id`)))) where (`wp`.`approveddate` is not null) group by `a`.`parent_wpid` */;

--
-- Final view structure for view `tap_vw_workplanlasteddates`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanlasteddates`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanlasteddates`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanlasteddates` AS select `taa1`.`parent_wpid` AS `parent_wpid`,if((max(`ttw1`.`approveddate`) > `ttwparent`.`approveddate`),max(`ttw1`.`approveddate`),`ttwparent`.`approveddate`) AS `maxapproveddate` from ((`tap_asc_amendment` `taa1` join `tap_tbl_workplan` `ttw1` on((`taa1`.`amended_wp` = `ttw1`.`id`))) join `tap_tbl_workplan` `ttwparent` on((`ttwparent`.`id` = `taa1`.`parent_wpid`))) group by `taa1`.`parent_wpid` */;

--
-- Final view structure for view `tap_vw_workplanlastestliveversion`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanlastestliveversion`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanlastestliveversion`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanlastestliveversion` AS select distinct `taa`.`parent_wpid` AS `parent_wpid`,(case when ((`ttw`.`approveddate` is not null) and (`tvwld`.`maxapproveddate` = `ttw`.`approveddate`)) then `ttw`.`id` when (`tvwld`.`maxapproveddate` = `ttwparent`.`approveddate`) then `ttwparent`.`id` end) AS `latestliveid` from (((`tap_asc_amendment` `taa` join `tap_tbl_workplan` `ttw` on((`taa`.`amended_wp` = `ttw`.`id`))) join `tap_vw_workplanlasteddates` `tvwld` on((`tvwld`.`parent_wpid` = `taa`.`parent_wpid`))) join `tap_tbl_workplan` `ttwparent` on((`taa`.`parent_wpid` = `ttwparent`.`id`))) where (case when ((`ttw`.`approveddate` is not null) and (`tvwld`.`maxapproveddate` = `ttw`.`approveddate`)) then (1 = 1) when (`tvwld`.`maxapproveddate` = `ttwparent`.`approveddate`) then (1 = 1) else (1 = 0) end) */;

--
-- Final view structure for view `tap_vw_workplanorgs2`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanorgs2`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanorgs2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanorgs2` AS select `ttw`.`id` AS `wpID`,`granteesdata`.`grantees` AS `grantees`,`granteesdata`.`granteeNoticesent_date` AS `granteeNoticesent_date`,`granteesdata`.`granteenames` AS `granteenames`,`granteesdata`.`fieldOffice` AS `fieldOffice`,`granteesdata`.`granteFieldOffices` AS `granteFieldOffices`,`cocdata`.`coc_nos` AS `coc_nos`,`cocdata`.`cocNoticesent_date` AS `cocNoticesent_date`,`cocdata`.`cocnames` AS `cocnames`,`cocdata`.`cocFieldOffice` AS `cocFieldOffice`,`cocdata`.`cocFieldOffices` AS `cocFieldOffices`,`hmisdata`.`hmiss` AS `hmisID`,`hmisdata`.`hmisNoticesent_date` AS `hmisNoticesent_date`,`hmisdata`.`hmisnames` AS `hmisnames`,`hmisdata`.`hmisFieldOffice` AS `hmisFieldOffice`,`hmisdata`.`hmisFieldOffices` AS `hmisFieldOffices`,concat_ws('; ',`granteesdata`.`granteenames`,`cocdata`.`cocnames`,`hmisdata`.`hmisnames`) AS `granteename`,concat_ws('; ',`granteesdata`.`fieldOffice`,`cocdata`.`cocFieldOffice`,`hmisdata`.`hmisFieldOffice`) AS `fieldOfficeName`,concat_ws('; ',`granteesdata`.`granteFieldOffices`,`cocdata`.`cocFieldOffices`,`hmisdata`.`hmisFieldOffices`) AS `granteFieldOfficeNames` from (((`tap_tbl_workplan` `ttw` left join `tap_vw_getgrantees` `granteesdata` on((`granteesdata`.`id` = `ttw`.`id`))) left join `tap_vw_getcocs` `cocdata` on((`cocdata`.`id` = `ttw`.`id`))) left join `tap_vw_gethmis` `hmisdata` on((`hmisdata`.`id` = `ttw`.`id`))) */;

--
-- Final view structure for view `tap_vw_workplansearchgrantees`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplansearchgrantees`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplansearchgrantees`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplansearchgrantees` AS select distinct `grantee`.`granteeid` AS `granteeid` from (((`tap_vw_workplangrantees` `grantee` left join `tap_tbl_workplan` `wp` on((`grantee`.`wpID` = `wp`.`id`))) left join `tap_lku_status` `tls` on((`tls`.`id` = `wp`.`status`))) left join `tap_tbl_assignment` `assign` on((`assign`.`id` = `wp`.`assignmentid`))) where ((`grantee`.`granteeid` is not null) and (`wp`.`id` is not null) and ((substr(`tls`.`status`,-(5)) <> 'Draft') or ((substr(`tls`.`status`,-(5)) = 'Draft') and (`wp`.`coop` is not null) and (`wp`.`enddate` is not null) and (`wp`.`startdate` is not null) and (`wp`.`fundingsource` is not null) and (`wp`.`workplan_num` is not null)) or ((substr(`tls`.`status`,-(5)) = 'Draft') and (isnull(`wp`.`coop`) or isnull(`wp`.`enddate`) or isnull(`wp`.`startdate`) or isnull(`wp`.`fundingsource`) or isnull(`wp`.`workplan_num`)) and (((`wp`.`tatype` not in (2,3)) and ((`assign`.`noticesent` = 1) or isnull(`assign`.`id`))) or ((`wp`.`tatype` in (2,3)) and ((`assign`.`noticesent` = 1) or (not(`wp`.`id` in (select distinct `tap_asc_oncallwp_assignment`.`workplanid` from `tap_asc_oncallwp_assignment` where (`tap_asc_oncallwp_assignment`.`association_completed` = 1)))))))))) union select distinct (case when (`recipient`.`granteeid` is not null) then `recipient`.`granteeid` else `recipient`.`coc_no` end) AS `granteeid` from (((`tap_tbl_assignment` `assign` join `tap_tbl_recipient` `recipient` on((`recipient`.`requestid` = `assign`.`requestid`))) left join `tap_tbl_workplan` `wp` on((`assign`.`id` = `wp`.`assignmentid`))) left join `tap_asc_oncallwp_assignment` `oncall` on(((`oncall`.`assignmentid` = `assign`.`id`) and ((`oncall`.`association_completed` = '0') or isnull(`oncall`.`association_completed`))))) where ((`recipient`.`granteeid` is not null) and isnull(`wp`.`id`) and (`assign`.`noticesent` = 1) and (not(`assign`.`id` in (select distinct `tap_asc_oncallwp_assignment`.`assignmentid` from `tap_asc_oncallwp_assignment` where (`tap_asc_oncallwp_assignment`.`association_completed` = 1))))) */;

--
-- Final view structure for view `tap_vw_workplanstatuslatestdates`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanstatuslatestdates`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanstatuslatestdates`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanstatuslatestdates` AS select `x`.`wpid` AS `wpid`,`x`.`submittedToGTM` AS `submittedToGTM`,`x`.`submittedToGTR` AS `submittedToGTR`,`x`.`submittedModificationDate` AS `submittedModificationDate`,`x`.`GTMApprovalDate` AS `GTMApprovalDate`,`x`.`GTRApprovalDate` AS `GTRApprovalDate`,(case when (`x`.`PutOnHoldDate` < `x`.`holdRemovedDate`) then NULL else `x`.`PutOnHoldDate` end) AS `PutOnHoldDate`,`x`.`holdRemovedDate` AS `holdRemovedDate`,(case when (`x`.`canceledDate` < `x`.`cancelationRemovedDate`) then NULL else `x`.`canceledDate` end) AS `canceledDate`,`x`.`cancelationRemovedDate` AS `cancelationRemovedDate` from `tap_vw_workplanstatuslatestdates_getdata` `x` order by `x`.`wpid` */;

--
-- Final view structure for view `tap_vw_workplanstatuslatestdates_getdata`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanstatuslatestdates_getdata`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanstatuslatestdates_getdata`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanstatuslatestdates_getdata` AS select `ttw`.`id` AS `wpid`,substring_index(group_concat(if(((`ttc`.`for_status` = 3) and ((`ttc`.`description` like 'Work Plan Submitted%') or (`ttc`.`description` like 'Work Plan Amendment Submitted%'))),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `submittedToGTM`,substring_index(group_concat(if(((`ttc`.`for_status` = 4) and ((`ttc`.`description` like 'Work Plan Submitted%') or (`ttc`.`description` like 'Work Plan Amendment Submitted%'))),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `submittedToGTR`,substring_index(group_concat(if(((`ttc`.`for_status` = 5) and (`ttc`.`description` like '%Modification Submitted%')),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `submittedModificationDate`,substring_index(group_concat(if(((`ttc`.`for_status` = 4) and (`ttc`.`description` like '%Approved by GTM%')),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `GTMApprovalDate`,substring_index(group_concat(if(((`ttc`.`for_status` = 5) and (`ttc`.`description` like '%Approved by GTR%')),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `GTRApprovalDate`,substring_index(group_concat(if((`ttc`.`for_status` = 6),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `PutOnHoldDate`,substring_index(group_concat(if((((`ttc`.`for_status` = 3) or (`ttc`.`for_status` = 4) or (`ttc`.`for_status` = 5)) and (`ttc`.`description` like '%Hold removed%')),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `holdRemovedDate`,substring_index(group_concat(if((`ttc`.`for_status` = 7),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `canceledDate`,substring_index(group_concat(if((((`ttc`.`for_status` = 3) or (`ttc`.`for_status` = 4) or (`ttc`.`for_status` = 5)) and (`ttc`.`description` like '%Cancelation removed%')),`ttc`.`createddate`,NULL) separator ','),',',-(1)) AS `cancelationRemovedDate` from (`tap_tbl_workplan` `ttw` left join `tap_tbl_comments` `ttc` on((`ttw`.`id` = `ttc`.`workplanid`))) group by `ttw`.`id` order by `ttw`.`id` */;

--
-- Final view structure for view `tap_vw_workplanversions`
--

/*!50001 DROP TABLE IF EXISTS `tap_vw_workplanversions`*/;
/*!50001 DROP VIEW IF EXISTS `tap_vw_workplanversions`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tap_vw_workplanversions` AS select `taa2`.`parent_wpid` AS `parent_wpid`,max(`taa2`.`workplan_trail`) AS `versionTrail`,convert(concat(concat(convert(concat('{"versions":[') using utf8),'{','"vWPID": ',convert(concat('"',`parentttw`.`id`,'"') using utf8),',"grantee": ',concat('"',if(isnull(`parentttw`.`name_granteeid`),ifnull(concat(`parenttc`.`coc_no`,' - ',`parenttc`.`coc_name`),''),ifnull(`parentcto`.`orgname`,'')),'"'),',"subjectName": ',concat('"',ifnull(`parentSubj`.`name`,''),'"'),',"taProvider": ',concat('"',`parentTa`.`orgname`,'"'),',"taType": ',concat('"',`parenttlt`.`name`,'"'),',"POP": ',concat('"',ifnull(`parentttw`.`periodofperformance`,''),'"'),',"version": "1"',',"editType": ',concat('"',ifnull(`parentttw`.`edittype_id`,''),'"'),',"editTypeName": ',concat('"',ifnull(`parenttlet`.`workplan_edittype`,''),'"'),',"isAmendment":',concat('"',`parentttw`.`isAmendment`,'"'),',"isVersion":',concat('"',`parentttw`.`isVersion`,'"'),',"status":',concat('"',`parenttls`.`status`,'"'),',"wpName":',if(isnull(`parentttw`.`workplan_name`),'""',concat('"',`parentttw`.`workplan_name`,'"')),'},'),concat(group_concat(concat('{','"vWPID": ',convert(concat('"',`ttw`.`id`,'"') using utf8),',"grantee": ',concat('"',if(isnull(`ttw`.`name_granteeid`),ifnull(concat(`tc`.`coc_no`,' - ',`tc`.`coc_name`),''),ifnull(`cto`.`orgname`,'')),'"'),',"subjectName": ',concat('"',ifnull(`subj`.`name`,''),'"'),',"taProvider": ',concat('"',`ta`.`orgname`,'"'),',"taType": ',concat('"',`tlt`.`name`,'"'),',"POP": ',concat('"',ifnull(`ttw`.`periodofperformance`,''),'"'),',"version": ',convert(concat('"',`taa2`.`version`,'"') using utf8),',"editType": ',concat('"',ifnull(`ttw`.`edittype_id`,''),'"'),',"editTypeName": ',concat('"',ifnull(`tlet`.`workplan_edittype`,''),'"'),',"isAmendment":',concat('"',`ttw`.`isAmendment`,'"'),',"isVersion":',concat('"',`ttw`.`isVersion`,'"'),',"status":',concat('"',`tls`.`status`,'"'),',"wpName":',if(isnull(`ttw`.`workplan_name`),'""',concat('"',`ttw`.`workplan_name`,'"')),'}') separator ','),']}')) using utf8) AS `versionData` from ((((((((((((((((`tap_asc_amendment` `taa2` join `tap_tbl_workplan` `ttw` on((`ttw`.`id` = `taa2`.`amended_wp`))) join `tap_lku_tatype` `tlt` on((`tlt`.`id` = `ttw`.`tatype`))) left join `tap_lku_edittype` `tlet` on((`tlet`.`id` = `ttw`.`edittype_id`))) left join `c_torganizations` `cto` on((`cto`.`orgid` = `ttw`.`name_granteeid`))) left join `c_tcoc` `tc` on((`tc`.`coc_no` = `ttw`.`name_coc_no`))) join `tap_lku_status` `tls` on((`tls`.`id` = `ttw`.`status`))) left join `c_torganizations` `ta` on((`ta`.`orgid` = `ttw`.`taproviderid`))) left join `tap_lku_subject` `subj` on((`subj`.`id` = `ttw`.`subject_id`))) join `tap_tbl_workplan` `parentttw` on((`parentttw`.`id` = `taa2`.`parent_wpid`))) join `tap_lku_tatype` `parenttlt` on((`parenttlt`.`id` = `parentttw`.`tatype`))) left join `tap_lku_edittype` `parenttlet` on((`parenttlet`.`id` = `parentttw`.`edittype_id`))) left join `c_torganizations` `parentcto` on((`parentcto`.`orgid` = `parentttw`.`name_granteeid`))) left join `c_tcoc` `parenttc` on((`parenttc`.`coc_no` = `parentttw`.`name_coc_no`))) join `tap_lku_status` `parenttls` on((`parenttls`.`id` = `parentttw`.`status`))) left join `c_torganizations` `parentTa` on((`parentTa`.`orgid` = `parentttw`.`taproviderid`))) left join `tap_lku_subject` `parentSubj` on((`parentSubj`.`id` = `parentttw`.`subject_id`))) group by `taa2`.`parent_wpid` order by `taa2`.`version` */;

--
-- Final view structure for view `um_vw_aaq_useraccess`
--

/*!50001 DROP TABLE IF EXISTS `um_vw_aaq_useraccess`*/;
/*!50001 DROP VIEW IF EXISTS `um_vw_aaq_useraccess`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `um_vw_aaq_useraccess` AS select `sq`.`userid` AS `userid`,group_concat(`sq`.`BRAC` separator ',') AS `BRAC`,group_concat(`sq`.`CDBG` separator ',') AS `CDBG`,group_concat(`sq`.`CoC` separator ',') AS `CoC`,group_concat(`sq`.`ConPlan` separator ',') AS `ConPlan`,group_concat(`sq`.`DRGR` separator ',') AS `DRGR`,group_concat(`sq`.`Environmental Review` separator ',') AS `Environmental Review`,group_concat(`sq`.`ESG` separator ',') AS `ESG`,group_concat(`sq`.`e-snaps` separator ',') AS `e-snaps`,group_concat(`sq`.`HDX` separator ',') AS `HDX`,group_concat(`sq`.`HMIS` separator ',') AS `HMIS`,group_concat(`sq`.`HOME` separator ',') AS `HOME`,group_concat(`sq`.`HOPWA` separator ',') AS `HOPWA`,group_concat(`sq`.`HUD-VASH` separator ',') AS `HUD-VASH`,group_concat(`sq`.`IDIS` separator ',') AS `IDIS`,group_concat(`sq`.`Legacy Homeless Programs` separator ',') AS `Legacy Homeless Programs`,group_concat(`sq`.`NSP` separator ',') AS `NSP`,group_concat(`sq`.`Title V` separator ',') AS `Title V`,group_concat(`sq`.`VHPD` separator ',') AS `VHPD`,group_concat(`sq`.`General Public` separator ',') AS `General Public`,group_concat(`sq`.`Albuquerque Field Office` separator ',') AS `Albuquerque Field Office`,group_concat(`sq`.`Anchorage Field Office` separator ',') AS `Anchorage Field Office`,group_concat(`sq`.`Atlanta Regional Office` separator ',') AS `Atlanta Regional Office`,group_concat(`sq`.`Baltimore Field Office` separator ',') AS `Baltimore Field Office`,group_concat(`sq`.`Birmingham Field Office` separator ',') AS `Birmingham Field Office`,group_concat(`sq`.`Boston Regional Office` separator ',') AS `Boston Regional Office`,group_concat(`sq`.`Buffalo Field Office` separator ',') AS `Buffalo Field Office`,group_concat(`sq`.`Chicago Regional Office` separator ',') AS `Chicago Regional Office`,group_concat(`sq`.`Columbia Field Office` separator ',') AS `Columbia Field Office`,group_concat(`sq`.`Columbus Field Office` separator ',') AS `Columbus Field Office`,group_concat(`sq`.`Denver Regional Office` separator ',') AS `Denver Regional Office`,group_concat(`sq`.`Detroit Field Office` separator ',') AS `Detroit Field Office`,group_concat(`sq`.`Ft. Worth Regional Office` separator ',') AS `Ft. Worth Regional Office`,group_concat(`sq`.`Greensboro Field Office` separator ',') AS `Greensboro Field Office`,group_concat(`sq`.`Hartford Field Office` separator ',') AS `Hartford Field Office`,group_concat(`sq`.`Honolulu Field Office` separator ',') AS `Honolulu Field Office`,group_concat(`sq`.`Houston Field Office` separator ',') AS `Houston Field Office`,group_concat(`sq`.`Indianapolis Field Office` separator ',') AS `Indianapolis Field Office`,group_concat(`sq`.`Jackson Field Office` separator ',') AS `Jackson Field Office`,group_concat(`sq`.`Jacksonville Field Office` separator ',') AS `Jacksonville Field Office`,group_concat(`sq`.`Kansas City Regional Office` separator ',') AS `Kansas City Regional Office`,group_concat(`sq`.`Knoxville Field Office` separator ',') AS `Knoxville Field Office`,group_concat(`sq`.`Little Rock Field Office` separator ',') AS `Little Rock Field Office`,group_concat(`sq`.`Los Angeles Field Office` separator ',') AS `Los Angeles Field Office`,group_concat(`sq`.`Louisville Field Office` separator ',') AS `Louisville Field Office`,group_concat(`sq`.`Miami Field Office` separator ',') AS `Miami Field Office`,group_concat(`sq`.`Milwaukee Field Office` separator ',') AS `Milwaukee Field Office`,group_concat(`sq`.`Minneapolis Field Office` separator ',') AS `Minneapolis Field Office`,group_concat(`sq`.`New Orleans Field Office` separator ',') AS `New Orleans Field Office`,group_concat(`sq`.`New York Regional Office` separator ',') AS `New York Regional Office`,group_concat(`sq`.`Newark Field Office` separator ',') AS `Newark Field Office`,group_concat(`sq`.`Oklahoma City Field Office` separator ',') AS `Oklahoma City Field Office`,group_concat(`sq`.`Omaha Field Office` separator ',') AS `Omaha Field Office`,group_concat(`sq`.`Philadelphia Regional Office` separator ',') AS `Philadelphia Regional Office`,group_concat(`sq`.`Pittsburgh Field Office` separator ',') AS `Pittsburgh Field Office`,group_concat(`sq`.`Portland Field Office` separator ',') AS `Portland Field Office`,group_concat(`sq`.`Richmond Field Office` separator ',') AS `Richmond Field Office`,group_concat(`sq`.`San Antonio Field Office` separator ',') AS `San Antonio Field Office`,group_concat(`sq`.`San Francisco Regional Office` separator ',') AS `San Francisco Regional Office`,group_concat(`sq`.`San Juan (Caribbean) Field Office` separator ',') AS `San Juan (Caribbean) Field Office`,group_concat(`sq`.`Seattle Regional Office` separator ',') AS `Seattle Regional Office`,group_concat(`sq`.`St. Louis Field Office` separator ',') AS `St. Louis Field Office`,group_concat(`sq`.`Washington DC Office` separator ',') AS `Washington DC Office` from `um_vw_aaq_useraccess_subquery2` `sq` group by `sq`.`userid` */;

--
-- Final view structure for view `um_vw_aaq_useraccess_subquery`
--

/*!50001 DROP TABLE IF EXISTS `um_vw_aaq_useraccess_subquery`*/;
/*!50001 DROP VIEW IF EXISTS `um_vw_aaq_useraccess_subquery`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `um_vw_aaq_useraccess_subquery` AS select `ur`.`user_id` AS `userid`,(case when (`ur`.`pool_id` is not null) then 1 else 2 end) AS `sort_order`,ifnull(`p`.`short_name`,`fo`.`orgname`) AS `group_name`,concat(`r`.`name`,'/',`pe`.`name`) AS `role_name` from ((((`aaq_tbl_user_role` `ur` left join `aaq_lku_pool` `p` on(((`p`.`id` = `ur`.`pool_id`) and (`p`.`active_um` = 1)))) left join `c_torganizations` `fo` on((`fo`.`orgid` = `ur`.`fieldoffice_id`))) join `aaq_lku_role` `r` on((`r`.`id` = `ur`.`role_id`))) join `aaq_lku_permission` `pe` on((`pe`.`id` = `ur`.`permission_id`))) order by (case when (`ur`.`pool_id` is not null) then 1 else 2 end),`ur`.`user_id`,`p`.`name`,`fo`.`orgname`,`r`.`name`,`pe`.`name` */;

--
-- Final view structure for view `um_vw_aaq_useraccess_subquery2`
--

/*!50001 DROP TABLE IF EXISTS `um_vw_aaq_useraccess_subquery2`*/;
/*!50001 DROP VIEW IF EXISTS `um_vw_aaq_useraccess_subquery2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `um_vw_aaq_useraccess_subquery2` AS select `sq`.`userid` AS `userid`,(case when (`sq`.`group_name` = 'BRAC') then `sq`.`role_name` else NULL end) AS `BRAC`,(case when (`sq`.`group_name` = 'CDBG') then `sq`.`role_name` else NULL end) AS `CDBG`,(case when (`sq`.`group_name` = 'CoC') then `sq`.`role_name` else NULL end) AS `CoC`,(case when (`sq`.`group_name` = 'ConPlan') then `sq`.`role_name` else NULL end) AS `ConPlan`,(case when (`sq`.`group_name` = 'DRGR') then `sq`.`role_name` else NULL end) AS `DRGR`,(case when (`sq`.`group_name` = 'Environmental Review') then `sq`.`role_name` else NULL end) AS `Environmental Review`,(case when (`sq`.`group_name` = 'ESG') then `sq`.`role_name` else NULL end) AS `ESG`,(case when (`sq`.`group_name` = 'e-snaps') then `sq`.`role_name` else NULL end) AS `e-snaps`,(case when (`sq`.`group_name` = 'FederalReporting.gov') then `sq`.`role_name` else NULL end) AS `FederalReporting.gov`,(case when (`sq`.`group_name` = 'HDX') then `sq`.`role_name` else NULL end) AS `HDX`,(case when (`sq`.`group_name` = 'HMIS') then `sq`.`role_name` else NULL end) AS `HMIS`,(case when (`sq`.`group_name` = 'HOME') then `sq`.`role_name` else NULL end) AS `HOME`,(case when (`sq`.`group_name` = 'HOPWA') then `sq`.`role_name` else NULL end) AS `HOPWA`,(case when (`sq`.`group_name` = 'HUD-VASH') then `sq`.`role_name` else NULL end) AS `HUD-VASH`,(case when (`sq`.`group_name` = 'IDIS') then `sq`.`role_name` else NULL end) AS `IDIS`,(case when (`sq`.`group_name` = 'Legacy Homeless Programs') then `sq`.`role_name` else NULL end) AS `Legacy Homeless Programs`,(case when (`sq`.`group_name` = 'NSP') then `sq`.`role_name` else NULL end) AS `NSP`,(case when (`sq`.`group_name` = 'RHSP') then `sq`.`role_name` else NULL end) AS `RHSP`,(case when (`sq`.`group_name` = 'Section 108') then `sq`.`role_name` else NULL end) AS `Section 108`,(case when (`sq`.`group_name` = 'Title V') then `sq`.`role_name` else NULL end) AS `Title V`,(case when (`sq`.`group_name` = 'VHPD') then `sq`.`role_name` else NULL end) AS `VHPD`,(case when (`sq`.`group_name` = 'General Public') then `sq`.`role_name` else NULL end) AS `General Public`,(case when (`sq`.`group_name` = 'Albuquerque Field Office') then `sq`.`role_name` else NULL end) AS `Albuquerque Field Office`,(case when (`sq`.`group_name` = 'Anchorage Field Office') then `sq`.`role_name` else NULL end) AS `Anchorage Field Office`,(case when (`sq`.`group_name` = 'Atlanta Regional Office') then `sq`.`role_name` else NULL end) AS `Atlanta Regional Office`,(case when (`sq`.`group_name` = 'Baltimore Field Office') then `sq`.`role_name` else NULL end) AS `Baltimore Field Office`,(case when (`sq`.`group_name` = 'Birmingham Field Office') then `sq`.`role_name` else NULL end) AS `Birmingham Field Office`,(case when (`sq`.`group_name` = 'Boston Regional Office') then `sq`.`role_name` else NULL end) AS `Boston Regional Office`,(case when (`sq`.`group_name` = 'Buffalo Field Office') then `sq`.`role_name` else NULL end) AS `Buffalo Field Office`,(case when (`sq`.`group_name` = 'Chicago Regional Office') then `sq`.`role_name` else NULL end) AS `Chicago Regional Office`,(case when (`sq`.`group_name` = 'Columbia Field Office') then `sq`.`role_name` else NULL end) AS `Columbia Field Office`,(case when (`sq`.`group_name` = 'Columbus Field Office') then `sq`.`role_name` else NULL end) AS `Columbus Field Office`,(case when (`sq`.`group_name` = 'Denver Regional Office') then `sq`.`role_name` else NULL end) AS `Denver Regional Office`,(case when (`sq`.`group_name` = 'Detroit Field Office') then `sq`.`role_name` else NULL end) AS `Detroit Field Office`,(case when (`sq`.`group_name` = 'Ft. Worth Regional Office') then `sq`.`role_name` else NULL end) AS `Ft. Worth Regional Office`,(case when (`sq`.`group_name` = 'Greensboro Field Office') then `sq`.`role_name` else NULL end) AS `Greensboro Field Office`,(case when (`sq`.`group_name` = 'Hartford Field Office') then `sq`.`role_name` else NULL end) AS `Hartford Field Office`,(case when (`sq`.`group_name` = 'Honolulu Field Office') then `sq`.`role_name` else NULL end) AS `Honolulu Field Office`,(case when (`sq`.`group_name` = 'Houston Field Office') then `sq`.`role_name` else NULL end) AS `Houston Field Office`,(case when (`sq`.`group_name` = 'Indianapolis Field Office') then `sq`.`role_name` else NULL end) AS `Indianapolis Field Office`,(case when (`sq`.`group_name` = 'Jackson Field Office') then `sq`.`role_name` else NULL end) AS `Jackson Field Office`,(case when (`sq`.`group_name` = 'Jacksonville Field Office') then `sq`.`role_name` else NULL end) AS `Jacksonville Field Office`,(case when (`sq`.`group_name` = 'Kansas City Regional Office') then `sq`.`role_name` else NULL end) AS `Kansas City Regional Office`,(case when (`sq`.`group_name` = 'Knoxville Field Office') then `sq`.`role_name` else NULL end) AS `Knoxville Field Office`,(case when (`sq`.`group_name` = 'Little Rock Field Office') then `sq`.`role_name` else NULL end) AS `Little Rock Field Office`,(case when (`sq`.`group_name` = 'Los Angeles Field Office') then `sq`.`role_name` else NULL end) AS `Los Angeles Field Office`,(case when (`sq`.`group_name` = 'Louisville Field Office') then `sq`.`role_name` else NULL end) AS `Louisville Field Office`,(case when (`sq`.`group_name` = 'Miami Field Office') then `sq`.`role_name` else NULL end) AS `Miami Field Office`,(case when (`sq`.`group_name` = 'Milwaukee Field Office') then `sq`.`role_name` else NULL end) AS `Milwaukee Field Office`,(case when (`sq`.`group_name` = 'Minneapolis Field Office') then `sq`.`role_name` else NULL end) AS `Minneapolis Field Office`,(case when (`sq`.`group_name` = 'New Orleans Field Office') then `sq`.`role_name` else NULL end) AS `New Orleans Field Office`,(case when (`sq`.`group_name` = 'New York Regional Office') then `sq`.`role_name` else NULL end) AS `New York Regional Office`,(case when (`sq`.`group_name` = 'Newark Field Office') then `sq`.`role_name` else NULL end) AS `Newark Field Office`,(case when (`sq`.`group_name` = 'Oklahoma City Field Office') then `sq`.`role_name` else NULL end) AS `Oklahoma City Field Office`,(case when (`sq`.`group_name` = 'Omaha Field Office') then `sq`.`role_name` else NULL end) AS `Omaha Field Office`,(case when (`sq`.`group_name` = 'Philadelphia Regional Office') then `sq`.`role_name` else NULL end) AS `Philadelphia Regional Office`,(case when (`sq`.`group_name` = 'Pittsburgh Field Office') then `sq`.`role_name` else NULL end) AS `Pittsburgh Field Office`,(case when (`sq`.`group_name` = 'Portland Field Office') then `sq`.`role_name` else NULL end) AS `Portland Field Office`,(case when (`sq`.`group_name` = 'Richmond Field Office') then `sq`.`role_name` else NULL end) AS `Richmond Field Office`,(case when (`sq`.`group_name` = 'San Antonio Field Office') then `sq`.`role_name` else NULL end) AS `San Antonio Field Office`,(case when (`sq`.`group_name` = 'San Francisco Regional Office') then `sq`.`role_name` else NULL end) AS `San Francisco Regional Office`,(case when (`sq`.`group_name` = 'San Juan (Caribbean) Field Office') then `sq`.`role_name` else NULL end) AS `San Juan (Caribbean) Field Office`,(case when (`sq`.`group_name` = 'Seattle Regional Office') then `sq`.`role_name` else NULL end) AS `Seattle Regional Office`,(case when (`sq`.`group_name` = 'St. Louis Field Office') then `sq`.`role_name` else NULL end) AS `St. Louis Field Office`,(case when (`sq`.`group_name` = 'Washington, DC Office') then `sq`.`role_name` else NULL end) AS `Washington DC Office` from `um_vw_aaq_useraccess_subquery` `sq` where (`sq`.`group_name` is not null) */;

--
-- Final view structure for view `um_vw_userorg`
--

/*!50001 DROP TABLE IF EXISTS `um_vw_userorg`*/;
/*!50001 DROP VIEW IF EXISTS `um_vw_userorg`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`mkim`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `um_vw_userorg` AS select distinct `u`.`UserID` AS `UserID`,`u`.`UserName` AS `username`,`u`.`Email` AS `email`,`eua`.`attributeValue` AS `orgid`,(case when (isnull(`eua2`.`attributeValue`) or (`eua2`.`attributeValue` = '')) then 'Individual' else `eua2`.`attributeValue` end) AS `orgname` from ((((`tusers` `u` join `tclassextenddatauseractivity` `eua` on((`eua`.`baseID` = `u`.`UserID`))) join `tclassextendattributes` `ea` on(((`ea`.`attributeID` = `eua`.`attributeID`) and (`ea`.`name` = 'orgid')))) join `tclassextenddatauseractivity` `eua2` on((`eua2`.`baseID` = `u`.`UserID`))) join `tclassextendattributes` `ea2` on(((`ea2`.`attributeID` = `eua2`.`attributeID`) and (`ea2`.`name` = 'organization_name')))) */;


