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');
37 // Use the "limit" plugin if we have one. Ignore include errors.
38 // The "limit" plugin is not required for normal operation of Time Tracker.
39 @include('plugins/limit/register.php');
43 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
45 if ($request->isPost()) {
46 $cl_group_name = trim($request->getParameter('group_name'));
47 $cl_currency = trim($request->getParameter('currency'));
48 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
49 $cl_lang = $request->getParameter('lang');
50 $cl_manager_name = trim($request->getParameter('manager_name'));
51 $cl_manager_login = trim($request->getParameter('manager_login'));
52 $cl_password1 = $request->getParameter('password1');
53 $cl_password2 = $request->getParameter('password2');
54 $cl_manager_email = trim($request->getParameter('manager_email'));
56 $cl_currency = CURRENCY_DEFAULT;
57 $cl_lang = $i18n->lang; // Browser setting from initialize.php.
60 $form = new Form('groupForm');
61 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group_name));
62 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
64 // Prepare an array of available languages.
65 $lang_files = I18n::getLangFileList();
66 foreach ($lang_files as $lfile) {
67 $content = file(RESOURCE_DIR."/".$lfile);
69 foreach ($content as $line) {
70 if (strstr($line, 'i18n_language')) {
71 $a = explode('=', $line);
72 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
77 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
79 $longname_lang = mu_sort($longname_lang, 'name');
80 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
82 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
83 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
84 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
85 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
86 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_email','value'=>$cl_manager_email));
87 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
89 if ($request->isPost()) {
90 // Create fields array for ttRegistrator instance.
92 'user_name' => $cl_manager_name,
93 'login' => $cl_manager_login,
94 'password1' => $cl_password1,
95 'password2' => $cl_password2,
96 'email' => $cl_manager_email,
97 'group_name' => $cl_group_name,
98 'currency' => $cl_currency,
101 // Create an instance of ttRegistrator class.
102 import('ttRegistrator');
103 $registrator = new ttRegistrator($fields, $err);
104 $registrator->register();
107 // Registration successful.
108 if ($auth->doLogin($cl_manager_login, $cl_password1)) {
109 setcookie('tt_login', $cl_manager_login, time() + COOKIE_EXPIRE, '/');
110 header('Location: time.php');
112 header('Location: login.php');
118 $smarty->assign('title', $i18n->get('title.add_group'));
119 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
120 $smarty->assign('onload', 'onLoad="document.groupForm.group_name.focus()"');
121 $smarty->assign('content_page_name', 'register.tpl');
122 $smarty->display('index.tpl');