<?php
if (!defined('INSTALL_MODULES')) {
	die ("You can't access this file directly...");
}

if ((!is_god($admin)) && (!is_user($user)) && (!is_admin($admin))) {
redirect_url("".$admin_file.".php?op=modules"); }

$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_albums` (
  `aid` int(11) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `visibility` int(11) NOT NULL default '0',
  `uploads` enum('YES','NO') NOT NULL default 'NO',
  `comments` enum('YES','NO') NOT NULL default 'YES',
  `votes` enum('YES','NO') NOT NULL default 'YES',
  `pos` int(11) NOT NULL default '0',
  `category` int(11) NOT NULL default '0',
  `pic_count` int(11) NOT NULL default '0',
  `thumb` int(11) NOT NULL default '0',
  `last_addition` datetime NOT NULL default '0000-00-00 00:00:00',
  `stat_uptodate` enum('YES','NO') NOT NULL default 'NO',
  PRIMARY KEY  (`aid`),
  KEY `alb_category` (`category`)
) ");

################################################################################

$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_categories` (
  `cid` int(11) NOT NULL auto_increment,
  `owner_id` int(11) NOT NULL default '0',
  `namee` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `pos` int(11) NOT NULL default '0',
  `parent` int(11) NOT NULL default '0',
  `subcat_count` int(11) NOT NULL default '0',
  `alb_count` int(11) NOT NULL default '0',
  `pic_count` int(11) NOT NULL default '0',
  `stat_uptodate` enum('YES','NO') NOT NULL default 'NO',
  PRIMARY KEY  (`cid`),
  KEY `cat_parent` (`parent`),
  KEY `cat_pos` (`pos`),
  KEY `cat_owner_id` (`owner_id`)
)");

################################################################################
$db2->sql_query("INSERT INTO `".$prefix_install."_cpg_categories` (`cid`, `owner_id`, `namee`, `description`, `pos`, `parent`, `subcat_count`, `alb_count`, `pic_count`, `stat_uptodate`) VALUES
(1, 0, 'Galerie des utilisateurs', 'Cette galerie contient les images issues des galeries personnelles des utilisateurs.', 0, 0, 0, 0, 0, 'NO'),
(2, 0, 'Première catégorie', 'Description de la première catégorie', 1, 0, 0, 0, 0, 'NO')");

################################################################################
$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_comments` (
  `pid` mediumint(10) NOT NULL default '0',
  `msg_id` mediumint(10) NOT NULL auto_increment,
  `msg_author` varchar(25) NOT NULL default '',
  `msg_body` text NOT NULL,
  `msg_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `author_md5_id` varchar(32) NOT NULL default '',
  `author_id` int(11) NOT NULL default '0',
  PRIMARY KEY  (`msg_id`),
  KEY `com_pic_id` (`pid`)
)");

################################################################################

$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_config` (
  `name` varchar(40) NOT NULL default '',
  `value` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`name`)
)");

################################################################################
$db2->sql_query("INSERT INTO `".$prefix_install."_cpg_config` (`name`, `value`) VALUES
('albums_per_page', '12'),
('album_list_cols', '2'),
('display_pic_info', '1'),
('alb_list_thumb_size', '50'),
('allowed_file_extensions', 'GIF/PNG/JPG/JPEG/TIF/TIFF'),
('allowed_img_types', 'JPG/GIF/PNG/TIFF'),
('allow_private_albums', '1'),
('allow_user_registration', '0'),
('allow_duplicate_emails_addr', '0'),
('caption_in_thumbview', '1'),
('charset', 'language file'),
('cookie_name', 'cpg'),
('cookie_path', '/'),
('debug_mode', '0'),
('default_dir_mode', '0755'),
('default_file_mode', '0644'),
('default_sort_order', 'na'),
('ecards_more_pic_target', '".$nukeurl."'),
('enable_smilies', '1'),
('filter_bad_words', '1'),
('forbiden_fname_char', '$/:*?'),
('fullpath', 'modules/Coppermine/albums/'),
('gallery_admin_email', '".$adminmail."'),
('gallery_description', 'Votre album photo en ligne'),
('gallery_name', 'Coppermine Photo Gallery'),
('im_options', '-antialias'),
('impath', ''),
('jpeg_qual', '80'),
('keep_votes_time', '30'),
('lang', 'french'),
('main_page_layout', 'catlist/alblist/random,2/lastup,2'),
('main_table_width', '100%'),
('make_intermediate', '1'),
('max_com_lines', '10'),
('max_com_size', '512'),
('max_com_wlength', '38'),
('max_img_desc_length', '512'),
('max_tabs', '12'),
('max_upl_size', '1024'),
('max_upl_width_height', '2048'),
('min_votes_for_rating', '1'),
('normal_pfx', 'normal_'),
('picture_table_width', '600'),
('picture_width', '400'),
('randpos_interval', '5'),
('read_exif_data', '0'),
('reg_requires_valid_email', '1'),
('subcat_level', '2'),
('theme', 'mac_ox_x'),
('thumbcols', '4'),
('thumbrows', '3'),
('thumb_method', 'gd2'),
('thumb_pfx', 'thumb_'),
('thumb_width', '100'),
('userpics', 'modules/Coppermine/albums/userpics/'),
('user_field1_name', ''),
('user_field2_name', ''),
('user_field3_name', ''),
('user_field4_name', ''),
('display_comment_count', '1')");
################################################################################

$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_pictures` (
  `pid` int(11) NOT NULL auto_increment,
  `aid` int(11) NOT NULL default '0',
  `filepath` varchar(255) NOT NULL default '',
  `filename` varchar(255) NOT NULL default '',
  `filesize` int(11) NOT NULL default '0',
  `total_filesize` int(11) NOT NULL default '0',
  `pwidth` smallint(6) NOT NULL default '0',
  `pheight` smallint(6) NOT NULL default '0',
  `hits` int(10) NOT NULL default '0',
  `mtime` timestamp(14),
  `ctime` int(11) NOT NULL default '0',
  `owner_id` int(11) NOT NULL default '0',
  `owner_name` varchar(40) NOT NULL default '',
  `pic_rating` int(11) NOT NULL default '0',
  `votes` int(11) NOT NULL default '0',
  `title` varchar(255) NOT NULL default '',
  `caption` text NOT NULL,
  `keywords` varchar(255) NOT NULL default '',
  `approved` enum('YES','NO') NOT NULL default 'NO',
  `user1` varchar(255) NOT NULL default '',
  `user2` varchar(255) NOT NULL default '',
  `user3` varchar(255) NOT NULL default '',
  `user4` varchar(255) NOT NULL default '',
  `url_prefix` tinyint(4) NOT NULL default '0',
  `randpos` int(11) NOT NULL default '0',
  PRIMARY KEY  (`pid`),
  KEY `pic_hits` (`hits`),
  KEY `pic_rate` (`pic_rating`),
  KEY `aid_approved` (`aid`,`approved`),
  KEY `randpos` (`randpos`),
  KEY `pic_aid` (`aid`),
  FULLTEXT KEY `search` (`title`,`caption`,`keywords`,`filename`)
)");
################################################################################

$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_usergroups` (
  `group_id` int(11) NOT NULL auto_increment,
  `group_name` varchar(255) NOT NULL default '',
  `group_quota` int(11) NOT NULL default '0',
  `has_admin_access` tinyint(4) NOT NULL default '0',
  `can_rate_pictures` tinyint(4) NOT NULL default '0',
  `can_send_ecards` tinyint(4) NOT NULL default '0',
  `can_post_comments` tinyint(4) NOT NULL default '0',
  `can_upload_pictures` tinyint(4) NOT NULL default '0',
  `can_create_albums` tinyint(4) NOT NULL default '0',
  `pub_upl_need_approval` tinyint(4) NOT NULL default '1',
  `priv_upl_need_approval` tinyint(4) NOT NULL default '1',
  PRIMARY KEY  (`group_id`)
) ");
################################################################################

$db2->sql_query("INSERT INTO `".$prefix_install."_cpg_usergroups` (`group_id`, `group_name`, `group_quota`, `has_admin_access`, `can_rate_pictures`, `can_send_ecards`, `can_post_comments`, `can_upload_pictures`, `can_create_albums`, `pub_upl_need_approval`, `priv_upl_need_approval`) VALUES
(1, 'Administrateurs', 1024, 1, 1, 1, 1, 1, 1, 0, 0),
(2, 'Enregistrés', 1024, 0, 1, 1, 1, 1, 1, 1, 1),
(3, 'Anonyme', 0, 0, 1, 1, 1, 1, 1, 1, 1),
(4, 'Bannis', 0, 0, 0, 0, 0, 0, 0, 1, 1) ");

################################################################################
$db2->sql_query("CREATE TABLE `".$prefix_install."_cpg_votes` (
  `pic_id` mediumint(9) NOT NULL default '0',
  `user_md5_id` varchar(32) NOT NULL default '',
  `vote_time` int(11) NOT NULL default '0',
  PRIMARY KEY  (`pic_id`,`user_md5_id`)
) ");

################################################################################
$db2->sql_query("ALTER TABLE `".$prefix_install."_users` ADD `user_group_cp` INT( 11 ) DEFAULT '2' NOT NULL, ADD `user_active_cp` ENUM( 'YES', 'NO' ) DEFAULT 'YES' NOT NULL ");

$db2->sql_query("UPDATE `".$prefix_install."_users` SET `user_group_cp` = '1' WHERE `user_id` = '2' ");