Completed
Push — master ( b35b0f...acc097 )
by Greg
05:21
created

Login::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * /classes/DomainMOD/Login.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class Login
25
{
26
    public $system;
27
    public $time;
28
29
    public function __construct()
30
    {
31
        $this->system = new System();
32
        $this->time = new Time();
33
    }
34
35
    public function getUserInfo($user_id)
36
    {
37
        $tmpq = $this->system->db()->prepare("
38
            SELECT first_name, last_name, username, email_address, new_password, admin, `read_only`, number_of_logins,
39
                last_login
40
            FROM users
41
            WHERE id = :user_id
42
              AND active = '1'");
43
        $tmpq->execute(array('user_id' => $user_id));
44
        return $tmpq->fetch();
45
    }
46
47
    public function getSystemSettings()
48
    {
49
        $tmpq = $this->system->db()->query("
50
            SELECT full_url, db_version, upgrade_available, email_address, large_mode, default_category_domains,
51
                default_category_ssl, default_dns, default_host, default_ip_address_domains,
52
                default_ip_address_ssl, default_owner_domains, default_owner_ssl, default_registrar,
53
                default_registrar_account, default_ssl_provider_account, default_ssl_type, default_ssl_provider,
54
                expiration_days, debug_mode
55
            FROM settings");
56
        return $tmpq->fetch();
57
    }
58
59
    public function getUserSettings($user_id)
60
    {
61
        $tmpq = $this->system->db()->prepare("
62
            SELECT default_currency, default_timezone, default_category_domains, default_category_ssl, default_dns,
63
                default_host, default_ip_address_domains, default_ip_address_ssl, default_owner_domains,
64
                default_owner_ssl, default_registrar, default_registrar_account, default_ssl_provider_account,
65
                default_ssl_type, default_ssl_provider, expiration_emails, number_of_domains,
66
                number_of_ssl_certs, display_domain_owner, display_domain_registrar, display_domain_account,
67
                display_domain_expiry_date, display_domain_category, display_domain_dns, display_domain_host,
68
                display_domain_ip, display_domain_host, display_domain_tld, display_domain_fee,
69
                display_ssl_owner, display_ssl_provider, display_ssl_account, display_ssl_domain,
70
                display_ssl_type, display_ssl_ip, display_ssl_category, display_ssl_expiry_date, display_ssl_fee,
71
                display_inactive_assets, display_dw_intro_page
72
            FROM user_settings
73
            WHERE user_id = :user_id");
74
        $tmpq->execute(array('user_id' => $user_id));
75
        return $tmpq->fetch();
76
    }
77
78
    public function getCurrencyInfo($currency)
79
    {
80
        $tmpq = $this->system->db()->prepare("
81
            SELECT `name`, symbol, symbol_order, symbol_space
82
            FROM currencies
83
            WHERE currency = :currency");
84
        $tmpq->execute(array('currency' => $currency));
85
        return $tmpq->fetch();
86
    }
87
88
    public function setLastLogin($user_id)
89
    {
90
        $tmpq = $this->system->db()->prepare("
91
            UPDATE users
92
            SET last_login = :last_login,
93
                number_of_logins = number_of_logins + 1,
94
                update_time = :update_time
95
            WHERE id = :user_id");
96
        $tmpq->execute(array(
97
                       'last_login' => $this->time->stamp(),
98
                       'update_time' => $this->time->stamp(),
99
                       'user_id' => $user_id));
100
    }
101
102
} //@formatter:on
103