Exemplo n.º 1
0
<?php

require_once "strings/strings.php";
defineCategoryColumns();
defineCommentColumns();
defineContactColumns();
defineContactTypeColumns();
defineContestColumns();
defineContestSubscriberColumns();
defineFeedbackColumns();
defineFollowColumns();
defineLogColumns();
defineMailColumns();
defineMailDirColumns();
defineMailInDirColumns();
definePostColumns();
defineReportColumns();
defineResourceColumns();
defineRoleColumns();
defineSubCategoryColumns();
defineTagColumns();
defineUserColumns();
defineVoteColumns();
define_tables();
$s = "CREATE TABLE IF NOT EXISTS `" . TABLE_CATEGORY . "` (\n  `" . CATEGORY_NAME . "` varchar(50) NOT NULL,\n  PRIMARY KEY (`" . CATEGORY_NAME . "`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_CONTEST . "` (\n  `" . CONTEST_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . CONTEST_TITLE . "` varchar(50) DEFAULT NULL,\n  `" . CONTEST_DESCRIPTION . "` text DEFAULT NULL,\n  `" . CONTEST_TYPE_OF_SUBSCRIBER . "` enum('post','photoreportage','videoreportage','news','collection','album','playlist','magazine') DEFAULT NULL,\n  `" . CONTEST_RULES . "` text,\n  `" . CONTEST_PRIZES . "` text DEFAULT NULL,\n  `" . CONTEST_START . "` datetime NULL DEFAULT NULL,\n  `" . CONTEST_END . "` datetime NULL DEFAULT NULL,\n  PRIMARY KEY (`" . CONTEST_ID . "`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_ROLE . "` (\n  `" . ROLE_NAME . "` varchar(50) NOT NULL,\n  PRIMARY KEY (`" . ROLE_NAME . "`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_USER . "` (\n  `" . USER_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . USER_NICKNAME . "` varchar(100) NULL,\n  `" . USER_E_MAIL . "` varchar(100) NOT NULL,\n  `" . USER_PASSWORD . "` varchar(128) NOT NULL,\n  `" . USER_NAME . "` varchar(100) NULL,\n  `" . USER_SURNAME . "` varchar(100) NULL,\n  `" . USER_GENDER . "` enum('m','f') DEFAULT NULL,\n  `" . USER_BIRTHDAY . "` date NULL,\n  `" . USER_BIRTHPLACE . "` varchar(255) NULL,\n  `" . USER_LIVINGPLACE . "` varchar(255) NULL,\n  `" . USER_AVATAR . "` varchar(255) DEFAULT NULL,\n  `" . USER_HOBBIES . "` varchar(200) NULL,\n  `" . USER_JOB . "` varchar(100) NULL,\n  `" . USER_ROLE . "` varchar(50) NULL DEFAULT 'user',\n  `" . USER_CREATION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  `" . USER_VISIBLE . "` tinyint(1) DEFAULT 0,\n  `" . USER_VERIFIED . "` tinyint(1) DEFAULT 0,\n  PRIMARY KEY (`" . USER_ID . "`),\n  UNIQUE KEY `" . USER_NICKNAME_UKEY . "` (`" . USER_NICKNAME . "`),\n  UNIQUE KEY `" . USER_E_MAIL_UKEY . "` (`" . USER_E_MAIL . "`),\n  KEY `" . USER_ROLE_FKEY . "` (`" . USER_ROLE . "`),\n  FOREIGN KEY (`" . USER_ROLE . "`) REFERENCES `" . TABLE_ROLE . "` (`" . ROLE_NAME . "`) ON DELETE SET NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_POST . "` (\n  `" . POST_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . POST_PERMALINK . "` text NOT NULL,\n  `" . POST_TYPE . "` enum('post','photoreportage','videoreportage','news','collection','album','playlist','magazine') DEFAULT NULL,\n  `" . POST_TITLE . "` varchar(100) NOT NULL,\n  `" . POST_SUBTITLE . "` varchar(100) NULL,\n  `" . POST_HEADLINE . "` varchar(100) NULL,\n  `" . POST_CREATION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  `" . POST_MODIFICATION_DATE . "` datetime NULL,\n  `" . POST_CONTENT . "` text NOT NULL,\n  `" . POST_TAGS . "` text NULL,\n  `" . POST_CATEGORIES . "` text NULL,\n  `" . POST_VISIBLE . "` tinyint(1) DEFAULT 0,\n  `" . POST_AUTHOR . "` bigint(20) NULL,\n  `" . POST_PLACE . "` text NULL,\n  PRIMARY KEY (`" . POST_ID . "`),\n  KEY `" . POST_USER_FKEY . "` (`" . POST_AUTHOR . "`),\n  FOREIGN KEY (`" . POST_AUTHOR . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE SET NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_COMMENT . "` (\n  `" . COMMENT_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . COMMENT_CREATION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  `" . COMMENT_COMMENT . "` text NOT NULL,\n  `" . COMMENT_AUTHOR . "` bigint(20) NULL,\n  `" . COMMENT_POST . "` bigint(20) NOT NULL,\n  PRIMARY KEY (`" . COMMENT_ID . "`),\n  KEY `" . COMMENT_USER_FKEY . "` (`" . COMMENT_AUTHOR . "`),\n  KEY `" . COMMENT_POST_FKEY . "` (`" . COMMENT_POST . "`),\n  FOREIGN KEY (`" . COMMENT_AUTHOR . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE SET NULL,\n  FOREIGN KEY (`" . COMMENT_POST . "`) REFERENCES `" . TABLE_POST . "` (`" . POST_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_CONTACT_TYPE . "` (\n  `" . CONTACT_TYPE_TYPE . "` enum('phone', 'address', 'email', 'website', 'IM') NOT NULL,\n  `" . CONTACT_TYPE_NAME . "` varchar(20) NOT NULL,\n  PRIMARY KEY (`" . CONTACT_TYPE_NAME . "`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_CONTACT . "` (\n  `" . CONTACT_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . CONTACT_CONTACT . "` varchar(100) NOT NULL,\n  `" . CONTACT_USER . "` bigint(20) NOT NULL,\n  `" . CONTACT_NAME . "` varchar(20) NULL DEFAULT 'other',\n  PRIMARY KEY (`" . CONTACT_ID . "`),\n  KEY `" . CONTACT_CONTACT_TYPE_FKEY . "` (`" . CONTACT_NAME . "`),\n  KEY `" . CONTACT_USER_FKEY . "` (`" . CONTACT_USER . "`),\n  FOREIGN KEY (`" . CONTACT_USER . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . CONTACT_NAME . "`) REFERENCES `" . TABLE_CONTACT_TYPE . "` (`" . CONTACT_TYPE_NAME . "`) ON DELETE SET NULL ON UPDATE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_CONTEST_SUBSCRIBER . "` (\n  `" . CONTEST_SUBSCRIBER_CONTEST . "` bigint(20) NOT NULL,\n  `" . CONTEST_SUBSCRIBER_POST . "` bigint(20) NOT NULL,\n  `" . CONTEST_SUBSCRIBER_PLACEMENT . "` tinyint(10) NOT NULL,\n  PRIMARY KEY (`" . CONTEST_SUBSCRIBER_CONTEST . "`,`" . CONTEST_SUBSCRIBER_POST . "`),\n  KEY `" . CONTEST_SUBSCRIBER_CONTEST_FKEY . "` (`" . CONTEST_SUBSCRIBER_CONTEST . "`),\n  KEY `" . CONTEST_SUBSCRIBER_POST_FKEY . "` (`" . CONTEST_SUBSCRIBER_POST . "`),\n  UNIQUE KEY `" . CONTEST_SUBSCRIBER_UKEY . "` (`" . CONTEST_SUBSCRIBER_CONTEST . "`, `" . CONTEST_SUBSCRIBER_PLACEMENT . "`),\n  FOREIGN KEY (`" . CONTEST_SUBSCRIBER_CONTEST . "`) REFERENCES `" . TABLE_CONTEST . "` (`" . CONTEST_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . CONTEST_SUBSCRIBER_POST . "`) REFERENCES `" . TABLE_POST . "` (`" . POST_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_FEEDBACK . "` (\n  `" . FEEDBACK_CREATOR . "` bigint(20) NOT NULL,\n  `" . FEEDBACK_SUBJECT . "` bigint(20) NOT NULL,\n  `" . FEEDBACK_VALUE . "` int(11) DEFAULT NULL,\n  `" . FEEDBACK_CREATION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`" . FEEDBACK_CREATOR . "`,`" . FEEDBACK_SUBJECT . "`),\n  KEY `" . FEEDBACK_USER_FKEY1 . "` (`" . FEEDBACK_CREATOR . "`),\n  KEY `" . FEEDBACK_USER_FKEY2 . "` (`" . FEEDBACK_SUBJECT . "`),\n  FOREIGN KEY (`" . FEEDBACK_CREATOR . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . FEEDBACK_SUBJECT . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_FOLLOW . "` (\n  `" . FOLLOW_SUBJECT . "` bigint(20) NOT NULL,\n  `" . FOLLOW_FOLLOWER . "` bigint(20) NOT NULL,\n  `" . FOLLOW_SUBSCRIPTION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`" . FOLLOW_SUBJECT . "`,`" . FOLLOW_FOLLOWER . "`),\n  KEY `" . FOLLOW_USER_FKEY1 . "` (`" . FOLLOW_SUBJECT . "`),\n  KEY `" . FOLLOW_USER_FKEY2 . "` (`" . FOLLOW_FOLLOWER . "`),\n  FOREIGN KEY (`" . FOLLOW_SUBJECT . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . FOLLOW_FOLLOWER . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_LOG . "` (\n  `" . LOG_ID . "` varchar(40) NOT NULL,\n  `" . LOG_TIMESTAMP . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  `" . LOG_ACTION . "` enum('INSERT','UPDATE','DELETE') NOT NULL,\n  `" . LOG_TABLE . "` varchar(20) NOT NULL,\n  `" . LOG_SUBJECT . "` bigint(20) NULL,\n  `" . LOG_OBJECT . "` varchar(40) NOT NULL,\n  PRIMARY KEY (`" . LOG_ID . "`),\n  KEY `" . LOG_USER_FKEY . "` (`" . LOG_SUBJECT . "`),\n  FOREIGN KEY (`" . LOG_SUBJECT . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE SET NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `AccessLog` (\n  `alog_type` varchar(10) NOT NULL,\n  `alog_id` bigint(20) NOT NULL,\n  `alog_count` bigint(20) NOT NULL DEFAULT 1,\n  PRIMARY KEY (`alog_type`, `alog_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_MAIL . "` (\n  `" . MAIL_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . MAIL_SUBJECT . "` varchar(50) DEFAULT NULL,\n  `" . MAIL_TEXT . "` text,\n  `" . MAIL_FROM . "` bigint(20) NOT NULL,\n  `" . MAIL_TO . "` varchar(255) NOT NULL,\n  `" . MAIL_REPLIES_TO . "` bigint(20) NULL,\n  `" . MAIL_CREATION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`" . MAIL_ID . "`),\n  KEY `" . MAIL_USER_FKEY . "` (`" . MAIL_FROM . "`),\n  KEY `" . MAIL_MAIL_FKEY . "` (`" . MAIL_REPLIES_TO . "`),\n  FOREIGN KEY (`" . MAIL_FROM . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . MAIL_REPLIES_TO . "`) REFERENCES `" . TABLE_MAIL . "` (`" . MAIL_ID . "`) ON DELETE SET NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_MAIL_DIRECTORY . "` (\n  `" . MAIL_DIRECTORY_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . MAIL_DIRECTORY_NAME . "` varchar(50) NOT NULL,\n  `" . MAIL_DIRECTORY_OWNER . "` bigint(20) NOT NULL,\n  PRIMARY KEY (`" . MAIL_DIRECTORY_ID . "`),\n  KEY `" . MAIL_DIRECTORY_USER_FKEY . "` (`" . MAIL_DIRECTORY_OWNER . "`),\n  FOREIGN KEY (`" . MAIL_DIRECTORY_OWNER . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_MAIL_IN_DIRECTORY . "` (\n  `" . MAIL_IN_DIRECTORY_READ . "` tinyint(1) DEFAULT 0,\n  `" . MAIL_IN_DIRECTORY_DIRECTORY . "` bigint(20) NOT NULL,\n  `" . MAIL_IN_DIRECTORY_MAIL . "` bigint(20) NOT NULL,\n  PRIMARY KEY (`mod_dir`,`mod_mail`),\n  KEY `" . MAIL_IN_DIRECTORY_MAIL_DIRECTORY_FKEY . "` (`" . MAIL_IN_DIRECTORY_DIRECTORY . "`),\n  KEY `" . MAIL_IN_DIRECTORY_MAIL_FKEY . "` (`" . MAIL_IN_DIRECTORY_MAIL . "`),\n  FOREIGN KEY (`" . MAIL_IN_DIRECTORY_DIRECTORY . "`) REFERENCES `" . TABLE_MAIL_DIRECTORY . "` (`" . MAIL_DIRECTORY_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . MAIL_IN_DIRECTORY_MAIL . "`) REFERENCES `" . TABLE_MAIL . "` (`" . MAIL_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_REPORT . "` (\n  `" . REPORT_ID . "` bigint(20) NOT NULL AUTO_INCREMENT,\n  `" . REPORT_POST . "` bigint(20) NOT NULL,\n  `" . REPORT_USER . "` bigint(20) NULL,\n  `rp_report` text NOT NULL,\n  PRIMARY KEY (`" . REPORT_ID . "`),\n  UNIQUE KEY `" . REPORT_USER_POST_UKEY . "` (`" . REPORT_POST . "`, `" . REPORT_USER . "`),\n  KEY `" . REPORT_POST_FKEY . "` (`" . REPORT_POST . "`),\n  KEY `" . REPORT_USER_FKEY . "` (`" . REPORT_USER . "`),\n  FOREIGN KEY (`" . REPORT_POST . "`) REFERENCES `" . TABLE_POST . "` (`" . POST_ID . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . REPORT_USER . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE SET NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_RESOURCE . "` (\n  `" . RESOURCE_ID . "` bigint(20) NOT NULL,\n  `" . RESOURCE_TYPE . "` enum('video','photo') NOT NULL,\n  `" . RESOURCE_PATH . "` varchar(255) NOT NULL,\n  `" . RESOURCE_OWNER . "` bigint(20) NULL,\n  PRIMARY KEY (`" . RESOURCE_ID . "`),\n  KEY `" . RESOURCE_USER_FKEY . "` (`" . RESOURCE_OWNER . "`),\n  FOREIGN KEY (`" . RESOURCE_OWNER . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE SET NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_SUB_CATEGORY . "` (\n  `" . SUB_CATEGORY_PARENT . "` varchar(50) NOT NULL,\n  `" . SUB_CATEGORY_CATEGORY . "` varchar(50) NOT NULL,\n  PRIMARY KEY (`" . SUB_CATEGORY_PARENT . "`,`" . SUB_CATEGORY_CATEGORY . "`),\n  KEY `" . SUB_CATEGORY_CATEGORY_FKEY1 . "` (`" . SUB_CATEGORY_PARENT . "`),\n  KEY `" . SUB_CATEGORY_CATEGORY_FKEY2 . "` (`" . SUB_CATEGORY_CATEGORY . "`),\n  FOREIGN KEY (`" . SUB_CATEGORY_PARENT . "`) REFERENCES `" . TABLE_CATEGORY . "` (`" . CATEGORY_NAME . "`) ON DELETE CASCADE,\n  FOREIGN KEY (`" . SUB_CATEGORY_CATEGORY . "`) REFERENCES `" . TABLE_CATEGORY . "` (`" . CATEGORY_NAME . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_TAG . "` (\n  `" . TAG_NAME . "` varchar(50) NOT NULL,\n  PRIMARY KEY (`" . TAG_NAME . "`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;\n\nCREATE TABLE IF NOT EXISTS `" . TABLE_VOTE . "` (\n  `" . VOTE_CREATION_DATE . "` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  `" . VOTE_VOTE . "` int(10) unsigned NOT NULL,\n  `" . VOTE_AUTHOR . "` bigint(20) NULL,\n  `" . VOTE_POST . "` bigint(20) NOT NULL,\n  KEY `" . VOTE_USER_FKEY . "` (`" . VOTE_AUTHOR . "`),\n  KEY `" . VOTE_POST_FKEY . "` (`" . VOTE_POST . "`),\n  FOREIGN KEY (`" . VOTE_AUTHOR . "`) REFERENCES `" . TABLE_USER . "` (`" . USER_ID . "`) ON DELETE SET NULL,\n  FOREIGN KEY (`" . VOTE_POST . "`) REFERENCES `" . TABLE_POST . "` (`" . POST_ID . "`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin DEFAULT CHARSET=utf8 COLLATE=utf8_bin;";
//avatar non può essere in dipendenza da una risorsa perché crea un ciclio di dipendenze…
//una soluzione è creare una tabella Avatar… da discutere.
//ALTER TABLE `" . TABLE_USER . "` ADD CONSTRAINT
//  KEY `" . USER_RESOURCE_FKEY . "` (`" . USER_AVATAR . "`),
//  FOREIGN KEY (`" . USER_AVATAR . "`) REFERENCES `" . TABLE_RESOURCE . "` (`" . RESOURCE_ID . "`) ON DELETE NO ACTION";
Exemplo n.º 2
0
 static function getContactsNames()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineContactTypeColumns();
         $table = Query::getDBSchema()->getTable(TABLE_CONTACT_TYPE);
         $db->execute($s = Query::generateSelectStm(array($table), array(), array(), array()));
         $names = array();
         if ($db->num_rows() > 0) {
             while ($row = $db->fetch_result()) {
                 $names[$row[CONTACT_TYPE_NAME]] = $row[CONTACT_TYPE_TYPE];
             }
         } else {
             if ($db->errno()) {
                 $db->display_error("Contact::getContactsNames()");
             }
         }
         return $names;
     } else {
         $db->display_connect_error("Contact::getContactsNames()");
     }
 }