<?PHP
/* this is a very basic install script.
    It will test fo the correct permisisons on folders and create if not there.
    It will create the config, articles and run generator as required.
*/
?>
<?PHP

function page_header(){
    print '<HTML>
<HEAD>
    <TITLE>RSSGM installer</TITLE>
</HEAD>
<BODY>';
}

//lets load the stuff that's in the config.php already.
if (file_exists('config.php')){
    include('config.php');
    }else{
    //check if access rights are such that config.php can be created.
    }
if ($_REQUEST['a_d']!="yes" && $_POST['create_config']==""){
    page_header();
    //phpinfo();
    Print '<P>WARNING: this install is a "one shot" only.<br />Once the script is install is completed,it will chmod the config.php so that it is no longer writable by the webserver - if you want to redo the install you will need to chmod the config.php</P>';
    Print '<P>Please answer the following questions<br /><span style="font-size:small">Guesses are already in the boxes please check if they are correct</span></P>';
    ?>
    <form method="POST" action="<?PHP print $_SERVER['PHP_SELF']?>">
    <table>
        <TR><TD>Site Name</TD><TD><input type="text" name="mysitename" value="<?PHP print $mysitename?>"></TD></TR>
        <TR><TD>Primary Keyword</TD><TD><input type="text" name="mainkeyword" value="<?PHP print $mainkeyword?>"></TD></TR>
        <TR><TD>Adsense publisher ID</TD><TD><input type="text" name="adsense_pub" value="<?PHP print $adsense_pub?>"></TD></TR>
        <TR><TD>Chitika ID</TD><TD><input type="text" name="chitika_pub" value="<?PHP print $chitika_pub?>"></TD></TR>
        <TR><TD>Chitika channel</TD><TD><input type="text" name="chitika_channel" value="<?PHP print $chitika_channel?>"></TD></TR>
        <TR><TD>PeakClick ID</TD><TD><input type="text" name="_aff" value="<?PHP print $_aff?>"></TD></TR>
        <TR><TD>PeakClick subaffiliate</TD><TD><input type="text" name="_subaff" value="<?PHP print $_subaff?>"></TD></TR>
        <TR><TD>PeakCLick Number of results</TD><TD><input type="text" name="_numResults" value="<?PHP print $_numResults?>"></TD></TR>
        <TR><TD>PeakCLick Enable thumbs</TD><TD><input type="text" name="_thumbs" value="<?PHP print $_thumbs?>"></TD></TR>
        <TR><TD>Site URL</TD><TD><?PHP print $site?></TD></TR>
        <TR><TD colspan="2" align="center"><input type="submit" name="create_config" value="create config"></TD></TR>
    </table>
    </form>
<?PHP
}else{
    //okay lets crate the config file
  if ($_POST['create_config']!=""){
    $mysitename = $_POST['mysitename'];
    $mainkeyword = $_POST['mainkeyword'];
    $adsense_pub = $_POST['adsense_pub'];
    $chitika_pub = $_POST['chitika_pub'];
    $chitika_channel = $_POST['chitika_channel'];
    $_aff = $_POST['_aff'];
    $_subaff = $_POST['_subaff'];
    $_numResults = $_POST['_numResults'];
    $_thumbs = $_POST['_thumbs'];
  }
    $config='<?PHP
//config file generated by install.php
$mysitename = "'.$mysitename.'";
$mainkeyword = "'.$mainkeyword.'";
$adsense_pub = "'.$adsense_pub.'";
$chitika_pub = "'.$chitika_pub.'";
$chitika_channel = "'.$chitika_channel.'";
$_aff = "'.$_aff.'";
$_subaff = "'.$_subaf.'";
$_numResults = "'.$_numResults.'";
$_thumbs = "'.$_thumbs.'";

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

//------------------------------------//
//DON\'T EDIT UNLESS A RSSGM DEVELOPER//
//------------------------------------//


$site = "http://"; 

$site .= $_SERVER["HTTP_HOST"]; 

$sitexml = $site."/";

$full = $_SERVER["REQUEST_URI"]; 

$dir = dirname($full);

$dir = str_replace("/rssgm", "", $dir);

$site .= $dir;

//--

$nr_links = 25;

$template_index = "theindex.php";

$template_pages = "pages.php";
$template_number = "3";

$template_sitemap = "thesitemap.php";

//----------------------------------//
?>
';
//print $config;
    $fh=fopen('config.php','w+');
    fwrite ($fh,$config);
    fclose($fh);

//now what we do depends on whether it's an auto install or not
    if ($_REQUEST['a_d']=="yes"){
        //check whether articles need generating
        if ($_REQUEST['articles']=="y"){
            //call the article generation scripts with a php redirect
            header("HTTP/1.1 301 Moved Permanently");
            //need to set the various variables in the following url for automation
            header("Location: wiki.php?a_d=yes");
        }else{
            //articles don't need generating so
            //call the generator.php script with a php redirect
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: generator.php");
        }
    }else{
        page_header();
        print '<P>config.php written</P>';
    }
}
?>
</BODY>
</HTML>