Adjusted Work units plugin to count only bullable units.
[timetracker.git] / register.php
1 <?php
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.
10 // |
11 // | There are only two ways to violate the license:
12 // |
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).
16 // |
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).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 require_once('initialize.php');
30 import('form.Form');
31
32 if (!isTrue(MULTITEAM_MODE) || $auth->isPasswordExternal()) {
33   header('Location: login.php');
34   exit();
35 }
36
37 $auth->doLogout();
38
39 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
40
41 if ($request->isPost()) {
42   $cl_group_name = trim($request->getParameter('group_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'));
51 } else {
52   $cl_currency = CURRENCY_DEFAULT;
53   $cl_lang = $i18n->lang; // Browser setting from initialize.php.
54 }
55
56 $form = new Form('groupForm');
57 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group_name));
58 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
59
60 // Prepare an array of available languages.
61 $lang_files = I18n::getLangFileList();
62 foreach ($lang_files as $lfile) {
63   $content = file(RESOURCE_DIR."/".$lfile);
64   $lname = '';
65   foreach ($content as $line) {
66     if (strstr($line, 'i18n_language')) {
67       $a = explode('=', $line);
68       $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
69       break;
70     }
71   }
72   unset($content);
73   $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
74 }
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));
77
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->get('button.submit')));
84
85 if ($request->isPost()) {
86   // Create fields array for ttRegistrator instance.
87   $fields = array(
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_group_name,
94     'currency' => $cl_currency,
95     'lang' => $cl_lang);
96
97   // Create an instance of ttRegistrator class.
98   import('ttRegistrator');
99   $registrator = new ttRegistrator($fields, $err);
100   $registrator->register();
101
102   if ($err->no()) {
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');
107     } else {
108       header('Location: login.php');
109     }
110     exit();
111   }
112 } // isPost
113
114 $smarty->assign('title', $i18n->get('title.create_group'));
115 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
116 $smarty->assign('onload', 'onLoad="document.groupForm.group_name.focus()"');
117 $smarty->assign('content_page_name', 'register.tpl');
118 $smarty->display('index.tpl');