blob: 6a9e2cfd5a528696dc55306de238a635b0b2288f [file] [log] [blame]
Marc Kupietzd871d882023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
Marc Kupietz4f63f382023-03-15 09:13:03 +01003include_once 'utils.php';
Marc Kupietzd871d882023-03-05 18:34:16 +01004
5class User
6{
Marc Kupietzce676312023-03-10 08:29:41 +01007 public $id;
Marc Kupietz3417c882023-03-07 12:03:21 +01008 public $username;
9 public $first_name;
10 public $last_name;
11 public $organization;
12 public $user_hash;
13 public $password;
14 public $street;
15 public $zip;
16 public $city;
17 public $country;
18 public $email;
19 public $phone;
20 public bool $eula_signed;
21 public bool $privacy_policy_signed;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010022 public bool $author;
23 public $accepted_paper_id;
Marc Kupietz87a14312023-03-09 20:39:31 +010024 public bool $participation_confirmed;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010025 public $participation_confirmed_at;
26 public bool $student;
27 public bool $conference_dinner;
Marc Kupietzce676312023-03-10 08:29:41 +010028 public $registered_at;
29 public bool $earlybird_registration;
Marc Kupietz87a14312023-03-09 20:39:31 +010030 public float $total_due;
Marc Kupietzce676312023-03-10 08:29:41 +010031 public $invoice;
Marc Kupietz3417c882023-03-07 12:03:21 +010032
33 function __construct()
34 {
Marc Kupietzce676312023-03-10 08:29:41 +010035 $this->id = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010036 $this->username = "";
37 $this->first_name = "";
38 $this->last_name = "";
39 $this->email = "";
40 $this->organization = "";
41 $this->user_hash = "";
42 $this->password = "";
43 $this->city = "";
44 $this->country = "";
45 $this->zip = "";
46 $this->street = "";
47 $this->phone = "";
48 $this->eula_signed = false;
49 $this->privacy_policy_signed = false;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010050 $this->author = false;
51 $this->accepted_paper_id = "";
52 $this->participation_confirmed = false;
53 $this->participation_confirmed_at = "";
54 $this->student = false;
55 $this->conference_dinner = false;
Marc Kupietzce676312023-03-10 08:29:41 +010056 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
57 $this->earlybird_registration = false;
Marc Kupietz87a14312023-03-09 20:39:31 +010058 $this->total_due = 0.0;
Marc Kupietzce676312023-03-10 08:29:41 +010059 $this->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010060 }
61
62 function __construct1(object $data)
63 {
64 foreach ($data as $key => $value) {
65 if (array_key_exists($key, (array) $this))
66 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010067 }
Marc Kupietz3417c882023-03-07 12:03:21 +010068 if (isset($data->password)) $this->set_password($data->password);
69 }
Marc Kupietzd871d882023-03-05 18:34:16 +010070
Marc Kupietz3417c882023-03-07 12:03:21 +010071 function init_from_object(object $data)
72 {
73 foreach ($data as $key => $value) {
74 if (array_key_exists($key, (array) $this))
75 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010076 }
Marc Kupietz3417c882023-03-07 12:03:21 +010077 if (isset($data->password)) $this->set_password($data->password);
78 }
Marc Kupietza57befa2023-03-06 21:39:23 +010079
Marc Kupietz3417c882023-03-07 12:03:21 +010080 function init_from_array(array $data)
81 {
82 foreach ($data as $key => $value) {
83 if (array_key_exists($key, (array) $this)) {
84 if (is_bool(gettype($this->{$key})) && is_string($value))
85 $this->{$key} = !empty($value);
86 else
87 $this->{$key} = $value;
88 }
89 }
90 if (!empty($data["password"])) $this->set_password($data["password"]);
91 }
92
Marc Kupietz3417c882023-03-07 12:03:21 +010093
94 function set_password(string $password)
95 {
96 include 'config.php';
Marc Kupietz3b7170a2023-03-10 13:54:21 +010097 if ($CONFERENCE_REGISTRATION) {
98 $this->password = generateRandomString(32);
Marc Kupietz3417c882023-03-07 12:03:21 +010099 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
100 } else {
Marc Kupietz3b7170a2023-03-10 13:54:21 +0100101 if ($ENCRYPT_PASSWORDS) {
102 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
103 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
104 } else {
105 $this->user_hash = "{CLEAR}" . $password;
106 }
107 $this->password = $this->user_hash;
Marc Kupietz3417c882023-03-07 12:03:21 +0100108 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100109 }
110
111 function to_string()
112 {
113 $tmp_user = $this;
Marc Kupietzce676312023-03-10 08:29:41 +0100114 $tmp_user->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +0100115 $tmp_user->password = "***";
116 $tmp_user->user_hash = "***";
117 return json_encode($tmp_user);
118 }
119
120 function backup_in_session()
121 {
122 global $_SESSION;
123 foreach ($this as $key => $value) {
124 $_SESSION[$key] = $value;
125 }
126 }
127
128 function to_table() {
129 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
130 foreach ($this as $key => $value) {
Marc Kupietzce676312023-03-10 08:29:41 +0100131 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz3417c882023-03-07 12:03:21 +0100132 if (is_bool($value)) {
133 if ($value) $value = "yes";
134 else $value = "no";
Marc Kupietz87a14312023-03-09 20:39:31 +0100135 } elseif(is_float($value)) {
136 $key .= " €";
Marc Kupietzd871d882023-03-05 18:34:16 +0100137 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100138 $value = str_replace("\r\n", "<br>", $value);
139 $key = str_replace("_", " ", ucfirst($key));
140 $table .= " <tr>
141 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
142 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
143 </tr>\n";
144 }
Marc Kupietzd871d882023-03-05 18:34:16 +0100145 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100146 $table .= "</table>";
147 return $table;
148 }
149}