<?php 
	include ('../config.php');

if(isset($_POST['create'])) { 
				
		$sitename = $_POST['sitename'];
		$siteurl = $_POST['siteurl'];
		$name = mysql_real_escape_string($_POST['name']);
		$email = mysql_real_escape_string($_POST['email']);
		$pass1 = $_POST['pass1'];
		$pass2 = $_POST['pass2'];
		$avatar = "http://www.gravatar.com/avatar/".md5( strtolower( trim( $email ) ) )."?d=".$siteurl."/images/avatar.png&s=90";
		
		function genRandomString() {
    $length = 10;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
	}		
	$universalid = genRandomString(); 
	
		
	if (!$sitename || !$siteurl || !$name || !$email) {
		header('Location: index.php?error=missing');
		exit();
	}


	if ($pass1 != $pass2) {
		header('Location: index.php?error=nomatch');
		exit();
	}



// CREATE TABLES
		
		// adboxes
		$sql = "CREATE TABLE IF NOT EXISTS `adboxes` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `adcode` text COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`) );";
		$query = mysql_query($sql);	
		
		// admins
		$sql = "CREATE TABLE IF NOT EXISTS `admins` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `email` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
  `username` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
  `avatar` varchar(256) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`) );";
		$query = mysql_query($sql);	

		//  articles
		$sql = "CREATE TABLE IF NOT EXISTS `articles` (
  `id` int(16) NOT NULL AUTO_INCREMENT,
  `status` int(1) NOT NULL,
  `authorid` int(16) NOT NULL,
  `date` datetime NOT NULL,
  `title` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
  `categoryid` int(8) NOT NULL,
  `parentid` int(8) DEFAULT NULL,
  `body` text COLLATE utf8_unicode_ci NOT NULL,
  `resource` text COLLATE utf8_unicode_ci NOT NULL,
  `problem` text COLLATE utf8_unicode_ci,
  PRIMARY KEY (`id`));";
		$query = mysql_query($sql);	

		//  articleviews
		$sql = "CREATE TABLE IF NOT EXISTS `articleviews` (
  `articleid` int(11) NOT NULL,
  `views` int(11) NOT NULL,
  PRIMARY KEY (`articleid`) ) ;";
		$query = mysql_query($sql);	

		//  authors
		$sql = "CREATE TABLE IF NOT EXISTS `authors` (
  `id` int(16) NOT NULL AUTO_INCREMENT,
  `status` int(1) NOT NULL DEFAULT '0',
  `email` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
  `username` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  `fname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `displayname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `bio` text COLLATE utf8_unicode_ci,
  `url` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
  `gravatar` varchar(256) COLLATE utf8_unicode_ci DEFAULT NULL,
  `mailopt` int(1) NOT NULL,
  PRIMARY KEY (`id`) ); ";
		$query = mysql_query($sql);	

		//  categories
		$sql = "CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `parentid` int(8) DEFAULT NULL,
  `name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`));";
		$query = mysql_query($sql);	

		//  pages
		$sql = "CREATE TABLE IF NOT EXISTS `pages` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `title` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
  `body` text COLLATE utf8_unicode_ci NOT NULL,
  `onmenu` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)) ;";
		$query = mysql_query($sql);	

		//  settings
		$sql = "CREATE TABLE IF NOT EXISTS `settings` (
  `title` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
  `url` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
  `minwords` int(8) NOT NULL,
  `maxwords` int(8) NOT NULL,
  `logourl` varchar(256) COLLATE utf8_unicode_ci DEFAULT NULL,
  `emailopt` int(1) NOT NULL,
  `skipqueue` int(1) NOT NULL,
  `distribution` int(1) NOT NULL,
  `universalid` varchar(16) DEFAULT NULL,
  `statcode` text COLLATE utf8_unicode_ci) ;";
		$query = mysql_query($sql);	


// INSERT DATA INTO TABLES

		// admin
		$sql = "INSERT INTO `admins` VALUES (NULL, '".$email."', 'admin', '".md5($pass1)."', '".$name."', '".$avatar."');";
		$query = mysql_query($sql);	

		// author (admin account)
		$sql = "INSERT INTO `authors` VALUES (NULL, 0, '".$email."', 'admin', '".md5($pass1)."', '".$name."', '".$name."', 'N/A', '".$siteurl."', '".$avatar."', 0);";
		$query = mysql_query($sql);	
				
		// site settings
		$sql = "INSERT INTO `settings` VALUES ('".$sitename."', '".$siteurl."', 1, 1500, NULL, 0, 0, 0, '".$universalid."', NULL);";
		$query = mysql_query($sql);	
		
		
		// setup blank ad slots
		$sql = "INSERT INTO `adboxes` (`id`, `adcode`) VALUES  (1, '<img src=\"".$siteurl."/images/250.gif\" />'), (2, '<img src=\"".$siteurl."/images/468.gif\" />'), (3, '<img src=\"".$siteurl."/images/125.gif\" />');";
		$query = mysql_query($sql);	


		// Insert Categories
		$sql = "INSERT INTO `categories` (`id`, `parentid`, `name`) VALUES
(1, NULL, 'Internet Business'),
(2, NULL, 'Arts & Entertainment'),
(3, NULL, 'Business'),
(4, NULL, 'Communications'),
(5, NULL, 'Computers'),
(6, NULL, 'Environment'),
(7, NULL, 'Fashion'),
(8, NULL, 'Finance'),
(9, NULL, 'Food & Beverage'),
(10, NULL, 'Health & Fitness'),
(11, NULL, 'Home & Family'),
(12, NULL, 'Politics'),
(13, NULL, 'Product Reviews'),
(14, NULL, 'Sports & Recreation'),
(15, NULL, 'Reference & Education'),
(16, NULL, 'Self Improvement'),
(17, NULL, 'Society'),
(18, NULL, 'Travel & Leisure'),
(19, NULL, 'Transportation'),
(20, NULL, 'Writing & Speaking'),
(21, 1, 'Ecommerce'),
(22, 1, 'Affiliate Programs'),
(23, 1, 'Auctions'),
(24, 1, 'Blogging'),
(25, 1, 'Domains'),
(26, 1, 'Ebooks'),
(27, 1, 'Email Marketing'),
(28, 1, 'Forums'),
(29, 1, 'Internet Marketing'),
(30, 1, 'Podcasts'),
(31, 1, 'PPC Advertising'),
(32, 1, 'RSS'),
(33, 1, 'Security'),
(34, 1, 'SEO'),
(35, 1, 'Site Promotion'),
(36, 1, 'Spam'),
(37, 1, 'Traffic Generation'),
(38, 1, 'Web Design'),
(39, 1, 'Web Hosting'),
(40, 2, 'Photography'),
(41, 2, 'Celebrities'),
(42, 2, 'Humanities'),
(43, 2, 'Humor'),
(44, 2, 'Music'),
(45, 2, 'Poetry'),
(46, 3, 'Advertising'),
(47, 3, 'Article Marketing'),
(48, 3, 'Careers'),
(49, 3, 'Customer Service'),
(50, 3, 'Entrepreneurs'),
(51, 3, 'Ethics'),
(52, 3, 'Home Based Business'),
(53, 3, 'Management'),
(54, 3, 'Marketing'),
(55, 3, 'Networking'),
(56, 3, 'Public Relations'),
(57, 3, 'Sales'),
(58, 3, 'Small Business'),
(59, 4, 'Broadband Internet'),
(60, 4, 'GPS'),
(61, 4, 'Mobile Phones'),
(62, 4, 'Satellite Radio'),
(63, 4, 'Satellite TV'),
(64, 4, 'Video Conferencing'),
(65, 4, 'VOIP'),
(66, 5, 'Computer Certification'),
(67, 5, 'Data Recovery'),
(68, 5, 'Games'),
(69, 5, 'Hardware'),
(70, 5, 'Networks'),
(71, 5, 'Software'),
(72, 5, 'Mobile'),
(73, 6, 'Agriculture'),
(74, 6, 'Green Living'),
(75, 7, 'Clothing'),
(76, 7, 'Jewelry'),
(77, 7, 'Runway'),
(78, 7, 'Shoes'),
(79, 8, 'Credit'),
(80, 8, 'Currency Trading'),
(81, 8, 'Debt Consolidation'),
(82, 8, 'Fundraising'),
(83, 8, 'Insurance'),
(84, 8, 'Investing'),
(85, 8, 'Investments'),
(86, 8, 'Leasing'),
(87, 8, 'Loans'),
(88, 8, 'Mortgage'),
(90, 8, 'Mutual Funds'),
(91, 8, 'Personal Finance'),
(92, 8, 'Real Estate'),
(93, 8, 'Stock Market'),
(94, 8, 'Taxes'),
(95, 8, 'Wealth Building'),
(96, 9, 'Coffee'),
(97, 9, 'Cooking'),
(98, 9, 'Gourmet'),
(99, 9, 'Recipes'),
(100, 9, 'Waiting Tables'),
(101, 9, 'Wine'),
(102, 10, 'Acne'),
(103, 10, 'Alternative Medicine'),
(104, 10, 'Beauty'),
(105, 10, 'Cardio'),
(106, 10, 'Depression'),
(107, 10, 'Diabetes'),
(108, 10, 'Exercise'),
(109, 10, 'Fitness Equipment'),
(110, 10, 'Hair Loss'),
(111, 10, 'Medicine'),
(112, 10, 'Meditation'),
(113, 10, 'Mens Issues'),
(114, 10, 'Muscle Building'),
(115, 10, 'Nutrition'),
(116, 10, 'Pollution'),
(117, 10, 'Supplements'),
(118, 10, 'Weight Loss'),
(119, 10, 'Womens Issues'),
(120, 10, 'Yoga'),
(121, 10, 'Disease'),
(122, 10, 'Cancer'),
(123, 11, 'Home Security'),
(124, 11, 'Babies'),
(125, 11, 'Crafts'),
(126, 11, 'Elderly Care'),
(127, 11, 'Gardening'),
(128, 11, 'Hobbies'),
(129, 11, 'Holidays'),
(130, 11, 'Home Improvement'),
(131, 11, 'Interior Design'),
(132, 11, 'Kids'),
(133, 11, 'Landscaping'),
(134, 11, 'Parental Care'),
(135, 11, 'Parenting'),
(136, 11, 'Pets'),
(137, 11, 'Pregnancy'),
(138, 12, 'Commentary'),
(139, 12, 'Current Events'),
(140, 12, 'History'),
(141, 13, 'Consumer Electronics'),
(142, 13, 'Digital Products'),
(143, 13, 'Movie Reviews'),
(144, 13, 'Music Reviews'),
(145, 14, 'Biking'),
(146, 14, 'Extreme'),
(147, 14, 'Fishing'),
(148, 14, 'Football'),
(149, 14, 'Gambling & Casinos'),
(150, 14, 'Golf'),
(151, 14, 'Hunting'),
(152, 14, 'Martial Arts'),
(153, 14, 'Running'),
(154, 14, 'Surfing'),
(155, 14, 'Tennis'),
(156, 15, 'Adult'),
(157, 15, 'College'),
(158, 15, 'Environmental'),
(159, 15, 'Homeschooling'),
(160, 15, 'K-12 Education'),
(161, 15, 'Language'),
(162, 15, 'Legal'),
(163, 15, 'Philosophy'),
(164, 15, 'Psychology'),
(165, 15, 'Science'),
(166, 15, 'Sociology'),
(167, 15, 'Weather'),
(168, 16, 'Attraction'),
(169, 16, 'Coaching'),
(170, 16, 'Creativity'),
(171, 16, 'Goal Setting'),
(172, 16, 'Grief'),
(173, 16, 'Happiness'),
(174, 16, 'Innovation'),
(175, 16, 'Inspirational'),
(176, 16, 'Leadership'),
(177, 16, 'Motivation'),
(178, 16, 'Organizing'),
(179, 16, 'Spirituality'),
(180, 16, 'Stress Management'),
(181, 16, 'Success'),
(182, 16, 'Time Management'),
(183, 17, 'Dating'),
(184, 17, 'Divorce'),
(185, 17, 'Marriage'),
(186, 17, 'Relationships'),
(187, 17, 'Religion'),
(188, 17, 'Sexuality'),
(189, 17, 'Weddings'),
(190, 18, 'Aviation'),
(191, 18, 'Boating'),
(192, 18, 'Cruises'),
(193, 18, 'Destinations'),
(194, 18, 'Outdoors'),
(195, 18, 'Travel Tips'),
(196, 18, 'Vacations'),
(197, 19, 'Boats'),
(198, 19, 'Cars'),
(199, 19, 'Motorcycles'),
(200, 19, 'RVs'),
(201, 19, 'Trucks-SUVS'),
(202, 20, 'Article Writing'),
(203, 20, 'Book Reviews');";
		$query = mysql_query($sql);	


// Post to Synergy

	$post_data['siteurl'] = $siteurl;
	$post_data['sitename'] = $sitename;
	$post_data['universalid'] = $universalid;
	
	//traverse array and prepare data for posting (key1=value1)
	foreach ( $post_data as $key => $value) {
		$post_items[] = $key . '=' . $value;
	}
	
	//create the final string to be posted using implode()
	$post_details = implode ('&', $post_items);
	
	//create cURL connection
	$curl_connection = curl_init('http://www.articlesynergy.com/listener.php');
	
	//set options
	curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
	curl_setopt($curl_connection, CURLOPT_USERAGENT, 
	  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
	curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
	
	//set data to be posted
	curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_details);
	
	//perform our request
	$result = curl_exec($curl_connection);
	
	//close the connection
	curl_close($curl_connection);
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 

	<title>ArticleSetup Installation</title> 

	<style type="text/css">
		body { background: #ddd; font-family:Verdana, sans-serif;font-size:12px;line-height:16px;color:#222; }
		#container     { left: 50%; margin-left: -275px; position: relative; width: 550px; padding: 10px; background: white;}
		a:link, a:visited { color: #396EB7; text-decoration: none; }
		a:hover { text-decoration: underline; }
		p {line-height: 1.4em; font-size: 1em; padding: 5px 0 8px 5px; margin: 0; color: #666;}
		h1 { color: #333;font-size: 18px; color: #666; font-weight:lighter; margin:0 0 10px; padding: 10px 0; border-bottom: 1px solid #ECE8DA;}
		#footer	       { width:540px; border-top: 2px solid #F3F1E9; margin: 10px 0; height: 25px; padding: 5px;}
		
		#submitstyle { background-color:#f5f5f5;  border:1px solid #dedede;  border-top:1px solid #eee;    border-left:1px solid #eee;     font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;    font-size:12px;    line-height:130%;    text-decoration:none;    font-weight:bold;    color:#336699;     cursor:pointer;     padding:5px 10px 6px 7px; /* Links */ }
 
 		#submitstyle:hover {     background-color:#dff4ff;   border:1px solid #c2e1ef;   color:#336699; }
		label { color: #666; float:left; width: 125px; padding: 5px 0;}
		input { color: #666; background: #fff; padding: 5px; border: 1px solid #ccc; }

	</style>
 		
		
</head> 
 
<body> 
 
<div id="container"> 
 
<!-- CONTENT AREA --> 
<div id="content">	


<h1>ArticleSetup Installation (Step 2 of 2)</h1>

<p><b>Success!</b> <?php echo $sitename; ?> has been successfully installed. There are a few final steps you need to take: </p> 

<p><b>Delete the install directory</b> - For security reasons, it's very important that you delete this /install folder in your server before you begin using your new directory. </p> 
		
<p><b>Login to the admin dashboard</b> - ArticleSetup includes a fully-featured admin control panel that allows you to manage and monitor every aspect of your directory. The admin panel can be found at: <a href="<?php echo $siteurl; ?>/admin"><?php echo $siteurl; ?>/admin</a> and you will login with the username: <b>admin</b> and the password you chose on the previous page.</p> 

<p><b>Polish your site's settings</b> - Once you've become comfortable with your admin panel, navigate to the site settings panel. From here, you can upload a logo, manage email settings, add stat tracking code and more. </p> 

<p>Finally, if you need any support, feel free to visit our support forums at: <a href="http://articlesetup.com/forums">http://articlesetup.com/forums</a> for fast support. Thanks again for installing ArticleSetup, and good luck with your new directory! </p> 



<?php } else { ?>
 
 
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 

	<title>ArticleSetup Installation</title> 

	<style type="text/css">
		body { background: #ddd; font-family:Verdana, sans-serif;font-size:12px;line-height:16px;color:#222; }
		#container     { left: 50%; margin-left: -275px; position: relative; width: 550px; padding: 10px; background: white;}
		a:link, a:visited { color: #396EB7; text-decoration: none; }
		a:hover { text-decoration: underline; }
		p {line-height: 1.4em; font-size: 1em; padding: 5px 0 8px 5px; margin: 0; color: #666;}
		h1 { color: #333;font-size: 18px; color: #666; font-weight:lighter; margin:0 0 10px; padding: 10px 0; border-bottom: 1px solid #ECE8DA;}
		#footer	       { width:540px; border-top: 2px solid #F3F1E9; margin: 10px 0; height: 25px; padding: 5px;}
		
		#submitstyle { background-color:#f5f5f5;  border:1px solid #dedede;  border-top:1px solid #eee;    border-left:1px solid #eee;     font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;    font-size:12px;    line-height:130%;    text-decoration:none;    font-weight:bold;    color:#336699;     cursor:pointer;     padding:5px 10px 6px 7px; /* Links */ }
 
 		#submitstyle:hover {     background-color:#dff4ff;   border:1px solid #c2e1ef;   color:#336699; }
		label { color: #666; float:left; width: 125px; padding: 5px 0;}
		input { color: #666; background: #fff; padding: 5px; border: 1px solid #ccc; }

	</style>
 		
		
</head> 
 
<body> 
 
<div id="container"> 
 
<!-- CONTENT AREA --> 
<div id="content">	

	<h1>ArticleSetup Installation (Step 1 of 2)</h1> 
	
				<?php 
	if($_GET["error"] == "nomatch") 
		echo '<p  style=" padding-left: 15px; color: red;">Passwords didn\'t Match</p>';
	if($_GET["error"] == "missing") 
		echo '<p  style="color: red; padding-left: 15px; color: red;">Please complete all fields</p>';
?>


<p><b>Welcome to Article Setup!</b> The installation process was designed to be simple, fast, and totally painless. Your brand new article directory should be up and running in less than 5 minutes. Let's get started!</p> 

<p><b>NOTE</b> At this point, you should have already uploaded all files into your server, setup a fresh database, and entered your database information into the config.php file on your server. If you haven't already, please complete those steps before continuing.</p> 

	<br/>
	<form style="padding-left: 15px;" name="submission" method="POST" action="index.php">

	<label>Site Name:</label>
	<input type="text" name="sitename" style="width: 250px;" value="<?php echo $oldname; ?>">
	<br/>
	<label>Site URL:</label>
	<input type="text" name="siteurl" style="width: 250px;" value="<?php echo $oldemail; ?>">
	<p style="font-size: .9em; padding: 0 35px 0 125px;"><em>NOTE: Site URL <u>must</u> be in exactly the following format: <b>http://www.example.com</b> OR <b>http://example.com</b> (no trailing slashes)</em></p>
	<br/>
	<label>Admin Email:</label>
	<input type="text" name="email" style="width: 250px;" value="<?php echo $oldname; ?>">
	<br/>	
	<label>Admin Name:</label>
	<input type="text" name="name" style="width: 250px;" value="<?php echo $oldname; ?>">
	<br/>
	<label>Admin Username:</label>
	<p>admin</p>
	<label>Admin Password:</label>
	<input type="password" name="pass1" style="width: 250px;">
	<br/>
	<label>Password (again):</label>
	<input type="password" name="pass2" style="width: 250px;">
	<br/>
	
	<input name="create" type="hidden" id="create" />
	<div style="clear:both"></div>
	<br/><br/>
	<button type="submit" id="submitstyle">Continue to Step 2 &raquo;</button>

</form>

<?php } ?>

</body> 
</html> 
	
</div> 
 
 
 
<!-- FOOTER --> 
<div id="footer"> 
	<div style="float:right"><p>&copy; 2011 - ArticleSetup.com<br/></p></div> 
</div> 
 
 
</div>  <!-- close Container -->
 
</body> 
</html>