public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Search Repo:
tedkulp (author)
Sat Apr 26 13:24:56 -0700 2008
commit  d0c7ce152c41ceaef9472cf23f6be1a732ba1151
tree    ca8c6f6b9c7a10ca27feae9a363e35d5b23d0b86
parent  70bf6724fdaa23598c17553a84853459a89d3e65
cmsmadesimple-2-0 / install / index.php
100644 221 lines (179 sloc) 8.521 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
//Cut them off at the pass...
if (version_compare(phpversion(), "5.2", "<"))
{
    echo 'CMS Made Simple 2.0 requires php 5.2 and above to run. Please upgrade your system before proceeding.';
    exit;
}
 
require_once('../lib/cmsms.api.php');
require_once('lib/class.cms_install_operations.php');
 
$session_key = substr(md5(dirname(__FILE__)), 0, 8);
 
#Setup session with different id and start it
@session_name('CMSSESSID' . $session_key);
@ini_set('url_rewriter.tags', '');
@ini_set('session.use_trans_sid', 0);
@session_start();
CmsRequest::setup();
$smarty = CmsSmarty::get_instance(false);
$smarty->force_compile = true;
$smarty->template_dir = cms_join_path(dirname(dirname(__FILE__)),'install','templates'.DS);
$smarty->plugins_dir = array(cms_join_path(dirname(dirname(__FILE__)),'lib','smarty','plugins'.DS), cms_join_path(dirname(__FILE__),'plugins'.DS));
 
$xajax = new CmsAjax();
$xajax->register_function('test_connection');
$xajax->process_requests();
$smarty->assign('xajax_header', $xajax->get_javascript());
 
display_page($smarty);
 
function display_page($smarty, $action = '')
{
  if ($action == '')
    $action = CmsInstallOperations::get_action();
  
  switch ($action)
  {
    case "intro":
  
      $smarty->assign('languages', CmsInstallOperations::get_language_list());
      $smarty->assign('selected_language', CmsInstallOperations::get_language_cookie());
 
      $smarty->assign('include_file', 'intro.tpl');
      $smarty->display('body.tpl');
      break;
    
    case "check":
    
      $required_checks = CmsInstallOperations::required_checks();
 
      $smarty->assign('php_version', CmsInstallOperations::required_setting_output($required_checks['php_version']));
      $smarty->assign('has_database', CmsInstallOperations::required_setting_output($required_checks['has_database']));
      $smarty->assign('which_database', $required_checks['which_database']);
 
      $smarty->assign('has_xml', CmsInstallOperations::required_setting_output($required_checks['has_xml']));
      $smarty->assign('has_simplexml', CmsInstallOperations::required_setting_output($required_checks['has_simplexml']));
    
      $smarty->assign('templates_path', cms_join_path(dirname(dirname(__FILE__)),'tmp','template_c'));
      $smarty->assign('canwrite_templates', CmsInstallOperations::required_setting_output($required_checks['canwrite_templates']));
      $smarty->assign('cache_path', cms_join_path(dirname(dirname(__FILE__)),'tmp','cache'));
      $smarty->assign('canwrite_cache', CmsInstallOperations::required_setting_output($required_checks['canwrite_cache']));
    
      $smarty->assign('failure', $required_checks['failure']);
    
      $recommended_checks = CmsInstallOperations::recommended_checks();
    
      $smarty->assign('file_uploads', CmsInstallOperations::recommended_setting_output($recommended_checks['file_uploads']));
      $smarty->assign('safe_mode', CmsInstallOperations::recommended_setting_output($recommended_checks['safe_mode'], true));
      $smarty->assign('magic_quotes_runtime', CmsInstallOperations::recommended_setting_output($recommended_checks['magic_quotes_runtime'], true));
      $smarty->assign('register_globals', CmsInstallOperations::recommended_setting_output($recommended_checks['register_globals'], true));
      $smarty->assign('output_buffering', CmsInstallOperations::recommended_setting_output($recommended_checks['output_buffering'], true));
 
      $smarty->assign('uploads_path', cms_join_path(dirname(dirname(__FILE__)),'uploads'));
      $smarty->assign('canwrite_uploads', CmsInstallOperations::recommended_setting_output($recommended_checks['canwrite_uploads']));
      $smarty->assign('modules_path', cms_join_path(dirname(dirname(__FILE__)),'modules'));
      $smarty->assign('canwrite_modules', CmsInstallOperations::recommended_setting_output($recommended_checks['canwrite_modules']));
    
      $smarty->assign('failure2', $recommended_checks['failure']);
 
      $smarty->assign('include_file', 'check.tpl');
      $smarty->display('body.tpl');
      break;
    
    case "database":
 
      $smarty->assign('databases', CmsInstallOperations::get_loaded_database_modules());
 
      if (isset($_REQUEST['connection']))
      {
        $_SESSION['connection'] = $_REQUEST['connection'];
        if (isset($_REQUEST['next']))
        {
          display_page($smarty, 'account');
          return;
        }
        else if (isset($_REQUEST['back']))
        {
          display_page($smarty, 'check');
          return;
        }
      }
  
      $smarty->assign('include_file', 'database.tpl');
      $smarty->display('body.tpl');
      break;
    
    case "account":
    
      if (isset($_REQUEST['admin_account']))
      {
        $_SESSION['admin_account'] = $_REQUEST['admin_account'];
        if (isset($_REQUEST['next']))
        {
          display_page($smarty, 'create_config');
          return;
        }
        else if (isset($_REQUEST['back']))
        {
          display_page($smarty, 'database');
          return;
        }
      }
    
      $smarty->assign('include_file', 'account.tpl');
      $smarty->display('body.tpl');
      break;
    
    case "create_config":
 
      if (isset($_REQUEST['config']))
      {
        $_SESSION['config'] = $_REQUEST['config'];
        if (isset($_REQUEST['next']))
        {
          display_page($smarty, 'create_schema');
          return;
        }
        else if (isset($_REQUEST['back']))
        {
          display_page($smarty, 'account');
          return;
        }
      }
      else
      {
        $_SESSION['config']['rootpath'] = dirname(dirname(__FILE__));
        $_SESSION['config']['rooturl'] = 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strlen($_SERVER['PHP_SELF'])-18);
      }
      $smarty->assign('include_file', 'config.tpl');
      $smarty->display('body.tpl');
      break;
      
    case "create_schema":
    
      $connection = $_SESSION['connection'];
      $admin_account = $_SESSION['admin_account'];
      
      $user_created = false;
      $config_created = false;
      $config_file_contents = '';
      
      $installed = CmsInstallOperations::install_schema($connection['driver'], $connection['hostname'], $connection['username'], $connection['password'], $connection['dbname'], $connection['table_prefix'], $connection['drop_tables']);
      if ($installed)
      {
        $basic_loaded = CmsInstallOperations::load_basic_schema($connection['driver'], $connection['hostname'], $connection['username'], $connection['password'], $connection['dbname'], $connection['table_prefix']);
        $user_created = CmsInstallOperations::install_account($connection['driver'], $connection['hostname'], $connection['username'], $connection['password'], $connection['dbname'], $connection['table_prefix'], $admin_account['username'], $admin_account['password']);
        $config_created = CmsInstallOperations::install_config($connection,$_SESSION['config'], $config_file_contents);
      }  
      $smarty->assign('installed', $installed);
      $smarty->assign('user_created', $user_created);
      $smarty->assign('config_created', $config_created);
      $smarty->assign('config_file_contents', $config_file_contents);
      $smarty->assign('include_file', 'create_schema.tpl');
      $smarty->display('body.tpl');
    
      break;
  }
}
 
function test_connection($params, $ajax = true)
{
  global $smarty; //Too lazy to set it all up again
 
  $response = new CmsAjaxResponse();
  
  $result = CmsInstallOperations::test_database_connection($params['connection']['driver'],
                               $params['connection']['hostname'],
                               $params['connection']['username'],
                               $params['connection']['password'],
                               $params['connection']['dbname']);
 
  $smarty->assign('databasetestresult', $result);
  $response->modify_html("#connection_options", $smarty->fetch('databaseinsert.tpl'));
  
  $response->script("$('#connection_options').slideDown('slow');");
 
  return $response->get_result();
}
 
# vim:ts=4 sw=4 noet
?>