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');
31 import('ttTeamHelper');
34 $cl_login = $request->getParameter('login');
35 $cl_password = $request->getParameter('password');
36 if ($cl_login == null && $request->getMethod() == 'GET')
37 $cl_login = @$_COOKIE['tt_login'];
39 $form = new Form('loginForm');
40 $form->addInput(array('type'=>'text','size'=>'25','maxlength'=>'100','name'=>'login','style'=>'width: 220px;','value'=>$cl_login));
41 $form->addInput(array('type'=>'text','size'=>'25','maxlength'=>'50','name'=>'password','style'=>'width: 220px;','aspassword'=>true,'value'=>$cl_password));
42 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_login click.
43 $form->addInput(array('type'=>'submit','name'=>'btn_login','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.login')));
45 if ($request->isPost()) {
46 // Validate user input.
47 if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login'));
48 if (!ttValidString($cl_password)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
51 // Use the "limit" plugin if we have one. Ignore include errors.
52 // The "limit" plugin is not required for normal operation of Time Tracker.
53 @include('plugins/limit/access_check.php');
55 if ($auth->doLogin($cl_login, $cl_password)) {
56 // Set current user date (as determined by user browser) into session.
57 $current_user_date = $request->getParameter('browser_today', null);
58 if ($current_user_date)
59 $_SESSION['date'] = $current_user_date;
61 // Remember user login in a cookie.
62 setcookie('tt_login', $cl_login, time() + COOKIE_EXPIRE, '/');
64 $user = new ttUser(null, $auth->getUserId());
65 // Redirect, depending on user role.
66 if ($user->isAdmin()) {
67 header('Location: admin_teams.php');
69 else if ($user->isClient()) {
70 header('Location: reports.php');
73 header('Location: time.php');
77 $err->add($i18n->getKey('error.auth'));
81 if(!isTrue(MULTITEAM_MODE) && !ttTeamHelper::getTeams())
82 $err->add($i18n->getKey('error.no_teams'));
84 // Determine whether to show login hint. It is currently used only for Windows LDAP authentication.
85 $show_hint = ('ad' == $GLOBALS['AUTH_MODULE_PARAMS']['type']);
87 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
88 $smarty->assign('show_hint', $show_hint);
89 $smarty->assign('onload', 'onLoad="document.loginForm.'.(!$cl_login?'login':'password').'.focus()"');
90 $smarty->assign('title', $i18n->getKey('title.login'));
91 $smarty->assign('content_page_name', 'login.tpl');
92 $smarty->assign('about_text', $i18n->getKey('form.login.about'));
93 $smarty->display('index.tpl');