blob: 1b459cff865ab68e9b120f5cadaa935f623737c1 [file] [log] [blame]
Marc Kupietz0215a442023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
Marc Kupietzbaf8d912023-03-15 09:13:03 +01003include_once 'utils.php';
Marc Kupietz0215a442023-03-05 18:34:16 +01004
5class User
6{
Marc Kupietz49f677c2023-03-10 08:29:41 +01007 public $id;
Marc Kupietz03146622023-03-07 12:03:21 +01008 public $username;
Marc Kupietz144d82e2023-03-26 15:55:42 +02009 public $title;
Marc Kupietz03146622023-03-07 12:03:21 +010010 public $first_name;
11 public $last_name;
12 public $organization;
13 public $user_hash;
14 public $password;
15 public $street;
16 public $zip;
17 public $city;
18 public $country;
19 public $email;
20 public $phone;
21 public bool $eula_signed;
22 public bool $privacy_policy_signed;
Marc Kupietzcdf29572023-03-09 08:14:12 +010023 public bool $author;
24 public $accepted_paper_id;
Marc Kupietz145f5b92023-03-09 20:39:31 +010025 public bool $participation_confirmed;
Marc Kupietzcdf29572023-03-09 08:14:12 +010026 public $participation_confirmed_at;
27 public bool $student;
28 public bool $conference_dinner;
Marc Kupietz0dbe6b62023-03-21 17:58:11 +010029 public bool $vegetarian_dinner;
Marc Kupietz49f677c2023-03-10 08:29:41 +010030 public $registered_at;
31 public bool $earlybird_registration;
Marc Kupietz79eaa0b2023-03-16 17:33:43 +010032 public $lunch_day_1;
33 public $lunch_day_2;
34 public $lunch_day_3;
Marc Kupietz145f5b92023-03-09 20:39:31 +010035 public float $total_due;
Marc Kupietz49f677c2023-03-10 08:29:41 +010036 public $invoice;
Marc Kupietz03146622023-03-07 12:03:21 +010037
38 function __construct()
39 {
Marc Kupietz49f677c2023-03-10 08:29:41 +010040 $this->id = "";
Marc Kupietz03146622023-03-07 12:03:21 +010041 $this->username = "";
Marc Kupietz144d82e2023-03-26 15:55:42 +020042 $this->title = "";
Marc Kupietz03146622023-03-07 12:03:21 +010043 $this->first_name = "";
44 $this->last_name = "";
45 $this->email = "";
46 $this->organization = "";
47 $this->user_hash = "";
48 $this->password = "";
49 $this->city = "";
50 $this->country = "";
51 $this->zip = "";
52 $this->street = "";
53 $this->phone = "";
54 $this->eula_signed = false;
55 $this->privacy_policy_signed = false;
Marc Kupietzcdf29572023-03-09 08:14:12 +010056 $this->author = false;
57 $this->accepted_paper_id = "";
58 $this->participation_confirmed = false;
59 $this->participation_confirmed_at = "";
60 $this->student = false;
61 $this->conference_dinner = false;
Marc Kupietz0dbe6b62023-03-21 17:58:11 +010062 $this->vegetarian_dinner = false;
Marc Kupietz49f677c2023-03-10 08:29:41 +010063 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
64 $this->earlybird_registration = false;
Marc Kupietz145f5b92023-03-09 20:39:31 +010065 $this->total_due = 0.0;
Marc Kupietz49f677c2023-03-10 08:29:41 +010066 $this->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +010067 }
68
69 function __construct1(object $data)
70 {
71 foreach ($data as $key => $value) {
72 if (array_key_exists($key, (array) $this))
73 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010074 }
Marc Kupietz03146622023-03-07 12:03:21 +010075 if (isset($data->password)) $this->set_password($data->password);
76 }
Marc Kupietz0215a442023-03-05 18:34:16 +010077
Marc Kupietz03146622023-03-07 12:03:21 +010078 function init_from_object(object $data)
79 {
80 foreach ($data as $key => $value) {
81 if (array_key_exists($key, (array) $this))
82 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010083 }
Marc Kupietz03146622023-03-07 12:03:21 +010084 if (isset($data->password)) $this->set_password($data->password);
85 }
Marc Kupietzade9e3c2023-03-06 21:39:23 +010086
Marc Kupietz03146622023-03-07 12:03:21 +010087 function init_from_array(array $data)
88 {
89 foreach ($data as $key => $value) {
90 if (array_key_exists($key, (array) $this)) {
91 if (is_bool(gettype($this->{$key})) && is_string($value))
92 $this->{$key} = !empty($value);
93 else
94 $this->{$key} = $value;
95 }
96 }
97 if (!empty($data["password"])) $this->set_password($data["password"]);
98 }
99
Marc Kupietz03146622023-03-07 12:03:21 +0100100
101 function set_password(string $password)
102 {
103 include 'config.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100104 if ($CONFERENCE_REGISTRATION) {
105 $this->password = generateRandomString(32);
Marc Kupietz03146622023-03-07 12:03:21 +0100106 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
107 } else {
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100108 if ($ENCRYPT_PASSWORDS) {
109 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
110 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
111 } else {
112 $this->user_hash = "{CLEAR}" . $password;
113 }
114 $this->password = $this->user_hash;
Marc Kupietz03146622023-03-07 12:03:21 +0100115 }
Marc Kupietz03146622023-03-07 12:03:21 +0100116 }
117
118 function to_string()
119 {
120 $tmp_user = $this;
Marc Kupietz49f677c2023-03-10 08:29:41 +0100121 $tmp_user->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +0100122 $tmp_user->password = "***";
123 $tmp_user->user_hash = "***";
124 return json_encode($tmp_user);
125 }
126
127 function backup_in_session()
128 {
129 global $_SESSION;
130 foreach ($this as $key => $value) {
131 $_SESSION[$key] = $value;
132 }
133 }
134
135 function to_table() {
136 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
137 foreach ($this as $key => $value) {
Marc Kupietz49f677c2023-03-10 08:29:41 +0100138 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz03146622023-03-07 12:03:21 +0100139 if (is_bool($value)) {
140 if ($value) $value = "yes";
141 else $value = "no";
Marc Kupietz145f5b92023-03-09 20:39:31 +0100142 } elseif(is_float($value)) {
143 $key .= " €";
Marc Kupietzfaa2bd12023-03-21 17:47:41 +0100144 $value = number_format($value, 2, '.', ' ');
Marc Kupietz0215a442023-03-05 18:34:16 +0100145 }
Marc Kupietz03146622023-03-07 12:03:21 +0100146 $value = str_replace("\r\n", "<br>", $value);
147 $key = str_replace("_", " ", ucfirst($key));
148 $table .= " <tr>
149 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
150 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
151 </tr>\n";
152 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100153 }
Marc Kupietz03146622023-03-07 12:03:21 +0100154 $table .= "</table>";
155 return $table;
156 }
157}