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 3 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, see .
Inheritance: extends AppController
 public function render($action = null, $layout = null, $file = null)
 {
     if (!$this->testView) {
         $this->renderedAction = $action;
     } else {
         return parent::render($action, $layout, $file);
     }
 }
 function add()
 {
     $this->Session->write('current_menu', 'logged');
     $this->pageTitle = __('Create an account', true);
     App::import('Controller', 'LanguagesUsers');
     $LangsUsers = new LanguagesUsersController();
     $LangsUsers->constructClasses();
     $user_id = $this->Auth->user('id');
     if (isset($user_id) && $user_id > 0) {
         $this->redirect($this->def_redirect);
     }
     if (!empty($this->data)) {
         //$this->User->set($this->data);
         $offer_levels = $this->_get_levels($this->data['User']['offer'], $this->data['User']['level']['offer']);
         if (!$this->User->validates()) {
             $this->set('errors', $this->User->validationErrors);
             $this->data['User']['password'] = "";
         } else {
             if (!$this->Recaptcha->valid($this->params['form'])) {
                 $this->data['User']['password'] = "";
                 $this->Session->setFlash(__('Captcha is incorrect', true));
             } else {
                 //print_r($this->data);
                 //$this->data['User']['password'] = $this->Auth->password($this->data['User']['password']);
                 $this->data['User']['message'] = Sanitize::html($this->data['User']['message']);
                 $cleaned_data = Sanitize::clean($this->data);
                 if (!$this->isAdmin()) {
                     $group = $this->User->Group->findByName('users');
                     $group_id = $group['Group']['id'];
                     $this->data['User']['group_id'] = $group_id;
                 }
                 $this->User->create();
                 //if ($this->User->saveAll($this->data, array('validate' => false) ))
                 if ($this->User->save($cleaned_data)) {
                     //$this->Auth->login($this->data);
                     $this->data['User']['password'] = "";
                     $user_id = $this->User->getLastInsertID();
                     $user = $this->data['User'];
                     $offers = $user['offer'];
                     foreach ($this->data['User']['offer'] as $offer_language_id) {
                         $data['language_id'] = $offer_language_id;
                         $data['user_id'] = $user_id;
                         $data['offer'] = 1;
                         $data['level'] = $offer_levels[$offer_language_id];
                         $LangsUsers->LanguagesUser->create();
                         $LangsUsers->LanguagesUser->save($data);
                     }
                     unset($data);
                     $wants = $user['want'];
                     foreach ($this->data['User']['want'] as $want_language_id) {
                         $data['language_id'] = $want_language_id;
                         $data['user_id'] = $user_id;
                         $data['offer'] = 0;
                         $LangsUsers->LanguagesUser->create();
                         $LangsUsers->LanguagesUser->save($data);
                     }
                     unset($data);
                     $name = $this->data['User']['name'] . " " . $this->data['User']['surname'];
                     //$this->_send_greetings($user_id, $name, $this->data['User']['email']);
                     $this->__send_activation_email($user_id, $name, $this->data['User']['email']);
                     $this->Session->setFlash(__('thanks_for_registration', true));
                     $this->redirect($this->def_redirect);
                 } else {
                     $this->data['User']['password'] = "";
                     $this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
                 }
             }
         }
         // validation
     }
     App::import('Controller', 'Languages');
     $Languages = new LanguagesController();
     $Languages->constructClasses();
     $offer = $Languages->Language->find('list');
     $want = $offer;
     $cities = $this->User->City->find('list');
     $countries = $this->User->Country->find('list');
     $groups = array();
     if ($this->isAdmin()) {
         $groups = $this->User->Group->find('list');
     }
     $this->set(compact('cities', 'countries', 'offer', 'want', 'groups'));
 }