Started to work on ttRegistrator class to encapsulate restration related tasks.
[timetracker.git] / WEB-INF / lib / ttRegistrator.class.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 // ttRegistrator class is used to register a user in Time Tracker.
30 class ttRegistrator {
31   var $user_name = null;  // User name.
32   var $login = null;      // User login.
33   var $password = null;   // User password.
34   var $email = null;      // User email.
35   var $group_name = null; // Group name.
36   var $currency = null;   // Currency.
37   var $lang = null;       // Language.
38   var $err = null;        // Error object, passed to us as reference.
39                           // We use it to communicate errors to caller.
40
41   // Constructor.
42   function __construct($fields, &$err) {
43     $this->user_name = $fields['user_name'];
44     $this->login = $fields['login'];    
45     $this->password1 = $fields['password1'];
46     $this->password2 = $fields['password2'];
47     $this->email = $fields['email'];
48     $this->group_name = $fields['group_name'];
49     $this->currency = $fields['currency'];
50     $this->lang = $fields['lang'];
51     if (!$thins->lang) $this->lang = 'en';
52     $this->err = $err;
53
54     // Validate passed in parameters.
55     $this->validate();
56   }
57
58   function validate() {
59     global $i18n;
60
61     if (!ttValidString($this->group_name, true))
62       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name'));
63     if (!ttValidString($this->currency, true))
64       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.currency'));
65     if (!ttValidString($this->user_name))
66       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_name'));
67     if (!ttValidString($this->login))
68       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_login'));
69     if (!ttValidString($this->password1))
70       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
71     if (!ttValidString($this->password2))
72       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password'));
73     if ($this->password1 !== $this->password2)
74       $this->err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password'));    
75     if (!ttValidEmail($this->email, true))
76       $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
77   }
78
79   // The register function registers a user in Time Tracker.
80   function register() {
81     // TODO: work in progress. Not implemented.
82   }
83 }