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('ttOrgHelper');
34 if ($request->isPost()) {
35 $cl_login = $request->getParameter('login');
37 $cl_login = @$_COOKIE['tt_login'];
39 $cl_password = $request->getParameter('password');
41 $form = new Form('loginForm');
42 $form->addInput(array('type'=>'text','size'=>'25','maxlength'=>'100','name'=>'login','style'=>'width: 220px;','value'=>$cl_login));
43 $form->addInput(array('type'=>'password','size'=>'25','maxlength'=>'50','name'=>'password','style'=>'width: 220px;','value'=>$cl_password));
44 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_login click.
45 $form->addInput(array('type'=>'submit','name'=>'btn_login','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.login')));
47 if ($request->isPost()) {
48 // Validate user input.
49 if (!ttValidString($cl_login)) $err->add($i18n->get('error.field'), $i18n->get('label.login'));
50 if (!ttValidString($cl_password)) $err->add($i18n->get('error.field'), $i18n->get('label.password'));
54 // Use the "limit" plugin if we have one. Ignore include errors.
55 // The "limit" plugin is not required for normal operation of Time Tracker.
56 @include('../plugins/limit/access_check.php');
58 if ($auth->doLogin($cl_login, $cl_password)) {
60 // Set current user date (as determined by user browser) into session.
61 $current_user_date = $request->getParameter('browser_today', null);
62 if ($current_user_date)
63 $_SESSION['date'] = $current_user_date;
65 // Remember user login in a cookie.
66 setcookie('tt_login', $cl_login, time() + COOKIE_EXPIRE, '/');
68 $user = new ttUser(null, $auth->getUserId());
69 // Redirect, depending on user role.
70 if ($user->can('administer_site')) {
71 header('Location: ../admin_groups.php');
72 } elseif ($user->isClient()) {
73 header('Location: ../reports.php');
75 header('Location: time.php');
79 $err->add($i18n->get('error.auth'));
83 if(!isTrue('MULTIORG_MODE') && !ttOrgHelper::getOrgs())
84 $err->add($i18n->get('error.no_groups'));
86 // Determine whether to show login hint. It is currently used only for Windows LDAP authentication.
87 $show_hint = ('ad' == $GLOBALS['AUTH_MODULE_PARAMS']['type']);
89 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
90 $smarty->assign('show_hint', $show_hint);
91 $smarty->assign('onload', 'onLoad="document.loginForm.'.(!$cl_login?'login':'password').'.focus()"');
92 $smarty->assign('title', $i18n->get('title.login'));
93 $smarty->assign('content_page_name', 'mobile/login.tpl');
94 $smarty->display('mobile/index.tpl');