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

// QuickTalk 2.5 build:20100731

session_start();
$strV = '2.5';

if ( !isset($_SESSION['qtg_setup_lang']) ) $_SESSION['qtg_setup_lang']='en';

include('qtg_lang_'.$_SESSION['qtg_setup_lang'].'.php');
include('../bin/config.php');

$strAppl = 'QuickTalk guestbook '.$strV;
$strPrevUrl = 'qtg_setup_1.php';
$strNextUrl = 'qtg_setup_2_db.php';
$strPrevLabel= $L['Back'];
$strNextLabel= $L['Next'];
$error = '';

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

include('qtg_setup_hd.php');

echo '
<table cellspacing="0">
<tr valign="top">
<td width="475" style="padding:0px">';

// --------
// SUBMITTED
// --------

if ( isset($_POST['submit']) )
{
  include('../bin/qt_lib_db.php');
  include('../bin/qt_lib_txt.php');

  $qtg_dbsystem = strip_tags(trim($_POST['qtg_dbsystem']));
  $qtg_host = strip_tags(trim($_POST['qtg_host']));
  $qtg_database = strip_tags(trim($_POST['qtg_database']));
  if ( $qtg_dbsystem=='sqlite' && substr($qtg_database,-3,3)!='.db' ) $qtg_database .= '.db';
  $qtg_prefix = strip_tags(trim($_POST['qtg_prefix']));
  $qtg_user = strip_tags(trim($_POST["qtg_user"]));
  $qtg_pwd = strip_tags(trim($_POST["qtg_pwd"]));
  $qtg_user_2 = strip_tags(trim($_POST["qtg_user_2"]));
  $qtg_pwd_2 = strip_tags(trim($_POST["qtg_pwd_2"]));
  $qtg_port = strip_tags(trim($_POST['qtg_port']));
  $qtg_dsn = strip_tags(trim($_POST['qtg_dsn']));
  $str = strip_tags(trim($_POST['qtg_dbo_login']));
  if ( $str!='') $_SESSION['qtg_dbologin'] = $str;
  $str = strip_tags(trim($_POST['qtg_dbo_pswrd']));
  if ( $str!='') $_SESSION['qtg_dbopwd'] = $str;

  if ( !QTislogin($qtg_user,2) ) { $qtg_user=QTconv($qtg_user,'U'); $error="Username [$qtg_user] will not be considered as a valid username."; }
  if ( !QTispassword($qtg_pwd,2) ) { $qtg_pwd=QTconv($qtg_pwd,'U'); $error="The password of [$qtg_user] will not be considered as a valid password."; }
  if ( $qtg_user_2!='' )
  {
    if ( !QTislogin($qtg_user_2,2) ) { $qtg_user_2=QTconv($qtg_user_2,'U'); $error="Username [$qtg_user_2] will not be considered as a valid username."; }
    if ( !QTispassword($qtg_pwd_2,2) ) { $qtg_pwd_2=QTconv($qtg_pwd_2,'U'); $error="The password of [$qtg_user_2] will not be considered as a valid password."; }
  }
  if ( !empty($error) ) echo '<div class="setup_err">',$error,'</div>';
  $error='';

  // Test Connection

  if ( isset($_SESSION['qtg_dbologin']) )
  {
    $oDB = new cDB($qtg_dbsystem,$qtg_host,$qtg_database,$_SESSION['qtg_dbologin'],$_SESSION['qtg_dbopwd'],$qtg_port,$qtg_dsn);
  }
  else
  {
    $oDB = new cDB($qtg_dbsystem,$qtg_host,$qtg_database,$qtg_user,$qtg_pwd,$qtg_port,$qtg_dsn);
  }

  if ( empty($oDB->error) )
  {
    echo '<div class="setup_ok">',$L['S_connect'],'</div>';
  }
  else
  {
    echo '<div class="setup_err">',sprintf ($L['E_connect'],$qtg_database,$qtg_host),'</div>';
  }
 
  // Save Connection
  
  $strFilename = '../bin/config.php';
  $strTxt = '<?php  
  $qtg_dbsystem = "'.$qtg_dbsystem.'";
  $qtg_host = "'.$qtg_host.'";
  $qtg_port = "'.$qtg_port.'";
  $qtg_dsn = "'.$qtg_dsn.'";
  $qtg_database = "'.$qtg_database.'";
  $qtg_prefix = "'.$qtg_prefix.'";
  $qtg_user = "'.$qtg_user.'";
  $qtg_pwd = "'.$qtg_pwd.'";
  $qtg_user_2 = "'.$qtg_user_2.'";
  $qtg_pwd_2 = "'.$qtg_pwd_2.'";
  $qtg_install = "'.date('Y-m-d').'";
  ?>';

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

  if ( empty($error) )
  {
    echo '<div class="setup_ok">',$L['S_save'],'</div>';
  }
  else
  {
    echo '<div class="setup_err">',$error,$L['E_save'],'</div>';
  }
}

// --------
// END SUBMITTED
// --------

echo '<form method="post" name="install" action="qtg_setup_1_db.php">
<table cellspacing="0" cellpadding="5">
<tr>
<td colspan="2"><h2>',$L['Connection_db'],'</h2><br/></td>
</tr>
';
echo '<tr>
<td>',$L['Database_type'],'</td>
<td><select name="qtg_dbsystem">
<option value="mysql4"',($qtg_dbsystem=='mysql4' ? ' selected="selected"' : ''),'>MySQL 4</option>
<option value="mysql"',($qtg_dbsystem=='mysql' ? ' selected="selected"' : ''),'>MySQL 5 or next</option>
<option value="mssql"',($qtg_dbsystem=='mssql' ? ' selected="selected"' : ''),'>Microsoft SQL server</option>
<option value="pg"'.($qtg_dbsystem=='pg' ? 'selected="selected"' : ''),'>PostgreSQL</option>
<option value="ibase"'.($qtg_dbsystem=='ibase' ? 'selected="selected"' : ''),'>FireBird</option>
<option value="sqlite"'.($qtg_dbsystem=='sqlite' ? 'selected="selected"' : ''),'>SQLite</option>
<option value="db2"',($qtg_dbsystem=='db2' ? ' selected="selected"' : ''),'>IBM DB2</option>
<option value="oci"'.($qtg_dbsystem=='oci' ? ' selected="selected"' : ''),'>Oracle</option>
</select></td>
</tr>
';
echo '<tr>
<td>',$L['Database_host'],'</td>
<td>
<input type="text" name="qtg_host" value="',$qtg_host,'" size="15" maxlength="100"/>
<input type="text" name="qtg_port" value="',$qtg_port,'" size="5" maxlength="20"/>
<input type="text" name="qtg_dsn" value="',$qtg_dsn,'" size="8" maxlength="100"/>
</td>
</tr>
<tr>
<td>',$L['Database_name'],'</td>
<td><input type="text" name="qtg_database" value="',$qtg_database,'" size="15" maxlength="100"/></td>
</tr>
<tr>
<td>',$L['Table_prefix'],'</td>
<td><input type="text" name="qtg_prefix" value="',$qtg_prefix,'" size="15" maxlength="100"/></td>
</tr>
<tr>
<td>Administrator 1 (login/password)</td>
<td>
<input name="qtg_user" value="',$qtg_user,'" size="15" maxlength="100"/>
<input type="password" name="qtg_pwd" value="',$qtg_pwd,'" size="15" maxlength="100"/>
</td>
</tr>
<tr>
<td>Administrator 2 (login/password)</td>
<td>
<input name="qtg_user_2" value="',$qtg_user_2,'" size="15" maxlength="100"/>
<input type="password" name="qtg_pwd_2" value="',$qtg_pwd_2,'" size="15" maxlength="100"/>
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#CCCCCC"><span class="small">',$L['Htablecreator'],'</span></td>
</tr>
<tr>
<td style="background-color:#CCCCCC">Table creator (login/password)</td>
<td style="background-color:#CCCCCC">
<input type="text" name="qtg_dbo_login" value="',(isset($_SESSION['qtg_dbologin']) ? $_SESSION['qtg_dbologin'] : ''),'" size="15" maxlength="100"/>
<input type="password" name="qtg_dbo_pswrd" value="',(isset($_SESSION['qtg_dbopwd']) ? $_SESSION['qtg_dbopwd'] : ''),'" size="15" maxlength="100"/>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="submit" value="',$L['Save'],'"/></td>
</tr>

</table>
</form>
<span class="small">',$L['Upgrade'],'</span>';

echo '
</td>
<td class="hidden"><div class="setup_help">',$L['Help_1a'],'</div></td>
</tr>
</table>
';

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

include('qtg_setup_ft.php');

?>
Return current item: Quick Guestbook