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