PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/oc-includes/osclass/install-functions.php

https://code.google.com/
PHP | 923 lines | 743 code | 80 blank | 100 comment | 53 complexity | 11177d6f8dc3153134af646796cabde5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * OSCLass â&#x20AC;&#x201C; software for creating and publishing online classified
  4. * advertising platforms
  5. *
  6. * Copyright (C) 2010 OSCLASS
  7. *
  8. * This program is free software: you can redistribute it and/or
  9. * modify it under the terms of the GNU Affero General Public License
  10. * as published by the Free Software Foundation, either version 3 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /*
  22. * The url of the site
  23. *
  24. * @since 1.2
  25. *
  26. * @return string The url of the site
  27. */
  28. function get_absolute_url( ) {
  29. $protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http' ;
  30. $pos = strpos($_SERVER['REQUEST_URI'], 'oc-includes') ;
  31. $URI = rtrim( substr( $_SERVER['REQUEST_URI'], 0, $pos ), '/' ) . '/' ;
  32. return $protocol . '://' . $_SERVER['HTTP_HOST'] . $URI ;
  33. }
  34. /*
  35. * The relative url on the domain url
  36. *
  37. * @since 1.2
  38. *
  39. * @return string The relative url on the domain url
  40. */
  41. function get_relative_url( ) {
  42. $url = $_SERVER['REQUEST_URI'];
  43. return substr($url, 0, strpos($url, '/oc-includes')) . "/";
  44. }
  45. /*
  46. * Get the requirements to install OSClass
  47. *
  48. * @since 1.2
  49. *
  50. * @return array Requirements
  51. */
  52. function get_requirements( ) {
  53. $array = array(
  54. 'PHP version >= 5.x' => array(
  55. 'requirement' => __('PHP version >= 5.x'),
  56. 'fn' => version_compare(PHP_VERSION, '5.0.0', '>='),
  57. 'solution' => __('PHP5 is required to run OSClass. You may talk with your hosting to upgrade your PHP version.')),
  58. 'MySQLi extension for PHP' => array(
  59. 'requirement' => __('MySQLi extension for PHP'),
  60. 'fn' => extension_loaded('mysqli'),
  61. 'solution' => __('MySQLi extension is required. How to <a target="_blank" href="http://www.php.net/manual/en/mysqli.setup.php">install/configure</a>.')),
  62. 'GD extension for PHP' => array(
  63. 'requirement' => __('GD extension for PHP'),
  64. 'fn' => extension_loaded('gd'),
  65. 'solution' => __('GD extension is required. How to <a target="_blank" href="http://www.php.net/manual/en/image.setup.php">install/configure</a>.')),
  66. 'Folder <code>oc-content/uploads</code> exists' => array(
  67. 'requirement' => __('Folder <code>oc-content/uploads</code> exists'),
  68. 'fn' => file_exists( ABS_PATH . 'oc-content/uploads/' ),
  69. 'solution' => sprintf(__('You have to create <code>uploads</code> folder, i.e.: <code>mkdir %soc-content/uploads/</code>' ), ABS_PATH)),
  70. 'Folder <code>oc-content/uploads</code> is writable' => array(
  71. 'requirement' => __('<code>oc-content/uploads</code> folder is writable'),
  72. 'fn' => is_writable( ABS_PATH . 'oc-content/uploads/' ),
  73. 'solution' => sprintf(__('<code>uploads</code> folder has to be writable, i.e.: <code>chmod a+w %soc-content/uploads/</code>'), ABS_PATH)),
  74. 'Folder <code>oc-content/languages</code> exists' => array(
  75. 'requirement' => __('<code>oc-content/languages</code> folder exists'),
  76. 'fn' => file_exists( ABS_PATH . 'oc-content/languages/' ),
  77. 'solution' => sprintf(__('You have to create the <code>languages</code> folder, i.e.: <code>mkdir %soc-content/languages/</code>'), ABS_PATH))
  78. );
  79. $config_writable = false;
  80. $root_writable = false;
  81. $config_sample = false;
  82. if( file_exists(ABS_PATH . 'config.php') ) {
  83. if( is_writable(ABS_PATH . 'config.php') ) {
  84. $config_writable = true;
  85. }
  86. $array['File <code>config.php</code> is writable'] = array(
  87. 'requirement' => __('<code>config.php</code> file is writable'),
  88. 'fn' => $config_writable,
  89. 'solution' => sprintf(__('<code>config.php</code> file has to be writable, i.e.: <code>chmod a+w %sconfig.php</code>'), ABS_PATH));
  90. } else {
  91. if (is_writable(ABS_PATH) ) {
  92. $root_writable = true;
  93. }
  94. $array['Root directory is writable'] = array(
  95. 'requirement' => __('Root directory is writable'),
  96. 'fn' => $root_writable,
  97. 'solution' => sprintf(__('Root folder has to be writable, i.e.: <code>chmod a+w %s</code>'), ABS_PATH));
  98. if( file_exists(ABS_PATH . 'config-sample.php') ) {
  99. $config_sample = true;
  100. }
  101. $array['File <code>config-sample.php</code> exists'] = array(
  102. 'requirement' => __('<code>config-sample.php</code> file exists'),
  103. 'fn' => $config_sample,
  104. 'solution' => __('<code>config-sample.php</code> file is required, you should re-download OSClass.'));
  105. }
  106. return $array;
  107. }
  108. /**
  109. * Check if some of the requirements to install OSClass are correct or not
  110. *
  111. * @since 1.2
  112. *
  113. * @return boolean Check if all the requirements are correct
  114. */
  115. function check_requirements($array) {
  116. foreach($array as $k => $v) {
  117. if( !$v['fn'] ) return true;
  118. }
  119. return false;
  120. }
  121. /**
  122. * Check if allowed to send stats to Osclass
  123. *
  124. * @return boolean Check if allowed to send stats to Osclass
  125. */
  126. function reportToOsclass() {
  127. return $_COOKIE['osclass_save_stats'] ;
  128. }
  129. /**
  130. * insert/update preference allow_report_osclass
  131. * @param boolean $bool
  132. */
  133. function set_allow_report_osclass($value) {
  134. $values = array(
  135. 's_section' => 'osclass',
  136. 's_name' => 'allow_report_osclass',
  137. 's_value' => $value,
  138. 'e_type' => 'BOOLEAN'
  139. ) ;
  140. Preference::newInstance()->insert($values) ;
  141. }
  142. /*
  143. * Install OSClass database
  144. *
  145. * @since 1.2
  146. *
  147. * @return mixed Error messages of the installation
  148. */
  149. function oc_install( ) {
  150. $dbhost = Params::getParam('dbhost') ;
  151. $dbname = Params::getParam('dbname') ;
  152. $username = Params::getParam('username') ;
  153. $password = Params::getParam('password', false, false) ;
  154. $tableprefix = Params::getParam('tableprefix') ;
  155. $createdb = false ;
  156. if( $tableprefix == '' ) {
  157. $tableprefix = 'oc_' ;
  158. }
  159. if( Params::getParam('createdb') != '' ) {
  160. $createdb = true ;
  161. }
  162. if ( $createdb ) {
  163. $adminuser = Params::getParam('admin_username') ;
  164. $adminpwd = Params::getParam('admin_password', false, false) ;
  165. $master_conn = new DBConnectionClass($dbhost, $adminuser, $adminpwd, '') ;
  166. $error_num = $master_conn->getErrorConnectionLevel() ;
  167. if( $error_num > 0 ) {
  168. if( reportToOsclass() ) {
  169. LogOsclassInstaller::instance()->error(sprintf(__('Cannot connect to the database. Error number: %s') , $error_num ), __FILE__."::".__LINE__) ;
  170. }
  171. switch ($error_num) {
  172. case 1049: return array('error' => __("The database doesn't exist. You should check the \"Create DB\" checkbox and fill in a username and password with the right privileges")) ;
  173. break;
  174. case 1045: return array('error' => __('Cannot connect to the database. Check if the user has privileges.')) ;
  175. break;
  176. case 1044: return array('error' => __('Cannot connect to the database. Check if the username and password are correct.')) ;
  177. break;
  178. case 2005: return array('error' => __("Can't resolve MySQL host. Check if the host is correct.")) ;
  179. break;
  180. default: return array('error' => sprintf(__('Cannot connect to the database. Error number: %s')), $error_num) ;
  181. break;
  182. }
  183. }
  184. $m_db = $master_conn->getOsclassDb() ;
  185. $comm = new DBCommandClass( $m_db ) ;
  186. $comm->query( sprintf("CREATE DATABASE IF NOT EXISTS %s DEFAULT CHARACTER SET 'UTF8' COLLATE 'UTF8_GENERAL_CI'", $dbname) ) ;
  187. $error_num = $comm->getErrorLevel() ;
  188. if( $error_num > 0 ) {
  189. if( reportToOsclass() ) {
  190. LogOsclassInstaller::instance()->error(sprintf(__("Can't create the database. Error number: %s"), $error_num) , __FILE__."::".__LINE__) ;
  191. }
  192. if( in_array( $error_num, array(1006, 1044, 1045) ) ) {
  193. return array('error' => __("Can't create the database. Check if the admin username and password are correct.")) ;
  194. }
  195. return array('error' => sprintf(__("Can't create the database. Error number: %s"), $error_num)) ;
  196. }
  197. unset($conn) ;
  198. unset($comm) ;
  199. unset($master_conn) ;
  200. }
  201. $conn = new DBConnectionClass($dbhost, $username, $password, $dbname) ;
  202. $error_num = $conn->getErrorConnectionLevel() ;
  203. if( $error_num == 0 ) {
  204. $error_num = $conn->getErrorLevel() ;
  205. }
  206. if( $error_num > 0 ) {
  207. if( reportToOsclass() ) {
  208. LogOsclassInstaller::instance()->error(sprintf(__('Cannot connect to the database. Error number: %s'), $error_num) , __FILE__."::".__LINE__) ;
  209. }
  210. switch( $error_num ) {
  211. case 1049: return array('error' => __("The database doesn't exist. You should check the \"Create DB\" checkbox and fill in a username and password with the right privileges")) ;
  212. break ;
  213. case 1045: return array('error' => __('Cannot connect to the database. Check if the user has privileges.')) ;
  214. break ;
  215. case 1044: return array('error' => __('Cannot connect to the database. Check if the username and password are correct.')) ;
  216. break ;
  217. case 2005: return array('error' => __("Can't resolve MySQL host. Check if the host is correct.")) ;
  218. break ;
  219. default: return array('error' => sprintf(__('Cannot connect to the database. Error number: %s'), $error_num)) ;
  220. break ;
  221. }
  222. }
  223. if( file_exists(ABS_PATH . 'config.php') ) {
  224. if( !is_writable(ABS_PATH . 'config.php') ) {
  225. if( reportToOsclass() ) {
  226. LogOsclassInstaller::instance()->error(__("Can't write in config.php file. Check if the file is writable.") , __FILE__."::".__LINE__) ;
  227. }
  228. return array('error' => __("Can't write in config.php file. Check if the file is writable."));
  229. }
  230. create_config_file($dbname, $username, $password, $dbhost, $tableprefix);
  231. } else {
  232. if( !file_exists(ABS_PATH . 'config-sample.php') ) {
  233. if( reportToOsclass() ) {
  234. LogOsclassInstaller::instance()->error(__("config-sample.php doesn't exist. Check if everything is decompressed correctly.") , __FILE__."::".__LINE__) ;
  235. }
  236. return array('error' => __("config-sample.php doesn't exist. Check if everything is decompressed correctly."));
  237. }
  238. if( !is_writable(ABS_PATH) ) {
  239. if( reportToOsclass() ) {
  240. LogOsclassInstaller::instance()->error(__('Can\'t copy config-sample.php. Check if the root directory is writable.') , __FILE__."::".__LINE__) ;
  241. }
  242. return array('error' => __('Can\'t copy config-sample.php. Check if the root directory is writable.'));
  243. }
  244. copy_config_file($dbname, $username, $password, $dbhost, $tableprefix);
  245. }
  246. require_once ABS_PATH . 'config.php';
  247. $sql = file_get_contents( ABS_PATH . 'oc-includes/osclass/installer/struct.sql' ) ;
  248. $c_db = $conn->getOsclassDb() ;
  249. $comm = new DBCommandClass( $c_db ) ;
  250. $comm->importSQL($sql) ;
  251. $error_num = $comm->getErrorLevel() ;
  252. if( $error_num > 0 ) {
  253. if( reportToOsclass() ) {
  254. LogOsclassInstaller::instance()->error(sprintf(__("Can't create the database structure. Error number: %s"), $error_num) , __FILE__."::".__LINE__) ;
  255. }
  256. switch ($error_num) {
  257. case 1050: return array('error' => __('There are tables with the same name in the database. Change the table prefix or the database and try again.')) ;
  258. break;
  259. default: return array('error' => sprintf(__("Can't create the database structure. Error number: %s"), $error_num)) ;
  260. break;
  261. }
  262. }
  263. require_once LIB_PATH . 'osclass/model/OSCLocale.php';
  264. $localeManager = OSCLocale::newInstance();
  265. $locales = osc_listLocales() ;
  266. $values = array(
  267. 'pk_c_code' => $locales[osc_current_admin_locale()]['code'],
  268. 's_name' => $locales[osc_current_admin_locale()]['name'],
  269. 's_short_name' => $locales[osc_current_admin_locale()]['short_name'],
  270. 's_description' => $locales[osc_current_admin_locale()]['description'],
  271. 's_version' => $locales[osc_current_admin_locale()]['version'],
  272. 's_author_name' => $locales[osc_current_admin_locale()]['author_name'],
  273. 's_author_url' => $locales[osc_current_admin_locale()]['author_url'],
  274. 's_currency_format' => $locales[osc_current_admin_locale()]['currency_format'],
  275. 's_date_format' => $locales[osc_current_admin_locale()]['date_format'],
  276. 'b_enabled' => 1,
  277. 'b_enabled_bo' => 1
  278. ) ;
  279. if( isset($locales[osc_current_admin_locale()]['stop_words']) ) {
  280. $values['s_stop_words'] = $locales[osc_current_admin_locale()]['stop_words'] ;
  281. }
  282. $localeManager->insert($values) ;
  283. $required_files = array(
  284. ABS_PATH . 'oc-includes/osclass/installer/basic_data.sql',
  285. ABS_PATH . 'oc-includes/osclass/installer/pages.sql',
  286. ABS_PATH . 'oc-content/languages/' . osc_current_admin_locale() . '/mail.sql',
  287. );
  288. $sql = '';
  289. foreach($required_files as $file) {
  290. if ( !file_exists($file) ) {
  291. if( reportToOsclass() ) {
  292. LogOsclassInstaller::instance()->error(sprintf(__('The file %s doesn\'t exist'), $file) , __FILE__."::".__LINE__) ;
  293. }
  294. return array('error' => sprintf(__('The file %s doesn\'t exist'), $file) );
  295. } else {
  296. $sql .= file_get_contents($file);
  297. }
  298. }
  299. $comm->importSQL($sql) ;
  300. $error_num = $comm->getErrorLevel() ;
  301. if( $error_num > 0 ) {
  302. if( reportToOsclass() ) {
  303. LogOsclassInstaller::instance()->error(sprintf(__("Can't insert basic configuration. Error number: %s"), $error_num) , __FILE__."::".__LINE__) ;
  304. }
  305. switch ($error_num) {
  306. case 1471: return array('error' => __("Can't insert basic configuration. This user has no privileges to 'INSERT' into the database."));
  307. break;
  308. default: return array('error' => sprintf(__("Can't insert basic configuration. Error number: %s"), $error_num));
  309. break;
  310. }
  311. }
  312. osc_set_preference('language', osc_current_admin_locale());
  313. osc_set_preference('admin_language', osc_current_admin_locale());
  314. oc_install_example_data();
  315. if( reportToOsclass() ) {
  316. set_allow_report_osclass( true ) ;
  317. } else {
  318. set_allow_report_osclass( false ) ;
  319. }
  320. return false ;
  321. }
  322. /*
  323. * Insert the example data (categories and emails) on all available locales
  324. *
  325. * @since 2.4
  326. *
  327. * @return mixed Error messages of the installation
  328. */
  329. function oc_install_example_data() {
  330. require_once LIB_PATH . 'osclass/formatting.php';
  331. require LIB_PATH . 'osclass/installer/categories.php';
  332. require_once LIB_PATH . 'osclass/model/Category.php';
  333. $mCat = Category::newInstance();
  334. if(!function_exists('osc_apply_filter')) {
  335. function osc_apply_filter($dummyfilter, $str) {
  336. return $str;
  337. }
  338. }
  339. foreach($categories as $category) {
  340. $fields['pk_i_id'] = $category['pk_i_id'];
  341. $fields['fk_i_parent_id'] = $category['fk_i_parent_id'];
  342. $fields['i_position'] = $category['i_position'];
  343. $fields['i_expiration_days'] = 0;
  344. $fields['b_enabled'] = 0;
  345. $aFieldsDescription[osc_current_admin_locale()]['s_name'] = $category['s_name'];
  346. $mCat->insert($fields, $aFieldsDescription);
  347. }
  348. }
  349. /*
  350. * Create config file from scratch
  351. *
  352. * @since 1.2
  353. *
  354. * @param string $dbname Database name
  355. * @param string $username User of the database
  356. * @param string $password Password for user of the database
  357. * @param string $dbhost Database host
  358. * @param string $tableprefix Prefix for table names
  359. * @return mixed Error messages of the installation
  360. */
  361. function create_config_file($dbname, $username, $password, $dbhost, $tableprefix) {
  362. $password = addslashes($password);
  363. $abs_url = get_absolute_url();
  364. $rel_url = get_relative_url();
  365. $config_text = <<<CONFIG
  366. <?php
  367. /**
  368. * The base MySQL settings of OSClass
  369. */
  370. define('MULTISITE', 0);
  371. /** MySQL database name for OSClass */
  372. define('DB_NAME', '$dbname');
  373. /** MySQL database username */
  374. define('DB_USER', '$username');
  375. /** MySQL database password */
  376. define('DB_PASSWORD', '$password');
  377. /** MySQL hostname */
  378. define('DB_HOST', '$dbhost');
  379. /** Database Table prefix */
  380. define('DB_TABLE_PREFIX', '$tableprefix');
  381. define('REL_WEB_URL', '$rel_url');
  382. define('WEB_PATH', '$abs_url');
  383. CONFIG;
  384. file_put_contents(ABS_PATH . 'config.php', $config_text);
  385. }
  386. /*
  387. * Create config from config-sample.php file
  388. *
  389. * @since 1.2
  390. */
  391. function copy_config_file($dbname, $username, $password, $dbhost, $tableprefix) {
  392. $password = addslashes($password);
  393. $abs_url = get_absolute_url();
  394. $rel_url = get_relative_url();
  395. $config_sample = file(ABS_PATH . 'config-sample.php');
  396. foreach ($config_sample as $line_num => $line) {
  397. switch (substr($line, 0, 16)) {
  398. case "define('DB_NAME'":
  399. $config_sample[$line_num] = str_replace("database_name", $dbname, $line);
  400. break;
  401. case "define('DB_USER'":
  402. $config_sample[$line_num] = str_replace("'username'", "'$username'", $line);
  403. break;
  404. case "define('DB_PASSW":
  405. $config_sample[$line_num] = str_replace("'password'", "'$password'", $line);
  406. break;
  407. case "define('DB_HOST'":
  408. $config_sample[$line_num] = str_replace("localhost", $dbhost, $line);
  409. break;
  410. case "define('DB_TABLE":
  411. $config_sample[$line_num] = str_replace('oc_', $tableprefix, $line);
  412. break;
  413. case "define('REL_WEB_":
  414. $config_sample[$line_num] = str_replace('rel_here', $rel_url, $line);
  415. break;
  416. case "define('WEB_PATH":
  417. $config_sample[$line_num] = str_replace('http://localhost', $abs_url, $line);
  418. break;
  419. }
  420. }
  421. $handle = fopen(ABS_PATH . 'config.php', 'w');
  422. foreach( $config_sample as $line ) {
  423. fwrite($handle, $line);
  424. }
  425. fclose($handle);
  426. chmod(ABS_PATH . 'config.php', 0666);
  427. }
  428. function is_osclass_installed( ) {
  429. if( !file_exists( ABS_PATH . 'config.php' ) ) {
  430. return false ;
  431. }
  432. require_once ABS_PATH . 'config.php' ;
  433. $conn = new DBConnectionClass( osc_db_host(), osc_db_user(), osc_db_password(), osc_db_name() ) ;
  434. $c_db = $conn->getOsclassDb() ;
  435. $comm = new DBCommandClass( $c_db ) ;
  436. $rs = $comm->query( sprintf( "SELECT * FROM %st_preference WHERE s_name = 'osclass_installed'", DB_TABLE_PREFIX ) ) ;
  437. if( $rs == false ) {
  438. return false ;
  439. }
  440. if( $rs->numRows() != 1 ) {
  441. return false ;
  442. }
  443. return true ;
  444. }
  445. function finish_installation( $password ) {
  446. require_once LIB_PATH . 'osclass/model/Admin.php' ;
  447. require_once LIB_PATH . 'osclass/model/Category.php';
  448. require_once LIB_PATH . 'osclass/model/Item.php';
  449. require_once LIB_PATH . 'osclass/helpers/hPlugins.php';
  450. require_once LIB_PATH . 'osclass/compatibility.php';
  451. require_once LIB_PATH . 'osclass/plugins.php';
  452. $data = array();
  453. $mAdmin = new Admin() ;
  454. $mPreference = Preference::newInstance() ;
  455. $mPreference->insert (
  456. array(
  457. 's_section' => 'osclass'
  458. ,'s_name' => 'osclass_installed'
  459. ,'s_value' => '1'
  460. ,'e_type' => 'BOOLEAN'
  461. )
  462. );
  463. // update categories
  464. $mCategories = new Category();
  465. if(Params::getParam('submit') != '') {
  466. $categories = Params::getParam('categories');
  467. if(is_array($categories)) {
  468. foreach($categories as $category_id) {
  469. $mCategories->update(array('b_enabled' => '1')
  470. ,array('pk_i_id' => $category_id));
  471. }
  472. }
  473. }
  474. $aCategoriesToDelete = $mCategories->listWhere("a.b_enabled = 0");
  475. foreach($aCategoriesToDelete as $aCategory) {
  476. $mCategories->deleteByPrimaryKey($aCategory['pk_i_id']);
  477. }
  478. $admin = $mAdmin->findByPrimaryKey(1) ;
  479. $data['s_email'] = $admin['s_email'] ;
  480. $data['admin_user'] = $admin['s_username'] ;
  481. $data['password'] = $password;
  482. return $data ;
  483. }
  484. /* Menus */
  485. function display_database_config() {
  486. ?>
  487. <form action="install.php" method="post">
  488. <input type="hidden" name="step" value="3" />
  489. <h2 class="target"><?php _e('Database information'); ?></h2>
  490. <div class="form-table">
  491. <table>
  492. <tbody>
  493. <tr>
  494. <th align="left"><label for="dbhost"><?php _e('Host'); ?></label></th>
  495. <td><input type="text" id="dbhost" name="dbhost" value="localhost" size="25" /></td>
  496. <td class="small"><?php _e('Server name or IP where the database engine resides'); ?></td>
  497. </tr>
  498. <tr>
  499. <th align="left"><label for="dbname"><?php _e('Database name'); ?></label></th>
  500. <td><input type="text" id="dbname" name="dbname" value="osclass" size="25" /></td>
  501. <td class="small"><?php _e('The name of the database you want to run OSClass in'); ?></td>
  502. </tr>
  503. <tr>
  504. <th align="left"><label for="username"><?php _e('User Name'); ?></label></th>
  505. <td><input type="text" id="username" name="username" size="25" /></td>
  506. <td class="small"><?php _e('Your MySQL username'); ?></td>
  507. </tr>
  508. <tr>
  509. <th align="left"><label for="password"><?php _e('Password'); ?></label></th>
  510. <td><input type="password" id="password" name="password" value="" size="25" /></td>
  511. <td class="small"><?php _e('Your MySQL password'); ?></td>
  512. </tr>
  513. <tr>
  514. <th align="left"><label for="tableprefix"><?php _e('Table prefix'); ?></label></th>
  515. <td><input type="text" id="tableprefix" name="tableprefix" value="oc_" size="25" /></td>
  516. <td class="small"><?php _e('If you want to run multiple OSClass installations in a single database, change this'); ?></td>
  517. </tr>
  518. </tbody>
  519. </table>
  520. <div id="advanced_install" class="shrink">
  521. <div class="text">
  522. <span><?php _e('Advanced'); ?></span>
  523. </div>
  524. </div>
  525. <script type="text/javascript">
  526. $(document).ready(function() {
  527. $('#advanced_install').click(function() {
  528. $('#more-options').toggle();
  529. if( $('#advanced_install').attr('class') == 'shrink' ) {
  530. $('#advanced_install').removeClass('shrink');
  531. $('#advanced_install').addClass('expanded');
  532. } else {
  533. $('#advanced_install').addClass('shrink');
  534. $('#advanced_install').removeClass('expanded');
  535. }
  536. });
  537. });
  538. </script>
  539. <div style="clear:both;"></div>
  540. <table id="more-options" style="display:none;">
  541. <tbody>
  542. <tr>
  543. <th></th>
  544. <td><input type="checkbox" id="createdb" name="createdb" onclick="db_admin();" value="1" /><label for="createdb"><?php _e('Create DB'); ?></label></td>
  545. <td class="small"><?php _e('Check here if the database is not created and you want to create it now'); ?></td>
  546. </tr>
  547. <tr id="admin_username_row">
  548. <th align="left"><label for="admin_username"><?php _e('DB admin username'); ?></label></th>
  549. <td><input type="text" id="admin_username" name="admin_username" size="25" disabled="disabled" /></td>
  550. <td></td>
  551. </tr>
  552. <tr id="admin_password_row">
  553. <th align="left"><label for="admin_password"><?php _e('DB admin password'); ?></label></th>
  554. <td><input type="password" id="admin_password" name="admin_password" value="" size="25" disabled="disabled" /></td>
  555. <td></td>
  556. </tr>
  557. </tbody>
  558. </table>
  559. </div>
  560. <div class="clear"></div>
  561. <p class="margin20">
  562. <input type="submit" class="button" name="submit" value="Next" />
  563. </p>
  564. <div class="clear"></div>
  565. </form>
  566. <?php
  567. }
  568. function display_target() {
  569. ?>
  570. <form id="target_form" name="target_form" action="#" method="post" onsubmit="return false;">
  571. <h2 class="target"><?php _e('Information needed'); ?></h2>
  572. <div class="form-table">
  573. <h2 class="title"><?php _e('Admin user'); ?></h2>
  574. <table class="admin-user">
  575. <tbody>
  576. <tr>
  577. <th><label><?php _e('Username'); ?></label></th>
  578. <td>
  579. <input size="25" id="admin_user" name="s_name" type="text" value="admin" />
  580. </td>
  581. <td><span id="admin-user-error" class="error" style="display:none;"><?php _e('Admin user is required'); ?></span></td>
  582. </tr>
  583. <tr>
  584. <th><label><?php _e('Password'); ?></label></th>
  585. <td>
  586. <input size="25" class="password_test" name="s_passwd" type="text" value="" />
  587. </td>
  588. <td></td>
  589. </tr>
  590. </tbody>
  591. </table>
  592. <div class="admin-user">
  593. <?php _e('A password will be automatically generated for you if you leave this blank.'); ?>
  594. <img src="<?php echo get_absolute_url() ?>oc-includes/images/question.png" class="question-skip vtip" title="<?php _e('You can modify username and password if you like, just change the input value.'); ?>" alt="" />
  595. </div>
  596. <h2 class="title"><?php _e('Contact information'); ?></h2>
  597. <table class="contact-info">
  598. <tbody>
  599. <tr>
  600. <th><label for="webtitle"><?php _e('Web title'); ?></label></th>
  601. <td><input type="text" id="webtitle" name="webtitle" size="25" /></td>
  602. <td></td>
  603. </tr>
  604. <tr>
  605. <th><label for="email"><?php _e('Contact e-mail'); ?></label></th>
  606. <td><input type="text" id="email" name="email" size="25" /></td>
  607. <td><span id="email-error" class="error" style="display:none;"><?php _e('Put your e-mail here'); ?></span></td>
  608. </tr>
  609. </tbody>
  610. </table>
  611. <h2 class="title"><?php _e('Location'); ?></h2>
  612. <p class="space-left-25 left no-bottom"><?php _e('Choose countries/cities where your target users are located'); ?></p>
  613. <div id="location-question" class="left question">
  614. <img class="vtip" src="<?php echo get_absolute_url(); ?>oc-includes/images/question.png" title="<?php _e("Once you type a country, you'll be able to choose region and city as well. Therefore, the installation will be more specific."); ?>" alt="" />
  615. </div>
  616. <div class="clear"></div>
  617. <div id="location">
  618. <div id="country-box">
  619. <div id="radio-target" style="display: none;">
  620. <input id="icountry" type="radio" name="c_country" value="Country" checked onclick="change_to_country(this);" />
  621. <label for="icountry"><?php _e('Country'); ?></label>
  622. <input id="worlwide" type="radio" name="c_country" value="International" onclick="change_to_international(this);" />
  623. <label for="worlwide"><?php _e('Worldwide'); ?></label>
  624. </div>
  625. <div id="d_country" class="box">
  626. <input type="text" id="t_country" class="left" name="t_country" size="1" onkeydown="more_size(this, event);" />
  627. <div class="clear"></div>
  628. </div>
  629. <div id="a_country">
  630. </div>
  631. <p id="country-error" style="display:none;"><?php _e('Region/City targeting is only available when you choose only "one country"'); ?></p>
  632. </div>
  633. <div id="region-div" style="display:none;">
  634. <div id="region-info" class="space-left-10">
  635. <a href="javascript:void(0);" onclick="$('#region-box').attr('style', '');$('#region-info').attr('style', 'display:none');$('#t_location').focus();"><?php _e('Click here if you want to specify region/regions or city/cities'); ?></a>
  636. </div>
  637. <div id="region-box" class="space-left-60" style="display:none;">
  638. <div id="radio-target">
  639. <input id="iregion" type="radio" name="c_location" value="By region" onclick='$("#d_location span").remove();' checked="checked" />
  640. <label for="iregion"><?php _e('By Region'); ?></label>
  641. <input id="icity" type="radio" name="c_location" value="By City" onclick='$("#d_location span").remove();' />
  642. <label for="icity"><?php _e('By City'); ?></label>
  643. </div>
  644. <div id="d_location" class="box">
  645. <input type="text" id="t_location" name="t_location" size="1" onkeydown="more_size(this);" />
  646. </div>
  647. <div id="a_location">
  648. </div>
  649. </div>
  650. </div>
  651. <div style="display: none;" id="location-error">
  652. <?php _e('No internet connection. You can continue the installation and insert countries later.'); ?>
  653. <input type="hidden" id="skip-location-h" name="skip-location-h" value="0" />
  654. </div>
  655. </div>
  656. </div>
  657. <div class="clear"></div>
  658. <p class="margin20">
  659. <a href="#" class="button" onclick="validate_form();">Next</a>
  660. </p>
  661. <div id="skip-location-d" style="display:none;">
  662. <label for="skip-location" style="padding-left: 12px;"><input id="skip-location" name="skip-location" type="checkbox" /><?php _e('Continue installation process and insert countries later'); ?></label>
  663. </div>
  664. <div class="clear"></div>
  665. </form>
  666. <div id="lightbox" style="display:none;">
  667. <div class="center">
  668. <img src="<?php echo get_absolute_url(); ?>oc-includes/images/loading.gif" alt="" title="" />
  669. </div>
  670. </div>
  671. <?php
  672. }
  673. function display_database_error($error ,$step) {
  674. ?>
  675. <h2 class="target"><?php _e('Error'); ?></h2>
  676. <p class="bottom space-left-10">
  677. <?php echo $error['error']?>
  678. </p>
  679. <a href="<?php echo get_absolute_url(); ?>oc-includes/osclass/install.php?step=<?php echo $step; ?>" class="button"><?php _e('Go back'); ?></a>
  680. <div class="clear bottom"></div>
  681. <?php
  682. }
  683. function display_categories($error, $password) {
  684. require_once ABS_PATH . 'config.php';
  685. require_once LIB_PATH . 'osclass/model/Category.php';
  686. $categories = Category::newInstance()->toTreeAll();
  687. $numCols = 3;
  688. $catsPerCol = ceil(count($categories)/$numCols) ;
  689. ?>
  690. <?php if($error) { ?>
  691. <h2 class="target"><?php _e('Error'); ?></h2>
  692. <p class="bottom space-left-10">
  693. <?php echo $error;?>
  694. </p>
  695. <?php } ?>
  696. <form id="category_form" action="install.php?step=5" method="post">
  697. <input type="hidden" name="password" value="<?php echo osc_esc_html( $password ) ; ?>" />
  698. <h2 class="target"><?php _e('Categories'); ?></h2>
  699. <div class="form-table">
  700. <?php if(Params::getParam('error_location') == 1) { ?>
  701. <script type="text/javascript">
  702. setTimeout (function(){
  703. $('.error-location').fadeOut('slow');
  704. }, 2500);
  705. </script>
  706. <div class="error-location">
  707. <?php _e('The selected location could not been installed'); ?>
  708. </div>
  709. <?php } ?>
  710. <div class="select-categories">
  711. &nbsp;
  712. <div class="right">
  713. <a href="#" onclick="check_all('category_form', true); return false;">Check all</a>
  714. Â?
  715. <a href="#" onclick="check_all('category_form', false); return false;">Uncheck all</a>
  716. </div>
  717. <div class="left">
  718. <h3><?php _e('Select your classified categories');?> <span style="font-size:11px;"><?php _e('or');?></span> <a href="install.php?step=5"><?php _e('Skip');?></a><img src="<?php echo get_absolute_url() ?>oc-includes/images/question.png" class="question-skip vtip" title="<?php _e('You can add/remove categories after the installation, using the admin dashboard');?>" alt="" /></h3>
  719. </div>
  720. </div>
  721. <table class="list-categories">
  722. <tr>
  723. <?php for ($j = 0 ; $j < $numCols ; $j++) {?>
  724. <td>
  725. <?php for ($i = $catsPerCol*$j ; $i < $catsPerCol*($j+1) ; $i++) {?>
  726. <?php if (isset($categories[$i]) && is_array($categories[$i])) {?>
  727. <div class="cat-title">
  728. <label for="category-<?php echo $categories[$i]['pk_i_id']?>">
  729. <input id="category-<?php echo $categories[$i]['pk_i_id']?>" class="left" type="checkbox" name="categories[]" value="<?php echo $categories[$i]['pk_i_id']?>" onclick="javascript:check_cat('<?php echo $categories[$i]['pk_i_id']?>', this.checked);" checked />
  730. <span><?php echo $categories[$i]['s_name']?></span>
  731. </label>
  732. </div>
  733. <div id="cat<?php echo $categories[$i]['pk_i_id'];?>" class="sub-cat-title">
  734. <?php foreach($categories[$i]['categories'] as $sc) { ?>
  735. <div id="category" class="space">
  736. <label for="category-<?php echo $sc['pk_i_id']?>" class="space">
  737. <input id="category-<?php echo $sc['pk_i_id']?>" type="checkbox" name="categories[]" value="<?php echo $sc['pk_i_id']?>" onclick="javascript:check('category-<?php echo $categories[$i]['pk_i_id']?>')" checked />
  738. <?php echo $sc['s_name']; ?>
  739. </label>
  740. </div>
  741. <?php } ?>
  742. </div>
  743. <?php } ?>
  744. <?php } ?>
  745. </td>
  746. <?php } ?>
  747. </tr>
  748. </table>
  749. </div>
  750. <div class="clear"></div>
  751. <p class="margin20">
  752. <input type="submit" class="button" name="submit" value="Next" />
  753. </p>
  754. <div class="clear"></div>
  755. </form>
  756. <?php
  757. }
  758. function ping_search_engines($bool){
  759. $mPreference = Preference::newInstance() ;
  760. if($bool == 1){
  761. $mPreference->insert (
  762. array(
  763. 's_section' => 'osclass'
  764. ,'s_name' => 'ping_search_engines'
  765. ,'s_value' => '1'
  766. ,'e_type' => 'BOOLEAN'
  767. )
  768. ) ;
  769. // GOOGLE
  770. osc_doRequest( 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.urlencode(osc_search_url(array('sFeed' => 'rss') )), array());
  771. // BING
  772. osc_doRequest( 'http://www.bing.com/webmaster/ping.aspx?siteMap='.urlencode( osc_search_url(array('sFeed' => 'rss') ) ), array());
  773. // YAHOO!
  774. osc_doRequest( 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap='.urlencode( osc_search_url(array('sFeed' => 'rss') ) ), array());
  775. } else {
  776. $mPreference->insert (
  777. array(
  778. 's_section' => 'osclass'
  779. ,'s_name' => 'ping_search_engines'
  780. ,'s_value' => '0'
  781. ,'e_type' => 'BOOLEAN'
  782. )
  783. ) ;
  784. }
  785. }
  786. function display_finish($password) {
  787. $data = finish_installation( $password );
  788. ?>
  789. <h2 class="target"><?php _e('Congratulations!');?></h2>
  790. <p class="space-left-10"><?php _e("OSClass has been installed. Were you expecting more steps? Sorry to disappoint!");?></p>
  791. <p class="space-left-10"><?php echo sprintf(__('An e-mail with the password for oc-admin has been sent to: %s'), $data['s_email']);?></p>
  792. <div style="clear:both;"></div>
  793. <div class="form-table finish">
  794. <table>
  795. <tbody>
  796. <tr>
  797. <th><label><?php _e('Username');?></label></th>
  798. <td>
  799. <div class="s_name">
  800. <span style="float:left;" ><?php echo $data['admin_user']; ?></span>
  801. </div>
  802. </td>
  803. </tr>
  804. <tr>
  805. <th><label><?php _e('Password');?></label></th>
  806. <td>
  807. <div class="s_passwd">
  808. <span style="float: left;"><?php echo osc_esc_html($data['password']); ?></span>
  809. </div>
  810. </td>
  811. </tr>
  812. </tbody>
  813. </table>
  814. </div>
  815. <p class="margin20">
  816. <a target="_blank" href="<?php echo get_absolute_url() ?>oc-admin/index.php" class="button"><?php _e('Finish and go to the administration panel');?></a>
  817. </p>
  818. <?php
  819. }
  820. ?>