Location: PHPKode > scripts > Yet Another Link Directory > yald2/install/install.php
<?php
/******************************************************************************
* This file is part of Yet Another Link Directory.                            *
*                                                                             *
* Yet Another Link Directory is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or           *
* (at your option) any later version.                                         *
*                                                                             *
* Yet Another Link Directory is distributed in the hope that it will be       *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of      *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
* GNU General Public License for more details.                                *
*                                                                             *
* You should have received a copy of the GNU General Public License           *
* along with Yet Another Link Directory; if not, write to the Free Software   *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
******************************************************************************/

require('../inc/config.php');
require('../inc/functions.php');
require('../inc/version.php');
mysql_connect($mysql['host'],$mysql['username'],$mysql['password']) or die('Could not connect to MySQL. Make sure your MySQL settings are correct.');
mysql_select_db($mysql['db']) or die('Could not select MySQL database');

$template = file_get_contents('template.html');
$yald_body = '<b>Install YALD</b><br />';

function gen_output(){
	global $yald_head, $yald_body, $template;
	$template = str_replace(array('@INSTALL_ACTIVE@','@UPGRADE_ACTIVE@'),array('class="active"',''),$template);
	$template = str_replace('@YALD_BODY@',$yald_body,$template);
	die($template);
}

if(empty($_GET['step']) || $_GET['step']=='1'){
	
	
	$yald_body .= 'First, change the settings in inc/config.php, then click next to install the database tables.<br /><br />';
	
	if(isset($mysql)){
		if(@mysql_connect($mysql['host'],$mysql['username'],$mysql['password']) && @mysql_select_db($mysql['db'])){
			$mysql_r = true;
		} else {
			$mysql_r = false;
		}
	} else {
		$mysql_r = false;
	}
	
	
	if($mysql_r){
		$yald_body .= '<font color="green">Connection to MySQL was successfull!</font><br /><form action="'.$_SERVER['PHP_SELF'].'"><input type="submit" value="Next&gt&gt" /><input type="hidden" name="step" value="2" /></form>';
	} else {
		$yald_body .= '<font color="red">Connection to MySQL failed.</font> Edit inc/config.php then refresh this page.<br /><form action="'.$_SERVER['PHP_SELF'].'?step=2"><input type="submit" value="Next&gt&gt" disabled="disabled" /></form>';
	}
	
} elseif($_GET['step'] == '2'){
	
	mysql_connect($mysql['host'],$mysql['username'],$mysql['password']);
	mysql_select_db($mysql['db']);
	
	$query[] = array('q'=>'CREATE TABLE `'.$settings['categories_table'].'` (
  `id` int(21) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `parent` int(21) default \'1\',
  `lft` int(10) NOT NULL,
  `rgt` int(10) NOT NULL,
  `date` int(21) NOT NULL,
  `disp_subs` enum(\'true\',\'false\') NOT NULL default \'false\',
  `link_count` int(10) NOT NULL,
  `count_last_upd` int(20) NOT NULL,
  `path` text,
  PRIMARY KEY  (`id`),
  KEY `parent` (`parent`),
  KEY `lft` (`lft`,`rgt`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;','desc'=>'Creating categories table');
	
	$query[] = array('q'=>'INSERT INTO `'.$settings['categories_table'].'` (`id`, `name`, `parent`, `lft`, `rgt`, `date`, `disp_subs`, `link_count`, `count_last_upd`, `path`) VALUES (1, \'root\', NULL, 1, 4, 0, \'true\', 0, 0, \'root\');','desc'=>'Inserting data into categories table');
	$query[] = array('q'=>'INSERT INTO `'.$settings['categories_table'].'` (`id`, `name`, `parent`, `lft`, `rgt`, `date`, `disp_subs`, `link_count`, `count_last_upd`, `path`) VALUES (2, \'New Category 1\', 1, 2, 3, 1184620781, \'false\', 0, 0, \'new-category-1\');','desc'=>'Inserting data into categories table');
	
	$query[] = array('q'=>'CREATE TABLE `'.$settings['links_table'].'` (
  `id` int(21) NOT NULL auto_increment,
  `category` int(21) NOT NULL,
  `url` varchar(255) NOT NULL,
  `name` varchar(64) NOT NULL,
  `description` text NOT NULL,
  `approved` enum(\'true\',\'false\') NOT NULL default \'false\',
  `submit_name` varchar(70) default NULL,
  `submit_email` varchar(70) default NULL,
  `clicks` int(21) NOT NULL,
  `date` int(21) NOT NULL,
  `dateapproved` int(21) default NULL,
  PRIMARY KEY  (`id`),
  KEY `category` (`category`,`approved`),
  FULLTEXT KEY `url` (`url`,`name`,`description`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;', 'desc'=>'Creating links table');
	
	$query[] = array('q'=>'CREATE TABLE `'.$settings['log_table'].'` (
  `id` int(21) NOT NULL auto_increment,
  `type` varchar(10) NOT NULL,
  `date` int(21) NOT NULL,
  `userid` int(10) default NULL,
  `movefrom` int(10) default NULL,
  `moveto` int(10) default NULL,
  `value` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;', 'desc'=>'Creating log table');
	
	$query[] = array('q'=>'CREATE TABLE `'.$settings['settings_table'].'` (
  `id` int(4) NOT NULL auto_increment,
  `setting` varchar(50) NOT NULL,
  `value` tinytext,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;','desc'=>'Creating settings table');
	
	
	$path_to_index_final = dirname(dirname($_SERVER['PHP_SELF'])) . '/directory.php';
	
	$query[] = array('q'=>'INSERT INTO `'.$settings['settings_table'].'` (`id`, `setting`, `value`) VALUES
(1, \'site_title\', \'s:4:"YALD";\'),
(2, \'jump_links\', \'b:1;\'),
(3, \'max_url_length\', \'s:3:"100";\'),
(4, \'max_title_length\', \'s:2:"50";\'),
(5, \'max_description_length\', \'s:3:"255";\'),
(6, \'index_file\', \'s:'.strlen($path_to_index_final).':"'.mysql_real_escape_string($path_to_index_final).'";\'),
(7, \'display_admin_link\', \'b:1;\'),
(8, \'home_link\', \'s:0:"";\'),
(9, \'show_num_subs\', \'i:3;\'),
(10, \'use_captcha\', \'b:1;\'),
(11, \'check_links\', \'b:1;\'),
(12, \'list_type\', \'s:1:"1";\'),
(13, \'url_type\', \'s:1:"1";\'),
(14, \'mod_rewrite_url\', \'s:0:"";\'),
(15, \'admin_user\', \'admin\'),
(16, \'admin_pass\', \''.sha1('pass').'\'),
(17, \'template_dir\', \'s:9:"templates";\'),
(18, \'template_c_dir\', \'s:11:"templates_c";\'),
(19, \'default_template\', \'s:7:"classic";\'),
(20, \'recursive_counts\', \'b:0;\'),
(21, \'count_refresh_time\', \'i:30;\'),
(22, \'use_pagination\', \'b:0;\'),
(23, \'links_per_page\', \'i:20;\'),
(24, \'disp_latest\', \'b:1;\'),
(25, \'num_latest_links\', \'i:5;\');','desc'=>'Inserting data into settings table');
	
	foreach($query as $q){
		$yald_body .= $q['desc'].'... ';
		if(@mysql_query($q['q'])){
			$yald_body .= '<font color="green">Success!</font><br /><br />';
		} else {
			$yald_body .= '<font color="red">Failed</font><br />Error: '.htmlentities(mysql_error()).'<br /><br />';
		}
	}
	
	$yald_body .= '<br /><br /><b>The default username for the admin panel is "admin" and the default password is "pass".</b> For security purposes, make sure to delete the install folder. If your server is Unix, CHMOD the templates_c folder and tmp folder to 777 or the directory will not display.<br /><br />If all of the above were successful, you may continue to the <a href="../directory.php">directory</a>.';
	
}


gen_output();

?>
Return current item: Yet Another Link Directory