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.

setup.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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' => 'mysqli', // 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('text', 'port', __('Custom database port'));
  191. $form -> addElement('select', 'engine', __('Database engine'), array('postgres'=>'PostgreSQL', 'mysqli'=>'MySQL'));
  192. $form -> addRule('engine', __('Field required'), 'required');
  193. $form -> addElement('text', 'user', __('Database server user'));
  194. $form -> addRule('user', __('Field required'), 'required');
  195. $form -> addElement('password', 'password', __('Database server password'));
  196. $form -> addRule('password', __('Field required'), 'required');
  197. $form -> addElement('text', 'db', __('Database name'));
  198. $form -> addRule('db', __('Field required'), 'required');
  199. $create_db_warn_msg = __('WARNING: Make sure you have CREATE access level to do this!');
  200. $form -> addElement('select', 'newdb', __('Create new database'),
  201. array(0 => __('No'), 1 => __('Yes')),
  202. array('onChange' => 'if(this.value==1) alert("' . $create_db_warn_msg . '","warning");'));
  203. $form -> addRule('newdb', __('Field required'), 'required');
  204. $form -> addElement('header', null, __('Other settings'));
  205. $form -> addElement('select', 'direction', __('Text direction'),
  206. array(0 => __('Left to Right'), 1 => __('Right to Left')));
  207. $form -> addElement('submit', 'submit', __('Next'));
  208. $form -> setDefaults(array('engine'=>'mysqli','db'=>'epesi','host'=>'localhost'));
  209. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">'.__('denotes required field').'</span>');
  210. if (file_exists($fast_install_filename)) {
  211. include $fast_install_filename;
  212. if (isset($CONFIG) && is_array($CONFIG)) {
  213. $txt = __('Some fields were filled to make installation easier.');
  214. print '<div style="text-align:center"><p style="width: 250px;margin-left: auto;margin-right: auto;">' . $txt . '</p></div>';
  215. foreach ($CONFIG as $key => $value) {
  216. $form->setDefaults(array($key => $value));
  217. $form->getElement($key)->freeze();
  218. }
  219. }
  220. }
  221. $required_note_text = __('denotes required field');
  222. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">' . $required_note_text . '</span>');
  223. $form -> addElement('html', '<tr><td colspan=2><br /><b>'
  224. . __('Any existing tables will be dropped!') . '</b><br />'
  225. . __('The database will be populated with data.') . '<br />'
  226. . __('This operation can take several minutes.') . '</td></tr>');
  227. if($form -> validate()) {
  228. $engine = $form -> exportValue('engine');
  229. $direction = $form -> exportValue('direction');
  230. $other = array('direction'=>$direction);
  231. $host = $form -> exportValue('host');
  232. $port = $form->exportValue('port');
  233. $user = $form -> exportValue('user');
  234. $pass = $form -> exportValue('password');
  235. $dbname = $form -> exportValue('db');
  236. $new_db = $form->exportValue('newdb');
  237. switch($engine) {
  238. case 'postgres':
  239. if(!function_exists('pg_connect')) {
  240. echo(__('Please enable postgresql extension in php.ini.'));
  241. } else {
  242. $port_def = $port ? " port=$port" : '';
  243. $link = pg_connect("host=$host user=$user password=$pass dbname=postgres" . $port_def);
  244. if(!$link) {
  245. echo(__('Could not connect.'));
  246. } else {
  247. if ($port) {
  248. $host .= ':' . $port;
  249. }
  250. if ($new_db == 1) {
  251. $sql = 'CREATE DATABASE "'.$dbname.'"';
  252. if (pg_query($link, $sql)) {
  253. //echo "Database '$dbname' created successfully\n";
  254. write_config($host,$user,$pass,$dbname,$engine,$other);
  255. } else {
  256. echo __('Error creating database') . ': ' . pg_last_error() . "\n";
  257. }
  258. pg_close($link);
  259. } else {
  260. include_once('libs/adodb/adodb.inc.php');
  261. $ado = & NewADOConnection('postgres');
  262. if(!@$ado->Connect($host,$user,$pass,$dbname)) {
  263. echo __('Database does not exist.') . "\n";
  264. echo '<br />' .__('Please create the database first or select option')
  265. . ':<br /><b>' . __('Create new database') . '</b>';
  266. } else {
  267. write_config($host, $user, $pass, $dbname, $engine,$other);
  268. }
  269. }
  270. }
  271. }
  272. break;
  273. case 'mysqli':
  274. if (!class_exists('mysqli')) {
  275. echo(__('Please enable mysql extension in php.ini.'));
  276. } else {
  277. if ($port) {
  278. $host .= ':' . $port;
  279. }
  280. $link = new mysqli($host, $user, $pass);
  281. if ($link->connect_errno) {
  282. echo(__('Could not connect') . "(Errno: {$link->connect_errno}): " . $link->connect_error);
  283. } else {
  284. if ($new_db == 1) {
  285. $sql = 'CREATE DATABASE `' . $dbname . '` CHARACTER SET utf8 COLLATE utf8_unicode_ci';
  286. if ($link->query($sql)) {
  287. write_config($host, $user, $pass, $dbname, $engine, $other);
  288. } else {
  289. echo __('Error creating database: ') . $link->error . "\n";
  290. }
  291. $link->close();
  292. } else {
  293. $result = $link->select_db($dbname);
  294. if (!$result) {
  295. echo __('Database does not exist') . ': ' . $link->error . "\n";
  296. echo '<br />' . __('Please create the database first or select option')
  297. . ':<br /><b>' . __('Create new database') . '</b>';
  298. } else {
  299. write_config($host, $user, $pass, $dbname, $engine, $other);
  300. }
  301. }
  302. }
  303. }
  304. break;
  305. }
  306. }
  307. $renderer =& $form->defaultRenderer();
  308. $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>");
  309. $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>");
  310. $form->accept($renderer);
  311. print($renderer->toHtml());
  312. }
  313. ///////////////////////////////////////////////////////////////
  314. ///////////////////////////////////////////////////////////////
  315. function check_htaccess() {
  316. $dir = trim(dirname($_SERVER['SCRIPT_NAME']),'/');
  317. $epesi_dir = '/'.$dir.($dir?'/':'');
  318. $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])!== "off") ? 'https://' : 'http://';
  319. $test_url = $protocol.$_SERVER['HTTP_HOST'].$epesi_dir.'data/test.php';
  320. file_put_contents('data/test.php','<?php'."\n".'print("OK"); ?>');
  321. copy('htaccess.txt','data/.htaccess');
  322. if(ini_get('allow_url_fopen'))
  323. $ret = @file_get_contents($test_url);
  324. elseif (extension_loaded('curl')) { // Test if curl is loaded
  325. $ch = curl_init();
  326. curl_setopt($ch, CURLOPT_HEADER, 0);
  327. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  328. curl_setopt($ch, CURLOPT_URL, $test_url);
  329. $ret = curl_exec($ch);
  330. curl_close($ch);
  331. }
  332. if(!isset($ret)) {
  333. unlink('data/.htaccess');
  334. unlink('data/test.php');
  335. print(__('Unable to check EPESI root .htaccess file hosting compatibility. You should tweak it yourself.')
  336. . '<br>' . __('Suggested .htaccess file is:') . '<pre>' . file_get_contents('htaccess.txt') . '</pre>');
  337. return false;
  338. }
  339. if($ret!=="OK") {
  340. file_put_contents('data/.htaccess',"Options -Indexes\nSetEnv PHPRC ".dirname(__FILE__)."\n");
  341. if(ini_get('allow_url_fopen'))
  342. $ret = @file_get_contents($test_url);
  343. elseif (extension_loaded('curl')) { // Test if curl is loaded
  344. $ch = curl_init();
  345. curl_setopt($ch, CURLOPT_HEADER, 0);
  346. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  347. curl_setopt($ch, CURLOPT_URL, $test_url);
  348. $ret = curl_exec($ch);
  349. curl_close($ch);
  350. }
  351. if($ret!=="OK") {
  352. unlink('data/.htaccess');
  353. unlink('data/test.php');
  354. print(__('Your hosting is not compatible with default EPESI root .htaccess file. You should tweak it yourself.')
  355. . '<br>' . __('Default .htaccess file is:') . '<pre>' . file_get_contents('htaccess.txt') . '</pre>');
  356. return false;
  357. }
  358. }
  359. if(!is_writable('.')) {
  360. unlink('data/test.php');
  361. 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.')
  362. . '<pre>' . file_get_contents('data/.htaccess') . '</pre>');
  363. unlink('data/.htaccess');
  364. return false;
  365. }
  366. unlink('data/test.php');
  367. rename('data/.htaccess','.htaccess');
  368. return true;
  369. }
  370. function write_config($host, $user, $pass, $dbname, $engine, $other) {
  371. global $install_lang_load;
  372. $local_dir = dirname(dirname(str_replace('\\','/',__FILE__)));
  373. $script_filename = str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']);
  374. $other_conf = '';
  375. if(strcmp($local_dir,substr($script_filename,0,strlen($local_dir)))) {
  376. $epesi_dir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
  377. $other_conf .= "\n".'@define(\'EPESI_DIR\',\''. addcslashes($epesi_dir, '\'\\') .'\');';
  378. }
  379. $other_conf .= "\n".'define(\'DIRECTION_RTL\',\''.($other['direction']?'1':'0').'\');';
  380. $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])!== "off") ? 'https://' : 'http://';
  381. $domain_name = '';
  382. if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) {
  383. $domain_name = $_SERVER['HTTP_HOST'];
  384. } else if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']) {
  385. $domain_name = $_SERVER['SERVER_NAME'];
  386. }
  387. if ($domain_name) {
  388. $url = $protocol . $domain_name . dirname($_SERVER['REQUEST_URI']);
  389. $url = str_replace('\\', '/', $url);
  390. $other_conf .= "\n" . 'define(\'EPESI_URL\',\'' . addcslashes($url, '\'\\') . '\');';
  391. }
  392. $c = & fopen(DATA_DIR.'/config.php', 'w');
  393. fwrite($c, '<?php
  394. /**
  395. * Config file.
  396. *
  397. * All commented out defines are default values as they were
  398. * during the installation process. Default values may change after an update,
  399. * but your config file will remain as it was. If you want to know
  400. * current default values please look at file include/config.php
  401. *
  402. * This file contains database configuration.
  403. */
  404. defined(\'_VALID_ACCESS\') || die(\'Direct access forbidden\');
  405. /**
  406. * Address of SQL server.
  407. */
  408. define(\'DATABASE_HOST\',\''.addcslashes($host, '\'\\').'\');
  409. /**
  410. * User to log in to SQL server.
  411. */
  412. define(\'DATABASE_USER\',\''.addcslashes($user, '\'\\').'\');
  413. /**
  414. * User password to authorize SQL server.
  415. */
  416. define(\'DATABASE_PASSWORD\',\''.addcslashes($pass, '\'\\').'\');
  417. /**
  418. * Database to use.
  419. */
  420. define(\'DATABASE_NAME\',\''.addcslashes($dbname, '\'\\').'\');
  421. /**
  422. * Database driver.
  423. */
  424. define(\'DATABASE_DRIVER\',\''.addcslashes($engine, '\'\\').'\');
  425. /*
  426. * Turns on transfer reduction: not everything is sent to the client
  427. */
  428. //define(\'REDUCING_TRANSFER\',1);
  429. /*
  430. * A lot of debug info, starting with what modules are changed, what module variables are set... etc.
  431. */
  432. //define(\'DEBUG\',0);
  433. /*
  434. * Show module loading time ... = module + all children times
  435. */
  436. //define(\'MODULE_TIMES\',0);
  437. /*
  438. * Show queries execution time.
  439. */
  440. //define(\'SQL_TIMES\',0);
  441. /*
  442. * If you have got good server, but poor connection, turn it on.
  443. */
  444. //define(\'STRIP_OUTPUT\',0);
  445. /*
  446. * Display errors on page.
  447. */
  448. //define(\'DISPLAY_ERRORS\',1);
  449. /*
  450. * Notify all errors, including E_NOTICE, etc. Developer should use it!
  451. */
  452. //define(\'REPORT_ALL_ERRORS\',0);
  453. /*
  454. * Compress history
  455. */
  456. //define(\'GZIP_HISTORY\',1);
  457. /*
  458. * Compress HTTP output
  459. */
  460. //define(\'MINIFY_ENCODE\',1);
  461. /*
  462. * Apply sources minifying algorithms.
  463. *
  464. * If enabled CPU usage may raise, but amount
  465. * of transferred data is smaller.
  466. */
  467. //define(\'MINIFY_SOURCES\',0);
  468. /*
  469. * Show donation links in EPESI
  470. */
  471. //define(\'SUGGEST_DONATION\',1);
  472. /*
  473. * automatically check for new version
  474. */
  475. //define(\'CHECK_VERSION\',1);
  476. /*
  477. * Disable some administrator preferences.
  478. */
  479. //define(\'DEMO_MODE\',0);
  480. define(\'FILE_SESSION_DIR\',\''.str_replace('\\', '/', sys_get_temp_dir()).'\');
  481. define(\'INSTALLATION_ID\',\''.md5(__FILE__ . strval(microtime(true))).'\');
  482. '.$other_conf.'
  483. ?>');
  484. fclose($c);
  485. ob_start();
  486. ob_start('rm_config');
  487. //fill database
  488. clean_database();
  489. install_base();
  490. ob_end_flush();
  491. if(file_exists(DATA_DIR.'/config.php'))
  492. header("Location: setup.php?install_lang={$install_lang_load}&check=1");
  493. ob_end_flush();
  494. }
  495. //////////////////////////////////////////////
  496. function rm_config($x) {
  497. if($x) {
  498. unlink(dirname(__FILE__).'/'.DATA_DIR.'/config.php');
  499. clean_database();
  500. }
  501. return $x;
  502. }
  503. function clean_database() {
  504. require_once('include/config.php');
  505. require_once('include/database.php');
  506. $tables_db = DB::MetaTables();
  507. $tables = array();
  508. if(DB::is_mysql())
  509. DB::Execute('SET FOREIGN_KEY_CHECKS=0');
  510. if(DB::is_postgresql() && strpos(DB::GetOne('SELECT version()'),'PostgreSQL 8.2')!==false) {
  511. foreach ($tables_db as $t) {
  512. $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');
  513. $matches = array(1=>array());
  514. while ($i = $idxs->FetchRow()) {
  515. $data = explode(chr(0), $i[0]);
  516. $matches[1][] = $data[0];
  517. }
  518. $num_keys = count($matches[1]);
  519. for ( $i = 0; $i < $num_keys; $i ++ )
  520. DB::Execute('ALTER TABLE '.$t.' DROP CONSTRAINT '.$matches[1][$i]);
  521. }
  522. }
  523. foreach($tables_db as $t) {
  524. DB::DropTable($t);
  525. }
  526. if(DB::is_mysql())
  527. DB::Execute('SET FOREIGN_KEY_CHECKS=1');
  528. }
  529. function install_base() {
  530. require_once('include/config.php');
  531. require_once('include/database.php');
  532. @DB::Execute('ALTER DATABASE `'.DATABASE_NAME.'` CHARACTER SET utf8 COLLATE utf8_unicode_ci');
  533. $ret = DB::CreateTable('modules',"name C(128) KEY,version I NOTNULL, priority I NOTNULL DEFAULT 0, state I NOTNULL DEFAULT 0");
  534. if($ret===false)
  535. die('Invalid SQL query - Setup module (modules table)');
  536. $ret = DB::CreateTable('cron',"func C(32) KEY,last I NOTNULL, running I1 NOTNULL DEFAULT 0, description C(255)");
  537. if($ret===false)
  538. die('Invalid SQL query - Setup cron (cron table)');
  539. $ret = DB::CreateTable('session',"name C(128) NOTNULL," .
  540. "expires I NOTNULL DEFAULT 0, data B",array('constraints'=>', PRIMARY KEY(name)'));
  541. if($ret===false)
  542. die('Invalid SQL query - Database module (session table)');
  543. $ret = DB::CreateTable('session_client',"session_name C(128) NOTNULL, client_id I2," .
  544. "data B",array('constraints'=>', FOREIGN KEY(session_name) REFERENCES session(name), PRIMARY KEY(client_id,session_name)'));
  545. if($ret===false)
  546. die('Invalid SQL query - Database module (session_client table)');
  547. $ret = DB::CreateTable('history',"session_name C(128) NOTNULL, page_id I, client_id I2," .
  548. "data B",array('constraints'=>', FOREIGN KEY(session_name) REFERENCES session(name), PRIMARY KEY(client_id,session_name,page_id)'));
  549. if($ret===false)
  550. die('Invalid SQL query - Database module (history table)');
  551. DB::CreateIndex('history__session_name__client_id__idx', 'history', 'session_name, client_id');
  552. $ret = DB::CreateTable('variables',"name C(128) KEY,value X");
  553. if($ret===false)
  554. die('Invalid SQL query - Database module (variables table)');
  555. $ret = DB::Execute("insert into variables values('default_module',%s)",array(serialize('FirstRun')));
  556. if($ret === false)
  557. die('Invalid SQL query - Setup module (populating variables)');
  558. $ret = DB::Execute("insert into variables values('version',%s)",array(serialize(EPESI_VERSION)));
  559. if($ret === false)
  560. die('Invalid SQL query - Setup module (populating variables)');
  561. }
  562. //////////////////////////////////////////////
  563. function read_doc_file($file_basename, $suffix = 'html') {
  564. global $install_lang_load;
  565. $dir = 'docs/';
  566. $file = $dir . $file_basename . '.' . $suffix; // default file
  567. $custom_file = $dir . "{$file_basename}_{$install_lang_load}.{$suffix}";
  568. if (file_exists($custom_file))
  569. $file = $custom_file;
  570. $fp = @fopen($file, 'r');
  571. if ($fp) {
  572. $content = fread($fp, filesize($file));
  573. }
  574. fclose($fp);
  575. return $content;
  576. }
  577. ob_end_flush();
  578. ?>