blob: 91cfa21d9b46e434dce767d921e98dbbb71ecc49 [file] [log] [blame]
Marc Kupietzd871d882023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
3
4class User
5{
Marc Kupietzce676312023-03-10 08:29:41 +01006 public $id;
Marc Kupietz3417c882023-03-07 12:03:21 +01007 public $username;
8 public $first_name;
9 public $last_name;
10 public $organization;
11 public $user_hash;
12 public $password;
13 public $street;
14 public $zip;
15 public $city;
16 public $country;
17 public $email;
18 public $phone;
19 public bool $eula_signed;
20 public bool $privacy_policy_signed;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010021 public bool $author;
22 public $accepted_paper_id;
Marc Kupietz87a14312023-03-09 20:39:31 +010023 public bool $participation_confirmed;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010024 public $participation_confirmed_at;
25 public bool $student;
26 public bool $conference_dinner;
Marc Kupietzce676312023-03-10 08:29:41 +010027 public $registered_at;
28 public bool $earlybird_registration;
Marc Kupietz87a14312023-03-09 20:39:31 +010029 public float $total_due;
Marc Kupietzce676312023-03-10 08:29:41 +010030 public $invoice;
Marc Kupietz3417c882023-03-07 12:03:21 +010031
32 function __construct()
33 {
Marc Kupietzce676312023-03-10 08:29:41 +010034 $this->id = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010035 $this->username = "";
36 $this->first_name = "";
37 $this->last_name = "";
38 $this->email = "";
39 $this->organization = "";
40 $this->user_hash = "";
41 $this->password = "";
42 $this->city = "";
43 $this->country = "";
44 $this->zip = "";
45 $this->street = "";
46 $this->phone = "";
47 $this->eula_signed = false;
48 $this->privacy_policy_signed = false;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010049 $this->author = false;
50 $this->accepted_paper_id = "";
51 $this->participation_confirmed = false;
52 $this->participation_confirmed_at = "";
53 $this->student = false;
54 $this->conference_dinner = false;
Marc Kupietzce676312023-03-10 08:29:41 +010055 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
56 $this->earlybird_registration = false;
Marc Kupietz87a14312023-03-09 20:39:31 +010057 $this->total_due = 0.0;
Marc Kupietzce676312023-03-10 08:29:41 +010058 $this->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010059 }
60
61 function __construct1(object $data)
62 {
63 foreach ($data as $key => $value) {
64 if (array_key_exists($key, (array) $this))
65 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010066 }
Marc Kupietz3417c882023-03-07 12:03:21 +010067 if (isset($data->password)) $this->set_password($data->password);
68 }
Marc Kupietzd871d882023-03-05 18:34:16 +010069
Marc Kupietz3417c882023-03-07 12:03:21 +010070 function init_from_object(object $data)
71 {
72 foreach ($data as $key => $value) {
73 if (array_key_exists($key, (array) $this))
74 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010075 }
Marc Kupietz3417c882023-03-07 12:03:21 +010076 if (isset($data->password)) $this->set_password($data->password);
77 }
Marc Kupietza57befa2023-03-06 21:39:23 +010078
Marc Kupietz3417c882023-03-07 12:03:21 +010079 function init_from_array(array $data)
80 {
81 foreach ($data as $key => $value) {
82 if (array_key_exists($key, (array) $this)) {
83 if (is_bool(gettype($this->{$key})) && is_string($value))
84 $this->{$key} = !empty($value);
85 else
86 $this->{$key} = $value;
87 }
88 }
89 if (!empty($data["password"])) $this->set_password($data["password"]);
90 }
91
Marc Kupietz3417c882023-03-07 12:03:21 +010092
93 function set_password(string $password)
94 {
95 include 'config.php';
96 if ($ENCRYPT_PASSWORDS) {
97 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
98 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
99 } else {
100 $this->user_hash = "{CLEAR}" . $password;
101 }
102 $this->password = $this->user_hash;
103 }
104
105 function to_string()
106 {
107 $tmp_user = $this;
Marc Kupietzce676312023-03-10 08:29:41 +0100108 $tmp_user->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +0100109 $tmp_user->password = "***";
110 $tmp_user->user_hash = "***";
111 return json_encode($tmp_user);
112 }
113
114 function backup_in_session()
115 {
116 global $_SESSION;
117 foreach ($this as $key => $value) {
118 $_SESSION[$key] = $value;
119 }
120 }
121
122 function to_table() {
123 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
124 foreach ($this as $key => $value) {
Marc Kupietzce676312023-03-10 08:29:41 +0100125 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz3417c882023-03-07 12:03:21 +0100126 if (is_bool($value)) {
127 if ($value) $value = "yes";
128 else $value = "no";
Marc Kupietz87a14312023-03-09 20:39:31 +0100129 } elseif(is_float($value)) {
130 $key .= " €";
Marc Kupietzd871d882023-03-05 18:34:16 +0100131 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100132 $value = str_replace("\r\n", "<br>", $value);
133 $key = str_replace("_", " ", ucfirst($key));
134 $table .= " <tr>
135 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
136 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
137 </tr>\n";
138 }
Marc Kupietzd871d882023-03-05 18:34:16 +0100139 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100140 $table .= "</table>";
141 return $table;
142 }
143}