Location: PHPKode > projects > Quick Guestbook > quicktalk/install/qtg_setup_3_db.php
<?php

// QuickTalk 2.5 build:20100731

session_start();

if ( isset($_SESSION['qtg_setup_lang']) ) { $strLang = $_SESSION['qtg_setup_lang']; } else { $strLang = 'en'; }
include('qtg_lang_'.$strLang.'.php');
include('../bin/config.php');
include('../bin/config_display.php');
include('../bin/qt_lib_db.php');
if ( isset($_SESSION['qtg_dbopwd']) )
{
$qtg_user = $_SESSION['qtg_dbologin'];
$qtg_pwd = $_SESSION['qtg_dbopwd'];
}  
$oDB = new cDB($qtg_dbsystem,$qtg_host,$qtg_database,$qtg_user,$qtg_pwd,$qtg_port,$qtg_dsn);

$strAppl = 'QuickTalk guestbook 2.5';
$strPrevUrl = 'qtg_setup_2b.php';
$strNextUrl = '../qtg_index.php';
$strPrevLabel= $L['Back'];
$strNextLabel= $L['Finish'];
$strMessage='';

if ( isset($_SESSION['qtg_boardmail']) ) $qtg_email = $_SESSION['qtg_boardmail'];

// Search version and Check !

$strVersion='';
$b = $oDB->Query( 'SELECT name FROM '.$qtg_prefix.'qtgmessage WHERE id=-1');
if ( !$b ) 
{
  include('qtg_setup_hd.php');
  echo '<div class="setup_err">Problem: the table '.$qtg_prefix.'qtgmessage cannot be found.</div>';
  include('qtg_setup_ft.php');
  exit;
}
else
{
  $row = $oDB->Getrow();
  if ( isset($row['name']) ) { $strVersion=$row['name']; } else { $strVersion='1.5'; }
}

// UPDATE 1.6

if ( $strVersion=='1.5' || $strVersion=='1.6' )
{
  $oDB->Query( 'INSERT INTO '.$qtg_prefix.'qtgmessage (id,name,'.($oDB->type=='ibase' ? 'textmsg' : 'message').',visible) VALUES(-1,"1.7","Version","N")');
  $strVersion=='1.6';
  $strMessage.='<p>Upgrade to version '.$strVersion.' completed.</p>';
}

// UPDATE TO 1.7

if ( $strVersion=='1.6' ) 
{
  switch (substr($oDB->type,0,5))
  {
  case 'mysql':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14) NOT NULL DEFAULT "0"');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage MODIFY x decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage MODIFY y decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage MODIFY z decimal(13,2)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=DATE_FORMAT(postdate,"%Y%m%d%H%i%s")');
    break;
  case 'mssql':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14) NOT NULL DEFAULT "0"');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN x decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN y decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN z decimal(13,2)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=replace(convert(varchar,postdate,102),".","") + replace(convert(varchar,postdate,108),":","")');
    break;
  case 'pg':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14) NOT NULL DEFAULT "0"');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN x TYPE decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN y TYPE decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN z TYPE decimal(13,2)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=TO_CHAR(postdate,"YYYYMMDDHH24MISS")');
    break;
  case 'acces':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=str( DATEPART("yyyy",postdate)*10000+DATEPART("m",postdate)*100+DATEPART("d",postdate) )');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=issuedate & RIGHT("0" & str(DATEPART("h",postdate)*10000+DATEPART("n",postdate)*100+DATEPART("s",postdate)),6)');
    break;
  case 'sqlit':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate text DEFAULT "0"');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=postdate');
    break;
  case 'ibase':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14) DEFAULT "0"');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN x TYPE decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN y TYPE decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN z TYPE decimal(13,2)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=CAST( EXTRACT(YEAR FROM postdate)*1000000000000+EXTRACT(MONTH FROM postdate)*100000000+EXTRACT(DAY FROM postdate)*1000000+EXTRACT(HOUR FROM postdate)*10000+EXTRACT(MINUTE FROM postdate)*100+EXTRACT(SECOND FROM postdate) AS VARCHAR(14) )');
    break;
  case 'db2':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14) NOT NULL DEFAULT "0"');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN x SET DATA TYPE decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN y SET DATA TYPE decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ALTER COLUMN z SET DATA TYPE decimal(13,2)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=CAST( YEAR(postdate)*1000000000000+MONTH(postdate)*100000000+DAY(postdate)*1000000+HOUR(postdate)*10000+MINUTE(postdate)*100+SECOND(postdate) AS VARCHAR(14) )');
    break;
  case 'oci':
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage ADD issuedate varchar(14)  default "0" NOT NULL');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage MODIFY x decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage MODIFY y decimal(13,10)');
    $oDB->Query('ALTER TABLE '.$qtg_prefix.'qtgmessage MODIFY z decimal(13,2)');
    $oDB->Query('UPDATE '.$qtg_prefix.'qtgmessage SET issuedate=TO_CHAR(postdate,"YYYYMMDDHH24MISS")');
    break;
  }
  $strVersion = '1.7';
  $oDB->Query( 'UPDATE '.$qtg_prefix.'qtgmessage SET name="1.7" WHERE id=-1');
  $strMessage.='<p>Upgrade to version '.$strVersion.' completed.</p>';
}

// UPDATE

if ( $strVersion=='1.7' || $strVersion=='2.0' ) 
{
  $strVersion = '2.5';
  $oDB->Query( 'UPDATE '.$qtg_prefix.'qtgmessage SET name="'.$strVersion.'" WHERE id=-1');
  $strMessage.='<p>Upgrade to version '.$strVersion.' completed.</p>';
}

// --------
// HTML START
// --------

include('qtg_setup_hd.php');

echo $strMessage;

// config_display
$strFile = "../bin/config_display.php";
$strTxt  = '<?php
$qtg_language = "'.$qtg_language.'";
$qtg_menulang = '.($qtg_menulang ? 'true' : 'false').';
$qtg_skin = "'.$qtg_skin.'";
$qtg_formatdate = "'.$qtg_formatdate.'";
$qtg_formattime = "'.$qtg_formattime.'";
$qtg_banner = '.($qtg_banner ? 'true' : 'false').';
$qtg_title = "'.$qtg_title.'";
$qtg_home = "'.$qtg_home.'";
$qtg_email = "'.$qtg_email.'";
$qtg_pagewidth = "'.$qtg_pagewidth.'";
$qtg_show_size = '.$qtg_show_size.';
$qtg_page_size = '.$qtg_page_size.';
$qtg_use_age = '.($qtg_use_age ? 'true' : 'false').';
$qtg_use_email = '.($qtg_use_email ? 'true' : 'false').';
$qtg_use_from = '.($qtg_use_from ? 'true' : 'false').';
$qtg_use_from_type = '.$qtg_use_from_type.';
$qtg_column_default = '.($qtg_column_default ? 'true' : 'false').';
$qtg_column_change = '.($qtg_column_change ? 'true' : 'false').';
$qtg_separateform = '.($qtg_separateform ? 'true' : 'false').';
$qtg_bbc_bold = '.($qtg_bbc_bold ? 'true' : 'false').';
$qtg_bbc_italic = '.($qtg_bbc_italic ? 'true' : 'false').';
$qtg_bbc_underline = '.($qtg_bbc_underline ? 'true' : 'false').';
$qtg_bbc_url = '.($qtg_bbc_url ? 'true' : 'false').';
$qtg_bbc_smiley = '.($qtg_bbc_smiley ? 'true' : 'false').'; ?>';

if ( !is_writable($strFile) ) $error="Impossible to write into the file [$strFile].";

if ( empty($error) )
{
   if ( !$handle=fopen($strFile, 'w') ) $error="Impossible to open the file [$strFile].";
}
if ( empty($error) )
{
   if ( fwrite($handle,$strTxt)===FALSE )
   {
    $error = "Impossible to write into the file [$strFile].";
   }
   else
   {
    fclose($handle);
   }
}

if ( empty($error) )
{
  if ( isset($_SESSION['qtgInstalled']) )
  {
    echo $L['S_install_exit'];
    echo '<div style="width:350px; padding:10px; border-style:solid; border-color:#FF0000; border-width:1px; background-color:#EEEEEE">',$L['End_message'],'<br/>',$L['User'],': <b>',$qtg_user,'</b><br/>',$L['Password'],': <b>',$qtg_pwd,'</b><br/></div><br/>';
  }
  else
  {
    echo $L['N_install'];
  }

  echo '<br/><br/><a href="../check.php">',$L['Check_install'],'</a><br/><br/>';

}
else
{
  echo '<br/><p class="error">',$error,'</p>';
}

// --------
// HTML END
// --------

include('qtg_setup_ft.php');


?>
Return current item: Quick Guestbook