PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/install/index.php

http://clients-oriented-ftp.googlecode.com/
PHP | 308 lines | 237 code | 36 blank | 35 comment | 20 complexity | 808eba730d41d599cd56cab5b6ee7697 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Contains the form and the processes used to install ProjectSend.
  4. *
  5. * @package ProjectSend
  6. * @subpackage Install
  7. */
  8. require_once('../sys.includes.php');
  9. $database->MySQLDB();
  10. /**
  11. * Function that takes an array of SQL queries and executes them in order.
  12. */
  13. function try_query($query)
  14. {
  15. if (empty($error_str)) {
  16. global $error_str;
  17. }
  18. foreach ($query as $i => $value) {
  19. $result = mysql_query($query[$i]);
  20. if (mysql_error()) {
  21. $error_str .= mysql_error().'<br />';
  22. }
  23. }
  24. return $result;
  25. }
  26. /** Collect data from form */
  27. if($_POST) {
  28. $this_install_title = mysql_real_escape_string($_POST['this_install_title']);
  29. $base_uri = mysql_real_escape_string($_POST['base_uri']);
  30. $got_admin_name = mysql_real_escape_string($_POST['install_user_fullname']);
  31. $got_admin_username = mysql_real_escape_string($_POST['install_user_username']);
  32. $got_admin_email = mysql_real_escape_string($_POST['install_user_mail']);
  33. $got_admin_pass = mysql_real_escape_string(md5($_POST['install_user_pass']));
  34. $got_admin_pass2 = mysql_real_escape_string(md5($_POST['install_user_repeat']));
  35. }
  36. /** Define the installation text stirngs */
  37. $page_title_install = __('Install','cftp_admin');
  38. $install_no_sitename = __('Sitename was not completed.','cftp_admin');
  39. $install_no_baseuri = __('ProjectSend URI was not completed.','cftp_admin');
  40. ?>
  41. <!DOCTYPE html>
  42. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
  43. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
  44. <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
  45. <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  46. <head>
  47. <meta charset="utf-8">
  48. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  49. <title><?php echo $page_title_install; ?> &raquo; <?php echo SYSTEM_NAME; ?></title>
  50. <link rel="shortcut icon" href="../favicon.ico" />
  51. <link rel="stylesheet" media="all" type="text/css" href="../css/base.css" />
  52. <link rel="stylesheet" media="all" type="text/css" href="../css/shared.css" />
  53. <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
  54. <link rel="stylesheet" media="all" type="text/css" href="../css/bootstrap.min.css" />
  55. <link rel="stylesheet" media="all" type="text/css" href="../css/bootstrap-responsive.min.css" />
  56. <script type="text/javascript" src="../includes/js/bootstrap/bootstrap.min.js"></script>
  57. <script type="text/javascript" src="../includes/js/bootstrap/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  58. <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,300' rel='stylesheet' type='text/css'>
  59. <link href='http://fonts.googleapis.com/css?family=Abel' rel='stylesheet' type='text/css'>
  60. <script type="text/javascript">
  61. $(document).ready(function() {
  62. $('.button').click(function() {
  63. $(this).blur();
  64. });
  65. });
  66. </script>
  67. </head>
  68. <body>
  69. <header>
  70. <div id="header">
  71. <div id="lonely_logo">
  72. <h1><?php echo SYSTEM_NAME.' '; _e('setup','cftp_admin'); ?></h1>
  73. </div>
  74. </div>
  75. <div id="login_header_low">
  76. </div>
  77. <?php
  78. include('../includes/updates.messages.php');
  79. ?>
  80. </header>
  81. <div id="main">
  82. <div class="options_box whitebox" id="install_form">
  83. <?php
  84. if (is_projectsend_installed()) {
  85. ?>
  86. <h3><?php _e('Already installed','cftp_admin'); ?></h3>
  87. <p><?php _e('It seems that ProjectSend is already installed here.','cftp_admin'); ?></p>
  88. <p><?php _e('If you want to reinstall, please delete the system tables from the database and come back to the installation form.','cftp_admin'); ?></p>
  89. <?php
  90. }
  91. else {
  92. if ($_POST) {
  93. /**
  94. * The URI must end with a /, so add it if it wasn't posted.
  95. */
  96. if ($base_uri{(strlen($base_uri) - 1)} != '/') { $base_uri .= '/'; }
  97. /** Begin form validation */
  98. $valid_me->validate('completed',$this_install_title,$install_no_sitename);
  99. $valid_me->validate('completed',$base_uri,$install_no_baseuri);
  100. $valid_me->validate('completed',$got_admin_name,$validation_no_name);
  101. $valid_me->validate('completed',$got_admin_email,$validation_no_email);
  102. /** Username validation */
  103. $valid_me->validate('completed',$got_admin_username,$validation_no_user);
  104. $valid_me->validate('length',$got_admin_username,$validation_length_user,MIN_USER_CHARS,MAX_USER_CHARS);
  105. $valid_me->validate('alpha',$got_admin_username,$validation_alpha_user);
  106. /** Password fields validation */
  107. $valid_me->validate('completed',$_POST['install_user_pass'],$validation_no_pass);
  108. $valid_me->validate('completed',$_POST['install_user_repeat'],$validation_no_pass2);
  109. $valid_me->validate('email',$got_admin_email,$validation_invalid_mail);
  110. $valid_me->validate('length',$_POST['install_user_pass'],$validation_length_pass,MIN_USER_CHARS,MAX_USER_CHARS);
  111. $valid_me->validate('password',$_POST['install_user_pass'],$validation_alpha_pass);
  112. $valid_me->validate('pass_match','',$validation_match_pass,'','',$_POST['install_user_pass'],$_POST['install_user_repeat']);
  113. if ($valid_me->return_val) {
  114. /**
  115. * Call the file that creates the tables and fill it with the data we got previously
  116. */
  117. include_once(ROOT_DIR.'/install/database.php');
  118. /**
  119. * Try to execute each query individually
  120. */
  121. try_query(array($q1,$q2,$q3,$q4,$q5,$q6,$q7,$q8,$q9,$q10,$q11));
  122. /**
  123. * Continue based on the value returned from the above function
  124. */
  125. if (!empty($error_str)) {
  126. $query_state = 'err';
  127. }
  128. else {
  129. $query_state = 'ok';
  130. }
  131. }
  132. }
  133. ?>
  134. <?php
  135. if(isset($valid_me)) {
  136. /** If the form was submited with errors, show them here */
  137. $valid_me->list_errors();
  138. }
  139. if (isset($query_state)) {
  140. switch ($query_state) {
  141. case 'ok':
  142. /**
  143. * Create/Chmod the upload directories to 755 to avoid
  144. * errors later.
  145. */
  146. $up_folders = array(
  147. 'main' => ROOT_DIR.'/upload',
  148. 'temp' => ROOT_DIR.'/upload/temp',
  149. 'files' => ROOT_DIR.'/upload/files'
  150. );
  151. foreach ($up_folders as $work_folder) {
  152. if (!file_exists($work_folder)) {
  153. mkdir($work_folder, 0755);
  154. }
  155. else {
  156. chmod($work_folder, 0755);
  157. }
  158. }
  159. chmod_timthumb();
  160. chmod_emails();
  161. chmod_main_files();
  162. $msg = __('Congratulations! Everything is up and running.','cftp_admin');
  163. echo system_message('ok',$msg);
  164. /** Record the action log */
  165. $new_log_action = new LogActions();
  166. $log_action_args = array(
  167. 'action' => 0,
  168. 'owner_id' => 1,
  169. 'owner_user' => $got_admin_name
  170. );
  171. $new_record_action = $new_log_action->log_action_save($log_action_args);
  172. ?>
  173. <p><?php _e('You may proceed to','cftp_admin'); ?> <a href="<?php echo $base_uri; ?>" target="_self"><?php _e('log in','cftp_admin'); ?></a> <?php _e('with your newely created username and password.','cftp_admin'); ?></p>
  174. <?php
  175. break;
  176. case 'err':
  177. $msg = __('There seems to be an error. Please try again.','cftp_admin');
  178. $msg .= '<p>';
  179. $msg .= $error_str;
  180. $msg .= '</p>';
  181. echo system_message('error',$msg);
  182. break;
  183. }
  184. }
  185. else {
  186. ?>
  187. <script type="text/javascript">
  188. $(document).ready(function() {
  189. $("form").submit(function() {
  190. clean_form(this);
  191. is_complete(this.this_install_title,'<?php echo $install_no_sitename; ?>');
  192. is_complete(this.base_uri,'<?php echo $install_no_baseuri; ?>');
  193. is_complete(this.install_user_fullname,'<?php echo $validation_no_name; ?>');
  194. is_complete(this.install_user_mail,'<?php echo $validation_no_email; ?>');
  195. // username
  196. is_complete(this.install_user_username,'<?php echo $validation_no_user; ?>');
  197. is_length(this.install_user_username,<?php echo MIN_USER_CHARS; ?>,<?php echo MAX_USER_CHARS; ?>,'<?php echo $validation_length_user; ?>');
  198. is_alpha(this.install_user_username,'<?php echo $validation_alpha_user; ?>');
  199. // password fields
  200. is_complete(this.install_user_pass,'<?php echo $validation_no_pass; ?>');
  201. is_complete(this.install_user_repeat,'<?php echo $validation_no_pass2; ?>');
  202. is_email(this.install_user_mail,'<?php echo $validation_invalid_mail; ?>');
  203. is_length(this.install_user_pass,<?php echo MIN_USER_CHARS; ?>,<?php echo MAX_USER_CHARS; ?>,'<?php echo $validation_length_pass; ?>');
  204. is_password(this.install_user_pass,'<?php $chars = addslashes($validation_valid_chars); echo $validation_valid_pass." ".$chars; ?>');
  205. is_match(this.install_user_pass,this.install_user_repeat,'<?php echo $validation_match_pass; ?>');
  206. // show the errors or continue if everything is ok
  207. if (show_form_errors() == false) { return false; }
  208. });
  209. });
  210. </script>
  211. <form action="index.php" name="installform" method="post">
  212. <ul class="form_fields">
  213. <li>
  214. <h3><?php _e('Basic system options','cftp_admin'); ?></h3>
  215. <p><?php _e("You need to provide this data for a correct system installation. The site name will be visible along the system panel, and the client's lists.<br />Don't forget to edit <em>/includes/sys.config.php</em> with your database settings before installing. If the file doesn't exist, you can create it by renanming the dummy file sys.config.sample.php.",'cftp_admin'); ?></p>
  216. </li>
  217. <li>
  218. <label for="this_install_title"><?php _e('Site name','cftp_admin'); ?></label>
  219. <input name="this_install_title" id="this_install_title" class="required" value="<?php echo (isset($this_install_title) ? $this_install_title : ''); ?>" />
  220. </li>
  221. <li>
  222. <label for="base_uri"><?php _e('ProjectSend URI (address)','cftp_admin'); ?></label>
  223. <input name="base_uri" id="base_uri" class="required" value="<?php echo (isset($base_uri) ? $base_uri : get_current_url()); ?>" />
  224. </li>
  225. <li class="options_divide"></li>
  226. <li>
  227. <h3><?php _e('Default system administrator options','cftp_admin'); ?></h3>
  228. <p><?php _e("This info will be used to create a default system user, which can't be deleted afterwards. Password should be between <strong>6 and 12 characters long</strong>.",'cftp_admin'); ?></p>
  229. </li>
  230. <li>
  231. <label for="install_user_fullname"><?php _e('Full name','cftp_admin'); ?></label>
  232. <input name="install_user_fullname" id="install_user_fullname" class="required" value="<?php echo (isset($got_admin_name) ? $got_admin_name : ''); ?>" />
  233. </li>
  234. <li>
  235. <label for="install_user_mail"><?php _e('E-mail address','cftp_admin'); ?></label>
  236. <input name="install_user_mail" id="install_user_mail" class="required" value="<?php echo (isset($got_admin_email) ? $got_admin_email : ''); ?>" />
  237. </li>
  238. <li>
  239. <label for="install_user_username"><?php _e('Log in username','cftp_admin'); ?></label>
  240. <input name="install_user_username" id="install_user_username" class="required" maxlength="<?php echo MAX_USER_CHARS; ?>" value="<?php echo (isset($got_admin_username) ? $got_admin_username : ''); ?>" />
  241. </li>
  242. <li>
  243. <label for="install_user_pass"><?php _e('Password','cftp_admin'); ?></label>
  244. <input type="password" name="install_user_pass" id="install_user_pass" class="required" maxlength="12" />
  245. </li>
  246. <li>
  247. <label for="install_user_repeat"><?php _e('Repeat','cftp_admin'); ?></label>
  248. <input type="password" name="install_user_repeat" id="install_user_repeat" class="required" maxlength="12" />
  249. </li>
  250. <li class="form_submit_li">
  251. <input type="submit" name="Submit" value="<?php _e('Install','cftp_admin'); ?>" class="button button_blue button_submit" />
  252. </li>
  253. </ul>
  254. <div id="install_extra">
  255. <p><?php _e('After installing the system, you can go to the options page to set your timezone, prefered date display format and thubmnails parameters, besides being able to change the site options provided here.','cftp_admin'); ?></p>
  256. </div>
  257. </form>
  258. <?php
  259. }
  260. }
  261. ?>
  262. </div>
  263. </div> <!--main-->
  264. <?php default_footer_info(); ?>
  265. </body>
  266. </html>
  267. <?php
  268. $database->Close();
  269. ob_end_flush();
  270. ?>