/installer/process.php

https://github.com/apurvgupta12/Ushahidi_Web · PHP · 310 lines · 207 code · 39 blank · 64 comment · 37 complexity · e27a80af5babb064520630e047e27400 MD5 · raw file

  1. <?php
  2. /**
  3. * simplify the task of processing form fields, redirecting to the pages.
  4. *
  5. * The Form class is meant to simplify the task of keeping
  6. * track of errors in user submitted forms and the form
  7. * field values that were entered correctly.
  8. *
  9. * PHP version 5
  10. * LICENSE: This source file is subject to LGPL license
  11. * that is available through the world-wide-web at the following URI:
  12. * http://www.gnu.org/copyleft/lesser.html
  13. * @author Ushahidi Team <team@ushahidi.com>
  14. * @package Ushahidi - http://source.ushahididev.com
  15. * @module Admin Dashboard Controller
  16. * @copyright Ushahidi - http://www.ushahidi.com
  17. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General
  18. * Public License (LGPL)
  19. */
  20. require_once("install.php");
  21. require_once("form.php");
  22. class Process
  23. {
  24. public function __construct()
  25. {
  26. $this->_index();
  27. }
  28. /**
  29. * Call up all the processors.
  30. */
  31. public function _index()
  32. {
  33. if(isset($_POST['basic_db_info'])) {
  34. $this->_proc_basic_db_info();
  35. }else if(isset($_POST['advanced_db_info'])){
  36. $this->_proc_advanced_db_info();
  37. }else if(isset($_POST['advanced_general_settings'])){
  38. $this->_proc_general_settings();
  39. }else if(isset($_POST['basic_general_settings'])){
  40. $this->_proc_basic_general_settings();
  41. }else if(isset($_POST['advanced_mail_server_settings'])){
  42. $this->_proc_mail_server();
  43. }else if(isset($_POST['advanced_map_config'])){
  44. $this->_proc_map();
  45. }else if(isset($_POST['advanced_perm_pre_check'])){
  46. $this->_proc_advanced_pre_perm_check();
  47. }else if(isset($_POST['basic_perm_pre_check'])){
  48. $this->_proc_basic_pre_perm_check();
  49. } else {
  50. header("Location:.");
  51. }
  52. }
  53. /**
  54. * Process basic database info.
  55. */
  56. public function _proc_basic_db_info()
  57. {
  58. global $form, $install;
  59. $status = $install->_install_db_info(
  60. $_POST['username'],
  61. $_POST['password'],
  62. $_POST['host'],
  63. 'mysql',
  64. $_POST['db_name'],
  65. $_POST['table_prefix'],
  66. $_POST['base_path']
  67. );
  68. //no errors
  69. if( $status == 0 ) {
  70. $_SESSION['basic_db_info'] = 'basic_general_settings';
  71. // send the database info to the next page for updating the settings table.
  72. $_SESSION['username'] = $_POST['username'];
  73. $_SESSION['password'] = $_POST['password'];
  74. $_SESSION['host'] = $_POST['host'];
  75. $_SESSION['db_name'] = $_POST['db_name'];
  76. $_SESSION['table_prefix'] = $_POST['table_prefix'];
  77. header("Location:basic_general_settings.php");
  78. }else if($status == 1 ) {
  79. $_SESSION['value_array'] = $_POST;
  80. $_SESSION['error_array'] = $form->get_error_array();
  81. header("Location:basic_db_info.php");
  82. }
  83. }
  84. /**
  85. * Process advanced database info.
  86. */
  87. public function _proc_advanced_db_info(){
  88. global $form, $install;
  89. $status = $install->_install_db_info(
  90. $_POST['username'],
  91. $_POST['password'],
  92. $_POST['host'],
  93. 'mysql',
  94. $_POST['db_name'],
  95. $_POST['table_prefix'],
  96. $_POST['base_path']
  97. );
  98. //no errors
  99. if( $status == 0 ) {
  100. // make sure users get to the general setting from advanced db info page.
  101. $_SESSION['general_settings'] = 'general_settings';
  102. // send the database info to the next page for updating the settings table.
  103. $_SESSION['username'] = $_POST['username'];
  104. $_SESSION['password'] = $_POST['password'];
  105. $_SESSION['host'] = $_POST['host'];
  106. $_SESSION['db_name'] = $_POST['db_name'];
  107. $_SESSION['table_prefix'] = $_POST['table_prefix'];
  108. header("Location:advanced_general_settings.php");
  109. }else if($status == 1 ) {
  110. $_SESSION['value_array'] = $_POST;
  111. $_SESSION['error_array'] = $form->get_error_array();
  112. header("Location:advanced_db_info.php");
  113. }
  114. }
  115. /**
  116. * Process the general settings.
  117. */
  118. public function _proc_general_settings() {
  119. global $form, $install;
  120. $status = $install->_general_settings(
  121. $_POST['site_name'],
  122. $_POST['site_tagline'],
  123. $_POST['select_language'],
  124. $_POST['site_email'],
  125. $_POST['table_prefix'],
  126. $_POST['enable_clean_url']
  127. );
  128. //no errors
  129. if( $status == 0 ) {
  130. // make sure users get to the general setting from advanced db info page.
  131. $_SESSION['mail_server'] = 'mail_server';
  132. // set it up in case someone wants to go to the previous page.
  133. $_SESSION['site_name'] = $_POST['site_name'];
  134. $_SESSION['site_tagline'] = $_POST['site_tagline'];
  135. $_SESSION['select_language'] = $_POST['select_language'];
  136. $_SESSION['site_email'] = $_POST['site_email'];
  137. $_SESSION['table_prefix'] = $_POST['table_prefix'];
  138. header("Location:advanced_mail_server_settings.php");
  139. }else if($status == 1 ) {
  140. $_SESSION['value_array'] = $_POST;
  141. $_SESSION['error_array'] = $form->get_error_array();
  142. header("Location:advanced_general_settings.php");
  143. }
  144. }
  145. /*
  146. * Process the general settings.
  147. */
  148. public function _proc_basic_general_settings() {
  149. global $form, $install;
  150. $status = $install->_general_settings(
  151. $_POST['site_name'],
  152. $_POST['site_tagline'],
  153. $_POST['select_language'],
  154. $_POST['site_email'],
  155. $_POST['table_prefix'],
  156. $_POST['enable_clean_url']
  157. );
  158. //no errors
  159. if( $status == 0 ) {
  160. // make sure users get to the general setting from advanced db info page.
  161. $_SESSION['basic_general_settings'] = 'basic_finished';
  162. // set it up in case someone want to goes the previous page.
  163. $_SESSION['site_name'] = $_POST['site_name'];
  164. $_SESSION['site_tagline'] = $_POST['site_tagline'];
  165. $_SESSION['select_language'] = $_POST['select_language'];
  166. $_SESSION['site_email'] = $_POST['site_email'];
  167. $_SESSION['table_prefix'] = $_POST['table_prefix'];
  168. header("Location:basic_finished.php");
  169. }else if($status == 1 ) {
  170. $_SESSION['value_array'] = $_POST;
  171. $_SESSION['error_array'] = $form->get_error_array();
  172. header("Location:basic_general_settings.php");
  173. }
  174. }
  175. /**
  176. * Process the mail server.
  177. */
  178. public function _proc_mail_server() {
  179. global $form, $install;
  180. $status = $install->_mail_server(
  181. $_POST['site_alert_email'],
  182. $_POST['mail_server_username'],
  183. $_POST['mail_server_pwd'],
  184. $_POST['mail_server_port'],
  185. $_POST['mail_server_host'],
  186. $_POST['select_mail_server_type'],
  187. $_POST['select_mail_server_ssl'],
  188. $_POST['table_prefix']
  189. );
  190. //no errors
  191. if( $status == 0 ) {
  192. // make sure users get to the general setting from advanced db info page.
  193. $_SESSION['map_settings'] = 'map_settings';
  194. // send the database info to the next page for updating the settings table.
  195. $_SESSION['site_alert_email'] = $_POST['site_alert_email'];
  196. $_SESSION['mail_server_username'] = $_POST['mail_server_username'];
  197. $_SESSION['mail_server_pwd'] = $_POST['mail_server_pwd'];
  198. $_SESSION['mail_server_port'] = $_POST['mail_server_port'];
  199. $_SESSION['mail_server_host'] = $_POST['mail_server_host'];
  200. $_SESSION['select_mail_server_type'] = $_POST['select_mail_server_type'];
  201. $_SESSION['select_mail_server_ssl'] = $_POST['select_mail_server_ssl'];
  202. $_SESSION['table_prefix'] = $_POST['table_prefix'];
  203. header("Location:advanced_map_configuration.php");
  204. }else if($status == 1 ) {
  205. $_SESSION['value_array'] = $_POST;
  206. $_SESSION['error_array'] = $form->get_error_array();
  207. header("Location:advanced_mail_server_settings.php");
  208. }
  209. }
  210. /**
  211. * Process the map details.
  212. */
  213. public function _proc_map() {
  214. global $form, $install;
  215. $status = $install->_map_info(
  216. $_POST['select_map_provider'],
  217. $_POST['map_provider_api_key'],
  218. $_POST['table_prefix']
  219. );
  220. //no errors
  221. if( $status == 0 ) {
  222. // make sure users get to the general setting from advanced db info page.
  223. $_SESSION['advanced_finished'] = 'advanced_map';
  224. // send the database info to the next page for updating the settings table.
  225. $_SESSION['select_map_provider'] = $_POST['select_map_provider'];
  226. $_SESSION['map_provider_api_key'] = $_POST['map_provider_api_key'];
  227. $_SESSION['table_prefix'] = $_POST['table_prefix'];
  228. header("Location:advanced_finished.php");
  229. }else if($status == 1 ) {
  230. $_SESSION['value_array'] = $_POST;
  231. $_SESSION['error_array'] = $form->get_error_array();
  232. header("Location:advanced_map_configuration.php");
  233. }
  234. }
  235. /**
  236. * Process the pre permission check for basic installer mode.
  237. */
  238. public function _proc_basic_pre_perm_check() {
  239. global $install,$form;
  240. $status = $install->_check_writable_dir();
  241. $status += $install->_check_modules();
  242. if($status == 0 ) {
  243. $_SESSION['basic_db_info'] = 'basic_summary';
  244. header("Location:basic_db_info.php");
  245. }else {
  246. $_SESSION['value_array'] = $_POST;
  247. $_SESSION['error_array'] = $form->get_error_array();
  248. header("Location:basic_summary.php");
  249. }
  250. }
  251. /**
  252. * Process the pre permission check for advanced installer mode.
  253. * +Check for required PHP libraries
  254. */
  255. public function _proc_advanced_pre_perm_check() {
  256. global $install, $form, $modules;
  257. $status = $install->_check_writable_dir();
  258. $status += $install->_check_modules_advanced();
  259. if($status == 0 ) {
  260. // make sure users get to the general setting from advanced db info page.
  261. $_SESSION['advanced_db_info'] = 'advanced_summary';
  262. header("Location:advanced_db_info.php");
  263. }else{
  264. $_SESSION['value_array'] = $_POST;
  265. $_SESSION['error_array'] = $form->get_error_array();
  266. header("Location:advanced_summary.php");
  267. }
  268. }
  269. }
  270. $process = new Process();
  271. ?>