PageRenderTime 27ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/vogoo/install/install.php

https://github.com/zackster/hip-hop-goblin
PHP | 281 lines | 234 code | 16 blank | 31 comment | 22 complexity | cd6d29729a6eb9218f284e95811c3d71 MD5 | raw file
  1. <?php
  2. /***************************************************************************
  3. * install.php
  4. * -------------------
  5. * begin : Thursday, Apr 7, 2005
  6. * copyright : (C) 2001 The phpBB Group, (C) 2005 Stephane DROUX
  7. *
  8. * Notice: Most of this file is taken from the install.php file of the phpBB v2 forum
  9. * The stylesheet associated is also a modified version of the subSilver.css stylesheet that comes with the phpBB v2 forum
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. ***************************************************************************/
  21. if (@file_exists('../config.php'))
  22. {
  23. include('../config.php');
  24. }
  25. $already_installed = false;
  26. if (defined("VOGOO_INSTALLED"))
  27. {
  28. $already_installed = true;
  29. }
  30. if (!isset($HTTP_POST_VARS) && isset($_POST))
  31. {
  32. $HTTP_POST_VARS = $_POST;
  33. }
  34. $dbms = isset($HTTP_POST_VARS['dbms']) ? $HTTP_POST_VARS['dbms'] : '';
  35. $dbhost = (!empty($HTTP_POST_VARS['dbhost'])) ? $HTTP_POST_VARS['dbhost'] : 'localhost';
  36. $dbuser = (!empty($HTTP_POST_VARS['dbuser'])) ? $HTTP_POST_VARS['dbuser'] : '';
  37. $dbpasswd = (!empty($HTTP_POST_VARS['dbpasswd'])) ? $HTTP_POST_VARS['dbpasswd'] : '';
  38. $dbname = (!empty($HTTP_POST_VARS['dbname'])) ? $HTTP_POST_VARS['dbname'] : '';
  39. // Define schema info
  40. $available_dbms = array(
  41. 'mysql'=> array(
  42. 'LABEL' => 'MySQL 3.x'
  43. ),
  44. 'mysql4' => array(
  45. 'LABEL' => 'MySQL 4.x'
  46. ),
  47. 'postgres' => array(
  48. 'LABEL' => 'PostgreSQL 7.x'
  49. )
  50. /* 'mssql' => array(
  51. 'LABEL' => 'MS SQL Server 7/2000',
  52. ),
  53. 'msaccess' => array(
  54. 'LABEL' => 'MS Access [ ODBC ]',
  55. ),
  56. 'mssql-odbc' => array(
  57. 'LABEL' => 'MS SQL Server [ ODBC ]',
  58. )*/
  59. );
  60. $valid_dbms = false;
  61. $dbms_select = '<select name="dbms">';
  62. while (list($dbms_name, $details) = @each($available_dbms))
  63. {
  64. if ($dbms_name == $dbms)
  65. {
  66. $selected = ' selected';
  67. $valid_dbms = true;
  68. }
  69. else
  70. {
  71. $selected = '';
  72. }
  73. $dbms_select .= '<option value="' . $dbms_name . '"' . $selected . '>' . $details['LABEL'] . '</option>';
  74. }
  75. $dbms_select .= '</select>';
  76. if ($already_installed)
  77. {
  78. $maintitle = 'VOGOO PHP Lib is already installed.';
  79. $text = 'Thank you for choosing VOGOO PHP Lib.';
  80. $form = false;
  81. }
  82. else if (!$valid_dbms)
  83. {
  84. $maintitle = 'Welcome to VOGOO PHP Lib Installation.';
  85. $text = 'Thank you for choosing VOGOO PHP Lib. In order to complete this install please fill out the details requested below. Please note that the database you install into should already exist.'; // 'If you are installing to a database that uses ODBC, e.g. MS Access you should first create a DSN for it before proceeding.';
  86. $form = true;
  87. }
  88. else
  89. {
  90. $maintitle = 'VOGOO PHP Lib Installation Finished.';
  91. $error = false;
  92. $msg = '';
  93. // Run the installation process
  94. define("VOGOO_DIR","../");
  95. define("VOGOO","installation");
  96. $vg_dbms = $dbms;
  97. include("../db.php");
  98. $db = new vg_sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
  99. if(!$db->db_connect_id)
  100. {
  101. $error = true;
  102. $msg .= 'CRITICAL ERROR : Could not connect to the database.<br />';
  103. }
  104. switch ($dbms)
  105. {
  106. case 'msaccess':
  107. case 'mssql-odbc':
  108. break;
  109. case 'mssql':
  110. $sql = '';
  111. break;
  112. case 'mysql':
  113. case 'mysql4':
  114. $sql = <<<EOF
  115. CREATE TABLE vogoo_ratings(member_id INT NOT NULL,product_id INT NOT NULL,category INT NOT NULL,rating FLOAT NOT NULL,ts TIMESTAMP);
  116. CREATE INDEX vogoo_ratings_mix ON vogoo_ratings(member_id);
  117. CREATE INDEX vogoo_ratings_pix ON vogoo_ratings(product_id);
  118. CREATE UNIQUE INDEX vogoo_ratings_mpix ON vogoo_ratings(member_id,product_id,category);
  119. CREATE TABLE vogoo_ads(ad_id INT NOT NULL,category INT NOT NULL,mini INT NOT NULL,KEY ad_id(ad_id));
  120. CREATE TABLE vogoo_ads_products(ad_id INT NOT NULL,category INT NOT NULL,product_id INT NOT NULL,KEY ad_id(ad_id),KEY category(category));
  121. CREATE TABLE vogoo_links(item_id1 INT NOT NULL,item_id2 INT NOT NULL,category INT NOT NULL,cnt INT,diff_slope FLOAT);
  122. CREATE INDEX vogoo_links_i1ix ON vogoo_links(item_id1);
  123. CREATE INDEX vogoo_links_i2ix ON vogoo_links(item_id2);
  124. CREATE UNIQUE INDEX vogoo_links_ix ON vogoo_links(item_id1,item_id2,category);
  125. EOF;
  126. break;
  127. case 'postgres':
  128. $sql = <<<EOF
  129. BEGIN;
  130. CREATE TABLE vogoo_ratings(member_id INTEGER,product_id INTEGER,category INTEGER,rating FLOAT,ts TIMESTAMP);
  131. CREATE INDEX vogoo_ratings_member_id_index ON vogoo_ratings(member_id);
  132. CREATE INDEX vogoo_ratings_product_id_index ON vogoo_ratings(product_id);
  133. CREATE INDEX vogoo_ratings_category_index ON vogoo_ratings(category);
  134. CREATE TABLE vogoo_ads(ad_id INTEGER,category INTEGER,mini INTEGER);
  135. CREATE INDEX vogoo_ads_ad_id_index ON vogoo_ads(ad_id);
  136. CREATE TABLE vogoo_ads_products(ad_id INTEGER,category INTEGER,product_id INTEGER);
  137. CREATE INDEX vogoo_ads_products_ad_id_index ON vogoo_ads_products(ad_id);
  138. CREATE INDEX vogoo_ads_products_category_index ON vogoo_ads_products(category);
  139. CREATE TABLE vogoo_links(item_id1 INTEGER,item_id2 INTEGER,category INTEGER,cnt INT,diff_slope FLOAT);
  140. CREATE INDEX vogoo_links_item_id1_index ON vogoo_links(item_id1);
  141. CREATE INDEX vogoo_links_item_id2_index ON vogoo_links(item_id2);
  142. CREATE INDEX vogoo_links_category ON vogoo_links(category);
  143. COMMIT;
  144. EOF;
  145. break;
  146. }
  147. // Write out the config file.
  148. $config_data = '<?php'."\n";
  149. $config_data .= "// VOGOO LIB auto-generated config file\n// Do not change anything in this file!\n\n";
  150. $config_data .= '$vg_dbms = \'' . $dbms . '\';' . "\n";
  151. $config_data .= '$vg_dbhost = \'' . $dbhost . '\';' . "\n";
  152. $config_data .= '$vg_dbname = \'' . $dbname . '\';' . "\n";
  153. $config_data .= '$vg_dbuser = \'' . $dbuser . '\';' . "\n";
  154. $config_data .= '$vg_dbpasswd = \'' . $dbpasswd . '\';' . "\n";
  155. $config_data .= 'define(\'VOGOO_INSTALLED\', true);'."\n";
  156. $config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
  157. @umask(0111);
  158. if (!$error)
  159. {
  160. if (!($fp = @fopen('../config.php', 'w')))
  161. {
  162. $error = true;
  163. $msg .= 'Could not write the config.php file. Please check the write permission for this file.<br />';
  164. }
  165. else
  166. {
  167. $result = @fputs($fp, $config_data, strlen($config_data));
  168. @fclose($fp);
  169. }
  170. }
  171. if (!$error)
  172. {
  173. $sqllines = explode("\n",$sql);
  174. foreach ($sqllines as $line)
  175. {
  176. if (!$db->sql_query($line))
  177. {
  178. $error = true;
  179. $msg .= 'Could not create the database tables required by the VOGOO LIB.<br />';
  180. }
  181. }
  182. }
  183. if (!$error)
  184. {
  185. $text = 'VOGOO PHP LIB installation is complete. Thank you for choosing the VOGOO PHP Lib.<br />You can now close this window and start using the VOGOO PHP Lib in your own PHP scripts.';
  186. }
  187. else
  188. {
  189. $text = 'At least an error occured during the installation process. Please check the errors listed below:<br />';
  190. $text .= $msg;
  191. }
  192. $form = false;
  193. }
  194. ?>
  195. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  196. <html>
  197. <head>
  198. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  199. <meta http-equiv="Content-Style-Type" content="text/css">
  200. <title>Welcome to VOGOO PHP LIB installation</title>
  201. <link rel="stylesheet" href="./style.css" type="text/css">
  202. </head>
  203. <body bgcolor="#DDDDDD" text="#000000" link="#006699" vlink="#5584AA">
  204. <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
  205. <tr>
  206. <td class="bodyline" width="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  207. <tr>
  208. <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  209. <tr>
  210. <td><img src="../img/logo.gif" border="0" alt="Vogoo" vspace="1" /></td>
  211. <td align="center" width="100%" valign="middle"><span class="maintitle"><?php echo $maintitle; ?></span></td>
  212. </tr>
  213. </table></td>
  214. </tr>
  215. <tr>
  216. <td><br /><br /></td>
  217. </tr>
  218. <tr>
  219. <td colspan="2"><table width="90%" border="0" align="center" cellspacing="0" cellpadding="0">
  220. <tr>
  221. <td><span class="gen"><?php echo $text; ?></span></td>
  222. </tr>
  223. </table></td>
  224. </tr>
  225. <tr>
  226. <td><br /><br /></td>
  227. </tr>
  228. <?php if ($form) { ?>
  229. <tr><td width="100%">
  230. <form action="install.php" name="install" method="post">
  231. <table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
  232. <tr>
  233. <th colspan="2">Database configuration</th>
  234. </tr>
  235. <tr>
  236. <td class="row1" align="right" width="30%"><span class="gen">Database Type: </span></td>
  237. <td class="row2"><?php echo $dbms_select; ?></td>
  238. </tr>
  239. <tr>
  240. <td class="row1" align="right" width="30%"><span class="gen">Database Server Hostname / DSN: </span></td>
  241. <td class="row2"><input type="text" name="dbhost" value="<?php echo ($dbhost != '') ? $dbhost : ''; ?>" /></td>
  242. </tr>
  243. <tr>
  244. <td class="row1" align="right" width="30%"><span class="gen">Your Database Name: </span></td>
  245. <td class="row2"><input type="text" name="dbname" value="<?php echo ($dbname != '') ? $dbname : ''; ?>" /></td>
  246. </tr>
  247. <tr>
  248. <td class="row1" align="right" width="30%"><span class="gen">Database Username: </span></td>
  249. <td class="row2"><input type="text" name="dbuser" value="<?php echo ($dbuser != '') ? $dbuser : ''; ?>" /></td>
  250. </tr>
  251. <tr>
  252. <td class="row1" align="right" width="30%"><span class="gen">Database Password: </span></td>
  253. <td class="row2"><input type="password" name="dbpasswd" value="<?php echo ($dbpasswd != '') ? $dbpasswd : ''; ?>" /></td>
  254. </tr>
  255. <tr>
  256. <td class="catBottom" align="center" colspan="2"><input class="mainoption" type="submit" value="Start Install" /></td>
  257. </tr>
  258. </table></form></td>
  259. </tr>
  260. <?php } ?>
  261. </table></td>
  262. </tr>
  263. </table>
  264. </body>
  265. </html>