- if ($errors->isEmpty()) {
- if (!ttUserHelper::getUserByLogin($cl_manager_login)) {
- // Create a new team.
- if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
- $team_id = ttTeamHelper::insert(array('name'=>$cl_team_name,'currency'=>CURRENCY_DEFAULT));
- if ($team_id) {
- // Team created, now create a team manager.
- $user_id = ttUserHelper::insert(array(
- 'team_id' => $team_id,
- 'role' => ROLE_MANAGER,
- 'name' => $cl_manager_name,
- 'login' => $cl_manager_login,
- 'password' => $cl_password1,
- 'email' => $cl_manager_email));
- }
- if ($team_id && $user_id) {
- header('Location: admin_teams.php');
- } else
- $errors->add($i18n->getKey('error.db'));
- } else
- $errors->add($i18n->getKey('error.user_exists'));
+ // Create fields array for ttRegistrator instance.
+ if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
+ $fields = array(
+ 'user_name' => $cl_manager_name,
+ 'login' => $cl_manager_login,
+ 'password1' => $cl_password1,
+ 'password2' => $cl_password2,
+ 'email' => $cl_manager_email,
+ 'group_name' => $cl_team_name,
+ 'currency' => CURRENCY_DEFAULT,
+ 'lang' => $cl_lang);
+
+ // Create an instance of ttRegistrator class.
+ import('ttRegistrator');
+ $registrator = new ttRegistrator($fields, $err);
+ $registrator->register();
+ $registrator->setCreatedBy($user->id); // Override created_by to admin account.
+ if ($err->no()) {
+ header('Location: admin_teams.php');
+ exit();