Location: PHPKode > projects > phlyMail Lite > phlymail/shared/drivers/mysql/install.php
<?php
/**
 * phlyMail core application database installation module
 *
 * @package phlyMail Nahariya 4.0+
 * @subpackage Core application
 * @subpackage Database driver
 * @copyright 2002-2008 phlyLabs Berlin, http://phlylabs.de
 * @author Matthias Sommerfeld <hide@address.com>
 * @version 4.0.3
 */
// Only valid within phlyMail
if (!defined('_IN_PHM_')) die();

if (file_exists($_PM_['tmp']['driver_dir'].'/lang.'.$WP_msg['language'].'.php')) {
    require_once($_PM_['tmp']['driver_dir'].'/lang.'.$WP_msg['language'].'.php');
} else require_once($_PM_['tmp']['driver_dir'].'/lang.en.php');

$WP_DBset_action = (isset($_REQUEST['WP_DBset_action'])) ? $_REQUEST['WP_DBset_action'] : false;
$WP_DB = (isset($_REQUEST['WP_DB'])) ? $_REQUEST['WP_DB'] : array();

require_once($_PM_['tmp']['driver_dir'].'/driver.php');
require_once($_PM_['tmp']['driver_dir'].'/admin.php');
$DB = new admin($_PM_['path']['conf'].'/driver.'.$_PM_['core']['database'].'.ini.php');

if ('do' == $WP_DBset_action) {
    if ($WP_DB['pw1'] == $WP_DB['pw2']) {
        $erroneous = 0;
        require_once('runonce.php');
        $fp = fopen($_PM_['tmp']['driver_dir'].'/install.tables.sql', 'r');
        while ($skeleton = fgets($fp, 4096)) {
            $skeleton = str_replace('$1', $DB->DB['prefix'], str_replace('$2', $WP_DB['adm_name'],
                        str_replace('$3', md5($WP_DB['pw1']), trim($skeleton))));
            if (!$DB->query($skeleton)) {
                echo '<span style="color:darkred">MySQL error:&nbsp;<pre>'.$DB->error().'</pre></span><br>';
                $erroneous++;
            }
        }
        fclose($fp);
        if ($erroneous == 0) {
            if ($DB->query('SELECT 1 FROM '.$DB->Tbl['user'])) {
                if ($DB->query('SELECT 1 FROM '.$DB->Tbl['profiles'])) {
                    echo '<span style="color:darkgreen">Installation okay</span><br>';
                } else {
                    echo '<span style="color:darkred">MySQL error:&nbsp;<pre>',$DB->error(),'</pre></span><br>';
                }
            } else {
                echo '<span style="color:darkred">MySQL error:&nbsp;<pre>',$DB->error(),'</pre></span><br>';
            }
        }
        $DB->close();
    } else {
        echo '<span style="color:darkred">',$WP_drvmsg['nonequal'],'</span><br>';
    }
    $WP_DBset_action = false;
}

if (!$WP_DBset_action) {
    $exists = 0;
    $fp = fopen($_PM_['tmp']['driver_dir'].'/install.tables.sql', 'r');
    while ($skeleton = fgets($fp, 4096)) {
        $skeleton = str_replace('$1', $DB->DB['prefix'], trim($skeleton));
        if (substr($skeleton, 0, 6) == 'CREATE') {
            preg_match('!CREATE TABLE `('.$DB->DB['prefix'].'_.+)`!U', $skeleton, $found);
            $qid = $DB->query('SHOW TABLES LIKE "'.$found[1].'"');
            if ($DB->fetchassoc($qid)) $exists++;
            break;
        }
    }
    fclose($fp);

    if ($exists) {
        echo '<div style="border:1px solid darkblue; background: #F0F0F0; padding: 4px;">'.$WP_drvmsg['InstTblExist'].'</div>';
    } else {
        echo $WP_drvmsg['HeadInst'],'<br /><table class="body">';
?>
<tr>
 <td align="left"><?php echo $WP_drvmsg['mysql_admname']; ?></td>
 <td align="left">
  <input type="text" name="WP_DB[adm_name]" value="<?php echo isset($WP_DB['adm_name']) ? $WP_DB['adm_name'] : ''; ?>" size=16 />
 </td>
</tr>
<tr>
 <td align="left"><?php echo $WP_drvmsg['mysql_admpass']; ?></td>
 <td align="left">
  <input type="password" name="WP_DB[pw1]" value="<?php echo isset($WP_DB['pw1']) ? $WP_DB['pw1'] : ''; ?>" size=16 />
 </td>
</tr>
<tr>
 <td align="left"><?php echo $WP_drvmsg['mysql_admpass2']; ?></td>
 <td align="left">
  <input type="password" name="WP_DB[pw2]" value="<?php echo isset($WP_DB['pw2']) ? $WP_DB['pw2'] : ''; ?>" size=16 />
 </td>
</tr>
<tr>
 <td colspan="2" align="right">
  <input type="hidden" name="WP_DBset_action" value="do" />
  <input type="submit" value="<?php echo $WP_drvmsg['save']; ?>" />
 </td>
</tr>
</table><?php
    }
}
?>
Return current item: phlyMail Lite