PluginProbe
ShiftController Employee Shift Scheduling / 2.1.0
ShiftController Employee Shift Scheduling v2.1.0
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / happ / application / controllers / setup.php

setup.php in ShiftController Employee Shift Scheduling 2.1.0, at happ/application/controllers/setup.php

235 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3 class Setup_controller extends MX_Controller
4 {
5 public $conf = array();
6
7 function __construct()
8 {
9 parent::__construct();
10
11 if( defined('NTS_DEVELOPMENT') )
12 {
13 // $this->output->enable_profiler(TRUE);
14 }
15
16 if( ! isset($this->conf) )
17 $this->conf = array();
18 if( ! isset($this->conf['path']) )
19 $this->conf['path'] = '';
20
21 $this->load->database();
22 $this->load->helper( array('url', 'language', 'form', 'hitcode', 'language', 'form') );
23 $this->load->library( array('form_validation', 'session', 'hc_bootstrap') );
24 $this->load->library( 'hc_form' );
25 $this->load->library( 'hc_modules' );
26 $this->form_validation->set_error_delimiters('<div class="hc-form-error">', '</div>');
27
28 // conf
29 $this->auth = NULL;
30
31 $this->data = array();
32 $this->data['message'] = $this->session->flashdata('message');
33 $this->data['error'] = $this->session->flashdata('error');
34
35 $this->session->set_flashdata('referrer', current_url());
36 $this->set_include( '' );
37 $this->data['page_title'] = $this->config->item('nts_app_title') . ' :: ' . 'Installation';
38
39 /* add module models paths for autoloading */
40 $modules = $this->config->item('modules');
41 $modules_locations = $this->config->item('modules_locations');
42 if( is_array($modules) )
43 {
44 reset($modules);
45 foreach( $modules as $module )
46 {
47 reset( $modules_locations );
48 foreach( $modules_locations as $ml )
49 {
50 $mod_dir = $ml . $module;
51 if( file_exists($mod_dir) )
52 {
53 Datamapper::add_model_path( $mod_dir );
54 }
55 }
56 }
57 }
58 }
59
60 protected function _drop_tables()
61 {
62 $app = $this->config->item('nts_app');
63 $my_table_prefix = isset($GLOBALS['NTS_CONFIG'][$app]['DB_TABLES_PREFIX']) ? $GLOBALS['NTS_CONFIG'][$app]['DB_TABLES_PREFIX'] : NTS_DB_TABLES_PREFIX;
64 $tables = array();
65 $sth = $this->db->query("SHOW TABLES LIKE '" . $my_table_prefix . "%'");
66 foreach( $sth->result_array() as $r )
67 {
68 reset( $r );
69 foreach( $r as $k => $v )
70 {
71 $tables[] = $v;
72 }
73 }
74 reset( $tables );
75 foreach( $tables as $t )
76 {
77 $this->db->query("DROP TABLE " . $t . "");
78 }
79 }
80
81 function index()
82 {
83 // check if already setup
84 if( $this->is_setup() )
85 {
86 ci_redirect();
87 return;
88 }
89
90 $this_module = CI::$APP->router->fetch_module();
91 if( $this_module )
92 {
93 $this->data['include'] = $this_module . '/setup';
94 }
95 else
96 {
97 $this->data['include'] = 'setup';
98 }
99 $this->load->view( '_layout/index_no_menu', $this->data );
100 }
101
102 function run()
103 {
104 $app = $this->config->item('nts_app');
105 $validation = array(
106 array(
107 'field' => 'first_name',
108 'label' => 'lang:user_first_name',
109 'rules' => 'trim|required'
110 ),
111 array(
112 'field' => 'last_name',
113 'label' => 'lang:user_last_name',
114 'rules' => 'trim|required'
115 ),
116 array(
117 'field' => 'email',
118 'label' => 'lang:common_email',
119 'rules' => 'trim|required|valid_email'
120 ),
121 array(
122 'field' => 'password',
123 'label' => 'lang:common_password',
124 'rules' => 'trim|required|matches[confirm_password]'
125 ),
126 array(
127 'field' => 'confirm_password',
128 'label' => 'lang:common_password_confirm',
129 'rules' => 'trim|required'
130 ),
131 );
132 $fields = array('first_name', 'last_name', 'email', 'password', 'confirm_password');
133
134 $this->form_validation->set_rules( $validation );
135
136 if( $this->input->post() )
137 {
138 $post = array();
139 reset( $fields );
140 foreach( $fields as $f )
141 {
142 $post[$f] = $this->input->post($f);
143 }
144 $this->hc_form->set_defaults( $post );
145
146 if( $this->form_validation->run() == FALSE )
147 {
148 $errors = array();
149 reset( $fields );
150 foreach( $fields as $f )
151 {
152 $errors[$f] = form_error($f);
153 }
154 $this->hc_form->set_errors( $errors );
155 }
156 else
157 {
158 /* run setup */
159 /* reset tables */
160 $this->_drop_tables();
161
162 /* setup tables */
163 $this->load->library('migration');
164 if ( ! $this->migration->current())
165 {
166 show_error($this->migration->error_string());
167 return false;
168 }
169
170 $this->load->library( 'conf/app_conf' );
171
172 $setup_ok = TRUE;
173 /* admin user */
174 $this->load->model( 'User_model' );
175 $this->User_model->from_array( $post );
176 $this->User_model->level = USER_MODEL::LEVEL_ADMIN;
177
178 if( $this->User_model->save() )
179 {
180 $email_from = $post['email'];
181 $email_from_name = $post['first_name'] . ' ' . $post['last_name'];
182 }
183 else
184 {
185 $this->hc_form->set_errors( $this->User_model->error->all );
186 $this->hc_form->set_defaults( $post );
187 $setup_ok = FALSE;
188 }
189
190 if( $setup_ok )
191 {
192 /* default settings */
193 $this->app_conf->set( 'email_from', $email_from );
194 $this->app_conf->set( 'email_from_name', $email_from_name );
195
196 $this->session->set_flashdata( 'message', lang('ok') );
197 ci_redirect( 'setup/ok' );
198 return;
199 }
200 }
201 }
202
203 $this->data['include'] = 'setup';
204 $this->load->view( '_layout/index_no_menu', $this->data );
205 return;
206 }
207
208 function ok()
209 {
210 $this->data['include'] = 'setup_ok';
211 $this->load->view( '_layout/index_no_menu', $this->data);
212 return;
213 }
214
215 function is_setup()
216 {
217 $return = TRUE;
218 if( $this->db->table_exists('conf') ){
219 $return = TRUE;
220 }
221 else {
222 $return = FALSE;
223 }
224 return $return;
225 }
226
227 function set_include( $file )
228 {
229 $this->data['include'] = '';
230 $this->data['include_submenu'] = '';
231 }
232 }
233
234 /* End of file setup.php */
235 /* Location: ./application/controllers/setup.php */