Location: PHPKode > scripts > WebsiteMemberManager > members-section/setup.php
<?php

if (!isset($_POST['email']))
{
 include("setup.html");
 exit;
}
if (file_exists("php-lib/config.inc.php"))
{
 include("php-lib/config.inc.php");
 if (INSTALLED) exit("<h2>Already installed!<br><br>To re-install remove the file:  php-lib/config.inc.php.");
} 

define("DBDRIVER", trim($_POST['dbdriver']));
define("DBPORT", trim($_POST['dbport']));
define('DBHOST', trim($_POST['dbhost']));
define('DBUSER', trim($_POST['dbuser']));
define('DBPASS', trim($_POST['dbpass']));
define('DBNAME', trim($_POST['dbname']));
define('ADMIN','admin');      
define('DEBUG', 1);      

include("php-lib/constants.php");


include("websitemembermanager-classes.php");
include("db-class.php");

class setup{
    public $WMM_version="4.0";
    public $adminSQLInsert;
    public $configSQLInsert;
    public $configFile="php-lib/config.inc.php";
    public $configDATA;
        
    public function __construct()
    {
     foreach ($_POST AS $key => $value) $$key = trim($value);      
     $cpass = WMMcrypt($dbpass,$email); 
     $this->adminSQLInsert="INSERT INTO `wmm_admin` (`id`, `their_username`, `their_password`, `contact_email`, `auto_activate`) VALUES(1, '$email', '$cpass', '$email', 1);";
     $this->configSQLInsert="INSERT INTO `wmm_config` (`id` ,`p_version` ,`functions_version`) VALUES ('1', '".$this->WMM_version."', '".$this->WMM_version."');";
     $just_one_dollar_please = "$";
     $this->configDATA = "<?php\n";
     $this->configDATA.= $just_one_dollar_please."WMM_version = \"".$this->WMM_version."\";\n";
     $this->configDATA.= "define('DBHOST', '$dbhost');\n";
     $this->configDATA.= "define('DBDRIVER', '$dbdriver');\n";
     $this->configDATA.= "define('DBPORT', '$dbport');\n";
     $this->configDATA.= "define('DBUSER', '$dbuser');\n";
     $this->configDATA.= "define('DBPASS', '$dbpass');\n";
     $this->configDATA.= "define('DBNAME', '$dbname');\n";
     $this->configDATA.= "define('CO_NAME','$coname');\n";
     $this->configDATA.= "define('INSTALLED',true);\n";
     $this->configDATA.= "define('ADMIN','$admin_folder');\n";
     $this->configDATA.= "define('DEBUG', 0);";
     echo "<center><h2>Date: ".strftime("%d %b %Y",time()).", WMM setup details for website: ".$_SERVER['HTTP_HOST']."</h2></center>";
    }

    public function showSetup()
    {
     echo "<table border=\"0\" cellpadding=\"12\"><tr><td width=\"40%\">Below is the <b>SQL</b>
           which can be helpful for a manual install (if required),
           or to reset the admin username/password (also see the file:
           <a href=\"SETUP.SQL\" target=\"_bank\">SETUP.SQL</a>):<br><textarea rows=\"3\" cols=\"35\">"
           .$this->adminSQLInsert."\n".$this->configSQLInsert."</textarea></td>";           
     echo  "<td width=\"30%\">On the right is the data which is required in the file: /members-section/"
            .$this->configFile."<br><br>Which is useful for a manual install (if required).<br>
           <br><br>If the setup program runs successfully it will update the config file and
           insert the SQL for you. Both are provided here in case it fails!</td>";
     echo  "<td width=\"30%\">".highlight_string($this->configDATA,true)."</td></tr></table>";
    }
    
    public function primaryCheck()
    {
     echo "<i><b>Now carrying out primary checks...</b> ";
     if (rename("admin",trim($_POST['admin_folder'])))
     {
      echo "Admin folder is writable... ";
      rename(trim($_POST['admin_folder']),"admin");//change it back for now, incase fails other tests
     } 
     else
     {
        echo "<h2><font color=\"#FF0000\">
                ERROR - unable to modify folder ".MEMBERS_SECTION_FOLDER."/admin/<br>change file permissions (CHMOD)
                to 775 or use the INSTALLER it as will do it for you!</font><br>Download Installer here:
                <a href=\"http://www.websitemembermanager.com/\">www.websitemembermanager.com</a></h2>";
        exit;
     }   
     if (rename("members","members.test"))
     {
      echo "Members folder is writable... ";
      rename("members.test","members");
     } 
     else
     {
        echo "<h2><font color=\"#FF0000\">
                ERROR - unable to modify folder ".MEMBERS_SECTION_FOLDER."/members/<br>change file permissions (CHMOD)
                to 775 or use the INSTALLER it as will do it for you!</font><br>Download Installer here:
                <a href=\"http://www.websitemembermanager.com/\">www.websitemembermanager.com</a></h2>";
        exit;
     }   
     $dbc = dbc::instance();
     //echo "<hr>".var_dump($dbc);
     if (isset($dbc->dbconn)) echo "DB connection details are correct... ";
     else
     {
        echo "<h2><font color=\"#FF0000\">
                ERROR - unable to connect to your database.</h2>";
        exit;
     }   
     if (is_writable("php-lib/")) echo "/php-lib/ is writable.</i>";
     else
     {
        echo "<h2><font color=\"#FF0000\">
                ERROR - unable to write to folder: \"php-lib/\"<br>change file permissions (CHMOD)
                to 775 or use the INSTALLER it as will do it for you!</font><br>Download Installer here:
                <a href=\"http://www.websitemembermanager.com/\">www.websitemembermanager.com</a></h2>";
        exit;
     }   
    }
        
    public function showLogin()
    {
     foreach ($_POST AS $key => $value) $$key = trim($value);
     $admin_url = "http://".$_SERVER['HTTP_HOST']."/".MEMBERS_SECTION_FOLDER."/".$admin_folder."/";
     $readme_url = "http://".$_SERVER['HTTP_HOST']."/".MEMBERS_SECTION_FOLDER."/";
     echo "<center><h3>ADMIN login here:<br><a href=\"$admin_url\" target=\"_bank\">$admin_url</a><br>
           <br>Username: $email
           <br>Password: $dbpass</h3>
           <b>A copy of this has been emailed to you. <font color=\"#006600\">Before you get too excited and login...</font></b>
           <br>Don't forget the other important steps listed in the <a href=\"$readme_url\">readme section</a>
           <br><br><i>You should save or print this page now, for your own use later.</i></center>";
     $themessage= "ADMIN login here: $admin_url
                   Username: $email
                   Password: $dbpass
                   
                   Also, do not forget to complete other stages in the readme:
                   $readme_url ";
     wmm_mail($email,"WMM admin login details",$themessage);
    }         
   
    public function updateConfig()
    {
     echo "<h2>WMM config</h2><blockquote>Updating details... ";        
     $fp=fopen($this->configFile, "w");
     if ($fp)
     {
      set_file_buffer($fp, 0);
      $file_write = fputs($fp, $this->configDATA);
      fclose($fp);
      echo "<b>Successfully updated config file, ";
     }
     if (rename("admin",trim($_POST['admin_folder']))) echo "\"admin\" folder renamed to \"".$_POST['admin_folder']."\"  - ALL setup now complete.</b></blockquote>";
     //in case second install attempt remove auto generated .htaccess files
     if(file_exists("members/.htaccess")) unlink("members/.htaccess");
     if(file_exists(trim($_POST['admin_folder'])."/.htaccess")) unlink(trim($_POST['admin_folder'])."/.htaccess");
    }
    
    public function dbSetup()
    {
     echo "<h2>WMM DB setup</h2><blockquote>Creating db structure... ";
     $dbc = dbc::instance();
     $query = "SHOW TABLES LIKE 'wmm_admin'";
     $result = $dbc->prepare($query);  
     if ($dbc->executeGetRows($result))
     {
        echo "<h2><font color=\"#FF0000\">\"WMM_admin\" table already exists, so quitting.<br><br>
              You need to remove all existing WMM tables before
              attemping a re-install.</font></h2>";
        exit;
     }
        //insert SETUP.SQL
     $handle = fopen("SETUP.SQL", "rb");
     $SQL=(fread($handle, filesize("SETUP.SQL")) );
     fclose($handle);
     $SQL_array=preg_split("/#/",$SQL);//split sql into separate queries
     foreach ($SQL_array AS $value)
     {
         $result = $dbc->prepare($value." ");
         $result = $dbc->execute($result);
        // echo "$value<hr>";
     }
     echo "Inserting relevant data... ";
     $result = $dbc->prepare($this->adminSQLInsert);
     $result = $dbc->execute($result);
     $result = $dbc->prepare($this->configSQLInsert);
     $result = $dbc->execute($result);
     if ($result) echo "<b>DB setup successfully complete.</b></blockquote>";
    }
}    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WMM setup</title>
<style type="text/css">
<!--
BODY{font-size: 9pt; font-family: Geneva, Arial, Helvetica, sans-serif}
-->
</style>

<link type="text/css" href="JQUERY/development-bundle/themes/custom-admin/jquery.ui.all.css" rel="stylesheet" />
<link type="text/css" href="JQUERY/development-bundle/themes/custom-admin/jquery.ui.base.css" rel="stylesheet" />
<link type="text/css" href="JQUERY/development-bundle/themes/custom-admin/jquery.ui.theme.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="JQUERY/development-bundle/plugins/jquery.validate.css" />

<script type="text/javascript" src="JQUERY/development-bundle/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.ui.tabs.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.ui.accordion.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.ui.button.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.core.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.clip.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.drop.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.fold.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.highlight.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.scale.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.slide.js"></script>
<script type="text/javascript" src="JQUERY/development-bundle/ui/jquery.effects.transfer.js"></script>

<body leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<div style="width:98%;padding-left:1%;padding-right:1%;">
<div class="ui-tabs" align="center">
	<ul class="ui-tabs-nav ui-widget-header ui-corner-all" style="height:85px;">
	  <div class="ui-tabs ui-widget ui-widget-content ui-corner-all" style="width:170px;float:left;">
	  <a href="http://www.websitemembermanager.com/"><img
   src="images/wmm-logo-small.gif"
    alt="WMM - Your automated members area for your own website" width="165" height="75" border="0" /></a></div>
<br />
<div style="float:left; width:80%"><div align="center">
<form action="http://www.dwalker.co.uk/forum/search.php" method="post" id="search">
  <?php
        $setup = new setup();
   ?>     
</form>
</div>
</div>	
</ul>
</div>
</div>
<br />
<div style="padding-left:10%">
<div id="layer" style="width:90%; padding-left:3%;" class="ui-widget-content ui-corner-all">
<blockquote>
        <?php
        $setup->showSetup();        
        $setup->primaryCheck();
        $setup->dbSetup();
        $setup->updateConfig();
        $setup->showLogin();
        ?>
</blockquote>
</div>
  
</div></div>  
<br />
<div id="pageFooterOuter" style="width:100%;position:fixed;bottom:0;height:22px;">
<div class="ui-tabs" align="center">
<ul class="ui-tabs-nav ui-widget-header ui-corner-all"">
<div align="center"><a href="http://www.websitemembermanager.com/" target="_blank">WebsiteMemberManager</a> - developed by <a href="http://www.dwalker.co.uk/">DWalker.co.uk</a></body></html>
Return current item: WebsiteMemberManager