Renamed MULTITEAM_MODE to MULTIORG_MODE to better reflect the meaning of the constant.
[timetracker.git] / mobile / login.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 import('ttOrgHelper');
32 import('ttUser');
33
34 if ($request->isPost()) {
35   $cl_login = $request->getParameter('login');
36 } else {
37   $cl_login = @$_COOKIE['tt_login'];
38 }
39 $cl_password = $request->getParameter('password');
40
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')));
46
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'));
51
52   if ($err->no()) {
53
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');
57
58     if ($auth->doLogin($cl_login, $cl_password)) {
59
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;
64
65       // Remember user login in a cookie.
66       setcookie('tt_login', $cl_login, time() + COOKIE_EXPIRE, '/');
67
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');
74       } else {
75         header('Location: time.php');
76       }
77       exit();
78     } else
79       $err->add($i18n->get('error.auth'));
80   }
81 } // isPost
82
83 if(!isTrue('MULTIORG_MODE') && !ttOrgHelper::getOrgs())
84   $err->add($i18n->get('error.no_groups'));
85
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']);
88
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');