EPESI BIM • Business Information Manager • Cloud CRM/ERP http://epe.si/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

635 lines
24 KiB

  1. <?php
  2. /**
  3. * @author Paul Bukowski <pbukowski@telaxus.com>
  4. * @version 1.0
  5. * @copyright Copyright &copy; 2007, Telaxus LLC
  6. * @license MIT
  7. * @package epesi-base
  8. */
  9. if (version_compare(phpversion(), '5.4.0')==-1)
  10. error_reporting(E_ALL); //all without notices
  11. else
  12. error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
  13. ob_start();
  14. ini_set('arg_separator.output','&');
  15. @define('SYSTEM_TIMEZONE',date_default_timezone_get());
  16. date_default_timezone_set(SYSTEM_TIMEZONE);
  17. define('_VALID_ACCESS',1);
  18. require_once('include/data_dir.php');
  19. require_once('modules/Libs/QuickForm/requires.php');
  20. /* You can predefine user, password, database name, etc in file defined by var below.
  21. Example installation_config.php file:
  22. <?php
  23. $CONFIG = array('user' => 'db_username', 'password' => 'db_password', 'db' => 'database_name', 'host' => 'db_server_host',
  24. 'newdb' => 0, // or 1 to create new database
  25. 'engine' => 'mysqlt', // or 'postgres' for PostgreSQL
  26. 'direction' => 0 // Left to Right, or 1 for Right to Left
  27. );
  28. ?>
  29. */
  30. $fast_install_filename = "installation_config.php";
  31. // translation support
  32. $install_lang_dir = 'modules/Base/Lang/lang';
  33. $ls_langs = scandir($install_lang_dir);
  34. $langs = array();
  35. foreach ($ls_langs as $entry)
  36. if (preg_match('/.\.php$/i', $entry)) {
  37. $lang = substr($entry, 0, -4);
  38. $langs[$lang] = $lang;
  39. }
  40. $install_lang_code = & $_GET['install_lang'];
  41. require 'include/misc.php';
  42. require 'include/module_primitive.php';
  43. require 'include/module.php';
  44. require 'include/module_common.php';
  45. require 'modules/Base/Lang/LangCommon_0.php';
  46. $install_lang_load = isset($langs[$install_lang_code])
  47. ? $langs[$install_lang_code] : 'en'; // fallback to english
  48. define('FORCE_LANG_CODE', $install_lang_load);
  49. include "{$install_lang_dir}/{$install_lang_load}.php";
  50. // end translations load
  51. function set_header($str) {
  52. print('<script type="text/javascript">document.getElementById("setup_page_header").innerHTML="'.$str.'";</script>');
  53. }
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  56. <html>
  57. <head>
  58. <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  59. <title><?php echo __("EPESI setup"); ?></title>
  60. <link href="setup.css" type="text/css" rel="stylesheet"/>
  61. </head>
  62. <body>
  63. <table id="banner" border="0" cellpadding="0" cellspacing="0">
  64. <tr>
  65. <td class="image">&nbsp;</td>
  66. <td class="back" id="setup_page_header">&nbsp;</td>
  67. <td class="image back">&nbsp;</td>
  68. </tr>
  69. </table>
  70. <br>
  71. <center>
  72. <table id="main" border="0" cellpadding="0" cellspacing="0">
  73. <tr>
  74. <td>
  75. <?php
  76. function footer() {
  77. ?>
  78. </td>
  79. </tr>
  80. </table>
  81. </center>
  82. <br>
  83. <center>
  84. <span class="footer">Copyright &copy; <?php echo date('Y'); ?> &bull; <a href="http://www.telaxus.com">Telaxus LLC</a></span>
  85. <br>
  86. <p><a href="http://www.epe.si"><img src="images/epesi-powered.png" border="0"></a></p>
  87. </center>
  88. </body>
  89. </html>
  90. <?php
  91. }
  92. register_shutdown_function('footer');
  93. // language selection form
  94. if (!isset($install_lang_code)) {
  95. $complete = Base_LangCommon::get_complete_languages();
  96. $labels = Base_LangCommon::get_base_languages();
  97. $list = array();
  98. foreach ($complete as $l) {
  99. $list[$l] = isset($labels[$l])?$labels[$l]:$l;
  100. }
  101. $rest = array();
  102. foreach ($langs as $l) {
  103. $rest[$l] = isset($labels[$l])?$labels[$l]:$l;
  104. }
  105. asort($list);
  106. asort($rest);
  107. $list = array_merge(array('en'=>$labels['en']), $list);
  108. print('<div id="complete_translations">');
  109. foreach ($list as $l=>$label) {
  110. Base_LangCommon::print_flag($l, $label, 'href="?install_lang='.$l.'"');
  111. unset($rest[$l]);
  112. }
  113. print('</div>');
  114. print('<a class="show_incomplete button" onclick="this.style.display=\'none\';document.getElementById(\'incomplete_translations\').style.display=\'\';">Show incomplete translations</a>');
  115. print('<div id="incomplete_translations" style="display:none;">');
  116. foreach ($rest as $l=>$label) {
  117. Base_LangCommon::print_flag($l, $label, 'href="?install_lang='.$l.'"');
  118. }
  119. print('</div>');
  120. set_header('Select Language');
  121. die();
  122. }
  123. /**
  124. * Check access to working directories
  125. */
  126. if(file_exists('easyinstall.php')){
  127. unlink('easyinstall.php');
  128. }
  129. if (isset($_GET['check'])) {
  130. require_once('check.php');
  131. print('<br><br><a class="button" href="index.php?install_lang='.$install_lang_load.'" style="display:block;width:200px; margin:0 auto;">' . __('Continue with installation') . '</a>');
  132. die();
  133. }
  134. if(trim(ini_get("safe_mode")))
  135. die(__('You cannot use EPESI with PHP safe mode turned on - please disable it. Please notice this feature is deprecated since PHP 5.3 and is removed in PHP 5.4.'));
  136. if(file_exists(DATA_DIR.'/config.php'))
  137. die(__('Cannot write into %s file. Please delete this file.', array(DATA_DIR.'/config.php')));
  138. if(!is_writable(DATA_DIR))
  139. die(__('Cannot write into "%s" directory. Please fix privileges.', array(DATA_DIR)));
  140. if (isset($_GET['tos1']) && $_GET['tos1'] && isset($_GET['tos2']) && $_GET['tos2'] && isset($_GET['tos3']) && $_GET['tos3'] && isset($_GET['tos4']) && $_GET['tos4']) {
  141. $_GET['license'] = 1;
  142. unset($_GET['tos1']);
  143. unset($_GET['tos2']);
  144. unset($_GET['tos3']);
  145. unset($_GET['tos4']);
  146. }
  147. if(!isset($_GET['license'])) {
  148. set_header(__('License Agreement'));
  149. print('<div class="license">');
  150. print read_doc_file('license');
  151. print('</div>');
  152. print('<div class="license agreement">');
  153. $form = new HTML_QuickForm('licenceform','get');
  154. $form -> addElement('html', '<tr><td colspan=2><h3>'.__('By installing and using this software you agree to the MIT license and following terms:').'</h3></td></tr>');
  155. $form -> addElement('checkbox','tos1','',__('I will not remove the <strong>"Copyright by Telaxus LLC"</strong> notice as required by the MIT license.'));
  156. $form -> addElement('checkbox','tos2','',__('I will not remove <strong>"EPESI powered"</strong> logo and the link from the application login screen or the toolbar.'));
  157. $form -> addElement('checkbox','tos3','',__('I will not remove <strong>"Support -> About"</strong> credit page from the application menu.'));
  158. $form -> addElement('checkbox','tos4','',__('I will not remove or rename <strong>"EPESI Store"</strong> links from the application.'));
  159. foreach($_GET as $f=>$v) {
  160. if (substr($f, 0, 3) != 'tos' && $f != 'submitted')
  161. $form->addElement('hidden',$f,$v);
  162. }
  163. $form->addElement('hidden','submitted',1);
  164. $form -> addRule('tos1', __('Field required'), 'required');
  165. $form -> addRule('tos2', __('Field required'), 'required');
  166. $form -> addRule('tos3', __('Field required'), 'required');
  167. $form -> addRule('tos4', __('Field required'), 'required');
  168. isset($_GET['submitted']) && $_GET['submitted'] && $form->validate();
  169. $form -> addElement('submit', null, __('Next'));
  170. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">'.__('denotes required field').'</span>');
  171. $form->display();
  172. print('</div>');
  173. } elseif(!isset($_GET['htaccess'])) {
  174. ob_start();
  175. print('<h1>' . __('Welcome to EPESI setup!') . '<br></h1><h2>' . __('Hosting compatibility') . ':</h2><br><div class="license">');
  176. if(check_htaccess()) {
  177. $_GET['htaccess'] = 1;
  178. ob_end_clean();
  179. } else {
  180. print('</div><br><a class="button" href="setup.php?license=1&htaccess=1&install_lang='.$install_lang_load.'">' . __('Ok') . '</a>');
  181. ob_end_flush();
  182. }
  183. }
  184. if(isset($_GET['htaccess']) && isset($_GET['license'])) {
  185. set_header(__('Configuration'));
  186. $form = new HTML_QuickForm('serverform','post',$_SERVER['PHP_SELF'].'?'.http_build_query($_GET));
  187. $form -> addElement('header', null, __('Database server settings'));
  188. $form -> addElement('text', 'host', __('Database server address'));
  189. $form -> addRule('host', __('Field required'), 'required');
  190. $form -> addElement('select', 'engine', __('Database engine'), array('postgres'=>'PostgreSQL', 'mysqlt'=>'MySQL'));
  191. $form -> addRule('engine', __('Field required'), 'required');
  192. $form -> addElement('text', 'user', __('Database server user'));
  193. $form -> addRule('user', __('Field required'), 'required');
  194. $form -> addElement('password', 'password', __('Database server password'));
  195. $form -> addRule('password', __('Field required'), 'required');
  196. $form -> addElement('text', 'db', __('Database name'));
  197. $form -> addRule('db', __('Field required'), 'required');
  198. $create_db_warn_msg = __('WARNING: Make sure you have CREATE access level to do this!');
  199. $form -> addElement('select', 'newdb', __('Create new database'),
  200. array(0 => __('No'), 1 => __('Yes')),
  201. array('onChange' => 'if(this.value==1) alert("' . $create_db_warn_msg . '","warning");'));
  202. $form -> addRule('newdb', __('Field required'), 'required');
  203. $form -> addElement('header', null, __('Other settings'));
  204. $form -> addElement('select', 'direction', __('Text direction'),
  205. array(0 => __('Left to Right'), 1 => __('Right to Left')));
  206. $form -> addElement('submit', 'submit', __('Next'));
  207. $form -> setDefaults(array('engine'=>'mysqlt','db'=>'epesi','host'=>'localhost'));
  208. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">'.__('denotes required field').'</span>');
  209. if (file_exists($fast_install_filename)) {
  210. include $fast_install_filename;
  211. if (isset($CONFIG) && is_array($CONFIG)) {
  212. $txt = __('Some fields were filled to make installation easier.');
  213. print '<div style="text-align:center"><p style="width: 250px;margin-left: auto;margin-right: auto;">' . $txt . '</p></div>';
  214. foreach ($CONFIG as $key => $value) {
  215. $form->setDefaults(array($key => $value));
  216. $form->getElement($key)->freeze();
  217. }
  218. }
  219. }
  220. $required_note_text = __('denotes required field');
  221. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">' . $required_note_text . '</span>');
  222. $form -> addElement('html', '<tr><td colspan=2><br /><b>'
  223. . __('Any existing tables will be dropped!') . '</b><br />'
  224. . __('The database will be populated with data.') . '<br />'
  225. . __('This operation can take several minutes.') . '</td></tr>');
  226. if($form -> validate()) {
  227. $engine = $form -> exportValue('engine');
  228. $direction = $form -> exportValue('direction');
  229. $other = array('direction'=>$direction);
  230. $host = $form -> exportValue('host');
  231. $user = $form -> exportValue('user');
  232. $pass = $form -> exportValue('password');
  233. $dbname = $form -> exportValue('db');
  234. $new_db = $form->exportValue('newdb');
  235. switch($engine) {
  236. case 'postgres':
  237. if(!function_exists('pg_connect')) {
  238. echo(__('Please enable postgresql extension in php.ini.'));
  239. } else {
  240. $link = pg_connect("host=$host user=$user password=$pass dbname=postgres");
  241. if(!$link) {
  242. echo(__('Could not connect.'));
  243. } else {
  244. if ($new_db == 1) {
  245. $sql = 'CREATE DATABASE '.$dbname;
  246. if (pg_query($link, $sql)) {
  247. //echo "Database '$dbname' created successfully\n";
  248. write_config($host,$user,$pass,$dbname,$engine,$other);
  249. } else {
  250. echo __('Error creating database') . ': ' . pg_last_error() . "\n";
  251. }
  252. pg_close($link);
  253. } else {
  254. include_once('libs/adodb/adodb.inc.php');
  255. $ado = & NewADOConnection('postgres');
  256. if(!@$ado->Connect($host,$user,$pass,$dbname)) {
  257. echo __('Database does not exist.') . "\n";
  258. echo '<br />' .__('Please create the database first or select option')
  259. . ':<br /><b>' . __('Create new database') . '</b>';
  260. } else {
  261. write_config($host, $user, $pass, $dbname, $engine,$other);
  262. }
  263. }
  264. }
  265. }
  266. break;
  267. case 'mysqlt':
  268. if (!function_exists('mysql_connect')) {
  269. echo(__('Please enable mysql extension in php.ini.'));
  270. } else {
  271. $link = @mysql_connect($host, $user, $pass);
  272. if (!$link) {
  273. echo(__('Could not connect') . ': ' . mysql_error());
  274. } else {
  275. if ($new_db == 1) {
  276. $sql = 'CREATE DATABASE `' . $dbname . '` CHARACTER SET utf8 COLLATE utf8_unicode_ci';
  277. if (mysql_query($sql, $link)) {
  278. write_config($host, $user, $pass, $dbname, $engine, $other);
  279. } else {
  280. echo __('Error creating database: ') . mysql_error() . "\n";
  281. }
  282. mysql_close($link);
  283. } else {
  284. $result = mysql_select_db($dbname, $link);
  285. if (!$result) {
  286. echo __('Database does not exist') . ': ' . mysql_error() . "\n";
  287. echo '<br />' . __('Please create the database first or select option')
  288. . ':<br /><b>' . __('Create new database') . '</b>';
  289. } else {
  290. write_config($host, $user, $pass, $dbname, $engine, $other);
  291. }
  292. }
  293. }
  294. }
  295. break;
  296. }
  297. }
  298. $renderer =& $form->defaultRenderer();
  299. $renderer->setHeaderTemplate("\n\t<tr>\n\t\t<td style=\"white-space: nowrap; height: 20px; vertical-align: middle; background-color: #336699; background-image: url('images/header-blue.png'); background-repeat: repeat-x; color: #FFFFFF; font-weight: normal; text-align: center;\" align=\"left\" valign=\"baseline\" colspan=\"2\">{header}</td>\n\t</tr>");
  300. $renderer->setElementTemplate("\n\t<tr>\n\t\t<td align=\"right\" valign=\"baseline\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required -->{label}</td>\n\t\t<td valign=\"baseline\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>");
  301. $form->accept($renderer);
  302. print($renderer->toHtml());
  303. }
  304. ///////////////////////////////////////////////////////////////
  305. ///////////////////////////////////////////////////////////////
  306. function check_htaccess() {
  307. $dir = trim(dirname($_SERVER['SCRIPT_NAME']),'/');
  308. $epesi_dir = '/'.$dir.($dir?'/':'');
  309. $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])!== "off") ? 'https://' : 'http://';
  310. $test_url = $protocol.$_SERVER['HTTP_HOST'].$epesi_dir.'data/test.php';
  311. file_put_contents('data/test.php','<?php'."\n".'print("OK"); ?>');
  312. copy('htaccess.txt','data/.htaccess');
  313. if(ini_get('allow_url_fopen'))
  314. $ret = @file_get_contents($test_url);
  315. elseif (extension_loaded('curl')) { // Test if curl is loaded
  316. $ch = curl_init();
  317. curl_setopt($ch, CURLOPT_HEADER, 0);
  318. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  319. curl_setopt($ch, CURLOPT_URL, $test_url);
  320. $ret = curl_exec($ch);
  321. curl_close($ch);
  322. }
  323. if(!isset($ret)) {
  324. unlink('data/.htaccess');
  325. unlink('data/test.php');
  326. print(__('Unable to check EPESI root .htaccess file hosting compatibility. You should tweak it yourself.')
  327. . '<br>' . __('Suggested .htaccess file is:') . '<pre>' . file_get_contents('htaccess.txt') . '</pre>');
  328. return false;
  329. }
  330. if($ret!=="OK") {
  331. file_put_contents('data/.htaccess',"Options -Indexes\nSetEnv PHPRC ".dirname(__FILE__)."\n");
  332. if(ini_get('allow_url_fopen'))
  333. $ret = @file_get_contents($test_url);
  334. elseif (extension_loaded('curl')) { // Test if curl is loaded
  335. $ch = curl_init();
  336. curl_setopt($ch, CURLOPT_HEADER, 0);
  337. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  338. curl_setopt($ch, CURLOPT_URL, $test_url);
  339. $ret = curl_exec($ch);
  340. curl_close($ch);
  341. }
  342. if($ret!=="OK") {
  343. unlink('data/.htaccess');
  344. unlink('data/test.php');
  345. print(__('Your hosting is not compatible with default EPESI root .htaccess file. You should tweak it yourself.')
  346. . '<br>' . __('Default .htaccess file is:') . '<pre>' . file_get_contents('htaccess.txt') . '</pre>');
  347. return false;
  348. }
  349. }
  350. if(!is_writable('.')) {
  351. unlink('data/test.php');
  352. print(__('Your hosting is compatible with default EPESI root .htaccess file, but installer cannot write to EPESI root directory. You should paste following text to .htaccess file manually.')
  353. . '<pre>' . file_get_contents('data/.htaccess') . '</pre>');
  354. unlink('data/.htaccess');
  355. return false;
  356. }
  357. unlink('data/test.php');
  358. rename('data/.htaccess','.htaccess');
  359. return true;
  360. }
  361. function write_config($host, $user, $pass, $dbname, $engine, $other) {
  362. global $install_lang_load;
  363. $local_dir = dirname(dirname(str_replace('\\','/',__FILE__)));
  364. $script_filename = str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']);
  365. $other_conf = '';
  366. if(strcmp($local_dir,substr($script_filename,0,strlen($local_dir)))) {
  367. $epesi_dir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
  368. $other_conf .= "\n".'@define(\'EPESI_DIR\',\''. addcslashes($epesi_dir, '\'\\') .'\');';
  369. }
  370. $other_conf .= "\n".'define(\'DIRECTION_RTL\',\''.($other['direction']?'1':'0').'\');';
  371. $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])!== "off") ? 'https://' : 'http://';
  372. $domain_name = '';
  373. if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) {
  374. $domain_name = $_SERVER['HTTP_HOST'];
  375. } else if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']) {
  376. $domain_name = $_SERVER['SERVER_NAME'];
  377. }
  378. if ($domain_name) {
  379. $url = $protocol . $domain_name . dirname($_SERVER['REQUEST_URI']);
  380. $url = str_replace('\\', '/', $url);
  381. $other_conf .= "\n" . 'define(\'EPESI_URL\',\'' . addcslashes($url, '\'\\') . '\');';
  382. }
  383. $c = & fopen(DATA_DIR.'/config.php', 'w');
  384. fwrite($c, '<?php
  385. /**
  386. * Config file.
  387. *
  388. * All commented out defines are default values as they were
  389. * during the installation process. Default values may change after an update,
  390. * but your config file will remain as it was. If you want to know
  391. * current default values please look at file include/config.php
  392. *
  393. * This file contains database configuration.
  394. */
  395. defined(\'_VALID_ACCESS\') || die(\'Direct access forbidden\');
  396. /**
  397. * Address of SQL server.
  398. */
  399. define(\'DATABASE_HOST\',\''.addcslashes($host, '\'\\').'\');
  400. /**
  401. * User to log in to SQL server.
  402. */
  403. define(\'DATABASE_USER\',\''.addcslashes($user, '\'\\').'\');
  404. /**
  405. * User password to authorize SQL server.
  406. */
  407. define(\'DATABASE_PASSWORD\',\''.addcslashes($pass, '\'\\').'\');
  408. /**
  409. * Database to use.
  410. */
  411. define(\'DATABASE_NAME\',\''.addcslashes($dbname, '\'\\').'\');
  412. /**
  413. * Database driver.
  414. */
  415. define(\'DATABASE_DRIVER\',\''.addcslashes($engine, '\'\\').'\');
  416. /*
  417. * Turns on transfer reduction: not everything is sent to the client
  418. */
  419. //define(\'REDUCING_TRANSFER\',1);
  420. /*
  421. * A lot of debug info, starting with what modules are changed, what module variables are set... etc.
  422. */
  423. //define(\'DEBUG\',0);
  424. /*
  425. * Show module loading time ... = module + all children times
  426. */
  427. //define(\'MODULE_TIMES\',0);
  428. /*
  429. * Show queries execution time.
  430. */
  431. //define(\'SQL_TIMES\',0);
  432. /*
  433. * If you have got good server, but poor connection, turn it on.
  434. */
  435. //define(\'STRIP_OUTPUT\',0);
  436. /*
  437. * Display errors on page.
  438. */
  439. //define(\'DISPLAY_ERRORS\',1);
  440. /*
  441. * Notify all errors, including E_NOTICE, etc. Developer should use it!
  442. */
  443. //define(\'REPORT_ALL_ERRORS\',0);
  444. /*
  445. * Compress history
  446. */
  447. //define(\'GZIP_HISTORY\',1);
  448. /*
  449. * Compress HTTP output
  450. */
  451. //define(\'MINIFY_ENCODE\',1);
  452. /*
  453. * Apply sources minifying algorithms.
  454. *
  455. * If enabled CPU usage may raise, but amount
  456. * of transferred data is smaller.
  457. */
  458. //define(\'MINIFY_SOURCES\',0);
  459. /*
  460. * Show donation links in EPESI
  461. */
  462. //define(\'SUGGEST_DONATION\',1);
  463. /*
  464. * automatically check for new version
  465. */
  466. //define(\'CHECK_VERSION\',1);
  467. /*
  468. * Disable some administrator preferences.
  469. */
  470. //define(\'DEMO_MODE\',0);
  471. define(\'FILE_SESSION_DIR\',\''.str_replace('\\', '/', sys_get_temp_dir()).'\');
  472. define(\'FILE_SESSION_TOKEN\',\'epesi_'.md5(__FILE__).'_\');
  473. '.$other_conf.'
  474. ?>');
  475. fclose($c);
  476. ob_start();
  477. ob_start('rm_config');
  478. //fill database
  479. clean_database();
  480. install_base();
  481. ob_end_flush();
  482. if(file_exists(DATA_DIR.'/config.php'))
  483. header("Location: setup.php?install_lang={$install_lang_load}&check=1");
  484. ob_end_flush();
  485. }
  486. //////////////////////////////////////////////
  487. function rm_config($x) {
  488. if($x) {
  489. unlink(dirname(__FILE__).'/'.DATA_DIR.'/config.php');
  490. clean_database();
  491. }
  492. return $x;
  493. }
  494. function clean_database() {
  495. require_once('include/config.php');
  496. require_once('include/database.php');
  497. $tables_db = DB::MetaTables();
  498. $tables = array();
  499. if(DB::is_mysql())
  500. DB::Execute('SET FOREIGN_KEY_CHECKS=0');
  501. if(DB::is_postgresql() && strpos(DB::GetOne('SELECT version()'),'PostgreSQL 8.2')!==false) {
  502. foreach ($tables_db as $t) {
  503. $idxs = DB::Execute('SELECT t.tgargs as args FROM pg_trigger t,pg_class c,pg_proc p WHERE t.tgenabled AND t.tgrelid = c.oid AND t.tgfoid = p.oid AND p.proname = \'RI_FKey_check_ins\' AND c.relname = \''.strtolower($t).'\' ORDER BY t.tgrelid');
  504. $matches = array(1=>array());
  505. while ($i = $idxs->FetchRow()) {
  506. $data = explode(chr(0), $i[0]);
  507. $matches[1][] = $data[0];
  508. }
  509. $num_keys = count($matches[1]);
  510. for ( $i = 0; $i < $num_keys; $i ++ )
  511. DB::Execute('ALTER TABLE '.$t.' DROP CONSTRAINT '.$matches[1][$i]);
  512. }
  513. }
  514. foreach($tables_db as $t) {
  515. DB::DropTable($t);
  516. }
  517. if(DB::is_mysql())
  518. DB::Execute('SET FOREIGN_KEY_CHECKS=1');
  519. }
  520. function install_base() {
  521. require_once('include/config.php');
  522. require_once('include/database.php');
  523. @DB::Execute('ALTER DATABASE '.DATABASE_NAME.' CHARACTER SET utf8 COLLATE utf8_general_ci');
  524. $ret = DB::CreateTable('modules',"name C(128) KEY,version I NOTNULL, priority I NOTNULL DEFAULT 0, state I NOTNULL DEFAULT 0");
  525. if($ret===false)
  526. die('Invalid SQL query - Setup module (modules table)');
  527. $ret = DB::CreateTable('cron',"func C(32) KEY,last I NOTNULL, running I1 NOTNULL DEFAULT 0, description C(255)");
  528. if($ret===false)
  529. die('Invalid SQL query - Setup cron (cron table)');
  530. $ret = DB::CreateTable('session',"name C(128) NOTNULL," .
  531. "expires I NOTNULL DEFAULT 0, data B",array('constraints'=>', PRIMARY KEY(name)'));
  532. if($ret===false)
  533. die('Invalid SQL query - Database module (session table)');
  534. $ret = DB::CreateTable('session_client',"session_name C(128) NOTNULL, client_id I2," .
  535. "data B",array('constraints'=>', FOREIGN KEY(session_name) REFERENCES session(name), PRIMARY KEY(client_id,session_name)'));
  536. if($ret===false)
  537. die('Invalid SQL query - Database module (session_client table)');
  538. $ret = DB::CreateTable('history',"session_name C(128) NOTNULL, page_id I, client_id I2," .
  539. "data B",array('constraints'=>', FOREIGN KEY(session_name) REFERENCES session(name), PRIMARY KEY(client_id,session_name,page_id)'));
  540. if($ret===false)
  541. die('Invalid SQL query - Database module (history table)');
  542. DB::CreateIndex('history__session_name__client_id__idx', 'history', 'session_name, client_id');
  543. $ret = DB::CreateTable('variables',"name C(32) KEY,value X");
  544. if($ret===false)
  545. die('Invalid SQL query - Database module (variables table)');
  546. $ret = DB::Execute("insert into variables values('default_module',%s)",array(serialize('FirstRun')));
  547. if($ret === false)
  548. die('Invalid SQL query - Setup module (populating variables)');
  549. $ret = DB::Execute("insert into variables values('version',%s)",array(serialize(EPESI_VERSION)));
  550. if($ret === false)
  551. die('Invalid SQL query - Setup module (populating variables)');
  552. }
  553. //////////////////////////////////////////////
  554. function read_doc_file($file_basename, $suffix = 'html') {
  555. global $install_lang_load;
  556. $dir = 'docs/';
  557. $file = $dir . $file_basename . '.' . $suffix; // default file
  558. $custom_file = $dir . "{$file_basename}_{$install_lang_load}.{$suffix}";
  559. if (file_exists($custom_file))
  560. $file = $custom_file;
  561. $fp = @fopen($file, 'r');
  562. if ($fp) {
  563. $content = fread($fp, filesize($file));
  564. }
  565. fclose($fp);
  566. return $content;
  567. }
  568. ob_end_flush();
  569. ?>