1
0

functions.install.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /* $Id: functions.install.php 3304 2007-12-09 14:33:13Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * load Settings
  17. *
  18. * @param $dbTable
  19. * @return array
  20. */
  21. function loadSettings($dbTable) {
  22. global $dbCon;
  23. // pull the config params out of the db
  24. $sql = "SELECT tf_key, tf_value FROM ".$dbTable;
  25. $recordset = $dbCon->Execute($sql);
  26. if ($dbCon->ErrorNo() != 0)
  27. return false;
  28. $retVal = array();
  29. while (list($key, $value) = $recordset->FetchRow()) {
  30. $tmpValue = '';
  31. if (strpos($key,"Filter") > 0) {
  32. $tmpValue = unserialize($value);
  33. } elseif ($key == 'searchEngineLinks') {
  34. $tmpValue = unserialize($value);
  35. }
  36. if(is_array($tmpValue))
  37. $value = $tmpValue;
  38. $retVal[$key] = $value;
  39. }
  40. return $retVal;
  41. }
  42. /**
  43. * update Setting
  44. *
  45. * @param $dbTable
  46. * @param $key
  47. * @param $value
  48. * @return boolean
  49. */
  50. function updateSetting($dbTable, $key, $value) {
  51. global $dbCon;
  52. if (is_array($value))
  53. $update_value = serialize($value);
  54. else
  55. $update_value = $value;
  56. $sql = "UPDATE ".$dbTable." SET tf_value = '".$update_value."' WHERE tf_key = '".$key."'";
  57. $dbCon->Execute($sql);
  58. if ($dbCon->ErrorNo() != 0)
  59. return false;
  60. return true;
  61. }
  62. /**
  63. * write the db-conf file.
  64. *
  65. * @param $type
  66. * @param $host
  67. * @param $user
  68. * @param $pass
  69. * @param $name
  70. * @param $pcon
  71. * @return boolean
  72. */
  73. function writeDatabaseConfig($type, $host, $user, $pass, $name, $pcon) {
  74. global $databaseConfWriteOk, $databaseConfWriteError, $databaseConfContent;
  75. $databaseConfContent = '<?php
  76. /*******************************************************************************
  77. LICENSE
  78. This program is free software; you can redistribute it and/or
  79. modify it under the terms of the GNU General Public License (GPL)
  80. as published by the Free Software Foundation; either version 2
  81. of the License, or (at your option) any later version.
  82. This program is distributed in the hope that it will be useful,
  83. but WITHOUT ANY WARRANTY; without even the implied warranty of
  84. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  85. GNU General Public License for more details.
  86. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  87. *******************************************************************************/
  88. /******************************************************************************/
  89. // YOUR DATABASE CONNECTION INFORMATION
  90. /******************************************************************************/
  91. $cfg["db_type"] = "'.strtolower($type).'"; // Database-Type : mysql/sqlite/postgres
  92. $cfg["db_host"] = "'.$host.'"; // Database host computer name or IP
  93. $cfg["db_name"] = "'.$name.'"; // Name of the Database
  94. $cfg["db_user"] = "'.$user.'"; // Username for Database
  95. $cfg["db_pass"] = "'.$pass.'"; // Password for Database
  96. $cfg["db_pcon"] = '.$pcon.'; // Persistent Connection enabled : true/false
  97. /******************************************************************************/
  98. ?>';
  99. $configFile = false;
  100. $configFile = @fopen(_DIR._FILE_DBCONF, "w");
  101. if (!$configFile) {
  102. $databaseConfWriteOk = false;
  103. $databaseConfWriteError = "Cannot open configuration file <em>"._DIR._FILE_DBCONF."</em> for writing. Please check permissions and try again.";
  104. return false;
  105. }
  106. $result = @fwrite($configFile, $databaseConfContent);
  107. @fclose($configFile);
  108. if ($result === false) {
  109. $databaseConfWriteOk = false;
  110. $databaseConfWriteError = "Cannot write content to config-file <em>"._DIR._FILE_DBCONF."</em>. Please check any file locking issues and try again.";
  111. return false;
  112. }
  113. $databaseConfWriteOk = true;
  114. return true;
  115. }
  116. /**
  117. * get a ado-connection to our database.
  118. *
  119. * @param $type
  120. * @param $host
  121. * @param $user
  122. * @param $pass
  123. * @param $name
  124. * @return database-connection or false on error
  125. */
  126. function getAdoConnection($type, $host, $user, $pass, $name = "") {
  127. require_once('inc/lib/adodb/adodb.inc.php');
  128. // create ado-object
  129. $db = &ADONewConnection($type);
  130. // connect
  131. $result = @ $db->Connect($host, $user, $pass, $name);
  132. // check for error
  133. if ($db->ErrorNo() != 0 || !$result)
  134. return false;
  135. // return db-connection
  136. return $db;
  137. }
  138. /**
  139. * send button
  140. */
  141. function sendButton($name = "", $value = "") {
  142. send('<form name="setup" action="' . _FILE_THIS . '" method="post"><input type="Hidden" name="'.$name.'" value="'.$value.'"><input type="submit" value="Continue"></form><br>');
  143. }
  144. /**
  145. * send head
  146. */
  147. function sendHead($title = "") {
  148. send('<html>');
  149. send('<head>');
  150. send('<title>'._TITLE.$title.'</title>');
  151. send('<style type="text/css">');
  152. send('font {font-family: Verdana,Helvetica; font-size: 12px}');
  153. send('body {font-family: Verdana,Helvetica; font-size: 12px}');
  154. send('p,td {font-family: Verdana,Helvetica; font-size: 12px}');
  155. send('h1 {font-family: Verdana,Helvetica; font-size: 15px}');
  156. send('h2 {font-family: Verdana,Helvetica; font-size: 14px}');
  157. send('h3 {font-family: Verdana,Helvetica; font-size: 13px}');
  158. send('</style>');
  159. send('</head>');
  160. send('<body topmargin="8" leftmargin="5" bgcolor="#FFFFFF">');
  161. }
  162. /**
  163. * send foot
  164. */
  165. function sendFoot() {
  166. send('</body>');
  167. send('</html>');
  168. }
  169. /**
  170. * send - sends a string to the client
  171. */
  172. function send($string = "") {
  173. echo $string;
  174. echo str_pad('', 4096)."\n";
  175. @ob_flush();
  176. @flush();
  177. }
  178. /**
  179. * displaySetupError - displays a setup message
  180. * @param $msg - message to display
  181. * @param $status - boolean, true for 'Ok:', false for 'Error:'
  182. */
  183. function displaySetupMessage($msg="A problem occurred.", $status=false){
  184. $thisMsg='<p><font color="'.($status ? "green" : "red").'"><strong>';
  185. $thisMsg.= ($status ? "Ok" : "Error").': </strong></font>'.$msg.'</p>';
  186. send($thisMsg);
  187. }
  188. /**
  189. * initQueries - assign SQL to an array for insertion into db
  190. * @param $type - type of SQL data to get. Valid options are: install + upgrade
  191. * @param $version - version for upgrade-queries
  192. * $queries : array of 'type of queries' => 'db type' where type of queries are:
  193. - data - actual data used by tfb
  194. - test - queries to test db credentials provided by user
  195. - create - creation of tables used by tb
  196. */
  197. function initQueries($type, $version = "") {
  198. global $queries;
  199. $queries = array();
  200. $queryFile = 'inc/install/';
  201. switch ($type) {
  202. case "install":
  203. $queryFile .= 'queries.install.php';
  204. break;
  205. case "upgrade":
  206. switch ($version) {
  207. case '2.1':
  208. $queryFile .= 'queries.upgrade.tf21.php';
  209. break;
  210. case '2.2':
  211. $queryFile .= 'queries.upgrade.tf22.php';
  212. break;
  213. case '2.3':
  214. $queryFile .= 'queries.upgrade.tf23.php';
  215. break;
  216. default:
  217. $queryFile .= 'queries.upgrade.'.$version.'.php';
  218. break;
  219. }
  220. break;
  221. }
  222. if ((@is_file($queryFile)) === true)
  223. require_once($queryFile);
  224. else
  225. die("Fatal Error. queries-file (".$queryFile.") is missing.");
  226. }
  227. ?>