Exemple #1
0
 function run()
 {
     $validator = new HC_Validator();
     // $validator->set_rules('first_name',			'trim|required');
     $post = $this->input->post();
     $this->form->grab($post);
     $values = $this->form->values();
     $errors = array();
     if ($values && $validator->run($values)) {
         /* run setup */
         /* reset tables */
         $this->_drop_tables();
         /* setup tables */
         $this->load->library('migration');
         if (!$this->migration->current()) {
             show_error($this->migration->error_string());
             return false;
         }
         $setup_ok = TRUE;
         /* admin user */
         $um = HC_App::model('user');
         $um->from_array($values);
         $um->level = $um->_const('LEVEL_ADMIN');
         if ($um->save()) {
             $email_from = $values['email'];
             $email_from_name = $values['first_name'] . ' ' . $values['last_name'];
         } else {
             $errors = array_merge($errors, $um->errors());
             $this->_drop_tables();
             $setup_ok = FALSE;
         }
         if ($setup_ok) {
             /* default settings */
             $app_conf = HC_App::app_conf();
             $app_conf->init();
             // to reload database
             $app_conf->set('email_from', $email_from);
             $app_conf->set('email_from_name', $email_from_name);
             $this->session->set_flashdata('message', HCM::__('OK'));
             # message sent on succesful setup
             $this->redirect('setup/ok');
             return;
         }
     }
     $errors = array_merge($errors, $validator->errors());
     $this->form->set_errors($errors);
     return $this->index();
 }