<?php

//+-----------------------------------------------------+//
//+ Copyright floopo.com
//+ Index.php
//+ Installion file
//+-----------------------------------------------------+//

include_once ('../config/config.php');
define('SETUP_TEMPLATE', BASEPATH.'/setup/tpl_setup.htm');


//____________Welcome Screen__________________________
$show = 1;
$title = 'Welcome';
$setup_start = 'SetupDone';


//____________FTP/CHMOD__________________________
if(isset($_POST['start']) || isset($_POST['ftpchmod']) || $_GET['refresh'] == 1){
$show = 2;
$title = 'CHMOD Directories';
$setup_step1 = 'SetupDone';

//__directories array__
$directories = array('dir1'=>'/config',
                     'dir2'=>'/lang',
                     'dir3'=>'/content/avatars',
                     'dir4'=>'/content/images',
                     'dir5'=>'/content/images/thumbs',
                     'dir6'=>'/plugins/customprofile/member_css',
                     'dir7'=>'/plugins/customprofile/member_images',
                     'dir8'=>'/themes/default/images',
                     'dir9'=>'/themes/default/css',
                     'dir10'=>'/lang/my_language.php',
                     'dir11'=>'/content/temp'
					 );


//__check each one__
$error_count = 0;
foreach($directories as $key => $value){

if (is_writable(BASEPATH.$value)) {
$$key = 'ChmodPass';//css
}else{
$$key = 'ChmodFail';//css
$error_count += 1;//error count
}

if($error_count == 0){ //its all ok al done
$show_chmod = 1;
$show = 3;
}else{ //continue with rest of checks

$show = (($_GET['refresh'] ==1)? 3 : 2); //are we skipping FTP

if($show == 2){
$setup_step2 = '';
include_once(BASEPATH.'/setup/helper.index.php');
}
}
}
}


//____________MYSQL DUMP__________________________
if(isset($_POST['sqldump']) || isset($_POST['chmodpassed'])){
$title = 'Website Details';
$show = 4;
$setup_start = 'SetupDone';
$setup_step1 = 'SetupDone';
$setup_step2 = 'SetupDone';


//form submitted
if(isset($_POST['sqldump'])){

    //turn each post into var
    foreach($_POST as $key => $value) {
        $$key = $value;
    }
    
//__process form__
$process = new FormProcessor();

//check all fields
($process->RequiredFields('all'))? $proceed = true  : $notification = 'Fill in all required fields';


//check password match
if($proceed){
$proceed = false;
($process->CheckFieldMatch('setup_password,setup_password2'))? $proceed = true : $notification = 'Passwords do not match';
}

//Validate url
if($proceed){
$proceed = false;
(ValidateURL($_POST['setup_url']) && $_POST['setup_url'] != 'http://www.yourdomain.com')? $proceed = true : $notification = 'Invalid domain name';
}



//check mysql connection
if($proceed){
$proceed = false;
    
$new_connection = @mysql_connect($_POST['setup_mysqlhost'],$_POST['setup_mysqluser'],$_POST['setup_mysqlpass']);
@mysql_select_db($_POST['setup_mysqldb'],$new_connection);
(@mysql_error())? $notification = 'Unable to connect to Database' : $proceed = true;
}


//load mysql helper
if($proceed){
include_once(BASEPATH.'/setup/helper.index.php');
}

}
}









//____DISPLAY ANY OUTPUT_________________________
$TBS = new clsTinyButStrong;
$TBS->NoErr = true;
$TBS->LoadTemplate(SETUP_TEMPLATE);
$TBS->MergeField('formdata',$_POST);
$TBS->Render = TBS_OUTPUT;
$TBS->Show();
@mysql_close();

?>