blob: 790af5a0b53e8843f0a87934689320a5f4a1b836 [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 Kupietz8701abd2023-03-16 17:33:43 +010030 public $lunch_day_1;
31 public $lunch_day_2;
32 public $lunch_day_3;
Marc Kupietz87a14312023-03-09 20:39:31 +010033 public float $total_due;
Marc Kupietzce676312023-03-10 08:29:41 +010034 public $invoice;
Marc Kupietz3417c882023-03-07 12:03:21 +010035
36 function __construct()
37 {
Marc Kupietzce676312023-03-10 08:29:41 +010038 $this->id = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010039 $this->username = "";
40 $this->first_name = "";
41 $this->last_name = "";
42 $this->email = "";
43 $this->organization = "";
44 $this->user_hash = "";
45 $this->password = "";
46 $this->city = "";
47 $this->country = "";
48 $this->zip = "";
49 $this->street = "";
50 $this->phone = "";
51 $this->eula_signed = false;
52 $this->privacy_policy_signed = false;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010053 $this->author = false;
54 $this->accepted_paper_id = "";
55 $this->participation_confirmed = false;
56 $this->participation_confirmed_at = "";
57 $this->student = false;
58 $this->conference_dinner = false;
Marc Kupietzce676312023-03-10 08:29:41 +010059 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
60 $this->earlybird_registration = false;
Marc Kupietz87a14312023-03-09 20:39:31 +010061 $this->total_due = 0.0;
Marc Kupietzce676312023-03-10 08:29:41 +010062 $this->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010063 }
64
65 function __construct1(object $data)
66 {
67 foreach ($data as $key => $value) {
68 if (array_key_exists($key, (array) $this))
69 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010070 }
Marc Kupietz3417c882023-03-07 12:03:21 +010071 if (isset($data->password)) $this->set_password($data->password);
72 }
Marc Kupietzd871d882023-03-05 18:34:16 +010073
Marc Kupietz3417c882023-03-07 12:03:21 +010074 function init_from_object(object $data)
75 {
76 foreach ($data as $key => $value) {
77 if (array_key_exists($key, (array) $this))
78 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010079 }
Marc Kupietz3417c882023-03-07 12:03:21 +010080 if (isset($data->password)) $this->set_password($data->password);
81 }
Marc Kupietza57befa2023-03-06 21:39:23 +010082
Marc Kupietz3417c882023-03-07 12:03:21 +010083 function init_from_array(array $data)
84 {
85 foreach ($data as $key => $value) {
86 if (array_key_exists($key, (array) $this)) {
87 if (is_bool(gettype($this->{$key})) && is_string($value))
88 $this->{$key} = !empty($value);
89 else
90 $this->{$key} = $value;
91 }
92 }
93 if (!empty($data["password"])) $this->set_password($data["password"]);
94 }
95
Marc Kupietz3417c882023-03-07 12:03:21 +010096
97 function set_password(string $password)
98 {
99 include 'config.php';
Marc Kupietz3b7170a2023-03-10 13:54:21 +0100100 if ($CONFERENCE_REGISTRATION) {
101 $this->password = generateRandomString(32);
Marc Kupietz3417c882023-03-07 12:03:21 +0100102 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
103 } else {
Marc Kupietz3b7170a2023-03-10 13:54:21 +0100104 if ($ENCRYPT_PASSWORDS) {
105 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
106 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
107 } else {
108 $this->user_hash = "{CLEAR}" . $password;
109 }
110 $this->password = $this->user_hash;
Marc Kupietz3417c882023-03-07 12:03:21 +0100111 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100112 }
113
114 function to_string()
115 {
116 $tmp_user = $this;
Marc Kupietzce676312023-03-10 08:29:41 +0100117 $tmp_user->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +0100118 $tmp_user->password = "***";
119 $tmp_user->user_hash = "***";
120 return json_encode($tmp_user);
121 }
122
123 function backup_in_session()
124 {
125 global $_SESSION;
126 foreach ($this as $key => $value) {
127 $_SESSION[$key] = $value;
128 }
129 }
130
131 function to_table() {
132 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
133 foreach ($this as $key => $value) {
Marc Kupietzce676312023-03-10 08:29:41 +0100134 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz3417c882023-03-07 12:03:21 +0100135 if (is_bool($value)) {
136 if ($value) $value = "yes";
137 else $value = "no";
Marc Kupietz87a14312023-03-09 20:39:31 +0100138 } elseif(is_float($value)) {
139 $key .= " €";
Marc Kupietz6557d442023-03-21 17:47:41 +0100140 $value = number_format($value, 2, '.', ' ');
Marc Kupietzd871d882023-03-05 18:34:16 +0100141 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100142 $value = str_replace("\r\n", "<br>", $value);
143 $key = str_replace("_", " ", ucfirst($key));
144 $table .= " <tr>
145 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
146 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
147 </tr>\n";
148 }
Marc Kupietzd871d882023-03-05 18:34:16 +0100149 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100150 $table .= "</table>";
151 return $table;
152 }
153}