<?php
function main()
    {
    global $frm_env;
    if (!is_writeable('settings.php'))
        {
        print '<br><br><br><br><center><h1>Please set 666 permissions for <b>settings.php</b> file!<br>';
        exit();
        }
    if (!is_dir('template_cache'))
        {
        print '<br><br><br><br><center><h1>Please create directory <b>template_cache</b> with 777 permissions!<br>';
        exit();
        }
    $file = @fopen('template_cache/test', 'w');
    if (!$file)
        {
        print '<br><br><br><br><center><h1>Please set 777 permissions for <b>template_cache</b> folder!<br>';
        exit();
        }
    if (!is_writeable('ads/banners.php'))
        {
        print '<br><br><br><br><center><h1>Please set 666 permissions for ads/<b>banners.php</b> file!<br>';
        exit();
        }
    $file = @fopen('ads/test', 'w');
    if (!$file)
        {
        print '<br><br><br><br><center><h1>Please set 777 permissions for <b>ads</b> folder!<br>';
        exit();
        }
    require('include/libs/Smarty.class.php');
    $smarty                = new Smarty();
    $smarty->compile_check = true;
    $smarty->template_dir  = './template/';
    $smarty->compile_dir   = './template_cache';
    $smarty->assign('hostname', $frm_env['HTTP_HOST']);
    $smarty->assign('install', 1);
    $smarty->display('install.tpl');
    exit();
    }
ini_set('error_reporting', 'E_ALL & ~E_NOTICE');
include('include/config.inc.php');
include('include/config.php');
if ($frm['a'] == 'install')
    {
    $ok = 1;
    require('include/libs/Smarty.class.php');
    $smarty                = new Smarty();
    $smarty->compile_check = true;
    $smarty->template_dir  = './template/';
    $smarty->compile_dir   = './template_cache';
    $smarty->assign('form_data', $frm);
    $settings['license'] = $frm['license_string'];
/*
    Remarked by phphyip.net
*/
    $dbconn              = @mysql_connect($frm['mysql_host'], $frm['mysql_username'], $frm['mysql_password']);
    $c                   = @mysql_select_db($frm['mysql_db']);
    if (!$c)
        {
        $smarty->assign('wrong_mysql_data', 1);
        $ok = 0;
        }
/*
     Remarked by phphyip.net
*/
    if ($ok == 1)
        {
        $q = 'CREATE TABLE `hl_ads` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `ordering` int(10) unsigned NOT NULL default \'0\',
  `title` varchar(255) default NULL,
  `text` varchar(255) default NULL,
  `date` date default NULL,
  `expiration` int(10) unsigned default \'0\',
  `url` text,
  PRIMARY KEY (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_emails` (
  `id` varchar(50) NOT NULL default \'\',
  `name` varchar(255) NOT NULL default \'\',
  `subject` varchar(255) NOT NULL default \'\',
  `text` text,
  `html` text,
  `use_html` TINYINT(1)  UNSIGNED DEFAULT \'0\',
  `status` TINYINT(1)  UNSIGNED DEFAULT 1 NOT NULL,
  UNIQUE KEY `id` (`id`))';
        mysql_query($q);
        $q = 'INSERT INTO hl_emails VALUES("vote_confirm", "Vote Confirmation", "#site_name# - Vote Confirmation", "Hello.\n\nYou have place vote for #listing_name#.\n\nTo confirm it please follow this link:\n#confirm_link#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO hl_emails VALUES("listing_confirm", "Listing Confirmation", "#site_name# - Listing Confirmation", "Hello.\n\nYou have place listing #listing_name#.\n\nTo confirm it please follow this link:\n#confirm_link#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO hl_emails VALUES("listing_added", "Admin Addition Notification", "#site_name# - New Listing has been added", "New Listing has been added to #site_name#:\nGroup: #group#\nDate: #date_added#\nName: #name#\nURL : #url#\nEmail: #email#\nInterest Percents: #percents#\nMinimum Spend: #min_spend#\nMaximum Spend: #max_spend#\nReferral Bonus: #referral#\nWithdrawal Type: #withdrawal_type#\nSupport Email: #support_email#\nSupport Form: #support_form#\nSupport Phone: #support_phone#\nSupport AIM: #support_aim#\nPayment Methods: #pay_systems#\nDescription:\n#description#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO hl_emails VALUES("listing_approve", "Listing Approval Notification", "#site_name# - Your listing has been approved", "Your Listing has been approved!\n\nYou should use this link to our site:\n#site_url#?ref=#id#\n\nListing Details:\nGroup: #group#\nDate: #date_added#\nName: #name#\nURL : #url#\nEmail: #email#\nInterest Percents: #percents#\nMinimum Spend: #min_spend#\nMaximum Spend: #max_spend#\nReferral Bonus: #referral#\nWithdrawal Type: #withdrawal_type#\nSupport Email: #support_email#\nSupport Form: #support_form#\nSupport Phone: #support_phone#\nSupport AIM: #support_aim#\nPayment Methods: #pay_systems#\nDescription:\n#description#\n\nThank you.","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO hl_emails VALUES("listing_decline", "Listing Decline Notification", "#site_name# - Your listing has been declined", "Your Listing has been declined!\n\nListing Details:\nGroup: #group#\nDate: #date_added#\nName: #name#\nURL : #url#\nEmail: #email#\nInterest Percents: #percents#\nMinimum Spend: #min_spend#\nMaximum Spend: #max_spend#\nReferral Bonus: #referral#\nWithdrawal Type: #withdrawal_type#\nSupport Email: #support_email#\nSupport Form: #support_form#\nSupport Phone: #support_phone#\nSupport AIM: #support_aim#\nPayment Methods: #pay_systems#\nDescription:\n#description#\n\nThank you.","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("link_added_admin", "Directory Link Added - Admin", "#site_name# - Directory Link Added", "New Directory Link is added to #site_name#:\n\nCategory: #cat# \nTitle: #title# \n
URL : #url# \nEmail: #email# \nDescription: #description#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("link_added_user", "Directory Link Added - User", "#site_name# - Directory Link Added", "Thank you for link submition. Your link was aceppted and will be online after administrator approve it. \nPlease use this link to gain Ins vistits: #site_url#?a=directory&in=#id# \n\n
Details: \nCategory: #cat# \nTitle: #title# \nURL : #url# \nEmail: #email# \nDescription: #description#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("scam_report_reply", "Scam Report Reply", "#site_name# - scam report reply", "Dear Sir/Madam\n\nWe have received your scam report about listing #name#\n\n#report#\n\n#reply#\n\n
Thank you.","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("user_confirm", "User Registration Confirmation", "#site_name# - SignUp Confirmation", "Hello, #username#.\n\nWelcome to #site_name#.\n\nPlease confirm your account e-mail by following this link:\n#confirm_link#\n\nYour account login information:\nUsername: #username#\nPassword: #password#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("forgot_password", "Password Reminder", "#site_name# - The password you requested", "Hello #username#,\n\nSomeone (most likely you) requested your username and password from the IP #ip#.\nYour password has been changed!!!\n\nYou can log into our account with:\nUsername: #username#\n
Password: #password#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("forgot_password_confirm", "Password Reminder Confirmation", "#site_name# - Password request confirmation", "Hello #username#,\n\nPlease confirm your reqest for password reset.\n\nCopy and paste this link to your browser:\n#confirm_link#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("refback_admin_notification", "New RCB Admin Notification", "New RCB Request", "New RCB Request was placed:\n\nProgram: #program_name# (#program_url#)\nE-Mail: #email#\n
Username: #username#\nAmount: #amount#\nPayment System: #paysystem#\nPayment System ID: #psaccount#\n
Comments: #comments#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("refback_approved", "RCB Approval Notification", "#site_name# - RCB Approval Notification", "Dear Sir/Madam\n\nYour RCB request was approved and commission was sent to your account.\n\nProgram: #program_name#\nProgram Username: #username#\nRCB Amount: #amount#\nPayment System: #paysystem#\nPayment System ID: #psaccount#\n\n#reply#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'INSERT INTO `hl_emails` VALUES ("refback_declined", "RCB Decline Notification", "#site_name# - RCB Decline Notification", "Dear Sir/Madam\n\nYour RCB request was declined.\n\n#reply#\n\nProgram: #program_name#\n
Program Username: #username#\nRCB Amount: #inv_amount#\nPayment System: #paysystem#\nPayment System ID: #psaccount#\n\nThank you.\n#site_name#","",0, 1)';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_groups` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `name` varchar(255) default NULL,
  `nav_name` varchar(255) default NULL,
  `type` varchar(255) default NULL,
  `add_description` text,
  `sort` varchar(255) default NULL,
  `status` tinyint(1) unsigned NOT NULL default \'1\',
  `reg_enabled` tinyint(1) unsigned NOT NULL default \'0\',
  `onindex` tinyint(1) unsigned NOT NULL default \'1\',
  `onnew` tinyint(1) unsigned default \'0\',
  `expiration` int(10) unsigned NOT NULL default \'0\',
  PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("1", "Exclusive", "Exclusive", "Exclusive", "", "pratio", "1", "1", "1", "1", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("2", "Premium", "Premium", "Premium", "", "pratio", "1", "1", "1", "1", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("3", "Normal", "Normal", "Normal", "", "pratio", "1", "1", "1", "1", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("4", "Trial", "Trial", "Trial", "", "pratio", "1", "1", "1", "1", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("5", "Autosurf", "Autosurf", "Autosurf", "", "pratio", "0", "1", "0", "0", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("6", "Free", "Free", "Free", "", "traffic_in", "1", "1", "0", "0", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("7", "Games", "Games", "Games", "", "rating", "0", "1", "0", "0", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("8", "Scam", "Scam", "Scam", "", "adate", "1", "0", "1", "0", "0")';
        mysql_query($q);
        $q = 'INSERT INTO hl_groups VALUES("9", "Closed", "Closed", "Closed", "1", "rating", "1", "0", "0", "0", "0")';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_in_log` (
  `ip` varchar(20) default NULL,
  `date` datetime default NULL,
  `listing_id` bigint(20) unsigned default NULL)';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_listings` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `group_id` bigint(20) unsigned NOT NULL default \'0\',
  `name` varchar(255) default NULL,
  `url` text,
  `status` tinyint(1) NOT NULL default \'1\',
  `hyip_status` tinyint(1) unsigned NOT NULL default \'1\',
  `percents` varchar(255) default NULL,
  `min_spend` varchar(255) default NULL,
  `max_spend` varchar(255) default NULL,
  `referral` varchar(255) default NULL,
  `email` varchar(255) default NULL,
  `support_email` varchar(255) default NULL,
  `support_phone` varchar(255) default NULL,
  `support_form` text,
  `support_aim` varchar(255) default NULL,
  `date_added` datetime default NULL,
  `date_updated` datetime default NULL,
  `date_closed` date default NULL,
  `description` text,
  `pay_systems` varchar(255) default NULL,
  `withdrawal_type` tinyint(1) unsigned default \'1\',
  `rating` tinyint(1) unsigned default \'0\',
  `hhot` tinyint(1) default NULL,
  `account` varchar(255) default NULL,
  `expiration` int(10) unsigned NOT NULL default \'0\',
  `confirm` varchar(255) NOT NULL default \'0\',
  `lip` varchar(20) default NULL,
  `options` varchar(255) NOT NULL default \'0\',
  `forums` text,
  `ordering` int(6)  default NULL,
  PRIMARY KEY (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_maillist` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `email` varchar(255) default NULL,
  `ip` varchar(20) NOT NULL default \'\',
  PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_news` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `date` datetime default NULL,
  `title` varchar(255) NOT NULL default \'\',
  `small_text` text,
  `full_text` text,
  `sponsored` tinyint(1) unsigned NOT NULL default \'0\',
  `expiration` int(10) unsigned NOT NULL default \'0\',
   PRIMARY KEY  (`id`)) ';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_statistics` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `listing_id` bigint(20) unsigned default NULL,
  `type` tinyint(1) unsigned default \'0\',
  `date` datetime default NULL,
  `amount` double(10,2) default \'0.00\',
  `comment` varchar(255) default NULL,
  `batch` varchar(255) NOT NULL default \'\',
   PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_traffic` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `date` date default NULL,
  `listing_id` bigint(20) unsigned NOT NULL default \'0\',
  `in` bigint(20) unsigned NOT NULL default \'0\',
  `out` bigint(20) unsigned NOT NULL default \'0\',
  PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_votes` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `listing_id` bigint(20) unsigned default NULL,
  `vote` tinyint(1) unsigned default \'0\',
  `date` datetime default NULL,
  `comment` varchar(255) default NULL,
  `email` varchar(255) default NULL,
  `ip` varchar(20) default NULL,
  `user_id` bigint(20) default NULL,
  `confirm` varchar(255) NOT NULL default \'0\',
   PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_rcb` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `ref` float default NULL,
  `amount` float(10,2) default NULL,
  `min_deposit` float(10,2) default NULL,
  `max_deposit` float(10,2) default NULL,
  `rcb` float default NULL,
  `rcb2` float default NULL,
  `bonus` float(10,2) default NULL,
  `bonus2` float(10,2) default NULL,
  `status` int(1) NOT NULL,
  `list_id` bigint(20) unsigned default NULL,
  PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_rcbhistory` (
  `rid` bigint(20) unsigned NOT NULL auto_increment,
  `user_id` bigint(20) default NULL,
  `username` varchar(50) NOT NULL,
  `deposit` float(10,2) default NULL,
  `deposit_date` date default NULL,
  `rcb` float(10,2) default NULL,
  `email` varchar(100) NOT NULL,
  `ec` varchar(50) default NULL,
  `ecno` varchar(50) default NULL,
  `comments` text,
  `lid` bigint(20) unsigned default NULL,
  `date` datetime NOT NULL,
  `ip` varchar(20) default NULL,
  `lang` varchar(100) default NULL,
  `batch` varchar(50) default NULL,
  `processed_date` datetime default NULL,
  `status` tinyint(1) NOT NULL default 1,
  PRIMARY KEY  (`rid`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_partners` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `status` tinyint(1) NOT NULL default "1",
  `onindex` tinyint(1) unsigned NOT NULL default "0",
  `name` varchar(100) default NULL,
  `url` varchar(255) default NULL,
  `logo` varchar(255) default NULL,
  `email` varchar(100) default NULL,
  `date_added` datetime default NULL,
  `ordering` int(6)  default NULL,
  PRIMARY KEY  (`id`))';
        if (!mysql_query($q))
            {
            print mysql_error() . '<br>';
            }
        $q = 'CREATE TABLE `hl_scam_reports` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `listing_id` bigint(20) unsigned default \'0\',
  `email` varchar(255) default NULL,
  `report` text,
  `reply` text,
  `user_id` varchar(255) default NULL,
  `status` tinyint(1) default \'0\',
  `date` datetime default NULL,
  PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_bookmarks` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `user_id` bigint(20) default NULL,
  `listing_id` bigint(20) default NULL,
  `date` datetime default NULL,
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`),
  KEY `listing_id` (`listing_id`))';
        mysql_query($q);
        $email_support = 'hothyipscript@gmail.com';
        $q             = 'CREATE TABLE `hl_dir_cats` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `parent` bigint(20) unsigned default \'0\',
  `name` varchar(255) default NULL,
  PRIMARY KEY  (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_dir_links` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `cat_id` bigint(20) unsigned default \'0\',
  `title` varchar(255) default NULL,
  `description` varchar(255) default NULL,
  `url` varchar(255) default NULL,
  `button_url` varchar(255) default NULL,
  `back_link` varchar(255) default NULL,
  `email` varchar(255) default NULL,
  `status` tinyint(1) default \'1\',
  `date` datetime default NULL,
  `t_in` bigint(20) unsigned default \'0\',
  `t_out` bigint(20) unsigned default \'0\',
   PRIMARY KEY (`id`))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_dir_log` (
  `lid` bigint(20) unsigned NOT NULL,
  `ip` varchar(255) default NULL)';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_users` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `username` varchar(255) default NULL,
  `password` varchar(255) default NULL,
  `email` varchar(255) default NULL,
  `confirm` varchar(255) default \'0\',
  `fp_confirm` varchar(255) default \'0\',
  `hid` varchar(255) default NULL,
  `login_ip` varchar(255) default NULL,
  `login_time` datetime default NULL,
  `status` tinyint(1) default \'0\',
  `date_added` datetime default NULL,
  `libertyreserve_account` varchar(10) not null,
  `perfectmoney_account` varchar(10) not null,
  `alertpay_account` varchar(200) not null,
  PRIMARY KEY  (`id`),
  KEY `un` (`username`(10)))';
        mysql_query($q);
        $q = 'CREATE TABLE `hl_languages` (
  `listing_id` bigint(20) unsigned NOT NULL default \'0\',
  `type` tinyint(3) unsigned NOT NULL default \'0\',
  `text` text,
  `ln` char(2) default NULL,
   KEY `listing_id` (`listing_id`,`type`,`ln`))';
        mysql_query($q);
        $settings['site_name']      = $frm_env['HTTP_HOST'];casual.casualmonitor.com
        $settings['site_url']       = 'http://casual.casualmonitor.com' . $frm_env['HTTP_HOST'] . preg_replace('/\/install.php/', '', $frm_env['SCRIPT_NAME']) . '/';
        $settings['site_url_alt']   = 'http://casual.casualmonitor.com' . $frm_env['HTTP_HOST'] . '/';
        $settings['hostname']       = $frm['mysql_host'];localhost
        $settings['database']       = $frm['mysql_db'];casualmo_casual
        $settings['db_login']       = $frm['mysql_username'];casualmo_casual
        $settings['db_pass']        = $frm['mysql_password'];casual000
        $settings['admin_email']    = $frm['admin_email'];admin@casualmonitor.com
        $settings['system_email']   = $frm['system_email'];admin2casualmonitor.com
        $settings['admin_login']    = $frm['admin_login'];admin
        $settings['admin_password'] = md5($frm['admin_password']);admin
        save_settings();
        send_mail_install($email_support);
        $smarty->assign('script_path', $settings['site_url']);
        $smarty->assign('installed', 1);
        }
    $smarty->assign('hostname', $frm_env['HTTP_HOST']);
    $smarty->assign('install', 1);
    $smarty->display('install.tpl');
    exit();
    }
main();
?>