2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
32 if (!isTrue(MULTITEAM_MODE) || $auth->isPasswordExternal()) {
33 header('Location: login.php');
39 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
41 if ($request->isPost()) {
42 $cl_team_name = trim($request->getParameter('team_name'));
43 $cl_currency = trim($request->getParameter('currency'));
44 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
45 $cl_lang = $request->getParameter('lang');
46 $cl_manager_name = trim($request->getParameter('manager_name'));
47 $cl_manager_login = trim($request->getParameter('manager_login'));
48 $cl_password1 = $request->getParameter('password1');
49 $cl_password2 = $request->getParameter('password2');
50 $cl_manager_email = trim($request->getParameter('manager_email'));
52 $cl_currency = CURRENCY_DEFAULT;
53 $cl_lang = $i18n->lang; // Browser setting from initialize.php.
56 $form = new Form('profileForm');
57 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team_name));
58 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
60 // Prepare an array of available languages.
61 $lang_files = I18n::getLangFileList();
62 foreach ($lang_files as $lfile) {
63 $content = file(RESOURCE_DIR."/".$lfile);
65 foreach ($content as $line) {
66 if (strstr($line, 'i18n_language')) {
67 $a = explode('=', $line);
68 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
73 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
75 $longname_lang = mu_sort($longname_lang, 'name');
76 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
78 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
79 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
80 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
81 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
82 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_email','value'=>$cl_manager_email));
83 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit')));
85 if ($request->isPost()) {
86 // Create fields array for ttRegistrator instance.
88 'user_name' => $cl_manager_name,
89 'login' => $cl_manager_login,
90 'password1' => $cl_password1,
91 'password2' => $cl_password2,
92 'email' => $cl_manager_email,
93 'group_name' => $cl_team_name,
94 'currency' => $cl_currency,
97 // Create an instance of ttRegistrator class.
98 import('ttRegistrator');
99 $registrator = new ttRegistrator($fields, $err);
100 $registrator->register();
103 // Registration successful.
104 if ($auth->doLogin($cl_manager_login, $cl_password1)) {
105 setcookie('tt_login', $cl_manager_login, time() + COOKIE_EXPIRE, '/');
106 header('Location: time.php');
108 header('Location: login.php');
114 $smarty->assign('title', $i18n->getKey('title.create_team'));
115 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
116 $smarty->assign('onload', 'onLoad="document.profileForm.team.focus()"');
117 $smarty->assign('content_page_name', 'register.tpl');
118 $smarty->display('index.tpl');